Commit d720eb45 authored by Muhammad Suryono's avatar Muhammad Suryono

Fix product add image convert and design by iman

parents 507446b0 69a2726d
...@@ -90,7 +90,7 @@ public class BottomSheets extends BottomSheetDialogFragment { ...@@ -90,7 +90,7 @@ public class BottomSheets extends BottomSheetDialogFragment {
grossAmount = paymentsModels.getGrossAmount(); grossAmount = paymentsModels.getGrossAmount();
long input = Long.parseLong(inputAmount.getText().toString()); long input = Long.parseLong(inputAmount.getText().toString());
long result = grossAmount - input; long result = input-grossAmount;
hargaChange.setText(utils.convertPrice("Rp.", result)); hargaChange.setText(utils.convertPrice("Rp.", result));
......
...@@ -13,10 +13,12 @@ import android.view.View; ...@@ -13,10 +13,12 @@ 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.Button;
import android.widget.ImageView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.DividerItemDecoration;
...@@ -55,20 +57,35 @@ public class CartActivity extends AppCompatActivity { ...@@ -55,20 +57,35 @@ public class CartActivity extends AppCompatActivity {
List<ProductCartModels> dataCart = null; List<ProductCartModels> dataCart = null;
public static Boolean statusPost; public static Boolean statusPost;
SharedPreferences sharedPreferences; SharedPreferences sharedPreferences;
ImageView cartEmptyImage;
MaterialTextView cartEmptyText;
public static MaterialTextView grandToral; public static MaterialTextView grandToral;
Utils utils = new Utils(); Utils utils = new Utils();
public static long GrandTotal = 0;
MaterialButton btnSaveCart; MaterialButton btnSaveCart;
Button btnBayar; Button btnCheckout;
CardView cardView;
@RequiresApi(api = Build.VERSION_CODES.N) @RequiresApi(api = Build.VERSION_CODES.N)
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cart); setContentView(R.layout.activity_cart);
Button btnCheckout;
grandToral = findViewById(R.id.tvHarga); grandToral = findViewById(R.id.tvHarga);
btnSaveCart = findViewById(R.id.btSave); btnSaveCart = findViewById(R.id.btSave);
cartEmptyImage = findViewById(R.id.cartEmpty);
cartEmptyText = findViewById(R.id.cartEmptyText);
recyclerView = findViewById(R.id.rvCart);
btnCheckout = findViewById(R.id.btCheckout);
cardView = findViewById(R.id.cardviews);
// set visibility gone for cartEmpty
cartEmptyImage.bringToFront();
cartEmptyText.bringToFront();
cartEmptyImage.setVisibility(View.GONE);
cartEmptyText.setVisibility(View.GONE);
modelsCart = new ViewModelProvider(this).get(MainViewModelsCart.class); modelsCart = new ViewModelProvider(this).get(MainViewModelsCart.class);
...@@ -82,11 +99,13 @@ public class CartActivity extends AppCompatActivity { ...@@ -82,11 +99,13 @@ public class CartActivity extends AppCompatActivity {
Log.i("Id Order on acart", "onCreate: "+orderId); Log.i("Id Order on acart", "onCreate: "+orderId);
if (orderId.isEmpty()){ if (orderId.isEmpty()){
SharedPreferences.Editor editor = sharedPreferences.edit(); SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(ORDER_ID, "MES-ORDER"+utils.timeStamp()); editor.putString(ORDER_ID, "MES-ORDER"+orderId);
if (editor.commit()){ if (editor.commit()){
Toast.makeText(CartActivity.this, orderId, Toast.LENGTH_LONG).show(); Toast.makeText(CartActivity.this, orderId, Toast.LENGTH_LONG).show();
} }
} }
// Toolbars // Toolbars
MaterialToolbar toolbars = findViewById(R.id.cAppBar); MaterialToolbar toolbars = findViewById(R.id.cAppBar);
setSupportActionBar(toolbars); setSupportActionBar(toolbars);
...@@ -95,8 +114,6 @@ public class CartActivity extends AppCompatActivity { ...@@ -95,8 +114,6 @@ public class CartActivity extends AppCompatActivity {
getSupportActionBar().setTitle("Cart"); getSupportActionBar().setTitle("Cart");
toolbars.setNavigationOnClickListener(view -> onBackPressed()); toolbars.setNavigationOnClickListener(view -> onBackPressed());
recyclerView = findViewById(R.id.rvCart);
btnCheckout = findViewById(R.id.btCheckout);
cartAdapter = new CartAdapter(); cartAdapter = new CartAdapter();
LinearLayoutManager llm = new LinearLayoutManager(this); LinearLayoutManager llm = new LinearLayoutManager(this);
...@@ -107,13 +124,19 @@ public class CartActivity extends AppCompatActivity { ...@@ -107,13 +124,19 @@ public class CartActivity extends AppCompatActivity {
modelsCart = new ViewModelProvider(this).get(MainViewModelsCart.class); modelsCart = new ViewModelProvider(this).get(MainViewModelsCart.class);
// show to cart
modelsCart.getCartById(orderId).observe(this, new Observer<List<ProductCartModels>>() { modelsCart.getCartById(orderId).observe(this, new Observer<List<ProductCartModels>>() {
@Override @Override
public void onChanged(List<ProductCartModels> productCartModels) { public void onChanged(List<ProductCartModels> productCartModels) {
if (productCartModels != null) { if (!productCartModels.isEmpty()) {
dataCart = productCartModels; dataCart = productCartModels;
cartAdapter.setCartAdapter(CartActivity.this, productCartModels); cartAdapter.setCartAdapter(CartActivity.this, productCartModels);
recyclerView.setAdapter(cartAdapter); recyclerView.setAdapter(cartAdapter);
}else {
cartEmptyText.setVisibility(View.VISIBLE);
cartEmptyImage.setVisibility(View.VISIBLE);
cardView.setVisibility(View.GONE);
recyclerView.setVisibility(View.GONE);
} }
} }
}); });
......
...@@ -10,8 +10,10 @@ import android.content.Intent; ...@@ -10,8 +10,10 @@ import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.View;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.ProgressBar;
import com.google.android.material.appbar.MaterialToolbar; import com.google.android.material.appbar.MaterialToolbar;
import com.yono.messeripos.adapter.TransactionAdapter; import com.yono.messeripos.adapter.TransactionAdapter;
...@@ -31,6 +33,7 @@ public class HistoryActivity extends AppCompatActivity { ...@@ -31,6 +33,7 @@ public class HistoryActivity extends AppCompatActivity {
MainViewModels mainViewModels; MainViewModels mainViewModels;
RecyclerView recyclerView; RecyclerView recyclerView;
Utils utils = new Utils(); Utils utils = new Utils();
ProgressBar loading;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -44,6 +47,9 @@ public class HistoryActivity extends AppCompatActivity { ...@@ -44,6 +47,9 @@ public class HistoryActivity extends AppCompatActivity {
MaterialToolbar toolbars = findViewById(R.id.cAppBar); MaterialToolbar toolbars = findViewById(R.id.cAppBar);
recyclerView = findViewById(R.id.rvHistory); recyclerView = findViewById(R.id.rvHistory);
loading = findViewById(R.id.loading);
loading.setVisibility(View.VISIBLE);
recyclerView.addItemDecoration(utils.dividerItemDecoration(HistoryActivity.this)); recyclerView.addItemDecoration(utils.dividerItemDecoration(HistoryActivity.this));
transactionAdapter = new TransactionAdapter(); transactionAdapter = new TransactionAdapter();
mainViewModels = new ViewModelProvider(this).get(MainViewModels.class); mainViewModels = new ViewModelProvider(this).get(MainViewModels.class);
...@@ -75,6 +81,8 @@ public class HistoryActivity extends AppCompatActivity { ...@@ -75,6 +81,8 @@ public class HistoryActivity extends AppCompatActivity {
* SILAHKAN PINDAH KE ACTIVITY SELANJUTNYA PADA ON..... * SILAHKAN PINDAH KE ACTIVITY SELANJUTNYA PADA ON.....
* */ * */
loading.setVisibility(View.GONE);
recyclerView.setLayoutManager(new LinearLayoutManager(HistoryActivity.this,RecyclerView.VERTICAL,false)); recyclerView.setLayoutManager(new LinearLayoutManager(HistoryActivity.this,RecyclerView.VERTICAL,false));
recyclerView.setAdapter(transactionAdapter); recyclerView.setAdapter(transactionAdapter);
} }
......
...@@ -7,9 +7,11 @@ import android.content.Intent; ...@@ -7,9 +7,11 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.service.controls.actions.ModeAction;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.Log; import android.util.Log;
import android.view.ActionMode;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
...@@ -29,6 +31,7 @@ import androidx.recyclerview.widget.GridLayoutManager; ...@@ -29,6 +31,7 @@ import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import com.google.android.material.appbar.MaterialToolbar; import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.snackbar.Snackbar;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.yono.messeripos.adapter.CategoryAdapter; import com.yono.messeripos.adapter.CategoryAdapter;
import com.yono.messeripos.adapter.ProductAdapter; import com.yono.messeripos.adapter.ProductAdapter;
...@@ -70,6 +73,7 @@ public class MainActivity extends AppCompatActivity { ...@@ -70,6 +73,7 @@ public class MainActivity extends AppCompatActivity {
public static ArrayList<ProductModels> productModelsArrayList = new ArrayList<>(); public static ArrayList<ProductModels> productModelsArrayList = new ArrayList<>();
public static final String DATA_PRODUCT = "DATA_PRODUCT"; public static final String DATA_PRODUCT = "DATA_PRODUCT";
ProgressDialog progressDialog; ProgressDialog progressDialog;
public static Boolean cartOpen;
@SuppressLint("LongLogTag") @SuppressLint("LongLogTag")
@Override @Override
...@@ -239,6 +243,10 @@ public class MainActivity extends AppCompatActivity { ...@@ -239,6 +243,10 @@ public class MainActivity extends AppCompatActivity {
binding.rvProduct.setAdapter(productAdapter); binding.rvProduct.setAdapter(productAdapter);
} }
} else {
showLoading(false);
binding.imgEmpty.setVisibility(View.VISIBLE);
binding.imgEmpty.bringToFront();
} }
} }
}); });
...@@ -287,10 +295,10 @@ public class MainActivity extends AppCompatActivity { ...@@ -287,10 +295,10 @@ public class MainActivity extends AppCompatActivity {
0 0
)); ));
Log.d("order_id_create", "onChanged: "+orderId); // Log.d("order_id_create", "onChanged: "+orderId);
cartIsEmpty = false; cartIsEmpty = false;
Log.i("Add data cart", "onChanged: Berhasil ditambahkan"); // Log.i("Add data cart", "onChanged: Berhasil ditambahkan");
}else { }else {
if (cartIsEmpty){ if (cartIsEmpty){
startActivity(new Intent(MainActivity.this, CartActivity.class)); startActivity(new Intent(MainActivity.this, CartActivity.class));
...@@ -301,6 +309,11 @@ public class MainActivity extends AppCompatActivity { ...@@ -301,6 +309,11 @@ public class MainActivity extends AppCompatActivity {
} }
}); });
} }
@Override
public void redirect() {
startActivity(new Intent(MainActivity.this, CartActivity.class));
}
}); });
} }
......
...@@ -8,6 +8,7 @@ import android.view.View; ...@@ -8,6 +8,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Filter; import android.widget.Filter;
import android.widget.Filterable; import android.widget.Filterable;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil; import androidx.databinding.DataBindingUtil;
...@@ -15,6 +16,7 @@ import androidx.fragment.app.FragmentActivity; ...@@ -15,6 +16,7 @@ import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.ViewModelProviders; import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.snackbar.Snackbar;
import com.yono.messeripos.MainActivity; import com.yono.messeripos.MainActivity;
import com.yono.messeripos.R; import com.yono.messeripos.R;
import com.yono.messeripos.databinding.ItemListBinding; import com.yono.messeripos.databinding.ItemListBinding;
...@@ -36,6 +38,8 @@ public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.MyViewHo ...@@ -36,6 +38,8 @@ public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.MyViewHo
void onDelete(ProductModels product, int position); void onDelete(ProductModels product, int position);
void onAddCart(ProductModels product); void onAddCart(ProductModels product);
void redirect();
} }
private ProductListener listener; private ProductListener listener;
...@@ -147,6 +151,14 @@ public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.MyViewHo ...@@ -147,6 +151,14 @@ public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.MyViewHo
public void onClick(View view) { public void onClick(View view) {
listener.onAddCart(products); listener.onAddCart(products);
MainActivity.cartIsEmpty = true; MainActivity.cartIsEmpty = true;
Snackbar.make(view, products.getProductName()+" berhasil ditambahkan", Snackbar.LENGTH_SHORT)
.setAction(R.string.open_cart, new View.OnClickListener() {
@Override
public void onClick(View view) {
listener.redirect();
}
})
.show();
} }
}); });
......
<vector android:height="24dp" android:tint="#4DFF42"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z"/>
</vector>
...@@ -11,18 +11,36 @@ ...@@ -11,18 +11,36 @@
android:id="@+id/cAppBar" android:id="@+id/cAppBar"
layout="@layout/app_bar"/> layout="@layout/app_bar"/>
<ImageView
android:id="@+id/cartEmpty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/emptycart"/>
<com.google.android.material.textview.MaterialTextView
android:id="@+id/cartEmptyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cart is empty!"
android:layout_below="@id/cartEmpty"
android:layout_centerInParent="true"
android:textSize="30dp"
android:textColor="#61333333"
/>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvCart" android:id="@+id/rvCart"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_above="@id/cardview" android:layout_above="@id/cardviews"
android:layout_below="@id/cAppBar" android:layout_below="@id/cAppBar"
android:overScrollMode="never" android:overScrollMode="never"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager" app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
tools:listitem="@layout/item_cart" /> tools:listitem="@layout/item_cart" />
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
android:id="@+id/cardview" android:id="@+id/cardviews"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:cardElevation="0dp" app:cardElevation="0dp"
......
...@@ -10,15 +10,23 @@ ...@@ -10,15 +10,23 @@
android:id="@+id/cAppBar" android:id="@+id/cAppBar"
layout="@layout/app_bar" /> layout="@layout/app_bar" />
<ProgressBar
android:id="@+id/loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:elevation="1dp"/>
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="600dp" android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_below="@+id/cAppBar"> android:layout_below="@+id/cAppBar">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvHistory" android:id="@+id/rvHistory"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_below="@id/cAppBar" android:layout_below="@id/cAppBar"
tools:listitem="@layout/item_history" /> tools:listitem="@layout/item_history" />
</ScrollView> </ScrollView>
......
...@@ -86,8 +86,9 @@ ...@@ -86,8 +86,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/title_product" app:layout_constraintTop_toBottomOf="@id/title_product"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/materialBtnAddCart"
tools:text="@tools:sample/full_names" tools:text="@tools:sample/full_names"
android:textColor="@android:color/black" android:textColor="#5E101010"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
android:textSize="18sp" android:textSize="18sp"
...@@ -99,29 +100,32 @@ ...@@ -99,29 +100,32 @@
android:id="@+id/status" android:id="@+id/status"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/title_product" app:layout_constraintBottom_toBottomOf="@id/price"
app:layout_constraintTop_toTopOf="@id/price"
app:layout_constraintStart_toEndOf="@id/price" app:layout_constraintStart_toEndOf="@id/price"
tools:text="@tools:sample/full_names" tools:text="@tools:sample/full_names"
android:textColor="@android:color/black" android:textColor="@android:color/black"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:textSize="10sp" android:textSize="10sp"
android:lines="1" android:lines="1"
android:textAllCaps="true" android:textAllCaps="true"
android:text="@{status}" android:text="@{status}"
android:maxLength="25"/> android:maxLength="25"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/materialBtnAddCart"
android:padding="1dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:text="Add To Cart"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/materialBtnAddCart"
android:padding="1dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:text="Add To Cart"/>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
......
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
</menu>
\ No newline at end of file
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
<string name="title_success">Success</string> <string name="title_success">Success</string>
<string name="hint_pay">cash</string> <string name="hint_pay">cash</string>
<string name="title_next">next</string> <string name="title_next">next</string>
<string name="open_cart">Open Cart</string>
<string-array name="planets_array"> <string-array name="planets_array">
<item>Mercury</item> <item>Mercury</item>
......
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