Refactor NotesCard

This commit is contained in:
2020-12-22 10:35:21 -06:00
parent 45574753c7
commit c2d89c7a60
7 changed files with 92 additions and 97 deletions

View File

@@ -76,6 +76,7 @@ class ShowHabitPresenter
val scoreLastYear = scores.getValue(lastYear).toFloat()
data = ShowHabitViewModel(
title = habit.name,
description = habit.description,
color = habit.color,
isNumerical = habit.isNumerical,
scoreToday = scoreToday,

View File

@@ -45,9 +45,9 @@ class ShowHabitRootView
displayHomeAsUp = true
binding.overviewCard.presenter = presenter
binding.notesCard.presenter = presenter
binding.subtitleCard.habit = habit
binding.notesCard.habit = habit
binding.scoreCard.habit = habit
binding.historyCard.habit = habit
binding.streakCard.habit = habit

View File

@@ -23,6 +23,7 @@ import org.isoron.uhabits.core.models.*
data class ShowHabitViewModel(
val title: String = "",
val description: String = "",
val isNumerical: Boolean = false,
val scoreToday: Float = 0f,
val scoreMonthDiff: Float = 0f,

View File

@@ -1,26 +1,37 @@
package org.isoron.uhabits.activities.habits.show.views
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.TextView
import org.isoron.uhabits.R
import org.isoron.uhabits.core.tasks.Task
import android.content.*
import android.util.*
import android.view.*
import android.widget.*
import org.isoron.uhabits.activities.habits.show.*
import org.isoron.uhabits.databinding.*
class NotesCard(context: Context?, attrs: AttributeSet?) : HabitCard(context, attrs) {
class NotesCard(
context: Context,
attrs: AttributeSet
) : LinearLayout(context, attrs), ShowHabitPresenter.Listener {
private val notesTextView: TextView
private val binding = ShowHabitNotesBinding.inflate(LayoutInflater.from(context), this)
lateinit var presenter: ShowHabitPresenter
init {
View.inflate(getContext(), R.layout.show_habit_notes, this)
notesTextView = findViewById(R.id.habitNotes)
override fun onAttachedToWindow() {
super.onAttachedToWindow()
presenter.addListener(this)
presenter.requestData(this)
}
override fun refreshData() {
notesTextView.text = habit.description
visibility = if(habit.description.isEmpty()) View.GONE else View.VISIBLE
notesTextView.visibility = visibility
override fun onDetachedFromWindow() {
presenter.removeListener(this)
super.onDetachedFromWindow()
}
override fun createRefreshTask(): Task = error("refresh task should never be called.")
override fun onData(data: ShowHabitViewModel) {
if (data.description.isEmpty()) {
visibility = GONE
} else {
visibility = VISIBLE
binding.habitNotes.text = data.description
}
}
}

View File

@@ -30,6 +30,5 @@
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="?highContrastTextColor"
android:visibility="gone"
tools:text="This is some example text for the notes" />
</merge>