Implementation of custom fonts app wide

This commit is contained in:
M M Arif
2020-01-02 01:03:53 +05:00
parent e9dcfc57f7
commit 6d7308210b
22 changed files with 336 additions and 29 deletions

View File

@@ -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());

View File

@@ -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");

View File

@@ -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");

View File

@@ -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);

View File

@@ -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));

View File

@@ -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");

View File

@@ -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

View File

@@ -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");