fix recyclerview bug

This commit is contained in:
Leland Wu 2020-05-22 22:29:15 -04:00
parent a43340a15b
commit 4091233842
2 changed files with 43 additions and 35 deletions

View file

@ -8,37 +8,35 @@
<LinearLayout
android:id="@+id/card_view"
android:layout_width="124dp"
android:layout_height="156dp"
android:layout_centerInParent="true"
android:layout_width="127dp"
android:layout_height="140dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
android:background="@drawable/layout_rounded_bg_shopitem"
android:orientation="vertical">
style="@style/CardContent">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/imageView"
android:layout_width="@dimen/mount_image_width"
android:layout_height="@dimen/mount_image_height"
android:layout_width="79dp"
android:layout_height="94dp"
android:layout_gravity="center_horizontal"
android:scaleType="fitEnd" />
<TextView
android:id="@+id/titleTextView"
style="@style/RowTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="3.5dp"
android:layout_gravity="center_horizontal"
android:id="@+id/titleTextView"
android:textSize="13sp"
android:gravity="center"
android:textSize="13sp" />
style="@style/RowTitle"/>
<TextView
android:id="@+id/ownedTextView"
style="@style/RowText"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:background="@drawable/layout_rounded_bg_shopitem_price"
android:gravity="center"

View file

@ -6,6 +6,7 @@ import android.graphics.drawable.BitmapDrawable
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.GridLayoutManager
import com.facebook.drawee.view.SimpleDraweeView
import com.habitrpg.android.habitica.R
@ -131,31 +132,40 @@ class StableRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<
"Mount_Icon_" + item.key
}
var owned = animal?.numberOwned?.toString()
var totalNum = animal?.totalNumber?.toString()
this.ownedTextView.text = context?.getString(R.string.pet_ownership_fraction, owned, totalNum)
this.ownedTextView.background = context?.getDrawable(R.drawable.layout_rounded_bg_shopitem_price)
ownedTextView.visibility = if (animal?.type == "special") View.GONE else View.VISIBLE
imageView.background = null
DataBindingUtils.loadImage(imageName) {
val drawable = BitmapDrawable(context?.resources, it)
Observable.just(drawable)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
imageView.background = drawable
}, RxErrorHandler.handleEmptyError())
}
if (item.numberOwned <= 0) {
this.imageView.alpha = 0.2f
this.titleView.alpha = 0.2f
this.ownedTextView.alpha = 0.2f
context?.let {
var owned = item.numberOwned?.toString()
var totalNum = item.totalNumber?.toString()
this.ownedTextView.text = context?.getString(R.string.pet_ownership_fraction, owned, totalNum)
this.ownedTextView.background = context?.getDrawable(R.drawable.layout_rounded_bg_shopitem_price)
this.ownedTextView.setTextColor(ContextCompat.getColor(it, R.color.black) )
ownedTextView.visibility = if (animal?.type == "special") View.GONE else View.VISIBLE
imageView.background = null
DataBindingUtils.loadImage(imageName) {
val drawable = BitmapDrawable(context?.resources, it)
Observable.just(drawable)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
imageView.background = drawable
}, RxErrorHandler.handleEmptyError())
}
if (item.numberOwned <= 0) {
this.imageView.alpha = 0.2f
this.titleView.alpha = 0.2f
this.ownedTextView.alpha = 0.2f
}
if (item.numberOwned == item.totalNumber) {
this.ownedTextView.background = context?.getDrawable(R.drawable.layout_rounded_bg_animalitem_complete)
this.ownedTextView.setTextColor(ContextCompat.getColor(it, R.color.white))
}
}
if (item.numberOwned == item.totalNumber) {
this.ownedTextView.setTextColor(Color.parseColor("#FFFFFF"))
var new_background = context?.getDrawable(R.drawable.layout_rounded_bg_animalitem_complete)?.mutate()
this.ownedTextView.background = new_background
}
}
override fun onClick(v: View) {