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

This commit is contained in:
Andy Scherzinger 2016-03-23 20:56:22 +01:00
parent ce803aa4e0
commit f82c4d96ba
4 changed files with 91 additions and 23 deletions

View file

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

View file

@ -1,20 +1,18 @@
package com.owncloud.android.ui.activity; package com.owncloud.android.ui.activity;
import android.accounts.Account;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.NavigationView; import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat; import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.ActionBarDrawerToggle;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.owncloud.android.R; import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.datamodel.OCFile;
/** /**
@ -22,8 +20,11 @@ import com.owncloud.android.datamodel.OCFile;
*/ */
public abstract class DrawerActivity extends ToolbarActivity { public abstract class DrawerActivity extends ToolbarActivity {
// Navigation Drawer // Navigation Drawer
protected DrawerLayout mDrawerLayout; private DrawerLayout mDrawerLayout;
protected ActionBarDrawerToggle mDrawerToggle; 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. * 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); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
if (navigationView != null) { if (navigationView != null) {
setupDrawerContent(navigationView); 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 // TODO re-enable when "Accounts" is available in Navigation Drawer
@ -138,19 +150,47 @@ public abstract class DrawerActivity extends ToolbarActivity {
* @return <code>true</code> if the drawer is open, else <code>false</code> * @return <code>true</code> if the drawer is open, else <code>false</code>
*/ */
public boolean isDrawerOpen() { public boolean isDrawerOpen() {
if(mDrawerLayout != null) { return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(GravityCompat.START);
return mDrawerLayout.isDrawerOpen(GravityCompat.START); }
} else {
return false; /**
* closes the drawer.
*/
public void closeDrawer() {
if (mDrawerLayout != null) {
mDrawerLayout.closeDrawer(GravityCompat.START);
} }
} }
/** /**
* closes the navigation drawer. * opens the drawer.
*/ */
public void closeNavDrawer() { public void openDrawer() {
if(mDrawerLayout != null) { if (mDrawerLayout != null) {
mDrawerLayout.closeDrawer(GravityCompat.START); 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);
} }
} }
@ -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 @Override
protected void onPostCreate(Bundle savedInstanceState) { protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState); super.onPostCreate(savedInstanceState);
@ -213,9 +268,19 @@ public abstract class DrawerActivity extends ToolbarActivity {
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if (isDrawerOpen()) { if (isDrawerOpen()) {
closeNavDrawer(); closeDrawer();
return; return;
} }
super.onBackPressed(); 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);
}
} }

View file

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

View file

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