Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stefan-niedermann/nextcloud-notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Niedermann <info@niedermann.it>2021-06-11 14:43:49 +0300
committerStefan Niedermann <info@niedermann.it>2021-06-11 14:43:49 +0300
commitafee96970d6d71802e27702191faf79ad9d688eb (patch)
tree780c95a29e902ebb54e1fd726a4a9b032213513a
parent6515ae484760b0fd0a0fbbdbc5708f7c8cc9e89a (diff)
parentb3afddeaaa048d9cd871bc2e1365ea2577d6ca2a (diff)
Merge branch 'open-trashbin-in-files-app'
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java2
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/main/menu/MenuAdapter.java43
2 files changed, 40 insertions, 5 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java
index 5edb0482..49f4a3e7 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java
@@ -332,7 +332,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
binding.navigationMenu.setAdapter(menuAdapter);
} else {
- menuAdapter.updateAccount(nextAccount);
+ menuAdapter.updateAccount(this, nextAccount);
}
});
}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/menu/MenuAdapter.java b/app/src/main/java/it/niedermann/owncloud/notes/main/menu/MenuAdapter.java
index cbcc6306..24c1a44e 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/main/menu/MenuAdapter.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/main/menu/MenuAdapter.java
@@ -2,6 +2,7 @@ package it.niedermann.owncloud.notes.main.menu;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.PackageManager;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.ViewGroup;
@@ -10,6 +11,9 @@ import androidx.annotation.NonNull;
import androidx.core.util.Consumer;
import androidx.recyclerview.widget.RecyclerView;
+import com.nextcloud.android.sso.Constants;
+import com.nextcloud.android.sso.helper.VersionCheckHelper;
+
import it.niedermann.owncloud.notes.FormattingHelpActivity;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.about.AboutActivity;
@@ -27,7 +31,7 @@ public class MenuAdapter extends RecyclerView.Adapter<MenuViewHolder> {
public MenuAdapter(@NonNull Context context, @NonNull Account account, int settingsRequestCode, @NonNull Consumer<MenuItem> onClick) {
this.menuItems = new MenuItem[]{
new MenuItem(new Intent(context, FormattingHelpActivity.class), R.string.action_formatting_help, R.drawable.ic_baseline_help_outline_24),
- new MenuItem(generateTrashbinIntent(account), R.string.action_trashbin, R.drawable.ic_delete_grey600_24dp),
+ new MenuItem(generateTrashbinIntent(context, account), R.string.action_trashbin, R.drawable.ic_delete_grey600_24dp),
new MenuItem(new Intent(context, PreferencesActivity.class), settingsRequestCode, R.string.action_settings, R.drawable.ic_settings_grey600_24dp),
new MenuItem(new Intent(context, AboutActivity.class), R.string.simple_about, R.drawable.ic_info_outline_grey600_24dp)
};
@@ -51,8 +55,8 @@ public class MenuAdapter extends RecyclerView.Adapter<MenuViewHolder> {
holder.bind(menuItems[position], onClick);
}
- public void updateAccount(@NonNull Account account) {
- menuItems[1].setIntent(new Intent(generateTrashbinIntent(account)));
+ public void updateAccount(@NonNull Context context, @NonNull Account account) {
+ menuItems[1].setIntent(new Intent(generateTrashbinIntent(context, account)));
}
@Override
@@ -61,7 +65,38 @@ public class MenuAdapter extends RecyclerView.Adapter<MenuViewHolder> {
}
@NonNull
- private static Intent generateTrashbinIntent(@NonNull Account account) {
+ private static Intent generateTrashbinIntent(@NonNull Context context, @NonNull Account account) {
+ // https://github.com/nextcloud/android/pull/8405#issuecomment-852966877
+ final int minVersionCode = 30170090;
+ try {
+ if (VersionCheckHelper.getNextcloudFilesVersionCode(context, true) > minVersionCode) {
+ return generateTrashbinAppIntent(context, account, true);
+ } else if (VersionCheckHelper.getNextcloudFilesVersionCode(context, false) > minVersionCode) {
+ return generateTrashbinAppIntent(context, account, false);
+ } else {
+ // Files app is too old to be able to switch the account when launching the TrashbinActivity
+ return generateTrashbinWebIntent(account);
+ }
+ } catch (PackageManager.NameNotFoundException | SecurityException e) {
+ e.printStackTrace();
+ return generateTrashbinWebIntent(account);
+ }
+ }
+
+ private static Intent generateTrashbinAppIntent(@NonNull Context context, @NonNull Account account, boolean prod) throws PackageManager.NameNotFoundException {
+ final PackageManager packageManager = context.getPackageManager();
+ final String packageName = prod ? Constants.PACKAGE_NAME_PROD : Constants.PACKAGE_NAME_DEV;
+ final Intent intent = new Intent();
+ intent.setClassName(packageName, "com.owncloud.android.ui.trashbin.TrashbinActivity");
+ if (packageManager.resolveActivity(intent, 0) != null) {
+ return intent
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ .putExtra(Intent.EXTRA_USER, account.getAccountName());
+ }
+ throw new PackageManager.NameNotFoundException("Could not resolve target activity.");
+ }
+
+ private static Intent generateTrashbinWebIntent(@NonNull Account account) {
return new Intent(Intent.ACTION_VIEW, Uri.parse(account.getUrl() + "/index.php/apps/files/?dir=/&view=trashbin"));
}
}