From dbc7587741ba6c6181fd84b585b1124b0fdcef36 Mon Sep 17 00:00:00 2001 From: Michael <5672750+mibac138@users.noreply.github.com> Date: Wed, 24 Apr 2024 22:44:59 +0200 Subject: [PATCH] Add settings button to attendance calculator (#2492) --- .../AttendanceCalculatorFragment.kt | 30 ++++++++++++++++++- .../AttendanceCalculatorPresenter.kt | 12 +++++++- .../calculator/AttendanceCalculatorView.kt | 2 ++ .../settings/appearance/AppearanceFragment.kt | 10 +++++++ .../action_menu_attendance_calculator.xml | 11 +++++++ app/src/main/res/values/preferences_keys.xml | 1 + app/src/main/res/values/strings.xml | 2 ++ .../res/xml/scheme_preferences_appearance.xml | 5 ++++ 8 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/menu/action_menu_attendance_calculator.xml diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/calculator/AttendanceCalculatorFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/calculator/AttendanceCalculatorFragment.kt index 2d5667015..63d1d8be5 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/calculator/AttendanceCalculatorFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/calculator/AttendanceCalculatorFragment.kt @@ -1,6 +1,9 @@ package io.github.wulkanowy.ui.modules.attendance.calculator import android.os.Bundle +import android.view.Menu +import android.view.MenuInflater +import android.view.MenuItem import android.view.View import androidx.core.view.isVisible import androidx.recyclerview.widget.LinearLayoutManager @@ -9,7 +12,9 @@ import io.github.wulkanowy.R import io.github.wulkanowy.data.pojos.AttendanceData import io.github.wulkanowy.databinding.FragmentAttendanceCalculatorBinding import io.github.wulkanowy.ui.base.BaseFragment +import io.github.wulkanowy.ui.modules.main.MainActivity import io.github.wulkanowy.ui.modules.main.MainView +import io.github.wulkanowy.ui.modules.settings.appearance.AppearanceFragment import io.github.wulkanowy.ui.widgets.DividerItemDecoration import io.github.wulkanowy.utils.getThemeAttrColor import javax.inject.Inject @@ -33,6 +38,12 @@ class AttendanceCalculatorFragment : override val isViewEmpty get() = attendanceCalculatorAdapter.items.isEmpty() + @Suppress("DEPRECATION") + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setHasOptionsMenu(true) + } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding = FragmentAttendanceCalculatorBinding.bind(view) @@ -40,6 +51,19 @@ class AttendanceCalculatorFragment : presenter.onAttachView(this) } + override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { + inflater.inflate(R.menu.action_menu_attendance_calculator, menu) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + return if (item.itemId == R.id.attendance_calculator_menu_settings) presenter.onSettingsSelected() + else false + } + + override fun openSettingsView() { + (activity as? MainActivity)?.pushView(AppearanceFragment.withFocusedPreference(getString(R.string.pref_key_attendance_target))) + } + override fun initView() { with(binding.attendanceCalculatorRecycler) { layoutManager = LinearLayoutManager(context) @@ -50,7 +74,11 @@ class AttendanceCalculatorFragment : with(binding) { attendanceCalculatorSwipe.setOnRefreshListener(presenter::onSwipeRefresh) attendanceCalculatorSwipe.setColorSchemeColors(requireContext().getThemeAttrColor(R.attr.colorPrimary)) - attendanceCalculatorSwipe.setProgressBackgroundColorSchemeColor(requireContext().getThemeAttrColor(R.attr.colorSwipeRefresh)) + attendanceCalculatorSwipe.setProgressBackgroundColorSchemeColor( + requireContext().getThemeAttrColor( + R.attr.colorSwipeRefresh + ) + ) attendanceCalculatorErrorRetry.setOnClickListener { presenter.onRetry() } attendanceCalculatorErrorDetails.setOnClickListener { presenter.onDetailsClick() } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/calculator/AttendanceCalculatorPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/calculator/AttendanceCalculatorPresenter.kt index d292e5650..29cb2197f 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/calculator/AttendanceCalculatorPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/calculator/AttendanceCalculatorPresenter.kt @@ -1,6 +1,11 @@ package io.github.wulkanowy.ui.modules.attendance.calculator -import io.github.wulkanowy.data.* +import io.github.wulkanowy.data.flatResourceFlow +import io.github.wulkanowy.data.logResourceStatus +import io.github.wulkanowy.data.onResourceData +import io.github.wulkanowy.data.onResourceError +import io.github.wulkanowy.data.onResourceIntermediate +import io.github.wulkanowy.data.onResourceNotLoading import io.github.wulkanowy.data.repositories.SemesterRepository import io.github.wulkanowy.data.repositories.StudentRepository import io.github.wulkanowy.domain.attendance.GetAttendanceCalculatorDataUseCase @@ -81,4 +86,9 @@ class AttendanceCalculatorPresenter @Inject constructor( } else showError(message, error) } } + + fun onSettingsSelected(): Boolean { + view?.openSettingsView() + return true + } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/calculator/AttendanceCalculatorView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/calculator/AttendanceCalculatorView.kt index 94e661212..21afe532e 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/calculator/AttendanceCalculatorView.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/calculator/AttendanceCalculatorView.kt @@ -26,4 +26,6 @@ interface AttendanceCalculatorView : BaseView { fun updateData(data: List) fun clearView() + + fun openSettingsView() } 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 index ba234aae2..62544f83e 100644 --- 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 @@ -3,6 +3,7 @@ package io.github.wulkanowy.ui.modules.settings.appearance import android.content.SharedPreferences import android.os.Bundle import android.view.View +import androidx.core.os.bundleOf import androidx.preference.PreferenceFragmentCompat import androidx.preference.SeekBarPreference import com.yariksoffice.lingver.Lingver @@ -30,9 +31,18 @@ class AppearanceFragment : PreferenceFragmentCompat(), override val titleStringId get() = R.string.pref_settings_appearance_title + companion object { + fun withFocusedPreference(key: String) = AppearanceFragment().apply { + arguments = bundleOf(FOCUSED_KEY to key) + } + + private const val FOCUSED_KEY = "focusedKey" + } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) presenter.onAttachView(this) + arguments?.getString(FOCUSED_KEY)?.let { scrollToPreference(it) } } override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { diff --git a/app/src/main/res/menu/action_menu_attendance_calculator.xml b/app/src/main/res/menu/action_menu_attendance_calculator.xml new file mode 100644 index 000000000..c50906901 --- /dev/null +++ b/app/src/main/res/menu/action_menu_attendance_calculator.xml @@ -0,0 +1,11 @@ + + + + diff --git a/app/src/main/res/values/preferences_keys.xml b/app/src/main/res/values/preferences_keys.xml index 080456ef9..e87e9854a 100644 --- a/app/src/main/res/values/preferences_keys.xml +++ b/app/src/main/res/values/preferences_keys.xml @@ -1,6 +1,7 @@ default_menu_index + attendance_calculator attendance_present attendance_target attendance_calculator_sorting_mode diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9175321d3..a8e159ec6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -796,6 +796,8 @@ Dashboard Tiles visibility Attendance + Attendance calculator + Settings Timetable Grades Calculated average diff --git a/app/src/main/res/xml/scheme_preferences_appearance.xml b/app/src/main/res/xml/scheme_preferences_appearance.xml index a05d95c04..1ca4d2048 100644 --- a/app/src/main/res/xml/scheme_preferences_appearance.xml +++ b/app/src/main/res/xml/scheme_preferences_appearance.xml @@ -85,6 +85,11 @@ app:iconSpaceReserved="false" app:key="@string/pref_key_attendance_present" app:title="@string/pref_view_present" /> + +