Panagiotis Triantafyllou

cosmote pass requests + ui

......@@ -17,8 +17,12 @@ import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.cardview.widget.CardView;
import androidx.core.content.res.ResourcesCompat;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.oned.EAN13Writer;
......@@ -28,12 +32,15 @@ import org.greenrobot.eventbus.EventBus;
import java.util.Locale;
import ly.warp.sdk.R;
import ly.warp.sdk.io.callbacks.CallbackReceiver;
import ly.warp.sdk.io.models.CustomTypefaceSpan;
import ly.warp.sdk.io.models.LoyaltySDKFirebaseEventModel;
import ly.warp.sdk.io.models.MarketPassDetailsModel;
import ly.warp.sdk.utils.WarpUtils;
import ly.warp.sdk.utils.WarplyManagerHelper;
import ly.warp.sdk.utils.managers.WarplyAnalyticsManager;
import ly.warp.sdk.utils.managers.WarplyEventBusManager;
import ly.warp.sdk.utils.managers.WarplyManager;
public class MarketPassActivity extends Activity implements View.OnClickListener {
......@@ -50,6 +57,10 @@ public class MarketPassActivity extends Activity implements View.OnClickListener
private TextView mFontHeader, mPassHeader, mPassSubtitle, mTvBarcode, mTvPassCount, mTvButtonMap;
private LinearLayout mLlMap, mLlParentLogosView;
private boolean mMapPressed = false, mPassInfoPressed = false;
private MarketPassDetailsModel mMarketPassDetails = new MarketPassDetailsModel();
private RelativeLayout mPbLoading;
private AlertDialog mAlertDialog;
private CardView mCvMarketDetails;
// ===========================================================
// Methods for/from SuperClass/Interfaces
......@@ -71,12 +82,16 @@ public class MarketPassActivity extends Activity implements View.OnClickListener
mTvButtonMap = findViewById(R.id.tv_button_map);
mLlMap = findViewById(R.id.ll_map);
mLlParentLogosView = findViewById(R.id.ll_sm_logos);
mPbLoading = findViewById(R.id.pb_loading);
mPbLoading.setOnTouchListener((v, event) -> true);
mCvMarketDetails = findViewById(R.id.cv_market_details);
WarpUtils.renderCustomFont(this, R.font.bt_cosmo_bold, mFontHeader, mPassHeader);
WarpUtils.renderCustomFont(this, R.font.peridot_regular, mPassSubtitle, mTvBarcode, mTvPassCount);
WarpUtils.renderCustomFont(this, R.font.peridot_semi_bold, mTvButtonMap);
initViews();
mPbLoading.setVisibility(View.VISIBLE);
WarplyManager.getMarketPassDetails(mMarketPassDetailsCallback);
}
@Override
......@@ -132,31 +147,42 @@ public class MarketPassActivity extends Activity implements View.OnClickListener
mIvInfo.setOnClickListener(this);
mLlMap.setOnClickListener(this);
//TODO: replace with dynmamic barcode
createBarcodeBitmap("4006381333931");
//TODO: replace with actual value
String passValue = String.format(Locale.GERMAN, "%.00f", 30f);
SpannableStringBuilder sBuilder = new SpannableStringBuilder();
sBuilder.append(String.format(getString(R.string.cos_market_pass_coupons_title), "30"));
Typeface typefaceBold = ResourcesCompat.getFont(this, R.font.peridot_bold);
CustomTypefaceSpan typefaceBoldSpan = new CustomTypefaceSpan(typefaceBold);
sBuilder.setSpan(typefaceBoldSpan, 31, 31 + passValue.length() + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mTvPassCount.setText(sBuilder, TextView.BufferType.SPANNABLE);
//TODO: replace with dynamic size of logos
for (int i = 0; i < 3; i++) {
int tempIndex = i;
LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout v = (RelativeLayout) vi.inflate(R.layout.item_sheet_image, null);
ImageView merchantLogo = (ImageView) v.findViewById(R.id.iv_market_logo);
merchantLogo.setImageResource(R.drawable.ic_ab_logo);
mLlParentLogosView.addView(v, tempIndex, new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
if (mMarketPassDetails != null)
createBarcodeBitmap(mMarketPassDetails.getBarcode());
if (mMarketPassDetails != null) {
String passValue = String.format(Locale.GERMAN, "%.02f", mMarketPassDetails.getTotalDiscount());
SpannableStringBuilder sBuilder = new SpannableStringBuilder();
sBuilder.append(String.format(getString(R.string.cos_market_pass_coupons_title), String.valueOf(mMarketPassDetails.getTotalDiscount())));
Typeface typefaceBold = ResourcesCompat.getFont(this, R.font.peridot_bold);
CustomTypefaceSpan typefaceBoldSpan = new CustomTypefaceSpan(typefaceBold);
sBuilder.setSpan(typefaceBoldSpan, 31, 31 + passValue.length() + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mTvPassCount.setText(sBuilder, TextView.BufferType.SPANNABLE);
}
if (mMarketPassDetails != null) {
for (int i = 0; i < mMarketPassDetails.getSupermarkets().size(); i++) {
int tempIndex = i;
LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout v = (RelativeLayout) vi.inflate(R.layout.item_sheet_image, null);
ImageView merchantLogo = (ImageView) v.findViewById(R.id.iv_market_logo);
Glide.with(this)
// .setDefaultRequestOptions(
// RequestOptions
// .placeholderOf(R.drawable.ic_default_contact_photo)
// .error(R.drawable.ic_default_contact_photo))
.load(mMarketPassDetails.getSupermarkets().get(i).getLogo())
.diskCacheStrategy(DiskCacheStrategy.DATA)
.into(merchantLogo);
mLlParentLogosView.addView(v, tempIndex, new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
}
}
mCvMarketDetails.setVisibility(View.VISIBLE);
}
private void createBarcodeBitmap(String barcodeString) {
......@@ -182,4 +208,27 @@ public class MarketPassActivity extends Activity implements View.OnClickListener
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
private final CallbackReceiver<MarketPassDetailsModel> mMarketPassDetailsCallback = new CallbackReceiver<MarketPassDetailsModel>() {
@Override
public void onSuccess(MarketPassDetailsModel result) {
mPbLoading.setVisibility(View.GONE);
mMarketPassDetails = result;
initViews();
}
@Override
public void onFailure(int errorCode) {
mPbLoading.setVisibility(View.GONE);
if (!isFinishing()) {
mAlertDialog = new AlertDialog.Builder(MarketPassActivity.this)
.setTitle(R.string.cos_dlg_error_subtitle)
.setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> {
dialogPositive.dismiss();
})
.show();
}
}
};
}
......
......@@ -42,15 +42,18 @@ public class MarketPassDetailsModel {
private static final String BARCODE = "barcode";
private static final String SUPERMARKETS = "supermarkets";
private static final String TOTAL_DISCOUNT = "total_available_discount";
private static final String NEW_OFFERS = "new_offers";
private ArrayList<Supermarkets> supermarkets = new ArrayList<Supermarkets>();
private String barcode = "";
private double totalDiscount = 0.0d;
private int newOffers = 0;
public MarketPassDetailsModel() {
this.supermarkets = new ArrayList<Supermarkets>();
this.barcode = "";
this.totalDiscount = 0.0d;
this.newOffers = 0;
}
/**
......@@ -81,6 +84,7 @@ public class MarketPassDetailsModel {
}
this.barcode = json.optString(BARCODE);
this.totalDiscount = json.optDouble(TOTAL_DISCOUNT);
this.newOffers = json.optInt(NEW_OFFERS);
}
}
......@@ -95,6 +99,7 @@ public class MarketPassDetailsModel {
jObj.putOpt(BARCODE, this.barcode);
jObj.putOpt(TOTAL_DISCOUNT, this.totalDiscount);
jObj.putOpt(SUPERMARKETS, this.supermarkets);
jObj.putOpt(NEW_OFFERS, this.newOffers);
} catch (JSONException e) {
if (WarpConstants.DEBUG) {
e.printStackTrace();
......@@ -148,15 +153,9 @@ public class MarketPassDetailsModel {
public Supermarkets(JSONObject json) {
if (json != null) {
if (json.optJSONObject(LOGO) != null) {
this.logo = json.optString(LOGO);
}
if (json.optJSONObject(NAME) != null) {
this.name = json.optString(NAME);
}
if (json.optJSONObject(UUID) != null) {
this.uuid = json.optString(UUID);
}
this.logo = json.optString(LOGO);
this.name = json.optString(NAME);
this.uuid = json.optString(UUID);
}
}
......@@ -213,4 +212,12 @@ public class MarketPassDetailsModel {
public void setTotalDiscount(double totalDiscount) {
this.totalDiscount = totalDiscount;
}
public int getNewOffers() {
return newOffers;
}
public void setNewOffers(int newOffers) {
this.newOffers = newOffers;
}
}
......
......@@ -109,6 +109,7 @@ public class ExpiredCouponAdapter extends RecyclerView.Adapter<ExpiredCouponAdap
if (couponItem != null) {
if (mIsCustom) {
holder.tvCouponTitle.setText(couponItem.getMerchantDetails().getAdminName());
holder.tvCouponsShop.setText(couponItem.getRedeemDetails().getName());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
holder.tvCouponSubtitle.setText(Html.fromHtml(couponItem.getCouponsetDetails().getInnerText(), Html.FROM_HTML_MODE_COMPACT));
} else {
......
......@@ -66,13 +66,16 @@
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:id="@+id/cv_market_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginVertical="24dp"
android:visibility="gone"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="16dp"
app:cardElevation="2dp">
app:cardElevation="2dp"
tools:visibility="visible">
<RelativeLayout
android:layout_width="match_parent"
......@@ -172,12 +175,12 @@
android:id="@+id/ll_sm_logos"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/ll_map"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@+id/ll_map">
app:layout_constraintTop_toTopOf="parent">
</LinearLayout>
......@@ -186,10 +189,10 @@
android:layout_width="148dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:layout_marginEnd="12dp"
android:background="@drawable/selector_button_green_border3"
android:gravity="center"
android:orientation="horizontal"
android:layout_marginEnd="12dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
......@@ -209,4 +212,25 @@
</androidx.cardview.widget.CardView>
</RelativeLayout>
</ScrollView>
<RelativeLayout
android:id="@+id/pb_loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible">
<ProgressBar
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_centerInParent="true"
android:indeterminate="true"
android:indeterminateTint="@color/cos_green5"
android:indeterminateTintMode="src_atop" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......