package com.owncloud.android.ui.activity;
import java.io.File;
+import java.util.ArrayList;
import android.accounts.Account;
import android.accounts.AccountManager;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.Window;
+import com.owncloud.android.BuildConfig;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.operations.UnshareLinkOperation;
import com.owncloud.android.services.observer.FileObserverService;
import com.owncloud.android.syncadapter.FileSyncAdapter;
+import com.owncloud.android.ui.NavigationDrawerItem;
import com.owncloud.android.ui.adapter.NavigationDrawerListAdapter;
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
import com.owncloud.android.ui.dialog.CreateFolderDialogFragment;
private static String DIALOG_UPLOAD_SOURCE = "DIALOG_UPLOAD_SOURCE";
private static String DIALOG_CERT_NOT_SAVED = "DIALOG_CERT_NOT_SAVED";
- private NavigationDrawerListAdapter adapter = null;
-
private OCFile mWaitingToSend;
-
+
+ // Navigation Drawer
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
+ private ListView mDrawerList;
+
+ // Slide menu items
+ private String[] mDrawerTitles;
+ private String[] mDrawerContentDescriptions;
+
+ private ArrayList<NavigationDrawerItem> mDrawerItems;
+
+ private NavigationDrawerListAdapter mNavigationDrawerAdapter = null;
+
private boolean mShowAccounts = false;
@Override
// Inflate and set the layout view
setContentView(R.layout.files);
- // TODO move to another place that all activity can use it
- mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
+ // Navigation Drawer
+ initDrawer();
+
+ mDualPane = getResources().getBoolean(R.bool.large_land_layout);
+ mLeftFragmentContainer = findViewById(R.id.left_fragment_container);
+ mRightFragmentContainer = findViewById(R.id.right_fragment_container);
+ if (savedInstanceState == null) {
+ createMinFragments();
+ }
+
+ // Action bar setup
+ mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ getSupportActionBar().setHomeButtonEnabled(true); // mandatory since Android ICS, according to the official documentation
+ getSupportActionBar().setDisplayShowCustomEnabled(true); // CRUCIAL - for displaying your custom actionbar
+ getSupportActionBar().setDisplayShowTitleEnabled(true);
+ setSupportProgressBarIndeterminateVisibility(mSyncInProgress /*|| mRefreshSharesInProgress*/); // always AFTER setContentView(...) ; to work around bug in its implementation
+
+ // TODO Remove??, it is done in onPostCreate
+ mDrawerToggle.syncState();
+ setBackgroundText();
+
+ Log_OC.v(TAG, "onCreate() end");
+ }
+
+ private void initDrawer(){
+ mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
+ // Notification Drawer
+ LinearLayout navigationDrawerLayout = (LinearLayout) findViewById(R.id.left_drawer);
+ mDrawerList = (ListView) navigationDrawerLayout.findViewById(R.id.drawer_list);
+
+ // load Account in the Drawer Title
+ // User-Icon
+ ImageView userIcon = (ImageView) navigationDrawerLayout.findViewById(R.id.drawer_userIcon);
+ userIcon.setImageResource(DisplayUtils.getSeasonalIconId());
+
+ // Username
+ TextView username = (TextView) navigationDrawerLayout.findViewById(R.id.drawer_username);
+ Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
+
+ if (account != null) {
+ int lastAtPos = account.name.lastIndexOf("@");
+ username.setText(account.name.substring(0, lastAtPos));
+ }
+
+ // load slide menu items
+ mDrawerTitles = getResources().getStringArray(R.array.drawer_items);
+
+ // nav drawer content description from resources
+ mDrawerContentDescriptions = getResources().
+ getStringArray(R.array.drawer_content_descriptions);
+
+ // nav drawer items
+ mDrawerItems = new ArrayList<NavigationDrawerItem>();
+ // adding nav drawer items to array
+ // Accounts
+ mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0], mDrawerContentDescriptions[0]));
+ // All Files
+ mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[1], mDrawerContentDescriptions[1]));
+
+ // TODO Enable when "On Device" is recovered
+ // On Device
+ // mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2], mDrawerContentDescriptions[2]));
+
+ // Settings
+ mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2], mDrawerContentDescriptions[2]));
+ // Logs
+ mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[3],mDrawerContentDescriptions[3]));
+
+ // setting the nav drawer list adapter
+ mNavigationDrawerAdapter = new NavigationDrawerListAdapter(getApplicationContext(), this,
+ mDrawerItems);
+ mDrawerList.setAdapter(mNavigationDrawerAdapter);
+
mDrawerToggle = new ActionBarDrawerToggle(
- this,
- mDrawerLayout,
- R.drawable.ic_drawer,
- R.string.drawer_open,
- R.string.empty
- ) {
+ this,
+ mDrawerLayout,
+ R.drawable.ic_drawer,
+ R.string.drawer_open,
+ R.string.empty) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
invalidateOptionsMenu();
}
};
-
- mDrawerToggle.setDrawerIndicatorEnabled(true);
-
- // Notification Drawer
- LinearLayout notificatonDrawer = (LinearLayout) findViewById(R.id.left_drawer);
-
- // ListView
- ListView listView = (ListView) notificatonDrawer.findViewById(R.id.drawer_list);
- adapter = new NavigationDrawerListAdapter(getApplicationContext(), this);
-
- listView.setAdapter(adapter);
-
- listView.setOnItemClickListener(new OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- if (mShowAccounts && position > 0){
- position = position - 1;
- }
- switch (position){
- case 0: // Accounts
- mShowAccounts = !mShowAccounts;
- adapter.setShowAccounts(mShowAccounts);
- adapter.notifyDataSetChanged();
- break;
-
- case 1: // All Files
- // TODO Enable when "On Device" is recovered ?
- //MainApp.showOnlyFilesOnDevice(false);
- mDrawerLayout.closeDrawers();
- break;
- // TODO Enable when "On Device" is recovered ?
-// case 2:
-// MainApp.showOnlyFilesOnDevice(true);
-// mDrawerLayout.closeDrawers();
-// break;
-
- case 2: // Settings
- Intent settingsIntent = new Intent(getApplicationContext(),
- Preferences.class);
- startActivity(settingsIntent);
- break;
-
- case 3: // Logs
- Intent loggerIntent = new Intent(getApplicationContext(),
- LogHistoryActivity.class);
- startActivity(loggerIntent);
- break;
- }
- }
- });
-
- // User-Icon
- ImageView userIcon = (ImageView) notificatonDrawer.findViewById(R.id.drawer_userIcon);
- userIcon.setImageResource(DisplayUtils.getSeasonalIconId());
-
- // Username
- TextView username = (TextView) notificatonDrawer.findViewById(R.id.drawer_username);
- Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
-
- if (account != null) {
- int lastAtPos = account.name.lastIndexOf("@");
- username.setText(account.name.substring(0, lastAtPos));
- }
+ mDrawerToggle.setDrawerIndicatorEnabled(true);
+ // Set the list's click listener
+ mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
-
- mDualPane = getResources().getBoolean(R.bool.large_land_layout);
- mLeftFragmentContainer = findViewById(R.id.left_fragment_container);
- mRightFragmentContainer = findViewById(R.id.right_fragment_container);
- if (savedInstanceState == null) {
- createMinFragments();
- }
-
- // Action bar setup
- mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- getSupportActionBar().setHomeButtonEnabled(true); // mandatory since Android ICS, according to the official documentation
- getSupportActionBar().setDisplayShowCustomEnabled(true); // CRUCIAL - for displaying your custom actionbar
- getSupportActionBar().setDisplayShowTitleEnabled(true);
- setSupportProgressBarIndeterminateVisibility(mSyncInProgress /*|| mRefreshSharesInProgress*/); // always AFTER setContentView(...) ; to work around bug in its implementation
-
- mDrawerToggle.syncState();
-
- setBackgroundText();
-
- Log_OC.v(TAG, "onCreate() end");
}
-
+
@Override
protected void onStart() {
Log_OC.v(TAG, "onStart() start");
builder.setTitle(R.string.actionbar_sort_title)
.setSingleChoiceItems(R.array.actionbar_sortby, sortOrder , new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
-
switch (which){
- case 0:
- sortByName(true);
- break;
- case 1:
- sortByDate(false);
- break;
-
+ case 0:
+ sortByName(true);
+ break;
+ case 1:
+ sortByDate(false);
+ break;
}
-
+
dialog.dismiss();
-
}
});
builder.create().show();
super.onResume();
// refresh Navigation Drawer account list
- adapter.updateAccountList();
+ mNavigationDrawerAdapter.updateAccountList();
// refresh list of files
refreshListOfFilesFragment();
mDrawerLayout.closeDrawers();
}
+ private class DrawerItemClickListener implements ListView.OnItemClickListener {
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ if (mShowAccounts && position > 0){
+ position = position - 1;
+ }
+ switch (position){
+ case 0: // Accounts
+ mShowAccounts = !mShowAccounts;
+ mNavigationDrawerAdapter.setShowAccounts(mShowAccounts);
+ mNavigationDrawerAdapter.notifyDataSetChanged();
+ break;
+
+ case 1: // All Files
+ // TODO Enable when "On Device" is recovered ?
+ //MainApp.showOnlyFilesOnDevice(false);
+ mDrawerLayout.closeDrawers();
+ break;
+
+ // TODO Enable when "On Device" is recovered ?
+// case 2:
+// MainApp.showOnlyFilesOnDevice(true);
+// mDrawerLayout.closeDrawers();
+// break;
+
+ case 2: // Settings
+ Intent settingsIntent = new Intent(getApplicationContext(),
+ Preferences.class);
+ startActivity(settingsIntent);
+ break;
+
+ case 3: // Logs
+ Intent loggerIntent = new Intent(getApplicationContext(),
+ LogHistoryActivity.class);
+ startActivity(loggerIntent);
+ break;
+ }
+ }
+ }
}