Improve stable design

This commit is contained in:
Phillip Thelen 2019-04-16 19:07:56 +02:00
parent 487460ce31
commit 91b8569284
8 changed files with 82 additions and 74 deletions

View file

@ -1,15 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/selection_highlight"
style="@style/CardContent">
android:layout_width="match_parent"
android:orientation="vertical"
android:background="@drawable/layout_rounded_bg_gray_700"
style="@style/CardContent">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/imageView"
android:layout_width="@dimen/pet_image_width"
@ -29,4 +25,3 @@
android:id="@+id/ownedTextView"
style="@style/RowText"/>
</LinearLayout>
</androidx.cardview.widget.CardView>

View file

@ -13,7 +13,8 @@
android:scrollbarThumbVertical="@color/scrollbarThumb"
android:scrollbars="vertical"
android:clipToPadding="false"
android:paddingBottom="?attr/actionBarSize"/>
android:paddingBottom="?attr/actionBarSize"
android:background="@color/white"/>
<TextView
android:layout_width="match_parent"

View file

@ -1,33 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:background="@drawable/layout_rounded_bg_gray_700"
android:orientation="vertical"
style="@style/CardContent">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/imageView"
android:layout_width="@dimen/pet_image_width"
android:layout_height="@dimen/pet_image_height"
android:layout_gravity="center_horizontal"
android:scaleType="fitEnd" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/selection_highlight"
style="@style/CardContent">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/imageView"
android:layout_width="@dimen/pet_image_width"
android:layout_height="@dimen/pet_image_height"
android:layout_gravity="center_horizontal"
android:scaleType="fitEnd" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="@+id/titleTextView"
style="@style/RowTitle"/>
android:layout_gravity="center_horizontal"
android:id="@+id/titleTextView"
style="@style/RowTitle"/>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/trainedProgressBar"
android:max="50" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/trainedProgressBar"
android:max="50" />
</LinearLayout>

View file

@ -1,5 +1,6 @@
package com.habitrpg.android.habitica.ui.adapter.inventory
import android.content.Context
import android.content.res.Resources
import android.graphics.drawable.BitmapDrawable
import androidx.recyclerview.widget.RecyclerView
@ -30,6 +31,7 @@ import io.realm.RealmRecyclerViewAdapter
class MountDetailRecyclerAdapter(data: OrderedRealmCollection<Mount>?, autoUpdate: Boolean) : RealmRecyclerViewAdapter<Mount, MountDetailRecyclerAdapter.MountViewHolder>(data, autoUpdate) {
var itemType: String? = null
var context: Context? = null
private var ownedMounts: Map<String, OwnedMount>? = null
private val equipEvents = PublishSubject.create<String>()
@ -72,18 +74,20 @@ class MountDetailRecyclerAdapter(data: OrderedRealmCollection<Mount>?, autoUpdat
titleView.text = item.color
ownedTextView.visibility = View.GONE
val imageName = "Mount_Icon_" + itemType + "-" + item.color
if (ownedMount?.owned == true) {
DataBindingUtils.loadImage(this.imageView, imageName)
} else {
DataBindingUtils.loadImage(imageName) {
val drawable = BitmapDrawable(context?.resources, it.extractAlpha())
this.imageView.alpha = 1.0f
if (ownedMount?.owned != true) {
this.imageView.alpha = 0.1f
}
imageView.backgroundCompat = null
val owned = ownedMount?.owned ?: false
DataBindingUtils.loadImage(imageName) {
val drawable = BitmapDrawable(context?.resources, if (owned) it else it.extractAlpha())
Observable.just(drawable)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
imageView.backgroundCompat = drawable
}, RxErrorHandler.handleEmptyError())
}
Observable.just(drawable)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
imageView.backgroundCompat = drawable
}, RxErrorHandler.handleEmptyError())
}
}

View file

@ -107,23 +107,19 @@ class PetDetailRecyclerAdapter(data: OrderedRealmCollection<Pet>?, autoUpdate: B
} else {
this.trainedProgressbar.visibility = View.GONE
}
DataBindingUtils.loadImage(this.imageView, imageName)
} else {
this.trainedProgressbar.visibility = View.GONE
if (this.ownedPet?.trained == null || ownedPet?.trained == 0) {
DataBindingUtils.loadImage(imageName) {
val drawable = BitmapDrawable(context?.resources, it.extractAlpha())
Observable.just(drawable)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
imageView.backgroundCompat = drawable
}, RxErrorHandler.handleEmptyError())
}
} else {
DataBindingUtils.loadImage(this.imageView, imageName)
}
this.imageView.alpha = 0.3f
this.imageView.alpha = 0.1f
}
imageView.backgroundCompat = null
val trained = ownedPet?.trained ?: 0
DataBindingUtils.loadImage(imageName) {
val drawable = BitmapDrawable(context?.resources, if (trained == 0) it.extractAlpha() else it)
Observable.just(drawable)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
imageView.backgroundCompat = drawable
}, RxErrorHandler.handleEmptyError())
}
}

View file

@ -1,23 +1,31 @@
package com.habitrpg.android.habitica.ui.adapter.inventory
import android.content.Context
import android.graphics.drawable.BitmapDrawable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.facebook.drawee.view.SimpleDraweeView
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.extensions.backgroundCompat
import com.habitrpg.android.habitica.extensions.notNull
import com.habitrpg.android.habitica.helpers.MainNavigationController
import com.habitrpg.android.habitica.helpers.RxErrorHandler
import com.habitrpg.android.habitica.models.inventory.Animal
import com.habitrpg.android.habitica.ui.activities.MainActivity
import com.habitrpg.android.habitica.ui.fragments.inventory.stable.StableFragmentDirections
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
import com.habitrpg.android.habitica.ui.helpers.bindView
import com.habitrpg.android.habitica.ui.viewHolders.SectionViewHolder
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.Consumer
class StableRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<androidx.recyclerview.widget.RecyclerView.ViewHolder>() {
var itemType: String? = null
var context: Context? = null
var activity: MainActivity? = null
private var itemList: List<Any> = ArrayList()
@ -74,17 +82,24 @@ class StableRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<
titleView.text = item.animal
ownedTextView.visibility = View.VISIBLE
this.imageView.alpha = 1.0f
if (item.numberOwned > 0) {
this.ownedTextView.text = animal?.numberOwned?.toString()
if (itemType == "pets") {
DataBindingUtils.loadImage(this.imageView, "Pet-" + item.key)
} else {
DataBindingUtils.loadImage(this.imageView, "Mount_Icon_" + item.key)
}
val imageName = if (itemType == "pets") {
"Pet-" + item.key
} else {
ownedTextView.visibility = View.GONE
DataBindingUtils.loadImage(this.imageView, "PixelPaw")
this.imageView.alpha = 0.4f
"Mount_Icon_" + item.key
}
this.ownedTextView.text = animal?.numberOwned?.toString()
ownedTextView.visibility = View.GONE
imageView.backgroundCompat = null
DataBindingUtils.loadImage(imageName) {
val drawable = BitmapDrawable(context?.resources, if (item.numberOwned > 0) it else it.extractAlpha())
Observable.just(drawable)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
imageView.backgroundCompat = drawable
}, RxErrorHandler.handleEmptyError())
}
if (item.numberOwned <= 0) {
this.imageView.alpha = 0.1f
}
}

View file

@ -63,6 +63,7 @@ class MountDetailRecyclerFragment : BaseMainFragment() {
if (adapter == null) {
adapter = MountDetailRecyclerAdapter(null, true)
adapter?.itemType = this.animalType
adapter?.context = context
recyclerView.adapter = adapter
recyclerView.itemAnimator = SafeDefaultItemAnimator()
this.loadItems()

View file

@ -85,6 +85,7 @@ class StableRecyclerFragment : BaseFragment() {
adapter = StableRecyclerAdapter()
adapter?.activity = this.activity as? MainActivity
adapter?.itemType = this.itemType
adapter?.context = context
recyclerView?.adapter = adapter
recyclerView?.itemAnimator = SafeDefaultItemAnimator()
}