From fe90b25010491e46697017ad6712939d03a03963 Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Thu, 6 Sep 2018 11:46:22 +0200 Subject: [PATCH] Fix minor issues. --- Habitica/AndroidManifest.xml | 2 +- .../android/habitica/models/tasks/Task.kt | 4 -- .../ui/fragments/SubscriptionFragment.kt | 3 +- .../tasks/TaskRecyclerViewFragment.kt | 2 +- .../viewHolders/tasks/BaseTaskViewHolder.kt | 45 +++++++++++-------- 5 files changed, 30 insertions(+), 26 deletions(-) diff --git a/Habitica/AndroidManifest.xml b/Habitica/AndroidManifest.xml index c7c00eaccc..8504719872 100644 --- a/Habitica/AndroidManifest.xml +++ b/Habitica/AndroidManifest.xml @@ -2,7 +2,7 @@ diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/Task.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/Task.kt index 7163f22e18..05732c440b 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/Task.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/models/tasks/Task.kt @@ -63,10 +63,6 @@ open class Task : RealmObject, Parcelable { var parsedText: CharSequence? = null @Ignore var parsedNotes: CharSequence? = null - set(value) { - field = value - repeat?.taskId = id - } var isDue: Boolean? = null diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/SubscriptionFragment.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/SubscriptionFragment.kt index 49e852f8c7..709511d0b0 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/SubscriptionFragment.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/SubscriptionFragment.kt @@ -20,6 +20,7 @@ import com.habitrpg.android.habitica.helpers.RxErrorHandler import com.habitrpg.android.habitica.models.user.User import com.habitrpg.android.habitica.proxy.CrashlyticsProxy import com.habitrpg.android.habitica.ui.activities.GemPurchaseActivity +import com.habitrpg.android.habitica.ui.helpers.bindOptionalView import com.habitrpg.android.habitica.ui.helpers.bindView import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper import com.habitrpg.android.habitica.ui.views.subscriptions.SubscriptionDetailsView @@ -62,7 +63,7 @@ class SubscriptionFragment : BaseFragment(), GemPurchaseActivity.CheckoutFragmen private val subscription6MonthView: SubscriptionOptionView? by bindView(R.id.subscription6month) private val subscription12MonthView: SubscriptionOptionView? by bindView(R.id.subscription12month) - private val subscriptionButton: Button? by bindView(R.id.subscribeButton) + private val subscriptionButton: Button? by bindOptionalView(R.id.subscribeButton) private val subscriptionDetailsView: SubscriptionDetailsView? by bindView(R.id.subscriptionDetails) private val subscribeBenefitsTitle: TextView? by bindView(R.id.subscribeBenefitsTitle) private val supportTextView: TextView? by bindView(R.id.supportTextView) diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/tasks/TaskRecyclerViewFragment.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/tasks/TaskRecyclerViewFragment.kt index 35419d5dca..d728cd9c57 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/tasks/TaskRecyclerViewFragment.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/tasks/TaskRecyclerViewFragment.kt @@ -124,7 +124,7 @@ open class TaskRecyclerViewFragment : BaseFragment(), View.OnClickListener, Swip if (fromPosition == null) { fromPosition = viewHolder.adapterPosition } - if (movingTaskID == null) { + if (movingTaskID == null && (viewHolder as? BaseTaskViewHolder)?.task?.isValid == true) { movingTaskID = (viewHolder as? BaseTaskViewHolder)?.task?.id } } diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/viewHolders/tasks/BaseTaskViewHolder.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/viewHolders/tasks/BaseTaskViewHolder.kt index 4bc0603ae3..c6b8012e27 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/viewHolders/tasks/BaseTaskViewHolder.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/viewHolders/tasks/BaseTaskViewHolder.kt @@ -28,7 +28,7 @@ abstract class BaseTaskViewHolder constructor(itemView: View) : RecyclerView.Vie var errorButtonClicked: Action? = null protected var context: Context private val titleTextView: EllipsisTextView by bindView(itemView, R.id.checkedTextView) - private val notesTextView: EllipsisTextView by bindView(itemView, R.id.notesTextView) + private val notesTextView: EllipsisTextView? by bindView(itemView, R.id.notesTextView) internal val rightBorderView: View? by bindOptionalView(itemView, R.id.rightBorderView) protected val specialTaskTextView: TextView? by bindOptionalView(itemView, R.id.specialTaskText) private val iconViewChallenge: ImageView? by bindView(itemView, R.id.iconviewChallenge) @@ -79,7 +79,7 @@ abstract class BaseTaskViewHolder constructor(itemView: View) : RecyclerView.Vie //titleTextView.movementMethod = LinkMovementMethod.getInstance() expandNotesButton?.setOnClickListener { expandTask() } - notesTextView.addEllipsesListener(object : EllipsisTextView.EllipsisListener { + notesTextView?.addEllipsesListener(object : EllipsisTextView.EllipsisListener { override fun ellipsisStateChanged(ellipses: Boolean) { Single.just(ellipses) .subscribeOn(Schedulers.io()) @@ -96,10 +96,10 @@ abstract class BaseTaskViewHolder constructor(itemView: View) : RecyclerView.Vie private fun expandTask() { notesExpanded = !notesExpanded if (notesExpanded) { - notesTextView.maxLines = 100 + notesTextView?.maxLines = 100 expandNotesButton?.text = context.getString(R.string.collapse_notes) } else { - notesTextView.maxLines = 3 + notesTextView?.maxLines = 3 expandNotesButton?.text = context.getString(R.string.expand_notes) } } @@ -109,43 +109,50 @@ abstract class BaseTaskViewHolder constructor(itemView: View) : RecyclerView.Vie itemView.setBackgroundResource(R.color.white) if (newTask.notes?.isNotEmpty() == true) { - notesTextView.visibility = View.VISIBLE + notesTextView?.visibility = View.VISIBLE //expandNotesButton.visibility = if (notesTextView.hadEllipses() || notesExpanded) View.VISIBLE else View.GONE } else { - notesTextView.visibility = View.GONE + notesTextView?.visibility = View.GONE expandNotesButton?.visibility = View.GONE } if (canContainMarkdown()) { if (newTask.parsedText != null) { titleTextView.text = newTask.parsedText - notesTextView.text = newTask.parsedNotes } else { titleTextView.text = newTask.text - notesTextView.text = newTask.notes - Single.just(newTask.text) - .map { MarkdownParser.parseMarkdown(it) } - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(Consumer{ parsedText -> - newTask.parsedText = parsedText - titleTextView.text = newTask.parsedText - }, RxErrorHandler.handleEmptyError()) + if (newTask.text.isNotEmpty()) { + Single.just(newTask.text) + .map { MarkdownParser.parseMarkdown(it) } + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(Consumer{ parsedText -> + newTask.parsedText = parsedText + titleTextView.text = parsedText + }, RxErrorHandler.handleEmptyError()) + } + if (newTask.parsedNotes != null) { + notesTextView?.text = newTask.parsedNotes + } else { + notesTextView?.text = newTask.notes newTask.notes.notNull {notes -> + if (notes.isEmpty()) { + return@notNull + } Single.just(notes) .map { MarkdownParser.parseMarkdown(it) } .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(Consumer { parsedNotes -> newTask.parsedNotes = parsedNotes - notesTextView.text = newTask.parsedNotes + notesTextView?.text = parsedNotes }, RxErrorHandler.handleEmptyError()) } - + } } } else { titleTextView.text = newTask.text - notesTextView.text = newTask.notes + notesTextView?.text = newTask.notes } rightBorderView?.setBackgroundResource(newTask.lightTaskColor)