1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2025-01-31 13:08:21 +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,
val context: Context
) {
val startMenuIndex: Int
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)
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 currentTheme: Int
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
val serviceEnablesKey: String = context.getString(R.string.pref_key_services_enable)
val serviceEnabled: Boolean
val isServiceEnabled: Boolean
get() = sharedPref.getBoolean(serviceEnablesKey, true)
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
val servicesOnlyWifiKey: String = context.getString(R.string.pref_key_services_wifi_only)
val servicesOnlyWifi: Boolean
val isServicesOnlyWifi: Boolean
get() = sharedPref.getBoolean(servicesOnlyWifiKey, true)
val notificationsEnable: Boolean
val isNotificationsEnable: Boolean
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) {
if (LocalDate.now().isHolidays || !prefRepository.serviceEnabled) {
if (LocalDate.now().isHolidays || !prefRepository.isServiceEnabled) {
Timber.d("Services disabled or it's holidays")
return
}
@ -41,7 +41,7 @@ class ServiceHelper @Inject constructor(
(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)
.setRetryStrategy(DEFAULT_EXPONENTIAL)
.build()

View File

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

View File

@ -71,7 +71,7 @@ class AttendancePresenter @Inject constructor(
.map { it.single { semester -> semester.current } }
.flatMap { attendanceRepository.getAttendance(it, date, date, forceRefresh) }
.map { list ->
if (prefRepository.showPresent) list
if (prefRepository.isShowPresent) list
else list.filter { !it.presence }
}
.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.view.LayoutInflater
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 eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager
@ -60,8 +62,6 @@ class GradeDetailsFragment : BaseFragment(), GradeDetailsView, GradeView.GradeCh
setOnItemClickListener { presenter.onGradeItemSelected(getItem(it)) }
}
gradeDetailsAdapter.getItemCountOfTypes()
gradeDetailsRecycler.run {
layoutManager = SmoothScrollLinearLayoutManager(context)
adapter = gradeDetailsAdapter

View File

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

View File

@ -102,7 +102,8 @@ class GradeDetailsPresenter @Inject constructor(
subject = it.key,
average = formatAverage(average),
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 {
subItems = it.value.map { item ->
GradeDetailsItem(

View File

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

View File

@ -135,6 +135,7 @@
<string name="pref_view_present">Pokazuj obecność we frekwencji</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_expand_grade">Rozwiń oceny</string>
<string name="pref_notify_header">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_attendance_present">attendance_present</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_interval">services_interval</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_grade_modifier">grade_modifier</string>
</resources>

View File

@ -128,6 +128,7 @@
<string name="pref_view_present">Show presence in attendance</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_expand_grade">Expand grades</string>
<string name="pref_notify_header">Notifications</string>
<string name="pref_notify_switch">Show notifications</string>

View File

@ -25,6 +25,11 @@
android:key="@string/pref_key_attendance_present"
android:title="@string/pref_view_present"
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
android:defaultValue="0.0"
android:entries="@array/grade_modifier_entries"