1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2025-01-31 15:54:38 +01:00

Add preference for the expandable grades (#178)

This commit is contained in:
Rafał Borcz 2018-11-10 23:29:18 +01:00 committed by Mikołaj Pich
parent 2b60f555e9
commit 240e61df0e
12 changed files with 45 additions and 26 deletions

View File

@ -11,13 +11,15 @@ class PreferencesRepository @Inject constructor(
private val sharedPref: SharedPreferences, private val sharedPref: SharedPreferences,
val context: Context val context: Context
) { ) {
val startMenuIndex: Int val startMenuIndex: Int
get() = sharedPref.getString(context.getString(R.string.pref_key_start_menu), "0")?.toInt() ?: 0 get() = sharedPref.getString(context.getString(R.string.pref_key_start_menu), "0")?.toInt() ?: 0
val showPresent: Boolean val isShowPresent: Boolean
get() = sharedPref.getBoolean(context.getString(R.string.pref_key_attendance_present), true) get() = sharedPref.getBoolean(context.getString(R.string.pref_key_attendance_present), true)
val isGradeExpandable: Boolean
get() = !sharedPref.getBoolean(context.getString(R.string.pref_key_expand_grade), false)
val currentThemeKey: String = context.getString(R.string.pref_key_theme) val currentThemeKey: String = context.getString(R.string.pref_key_theme)
val currentTheme: Int val currentTheme: Int
get() = sharedPref.getString(currentThemeKey, "1")?.toInt() ?: 1 get() = sharedPref.getString(currentThemeKey, "1")?.toInt() ?: 1
@ -26,7 +28,7 @@ class PreferencesRepository @Inject constructor(
get() = sharedPref.getString(context.getString(R.string.pref_key_grade_modifier), "0.0")?.toDouble() ?: 0.0 get() = sharedPref.getString(context.getString(R.string.pref_key_grade_modifier), "0.0")?.toDouble() ?: 0.0
val serviceEnablesKey: String = context.getString(R.string.pref_key_services_enable) val serviceEnablesKey: String = context.getString(R.string.pref_key_services_enable)
val serviceEnabled: Boolean val isServiceEnabled: Boolean
get() = sharedPref.getBoolean(serviceEnablesKey, true) get() = sharedPref.getBoolean(serviceEnablesKey, true)
val servicesIntervalKey: String = context.getString(R.string.pref_key_services_interval) val servicesIntervalKey: String = context.getString(R.string.pref_key_services_interval)
@ -34,9 +36,9 @@ class PreferencesRepository @Inject constructor(
get() = sharedPref.getString(servicesIntervalKey, "60")?.toInt() ?: 60 get() = sharedPref.getString(servicesIntervalKey, "60")?.toInt() ?: 60
val servicesOnlyWifiKey: String = context.getString(R.string.pref_key_services_wifi_only) val servicesOnlyWifiKey: String = context.getString(R.string.pref_key_services_wifi_only)
val servicesOnlyWifi: Boolean val isServicesOnlyWifi: Boolean
get() = sharedPref.getBoolean(servicesOnlyWifiKey, true) get() = sharedPref.getBoolean(servicesOnlyWifiKey, true)
val notificationsEnable: Boolean val isNotificationsEnable: Boolean
get() = sharedPref.getBoolean(context.getString(R.string.pref_key_notifications_enable), true) get() = sharedPref.getBoolean(context.getString(R.string.pref_key_notifications_enable), true)
} }

View File

@ -24,7 +24,7 @@ class ServiceHelper @Inject constructor(
} }
fun startFullSyncService(replaceCurrent: Boolean = false) { fun startFullSyncService(replaceCurrent: Boolean = false) {
if (LocalDate.now().isHolidays || !prefRepository.serviceEnabled) { if (LocalDate.now().isHolidays || !prefRepository.isServiceEnabled) {
Timber.d("Services disabled or it's holidays") Timber.d("Services disabled or it's holidays")
return return
} }
@ -41,7 +41,7 @@ class ServiceHelper @Inject constructor(
(prefRepository.servicesInterval + 10) * 60 (prefRepository.servicesInterval + 10) * 60
) )
) )
.setConstraints(if (prefRepository.servicesOnlyWifi) ON_UNMETERED_NETWORK else ON_ANY_NETWORK) .setConstraints(if (prefRepository.isServicesOnlyWifi) ON_UNMETERED_NETWORK else ON_ANY_NETWORK)
.setReplaceCurrent(replaceCurrent) .setReplaceCurrent(replaceCurrent)
.setRetryStrategy(DEFAULT_EXPONENTIAL) .setRetryStrategy(DEFAULT_EXPONENTIAL)
.build() .build()

View File

@ -80,7 +80,7 @@ class SyncWorker : SimpleJobService() {
.subscribe({}, { error = it })) .subscribe({}, { error = it }))
return if (null === error) { return if (null === error) {
if (prefRepository.notificationsEnable) sendNotifications() if (prefRepository.isNotificationsEnable) sendNotifications()
Timber.d("Synchronization successful") Timber.d("Synchronization successful")
RESULT_SUCCESS RESULT_SUCCESS
} else { } else {

View File

@ -71,7 +71,7 @@ class AttendancePresenter @Inject constructor(
.map { it.single { semester -> semester.current } } .map { it.single { semester -> semester.current } }
.flatMap { attendanceRepository.getAttendance(it, date, date, forceRefresh) } .flatMap { attendanceRepository.getAttendance(it, date, date, forceRefresh) }
.map { list -> .map { list ->
if (prefRepository.showPresent) list if (prefRepository.isShowPresent) list
else list.filter { !it.presence } else list.filter { !it.presence }
} }
.map { items -> items.map { AttendanceItem(it) } } .map { items -> items.map { AttendanceItem(it) } }

View File

@ -3,7 +3,9 @@ package io.github.wulkanowy.ui.modules.grade.details
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.View.* import android.view.View.GONE
import android.view.View.INVISIBLE
import android.view.View.VISIBLE
import android.view.ViewGroup import android.view.ViewGroup
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager
@ -60,8 +62,6 @@ class GradeDetailsFragment : BaseFragment(), GradeDetailsView, GradeView.GradeCh
setOnItemClickListener { presenter.onGradeItemSelected(getItem(it)) } setOnItemClickListener { presenter.onGradeItemSelected(getItem(it)) }
} }
gradeDetailsAdapter.getItemCountOfTypes()
gradeDetailsRecycler.run { gradeDetailsRecycler.run {
layoutManager = SmoothScrollLinearLayoutManager(context) layoutManager = SmoothScrollLinearLayoutManager(context)
adapter = gradeDetailsAdapter adapter = gradeDetailsAdapter

View File

@ -15,8 +15,13 @@ class GradeDetailsHeader(
private val subject: String, private val subject: String,
private val number: String, private val number: String,
private val average: String, private val average: String,
var newGrades: Int) var newGrades: Int,
: AbstractExpandableItem<GradeDetailsHeader.ViewHolder, GradeDetailsItem>() { private val isExpandable: Boolean
) : AbstractExpandableItem<GradeDetailsHeader.ViewHolder, GradeDetailsItem>() {
init {
isExpanded = !isExpandable
}
override fun getLayoutRes() = R.layout.header_grade_details override fun getLayoutRes() = R.layout.header_grade_details
@ -24,16 +29,16 @@ class GradeDetailsHeader(
return ViewHolder(view, adapter) return ViewHolder(view, adapter)
} }
override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<*>>?, holder: ViewHolder, override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<*>>?, holder: ViewHolder, position: Int, payloads: MutableList<Any>?) {
position: Int, payloads: MutableList<Any>?) {
holder.run { holder.run {
gradeHeaderSubject.text = subject gradeHeaderSubject.text = subject
gradeHeaderAverage.text = average gradeHeaderAverage.text = average
gradeHeaderNumber.text = number gradeHeaderNumber.text = number
gradeHeaderPredicted.visibility = GONE gradeHeaderPredicted.visibility = GONE
gradeHeaderFinal.visibility = GONE gradeHeaderFinal.visibility = GONE
gradeHeaderNote.visibility = if (newGrades > 0) VISIBLE else GONE gradeHeaderNote.visibility = if (newGrades > 0) VISIBLE else GONE
isViewExpandable = isExpandable
} }
} }
@ -57,15 +62,18 @@ class GradeDetailsHeader(
return result return result
} }
class ViewHolder(view: View?, adapter: FlexibleAdapter<IFlexible<*>>?) :
ExpandableViewHolder(view, adapter), LayoutContainer {
class ViewHolder(view: View?, adapter: FlexibleAdapter<IFlexible<*>>?) : ExpandableViewHolder(view, adapter), var isViewExpandable = true
LayoutContainer {
init { init {
contentView.setOnClickListener(this) contentView.setOnClickListener(this)
} }
override fun shouldNotifyParentOnClick() = true override fun isViewCollapsibleOnClick() = isViewExpandable
override fun isViewExpandableOnClick() = isViewExpandable
override val containerView: View override val containerView: View
get() = contentView get() = contentView

View File

@ -102,7 +102,8 @@ class GradeDetailsPresenter @Inject constructor(
subject = it.key, subject = it.key,
average = formatAverage(average), average = formatAverage(average),
number = view?.getGradeNumberString(it.value.size).orEmpty(), number = view?.getGradeNumberString(it.value.size).orEmpty(),
newGrades = it.value.filter { grade -> !grade.isRead }.size newGrades = it.value.filter { grade -> !grade.isRead }.size,
isExpandable = preferencesRepository.isGradeExpandable
).apply { ).apply {
subItems = it.value.map { item -> subItems = it.value.map { item ->
GradeDetailsItem( GradeDetailsItem(

View File

@ -26,7 +26,7 @@ class SettingsPresenter @Inject constructor(
fun onSharedPreferenceChanged(key: String) { fun onSharedPreferenceChanged(key: String) {
when (key) { when (key) {
preferencesRepository.serviceEnablesKey -> { preferencesRepository.serviceEnablesKey -> {
if (preferencesRepository.serviceEnabled) serviceHelper.startFullSyncService() if (preferencesRepository.isServiceEnabled) serviceHelper.startFullSyncService()
else serviceHelper.stopFullSyncService() else serviceHelper.stopFullSyncService()
} }
preferencesRepository.servicesIntervalKey, preferencesRepository.servicesIntervalKey,

View File

@ -135,6 +135,7 @@
<string name="pref_view_present">Pokazuj obecność we frekwencji</string> <string name="pref_view_present">Pokazuj obecność we frekwencji</string>
<string name="pref_view_theme_dark">Ciemny motyw (Beta)</string> <string name="pref_view_theme_dark">Ciemny motyw (Beta)</string>
<string name="pref_view_grade_modifier">Wartość plusa i minusa</string> <string name="pref_view_grade_modifier">Wartość plusa i minusa</string>
<string name="pref_view_expand_grade">Rozwiń oceny</string>
<string name="pref_notify_header">Powiadomienia</string> <string name="pref_notify_header">Powiadomienia</string>
<string name="pref_notify_switch">Pokazuj powiadomienia</string> <string name="pref_notify_switch">Pokazuj powiadomienia</string>

View File

@ -3,9 +3,10 @@
<string name="pref_key_start_menu">start_menu</string> <string name="pref_key_start_menu">start_menu</string>
<string name="pref_key_attendance_present">attendance_present</string> <string name="pref_key_attendance_present">attendance_present</string>
<string name="pref_key_theme">theme</string> <string name="pref_key_theme">theme</string>
<string name="pref_key_grade_modifier">grade_modifier</string>
<string name="pref_key_expand_grade">expand_grade</string>
<string name="pref_key_services_enable">services_enable</string> <string name="pref_key_services_enable">services_enable</string>
<string name="pref_key_services_interval">services_interval</string> <string name="pref_key_services_interval">services_interval</string>
<string name="pref_key_services_wifi_only">services_disable_wifi_only</string> <string name="pref_key_services_wifi_only">services_disable_wifi_only</string>
<string name="pref_key_notifications_enable">notifications_enable</string> <string name="pref_key_notifications_enable">notifications_enable</string>
<string name="pref_key_grade_modifier">grade_modifier</string>
</resources> </resources>

View File

@ -128,6 +128,7 @@
<string name="pref_view_present">Show presence in attendance</string> <string name="pref_view_present">Show presence in attendance</string>
<string name="pref_view_theme_dark">Dark theme (Beta)</string> <string name="pref_view_theme_dark">Dark theme (Beta)</string>
<string name="pref_view_grade_modifier">Value of the plus and minus</string> <string name="pref_view_grade_modifier">Value of the plus and minus</string>
<string name="pref_view_expand_grade">Expand grades</string>
<string name="pref_notify_header">Notifications</string> <string name="pref_notify_header">Notifications</string>
<string name="pref_notify_switch">Show notifications</string> <string name="pref_notify_switch">Show notifications</string>

View File

@ -25,6 +25,11 @@
android:key="@string/pref_key_attendance_present" android:key="@string/pref_key_attendance_present"
android:title="@string/pref_view_present" android:title="@string/pref_view_present"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:key="@string/pref_key_expand_grade"
android:title="@string/pref_view_expand_grade"
app:iconSpaceReserved="false" />
<ListPreference <ListPreference
android:defaultValue="0.0" android:defaultValue="0.0"
android:entries="@array/grade_modifier_entries" android:entries="@array/grade_modifier_entries"