thkouk00

home coupon recycler v1 WIP

......@@ -11,14 +11,23 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import org.json.JSONException;
import ly.warp.sdk.R;
import ly.warp.sdk.views.adapters.HomeCouponAdapter;
import ly.warp.sdk.activities.WarpViewActivity;
import ly.warp.sdk.io.models.Coupon;
import ly.warp.sdk.io.models.CouponList;
import ly.warp.sdk.views.adapters.ProfileCampaignAdapter;
public class HomeFragment extends Fragment {
private RelativeLayout mOptionOne;
private RelativeLayout mOptionTwo;
private RelativeLayout mOptionThree;
private RelativeLayout mOptionOne, mOptionTwo, mOptionThree;
private RecyclerView mRecyclerCoupons;
private HomeCouponAdapter mAdapterCoupons;
@Override
public View onCreateView(
......@@ -63,6 +72,30 @@ public class HomeFragment extends Fragment {
ImageView mOptionThreeImage = (ImageView) mOptionThree.findViewById(R.id.option_icon);
mOptionThreeText.setText("1");
mOptionThreeImage.setImageResource(R.drawable.tv_option);
/********* TEST DATA **********/
CouponList clist = new CouponList();
try {
clist.add(new Coupon("{\"session_uuid\": \"a724e911a71a42408b6ba50ae6c08dbb\", \"title\": \"\\u039a\\u03ac\\u03bd\\u03b5 strike\", \"subtitle\": \"\\u03ba\\u03b1\\u03b9 \\u03ba\\u03ad\\u03c1\\u03b4\\u03b9\\u03c3\\u03b5!\", \"offer_message\": null, \"message\": null, \"index_url\": \"https://warply.s3.amazonaws.com/artworks/034fba10ceac4e0f9338bd8e60086292/index.html\", \"logo_url\": \"https://warply.s3.amazonaws.com/temp/96322898cc824981aece923d8b5afc88/drggtdr.jpg\", \"starts\": 1644494400, \"expires\": 1881522000, \"delivered\": 1644607293, \"action\": 0, \"opened\": 1, \"offer_category\": \"standard-offer\", \"sorting\": 0, \"is_new\": true, \"session_metadata\": \"\\\"\\\"\", \"display_type\": null, \"delivery_method\": 2, \"extra_fields\": \"{}\", \"campaign_type\": null, \"campaign_type_settings\": null, \"actions\": null, \"show\": true, \"expired\": false, \"audience\": \"all\"}"));
clist.add(new Coupon("{\"session_uuid\": \"a724e911a71a42408b6ba50ae6c08dbb\", \"title\": \"\\u039a\\u03ac\\u03bd\\u03b5 strike\", \"subtitle\": \"\\u03ba\\u03b1\\u03b9 \\u03ba\\u03ad\\u03c1\\u03b4\\u03b9\\u03c3\\u03b5!\", \"offer_message\": null, \"message\": null, \"index_url\": \"https://warply.s3.amazonaws.com/artworks/034fba10ceac4e0f9338bd8e60086292/index.html\", \"logo_url\": \"https://warply.s3.amazonaws.com/temp/96322898cc824981aece923d8b5afc88/drggtdr.jpg\", \"starts\": 1644494400, \"expires\": 1881522000, \"delivered\": 1644607293, \"action\": 0, \"opened\": 1, \"offer_category\": \"standard-offer\", \"sorting\": 0, \"is_new\": true, \"session_metadata\": \"\\\"\\\"\", \"display_type\": null, \"delivery_method\": 2, \"extra_fields\": \"{}\", \"campaign_type\": null, \"campaign_type_settings\": null, \"actions\": null, \"show\": true, \"expired\": false, \"audience\": \"all\"}"));
} catch (JSONException e) {
e.printStackTrace();
}
/********* TEST DATA **********/
mRecyclerCoupons = view.findViewById(R.id.rv_home_coupons);
mRecyclerCoupons.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
mAdapterCoupons = new HomeCouponAdapter(getContext(), clist);
mRecyclerCoupons.setAdapter(mAdapterCoupons);
mAdapterCoupons.getPositionClicks()
.doOnNext(coupon -> {
getContext().startActivity(
WarpViewActivity.createIntentFromSessionUUID(getContext(),
coupon.getSessionUUID()));
})
.doOnError(error -> {
})
.subscribe();
}
@Override
......
package ly.warp.sdk.views.adapters;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import io.reactivex.Observable;
import io.reactivex.subjects.PublishSubject;
import ly.warp.sdk.R;
import ly.warp.sdk.io.models.Coupon;
import ly.warp.sdk.io.models.CouponList;
public class HomeCouponAdapter extends RecyclerView.Adapter<HomeCouponAdapter.HomeCouponViewHolder> {
private Context mContext;
private CouponList mCoupons;
private final PublishSubject<Coupon> onClickSubject = PublishSubject.create();
public HomeCouponAdapter(Context mContext, CouponList campaignList) {
this.mContext = mContext;
this.mCoupons = campaignList;
}
public class HomeCouponViewHolder extends RecyclerView.ViewHolder {
private ImageView ivCampaignTitle;
private TextView tvCampaignTitle;
public HomeCouponViewHolder(View view) {
super(view);
ivCampaignTitle = view.findViewById(R.id.iv_campaign_logo);
tvCampaignTitle = view.findViewById(R.id.tv_campaign_title);
}
}
@Override
public int getItemCount() {
if (mCoupons == null)
return 0;
else
return mCoupons.size();
}
public Coupon getItem(int id) {
return mCoupons.get(id);
}
public void updateData(CouponList couponList) {
mCoupons.clear();
mCoupons.addAll(couponList);
notifyDataSetChanged();
}
@Override
public HomeCouponViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.coupon_layout, parent, false);
return new HomeCouponViewHolder(itemView);
}
@Override
public void onBindViewHolder(final HomeCouponViewHolder holder, int position) {
Coupon couponItem = mCoupons.get(position);
if (couponItem != null) {
if (!TextUtils.isEmpty(couponItem.getLogoUrl())) {
Glide.with(mContext)
// .setDefaultRequestOptions(
// RequestOptions
// .placeholderOf(R.drawable.ic_default_contact_photo)
// .error(R.drawable.ic_default_contact_photo))
.load(couponItem.getLogoUrl())
.diskCacheStrategy(DiskCacheStrategy.DATA)
.into(holder.ivCampaignTitle);
} else {
Glide.with(mContext)
.load(R.drawable.ic_cosmote_logo_horizontal_grey)
.into(holder.ivCampaignTitle);
}
holder.tvCampaignTitle.setText(couponItem.getTitle());
holder.itemView.setOnClickListener(v -> onClickSubject.onNext(couponItem));
}
}
public Observable<Coupon> getPositionClicks() {
return onClickSubject.cache();
}
}
......@@ -101,15 +101,24 @@
<include layout="@layout/carousel_item" />
</RelativeLayout>
<RelativeLayout
<LinearLayout
android:id="@+id/rl_home_coupons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/rl_home_campaigns"
android:layout_marginVertical="25dp"
android:paddingHorizontal="15dp">
<include layout="@layout/coupon_layout"/>
</RelativeLayout>
<!-- <androidx.recyclerview.widget.RecyclerView-->
<!-- android:id="@+id/rv_home_coupons"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginBottom="8dp"-->
<!-- android:clipToPadding="false"-->
<!-- android:orientation="horizontal"-->
<!-- android:paddingEnd="10dp"-->
<!-- />-->
<include layout="@layout/coupon_layout" />
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/rl_home_info_widget"
......