From 47b0f1b527821f6dcf28b1e21d0cc5b3d000b478 Mon Sep 17 00:00:00 2001 From: Damian Czupryn <60961958+Daxxxis@users.noreply.github.com> Date: Sat, 6 Mar 2021 18:18:42 +0100 Subject: [PATCH] Settings revamp (#1160) --- .../java/io/github/wulkanowy/WulkanowyApp.kt | 1 - .../repositories/PreferencesRepository.kt | 91 ++++++-- .../wulkanowy/ui/modules/main/MainActivity.kt | 32 ++- .../wulkanowy/ui/modules/more/MoreFragment.kt | 7 - .../ui/modules/more/MorePresenter.kt | 4 +- .../wulkanowy/ui/modules/more/MoreView.kt | 4 - .../ui/modules/settings/SettingsFragment.kt | 139 +----------- .../settings/advanced/AdvancedFragment.kt | 78 +++++++ .../settings/advanced/AdvancedPresenter.kt | 25 +++ .../modules/settings/advanced/AdvancedView.kt | 5 + .../settings/appearance/AppearanceFragment.kt | 90 ++++++++ .../appearance/AppearancePresenter.kt | 45 ++++ .../settings/appearance/AppearanceView.kt | 12 + .../notifications/NotificationsFragment.kt | 130 +++++++++++ .../notifications/NotificationsPresenter.kt | 58 +++++ .../notifications/NotificationsView.kt | 12 + .../ui/modules/settings/sync/SyncFragment.kt | 100 +++++++++ .../SyncPresenter.kt} | 34 +-- .../{SettingsView.kt => sync/SyncView.kt} | 12 +- app/src/main/res/drawable/ic_all_about.xml | 1 + .../res/drawable/ic_settings_advanced.xml | 13 ++ .../res/drawable/ic_settings_appearance.xml | 22 ++ .../drawable/ic_settings_notifications.xml | 10 + .../main/res/drawable/ic_settings_sync.xml | 10 + app/src/main/res/layout/activity_main.xml | 15 +- app/src/main/res/values/strings.xml | 44 ++-- app/src/main/res/xml/scheme_preferences.xml | 209 +++--------------- .../res/xml/scheme_preferences_advanced.xml | 47 ++++ .../res/xml/scheme_preferences_appearance.xml | 104 +++++++++ .../xml/scheme_preferences_notifications.xml | 29 +++ .../main/res/xml/scheme_preferences_sync.xml | 31 +++ 31 files changed, 1001 insertions(+), 413 deletions(-) create mode 100644 app/src/main/java/io/github/wulkanowy/ui/modules/settings/advanced/AdvancedFragment.kt create mode 100644 app/src/main/java/io/github/wulkanowy/ui/modules/settings/advanced/AdvancedPresenter.kt create mode 100644 app/src/main/java/io/github/wulkanowy/ui/modules/settings/advanced/AdvancedView.kt create mode 100644 app/src/main/java/io/github/wulkanowy/ui/modules/settings/appearance/AppearanceFragment.kt create mode 100644 app/src/main/java/io/github/wulkanowy/ui/modules/settings/appearance/AppearancePresenter.kt create mode 100644 app/src/main/java/io/github/wulkanowy/ui/modules/settings/appearance/AppearanceView.kt create mode 100644 app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsFragment.kt create mode 100644 app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsPresenter.kt create mode 100644 app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsView.kt create mode 100644 app/src/main/java/io/github/wulkanowy/ui/modules/settings/sync/SyncFragment.kt rename app/src/main/java/io/github/wulkanowy/ui/modules/settings/{SettingsPresenter.kt => sync/SyncPresenter.kt} (63%) rename app/src/main/java/io/github/wulkanowy/ui/modules/settings/{SettingsView.kt => sync/SyncView.kt} (54%) create mode 100644 app/src/main/res/drawable/ic_settings_advanced.xml create mode 100644 app/src/main/res/drawable/ic_settings_appearance.xml create mode 100644 app/src/main/res/drawable/ic_settings_notifications.xml create mode 100644 app/src/main/res/drawable/ic_settings_sync.xml create mode 100644 app/src/main/res/xml/scheme_preferences_advanced.xml create mode 100644 app/src/main/res/xml/scheme_preferences_appearance.xml create mode 100644 app/src/main/res/xml/scheme_preferences_notifications.xml create mode 100644 app/src/main/res/xml/scheme_preferences_sync.xml diff --git a/app/src/main/java/io/github/wulkanowy/WulkanowyApp.kt b/app/src/main/java/io/github/wulkanowy/WulkanowyApp.kt index 46ff3651..d01a953d 100644 --- a/app/src/main/java/io/github/wulkanowy/WulkanowyApp.kt +++ b/app/src/main/java/io/github/wulkanowy/WulkanowyApp.kt @@ -52,7 +52,6 @@ class WulkanowyApp : Application(), Configuration.Provider { override fun onCreate() { super.onCreate() FragmentManager.enableNewStateManager(false) - initializeAppLanguage() themeManager.applyDefaultTheme() initLogging() diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/PreferencesRepository.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/PreferencesRepository.kt index 8cb815cc..11adbd0f 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/PreferencesRepository.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/PreferencesRepository.kt @@ -18,26 +18,43 @@ class PreferencesRepository @Inject constructor( get() = getString(R.string.pref_key_start_menu, R.string.pref_default_startup).toInt() val isShowPresent: Boolean - get() = getBoolean(R.string.pref_key_attendance_present, R.bool.pref_default_attendance_present) + get() = getBoolean( + R.string.pref_key_attendance_present, + R.bool.pref_default_attendance_present + ) val gradeAverageMode: GradeAverageMode - get() = GradeAverageMode.getByValue(getString(R.string.pref_key_grade_average_mode, R.string.pref_default_grade_average_mode)) + get() = GradeAverageMode.getByValue( + getString( + R.string.pref_key_grade_average_mode, + R.string.pref_default_grade_average_mode + ) + ) val gradeAverageForceCalc: Boolean - get() = getBoolean(R.string.pref_key_grade_average_force_calc, R.bool.pref_default_grade_average_force_calc) + get() = getBoolean( + R.string.pref_key_grade_average_force_calc, + R.bool.pref_default_grade_average_force_calc + ) val isGradeExpandable: Boolean get() = !getBoolean(R.string.pref_key_expand_grade, R.bool.pref_default_expand_grade) val showAllSubjectsOnStatisticsList: Boolean - get() = getBoolean(R.string.pref_key_grade_statistics_list, R.bool.pref_default_grade_statistics_list) + get() = getBoolean( + R.string.pref_key_grade_statistics_list, + R.bool.pref_default_grade_statistics_list + ) val appThemeKey = context.getString(R.string.pref_key_app_theme) val appTheme: String get() = getString(appThemeKey, R.string.pref_default_app_theme) val gradeColorTheme: String - get() = getString(R.string.pref_key_grade_color_scheme, R.string.pref_default_grade_color_scheme) + get() = getString( + R.string.pref_key_grade_color_scheme, + R.string.pref_default_grade_color_scheme + ) val appLanguageKey = context.getString(R.string.pref_key_app_language) val appLanguage @@ -55,50 +72,86 @@ class PreferencesRepository @Inject constructor( val isServicesOnlyWifi: Boolean get() = getBoolean(servicesOnlyWifiKey, R.bool.pref_default_services_wifi_only) + val notificationsEnableKey = context.getString(R.string.pref_key_notifications_enable) val isNotificationsEnable: Boolean - get() = getBoolean(R.string.pref_key_notifications_enable, R.bool.pref_default_notifications_enable) + get() = getBoolean(notificationsEnableKey, R.bool.pref_default_notifications_enable) - val isUpcomingLessonsNotificationsEnableKey = context.getString(R.string.pref_key_notifications_upcoming_lessons_enable) + val isUpcomingLessonsNotificationsEnableKey = + context.getString(R.string.pref_key_notifications_upcoming_lessons_enable) val isUpcomingLessonsNotificationsEnable: Boolean - get() = getBoolean(isUpcomingLessonsNotificationsEnableKey, R.bool.pref_default_notification_upcoming_lessons_enable) + get() = getBoolean( + isUpcomingLessonsNotificationsEnableKey, + R.bool.pref_default_notification_upcoming_lessons_enable + ) val isDebugNotificationEnableKey = context.getString(R.string.pref_key_notification_debug) val isDebugNotificationEnable: Boolean get() = getBoolean(isDebugNotificationEnableKey, R.bool.pref_default_notification_debug) val gradePlusModifier: Double - get() = getString(R.string.pref_key_grade_modifier_plus, R.string.pref_default_grade_modifier_plus).toDouble() + get() = getString( + R.string.pref_key_grade_modifier_plus, + R.string.pref_default_grade_modifier_plus + ).toDouble() val gradeMinusModifier: Double - get() = getString(R.string.pref_key_grade_modifier_minus, R.string.pref_default_grade_modifier_minus).toDouble() + get() = getString( + R.string.pref_key_grade_modifier_minus, + R.string.pref_default_grade_modifier_minus + ).toDouble() val fillMessageContent: Boolean - get() = getBoolean(R.string.pref_key_fill_message_content, R.bool.pref_default_fill_message_content) + get() = getBoolean( + R.string.pref_key_fill_message_content, + R.bool.pref_default_fill_message_content + ) val showGroupsInPlan: Boolean - get() = getBoolean(R.string.pref_key_timetable_show_groups, R.bool.pref_default_timetable_show_groups) + get() = getBoolean( + R.string.pref_key_timetable_show_groups, + R.bool.pref_default_timetable_show_groups + ) val showWholeClassPlan: String - get() = getString(R.string.pref_key_timetable_show_whole_class, R.string.pref_default_timetable_show_whole_class) + get() = getString( + R.string.pref_key_timetable_show_whole_class, + R.string.pref_default_timetable_show_whole_class + ) val gradeSortingMode: GradeSortingMode - get() = GradeSortingMode.getByValue(getString(R.string.pref_key_grade_sorting_mode, R.string.pref_default_grade_sorting_mode)) + get() = GradeSortingMode.getByValue( + getString( + R.string.pref_key_grade_sorting_mode, + R.string.pref_default_grade_sorting_mode + ) + ) val showTimetableTimers: Boolean - get() = getBoolean(R.string.pref_key_timetable_show_timers, R.bool.pref_default_timetable_show_timers) + get() = getBoolean( + R.string.pref_key_timetable_show_timers, + R.bool.pref_default_timetable_show_timers + ) var isHomeworkFullscreen: Boolean - get() = getBoolean(R.string.pref_key_homework_fullscreen, R.bool.pref_default_homework_fullscreen) + get() = getBoolean( + R.string.pref_key_homework_fullscreen, + R.bool.pref_default_homework_fullscreen + ) set(value) = sharedPref.edit().putBoolean("homework_fullscreen", value).apply() val showSubjectsWithoutGrades: Boolean - get() = getBoolean(R.string.pref_key_subjects_without_grades, R.bool.pref_default_subjects_without_grades) + get() = getBoolean( + R.string.pref_key_subjects_without_grades, + R.bool.pref_default_subjects_without_grades + ) private fun getString(id: Int, default: Int) = getString(context.getString(id), default) - private fun getString(id: String, default: Int) = sharedPref.getString(id, context.getString(default)) ?: context.getString(default) + private fun getString(id: String, default: Int) = + sharedPref.getString(id, context.getString(default)) ?: context.getString(default) private fun getBoolean(id: Int, default: Int) = getBoolean(context.getString(id), default) - private fun getBoolean(id: String, default: Int) = sharedPref.getBoolean(id, context.resources.getBoolean(default)) + private fun getBoolean(id: String, default: Int) = + sharedPref.getBoolean(id, context.resources.getBoolean(default)) } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/main/MainActivity.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/main/MainActivity.kt index efa83f44..2b207933 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/main/MainActivity.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/main/MainActivity.kt @@ -15,12 +15,17 @@ import android.os.Build.VERSION_CODES.P import android.os.Bundle import android.view.Menu import android.view.MenuItem -import android.view.View +import android.view.ViewGroup import androidx.annotation.RequiresApi import androidx.core.content.getSystemService import androidx.core.view.ViewCompat +import androidx.core.view.isVisible +import androidx.core.view.updateLayoutParams +import androidx.core.view.updateMargins import androidx.fragment.app.DialogFragment import androidx.fragment.app.Fragment +import androidx.preference.Preference +import androidx.preference.PreferenceFragmentCompat import com.aurelhubert.ahbottomnavigation.AHBottomNavigation.TitleState.ALWAYS_SHOW import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem import com.google.android.material.elevation.ElevationOverlayProvider @@ -55,7 +60,8 @@ import timber.log.Timber import javax.inject.Inject @AndroidEntryPoint -class MainActivity : BaseActivity(), MainView { +class MainActivity : BaseActivity(), MainView, + PreferenceFragmentCompat.OnPreferenceStartFragmentCallback { @Inject override lateinit var presenter: MainPresenter @@ -245,12 +251,20 @@ class MainActivity : BaseActivity(), MainVie with(navController) { setOnViewChangeListener { section, name -> if (section == MainView.Section.ACCOUNT || section == MainView.Section.STUDENT_INFO) { - binding.mainBottomNav.visibility = View.GONE + binding.mainBottomNav.isVisible = false + binding.mainFragmentContainer.updateLayoutParams { + updateMargins(bottom = 0) + } + if (appInfo.systemVersion >= P) { window.navigationBarColor = getThemeAttrColor(R.attr.colorSurface) } } else { - binding.mainBottomNav.visibility = View.VISIBLE + binding.mainBottomNav.isVisible = true + binding.mainFragmentContainer.updateLayoutParams { + updateMargins(bottom = dpToPx(56f).toInt()) + } + if (appInfo.systemVersion >= P) { window.navigationBarColor = getThemeAttrColor(android.R.attr.navigationBarColor) @@ -271,6 +285,16 @@ class MainActivity : BaseActivity(), MainVie } } + override fun onPreferenceStartFragment( + caller: PreferenceFragmentCompat, + pref: Preference + ): Boolean { + val fragment = + supportFragmentManager.fragmentFactory.instantiate(classLoader, pref.fragment) + navController.pushFragment(fragment) + return true + } + override fun onOptionsItemSelected(item: MenuItem): Boolean { return if (item.itemId == R.id.mainMenuAccount) presenter.onAccountManagerSelected() else false diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/more/MoreFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/more/MoreFragment.kt index bf8918fc..c4a14a52 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/more/MoreFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/more/MoreFragment.kt @@ -63,9 +63,6 @@ class MoreFragment : BaseFragment(R.layout.fragment_more), override val settingsRes: Pair? get() = context?.run { getString(R.string.settings_title) to getCompatDrawable(R.drawable.ic_more_settings) } - override val aboutRes: Pair? - get() = context?.run { getString(R.string.about_title) to getCompatDrawable(R.drawable.ic_all_about) } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding = FragmentMoreBinding.bind(view) @@ -124,10 +121,6 @@ class MoreFragment : BaseFragment(R.layout.fragment_more), (activity as? MainActivity)?.pushView(SettingsFragment.newInstance()) } - override fun openAboutView() { - (activity as? MainActivity)?.pushView(AboutFragment.newInstance()) - } - override fun popView(depth: Int) { (activity as? MainActivity)?.popView(depth) } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/more/MorePresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/more/MorePresenter.kt index d119000d..6079141f 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/more/MorePresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/more/MorePresenter.kt @@ -30,7 +30,6 @@ class MorePresenter @Inject constructor( conferencesRes?.first -> openConferencesView() schoolAndTeachersRes?.first -> openSchoolAndTeachersView() settingsRes?.first -> openSettingsView() - aboutRes?.first -> openAboutView() } } } @@ -51,8 +50,7 @@ class MorePresenter @Inject constructor( mobileDevicesRes, conferencesRes, schoolAndTeachersRes, - settingsRes, - aboutRes + settingsRes )) } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/more/MoreView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/more/MoreView.kt index bb1faeda..0543742e 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/more/MoreView.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/more/MoreView.kt @@ -21,16 +21,12 @@ interface MoreView : BaseView { val settingsRes: Pair? - val aboutRes: Pair? - fun initView() fun updateData(data: List>) fun openSettingsView() - fun openAboutView() - fun popView(depth: Int) fun openMessagesView() diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsFragment.kt index e02f3b8d..2612fab3 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsFragment.kt @@ -1,153 +1,22 @@ package io.github.wulkanowy.ui.modules.settings -import android.content.SharedPreferences import android.os.Bundle -import android.view.View -import androidx.appcompat.app.AlertDialog -import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat -import com.thelittlefireman.appkillermanager.AppKillerManager -import com.thelittlefireman.appkillermanager.exceptions.NoActionFoundException -import com.yariksoffice.lingver.Lingver -import dagger.hilt.android.AndroidEntryPoint import io.github.wulkanowy.R -import io.github.wulkanowy.ui.base.BaseActivity -import io.github.wulkanowy.ui.base.ErrorDialog import io.github.wulkanowy.ui.modules.main.MainView -import io.github.wulkanowy.utils.AppInfo -import io.github.wulkanowy.utils.openInternetBrowser -import javax.inject.Inject +import timber.log.Timber -@AndroidEntryPoint -class SettingsFragment : PreferenceFragmentCompat(), - SharedPreferences.OnSharedPreferenceChangeListener, - MainView.TitledView, SettingsView { - - @Inject - lateinit var presenter: SettingsPresenter - - @Inject - lateinit var appInfo: AppInfo - - @Inject - lateinit var lingver: Lingver +class SettingsFragment : PreferenceFragmentCompat(), MainView.TitledView { companion object { + fun newInstance() = SettingsFragment() } override val titleStringId get() = R.string.settings_title - override val syncSuccessString get() = getString(R.string.pref_services_message_sync_success) - - override val syncFailedString get() = getString(R.string.pref_services_message_sync_failed) - - override fun initView() { - findPreference(getString(R.string.pref_key_services_force_sync))?.run { - onPreferenceClickListener = Preference.OnPreferenceClickListener { - presenter.onSyncNowClicked() - true - } - } - findPreference(getString(R.string.pref_key_notifications_fix_issues))?.run { - isVisible = - AppKillerManager.isDeviceSupported() && AppKillerManager.isAnyActionAvailable( - requireContext() - ) - setOnPreferenceClickListener { - presenter.onFixSyncIssuesClicked() - true - } - } - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - presenter.onAttachView(this) - } - override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.scheme_preferences, rootKey) - findPreference(getString(R.string.pref_key_notification_debug))?.isVisible = - appInfo.isDebug - } - - override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) { - presenter.onSharedPreferenceChanged(key) - } - - override fun recreateView() { - activity?.recreate() - } - - override fun updateLanguage(langCode: String) { - lingver.setLocale(requireContext(), langCode) - } - - override fun updateLanguageToFollowSystem() { - lingver.setFollowSystemLocale(requireContext()) - } - - override fun setServicesSuspended(serviceEnablesKey: String, isHolidays: Boolean) { - findPreference(serviceEnablesKey)?.run { - summary = if (isHolidays) getString(R.string.pref_services_suspended) else "" - isEnabled = !isHolidays - } - } - - override fun setSyncInProgress(inProgress: Boolean) { - if (activity == null || !isAdded) return - - findPreference(getString(R.string.pref_key_services_force_sync))?.run { - isEnabled = !inProgress - summary = if (inProgress) getString(R.string.pref_services_sync_in_progress) else "" - } - } - - override fun showError(text: String, error: Throwable) { - (activity as? BaseActivity<*, *>)?.showError(text, error) - } - - override fun showMessage(text: String) { - (activity as? BaseActivity<*, *>)?.showMessage(text) - } - - override fun showExpiredDialog() { - (activity as? BaseActivity<*, *>)?.showExpiredDialog() - } - - override fun openClearLoginView() { - (activity as? BaseActivity<*, *>)?.openClearLoginView() - } - - override fun showErrorDetailsDialog(error: Throwable) { - ErrorDialog.newInstance(error).show(childFragmentManager, error.toString()) - } - - override fun showFixSyncDialog() { - AlertDialog.Builder(requireContext()) - .setTitle(R.string.pref_notify_fix_sync_issues) - .setMessage(R.string.pref_notify_fix_sync_issues_message) - .setNegativeButton(android.R.string.cancel) { _, _ -> } - .setPositiveButton(R.string.pref_notify_fix_sync_issues_settings_button) { _, _ -> - try { - AppKillerManager.doActionPowerSaving(requireContext()) - AppKillerManager.doActionAutoStart(requireContext()) - AppKillerManager.doActionNotification(requireContext()) - } catch (e: NoActionFoundException) { - requireContext().openInternetBrowser("https://dontkillmyapp.com/${AppKillerManager.getDevice()?.manufacturer}", ::showMessage) - } - } - .show() - } - - override fun onResume() { - super.onResume() - preferenceScreen.sharedPreferences.registerOnSharedPreferenceChangeListener(this) - } - - override fun onPause() { - super.onPause() - preferenceScreen.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) + Timber.i("Settings view was initialized") } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/advanced/AdvancedFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/advanced/AdvancedFragment.kt new file mode 100644 index 00000000..524d7ba6 --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/advanced/AdvancedFragment.kt @@ -0,0 +1,78 @@ +package io.github.wulkanowy.ui.modules.settings.advanced + +import android.content.SharedPreferences +import android.os.Bundle +import android.view.View +import androidx.preference.PreferenceFragmentCompat +import com.yariksoffice.lingver.Lingver +import dagger.hilt.android.AndroidEntryPoint +import io.github.wulkanowy.R +import io.github.wulkanowy.ui.base.BaseActivity +import io.github.wulkanowy.ui.base.ErrorDialog +import io.github.wulkanowy.ui.modules.main.MainView +import io.github.wulkanowy.utils.AppInfo +import javax.inject.Inject + +@AndroidEntryPoint +class AdvancedFragment : PreferenceFragmentCompat(), + SharedPreferences.OnSharedPreferenceChangeListener, + MainView.TitledView, AdvancedView { + + @Inject + lateinit var presenter: AdvancedPresenter + + @Inject + lateinit var appInfo: AppInfo + + @Inject + lateinit var lingver: Lingver + + companion object { + fun newInstance() = AdvancedFragment() + } + + override val titleStringId get() = R.string.pref_settings_advanced_title + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + presenter.onAttachView(this) + } + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + setPreferencesFromResource(R.xml.scheme_preferences_advanced, rootKey) + } + + override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) { + presenter.onSharedPreferenceChanged(key) + } + + override fun showError(text: String, error: Throwable) { + (activity as? BaseActivity<*, *>)?.showError(text, error) + } + + override fun showMessage(text: String) { + (activity as? BaseActivity<*, *>)?.showMessage(text) + } + + override fun showExpiredDialog() { + (activity as? BaseActivity<*, *>)?.showExpiredDialog() + } + + override fun openClearLoginView() { + (activity as? BaseActivity<*, *>)?.openClearLoginView() + } + + override fun showErrorDetailsDialog(error: Throwable) { + ErrorDialog.newInstance(error).show(childFragmentManager, error.toString()) + } + + override fun onResume() { + super.onResume() + preferenceScreen.sharedPreferences.registerOnSharedPreferenceChangeListener(this) + } + + override fun onPause() { + super.onPause() + preferenceScreen.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) + } +} diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/advanced/AdvancedPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/advanced/AdvancedPresenter.kt new file mode 100644 index 00000000..d38f841f --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/advanced/AdvancedPresenter.kt @@ -0,0 +1,25 @@ +package io.github.wulkanowy.ui.modules.settings.advanced + +import io.github.wulkanowy.data.repositories.StudentRepository +import io.github.wulkanowy.ui.base.BasePresenter +import io.github.wulkanowy.ui.base.ErrorHandler +import io.github.wulkanowy.utils.AnalyticsHelper +import timber.log.Timber +import javax.inject.Inject + +class AdvancedPresenter @Inject constructor( + errorHandler: ErrorHandler, + studentRepository: StudentRepository, + private val analytics: AnalyticsHelper, +) : BasePresenter(errorHandler, studentRepository) { + + override fun onAttachView(view: AdvancedView) { + super.onAttachView(view) + Timber.i("Settings advanced view was initialized") + } + + fun onSharedPreferenceChanged(key: String) { + Timber.i("Change settings $key") + analytics.logEvent("setting_changed", "name" to key) + } +} diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/advanced/AdvancedView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/advanced/AdvancedView.kt new file mode 100644 index 00000000..c2e8e52d --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/advanced/AdvancedView.kt @@ -0,0 +1,5 @@ +package io.github.wulkanowy.ui.modules.settings.advanced + +import io.github.wulkanowy.ui.base.BaseView + +interface AdvancedView : BaseView {} diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/appearance/AppearanceFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/appearance/AppearanceFragment.kt new file mode 100644 index 00000000..5ac801dc --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/appearance/AppearanceFragment.kt @@ -0,0 +1,90 @@ +package io.github.wulkanowy.ui.modules.settings.appearance + +import android.content.SharedPreferences +import android.os.Bundle +import android.view.View +import androidx.preference.PreferenceFragmentCompat +import com.yariksoffice.lingver.Lingver +import dagger.hilt.android.AndroidEntryPoint +import io.github.wulkanowy.R +import io.github.wulkanowy.ui.base.BaseActivity +import io.github.wulkanowy.ui.base.ErrorDialog +import io.github.wulkanowy.ui.modules.main.MainView +import io.github.wulkanowy.utils.AppInfo +import javax.inject.Inject + +@AndroidEntryPoint +class AppearanceFragment : PreferenceFragmentCompat(), + SharedPreferences.OnSharedPreferenceChangeListener, + MainView.TitledView, AppearanceView { + + @Inject + lateinit var presenter: AppearancePresenter + + @Inject + lateinit var appInfo: AppInfo + + @Inject + lateinit var lingver: Lingver + + companion object { + fun newInstance() = AppearanceFragment() + } + + override val titleStringId get() = R.string.pref_settings_appearance_title + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + presenter.onAttachView(this) + } + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + setPreferencesFromResource(R.xml.scheme_preferences_appearance, rootKey) + } + + override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) { + presenter.onSharedPreferenceChanged(key) + } + + override fun recreateView() { + activity?.recreate() + } + + override fun updateLanguage(langCode: String) { + lingver.setLocale(requireContext(), langCode) + } + + override fun updateLanguageToFollowSystem() { + lingver.setFollowSystemLocale(requireContext()) + } + + override fun showError(text: String, error: Throwable) { + (activity as? BaseActivity<*, *>)?.showError(text, error) + } + + override fun showMessage(text: String) { + (activity as? BaseActivity<*, *>)?.showMessage(text) + } + + override fun showExpiredDialog() { + (activity as? BaseActivity<*, *>)?.showExpiredDialog() + } + + override fun openClearLoginView() { + (activity as? BaseActivity<*, *>)?.openClearLoginView() + } + + override fun showErrorDetailsDialog(error: Throwable) { + ErrorDialog.newInstance(error).show(childFragmentManager, error.toString()) + } + + override fun onResume() { + super.onResume() + preferenceScreen.sharedPreferences.registerOnSharedPreferenceChangeListener(this) + } + + override fun onPause() { + super.onPause() + preferenceScreen.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) + } +} diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/appearance/AppearancePresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/appearance/AppearancePresenter.kt new file mode 100644 index 00000000..14592a6c --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/appearance/AppearancePresenter.kt @@ -0,0 +1,45 @@ +package io.github.wulkanowy.ui.modules.settings.appearance + +import io.github.wulkanowy.data.repositories.PreferencesRepository +import io.github.wulkanowy.data.repositories.StudentRepository +import io.github.wulkanowy.ui.base.BasePresenter +import io.github.wulkanowy.ui.base.ErrorHandler +import io.github.wulkanowy.utils.AnalyticsHelper +import io.github.wulkanowy.utils.AppInfo +import timber.log.Timber +import javax.inject.Inject + +class AppearancePresenter @Inject constructor( + errorHandler: ErrorHandler, + studentRepository: StudentRepository, + private val preferencesRepository: PreferencesRepository, + private val analytics: AnalyticsHelper, + private val appInfo: AppInfo +) : BasePresenter(errorHandler, studentRepository) { + + override fun onAttachView(view: AppearanceView) { + super.onAttachView(view) + Timber.i("Settings appearance view was initialized") + } + + fun onSharedPreferenceChanged(key: String) { + Timber.i("Change settings $key") + + preferencesRepository.apply { + when (key) { + appThemeKey -> view?.recreateView() + appLanguageKey -> view?.run { + if (appLanguage == "system") { + updateLanguageToFollowSystem() + analytics.logEvent("language", "setting_changed" to appInfo.systemLanguage) + } else { + updateLanguage(appLanguage) + analytics.logEvent("language", "setting_changed" to appLanguage) + } + recreateView() + } + } + } + analytics.logEvent("setting_changed", "name" to key) + } +} diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/appearance/AppearanceView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/appearance/AppearanceView.kt new file mode 100644 index 00000000..ecee4f42 --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/appearance/AppearanceView.kt @@ -0,0 +1,12 @@ +package io.github.wulkanowy.ui.modules.settings.appearance + +import io.github.wulkanowy.ui.base.BaseView + +interface AppearanceView : BaseView { + + fun recreateView() + + fun updateLanguage(langCode: String) + + fun updateLanguageToFollowSystem() +} diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsFragment.kt new file mode 100644 index 00000000..a9641d88 --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsFragment.kt @@ -0,0 +1,130 @@ +package io.github.wulkanowy.ui.modules.settings.notifications + +import android.content.SharedPreferences +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.appcompat.app.AlertDialog +import androidx.preference.Preference +import androidx.preference.PreferenceFragmentCompat +import androidx.recyclerview.widget.RecyclerView +import com.thelittlefireman.appkillermanager.AppKillerManager +import com.thelittlefireman.appkillermanager.exceptions.NoActionFoundException +import dagger.hilt.android.AndroidEntryPoint +import io.github.wulkanowy.R +import io.github.wulkanowy.ui.base.BaseActivity +import io.github.wulkanowy.ui.base.ErrorDialog +import io.github.wulkanowy.ui.modules.main.MainView +import io.github.wulkanowy.utils.openInternetBrowser +import javax.inject.Inject + +@AndroidEntryPoint +class NotificationsFragment : PreferenceFragmentCompat(), + SharedPreferences.OnSharedPreferenceChangeListener, + MainView.TitledView, NotificationsView { + + @Inject + lateinit var presenter: NotificationsPresenter + + companion object { + fun newInstance() = NotificationsFragment() + } + + override val titleStringId get() = R.string.pref_settings_notifications_title + + override fun initView(showDebugNotificationSwitch: Boolean) { + findPreference(getString(R.string.pref_key_notification_debug))?.isVisible = + showDebugNotificationSwitch + + findPreference(getString(R.string.pref_key_notifications_fix_issues))?.run { + isVisible = AppKillerManager.isDeviceSupported() + && AppKillerManager.isAnyActionAvailable(requireContext()) + + setOnPreferenceClickListener { + presenter.onFixSyncIssuesClicked() + true + } + } + } + + override fun onCreateRecyclerView( + inflater: LayoutInflater?, + parent: ViewGroup?, + state: Bundle? + ): RecyclerView? = super.onCreateRecyclerView(inflater, parent, state) + .also { + it.itemAnimator = null + it.layoutAnimation = null + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + presenter.onAttachView(this) + } + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + setPreferencesFromResource(R.xml.scheme_preferences_notifications, rootKey) + } + + override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) { + presenter.onSharedPreferenceChanged(key) + } + + override fun enableNotification(notificationKey: String, enable: Boolean) { + findPreference(notificationKey)?.run { + isEnabled = enable + summary = if (enable) null else getString(R.string.pref_notify_disabled_summary) + } + } + + override fun showError(text: String, error: Throwable) { + (activity as? BaseActivity<*, *>)?.showError(text, error) + } + + override fun showMessage(text: String) { + (activity as? BaseActivity<*, *>)?.showMessage(text) + } + + override fun showExpiredDialog() { + (activity as? BaseActivity<*, *>)?.showExpiredDialog() + } + + override fun openClearLoginView() { + (activity as? BaseActivity<*, *>)?.openClearLoginView() + } + + override fun showErrorDetailsDialog(error: Throwable) { + ErrorDialog.newInstance(error).show(childFragmentManager, error.toString()) + } + + override fun showFixSyncDialog() { + AlertDialog.Builder(requireContext()) + .setTitle(R.string.pref_notify_fix_sync_issues) + .setMessage(R.string.pref_notify_fix_sync_issues_message) + .setNegativeButton(android.R.string.cancel) { _, _ -> } + .setPositiveButton(R.string.pref_notify_fix_sync_issues_settings_button) { _, _ -> + try { + AppKillerManager.doActionPowerSaving(requireContext()) + AppKillerManager.doActionAutoStart(requireContext()) + AppKillerManager.doActionNotification(requireContext()) + } catch (e: NoActionFoundException) { + requireContext().openInternetBrowser( + "https://dontkillmyapp.com/${AppKillerManager.getDevice()?.manufacturer}", + ::showMessage + ) + } + } + .show() + } + + override fun onResume() { + super.onResume() + preferenceScreen.sharedPreferences.registerOnSharedPreferenceChangeListener(this) + } + + override fun onPause() { + super.onPause() + preferenceScreen.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) + } +} diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsPresenter.kt new file mode 100644 index 00000000..981af17d --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsPresenter.kt @@ -0,0 +1,58 @@ +package io.github.wulkanowy.ui.modules.settings.notifications + +import com.chuckerteam.chucker.api.ChuckerCollector +import io.github.wulkanowy.data.repositories.PreferencesRepository +import io.github.wulkanowy.data.repositories.StudentRepository +import io.github.wulkanowy.services.alarm.TimetableNotificationSchedulerHelper +import io.github.wulkanowy.ui.base.BasePresenter +import io.github.wulkanowy.ui.base.ErrorHandler +import io.github.wulkanowy.utils.AnalyticsHelper +import io.github.wulkanowy.utils.AppInfo +import timber.log.Timber +import javax.inject.Inject + +class NotificationsPresenter @Inject constructor( + errorHandler: ErrorHandler, + studentRepository: StudentRepository, + private val preferencesRepository: PreferencesRepository, + private val timetableNotificationHelper: TimetableNotificationSchedulerHelper, + private val appInfo: AppInfo, + private val analytics: AnalyticsHelper, + private val chuckerCollector: ChuckerCollector +) : BasePresenter(errorHandler, studentRepository) { + + override fun onAttachView(view: NotificationsView) { + super.onAttachView(view) + + with(view) { + enableNotification( + preferencesRepository.notificationsEnableKey, + preferencesRepository.isServiceEnabled + ) + initView(appInfo.isDebug) + } + Timber.i("Settings notifications view was initialized") + } + + fun onSharedPreferenceChanged(key: String) { + Timber.i("Change settings $key") + + preferencesRepository.apply { + when (key) { + isUpcomingLessonsNotificationsEnableKey -> { + if (!isUpcomingLessonsNotificationsEnable) { + timetableNotificationHelper.cancelNotification() + } + } + isDebugNotificationEnableKey -> { + chuckerCollector.showNotification = isDebugNotificationEnable + } + } + } + analytics.logEvent("setting_changed", "name" to key) + } + + fun onFixSyncIssuesClicked() { + view?.showFixSyncDialog() + } +} diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsView.kt new file mode 100644 index 00000000..2618cde1 --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/notifications/NotificationsView.kt @@ -0,0 +1,12 @@ +package io.github.wulkanowy.ui.modules.settings.notifications + +import io.github.wulkanowy.ui.base.BaseView + +interface NotificationsView : BaseView { + + fun initView(showDebugNotificationSwitch: Boolean) + + fun showFixSyncDialog() + + fun enableNotification(notificationKey: String, enable: Boolean) +} diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/sync/SyncFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/sync/SyncFragment.kt new file mode 100644 index 00000000..207fe2ff --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/sync/SyncFragment.kt @@ -0,0 +1,100 @@ +package io.github.wulkanowy.ui.modules.settings.sync + +import android.content.SharedPreferences +import android.os.Bundle +import android.view.View +import androidx.preference.Preference +import androidx.preference.PreferenceFragmentCompat +import dagger.hilt.android.AndroidEntryPoint +import io.github.wulkanowy.R +import io.github.wulkanowy.ui.base.BaseActivity +import io.github.wulkanowy.ui.base.ErrorDialog +import io.github.wulkanowy.ui.modules.main.MainView +import javax.inject.Inject + +@AndroidEntryPoint +class SyncFragment : PreferenceFragmentCompat(), + SharedPreferences.OnSharedPreferenceChangeListener, + MainView.TitledView, SyncView { + + @Inject + lateinit var presenter: SyncPresenter + + companion object { + fun newInstance() = SyncFragment() + } + + override val titleStringId get() = R.string.pref_settings_sync_title + + override val syncSuccessString get() = getString(R.string.pref_services_message_sync_success) + + override val syncFailedString get() = getString(R.string.pref_services_message_sync_failed) + + override fun initView() { + findPreference(getString(R.string.pref_key_services_force_sync))?.run { + onPreferenceClickListener = Preference.OnPreferenceClickListener { + presenter.onSyncNowClicked() + true + } + } + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + presenter.onAttachView(this) + } + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + setPreferencesFromResource(R.xml.scheme_preferences_sync, rootKey) + } + + override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) { + presenter.onSharedPreferenceChanged(key) + } + + override fun setServicesSuspended(serviceEnablesKey: String, isHolidays: Boolean) { + findPreference(serviceEnablesKey)?.run { + summary = if (isHolidays) getString(R.string.pref_services_suspended) else "" + isEnabled = !isHolidays + } + } + + override fun setSyncInProgress(inProgress: Boolean) { + if (activity == null || !isAdded) return + + findPreference(getString(R.string.pref_key_services_force_sync))?.run { + isEnabled = !inProgress + summary = if (inProgress) getString(R.string.pref_services_sync_in_progress) else "" + } + } + + override fun showError(text: String, error: Throwable) { + (activity as? BaseActivity<*, *>)?.showError(text, error) + } + + override fun showMessage(text: String) { + (activity as? BaseActivity<*, *>)?.showMessage(text) + } + + override fun showExpiredDialog() { + (activity as? BaseActivity<*, *>)?.showExpiredDialog() + } + + override fun openClearLoginView() { + (activity as? BaseActivity<*, *>)?.openClearLoginView() + } + + override fun showErrorDetailsDialog(error: Throwable) { + ErrorDialog.newInstance(error).show(childFragmentManager, error.toString()) + } + + override fun onResume() { + super.onResume() + preferenceScreen.sharedPreferences.registerOnSharedPreferenceChangeListener(this) + } + + override fun onPause() { + super.onPause() + preferenceScreen.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) + } +} diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/sync/SyncPresenter.kt similarity index 63% rename from app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsPresenter.kt rename to app/src/main/java/io/github/wulkanowy/ui/modules/settings/sync/SyncPresenter.kt index e3b2e232..36b8d792 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/sync/SyncPresenter.kt @@ -1,15 +1,12 @@ -package io.github.wulkanowy.ui.modules.settings +package io.github.wulkanowy.ui.modules.settings.sync import androidx.work.WorkInfo -import com.chuckerteam.chucker.api.ChuckerCollector import io.github.wulkanowy.data.repositories.PreferencesRepository import io.github.wulkanowy.data.repositories.StudentRepository -import io.github.wulkanowy.services.alarm.TimetableNotificationSchedulerHelper import io.github.wulkanowy.services.sync.SyncManager import io.github.wulkanowy.ui.base.BasePresenter import io.github.wulkanowy.ui.base.ErrorHandler import io.github.wulkanowy.utils.AnalyticsHelper -import io.github.wulkanowy.utils.AppInfo import io.github.wulkanowy.utils.isHolidays import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.onEach @@ -17,20 +14,17 @@ import timber.log.Timber import java.time.LocalDate.now import javax.inject.Inject -class SettingsPresenter @Inject constructor( +class SyncPresenter @Inject constructor( errorHandler: ErrorHandler, studentRepository: StudentRepository, private val preferencesRepository: PreferencesRepository, - private val timetableNotificationHelper: TimetableNotificationSchedulerHelper, private val analytics: AnalyticsHelper, private val syncManager: SyncManager, - private val chuckerCollector: ChuckerCollector, - private val appInfo: AppInfo -) : BasePresenter(errorHandler, studentRepository) { +) : BasePresenter(errorHandler, studentRepository) { - override fun onAttachView(view: SettingsView) { + override fun onAttachView(view: SyncView) { super.onAttachView(view) - Timber.i("Settings view was initialized") + Timber.i("Settings sync view was initialized") view.setServicesSuspended(preferencesRepository.serviceEnableKey, now().isHolidays) view.initView() } @@ -42,20 +36,6 @@ class SettingsPresenter @Inject constructor( when (key) { serviceEnableKey -> with(syncManager) { if (isServiceEnabled) startPeriodicSyncWorker() else stopSyncWorker() } servicesIntervalKey, servicesOnlyWifiKey -> syncManager.startPeriodicSyncWorker(true) - isDebugNotificationEnableKey -> chuckerCollector.showNotification = - isDebugNotificationEnable - appThemeKey -> view?.recreateView() - isUpcomingLessonsNotificationsEnableKey -> if (!isUpcomingLessonsNotificationsEnable) timetableNotificationHelper.cancelNotification() - appLanguageKey -> view?.run { - if (appLanguage == "system") { - updateLanguageToFollowSystem() - analytics.logEvent("language", "setting_changed" to appInfo.systemLanguage) - } else { - updateLanguage(appLanguage) - analytics.logEvent("language", "setting_changed" to appLanguage) - } - recreateView() - } } } analytics.logEvent("setting_changed", "name" to key) @@ -89,8 +69,4 @@ class SettingsPresenter @Inject constructor( }.launch("sync") } } - - fun onFixSyncIssuesClicked() { - view?.showFixSyncDialog() - } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/sync/SyncView.kt similarity index 54% rename from app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsView.kt rename to app/src/main/java/io/github/wulkanowy/ui/modules/settings/sync/SyncView.kt index 80271741..9da473ba 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsView.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/sync/SyncView.kt @@ -1,8 +1,8 @@ -package io.github.wulkanowy.ui.modules.settings +package io.github.wulkanowy.ui.modules.settings.sync import io.github.wulkanowy.ui.base.BaseView -interface SettingsView : BaseView { +interface SyncView : BaseView { val syncSuccessString: String @@ -10,15 +10,7 @@ interface SettingsView : BaseView { fun initView() - fun recreateView() - - fun updateLanguage(langCode: String) - - fun updateLanguageToFollowSystem() - fun setServicesSuspended(serviceEnablesKey: String, isHolidays: Boolean) fun setSyncInProgress(inProgress: Boolean) - - fun showFixSyncDialog() } diff --git a/app/src/main/res/drawable/ic_all_about.xml b/app/src/main/res/drawable/ic_all_about.xml index 3dfbbda1..3868f85c 100644 --- a/app/src/main/res/drawable/ic_all_about.xml +++ b/app/src/main/res/drawable/ic_all_about.xml @@ -2,6 +2,7 @@ android:width="24dp" android:height="24dp" android:viewportWidth="24" + android:tint="?colorOnSurface" android:viewportHeight="24"> + + + diff --git a/app/src/main/res/drawable/ic_settings_appearance.xml b/app/src/main/res/drawable/ic_settings_appearance.xml new file mode 100644 index 00000000..afea27f2 --- /dev/null +++ b/app/src/main/res/drawable/ic_settings_appearance.xml @@ -0,0 +1,22 @@ + + + + + + + diff --git a/app/src/main/res/drawable/ic_settings_notifications.xml b/app/src/main/res/drawable/ic_settings_notifications.xml new file mode 100644 index 00000000..f4ff247f --- /dev/null +++ b/app/src/main/res/drawable/ic_settings_notifications.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_settings_sync.xml b/app/src/main/res/drawable/ic_settings_sync.xml new file mode 100644 index 00000000..3697ac0b --- /dev/null +++ b/app/src/main/res/drawable/ic_settings_sync.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 2f88ecc8..2ea0a4d3 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,5 +1,5 @@ - + app:contentInsetStartWithNavigation="0dp" /> + android:layout_height="match_parent" + android:layout_marginTop="?actionBarSize" + android:layout_marginBottom="@dimen/bottom_navigation_height" /> - + android:layout_gravity="bottom" /> + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a7b7004d..9f15c008 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -464,21 +464,21 @@ - Appearance + App apearance & behavior Default view Calculation of the end-of-year average Force average calculation by app - Show presence in attendance - Application theme + Show presence + Theme Expand grades - Mark current lesson in timetable - Show groups next to subjects in timetable + Mark current lesson + Show groups next to subjects Show chart list in class grades Show whole class lessons - Show subjects without grades in Grades + Show subjects without grades Grades color scheme - Subjects sorting in "Grades" - App language + Subjects sorting + Language Notifications Show notifications @@ -487,6 +487,7 @@ Your device may have data synchronization issues and with notifications.\n\nTo fix them, you need to add Wulkanowy to the autostart and turn off battery optimization/saving in the phone settings. Go to settings Show debug notifications + Synchronization is disabled Synchronization Automatic update @@ -497,17 +498,32 @@ Synced! Sync failed Sync in progress - Synchronization - - Manual sync doesn\'t refresh app views. - \nTo see the synced data relaunch the app after syncing. - - Other Value of the plus Value of the minus Reply with message history + Advanced + Appearance & Behavior + Notifications + Synchronization + + Grades + Attendance + Timetable + Grades + Messages + + Appearance & Behavior + Languages, themes, subjects sorting + App notifications, fix problems + Notifications + Synchronization + Automatic update, synchronization interval + Plus and minus values, average calculation + Advanced + App version, contributors, social portals, licenses + New entries in register diff --git a/app/src/main/res/xml/scheme_preferences.xml b/app/src/main/res/xml/scheme_preferences.xml index 3f24c787..08621492 100644 --- a/app/src/main/res/xml/scheme_preferences.xml +++ b/app/src/main/res/xml/scheme_preferences.xml @@ -1,182 +1,33 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/app/src/main/res/xml/scheme_preferences_advanced.xml b/app/src/main/res/xml/scheme_preferences_advanced.xml new file mode 100644 index 00000000..1d7e9b83 --- /dev/null +++ b/app/src/main/res/xml/scheme_preferences_advanced.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/xml/scheme_preferences_appearance.xml b/app/src/main/res/xml/scheme_preferences_appearance.xml new file mode 100644 index 00000000..095c5070 --- /dev/null +++ b/app/src/main/res/xml/scheme_preferences_appearance.xml @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/xml/scheme_preferences_notifications.xml b/app/src/main/res/xml/scheme_preferences_notifications.xml new file mode 100644 index 00000000..3d435ca8 --- /dev/null +++ b/app/src/main/res/xml/scheme_preferences_notifications.xml @@ -0,0 +1,29 @@ + + + + + + + + + diff --git a/app/src/main/res/xml/scheme_preferences_sync.xml b/app/src/main/res/xml/scheme_preferences_sync.xml new file mode 100644 index 00000000..b6c3c2a8 --- /dev/null +++ b/app/src/main/res/xml/scheme_preferences_sync.xml @@ -0,0 +1,31 @@ + + + + + + + + +