Commit 3e0b4323 authored by Muhammad Suryono's avatar Muhammad Suryono

update code

parent 928de6d8
......@@ -82,6 +82,7 @@ public class LoginActivity extends AppCompatActivity {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(SplashScreen.SESSION, true);
editor.commit();
startActivity(new Intent(LoginActivity.this, MainActivity.class));
progressBar.setVisibility(View.GONE);
......
......@@ -6,19 +6,16 @@ import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.databinding.DataBindingUtil;
......@@ -29,30 +26,20 @@ import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.snackbar.Snackbar;
import com.yono.messeripos.adapter.CartAdapter;
import com.yono.messeripos.adapter.ProductAdapter;
import com.yono.messeripos.databinding.ActivityMainBinding;
import com.yono.messeripos.models.MainViewModels;
import com.yono.messeripos.models.MainViewModelsCart;
import com.yono.messeripos.models.ProductCartModels;
import com.yono.messeripos.models.ProductModels;
import com.google.gson.Gson;
import com.yono.messeripos.adapter.CartAdapter;
import com.yono.messeripos.adapter.CategoryAdapter;
import com.yono.messeripos.adapter.ProductAdapter;
import com.yono.messeripos.databinding.ActivityMainBinding;
import com.yono.messeripos.databinding.ItemListBinding;
import com.yono.messeripos.models.CategoryModels;
import com.yono.messeripos.models.MainViewModels;
import com.yono.messeripos.models.MainViewModelsCart;
import com.yono.messeripos.models.ProductCartModels;
import com.yono.messeripos.models.ProductModels;
import com.yono.messeripos.response.DataResponse;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;
public class MainActivity extends AppCompatActivity {
MaterialToolbar toolbar;
......@@ -238,44 +225,33 @@ public class MainActivity extends AppCompatActivity {
ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Loading...");
progressDialog.show();
binding.rvProduct.setVisibility(View.GONE);
mainViewModels.getProductByCategory(categoryModels.getIdCategory()).observe(
MainActivity.this, new Observer<List<CategoryModels<List<ProductModels>>>>() {
mainViewModels.getProductByCategory(categoryModels.getIdCategory()).observe(MainActivity.this, new Observer<DataResponse<List<ProductModels>>>() {
@Override
public void onChanged(List<CategoryModels<List<ProductModels>>> categoryModels) {
ProductModels productModels = new ProductModels();
for (CategoryModels<List<ProductModels>> pd : categoryModels){
for (ProductModels ps : pd.getProductCategory()){
Log.i("eeee", "onChanged: "+ps.getProductName());
productModels.setIdProduct(ps.getIdProduct());
productModels.setProductName(ps.getProductName());
productModels.setStockProduct(ps.getStockProduct());
productModels.setPriceProduct(ps.getPriceProduct());
productModels.setImageProduct(ps.getImageProduct());
}
Log.i("ddddd", "onChanged: "+pd.getProductCategory());
}
// List<ProductModels> pdf = (List<ProductModels>) productModels;
ArrayList<ProductModels> pdModel = new ArrayList<>();
public void onChanged(DataResponse<List<ProductModels>> listDataResponse) {
if (listDataResponse != null) {
List<ProductModels> productModels = listDataResponse.getData();
ArrayList<ProductModels> productModelsArrayList = new ArrayList<>();
productAdapter.setProduct(MainActivity.this,pdModel );
productAdapter.notifyDataSetChanged();
showLoading(false);
productModelsArrayList.addAll(productModels);
progressDialog.dismiss();
if (pdModel.isEmpty()){
showLoading(false);
if (productModelsArrayList.isEmpty()) {
binding.rvProduct.setVisibility(View.GONE);
binding.imgEmpty.setVisibility(View.VISIBLE);
}else{
binding.imgEmpty.bringToFront();
} else {
binding.rvProduct.setVisibility(View.VISIBLE);
binding.imgEmpty.setVisibility(View.GONE);
productAdapter.setProduct(MainActivity.this, productModelsArrayList);
binding.rvProduct.setLayoutManager(new GridLayoutManager(MainActivity.this, 2));
binding.rvProduct.setAdapter(productAdapter);
productAdapter.notifyDataSetChanged();
}
// binding.rvProduct.setLayoutManager(new GridLayoutManager(MainActivity.this, 2));
// binding.rvProduct.setAdapter(productAdapter);
}
}
);
});
}
});
}
......
......@@ -93,6 +93,7 @@ public class CartAdapter extends RecyclerView.Adapter<CartAdapter.MyViewHolder>
subtotal = cartModels.getPrice_orders() * cartModels.getQuantity_orders();
binding.setSubTotal(utils.convertPrice("Rp. ", subtotal));
binding.etQty.setText(Long.toString(cartModels.getQuantity_orders()));
}
}
......
......@@ -16,6 +16,6 @@ public interface CategoryServise {
@GET(ApiHelper.VERSI_API_1+"categories")
Call<DataResponse<List<CategoryModels>>> getCategory();
@GET(ApiHelper.VERSI_API_1+"categories-join/{id}")
Call<DataResponse<List<CategoryModels<List<ProductModels>>>>> getCategoryById(@Path("id") int id);
@GET(ApiHelper.VERSI_API_1+"products-category/{id}")
Call<DataResponse<List<ProductModels>>> getCategoryById(@Path("id") int id);
}
......@@ -22,7 +22,7 @@ import retrofit2.Response;
public class MainViewModels extends ViewModel {
MutableLiveData<DataResponse<List<ProductModels<CategoryModels>>>> productList;
MutableLiveData<List<CategoryModels<List<ProductModels>>>> productByCategory;
MutableLiveData<DataResponse<List<ProductModels>>> productByCategory;
MutableLiveData<DataResponse<List<CategoryModels>>> categoryList;
MutableLiveData<DataResponse<UsersModels>> usersLogin;
......@@ -44,7 +44,7 @@ public class MainViewModels extends ViewModel {
return categoryList;
}
public LiveData<List<CategoryModels<List<ProductModels>>>> getProductByCategory(int id){
public LiveData<DataResponse<List<ProductModels>>> getProductByCategory(int id){
getDataProductByCategory(id);
return productByCategory;
}
......@@ -52,19 +52,19 @@ public class MainViewModels extends ViewModel {
private void getDataProductByCategory(int id) {
CategoryServise categoryServise = client.Client(CategoryServise.class);
categoryServise.getCategoryById(id).enqueue(new Callback<DataResponse<List<CategoryModels<List<ProductModels>>>>>() {
categoryServise.getCategoryById(id).enqueue(new Callback<DataResponse<List<ProductModels>>>() {
@Override
public void onResponse(Call<DataResponse<List<CategoryModels<List<ProductModels>>>>> call,
Response<DataResponse<List<CategoryModels<List<ProductModels>>>>> response) {
public void onResponse(Call<DataResponse<List<ProductModels>>> call,
Response<DataResponse<List<ProductModels>>> response) {
String js = new Gson().toJson(response.body());
Log.i("Get data by category", "onResponse: "+js);
if (response != null){
productByCategory.setValue(response.body().getData());
productByCategory.setValue(response.body());
}
}
@Override
public void onFailure(Call<DataResponse<List<CategoryModels<List<ProductModels>>>>> call, Throwable t) {
public void onFailure(Call<DataResponse<List<ProductModels>>> call, Throwable t) {
Log.e("Error!", "onFailure: ", t);
}
});
......
......@@ -119,7 +119,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
android:text="1"
android:textColor="#333" />
</com.google.android.material.textfield.TextInputLayout>
......
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