HabitPickerDialog: Show "no habits found" message

pull/634/head
Alinson S. Xavier 5 years ago
parent cddbf558e6
commit e8e52db9b1

@ -32,10 +32,12 @@ import java.util.*
class BooleanHabitPickerDialog : HabitPickerDialog() {
override fun shouldHideNumerical() = true
override fun getEmptyMessage() = R.string.no_boolean_habits
}
class NumericalHabitPickerDialog : HabitPickerDialog() {
override fun shouldHideBoolean() = true
override fun getEmptyMessage() = R.string.no_numerical_habits
}
open class HabitPickerDialog : Activity() {
@ -46,6 +48,7 @@ open class HabitPickerDialog : Activity() {
protected open fun shouldHideNumerical() = false
protected open fun shouldHideBoolean() = false
protected open fun getEmptyMessage() = R.string.no_habits
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -66,6 +69,12 @@ open class HabitPickerDialog : Activity() {
habitNames.add(h.name)
}
if (habitNames.isEmpty()) {
setContentView(R.layout.widget_empty_activity)
findViewById<TextView>(R.id.message).setText(getEmptyMessage())
return;
}
setContentView(R.layout.widget_configure_activity)
val listView = findViewById<ListView>(R.id.listView)
val saveButton = findViewById<Button>(R.id.buttonSave)

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2016-2020 Álinson Santos Xavier <isoron@gmail.com>
~
~ This file is part of Loop Habit Tracker.
~
~ Loop Habit Tracker is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by the
~ Free Software Foundation, either version 3 of the License, or (at your
~ option) any later version.
~
~ Loop Habit Tracker is distributed in the hope that it will be useful, but
~ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
~ more details.
~
~ You should have received a copy of the GNU General Public License along
~ with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/message"
android:layout_width="250dp"
android:layout_height="150dp"
android:textSize="@dimen/regularTextSize"
android:text="@string/no_habits"
android:gravity="center"
/>
</FrameLayout>

@ -194,4 +194,7 @@
<string name="every_month">Every month</string>
<string name="validation_cannot_be_blank">Cannot be blank</string>
<string name="today">Today</string>
<string name="no_habits">No habits found</string>
<string name="no_numerical_habits">No measurable habits found</string>
<string name="no_boolean_habits">No yes-or-no habits found</string>
</resources>

@ -27,7 +27,7 @@
android:previewImage="@drawable/widget_preview_streaks"
android:resizeMode="vertical|horizontal"
android:updatePeriodMillis="3600000"
android:configure="org.isoron.uhabits.widgets.activities.NumericalHabitPickerDialog"
android:configure="org.isoron.uhabits.widgets.activities.BooleanHabitPickerDialog"
android:widgetCategory="home_screen">
</appwidget-provider>

@ -27,7 +27,7 @@
android:previewImage="@drawable/widget_preview_target"
android:resizeMode="vertical|horizontal"
android:updatePeriodMillis="3600000"
android:configure="org.isoron.uhabits.widgets.activities.BooleanHabitPickerDialog"
android:configure="org.isoron.uhabits.widgets.activities.NumericalHabitPickerDialog"
android:widgetCategory="home_screen">
</appwidget-provider>
Loading…
Cancel
Save