Browse Source

Merge pull request #432 from fi3te/master

Navigation drawer: lag on older devices
Andy Scherzinger 8 năm trước cách đây
mục cha
commit
82b522ebb0
1 tập tin đã thay đổi với 66 bổ sung47 xóa
  1. 66 47
      src/com/owncloud/android/ui/activity/DrawerActivity.java

+ 66 - 47
src/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -30,6 +30,7 @@ import android.content.res.Configuration;
 import android.graphics.drawable.Drawable;
 import android.os.Build;
 import android.os.Bundle;
+import android.os.Handler;
 import android.support.design.widget.NavigationView;
 import android.support.v4.view.GravityCompat;
 import android.support.v4.widget.DrawerLayout;
@@ -141,6 +142,11 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
      */
     private TextView mQuotaTextView;
 
+    /**
+     * runnable that will be executed after the drawer has been closed.
+     */
+    private Runnable pendingRunnable;
+
     /**
      * Initializes the drawer, its content and highlights the menu item with the given id.
      * This method needs to be called after the content view has been set.
@@ -192,6 +198,11 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
                     toggleAccountList();
                 }
                 invalidateOptionsMenu();
+
+                if (pendingRunnable != null) {
+                    new Handler().post(pendingRunnable);
+                    pendingRunnable = null;
+                }
             }
 
             /** Called when a drawer has settled in a completely open state. */
@@ -252,54 +263,15 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
         navigationView.setNavigationItemSelectedListener(
                 new NavigationView.OnNavigationItemSelectedListener() {
                     @Override
-                    public boolean onNavigationItemSelected(MenuItem menuItem) {
+                    public boolean onNavigationItemSelected(final MenuItem menuItem) {
                         mDrawerLayout.closeDrawers();
-
-                        switch (menuItem.getItemId()) {
-                            case R.id.nav_all_files:
-                                menuItem.setChecked(true);
-                                mCheckedMenuItem = menuItem.getItemId();
-                                showFiles(false);
-                                break;
-                             case R.id.nav_on_device:
-                                 menuItem.setChecked(true);
-                                 mCheckedMenuItem = menuItem.getItemId();
-                                 showFiles(true);
-                                 break;
-                            case R.id.nav_uploads:
-                                Intent uploadListIntent = new Intent(getApplicationContext(),
-                                        UploadListActivity.class);
-                                uploadListIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
-                                startActivity(uploadListIntent);
-                                break;
-                            case R.id.nav_folder_sync:
-                                Intent folderSyncIntent = new Intent(getApplicationContext(),FolderSyncActivity.class);
-                                startActivity(folderSyncIntent);
-                                break;
-                            case R.id.nav_settings:
-                                Intent settingsIntent = new Intent(getApplicationContext(), Preferences.class);
-                                startActivity(settingsIntent);
-                                break;
-                            case R.id.nav_participate:
-                                Intent participateIntent = new Intent(getApplicationContext(),
-                                        ParticipateActivity.class);
-                                startActivity(participateIntent);
-                                break;
-                            case R.id.drawer_menu_account_add:
-                                createAccount(false);
-                                break;
-                            case R.id.drawer_menu_account_manage:
-                                Intent manageAccountsIntent = new Intent(getApplicationContext(),
-                                        ManageAccountsActivity.class);
-                                startActivityForResult(manageAccountsIntent, ACTION_MANAGE_ACCOUNTS);
-                                break;
-                            case Menu.NONE:
-                                // account clicked
-                                accountClicked(menuItem.getTitle().toString());
-                            default:
-                                Log_OC.i(TAG, "Unknown drawer menu item clicked: " + menuItem.getTitle());
-                        }
-
+                        // pending runnable will be executed after the drawer has been closed
+                        pendingRunnable = new Runnable() {
+                            @Override
+                            public void run() {
+                                selectNavigationItem(menuItem);
+                            }
+                        };
                         return true;
                     }
                 });
@@ -312,6 +284,53 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
         }
     }
 
+    private void selectNavigationItem(final MenuItem menuItem) {
+        switch (menuItem.getItemId()) {
+            case R.id.nav_all_files:
+                menuItem.setChecked(true);
+                mCheckedMenuItem = menuItem.getItemId();
+                showFiles(false);
+                break;
+            case R.id.nav_on_device:
+                menuItem.setChecked(true);
+                mCheckedMenuItem = menuItem.getItemId();
+                showFiles(true);
+                break;
+            case R.id.nav_uploads:
+                Intent uploadListIntent = new Intent(getApplicationContext(),
+                        UploadListActivity.class);
+                uploadListIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+                startActivity(uploadListIntent);
+                break;
+            case R.id.nav_folder_sync:
+                Intent folderSyncIntent = new Intent(getApplicationContext(),FolderSyncActivity.class);
+                startActivity(folderSyncIntent);
+                break;
+            case R.id.nav_settings:
+                Intent settingsIntent = new Intent(getApplicationContext(), Preferences.class);
+                startActivity(settingsIntent);
+                break;
+            case R.id.nav_participate:
+                Intent participateIntent = new Intent(getApplicationContext(),
+                        ParticipateActivity.class);
+                startActivity(participateIntent);
+                break;
+            case R.id.drawer_menu_account_add:
+                createAccount(false);
+                break;
+            case R.id.drawer_menu_account_manage:
+                Intent manageAccountsIntent = new Intent(getApplicationContext(),
+                        ManageAccountsActivity.class);
+                startActivityForResult(manageAccountsIntent, ACTION_MANAGE_ACCOUNTS);
+                break;
+            case Menu.NONE:
+                // account clicked
+                accountClicked(menuItem.getTitle().toString());
+            default:
+                Log_OC.i(TAG, "Unknown drawer menu item clicked: " + menuItem.getTitle());
+        }
+    }
+
     /**
      * show the file list to the user.
      *