mirror of
https://github.com/gitnex-org/gitnex.git
synced 2026-04-27 19:16:55 -05:00
Move code editor settings to db
This commit is contained in:
@@ -13,6 +13,7 @@ import java.util.Map;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.core.MainGrammarLocator;
|
||||
import org.mian.gitnex.databinding.ActivityCodeEditorBinding;
|
||||
import org.mian.gitnex.helpers.AppDatabaseSettings;
|
||||
import org.mian.gitnex.helpers.codeeditor.CustomCodeViewAdapter;
|
||||
import org.mian.gitnex.helpers.codeeditor.SourcePositionListener;
|
||||
import org.mian.gitnex.helpers.codeeditor.languages.Language;
|
||||
@@ -73,9 +74,14 @@ public class CodeEditorActivity extends BaseActivity {
|
||||
binding.codeView.setLineNumberTextSize(32f);
|
||||
|
||||
// Setup Auto indenting feature
|
||||
if (tinyDB.getInt("ceIndentationId") == 0) {
|
||||
if (Integer.parseInt(
|
||||
AppDatabaseSettings.getSettingsValue(
|
||||
ctx, AppDatabaseSettings.APP_CE_INDENTATION_KEY))
|
||||
== 0) {
|
||||
binding.codeView.setEnableAutoIndentation(true);
|
||||
switch (tinyDB.getInt("ceIndentationTabsId")) {
|
||||
switch (Integer.parseInt(
|
||||
AppDatabaseSettings.getSettingsValue(
|
||||
ctx, AppDatabaseSettings.APP_CE_TABS_WIDTH_KEY))) {
|
||||
case 0:
|
||||
binding.codeView.setTabLength(2);
|
||||
break;
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.databinding.ActivitySettingsCodeEditorBinding;
|
||||
import org.mian.gitnex.fragments.SettingsFragment;
|
||||
import org.mian.gitnex.helpers.AppDatabaseSettings;
|
||||
import org.mian.gitnex.helpers.SnackBar;
|
||||
|
||||
/**
|
||||
@@ -33,7 +34,10 @@ public class SettingsCodeEditorActivity extends BaseActivity {
|
||||
|
||||
// color selector dialog
|
||||
colorList = getResources().getStringArray(R.array.ceColors);
|
||||
colorSelectedChoice = tinyDB.getInt("ceColorId");
|
||||
colorSelectedChoice =
|
||||
Integer.parseInt(
|
||||
AppDatabaseSettings.getSettingsValue(
|
||||
ctx, AppDatabaseSettings.APP_CE_SYNTAX_HIGHLIGHT_KEY));
|
||||
activitySettingsCodeEditorBinding.ceColorSelected.setText(colorList[colorSelectedChoice]);
|
||||
|
||||
activitySettingsCodeEditorBinding.ceColorSelectionFrame.setOnClickListener(
|
||||
@@ -48,7 +52,11 @@ public class SettingsCodeEditorActivity extends BaseActivity {
|
||||
colorSelectedChoice = i;
|
||||
activitySettingsCodeEditorBinding.ceColorSelected
|
||||
.setText(colorList[i]);
|
||||
tinyDB.putInt("ceColorId", i);
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(i),
|
||||
AppDatabaseSettings
|
||||
.APP_CE_SYNTAX_HIGHLIGHT_KEY);
|
||||
|
||||
SettingsFragment.refreshParent = true;
|
||||
this.recreate();
|
||||
@@ -65,7 +73,10 @@ public class SettingsCodeEditorActivity extends BaseActivity {
|
||||
|
||||
// indentation selector dialog
|
||||
indentationList = getResources().getStringArray(R.array.ceIndentation);
|
||||
indentationSelectedChoice = tinyDB.getInt("ceIndentationId");
|
||||
indentationSelectedChoice =
|
||||
Integer.parseInt(
|
||||
AppDatabaseSettings.getSettingsValue(
|
||||
ctx, AppDatabaseSettings.APP_CE_INDENTATION_KEY));
|
||||
activitySettingsCodeEditorBinding.indentationSelected.setText(
|
||||
indentationList[indentationSelectedChoice]);
|
||||
|
||||
@@ -82,7 +93,10 @@ public class SettingsCodeEditorActivity extends BaseActivity {
|
||||
activitySettingsCodeEditorBinding
|
||||
.indentationSelected.setText(
|
||||
indentationList[i]);
|
||||
tinyDB.putInt("ceIndentationId", i);
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(i),
|
||||
AppDatabaseSettings.APP_CE_INDENTATION_KEY);
|
||||
|
||||
SettingsFragment.refreshParent = true;
|
||||
this.recreate();
|
||||
@@ -107,7 +121,10 @@ public class SettingsCodeEditorActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
indentationTabsList = getResources().getStringArray(R.array.ceIndentationTabsWidth);
|
||||
indentationTabsSelectedChoice = tinyDB.getInt("ceIndentationTabsId");
|
||||
indentationTabsSelectedChoice =
|
||||
Integer.parseInt(
|
||||
AppDatabaseSettings.getSettingsValue(
|
||||
ctx, AppDatabaseSettings.APP_CE_TABS_WIDTH_KEY));
|
||||
activitySettingsCodeEditorBinding.indentationTabsSelected.setText(
|
||||
indentationTabsList[indentationTabsSelectedChoice]);
|
||||
|
||||
@@ -124,7 +141,10 @@ public class SettingsCodeEditorActivity extends BaseActivity {
|
||||
activitySettingsCodeEditorBinding
|
||||
.indentationTabsSelected.setText(
|
||||
indentationTabsList[i]);
|
||||
tinyDB.putInt("ceIndentationTabsId", i);
|
||||
AppDatabaseSettings.updateSettingsValue(
|
||||
ctx,
|
||||
String.valueOf(i),
|
||||
AppDatabaseSettings.APP_CE_TABS_WIDTH_KEY);
|
||||
|
||||
SettingsFragment.refreshParent = true;
|
||||
this.recreate();
|
||||
|
||||
@@ -59,54 +59,65 @@ public class AppDatabaseSettings {
|
||||
|
||||
public static void initDefaultSettings(Context ctx) {
|
||||
|
||||
TinyDB tinyDB = TinyDB.getInstance(ctx);
|
||||
AppSettingsApi appSettingsApi = BaseApi.getInstance(ctx, AppSettingsApi.class);
|
||||
assert appSettingsApi != null;
|
||||
|
||||
if (appSettingsApi.fetchSettingCountByKey(APP_THEME_KEY) == 0) {
|
||||
appSettingsApi.insertNewSetting(APP_THEME_KEY, APP_THEME_DEFAULT, APP_THEME_DEFAULT);
|
||||
appSettingsApi.insertNewSetting(
|
||||
APP_THEME_KEY, String.valueOf(tinyDB.getInt("themeId")), APP_THEME_DEFAULT);
|
||||
}
|
||||
if (appSettingsApi.fetchSettingCountByKey(APP_THEME_AUTO_LIGHT_HOUR_KEY) == 0) {
|
||||
appSettingsApi.insertNewSetting(
|
||||
APP_THEME_AUTO_LIGHT_HOUR_KEY,
|
||||
APP_THEME_AUTO_LIGHT_HOUR_DEFAULT,
|
||||
String.valueOf(tinyDB.getInt("lightThemeTimeHour")),
|
||||
APP_THEME_AUTO_LIGHT_HOUR_DEFAULT);
|
||||
}
|
||||
if (appSettingsApi.fetchSettingCountByKey(APP_THEME_AUTO_LIGHT_MIN_KEY) == 0) {
|
||||
appSettingsApi.insertNewSetting(
|
||||
APP_THEME_AUTO_LIGHT_MIN_KEY,
|
||||
APP_THEME_AUTO_LIGHT_MIN_DEFAULT,
|
||||
String.valueOf(tinyDB.getInt("lightThemeTimeMinute")),
|
||||
APP_THEME_AUTO_LIGHT_MIN_DEFAULT);
|
||||
}
|
||||
if (appSettingsApi.fetchSettingCountByKey(APP_THEME_AUTO_DARK_HOUR_KEY) == 0) {
|
||||
appSettingsApi.insertNewSetting(
|
||||
APP_THEME_AUTO_DARK_HOUR_KEY,
|
||||
APP_THEME_AUTO_DARK_HOUR_DEFAULT,
|
||||
String.valueOf(tinyDB.getInt("darkThemeTimeHour")),
|
||||
APP_THEME_AUTO_DARK_HOUR_DEFAULT);
|
||||
}
|
||||
if (appSettingsApi.fetchSettingCountByKey(APP_THEME_AUTO_DARK_MIN_KEY) == 0) {
|
||||
appSettingsApi.insertNewSetting(
|
||||
APP_THEME_AUTO_DARK_MIN_KEY,
|
||||
APP_THEME_AUTO_DARK_MIN_DEFAULT,
|
||||
String.valueOf(tinyDB.getInt("darkThemeTimeMinute")),
|
||||
APP_THEME_AUTO_DARK_MIN_DEFAULT);
|
||||
}
|
||||
if (appSettingsApi.fetchSettingCountByKey(APP_FONT_KEY) == 0) {
|
||||
appSettingsApi.insertNewSetting(APP_FONT_KEY, APP_FONT_DEFAULT, APP_FONT_DEFAULT);
|
||||
appSettingsApi.insertNewSetting(
|
||||
APP_FONT_KEY, String.valueOf(tinyDB.getInt("customFontId")), APP_FONT_DEFAULT);
|
||||
}
|
||||
if (appSettingsApi.fetchSettingCountByKey(APP_TABS_ANIMATION_KEY) == 0) {
|
||||
appSettingsApi.insertNewSetting(
|
||||
APP_TABS_ANIMATION_KEY, APP_TABS_ANIMATION_DEFAULT, APP_TABS_ANIMATION_DEFAULT);
|
||||
APP_TABS_ANIMATION_KEY,
|
||||
String.valueOf(tinyDB.getInt("fragmentTabsAnimationId")),
|
||||
APP_TABS_ANIMATION_DEFAULT);
|
||||
}
|
||||
if (appSettingsApi.fetchSettingCountByKey(APP_LOCALE_KEY) == 0) {
|
||||
appSettingsApi.insertNewSetting(
|
||||
APP_LOCALE_KEY, APP_LOCALE_KEY_DEFAULT, APP_LOCALE_KEY_DEFAULT);
|
||||
APP_LOCALE_KEY,
|
||||
tinyDB.getInt("langId") + "|" + tinyDB.getString("locale"),
|
||||
APP_LOCALE_KEY_DEFAULT);
|
||||
}
|
||||
if (appSettingsApi.fetchSettingCountByKey(APP_COUNTER_KEY) == 0) {
|
||||
appSettingsApi.insertNewSetting(
|
||||
APP_COUNTER_KEY, APP_COUNTER_DEFAULT, APP_COUNTER_DEFAULT);
|
||||
APP_COUNTER_KEY,
|
||||
String.valueOf(tinyDB.getBoolean("enableCounterBadges")),
|
||||
APP_COUNTER_DEFAULT);
|
||||
}
|
||||
if (appSettingsApi.fetchSettingCountByKey(APP_LABELS_IN_LIST_KEY) == 0) {
|
||||
appSettingsApi.insertNewSetting(
|
||||
APP_LABELS_IN_LIST_KEY, APP_LABELS_IN_LIST_DEFAULT, APP_LABELS_IN_LIST_DEFAULT);
|
||||
APP_LABELS_IN_LIST_KEY,
|
||||
String.valueOf(tinyDB.getBoolean("showLabelsInList")),
|
||||
APP_LABELS_IN_LIST_DEFAULT);
|
||||
}
|
||||
if (appSettingsApi.fetchSettingCountByKey(APP_LINK_HANDLER_KEY) == 0) {
|
||||
appSettingsApi.insertNewSetting(
|
||||
@@ -133,16 +144,20 @@ public class AppDatabaseSettings {
|
||||
if (appSettingsApi.fetchSettingCountByKey(APP_CE_SYNTAX_HIGHLIGHT_KEY) == 0) {
|
||||
appSettingsApi.insertNewSetting(
|
||||
APP_CE_SYNTAX_HIGHLIGHT_KEY,
|
||||
APP_CE_SYNTAX_HIGHLIGHT_DEFAULT,
|
||||
String.valueOf(tinyDB.getInt("ceColorId")),
|
||||
APP_CE_SYNTAX_HIGHLIGHT_DEFAULT);
|
||||
}
|
||||
if (appSettingsApi.fetchSettingCountByKey(APP_CE_INDENTATION_KEY) == 0) {
|
||||
appSettingsApi.insertNewSetting(
|
||||
APP_CE_INDENTATION_KEY, APP_CE_INDENTATION_DEFAULT, APP_CE_INDENTATION_DEFAULT);
|
||||
APP_CE_INDENTATION_KEY,
|
||||
String.valueOf(tinyDB.getInt("ceIndentationId")),
|
||||
APP_CE_INDENTATION_DEFAULT);
|
||||
}
|
||||
if (appSettingsApi.fetchSettingCountByKey(APP_CE_TABS_WIDTH_KEY) == 0) {
|
||||
appSettingsApi.insertNewSetting(
|
||||
APP_CE_TABS_WIDTH_KEY, APP_CE_TABS_WIDTH_DEFAULT, APP_CE_TABS_WIDTH_DEFAULT);
|
||||
APP_CE_TABS_WIDTH_KEY,
|
||||
String.valueOf(tinyDB.getInt("ceIndentationTabsId")),
|
||||
APP_CE_TABS_WIDTH_DEFAULT);
|
||||
}
|
||||
if (appSettingsApi.fetchSettingCountByKey(APP_NOTIFICATIONS_KEY) == 0) {
|
||||
appSettingsApi.insertNewSetting(
|
||||
|
||||
@@ -3,8 +3,8 @@ package org.mian.gitnex.helpers.codeeditor.theme;
|
||||
import android.content.Context;
|
||||
import androidx.annotation.ColorRes;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.helpers.AppDatabaseSettings;
|
||||
import org.mian.gitnex.helpers.AppUtil;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.helpers.codeeditor.languages.LanguageElement;
|
||||
|
||||
/**
|
||||
@@ -19,8 +19,10 @@ public interface Theme {
|
||||
BlueMoonDarkTheme BLUE_MOON_DARK_THEME = new BlueMoonDarkTheme();
|
||||
|
||||
static Theme getDefaultTheme(Context context) {
|
||||
TinyDB tinyDB = TinyDB.getInstance(context);
|
||||
if (tinyDB.getInt("ceColorId") == 0) {
|
||||
if (Integer.parseInt(
|
||||
AppDatabaseSettings.getSettingsValue(
|
||||
context, AppDatabaseSettings.APP_CE_SYNTAX_HIGHLIGHT_KEY))
|
||||
== 0) {
|
||||
return AppUtil.getColorFromAttribute(context, R.attr.isDark) == 1
|
||||
? FIVE_COLORS_DARK
|
||||
: FIVE_COLORS;
|
||||
|
||||
Reference in New Issue
Block a user