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

update code

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