Add link to help guild to FAQ page. Fixes #1128

This commit is contained in:
Phillip Thelen 2019-04-17 10:46:24 +02:00
parent 067d2ba609
commit 6ab2868dcf
3 changed files with 65 additions and 18 deletions

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/gray_700"
android:paddingTop="@dimen/spacing_medium"
android:paddingBottom="@dimen/spacing_medium"
android:paddingLeft="@dimen/spacing_large"
android:paddingRight="@dimen/spacing_large">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/need_more_help"
android:gravity="center"
android:paddingBottom="@dimen/spacing_medium"
style="@style/Headline"
android:textStyle="bold"/>
<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Post a message in the [Habitica Help Guild] to have your questions answered by a fellow player."
android:gravity="center"/>
</LinearLayout>

View file

@ -583,7 +583,7 @@
<string name="empty_title_todos">You don\'t have any To-Dos</string>
<string name="empty_description_todos">To-Dos are tasks that only need to be completed once. Add checklists to your To-Dos to increase their value.</string>
<string name="empty_title_rewards">You don\'t have any Rewards</string>
<string name="reset_walkthrough">Reset Justins Walkthrough</string>
<string name="reset_walkthrough">Reset Tutorials</string>
<string name="read_community_guidelines">Read our Community Guidelines before posting</string>
<string name="maintenance">Maintenance</string>
<string name="reload_content">Reload Content</string>
@ -882,4 +882,6 @@
<string name="new_reminder">New reminder</string>
<string name="streak">Streak</string>
<string name="update_available">Update available: %1$s (%2$d)</string>
<string name="need_help_header_description">Post a message in the %s to have your questions answered by a fellow player.</string>
<string name="need_more_help">Need more help?</string>
</resources>

View file

@ -1,5 +1,6 @@
package com.habitrpg.android.habitica.ui.adapter
import android.text.method.LinkMovementMethod
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -11,6 +12,7 @@ import com.habitrpg.android.habitica.helpers.MainNavigationController
import com.habitrpg.android.habitica.models.FAQArticle
import com.habitrpg.android.habitica.ui.activities.MainActivity
import com.habitrpg.android.habitica.ui.fragments.faq.FAQOverviewFragmentDirections
import com.habitrpg.android.habitica.ui.helpers.MarkdownParser
import com.habitrpg.android.habitica.ui.helpers.bindView
import io.reactivex.BackpressureStrategy
import io.reactivex.Flowable
@ -29,32 +31,39 @@ class FAQOverviewRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Ada
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): androidx.recyclerview.widget.RecyclerView.ViewHolder {
return if (viewType == VIEW_TYPE_JUSTIN) {
val view = LayoutInflater.from(parent.context).inflate(R.layout.button_list_item, parent, false)
ResetWalkthroughViewHolder(view)
} else {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.plain_list_item, parent, false)
FAQArticleViewHolder(view)
return when (viewType) {
VIEW_TYPE_JUSTIN -> {
val view = LayoutInflater.from(parent.context).inflate(R.layout.button_list_item, parent, false)
ResetWalkthroughViewHolder(view)
}
VIEW_TYPE_HEADER -> {
val view = LayoutInflater.from(parent.context).inflate(R.layout.help_header, parent, false)
HeaderViewHolder(view)
}
else -> {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.plain_list_item, parent, false)
FAQArticleViewHolder(view)
}
}
}
override fun onBindViewHolder(holder: androidx.recyclerview.widget.RecyclerView.ViewHolder, position: Int) {
if (getItemViewType(position) == VIEW_TYPE_FAQ) {
(holder as FAQArticleViewHolder).bind(articles[position - 1])
(holder as? FAQArticleViewHolder)?.bind(articles[position - 1])
}
}
override fun getItemViewType(position: Int): Int {
return if (position == 0) {
VIEW_TYPE_JUSTIN
} else {
VIEW_TYPE_FAQ
return when (position) {
0 -> VIEW_TYPE_HEADER
articles.size+1 -> VIEW_TYPE_JUSTIN
else -> VIEW_TYPE_FAQ
}
}
override fun getItemCount(): Int {
return this.articles.size + 1
return this.articles.size + 2
}
fun getResetWalkthroughEvents(): Flowable<String> {
@ -86,15 +95,25 @@ class FAQOverviewRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Ada
private inner class ResetWalkthroughViewHolder internal constructor(itemView: View) : androidx.recyclerview.widget.RecyclerView.ViewHolder(itemView) {
init {
val button = itemView as Button
button.text = itemView.getContext().getString(R.string.reset_walkthrough)
button.setOnClickListener { resetWalkthroughEvents.onNext("") }
val button = itemView as? Button
button?.text = itemView.context.getString(R.string.reset_walkthrough)
button?.setOnClickListener { resetWalkthroughEvents.onNext("") }
}
}
private inner class HeaderViewHolder internal constructor(itemView: View) : androidx.recyclerview.widget.RecyclerView.ViewHolder(itemView) {
init {
val textView = itemView.findViewById<TextView>(R.id.text_view)
textView.text = MarkdownParser.parseMarkdown(itemView.context.getString(R.string.need_help_header_description, "[Habitica Help Guild](https://habitica.com/groups/guild/5481ccf3-5d2d-48a9-a871-70a7380cee5a)"))
textView.setMovementMethod(LinkMovementMethod.getInstance());
}
}
companion object {
private const val VIEW_TYPE_JUSTIN = 0
private const val VIEW_TYPE_FAQ = 1
private const val VIEW_TYPE_HEADER = 1
private const val VIEW_TYPE_FAQ = 2
}
}