From 015eb6fee99b59abab2f70bb67cf7b6cda191620 Mon Sep 17 00:00:00 2001 From: masensio Date: Tue, 26 May 2015 00:01:39 +0200 Subject: [PATCH 1/6] Disable On Device option in Navigation Drawer --- res/values/strings.xml | 2 +- src/com/owncloud/android/MainApp.java | 22 ++++++----- .../datamodel/FileDataStorageManager.java | 27 +++++++------ .../operations/RefreshFolderOperation.java | 6 ++- .../SynchronizeFolderOperation.java | 27 +++---------- .../ui/activity/FileDisplayActivity.java | 38 +++++++++++++------ .../ui/activity/FolderPickerActivity.java | 16 +++++--- .../ui/activity/UploadPathActivity.java | 3 +- .../android/ui/activity/Uploader.java | 6 ++- .../ui/adapter/FileListListAdapter.java | 6 ++- .../ui/dialog/RemoveFileDialogFragment.java | 3 +- .../ui/fragment/OCFileListFragment.java | 25 ++++++------ .../ui/preview/PreviewImageActivity.java | 5 ++- .../ui/preview/PreviewImagePagerAdapter.java | 16 ++++---- 14 files changed, 113 insertions(+), 89 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index b9aeea495e..d17fdb5040 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -23,7 +23,7 @@ Accounts All Files - On device + Settings ownCloud diff --git a/src/com/owncloud/android/MainApp.java b/src/com/owncloud/android/MainApp.java index 0d725e5ad2..c805f9f7f4 100644 --- a/src/com/owncloud/android/MainApp.java +++ b/src/com/owncloud/android/MainApp.java @@ -53,9 +53,10 @@ public class MainApp extends Application { private static final String POLICY_ALWAYS_NEW_CLIENT = "always new client"; private static Context mContext; - + + // TODO Enable when "On Device" is recovered? // TODO better place - private static boolean mOnlyOnDevice = false; + // private static boolean mOnlyOnDevice = false; public void onCreate(){ @@ -174,14 +175,15 @@ public class MainApp extends Application { public static String getLogName() { return getAppContext().getResources().getString(R.string.log_name); } - - public static void showOnlyFilesOnDevice(boolean state){ - mOnlyOnDevice = state; - } - - public static boolean getOnlyOnDevice(){ - return mOnlyOnDevice; - } + + // TODO Enable when "On Device" is recovered ? +// public static void showOnlyFilesOnDevice(boolean state){ +// mOnlyOnDevice = state; +// } +// +// public static boolean getOnlyOnDevice(){ +// return mOnlyOnDevice; +// } // user agent public static String getUserAgent() { diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index 42f2c780d1..7db0a637f5 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -142,9 +142,10 @@ public class FileDataStorageManager { } - public Vector getFolderContent(OCFile f, boolean onlyOnDevice) { + public Vector getFolderContent(OCFile f/*, boolean onlyOnDevice*/) { if (f != null && f.isFolder() && f.getFileId() != -1) { - return getFolderContent(f.getFileId(), onlyOnDevice); + // TODO Enable when "On Device" is recovered ? + return getFolderContent(f.getFileId()/*, onlyOnDevice*/); } else { return new Vector(); @@ -152,11 +153,12 @@ public class FileDataStorageManager { } - public Vector getFolderImages(OCFile folder, boolean onlyOnDevice) { + public Vector getFolderImages(OCFile folder/*, boolean onlyOnDevice*/) { Vector ret = new Vector(); if (folder != null) { - // TODO better implementation, filtering in the access to database instead of here - Vector tmp = getFolderContent(folder, onlyOnDevice); + // TODO better implementation, filtering in the access to database instead of here + // TODO Enable when "On Device" is recovered ? + Vector tmp = getFolderContent(folder/*, onlyOnDevice*/); OCFile current = null; for (int i=0; i files = getFolderContent(folder.getFileId(), false); + // TODO Enable when "On Device" is recovered ? + Vector files = getFolderContent(folder.getFileId()/*, false*/); if (files != null) { for (OCFile file : files) { if (file.isFolder()) { @@ -731,7 +734,7 @@ public class FileDataStorageManager { } - private Vector getFolderContent(long parentId, boolean onlyOnDevice) { + private Vector getFolderContent(long parentId/*, boolean onlyOnDevice*/) { Vector ret = new Vector(); @@ -758,9 +761,10 @@ public class FileDataStorageManager { if (c.moveToFirst()) { do { OCFile child = createFileInstance(c); - if (child.isFolder() || !onlyOnDevice || onlyOnDevice && child.isDown()){ + // TODO Enable when "On Device" is recovered ? + // if (child.isFolder() || !onlyOnDevice || onlyOnDevice && child.isDown()){ ret.add(child); - } + // } } while (c.moveToNext()); } @@ -1442,8 +1446,9 @@ public class FileDataStorageManager { String where = ProviderTableMeta.OCSHARES_PATH + "=?" + " AND " + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?"; String [] whereArgs = new String[]{ "", mAccount.name }; - - Vector files = getFolderContent(folder, false); + + // TODO Enable when "On Device" is recovered ? + Vector files = getFolderContent(folder /*, false*/); for (OCFile file : files) { whereArgs[0] = file.getRemotePath(); diff --git a/src/com/owncloud/android/operations/RefreshFolderOperation.java b/src/com/owncloud/android/operations/RefreshFolderOperation.java index 5a1cf856ee..2e3c46922b 100644 --- a/src/com/owncloud/android/operations/RefreshFolderOperation.java +++ b/src/com/owncloud/android/operations/RefreshFolderOperation.java @@ -201,7 +201,8 @@ public class RefreshFolderOperation extends RemoteOperation { if (mRemoteFolderChanged) { result = fetchAndSyncRemoteFolder(client); } else { - mChildren = mStorageManager.getFolderContent(mLocalFolder, false); + // TODO Enable when "On Device" is recovered ? + mChildren = mStorageManager.getFolderContent(mLocalFolder/*, false*/); } } @@ -341,7 +342,8 @@ public class RefreshFolderOperation extends RemoteOperation { List filesToSyncContents = new Vector(); // get current data about local contents of the folder to synchronize - List localFiles = mStorageManager.getFolderContent(mLocalFolder, false); + // TODO Enable when "On Device" is recovered ? + List localFiles = mStorageManager.getFolderContent(mLocalFolder/*, false*/); Map localFilesMap = new HashMap(localFiles.size()); for (OCFile file : localFiles) { localFilesMap.put(file.getRemotePath(), file); diff --git a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java index d4423d118c..6bf1ef8264 100644 --- a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -21,51 +21,33 @@ package com.owncloud.android.operations; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Vector; -import org.apache.http.HttpStatus; - import android.accounts.Account; import android.content.Context; import android.content.Intent; import android.util.Log; -import com.owncloud.android.MainApp; + import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileDownloader; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.OperationCancelledException; -import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.lib.resources.files.FileUtils; import com.owncloud.android.lib.resources.files.ReadRemoteFileOperation; import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation; import com.owncloud.android.lib.resources.files.RemoteFile; -import com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation; -import com.owncloud.android.lib.resources.shares.OCShare; -import com.owncloud.android.syncadapter.FileSyncAdapter; import com.owncloud.android.operations.common.SyncOperation; import com.owncloud.android.services.OperationsService; import com.owncloud.android.utils.FileStorageUtils; -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Vector; import java.util.concurrent.atomic.AtomicBoolean; //import android.support.v4.content.LocalBroadcastManager; @@ -316,7 +298,8 @@ public class SynchronizeFolderOperation extends SyncOperation { } // get current data about local contents of the folder to synchronize - List localFiles = storageManager.getFolderContent(mLocalFolder, false); + // TODO Enable when "On Device" is recovered ? + List localFiles = storageManager.getFolderContent(mLocalFolder/*, false*/); Map localFilesMap = new HashMap(localFiles.size()); for (OCFile file : localFiles) { localFilesMap.put(file.getRemotePath(), file); @@ -411,8 +394,8 @@ public class SynchronizeFolderOperation extends SyncOperation { private void prepareOpsFromLocalKnowledge() throws OperationCancelledException { - // TODO TOBI ist das richtig? - List children = getStorageManager().getFolderContent(mLocalFolder, false); + // TODO Enable when "On Device" is recovered ? + List children = getStorageManager().getFolderContent(mLocalFolder/*, false*/); for (OCFile child : children) { /// classify file to sync/download contents later if (child.isFolder()) { diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index b820e13fad..a15f9c1d4f 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -255,14 +255,16 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { adapter.notifyDataSetChanged(); break; case 1: - MainApp.showOnlyFilesOnDevice(false); + // 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: - MainApp.showOnlyFilesOnDevice(true); - mDrawerLayout.closeDrawers(); - break; - case 3: Intent settingsIntent = new Intent(getApplicationContext(), Preferences.class); startActivity(settingsIntent); break; @@ -408,7 +410,9 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { /// First fragment OCFileListFragment listOfFiles = getListOfFilesFragment(); if (listOfFiles != null) { - listOfFiles.listDirectory(getCurrentDir(), MainApp.getOnlyOnDevice()); + listOfFiles.listDirectory(getCurrentDir()); + // TODO Enable when "On Device" is recovered + // listOfFiles.listDirectory(getCurrentDir(), MainApp.getOnlyOnDevice()); } else { Log_OC.e(TAG, "Still have a chance to lose the initializacion of list fragment >("); } @@ -527,8 +531,10 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { protected void refreshListOfFilesFragment() { OCFileListFragment fileListFragment = getListOfFilesFragment(); - if (fileListFragment != null) { - fileListFragment.listDirectory(MainApp.getOnlyOnDevice()); + if (fileListFragment != null) { + fileListFragment.listDirectory(); + // TODO Enable when "On Device" is recovered ? + // fileListFragment.listDirectory(MainApp.getOnlyOnDevice()); } } @@ -1046,7 +1052,9 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { if (synchFolderRemotePath != null && currentDir.getRemotePath().equals(synchFolderRemotePath)) { OCFileListFragment fileListFragment = getListOfFilesFragment(); if (fileListFragment != null) { - fileListFragment.listDirectory(currentDir, MainApp.getOnlyOnDevice()); + fileListFragment.listDirectory(); + // TODO Enable when "On Device" is recovered ? + // fileListFragment.listDirectory(currentDir, MainApp.getOnlyOnDevice()); } } setFile(currentFile); @@ -1275,7 +1283,9 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { popDirname(); } OCFile root = getStorageManager().getFileByPath(OCFile.ROOT_PATH); - listOfFiles.listDirectory(root, MainApp.getOnlyOnDevice()); + listOfFiles.listDirectory(root); + // TODO Enable when "On Device" is recovered ? + // listOfFiles.listDirectory(root, MainApp.getOnlyOnDevice()); setFile(listOfFiles.getCurrentFile()); startSyncFolderOperation(root, false); } @@ -1290,7 +1300,9 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { OCFileListFragment listOfFiles = getListOfFilesFragment(); if (listOfFiles != null) { setNavigationListWithFolder(folder); - listOfFiles.listDirectory(folder, MainApp.getOnlyOnDevice()); + listOfFiles.listDirectory(folder); + // TODO Enable when "On Device" is recovered ? + // listOfFiles.listDirectory(folder, MainApp.getOnlyOnDevice()); setFile(listOfFiles.getCurrentFile()); startSyncFolderOperation(folder, false); } else { @@ -1402,7 +1414,9 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS OCFileListFragment listOfFiles = getListOfFilesFragment(); if (listOfFiles != null) { - listOfFiles.listDirectory(MainApp.getOnlyOnDevice()); + listOfFiles.listDirectory(); + // TODO Enable when "On Device" is recovered ? + // listOfFiles.listDirectory(MainApp.getOnlyOnDevice()); } FileFragment secondFragment = getSecondFragment(); if (secondFragment != null && secondFragment instanceof FileDetailFragment) { diff --git a/src/com/owncloud/android/ui/activity/FolderPickerActivity.java b/src/com/owncloud/android/ui/activity/FolderPickerActivity.java index 6dec67d25c..eec8ab3a1d 100644 --- a/src/com/owncloud/android/ui/activity/FolderPickerActivity.java +++ b/src/com/owncloud/android/ui/activity/FolderPickerActivity.java @@ -142,7 +142,7 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C if (!stateWasRecovered) { OCFileListFragment listOfFolders = getListOfFilesFragment(); - listOfFolders.listDirectory(folder, false); + listOfFolders.listDirectory(folder/*, false*/); startSyncFolderOperation(folder, false); } @@ -310,8 +310,10 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C protected void refreshListOfFilesFragment() { OCFileListFragment fileListFragment = getListOfFilesFragment(); - if (fileListFragment != null) { - fileListFragment.listDirectory(false); + if (fileListFragment != null) { + fileListFragment.listDirectory(); + // TODO Enable when "On Device" is recovered ? + // fileListFragment.listDirectory(false); } } @@ -319,7 +321,9 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C OCFileListFragment listOfFiles = getListOfFilesFragment(); if (listOfFiles != null) { // should never be null, indeed OCFile root = getStorageManager().getFileByPath(OCFile.ROOT_PATH); - listOfFiles.listDirectory(root, false); + listOfFiles.listDirectory(root); + // TODO Enable when "On Device" is recovered ? + // listOfFiles.listDirectory(root, false); setFile(listOfFiles.getCurrentFile()); updateNavigationElementsInActionBar(); startSyncFolderOperation(root, false); @@ -471,7 +475,9 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C equals(synchFolderRemotePath)) { OCFileListFragment fileListFragment = getListOfFilesFragment(); if (fileListFragment != null) { - fileListFragment.listDirectory(currentDir, false); + fileListFragment.listDirectory(currentDir); + // TODO Enable when "On Device" is recovered ? + // fileListFragment.listDirectory(currentDir, false); } } setFile(currentFile); diff --git a/src/com/owncloud/android/ui/activity/UploadPathActivity.java b/src/com/owncloud/android/ui/activity/UploadPathActivity.java index a4e9cb730a..db704d145c 100644 --- a/src/com/owncloud/android/ui/activity/UploadPathActivity.java +++ b/src/com/owncloud/android/ui/activity/UploadPathActivity.java @@ -67,7 +67,8 @@ public class UploadPathActivity extends FolderPickerActivity implements FileFrag if (!stateWasRecovered) { OCFileListFragment listOfFolders = getListOfFilesFragment(); - listOfFolders.listDirectory(folder, false); + // TODO Enable when "On Device" is recovered ? + listOfFolders.listDirectory(folder/*, false*/); startSyncFolderOperation(folder, false); } diff --git a/src/com/owncloud/android/ui/activity/Uploader.java b/src/com/owncloud/android/ui/activity/Uploader.java index 7336af9632..6723616237 100644 --- a/src/com/owncloud/android/ui/activity/Uploader.java +++ b/src/com/owncloud/android/ui/activity/Uploader.java @@ -332,7 +332,8 @@ public class Uploader extends FileActivity public void onItemClick(AdapterView parent, View view, int position, long id) { // click on folder in the list Log_OC.d(TAG, "on item click"); - Vector tmpfiles = getStorageManager().getFolderContent(mFile, false); + // TODO Enable when "On Device" is recovered ? + Vector tmpfiles = getStorageManager().getFolderContent(mFile /*, false*/); if (tmpfiles.size() <= 0) return; // filter on dirtype Vector files = new Vector(); @@ -417,7 +418,8 @@ public class Uploader extends FileActivity mFile = getStorageManager().getFileByPath(full_path); if (mFile != null) { - Vector files = getStorageManager().getFolderContent(mFile, false); + // TODO Enable when "On Device" is recovered ? + Vector files = getStorageManager().getFolderContent(mFile/*, false*/); List> data = new LinkedList>(); for (OCFile f : files) { HashMap h = new HashMap(); diff --git a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java index 43c308342d..c6ea0344d1 100644 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -407,14 +407,16 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { * @param updatedStorageManager Optional updated storage manager; used to replace * mStorageManager if is different (and not NULL) */ - public void swapDirectory(OCFile directory, FileDataStorageManager updatedStorageManager, boolean onlyOnDevice) { + public void swapDirectory(OCFile directory, FileDataStorageManager updatedStorageManager + /*, boolean onlyOnDevice*/) { mFile = directory; if (updatedStorageManager != null && updatedStorageManager != mStorageManager) { mStorageManager = updatedStorageManager; mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext); } if (mStorageManager != null) { - mFiles = mStorageManager.getFolderContent(mFile, onlyOnDevice); + // TODO Enable when "On Device" is recovered ? + mFiles = mStorageManager.getFolderContent(mFile/*, onlyOnDevice*/); mFilesOrig.clear(); mFilesOrig.addAll(mFiles); diff --git a/src/com/owncloud/android/ui/dialog/RemoveFileDialogFragment.java b/src/com/owncloud/android/ui/dialog/RemoveFileDialogFragment.java index 179ab96245..f00b19f1a8 100644 --- a/src/com/owncloud/android/ui/dialog/RemoveFileDialogFragment.java +++ b/src/com/owncloud/android/ui/dialog/RemoveFileDialogFragment.java @@ -112,7 +112,8 @@ implements ConfirmationDialogFragmentListener { boolean containsKeepInSync = false; if (mTargetFile.isFolder()) { - Vector files = storageManager.getFolderContent(mTargetFile, false); + // TODO Enable when "On Device" is recovered ? + Vector files = storageManager.getFolderContent(mTargetFile/*, false*/); for(OCFile file: files) { containsKeepInSync = file.keepInSync() || containsKeepInSync; diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index 9430f112fe..4bf68ad076 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -29,15 +29,12 @@ import android.content.Intent; import android.os.Bundle; import android.support.v4.widget.SwipeRefreshLayout; import android.view.ContextMenu; -import android.view.LayoutInflater; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.AdapterContextMenuInfo; -import android.widget.TextView; -import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; @@ -186,8 +183,9 @@ public class OCFileListFragment extends ExtendedListFragment { moveCount++; } // exit is granted because storageManager.getFileByPath("/") never returns null mFile = parentDir; - - listDirectory(mFile, MainApp.getOnlyOnDevice()); + + // TODO Enable when "On Device" is recovered ? + listDirectory(mFile /*, MainApp.getOnlyOnDevice()*/); onRefresh(false); @@ -205,7 +203,8 @@ public class OCFileListFragment extends ExtendedListFragment { if (file != null) { if (file.isFolder()) { // update state and view of this fragment - listDirectory(file, MainApp.getOnlyOnDevice()); + // TODO Enable when "On Device" is recovered ? + listDirectory(file/*, MainApp.getOnlyOnDevice()*/); // then, notify parent activity to let it update its state and view mContainerActivity.onBrowsedDownTo(file); // save index and top position @@ -359,12 +358,15 @@ public class OCFileListFragment extends ExtendedListFragment { /** * Calls {@link OCFileListFragment#listDirectory(OCFile)} with a null parameter */ - public void listDirectory(boolean onlyOnDevice){ - listDirectory(null, onlyOnDevice); + public void listDirectory(/*boolean onlyOnDevice*/){ + listDirectory(null); + // TODO Enable when "On Device" is recovered ? + // listDirectory(null, onlyOnDevice); } public void refreshDirectory(){ - listDirectory(getCurrentFile(), MainApp.getOnlyOnDevice()); + // TODO Enable when "On Device" is recovered ? + listDirectory(getCurrentFile()/*, MainApp.getOnlyOnDevice()*/); } /** @@ -374,7 +376,7 @@ public class OCFileListFragment extends ExtendedListFragment { * * @param directory File to be listed */ - public void listDirectory(OCFile directory, boolean onlyOnDevice) { + public void listDirectory(OCFile directory/*, boolean onlyOnDevice*/) { FileDataStorageManager storageManager = mContainerActivity.getStorageManager(); if (storageManager != null) { @@ -395,7 +397,8 @@ public class OCFileListFragment extends ExtendedListFragment { directory = storageManager.getFileById(directory.getParentId()); } - mAdapter.swapDirectory(directory, storageManager, onlyOnDevice); + // TODO Enable when "On Device" is recovered ? + mAdapter.swapDirectory(directory, storageManager/*, onlyOnDevice*/); if (mFile == null || !mFile.equals(directory)) { mCurrentListView.setSelection(0); } diff --git a/src/com/owncloud/android/ui/preview/PreviewImageActivity.java b/src/com/owncloud/android/ui/preview/PreviewImageActivity.java index 3af7992b8f..6ff3cb8feb 100644 --- a/src/com/owncloud/android/ui/preview/PreviewImageActivity.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageActivity.java @@ -38,7 +38,6 @@ import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.Window; import com.ortiz.touch.ExtendedViewPager; -import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.datamodel.FileDataStorageManager; @@ -140,7 +139,9 @@ ViewPager.OnPageChangeListener, OnRemoteOperationListener { // should not be necessary parentFolder = getStorageManager().getFileByPath(OCFile.ROOT_PATH); } - mPreviewImagePagerAdapter = new PreviewImagePagerAdapter(getSupportFragmentManager(), parentFolder, getAccount(), getStorageManager(), MainApp.getOnlyOnDevice()); + // TODO Enable when "On Device" is recovered ? + mPreviewImagePagerAdapter = new PreviewImagePagerAdapter(getSupportFragmentManager(), + parentFolder, getAccount(), getStorageManager()/*, MainApp.getOnlyOnDevice()*/); mViewPager = (ExtendedViewPager) findViewById(R.id.fragmentPager); int position = mHasSavedPosition ? mSavedPosition : mPreviewImagePagerAdapter.getFilePosition(getFile()); position = (position >= 0) ? position : 0; diff --git a/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java b/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java index fc99d289ac..dda7dda25a 100644 --- a/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java +++ b/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java @@ -19,8 +19,6 @@ */ package com.owncloud.android.ui.preview; -import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -36,7 +34,6 @@ import android.view.ViewGroup; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; -import com.owncloud.android.ui.adapter.FileListListAdapter; import com.owncloud.android.ui.fragment.FileFragment; import com.owncloud.android.utils.FileStorageUtils; @@ -58,11 +55,14 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter { /** * Constructor. * - * @param fragmentManager {@link FragmentManager} instance that will handle the {@link Fragment}s provided by the adapter. + * @param fragmentManager {@link FragmentManager} instance that will handle + * the {@link Fragment}s provided by the adapter. * @param parentFolder Folder where images will be searched for. * @param storageManager Bridge to database. */ - public PreviewImagePagerAdapter(FragmentManager fragmentManager, OCFile parentFolder, Account account, FileDataStorageManager storageManager, boolean onlyOnDevice) { + public PreviewImagePagerAdapter(FragmentManager fragmentManager, OCFile parentFolder, + Account account, FileDataStorageManager storageManager /*, + boolean onlyOnDevice*/) { super(fragmentManager); if (fragmentManager == null) { @@ -77,7 +77,8 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter { mAccount = account; mStorageManager = storageManager; - mImageFiles = mStorageManager.getFolderImages(parentFolder, false); + // TODO Enable when "On Device" is recovered ? + mImageFiles = mStorageManager.getFolderImages(parentFolder/*, false*/); mImageFiles = FileStorageUtils.sortFolder(mImageFiles); @@ -102,7 +103,8 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter { OCFile file = mImageFiles.get(i); Fragment fragment = null; if (file.isDown()) { - fragment = PreviewImageFragment.newInstance(file, mObsoletePositions.contains(Integer.valueOf(i))); + fragment = PreviewImageFragment.newInstance(file, + mObsoletePositions.contains(Integer.valueOf(i))); } else if (mDownloadErrors.contains(Integer.valueOf(i))) { fragment = FileDownloadFragment.newInstance(file, mAccount, true); From 6d8fc58eabd9220306497e2f16e0499d8284444c Mon Sep 17 00:00:00 2001 From: masensio Date: Tue, 26 May 2015 08:48:36 +0200 Subject: [PATCH 2/6] Remove some imports --- .../owncloud/android/ui/activity/FileDisplayActivity.java | 3 --- .../owncloud/android/ui/activity/FolderPickerActivity.java | 4 ---- src/com/owncloud/android/ui/activity/Uploader.java | 7 ------- 3 files changed, 14 deletions(-) diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index a15f9c1d4f..c248f82774 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -27,7 +27,6 @@ import java.io.File; import android.accounts.Account; import android.accounts.AccountManager; import android.accounts.AuthenticatorException; -import android.accounts.OperationCanceledException; import android.annotation.TargetApi; import android.app.AlertDialog; import android.content.BroadcastReceiver; @@ -55,7 +54,6 @@ import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; -import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; @@ -101,7 +99,6 @@ import com.owncloud.android.operations.RefreshFolderOperation; import com.owncloud.android.operations.UnshareLinkOperation; import com.owncloud.android.services.observer.FileObserverService; import com.owncloud.android.syncadapter.FileSyncAdapter; -import com.owncloud.android.ui.adapter.FileListListAdapter; import com.owncloud.android.ui.adapter.NavigationDrawerListAdapter; import com.owncloud.android.ui.dialog.ConfirmationDialogFragment; import com.owncloud.android.ui.dialog.CreateFolderDialogFragment; diff --git a/src/com/owncloud/android/ui/activity/FolderPickerActivity.java b/src/com/owncloud/android/ui/activity/FolderPickerActivity.java index eec8ab3a1d..f135dceae6 100644 --- a/src/com/owncloud/android/ui/activity/FolderPickerActivity.java +++ b/src/com/owncloud/android/ui/activity/FolderPickerActivity.java @@ -19,12 +19,9 @@ package com.owncloud.android.ui.activity; -import java.io.IOException; - import android.accounts.Account; import android.accounts.AccountManager; import android.accounts.AuthenticatorException; -import android.accounts.OperationCanceledException; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -45,7 +42,6 @@ import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.Window; -import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.OwnCloudAccount; diff --git a/src/com/owncloud/android/ui/activity/Uploader.java b/src/com/owncloud/android/ui/activity/Uploader.java index 6723616237..bee923337d 100644 --- a/src/com/owncloud/android/ui/activity/Uploader.java +++ b/src/com/owncloud/android/ui/activity/Uploader.java @@ -70,18 +70,11 @@ import com.actionbarsherlock.view.MenuItem; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.authentication.AccountAuthenticator; -import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.MainApp; -import com.owncloud.android.R; -import com.owncloud.android.authentication.AccountAuthenticator; -import com.owncloud.android.datamodel.OCFile; -import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.operations.CreateFolderOperation; import com.owncloud.android.ui.dialog.CreateFolderDialogFragment; import com.owncloud.android.ui.dialog.LoadingDialog; From 101989b70c302517d1e0dc6eb6c164d97d97fd0a Mon Sep 17 00:00:00 2001 From: masensio Date: Tue, 26 May 2015 09:11:27 +0200 Subject: [PATCH 3/6] Move 'Logs' from Settings to Navigation Drawer --- res/values/strings.xml | 1 + res/xml/preferences.xml | 1 - .../ui/activity/FileDisplayActivity.java | 42 ++++++++++++------- .../android/ui/activity/Preferences.java | 7 ++-- 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index d17fdb5040..84ede4fa07 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -25,6 +25,7 @@ All Files Settings + Logs ownCloud Close diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index e1d0a476f4..4823a83f9b 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -56,7 +56,6 @@ - diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index c248f82774..26992ad988 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -167,7 +167,7 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { private DrawerLayout mDrawerLayout; private ActionBarDrawerToggle mDrawerToggle; - private boolean showAccounts = false; + private boolean mShowAccounts = false; @Override protected void onCreate(Bundle savedInstanceState) { @@ -242,29 +242,39 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - if (showAccounts && position > 0){ + if (mShowAccounts && position > 0){ position = position - 1; } switch (position){ - case 0: - showAccounts = !showAccounts; - adapter.setShowAccounts(showAccounts); - adapter.notifyDataSetChanged(); - break; - case 1: + 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 ? - //MainApp.showOnlyFilesOnDevice(false); - mDrawerLayout.closeDrawers(); - break; - // TODO Enable when "On Device" is recovered ? // case 2: // MainApp.showOnlyFilesOnDevice(true); // mDrawerLayout.closeDrawers(); // break; - case 2: - Intent settingsIntent = new Intent(getApplicationContext(), Preferences.class); - startActivity(settingsIntent); - 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; } } }); diff --git a/src/com/owncloud/android/ui/activity/Preferences.java b/src/com/owncloud/android/ui/activity/Preferences.java index e7e76790c5..39fc314ce0 100644 --- a/src/com/owncloud/android/ui/activity/Preferences.java +++ b/src/com/owncloud/android/ui/activity/Preferences.java @@ -203,7 +203,7 @@ public class Preferences extends SherlockPreferenceActivity } } - + if (BuildConfig.DEBUG) { Preference pLog = findPreference("log"); if (pLog != null ){ @@ -215,7 +215,7 @@ public class Preferences extends SherlockPreferenceActivity return true; } }); - } + } } boolean recommendEnabled = getResources().getBoolean(R.bool.recommend_enabled); @@ -236,7 +236,8 @@ public class Preferences extends SherlockPreferenceActivity Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(Preferences.this); String username = currentAccount.name.substring(0, currentAccount.name.lastIndexOf('@')); - String recommendSubject = String.format(getString(R.string.recommend_subject), appName); + String recommendSubject = String.format(getString(R.string.recommend_subject), + appName); String recommendText = String.format(getString(R.string.recommend_text), appName, downloadUrl, username); From a9dad9e480909173f16dbcb67313ac5c8799ec84 Mon Sep 17 00:00:00 2001 From: masensio Date: Tue, 26 May 2015 11:46:15 +0200 Subject: [PATCH 4/6] Add content_description to Navigation Drawer options --- res/layout/drawer_list_item.xml | 55 ++-- res/layout/files.xml | 82 +++--- res/values/drawer_resources.xml | 39 +++ res/values/strings.xml | 13 +- .../android/ui/NavigationDrawerItem.java | 56 ++++ .../ui/activity/FileDisplayActivity.java | 252 ++++++++++-------- .../adapter/NavigationDrawerListAdapter.java | 74 +++-- 7 files changed, 373 insertions(+), 198 deletions(-) create mode 100644 res/values/drawer_resources.xml create mode 100644 src/com/owncloud/android/ui/NavigationDrawerItem.java diff --git a/res/layout/drawer_list_item.xml b/res/layout/drawer_list_item.xml index 630366e0bb..30f3843b44 100644 --- a/res/layout/drawer_list_item.xml +++ b/res/layout/drawer_list_item.xml @@ -1,25 +1,42 @@ + -. +--> + + + android:layout_height="wrap_content" + android:layout_alignParentLeft="true" + android:orientation="horizontal" + android:background="@color/background_color" + android:layout_marginTop="10dp" + android:layout_marginBottom="10dp"> + + + diff --git a/res/layout/files.xml b/res/layout/files.xml index 5d87b12667..b1050ff048 100644 --- a/res/layout/files.xml +++ b/res/layout/files.xml @@ -32,7 +32,7 @@ android:baselineAligned="false" android:orientation="horizontal" > - + - - + xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/left_drawer" + android:layout_width="240dp" + android:layout_height="match_parent" + android:layout_gravity="start" + android:background="@color/background_color" + android:baselineAligned="false" + android:clickable="true" + android:orientation="vertical"> - + + + + + + + + android:layout_width="fill_parent" + android:layout_height="2dip" + android:background="@color/list_item_lastmod_and_filesize_text" /> + - - - - - \ No newline at end of file diff --git a/res/values/drawer_resources.xml b/res/values/drawer_resources.xml new file mode 100644 index 0000000000..ca0143baeb --- /dev/null +++ b/res/values/drawer_resources.xml @@ -0,0 +1,39 @@ + + + + + + + @string/prefs_accounts + @string/drawer_item_all_files + + @string/actionbar_settings + @string/actionbar_logger + + + + + @string/drawer_item_accounts + @string/drawer_item_all_files + + @string/drawer_item_settings + @string/drawer_item_logs + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 84ede4fa07..8a7d813960 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -20,13 +20,12 @@ - - Accounts - All Files - - Settings - Logs - + Accounts + All files + + Settings + Logs ownCloud Close General diff --git a/src/com/owncloud/android/ui/NavigationDrawerItem.java b/src/com/owncloud/android/ui/NavigationDrawerItem.java new file mode 100644 index 0000000000..44ed3eccb4 --- /dev/null +++ b/src/com/owncloud/android/ui/NavigationDrawerItem.java @@ -0,0 +1,56 @@ +/** + * ownCloud Android client application + * + * @author masensio + * Copyright (C) 2015 ownCloud Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package com.owncloud.android.ui; + +public class NavigationDrawerItem { + + private String mTitle; + private String mContentDescription; + + // Constructors + public NavigationDrawerItem(){} + + public NavigationDrawerItem(String title){ + mTitle = title; + } + + public NavigationDrawerItem(String title, String contentDescription){ + mTitle = title; + mContentDescription = contentDescription; + } + + // Getters and Setters + public String getTitle() { + return mTitle; + } + + public void setTitle(String title) { + this.mTitle = title; + } + + public String getContentDescription() { + return mContentDescription; + } + + public void setContentDescription(String contentDescription) { + this.mContentDescription = contentDescription; + } +} diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 26992ad988..1d4f17a790 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -23,6 +23,7 @@ package com.owncloud.android.ui.activity; import java.io.File; +import java.util.ArrayList; import android.accounts.Account; import android.accounts.AccountManager; @@ -71,6 +72,7 @@ import com.actionbarsherlock.view.Menu; 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; @@ -99,6 +101,7 @@ import com.owncloud.android.operations.RefreshFolderOperation; 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; @@ -161,12 +164,21 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { 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 mDrawerItems; + + private NavigationDrawerListAdapter mNavigationDrawerAdapter = null; + private boolean mShowAccounts = false; @Override @@ -199,16 +211,87 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { // 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(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(); + // 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) { @@ -227,96 +310,15 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { 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)); - } + // 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(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"); @@ -636,19 +638,16 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { 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(); @@ -908,7 +907,7 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { super.onResume(); // refresh Navigation Drawer account list - adapter.updateAccountList(); + mNavigationDrawerAdapter.updateAccountList(); // refresh list of files refreshListOfFilesFragment(); @@ -1907,4 +1906,43 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { 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; + } + } + } } diff --git a/src/com/owncloud/android/ui/adapter/NavigationDrawerListAdapter.java b/src/com/owncloud/android/ui/adapter/NavigationDrawerListAdapter.java index f56f529c6d..b53f66f482 100644 --- a/src/com/owncloud/android/ui/adapter/NavigationDrawerListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/NavigationDrawerListAdapter.java @@ -1,3 +1,24 @@ +/** + * ownCloud Android client application + * + * @author tobiasKaminsky + * @author masensio + * Copyright (C) 2015 ownCloud Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package com.owncloud.android.ui.adapter; import java.nio.ByteBuffer; @@ -12,6 +33,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; +import android.widget.LinearLayout; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.RadioGroup.LayoutParams; @@ -21,46 +43,47 @@ import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.ui.NavigationDrawerItem; import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.utils.BitmapUtils; public class NavigationDrawerListAdapter extends BaseAdapter { - private final static String TAG = "NavigationDrawerListAdapter"; + private final static String TAG = NavigationDrawerListAdapter.class.getSimpleName(); + private Context mContext; - private ArrayList mDrawerItems = new ArrayList(); - ArrayList all = new ArrayList(); + + private ArrayList mNavigationDrawerItems; + private ArrayList mAll = new ArrayList(); private Account[] mAccounts; private boolean mShowAccounts; - private Account currentAccount; + private Account mCurrentAccount; private FileDisplayActivity mFileDisplayActivity; - public NavigationDrawerListAdapter(Context context, FileDisplayActivity fileDisplayActivity){ + public NavigationDrawerListAdapter(Context context, FileDisplayActivity fileDisplayActivity, + ArrayList navigationDrawerItems){ mFileDisplayActivity = fileDisplayActivity; mContext = context; - - for (String string : mContext.getResources().getStringArray(R.array.drawer_items)) { - mDrawerItems.add(string); - } + mNavigationDrawerItems = navigationDrawerItems; updateAccountList(); - all.addAll(mDrawerItems); + mAll.addAll(mNavigationDrawerItems); } public void updateAccountList(){ AccountManager am = (AccountManager) mContext.getSystemService(mContext.ACCOUNT_SERVICE); mAccounts = am.getAccountsByType(MainApp.getAccountType()); - currentAccount = AccountUtils.getCurrentOwnCloudAccount(mContext); + mCurrentAccount = AccountUtils.getCurrentOwnCloudAccount(mContext); } @Override public int getCount() { if (mShowAccounts){ - return mDrawerItems.size() + 1; + return mNavigationDrawerItems.size() + 1; } else { - return mDrawerItems.size(); + return mNavigationDrawerItems.size(); } } @@ -81,21 +104,23 @@ public class NavigationDrawerListAdapter extends BaseAdapter { LayoutInflater inflator = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - if (all.size() > position) { + if (mAll.size() > position) { // Normal entry - if (all.get(position) instanceof String){ + if (mAll.get(position) instanceof NavigationDrawerItem){ + NavigationDrawerItem navItem = (NavigationDrawerItem) mAll.get(position); + View view = inflator.inflate(R.layout.drawer_list_item, null); view.setMinimumHeight(40); - TextView textView = (TextView) view.findViewById(R.id.drawer_textView); - - String entry = (String) all.get(position); - textView.setText(entry); + LinearLayout itemLayout = (LinearLayout) view.findViewById(R.id.itemLayout); + itemLayout.setContentDescription(navItem.getContentDescription()); + TextView itemText = (TextView) view.findViewById(R.id.itemTitle); + itemText.setText(navItem.getTitle()); return view; } // Account - if (all.get(position) instanceof Account[]){ + if (mAll.get(position) instanceof Account[]){ final View view = inflator.inflate(R.layout.drawer_account_group, null); final RadioGroup group = (RadioGroup) view.findViewById(R.id.drawer_radio_group); @@ -103,6 +128,7 @@ public class NavigationDrawerListAdapter extends BaseAdapter { for (Account account : mAccounts) { RadioButton rb = new RadioButton(mContext); rb.setText(account.name); + rb.setContentDescription(account.name); try { byte[] bytesOfMessage = account.name.substring(0,5).getBytes("UTF-8"); @@ -132,7 +158,7 @@ public class NavigationDrawerListAdapter extends BaseAdapter { params.setMargins(15, 5, 5, 5); // Check the current account that is being used - if (account.name.equals(currentAccount.name)) { + if (account.name.equals(mCurrentAccount.name)) { rb.setChecked(true); } else { rb.setChecked(false); @@ -163,11 +189,11 @@ public class NavigationDrawerListAdapter extends BaseAdapter { // TODO update Account List after creating a new account and on fresh installation public void setShowAccounts(boolean value){ - all.clear(); - all.addAll(mDrawerItems); + mAll.clear(); + mAll.addAll(mNavigationDrawerItems); if (value){ - all.add(1, mAccounts); + mAll.add(1, mAccounts); } mShowAccounts = value; } From e934f015e8272d998999962c7df38efa9fe81c98 Mon Sep 17 00:00:00 2001 From: masensio Date: Tue, 26 May 2015 12:55:40 +0200 Subject: [PATCH 5/6] Enable 'Logs' navigation drawer entry only in DEBUG mode --- .../owncloud/android/ui/activity/FileDisplayActivity.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 1d4f17a790..c37d9271a3 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -274,12 +274,16 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener { // TODO Enable when "On Device" is recovered // On Device - // mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2], mDrawerContentDescriptions[2])); + //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])); + if (BuildConfig.DEBUG) { + mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[3], + mDrawerContentDescriptions[3])); + } // setting the nav drawer list adapter mNavigationDrawerAdapter = new NavigationDrawerListAdapter(getApplicationContext(), this, From 0238727d1368a0357804eb3daf4e2917bfc81429 Mon Sep 17 00:00:00 2001 From: masensio Date: Tue, 26 May 2015 13:12:19 +0200 Subject: [PATCH 6/6] Add ic_drawer for mdpi and xhdpi --- res/drawable-mdpi/ic_drawer.png | Bin 0 -> 2837 bytes res/drawable-xhdpi/ic_drawer.png | Bin 0 -> 1056 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 res/drawable-mdpi/ic_drawer.png create mode 100644 res/drawable-xhdpi/ic_drawer.png diff --git a/res/drawable-mdpi/ic_drawer.png b/res/drawable-mdpi/ic_drawer.png new file mode 100644 index 0000000000000000000000000000000000000000..fb681ba2639897cc4646d3784b97bbe16f5d4e91 GIT binary patch literal 2837 zcmV+w3+nWVP)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#bBIa#GxRa#xMMy;K#CDyyGyQdMSxlWT#tDe?p!?5wT$+oGt z8L;Kp2HUQ-ZMJ=3XJQv;x5ci*?vuTfeY$;({XGW_huIFR9a(?@3)XSs8O^N5RyOM=TTmp(3=8^+zpz2r)C z^>JO{deZfso3oq3?Wo(Y?l$ge?uXo;%ru`Vo>?<<(8I_>;8Eq#KMS9gFl*neeosSB zfoHYnBQIkwkyowPu(zdms`p{<7e4kra-ZWq<2*OsGTvEV%s0Td$hXT+!*8Bnh2KMe zBmZRodjHV?r+_5^X9J0WL4jKW`}lf%A-|44I@@LTvf1rHjG(ze6+w@Jt%Bvjts!X0 z?2xS?_ve_-kiKB_KiJlZ$9G`c^=E@oNG)mWWaNo-3TIW8)$Hg0Ub-~8?KhvJ>$ z3*&nim@mj(aCxE5!t{lw7O5^0EIO7zOo&c6l<+|iDySBWCGrz@C5{St!X3hAA}`T4 z(TLbXTq+(;@<=L8dXnssyft|w#WSTW<++3>sgS%(4NTpeI-VAqb|7ssJvzNHgOZVu zaYCvgO_R1~>SyL=cFU|~g|hy|Zi}}s9+d~lYqOB71z9Z$wnC=pR9Yz4DhIM>Wmjgu z&56o6maCpC&F##y%G;1PobR9i?GnNg;gYtchD%p19a!eQtZF&3JaKv33gZ<8D~47E ztUS1iwkmDaPpj=$m#%)jCVEY4fnLGNg2A-`YwHVD3gv};>)hAvT~AmqS>Lr``i7kw zJ{5_It`yrBmlc25DBO7E8;5VoznR>Ww5hAaxn$2~(q`%A-YuS64wkBy=9dm`4cXeX z4c}I@?e+FW+b@^RDBHV(wnMq2zdX3SWv9u`%{xC-q*U}&`cyXV(%rRT*Z6MH?i+i& z_B8C(+grT%{XWUQ+f@NoP1R=AW&26{v-dx)iK^-Nmiuj8txj!m?Z*Ss1N{dh4z}01 z)YTo*JycSU)+_5r4#yw9{+;i4Ee$peRgIj+;v;ZGdF1K$3E%e~4LaI(jC-u%2h$&R z9cLXcYC@Xwnns&bn)_Q~Te?roKGD|d-g^8;+aC{{G(1^(O7m37Y1-+6)01cN&y1aw zoqc{T`P^XJqPBbIW6s}d4{z_f5Om?vMgNQEJG?v2T=KYd^0M3I6IZxbny)%vZR&LD zJpPl@Psh8QyPB@KTx+@RdcC!KX7}kEo;S|j^u2lU7XQ}Oo;f|;z4Ll+_r>@1-xl3| zawq-H%e&ckC+@AhPrP6BKT#_XdT7&;F71j}Joy zkC~6lh7E@6o;W@^IpRNZ{ptLtL(gQ-CY~4mqW;US7Zxvm_|@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z0000$NklT0VPv57M=PzWeCfQ5m9fsqme7%2@z%Dpfe n3zWNnaWpS500000|NjF3akv#B{xHpr00000NkvXXu0mjfm;ygF literal 0 HcmV?d00001 diff --git a/res/drawable-xhdpi/ic_drawer.png b/res/drawable-xhdpi/ic_drawer.png new file mode 100644 index 0000000000000000000000000000000000000000..b9bc3d70f1d29fec2e4530e5d1809edc8e15ad35 GIT binary patch literal 1056 zcmbVLy>HV%6u%0oKud=rkbnW5+yx|J`<&Q`t(wY-lQsgURT^lJI@GnVjg{JG>??6I zp$-TJMs}p`%!m$vm_Q6HNWhFgdkGtJ{wp^s;CS4?Jv|~pY7%o}Gu+V}T4Zw+(*J#qF zbyIVQ&)caDpZFm|128?4gtpVh6t3cRFVMN~yDvHDxjMHbTcQ<~aLb$PMtHGXYdGDu zqq^M8bvT`9jKIg#hKaus#9E?rJzkB;saoJ*&xE#ht{+s>T7V@IVJP$2j3Xih6@^DR zSy9k6D2YfCMD{8fl+$EIlk#xzaLileu4#3%GVsNAI@h8!)C8f^>F}K_Poi}Jsj8ZC zNK%GbWa6!W+DRser-lqBj-AL0sYe2sGTN(TljTGkrXC2cz{u9QL)^TGi#6lg%WHWNueXLCl!K`-2J4y{%G}?URu}iTxOyX?%IG|Ni z=hzAFdahPhWYd&UB`ZouDIio33t8338aX7(id>P097kc5Tt2T#qN-LD1EI21DCNpU z)l>>nF>e%+ImA|jnA(AZhkiZgcYrM%i`7aIwke4kglr5uV4+1QiCZLur9}l^v24c+ zQpMHug8KQIIP&gcw-ON__A0D-M?~=N%==jPf2t<1V1%?i{%V(@iuGVB9yUMQ9F7kT z*vv$1ICdVt{>%oeRyB=A^5xqTV+_DEZ*K2>+`fG7_s{+D?GHCbcTc|H-@OlOr+<7J z`MUh8J-U;h90BvQ$x;pMJp@l5JO^O;{&-)=znWYD7w()l&fdzcq%&JB*UV?dmF)v& C(MM