mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
More Kotlin!
This commit is contained in:
parent
8c3fae91cc
commit
c591b209e6
27 changed files with 333 additions and 373 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -56,3 +56,4 @@ habitica.properties
|
|||
habitica.resources
|
||||
Habitica/google-services.json
|
||||
reports/
|
||||
/prod
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ open class ShopItem : RealmObject() {
|
|||
var value: Int = 0
|
||||
var locked: Boolean = false
|
||||
var isLimited: Boolean = false
|
||||
var currency: String = ""
|
||||
var currency: String? = null
|
||||
var purchaseType: String = ""
|
||||
var categoryIdentifier: String = ""
|
||||
var limitedNumberLeft: Int? = null
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ public class ItemDetailDialog extends AlertDialog {
|
|||
|
||||
public void setImage(String imageName) {
|
||||
itemImageView.setVisibility(View.VISIBLE);
|
||||
DataBindingUtils.loadImage(itemImageView, imageName);
|
||||
DataBindingUtils.INSTANCE.loadImage(itemImageView, imageName);
|
||||
}
|
||||
|
||||
public void setBuyListener(OnClickListener listener) {
|
||||
|
|
|
|||
|
|
@ -642,7 +642,7 @@ public class MainActivity extends BaseActivity implements TutorialView.OnTutoria
|
|||
FrameLayout petWrapper = (FrameLayout) View.inflate(this, R.layout.pet_imageview, null);
|
||||
SimpleDraweeView petImageView = (SimpleDraweeView) petWrapper.findViewById(R.id.pet_imageview);
|
||||
|
||||
DataBindingUtils.loadImage(petImageView, "Pet-" + event.usingEgg.getKey() + "-" + event.usingHatchingPotion.getKey());
|
||||
DataBindingUtils.INSTANCE.loadImage(petImageView, "Pet-" + event.usingEgg.getKey() + "-" + event.usingHatchingPotion.getKey());
|
||||
String potionName = event.usingHatchingPotion.getText();
|
||||
String eggName = event.usingEgg.getText();
|
||||
AlertDialog dialog = new AlertDialog.Builder(MainActivity.this)
|
||||
|
|
@ -678,7 +678,7 @@ public class MainActivity extends BaseActivity implements TutorialView.OnTutoria
|
|||
FrameLayout mountWrapper = (FrameLayout) View.inflate(this, R.layout.pet_imageview, null);
|
||||
SimpleDraweeView mountImageView = (SimpleDraweeView) mountWrapper.findViewById(R.id.pet_imageview);
|
||||
|
||||
DataBindingUtils.loadImage(mountImageView, "Mount_Icon_" + event.usingPet.getKey());
|
||||
DataBindingUtils.INSTANCE.loadImage(mountImageView, "Mount_Icon_" + event.usingPet.getKey());
|
||||
String colorName = event.usingPet.getColorText();
|
||||
String animalName = event.usingPet.getAnimalText();
|
||||
AlertDialog dialog = new AlertDialog.Builder(MainActivity.this)
|
||||
|
|
@ -950,7 +950,7 @@ public class MainActivity extends BaseActivity implements TutorialView.OnTutoria
|
|||
|
||||
SimpleDraweeView imageView = (SimpleDraweeView) view.findViewById(R.id.imageView);
|
||||
String imageKey = event.notification.data.rewardKey.get(0);
|
||||
DataBindingUtils.loadImage(imageView, imageKey);
|
||||
DataBindingUtils.INSTANCE.loadImage(imageView, imageKey);
|
||||
|
||||
String youEarnedMessage = this.getString(R.string.checkInRewardEarned, event.notification.data.rewardText);
|
||||
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ public class CustomizationRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
|
|||
this.customization = customization;
|
||||
|
||||
|
||||
DataBindingUtils.loadImage(this.imageView, customization.getImageName(userSize, hairColor));
|
||||
DataBindingUtils.INSTANCE.loadImage(this.imageView, customization.getImageName(userSize, hairColor));
|
||||
cardView.setCardBackgroundColor(context.getResources().getColor(android.R.color.white));
|
||||
if (customization.isUsable()) {
|
||||
imageView.setAlpha(1.0f);
|
||||
|
|
@ -206,7 +206,7 @@ public class CustomizationRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
|
|||
LinearLayout dialogContent = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.dialog_purchase_customization, null);
|
||||
|
||||
SimpleDraweeView imageView = (SimpleDraweeView) dialogContent.findViewById(R.id.imageView);
|
||||
DataBindingUtils.loadImage(imageView, customization.getImageName(userSize, hairColor));
|
||||
DataBindingUtils.INSTANCE.loadImage(imageView, customization.getImageName(userSize, hairColor));
|
||||
|
||||
TextView priceLabel = (TextView) dialogContent.findViewById(R.id.priceLabel);
|
||||
priceLabel.setText(String.valueOf(customization.getPrice()));
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ public class SkillsRecyclerViewAdapter extends RecyclerView.Adapter<SkillsRecycl
|
|||
|
||||
priceButton.setCompoundDrawablesWithIntrinsicBounds(magicDrawable, null, null, null);
|
||||
}
|
||||
DataBindingUtils.loadImage(skillImageView, "shop_" + skill.key);
|
||||
DataBindingUtils.INSTANCE.loadImage(skillImageView, "shop_" + skill.key);
|
||||
|
||||
if (skill.mana > mana) {
|
||||
priceButton.setEnabled(false);
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ public class ItemRecyclerAdapter extends RealmRecyclerViewAdapter<Item, ItemRecy
|
|||
disabled = this.isPetOwned();
|
||||
}
|
||||
}
|
||||
DataBindingUtils.loadImage(imageView, imageName != null ? imageName : "head_0");
|
||||
DataBindingUtils.INSTANCE.loadImage(imageView, imageName != null ? imageName : "head_0");
|
||||
|
||||
float alpha = 1.0f;
|
||||
if (disabled) {
|
||||
|
|
|
|||
|
|
@ -88,9 +88,9 @@ public class MountDetailRecyclerAdapter extends RealmRecyclerViewAdapter<Mount,
|
|||
ownedTextView.setVisibility(View.GONE);
|
||||
this.imageView.setAlpha(1.0f);
|
||||
if (this.animal.getOwned()) {
|
||||
DataBindingUtils.loadImage(this.imageView, "Mount_Icon_" + itemType + "-" + item.getColor());
|
||||
DataBindingUtils.INSTANCE.loadImage(this.imageView, "Mount_Icon_" + itemType + "-" + item.getColor());
|
||||
} else {
|
||||
DataBindingUtils.loadImage(this.imageView, "PixelPaw");
|
||||
DataBindingUtils.INSTANCE.loadImage(this.imageView, "PixelPaw");
|
||||
this.imageView.setAlpha(0.3f);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,13 +104,13 @@ public class PetDetailRecyclerAdapter extends RealmRecyclerViewAdapter<Pet, PetD
|
|||
} else {
|
||||
this.trainedProgressbar.setProgress(this.animal.getTrained());
|
||||
}
|
||||
DataBindingUtils.loadImage(this.imageView, "Pet-" + itemType + "-" + item.getColor());
|
||||
DataBindingUtils.INSTANCE.loadImage(this.imageView, "Pet-" + itemType + "-" + item.getColor());
|
||||
} else {
|
||||
this.trainedProgressbar.setVisibility(View.GONE);
|
||||
if (this.animal.getTrained() == 0) {
|
||||
DataBindingUtils.loadImage(this.imageView, "PixelPaw");
|
||||
DataBindingUtils.INSTANCE.loadImage(this.imageView, "PixelPaw");
|
||||
} else {
|
||||
DataBindingUtils.loadImage(this.imageView, "Pet-" + itemType + "-" + item.getColor());
|
||||
DataBindingUtils.INSTANCE.loadImage(this.imageView, "Pet-" + itemType + "-" + item.getColor());
|
||||
}
|
||||
this.imageView.setAlpha(0.3f);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,9 +142,9 @@ class ShopRecyclerAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
|||
val item = obj as ShopItem
|
||||
(holder as ShopItemViewHolder).bind(item, item.canBuy(user))
|
||||
if (ownedItems.containsKey(item.key)) {
|
||||
holder.setItemCount(ownedItems[item.key]?.owned ?: 0)
|
||||
holder.itemCount = ownedItems[item.key]?.owned ?: 0
|
||||
}
|
||||
holder.setIsPinned(pinnedItemKeys.contains(item.key))
|
||||
holder.isPinned = pinnedItemKeys.contains(item.key)
|
||||
}
|
||||
String::class.java -> (holder as EmptyStateViewHolder).text = obj as String
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,13 +107,13 @@ public class StableRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.Vie
|
|||
if (animal.getNumberOwned() > 0) {
|
||||
this.ownedTextView.setText(String.valueOf(animal.getNumberOwned()));
|
||||
if (itemType.equals("pets")) {
|
||||
DataBindingUtils.loadImage(this.imageView, "Pet-" + item.getKey());
|
||||
DataBindingUtils.INSTANCE.loadImage(this.imageView, "Pet-" + item.getKey());
|
||||
} else {
|
||||
DataBindingUtils.loadImage(this.imageView, "Mount_Icon_" + item.getKey());
|
||||
DataBindingUtils.INSTANCE.loadImage(this.imageView, "Mount_Icon_" + item.getKey());
|
||||
}
|
||||
} else {
|
||||
ownedTextView.setVisibility(View.GONE);
|
||||
DataBindingUtils.loadImage(this.imageView, "PixelPaw");
|
||||
DataBindingUtils.INSTANCE.loadImage(this.imageView, "PixelPaw");
|
||||
this.imageView.setAlpha(0.4f);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,9 +150,9 @@ public class ChatRecyclerViewAdapter extends RealmRecyclerViewAdapter<ChatMessag
|
|||
|
||||
if (userBackground != null) {
|
||||
if (msg.sent != null && msg.sent.equals("true") && sendingUser != null) {
|
||||
DataBindingUtils.setRoundedBackgroundInt(userBackground, sendingUser.getContributorColor());
|
||||
DataBindingUtils.INSTANCE.setRoundedBackgroundInt(userBackground, sendingUser.getContributorColor());
|
||||
} else {
|
||||
DataBindingUtils.setRoundedBackgroundInt(userBackground, msg.getContributorColor());
|
||||
DataBindingUtils.INSTANCE.setRoundedBackgroundInt(userBackground, msg.getContributorColor());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -171,7 +171,7 @@ public class ChatRecyclerViewAdapter extends RealmRecyclerViewAdapter<ChatMessag
|
|||
userLabel.setOnClickListener(view -> userLabelClickEvents.onNext(msg.uuid));
|
||||
}
|
||||
|
||||
DataBindingUtils.setForegroundTintColor(userLabel, msg.getContributorForegroundColor());
|
||||
DataBindingUtils.INSTANCE.setForegroundTintColor(userLabel, msg.getContributorForegroundColor());
|
||||
|
||||
if (messageText != null) {
|
||||
messageText.setText(chatMessage.parsedText);
|
||||
|
|
@ -214,7 +214,7 @@ public class ChatRecyclerViewAdapter extends RealmRecyclerViewAdapter<ChatMessag
|
|||
foregroundColorRes = R.color.tavern_nolikes_foreground;
|
||||
}
|
||||
|
||||
DataBindingUtils.setRoundedBackground(likeBackground, ContextCompat.getColor(context, backgroundColorRes));
|
||||
DataBindingUtils.INSTANCE.setRoundedBackground(likeBackground, ContextCompat.getColor(context, backgroundColorRes));
|
||||
tvLikes.setTextColor(ContextCompat.getColor(context, foregroundColorRes));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,8 +62,8 @@ public class RewardsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||
} else if (inAppRewards != null) {
|
||||
ShopItem item = inAppRewards.get(position-getCustomRewardCount());
|
||||
((ShopItemViewHolder)holder).bind(item, item.canBuy(user));
|
||||
((ShopItemViewHolder)holder).setIsPinned(true);
|
||||
((ShopItemViewHolder)holder).pinIndicator.setVisibility(View.GONE);
|
||||
((ShopItemViewHolder)holder).setPinned(true);
|
||||
((ShopItemViewHolder) holder).hidePinIndicator();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -108,8 +108,8 @@ class ShopsFragment : BaseMainFragment() {
|
|||
if (user == null) {
|
||||
return
|
||||
}
|
||||
currencyView.setGold(user!!.stats.getGp())
|
||||
currencyView.setGems(user!!.gemCount)
|
||||
currencyView.setHourglasses(user!!.hourglassCount)
|
||||
currencyView.gold = user?.stats?.getGp()?.toDouble() ?: 0.0
|
||||
currencyView.gems = user?.gemCount?.toDouble() ?: 0.0
|
||||
currencyView.hourglasses = user?.hourglassCount?.toDouble() ?: 0.0
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ public class QuestDetailFragment extends BaseMainFragment {
|
|||
}
|
||||
questTitleView.setText(questContent.getText());
|
||||
questDescriptionView.setText(MarkdownParser.parseMarkdown(questContent.getNotes()));
|
||||
DataBindingUtils.loadImage(questScrollImageView, "inventory_quest_scroll_"+questContent.getKey());
|
||||
DataBindingUtils.INSTANCE.loadImage(questScrollImageView, "inventory_quest_scroll_"+questContent.getKey());
|
||||
}
|
||||
|
||||
private void setQuestParticipants(List<Member> participants) {
|
||||
|
|
|
|||
|
|
@ -195,8 +195,8 @@ public class PartyDetailFragment extends BaseFragment {
|
|||
return;
|
||||
}
|
||||
questTitleView.setText(questContent.getText());
|
||||
DataBindingUtils.loadImage(questScrollImageView, "inventory_quest_scroll_"+questContent.getKey());
|
||||
DataBindingUtils.loadImage(questImageView, "quest_"+questContent.getKey());
|
||||
DataBindingUtils.INSTANCE.loadImage(questScrollImageView, "inventory_quest_scroll_"+questContent.getKey());
|
||||
DataBindingUtils.INSTANCE.loadImage(questImageView, "quest_"+questContent.getKey());
|
||||
if (isQuestActive()) {
|
||||
questProgressView.setVisibility(View.VISIBLE);
|
||||
questProgressView.setData(questContent, quest.getProgress());
|
||||
|
|
|
|||
|
|
@ -1,86 +0,0 @@
|
|||
package com.habitrpg.android.habitica.ui.helpers;
|
||||
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.content.res.ResourcesCompat;
|
||||
import android.view.View;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.Transformation;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
|
||||
import net.pherth.android.emoji_library.EmojiTextView;
|
||||
|
||||
public class DataBindingUtils {
|
||||
|
||||
public static void loadImage(SimpleDraweeView view, String imageName) {
|
||||
if (view != null && view.getVisibility() == View.VISIBLE) {
|
||||
view.setImageURI(Uri.parse("https://habitica-assets.s3.amazonaws.com/mobileApp/images/" + imageName + ".png"));
|
||||
}
|
||||
}
|
||||
|
||||
public static void setForegroundTintColor(TextView view, int color) {
|
||||
if (color > 0) {
|
||||
color = ContextCompat.getColor(view.getContext(), color);
|
||||
}
|
||||
view.setTextColor(color);
|
||||
}
|
||||
|
||||
public static void setRoundedBackground(View view, int color) {
|
||||
Drawable drawable = ResourcesCompat.getDrawable(view.getResources(), R.drawable.layout_rounded_bg, null);
|
||||
if (drawable != null) {
|
||||
drawable.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
|
||||
}
|
||||
if (Build.VERSION.SDK_INT < 16) {
|
||||
view.setBackgroundDrawable(drawable);
|
||||
} else {
|
||||
view.setBackground(drawable);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setRoundedBackgroundInt(View view, int color) {
|
||||
if (color != 0) {
|
||||
setRoundedBackground(view, ContextCompat.getColor(view.getContext(), color));
|
||||
}
|
||||
}
|
||||
|
||||
public static void bindEmojiconTextView(EmojiTextView textView, CharSequence value) {
|
||||
if (value != null) {
|
||||
textView.setText(MarkdownParser.parseMarkdown(value.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
public static class LayoutWeightAnimation extends Animation {
|
||||
float targetWeight;
|
||||
float initializeWeight;
|
||||
View view;
|
||||
|
||||
LinearLayout.LayoutParams layoutParams;
|
||||
|
||||
public LayoutWeightAnimation(View view, float targetWeight) {
|
||||
this.view = view;
|
||||
this.targetWeight = targetWeight;
|
||||
|
||||
layoutParams = (LinearLayout.LayoutParams) view.getLayoutParams();
|
||||
initializeWeight = layoutParams.weight;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
||||
layoutParams.weight = initializeWeight + (targetWeight - initializeWeight) * interpolatedTime;
|
||||
|
||||
view.requestLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean willChangeBounds() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
package com.habitrpg.android.habitica.ui.helpers
|
||||
|
||||
import android.graphics.PorterDuff
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v4.content.res.ResourcesCompat
|
||||
import android.view.View
|
||||
import android.view.animation.Animation
|
||||
import android.view.animation.Transformation
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView
|
||||
import com.habitrpg.android.habitica.R
|
||||
|
||||
object DataBindingUtils {
|
||||
|
||||
fun loadImage(view: SimpleDraweeView?, imageName: String?) {
|
||||
if (view != null && imageName != null && view.visibility == View.VISIBLE) {
|
||||
view.setImageURI("https://habitica-assets.s3.amazonaws.com/mobileApp/images/$imageName.png")
|
||||
}
|
||||
}
|
||||
|
||||
fun setForegroundTintColor(view: TextView, color: Int) {
|
||||
var color = color
|
||||
if (color > 0) {
|
||||
color = ContextCompat.getColor(view.context, color)
|
||||
}
|
||||
view.setTextColor(color)
|
||||
}
|
||||
|
||||
fun setRoundedBackground(view: View, color: Int) {
|
||||
val drawable = ResourcesCompat.getDrawable(view.resources, R.drawable.layout_rounded_bg, null)
|
||||
drawable?.setColorFilter(color, PorterDuff.Mode.MULTIPLY)
|
||||
if (Build.VERSION.SDK_INT < 16) {
|
||||
view.setBackgroundDrawable(drawable)
|
||||
} else {
|
||||
view.background = drawable
|
||||
}
|
||||
}
|
||||
|
||||
fun setRoundedBackgroundInt(view: View, color: Int) {
|
||||
if (color != 0) {
|
||||
setRoundedBackground(view, ContextCompat.getColor(view.context, color))
|
||||
}
|
||||
}
|
||||
|
||||
class LayoutWeightAnimation(internal var view: View, internal var targetWeight: Float) : Animation() {
|
||||
private var initializeWeight: Float = 0.toFloat()
|
||||
|
||||
private var layoutParams: LinearLayout.LayoutParams = view.layoutParams as LinearLayout.LayoutParams
|
||||
|
||||
init {
|
||||
initializeWeight = layoutParams.weight
|
||||
}
|
||||
|
||||
override fun applyTransformation(interpolatedTime: Float, t: Transformation) {
|
||||
layoutParams.weight = initializeWeight + (targetWeight - initializeWeight) * interpolatedTime
|
||||
|
||||
view.requestLayout()
|
||||
}
|
||||
|
||||
override fun willChangeBounds(): Boolean = true
|
||||
}
|
||||
}
|
||||
|
|
@ -1,115 +0,0 @@
|
|||
package com.habitrpg.android.habitica.ui.viewHolders;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.habitrpg.android.habitica.HabiticaBaseApplication;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.models.shops.ShopItem;
|
||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils;
|
||||
import com.habitrpg.android.habitica.ui.views.CurrencyView;
|
||||
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper;
|
||||
import com.habitrpg.android.habitica.ui.views.shops.PurchaseDialog;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class ShopItemViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
|
||||
@BindView(R.id.imageView)
|
||||
SimpleDraweeView imageView;
|
||||
@BindView(R.id.buyButton)
|
||||
View buyButton;
|
||||
@BindView(R.id.priceLabel)
|
||||
CurrencyView priceLabel;
|
||||
|
||||
@BindView(R.id.item_detail_indicator)
|
||||
TextView itemDetailIndicator;
|
||||
|
||||
@BindView(R.id.pin_indicator)
|
||||
public
|
||||
ImageView pinIndicator;
|
||||
|
||||
public String shopIdentifier;
|
||||
private ShopItem item;
|
||||
private boolean isPinned;
|
||||
|
||||
private Context context;
|
||||
|
||||
Drawable lockedDrawable;
|
||||
Drawable limitedDrawable;
|
||||
Drawable countDrawable;
|
||||
|
||||
public ShopItemViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
context = itemView.getContext();
|
||||
|
||||
ButterKnife.bind(this, itemView);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
itemView.setClickable(true);
|
||||
|
||||
lockedDrawable = new BitmapDrawable(context.getResources(), HabiticaIconsHelper.imageOfItemIndicatorLocked());
|
||||
limitedDrawable = new BitmapDrawable(context.getResources(), HabiticaIconsHelper.imageOfItemIndicatorLimited());
|
||||
countDrawable = new BitmapDrawable(context.getResources(), HabiticaIconsHelper.imageOfItemIndicatorNumber());
|
||||
pinIndicator.setImageBitmap(HabiticaIconsHelper.imageOfPinnedItem());
|
||||
}
|
||||
|
||||
public void bind(ShopItem item, boolean canBuy) {
|
||||
this.item = item;
|
||||
buyButton.setVisibility(View.VISIBLE);
|
||||
|
||||
DataBindingUtils.loadImage(this.imageView, item.getImageName());
|
||||
|
||||
if (item.getUnlockCondition() == null || !item.getLocked()) {
|
||||
priceLabel.setText(String.valueOf(item.getValue()));
|
||||
priceLabel.setCurrency(item.getCurrency());
|
||||
if (item.getCurrency() == null) {
|
||||
buyButton.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
priceLabel.setText(item.getUnlockCondition().readableUnlockConditionId());
|
||||
}
|
||||
|
||||
itemDetailIndicator.setText(null);
|
||||
itemDetailIndicator.setVisibility(View.GONE);
|
||||
if (item.isLimited()) {
|
||||
itemDetailIndicator.setBackground(limitedDrawable);
|
||||
itemDetailIndicator.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
priceLabel.setLocked(item.getLocked() || !canBuy);
|
||||
if (item.getLocked()) {
|
||||
itemDetailIndicator.setBackground(lockedDrawable);
|
||||
itemDetailIndicator.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
public void setItemCount(int count) {
|
||||
if (count > 0) {
|
||||
itemDetailIndicator.setText(String.valueOf(count));
|
||||
itemDetailIndicator.setBackground(countDrawable);
|
||||
itemDetailIndicator.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
public void setIsPinned(boolean isPinned) {
|
||||
this.isPinned = isPinned;
|
||||
pinIndicator.setVisibility(isPinned ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
PurchaseDialog dialog = new PurchaseDialog(context, HabiticaBaseApplication.getComponent(), item);
|
||||
dialog.shopIdentifier = shopIdentifier;
|
||||
dialog.setIsPinned(isPinned);
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
package com.habitrpg.android.habitica.ui.viewHolders
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import com.facebook.drawee.view.SimpleDraweeView
|
||||
import com.habitrpg.android.habitica.HabiticaBaseApplication
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.extensions.bindView
|
||||
import com.habitrpg.android.habitica.models.shops.ShopItem
|
||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
|
||||
import com.habitrpg.android.habitica.ui.views.CurrencyView
|
||||
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
|
||||
import com.habitrpg.android.habitica.ui.views.shops.PurchaseDialog
|
||||
|
||||
class ShopItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), View.OnClickListener {
|
||||
|
||||
private val imageView: SimpleDraweeView by bindView(itemView, R.id.imageView)
|
||||
private val buyButton: View by bindView(itemView, R.id.buyButton)
|
||||
private val priceLabel: CurrencyView by bindView(itemView, R.id.priceLabel)
|
||||
private val itemDetailIndicator: TextView by bindView(itemView, R.id.item_detail_indicator)
|
||||
private val pinIndicator: ImageView by bindView(itemView, R.id.pin_indicator)
|
||||
|
||||
var shopIdentifier: String? = null
|
||||
private var item: ShopItem? = null
|
||||
|
||||
private var context: Context = itemView.context
|
||||
|
||||
private var lockedDrawable = BitmapDrawable(context.resources, HabiticaIconsHelper.imageOfItemIndicatorLocked())
|
||||
private var limitedDrawable = BitmapDrawable(context.resources, HabiticaIconsHelper.imageOfItemIndicatorLimited())
|
||||
private var countDrawable = BitmapDrawable(context.resources, HabiticaIconsHelper.imageOfItemIndicatorNumber())
|
||||
|
||||
var itemCount = 0
|
||||
set(value) {
|
||||
field = value
|
||||
if (value > 0) {
|
||||
itemDetailIndicator.text = value.toString()
|
||||
itemDetailIndicator.background = countDrawable
|
||||
itemDetailIndicator.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
var isPinned = false
|
||||
set(value) {
|
||||
field =value
|
||||
pinIndicator.visibility = if (isPinned) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
init {
|
||||
itemView.setOnClickListener(this)
|
||||
itemView.isClickable = true
|
||||
pinIndicator.setImageBitmap(HabiticaIconsHelper.imageOfPinnedItem())
|
||||
}
|
||||
|
||||
fun bind(item: ShopItem, canBuy: Boolean) {
|
||||
this.item = item
|
||||
buyButton.visibility = View.VISIBLE
|
||||
|
||||
DataBindingUtils.loadImage(this.imageView, item.imageName)
|
||||
|
||||
if (item.unlockCondition == null || !item.locked) {
|
||||
priceLabel.text = item.value.toString()
|
||||
priceLabel.currency = item.currency
|
||||
if (item.currency == null) {
|
||||
buyButton.visibility = View.GONE
|
||||
}
|
||||
} else {
|
||||
priceLabel.setText(item.unlockCondition!!.readableUnlockConditionId())
|
||||
}
|
||||
|
||||
itemDetailIndicator.text = null
|
||||
itemDetailIndicator.visibility = View.GONE
|
||||
if (item.isLimited) {
|
||||
itemDetailIndicator.background = limitedDrawable
|
||||
itemDetailIndicator.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
priceLabel.isLocked = item.locked || !canBuy
|
||||
if (item.locked) {
|
||||
itemDetailIndicator.background = lockedDrawable
|
||||
itemDetailIndicator.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
override fun onClick(view: View) {
|
||||
val dialog = PurchaseDialog(context, HabiticaBaseApplication.getComponent(), item)
|
||||
dialog.shopIdentifier = shopIdentifier
|
||||
dialog.setIsPinned(isPinned)
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
fun hidePinIndicator() {
|
||||
pinIndicator.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
|
@ -12,50 +12,92 @@ import com.habitrpg.android.habitica.R
|
|||
import com.habitrpg.android.habitica.helpers.NumberAbbreviator
|
||||
|
||||
class CurrencyView : android.support.v7.widget.AppCompatTextView {
|
||||
|
||||
private var lightbackground = false
|
||||
var lightBackground: Boolean = false
|
||||
set(value) {
|
||||
field = value
|
||||
configureCurrency()
|
||||
}
|
||||
var currency: String? = null
|
||||
set(currency) {
|
||||
field = currency
|
||||
if ("gold" == currency) {
|
||||
setIcon(HabiticaIconsHelper.imageOfGold())
|
||||
if (lightbackground) {
|
||||
setTextColor(ContextCompat.getColor(context, R.color.yellow_5))
|
||||
} else {
|
||||
setTextColor(ContextCompat.getColor(context, R.color.yellow_100))
|
||||
}
|
||||
} else if ("gems" == currency) {
|
||||
setIcon(HabiticaIconsHelper.imageOfGem())
|
||||
if (lightbackground) {
|
||||
setTextColor(ContextCompat.getColor(context, R.color.green_100))
|
||||
} else {
|
||||
setTextColor(ContextCompat.getColor(context, R.color.green_50))
|
||||
}
|
||||
} else if ("hourglasses" == currency) {
|
||||
setIcon(HabiticaIconsHelper.imageOfHourglass())
|
||||
if (lightbackground) {
|
||||
setTextColor(ContextCompat.getColor(context, R.color.brand_300))
|
||||
} else {
|
||||
setTextColor(ContextCompat.getColor(context, R.color.brand_500))
|
||||
}
|
||||
}
|
||||
configureCurrency()
|
||||
updateVisibility()
|
||||
}
|
||||
private var drawable: BitmapDrawable? = null
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {}
|
||||
|
||||
constructor(context: Context, currency: String, lightbackground: Boolean) : super(context) {
|
||||
this.lightbackground = lightbackground
|
||||
this.lightBackground = lightbackground
|
||||
this.currency = currency
|
||||
}
|
||||
|
||||
private fun setIcon(iconBitmap: Bitmap) {
|
||||
drawable = BitmapDrawable(resources, iconBitmap)
|
||||
private fun configureCurrency() {
|
||||
if ("gold" == currency) {
|
||||
icon = HabiticaIconsHelper.imageOfGold()
|
||||
if (lightBackground) {
|
||||
setTextColor(ContextCompat.getColor(context, R.color.yellow_5))
|
||||
} else {
|
||||
setTextColor(ContextCompat.getColor(context, R.color.yellow_100))
|
||||
}
|
||||
} else if ("gems" == currency) {
|
||||
icon = HabiticaIconsHelper.imageOfGem()
|
||||
if (lightBackground) {
|
||||
setTextColor(ContextCompat.getColor(context, R.color.green_100))
|
||||
} else {
|
||||
setTextColor(ContextCompat.getColor(context, R.color.green_50))
|
||||
}
|
||||
} else if ("hourglasses" == currency) {
|
||||
icon = HabiticaIconsHelper.imageOfHourglass()
|
||||
if (lightBackground) {
|
||||
setTextColor(ContextCompat.getColor(context, R.color.brand_300))
|
||||
} else {
|
||||
setTextColor(ContextCompat.getColor(context, R.color.brand_500))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var drawable: BitmapDrawable? = null
|
||||
|
||||
var icon: Bitmap? = null
|
||||
set(value) {
|
||||
field = value
|
||||
if (value != null) {
|
||||
drawable = BitmapDrawable(resources, value)
|
||||
this.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
|
||||
val padding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 6f, context.resources.displayMetrics).toInt()
|
||||
compoundDrawablePadding = padding
|
||||
this.gravity = Gravity.CENTER_VERTICAL
|
||||
}
|
||||
}
|
||||
|
||||
var value = 0.0
|
||||
set(value) {
|
||||
field = value
|
||||
text = NumberAbbreviator.abbreviate(context, value)
|
||||
updateVisibility()
|
||||
}
|
||||
|
||||
var isLocked = false
|
||||
set(value) {
|
||||
field = value
|
||||
if (isLocked) {
|
||||
this.setTextColor(ContextCompat.getColor(context, R.color.gray_300))
|
||||
drawable?.alpha = 127
|
||||
} else {
|
||||
drawable?.alpha = 255
|
||||
}
|
||||
this.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
|
||||
}
|
||||
|
||||
var cantAfford = false
|
||||
set(value) {
|
||||
if (cantAfford) {
|
||||
this.setTextColor(ContextCompat.getColor(context, R.color.red_50))
|
||||
drawable?.alpha = 127
|
||||
} else {
|
||||
drawable?.alpha = 255
|
||||
}
|
||||
this.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
|
||||
val padding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 6f, context.resources.displayMetrics).toInt()
|
||||
compoundDrawablePadding = padding
|
||||
this.gravity = Gravity.CENTER_VERTICAL
|
||||
}
|
||||
|
||||
private fun updateVisibility() {
|
||||
|
|
@ -63,37 +105,4 @@ class CurrencyView : android.support.v7.widget.AppCompatTextView {
|
|||
visibility = if ("0" == text) View.GONE else View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
fun setValue(value: Double?) {
|
||||
text = NumberAbbreviator.abbreviate(context, value!!)
|
||||
updateVisibility()
|
||||
}
|
||||
|
||||
fun setLocked(isLocked: Boolean) {
|
||||
if (drawable == null) {
|
||||
return
|
||||
}
|
||||
if (isLocked) {
|
||||
this.setTextColor(ContextCompat.getColor(context, R.color.gray_300))
|
||||
drawable!!.alpha = 127
|
||||
} else {
|
||||
drawable!!.alpha = 255
|
||||
}
|
||||
|
||||
this.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
|
||||
}
|
||||
|
||||
fun setCantAfford(cantAfford: Boolean) {
|
||||
if (drawable == null) {
|
||||
return
|
||||
}
|
||||
if (cantAfford) {
|
||||
this.setTextColor(ContextCompat.getColor(context, R.color.red_50))
|
||||
drawable!!.alpha = 127
|
||||
} else {
|
||||
drawable!!.alpha = 255
|
||||
}
|
||||
|
||||
this.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,73 +0,0 @@
|
|||
package com.habitrpg.android.habitica.ui.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
|
||||
/**
|
||||
* Created by phillip on 08.09.17.
|
||||
*/
|
||||
|
||||
public class CurrencyViews extends LinearLayout {
|
||||
private CurrencyView hourglassTextView;
|
||||
private CurrencyView goldTextView;
|
||||
private CurrencyView gemTextView;
|
||||
public boolean lightbackground;
|
||||
|
||||
public CurrencyViews(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
TypedArray attributes = context.getTheme().obtainStyledAttributes(
|
||||
attrs,
|
||||
R.styleable.CurrencyViews,
|
||||
0, 0);
|
||||
|
||||
lightbackground = attributes.getBoolean(R.styleable.CurrencyViews_hasLightBackground, true);
|
||||
|
||||
setupViews();
|
||||
}
|
||||
|
||||
public CurrencyViews(Context context) {
|
||||
super(context);
|
||||
setupViews();
|
||||
}
|
||||
|
||||
private void setupViews() {
|
||||
Resources r = getContext().getResources();
|
||||
int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12, r.getDisplayMetrics());
|
||||
|
||||
hourglassTextView = new CurrencyView(getContext(), "hourglasses", lightbackground);
|
||||
this.addView(hourglassTextView);
|
||||
LinearLayout.LayoutParams hourglassParams = (LayoutParams) hourglassTextView.getLayoutParams();
|
||||
hourglassParams.setMargins(margin, 0, 0, 0);
|
||||
hourglassTextView.setLayoutParams(hourglassParams);
|
||||
goldTextView = new CurrencyView(getContext(), "gold", lightbackground);
|
||||
this.addView(goldTextView);
|
||||
LinearLayout.LayoutParams goldParams = (LayoutParams) goldTextView.getLayoutParams();
|
||||
goldParams.setMargins(margin, 0, 0, 0);
|
||||
goldTextView.setLayoutParams(goldParams);
|
||||
gemTextView = new CurrencyView(getContext(), "gems", lightbackground);
|
||||
this.addView(gemTextView);
|
||||
LinearLayout.LayoutParams gemParams = (LayoutParams) gemTextView.getLayoutParams();
|
||||
gemParams.setMargins(margin, 0, 0, 0);
|
||||
gemTextView.setLayoutParams(gemParams);
|
||||
}
|
||||
|
||||
public void setGold(Double gold) {
|
||||
goldTextView.setValue(gold);
|
||||
}
|
||||
|
||||
public void setGems(Integer gemCount) {
|
||||
gemTextView.setValue(Double.valueOf(gemCount));
|
||||
}
|
||||
|
||||
public void setHourglasses(Integer hourglassCount) {
|
||||
hourglassTextView.setText(String.valueOf(hourglassCount));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package com.habitrpg.android.habitica.ui.views
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.util.TypedValue
|
||||
import android.widget.LinearLayout
|
||||
import com.habitrpg.android.habitica.R
|
||||
|
||||
class CurrencyViews : LinearLayout {
|
||||
var lightBackground: Boolean = false
|
||||
set(value) {
|
||||
field = value
|
||||
hourglassTextView.lightBackground = value
|
||||
gemTextView.lightBackground = value
|
||||
goldTextView.lightBackground = value
|
||||
}
|
||||
private val hourglassTextView: CurrencyView = CurrencyView(context, "hourglasses", lightBackground)
|
||||
private val goldTextView: CurrencyView = CurrencyView(context, "gold", lightBackground)
|
||||
private val gemTextView: CurrencyView = CurrencyView(context, "gems", lightBackground)
|
||||
|
||||
var gold: Double
|
||||
get() = goldTextView.value
|
||||
set(value) { goldTextView.value = value }
|
||||
var gems: Double
|
||||
get() = goldTextView.value
|
||||
set(value) { gemTextView.value = value }
|
||||
var hourglasses: Double
|
||||
get() = hourglassTextView.value
|
||||
set(value) { hourglassTextView.value = value }
|
||||
|
||||
|
||||
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
|
||||
|
||||
val attributes = context?.theme?.obtainStyledAttributes(
|
||||
attrs,
|
||||
R.styleable.CurrencyViews,
|
||||
0, 0)
|
||||
setupViews()
|
||||
lightBackground = attributes?.getBoolean(R.styleable.CurrencyViews_hasLightBackground, true) ?: true
|
||||
}
|
||||
|
||||
constructor(context: Context?) : super(context) {
|
||||
setupViews()
|
||||
}
|
||||
|
||||
private fun setupViews() {
|
||||
val margin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12f, context.resources.displayMetrics).toInt()
|
||||
setupView(hourglassTextView, margin)
|
||||
setupView(goldTextView, margin)
|
||||
setupView(gemTextView, margin)
|
||||
}
|
||||
|
||||
private fun setupView(view: CurrencyView, margin: Int) {
|
||||
this.addView(view)
|
||||
val params = view.layoutParams as LayoutParams
|
||||
params.setMargins(margin, 0, 0, 0)
|
||||
view.layoutParams = params
|
||||
}
|
||||
}
|
||||
|
|
@ -50,7 +50,7 @@ public class ValueBar extends FrameLayout {
|
|||
setLightBackground(attributes.getBoolean(R.styleable.ValueBar_lightBackground, false));
|
||||
|
||||
int color = attributes.getColor(R.styleable.ValueBar_barForegroundColor, 0);
|
||||
DataBindingUtils.setRoundedBackground(barView, color);
|
||||
DataBindingUtils.INSTANCE.setRoundedBackground(barView, color);
|
||||
|
||||
Drawable iconRes = attributes.getDrawable(R.styleable.ValueBar_barIconDrawable);
|
||||
if (iconRes != null) {
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public abstract class PurchaseDialogContent extends LinearLayout {
|
|||
|
||||
|
||||
public void setItem(ShopItem item) {
|
||||
DataBindingUtils.loadImage(imageView, item.getImageName());
|
||||
DataBindingUtils.INSTANCE.loadImage(imageView, item.getImageName());
|
||||
titleTextView.setText(item.getText());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ public class PurchaseDialogQuestContent extends PurchaseDialogContent {
|
|||
ViewGroup view = (ViewGroup) inflater.inflate(R.layout.row_quest_reward, containerView, false);
|
||||
SimpleDraweeView imageView = (SimpleDraweeView) view.findViewById(R.id.imageView);
|
||||
TextView titleTextView = (TextView) view.findViewById(R.id.titleTextView);
|
||||
DataBindingUtils.loadImage(imageView, item.getImageName());
|
||||
DataBindingUtils.INSTANCE.loadImage(imageView, item.getImageName());
|
||||
if (item.getCount() > 1) {
|
||||
titleTextView.setText(getContext().getString(R.string.quest_reward_count, item.getText(), item.getCount()));
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public class QuestProgressView extends LinearLayout {
|
|||
SimpleDraweeView iconView = (SimpleDraweeView) view.findViewById(R.id.icon_view);
|
||||
TextView nameView = (TextView) view.findViewById(R.id.name_view);
|
||||
ValueBar valueView = (ValueBar) view.findViewById(R.id.value_view);
|
||||
DataBindingUtils.loadImage(iconView, "quest_" + quest.getKey() + "_" + collect.key);
|
||||
DataBindingUtils.INSTANCE.loadImage(iconView, "quest_" + quest.getKey() + "_" + collect.key);
|
||||
nameView.setText(contentCollect.text);
|
||||
valueView.set(collect.count, contentCollect.count);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue