add: developer mode + translations (1/2)

This commit is contained in:
sadorowo 2024-03-22 16:45:34 +01:00
parent 3f2a02f242
commit c80c041dd0
27 changed files with 101 additions and 8 deletions

View File

@ -313,6 +313,16 @@ class PreferencesRepository @Inject constructor(
get() = showNotesPreference.get()
set(value) = showNotesPreference.set(value)
var developerMode: Boolean
get() = developerModePreference.get()
set(value) = developerModePreference.set(value)
private val developerModePreference: Preference<Boolean>
get() = flowSharedPref.getBoolean(
context.getString(R.string.pref_key_developer_mode),
context.resources.getBoolean(R.bool.pref_default_developer_mode)
)
private val hiddenGradesPreference: Preference<Set<String>>
get() {
val defaultSet = context.resources.getStringArray(R.array.pref_default_hidden_grades).toSet()

View File

@ -5,11 +5,15 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.res.ResourcesCompat
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.snackbar.Snackbar
import io.github.wulkanowy.data.repositories.PreferencesRepository
import io.github.wulkanowy.databinding.ItemAboutBinding
import io.github.wulkanowy.databinding.ScrollableHeaderAboutBinding
import javax.inject.Inject
class AboutAdapter @Inject constructor() : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
class AboutAdapter @Inject constructor(
private val preferencesRepository: PreferencesRepository
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private enum class ViewType(val id: Int) {
ITEM_HEADER(1),
@ -18,6 +22,7 @@ class AboutAdapter @Inject constructor() : RecyclerView.Adapter<RecyclerView.Vie
var items = emptyList<Triple<String, String, Drawable?>>()
var developerModeClicks = 0
var onClickListener: (name: String) -> Unit = {}
override fun getItemCount() = items.size + 1
@ -46,6 +51,19 @@ class AboutAdapter @Inject constructor() : RecyclerView.Adapter<RecyclerView.Vie
private fun bindHeaderViewHolder(binding: ScrollableHeaderAboutBinding) {
with(binding.aboutScrollableHeaderIcon) {
setOnClickListener {
if (++developerModeClicks == 5) {
preferencesRepository.developerMode = true
developerModeClicks = 0
Snackbar.make(
binding.root,
"👍🏻",
Snackbar.LENGTH_SHORT
).show()
}
}
setImageDrawable(ResourcesCompat.getDrawableForDensity(
context.resources, context.applicationInfo.icon, 640, null)
)

View File

@ -1,13 +1,22 @@
package io.github.wulkanowy.ui.modules.settings
import android.content.SharedPreferences
import android.os.Bundle
import android.view.View
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceScreen
import dagger.hilt.android.AndroidEntryPoint
import io.github.wulkanowy.R
import io.github.wulkanowy.ui.base.BaseActivity
import io.github.wulkanowy.data.repositories.PreferencesRepository
import io.github.wulkanowy.ui.modules.main.MainView
import timber.log.Timber
import javax.inject.Inject
class SettingsFragment : PreferenceFragmentCompat(), MainView.TitledView, SettingsView {
@AndroidEntryPoint
class SettingsFragment : PreferenceFragmentCompat(),
SharedPreferences.OnSharedPreferenceChangeListener,
MainView.TitledView, SettingsView {
companion object {
@ -16,11 +25,26 @@ class SettingsFragment : PreferenceFragmentCompat(), MainView.TitledView, Settin
override val titleStringId get() = R.string.settings_title
@Inject
lateinit var preferencesRepository: PreferencesRepository
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.scheme_preferences, rootKey)
val prefScreen: PreferenceScreen? = findPreference("settings_preferences")
val prefDeveloper: Preference? = findPreference("mod_settings")
if (!preferencesRepository.developerMode && prefScreen != null && prefDeveloper != null) {
prefScreen.removePreference(prefDeveloper)
}
Timber.i("Settings view was initialized")
}
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, rootKey: String?) {
setPreferencesFromResource(R.xml.scheme_preferences, rootKey)
}
override fun showError(text: String, error: Throwable) {}
override fun showMessage(text: String) {}

View File

@ -16,4 +16,5 @@
<item>Ospravedlněná absence</item>
<item>Neznámá</item>
</string-array>
<string name="pref_mod_settings_developer_mode">Režim pro vývojáře (přístup na tuto stránku)</string>
</resources>

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<resources></resources>

View File

@ -883,4 +883,5 @@
<string name="message_unmute">Zrušit ztlumení</string>
<string name="message_mute_success">Ztlumili jste tohoto uživatele</string>
<string name="message_unmute_success">Zrušili jste ztlumení tohoto uživatele</string>
<string name="pref_mod_settings_other_title">Jiné</string>
</resources>

View File

@ -16,4 +16,5 @@
<item>Excused absence</item>
<item>Unknown</item>
</string-array>
<string name="pref_mod_settings_developer_mode">Developer mode (access to this page)</string>
</resources>

View File

@ -754,4 +754,5 @@
<string name="error_feature_disabled">Feature disabled by your school</string>
<string name="error_feature_not_available">Feature not available. Login in a mode other than Mobile API</string>
<string name="error_field_required">This field is required</string>
<string name="pref_mod_settings_other_title">Other</string>
</resources>

View File

@ -16,4 +16,5 @@
<item>Unentschuldigtes Fehlen</item>
<item>Unbekannt</item>
</string-array>
<string name="pref_mod_settings_developer_mode">Entwicklermodus (Zugang zu dieser Seite)</string>
</resources>

View File

@ -789,4 +789,5 @@
<string name="message_unmute">Unmute</string>
<string name="message_mute_success">You have muted this user</string>
<string name="message_unmute_success">You have unmuted this user</string>
<string name="pref_mod_settings_other_title">Sonstiges</string>
</resources>

View File

@ -16,4 +16,5 @@
<item>Excused absence</item>
<item>Unknown</item>
</string-array>
<string name="pref_mod_settings_developer_mode">Developer mode (access to this page)</string>
</resources>

View File

@ -754,4 +754,5 @@
<string name="error_feature_disabled">Feature disabled by your school</string>
<string name="error_feature_not_available">Feature not available. Login in a mode other than Mobile API</string>
<string name="error_field_required">This field is required</string>
<string name="pref_mod_settings_other_title">Other</string>
</resources>

View File

@ -16,4 +16,5 @@
<item>Excused absence</item>
<item>Unknown</item>
</string-array>
<string name="pref_mod_settings_developer_mode">Developer mode (access to this page)</string>
</resources>

View File

@ -754,4 +754,5 @@
<string name="error_feature_disabled">Feature disabled by your school</string>
<string name="error_feature_not_available">Feature not available. Login in a mode other than Mobile API</string>
<string name="error_field_required">This field is required</string>
<string name="pref_mod_settings_other_title">Other</string>
</resources>

View File

@ -16,4 +16,5 @@
<item>Nieobecność usprawiedliwiona</item>
<item>Nieznane</item>
</string-array>
<string name="pref_mod_settings_developer_mode">Tryb dewelopera (dostęp do tej strony)</string>
</resources>

View File

@ -883,4 +883,5 @@
<string name="message_unmute">Wyłącz wyciszenie</string>
<string name="message_mute_success">Wyciszyleś tego użytkownika</string>
<string name="message_unmute_success">Wyłączyłeś wyciszenie tego użytkownika</string>
<string name="pref_mod_settings_other_title">Inne</string>
</resources>

View File

@ -16,4 +16,5 @@
<item>Отсутствие без уважительной причины</item>
<item>Неизвестный</item>
</string-array>
<string name="pref_mod_settings_developer_mode">Режим разработчика (доступ к этой странице)</string>
</resources>

View File

@ -883,4 +883,5 @@
<string name="message_unmute">Unmute</string>
<string name="message_mute_success">You have muted this user</string>
<string name="message_unmute_success">You have unmuted this user</string>
<string name="pref_mod_settings_other_title">Прочее</string>
</resources>

View File

@ -16,4 +16,5 @@
<item>Ospravedlnená absencia</item>
<item>Neznámy</item>
</string-array>
<string name="pref_mod_settings_developer_mode">Vývojársky režim (prístup na túto stránku)</string>
</resources>

View File

@ -883,4 +883,5 @@
<string name="message_unmute">Zrušiť stlmenie</string>
<string name="message_mute_success">Stlmili ste tohto používateľa</string>
<string name="message_unmute_success">Zrušili ste stlmenie tohto používateľa</string>
<string name="pref_mod_settings_other_title">Iné</string>
</resources>

View File

@ -16,4 +16,5 @@
<item>Поважна відсутність</item>
<item>Невідомо</item>
</string-array>
<string name="pref_mod_settings_developer_mode">Режим розробника (доступ до цієї сторінки)</string>
</resources>

View File

@ -883,4 +883,5 @@
<string name="message_unmute">Ввімкнути сповіщення</string>
<string name="message_mute_success">Ви ігноруєте цього користувача</string>
<string name="message_unmute_success">Ви не ігноруєте цього користувача</string>
<string name="pref_mod_settings_other_title">Інше</string>
</resources>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="pref_mod_settings_title">Wulkanowy MOD settings</string>
<string name="pref_mod_settings_title">Hidden settings</string>
<string name="pref_mod_settings_hidden_attendance_items">Hidden attendance items</string>
<string name="pref_hidden_settings_attendance_percentage">Attendance percentage</string>
<string name="pref_hidden_settings_hidden_grades">Hidden grades</string>
@ -8,10 +8,15 @@
<string name="pref_key_hidden_grades" translatable="false">hidden_grades</string>
<string name="pref_key_attendance_items" translatable="false">attendance_items</string>
<string name="pref_key_attendance_percentage" translatable="false">attendance_percentage</string>
<string name="pref_key_developer_mode" translatable="false">developer_mode</string>
<string name="pref_default_attendance_percentage" translatable="false">-1</string>
<string name="pref_mod_settings_show_notes">Show notes</string>
<string name="pref_key_show_notes" translatable="false">show_notes</string>
<string name="pref_mod_settings_developer_mode">Developer mode (access to this page)</string>
<string name="pref_mod_settings_developer_mode_summary">After disabling this setting, you will not be able to access this page anymore, but the settings will still be applied.</string>
<string name="pref_mod_settings_show_notes">Show notes</string>
<bool name="pref_default_developer_mode">false</bool>
<bool name="pref_default_show_notes">true</bool>
<string-array name="mod_settings_attendance_entries">

View File

@ -884,4 +884,5 @@
<string name="message_unmute">Unmute</string>
<string name="message_mute_success">You have muted this user</string>
<string name="message_unmute_success">You have unmuted this user</string>
<string name="pref_mod_settings_other_title">Other</string>
</resources>

View File

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceScreen
xmlns:app="http://schemas.android.com/apk/res-auto"
app:key="settings_preferences">
<Preference
app:fragment="io.github.wulkanowy.ui.modules.settings.appearance.AppearanceFragment"
app:icon="@drawable/ic_settings_appearance"

View File

@ -42,4 +42,15 @@
app:singleLineTitle="false"
app:title="@string/pref_mod_settings_show_notes" />
</PreferenceCategory>
<PreferenceCategory
app:iconSpaceReserved="false"
app:title="@string/pref_mod_settings_other_title">
<SwitchPreferenceCompat
app:defaultValue="@bool/pref_default_developer_mode"
app:iconSpaceReserved="false"
app:key="@string/pref_key_developer_mode"
app:singleLineTitle="false"
app:title="@string/pref_mod_settings_developer_mode"
app:summary="@string/pref_mod_settings_developer_mode_summary"/>
</PreferenceCategory>
</PreferenceScreen>

View File

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceScreen
xmlns:app="http://schemas.android.com/apk/res-auto"
app:key="settings_preferences">
<Preference
app:fragment="io.github.wulkanowy.ui.modules.settings.appearance.AppearanceFragment"
app:icon="@drawable/ic_settings_appearance"