From c84e6f2fa2385c8d5bc1e5a02683cc4513eef727 Mon Sep 17 00:00:00 2001 From: Franze Jr Date: Fri, 13 Nov 2015 18:47:24 -0300 Subject: [PATCH] [#36] Price gold centered and samll refactorings --- .../adapter/HabitItemRecyclerViewAdapter.java | 69 ++++++++++--------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/Habitica/src/com/habitrpg/android/habitica/ui/adapter/HabitItemRecyclerViewAdapter.java b/Habitica/src/com/habitrpg/android/habitica/ui/adapter/HabitItemRecyclerViewAdapter.java index b946dbdb1..50fd82303 100644 --- a/Habitica/src/com/habitrpg/android/habitica/ui/adapter/HabitItemRecyclerViewAdapter.java +++ b/Habitica/src/com/habitrpg/android/habitica/ui/adapter/HabitItemRecyclerViewAdapter.java @@ -485,38 +485,41 @@ public class HabitItemRecyclerViewAdapter if (v == binding.btnReward || v == binding.imageView3 || v == binding.gearElementsLayout) { LinearLayout contentViewForDialog = createContentViewForDialog(); - final MaterialDialog dialog = new MaterialDialog.Builder(context) - .onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) { - event.Reward = Item; - EventBus.getDefault().post(event); - } - }) - .positiveColor(context.getResources().getColor(R.color.brand_200)) - .positiveText("Buy") - .title(binding.getReward().getText()) - .customView(contentViewForDialog, true) - .negativeText("Dismiss") - .onNegative(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) { - materialDialog.dismiss(); - } - }).build(); - + MaterialDialog dialog = createGearDialog(event, contentViewForDialog); dialog.show(); } else super.onClick(v); } + private MaterialDialog createGearDialog(final BuyRewardTappedEvent event, LinearLayout contentViewForDialog) { + return new MaterialDialog.Builder(context) + .onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) { + event.Reward = Item; + EventBus.getDefault().post(event); + } + }) + .positiveColor(context.getResources().getColor(R.color.brand_200)) + .positiveText("Buy") + .title(binding.getReward().getText()) + .customView(contentViewForDialog, true) + .negativeText("Dismiss") + .onNegative(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) { + materialDialog.dismiss(); + } + }).build(); + } + @NonNull private LinearLayout createContentViewForDialog() { String price = String.format("%.0f", binding.getReward().value); String content = binding.getReward().getNotes(); - LinearLayout l = new LinearLayout(context); - l.setOrientation(LinearLayout.VERTICAL); + LinearLayout contentViewLayout = new LinearLayout(context); + contentViewLayout.setOrientation(LinearLayout.VERTICAL); ImageView imageView = new ImageView(context); imageView.setMinimumWidth(200); @@ -524,11 +527,11 @@ public class HabitItemRecyclerViewAdapter DataBindingUtils.loadImage(imageView, "shop_" + binding.getReward().getId()); - TextView t = new TextView(context); - t.setText(content); + TextView contentTextView = new TextView(context, null); + contentTextView.setText(content); - LinearLayout bottomLayout = new LinearLayout(context); - bottomLayout.setOrientation(LinearLayout.HORIZONTAL); + LinearLayout goldPriceLayout = new LinearLayout(context); + goldPriceLayout.setOrientation(LinearLayout.HORIZONTAL); TextView priceTextView = new TextView(context); priceTextView.setText(price); @@ -539,16 +542,16 @@ public class HabitItemRecyclerViewAdapter gold.setMinimumWidth(50); gold.setPadding(0, 0, 20, 0); - bottomLayout.addView(gold); - bottomLayout.addView(priceTextView); - bottomLayout.setGravity(Gravity.RIGHT); + goldPriceLayout.addView(gold); + goldPriceLayout.addView(priceTextView); + goldPriceLayout.setGravity(Gravity.CENTER); if(imageView.getDrawable()!= null){ - l.addView(imageView); + contentViewLayout.addView(imageView); } - l.addView(t); - l.addView(bottomLayout); - return l; + contentViewLayout.addView(goldPriceLayout); + contentViewLayout.addView(contentTextView); + return contentViewLayout; } @Override