diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt index ea3bc3cc..5bb4cc9e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt @@ -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, ignoreCase: Boolean = fal } return true } + +fun RadioButton.setOnSelectedListener(listener: (buttonView: CompoundButton) -> Unit) + = setOnCheckedChangeListener { buttonView, isChecked -> if (isChecked) listener(buttonView) } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/settings/GradesConfigDialog.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/settings/GradesConfigDialog.kt new file mode 100644 index 00000000..d29160c3 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/settings/GradesConfigDialog.kt @@ -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 } + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradesFragment.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradesFragment.java index 19a360e4..b24b0d9c 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradesFragment.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/grades/GradesFragment.java @@ -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 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 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) diff --git a/app/src/main/res/layout/dialog_config_grades.xml b/app/src/main/res/layout/dialog_config_grades.xml new file mode 100644 index 00000000..ce22c0ac --- /dev/null +++ b/app/src/main/res/layout/dialog_config_grades.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index 88120fc6..9571056c 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -938,7 +938,7 @@ Lesson shifted to %s No lessons this day (no name) - Synchronize the timetable + Synchronize Timetable for this week hasn\'t been synchronized yet No timetable for week %s @@ -953,4 +953,10 @@ Timetable isn\'t synchronized. Open the app and synchronize the timetable. No lessons for the next 7 days. Timetable isn\'t synchronized. + From newest + By subject name + From e-register + By grade\'s value + Other + Grades view config diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b85688cb..f302fb2e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1167,4 +1167,10 @@ Kliknij, aby zobaczyć wszystkie powiadomienia Nie udało się sprawdzić aktualizacji Pobieranie szczegółów konta... + Od najnowszych + Wg nazwy przedmiotu + Wg e-dziennika + Wg wartości oceny + Inne + Ustawienia widoku ocen