Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
248 changes: 114 additions & 134 deletions app/src/main/java/com/itsaky/androidide/preferences/generalPrefExts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,183 +32,163 @@ import kotlinx.parcelize.Parcelize

@Parcelize
class GeneralPreferencesScreen(
override val key: String = "idepref_general",
override val title: Int = string.title_general,
override val summary: Int? = string.idepref_general_summary,
override val children: List<IPreference> = mutableListOf()
override val key: String = "idepref_general",
override val title: Int = string.title_general,
override val summary: Int? = string.idepref_general_summary,
override val children: List<IPreference> = mutableListOf()
) : IPreferenceScreen() {

init {
addPreference(InterfaceConfig())
addPreference(ProjectConfig())
}
init {
addPreference(InterfaceConfig())
addPreference(ProjectConfig())
}
}

@Parcelize
class InterfaceConfig(
override val key: String = "idepref_general_interface",
override val title: Int = string.title_interface,
override val children: List<IPreference> = mutableListOf(),
override val key: String = "idepref_general_interface",
override val title: Int = string.title_interface,
override val children: List<IPreference> = mutableListOf(),
) : IPreferenceGroup() {

init {
addPreference(UiMode())
addPreference(LocaleSelector())
}
init {
addPreference(UiMode())
addPreference(LocaleSelector())
}
}

@Parcelize
class ProjectConfig(
override val key: String = "idepref_general_project",
override val title: Int = R.string.idepref_general_projectConfig,
override val children: List<IPreference> = mutableListOf(),
override val key: String = "idepref_general_project",
override val title: Int = R.string.idepref_general_projectConfig,
override val children: List<IPreference> = mutableListOf(),
) : IPreferenceGroup() {

init {
addPreference(OpenLastProject())
addPreference(ConfirmProjectOpen())
}
init {
addPreference(OpenLastProject())
addPreference(ConfirmProjectOpen())
}
}

@Parcelize
class UiMode(
override val key: String = GeneralPreferences.UI_MODE,
override val title: Int = R.string.idepref_general_uiMode,
override val summary: Int? = R.string.idepref_general_uiMode_summary,
override val icon: Int? = R.drawable.ic_ui_mode
override val key: String = GeneralPreferences.UI_MODE,
override val title: Int = R.string.idepref_general_uiMode,
override val summary: Int? = R.string.idepref_general_uiMode_summary,
override val icon: Int? = R.drawable.ic_ui_mode
) : SingleChoicePreference() {

@IgnoredOnParcel
override val tooltipTag: String = PREFS_GENERAL
@IgnoredOnParcel
override val tooltipTag: String = PREFS_GENERAL

override fun getEntries(preference: Preference): Array<PreferenceChoices.Entry> {
val context = preference.context
val currentUiMode = GeneralPreferences.uiMode
override fun getEntries(preference: Preference): Array<PreferenceChoices.Entry> {
val context = preference.context
val currentUiMode = GeneralPreferences.uiMode

return Array(3) { index ->
val (label, mode) = when (index) {
0 -> context.getString(R.string.uiMode_light) to AppCompatDelegate.MODE_NIGHT_NO
1 -> context.getString(R.string.uiMode_dark) to AppCompatDelegate.MODE_NIGHT_YES
2 -> context.getString(R.string.uiMode_system) to AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
else -> throw IllegalStateException("Invalid index")
}
return Array(3) { index ->
val (label, mode) = when (index) {
0 -> context.getString(R.string.uiMode_light) to AppCompatDelegate.MODE_NIGHT_NO
1 -> context.getString(R.string.uiMode_dark) to AppCompatDelegate.MODE_NIGHT_YES
2 -> context.getString(R.string.uiMode_system) to AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
else -> throw IllegalStateException("Invalid index")
}

PreferenceChoices.Entry(label, currentUiMode == mode, mode)
}
}
PreferenceChoices.Entry(label, currentUiMode == mode, mode)
}
}

override fun onChoiceConfirmed(
preference: Preference,
entry: PreferenceChoices.Entry?,
position: Int
) {
GeneralPreferences.uiMode = (entry?.data as? Int?) ?: AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
override fun onChoiceConfirmed(
preference: Preference,
entry: PreferenceChoices.Entry?,
position: Int
) {
GeneralPreferences.uiMode = (entry?.data as? Int?) ?: AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
}

@Parcelize
class LocaleSelector(
override val key: String = GeneralPreferences.SELECTED_LOCALE,
override val title: Int = R.string.idepref_general_localeSelector_title,
override val summary: Int? = R.string.idepref_general_localeSelector_summary,
override val icon: Int? = R.drawable.ic_translate
override val key: String = GeneralPreferences.SELECTED_LOCALE,
override val title: Int = R.string.idepref_general_localeSelector_title,
override val summary: Int? = R.string.idepref_general_localeSelector_summary,
override val icon: Int? = R.drawable.ic_translate
) : SingleChoicePreference() {

@IgnoredOnParcel
override val tooltipTag: String = PREFS_GENERAL

override fun getEntries(preference: Preference): Array<PreferenceChoices.Entry> {
val context = preference.context
val currentLocale = GeneralPreferences.selectedLocale
val supportedLocales = LocaleProvider.SUPPORTED_LOCALES.keys.toList()
return Array(supportedLocales.size + 1) { index ->
if (index == 0) {
PreferenceChoices.Entry(
label = ContextCompat.getString(context, R.string.locale_system_default),
_isChecked = GeneralPreferences.selectedLocale == null,
data = 0
)
} else {
val localeKey = supportedLocales[index - 1]
val locale = LocaleProvider.getLocale(localeKey)!!
PreferenceChoices.Entry(
label = locale.getDisplayName(locale),
_isChecked = currentLocale == localeKey,
data = localeKey
)
}
}
}

override fun onChoiceConfirmed(
preference: Preference,
entry: PreferenceChoices.Entry?,
position: Int
) {
GeneralPreferences.selectedLocale = entry?.data?.let { localeKey ->
if (localeKey is Int) null else localeKey as String
}
}
@IgnoredOnParcel
override val tooltipTag: String = PREFS_GENERAL

override fun getEntries(preference: Preference): Array<PreferenceChoices.Entry> {
val context = preference.context
val currentLocale = GeneralPreferences.selectedLocale
val supportedLocales = LocaleProvider.SUPPORTED_LOCALES.keys.toList()
return Array(supportedLocales.size + 1) { index ->
if (index == 0) {
PreferenceChoices.Entry(
label = ContextCompat.getString(context, R.string.locale_system_default),
_isChecked = GeneralPreferences.selectedLocale == null,
data = 0
)
} else {
val localeKey = supportedLocales[index - 1]
val locale = LocaleProvider.getLocale(localeKey)!!
PreferenceChoices.Entry(
label = locale.getDisplayName(locale),
_isChecked = currentLocale == localeKey,
data = localeKey
)
}
}
}

override fun onChoiceConfirmed(
preference: Preference,
entry: PreferenceChoices.Entry?,
position: Int
) {
GeneralPreferences.selectedLocale = entry?.data?.let { localeKey ->
if (localeKey is Int) null else localeKey as String
}
}
}

@Parcelize
class OpenLastProject(
override val key: String = GeneralPreferences.OPEN_PROJECTS,
override val title: Int = string.title_open_projects,
override val summary: Int? = string.msg_open_projects,
override val icon: Int? = drawable.ic_open_project
override val key: String = GeneralPreferences.OPEN_PROJECTS,
override val title: Int = string.title_open_projects,
override val summary: Int? = string.msg_open_projects,
override val icon: Int? = drawable.ic_open_project
) : SwitchPreference() {

override fun onCreatePreference(context: Context): Preference {
val pref = super.onCreatePreference(context) as androidx.preference.SwitchPreference
pref.isChecked = GeneralPreferences.autoOpenProjects
return pref
}
override fun onCreatePreference(context: Context): Preference {
val pref = super.onCreatePreference(context) as androidx.preference.SwitchPreference
pref.isChecked = GeneralPreferences.autoOpenProjects
return pref
}

override fun onPreferenceChanged(preference: Preference, newValue: Any?): Boolean {
GeneralPreferences.autoOpenProjects = newValue as Boolean?
?: GeneralPreferences.autoOpenProjects
return true
}
override fun onPreferenceChanged(preference: Preference, newValue: Any?): Boolean {
GeneralPreferences.autoOpenProjects = newValue as Boolean?
?: GeneralPreferences.autoOpenProjects
return true
}
}

@Parcelize
class ConfirmProjectOpen(
override val key: String = GeneralPreferences.CONFIRM_PROJECT_OPEN,
override val title: Int = string.title_confirm_project_open,
override val summary: Int? = string.msg_confirm_project_open,
override val icon: Int? = drawable.ic_open_project
override val key: String = GeneralPreferences.CONFIRM_PROJECT_OPEN,
override val title: Int = string.title_confirm_project_open,
override val summary: Int? = string.msg_confirm_project_open,
override val icon: Int? = drawable.ic_open_project
) : SwitchPreference() {

override fun onCreatePreference(context: Context): Preference {
val pref = super.onCreatePreference(context) as androidx.preference.SwitchPreference
pref.isChecked = GeneralPreferences.confirmProjectOpen
return pref
}

override fun onPreferenceChanged(preference: Preference, newValue: Any?): Boolean {
GeneralPreferences.confirmProjectOpen = newValue as Boolean?
?: GeneralPreferences.confirmProjectOpen
return true
}
override fun onCreatePreference(context: Context): Preference {
val pref = super.onCreatePreference(context) as androidx.preference.SwitchPreference
pref.isChecked = GeneralPreferences.confirmProjectOpen
return pref
}

@Parcelize
class UseSytemShell(
override val key: String = GeneralPreferences.TERMINAL_USE_SYSTEM_SHELL,
override val title: Int = string.title_default_shell,
override val summary: Int? = string.msg_default_shell,
override val icon: Int? = drawable.ic_bash_commands
) : SwitchPreference() {

override fun onCreatePreference(context: Context): Preference {
val pref = super.onCreatePreference(context) as androidx.preference.SwitchPreference
pref.isChecked = GeneralPreferences.useSystemShell
return pref
}

override fun onPreferenceChanged(preference: Preference, newValue: Any?): Boolean {
GeneralPreferences.useSystemShell = newValue as Boolean? ?: GeneralPreferences.useSystemShell
return true
}
override fun onPreferenceChanged(preference: Preference, newValue: Any?): Boolean {
GeneralPreferences.confirmProjectOpen = newValue as Boolean?
?: GeneralPreferences.confirmProjectOpen
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ object GeneralPreferences {
const val SELECTED_LOCALE = "idpref_general_locale"
const val OPEN_PROJECTS = "idepref_general_autoOpenProjects"
const val CONFIRM_PROJECT_OPEN = "idepref_general_confirmProjectOpen"
const val TERMINAL_USE_SYSTEM_SHELL = "idepref_general_terminalShell"
const val LAST_OPENED_PROJECT = "ide_last_project"
const val LOGCAT_CAPTURE_ALL = "idepref_general_logcatCaptureAll"

Expand Down Expand Up @@ -83,12 +82,6 @@ object GeneralPreferences {
prefManager.putBoolean(CONFIRM_PROJECT_OPEN, value)
}

var useSystemShell: Boolean
get() = prefManager.getBoolean(TERMINAL_USE_SYSTEM_SHELL, false)
set(value) {
prefManager.putBoolean(TERMINAL_USE_SYSTEM_SHELL, value)
}

var lastOpenedProject: String
get() = prefManager.getString(LAST_OPENED_PROJECT, NO_OPENED_PROJECT)!!
set(value) {
Expand Down
2 changes: 0 additions & 2 deletions resources/src/main/res/values-ar-rSA/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@
<string name="msg_open_projects">إذا تم تحديده، فسيتذكر IDE آخر مشروع تم فتحه وسيتم إعادة فتحه عند بدء التشغيل التالي.</string>
<string name="title_confirm_project_open">تأكيد فتح المشروع</string>
<string name="msg_confirm_project_open">اسأل قبل فتح آخر مشروع مفتوح.</string>
<string name="title_default_shell">استخدام shell النظام في الـterminal</string>
<string name="msg_default_shell">إذا تم تحديده، سيتم استخدام \'/system/bin/sh\' في التيرمنال.</string>
<string name="title_general">عام</string>
<string name="title_tab_size">حجم التبويبة</string>
<string name="msg_tab_size">حدد عدد المسافات لـ TAB</string>
Expand Down
2 changes: 0 additions & 2 deletions resources/src/main/res/values-bn-rIN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@
<string name="msg_open_projects">চেক করা থাকলে, IDE শেষ খোলা প্রকল্পটি মনে রাখবে এবং পরবর্তী স্টার্টআপে এটি পুনরায় খোলা হবে৷</string>
<string name="title_confirm_project_open">প্রকল্প খোলার বিষয়টি নিশ্চিত করুন</string>
<string name="msg_confirm_project_open">শেষ খোলা প্রকল্প খোলার আগে জিজ্ঞাসা করুন৷</string>
<string name="title_default_shell">টার্মিনালে সিস্টেম শেল ব্যবহার করুন</string>
<string name="msg_default_shell">চেক করা থাকলে, টার্মিনালে \'/system/bin/sh\' ব্যবহার করা হবে।</string>
<string name="title_general">সাধারণ</string>
<string name="title_tab_size">ট্যাবের আকার</string>
<string name="msg_tab_size">TAB এর জন্য স্পেস সংখ্যা নির্দিষ্ট করুন</string>
Expand Down
2 changes: 0 additions & 2 deletions resources/src/main/res/values-de-rDE/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@
<string name="msg_open_projects">Wenn diese Option aktiviert ist, merkt sich die IDE das zuletzt ge&#xF6;ffnete Projekt und &#xF6;ffnet dieses beim n&#xE4;chsten Start.</string>
<string name="title_confirm_project_open">Projekt &#xF6;ffnung best&#xE4;tigen</string>
<string name="msg_confirm_project_open">Vor dem &#xD6;ffnen des zuletzt ge&#xF6;ffneten Projekts nachfragen.</string>
<string name="title_default_shell">Verwenden Sie die System-Shell im Terminal</string>
<string name="msg_default_shell">Wenn aktiviert, wird \'/system/bin/sh\' im Terminal verwendet.</string>
<string name="title_general">Allgemein</string>
<string name="title_tab_size">Tab-Gr&#xF6;&#xDF;e</string>
<string name="msg_tab_size">Geben Sie die Anzahl der Leerzeichen f&#xFC;r TAB an</string>
Expand Down
2 changes: 0 additions & 2 deletions resources/src/main/res/values-es-rES/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@
<string name="msg_open_projects">Si está marcado, el IDE recordará el último proyecto abierto y volverá a abrirse en el próximo arranque.</string>
<string name="title_confirm_project_open">Confirmar apertura del proyecto</string>
<string name="msg_confirm_project_open">Preguntar antes de abrir el último proyecto abierto.</string>
<string name="title_default_shell">Use system shell in terminal</string>
<string name="msg_default_shell">Si está marcado, se utilizará \'/system/bin/sh\' en el terminal.</string>
<string name="title_general">General</string>
<string name="title_tab_size">Tamaño de la pestaña</string>
<string name="msg_tab_size">Especificar el número de espacios para la TAB</string>
Expand Down
2 changes: 0 additions & 2 deletions resources/src/main/res/values-fr-rFR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ Dernier projet ouvert : \n%s</string>
<string name="msg_open_projects">Si il est activé, l\'IDE se rappelera du dernier projet ouvert et l\'ouvrira au prochain démarrage de l\'application</string>
<string name="title_confirm_project_open">Confirmer l\'ouverture du projet</string>
<string name="msg_confirm_project_open">Demander avant d\'ouvrir le dernier projet ouvert</string>
<string name="title_default_shell">Utiliser le système Shell dans le terminal</string>
<string name="msg_default_shell">Si il est activer, \'/system/bin/sh\' sera utilisé dans le terminal.</string>
<string name="title_general">Général</string>
<string name="title_tab_size">Taille de l\'onglet</string>
<string name="msg_tab_size">Spécifier la taille de l\'onglet</string>
Expand Down
2 changes: 0 additions & 2 deletions resources/src/main/res/values-hi-rIN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@
<string name="msg_open_projects">यदि चेक किया गया है, तो आईडीई पिछले खुले हुए प्रोजेक्ट को याद रखेगा और इसे अगले स्टार्टअप पर फिर से खोल दिया जाएगा।</string>
<string name="title_confirm_project_open">प्रोजेक्ट के खोलने की पुष्टि करें</string>
<string name="msg_confirm_project_open">अंतिम खुली प्रोजेक्ट को खोलने से पहले पूछें।</string>
<string name="title_default_shell">टर्मिनल में सिस्टम शेल का उपयोग करें</string>
<string name="msg_default_shell">यदि चेक किया गया है, तो टर्मिनल में \'/system/bin/sh\' का उपयोग किया जाएगा।</string>
<string name="title_general">जनरल</string>
<string name="title_tab_size">टैब साइज</string>
<string name="msg_tab_size">टैब के लिए स्पेसेस की संख्या निर्दिष्ट करें</string>
Expand Down
2 changes: 0 additions & 2 deletions resources/src/main/res/values-in-rID/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,6 @@
<string name="title_confirm_project_open">Konfirmasi pembukaan proyek</string>
<string name="msg_confirm_project_open">Jika diaktifkan, Code on the Go akan meminta konfirmasi sebelum membuka proyek terakhir.</string>
<string name="msg_error_opening_project">Terjadi kesalahan saat membuka proyek.</string>
<string name="title_default_shell">Gunakan shell sistem di terminal</string>
<string name="msg_default_shell">Jika dicentang, \'/system/bin/sh\' akan digunakan di terminal.</string>
<string name="title_general">Umum</string>
<string name="title_tab_size">Ukuran tab</string>
<string name="msg_tab_size">Atur jumlah spasi yang digunakan oleh karakter tab untuk indentasi.</string>
Expand Down
2 changes: 0 additions & 2 deletions resources/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@
<string name="msg_open_projects">Se habilitado, a IDE se lembrará do último projeto aberto e será reaberto na próxima vez.</string>
<string name="title_confirm_project_open">Confirmar abertura do projeto</string>
<string name="msg_confirm_project_open">Perguntar antes de abrir o último projeto aberto.</string>
<string name="title_default_shell">Usar shell do sistema no terminal</string>
<string name="msg_default_shell">Se habilitado, \'/system/bin/sh\' será usado no terminal.</string>
<string name="title_general">Geral</string>
<string name="title_tab_size">Tamanho da tabulação</string>
<string name="msg_tab_size">Especifique o número de espaços para o TAB</string>
Expand Down
2 changes: 0 additions & 2 deletions resources/src/main/res/values-ro-rRO/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@
<string name="msg_open_projects">Dacă este activat, IDE va preântâmpina despre ultimul proiect deschis și va fi redeschis la următoarea pornire.</string>
<string name="title_confirm_project_open">Confirmați deschiderea proiectului</string>
<string name="msg_confirm_project_open">Întrebați înainte de a deschide ultimul proiect deschis.</string>
<string name="title_default_shell">Utilizați shell-ul sistemului în terminal</string>
<string name="msg_default_shell">Dacă este activat, \'/system/bin/sh\' va fi utilizat în terminal.</string>
<string name="title_general">General</string>
<string name="title_tab_size">Mărime Tab</string>
<string name="msg_tab_size">Specificarea numărului de spații pentru TAB</string>
Expand Down
Loading
Loading