Эх сурвалжийг харах

initial account chooser toggle and further abstraction of the drawer API for child classes

Andy Scherzinger 9 жил өмнө
parent
commit
f82c4d96ba

+ 2 - 1
res/layout/drawer_header.xml

@@ -24,6 +24,7 @@
               android:background="@color/drawer_header_color">
 
     <LinearLayout
+        android:id="@+id/drawer_active_user"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_gravity="bottom"
@@ -79,7 +80,7 @@
         </LinearLayout>
 
         <ImageView
-            android:id="@+id/drawer_manage_accounts"
+            android:id="@+id/drawer_account_chooser_toogle"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:contentDescription="@string/drawer_manage_accounts"

+ 80 - 15
src/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -1,20 +1,18 @@
 package com.owncloud.android.ui.activity;
 
-import android.accounts.Account;
 import android.content.Intent;
 import android.content.res.Configuration;
 import android.os.Bundle;
 import android.support.design.widget.NavigationView;
 import android.support.v4.view.GravityCompat;
 import android.support.v4.widget.DrawerLayout;
-import android.support.v7.app.ActionBar;
 import android.support.v7.app.ActionBarDrawerToggle;
 import android.view.MenuItem;
 import android.view.View;
+import android.widget.ImageView;
 import android.widget.TextView;
 
 import com.owncloud.android.R;
-import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 
 /**
@@ -22,8 +20,11 @@ import com.owncloud.android.datamodel.OCFile;
  */
 public abstract class DrawerActivity extends ToolbarActivity {
     // Navigation Drawer
-    protected DrawerLayout mDrawerLayout;
-    protected ActionBarDrawerToggle mDrawerToggle;
+    private DrawerLayout mDrawerLayout;
+    private ActionBarDrawerToggle mDrawerToggle;
+    private ImageView mAccountChooserToggle;
+
+    private boolean mIsAccountChooserActive;
 
     /**
      * Initializes the drawer and its content. This method needs to be called after the content view has been set.
@@ -34,6 +35,17 @@ public abstract class DrawerActivity extends ToolbarActivity {
         NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
         if (navigationView != null) {
             setupDrawerContent(navigationView);
+            mAccountChooserToggle = (ImageView) findNavigationViewChildById(R.id.drawer_account_chooser_toogle);
+            mAccountChooserToggle.setImageResource(R.drawable.ic_down);
+            mIsAccountChooserActive = false;
+
+            findNavigationViewChildById(R.id.drawer_active_user)
+                    .setOnClickListener(new View.OnClickListener() {
+                        @Override
+                        public void onClick(View v) {
+                            toggleAccountList();
+                        }
+                    });
         }
 
         // TODO re-enable when "Accounts" is available in Navigation Drawer
@@ -138,22 +150,50 @@ public abstract class DrawerActivity extends ToolbarActivity {
      * @return <code>true</code> if the drawer is open, else <code>false</code>
      */
     public boolean isDrawerOpen() {
-        if(mDrawerLayout != null) {
-            return mDrawerLayout.isDrawerOpen(GravityCompat.START);
-        } else {
-            return false;
-        }
+        return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(GravityCompat.START);
     }
 
     /**
-     * closes the navigation drawer.
+     * closes the drawer.
      */
-    public void closeNavDrawer() {
-        if(mDrawerLayout != null) {
+    public void closeDrawer() {
+        if (mDrawerLayout != null) {
             mDrawerLayout.closeDrawer(GravityCompat.START);
         }
     }
 
+    /**
+     * opens the drawer.
+     */
+    public void openDrawer() {
+        if (mDrawerLayout != null) {
+            mDrawerLayout.openDrawer(GravityCompat.START);
+        }
+    }
+
+    /**
+     * Enable or disable interaction with all drawers.
+     *
+     * @param lockMode The new lock mode for the given drawer. One of {@link DrawerLayout#LOCK_MODE_UNLOCKED},
+     *                 {@link DrawerLayout#LOCK_MODE_LOCKED_CLOSED} or {@link DrawerLayout#LOCK_MODE_LOCKED_OPEN}.
+     */
+    public void setDrawerLockMode(int lockMode) {
+        if (mDrawerLayout != null) {
+            mDrawerLayout.setDrawerLockMode(lockMode);
+        }
+    }
+
+    /**
+     * Enable or disable the drawer indicator.
+     *
+     * @param enable <code>true</code> to enable, <code>false</code> to disable
+     */
+    public void setDrawerIndicatorEnabled(boolean enable) {
+        if (mDrawerToggle != null) {
+            mDrawerToggle.setDrawerIndicatorEnabled(enable);
+        }
+    }
+
     /**
      * Method that gets called on drawer menu click for 'All Files'.
      */
@@ -175,7 +215,7 @@ public abstract class DrawerActivity extends ToolbarActivity {
      * sets the given account name in the drawer in case the drawer is available. The account name is shortened
      * beginning from the @-sign in the username.
      *
-     * @param accountName            the account to be set in the drawer
+     * @param accountName the account to be set in the drawer
      */
     protected void setUsernameInDrawer(String accountName) {
         if (mDrawerLayout != null && accountName != null) {
@@ -189,6 +229,21 @@ public abstract class DrawerActivity extends ToolbarActivity {
         }
     }
 
+    /**
+     * Toggle between drawer menu and account list.
+     */
+    private void toggleAccountList() {
+        if (mIsAccountChooserActive) {
+            // TODO close accounts list and display drawer menu again
+            mAccountChooserToggle.setImageResource(R.drawable.ic_down);
+        } else {
+            // TODO show accounts list
+            mAccountChooserToggle.setImageResource(R.drawable.ic_up);
+        }
+
+        mIsAccountChooserActive = !mIsAccountChooserActive;
+    }
+
     @Override
     protected void onPostCreate(Bundle savedInstanceState) {
         super.onPostCreate(savedInstanceState);
@@ -213,9 +268,19 @@ public abstract class DrawerActivity extends ToolbarActivity {
     @Override
     public void onBackPressed() {
         if (isDrawerOpen()) {
-            closeNavDrawer();
+            closeDrawer();
             return;
         }
         super.onBackPressed();
     }
+
+    /**
+     * Finds a view that was identified by the id attribute from the drawer header.
+     *
+     * @param id the view's id
+     * @return The view if found or <code>null</code> otherwise.
+     */
+    private View findNavigationViewChildById(int id) {
+        return ((NavigationView) findViewById(R.id.nav_view)).getHeaderView(0).findViewById(id);
+    }
 }

+ 2 - 0
src/com/owncloud/android/ui/activity/FileActivity.java

@@ -838,6 +838,7 @@ public class FileActivity extends DrawerActivity
 
                 case 0: // All Files
                     allFilesOption();
+                    //mDrawerLayout.closeDrawers();
                     break;
 
                 // TODO Enable when "On Device" is recovered ?
@@ -856,6 +857,7 @@ public class FileActivity extends DrawerActivity
                     Intent settingsIntent = new Intent(getApplicationContext(),
                             Preferences.class);
                     startActivity(settingsIntent);
+                    //mDrawerLayout.closeDrawers();
                     break;
             }
             mDrawerLayout.closeDrawers();

+ 7 - 7
src/com/owncloud/android/ui/preview/PreviewImageActivity.java

@@ -120,10 +120,10 @@ public class PreviewImageActivity extends FileActivity implements
                     ActionBar actionBar = getSupportActionBar();
                     if (visible) {
                         actionBar.show();
-                        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
+                        setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
                     } else {
                         actionBar.hide();
-                        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
+                        setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
                     }
                 }
             });
@@ -304,8 +304,8 @@ public class PreviewImageActivity extends FileActivity implements
         
         switch(item.getItemId()){
         case android.R.id.home:
-            if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
-                mDrawerLayout.closeDrawer(GravityCompat.START);
+            if (isDrawerOpen()) {
+                closeDrawer();
             } else {
                 backToDisplayActivity();
             }
@@ -391,7 +391,7 @@ public class PreviewImageActivity extends FileActivity implements
         } else {
             OCFile currentFile = mPreviewImagePagerAdapter.getFileAt(position); 
             getSupportActionBar().setTitle(currentFile.getFileName());
-            mDrawerToggle.setDrawerIndicatorEnabled(false);
+            setDrawerIndicatorEnabled(false);
             if (!currentFile.isDown()) {
                 if (!mPreviewImagePagerAdapter.pendingErrorAt(position)) {
                     requestForDownload(currentFile);
@@ -496,11 +496,11 @@ public class PreviewImageActivity extends FileActivity implements
             ActionBar actionBar = getSupportActionBar();
             if (!actionBar.isShowing()) {
                 actionBar.show();
-                mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
+                setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
 
             } else {
                 actionBar.hide();
-                mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
+                setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
 
             }