[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [snowflake-mobile/master] Handled back press from fragments
commit a9548589575a7bc6dc443df09189e5eef27b4c1c
Author: Hashik Donthineni <HashikDonthineni@xxxxxxxxx>
Date: Sun Jun 28 16:19:23 2020 +0530
Handled back press from fragments
---
.../java/org/torproject/snowflake/MainActivity.java | 20 ++++++++++++++++++++
.../snowflake/constants/FragmentConstants.java | 6 ++++++
2 files changed, 26 insertions(+)
diff --git a/app/src/main/java/org/torproject/snowflake/MainActivity.java b/app/src/main/java/org/torproject/snowflake/MainActivity.java
index a1eb34d..7bafaf4 100644
--- a/app/src/main/java/org/torproject/snowflake/MainActivity.java
+++ b/app/src/main/java/org/torproject/snowflake/MainActivity.java
@@ -8,6 +8,7 @@ import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
+import android.util.Log;
import android.view.View;
import android.widget.Button;
@@ -15,6 +16,7 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import org.torproject.snowflake.constants.ForegroundServiceConstants;
+import org.torproject.snowflake.constants.FragmentConstants;
import org.torproject.snowflake.interfaces.MainFragmentCallback;
/**
@@ -22,6 +24,7 @@ import org.torproject.snowflake.interfaces.MainFragmentCallback;
*/
public class MainActivity extends AppCompatActivity implements MainFragmentCallback {
private static final String TAG = "MainActivity";
+ int currentFragment;
private SharedPreferences sharedPreferences;
private Button settingsButton;
@@ -59,6 +62,14 @@ public class MainActivity extends AppCompatActivity implements MainFragmentCallb
* @param fragment New Fragment that is to be placed in the container.
*/
private void startFragment(Fragment fragment) {
+ if (fragment instanceof MainFragment) {
+ currentFragment = FragmentConstants.MAIN_FRAGMENT;
+ } else {
+ currentFragment = FragmentConstants.APP_SETTINGS_FRAGMENT;
+ }
+
+ Log.d(TAG, "startFragment: " + currentFragment);
+
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container,
@@ -107,4 +118,13 @@ public class MainActivity extends AppCompatActivity implements MainFragmentCallb
notificationManager.createNotificationChannel(channel);
}
}
+
+ @Override
+ public void onBackPressed() {
+ //If the back is pressed on AppSettingsFragment take it back to MainFragment.
+ if(currentFragment == FragmentConstants.APP_SETTINGS_FRAGMENT)
+ startFragment(MainFragment.newInstance());
+ else
+ super.onBackPressed();
+ }
}
diff --git a/app/src/main/java/org/torproject/snowflake/constants/FragmentConstants.java b/app/src/main/java/org/torproject/snowflake/constants/FragmentConstants.java
new file mode 100644
index 0000000..00942b8
--- /dev/null
+++ b/app/src/main/java/org/torproject/snowflake/constants/FragmentConstants.java
@@ -0,0 +1,6 @@
+package org.torproject.snowflake.constants;
+
+public class FragmentConstants {
+ public static final int MAIN_FRAGMENT = 0;
+ public static final int APP_SETTINGS_FRAGMENT = 1;
+}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits