Preyea Regmi
5 years ago
4 changed files with 246 additions and 0 deletions
-
79app/src/main/java/com/gmeremit/online/gmeremittance_native/accountmanage/adapter/paymentsources/PaymentSourceListAdapter.java
-
12app/src/main/java/com/gmeremit/online/gmeremittance_native/accountmanage/gateway/paymentsources/PaymentSourceRvViewHolder.java
-
91app/src/main/java/com/gmeremit/online/gmeremittance_native/customwidgets/SelectedRedBorderWithTickDecoration.java
-
64app/src/main/res/layout/payment_source_select_item.xml
@ -0,0 +1,79 @@ |
|||
package com.gmeremit.online.gmeremittance_native.accountmanage.adapter.paymentsources; |
|||
|
|||
import android.view.LayoutInflater; |
|||
import android.view.ViewGroup; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
import androidx.recyclerview.widget.RecyclerView; |
|||
|
|||
import com.gmeremit.online.gmeremittance_native.R; |
|||
import com.gmeremit.online.gmeremittance_native.accountmanage.gateway.paymentsources.PaymentSourceRvViewHolder; |
|||
import com.gmeremit.online.gmeremittance_native.accountmanage.model.paymentsources.PaymentSourceDTO; |
|||
import com.gmeremit.online.gmeremittance_native.customwidgets.SelectedRedBorderWithTickDecoration; |
|||
|
|||
import java.util.ArrayList; |
|||
|
|||
public class PaymentSourceListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements SelectedRedBorderWithTickDecoration.RedItemWithTickSelectionListener { |
|||
|
|||
private final PaymentSourceSelectionListener listener; |
|||
|
|||
private ArrayList<PaymentSourceDTO> data; |
|||
private int selectedItemIndex; |
|||
private static final int SELECT_NO_COUPON_VIEW = 12; |
|||
private static final int COUPON_VIEW = 13; |
|||
|
|||
public PaymentSourceListAdapter(PaymentSourceSelectionListener listener) { |
|||
this.listener = listener; |
|||
this.data = new ArrayList<>(); |
|||
selectedItemIndex = -1; |
|||
} |
|||
|
|||
@NonNull |
|||
@Override |
|||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
|||
return new PaymentSourceRvViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.payment_source_select_item, parent, false)); |
|||
} |
|||
|
|||
@Override |
|||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { |
|||
|
|||
} |
|||
|
|||
public void updateDataList(ArrayList<PaymentSourceDTO> data) { |
|||
if (data != null && data.size() > 0) { |
|||
this.data.clear(); |
|||
this.data.addAll(data); |
|||
notifyDataSetChanged(); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public int getItemViewType(int position) { |
|||
if (position == 0 && data.get(position) == null) { |
|||
return SELECT_NO_COUPON_VIEW; |
|||
} else |
|||
return COUPON_VIEW; |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public int getItemCount() { |
|||
return data.size(); |
|||
} |
|||
|
|||
@Override |
|||
public int getSelectedRedItemPosition() { |
|||
return this.selectedItemIndex; |
|||
} |
|||
|
|||
public void setCurrentSelectableItem(int i) { |
|||
this.selectedItemIndex = i; |
|||
if (listener != null) |
|||
listener.onPaymentSourceSelected(data.get(this.selectedItemIndex)); |
|||
|
|||
} |
|||
|
|||
public interface PaymentSourceSelectionListener { |
|||
void onPaymentSourceSelected(PaymentSourceDTO couponDTO); |
|||
} |
|||
} |
@ -0,0 +1,12 @@ |
|||
package com.gmeremit.online.gmeremittance_native.accountmanage.gateway.paymentsources; |
|||
|
|||
import android.view.View; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
import androidx.recyclerview.widget.RecyclerView; |
|||
|
|||
public class PaymentSourceRvViewHolder extends RecyclerView.ViewHolder { |
|||
public PaymentSourceRvViewHolder(@NonNull View itemView) { |
|||
super(itemView); |
|||
} |
|||
} |
@ -0,0 +1,91 @@ |
|||
package com.gmeremit.online.gmeremittance_native.customwidgets; |
|||
|
|||
import android.content.Context; |
|||
import android.graphics.Canvas; |
|||
import android.graphics.Paint; |
|||
import android.graphics.RectF; |
|||
import android.os.Build; |
|||
|
|||
import androidx.recyclerview.widget.RecyclerView; |
|||
|
|||
import com.gmeremit.online.gmeremittance_native.R; |
|||
import com.gmeremit.online.gmeremittance_native.utils.Utils; |
|||
|
|||
public class SelectedRedBorderWithTickDecoration extends RecyclerView.ItemDecoration { |
|||
|
|||
private float mRectWidth; |
|||
private float mCornerRadius; |
|||
private Paint mTickStampPaint; |
|||
private Paint mBorderPaint; |
|||
private float multi; |
|||
private Paint mTickColorPaint; |
|||
private RectF rectF; |
|||
|
|||
|
|||
public SelectedRedBorderWithTickDecoration(Context context) { |
|||
init(context); |
|||
} |
|||
|
|||
private void init(Context context) { |
|||
multi = context.getResources().getDisplayMetrics().density; |
|||
// mRectWidth = multi * 1; |
|||
// mCornerRadius = multi * 12; |
|||
mRectWidth = context.getResources().getDimension(R.dimen._1sdp); |
|||
mCornerRadius = context.getResources().getDimension(R.dimen._6sdp); |
|||
mBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
|||
mBorderPaint.setStyle(Paint.Style.STROKE); |
|||
mBorderPaint.setStrokeWidth(mRectWidth); |
|||
mBorderPaint.setStrokeCap(Paint.Cap.ROUND); |
|||
|
|||
mTickStampPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
|||
mTickStampPaint.setStyle(Paint.Style.FILL); |
|||
|
|||
mTickColorPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
|||
mTickColorPaint.setStyle(Paint.Style.STROKE); |
|||
mTickColorPaint.setStrokeWidth(mRectWidth); |
|||
mTickColorPaint.setStrokeCap(Paint.Cap.ROUND); |
|||
rectF = new RectF(); |
|||
if (Utils.getCurrentAPILevel() < Build.VERSION_CODES.M) { |
|||
mBorderPaint.setColor(context.getResources().getColor(R.color.colorPrimary)); |
|||
mTickStampPaint.setColor(context.getResources().getColor(R.color.colorPrimary)); |
|||
mTickColorPaint.setColor(context.getResources().getColor(R.color.colorPrimary)); |
|||
} else { |
|||
mBorderPaint.setColor(context.getResources().getColor(R.color.colorPrimary, null)); |
|||
mTickStampPaint.setColor(context.getResources().getColor(R.color.colorPrimary, null)); |
|||
mTickColorPaint.setColor(context.getResources().getColor(R.color.colorPrimary, null)); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { |
|||
int selectedPosition = ((RedItemWithTickSelectionListener) parent.getAdapter()).getSelectedRedItemPosition(); |
|||
for (int i = 0; i < parent.getChildCount(); i++) { |
|||
int childViewAdapterPosition = parent.getChildAdapterPosition(parent.getChildAt(i)); |
|||
if (childViewAdapterPosition == selectedPosition) { |
|||
|
|||
// |
|||
rectF.left = parent.getChildAt(i).getLeft() + mRectWidth; |
|||
rectF.top = parent.getChildAt(i).getTop() + mRectWidth; |
|||
rectF.right = parent.getChildAt(i).getRight() - mRectWidth; |
|||
rectF.bottom = parent.getChildAt(i).getBottom() - mRectWidth; |
|||
|
|||
c.drawRoundRect(rectF, mCornerRadius, mCornerRadius, mBorderPaint); |
|||
|
|||
drawTickStamp(c, parent.getChildAt(i).getRight() - (20 * multi), parent.getChildAt(i).getTop() +parent.getChildAt(i).getHeight()/2); |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
private void drawTickStamp(Canvas c, float x, float y) { |
|||
// c.drawCircle(x, y, 13 * multi, mTickStampPaint); |
|||
c.drawLine(x - (4 * multi), y, x, y + (3 * multi), mTickColorPaint); |
|||
c.drawLine(x, y + (3 * multi), x + (6.5f * multi), y - (4 * multi), mTickColorPaint); |
|||
} |
|||
|
|||
|
|||
public interface RedItemWithTickSelectionListener { |
|||
int getSelectedRedItemPosition(); |
|||
} |
|||
} |
@ -0,0 +1,64 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|||
xmlns:app="http://schemas.android.com/apk/res-auto" |
|||
xmlns:tools="http://schemas.android.com/tools" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="wrap_content" |
|||
android:background="@drawable/ic_rectangle_white_corners" |
|||
android:padding="@dimen/_8sdp" |
|||
android:minHeight="@dimen/_75sdp" |
|||
android:layout_marginStart="@dimen/_4sdp" |
|||
android:layout_marginEnd="@dimen/_4sdp" |
|||
android:layout_marginTop="@dimen/_4sdp"> |
|||
|
|||
<com.gmeremit.online.gmeremittance_native.customwidgets.GmeTextView |
|||
android:id="@+id/tv_coupon_name" |
|||
android:layout_width="0dp" |
|||
android:layout_height="match_parent" |
|||
android:layout_weight="1" |
|||
android:gravity="start" |
|||
android:textColor="@color/darkgray" |
|||
android:textSize="@dimen/_10ssp" |
|||
app:layout_constraintBottom_toTopOf="@+id/tv_coupon_type" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintHorizontal_bias="0.5" |
|||
app:layout_constraintStart_toStartOf="parent" |
|||
app:layout_constraintTop_toTopOf="parent" |
|||
app:txtfontName="@string/semibold" |
|||
android:layout_marginEnd="@dimen/_32sdp" |
|||
tools:text="Coupon Name" /> |
|||
|
|||
<com.gmeremit.online.gmeremittance_native.customwidgets.GmeTextView |
|||
android:paddingTop="@dimen/_2sdp" |
|||
android:paddingBottom="@dimen/_2sdp" |
|||
android:id="@+id/tv_coupon_type" |
|||
android:layout_width="0dp" |
|||
android:layout_height="wrap_content" |
|||
android:layout_weight="1" |
|||
android:gravity="start" |
|||
android:textColor="@color/darkgray" |
|||
android:textSize="@dimen/_13ssp" |
|||
app:layout_constraintBottom_toTopOf="@+id/tv_coupon_date" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintHorizontal_bias="0.5" |
|||
app:layout_constraintStart_toStartOf="parent" |
|||
app:layout_constraintTop_toBottomOf="@+id/tv_coupon_name" |
|||
app:txtfontName="@string/bold" |
|||
android:layout_marginEnd="@dimen/_32sdp" |
|||
tools:text="Coupon Type" /> |
|||
|
|||
<com.gmeremit.online.gmeremittance_native.customwidgets.GmeTextView |
|||
android:id="@+id/tv_coupon_date" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="wrap_content" |
|||
android:gravity="start" |
|||
android:textColor="@color/darkgray" |
|||
android:textSize="@dimen/_10ssp" |
|||
app:layout_constraintBottom_toBottomOf="parent" |
|||
app:layout_constraintTop_toBottomOf="@+id/tv_coupon_type" |
|||
app:txtfontName="@string/regular" |
|||
android:layout_marginEnd="@dimen/_32sdp" |
|||
tools:text="Date" /> |
|||
|
|||
|
|||
</androidx.constraintlayout.widget.ConstraintLayout> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue