Commit c62d96a2 authored by fauzi's avatar fauzi

fix login dan tambahkan animasi di alert dialog

parent 5e2c7278
package com.yono.messeripos;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
......@@ -18,7 +20,6 @@ import android.widget.RelativeLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.Observer;
......@@ -30,6 +31,7 @@ import com.google.android.material.button.MaterialButton;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textfield.TextInputEditText;
import com.yono.messeripos.models.CategoryModels;
import com.yono.messeripos.models.MainViewModels;
import com.yono.messeripos.models.UsersModels;
import com.yono.messeripos.response.DataResponse;
......@@ -50,7 +52,7 @@ public class LoginState extends BottomSheetDialogFragment {
SharedPreferences sharedPreferences;
Utils utils;
ProgressBar bar;
AlertDialog alertDialog;
AlertDialog.Builder builder;
ProgressDialog dialog;
......@@ -100,15 +102,7 @@ public class LoginState extends BottomSheetDialogFragment {
sheetBehavior.setPeekHeight(setHeight);
loginLayout.setMinimumHeight(setHeight);
// alert dialog buat nampilin error
alertDialog = new AlertDialog.Builder(context)
.setTitle("Username dan Password Salah")
.setMessage("Oppss! Username dan Password yang kamu masukan salah!")
.setPositiveButton("Coba Lagi", null)
.setCancelable(false)
.create();
// loginButton on click
loginButton.setOnClickListener(view1 -> {
if (sheetBehavior.getState() != BottomSheetBehavior.STATE_EXPANDED) {
bar.setVisibility(View.VISIBLE);
......@@ -157,6 +151,7 @@ public class LoginState extends BottomSheetDialogFragment {
mainViewModels.checkLogin(new UsersModels(username.getText().toString(),
password.getText().toString()))
.observe((LifecycleOwner) context, new Observer<DataResponse<UsersModels>>() {
@SuppressLint("ResourceType")
@Override
public void onChanged(DataResponse<UsersModels> usersModelsDataResponse) {
......@@ -198,7 +193,19 @@ public class LoginState extends BottomSheetDialogFragment {
sheetDialog.setCancelable(true);
utils.snackBar(v, "Oppss! Wrong Username or Password!").show();
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);
......
package com.yono.messeripos.utils;
import android.app.AlertDialog;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
......@@ -8,14 +9,20 @@ import android.os.Build;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.DividerItemDecoration;
import com.bumptech.glide.load.engine.Resource;
import com.google.android.material.snackbar.Snackbar;
import com.google.gson.Gson;
import com.yono.messeripos.R;
import com.yono.messeripos.adapter.CategoryAdapter;
import com.yono.messeripos.models.CategoryModels;
import java.io.ByteArrayOutputStream;
import java.text.DecimalFormat;
......@@ -29,7 +36,21 @@ import java.util.Locale;
public class Utils {
public Utils(){};
public Utils(View v){};
public long grandTotal = 0;
public static TextView btnCard;
public interface DialogListener {
void onClickDisimiss(AlertDialog alertDialog);
}
private DialogListener listener;
public void setListener(DialogListener listener) {
this.listener = listener;
}
public String convertPrice(String mataUang, int nilai ){
DecimalFormat rupiah = (DecimalFormat) DecimalFormat.getCurrencyInstance();
......@@ -169,4 +190,104 @@ public class Utils {
return snackbar;
}
/**
* Alert Dialog
* @param context
* @param cancelable
* @param view
* @return
*/
public AlertDialog dialog(Context context, Boolean cancelable, View view) {
CardView btCard = view.findViewById(R.id.cvAlertOnClick);
AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setCancelable(cancelable)
.setView(view);
AlertDialog dialog = builder.create();
dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
btnCard.setOnClickListener(view1 -> listener.onClickDisimiss(dialog));
return dialog;
}
public AlertDialog dialog(Context context, Boolean cancelable, View view, @Nullable String titles) {
TextView title = view.findViewById(R.id.alertTitles);
CardView btCard = view.findViewById(R.id.cvAlertOnClick);
// set title and message
if (titles != null){
title.setText(titles);
}
AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setCancelable(cancelable)
.setView(view);
AlertDialog dialog = builder.create();
dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
btnCard.setOnClickListener(view1 -> listener.onClickDisimiss(dialog));
return dialog;
}
public AlertDialog dialog(Context context, Boolean cancelable, View view, @Nullable String titles, @Nullable String messages) {
TextView title = view.findViewById(R.id.alertTitles);
TextView message = view.findViewById(R.id.alertBody);
CardView btCard = view.findViewById(R.id.cvAlertOnClick);
// set title and message
if (titles != null){
title.setText(titles);
}
if (message != null){
message.setText(messages);
}
AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setCancelable(cancelable)
.setView(view);
AlertDialog dialog = builder.create();
dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
btnCard.setOnClickListener(view1 -> listener.onClickDisimiss(dialog));
return dialog;
}
public AlertDialog dialog(Context context, Boolean cancelable, View view, @Nullable String titles, @Nullable String messages, @Nullable String buttons) {
TextView title = view.findViewById(R.id.alertTitles);
TextView message = view.findViewById(R.id.alertBody);
TextView button = view.findViewById(R.id.tvTextBtn);
CardView btnCard = view.findViewById(R.id.cvAlertOnClick);
// set title and message
if (titles != null){
title.setText(titles);
}
if (message != null){
message.setText(messages);
}
if (button != null){
button.setText(buttons);
}
AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setCancelable(cancelable)
.setView(view);
AlertDialog dialog = builder.create();
dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
btnCard.setOnClickListener(view1 -> listener.onClickDisimiss(dialog));
return dialog;
}
}
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:fromYDelta="0%"
android:toYDelta="100%"
android:duration="@android:integer/config_mediumAnimTime"/>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="2000"/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:fromYDelta="0%"
android:toYDelta="100%"
android:duration="@android:integer/config_mediumAnimTime"/>
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/bounce_interpolator">
<scale
android:duration="1300"
android:fromXScale="0.0"
android:fromYScale="0.0"
android:pivotY="50%"
android:pivotX="50%"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/bounce_interpolator">
<scale
android:duration="1300"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotY="50%"
android:pivotX="50%"
android:toXScale="0.0"
android:toYScale="0.0" />
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout android:layout_height="wrap_content"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.google.android.material.card.MaterialCardView
android:id="@+id/cvAlertDialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="0dp"
app:cardBackgroundColor="@android:color/transparent"
android:layout_marginVertical="10dp"
android:layout_marginHorizontal="20dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/divider"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/alertTitles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@android:string/dialog_alert_title"
android:textSize="18sp"
android:textStyle="bold"
android:layout_marginBottom="10dp"
android:layout_gravity="center"/>
<TextView
android:id="@+id/alertBody"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your username or password wrong"
android:textSize="18sp"
android:gravity="center"
android:layout_gravity="center"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<View
android:id="@+id/divider"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="1dp"
style="@style/Divider.Horizontal"
app:layout_constraintTop_toBottomOf="@id/cvAlertDialog"/>
<com.google.android.material.card.MaterialCardView
android:id="@+id/cvAlertOnClick"
app:cardCornerRadius="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
app:layout_constraintTop_toBottomOf="@id/divider">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/tvTextBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Coba Lagi"
android:textSize="18sp"
android:paddingVertical="15dp"
android:gravity="center"/>
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -25,7 +25,6 @@
<item name="android:fontFamily">@font/roboto</item>
<item name="actionBarStyle">@style/ThemeActionBar</item>
<item name="bottomSheetDialogTheme">@style/ThemeOverlay.Rounded.BottomSheetDialog</item>
</style>
<style name="AppTheme.my.a" parent="Theme.MaterialComponents.Light.NoActionBar">
......@@ -98,4 +97,23 @@
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="Divider">
<item name="android:background">#36333333</item> //you can give your color here. that will change all divider color in your app.
</style>
<style name="Divider.Horizontal" parent="Divider">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item> // You can change thickness here.
</style>
<style name="Divider.Vertical" parent="Divider">
<item name="android:layout_width">1dp</item>
<item name="android:layout_height">match_parent</item>
</style>
<style name="DialogAnimation">
<item name="android:windowEnterAnimation">@anim/zoom_in_bounce</item>
<item name="android:windowExitAnimation">@anim/zoom_out_bounce</item>
</style>
</resources>
\ No newline at end of file
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