import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
+import android.widget.ImageButton;
+import android.widget.TextView;
import android.widget.Toast;
+import android.widget.ViewSwitcher;
import com.crashlytics.android.Crashlytics;
private DrawerLayout mRightDrawerLayout;
private FrameLayout mLeftDrawerMenu;
private ActionBarDrawerToggle mLeftDrawerToggle;
+ private ViewSwitcher mNavigationDrawerAccountViewSwitcher;
+ private View mNavigationDrawerFilterContainer;
+
+ private boolean mSouldOpenDrawerOnRestore = false;
private ActionMode mActionMode; // The actionMode used when dossiers are checked
// <editor-fold desc="LifeCycle">
mLeftDrawerLayout.addDrawerListener(mLeftDrawerToggle);
mRightDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
+ mNavigationDrawerAccountViewSwitcher = (ViewSwitcher) findViewById(R.id.navigation_drawer_viewswitcher);
+ mNavigationDrawerFilterContainer = findViewById(R.id.navigation_drawer_filters_menu_header_filters_container);
+ ImageButton drawerAccountImageButton = (ImageButton) findViewById(R.id.navigation_drawer_menu_header_account_button);
+ if (drawerAccountImageButton != null) {
+ drawerAccountImageButton.setOnClickListener(new View.OnClickListener() {
+ @Override public void onClick(View v) {
+
+ if (mNavigationDrawerAccountViewSwitcher == null)
+ return;
+
+ boolean switchToAccountView = (mNavigationDrawerAccountViewSwitcher.getDisplayedChild() == 0);
+ if (switchToAccountView)
+ mNavigationDrawerAccountViewSwitcher.showNext();
+ else
+ mNavigationDrawerAccountViewSwitcher.showPrevious();
+
+ if (mNavigationDrawerFilterContainer != null)
+ mNavigationDrawerFilterContainer.setVisibility(switchToAccountView ? View.INVISIBLE : View.VISIBLE);
+ }
+ });
+ }
+
// ContentView Fragment restore
Fragment contentFragment = getFragmentManager().findFragmentByTag(DossierDetailFragment.FRAGMENT_TAG);
FragmentTransaction contentTransaction = getFragmentManager().beginTransaction();
contentTransaction.replace(R.id.dossier_detail_layout, contentFragment, DossierDetailFragment.FRAGMENT_TAG);
contentTransaction.commit();
-
- // Menu Fragment restore
-
}
@Override protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mLeftDrawerToggle.syncState();
+ refreshNavigationDrawerHeader();
}
@Override protected void onStart() {
boolean isDrawerKnown = settings.getBoolean(SHARED_PREFERENCES_IS_DRAWER_KNOWN, false);
boolean isDeviceInPortrait = (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);
- if ((!isDrawerKnown) && isDeviceInPortrait) {
-
+ if (!isDrawerKnown) {
mLeftDrawerLayout.openDrawer(mLeftDrawerMenu);
// Registering the fact that the user knows the drawer
-
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean(SHARED_PREFERENCES_IS_DRAWER_KNOWN, true);
editor.apply();
}
+ else if (mSouldOpenDrawerOnRestore) {
+
+ mSouldOpenDrawerOnRestore = false;
+ mLeftDrawerLayout.openDrawer(mLeftDrawerMenu);
+
+ if (isDeviceInPortrait)
+ if (mNavigationDrawerAccountViewSwitcher != null)
+ mNavigationDrawerAccountViewSwitcher.showNext();
+ }
+ else {
+ mLeftDrawerLayout.closeDrawer(mLeftDrawerMenu);
+ }
// Restoring proper Drawer state on selected dossiers
@Override protected void onPause() {
super.onPause();
+ boolean isDrawerOpened = mLeftDrawerLayout.isDrawerOpen(mLeftDrawerMenu);
+ boolean isAccountViewSelected = (mNavigationDrawerAccountViewSwitcher != null) && (mNavigationDrawerAccountViewSwitcher.getDisplayedChild() == 1);
+ mSouldOpenDrawerOnRestore = (isDrawerOpened && isAccountViewSelected);
+
// Save accounts state for later use. In our case, the latest selected account
// will be automatically selected if the application is killed and relaunched.
MyAccounts.INSTANCE.saveState();
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
- // First, try to pop backStack (and open the drawer to show it)
+ // Drawer account back
+
+ if (mNavigationDrawerAccountViewSwitcher.getDisplayedChild() == 1) {
+ mNavigationDrawerAccountViewSwitcher.showPrevious();
+ return;
+ }
+
+ // Menu back
MenuFragment bureauxFragment = (MenuFragment) getFragmentManager().findFragmentByTag(MenuFragment.FRAGMENT_TAG);
if (bureauxFragment != null) {
// </editor-fold desc="ActionMode">
+ private void refreshNavigationDrawerHeader() {
+
+ Account account = MyAccounts.INSTANCE.getSelectedAccount();
+
+ TextView navigationDrawerAccountTitle = (TextView) findViewById(R.id.navigation_drawer_menu_header_title);
+ TextView navigationDrawerAccountSubTitle = (TextView) findViewById(R.id.navigation_drawer_menu_header_subtitle);
+
+ if (navigationDrawerAccountTitle != null)
+ navigationDrawerAccountTitle.setText(account.getTitle());
+
+ if (navigationDrawerAccountSubTitle != null)
+ navigationDrawerAccountSubTitle.setText(account.getLogin());
+
+ }
+
private void importCertificate(@NonNull final String url, @Nullable final String password) {
String certificateFileName = url.substring(url.lastIndexOf('/') + 1);
@Override public void onAccountSelected(@NonNull Account account) {
MyAccounts.INSTANCE.selectAccount(account.getId());
+ refreshNavigationDrawerHeader();
// Close the drawer
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
-import android.util.Log;
import android.util.SparseArray;
import android.view.Menu;
import android.view.MenuInflater;
public void update(@Nullable Dossier dossier, @NonNull String bureauId, @Nullable String documentId) {
- Log.w("Adrien", "update : " + dossier + " " + documentId);
-
mBureauId = bureauId;
mDossier = dossier;
mDocumentId = documentId;
-<ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:baselineAligned="false"
- android:orientation="vertical">
+<ViewSwitcher android:id="@+id/navigation_drawer_viewswitcher"
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:baselineAligned="false"
+ android:orientation="vertical">
<fragment
- android:id="@+id/account_list_fragment"
- android:name="org.adullact.iparapheur.controller.account.AccountListFragment"
+ android:id="@+id/menu_fragment"
+ android:name="org.adullact.iparapheur.controller.MenuFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:tag="account_list_fragment"
- tools:layout="@layout/account_list_fragment"/>
+ android:tag="menu_fragment" />
<fragment
- android:id="@+id/menu_fragment"
- android:name="org.adullact.iparapheur.controller.MenuFragment"
+ android:id="@+id/account_list_fragment"
+ android:name="org.adullact.iparapheur.controller.account.AccountListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:tag="menu_fragment"/>
+ android:tag="account_list_fragment"
+ tools:layout="@layout/account_list_fragment" />
</ViewSwitcher>
\ No newline at end of file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="178dp"
- android:background="@drawable/navigation_drawer_header_gradient"
- android:orientation="vertical">
+ android:layout_width="match_parent"
+ android:layout_height="178dp"
+ android:background="@drawable/navigation_drawer_header_gradient"
+ android:orientation="vertical">
<View
android:id="@+id/navigation_drawer_fake_status_bar"
android:layout_width="match_parent"
android:layout_height="24dp"
- android:background="@color/secondary_700"/>
+ android:background="@color/secondary_700" />
<LinearLayout
android:layout_width="match_parent"
android:paddingStart="16dp">
<ImageButton
- android:id="@+id/navigation_drawer_filters_menu_header_account_button"
+ android:id="@+id/navigation_drawer_menu_header_account_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:contentDescription="@string/pref_account_title"
- android:src="@drawable/ic_account_circle_white_72dp"/>
+ android:src="@drawable/ic_account_circle_white_72dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical">
<TextView
- android:id="@+id/navigation_drawer_filters_menu_header_title"
+ android:id="@+id/navigation_drawer_menu_header_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:text="@string/Parapheurs"
android:textColor="@color/text_white"
android:textSize="14sp"
- android:textStyle="bold"/>
+ android:textStyle="bold" />
<TextView
- android:id="@+id/navigation_drawer_filters_menu_header_subtitle"
+ android:id="@+id/navigation_drawer_menu_header_subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/Parapheurs"
android:textColor="@color/text_white"
- android:textSize="14sp"/>
+ android:textSize="14sp" />
</LinearLayout>
- <ImageButton
- android:id="@+id/navigation_drawer_filters_menu_header_filters_imagebutton"
+
+ <FrameLayout
+ android:id="@+id/navigation_drawer_filters_menu_header_filters_container"
android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@android:color/transparent"
- android:contentDescription="@string/Filter_selection"
- android:src="@drawable/ic_filter_list_white_24dp"/>
+ android:layout_height="wrap_content">
+
+ <ImageButton
+ android:id="@+id/navigation_drawer_filters_menu_header_filters_imagebutton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@android:color/transparent"
+ android:contentDescription="@string/Filter_selection"
+ android:src="@drawable/ic_filter_list_white_24dp" />
+ </FrameLayout>
</LinearLayout>
</LinearLayout>
\ No newline at end of file