Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
Your Cashier
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
Ahmad Abi Mulya
Your Cashier
Commits
2a6a2dab
Commit
2a6a2dab
authored
Aug 27, 2020
by
Wahyu Wibowo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add fitur login
parent
5e3f552d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
137 additions
and
4 deletions
+137
-4
LoginActivity.java
...com/example/yourcashiertest/activities/LoginActivity.java
+26
-3
ResponseUser.java
...java/com/example/yourcashiertest/models/ResponseUser.java
+40
-0
User.java
...rc/main/java/com/example/yourcashiertest/models/User.java
+40
-1
UserService.java
...ava/com/example/yourcashiertest/services/UserService.java
+7
-0
UserViewModel.java
...com/example/yourcashiertest/viewmodels/UserViewModel.java
+24
-0
No files found.
app/src/main/java/com/example/yourcashiertest/activities/LoginActivity.java
View file @
2a6a2dab
package
com
.
example
.
yourcashiertest
.
activities
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.lifecycle.Observer
;
import
androidx.lifecycle.ViewModelProvider
;
import
android.content.Context
;
import
android.content.Intent
;
...
...
@@ -10,9 +12,13 @@ import android.view.View;
import
android.widget.Toast
;
import
com.example.yourcashiertest.R
;
import
com.example.yourcashiertest.models.User
;
import
com.example.yourcashiertest.viewmodels.UserViewModel
;
import
com.google.android.material.button.MaterialButton
;
import
com.google.android.material.textfield.TextInputEditText
;
import
java.util.List
;
public
class
LoginActivity
extends
AppCompatActivity
{
TextInputEditText
etUsername
,
etPassword
;
MaterialButton
btnLogin
;
...
...
@@ -23,6 +29,8 @@ public class LoginActivity extends AppCompatActivity {
// public static final String my_shared = "session_status";
private
PrefManager
prefManager
;
UserViewModel
viewModel
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
...
...
@@ -38,6 +46,8 @@ public class LoginActivity extends AppCompatActivity {
etUsername
=
findViewById
(
R
.
id
.
etUsername
);
btnLogin
=
findViewById
(
R
.
id
.
btnLogin
);
viewModel
=
new
ViewModelProvider
(
this
,
new
ViewModelProvider
.
NewInstanceFactory
()).
get
(
UserViewModel
.
class
);
btnLogin
.
setOnClickListener
(
view
->
{
if
(
etUsername
.
getText
().
toString
().
length
()
==
0
||
etPassword
.
getText
().
toString
().
length
()
==
0
){
...
...
@@ -47,10 +57,23 @@ public class LoginActivity extends AppCompatActivity {
}
else
if
(
etPassword
.
getText
().
toString
().
length
()
<
8
)
{
etPassword
.
setError
(
"Password length cannot be less than 8 characters"
);
}
else
{
startActivity
(
new
Intent
(
LoginActivity
.
this
,
MainActivity
.
class
)
.
putExtra
(
DATA_LOGIN
,
etUsername
.
getText
().
toString
()));
finish
();
viewModel
.
setListUser
();
checkLogin
();
}
});
}
private
void
checkLogin
()
{
viewModel
.
getListUser
().
observe
(
this
,
users
->
{
for
(
int
i
=
0
;
i
<
users
.
size
();
i
++){
if
(
users
.
get
(
i
).
getEmail
().
equals
(
etUsername
.
getText
().
toString
())
&&
users
.
get
(
i
).
getPassword
().
equals
(
etPassword
.
getText
().
toString
())){
startActivity
(
new
Intent
(
LoginActivity
.
this
,
MainActivity
.
class
)
.
putExtra
(
DATA_LOGIN
,
users
.
get
(
i
).
getFullName
()));
}
}
// Toast.makeText(getApplication(), "Username or password wrong", Toast.LENGTH_LONG).show();
});
}
...
...
app/src/main/java/com/example/yourcashiertest/models/ResponseUser.java
0 → 100644
View file @
2a6a2dab
package
com
.
example
.
yourcashiertest
.
models
;
import
java.util.List
;
import
com.google.gson.annotations.SerializedName
;
public
class
ResponseUser
{
@SerializedName
(
"data"
)
private
List
<
User
>
user
;
@SerializedName
(
"message"
)
private
String
message
;
@SerializedName
(
"status"
)
private
boolean
status
;
public
void
setData
(
List
<
User
>
data
){
this
.
user
=
data
;
}
public
List
<
User
>
getData
(){
return
user
;
}
public
void
setMessage
(
String
message
){
this
.
message
=
message
;
}
public
String
getMessage
(){
return
message
;
}
public
void
setStatus
(
boolean
status
){
this
.
status
=
status
;
}
public
boolean
isStatus
(){
return
status
;
}
}
\ No newline at end of file
app/src/main/java/com/example/yourcashiertest/models/User.java
View file @
2a6a2dab
package
com
.
example
.
yourcashiertest
.
models
;
import
android.os.Parcel
;
import
android.os.Parcelable
;
import
com.google.gson.annotations.SerializedName
;
public
class
User
{
public
class
User
implements
Parcelable
{
@SerializedName
(
"password"
)
private
String
password
;
...
...
@@ -16,6 +19,29 @@ public class User{
@SerializedName
(
"email"
)
private
String
email
;
public
User
(
Parcel
in
)
{
password
=
in
.
readString
();
fullName
=
in
.
readString
();
phoneNumber
=
in
.
readString
();
email
=
in
.
readString
();
}
public
static
final
Creator
<
User
>
CREATOR
=
new
Creator
<
User
>()
{
@Override
public
User
createFromParcel
(
Parcel
in
)
{
return
new
User
(
in
);
}
@Override
public
User
[]
newArray
(
int
size
)
{
return
new
User
[
size
];
}
};
public
User
()
{
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
...
...
@@ -47,4 +73,17 @@ public class User{
public
String
getEmail
(){
return
email
;
}
@Override
public
int
describeContents
()
{
return
0
;
}
@Override
public
void
writeToParcel
(
Parcel
dest
,
int
flags
)
{
dest
.
writeString
(
password
);
dest
.
writeString
(
fullName
);
dest
.
writeString
(
phoneNumber
);
dest
.
writeString
(
email
);
}
}
\ No newline at end of file
app/src/main/java/com/example/yourcashiertest/services/UserService.java
View file @
2a6a2dab
package
com
.
example
.
yourcashiertest
.
services
;
import
com.example.yourcashiertest.models.ResponseUser
;
import
com.example.yourcashiertest.models.User
;
import
java.util.List
;
import
retrofit2.Call
;
import
retrofit2.http.Body
;
import
retrofit2.http.GET
;
import
retrofit2.http.Headers
;
import
retrofit2.http.POST
;
public
interface
UserService
{
@GET
(
"v1/customer"
)
Call
<
ResponseUser
>
getAllUser
();
@Headers
(
"Content-Type: application/json"
)
@POST
(
"v1/customer"
)
Call
<
User
>
registerUser
(
@Body
User
user
);
...
...
app/src/main/java/com/example/yourcashiertest/viewmodels/UserViewModel.java
View file @
2a6a2dab
package
com
.
example
.
yourcashiertest
.
viewmodels
;
import
android.util.Log
;
import
androidx.lifecycle.MutableLiveData
;
import
androidx.lifecycle.ViewModel
;
import
com.example.yourcashiertest.clients.ApiClient
;
import
com.example.yourcashiertest.models.ResponseUser
;
import
com.example.yourcashiertest.models.User
;
import
com.example.yourcashiertest.services.UserService
;
...
...
@@ -18,6 +21,11 @@ public class UserViewModel extends ViewModel {
public
final
String
BASE_URL
=
"https://your-cashier.herokuapp.com/api/"
;
public
MutableLiveData
<
List
<
User
>>
getListUser
(){
return
this
.
listUser
;
}
public
void
registrasi
(
User
user
){
ApiClient
.
client
(
UserService
.
class
,
BASE_URL
).
registerUser
(
user
)
.
enqueue
(
new
Callback
<
User
>()
{
...
...
@@ -32,4 +40,20 @@ public class UserViewModel extends ViewModel {
}
});
}
public
void
setListUser
(){
ApiClient
.
client
(
UserService
.
class
,
BASE_URL
).
getAllUser
().
enqueue
(
new
Callback
<
ResponseUser
>()
{
@Override
public
void
onResponse
(
Call
<
ResponseUser
>
call
,
Response
<
ResponseUser
>
response
)
{
listUser
.
setValue
(
response
.
body
().
getData
());
Log
.
d
(
"user"
,
String
.
valueOf
(
response
.
body
().
getData
()));
}
@Override
public
void
onFailure
(
Call
<
ResponseUser
>
call
,
Throwable
t
)
{
}
});
}
}
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