Split settings screen into different sections (#457)
add reports section Add translation, fix change lang bug not taking affect Add security section Add file viewer section Change settings screen into different sections Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/457 Reviewed-by: 6543 <6543@noreply.gitea.io>
This commit is contained in:
		| @@ -50,6 +50,9 @@ public abstract class BaseActivity extends AppCompatActivity { | ||||
| 			setTheme(R.style.AppTheme); | ||||
| 		} | ||||
|  | ||||
| 		String appLocale = tinyDb.getString("locale"); | ||||
| 		AppUtil.setAppLocale(getResources(), appLocale); | ||||
|  | ||||
| 		super.onCreate(savedInstanceState); | ||||
| 		setContentView(getLayoutResourceId()); | ||||
|  | ||||
|   | ||||
| @@ -97,9 +97,6 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig | ||||
| 			tinyDb.putInt("homeScreenId", 0); | ||||
| 		} | ||||
|  | ||||
| 		String appLocale = tinyDb.getString("locale"); | ||||
| 		AppUtil.setAppLocale(getResources(), appLocale); | ||||
|  | ||||
| 		boolean connToInternet = AppUtil.haveNetworkConnection(getApplicationContext()); | ||||
|  | ||||
| 		if(!tinyDb.getBoolean("loggedInMode")) { | ||||
|   | ||||
| @@ -0,0 +1,327 @@ | ||||
| package org.mian.gitnex.activities; | ||||
|  | ||||
| import android.content.Context; | ||||
| import android.os.Bundle; | ||||
| import android.view.View; | ||||
| import android.widget.ImageView; | ||||
| import android.widget.LinearLayout; | ||||
| import android.widget.Switch; | ||||
| import android.widget.TextView; | ||||
| import androidx.appcompat.app.AlertDialog; | ||||
| import org.mian.gitnex.R; | ||||
| import org.mian.gitnex.helpers.Toasty; | ||||
| import org.mian.gitnex.util.TinyDB; | ||||
|  | ||||
| /** | ||||
|  * Author M M Arif | ||||
|  */ | ||||
|  | ||||
| public class SettingsAppearanceActivity extends BaseActivity { | ||||
|  | ||||
| 	private Context ctx; | ||||
| 	private View.OnClickListener onClickListener; | ||||
|  | ||||
| 	private static String[] timeList = {"Pretty", "Normal"}; | ||||
| 	private static int timeSelectedChoice = 0; | ||||
|  | ||||
| 	private static String[] codeBlockList = {"Green - Black", "White - Black", "Grey - Black", "White - Grey", "Dark - White"}; | ||||
| 	private static int codeBlockSelectedChoice = 0; | ||||
|  | ||||
| 	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; | ||||
|  | ||||
| 	private static String[] themeList = {"Dark", "Light", "Auto (Day/Night)"}; | ||||
| 	private static int themeSelectedChoice = 0; | ||||
|  | ||||
| 	@Override | ||||
| 	protected int getLayoutResourceId() { | ||||
|  | ||||
| 		return R.layout.activity_settings_appearance; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void onCreate(Bundle savedInstanceState) { | ||||
|  | ||||
| 		super.onCreate(savedInstanceState); | ||||
| 		this.ctx = getApplicationContext(); | ||||
| 		final TinyDB tinyDb = new TinyDB(ctx); | ||||
|  | ||||
| 		ImageView closeActivity = findViewById(R.id.close); | ||||
|  | ||||
| 		final TextView tvDateTimeSelected = findViewById(R.id.tvDateTimeSelected); // setter for time | ||||
| 		final TextView codeBlockSelected = findViewById(R.id.codeBlockSelected); // setter for code block | ||||
| 		final TextView homeScreenSelected = findViewById(R.id.homeScreenSelected); // setter for home screen | ||||
| 		final TextView customFontSelected = findViewById(R.id.customFontSelected); // setter for custom font | ||||
| 		final TextView themeSelected = findViewById(R.id.themeSelected); // setter for theme | ||||
|  | ||||
| 		LinearLayout timeFrame = findViewById(R.id.timeFrame); | ||||
| 		LinearLayout codeBlockFrame = findViewById(R.id.codeBlockFrame); | ||||
| 		LinearLayout homeScreenFrame = findViewById(R.id.homeScreenFrame); | ||||
| 		LinearLayout customFontFrame = findViewById(R.id.customFontFrame); | ||||
| 		LinearLayout themeFrame = findViewById(R.id.themeSelectionFrame); | ||||
|  | ||||
| 		Switch counterBadgesSwitch = findViewById(R.id.switchCounterBadge); | ||||
|  | ||||
| 		initCloseListener(); | ||||
| 		closeActivity.setOnClickListener(onClickListener); | ||||
|  | ||||
| 		if(!tinyDb.getString("timeStr").isEmpty()) { | ||||
| 			tvDateTimeSelected.setText(tinyDb.getString("timeStr")); | ||||
| 		} | ||||
|  | ||||
| 		if(!tinyDb.getString("codeBlockStr").isEmpty()) { | ||||
| 			codeBlockSelected.setText(tinyDb.getString("codeBlockStr")); | ||||
| 		} | ||||
|  | ||||
| 		if(!tinyDb.getString("homeScreenStr").isEmpty()) { | ||||
| 			homeScreenSelected.setText(tinyDb.getString("homeScreenStr")); | ||||
| 		} | ||||
|  | ||||
| 		if(!tinyDb.getString("customFontStr").isEmpty()) { | ||||
| 			customFontSelected.setText(tinyDb.getString("customFontStr")); | ||||
| 		} | ||||
|  | ||||
| 		if(!tinyDb.getString("themeStr").isEmpty()) { | ||||
| 			themeSelected.setText(tinyDb.getString("themeStr")); | ||||
| 		} | ||||
|  | ||||
| 		if(timeSelectedChoice == 0) { | ||||
| 			timeSelectedChoice = tinyDb.getInt("timeId"); | ||||
| 		} | ||||
|  | ||||
| 		if(codeBlockSelectedChoice == 0) { | ||||
| 			codeBlockSelectedChoice = tinyDb.getInt("codeBlockId"); | ||||
| 		} | ||||
|  | ||||
| 		if(homeScreenSelectedChoice == 0) { | ||||
| 			homeScreenSelectedChoice = tinyDb.getInt("homeScreenId"); | ||||
| 		} | ||||
|  | ||||
| 		if(customFontSelectedChoice == 0) { | ||||
| 			customFontSelectedChoice = tinyDb.getInt("customFontId", 1); | ||||
| 		} | ||||
|  | ||||
| 		if(themeSelectedChoice == 0) { | ||||
| 			themeSelectedChoice = tinyDb.getInt("themeId"); | ||||
| 		} | ||||
|  | ||||
| 		if(tinyDb.getBoolean("enableCounterBadges")) { | ||||
| 			counterBadgesSwitch.setChecked(true); | ||||
| 		} | ||||
| 		else { | ||||
| 			counterBadgesSwitch.setChecked(false); | ||||
| 		} | ||||
|  | ||||
| 		// counter badge switcher | ||||
| 		counterBadgesSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { | ||||
|  | ||||
| 			if (isChecked) { | ||||
| 				tinyDb.putBoolean("enableCounterBadges", true); | ||||
| 				Toasty.info(ctx, getResources().getString(R.string.settingsSave)); | ||||
| 			} | ||||
| 			else { | ||||
| 				tinyDb.putBoolean("enableCounterBadges", false); | ||||
| 				Toasty.info(ctx, getResources().getString(R.string.settingsSave)); | ||||
| 			} | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 		// theme selection dialog | ||||
| 		themeFrame.setOnClickListener(view -> { | ||||
|  | ||||
| 			AlertDialog.Builder tsBuilder = new AlertDialog.Builder(SettingsAppearanceActivity.this); | ||||
|  | ||||
| 			tsBuilder.setTitle(getResources().getString(R.string.themeSelectorDialogTitle)); | ||||
| 			if(themeSelectedChoice != -1) { | ||||
| 				tsBuilder.setCancelable(true); | ||||
| 			} | ||||
| 			else { | ||||
| 				tsBuilder.setCancelable(false); | ||||
| 			} | ||||
|  | ||||
| 			tsBuilder.setSingleChoiceItems(themeList, themeSelectedChoice, (dialogInterfaceTheme, i) -> { | ||||
|  | ||||
| 				themeSelectedChoice = i; | ||||
| 				themeSelected.setText(themeList[i]); | ||||
| 				tinyDb.putString("themeStr", themeList[i]); | ||||
| 				tinyDb.putInt("themeId", i); | ||||
|  | ||||
| 				tinyDb.putBoolean("refreshParent", true); | ||||
| 				this.recreate(); | ||||
| 				this.overridePendingTransition(0, 0); | ||||
| 				dialogInterfaceTheme.dismiss(); | ||||
| 				Toasty.info(ctx, getResources().getString(R.string.settingsSave)); | ||||
|  | ||||
| 			}); | ||||
|  | ||||
| 			AlertDialog cfDialog = tsBuilder.create(); | ||||
| 			cfDialog.show(); | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 		// custom font dialog | ||||
| 		customFontFrame.setOnClickListener(view -> { | ||||
|  | ||||
| 			AlertDialog.Builder cfBuilder = new AlertDialog.Builder(SettingsAppearanceActivity.this); | ||||
|  | ||||
| 			cfBuilder.setTitle(R.string.settingsCustomFontSelectorDialogTitle); | ||||
| 			if(customFontSelectedChoice != -1) { | ||||
| 				cfBuilder.setCancelable(true); | ||||
| 			} | ||||
| 			else { | ||||
| 				cfBuilder.setCancelable(false); | ||||
| 			} | ||||
|  | ||||
| 			cfBuilder.setSingleChoiceItems(customFontList, customFontSelectedChoice, (dialogInterfaceCustomFont, i) -> { | ||||
|  | ||||
| 				customFontSelectedChoice = i; | ||||
| 				customFontSelected.setText(customFontList[i]); | ||||
| 				tinyDb.putString("customFontStr", customFontList[i]); | ||||
| 				tinyDb.putInt("customFontId", i); | ||||
|  | ||||
| 				tinyDb.putBoolean("refreshParent", true); | ||||
| 				this.recreate(); | ||||
| 				this.overridePendingTransition(0, 0); | ||||
| 				dialogInterfaceCustomFont.dismiss(); | ||||
| 				Toasty.info(ctx, ctx.getResources().getString(R.string.settingsSave)); | ||||
|  | ||||
| 			}); | ||||
|  | ||||
| 			AlertDialog cfDialog = cfBuilder.create(); | ||||
| 			cfDialog.show(); | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 		// home screen dialog | ||||
| 		homeScreenFrame.setOnClickListener(view -> { | ||||
|  | ||||
| 			AlertDialog.Builder hsBuilder = new AlertDialog.Builder(SettingsAppearanceActivity.this); | ||||
|  | ||||
| 			hsBuilder.setTitle(R.string.settingshomeScreenSelectorDialogTitle); | ||||
| 			if(homeScreenSelectedChoice != -1) { | ||||
| 				hsBuilder.setCancelable(true); | ||||
| 			} | ||||
| 			else { | ||||
| 				hsBuilder.setCancelable(false); | ||||
| 			} | ||||
|  | ||||
| 			hsBuilder.setSingleChoiceItems(homeScreenList, homeScreenSelectedChoice, (dialogInterfaceHomeScreen, i) -> { | ||||
|  | ||||
| 				homeScreenSelectedChoice = i; | ||||
| 				homeScreenSelected.setText(homeScreenList[i]); | ||||
| 				tinyDb.putString("homeScreenStr", homeScreenList[i]); | ||||
| 				tinyDb.putInt("homeScreenId", i); | ||||
|  | ||||
| 				dialogInterfaceHomeScreen.dismiss(); | ||||
| 				Toasty.info(ctx, getResources().getString(R.string.settingsSave)); | ||||
|  | ||||
| 			}); | ||||
|  | ||||
| 			AlertDialog hsDialog = hsBuilder.create(); | ||||
| 			hsDialog.show(); | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 		// code block dialog | ||||
| 		codeBlockFrame.setOnClickListener(view -> { | ||||
|  | ||||
| 			AlertDialog.Builder cBuilder = new AlertDialog.Builder(SettingsAppearanceActivity.this); | ||||
|  | ||||
| 			cBuilder.setTitle(R.string.settingsCodeBlockSelectorDialogTitle); | ||||
| 			if(codeBlockSelectedChoice != -1) { | ||||
| 				cBuilder.setCancelable(true); | ||||
| 			} | ||||
| 			else { | ||||
| 				cBuilder.setCancelable(false); | ||||
| 			} | ||||
|  | ||||
| 			cBuilder.setSingleChoiceItems(codeBlockList, codeBlockSelectedChoice, (dialogInterfaceCodeBlock, i) -> { | ||||
|  | ||||
| 				codeBlockSelectedChoice = i; | ||||
| 				codeBlockSelected.setText(codeBlockList[i]); | ||||
| 				tinyDb.putString("codeBlockStr", codeBlockList[i]); | ||||
| 				tinyDb.putInt("codeBlockId", i); | ||||
|  | ||||
| 				switch(codeBlockList[i]) { | ||||
| 					case "White - Black": | ||||
| 						tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.white)); | ||||
| 						tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.black)); | ||||
| 						break; | ||||
| 					case "Grey - Black": | ||||
| 						tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.colorAccent)); | ||||
| 						tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.black)); | ||||
| 						break; | ||||
| 					case "White - Grey": | ||||
| 						tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.white)); | ||||
| 						tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.colorAccent)); | ||||
| 						break; | ||||
| 					case "Dark - White": | ||||
| 						tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.colorPrimary)); | ||||
| 						tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.white)); | ||||
| 						break; | ||||
| 					default: | ||||
| 						tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.colorLightGreen)); | ||||
| 						tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.black)); | ||||
| 						break; | ||||
| 				} | ||||
|  | ||||
| 				dialogInterfaceCodeBlock.dismiss(); | ||||
| 				Toasty.info(ctx, getResources().getString(R.string.settingsSave)); | ||||
|  | ||||
| 			}); | ||||
|  | ||||
| 			AlertDialog cDialog = cBuilder.create(); | ||||
| 			cDialog.show(); | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 		// time and date dialog | ||||
| 		timeFrame.setOnClickListener(view -> { | ||||
|  | ||||
| 			AlertDialog.Builder tBuilder = new AlertDialog.Builder(SettingsAppearanceActivity.this); | ||||
|  | ||||
| 			tBuilder.setTitle(R.string.settingsTimeSelectorDialogTitle); | ||||
| 			if(timeSelectedChoice != -1) { | ||||
| 				tBuilder.setCancelable(true); | ||||
| 			} | ||||
| 			else { | ||||
| 				tBuilder.setCancelable(false); | ||||
| 			} | ||||
|  | ||||
| 			tBuilder.setSingleChoiceItems(timeList, timeSelectedChoice, (dialogInterfaceTime, i) -> { | ||||
|  | ||||
| 				timeSelectedChoice = i; | ||||
| 				tvDateTimeSelected.setText(timeList[i]); | ||||
| 				tinyDb.putString("timeStr", timeList[i]); | ||||
| 				tinyDb.putInt("timeId", i); | ||||
|  | ||||
| 				if("Normal".equals(timeList[i])) { | ||||
| 					tinyDb.putString("dateFormat", "normal"); | ||||
| 				} | ||||
| 				else { | ||||
| 					tinyDb.putString("dateFormat", "pretty"); | ||||
| 				} | ||||
|  | ||||
| 				dialogInterfaceTime.dismiss(); | ||||
| 				Toasty.info(ctx, getResources().getString(R.string.settingsSave)); | ||||
|  | ||||
| 			}); | ||||
|  | ||||
| 			AlertDialog tDialog = tBuilder.create(); | ||||
| 			tDialog.show(); | ||||
|  | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	private void initCloseListener() { | ||||
| 		onClickListener = view -> { | ||||
| 			finish(); | ||||
| 		}; | ||||
| 	} | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,120 @@ | ||||
| package org.mian.gitnex.activities; | ||||
|  | ||||
| import android.content.Context; | ||||
| import android.os.Bundle; | ||||
| import android.view.View; | ||||
| import android.widget.ImageView; | ||||
| import android.widget.LinearLayout; | ||||
| import android.widget.Switch; | ||||
| import android.widget.TextView; | ||||
| import androidx.appcompat.app.AlertDialog; | ||||
| import org.mian.gitnex.R; | ||||
| import org.mian.gitnex.helpers.Toasty; | ||||
| import org.mian.gitnex.util.TinyDB; | ||||
|  | ||||
| /** | ||||
|  * Author M M Arif | ||||
|  */ | ||||
|  | ||||
| public class SettingsFileViewerActivity extends BaseActivity { | ||||
|  | ||||
| 	private Context ctx; | ||||
| 	private View.OnClickListener onClickListener; | ||||
|  | ||||
| 	private static String[] fileveiwerSourceCodeThemesList = {"Sublime", "Arduino Light", "Github", "Far ", "Ir Black", "Android Studio"}; | ||||
| 	private static int fileveiwerSourceCodeThemesSelectedChoice = 0; | ||||
|  | ||||
| 	@Override | ||||
| 	protected int getLayoutResourceId() { | ||||
|  | ||||
| 		return R.layout.activity_settings_fileview; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void onCreate(Bundle savedInstanceState) { | ||||
|  | ||||
| 		super.onCreate(savedInstanceState); | ||||
| 		this.ctx = getApplicationContext(); | ||||
| 		final TinyDB tinyDb = new TinyDB(ctx); | ||||
|  | ||||
| 		ImageView closeActivity = findViewById(R.id.close); | ||||
|  | ||||
| 		initCloseListener(); | ||||
| 		closeActivity.setOnClickListener(onClickListener); | ||||
|  | ||||
| 		final TextView fileveiwerSourceCodeThemesSelected = findViewById(R.id.sourceCodeThemeSelected); // setter for fileviewer theme | ||||
|  | ||||
| 		LinearLayout sourceCodeThemeFrame = findViewById(R.id.sourceCodeThemeFrame); | ||||
|  | ||||
| 		Switch pdfModeSwitch = findViewById(R.id.switchPdfMode); | ||||
|  | ||||
| 		if(!tinyDb.getString("fileviewerSourceCodeThemeStr").isEmpty()) { | ||||
| 			fileveiwerSourceCodeThemesSelected.setText(tinyDb.getString("fileviewerSourceCodeThemeStr")); | ||||
| 		} | ||||
|  | ||||
| 		if(fileveiwerSourceCodeThemesSelectedChoice == 0) { | ||||
| 			fileveiwerSourceCodeThemesSelectedChoice = tinyDb.getInt("fileviewerThemeId"); | ||||
| 		} | ||||
|  | ||||
| 		if(tinyDb.getBoolean("enablePdfMode")) { | ||||
| 			pdfModeSwitch.setChecked(true); | ||||
| 		} | ||||
| 		else { | ||||
| 			pdfModeSwitch.setChecked(false); | ||||
| 		} | ||||
|  | ||||
| 		// fileviewer srouce code theme selection dialog | ||||
| 		sourceCodeThemeFrame.setOnClickListener(view -> { | ||||
|  | ||||
| 			AlertDialog.Builder fvtsBuilder = new AlertDialog.Builder(SettingsFileViewerActivity.this); | ||||
|  | ||||
| 			fvtsBuilder.setTitle(R.string.fileviewerSourceCodeThemeSelectorDialogTitle); | ||||
| 			if(fileveiwerSourceCodeThemesSelectedChoice != -1) { | ||||
| 				fvtsBuilder.setCancelable(true); | ||||
| 			} | ||||
| 			else { | ||||
| 				fvtsBuilder.setCancelable(false); | ||||
| 			} | ||||
|  | ||||
| 			fvtsBuilder.setSingleChoiceItems(fileveiwerSourceCodeThemesList, fileveiwerSourceCodeThemesSelectedChoice, (dialogInterfaceTheme, i) -> { | ||||
|  | ||||
| 				fileveiwerSourceCodeThemesSelectedChoice = i; | ||||
| 				fileveiwerSourceCodeThemesSelected.setText(fileveiwerSourceCodeThemesList[i]); | ||||
| 				tinyDb.putString("fileviewerSourceCodeThemeStr", fileveiwerSourceCodeThemesList[i]); | ||||
| 				tinyDb.putInt("fileviewerSourceCodeThemeId", i); | ||||
|  | ||||
| 				dialogInterfaceTheme.dismiss(); | ||||
| 				Toasty.info(ctx, getResources().getString(R.string.settingsSave)); | ||||
|  | ||||
| 			}); | ||||
|  | ||||
| 			AlertDialog cfDialog = fvtsBuilder.create(); | ||||
| 			cfDialog.show(); | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 		// pdf night mode switcher | ||||
| 		pdfModeSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { | ||||
|  | ||||
| 			if(isChecked) { | ||||
| 				tinyDb.putBoolean("enablePdfMode", true); | ||||
| 				tinyDb.putString("enablePdfModeInit", "yes"); | ||||
| 				Toasty.info(ctx, getResources().getString(R.string.settingsSave)); | ||||
| 			} | ||||
| 			else { | ||||
| 				tinyDb.putBoolean("enablePdfMode", false); | ||||
| 				tinyDb.putString("enablePdfModeInit", "yes"); | ||||
| 				Toasty.info(ctx, getResources().getString(R.string.settingsSave)); | ||||
| 			} | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	private void initCloseListener() { | ||||
| 		onClickListener = view -> { | ||||
| 			finish(); | ||||
| 		}; | ||||
| 	} | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,70 @@ | ||||
| package org.mian.gitnex.activities; | ||||
|  | ||||
| import android.content.Context; | ||||
| import android.os.Bundle; | ||||
| import android.view.View; | ||||
| import android.widget.ImageView; | ||||
| import android.widget.Switch; | ||||
| import org.mian.gitnex.R; | ||||
| import org.mian.gitnex.helpers.Toasty; | ||||
| import org.mian.gitnex.util.TinyDB; | ||||
|  | ||||
| /** | ||||
|  * Author M M Arif | ||||
|  */ | ||||
|  | ||||
| public class SettingsReportsActivity extends BaseActivity { | ||||
|  | ||||
| 	private Context ctx; | ||||
| 	private View.OnClickListener onClickListener; | ||||
|  | ||||
| 	@Override | ||||
| 	protected int getLayoutResourceId() { | ||||
|  | ||||
| 		return R.layout.activity_settings_reporting; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void onCreate(Bundle savedInstanceState) { | ||||
|  | ||||
| 		super.onCreate(savedInstanceState); | ||||
| 		this.ctx = getApplicationContext(); | ||||
| 		TinyDB tinyDb = new TinyDB(ctx); | ||||
|  | ||||
| 		ImageView closeActivity = findViewById(R.id.close); | ||||
|  | ||||
| 		initCloseListener(); | ||||
| 		closeActivity.setOnClickListener(onClickListener); | ||||
|  | ||||
| 		Switch crashReportsSwitch = findViewById(R.id.crashReportsSwitch); | ||||
|  | ||||
| 		if(tinyDb.getBoolean("crashReportingEnabled")) { | ||||
| 			crashReportsSwitch.setChecked(true); | ||||
| 		} | ||||
| 		else { | ||||
| 			crashReportsSwitch.setChecked(false); | ||||
| 		} | ||||
|  | ||||
| 		// crash reports switcher | ||||
| 		crashReportsSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { | ||||
|  | ||||
| 			if(isChecked) { | ||||
| 				tinyDb.putBoolean("crashReportingEnabled", true); | ||||
| 				Toasty.info(ctx, getResources().getString(R.string.settingsSave)); | ||||
| 			} | ||||
| 			else { | ||||
| 				tinyDb.putBoolean("crashReportingEnabled", false); | ||||
| 				Toasty.info(ctx, getResources().getString(R.string.settingsSave)); | ||||
| 			} | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	private void initCloseListener() { | ||||
| 		onClickListener = view -> { | ||||
| 			finish(); | ||||
| 		}; | ||||
| 	} | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,78 @@ | ||||
| package org.mian.gitnex.activities; | ||||
|  | ||||
| import android.content.Context; | ||||
| import android.content.Intent; | ||||
| import android.os.Bundle; | ||||
| import android.view.View; | ||||
| import android.widget.ImageView; | ||||
| import android.widget.LinearLayout; | ||||
| import androidx.appcompat.app.AlertDialog; | ||||
| import org.mian.gitnex.R; | ||||
| import org.mian.gitnex.helpers.ssl.MemorizingTrustManager; | ||||
| import org.mian.gitnex.util.TinyDB; | ||||
|  | ||||
| /** | ||||
|  * Author M M Arif | ||||
|  */ | ||||
|  | ||||
| public class SettingsSecurityActivity extends BaseActivity { | ||||
|  | ||||
| 	private Context ctx; | ||||
| 	private View.OnClickListener onClickListener; | ||||
|  | ||||
| 	@Override | ||||
| 	protected int getLayoutResourceId() { | ||||
|  | ||||
| 		return R.layout.activity_settings_security; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void onCreate(Bundle savedInstanceState) { | ||||
|  | ||||
| 		super.onCreate(savedInstanceState); | ||||
| 		this.ctx = getApplicationContext(); | ||||
| 		TinyDB tinyDb = new TinyDB(ctx); | ||||
|  | ||||
| 		ImageView closeActivity = findViewById(R.id.close); | ||||
|  | ||||
| 		initCloseListener(); | ||||
| 		closeActivity.setOnClickListener(onClickListener); | ||||
|  | ||||
| 		LinearLayout certsFrame = findViewById(R.id.certsFrame); | ||||
|  | ||||
| 		// certs deletion | ||||
| 		certsFrame.setOnClickListener(v1 -> { | ||||
|  | ||||
| 			AlertDialog.Builder builder = new AlertDialog.Builder(SettingsSecurityActivity.this); | ||||
|  | ||||
| 			builder.setTitle(getResources().getString(R.string.settingsCertsPopupTitle)); | ||||
| 			builder.setMessage(getResources().getString(R.string.settingsCertsPopupMessage)); | ||||
| 			builder.setPositiveButton(R.string.menuDeleteText, (dialog, which) -> { | ||||
|  | ||||
| 				ctx.getSharedPreferences(MemorizingTrustManager.KEYSTORE_NAME, Context.MODE_PRIVATE).edit().remove(MemorizingTrustManager.KEYSTORE_KEY).apply(); | ||||
|  | ||||
| 				tinyDb.putBoolean("loggedInMode", false); | ||||
| 				tinyDb.remove("basicAuthPassword"); | ||||
| 				tinyDb.putBoolean("basicAuthFlag", false); | ||||
| 				//tinyDb.clear(); | ||||
|  | ||||
| 				Intent loginActivityIntent = new Intent().setClass(ctx, LoginActivity.class); | ||||
| 				loginActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||||
| 				ctx.startActivity(loginActivityIntent); | ||||
|  | ||||
| 			}); | ||||
|  | ||||
| 			builder.setNeutralButton(R.string.cancelButton, (dialog, which) -> dialog.dismiss()); | ||||
| 			builder.create().show(); | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	private void initCloseListener() { | ||||
| 		onClickListener = view -> { | ||||
| 			finish(); | ||||
| 		}; | ||||
| 	} | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,164 @@ | ||||
| package org.mian.gitnex.activities; | ||||
|  | ||||
| import android.content.Context; | ||||
| import android.content.Intent; | ||||
| import android.net.Uri; | ||||
| import android.os.Bundle; | ||||
| import android.view.View; | ||||
| import android.widget.ImageView; | ||||
| import android.widget.LinearLayout; | ||||
| import android.widget.TextView; | ||||
| import androidx.appcompat.app.AlertDialog; | ||||
| import org.mian.gitnex.R; | ||||
| import org.mian.gitnex.helpers.Toasty; | ||||
| import org.mian.gitnex.util.TinyDB; | ||||
|  | ||||
| /** | ||||
|  * Author M M Arif | ||||
|  */ | ||||
|  | ||||
| public class SettingsTranslationActivity extends BaseActivity { | ||||
|  | ||||
| 	private Context ctx; | ||||
| 	private View.OnClickListener onClickListener; | ||||
|  | ||||
| 	private static String[] langList = {"English", "Arabic", "Chinese", "Finnish", "French", "German", "Italian", "Latvian", "Persian", "Polish", "Portuguese/Brazilian", "Russian", "Serbian", "Spanish", "Turkish", | ||||
| 			"Ukrainian"}; | ||||
| 	private static int langSelectedChoice = 0; | ||||
|  | ||||
| 	@Override | ||||
| 	protected int getLayoutResourceId() { | ||||
|  | ||||
| 		return R.layout.activity_settings_translation; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void onCreate(Bundle savedInstanceState) { | ||||
|  | ||||
| 		super.onCreate(savedInstanceState); | ||||
| 		this.ctx = getApplicationContext(); | ||||
| 		TinyDB tinyDb = new TinyDB(ctx); | ||||
|  | ||||
| 		ImageView closeActivity = findViewById(R.id.close); | ||||
|  | ||||
| 		initCloseListener(); | ||||
| 		closeActivity.setOnClickListener(onClickListener); | ||||
|  | ||||
| 		final TextView tvLanguageSelected = findViewById(R.id.tvLanguageSelected); // setter for en, fr | ||||
| 		TextView helpTranslate = findViewById(R.id.helpTranslate); | ||||
|  | ||||
| 		LinearLayout langFrame = findViewById(R.id.langFrame); | ||||
|  | ||||
| 		helpTranslate.setOnClickListener(v12 -> { | ||||
|  | ||||
| 			Intent intent = new Intent(); | ||||
| 			intent.setAction(Intent.ACTION_VIEW); | ||||
| 			intent.addCategory(Intent.CATEGORY_BROWSABLE); | ||||
| 			intent.setData(Uri.parse(getResources().getString(R.string.crowdInLink))); | ||||
| 			startActivity(intent); | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 		if(!tinyDb.getString("localeStr").isEmpty()) { | ||||
| 			tvLanguageSelected.setText(tinyDb.getString("localeStr")); | ||||
| 		} | ||||
|  | ||||
| 		if(langSelectedChoice == 0) { | ||||
| 			langSelectedChoice = tinyDb.getInt("langId"); | ||||
| 		} | ||||
|  | ||||
| 		// language dialog | ||||
| 		langFrame.setOnClickListener(view -> { | ||||
|  | ||||
| 			AlertDialog.Builder lBuilder = new AlertDialog.Builder(SettingsTranslationActivity.this); | ||||
|  | ||||
| 			lBuilder.setTitle(R.string.settingsLanguageSelectorDialogTitle); | ||||
| 			if(langSelectedChoice != -1) { | ||||
| 				lBuilder.setCancelable(true); | ||||
| 			} | ||||
| 			else { | ||||
| 				lBuilder.setCancelable(false); | ||||
| 			} | ||||
|  | ||||
| 			lBuilder.setSingleChoiceItems(langList, langSelectedChoice, (dialogInterface, i) -> { | ||||
|  | ||||
| 				langSelectedChoice = i; | ||||
| 				tvLanguageSelected.setText(langList[i]); | ||||
| 				tinyDb.putString("localeStr", langList[i]); | ||||
| 				tinyDb.putInt("langId", i); | ||||
|  | ||||
| 				switch(langList[i]) { | ||||
| 					case "Arabic": | ||||
| 						tinyDb.putString("locale", "ar"); | ||||
| 						break; | ||||
| 					case "Chinese": | ||||
| 						tinyDb.putString("locale", "zh"); | ||||
| 						break; | ||||
| 					case "Finnish": | ||||
| 						tinyDb.putString("locale", "fi"); | ||||
| 						break; | ||||
| 					case "French": | ||||
| 						tinyDb.putString("locale", "fr"); | ||||
| 						break; | ||||
| 					case "German": | ||||
| 						tinyDb.putString("locale", "de"); | ||||
| 						break; | ||||
| 					case "Italian": | ||||
| 						tinyDb.putString("locale", "it"); | ||||
| 						break; | ||||
| 					case "Latvian": | ||||
| 						tinyDb.putString("locale", "lv"); | ||||
| 						break; | ||||
| 					case "Persian": | ||||
| 						tinyDb.putString("locale", "fa"); | ||||
| 						break; | ||||
| 					case "Polish": | ||||
| 						tinyDb.putString("locale", "pl"); | ||||
| 						break; | ||||
| 					case "Portuguese/Brazilian": | ||||
| 						tinyDb.putString("locale", "pt"); | ||||
| 						break; | ||||
| 					case "Russian": | ||||
| 						tinyDb.putString("locale", "ru"); | ||||
| 						break; | ||||
| 					case "Serbian": | ||||
| 						tinyDb.putString("locale", "sr"); | ||||
| 						break; | ||||
| 					case "Spanish": | ||||
| 						tinyDb.putString("locale", "es"); | ||||
| 						break; | ||||
| 					case "Turkish": | ||||
| 						tinyDb.putString("locale", "tr"); | ||||
| 						break; | ||||
| 					case "Ukrainian": | ||||
| 						tinyDb.putString("locale", "uk"); | ||||
| 						break; | ||||
| 					default: | ||||
| 						tinyDb.putString("locale", "en"); | ||||
| 						break; | ||||
| 				} | ||||
|  | ||||
| 				tinyDb.putBoolean("refreshParent", true); | ||||
| 				this.recreate(); | ||||
| 				this.overridePendingTransition(0, 0); | ||||
| 				dialogInterface.dismiss(); | ||||
| 				Toasty.info(ctx, getResources().getString(R.string.settingsSave)); | ||||
|  | ||||
| 			}); | ||||
|  | ||||
| 			lBuilder.setNegativeButton(getString(R.string.cancelButton), (dialog, which) -> dialog.dismiss()); | ||||
|  | ||||
| 			AlertDialog lDialog = lBuilder.create(); | ||||
| 			lDialog.show(); | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	private void initCloseListener() { | ||||
| 		onClickListener = view -> { | ||||
| 			finish(); | ||||
| 		}; | ||||
| 	} | ||||
|  | ||||
| } | ||||
| @@ -1,23 +1,20 @@ | ||||
| package org.mian.gitnex.fragments; | ||||
|  | ||||
| import android.content.Context; | ||||
| import android.content.Intent; | ||||
| import android.net.Uri; | ||||
| import android.os.Bundle; | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.View; | ||||
| import android.view.ViewGroup; | ||||
| import android.widget.LinearLayout; | ||||
| import android.widget.Switch; | ||||
| import android.widget.TextView; | ||||
| import androidx.annotation.NonNull; | ||||
| import androidx.annotation.Nullable; | ||||
| import androidx.appcompat.app.AlertDialog; | ||||
| import androidx.fragment.app.Fragment; | ||||
| import org.mian.gitnex.R; | ||||
| import org.mian.gitnex.activities.MainActivity; | ||||
| import org.mian.gitnex.helpers.Toasty; | ||||
| import org.mian.gitnex.helpers.ssl.MemorizingTrustManager; | ||||
| import org.mian.gitnex.activities.SettingsAppearanceActivity; | ||||
| import org.mian.gitnex.activities.SettingsFileViewerActivity; | ||||
| import org.mian.gitnex.activities.SettingsReportsActivity; | ||||
| import org.mian.gitnex.activities.SettingsSecurityActivity; | ||||
| import org.mian.gitnex.activities.SettingsTranslationActivity; | ||||
| import org.mian.gitnex.util.TinyDB; | ||||
| import java.util.Objects; | ||||
|  | ||||
| @@ -27,518 +24,44 @@ import java.util.Objects; | ||||
|  | ||||
| public class SettingsFragment extends Fragment { | ||||
|  | ||||
| 	private Context ctx = null; | ||||
|  | ||||
| 	private static String[] langList = {"Arabic", "Chinese", "English", "Finnish", "French", "German", "Italian", "Latvian", "Persian", "Polish", "Portuguese/Brazilian", "Russian", "Serbian", "Spanish", "Turkish", "Ukrainian"}; | ||||
| 	private static int langSelectedChoice = 0; | ||||
|  | ||||
| 	private static String[] timeList = {"Pretty", "Normal"}; | ||||
| 	private static int timeSelectedChoice = 0; | ||||
|  | ||||
| 	private static String[] codeBlockList = {"Green - Black", "White - Black", "Grey - Black", "White - Grey", "Dark - White"}; | ||||
| 	private static int codeBlockSelectedChoice = 0; | ||||
|  | ||||
| 	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; | ||||
|  | ||||
| 	private static String[] themeList = {"Dark", "Light", "Auto (Day/Night)"}; | ||||
| 	private static int themeSelectedChoice = 0; | ||||
|  | ||||
| 	private static String[] fileveiwerSourceCodeThemesList = {"Sublime", "Arduino Light", "Github", "Far ", "Ir Black", "Android Studio"}; | ||||
| 	private static int fileveiwerSourceCodeThemesSelectedChoice = 0; | ||||
|  | ||||
| 	@Nullable | ||||
| 	@Override | ||||
| 	public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||||
|  | ||||
| 		View v = inflater.inflate(R.layout.fragment_settings, container, false); | ||||
| 		final TinyDB tinyDb = new TinyDB(getContext()); | ||||
|  | ||||
| 		final TextView tvLanguageSelected = v.findViewById(R.id.tvLanguageSelected); // setter for en, fr | ||||
| 		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 | ||||
| 		final TextView themeSelected = v.findViewById(R.id.themeSelected); // setter for theme | ||||
| 		final TextView fileveiwerSourceCodeThemesSelected = v.findViewById(R.id.sourceCodeThemeSelected); // setter for fileviewer theme | ||||
| 		LinearLayout appreanceFrame = v.findViewById(R.id.appreanceFrame); | ||||
| 		LinearLayout fileViewerFrame = v.findViewById(R.id.fileViewerFrame); | ||||
| 		LinearLayout securityFrame = v.findViewById(R.id.securityFrame); | ||||
| 		LinearLayout languagesFrame = v.findViewById(R.id.languagesFrame); | ||||
| 		LinearLayout reportsFrame = v.findViewById(R.id.reportsFrame); | ||||
|  | ||||
| 		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); | ||||
| 		LinearLayout certsFrame = v.findViewById(R.id.certsFrame); | ||||
| 		LinearLayout sourceCodeThemeFrame = v.findViewById(R.id.sourceCodeThemeFrame); | ||||
| 		appreanceFrame.setOnClickListener(v1 -> startActivity(new Intent(getContext(), SettingsAppearanceActivity.class))); | ||||
|  | ||||
| 		Switch counterBadgesSwitch = v.findViewById(R.id.switchCounterBadge); | ||||
| 		Switch pdfModeSwitch = v.findViewById(R.id.switchPdfMode); | ||||
| 		Switch crashReportsSwitch = v.findViewById(R.id.crashReportsSwitch); | ||||
| 		TextView helpTranslate = v.findViewById(R.id.helpTranslate); | ||||
| 		fileViewerFrame.setOnClickListener(v1 -> startActivity(new Intent(getContext(), SettingsFileViewerActivity.class))); | ||||
|  | ||||
| 		helpTranslate.setOnClickListener(v12 -> { | ||||
| 		securityFrame.setOnClickListener(v1 -> startActivity(new Intent(getContext(), SettingsSecurityActivity.class))); | ||||
|  | ||||
| 			Intent intent = new Intent(); | ||||
| 			intent.setAction(Intent.ACTION_VIEW); | ||||
| 			intent.addCategory(Intent.CATEGORY_BROWSABLE); | ||||
| 			intent.setData(Uri.parse(getResources().getString(R.string.crowdInLink))); | ||||
| 			startActivity(intent); | ||||
| 		languagesFrame.setOnClickListener(v1 -> startActivity(new Intent(getContext(), SettingsTranslationActivity.class))); | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 		if(!tinyDb.getString("localeStr").isEmpty()) { | ||||
| 			tvLanguageSelected.setText(tinyDb.getString("localeStr")); | ||||
| 		} | ||||
|  | ||||
| 		if(!tinyDb.getString("timeStr").isEmpty()) { | ||||
| 			tvDateTimeSelected.setText(tinyDb.getString("timeStr")); | ||||
| 		} | ||||
|  | ||||
| 		if(!tinyDb.getString("codeBlockStr").isEmpty()) { | ||||
| 			codeBlockSelected.setText(tinyDb.getString("codeBlockStr")); | ||||
| 		} | ||||
|  | ||||
| 		if(!tinyDb.getString("homeScreenStr").isEmpty()) { | ||||
| 			homeScreenSelected.setText(tinyDb.getString("homeScreenStr")); | ||||
| 		} | ||||
|  | ||||
|         if(!tinyDb.getString("customFontStr").isEmpty()) { | ||||
|             customFontSelected.setText(tinyDb.getString("customFontStr")); | ||||
|         } | ||||
|  | ||||
| 		if(!tinyDb.getString("themeStr").isEmpty()) { | ||||
| 			themeSelected.setText(tinyDb.getString("themeStr")); | ||||
| 		} | ||||
|  | ||||
| 		if(!tinyDb.getString("fileviewerSourceCodeThemeStr").isEmpty()) { | ||||
| 			fileveiwerSourceCodeThemesSelected.setText(tinyDb.getString("fileviewerSourceCodeThemeStr")); | ||||
| 		} | ||||
|  | ||||
| 		if(langSelectedChoice == 0) { | ||||
| 			langSelectedChoice = tinyDb.getInt("langId"); | ||||
| 		} | ||||
|  | ||||
| 		if(timeSelectedChoice == 0) { | ||||
| 			timeSelectedChoice = tinyDb.getInt("timeId"); | ||||
| 		} | ||||
|  | ||||
| 		if(codeBlockSelectedChoice == 0) { | ||||
| 			codeBlockSelectedChoice = tinyDb.getInt("codeBlockId"); | ||||
| 		} | ||||
|  | ||||
| 		if(homeScreenSelectedChoice == 0) { | ||||
| 			homeScreenSelectedChoice = tinyDb.getInt("homeScreenId"); | ||||
| 		} | ||||
|  | ||||
| 		if(customFontSelectedChoice == 0) { | ||||
| 			customFontSelectedChoice = tinyDb.getInt("customFontId", 1); | ||||
| 		} | ||||
|  | ||||
| 		if(themeSelectedChoice == 0) { | ||||
| 			themeSelectedChoice = tinyDb.getInt("themeId"); | ||||
| 		} | ||||
|  | ||||
| 		if(fileveiwerSourceCodeThemesSelectedChoice == 0) { | ||||
| 			fileveiwerSourceCodeThemesSelectedChoice = tinyDb.getInt("fileviewerThemeId"); | ||||
| 		} | ||||
|  | ||||
| 		if(tinyDb.getBoolean("enableCounterBadges")) { | ||||
| 			counterBadgesSwitch.setChecked(true); | ||||
| 		} | ||||
| 		else { | ||||
| 			counterBadgesSwitch.setChecked(false); | ||||
| 		} | ||||
|  | ||||
| 		if(tinyDb.getBoolean("enablePdfMode")) { | ||||
| 			pdfModeSwitch.setChecked(true); | ||||
| 		} | ||||
| 		else { | ||||
| 			pdfModeSwitch.setChecked(false); | ||||
| 		} | ||||
|  | ||||
| 		if(tinyDb.getBoolean("crashReportingEnabled")) { | ||||
| 			crashReportsSwitch.setChecked(true); | ||||
| 		} | ||||
| 		else { | ||||
| 			crashReportsSwitch.setChecked(false); | ||||
| 		} | ||||
|  | ||||
| 		// fileviewer srouce code theme selection dialog | ||||
| 		sourceCodeThemeFrame.setOnClickListener(view -> { | ||||
|  | ||||
| 			AlertDialog.Builder fvtsBuilder = new AlertDialog.Builder(ctx); | ||||
|  | ||||
| 			fvtsBuilder.setTitle(R.string.fileviewerSourceCodeThemeSelectorDialogTitle); | ||||
| 			if(fileveiwerSourceCodeThemesSelectedChoice != -1) { | ||||
| 				fvtsBuilder.setCancelable(true); | ||||
| 			} | ||||
| 			else { | ||||
| 				fvtsBuilder.setCancelable(false); | ||||
| 			} | ||||
|  | ||||
| 			fvtsBuilder.setSingleChoiceItems(fileveiwerSourceCodeThemesList, fileveiwerSourceCodeThemesSelectedChoice, (dialogInterfaceTheme, i) -> { | ||||
|  | ||||
| 				fileveiwerSourceCodeThemesSelectedChoice = i; | ||||
| 				fileveiwerSourceCodeThemesSelected.setText(fileveiwerSourceCodeThemesList[i]); | ||||
| 				tinyDb.putString("fileviewerSourceCodeThemeStr", fileveiwerSourceCodeThemesList[i]); | ||||
| 				tinyDb.putInt("fileviewerSourceCodeThemeId", i); | ||||
|  | ||||
| 				Objects.requireNonNull(getActivity()).recreate(); | ||||
| 				getActivity().overridePendingTransition(0, 0); | ||||
| 				dialogInterfaceTheme.dismiss(); | ||||
| 				Toasty.info(getContext(), getResources().getString(R.string.settingsSave)); | ||||
|  | ||||
| 			}); | ||||
|  | ||||
| 			AlertDialog cfDialog = fvtsBuilder.create(); | ||||
| 			cfDialog.show(); | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 		// certs deletion | ||||
| 		certsFrame.setOnClickListener(v1 -> { | ||||
|  | ||||
| 			AlertDialog.Builder builder = new AlertDialog.Builder(ctx); | ||||
| 			builder.setTitle(getResources().getString(R.string.settingsCertsPopupTitle)); | ||||
| 			builder.setMessage(getResources().getString(R.string.settingsCertsPopupMessage)); | ||||
| 			builder.setPositiveButton(R.string.menuDeleteText, (dialog, which) -> { | ||||
|  | ||||
| 				ctx.getSharedPreferences(MemorizingTrustManager.KEYSTORE_NAME, Context.MODE_PRIVATE).edit().remove(MemorizingTrustManager.KEYSTORE_KEY).apply(); | ||||
|  | ||||
| 				MainActivity.logout(Objects.requireNonNull(getActivity()), ctx); | ||||
|  | ||||
| 			}); | ||||
|  | ||||
| 			builder.setNeutralButton(R.string.cancelButton, (dialog, which) -> dialog.dismiss()); | ||||
| 			builder.create().show(); | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 		// counter badge switcher | ||||
| 		counterBadgesSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { | ||||
|  | ||||
|             if (isChecked) { | ||||
|                 tinyDb.putBoolean("enableCounterBadges", true); | ||||
|                 Toasty.info(getContext(), getResources().getString(R.string.settingsSave)); | ||||
|             } | ||||
|             else { | ||||
|                 tinyDb.putBoolean("enableCounterBadges", false); | ||||
|                 Toasty.info(getContext(), getResources().getString(R.string.settingsSave)); | ||||
|             } | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 		// pdf night mode switcher | ||||
| 		pdfModeSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { | ||||
|  | ||||
| 			if(isChecked) { | ||||
| 				tinyDb.putBoolean("enablePdfMode", true); | ||||
| 				tinyDb.putString("enablePdfModeInit", "yes"); | ||||
| 				Toasty.info(getContext(), getResources().getString(R.string.settingsSave)); | ||||
| 			} | ||||
| 			else { | ||||
| 				tinyDb.putBoolean("enablePdfMode", false); | ||||
| 				tinyDb.putString("enablePdfModeInit", "yes"); | ||||
| 				Toasty.info(getContext(), getResources().getString(R.string.settingsSave)); | ||||
| 			} | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 		// crash reports switcher | ||||
| 		crashReportsSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { | ||||
|  | ||||
| 			if(isChecked) { | ||||
| 				tinyDb.putBoolean("crashReportingEnabled", true); | ||||
| 				Toasty.info(getContext(), getResources().getString(R.string.settingsSave)); | ||||
| 			} | ||||
| 			else { | ||||
| 				tinyDb.putBoolean("crashReportingEnabled", false); | ||||
| 				Toasty.info(getContext(), getResources().getString(R.string.settingsSave)); | ||||
| 			} | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 		// theme selection dialog | ||||
| 		themeFrame.setOnClickListener(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, (dialogInterfaceTheme, 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(view -> { | ||||
|  | ||||
| 			AlertDialog.Builder cfBuilder = new AlertDialog.Builder(ctx); | ||||
|  | ||||
| 			cfBuilder.setTitle(R.string.settingsCustomFontSelectorDialogTitle); | ||||
| 			if(customFontSelectedChoice != -1) { | ||||
| 				cfBuilder.setCancelable(true); | ||||
| 			} | ||||
| 			else { | ||||
| 				cfBuilder.setCancelable(false); | ||||
| 			} | ||||
|  | ||||
| 			cfBuilder.setSingleChoiceItems(customFontList, customFontSelectedChoice, (dialogInterfaceCustomFont, 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(view -> { | ||||
|  | ||||
| 			AlertDialog.Builder hsBuilder = new AlertDialog.Builder(ctx); | ||||
|  | ||||
| 			hsBuilder.setTitle(R.string.settingshomeScreenSelectorDialogTitle); | ||||
| 			if(homeScreenSelectedChoice != -1) { | ||||
| 				hsBuilder.setCancelable(true); | ||||
| 			} | ||||
| 			else { | ||||
| 				hsBuilder.setCancelable(false); | ||||
| 			} | ||||
|  | ||||
| 			hsBuilder.setSingleChoiceItems(homeScreenList, homeScreenSelectedChoice, (dialogInterfaceHomeScreen, i) -> { | ||||
|  | ||||
| 				homeScreenSelectedChoice = i; | ||||
| 				homeScreenSelected.setText(homeScreenList[i]); | ||||
| 				tinyDb.putString("homeScreenStr", homeScreenList[i]); | ||||
| 				tinyDb.putInt("homeScreenId", i); | ||||
|  | ||||
| 				dialogInterfaceHomeScreen.dismiss(); | ||||
| 				Toasty.info(getContext(), getResources().getString(R.string.settingsSave)); | ||||
|  | ||||
| 			}); | ||||
|  | ||||
| 			AlertDialog hsDialog = hsBuilder.create(); | ||||
| 			hsDialog.show(); | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 		// code block dialog | ||||
| 		codeBlockFrame.setOnClickListener(view -> { | ||||
|  | ||||
| 			AlertDialog.Builder cBuilder = new AlertDialog.Builder(ctx); | ||||
|  | ||||
| 			cBuilder.setTitle(R.string.settingsCodeBlockSelectorDialogTitle); | ||||
| 			if(codeBlockSelectedChoice != -1) { | ||||
| 				cBuilder.setCancelable(true); | ||||
| 			} | ||||
| 			else { | ||||
| 				cBuilder.setCancelable(false); | ||||
| 			} | ||||
|  | ||||
| 			cBuilder.setSingleChoiceItems(codeBlockList, codeBlockSelectedChoice, (dialogInterfaceCodeBlock, i) -> { | ||||
|  | ||||
| 				codeBlockSelectedChoice = i; | ||||
| 				codeBlockSelected.setText(codeBlockList[i]); | ||||
| 				tinyDb.putString("codeBlockStr", codeBlockList[i]); | ||||
| 				tinyDb.putInt("codeBlockId", i); | ||||
|  | ||||
| 				switch(codeBlockList[i]) { | ||||
| 					case "White - Black": | ||||
| 						tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.white)); | ||||
| 						tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.black)); | ||||
| 						break; | ||||
| 					case "Grey - Black": | ||||
| 						tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.colorAccent)); | ||||
| 						tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.black)); | ||||
| 						break; | ||||
| 					case "White - Grey": | ||||
| 						tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.white)); | ||||
| 						tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.colorAccent)); | ||||
| 						break; | ||||
| 					case "Dark - White": | ||||
| 						tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.colorPrimary)); | ||||
| 						tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.white)); | ||||
| 						break; | ||||
| 					default: | ||||
| 						tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.colorLightGreen)); | ||||
| 						tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.black)); | ||||
| 						break; | ||||
| 				} | ||||
|  | ||||
| 				dialogInterfaceCodeBlock.dismiss(); | ||||
| 				Toasty.info(getContext(), getResources().getString(R.string.settingsSave)); | ||||
|  | ||||
| 			}); | ||||
|  | ||||
| 			AlertDialog cDialog = cBuilder.create(); | ||||
| 			cDialog.show(); | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 		// language dialog | ||||
| 		langFrame.setOnClickListener(view -> { | ||||
|  | ||||
| 			AlertDialog.Builder lBuilder = new AlertDialog.Builder(ctx); | ||||
|  | ||||
| 			lBuilder.setTitle(R.string.settingsLanguageSelectorDialogTitle); | ||||
| 			if(langSelectedChoice != -1) { | ||||
| 				lBuilder.setCancelable(true); | ||||
| 			} | ||||
| 			else { | ||||
| 				lBuilder.setCancelable(false); | ||||
| 			} | ||||
|  | ||||
| 			lBuilder.setSingleChoiceItems(langList, langSelectedChoice, (dialogInterface, i) -> { | ||||
|  | ||||
| 				langSelectedChoice = i; | ||||
| 				tvLanguageSelected.setText(langList[i]); | ||||
| 				tinyDb.putString("localeStr", langList[i]); | ||||
| 				tinyDb.putInt("langId", i); | ||||
|  | ||||
| 				switch(langList[i]) { | ||||
| 					case "Arabic": | ||||
| 						tinyDb.putString("locale", "ar"); | ||||
| 						break; | ||||
| 					case "Chinese": | ||||
| 						tinyDb.putString("locale", "zh"); | ||||
| 						break; | ||||
| 					case "Finnish": | ||||
| 						tinyDb.putString("locale", "fi"); | ||||
| 						break; | ||||
| 					case "French": | ||||
| 						tinyDb.putString("locale", "fr"); | ||||
| 						break; | ||||
| 					case "German": | ||||
| 						tinyDb.putString("locale", "de"); | ||||
| 						break; | ||||
| 					case "Italian": | ||||
| 						tinyDb.putString("locale", "it"); | ||||
| 						break; | ||||
| 					case "Latvian": | ||||
| 						tinyDb.putString("locale", "lv"); | ||||
| 						break; | ||||
| 					case "Persian": | ||||
| 						tinyDb.putString("locale", "fa"); | ||||
| 						break; | ||||
| 					case "Polish": | ||||
| 						tinyDb.putString("locale", "pl"); | ||||
| 						break; | ||||
| 					case "Portuguese/Brazilian": | ||||
| 						tinyDb.putString("locale", "pt"); | ||||
| 						break; | ||||
| 					case "Russian": | ||||
| 						tinyDb.putString("locale", "ru"); | ||||
| 						break; | ||||
| 					case "Serbian": | ||||
| 						tinyDb.putString("locale", "sr"); | ||||
| 						break; | ||||
| 					case "Spanish": | ||||
| 						tinyDb.putString("locale", "es"); | ||||
| 						break; | ||||
| 					case "Turkish": | ||||
| 						tinyDb.putString("locale", "tr"); | ||||
| 						break; | ||||
| 					case "Ukrainian": | ||||
| 						tinyDb.putString("locale", "uk"); | ||||
| 						break; | ||||
| 					default: | ||||
| 						tinyDb.putString("locale", "en"); | ||||
| 						break; | ||||
| 				} | ||||
|  | ||||
| 				dialogInterface.dismiss(); | ||||
| 				Toasty.info(getContext(), getResources().getString(R.string.settingsSave)); | ||||
| 				Objects.requireNonNull(getActivity()).recreate(); | ||||
| 				getActivity().overridePendingTransition(0, 0); | ||||
|  | ||||
| 			}); | ||||
|  | ||||
| 			lBuilder.setNegativeButton(getString(R.string.cancelButton), (dialog, which) -> dialog.dismiss()); | ||||
|  | ||||
| 			AlertDialog lDialog = lBuilder.create(); | ||||
| 			lDialog.show(); | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 		// time n date dialog | ||||
| 		timeFrame.setOnClickListener(view -> { | ||||
|  | ||||
| 			AlertDialog.Builder tBuilder = new AlertDialog.Builder(ctx); | ||||
|  | ||||
| 			tBuilder.setTitle(R.string.settingsTimeSelectorDialogTitle); | ||||
| 			if(timeSelectedChoice != -1) { | ||||
| 				tBuilder.setCancelable(true); | ||||
| 			} | ||||
| 			else { | ||||
| 				tBuilder.setCancelable(false); | ||||
| 			} | ||||
|  | ||||
| 			tBuilder.setSingleChoiceItems(timeList, timeSelectedChoice, (dialogInterfaceTime, i) -> { | ||||
|  | ||||
| 				timeSelectedChoice = i; | ||||
| 				tvDateTimeSelected.setText(timeList[i]); | ||||
| 				tinyDb.putString("timeStr", timeList[i]); | ||||
| 				tinyDb.putInt("timeId", i); | ||||
|  | ||||
| 				if("Normal".equals(timeList[i])) { | ||||
| 					tinyDb.putString("dateFormat", "normal"); | ||||
| 				} | ||||
| 				else { | ||||
| 					tinyDb.putString("dateFormat", "pretty"); | ||||
| 				} | ||||
|  | ||||
| 				dialogInterfaceTime.dismiss(); | ||||
| 				Toasty.info(getContext(), getResources().getString(R.string.settingsSave)); | ||||
|  | ||||
| 			}); | ||||
|  | ||||
| 			AlertDialog tDialog = tBuilder.create(); | ||||
| 			tDialog.show(); | ||||
|  | ||||
| 		}); | ||||
| 		reportsFrame.setOnClickListener(v1 -> startActivity(new Intent(getContext(), SettingsReportsActivity.class))); | ||||
|  | ||||
| 		return v; | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void onAttach(@NonNull Context context) { | ||||
| 	public void onResume() { | ||||
|  | ||||
| 		super.onAttach(context); | ||||
| 		ctx = context; | ||||
| 		super.onResume(); | ||||
|  | ||||
| 		TinyDB tinyDb = new TinyDB(getContext()); | ||||
|  | ||||
| 		if(tinyDb.getBoolean("refreshParent")) { | ||||
| 			Objects.requireNonNull(getActivity()).recreate(); | ||||
| 			getActivity().overridePendingTransition(0, 0); | ||||
| 			tinyDb.putBoolean("refreshParent", false); | ||||
| 		} | ||||
|  | ||||
| 	} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user