Browse Source

Fix Lint Missing Super Call due to new targetSDKVersion

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 year ago
parent
commit
7b13a87680

+ 12 - 7
app/src/main/java/com/owncloud/android/ui/activity/ContactsPreferenceActivity.java

@@ -36,6 +36,7 @@ import com.owncloud.android.ui.fragment.contactsbackup.BackupListFragment;
 
 import javax.inject.Inject;
 
+import androidx.activity.OnBackPressedCallback;
 import androidx.drawerlayout.widget.DrawerLayout;
 import androidx.fragment.app.FragmentManager;
 import androidx.fragment.app.FragmentTransaction;
@@ -115,6 +116,8 @@ public class ContactsPreferenceActivity extends FileActivity implements FileFrag
             }
             transaction.commit();
         }
+
+        getOnBackPressedDispatcher().addCallback(this, onBackPressedCallback);
     }
 
     @Override
@@ -137,12 +140,14 @@ public class ContactsPreferenceActivity extends FileActivity implements FileFrag
         // not needed
     }
 
-    @Override
-    public void onBackPressed() {
-        if (getSupportFragmentManager().findFragmentByTag(BackupListFragment.TAG) != null) {
-            getSupportFragmentManager().popBackStack(BACKUP_TO_LIST, FragmentManager.POP_BACK_STACK_INCLUSIVE);
-        } else {
-            finish();
+    private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(true) {
+        @Override
+        public void handleOnBackPressed() {
+            if (getSupportFragmentManager().findFragmentByTag(BackupListFragment.TAG) != null) {
+                getSupportFragmentManager().popBackStack(BACKUP_TO_LIST, FragmentManager.POP_BACK_STACK_INCLUSIVE);
+            } else {
+                finish();
+            }
         }
-    }
+    };
 }

+ 25 - 14
app/src/main/java/com/owncloud/android/ui/activity/FolderPickerActivity.kt

@@ -32,6 +32,7 @@ import android.view.ActionMode
 import android.view.Menu
 import android.view.MenuItem
 import android.view.View
+import androidx.activity.OnBackPressedCallback
 import androidx.localbroadcastmanager.content.LocalBroadcastManager
 import com.google.android.material.button.MaterialButton
 import com.nextcloud.client.di.Injectable
@@ -125,9 +126,33 @@ open class FolderPickerActivity :
 
         // sets message for empty list of folders
         setBackgroundText()
+
+        handleOnBackPressed()
+
         Log_OC.d(TAG, "onCreate() end")
     }
 
+    private fun handleOnBackPressed() {
+        onBackPressedDispatcher.addCallback(
+            this,
+            object : OnBackPressedCallback(true) {
+                override fun handleOnBackPressed() {
+                    val listOfFiles = listOfFilesFragment
+                    if (listOfFiles != null) {
+                        // should never be null, indeed
+                        val levelsUp = listOfFiles.onBrowseUp()
+                        if (levelsUp == 0) {
+                            finish()
+                            return
+                        }
+                        file = listOfFiles.currentFile
+                        updateUiElements()
+                    }
+                }
+            }
+        )
+    }
+
     override fun onActionModeStarted(mode: ActionMode) {
         super.onActionModeStarted(mode)
         if (account != null) {
@@ -321,20 +346,6 @@ open class FolderPickerActivity :
         }
     }
 
-    override fun onBackPressed() {
-        val listOfFiles = listOfFilesFragment
-        if (listOfFiles != null) {
-            // should never be null, indeed
-            val levelsUp = listOfFiles.onBrowseUp()
-            if (levelsUp == 0) {
-                finish()
-                return
-            }
-            file = listOfFiles.currentFile
-            updateUiElements()
-        }
-    }
-
     private fun updateUiElements() {
         toggleChooseEnabled()
         updateNavigationElementsInActionBar()

+ 35 - 30
app/src/main/java/com/owncloud/android/ui/activity/UploadFilesActivity.java

@@ -61,6 +61,7 @@ import java.util.List;
 
 import javax.inject.Inject;
 
+import androidx.activity.OnBackPressedCallback;
 import androidx.annotation.NonNull;
 import androidx.annotation.VisibleForTesting;
 import androidx.appcompat.app.ActionBar;
@@ -258,6 +259,8 @@ public class UploadFilesActivity extends DrawerActivity implements LocalFileList
 
         checkWritableFolder(mCurrentDir);
 
+        getOnBackPressedDispatcher().addCallback(this, onBackPressedCallback);
+
         Log_OC.d(TAG, "onCreate() end");
     }
 
@@ -369,43 +372,45 @@ public class UploadFilesActivity extends DrawerActivity implements LocalFileList
         }
     }
 
-    @Override
-    public void onBackPressed() {
-        if (isSearchOpen() && mSearchView != null) {
-            mSearchView.setQuery("", false);
-            mFileListFragment.onClose();
-            mSearchView.onActionViewCollapsed();
-            setDrawerIndicatorEnabled(isDrawerIndicatorAvailable());
-        } else {
-            if (mDirectories.getCount() <= SINGLE_DIR) {
-                finish();
-                return;
-            }
+    private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(true) {
+        @Override
+        public void handleOnBackPressed() {
+            if (isSearchOpen() && mSearchView != null) {
+                mSearchView.setQuery("", false);
+                mFileListFragment.onClose();
+                mSearchView.onActionViewCollapsed();
+                setDrawerIndicatorEnabled(isDrawerIndicatorAvailable());
+            } else {
+                if (mDirectories.getCount() <= SINGLE_DIR) {
+                    finish();
+                    return;
+                }
 
-            File parentFolder = mCurrentDir.getParentFile();
-            if (!parentFolder.canRead()) {
-                checkLocalStoragePathPickerPermission();
-                return;
-            }
+                File parentFolder = mCurrentDir.getParentFile();
+                if (!parentFolder.canRead()) {
+                    checkLocalStoragePathPickerPermission();
+                    return;
+                }
 
-            popDirname();
-            mFileListFragment.onNavigateUp();
-            mCurrentDir = mFileListFragment.getCurrentDirectory();
-            checkWritableFolder(mCurrentDir);
+                popDirname();
+                mFileListFragment.onNavigateUp();
+                mCurrentDir = mFileListFragment.getCurrentDirectory();
+                checkWritableFolder(mCurrentDir);
 
-            if (mCurrentDir.getParentFile() == null) {
-                ActionBar actionBar = getSupportActionBar();
-                if (actionBar != null) {
-                    actionBar.setDisplayHomeAsUpEnabled(false);
+                if (mCurrentDir.getParentFile() == null) {
+                    ActionBar actionBar = getSupportActionBar();
+                    if (actionBar != null) {
+                        actionBar.setDisplayHomeAsUpEnabled(false);
+                    }
                 }
-            }
 
-            // invalidate checked state when navigating directories
-            if (!mLocalFolderPickerMode) {
-                setSelectAllMenuItem(mOptionsMenu.findItem(R.id.action_select_all), false);
+                // invalidate checked state when navigating directories
+                if (!mLocalFolderPickerMode) {
+                    setSelectAllMenuItem(mOptionsMenu.findItem(R.id.action_select_all), false);
+                }
             }
         }
-    }
+    };
 
     @Override
     protected void onSaveInstanceState(@NonNull Bundle outState) {