added theme selection to settings, updated login layout.

This commit is contained in:
M M Arif
2020-03-06 01:56:42 +05:00
parent b012a7058d
commit 14addf5ed0
12 changed files with 196 additions and 80 deletions

View File

@@ -15,13 +15,21 @@ public abstract class BaseActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppThemeLight);
final TinyDB tinyDb = new TinyDB(getApplicationContext());
if(tinyDb.getInt("themeId") == 0) {
setTheme(R.style.AppTheme);
}
else if(tinyDb.getInt("themeId") == 1) {
setTheme(R.style.AppThemeLight);
}
else {
setTheme(R.style.AppTheme);
}
super.onCreate(savedInstanceState);
setContentView(getLayoutResourceId());
final TinyDB tinyDb = new TinyDB(getApplicationContext());
if(tinyDb.getInt("customFontId") == 0) {
FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/roboto.ttf");

View File

@@ -104,6 +104,7 @@ public class ReposListAdapter extends RecyclerView.Adapter<ReposListAdapter.Repo
fMenuHelper.setAccessible(true);
menuHelper = fMenuHelper.get(popupMenu);
argTypes = new Class[] { boolean.class };
assert menuHelper != null;
menuHelper.getClass().getDeclaredMethod("setForceShowIcon",
argTypes).invoke(menuHelper, true);

View File

@@ -44,6 +44,9 @@ public class SettingsFragment extends Fragment {
private static String[] customFontList = {"Roboto", "Manrope", "Source Code Pro"};
private static int customFontSelectedChoice = 0;
private static String[] themeList = {"Dark", "Light"};
private static int themeSelectedChoice = 0;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@@ -56,12 +59,14 @@ public class SettingsFragment extends Fragment {
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
final TextView themeSelected = v.findViewById(R.id.themeSelected); // setter for theme
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);
LinearLayout themeFrame = v.findViewById(R.id.themeSelectionFrame);
Switch issuesSwitch = v.findViewById(R.id.switchIssuesBadge);
TextView helpTranslate = v.findViewById(R.id.helpTranslate);
@@ -96,6 +101,10 @@ public class SettingsFragment extends Fragment {
customFontSelected.setText(tinyDb.getString("customFontStr"));
}
if(!tinyDb.getString("themeStr").isEmpty()) {
themeSelected.setText(tinyDb.getString("themeStr"));
}
if(langSelectedChoice == 0) {
langSelectedChoice = tinyDb.getInt("langId");
}
@@ -116,6 +125,10 @@ public class SettingsFragment extends Fragment {
customFontSelectedChoice = tinyDb.getInt("customFontId");
}
if(themeSelectedChoice == 0) {
themeSelectedChoice = tinyDb.getInt("themeId");
}
if(tinyDb.getBoolean("enableCounterIssueBadge")) {
issuesSwitch.setChecked(true);
}
@@ -135,6 +148,44 @@ public class SettingsFragment extends Fragment {
}
});
// theme selection dialog
themeFrame.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder tsBuilder = new AlertDialog.Builder(ctx);
tsBuilder.setTitle(R.string.themeSelectorDialogTitle);
if(themeSelectedChoice != -1) {
tsBuilder.setCancelable(true);
}
else {
tsBuilder.setCancelable(false);
}
tsBuilder.setSingleChoiceItems(themeList, themeSelectedChoice, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterfaceTheme, int i) {
themeSelectedChoice = i;
themeSelected.setText(themeList[i]);
tinyDb.putString("themeStr", themeList[i]);
tinyDb.putInt("themeId", i);
Objects.requireNonNull(getActivity()).recreate();
getActivity().overridePendingTransition(0, 0);
dialogInterfaceTheme.dismiss();
Toasty.info(getContext(), getResources().getString(R.string.settingsSave));
}
});
AlertDialog cfDialog = tsBuilder.create();
cfDialog.show();
}
});
// custom font dialog
customFontFrame.setOnClickListener(new View.OnClickListener() {
@Override