mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-31 13:48:20 +01:00
[UI/Settings] Add grades config dialog to settings fragment.
This commit is contained in:
parent
7d8caa8df7
commit
d48c7844a4
@ -17,6 +17,7 @@ import pl.szczodrzynski.edziennik.setOnSelectedListener
|
|||||||
|
|
||||||
class GradesConfigDialog(
|
class GradesConfigDialog(
|
||||||
val activity: AppCompatActivity,
|
val activity: AppCompatActivity,
|
||||||
|
private val reloadOnDismiss: Boolean = true,
|
||||||
val onShowListener: ((tag: String) -> Unit)? = null,
|
val onShowListener: ((tag: String) -> Unit)? = null,
|
||||||
val onDismissListener: ((tag: String) -> Unit)? = null
|
val onDismissListener: ((tag: String) -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
@ -39,9 +40,10 @@ class GradesConfigDialog(
|
|||||||
dialog = MaterialAlertDialogBuilder(activity)
|
dialog = MaterialAlertDialogBuilder(activity)
|
||||||
.setTitle(R.string.menu_grades_config)
|
.setTitle(R.string.menu_grades_config)
|
||||||
.setView(b.root)
|
.setView(b.root)
|
||||||
.setPositiveButton(R.string.ok) { dialog, _ ->
|
.setPositiveButton(R.string.ok) { dialog, _ -> dialog.dismiss() }
|
||||||
dialog.dismiss()
|
.setOnDismissListener {
|
||||||
(activity as? MainActivity)?.reloadTarget()
|
onDismissListener?.invoke(TAG)
|
||||||
|
if (reloadOnDismiss) (activity as? MainActivity)?.reloadTarget()
|
||||||
}
|
}
|
||||||
.create()
|
.create()
|
||||||
initView()
|
initView()
|
||||||
|
@ -132,7 +132,7 @@ public class GradesFragment extends Fragment {
|
|||||||
.withIcon(CommunityMaterial.Icon2.cmd_settings_outline)
|
.withIcon(CommunityMaterial.Icon2.cmd_settings_outline)
|
||||||
.withOnClickListener(v3 -> {
|
.withOnClickListener(v3 -> {
|
||||||
activity.getBottomSheet().close();
|
activity.getBottomSheet().close();
|
||||||
new GradesConfigDialog(activity, null, null);
|
new GradesConfigDialog(activity, true, null, null);
|
||||||
}),
|
}),
|
||||||
new BottomSheetSeparatorItem(true),
|
new BottomSheetSeparatorItem(true),
|
||||||
new BottomSheetPrimaryItem(true)
|
new BottomSheetPrimaryItem(true)
|
||||||
|
@ -52,6 +52,7 @@ import pl.szczodrzynski.edziennik.network.NetworkUtils;
|
|||||||
import pl.szczodrzynski.edziennik.sync.SyncWorker;
|
import pl.szczodrzynski.edziennik.sync.SyncWorker;
|
||||||
import pl.szczodrzynski.edziennik.sync.UpdateWorker;
|
import pl.szczodrzynski.edziennik.sync.UpdateWorker;
|
||||||
import pl.szczodrzynski.edziennik.ui.dialogs.changelog.ChangelogDialog;
|
import pl.szczodrzynski.edziennik.ui.dialogs.changelog.ChangelogDialog;
|
||||||
|
import pl.szczodrzynski.edziennik.ui.dialogs.settings.GradesConfigDialog;
|
||||||
import pl.szczodrzynski.edziennik.ui.dialogs.settings.ProfileRemoveDialog;
|
import pl.szczodrzynski.edziennik.ui.dialogs.settings.ProfileRemoveDialog;
|
||||||
import pl.szczodrzynski.edziennik.utils.Themes;
|
import pl.szczodrzynski.edziennik.utils.Themes;
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils;
|
import pl.szczodrzynski.edziennik.utils.Utils;
|
||||||
@ -858,47 +859,20 @@ public class SettingsNewFragment extends MaterialAboutFragment {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
private MaterialAboutActionItem registerCardAverageModeItem;
|
|
||||||
private MaterialAboutSwitchItem registerCardAllowRegistrationItem;
|
private MaterialAboutSwitchItem registerCardAllowRegistrationItem;
|
||||||
private MaterialAboutActionItem registerCardBellSyncItem;
|
private MaterialAboutActionItem registerCardBellSyncItem;
|
||||||
private ArrayList<MaterialAboutItem> getRegisterCard(boolean expandedOnly) {
|
private ArrayList<MaterialAboutItem> getRegisterCard(boolean expandedOnly) {
|
||||||
ArrayList<MaterialAboutItem> items = new ArrayList<>();
|
ArrayList<MaterialAboutItem> items = new ArrayList<>();
|
||||||
if (!expandedOnly) {
|
if (!expandedOnly) {
|
||||||
|
items.add(new MaterialAboutActionItem(
|
||||||
registerCardAverageModeItem = new MaterialAboutActionItem(
|
getString(R.string.menu_grades_config),
|
||||||
getString(R.string.settings_register_avg_mode_text),
|
null,
|
||||||
getRegisterCardAverageModeSubText(),
|
|
||||||
new IconicsDrawable(activity)
|
new IconicsDrawable(activity)
|
||||||
.icon(CommunityMaterial.Icon2.cmd_scale_balance)
|
.icon(CommunityMaterial.Icon2.cmd_numeric_5_box_outline)
|
||||||
.size(IconicsSize.dp(iconSizeDp))
|
.size(IconicsSize.dp(iconSizeDp))
|
||||||
.color(IconicsColor.colorInt(iconColor))
|
.color(IconicsColor.colorInt(iconColor))
|
||||||
);
|
).setOnClickAction(() -> new GradesConfigDialog(activity, false, null, null)));
|
||||||
registerCardAverageModeItem.setOnClickAction(() -> {
|
|
||||||
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.getConfig().forProfile().getGrades().getYearAverageMode()), (dialog, itemView, which, text) -> {
|
|
||||||
app.getConfig().forProfile().getGrades().setYearAverageMode(modeIds.get(which));
|
|
||||||
registerCardAverageModeItem.setSubText(getRegisterCardAverageModeSubText());
|
|
||||||
refreshMaterialAboutList();
|
|
||||||
return true;
|
|
||||||
})
|
|
||||||
.show();
|
|
||||||
});
|
|
||||||
items.add(registerCardAverageModeItem);
|
|
||||||
|
|
||||||
registerCardAllowRegistrationItem = new MaterialAboutSwitchItem(
|
registerCardAllowRegistrationItem = new MaterialAboutSwitchItem(
|
||||||
getString(R.string.settings_register_allow_registration_text),
|
getString(R.string.settings_register_allow_registration_text),
|
||||||
@ -960,7 +934,6 @@ public class SettingsNewFragment extends MaterialAboutFragment {
|
|||||||
items.add(getMoreItem(() -> addCardItems(CARD_REGISTER, getRegisterCard(true))));
|
items.add(getMoreItem(() -> addCardItems(CARD_REGISTER, getRegisterCard(true))));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
registerCardBellSyncItem = new MaterialAboutActionItem(
|
registerCardBellSyncItem = new MaterialAboutActionItem(
|
||||||
getString(R.string.settings_register_bell_sync_text),
|
getString(R.string.settings_register_bell_sync_text),
|
||||||
getRegisterCardBellSyncSubText(),
|
getRegisterCardBellSyncSubText(),
|
||||||
@ -1030,22 +1003,6 @@ public class SettingsNewFragment extends MaterialAboutFragment {
|
|||||||
});
|
});
|
||||||
items.add(registerCardBellSyncItem);
|
items.add(registerCardBellSyncItem);
|
||||||
|
|
||||||
items.add(
|
|
||||||
new MaterialAboutSwitchItem(
|
|
||||||
getString(R.string.settings_register_dont_count_zero_text),
|
|
||||||
null,
|
|
||||||
new IconicsDrawable(activity)
|
|
||||||
.icon(CommunityMaterial.Icon2.cmd_numeric_0_box_outline)
|
|
||||||
.size(IconicsSize.dp(iconSizeDp))
|
|
||||||
.color(IconicsColor.colorInt(iconColor))
|
|
||||||
)
|
|
||||||
.setChecked(!app.getConfig().getFor(app.getProfileId()).getGrades().getCountZeroToAvg())
|
|
||||||
.setOnChangeAction((isChecked, tag) -> {
|
|
||||||
app.getConfig().getFor(app.getProfileId()).getGrades().setCountZeroToAvg(!isChecked);
|
|
||||||
return true;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
items.add(
|
items.add(
|
||||||
new MaterialAboutSwitchItem(
|
new MaterialAboutSwitchItem(
|
||||||
getString(R.string.settings_register_count_in_seconds_text),
|
getString(R.string.settings_register_count_in_seconds_text),
|
||||||
|
@ -958,5 +958,5 @@
|
|||||||
<string name="dialog_grades_config_color_from_eregister">From e-register</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="dialog_grades_config_color_by_value">By grade\'s value</string>
|
||||||
<string name="other">Other</string>
|
<string name="other">Other</string>
|
||||||
<string name="menu_grades_config">Grades view config</string>
|
<string name="menu_grades_config">Grades settings</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1172,5 +1172,5 @@
|
|||||||
<string name="dialog_grades_config_color_from_eregister">Wg e-dziennika</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="dialog_grades_config_color_by_value">Wg wartości oceny</string>
|
||||||
<string name="other">Inne</string>
|
<string name="other">Inne</string>
|
||||||
<string name="menu_grades_config">Ustawienia widoku ocen</string>
|
<string name="menu_grades_config">Ustawienia ocen</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user