Commit 3c5e6bc5 authored by fauzi's avatar fauzi

menambahkan scroll view ke login dan register form

parent c62d96a2
...@@ -61,7 +61,6 @@ public class LoginState extends BottomSheetDialogFragment { ...@@ -61,7 +61,6 @@ public class LoginState extends BottomSheetDialogFragment {
this.mainViewModels = mainViewModels; this.mainViewModels = mainViewModels;
} }
@NonNull @NonNull
@Override @Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
...@@ -114,7 +113,6 @@ public class LoginState extends BottomSheetDialogFragment { ...@@ -114,7 +113,6 @@ public class LoginState extends BottomSheetDialogFragment {
// close btn is clicked // close btn is clicked
closeBtn.setOnClickListener(view12 -> { closeBtn.setOnClickListener(view12 -> {
Log.d(TAG, "onCreateDialog: "+sheetBehavior.getState());
sheetDialog.dismiss(); sheetDialog.dismiss();
}); });
...@@ -134,14 +132,8 @@ public class LoginState extends BottomSheetDialogFragment { ...@@ -134,14 +132,8 @@ public class LoginState extends BottomSheetDialogFragment {
}else{ }else{
/** /**
* Jika tombol sign in ditekan * Jika tombol sign in ditekan
*/ *
* nonaktifkan semua form */
// aktifkan progress bar
bar.setVisibility(View.VISIBLE);
// hilangkan tulisan di button
loginButton.setText("");
// nonaktifkan semua form
username.setEnabled(false); username.setEnabled(false);
password.setEnabled(false); password.setEnabled(false);
loginButton.setEnabled(false); loginButton.setEnabled(false);
...@@ -150,74 +142,70 @@ public class LoginState extends BottomSheetDialogFragment { ...@@ -150,74 +142,70 @@ public class LoginState extends BottomSheetDialogFragment {
// buat checking login // buat checking login
mainViewModels.checkLogin(new UsersModels(username.getText().toString(), mainViewModels.checkLogin(new UsersModels(username.getText().toString(),
password.getText().toString())) password.getText().toString()))
.observe((LifecycleOwner) context, new Observer<DataResponse<UsersModels>>() { .observe((LifecycleOwner) context, usersModelsDataResponse -> {
@SuppressLint("ResourceType")
@Override
public void onChanged(DataResponse<UsersModels> usersModelsDataResponse) {
if (usersModelsDataResponse != null) {
/**
* Jika response atau data ada dan cocok
*/
if (usersModelsDataResponse.getStatusData()) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(SplashScreen.SESSION, true);
if(editor.commit()){
startActivity(new Intent(context, MainActivity.class));
}
// redirect ke home
// set progress bar jadi nonaktif if (usersModelsDataResponse != null) {
bar.setVisibility(View.GONE);
// munculkan tulisan default di button sign in
loginButton.setText(DEFAULT_LOGIN_NAME);
// ubah sheet dialog jadi tidak bisa di slide atau cancel
sheetDialog.setCancelable(true);
// set form jadi enable
username.setEnabled(true);
password.setEnabled(true);
loginButton.setEnabled(true);
closeBtn.setEnabled(true);
} else {
/** /**
* Jika response atau data tidak cocok * Jika response atau data ada dan cocok
*/ */
if (usersModelsDataResponse.getStatusData()) {
bar.setVisibility(View.GONE); SharedPreferences.Editor editor = sharedPreferences.edit();
loginButton.setText(DEFAULT_LOGIN_NAME); editor.putBoolean(SplashScreen.SESSION, true);
if(editor.commit()){
sheetDialog.setCancelable(true); startActivity(new Intent(context, MainActivity.class));
}
final View customLayout = getLayoutInflater() // redirect ke home
.inflate(
R.layout.alert_dialog,
null); // set progress bar jadi nonaktif
bar.setVisibility(View.GONE);
// tampilkan alert dialog // munculkan tulisan default di button sign in
utils = new Utils(customLayout); loginButton.setText(DEFAULT_LOGIN_NAME);
utils.dialog(context, false, customLayout, "Wrong Username or Password",
"The username or password is incorrect. Please try again!", // ubah sheet dialog jadi tidak bisa di slide atau cancel
"Try Again") sheetDialog.setCancelable(true);
.show();
utils.setListener(Dialog::dismiss); // set form jadi enable
username.setEnabled(true);
username.setEnabled(true); password.setEnabled(true);
password.setEnabled(true); loginButton.setEnabled(true);
loginButton.setEnabled(true); closeBtn.setEnabled(true);
closeBtn.setEnabled(true);
} else {
/**
* Jika response atau data tidak cocok
*/
bar.setVisibility(View.GONE);
loginButton.setText(DEFAULT_LOGIN_NAME);
sheetDialog.setCancelable(true);
final View customLayout = getLayoutInflater()
.inflate(
R.layout.alert_dialog,
null);
// tampilkan alert dialog
utils = new Utils(customLayout);
utils.dialog(context, false, customLayout, "Wrong Username or Password",
"The username or password is incorrect. Please try again!",
"Try Again")
.show();
utils.setListener(Dialog::dismiss);
username.setEnabled(true);
password.setEnabled(true);
loginButton.setEnabled(true);
closeBtn.setEnabled(true);
}
} else {
bar.setVisibility(View.VISIBLE);
utils.snackBar(v, "Oppss! ログイン中にエラーが発生しました。しばらくしてからもう一度お試しください").show();
} }
} else {
bar.setVisibility(View.VISIBLE);
utils.snackBar(v, "Oppss! ログイン中にエラーが発生しました。しばらくしてからもう一度お試しください").show();
}
} });
});
} }
loginButton.setText(DEFAULT_LOGIN_NAME); loginButton.setText(DEFAULT_LOGIN_NAME);
} }
......
<vector android:height="24dp" android:tint="#B6B6B6"
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="M12,4.5C7,4.5 2.73,7.61 1,12c1.73,4.39 6,7.5 11,7.5s9.27,-3.11 11,-7.5c-1.73,-4.39 -6,-7.5 -11,-7.5zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5zM12,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3z"/>
</vector>
...@@ -26,112 +26,118 @@ ...@@ -26,112 +26,118 @@
android:scaleType="centerInside" android:scaleType="centerInside"
android:src="@drawable/ic_close" /> android:src="@drawable/ic_close" />
<ImageView <ScrollView
android:id="@+id/messerLogoInLogin"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_below="@id/closeBtnLogin" android:layout_below="@id/closeBtnLogin"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:src="@drawable/ic_messer_primary" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/tvLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/messerLogoInLogin"
android:paddingLeft="12dp"
android:text="Login Your Account"
android:textColor="@color/colorPrimary"
android:textFontWeight="600"
android:textSize="16sp" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/formUsernameLogin"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent">
android:layout_below="@id/tvLogin"
android:hint="@string/username">
<com.google.android.material.textfield.TextInputEditText <RelativeLayout
android:id="@+id/ETUsernameLogin"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/messerLogoInLogin"
android:layout_width="wrap_content"
android:layout_height="213dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:layout_marginBottom="40dp"
android:src="@drawable/login_image" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/tvLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/messerLogoInLogin"
android:paddingLeft="12dp"
android:text="Login Your Account"
android:textColor="@color/colorPrimary"
android:textFontWeight="600"
android:textSize="16sp" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/formUsernameLogin"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tvLogin"
android:hint="@string/username">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/ETUsernameLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:textColor="@color/colorPrimary"
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/FormPasswordLogin"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/formUsernameLogin"
android:layout_marginTop="20dp"
android:hint="@string/password">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/ETPasswordLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone|actionGo"
android:textColor="@color/colorPrimary"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintBtn"
android:layout_below="@id/FormPasswordLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<com.google.android.material.button.MaterialButton
android:id="@+id/SignInButtonInLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in"
android:padding="20dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
<ProgressBar
android:id="@+id/progressLogin"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="2dp"
app:layout_constraintBottom_toBottomOf="@id/SignInButtonInLogin"
app:layout_constraintTop_toTopOf="@id/SignInButtonInLogin"
app:layout_constraintStart_toStartOf="@id/SignInButtonInLogin"
app:layout_constraintEnd_toEndOf="@id/SignInButtonInLogin"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.textview.MaterialTextView
android:id="@+id/forgotPwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:imeOptions="actionNext" android:text="Forgot Password?"
android:inputType="text" /> android:layout_below="@id/constraintBtn"
android:layout_marginTop="10dp"
</com.google.android.material.textfield.TextInputLayout> android:layout_alignParentEnd="true"
android:textColor="@color/colorPrimary"/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/FormPasswordLogin" </RelativeLayout>
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" </ScrollView>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/formUsernameLogin"
android:layout_marginTop="20dp"
android:hint="@string/password">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/ETPasswordLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone|actionGo"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<CheckBox
android:id="@+id/CBRememberMe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/FormPasswordLogin"
android:layout_marginVertical="10dp"
android:text="Remember Me"
android:textColor="@color/colorPrimary"
app:useMaterialThemeColors="true" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintBtn"
android:layout_below="@id/CBRememberMe"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.button.MaterialButton
android:id="@+id/SignInButtonInLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in"
android:padding="20dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
<ProgressBar
android:id="@+id/progressLogin"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="2dp"
app:layout_constraintBottom_toBottomOf="@id/SignInButtonInLogin"
app:layout_constraintTop_toTopOf="@id/SignInButtonInLogin"
app:layout_constraintStart_toStartOf="@id/SignInButtonInLogin"
app:layout_constraintEnd_toEndOf="@id/SignInButtonInLogin"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.textview.MaterialTextView
android:id="@+id/forgotPwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forgot Password?"
android:layout_below="@id/constraintBtn"
android:layout_marginTop="10dp"
android:layout_alignParentEnd="true"
android:textColor="@color/colorPrimary"/>
</RelativeLayout> </RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>
......
...@@ -25,12 +25,22 @@ ...@@ -25,12 +25,22 @@
/> />
<ScrollView
android:layout_below="@id/ivclose"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView <ImageView
android:id="@+id/ivMeserRegister" android:id="@+id/ivMeserRegister"
android:layout_width="150dp" android:layout_width="match_parent"
android:layout_height="150dp" android:layout_height="213dp"
android:src="@drawable/ic_messer_primary" android:src="@drawable/register_image"
android:layout_below="@+id/ivclose" android:layout_marginTop="20dp"
android:layout_marginBottom="40dp"
android:layout_centerHorizontal="true" /> android:layout_centerHorizontal="true" />
<com.google.android.material.textview.MaterialTextView <com.google.android.material.textview.MaterialTextView
...@@ -45,8 +55,6 @@ ...@@ -45,8 +55,6 @@
android:paddingLeft="12dp" android:paddingLeft="12dp"
/> />
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/formUsernameReg" android:id="@+id/formUsernameReg"
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -141,6 +149,11 @@ ...@@ -141,6 +149,11 @@
android:text="Create Account" android:text="Create Account"
android:layout_below="@id/cbAgree" android:layout_below="@id/cbAgree"
android:padding="20dp"/> android:padding="20dp"/>
</RelativeLayout>
</ScrollView>
</RelativeLayout> </RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>
......
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