mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 21:55:48 +03:00
initial account chooser toggle and further abstraction of the drawer API for child classes
This commit is contained in:
parent
ce803aa4e0
commit
f82c4d96ba
4 changed files with 91 additions and 23 deletions
|
@ -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"
|
||||
|
|
|
@ -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,19 +150,47 @@ public abstract class DrawerActivity extends ToolbarActivity {
|
|||
* @return <code>true</code> if the drawer is open, else <code>false</code>
|
||||
*/
|
||||
public boolean isDrawerOpen() {
|
||||
return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(GravityCompat.START);
|
||||
}
|
||||
|
||||
/**
|
||||
* closes the drawer.
|
||||
*/
|
||||
public void closeDrawer() {
|
||||
if (mDrawerLayout != null) {
|
||||
return mDrawerLayout.isDrawerOpen(GravityCompat.START);
|
||||
} else {
|
||||
return false;
|
||||
mDrawerLayout.closeDrawer(GravityCompat.START);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* closes the navigation drawer.
|
||||
* opens the drawer.
|
||||
*/
|
||||
public void closeNavDrawer() {
|
||||
public void openDrawer() {
|
||||
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
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue