Implement all relevant card views for habit groups

This commit is contained in:
Dharanish
2024-07-09 12:14:04 +02:00
parent 186d672141
commit 30b124ae6e
11 changed files with 282 additions and 3 deletions

View File

@@ -110,6 +110,15 @@
</intent-filter>
</activity>
<activity
android:name=".widgets.activities.BooleanHabitPickerDialog"
android:exported="true"
android:theme="@style/Theme.AppCompat.Light.Dialog">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
<activity
android:name=".widgets.activities.NumericalHabitPickerDialog"
android:exported="true"

View File

@@ -25,8 +25,29 @@ class ShowHabitGroupView(context: Context) : FrameLayout(context) {
binding.subtitleCard.setState(data.subtitle)
binding.overviewCard.setState(data.overview)
binding.notesCard.setState(data.notes)
binding.targetCard.setState(data.target)
binding.streakCard.setState(data.streaks)
binding.scoreCard.setState(data.scores)
binding.barCard.setState(data.bar)
binding.frequencyCard.setState(data.frequency)
if (!data.isBoolean) {
binding.streakCard.visibility = GONE
if (!data.isNumerical) {
binding.barCard.visibility = GONE
}
}
if (!data.isNumerical) {
binding.targetCard.visibility = GONE
}
if (data.isEmpty) {
binding.targetCard.visibility = GONE
binding.barCard.visibility = GONE
binding.streakCard.visibility = GONE
binding.overviewCard.visibility = GONE
binding.scoreCard.visibility = GONE
binding.frequencyCard.visibility = GONE
binding.noSubHabitsCard.visibility = VISIBLE
}
}
fun setListener(presenter: ShowHabitGroupPresenter) {

View File

@@ -33,6 +33,11 @@ import org.isoron.uhabits.activities.AndroidThemeSwitcher
import org.isoron.uhabits.core.preferences.WidgetPreferences
import org.isoron.uhabits.widgets.WidgetUpdater
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
@@ -44,6 +49,7 @@ open class HabitPickerDialog : Activity() {
private lateinit var widgetPreferences: WidgetPreferences
private lateinit var widgetUpdater: WidgetUpdater
protected open fun shouldHideNumerical() = false
protected open fun shouldHideBoolean() = false
protected open fun getEmptyMessage() = R.string.no_habits
@@ -61,6 +67,7 @@ open class HabitPickerDialog : Activity() {
val habitNames = ArrayList<String>()
for (h in habitList) {
if (h.isArchived) continue
if (h.isNumerical and shouldHideNumerical()) continue
if (!h.isNumerical and shouldHideBoolean()) continue
habitIds.add(h.id!!)
habitNames.add(h.name)

View File

@@ -57,15 +57,44 @@
style="@style/Card"
android:paddingTop="12dp"/>
<FrameLayout
android:id="@+id/noSubHabitsCard"
style="@style/Card"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="12dp"
android:visibility="gone">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/no_sub_habits" />
</FrameLayout>
<org.isoron.uhabits.activities.habits.show.views.TargetCardView
android:id="@+id/targetCard"
style="@style/Card"
android:paddingTop="12dp"/>
<org.isoron.uhabits.activities.habits.show.views.ScoreCardView
android:id="@+id/scoreCard"
style="@style/Card"
android:gravity="center"/>
<org.isoron.uhabits.activities.habits.show.views.BarCardView
android:id="@+id/barCard"
style="@style/Card"
android:gravity="center"/>
<org.isoron.uhabits.activities.habits.show.views.StreakCardView
android:id="@+id/streakCard"
style="@style/Card"/>
<org.isoron.uhabits.activities.habits.show.views.FrequencyCardView
android:id="@+id/frequencyCard"
style="@style/Card"/>
</LinearLayout>
</ScrollView>

View File

@@ -237,4 +237,5 @@
<string name="activity_not_found">No app was found to support this action</string>
<string name="pref_midnight_delay_title">Extend day a few hours past midnight</string>
<string name="pref_midnight_delay_description">Wait until 3:00 AM to show a new day. Useful if you typically go to sleep after midnight. Requires app restart.</string>
<string name="no_sub_habits">Group contains no habits.</string>
</resources>

View File

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