Skip to content

Commit f3d21f8

Browse files
author
Fiqry choerudin
committed
init
0 parents  commit f3d21f8

44 files changed

Lines changed: 1221 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
.idea

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 29
5+
buildToolsVersion "29.0.3"
6+
7+
defaultConfig {
8+
applicationId "com.suncode.loginapp"
9+
minSdkVersion 23
10+
targetSdkVersion 29
11+
versionCode 1
12+
versionName "1.0"
13+
14+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15+
}
16+
17+
buildTypes {
18+
release {
19+
minifyEnabled false
20+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21+
}
22+
}
23+
compileOptions {
24+
sourceCompatibility = 1.8
25+
targetCompatibility = 1.8
26+
}
27+
28+
}
29+
30+
dependencies {
31+
implementation fileTree(dir: 'libs', include: ['*.jar'])
32+
33+
implementation 'androidx.appcompat:appcompat:1.1.0'
34+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
35+
implementation 'com.google.android.material:material:1.1.0'
36+
implementation 'androidx.annotation:annotation:1.1.0'
37+
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
38+
testImplementation 'junit:junit:4.13'
39+
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
40+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
41+
implementation 'com.google.firebase:firebase-analytics:17.4.4'
42+
implementation 'com.google.firebase:firebase-auth:19.3.2'
43+
implementation 'com.google.firebase:firebase-firestore:21.5.0'
44+
}
45+
46+
apply plugin: 'com.google.gms.google-services'

app/google-services.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"project_info": {
3+
"project_number": "557430454440",
4+
"firebase_url": "https://work-login-multi-role.firebaseio.com",
5+
"project_id": "work-login-multi-role",
6+
"storage_bucket": "work-login-multi-role.appspot.com"
7+
},
8+
"client": [
9+
{
10+
"client_info": {
11+
"mobilesdk_app_id": "1:557430454440:android:1602d16e2e3c956f776a9d",
12+
"android_client_info": {
13+
"package_name": "com.suncode.loginapp"
14+
}
15+
},
16+
"oauth_client": [
17+
{
18+
"client_id": "557430454440-6s6po8530semj0585kac83avadbl5h9g.apps.googleusercontent.com",
19+
"client_type": 1,
20+
"android_info": {
21+
"package_name": "com.suncode.loginapp",
22+
"certificate_hash": "4ee547df616aec8ffae8d3740623f4ed37c180af"
23+
}
24+
},
25+
{
26+
"client_id": "557430454440-o9s47o3vq7kfh9ntt0ouumr64s66a9me.apps.googleusercontent.com",
27+
"client_type": 3
28+
}
29+
],
30+
"api_key": [
31+
{
32+
"current_key": "AIzaSyCRxu2FrLl0pqV3jh87sD0LPNO4662cOao"
33+
}
34+
],
35+
"services": {
36+
"appinvite_service": {
37+
"other_platform_oauth_client": [
38+
{
39+
"client_id": "557430454440-o9s47o3vq7kfh9ntt0ouumr64s66a9me.apps.googleusercontent.com",
40+
"client_type": 3
41+
}
42+
]
43+
}
44+
}
45+
}
46+
],
47+
"configuration_version": "1"
48+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.suncode.loginapp;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
25+
assertEquals("com.suncode.loginapp", appContext.getPackageName());
26+
}
27+
}

app/src/main/AndroidManifest.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.suncode.loginapp">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity android:name=".ui.ActivityTwo" />
13+
<activity android:name=".ui.ActivityOne" />
14+
<activity android:name=".LoginActivity" android:label="Login">
15+
<intent-filter>
16+
<action android:name="android.intent.action.MAIN" />
17+
18+
<category android:name="android.intent.category.LAUNCHER" />
19+
</intent-filter>
20+
</activity>
21+
</application>
22+
23+
</manifest>
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
package com.suncode.loginapp;
2+
3+
import androidx.annotation.NonNull;
4+
import androidx.appcompat.app.AppCompatActivity;
5+
6+
import android.annotation.SuppressLint;
7+
import android.content.Intent;
8+
import android.os.Bundle;
9+
import android.provider.Settings;
10+
import android.text.TextUtils;
11+
import android.util.Log;
12+
import android.view.View;
13+
import android.widget.BaseAdapter;
14+
import android.widget.Button;
15+
import android.widget.EditText;
16+
17+
import com.google.android.gms.tasks.OnFailureListener;
18+
import com.google.firebase.auth.FirebaseUser;
19+
import com.google.firebase.firestore.DocumentReference;
20+
import com.google.firebase.firestore.DocumentSnapshot;
21+
import com.suncode.loginapp.callback.LoginViewCallback;
22+
import com.suncode.loginapp.model.User;
23+
import com.suncode.loginapp.ui.ActivityOne;
24+
import com.suncode.loginapp.ui.ActivityTwo;
25+
import com.suncode.loginapp.ui.base.BaseActivity;
26+
import com.suncode.loginapp.util.Constant;
27+
28+
public class LoginActivity extends BaseActivity implements LoginViewCallback {
29+
30+
private EditText mEmail;
31+
private EditText mPassword;
32+
private Button mLoginButton;
33+
34+
@Override
35+
protected void onCreate(Bundle savedInstanceState) {
36+
super.onCreate(savedInstanceState);
37+
setContentView(R.layout.activity_main);
38+
39+
mEmail = findViewById(R.id.email);
40+
mPassword = findViewById(R.id.password);
41+
mLoginButton = findViewById(R.id.login);
42+
43+
mLoginButton.setOnClickListener(new View.OnClickListener() {
44+
@Override
45+
public void onClick(View v) {
46+
onShowProgress();
47+
String userEmail = mEmail.getText().toString();
48+
String userPassword = mPassword.getText().toString();
49+
50+
if (TextUtils.isEmpty(mEmail.getText()) && TextUtils.isEmpty(mPassword.getText())) {
51+
showToast("Username / Password Kosong");
52+
onHideProgress();
53+
} else if (TextUtils.isEmpty(mEmail.getText())) {
54+
showToast("Username Kosong");
55+
onHideProgress();
56+
} else if (TextUtils.isEmpty(mPassword.getText())) {
57+
showToast("Password Kosong");
58+
onHideProgress();
59+
} else {
60+
getAuthFirebase(userEmail, userPassword);
61+
}
62+
}
63+
});
64+
}
65+
66+
private void getFireStoreData(String idUser) {
67+
DocumentReference docRef = firebaseFirestore.collection("user").document(idUser);
68+
docRef.get().addOnCompleteListener(task -> {
69+
if (task.isSuccessful()) {
70+
DocumentSnapshot document = task.getResult();
71+
if (document.exists()) {
72+
int userTag = document.getLong("tag").intValue();
73+
saveSession(idUser, userTag, document);
74+
} else {
75+
Log.d("gagal", "Documment tidak ada");
76+
}
77+
} else {
78+
Log.d("TAG", "gagal", task.getException());
79+
}
80+
});
81+
}
82+
83+
// Save Session
84+
private void saveSession(String uid, int userTag, DocumentSnapshot documentSnapshot) {
85+
if (userTag == 1) {
86+
User userAdmin = new User();
87+
userAdmin.setName(documentSnapshot.getString("name"));
88+
userAdmin.setTag(documentSnapshot.getLong("tag").intValue());
89+
userAdmin.setuId(uid);
90+
mSession.setupSessionAdmin(userAdmin);
91+
92+
} else if (userTag == 2) {
93+
User user = new User();
94+
user.setName(documentSnapshot.getString("name"));
95+
user.setTag(documentSnapshot.getLong("tag").intValue());
96+
user.setuId(uid);
97+
mSession.setupSessionUser(user);
98+
}
99+
checkUserLogin(mSession.getPreferences().getInt(Constant.KEY_IS_LOGIN,0));
100+
}
101+
102+
private void getAuthFirebase(String userEmail, String userPassword) {
103+
firebaseAuth.signInWithEmailAndPassword(userEmail, userPassword).addOnCompleteListener(task -> {
104+
task.addOnFailureListener(LoginActivity.this, e -> onFailedAuthFirebase());
105+
if (task.isSuccessful()) {
106+
FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
107+
assert firebaseUser != null;
108+
onSuccessAuthFirebase(firebaseUser.getUid());
109+
} else {
110+
onFailedAuthFirebase();
111+
}
112+
});
113+
}
114+
115+
private void checkUserLogin(int cekPengguna) {
116+
onHideProgress();
117+
if (cekPengguna == 1) {
118+
Intent j = new Intent(LoginActivity.this, ActivityOne.class);
119+
startActivity(j);
120+
finish();
121+
} else if (cekPengguna == 2) {
122+
Intent i = new Intent(LoginActivity.this, ActivityTwo.class);
123+
startActivity(i);
124+
finish();
125+
}
126+
}
127+
128+
@Override
129+
public void onSuccessAuthFirebase(String uid) {
130+
getFireStoreData(uid);
131+
}
132+
133+
@Override
134+
public void onFailedAuthFirebase() {
135+
136+
}
137+
138+
@Override
139+
public void onShowProgress() {
140+
141+
}
142+
143+
@Override
144+
public void onHideProgress() {
145+
146+
}
147+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.suncode.loginapp.callback;
2+
3+
public interface LoginViewCallback {
4+
5+
void onSuccessAuthFirebase(String uid);
6+
void onFailedAuthFirebase();
7+
void onShowProgress();
8+
void onHideProgress();
9+
10+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.suncode.loginapp.model;
2+
3+
public class User {
4+
private String name;
5+
private String uId;
6+
private int tag;
7+
8+
public User(String name, String uId, int tag) {
9+
this.name = name;
10+
this.uId = uId;
11+
this.tag = tag;
12+
}
13+
14+
public User() {
15+
}
16+
17+
public String getName() {
18+
return name;
19+
}
20+
21+
public void setName(String name) {
22+
this.name = name;
23+
}
24+
25+
public String getuId() {
26+
return uId;
27+
}
28+
29+
public void setuId(String uId) {
30+
this.uId = uId;
31+
}
32+
33+
public int getTag() {
34+
return tag;
35+
}
36+
37+
public void setTag(int tag) {
38+
this.tag = tag;
39+
}
40+
}

0 commit comments

Comments
 (0)