Commit 6ea65ccb authored by Muhammad Suryono's avatar Muhammad Suryono

Merge branch 'cart' into dev

parents e689243a b2224723
......@@ -6,8 +6,11 @@ import androidx.recyclerview.widget.RecyclerView;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.Toast;
import android.widget.Toolbar;
import com.google.android.material.appbar.MaterialToolbar;
......@@ -19,6 +22,9 @@ import java.util.ArrayList;
public class PaymentActivity extends AppCompatActivity {
private ArrayList<PaymentResponse> paymentResponses = new ArrayList<>();
Button btnPay;
public static String methodPay="";
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -40,7 +46,7 @@ public class PaymentActivity extends AppCompatActivity {
RecyclerView rvPayment = findViewById(R.id.rvPayment);
LinearLayoutManager llm = new LinearLayoutManager(this);
LinearLayoutManager llm = new LinearLayoutManager(this, RecyclerView.VERTICAL, false);
rvPayment.setLayoutManager(llm);
paymentResponses.add(new PaymentResponse("https://i.ibb.co/RjJQT9K/BNI-logo.png", "cash"));
......@@ -51,5 +57,18 @@ public class PaymentActivity extends AppCompatActivity {
PaymentAdapter adapter = new PaymentAdapter(paymentResponses, this);
rvPayment.setAdapter(adapter);
btnPay = findViewById(R.id.btnPay);
adapter.setListener(paymentResponse -> {
methodPay = paymentResponse.getBank();
btnPay.setEnabled(true);
});
btnPay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), methodPay, Toast.LENGTH_LONG).show();
}
});
}
}
\ No newline at end of file
package com.yono.messeripos.adapter;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
......@@ -87,6 +88,7 @@ public class CartAdapter extends RecyclerView.Adapter<CartAdapter.MyViewHolder>
this.binding = binding;
}
@SuppressLint("SetTextI18n")
public void bindData(ProductCartModels cartModels) {
binding.setCarts(cartModels);
binding.setPrice(utils.convertPrice("Rp. ", cartModels.getPrice_orders()));
......
......@@ -6,6 +6,7 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.Toast;
import androidx.annotation.NonNull;
......@@ -17,6 +18,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.card.MaterialCardView;
import com.yono.messeripos.PaymentActivity;
import com.yono.messeripos.models.ProductCartModels;
import com.yono.messeripos.response.PaymentResponse;
import com.yono.messeripos.R;
import com.yono.messeripos.databinding.PaymentListBinding;
......@@ -29,6 +31,16 @@ public class PaymentAdapter extends RecyclerView.Adapter<PaymentAdapter.ViewHold
Context context;
int getPosition = -1;
public interface PaymentListener {
void onSelectPayment(PaymentResponse paymentResponse);
}
private PaymentListener listener;
public void setListener(PaymentListener listener) {
this.listener = listener;
}
public PaymentAdapter(ArrayList<PaymentResponse> paymentResponses, PaymentActivity mainActivity) {
this.paymentResponses = paymentResponses;
this.context = mainActivity;
......@@ -58,7 +70,8 @@ public class PaymentAdapter extends RecyclerView.Adapter<PaymentAdapter.ViewHold
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.binData(paymentResponses.get(position));
// holder.radioButton.setChecked(position == getPosition);
holder.radioButton.setChecked(position == getPosition);
// final PaymentModel paymentModel = paymentModels.get(position);
//
// ImageView imageView = holder.logoComp;
......@@ -76,15 +89,13 @@ public class PaymentAdapter extends RecyclerView.Adapter<PaymentAdapter.ViewHold
}
public class ViewHolder extends RecyclerView.ViewHolder {
MaterialCardView cardView;
PaymentListBinding binding;
public int position;
RadioButton radioButton;
public ViewHolder(@NonNull PaymentListBinding view) {
super(view.getRoot());
this.binding = view;
getPosition = getAdapterPosition();
Log.d("ViewHolder: ", String.valueOf(cardView));
this.radioButton = view.rbPayment;
}
@SuppressLint("ResourceAsColor")
......@@ -92,15 +103,10 @@ public class PaymentAdapter extends RecyclerView.Adapter<PaymentAdapter.ViewHold
binding.setPayment(paymentResponse);
binding.setLogo(paymentResponse.getUrl());
Log.d("Position ", ""+getAdapterPosition());
binding.cvPayment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d("Click VC", paymentResponse.getBank());
binding.cvPayment.toggle();
}
});
binding.cvPayment.setOnClickListener(view ->{
getPosition = getAdapterPosition();
notifyDataSetChanged();
listener.onSelectPayment(paymentResponse);});
}
}
}
......@@ -19,7 +19,8 @@
android:id="@+id/rvPayment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/appbar"/>
app:layout_constraintTop_toBottomOf="@id/appbar"
/>
<com.google.android.material.button.MaterialButton
android:id="@+id/btnPay"
......@@ -28,6 +29,7 @@
android:text="pay"
android:padding="15dp"
android:textSize="16sp"
android:enabled="false"
android:layout_margin="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
......
......@@ -67,6 +67,16 @@
app:layout_constraintTop_toTopOf="parent"
/>
<RadioButton
android:id="@+id/rbPayment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@color/colorPrimary"
android:enabled="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment