mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2024-11-13 22:40:28 -06:00
Add settings button to attendance calculator (#2492)
This commit is contained in:
parent
bc3aa7b8dc
commit
dbc7587741
@ -1,6 +1,9 @@
|
|||||||
package io.github.wulkanowy.ui.modules.attendance.calculator
|
package io.github.wulkanowy.ui.modules.attendance.calculator
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuInflater
|
||||||
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
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.data.pojos.AttendanceData
|
||||||
import io.github.wulkanowy.databinding.FragmentAttendanceCalculatorBinding
|
import io.github.wulkanowy.databinding.FragmentAttendanceCalculatorBinding
|
||||||
import io.github.wulkanowy.ui.base.BaseFragment
|
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.main.MainView
|
||||||
|
import io.github.wulkanowy.ui.modules.settings.appearance.AppearanceFragment
|
||||||
import io.github.wulkanowy.ui.widgets.DividerItemDecoration
|
import io.github.wulkanowy.ui.widgets.DividerItemDecoration
|
||||||
import io.github.wulkanowy.utils.getThemeAttrColor
|
import io.github.wulkanowy.utils.getThemeAttrColor
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -33,6 +38,12 @@ class AttendanceCalculatorFragment :
|
|||||||
|
|
||||||
override val isViewEmpty get() = attendanceCalculatorAdapter.items.isEmpty()
|
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?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
binding = FragmentAttendanceCalculatorBinding.bind(view)
|
binding = FragmentAttendanceCalculatorBinding.bind(view)
|
||||||
@ -40,6 +51,19 @@ class AttendanceCalculatorFragment :
|
|||||||
presenter.onAttachView(this)
|
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() {
|
override fun initView() {
|
||||||
with(binding.attendanceCalculatorRecycler) {
|
with(binding.attendanceCalculatorRecycler) {
|
||||||
layoutManager = LinearLayoutManager(context)
|
layoutManager = LinearLayoutManager(context)
|
||||||
@ -50,7 +74,11 @@ class AttendanceCalculatorFragment :
|
|||||||
with(binding) {
|
with(binding) {
|
||||||
attendanceCalculatorSwipe.setOnRefreshListener(presenter::onSwipeRefresh)
|
attendanceCalculatorSwipe.setOnRefreshListener(presenter::onSwipeRefresh)
|
||||||
attendanceCalculatorSwipe.setColorSchemeColors(requireContext().getThemeAttrColor(R.attr.colorPrimary))
|
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() }
|
attendanceCalculatorErrorRetry.setOnClickListener { presenter.onRetry() }
|
||||||
attendanceCalculatorErrorDetails.setOnClickListener { presenter.onDetailsClick() }
|
attendanceCalculatorErrorDetails.setOnClickListener { presenter.onDetailsClick() }
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
package io.github.wulkanowy.ui.modules.attendance.calculator
|
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.SemesterRepository
|
||||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||||
import io.github.wulkanowy.domain.attendance.GetAttendanceCalculatorDataUseCase
|
import io.github.wulkanowy.domain.attendance.GetAttendanceCalculatorDataUseCase
|
||||||
@ -81,4 +86,9 @@ class AttendanceCalculatorPresenter @Inject constructor(
|
|||||||
} else showError(message, error)
|
} else showError(message, error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onSettingsSelected(): Boolean {
|
||||||
|
view?.openSettingsView()
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,4 +26,6 @@ interface AttendanceCalculatorView : BaseView {
|
|||||||
fun updateData(data: List<AttendanceData>)
|
fun updateData(data: List<AttendanceData>)
|
||||||
|
|
||||||
fun clearView()
|
fun clearView()
|
||||||
|
|
||||||
|
fun openSettingsView()
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package io.github.wulkanowy.ui.modules.settings.appearance
|
|||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import androidx.core.os.bundleOf
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
import androidx.preference.SeekBarPreference
|
import androidx.preference.SeekBarPreference
|
||||||
import com.yariksoffice.lingver.Lingver
|
import com.yariksoffice.lingver.Lingver
|
||||||
@ -30,9 +31,18 @@ class AppearanceFragment : PreferenceFragmentCompat(),
|
|||||||
|
|
||||||
override val titleStringId get() = R.string.pref_settings_appearance_title
|
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?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
presenter.onAttachView(this)
|
presenter.onAttachView(this)
|
||||||
|
arguments?.getString(FOCUSED_KEY)?.let { scrollToPreference(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
|
11
app/src/main/res/menu/action_menu_attendance_calculator.xml
Normal file
11
app/src/main/res/menu/action_menu_attendance_calculator.xml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<item
|
||||||
|
android:id="@+id/attendance_calculator_menu_settings"
|
||||||
|
android:icon="@drawable/ic_more_settings"
|
||||||
|
android:orderInCategory="2"
|
||||||
|
android:title="@string/pref_attendance_calculator_appearance_settings_title"
|
||||||
|
app:iconTint="?colorControlNormal"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
|
</menu>
|
@ -1,6 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
|
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
|
||||||
<string name="pref_key_start_menu">default_menu_index</string>
|
<string name="pref_key_start_menu">default_menu_index</string>
|
||||||
|
<string name="pref_key_attendance_calculator">attendance_calculator</string>
|
||||||
<string name="pref_key_attendance_present">attendance_present</string>
|
<string name="pref_key_attendance_present">attendance_present</string>
|
||||||
<string name="pref_key_attendance_target">attendance_target</string>
|
<string name="pref_key_attendance_target">attendance_target</string>
|
||||||
<string name="pref_key_attendance_calculator_sorting_mode">attendance_calculator_sorting_mode</string>
|
<string name="pref_key_attendance_calculator_sorting_mode">attendance_calculator_sorting_mode</string>
|
||||||
|
@ -796,6 +796,8 @@
|
|||||||
<string name="pref_dashboard_appearance_header">Dashboard</string>
|
<string name="pref_dashboard_appearance_header">Dashboard</string>
|
||||||
<string name="pref_dashboard_appearance_tiles_title">Tiles visibility</string>
|
<string name="pref_dashboard_appearance_tiles_title">Tiles visibility</string>
|
||||||
<string name="pref_attendance_appearance_view">Attendance</string>
|
<string name="pref_attendance_appearance_view">Attendance</string>
|
||||||
|
<string name="pref_attendance_calculator_appearance_view">Attendance calculator</string>
|
||||||
|
<string name="pref_attendance_calculator_appearance_settings_title">Settings</string>
|
||||||
<string name="pref_timetable_appearance_view">Timetable</string>
|
<string name="pref_timetable_appearance_view">Timetable</string>
|
||||||
<string name="pref_grades_advanced_header">Grades</string>
|
<string name="pref_grades_advanced_header">Grades</string>
|
||||||
<string name="pref_counted_average_advanced_header">Calculated average</string>
|
<string name="pref_counted_average_advanced_header">Calculated average</string>
|
||||||
|
@ -85,6 +85,11 @@
|
|||||||
app:iconSpaceReserved="false"
|
app:iconSpaceReserved="false"
|
||||||
app:key="@string/pref_key_attendance_present"
|
app:key="@string/pref_key_attendance_present"
|
||||||
app:title="@string/pref_view_present" />
|
app:title="@string/pref_view_present" />
|
||||||
|
</PreferenceCategory>
|
||||||
|
<PreferenceCategory
|
||||||
|
app:iconSpaceReserved="false"
|
||||||
|
app:title="@string/pref_attendance_calculator_appearance_view"
|
||||||
|
app:key="@string/pref_key_attendance_calculator">
|
||||||
<SeekBarPreference
|
<SeekBarPreference
|
||||||
app:defaultValue="@integer/pref_default_attendance_target"
|
app:defaultValue="@integer/pref_default_attendance_target"
|
||||||
app:iconSpaceReserved="false"
|
app:iconSpaceReserved="false"
|
||||||
|
Loading…
Reference in New Issue
Block a user