From 61c3da68fb6572635d28ee16bf03575e054f3b54 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Mon, 15 Oct 2018 18:17:12 +0300 Subject: [PATCH] Redirect to previous activity after login --- app/build.gradle | 1 + .../gr/thmmy/mthmmy/activities/LoginActivity.java | 13 +++++++++---- .../thmmy/mthmmy/activities/main/MainActivity.java | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index cb7439de..ecbd4dbc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -19,6 +19,7 @@ android { buildTypes { release { minifyEnabled true + shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } debug { diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java index a7adbf02..d6c840ad 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java @@ -40,12 +40,15 @@ public class LoginActivity extends BaseActivity { /* --Graphics End-- */ private LoginTask loginTask; + private boolean initialRedirect; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); + initialRedirect = getIntent().getBooleanExtra("REDIRECT", false); + PreferenceManager.setDefaultValues(this, R.xml.app_preferences_user, false); //Variables initialization @@ -56,7 +59,6 @@ public class LoginActivity extends BaseActivity { //Login button Click Event btnLogin.setOnClickListener(view -> { - Timber.d("Login"); //Get username and password strings username = inputUsername.getText().toString().trim(); @@ -162,9 +164,12 @@ public class LoginActivity extends BaseActivity { "Welcome, " + sessionManager.getUsername() + "!", Toast.LENGTH_LONG) .show(); BaseApplication.getInstance().logFirebaseAnalyticsEvent(FirebaseAnalytics.Event.LOGIN, null); - //Go to main - Intent intent = new Intent(LoginActivity.this, MainActivity.class); - startActivity(intent); + if(initialRedirect){ + Intent intent = new Intent(LoginActivity.this, MainActivity.class); + startActivity(intent); + } else + onBackPressed(); + finish(); overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out); break; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java index ffd82dda..67f99897 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java @@ -63,6 +63,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF if (sessionManager.isLoginScreenDefault()) { //Go to login Intent intent = new Intent(MainActivity.this, LoginActivity.class); + intent.putExtra("REDIRECT", true); startActivity(intent); finish(); overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);