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