Commit d2542572 authored by Alfansyah Fadlian's avatar Alfansyah Fadlian

login register

parents 0499afd4 041fcb0e
......@@ -35,9 +35,6 @@
<activity
android:name=".CartActivity"
android:theme="@style/AppTheme.appbar" />
<activity
android:name=".ProductActivity"
android:theme="@style/AppTheme.appbar" />
<activity android:name=".SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......
......@@ -181,37 +181,32 @@ public class FormProductActivity extends AppCompatActivity {
@RequiresApi(api = Build.VERSION_CODES.N)
private void setSpinner(String s) {
progressDialog.show();
HashSet<String> set = new HashSet<>();
List<String> str = new ArrayList<>();
categoryModels = new ArrayList<>();
categoryModels.add("SELECT CATEGORY");
str.add("SELECT CATEGORY");
mainViewModels.getCategory().observe(this, listDataResponse -> {
List<CategoryModels> cate = listDataResponse.getData();
for (CategoryModels cd: cate){
Log.i("SPINNER", "setSpinner: "+utils.convertGson(cd.getNameCategory()));
progressDialog.dismiss();
for (CategoryModels cd: listDataResponse.getData()){
categoryModels.add(cd.getNameCategory());
}
List<String> collect = categoryModels.stream().map(v -> {
if (set.add(v) == true) {
str.add(v);
}
return v;
}).collect(Collectors.toList());
// Log.i("Spinner data", "onCreate: "+utils.convertGson(categoryModels));
Log.i("SPINNER", "setSpinner: "+utils.convertGson(str));
@SuppressLint("ResourceType")
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(FormProductActivity.this,
R.id.listCategory, str);
binding.listCategory.setAdapter(dataAdapter);
});
List<HashSet<String>> collect = categoryModels.stream().map(v -> {
if (set.add(v) == true) {
set.add(v);
}
return set;
}).collect(Collectors.toList());
Log.i("SPINNER", "setSpinner: "+utils.convertGson(collect));
@SuppressLint("ResourceType")
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(FormProductActivity.this,
R.id.listCategory, categoryModels);
binding.listCategory.setAdapter(dataAdapter);
progressDialog.dismiss();
}
private void saveProduct(){
......
......@@ -37,7 +37,7 @@ public class LoginActivity extends AppCompatActivity {
SharedPreferences sharedPreferences;
Utils utils = new Utils();
MaterialButton btnSignup, btnSignIn;
MaterialButton btnSignup, btnSignin;
ConstraintLayout loginSheetLayout, registerSheetLayout;
BottomSheetBehavior sheetBehavior,sheetBehavior2;
int height, width;
......@@ -54,7 +54,7 @@ public class LoginActivity extends AppCompatActivity {
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
// bindUI
btnSignIn = findViewById(R.id.signInButtonDashboardLogin);
btnSignin = findViewById(R.id.signInButtonDashboardLogin);
loginSheetLayout = findViewById(R.id.ConstraintLoginLayout);
btnSignup = findViewById(R.id.signUpButtonDashboardLogin);
registerSheetLayout = findViewById(R.id.ConstraintRegisterLayout);
......@@ -65,18 +65,22 @@ public class LoginActivity extends AppCompatActivity {
height = displayMetrics.heightPixels;
width = displayMetrics.widthPixels;
int maxHeight = height - ((height * 10) / 100);
loginSheetLayout.setMaxHeight(maxHeight);
// get bottom sheets
sheetBehavior = BottomSheetBehavior.from(loginSheetLayout);
sheetBehavior2 = BottomSheetBehavior.from(registerSheetLayout);
// button on click to form login
btnSignIn.setOnClickListener(new View.OnClickListener() {
// button on click
btnSignin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (sheetBehavior.getState() != BottomSheetBehavior.STATE_EXPANDED) {
sheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
loginSheetLayout.setMaxHeight(height - 100);
} else {
}else {
sheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
}
......
......@@ -388,7 +388,6 @@ public class MainActivity extends AppCompatActivity {
categoryAdapter.setListener(new CategoryAdapter.CategoryListener() {
@Override
public void onGetProduct(CategoryModels categoryModels) {
progressDialog.show();
Log.i("diluar if", "onGetProduct: "+selectCategory);
if (!selectCategory){
binding.rvProduct.setVisibility(View.GONE);
......@@ -398,14 +397,16 @@ public class MainActivity extends AppCompatActivity {
Log.i("setelah if", "onGetProduct: "+selectCategory);
if (categoryModels.getIdCategory() == 0){
progressDialog.show();
if (mainViewModels.getProduct().getValue().getData().size() != 0){
selectCategory = false;
mainViewModels.getProduct().observe(MainActivity.this, new Observer<DataResponse<List<ProductModels<CategoryModels>>>>() {
@Override
public void onChanged(DataResponse<List<ProductModels<CategoryModels>>> listDataResponse) {
progressDialog.dismiss();
productModelsArrayList.clear();
productModelsArrayList.addAll(listDataResponse.getData());
progressDialog.dismiss();
binding.rvProduct.setVisibility(View.VISIBLE);
binding.imgEmpty.setVisibility(View.GONE);
productAdapter.setProduct(MainActivity.this, productModelsArrayList);
......@@ -420,14 +421,16 @@ public class MainActivity extends AppCompatActivity {
// binding.imgEmpty.bringToFront();
}
}else{
progressDialog.show();
selectCategory = false;
mainViewModels.getProductByCategory(categoryModels.getIdCategory()).observe(MainActivity.this, new Observer<DataResponse<List<ProductModels>>>() {
@Override
public void onChanged(DataResponse<List<ProductModels>> listDataResponse) {
progressDialog.dismiss();
if (listDataResponse != null) {
productModelsArrayList.clear();
productModelsArrayList.addAll(listDataResponse.getData());
progressDialog.dismiss();
showLoading(false);
if (productModelsArrayList.isEmpty()) {
binding.rvProduct.setVisibility(View.GONE);
......
......@@ -11,4 +11,7 @@ import retrofit2.http.POST;
public interface UsersService {
@POST(ApiHelper.VERSI_API_1+"login")
Call<DataResponse<UsersModels>> checkLogin(@Body UsersModels usersModels);
@POST(ApiHelper.VERSI_API_1+"register")
Call<DataResponse<UsersModels>> postRegister(@Body UsersModels usersModels);
}
......@@ -29,6 +29,8 @@ public class MainViewModels extends ViewModel {
MutableLiveData<DataResponse<List<ProductModels>>> productByCategory;
MutableLiveData<DataResponse<List<CategoryModels>>> categoryList;
MutableLiveData<DataResponse<UsersModels>> usersLogin;
MutableLiveData<DataResponse<UsersModels>> usersRegister;
MutableLiveData<DataResponse<List<PaymentsModels<String>>>> transactions;
private MainViewModels mainViewModels;
......@@ -36,7 +38,7 @@ public class MainViewModels extends ViewModel {
Client client = new Client();
Utils utils = new Utils();
public MainViewModels(){
public MainViewModels() {
productList = new MutableLiveData<>();
categoryList = new MutableLiveData<>();
productByCategory = new MutableLiveData<>();
......@@ -44,26 +46,26 @@ public class MainViewModels extends ViewModel {
}
public LiveData<DataResponse<List<ProductModels<CategoryModels>>>> getProduct(){
public LiveData<DataResponse<List<ProductModels<CategoryModels>>>> getProduct() {
getProductList();
return productList;
}
public LiveData<DataResponse<List<CategoryModels>>> getCategory(){
public LiveData<DataResponse<List<CategoryModels>>> getCategory() {
getCategoryList();
return categoryList;
}
public void postCategory(CategoryModels categoryModels){
public void postCategory(CategoryModels categoryModels) {
saveCategory(categoryModels);
}
public LiveData<DataResponse<List<ProductModels>>> getProductByCategory(int id){
public LiveData<DataResponse<List<ProductModels>>> getProductByCategory(int id) {
getDataProductByCategory(id);
return productByCategory;
}
public LiveData<DataResponse<List<PaymentsModels<String>>>> getAllTransactions(){
public LiveData<DataResponse<List<PaymentsModels<String>>>> getAllTransactions() {
getDataTransaction();
return transactions;
}
......@@ -74,27 +76,27 @@ public class MainViewModels extends ViewModel {
categoryServise.addCategory(categoryModels).enqueue(new Callback<DataResponse<CategoryModels>>() {
@Override
public void onResponse(Call<DataResponse<CategoryModels>> call, Response<DataResponse<CategoryModels>> response) {
Log.i("Add Categiry", "onResponse: "+utils.convertGson(response.body()));
Log.i("Add Categiry", "onResponse: " + utils.convertGson(response.body()));
}
@Override
public void onFailure(Call<DataResponse<CategoryModels>> call, Throwable t) {
Log.e("error add", "onFailure: ",t );
Log.e("error add", "onFailure: ", t);
}
});
}
public void deleteProducts(int id){
public void deleteProducts(int id) {
ProductService productService = client.Client(ProductService.class);
productService.deleteProducts(id).enqueue(new Callback<DataResponse<ProductModels>>() {
@Override
public void onResponse(Call<DataResponse<ProductModels>> call, Response<DataResponse<ProductModels>> response) {
Log.i("Delete", "onResponse: "+utils.convertGson(response.body()));
Log.i("Delete", "onResponse: " + utils.convertGson(response.body()));
}
@Override
public void onFailure(Call<DataResponse<ProductModels>> call, Throwable t) {
Log.e("error delete", "onFailure: ",t );
Log.e("error delete", "onFailure: ", t);
}
});
}
......@@ -106,17 +108,17 @@ public class MainViewModels extends ViewModel {
@Override
public void onResponse(Call<DataResponse<List<PaymentsModels<String>>>> call,
Response<DataResponse<List<PaymentsModels<String>>>> response) {
Log.i("Get all transaction", "onResponse: "+utils.convertGson(response.body()));
if (response.body() != null){
Log.i("Get all transaction", "onResponse: " + utils.convertGson(response.body()));
if (response.body() != null) {
transactions.setValue(response.body());
}else{
} else {
transactions = null;
}
}
@Override
public void onFailure(Call<DataResponse<List<PaymentsModels<String>>>> call, Throwable t) {
Log.e("Error get transaction", "onFailure: ",t );
Log.e("Error get transaction", "onFailure: ", t);
transactions = null;
}
});
......@@ -130,8 +132,8 @@ public class MainViewModels extends ViewModel {
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){
Log.i("Get data by category", "onResponse: " + js);
if (response != null) {
productByCategory.setValue(response.body());
}
}
......@@ -143,28 +145,53 @@ public class MainViewModels extends ViewModel {
});
}
public MutableLiveData<DataResponse<UsersModels>> checkLogin(UsersModels usersModels){
public MutableLiveData<DataResponse<UsersModels>> checkLogin(UsersModels usersModels) {
usersLogin = new MutableLiveData<>();
PeriksaLogin(usersModels);
return usersLogin;
}
public MutableLiveData<DataResponse<UsersModels>> checkRegis(UsersModels usersModels){
usersRegister = new MutableLiveData<>();
CreateRegister(usersModels);
return usersRegister;
}
private void PeriksaLogin(UsersModels usersModels) {
UsersService usersService = client.Client(UsersService.class);
//cek login
usersService.checkLogin(usersModels).enqueue(new Callback<DataResponse<UsersModels>>() {
@Override
public void onResponse(Call<DataResponse<UsersModels>> call, Response<DataResponse<UsersModels>> response) {
if (response.body() != null){
if (response.body() != null) {
usersLogin.setValue(response.body());
}
String js = new Gson().toJson(response.body());
Log.d("Periksa login", "Response "+js);
Log.d("Periksa login", "Response " + js);
}
@Override
public void onFailure(Call<DataResponse<UsersModels>> call, Throwable t) {
Log.e("Error Login", "Response " + t.getMessage());
}
});
}
private void CreateRegister(UsersModels usersModels){
UsersService usersService = client.Client(UsersService.class);
//post register
usersService.postRegister(usersModels).enqueue(new Callback<DataResponse<UsersModels>>() {
@Override
public void onResponse(Call<DataResponse<UsersModels>> call, Response<DataResponse<UsersModels>> response) {
}
@Override
public void onFailure(Call<DataResponse<UsersModels>> call, Throwable t) {
Log.e("Error Login", "Response "+t.getMessage());
Log.e("Error Register","Response"+t.getMessage());
}
});
}
......@@ -176,40 +203,40 @@ public class MainViewModels extends ViewModel {
productService.getProducts().enqueue(new Callback<DataResponse<List<ProductModels<CategoryModels>>>>() {
@Override
public void onResponse(Call<DataResponse<List<ProductModels<CategoryModels>>>> call, Response<DataResponse<List<ProductModels<CategoryModels>>>> response) {
Log.i("Get products", "onResponse: "+utils.convertGson(response.body()));
if (response.body() != null){
Log.i("Get products", "onResponse: " + utils.convertGson(response.body()));
if (response.body() != null) {
productList.setValue(response.body());
}else{
} else {
productList.setValue(null);
}
}
@Override
public void onFailure(Call<DataResponse<List<ProductModels<CategoryModels>>>> call, Throwable t) {
Log.e("Error get product", "Response "+t.getMessage());
Log.e("Error get product", "Response " + t.getMessage());
}
});
}
private void getCategoryList(){
private void getCategoryList() {
CategoryServise categoryServise = client.Client(CategoryServise.class);
categoryServise.getCategory().enqueue(new Callback<DataResponse<List<CategoryModels>>>() {
@Override
public void onResponse(Call<DataResponse<List<CategoryModels>>> call, Response<DataResponse<List<CategoryModels>>> response) {
String js = new Gson().toJson(response.body());
Log.d("Get Data Category", "Response "+js);
if (response.body() != null){
Log.d("Get Data Category", "Response " + js);
if (response.body() != null) {
categoryList.setValue(response.body());
}else {
} else {
categoryList.setValue(null);
}
}
@Override
public void onFailure(Call<DataResponse<List<CategoryModels>>> call, Throwable t) {
Log.e("Error get product", "Response "+t.getMessage());
Log.e("Error get product", "Response " + t.getMessage());
}
});
}
......
......@@ -6,14 +6,27 @@ public class UsersModels {
@SerializedName("username")
private String usernameUsers;
@SerializedName("email")
private String emailUsers;
@SerializedName("password")
private String passwordUsers;
public UsersModels(String usernameUsers, String passwordUsers) {
public UsersModels(String usernameUsers, String emailUsers, String passwordUsers) {
this.usernameUsers = usernameUsers;
this.emailUsers = emailUsers;
this.passwordUsers = passwordUsers;
}
public String getEmailUsers() {
return emailUsers;
}
public void setEmailUsers(String emailUsers) {
this.emailUsers = emailUsers;
}
public String getUsernameUsers() {
return usernameUsers;
}
......
......@@ -6,7 +6,8 @@
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
app:behavior_hideable="true"
android:layout_gravity="bottom"
app:behavior_hideable="false"
android:padding="20dp"
style="@style/Widget.Rounded.BottomSheet"
app:behavior_peekHeight="0dp"
......
......@@ -9,6 +9,7 @@
android:fitsSystemWindows="true"
android:paddingTop="10dp"
android:orientation="vertical"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
style="@style/Widget.Rounded.BottomSheet">
......@@ -172,7 +173,7 @@
app:useMaterialThemeColors="true" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btnLogin"
android:id="@+id/btnRegister"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
......@@ -190,20 +191,6 @@
app:layout_constraintVertical_bias="0.01999998" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="2dp"
app:layout_constraintBottom_toBottomOf="@id/btnLogin"
app:layout_constraintEnd_toEndOf="@id/btnLogin"
app:layout_constraintStart_toStartOf="@id/btnLogin"
app:layout_constraintTop_toTopOf="@id/btnLogin"
tools:layout_editor_absoluteX="64dp"
tools:layout_editor_absoluteY="337dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
......
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