Resize petnmounts cards (#1310)

* resize cards and font

* resolve merge conflict in strings

* add background

* resize mounts cards

* fix recyclerview bug

* change stringto accept decimals

Co-authored-by: Phillip Thelen <viirus@pherth.net>
This commit is contained in:
Phillip Thelen 2020-06-11 12:00:53 +02:00 committed by GitHub
commit 95ce5666ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 198 additions and 60 deletions

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/animalitem_all_eggs" />
<corners android:bottomLeftRadius="6dp" android:bottomRightRadius="6dp"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

View file

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<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"
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"
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"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="@+id/ownedTextView"
style="@style/RowText"/>
</LinearLayout>

View file

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:background="@color/white"
android:focusable="true">
<LinearLayout
android:id="@+id/card_view"
android:layout_width="127dp"
android:layout_height="140dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="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="79dp"
android:layout_height="94dp"
android:layout_gravity="center_horizontal"
android:scaleType="fitEnd" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3.5dp"
android:layout_gravity="center_horizontal"
android:id="@+id/titleTextView"
android:textSize="13sp"
android:gravity="center"
style="@style/RowTitle"/>
<TextView
android:id="@+id/ownedTextView"
style="@style/RowText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:background="@drawable/layout_rounded_bg_shopitem_price"
android:gravity="center"
android:textSize="12sp" />
</LinearLayout>
</RelativeLayout>

View file

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:background="@color/white"
android:focusable="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
android:layout_width="80dp"
android:layout_height="108dp"
android:orientation="vertical"
android:background="@drawable/layout_rounded_bg_shopitem"
android:layout_centerInParent="true">
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_marginBottom="3.5dp"
android:layout_gravity="center_horizontal"
android:id="@+id/titleTextView"
android:textSize="13sp"
android:gravity="center"
style="@style/RowTitle"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:id="@+id/ownedTextView"
android:gravity="center"
android:textSize="12sp"
android:background="@drawable/layout_rounded_bg_shopitem_price"
style="@style/RowText"/>
</LinearLayout>
</RelativeLayout>

View file

@ -148,6 +148,7 @@
<color name="black">#000</color>
<color name="setup_background">#efeff4</color>
<color name="setup_label_background">#fafaff</color>
<color name="animalitem_all_eggs">#6ECDB2</color>
<color name="dark_brown">#794b00</color>
</resources>

View file

@ -50,10 +50,13 @@
<dimen name="row_title_size">16sp</dimen>
<dimen name="row_text_size">14sp</dimen>
<dimen name="row_title_bottommargin">2dp</dimen>
<dimen name="pet_width">120dp</dimen>
<dimen name="pet_width">84dp</dimen>
<dimen name="mount_width">120dp</dimen>
<dimen name="bottom_menu_padding">28dp</dimen>
<dimen name="pet_image_width">81dp</dimen>
<dimen name="pet_image_height">99dp</dimen>
<dimen name="pet_image_width">68dp</dimen>
<dimen name="pet_image_height">65dp</dimen>
<dimen name="mount_image_width">81dp</dimen>
<dimen name="mount_image_height">99dp</dimen>
<dimen name="shop_height">124dp</dimen>
<dimen name="bar_icon_padding">10dp</dimen>
<dimen name="task_text_padding">16dp</dimen>

View file

@ -1015,6 +1015,8 @@
<string name="read_more">Read More</string>
<string name="purchase_amount_error">You are unable to buy that amount.</string>
<string name="still_questions">Still have a question?</string>
<string name="delete_checklist_entry">Delete Checklist entry</string>
<string name="pet_ownership_fraction">%1$d/%2$d</string>
<string name="task_display">Task list display</string>
<string name="onboarding_tasks">Onboarding Tasks</string>
<string name="complete_for_gold">Complete to earn 100 Gold!</string>

View file

@ -6,6 +6,6 @@
</trust-anchors>
</debug-overrides>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">192.168.178.52</domain>
<domain includeSubdomains="true">10.0.0.107</domain>
</domain-config>
</network-security-config>

View file

@ -29,4 +29,8 @@ public interface Animal {
Integer getNumberOwned();
void setNumberOwned(Integer numberOwned);
Integer getTotalNumber();
void setTotalNumber(Integer totalNumber);
}

View file

@ -12,7 +12,10 @@ public class Mount extends RealmObject implements Animal {
boolean premium;
@Ignore
Integer numberOwned;
private Integer numberOwned;
@Ignore
private Integer totalNumber;
public String getKey() {
return key;
@ -82,4 +85,15 @@ public class Mount extends RealmObject implements Animal {
public void setNumberOwned(Integer numberOwned) {
this.numberOwned = numberOwned;
}
public Integer getTotalNumber() {
if (totalNumber == null) {
return 0;
}
return totalNumber;
}
public void setTotalNumber(Integer totalNumber) {
this.totalNumber = totalNumber;
}
}

View file

@ -14,6 +14,9 @@ public class Pet extends RealmObject implements Animal{
@Ignore
private Integer numberOwned;
@Ignore
private Integer totalNumber;
public String getKey() {
return key;
}
@ -83,4 +86,16 @@ public class Pet extends RealmObject implements Animal{
public void setNumberOwned(Integer numberOwned) {
this.numberOwned = numberOwned;
}
public Integer getTotalNumber() {
if (totalNumber == null) {
return 0;
}
return totalNumber;
}
public void setTotalNumber(Integer totalNumber) {
this.totalNumber = totalNumber;
}
}

View file

@ -39,7 +39,7 @@ class MountDetailRecyclerAdapter(data: OrderedRealmCollection<Mount>?, autoUpdat
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MountViewHolder {
return MountViewHolder(parent.inflate(R.layout.animal_overview_item))
return MountViewHolder(parent.inflate(R.layout.mount_overview_item))
}
override fun onBindViewHolder(holder: MountViewHolder, position: Int) {

View file

@ -1,14 +1,12 @@
package com.habitrpg.android.habitica.ui.adapter.inventory
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.BitmapDrawable
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.GridLayoutManager
import com.facebook.drawee.view.SimpleDraweeView
import com.habitrpg.android.habitica.R
@ -47,9 +45,11 @@ class StableRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<
} else if (viewType == 1) {
val view = parent.inflate(R.layout.customization_section_header)
SectionViewHolder(view)
}
else {
val view = parent.inflate(R.layout.animal_overview_item)
} else if (viewType == 2) {
val view = parent.inflate(R.layout.pet_overview_item)
StableViewHolder(view)
} else {
val view = parent.inflate(R.layout.mount_overview_item)
StableViewHolder(view)
}
@ -72,15 +72,20 @@ class StableRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<
}
override fun getItemViewType(position: Int): Int {
return if (itemList[position] == "header") {
var item = itemList[position]
return if (item == "header") {
0
}
else if (itemList[position].javaClass == String::class.java) {
else if (item.javaClass == String::class.java) {
1
}
else {
else if (itemType == "pets") {
2
}
else {
3
}
}
override fun getItemCount(): Int = itemList.size
@ -118,25 +123,49 @@ class StableRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<
}
ownedTextView.visibility = View.VISIBLE
this.imageView.alpha = 1.0f
this.titleView.alpha = 1.0f
this.ownedTextView.alpha = 1.0f
val imageName = if (itemType == "pets") {
"Pet-" + item.key
"Pet_Egg_" + item.animal
} else {
"Mount_Icon_" + item.key
}
this.ownedTextView.text = animal?.numberOwned?.toString()
ownedTextView.visibility = if (animal?.numberOwned == 0 || animal?.type == "special") View.GONE else View.VISIBLE
imageView.background = 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.background = drawable
}, RxErrorHandler.handleEmptyError())
}
if (item.numberOwned <= 0) {
this.imageView.alpha = 0.1f
context?.let {
var owned = item.numberOwned
var totalNum = item.totalNumber
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))
}
}
}
override fun onClick(v: View) {

View file

@ -106,7 +106,8 @@ class StableRecyclerFragment : BaseFragment() {
private fun setGridSpanCount(width: Int) {
var spanCount = 0
if (context != null && context?.resources != null) {
val itemWidth: Float = context?.resources?.getDimension(R.dimen.pet_width) ?: 0.toFloat()
var animal_width = if (itemType == "pets") R.dimen.pet_width else R.dimen.mount_width
val itemWidth: Float = context?.resources?.getDimension(animal_width) ?: 0.toFloat()
spanCount = (width / itemWidth).toInt()
}
@ -144,7 +145,6 @@ class StableRecyclerFragment : BaseFragment() {
val items = ArrayList<Any>()
var lastAnimal: Animal = unsortedAnimals[0] ?: return items
var lastSectionTitle = ""
for (animal in unsortedAnimals) {
val identifier = if (animal.animal.isNotEmpty() && animal.type != "special") animal.animal else animal.key
val lastIdentifier = if (lastAnimal.animal.isNotEmpty()) lastAnimal.animal else lastAnimal.key
@ -154,6 +154,9 @@ class StableRecyclerFragment : BaseFragment() {
}
lastAnimal = animal
}
lastAnimal.totalNumber += 1
if (animal.type != lastSectionTitle) {
if (items.size > 0 && items[items.size - 1].javaClass == String::class.java) {
items.removeAt(items.size - 1)
@ -175,6 +178,7 @@ class StableRecyclerFragment : BaseFragment() {
}
}
}
}
if (!((lastAnimal.type == "premium" || lastAnimal.type == "special") && lastAnimal.numberOwned == 0)) {
items.add(lastAnimal)
@ -187,6 +191,5 @@ class StableRecyclerFragment : BaseFragment() {
companion object {
private const val ITEM_TYPE_KEY = "CLASS_TYPE_KEY"
private const val HEADER_VIEW_TYPE = 0
private const val SECTION_VIEW_TYPE = 1
}
}