Redesign challenge list

This commit is contained in:
Phillip Thelen 2018-07-24 13:45:23 +02:00
parent 0270c3a147
commit ae98b69e99
6 changed files with 99 additions and 174 deletions

View file

@ -1,180 +1,105 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:clickable="true"
android:background="#fff"
android:orientation="horizontal"
android:baselineAligned="false"
android:paddingRight="16dp"
android:paddingEnd="16dp">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:clickable="true"
android:background="#fff"
android:orientation="horizontal"
android:baselineAligned="false"
android:paddingRight="16dp"
android:paddingEnd="16dp">
<LinearLayout
android:layout_width="0dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
android:layout_gravity="center">
<ImageView
android:id="@+id/gem_icon"
android:layout_width="24dp"
android:layout_height="24dp" />
<TextView
android:id="@+id/gemPrizeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:layout_weight="1"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="32dp"
android:layout_height="32dp"
android:background="@drawable/gem_circle_background"
android:gravity="center">
<ImageView
android:id="@+id/gem_icon"
android:layout_width="18dp"
android:layout_height="18dp" />
</LinearLayout>
<LinearLayout
android:layout_width="38dp"
android:layout_height="17dp"
android:layout_marginTop="-6dp"
android:background="@drawable/gem_value_circle_background"
android:gravity="center">
<TextView
android:id="@+id/gemPrizeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ellipsize="middle"
android:lines="1"
android:singleLine="true"
tools:text="0"
android:textColor="@color/gem_icon_color"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
android:ellipsize="middle"
android:singleLine="true"
tools:text="0"
android:textColor="@color/gem_icon_color"
android:textSize="17sp"
android:textStyle="bold"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_weight="6"
android:orientation="vertical">
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_weight="6"
android:orientation="vertical">
<net.pherth.android.emoji_library.EmojiTextView
android:id="@+id/challenge_name"
style="@style/ChallengeName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="2"
tools:text="Example Challenge Name that is very long" />
android:id="@+id/challenge_name"
style="@style/ChallengeName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="3"
tools:text="Name" />
<TextView
android:id="@+id/challenge_group_name"
style="@style/ChallengeByGroup"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_marginTop="1dp"
tools:text="Guild: XYZ" />
<net.pherth.android.emoji_library.EmojiTextView
android:id="@+id/challenge_shorttext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/gray_200"
android:textSize="12sp"
tools:text="Description"
android:layout_marginTop="@dimen/spacing_small"
android:layout_marginBottom="@dimen/spacing_medium"/>
<LinearLayout
android:id="@+id/leaderParticipantLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/leaderName"
style="@style/ChallengeTaskDetails"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_marginTop="1dp"
tools:text="by Leader" />
<View
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="1dp"
android:layout_height="16dp"
android:layout_gravity="center_vertical"
android:background="@color/text_light" />
<ImageView
android:layout_width="18dp"
android:layout_height="20dp"
android:src="@drawable/dialogue_participants" />
<TextView
android:id="@+id/participantCount"
style="@style/ChallengeTaskDetails"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_marginTop="1dp"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
tools:text="12334" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/officialHabiticaChallengeLayout"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_marginTop="3dp"
android:background="@drawable/layout_rounded_bg_official_challenge"
android:gravity="center"
android:layout_marginRight="10dp">
<TextView
android:id="@+id/textView2"
style="@style/OfficialChallenge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:text="@string/official" />
</LinearLayout>
<LinearLayout
android:id="@+id/challenge_is_participating"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_marginTop="3dp"
android:background="@drawable/layout_rounded_bg_official_challenge"
android:gravity="center">
<TextView
style="@style/ParticipatingChallenge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:text="@string/participating" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/arrowImage"
android:id="@+id/leaderParticipantLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
android:orientation="horizontal">
<ImageView
android:layout_width="18dp"
android:layout_height="match_parent"
android:src="@drawable/dialogue_participants" />
<ImageView
<TextView
android:id="@+id/participantCount"
style="@style/ChallengeTaskDetails"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
tools:text="12334" />
<TextView
android:id="@+id/official_challenge_view"
android:layout_marginLeft="@dimen/spacing_small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_keyboard_arrow_right_gray_24dp"/>
style="@style/Pill.Purple"
android:text="@string/official"/>
<TextView
android:id="@+id/is_joined_label"
android:layout_marginLeft="@dimen/spacing_small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Pill.Selected.Green"
android:text="@string/joined"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -785,4 +785,5 @@
<string name="challenge_prize">Challenge Prize</string>
<string name="challenge_categories">Challenge Categories</string>
<string name="created_challenge">Created Challenge</string>
<string name="joined">Joined</string>
</resources>

View file

@ -227,6 +227,10 @@
<style name="Pill.White">
<item name="android:background">@drawable/pill_bg_white</item>
</style>
<style name="Pill.Purple">
<item name="android:textColor">@color/white</item>
<item name="android:background">@drawable/pill_bg_purple_300</item>
</style>
<style name="Pill.Selected">
<item name="android:textColor">@color/white</item>

View file

@ -34,6 +34,7 @@ open class Challenge : RealmObject() {
var leader: User? = null
@Ignore
var tasksOrder: TasksOrder? = null
var summary: String? = null
fun getTasksOrder(): HashMap<String, Array<String>> {
val map = HashMap<String, Array<String>>()

View file

@ -11,6 +11,7 @@ import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.extensions.inflate
import com.habitrpg.android.habitica.extensions.notNull
import com.habitrpg.android.habitica.models.social.Challenge
import com.habitrpg.android.habitica.models.social.ChallengeMembership
import com.habitrpg.android.habitica.ui.fragments.social.challenges.ChallengeFilterOptions
import com.habitrpg.android.habitica.ui.helpers.bindView
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
@ -26,6 +27,7 @@ import org.greenrobot.eventbus.EventBus
class ChallengesListViewAdapter(data: OrderedRealmCollection<Challenge>?, autoUpdate: Boolean, private val viewUserChallengesOnly: Boolean, private val userId: String) : RealmRecyclerViewAdapter<Challenge, ChallengesListViewAdapter.ChallengeViewHolder>(data, autoUpdate) {
private var unfilteredData: OrderedRealmCollection<Challenge>? = null
var challengeMemberships: OrderedRealmCollection<ChallengeMembership>? = null
private val openChallengeFragmentEvents = PublishSubject.create<String>()
@ -35,7 +37,7 @@ class ChallengesListViewAdapter(data: OrderedRealmCollection<Challenge>?, autoUp
override fun onBindViewHolder(holder: ChallengeViewHolder, position: Int) {
data?.get(position).notNull { challenge ->
holder.bind(challenge)
holder.bind(challenge, challengeMemberships?.first { challenge.id == it.challengeID } != null)
holder.itemView.setOnClickListener {
if (challenge.isManaged) {
challenge.id.notNull {
@ -88,14 +90,10 @@ class ChallengesListViewAdapter(data: OrderedRealmCollection<Challenge>?, autoUp
class ChallengeViewHolder internal constructor(itemView: View, private val viewUserChallengesOnly: Boolean) : RecyclerView.ViewHolder(itemView) {
private val challengeName: EmojiTextView by bindView(R.id.challenge_name)
private val challengeDescription: TextView by bindView(R.id.challenge_group_name)
private val leaderParticipantLayout: LinearLayout by bindView(R.id.leaderParticipantLayout)
private val leaderName: TextView by bindView(R.id.leaderName)
private val challengeDescription: TextView by bindView(R.id.challenge_shorttext)
private val participantCount: TextView by bindView(R.id.participantCount)
private val officialChallengeLayout: LinearLayout by bindView(R.id.officialHabiticaChallengeLayout)
private val challengeParticipatingTextView: View by bindView(R.id.challenge_is_participating)
private val memberCountTextView: TextView by bindView(R.id.memberCountTextView)
private val arrowImage: LinearLayout by bindView(R.id.arrowImage)
private val officialChallengeLayout: TextView by bindView(R.id.official_challenge_view)
private val challengeParticipatingTextView: View by bindView(R.id.is_joined_label)
private val gemPrizeTextView: TextView by bindView(R.id.gemPrizeTextView)
private val gemIconView: ImageView by bindView(R.id.gem_icon)
@ -109,27 +107,21 @@ class ChallengesListViewAdapter(data: OrderedRealmCollection<Challenge>?, autoUp
}
}
fun bind(challenge: Challenge) {
fun bind(challenge: Challenge, isParticipating: Boolean) {
this.challenge = challenge
Log.e(challenge.id + challenge.name)
challengeName.text = EmojiParser.parseEmojis(challenge.name?.trim { it <= ' ' })
challengeDescription.text = challenge.groupName
challengeDescription.text = challenge.summary
officialChallengeLayout.visibility = if (challenge.official) View.VISIBLE else View.GONE
if (viewUserChallengesOnly) {
leaderParticipantLayout.visibility = View.GONE
challengeParticipatingTextView.visibility = View.GONE
arrowImage.visibility = View.VISIBLE
} else {
//challengeParticipatingTextView.visibility = if (challenge.isParticipating) View.VISIBLE else View.GONE
leaderName.text = itemView.context.getString(R.string.byLeader, challenge.leaderName)
participantCount.text = challenge.memberCount.toString()
leaderParticipantLayout.visibility = View.VISIBLE
arrowImage.visibility = View.GONE
challengeParticipatingTextView.visibility = if (isParticipating) View.VISIBLE else View.GONE
}
participantCount.text = challenge.memberCount.toString()
gemPrizeTextView.text = challenge.prize.toString()
}

View file

@ -67,6 +67,8 @@ class ChallengeDeserializer : JsonDeserializer<Challenge>, JsonSerializer<Challe
challenge.updatedAt = context.deserialize(jsonObject.get("updatedAt"), Date::class.java)
}
challenge.summary = jsonObject.get("summary").asString
val groupElement = jsonObject.get("group")
if (groupElement != null && !groupElement.isJsonNull) {