Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
meser
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Muhammad Suryono
meser
Commits
c62d96a2
Commit
c62d96a2
authored
Sep 02, 2020
by
fauzi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix login dan tambahkan animasi di alert dialog
parent
5e2c7278
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
276 additions
and
22 deletions
+276
-22
LoginState.java
app/src/main/java/com/yono/messeripos/LoginState.java
+19
-12
Utils.java
app/src/main/java/com/yono/messeripos/utils/Utils.java
+121
-0
fade_out.xml
app/src/main/res/anim/fade_out.xml
+7
-6
slide_in.xml
app/src/main/res/anim/slide_in.xml
+7
-0
zoom_in_bounce.xml
app/src/main/res/anim/zoom_in_bounce.xml
+15
-0
zoom_out_bounce.xml
app/src/main/res/anim/zoom_out_bounce.xml
+15
-0
alert_dialog.xml
app/src/main/res/layout/alert_dialog.xml
+73
-3
styles.xml
app/src/main/res/values/styles.xml
+19
-1
No files found.
app/src/main/java/com/yono/messeripos/LoginState.java
View file @
c62d96a2
package
com
.
yono
.
messeripos
;
package
com
.
yono
.
messeripos
;
import
android.annotation.SuppressLint
;
import
android.app.AlertDialog
;
import
android.app.Dialog
;
import
android.app.Dialog
;
import
android.app.ProgressDialog
;
import
android.app.ProgressDialog
;
import
android.content.Context
;
import
android.content.Context
;
...
@@ -18,7 +20,6 @@ import android.widget.RelativeLayout;
...
@@ -18,7 +20,6 @@ import android.widget.RelativeLayout;
import
androidx.annotation.NonNull
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.Nullable
;
import
androidx.appcompat.app.AlertDialog
;
import
androidx.lifecycle.LifecycleOwner
;
import
androidx.lifecycle.LifecycleOwner
;
import
androidx.lifecycle.Observer
;
import
androidx.lifecycle.Observer
;
...
@@ -30,6 +31,7 @@ import com.google.android.material.button.MaterialButton;
...
@@ -30,6 +31,7 @@ import com.google.android.material.button.MaterialButton;
import
com.google.android.material.dialog.MaterialAlertDialogBuilder
;
import
com.google.android.material.dialog.MaterialAlertDialogBuilder
;
import
com.google.android.material.snackbar.Snackbar
;
import
com.google.android.material.snackbar.Snackbar
;
import
com.google.android.material.textfield.TextInputEditText
;
import
com.google.android.material.textfield.TextInputEditText
;
import
com.yono.messeripos.models.CategoryModels
;
import
com.yono.messeripos.models.MainViewModels
;
import
com.yono.messeripos.models.MainViewModels
;
import
com.yono.messeripos.models.UsersModels
;
import
com.yono.messeripos.models.UsersModels
;
import
com.yono.messeripos.response.DataResponse
;
import
com.yono.messeripos.response.DataResponse
;
...
@@ -50,7 +52,7 @@ public class LoginState extends BottomSheetDialogFragment {
...
@@ -50,7 +52,7 @@ public class LoginState extends BottomSheetDialogFragment {
SharedPreferences
sharedPreferences
;
SharedPreferences
sharedPreferences
;
Utils
utils
;
Utils
utils
;
ProgressBar
bar
;
ProgressBar
bar
;
AlertDialog
alertDialog
;
AlertDialog
.
Builder
builder
;
ProgressDialog
dialog
;
ProgressDialog
dialog
;
...
@@ -100,15 +102,7 @@ public class LoginState extends BottomSheetDialogFragment {
...
@@ -100,15 +102,7 @@ public class LoginState extends BottomSheetDialogFragment {
sheetBehavior
.
setPeekHeight
(
setHeight
);
sheetBehavior
.
setPeekHeight
(
setHeight
);
loginLayout
.
setMinimumHeight
(
setHeight
);
loginLayout
.
setMinimumHeight
(
setHeight
);
// alert dialog buat nampilin error
// loginButton on click
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
.
setOnClickListener
(
view1
->
{
loginButton
.
setOnClickListener
(
view1
->
{
if
(
sheetBehavior
.
getState
()
!=
BottomSheetBehavior
.
STATE_EXPANDED
)
{
if
(
sheetBehavior
.
getState
()
!=
BottomSheetBehavior
.
STATE_EXPANDED
)
{
bar
.
setVisibility
(
View
.
VISIBLE
);
bar
.
setVisibility
(
View
.
VISIBLE
);
...
@@ -157,6 +151,7 @@ public class LoginState extends BottomSheetDialogFragment {
...
@@ -157,6 +151,7 @@ public class LoginState extends BottomSheetDialogFragment {
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
,
new
Observer
<
DataResponse
<
UsersModels
>>()
{
@SuppressLint
(
"ResourceType"
)
@Override
@Override
public
void
onChanged
(
DataResponse
<
UsersModels
>
usersModelsDataResponse
)
{
public
void
onChanged
(
DataResponse
<
UsersModels
>
usersModelsDataResponse
)
{
...
@@ -198,7 +193,19 @@ public class LoginState extends BottomSheetDialogFragment {
...
@@ -198,7 +193,19 @@ public class LoginState extends BottomSheetDialogFragment {
sheetDialog
.
setCancelable
(
true
);
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
);
username
.
setEnabled
(
true
);
password
.
setEnabled
(
true
);
password
.
setEnabled
(
true
);
loginButton
.
setEnabled
(
true
);
loginButton
.
setEnabled
(
true
);
...
...
app/src/main/java/com/yono/messeripos/utils/Utils.java
View file @
c62d96a2
package
com
.
yono
.
messeripos
.
utils
;
package
com
.
yono
.
messeripos
.
utils
;
import
android.app.AlertDialog
;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.res.Resources
;
import
android.content.res.Resources
;
import
android.graphics.Bitmap
;
import
android.graphics.Bitmap
;
...
@@ -8,14 +9,20 @@ import android.os.Build;
...
@@ -8,14 +9,20 @@ import android.os.Build;
import
android.util.Base64
;
import
android.util.Base64
;
import
android.util.Log
;
import
android.util.Log
;
import
android.view.View
;
import
android.view.View
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.RequiresApi
;
import
androidx.annotation.RequiresApi
;
import
androidx.cardview.widget.CardView
;
import
androidx.recyclerview.widget.DividerItemDecoration
;
import
androidx.recyclerview.widget.DividerItemDecoration
;
import
com.bumptech.glide.load.engine.Resource
;
import
com.bumptech.glide.load.engine.Resource
;
import
com.google.android.material.snackbar.Snackbar
;
import
com.google.android.material.snackbar.Snackbar
;
import
com.google.gson.Gson
;
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.io.ByteArrayOutputStream
;
import
java.text.DecimalFormat
;
import
java.text.DecimalFormat
;
...
@@ -29,7 +36,21 @@ import java.util.Locale;
...
@@ -29,7 +36,21 @@ import java.util.Locale;
public
class
Utils
{
public
class
Utils
{
public
Utils
(){};
public
Utils
(
View
v
){};
public
long
grandTotal
=
0
;
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
){
public
String
convertPrice
(
String
mataUang
,
int
nilai
){
DecimalFormat
rupiah
=
(
DecimalFormat
)
DecimalFormat
.
getCurrencyInstance
();
DecimalFormat
rupiah
=
(
DecimalFormat
)
DecimalFormat
.
getCurrencyInstance
();
...
@@ -169,4 +190,104 @@ public class Utils {
...
@@ -169,4 +190,104 @@ public class Utils {
return
snackbar
;
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
;
}
}
}
app/src/main/res/anim/fade_out.xml
View file @
c62d96a2
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<set
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<translate
android:fromYDelta=
"0%"
<alpha
android:toYDelta=
"100%"
android:fromAlpha=
"1.0"
android:duration=
"@android:integer/config_mediumAnimTime"
/>
android:toAlpha=
"0.0"
</set>
android:duration=
"2000"
/>
\ No newline at end of file
</set>
app/src/main/res/anim/slide_in.xml
0 → 100644
View file @
c62d96a2
<?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
app/src/main/res/anim/zoom_in_bounce.xml
0 → 100644
View file @
c62d96a2
<?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
app/src/main/res/anim/zoom_out_bounce.xml
0 → 100644
View file @
c62d96a2
<?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
app/src/main/res/layout/alert_dialog.xml
View file @
c62d96a2
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_height=
"wrap_content"
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"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>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
app/src/main/res/values/styles.xml
View file @
c62d96a2
...
@@ -25,7 +25,6 @@
...
@@ -25,7 +25,6 @@
<item
name=
"android:fontFamily"
>
@font/roboto
</item>
<item
name=
"android:fontFamily"
>
@font/roboto
</item>
<item
name=
"actionBarStyle"
>
@style/ThemeActionBar
</item>
<item
name=
"actionBarStyle"
>
@style/ThemeActionBar
</item>
<item
name=
"bottomSheetDialogTheme"
>
@style/ThemeOverlay.Rounded.BottomSheetDialog
</item>
<item
name=
"bottomSheetDialogTheme"
>
@style/ThemeOverlay.Rounded.BottomSheetDialog
</item>
</style>
</style>
<style
name=
"AppTheme.my.a"
parent=
"Theme.MaterialComponents.Light.NoActionBar"
>
<style
name=
"AppTheme.my.a"
parent=
"Theme.MaterialComponents.Light.NoActionBar"
>
...
@@ -98,4 +97,23 @@
...
@@ -98,4 +97,23 @@
<item
name=
"windowActionBar"
>
false
</item>
<item
name=
"windowActionBar"
>
false
</item>
<item
name=
"windowNoTitle"
>
true
</item>
<item
name=
"windowNoTitle"
>
true
</item>
</style>
</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>
</resources>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment