Archived
Added setting to change day/date format for canteen screen
This commit is contained in:
@@ -11,7 +11,7 @@ import com.denizk0461.weserplaner.R
|
||||
* @param context context reference
|
||||
* @param items list of texts to display
|
||||
*/
|
||||
class DropdownAdapter(context: Context, items: MutableList<String>)
|
||||
class DropdownAdapter(context: Context, items: List<String>)
|
||||
: ArrayAdapter<String>(context, R.layout.item_dropdown, items) {
|
||||
|
||||
private val noOpFilter = object : Filter() {
|
||||
|
||||
@@ -439,6 +439,16 @@ class AppRepository(app: Application) {
|
||||
setPreference(SettingsPreferences.SELECTED_TIMETABLE, newValue)
|
||||
}
|
||||
|
||||
/**
|
||||
* User-selected timetable to display.
|
||||
*/
|
||||
fun getPreferenceCanteenDate(): Int = getIntPreference(
|
||||
SettingsPreferences.CANTEEN_DATE_PREFERENCE,
|
||||
)
|
||||
fun setPreferenceCanteenDate(newValue: Int) {
|
||||
setPreference(SettingsPreferences.CANTEEN_DATE_PREFERENCE, newValue)
|
||||
}
|
||||
|
||||
/**
|
||||
* This value determines which navigation graph will be used for app navigation.
|
||||
*/
|
||||
|
||||
@@ -230,7 +230,12 @@ class CanteenFragment : AppFragment<FragmentCanteenBinding>() {
|
||||
|
||||
// Set up TabLayoutMediator to populate tabs
|
||||
TabLayoutMediator(binding.dayTabLayout, binding.viewPager) { tab, position ->
|
||||
tab.text = dates[position].run { "$day, $date" }
|
||||
tab.text = dates[position].let { d -> when (viewModel.preferenceCanteenDate) {
|
||||
0 -> "${d.day.shortenDay()}, ${d.date}"
|
||||
1 -> "${d.day}, ${d.date}"
|
||||
2 -> d.date
|
||||
else -> d.day // 3
|
||||
}}
|
||||
}.attach()
|
||||
|
||||
// Set extended FAB to extend when the page is changed
|
||||
@@ -263,6 +268,23 @@ class CanteenFragment : AppFragment<FragmentCanteenBinding>() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortens a German day name to its shortened form, followed by a period. Example:
|
||||
* Montag -> Mo.
|
||||
*
|
||||
* @receiver day name to shorten
|
||||
* @return shortened day name with period following it
|
||||
*/
|
||||
private fun String.shortenDay(): String = when (this) {
|
||||
"Montag" -> "Mo."
|
||||
"Dienstag" -> "Di."
|
||||
"Mittwoch" -> "Mi."
|
||||
"Donnerstag" -> "Do."
|
||||
"Freitag" -> "Fr."
|
||||
"Samstag" -> "Sa."
|
||||
else -> "So."
|
||||
}
|
||||
|
||||
// Invalidate the view binding
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
|
||||
@@ -218,6 +218,22 @@ class SettingsFragment : AppFragment<FragmentSettingsBinding>() {
|
||||
}
|
||||
}
|
||||
|
||||
val dateAdapter = DropdownAdapter(
|
||||
context,
|
||||
context.resources.getStringArray(R.array.settings_dates).toList(),
|
||||
)
|
||||
|
||||
binding.autoCompleteDates.setAdapter(dateAdapter)
|
||||
binding.autoCompleteDates.setText(
|
||||
dateAdapter.getItem(viewModel.preferenceCanteenDate),
|
||||
false,
|
||||
)
|
||||
|
||||
binding.autoCompleteDates.setOnItemClickListener { _, _, position, _ ->
|
||||
viewModel.preferenceCanteenDate = position
|
||||
binding.autoCompleteDates.setText(dateAdapter.getItem(position))
|
||||
}
|
||||
|
||||
// --- miscellaneous settings --- //
|
||||
|
||||
// Set up button toggle group for changing default fragment
|
||||
|
||||
@@ -95,4 +95,10 @@ class CanteenViewModel(app: Application) : AppViewModel(app) {
|
||||
*/
|
||||
val preferenceAppLayout: AppLayout
|
||||
get() = repo.getAppLayout()
|
||||
|
||||
/**
|
||||
* Determines in which format dates should be displayed on the canteen screen.
|
||||
*/
|
||||
val preferenceCanteenDate: Int
|
||||
get() = repo.getPreferenceCanteenDate()
|
||||
}
|
||||
@@ -103,6 +103,13 @@ class SettingsViewModel(app: Application) : AppViewModel(app) {
|
||||
get() = repo.getAppLayout()
|
||||
set(newValue) { repo.setAppLayout(newValue) }
|
||||
|
||||
/**
|
||||
* Determines in which format dates should be displayed on the canteen screen.
|
||||
*/
|
||||
var preferenceCanteenDate: Int
|
||||
get() = repo.getPreferenceCanteenDate()
|
||||
set(newValue) { repo.setPreferenceCanteenDate(newValue) }
|
||||
|
||||
fun setPreferenceFeatureTimetables(newValue: Boolean) { repo.setPreferenceFeatureTimetables(newValue) }
|
||||
|
||||
// --- functions for dev codes --- //
|
||||
|
||||
@@ -485,6 +485,97 @@
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
<!-- Dates -->
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:orientation="vertical"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:paddingVertical="8dp">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:fontFamily="@font/lato_bolditalic"
|
||||
android:text="@string/settings_dates_title"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/settings_dates_subtitle"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/text_layout_dates"
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:boxStrokeColor="@color/selector_text_input"
|
||||
app:hintTextColor="@color/selector_text_input">
|
||||
|
||||
<com.google.android.material.textfield.MaterialAutoCompleteTextView
|
||||
android:id="@+id/auto_complete_dates"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?attr/colorOnSurfaceVariant"
|
||||
android:inputType="none"/>
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<!-- <com.google.android.material.button.MaterialButtonToggleGroup-->
|
||||
<!-- android:id="@+id/toggle_date_group"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:gravity="center_horizontal"-->
|
||||
<!-- app:singleSelection="true"-->
|
||||
<!-- app:selectionRequired="true">-->
|
||||
|
||||
<!-- <com.google.android.material.button.MaterialButton-->
|
||||
<!-- style="@style/Widget.Material3.Button.OutlinedButton"-->
|
||||
<!-- android:id="@+id/toggle_date_0"-->
|
||||
<!-- android:layout_width="0dp"-->
|
||||
<!-- android:layout_weight="1"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:text="@string/settings_dates_0"-->
|
||||
<!-- android:textColor="@color/list_group_button"-->
|
||||
<!-- app:strokeColor="?attr/colorOutlineVariant"/>-->
|
||||
|
||||
<!-- <com.google.android.material.button.MaterialButton-->
|
||||
<!-- style="@style/Widget.Material3.Button.OutlinedButton"-->
|
||||
<!-- android:id="@+id/toggle_date_1"-->
|
||||
<!-- android:layout_width="0dp"-->
|
||||
<!-- android:layout_weight="1"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:text="@string/settings_dates_1"-->
|
||||
<!-- android:textColor="@color/list_group_button"-->
|
||||
<!-- app:strokeColor="?attr/colorOutlineVariant"/>-->
|
||||
|
||||
<!-- <com.google.android.material.button.MaterialButton-->
|
||||
<!-- style="@style/Widget.Material3.Button.OutlinedButton"-->
|
||||
<!-- android:id="@+id/toggle_date_2"-->
|
||||
<!-- android:layout_width="0dp"-->
|
||||
<!-- android:layout_weight="1"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:text="@string/settings_dates_2"-->
|
||||
<!-- android:textColor="@color/list_group_button"-->
|
||||
<!-- app:strokeColor="?attr/colorOutlineVariant"/>-->
|
||||
|
||||
<!-- <com.google.android.material.button.MaterialButton-->
|
||||
<!-- style="@style/Widget.Material3.Button.OutlinedButton"-->
|
||||
<!-- android:id="@+id/toggle_date_3"-->
|
||||
<!-- android:layout_width="0dp"-->
|
||||
<!-- android:layout_weight="1"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:text="@string/settings_dates_3"-->
|
||||
<!-- android:textColor="@color/list_group_button"-->
|
||||
<!-- app:strokeColor="?attr/colorOutlineVariant"/>-->
|
||||
|
||||
<!-- </com.google.android.material.button.MaterialButtonToggleGroup>-->
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
@@ -286,6 +286,9 @@
|
||||
<string name="settings_pricing_student">Studierende</string>
|
||||
<string name="settings_pricing_employee">Bedienstete</string>
|
||||
|
||||
<string name="settings_dates_title">Stelle Anzeige des Datums ein</string>
|
||||
<string name="settings_dates_subtitle">Gilt für die Reiter der täglichen Mensenangebote</string>
|
||||
|
||||
<string name="settings_allergens_title">Markiere Angebote mit Allergenen mit einem Stern*</string>
|
||||
<string name="settings_allergens_subtitle">Wird auch für Zusatzstoffe genutzt</string>
|
||||
<string name="settings_allergens_title_alt">App entwickelt von denizk0461</string>
|
||||
|
||||
@@ -291,6 +291,15 @@
|
||||
<string name="settings_pricing_student">Students</string>
|
||||
<string name="settings_pricing_employee">Employees</string>
|
||||
|
||||
<string name="settings_dates_title">Set how dates are displayed</string>
|
||||
<string name="settings_dates_subtitle">Applies to the daily canteen offers\' tabs</string>
|
||||
<string-array name="settings_dates">
|
||||
<item translatable="false">Fr., 12.01.</item>
|
||||
<item translatable="false">Freitag, 12.01.</item>
|
||||
<item translatable="false">12.01.</item>
|
||||
<item translatable="false">Freitag</item>
|
||||
</string-array>
|
||||
|
||||
<string name="settings_allergens_title">Mark offers with allergens with a star*</string>
|
||||
<string name="settings_allergens_subtitle">Also applies to additives</string>
|
||||
<string name="settings_allergens_title_alt">App developed by denizk0461</string>
|
||||
|
||||
Reference in New Issue
Block a user