Implementation of custom fonts app wide
This commit is contained in:
parent
e9dcfc57f7
commit
6d7308210b
@ -13,7 +13,7 @@
|
||||
android:roundIcon="@mipmap/app_logo_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".activities.MergePullRequestActivity"></activity>
|
||||
<activity android:name=".activities.MergePullRequestActivity" />
|
||||
<activity
|
||||
android:name=".activities.FileViewActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
|
BIN
app/src/main/assets/fonts/manroperegular.ttf
Normal file
BIN
app/src/main/assets/fonts/manroperegular.ttf
Normal file
Binary file not shown.
@ -0,0 +1,61 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import org.mian.gitnex.helpers.FontsOverride;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public abstract class BaseActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(getLayoutResourceId());
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(getApplicationContext());
|
||||
|
||||
if(tinyDb.getInt("customFontId") == 0) {
|
||||
|
||||
FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/roboto.ttf");
|
||||
FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/roboto.ttf");
|
||||
FontsOverride.setDefaultFont(this, "SERIF", "fonts/roboto.ttf");
|
||||
FontsOverride.setDefaultFont(this, "SANS_SERIF", "fonts/roboto.ttf");
|
||||
|
||||
}
|
||||
else if (tinyDb.getInt("customFontId") == 1) {
|
||||
|
||||
FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/manroperegular.ttf");
|
||||
FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/manroperegular.ttf");
|
||||
FontsOverride.setDefaultFont(this, "SERIF", "fonts/manroperegular.ttf");
|
||||
FontsOverride.setDefaultFont(this, "SANS_SERIF", "fonts/manroperegular.ttf");
|
||||
|
||||
}
|
||||
else if (tinyDb.getInt("customFontId") == 2) {
|
||||
|
||||
FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/sourcecodeproregular.ttf");
|
||||
FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/sourcecodeproregular.ttf");
|
||||
FontsOverride.setDefaultFont(this, "SERIF", "fonts/sourcecodeproregular.ttf");
|
||||
FontsOverride.setDefaultFont(this, "SANS_SERIF", "fonts/sourcecodeproregular.ttf");
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/roboto.ttf");
|
||||
FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/roboto.ttf");
|
||||
FontsOverride.setDefaultFont(this, "SERIF", "fonts/roboto.ttf");
|
||||
FontsOverride.setDefaultFont(this, "SANS_SERIF", "fonts/roboto.ttf");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected abstract int getLayoutResourceId();
|
||||
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,6 @@ import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import com.tooltip.Tooltip;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
@ -44,7 +43,7 @@ import retrofit2.Callback;
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
|
||||
public class LoginActivity extends BaseActivity implements View.OnClickListener {
|
||||
|
||||
private Button loginButton;
|
||||
private EditText instanceUrlET, loginUidET, loginPassword, otpCode, loginTokenCode;
|
||||
@ -55,10 +54,14 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
|
||||
private String device_id = "token";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
protected int getLayoutResourceId(){
|
||||
return R.layout.activity_login;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_login);
|
||||
|
||||
TinyDB tinyDb = new TinyDB(getApplicationContext());
|
||||
boolean connToInternet = AppUtil.haveNetworkConnection(getApplicationContext());
|
||||
|
@ -8,7 +8,9 @@ import com.google.android.material.navigation.NavigationView;
|
||||
import androidx.core.view.GravityCompat;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import android.graphics.Typeface;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
@ -45,18 +47,27 @@ import retrofit2.Callback;
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
|
||||
public class MainActivity extends BaseActivity implements NavigationView.OnNavigationItemSelectedListener {
|
||||
|
||||
private DrawerLayout drawer;
|
||||
private TextView userFullName;
|
||||
private TextView userEmail;
|
||||
private ImageView userAvatar;
|
||||
private TextView toolbarTitle;
|
||||
final Context ctx = this;
|
||||
private Typeface myTypeface;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
protected int getLayoutResourceId(){
|
||||
return R.layout.activity_main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
final TinyDB tinyDb = new TinyDB(getApplicationContext());
|
||||
|
||||
tinyDb.putBoolean("noConnection", false);
|
||||
//userAvatar = findViewById(R.id.userAvatar);
|
||||
|
||||
@ -86,17 +97,62 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||
|
||||
boolean connToInternet = AppUtil.haveNetworkConnection(getApplicationContext());
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
if(!tinyDb.getBoolean("loggedInMode")) {
|
||||
logout();
|
||||
return;
|
||||
}
|
||||
|
||||
androidx.appcompat.widget.Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
toolbarTitle = toolbar.findViewById(R.id.toolbar_title);
|
||||
|
||||
if(tinyDb.getInt("customFontId") == 0) {
|
||||
|
||||
myTypeface = Typeface.createFromAsset(getAssets(), "fonts/roboto.ttf");
|
||||
|
||||
}
|
||||
else if (tinyDb.getInt("customFontId") == 1) {
|
||||
|
||||
myTypeface = Typeface.createFromAsset(getAssets(), "fonts/manroperegular.ttf");
|
||||
|
||||
}
|
||||
else if (tinyDb.getInt("customFontId") == 2) {
|
||||
|
||||
myTypeface = Typeface.createFromAsset(getAssets(), "fonts/sourcecodeproregular.ttf");
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
myTypeface = Typeface.createFromAsset(getAssets(), "fonts/roboto.ttf");
|
||||
|
||||
}
|
||||
|
||||
toolbarTitle.setTypeface(myTypeface);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
Fragment fragmentById = fm.findFragmentById(R.id.fragment_container);
|
||||
if (fragmentById instanceof SettingsFragment) {
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleSettings));
|
||||
}
|
||||
else if (fragmentById instanceof MyRepositoriesFragment) {
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleMyRepos));
|
||||
}
|
||||
else if (fragmentById instanceof StarredRepositoriesFragment) {
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleStarredRepos));
|
||||
}
|
||||
else if (fragmentById instanceof OrganizationsFragment) {
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleOrganizations));
|
||||
}
|
||||
else if (fragmentById instanceof ExploreRepositoriesFragment) {
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleExplore));
|
||||
}
|
||||
else if (fragmentById instanceof ProfileFragment) {
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleProfile));
|
||||
}
|
||||
else if (fragmentById instanceof AboutFragment) {
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleAbout));
|
||||
}
|
||||
|
||||
drawer = findViewById(R.id.drawer_layout);
|
||||
NavigationView navigationView = findViewById(R.id.nav_view);
|
||||
navigationView.setNavigationItemSelectedListener(this);
|
||||
@ -139,11 +195,13 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||
userEmail = hView.findViewById(R.id.userEmail);
|
||||
if (!userEmailNav.equals("")) {
|
||||
userEmail.setText(userEmailNav);
|
||||
userEmail.setTypeface(myTypeface);
|
||||
}
|
||||
|
||||
userFullName = hView.findViewById(R.id.userFullname);
|
||||
if (!userFullNameNav.equals("")) {
|
||||
userFullName.setText(userFullNameNav);
|
||||
userFullName.setTypeface(myTypeface);
|
||||
}
|
||||
|
||||
userAvatar = hView.findViewById(R.id.userAvatar);
|
||||
@ -176,31 +234,37 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||
|
||||
if(savedInstanceState == null) {
|
||||
if(tinyDb.getInt("homeScreenId") == 0) {
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleMyRepos));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
|
||||
new MyRepositoriesFragment()).commit();
|
||||
navigationView.setCheckedItem(R.id.nav_home);
|
||||
}
|
||||
else if(tinyDb.getInt("homeScreenId") == 1) {
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleStarredRepos));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
|
||||
new StarredRepositoriesFragment()).commit();
|
||||
navigationView.setCheckedItem(R.id.nav_starred_repos);
|
||||
}
|
||||
else if(tinyDb.getInt("homeScreenId") == 2) {
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleOrganizations));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
|
||||
new OrganizationsFragment()).commit();
|
||||
navigationView.setCheckedItem(R.id.nav_organizations);
|
||||
}
|
||||
else if(tinyDb.getInt("homeScreenId") == 3) {
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleRepositories));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
|
||||
new RepositoriesFragment()).commit();
|
||||
navigationView.setCheckedItem(R.id.nav_repositories);
|
||||
}
|
||||
else if(tinyDb.getInt("homeScreenId") == 4) {
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleProfile));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
|
||||
new ProfileFragment()).commit();
|
||||
navigationView.setCheckedItem(R.id.nav_profile);
|
||||
}
|
||||
else {
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleMyRepos));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
|
||||
new MyRepositoriesFragment()).commit();
|
||||
navigationView.setCheckedItem(R.id.nav_home);
|
||||
@ -246,22 +310,28 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||
|
||||
switch (menuItem.getItemId()) {
|
||||
case R.id.nav_home:
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleMyRepos));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
|
||||
new MyRepositoriesFragment()).commit();
|
||||
break;
|
||||
case R.id.nav_organizations:
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleOrganizations));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
|
||||
new OrganizationsFragment()).commit();
|
||||
break;
|
||||
case R.id.nav_profile:
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleProfile));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
|
||||
new ProfileFragment()).commit();
|
||||
break;
|
||||
case R.id.nav_repositories:
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleRepositories));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
|
||||
new RepositoriesFragment()).commit();
|
||||
|
||||
break;
|
||||
case R.id.nav_settings:
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleSettings));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
|
||||
new SettingsFragment()).commit();
|
||||
break;
|
||||
@ -270,6 +340,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
|
||||
break;
|
||||
case R.id.nav_about:
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleAbout));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
|
||||
new AboutFragment()).commit();
|
||||
break;
|
||||
@ -277,10 +348,12 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||
rateThisApp();
|
||||
break;
|
||||
case R.id.nav_starred_repos:
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleStarredRepos));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
|
||||
new StarredRepositoriesFragment()).commit();
|
||||
break;
|
||||
case R.id.nav_explore:
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleExplore));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
|
||||
new ExploreRepositoriesFragment()).commit();
|
||||
break;
|
||||
|
@ -14,6 +14,7 @@ import retrofit2.Callback;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
@ -47,14 +48,18 @@ import android.net.Uri;
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class RepoDetailActivity extends AppCompatActivity implements RepoBottomSheetFragment.BottomSheetListener {
|
||||
public class RepoDetailActivity extends BaseActivity implements RepoBottomSheetFragment.BottomSheetListener {
|
||||
|
||||
private TextView textViewBadge;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
protected int getLayoutResourceId(){
|
||||
return R.layout.activity_repo_detail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_repo_detail);
|
||||
|
||||
TinyDB tinyDb = new TinyDB(getApplicationContext());
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
|
@ -27,7 +27,6 @@ public class AboutFragment extends Fragment {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_about, container, false);
|
||||
((MainActivity) Objects.requireNonNull(getActivity())).setActionBarTitle(getResources().getString(R.string.pageTitleAbout));
|
||||
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
|
||||
|
@ -77,7 +77,6 @@ public class ExploreRepositoriesFragment extends Fragment {
|
||||
|
||||
final View v = inflater.inflate(R.layout.fragment_explore_repo, container, false);
|
||||
//setHasOptionsMenu(true);
|
||||
((MainActivity) Objects.requireNonNull(getActivity())).setActionBarTitle(getResources().getString(R.string.pageTitleExplore));
|
||||
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
|
@ -83,7 +83,6 @@ public class MyRepositoriesFragment extends Fragment {
|
||||
|
||||
final View v = inflater.inflate(R.layout.fragment_my_repositories, container, false);
|
||||
setHasOptionsMenu(true);
|
||||
((MainActivity) Objects.requireNonNull(getActivity())).setActionBarTitle(getResources().getString(R.string.pageTitleMyRepos));
|
||||
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
|
@ -50,7 +50,6 @@ public class OrganizationsFragment extends Fragment {
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
((MainActivity) Objects.requireNonNull(getActivity())).setActionBarTitle(getResources().getString(R.string.pageTitleOrganizations));
|
||||
final View v = inflater.inflate(R.layout.fragment_organizations, container, false);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.mian.gitnex.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@ -37,7 +38,6 @@ public class ProfileFragment extends Fragment {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_profile, container, false);
|
||||
((MainActivity) Objects.requireNonNull(getActivity())).setActionBarTitle(getResources().getString(R.string.pageTitleProfile));
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
@ -57,8 +57,42 @@ public class ProfileFragment extends Fragment {
|
||||
ViewPager mViewPager = v.findViewById(R.id.container);
|
||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||
|
||||
Typeface myTypeface;
|
||||
if(tinyDb.getInt("customFontId") == 0) {
|
||||
|
||||
myTypeface = Typeface.createFromAsset(Objects.requireNonNull(getContext()).getAssets(), "fonts/roboto.ttf");
|
||||
|
||||
}
|
||||
else if (tinyDb.getInt("customFontId") == 1) {
|
||||
|
||||
myTypeface = Typeface.createFromAsset(Objects.requireNonNull(getContext()).getAssets(), "fonts/manroperegular.ttf");
|
||||
|
||||
}
|
||||
else if (tinyDb.getInt("customFontId") == 2) {
|
||||
|
||||
myTypeface = Typeface.createFromAsset(Objects.requireNonNull(getContext()).getAssets(), "fonts/sourcecodeproregular.ttf");
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
myTypeface = Typeface.createFromAsset(Objects.requireNonNull(getContext()).getAssets(), "fonts/roboto.ttf");
|
||||
|
||||
}
|
||||
TabLayout tabLayout = v.findViewById(R.id.tabs);
|
||||
|
||||
ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0);
|
||||
int tabsCount = vg.getChildCount();
|
||||
for (int j = 0; j < tabsCount; j++) {
|
||||
ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
|
||||
int tabChildCount = vgTab.getChildCount();
|
||||
for (int i = 0; i < tabChildCount; i++) {
|
||||
View tabViewChild = vgTab.getChildAt(i);
|
||||
if (tabViewChild instanceof TextView) {
|
||||
((TextView) tabViewChild).setTypeface(myTypeface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
|
||||
tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
|
||||
|
||||
|
@ -22,7 +22,6 @@ import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.MainActivity;
|
||||
import org.mian.gitnex.activities.NewRepoActivity;
|
||||
import org.mian.gitnex.adapters.ReposListAdapter;
|
||||
import org.mian.gitnex.helpers.Authorization;
|
||||
@ -54,7 +53,6 @@ public class RepositoriesFragment extends Fragment {
|
||||
|
||||
final View v = inflater.inflate(R.layout.fragment_repositories, container, false);
|
||||
setHasOptionsMenu(true);
|
||||
((MainActivity) Objects.requireNonNull(getActivity())).setActionBarTitle(getResources().getString(R.string.pageTitleRepositories));
|
||||
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
|
@ -42,11 +42,13 @@ public class SettingsFragment extends Fragment {
|
||||
private static String[] homeScreenList = {"My Repositories", "Starred Repositories", "Organizations", "Repositories", "Profile"};
|
||||
private static int homeScreenSelectedChoice = 0;
|
||||
|
||||
private static String[] customFontList = {"Roboto", "Manrope", "Source Code Pro"};
|
||||
private static int customFontSelectedChoice = 0;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
((MainActivity) Objects.requireNonNull(getActivity())).setActionBarTitle(getResources().getString(R.string.pageTitleSettings));
|
||||
View v = inflater.inflate(R.layout.fragment_settings, container, false);
|
||||
final TinyDB tinyDb = new TinyDB(getContext());
|
||||
|
||||
@ -54,11 +56,13 @@ public class SettingsFragment extends Fragment {
|
||||
final TextView tvDateTimeSelected = v.findViewById(R.id.tvDateTimeSelected); // setter for time
|
||||
final TextView codeBlockSelected = v.findViewById(R.id.codeBlockSelected); // setter for code block
|
||||
final TextView homeScreenSelected = v.findViewById(R.id.homeScreenSelected); // setter for home screen
|
||||
final TextView customFontSelected = v.findViewById(R.id.customFontSelected); // setter for custom font
|
||||
|
||||
LinearLayout langFrame = v.findViewById(R.id.langFrame);
|
||||
LinearLayout timeFrame = v.findViewById(R.id.timeFrame);
|
||||
LinearLayout codeBlockFrame = v.findViewById(R.id.codeBlockFrame);
|
||||
LinearLayout homeScreenFrame = v.findViewById(R.id.homeScreenFrame);
|
||||
LinearLayout customFontFrame = v.findViewById(R.id.customFontFrame);
|
||||
|
||||
Switch issuesSwitch = v.findViewById(R.id.switchIssuesBadge);
|
||||
TextView helpTranslate = v.findViewById(R.id.helpTranslate);
|
||||
@ -89,6 +93,10 @@ public class SettingsFragment extends Fragment {
|
||||
homeScreenSelected.setText(tinyDb.getString("homeScreenStr"));
|
||||
}
|
||||
|
||||
if(!tinyDb.getString("customFontStr").isEmpty()) {
|
||||
customFontSelected.setText(tinyDb.getString("customFontStr"));
|
||||
}
|
||||
|
||||
if(langSelectedChoice == 0) {
|
||||
langSelectedChoice = tinyDb.getInt("langId");
|
||||
}
|
||||
@ -105,6 +113,10 @@ public class SettingsFragment extends Fragment {
|
||||
homeScreenSelectedChoice = tinyDb.getInt("homeScreenId");
|
||||
}
|
||||
|
||||
if(customFontSelectedChoice == 0) {
|
||||
customFontSelectedChoice = tinyDb.getInt("customFontId");
|
||||
}
|
||||
|
||||
if(tinyDb.getBoolean("enableCounterIssueBadge")) {
|
||||
issuesSwitch.setChecked(true);
|
||||
}
|
||||
@ -124,6 +136,44 @@ public class SettingsFragment extends Fragment {
|
||||
}
|
||||
});
|
||||
|
||||
// custom font dialog
|
||||
customFontFrame.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
AlertDialog.Builder cfBuilder = new AlertDialog.Builder(ctx, R.style.confirmDialog);
|
||||
|
||||
cfBuilder.setTitle(R.string.settingsCustomFontSelectorDialogTitle);
|
||||
if(customFontSelectedChoice != -1) {
|
||||
cfBuilder.setCancelable(true);
|
||||
}
|
||||
else {
|
||||
cfBuilder.setCancelable(false);
|
||||
}
|
||||
|
||||
cfBuilder.setSingleChoiceItems(customFontList, customFontSelectedChoice, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterfaceCustomFont, int i) {
|
||||
|
||||
customFontSelectedChoice = i;
|
||||
customFontSelected.setText(customFontList[i]);
|
||||
tinyDb.putString("customFontStr", customFontList[i]);
|
||||
tinyDb.putInt("customFontId", i);
|
||||
|
||||
Objects.requireNonNull(getActivity()).recreate();
|
||||
getActivity().overridePendingTransition(0, 0);
|
||||
dialogInterfaceCustomFont.dismiss();
|
||||
Toasty.info(getContext(), getResources().getString(R.string.settingsSave));
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
AlertDialog cfDialog = cfBuilder.create();
|
||||
cfDialog.show();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// home screen dialog
|
||||
homeScreenFrame.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -79,7 +79,6 @@ public class StarredRepositoriesFragment extends Fragment {
|
||||
View v = inflater.inflate(R.layout.fragment_starred_repositories, container, false);
|
||||
boolean connToInternet = AppUtil.haveNetworkConnection(Objects.requireNonNull(getContext()));
|
||||
setHasOptionsMenu(true);
|
||||
((MainActivity) Objects.requireNonNull(getActivity())).setActionBarTitle(getResources().getString(R.string.pageTitleStarredRepos));
|
||||
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
|
43
app/src/main/java/org/mian/gitnex/helpers/FontsOverride.java
Normal file
43
app/src/main/java/org/mian/gitnex/helpers/FontsOverride.java
Normal file
@ -0,0 +1,43 @@
|
||||
package org.mian.gitnex.helpers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.util.Log;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class FontsOverride {
|
||||
|
||||
public static void setDefaultFont(Context context,
|
||||
String staticTypefaceFieldName, String fontAssetName) {
|
||||
|
||||
final Typeface regular = Typeface.createFromAsset(context.getAssets(),
|
||||
fontAssetName);
|
||||
replaceFont(staticTypefaceFieldName, regular);
|
||||
|
||||
}
|
||||
|
||||
private static void replaceFont(String staticTypefaceFieldName,
|
||||
final Typeface newTypeface) {
|
||||
|
||||
try {
|
||||
|
||||
final Field staticField = Typeface.class
|
||||
.getDeclaredField(staticTypefaceFieldName);
|
||||
staticField.setAccessible(true);
|
||||
staticField.set(null, newTypeface);
|
||||
|
||||
}
|
||||
catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
|
||||
Log.e("error", Objects.requireNonNull(e.getMessage()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -13,8 +13,7 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:layout_width="match_parent"
|
||||
@ -24,12 +23,23 @@
|
||||
app:titleTextColor="@color/white"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||
android:elevation="4dp"/>
|
||||
android:elevation="4dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:gravity="center_vertical"
|
||||
android:textSize="18sp"
|
||||
android:id="@+id/toolbar_title" />
|
||||
|
||||
</androidx.appcompat.widget.Toolbar>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fragment_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.navigation.NavigationView
|
||||
|
@ -135,4 +135,34 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/customFontFrame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/customFontHeaderSelector"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginStart="44dp"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:text="@string/settingsCustomFontHeaderText"
|
||||
android:textColor="@color/white"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/customFontSelected"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:layout_marginStart="44dp"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:text="@string/defaultCopy"
|
||||
android:textColor="@color/white"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -5,8 +5,8 @@
|
||||
<item name="android:statusBarColor">@color/colorPrimary</item>
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimary</item>
|
||||
<item name="android:fontFamily">@font/roboto</item>
|
||||
<item name="android:windowBackground">@color/colorPrimary</item>
|
||||
<item name="android:typeface">monospace</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
@ -244,7 +244,7 @@
|
||||
<!-- settings -->
|
||||
<string name="settingsLanguageHeaderText">Translation</string>
|
||||
<string name="settingsDateTimeHeaderText">Date & Time</string>
|
||||
<string name="settingsSave">Settings saved.</string>
|
||||
<string name="settingsSave">Settings saved</string>
|
||||
<string name="settingsLanguageSelectorHeader">Language</string>
|
||||
<string name="settingsLanguageSelectedHeaderDefault">English</string>
|
||||
<string name="settingsAppearanceHeader">Appearance</string>
|
||||
@ -497,6 +497,7 @@
|
||||
<string name="dashCharacter" translatable="false">-</string>
|
||||
<string name="strPrivate" translatable="false">private</string>
|
||||
<string name="strPublic" translatable="false">public</string>
|
||||
<string name="defaultCopy" translatable="false">Default</string>
|
||||
<!-- generic copy -->
|
||||
|
||||
<string name="translateText">Translate GitNex with Crowdin</string>
|
||||
@ -542,4 +543,8 @@
|
||||
<string name="mergePRSuccessMsg">Pull Request was merged successfully</string>
|
||||
<string name="mergePR404ErrorMsg">Pull Request is not available for merge</string>
|
||||
|
||||
<string name="settingsCustomFontHeaderText">Font</string>
|
||||
<string name="settingsCustomFontSelectorDialogTitle">Choose Font</string>
|
||||
<string name="settingsCustomFontDefault">Roboto</string>
|
||||
|
||||
</resources>
|
||||
|
@ -4,9 +4,9 @@
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
<item name="android:fontFamily">@font/roboto</item>
|
||||
<item name="drawerArrowStyle">@style/DrawerIcon</item>
|
||||
<item name="colorControlHighlight">#123456</item>
|
||||
<item name="android:typeface">monospace</item>
|
||||
</style>
|
||||
|
||||
<style name="DrawerIcon" parent="Widget.AppCompat.DrawerArrowToggle">
|
||||
|
Loading…
x
Reference in New Issue
Block a user