Procházet zdrojové kódy

Implemented "Switch to account" feature in Accounts list

Signed-off-by: Kilian Périsset <kilian.perisset@infomaniak.com>
Kilian Périsset před 4 roky
rodič
revize
8081bf7d06

+ 16 - 9
src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java

@@ -38,7 +38,6 @@ import android.os.Handler;
 import android.os.IBinder;
 import android.view.MenuItem;
 import android.view.View;
-import android.widget.ImageView;
 
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.UserAccountManager;
@@ -485,19 +484,27 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap
     @Override
     public void onOptionItemClicked(User user, View view) {
         if (view.getId() == R.id.account_menu) {
-            ImageView menuButton = findViewById(R.id.account_menu);
-
-            PopupMenu popup = new PopupMenu(view.getContext(), menuButton);
+            PopupMenu popup = new PopupMenu(this, view);
             popup.getMenuInflater().inflate(R.menu.item_account, popup.getMenu());
-            popup.show();
+
+            if((accountManager.getUser()).equals(user)) {
+                popup.getMenu().findItem(R.id.action_open_account).setVisible(false);
+            }
             popup.setOnMenuItemClickListener(item -> {
-                if (item.getItemId() == R.id.action_delete_account) {
-                    openAccountRemovalConfirmationDialog(user, getSupportFragmentManager());
-                } else {
-                    openAccount(user);
+                switch (item.getItemId()) {
+                    case R.id.action_open_account:
+                        accountClicked(user.hashCode());
+                        break;
+                    case R.id.action_delete_account:
+                        openAccountRemovalConfirmationDialog(user, getSupportFragmentManager());
+                        break;
+                    default:
+                        openAccount(user);
+                        break;
                 }
                 return true;
             });
+            popup.show();
         } else {
             openAccount(user);
         }

+ 13 - 2
src/main/java/com/owncloud/android/ui/activity/UserInfoActivity.java

@@ -165,10 +165,18 @@ public class UserInfoActivity extends FileActivity implements Injectable {
         setHeaderImage();
     }
 
+    @Override
+    public boolean onPrepareOptionsMenu(Menu menu) {
+        if ((accountManager.getUser()).equals(user)) {
+            menu.findItem(R.id.action_open_account).setVisible(false);
+        }
+        return super.onPrepareOptionsMenu(menu);
+    }
+
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
         MenuInflater inflater = getMenuInflater();
-        inflater.inflate(R.menu.activity_user_info, menu);
+        inflater.inflate(R.menu.item_account, menu);
 
         return true;
     }
@@ -180,7 +188,10 @@ public class UserInfoActivity extends FileActivity implements Injectable {
             case android.R.id.home:
                 onBackPressed();
                 break;
-            case R.id.delete_account:
+            case R.id.action_open_account:
+                accountClicked(user.hashCode());
+                break;
+            case R.id.action_delete_account:
                 openAccountRemovalConfirmationDialog(user, getSupportFragmentManager());
                 break;
             default:

+ 0 - 28
src/main/res/menu/activity_user_info.xml

@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  Nextcloud Android client application
-
-  Copyright (C) 2017-2018 Andy Scherzinger
-  Copyright (C) 2017-2018 Nextcloud
-
-  This program is free software; you can redistribute it and/or
-  modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-  License as published by the Free Software Foundation; either
-  version 3 of the License, or any later version.
-
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-  GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-
-  You should have received a copy of the GNU Affero General Public
-  License along with this program.  If not, see <http://www.gnu.org/licenses/>.
--->
-<menu xmlns:android="http://schemas.android.com/apk/res/android">
-
-    <item
-        android:id="@+id/delete_account"
-        android:title="@string/delete_account">
-    </item>
-
-</menu>

+ 1 - 1
src/main/res/menu/item_account.xml

@@ -26,7 +26,7 @@
 
     <item
         android:id="@+id/action_open_account"
-        android:title="@string/view_profile"
+        android:title="@string/common_switch_to_account"
         app:showAsAction="never"
         android:showAsAction="never" />
 

+ 2 - 1
src/main/res/values/strings.xml

@@ -184,7 +184,8 @@
     <string name="downloader_not_downloaded_yet">Not downloaded yet</string>
     <string name="downloader_download_failed_credentials_error">Download failed, log in again</string>
     <string name="common_choose_account">Choose account</string>
-    <string name="common_switch_account">Switch Account</string>
+    <string name="common_switch_account">Switch account</string>
+    <string name="common_switch_to_account">Switch to account</string>
     <string name="sync_fail_ticker">Sync failed</string>
     <string name="sync_fail_ticker_unauthorized">Sync failed, log in again</string>
     <string name="sync_fail_content">Could not sync %1$s</string>