Commit 40a816d9 authored by Muhammad Suryono's avatar Muhammad Suryono

Update data

parent 67cf5ded
......@@ -80,41 +80,41 @@ public class BottomSheets extends BottomSheetDialogFragment {
btnCash = v.findViewById(R.id.btnCash);
totalHarga = v.findViewById(R.id.totalHarga);
utils = new Utils();
bottomSheetBehavior = BottomSheetBehavior.from(layoutFormCash);
// bottomSheetBehavior = BottomSheetBehavior.from(layoutFormCash);
sharedPreferences = getActivity().getSharedPreferences(MainActivity.MY_SHARED_PREFERENCES, Context.MODE_PRIVATE);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
// bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
long ga = paymentsModels.getGrossAmount();
String setCurrency = utils.convertPrice("Rp.", ga);
totalHarga.setText(setCurrency);
hargaChange.setText(defaultText);
bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
switch (newState) {
case BottomSheetBehavior.STATE_HIDDEN:
break;
case BottomSheetBehavior.STATE_EXPANDED:
break;
case BottomSheetBehavior.STATE_COLLAPSED:
break;
case BottomSheetBehavior.STATE_DRAGGING:
break;
case BottomSheetBehavior.STATE_SETTLING:
break;
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
if (bottomSheetBehavior.getState() != BottomSheetBehavior.STATE_EXPANDED) {
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
} else {
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
}
});
// bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
// @Override
// public void onStateChanged(@NonNull View bottomSheet, int newState) {
// switch (newState) {
// case BottomSheetBehavior.STATE_HIDDEN:
// break;
// case BottomSheetBehavior.STATE_EXPANDED:
// break;
// case BottomSheetBehavior.STATE_COLLAPSED:
// break;
// case BottomSheetBehavior.STATE_DRAGGING:
// break;
// case BottomSheetBehavior.STATE_SETTLING:
// break;
// }
// }
//
// @Override
// public void onSlide(@NonNull View bottomSheet, float slideOffset) {
// if (bottomSheetBehavior.getState() != BottomSheetBehavior.STATE_EXPANDED) {
// bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
// } else {
// bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
// }
// }
// });
inputAmount.addTextChangedListener(new TextWatcher() {
@Override
......
......@@ -4,31 +4,85 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProvider;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import com.google.android.material.button.MaterialButton;
import com.yono.messeripos.adapter.CategoryAdapter;
import com.yono.messeripos.api.client.Client;
import com.yono.messeripos.api.service.CategoryServise;
import com.yono.messeripos.models.CategoryModels;
import com.yono.messeripos.models.MainViewModels;
import com.yono.messeripos.models.MainViewModelsCart;
import com.yono.messeripos.response.DataResponse;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class FormCategory extends BottomSheetDialogFragment {
MainViewModels mainViewModels;
public EditText etCategoryName;
public MaterialButton btnAddCategory;
CategoryModels categoryModelsEdit;
Boolean updateCategory = false;
public FormCategory() {
}
public interface FormCategoryListener {
void onAddCategory(CategoryModels categoryModels);
void onUpdateCategory(CategoryModels categoryModels);
}
private FormCategoryListener listener;
public void setListener(FormCategoryListener listener) {
this.listener = listener;
}
public void EditFormCategory(CategoryModels categoryModels){
this.updateCategory = true;
this.categoryModelsEdit = categoryModels;
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.form_category,
container, false);
etCategoryName = v.findViewById(R.id.etCategoryName);
btnAddCategory = v.findViewById(R.id.btnAddCategory);
mainViewModels = new ViewModelProvider(getActivity()).get(MainViewModels.class);
if (!updateCategory){
etCategoryName.setText("");
}else{
etCategoryName.setText(categoryModelsEdit.getNameCategory());
btnAddCategory.setText("Update Category");
}
btnAddCategory.setOnClickListener(view -> addCategory());
return v;
}
private void addCategory() {
if (!updateCategory){
CategoryModels categoryModels = new CategoryModels();
categoryModels.setNameCategory(etCategoryName.getText().toString());
listener.onAddCategory(categoryModels);
}else{
CategoryModels categoryModels = new CategoryModels();
categoryModels.setNameCategory(etCategoryName.getText().toString());
categoryModels.setIdCategory(categoryModelsEdit.getIdCategory());
listener.onUpdateCategory(categoryModels);
}
}
}
......@@ -31,6 +31,7 @@ import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import com.jaredrummler.materialspinner.MaterialSpinner;
import com.yono.messeripos.api.client.Client;
import com.yono.messeripos.api.service.CategoryServise;
import com.yono.messeripos.api.service.ProductService;
import com.yono.messeripos.databinding.FormProductBinding;
import com.yono.messeripos.models.CategoryModels;
......@@ -70,6 +71,7 @@ public class FormProductActivity extends AppCompatActivity {
Client client = new Client();
ProductModels productModelsIntent;
List<String> categorySelect = new ArrayList<>();
FormCategory formCategory;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
......@@ -89,7 +91,7 @@ public class FormProductActivity extends AppCompatActivity {
}
productModelsIntent = getIntent().getParcelableExtra(MainActivity.DATA_PRODUCT);
formCategory = new FormCategory();
MaterialToolbar toolbars = findViewById(R.id.topAppBarForm);
setSupportActionBar(toolbars);
......@@ -122,14 +124,45 @@ public class FormProductActivity extends AppCompatActivity {
binding.btnAddCategory.setOnClickListener(view -> addCategory());
//spinner
categoryModels = new ArrayList<>();
categoryModels.add("SELECT CATEGORY");
setSpinner();
setSpinner("");
setSelectedSpinner();
setAddListenerCategory();
}
private void setAddListenerCategory() {
formCategory.setListener(new FormCategory.FormCategoryListener() {
@Override
public void onAddCategory(CategoryModels categoryModels) {
progressDialog.show();
CategoryServise categoryServise = client.Client(CategoryServise.class);
categoryServise.addCategory(categoryModels).enqueue(new Callback<DataResponse<CategoryModels>>() {
@Override
public void onResponse(Call<DataResponse<CategoryModels>> call, Response<DataResponse<CategoryModels>> response) {
if (response.body().getStatusData()){
progressDialog.dismiss();
setSpinner("post");
formCategory.dismiss();
formCategory.etCategoryName.setText("");
}
}
@Override
public void onFailure(Call<DataResponse<CategoryModels>> call, Throwable t) {
new AlertDialog.Builder(FormProductActivity.this)
.setTitle("Add Category failed!")
.setMessage("Add category failed, try again!").show();
}
});
}
@Override
public void onUpdateCategory(CategoryModels categoryModels) {
}
});
}
private void addCategory() {
FormCategory formCategory = new FormCategory();
formCategory.show(getSupportFragmentManager(),
"ModalFormCategory");
}
......@@ -143,10 +176,13 @@ public class FormProductActivity extends AppCompatActivity {
});
}
private void setSpinner() {
private void setSpinner(String s) {
categoryModels = new ArrayList<>();
categoryModels.add("SELECT CATEGORY");
mainViewModels.getCategory().observe(this, listDataResponse -> {
List<CategoryModels> cate = listDataResponse.getData();
for (CategoryModels cd: cate){
categoryModels.add(cd.getNameCategory());
}
......@@ -163,7 +199,7 @@ public class FormProductActivity extends AppCompatActivity {
productModels.setProductName(binding.etName.getText().toString());
productModels.setPriceProduct(Integer.parseInt(binding.etPrice.getText().toString()));
productModels.setStockProduct(Integer.parseInt(binding.etStock.getText().toString()));
productModels.setCategoryProduct(getCategory(categoryModels.get(0)));
productModels.setCategoryProduct(getCategory(categorySelect.get(0)));
if (isUpdate){
......
package com.yono.messeripos;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
......@@ -41,6 +42,7 @@ import com.google.gson.Gson;
import com.yono.messeripos.adapter.CategoryAdapter;
import com.yono.messeripos.adapter.ProductAdapter;
import com.yono.messeripos.api.client.Client;
import com.yono.messeripos.api.service.CategoryServise;
import com.yono.messeripos.api.service.ProductService;
import com.yono.messeripos.databinding.ActivityMainBinding;
import com.yono.messeripos.models.CategoryModels;
......@@ -76,11 +78,13 @@ public class MainActivity extends AppCompatActivity {
public static final String ORDER_ID = "orderId";
Client client = new Client();
public static ArrayList<ProductModels> productModelsArrayList = new ArrayList<>();
public static ArrayList<CategoryModels> categoryModelsArrayList = new ArrayList<>();
public static final String DATA_PRODUCT = "DATA_PRODUCT";
public static final String MY_SHARED_PREFERENCES = "main_sahred";
ProgressDialog progressDialog;
MaterialButton btnAddCart;
SkeletonScreen skeletonCategory;
FormCategory formCategory;
......@@ -99,6 +103,7 @@ public class MainActivity extends AppCompatActivity {
binding.tvCategory.setVisibility(View.GONE);
binding.tvProduct.setVisibility(View.GONE);
formCategory = new FormCategory();
categoryAdapter = new CategoryAdapter();
productAdapter = new ProductAdapter();
mainViewModelsCart = new ViewModelProvider(MainActivity.this).get(MainViewModelsCart.class);
......@@ -134,6 +139,7 @@ public class MainActivity extends AppCompatActivity {
mainViewModelsGetProduct();
productAdapterListener();
categoryAdapterListener();
formCategoryListener();
}
private void toolbarSetOnItemClicked() {
......@@ -184,7 +190,7 @@ public class MainActivity extends AppCompatActivity {
caModels.setIdCategory(0);
List<CategoryModels> categoryModels = listDataResponse.getData();
ArrayList<CategoryModels> categoryModelsArrayList = new ArrayList<>();
categoryModelsArrayList = new ArrayList<>();
categoryModels.add(0,caModels);
categoryModelsArrayList.addAll(categoryModels);
......@@ -337,6 +343,43 @@ public class MainActivity extends AppCompatActivity {
});
}
private void formCategoryListener() {
formCategory.setListener(new FormCategory.FormCategoryListener() {
@Override
public void onAddCategory(CategoryModels categoryModels) {
}
@Override
public void onUpdateCategory(CategoryModels categoryModels) {
progressDialog.show();
CategoryServise categoryServise = client.Client(CategoryServise.class);
categoryServise.updateCategory(categoryModels.getIdCategory(), categoryModels).enqueue(new Callback<DataResponse<CategoryModels>>() {
@Override
public void onResponse(Call<DataResponse<CategoryModels>> call, Response<DataResponse<CategoryModels>> response) {
progressDialog.dismiss();
Log.i("Update", "onResponse: "+utils.convertGson(response.body()));
if (response.body() != null && response.body().getMessageData() != "Parameter not found!"){
categoryAdapter.notifyDataSetChanged();
formCategory.dismiss();
}else{
new AlertDialog.Builder(MainActivity.this)
.setTitle("Update Category failed!")
.setMessage(response.body().getMessageData()).show();
}
}
@Override
public void onFailure(Call<DataResponse<CategoryModels>> call, Throwable t) {
new AlertDialog.Builder(MainActivity.this)
.setTitle("Update Category failed!")
.setMessage("Update category failed, try again!").show();
}
});
}
});
}
private void categoryAdapterListener() {
categoryAdapter.setListener(new CategoryAdapter.CategoryListener() {
@Override
......@@ -403,15 +446,34 @@ public class MainActivity extends AppCompatActivity {
@Override
public void onUpdateCategory(CategoryModels categoryModels) {
formCategory.EditFormCategory(categoryModels);
formCategory.show(getSupportFragmentManager(),
"ModalFormCategory");
}
@Override
public void onDeleteCategory(CategoryModels categoryModels, int position) {
progressDialog.show();
CategoryServise categoryServise = client.Client(CategoryServise.class);
categoryServise.deleteCategory(categoryModels.getIdCategory()).enqueue(new Callback<DataResponse<CategoryModels>>() {
@Override
public void onResponse(Call<DataResponse<CategoryModels>> call, Response<DataResponse<CategoryModels>> response) {
progressDialog.dismiss();
categoryModelsArrayList.remove(position);
Log.i("KAAAA", "onResponse: "+utils.convertGson(categoryModelsArrayList));
// binding.rvCategory.removeViewAt(position);
categoryAdapter.notifyItemRemoved(position);
categoryAdapter.notifyItemRangeChanged(position, categoryModelsArrayList.size());
}
@Override
public void onDeleteCategory(CategoryModels categoryModels) {
public void onFailure(Call<DataResponse<CategoryModels>> call, Throwable t) {
}
});
}
});
}
private void functionSearch() {
binding.etSearchProduct.addTextChangedListener(new TextWatcher() {
......
......@@ -28,7 +28,7 @@ public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.MyView
void onUpdateCategory(CategoryModels categoryModels);
void onDeleteCategory(CategoryModels categoryModels);
void onDeleteCategory(CategoryModels categoryModels, int position);
}
private CategoryListener listener;
......@@ -78,7 +78,7 @@ public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.MyView
binding.setCategory(categoryModels);
binding.cvCategory.setOnClickListener(view -> listener.onGetProduct(categoryModels));
binding.categoryDelete.setOnClickListener(view -> listener.onDeleteCategory(categoryModels));
binding.categoryDelete.setOnClickListener(view -> listener.onDeleteCategory(categoryModels, getAdapterPosition()));
binding.categoryUpdate.setOnClickListener(view -> listener.onUpdateCategory(categoryModels));
if (!MainActivity.status_update) {
......
......@@ -9,8 +9,10 @@ import java.util.List;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Path;
import retrofit2.http.Query;
......@@ -23,4 +25,10 @@ public interface CategoryServise {
@POST(ApiHelper.VERSI_API_1+"category")
Call<DataResponse<CategoryModels>> addCategory(@Body CategoryModels categoryModels);
@DELETE(ApiHelper.VERSI_API_1+"category/{id}")
Call<DataResponse<CategoryModels>> deleteCategory(@Path("id") int id);
@PUT(ApiHelper.VERSI_API_1+"category/{id}")
Call<DataResponse<CategoryModels>> updateCategory(@Path("id") int id, @Body CategoryModels categoryModels);
}
......@@ -121,15 +121,6 @@
app:layout_constraintTop_toBottomOf="@id/tfPassword"
app:layout_constraintVertical_bias="0.01999998" />
<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="forgot your password ?"
android:textColor="@color/colorWhite"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnLogin" />
<ProgressBar
android:id="@+id/progressBar"
......
......@@ -17,7 +17,7 @@
android:layout_alignParentStart="true" />
<EditText
android:id="@+id/etBayar"
android:id="@+id/etCategoryName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tvAddCategory"
......@@ -26,12 +26,12 @@
android:imeOptions="actionDone"/>
<Button
android:id="@+id/btnCash"
android:id="@+id/btnAddCategory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/text_new_category"
android:hint="Insert Money"
android:layout_below="@id/etBayar" />
android:layout_below="@id/etCategoryName" />
</RelativeLayout>
......
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