Parcourir la source

proper back arrow handling after moving auto upload screen to settings

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Andy Scherzinger il y a 4 ans
Parent
commit
54589b42b4

+ 0 - 1
src/main/java/com/nextcloud/client/jobs/MediaFoldersDetectionWork.kt

@@ -193,7 +193,6 @@ class MediaFoldersDetectionWork constructor(
         intent.putExtra(NotificationWork.KEY_NOTIFICATION_ACCOUNT, user.accountName)
         intent.putExtra(KEY_MEDIA_FOLDER_PATH, path)
         intent.putExtra(KEY_MEDIA_FOLDER_TYPE, type)
-        intent.putExtra(SyncedFoldersActivity.EXTRA_SHOW_SIDEBAR, true)
         val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT)
         val notificationBuilder = NotificationCompat.Builder(
             context,

+ 4 - 2
src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java

@@ -463,7 +463,8 @@ public class SettingsActivity extends ThemedPreferenceActivity
             preferenceCategoryMore.removePreference(autoUpload);
         } else {
             autoUpload.setOnPreferenceClickListener(preference -> {
-                SyncedFoldersActivity.startActivityWithoutSidebar(this);
+                Intent intent = new Intent(this, SyncedFoldersActivity.class);
+                startActivity(intent);
                 return true;
             });
         }
@@ -632,7 +633,8 @@ public class SettingsActivity extends ThemedPreferenceActivity
                 if (getResources().getBoolean(R.bool.syncedFolder_light)
                         && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                     pSyncedFolder.setOnPreferenceClickListener(preference -> {
-                        SyncedFoldersActivity.startActivityWithoutSidebar(this);
+                        Intent intent = new Intent(this, SyncedFoldersActivity.class);
+                        startActivity(intent);
                         return true;
                     });
                 } else {

+ 34 - 58
src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.java

@@ -28,6 +28,7 @@ import android.app.NotificationManager;
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.PackageManager;
+import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
@@ -82,6 +83,7 @@ import javax.inject.Inject;
 
 import androidx.annotation.NonNull;
 import androidx.appcompat.app.AlertDialog;
+import androidx.core.content.res.ResourcesCompat;
 import androidx.drawerlayout.widget.DrawerLayout;
 import androidx.fragment.app.FragmentManager;
 import androidx.fragment.app.FragmentTransaction;
@@ -98,7 +100,6 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
         SyncedFolderPreferencesDialogFragment.OnSyncedFolderPreferenceListener, Injectable {
 
     private static final String[] PRIORITIZED_FOLDERS = new String[]{"Camera", "Screenshots"};
-    public static final String EXTRA_SHOW_SIDEBAR = "SHOW_SIDEBAR";
     private static final String SYNCED_FOLDER_PREFERENCES_DIALOG_TAG = "SYNCED_FOLDER_PREFERENCES_DIALOG";
     private static final String TAG = SyncedFoldersActivity.class.getSimpleName();
 
@@ -106,7 +107,6 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
     private SyncedFolderAdapter adapter;
     private SyncedFolderProvider syncedFolderProvider;
     private SyncedFolderPreferencesDialogFragment syncedFolderPreferencesDialogFragment;
-    private boolean showSidebar = true;
 
     private String path;
     private int type;
@@ -115,20 +115,10 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
     @Inject Clock clock;
     @Inject BackgroundJobManager backgroundJobManager;
 
-    public static void startActivityWithoutSidebar(Context context) {
-        Intent intent = new Intent(context, SyncedFoldersActivity.class);
-        intent.putExtra(EXTRA_SHOW_SIDEBAR, false);
-        context.startActivity(intent);
-    }
-
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
-        if (getIntent().getExtras() != null) {
-            showSidebar = getIntent().getExtras().getBoolean(EXTRA_SHOW_SIDEBAR);
-        }
-
         binding = SyncedFoldersLayoutBinding.inflate(getLayoutInflater());
         setContentView(binding.getRoot());
 
@@ -157,16 +147,15 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
         setupToolbar();
         updateActionBarTitleAndHomeButtonByString(getString(R.string.drawer_synced_folders));
 
-        if (!showSidebar) {
-            setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
+        setupDrawer();
+        setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
 
-            if (getSupportActionBar() != null) {
-                getSupportActionBar().setDisplayHomeAsUpEnabled(true);
-            }
+        if (getSupportActionBar() != null) {
+            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+        }
 
-            if (mDrawerToggle != null) {
-                mDrawerToggle.setDrawerIndicatorEnabled(false);
-            }
+        if (mDrawerToggle != null) {
+            mDrawerToggle.setDrawerIndicatorEnabled(false);
         }
 
         // TODO: The content loading should be done asynchronously
@@ -530,45 +519,32 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
         boolean result = true;
-        switch (item.getItemId()) {
-            case android.R.id.home: {
-                if (showSidebar) {
-                    if (isDrawerOpen()) {
-                        closeDrawer();
-                    } else {
-                        openDrawer();
-                    }
-                } else {
-                    Intent settingsIntent = new Intent(getApplicationContext(), SettingsActivity.class);
-                    startActivity(settingsIntent);
-                }
-                break;
-            }
-
-            case R.id.action_create_custom_folder: {
-                Log.d(TAG, "Show custom folder dialog");
-                SyncedFolderDisplayItem emptyCustomFolder = new SyncedFolderDisplayItem(
-                    SyncedFolder.UNPERSISTED_ID,
-                    null,
-                    null,
-                    true,
-                    false,
-                    true,
-                    false,
-                    getAccount().name,
-                    FileUploader.LOCAL_BEHAVIOUR_FORGET,
-                    FileUploader.NameCollisionPolicy.ASK_USER.serialize(),
-                    false,
-                    clock.getCurrentTime(),
-                    null,
-                    MediaFolderType.CUSTOM,
-                    false);
-                onSyncFolderSettingsClick(0, emptyCustomFolder);
-            }
+        int itemId = item.getItemId();
+        if (itemId == android.R.id.home) {
+            finish();
+        } else if (itemId == R.id.action_create_custom_folder) {
+            Log.d(TAG, "Show custom folder dialog");
+            SyncedFolderDisplayItem emptyCustomFolder = new SyncedFolderDisplayItem(
+                UNPERSISTED_ID,
+                null,
+                null,
+                true,
+                false,
+                true,
+                false,
+                getAccount().name,
+                FileUploader.LOCAL_BEHAVIOUR_FORGET,
+                FileUploader.NameCollisionPolicy.ASK_USER.serialize(),
+                false,
+                clock.getCurrentTime(),
+                null,
+                MediaFolderType.CUSTOM,
+                false);
+            onSyncFolderSettingsClick(0, emptyCustomFolder);
 
-            default:
-                result = super.onOptionsItemSelected(item);
-                break;
+            result = super.onOptionsItemSelected(item);
+        } else {
+            result = super.onOptionsItemSelected(item);
         }
 
         return result;