mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 21:06:44 -06:00
[Dialog/GradesConfig] Add grades view config dialog.
This commit is contained in:
parent
9a45cbb679
commit
62f53930da
@ -25,6 +25,7 @@ import android.util.Base64.encodeToString
|
||||
import android.view.View
|
||||
import android.widget.CheckBox
|
||||
import android.widget.CompoundButton
|
||||
import android.widget.RadioButton
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.*
|
||||
import androidx.core.app.ActivityCompat
|
||||
@ -1032,3 +1033,6 @@ fun CharSequence.containsAll(list: List<CharSequence>, ignoreCase: Boolean = fal
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun RadioButton.setOnSelectedListener(listener: (buttonView: CompoundButton) -> Unit)
|
||||
= setOnCheckedChangeListener { buttonView, isChecked -> if (isChecked) listener(buttonView) }
|
||||
|
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2020-1-16
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.dialogs.settings
|
||||
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.MainActivity
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.config.ConfigGrades
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
||||
import pl.szczodrzynski.edziennik.databinding.DialogConfigGradesBinding
|
||||
import pl.szczodrzynski.edziennik.setOnSelectedListener
|
||||
|
||||
class GradesConfigDialog(
|
||||
val activity: AppCompatActivity,
|
||||
val onShowListener: ((tag: String) -> Unit)? = null,
|
||||
val onDismissListener: ((tag: String) -> Unit)? = null
|
||||
) {
|
||||
companion object {
|
||||
const val TAG = "GradesConfigDialog"
|
||||
}
|
||||
|
||||
private val app by lazy { activity.application as App }
|
||||
private val config by lazy { app.config.grades }
|
||||
private val profileConfig by lazy { app.config.getFor(app.profileId).grades }
|
||||
|
||||
private lateinit var b: DialogConfigGradesBinding
|
||||
private lateinit var dialog: AlertDialog
|
||||
|
||||
init { run {
|
||||
if (activity.isFinishing)
|
||||
return@run
|
||||
b = DialogConfigGradesBinding.inflate(activity.layoutInflater)
|
||||
onShowListener?.invoke(TAG)
|
||||
dialog = MaterialAlertDialogBuilder(activity)
|
||||
.setTitle(R.string.menu_grades_config)
|
||||
.setView(b.root)
|
||||
.setPositiveButton(R.string.ok) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
(activity as? MainActivity)?.reloadTarget()
|
||||
}
|
||||
.create()
|
||||
initView()
|
||||
loadConfig()
|
||||
dialog.show()
|
||||
}}
|
||||
|
||||
private fun loadConfig() {
|
||||
when (config.orderBy) {
|
||||
ConfigGrades.ORDER_BY_DATE_DESC -> b.sortGradesByDateRadio
|
||||
ConfigGrades.ORDER_BY_SUBJECT_ASC -> b.sortGradesBySubjectRadio
|
||||
else -> null
|
||||
}?.isChecked = true
|
||||
|
||||
when (profileConfig.colorMode) {
|
||||
Profile.COLOR_MODE_DEFAULT -> b.gradeColorFromERegister
|
||||
Profile.COLOR_MODE_WEIGHTED -> b.gradeColorByValue
|
||||
else -> null
|
||||
}?.isChecked = true
|
||||
|
||||
when (profileConfig.yearAverageMode) {
|
||||
Profile.YEAR_ALL_GRADES -> b.gradeAverageMode4
|
||||
Profile.YEAR_1_AVG_2_AVG -> b.gradeAverageMode0
|
||||
Profile.YEAR_1_SEM_2_AVG -> b.gradeAverageMode1
|
||||
Profile.YEAR_1_AVG_2_SEM -> b.gradeAverageMode2
|
||||
Profile.YEAR_1_SEM_2_SEM -> b.gradeAverageMode3
|
||||
else -> null
|
||||
}?.isChecked = true
|
||||
|
||||
b.dontCountZeroToAverage.isChecked = !profileConfig.countZeroToAvg
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
b.sortGradesByDateRadio.setOnSelectedListener { config.orderBy = ConfigGrades.ORDER_BY_DATE_DESC }
|
||||
b.sortGradesBySubjectRadio.setOnSelectedListener { config.orderBy = ConfigGrades.ORDER_BY_SUBJECT_ASC }
|
||||
|
||||
b.gradeColorFromERegister.setOnSelectedListener { profileConfig.colorMode = Profile.COLOR_MODE_DEFAULT }
|
||||
b.gradeColorByValue.setOnSelectedListener { profileConfig.colorMode = Profile.COLOR_MODE_WEIGHTED }
|
||||
|
||||
b.gradeAverageMode4.setOnSelectedListener { profileConfig.yearAverageMode = Profile.YEAR_ALL_GRADES }
|
||||
b.gradeAverageMode0.setOnSelectedListener { profileConfig.yearAverageMode = Profile.YEAR_1_AVG_2_AVG }
|
||||
b.gradeAverageMode1.setOnSelectedListener { profileConfig.yearAverageMode = Profile.YEAR_1_SEM_2_AVG }
|
||||
b.gradeAverageMode2.setOnSelectedListener { profileConfig.yearAverageMode = Profile.YEAR_1_AVG_2_SEM }
|
||||
b.gradeAverageMode3.setOnSelectedListener { profileConfig.yearAverageMode = Profile.YEAR_1_SEM_2_SEM }
|
||||
|
||||
b.dontCountZeroToAverage.setOnCheckedChangeListener { _, isChecked -> profileConfig.countZeroToAvg = !isChecked }
|
||||
}
|
||||
}
|
@ -27,6 +27,7 @@ import pl.szczodrzynski.edziennik.data.db.entity.Grade;
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Subject;
|
||||
import pl.szczodrzynski.edziennik.data.db.full.GradeFull;
|
||||
import pl.szczodrzynski.edziennik.databinding.FragmentGradesBinding;
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.settings.GradesConfigDialog;
|
||||
import pl.szczodrzynski.edziennik.utils.Themes;
|
||||
import pl.szczodrzynski.edziennik.utils.models.ItemGradesSubjectModel;
|
||||
import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetPrimaryItem;
|
||||
@ -127,64 +128,11 @@ public class GradesFragment extends Fragment {
|
||||
showAverages();
|
||||
}),
|
||||
new BottomSheetPrimaryItem(true)
|
||||
.withTitle(R.string.menu_grades_color_mode)
|
||||
.withIcon(CommunityMaterial.Icon2.cmd_palette_outline)
|
||||
.withTitle(R.string.menu_grades_config)
|
||||
.withIcon(CommunityMaterial.Icon2.cmd_settings_outline)
|
||||
.withOnClickListener(v3 -> {
|
||||
activity.getBottomSheet().close();
|
||||
ProfileConfigGrades config = app.getConfig().getFor(App.Companion.getProfileId()).getGrades();
|
||||
new MaterialDialog.Builder(activity)
|
||||
.title(R.string.dialog_grades_color_mode_title)
|
||||
.items(R.array.dialog_grades_color_modes)
|
||||
.itemsCallbackSingleChoice(config.getColorMode(), (dialog, view1, which, text) -> {
|
||||
config.setColorMode(which);
|
||||
activity.reloadTarget();
|
||||
return true;
|
||||
})
|
||||
.show();
|
||||
}),
|
||||
new BottomSheetPrimaryItem(true)
|
||||
.withTitle(R.string.menu_grades_sort_mode)
|
||||
.withIcon(CommunityMaterial.Icon2.cmd_sort)
|
||||
.withOnClickListener(v3 -> {
|
||||
activity.getBottomSheet().close();
|
||||
new MaterialDialog.Builder(activity)
|
||||
.title(R.string.dialog_grades_sort_title)
|
||||
.items(R.array.dialog_grades_sort_modes)
|
||||
.itemsCallbackSingleChoice(app.getConfig().getGrades().getOrderBy(), (dialog, view1, which, text) -> {
|
||||
app.getConfig().getGrades().setOrderBy(which);
|
||||
activity.reloadTarget();
|
||||
return true;
|
||||
})
|
||||
.show();
|
||||
}),
|
||||
new BottomSheetPrimaryItem(true)
|
||||
.withTitle(R.string.menu_grades_average_mode)
|
||||
.withDescription(getRegisterCardAverageModeSubText())
|
||||
.withIcon(CommunityMaterial.Icon2.cmd_scale_balance)
|
||||
.withOnClickListener(v3 -> {
|
||||
activity.getBottomSheet().close();
|
||||
List<CharSequence> modeNames = new ArrayList<>();
|
||||
modeNames.add(getString(R.string.settings_register_avg_mode_4));
|
||||
modeNames.add(getString(R.string.settings_register_avg_mode_0));
|
||||
modeNames.add(getString(R.string.settings_register_avg_mode_1));
|
||||
modeNames.add(getString(R.string.settings_register_avg_mode_2));
|
||||
modeNames.add(getString(R.string.settings_register_avg_mode_3));
|
||||
List<Integer> modeIds = new ArrayList<>();
|
||||
modeIds.add(YEAR_ALL_GRADES);
|
||||
modeIds.add(YEAR_1_AVG_2_AVG);
|
||||
modeIds.add(YEAR_1_SEM_2_AVG);
|
||||
modeIds.add(YEAR_1_AVG_2_SEM);
|
||||
modeIds.add(YEAR_1_SEM_2_SEM);
|
||||
new MaterialDialog.Builder(activity)
|
||||
.title(getString(R.string.settings_register_avg_mode_dialog_title))
|
||||
.content(getString(R.string.settings_register_avg_mode_dialog_text))
|
||||
.items(modeNames)
|
||||
.itemsCallbackSingleChoice(modeIds.indexOf(App.Companion.getConfig().forProfile().getGrades().getYearAverageMode()), (dialog, itemView, which, text) -> {
|
||||
App.Companion.getConfig().forProfile().getGrades().setYearAverageMode(modeIds.get(which));
|
||||
activity.reloadTarget();
|
||||
return true;
|
||||
})
|
||||
.show();
|
||||
new GradesConfigDialog(activity, null, null);
|
||||
}),
|
||||
new BottomSheetSeparatorItem(true),
|
||||
new BottomSheetPrimaryItem(true)
|
||||
|
124
app/src/main/res/layout/dialog_config_grades.xml
Normal file
124
app/src/main/res/layout/dialog_config_grades.xml
Normal file
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (c) Kacper Ziubryniewicz 2020-1-20
|
||||
-->
|
||||
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="24dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
style="@style/TextAppearance.AppCompat.Small"
|
||||
android:text="@string/menu_grades_sort_mode"/>
|
||||
|
||||
<RadioGroup
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/sortGradesByDateRadio"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/dialog_grades_config_sort_by_date"/>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/sortGradesBySubjectRadio"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/dialog_grades_config_sort_by_subject"/>
|
||||
</RadioGroup>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
style="@style/TextAppearance.AppCompat.Small"
|
||||
android:text="@string/menu_grades_color_mode"/>
|
||||
|
||||
<RadioGroup
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/gradeColorFromERegister"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/dialog_grades_config_color_from_eregister"/>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/gradeColorByValue"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/dialog_grades_config_color_by_value"/>
|
||||
</RadioGroup>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
style="@style/TextAppearance.AppCompat.Small"
|
||||
android:text="@string/menu_grades_average_mode"/>
|
||||
|
||||
<RadioGroup
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/gradeAverageMode4"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/settings_register_avg_mode_4"/>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/gradeAverageMode0"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/settings_register_avg_mode_0"/>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/gradeAverageMode1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/settings_register_avg_mode_1"/>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/gradeAverageMode2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/settings_register_avg_mode_2"/>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/gradeAverageMode3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/settings_register_avg_mode_3"/>
|
||||
</RadioGroup>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
style="@style/TextAppearance.AppCompat.Small"
|
||||
android:text="@string/other"/>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/dontCountZeroToAverage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/settings_register_dont_count_zero_text"/>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</layout>
|
@ -938,7 +938,7 @@
|
||||
<string name="timetable_lesson_shifted_same_day">Lesson shifted to %s</string>
|
||||
<string name="timetable_no_lessons_title">No lessons this day</string>
|
||||
<string name="timetable_no_subject_name">(no name)</string>
|
||||
<string name="timetable_no_timetable_sync">Synchronize the timetable</string>
|
||||
<string name="timetable_no_timetable_sync">Synchronize</string>
|
||||
<string name="timetable_no_timetable_text">Timetable for this week hasn\'t been synchronized yet</string>
|
||||
<string name="timetable_no_timetable_title">No timetable</string>
|
||||
<string name="timetable_no_timetable_week">for week %s</string>
|
||||
@ -953,4 +953,10 @@
|
||||
<string name="widget_timetable_no_timetable">Timetable isn\'t synchronized. Open the app and synchronize the timetable.</string>
|
||||
<string name="widget_timetable_short_no_lessons">No lessons for the next 7 days.</string>
|
||||
<string name="widget_timetable_short_no_timetable">Timetable isn\'t synchronized.</string>
|
||||
<string name="dialog_grades_config_sort_by_date">From newest</string>
|
||||
<string name="dialog_grades_config_sort_by_subject">By subject name</string>
|
||||
<string name="dialog_grades_config_color_from_eregister">From e-register</string>
|
||||
<string name="dialog_grades_config_color_by_value">By grade\'s value</string>
|
||||
<string name="other">Other</string>
|
||||
<string name="menu_grades_config">Grades view config</string>
|
||||
</resources>
|
||||
|
@ -1167,4 +1167,10 @@
|
||||
<string name="notification_click_to_see_all">Kliknij, aby zobaczyć wszystkie powiadomienia</string>
|
||||
<string name="notification_cant_check_update">Nie udało się sprawdzić aktualizacji</string>
|
||||
<string name="edziennik_progress_endpoint_account_details">Pobieranie szczegółów konta...</string>
|
||||
<string name="dialog_grades_config_sort_by_date">Od najnowszych</string>
|
||||
<string name="dialog_grades_config_sort_by_subject">Wg nazwy przedmiotu</string>
|
||||
<string name="dialog_grades_config_color_from_eregister">Wg e-dziennika</string>
|
||||
<string name="dialog_grades_config_color_by_value">Wg wartości oceny</string>
|
||||
<string name="other">Inne</string>
|
||||
<string name="menu_grades_config">Ustawienia widoku ocen</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user