Commit e6e8c712 authored by Muhammad Suryono's avatar Muhammad Suryono

check order cart

parent 8c179cce
......@@ -13,6 +13,7 @@ import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.Toast;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
......@@ -79,6 +80,13 @@ public class CartActivity extends AppCompatActivity {
sharedPreferences = getSharedPreferences(SplashScreen.MY_SHARED_PREFERENCES, Context.MODE_PRIVATE);
Log.i("Id Order on acart", "onCreate: "+orderId);
if (orderId.isEmpty()){
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(ORDER_ID, "MES-ORDER"+utils.timeStamp());
if (editor.commit()){
Toast.makeText(CartActivity.this, orderId, Toast.LENGTH_LONG).show();
}
}
// Toolbars
MaterialToolbar toolbars = findViewById(R.id.cAppBar);
setSupportActionBar(toolbars);
......@@ -99,7 +107,7 @@ public class CartActivity extends AppCompatActivity {
modelsCart = new ViewModelProvider(this).get(MainViewModelsCart.class);
modelsCart.getCartByOrderId(orderId).observe(this, new Observer<List<ProductCartModels>>() {
modelsCart.getCartById(orderId).observe(this, new Observer<List<ProductCartModels>>() {
@Override
public void onChanged(List<ProductCartModels> productCartModels) {
if (productCartModels != null) {
......@@ -171,7 +179,7 @@ public class CartActivity extends AppCompatActivity {
private void actionSaveCart() {
Client client = new Client();
modelsCart.getCartByOrderId(orderId).observe(this, new Observer<List<ProductCartModels>>() {
modelsCart.getCartById(orderId).observe(this, new Observer<List<ProductCartModels>>() {
@Override
public void onChanged(List<ProductCartModels> productCartModels) {
long grossAmount = 0;
......
......@@ -18,8 +18,8 @@ public interface CartDaos {
@Query("SELECT * FROM carts ORDER BY id DESC")
public LiveData<List<ProductCartModels>> getCart();
@Query("SELECT * FROM carts WHERE id_product_orders = :idCart")
public LiveData<List<ProductCartModels>> getCartById(long idCart);
@Query("SELECT * FROM carts WHERE id_orders = :idCart")
public LiveData<List<ProductCartModels>> getCartById(String idCart);
@Query("SELECT * FROM carts WHERE id_orders = :orderId AND id_product_orders = :idOrders")
public LiveData<List<ProductCartModels>> getCartByOrderId(String orderId, long idOrders);
......
......@@ -107,7 +107,7 @@ public class MainViewModelsCart extends AndroidViewModel {
});
}
public LiveData<List<ProductCartModels>> getCartById(long id){
public LiveData<List<ProductCartModels>> getCartById(String id){
return cartRepositories.getDataById(id);
}
......@@ -115,9 +115,9 @@ public class MainViewModelsCart extends AndroidViewModel {
return cartRepositories.getCartByOrderId(idOrders, idProduct);
}
public LiveData<List<ProductCartModels>> getCartByOrderId(long id){
return cartRepositories.getDataById(id);
}
// public LiveData<List<ProductCartModels>> getCartByOrderId(long id){
// return cartRepositories.getDataById(id);
// }
public MutableLiveData<ProductCartModels> getCart(){
// String js = new Gson().toJson(cartRepositories.getDataCart());
......
......@@ -42,7 +42,7 @@ public class CartRepositories {
LocalDatabase.databaseWriterExecutor.execute(() ->cartDaos.updateCart(qty, id));
}
public LiveData<List<ProductCartModels>> getDataById(long id){
public LiveData<List<ProductCartModels>> getDataById(String id){
return cartDaos.getCartById(id);
}
......
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