Skip to content

Commit 7a0e485

Browse files
committedApr 22, 2016
add auto login
1 parent 7790d9e commit 7a0e485

File tree

10 files changed

+82
-9
lines changed

10 files changed

+82
-9
lines changed
 

‎.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/modules.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎LoginAppFB.iml ‎AndroidRecipes.iml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.id="LoginAppFB" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.id="AndroidRecipes" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
33
<component name="FacetManager">
44
<facet type="java-gradle" name="Java-Gradle">
55
<configuration>

‎app/app.iml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="LoginAppFB" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="AndroidRecipes" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
33
<component name="FacetManager">
44
<facet type="android-gradle" name="Android-Gradle">
55
<configuration>

‎app/src/main/java/com/example/royrosenberg/loginappfb/DM/ApplicationData.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
* Created by Roy.Rosenberg on 21/04/2016.
55
*/
66
public class ApplicationData {
7-
public static final String FIREBASE_BASE_URL = "https://radiant-torch-1155.firebaseio.com/";
7+
//public static final String FIREBASE_BASE_URL = "https://radiant-torch-1155.firebaseio.com/";
8+
public static final String FIREBASE_BASE_URL = "https://looksgoodandontime.firebaseio.com/";
89
}

‎app/src/main/java/com/example/royrosenberg/loginappfb/MainActivity.java

+48
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package com.example.royrosenberg.loginappfb;
22

33
import android.content.Intent;
4+
import android.content.SharedPreferences;
5+
import android.preference.PreferenceManager;
46
import android.support.v7.app.AppCompatActivity;
57
import android.os.Bundle;
68
import android.view.View;
9+
import android.widget.LinearLayout;
10+
11+
import com.example.royrosenberg.loginappfb.DM.User;
12+
import com.example.royrosenberg.loginappfb.Services.UserManager;
713

814
public class MainActivity extends AppCompatActivity {
915

@@ -12,6 +18,48 @@ protected void onCreate(Bundle savedInstanceState) {
1218
super.onCreate(savedInstanceState);
1319
setContentView(R.layout.activity_main);
1420
setTitle("Gali's Kitchen - Welcome Page");
21+
22+
CheckPreferences();
23+
}
24+
25+
private void CheckPreferences() {
26+
//check if user should auto-loggin
27+
SharedPreferences preferencesObj =
28+
PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
29+
String key = preferencesObj.getString("UserKey", "");
30+
String email = preferencesObj.getString("UserEmail", "");
31+
String psw = preferencesObj.getString("UserPassword", "");
32+
33+
if(key.isEmpty() || email.isEmpty() || psw.isEmpty())
34+
return;
35+
36+
User u = new User();
37+
u.Email = email;
38+
u.Password = psw;
39+
u.Key = key;
40+
UserManager mng = new UserManager(this);
41+
42+
//disable controls
43+
final LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);
44+
layout.setVisibility(View.INVISIBLE);
45+
setTitle("Loggin In...");
46+
mng.Login(u, new UserManager.LoginEvents() {
47+
@Override
48+
public void onLoginSucceeded(User userOK) {
49+
//go to main screen
50+
Intent intent = new Intent(getApplicationContext(), WelcomeActivity.class);
51+
intent.putExtra("UserObj", userOK);
52+
startActivity(intent);
53+
}
54+
55+
@Override
56+
public void onLoginFailed(User u) {
57+
layout.setVisibility(View.VISIBLE);
58+
}
59+
});
60+
61+
62+
1563
}
1664

1765
public void register_click(View view){

‎app/src/main/java/com/example/royrosenberg/loginappfb/SignInActivity.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
import android.app.Service;
44
import android.content.Intent;
5+
import android.content.SharedPreferences;
6+
import android.preference.PreferenceManager;
57
import android.support.v7.app.AppCompatActivity;
68
import android.os.Bundle;
79
import android.view.View;
10+
import android.widget.CheckBox;
811
import android.widget.EditText;
912
import android.widget.ProgressBar;
1013
import android.widget.TextView;
@@ -35,14 +38,26 @@ private User getUserFromControl() {
3538
return user;
3639
}
3740

38-
public void login_click(View view){
39-
final ProgressBar pb = (ProgressBar)findViewById(R.id.progressBar);
41+
public void login_click(View view) {
42+
final ProgressBar pb = (ProgressBar) findViewById(R.id.progressBar);
4043
pb.setVisibility(View.VISIBLE);
4144

4245
User user = getUserFromControl();
4346
_usrMgr.Login(user, new UserManager.LoginEvents() {
4447
@Override
4548
public void onLoginSucceeded(User userOK) {
49+
//if keep me logged in is set, save in preferences
50+
CheckBox chBx = (CheckBox)findViewById(R.id.chbxKeepLogged);
51+
if(chBx.isChecked()) {
52+
SharedPreferences preferencesObj =
53+
PreferenceManager.getDefaultSharedPreferences(SignInActivity.this);
54+
SharedPreferences.Editor editor = preferencesObj.edit();
55+
editor.putString("UserKey", userOK.Key);
56+
editor.putString("UserEmail", userOK.Email);
57+
editor.putString("UserPassword", userOK.Password);
58+
editor.commit();
59+
}
60+
//go to main screen
4661
Intent intent = new Intent(getApplicationContext(), WelcomeActivity.class);
4762
intent.putExtra("UserObj", userOK);
4863
startActivity(intent);
@@ -51,7 +66,7 @@ public void onLoginSucceeded(User userOK) {
5166
@Override
5267
public void onLoginFailed(User u) {
5368
pb.setVisibility(View.INVISIBLE);
54-
TextView tvNotification = (TextView)findViewById(R.id.tvNotification);
69+
TextView tvNotification = (TextView) findViewById(R.id.tvNotification);
5570
tvNotification.setText("Login Failed, Try again");
5671
tvNotification.setVisibility(View.VISIBLE);
5772
}

‎app/src/main/java/com/example/royrosenberg/loginappfb/WelcomeActivity.java

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public class WelcomeActivity extends AppCompatActivity {
2626
protected void onCreate(Bundle savedInstanceState) {
2727
super.onCreate(savedInstanceState);
2828
setContentView(R.layout.activity_welcome);
29-
setTitle("Gali's Kitchen - Welcome");
3029
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
3130
setSupportActionBar(toolbar);
3231

‎app/src/main/res/layout/activity_main.xml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
android:layout_centerInParent="true"
1818
android:background="@drawable/linearlayout_bg"
1919
android:padding="10dp"
20+
android:id="@+id/mainLayout"
2021
>
2122

2223
<Button

‎app/src/main/res/layout/activity_sign_in.xml

+9
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@
3939
android:textColorHint="#cccccc"
4040
android:password="true"
4141
android:drawableLeft="@drawable/password"/>
42+
43+
44+
<CheckBox
45+
android:layout_width="wrap_content"
46+
android:layout_height="wrap_content"
47+
android:padding="10dp"
48+
android:text="Keep me logged in"
49+
android:id="@+id/chbxKeepLogged" />
50+
4251
<Button
4352
android:id="@+id/btnSingIn"
4453
android:layout_width="match_parent"

0 commit comments

Comments
 (0)
Please sign in to comment.