--Subproject commit dbc8c325d74f3f7e8da8236c5abe77a141ae4019
++Subproject commit c8f6e5ad57ee27fdac39c7b14eb6ab1942a92d49
android:title="@string/actionbar_mkdir"
android:contentDescription="@string/actionbar_mkdir"/>
<item
- android:icon="@android:drawable/ic_menu_view"
+ android:id="@+id/action_switch_view"
++ android:icon="@drawable/ic_view_module"
+ android:orderInCategory="2"
++ app:showAsAction="always"
+ android:title="@string/action_switch_grid_view" />
+ <item
android:id="@+id/action_sync_account"
android:icon="@drawable/ic_action_refresh"
android:orderInCategory="2"
menu.findItem(R.id.action_create_dir).setVisible(!drawerOpen);
menu.findItem(R.id.action_sort).setVisible(!drawerOpen);
menu.findItem(R.id.action_sync_account).setVisible(!drawerOpen);
++ menu.findItem(R.id.action_switch_view).setVisible(!drawerOpen);
return super.onPrepareOptionsMenu(menu);
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
- if (DisplayUtils.isGridView(getFile(), getStorageManager())){
- menuItem.setTitle(getApplicationContext().getString(R.string.action_switch_list_view));
- } else {
- menuItem.setTitle(getApplicationContext().getString(R.string.action_switch_grid_view));
- }
+ mOptionsMenu = menu;
+
+ MenuItem menuItem = mOptionsMenu.findItem(R.id.action_switch_view);
+
++ changeGridIcon();
+
return true;
}
builder.create().show();
break;
}
- item.setTitle(getApplicationContext().getString(R.string.action_switch_list_view));
+ case R.id.action_switch_view:{
+ if (isGridView()){
- item.setTitle(getApplicationContext().getString(R.string.action_switch_grid_view));
++ item.setTitle(getApplicationContext().getString(R.string.action_switch_grid_view));
++ item.setIcon(ContextCompat.getDrawable(getApplicationContext(),
++ R.drawable.ic_view_module));
+ DisplayUtils.setViewMode(getFile(), false);
+ switchToListView();
+ } else {
++ item.setTitle(getApplicationContext().getString(R.string.action_switch_list_view));
++ item.setIcon(ContextCompat.getDrawable(getApplicationContext(),
++ R.drawable.ic_view_list));
+ DisplayUtils.setViewMode(getFile(), true);
+ switchToGridView();
+ }
++
+ return true;
+ }
default:
retval = super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
- OCFileListFragment listOfFiles = getListOfFilesFragment();
- if (mDualPane || getSecondFragment() == null) {
- OCFile currentDir = getCurrentDir();
- if (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID) {
- finish();
- return;
+ if (!isDrawerOpen()){
+ OCFileListFragment listOfFiles = getListOfFilesFragment();
+ if (mDualPane || getSecondFragment() == null) {
+ OCFile currentDir = getCurrentDir();
+ if (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID) {
+ finish();
+ return;
+ }
+ if (listOfFiles != null) { // should never be null, indeed
+ listOfFiles.onBrowseUp();
+ }
}
if (listOfFiles != null) { // should never be null, indeed
- listOfFiles.onBrowseUp();
+ setFile(listOfFiles.getCurrentFile());
}
+ cleanSecondFragment();
++
++ changeGridIcon();
+ } else {
+ super.onBackPressed();
}
- if (listOfFiles != null) { // should never be null, indeed
- setFile(listOfFiles.getCurrentFile());
- }
- cleanSecondFragment();
+ }
++ private void changeGridIcon(){
+ MenuItem menuItem = mOptionsMenu.findItem(R.id.action_switch_view);
+ if (DisplayUtils.isGridView(getFile(), getStorageManager())){
+ menuItem.setTitle(getApplicationContext().getString(R.string.action_switch_list_view));
++ menuItem.setIcon(ContextCompat.getDrawable(getApplicationContext(),
++ R.drawable.ic_view_list));
+ } else {
+ menuItem.setTitle(getApplicationContext().getString(R.string.action_switch_grid_view));
++ menuItem.setIcon(ContextCompat.getDrawable(getApplicationContext(),
++ R.drawable.ic_view_module));
+ }
+ }
+
@Override
protected void onSaveInstanceState(Bundle outState) {
// responsibility of restore is preferred in onCreate() before than in
cleanSecondFragment();
// Sync Folder
startSyncFolderOperation(directory, false);
- menuItem.setTitle(getApplicationContext().getString(R.string.action_switch_list_view));
+
+ MenuItem menuItem = mOptionsMenu.findItem(R.id.action_switch_view);
+
++ changeGridIcon();
+ if (DisplayUtils.isGridView(directory, getStorageManager())){
- menuItem.setTitle(getApplicationContext().getString(R.string.action_switch_grid_view));
+ switchToGridView();
+ } else {
+ switchToListView();
+ }
}
/**
item.setEnabled(false);
}
}
+
+// String.format(mContext.getString(R.string.subject_token),
+// getClient().getCredentials().getUsername(), file.getFileName()));
}
}
-
-
+
/**
- * {@inhericDoc}
+ * {@inheritDoc}
*/
@Override
- public boolean onContextItemSelected (MenuItem item) {
- AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
- mTargetFile = (OCFile) mAdapter.getItem(info.position);
- switch (item.getItemId()) {
+ public boolean onFileActionChosen(int menuId, int filePosition) {
+ mTargetFile = (OCFile) mAdapter.getItem(filePosition);
+ switch (menuId) {
case R.id.action_share_file: {
mContainerActivity.getFileOperationsHelper().shareFileWithLink(mTargetFile);
return true;
OwnCloudVersion version = AccountUtils.getServerVersion(
((FileActivity)mContainerActivity).getAccount());
if (version != null && version.supportsRemoteThumbnails() &&
- imagesCount > 0 && imagesCount == filesCount) {
+ DisplayUtils.isGridView(mFile, mContainerActivity.getStorageManager())) {
switchToGridView();
+ registerLongClickListener();
} else {
switchToListView();
}
import android.annotation.TargetApi;\r
import android.app.Activity;\r
import android.content.Context;\r
-import android.graphics.Color;\r
+import android.content.SharedPreferences;\r
import android.graphics.Point;\r
+ import android.graphics.PorterDuff;\r
import android.os.Build;\r
import android.text.format.DateUtils;\r
import android.view.Display;\r
}\r
\r
/**\r
+ * Determines if user set folder to grid or list view. If folder is not set itself,\r
+ * it finds a parent that is set (at least root is set).\r
+ * @param file\r
+ * @param storageManager\r
+ * @return\r
+ */\r
+ public static boolean isGridView(OCFile file, FileDataStorageManager storageManager){\r
+ if (file != null) {\r
+ OCFile fileToTest = file;\r
+ OCFile parentDir = null;\r
+ String parentPath = null;\r
+\r
+ SharedPreferences setting = MainApp.getAppContext().getSharedPreferences(\r
+ "viewMode", Context.MODE_PRIVATE);\r
+\r
+ if (setting.contains(fileToTest.getRemoteId())) {\r
+ return setting.getBoolean(fileToTest.getRemoteId(), false);\r
+ } else {\r
+ do {\r
+ if (fileToTest.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) {\r
+ parentPath = new File(fileToTest.getRemotePath()).getParent();\r
+ parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath :\r
+ parentPath + OCFile.PATH_SEPARATOR;\r
+ parentDir = storageManager.getFileByPath(parentPath);\r
+ } else {\r
+ parentDir = storageManager.getFileByPath(OCFile.ROOT_PATH);\r
+ }\r
+\r
+ while (parentDir == null) {\r
+ parentPath = new File(parentPath).getParent();\r
+ parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath :\r
+ parentPath + OCFile.PATH_SEPARATOR;\r
+ parentDir = storageManager.getFileByPath(parentPath);\r
+ }\r
+ fileToTest = parentDir;\r
+ } while (endWhile(parentDir, setting));\r
+ return setting.getBoolean(fileToTest.getRemoteId(), false);\r
+ }\r
+ } else {\r
+ return false;\r
+ }\r
+ }\r
+\r
+ private static boolean endWhile(OCFile parentDir, SharedPreferences setting) {\r
+ if (parentDir.getRemotePath().compareToIgnoreCase(OCFile.ROOT_PATH) == 0) {\r
+ return false;\r
+ } else {\r
+ return !setting.contains(parentDir.getRemoteId());\r
+ }\r
+ }\r
+\r
+ public static void setViewMode(OCFile file, boolean setGrid){\r
+ SharedPreferences setting = MainApp.getAppContext().getSharedPreferences(\r
+ "viewMode", Context.MODE_PRIVATE);\r
+\r
+ SharedPreferences.Editor editor = setting.edit();\r
+ editor.putBoolean(file.getRemoteId(), setGrid);\r
+ editor.commit();\r
+ }\r
+\r
++ /**\r
+ * sets the coloring of the given progress bar to color_accent.\r
+ *\r
+ * @param progressBar the progress bar to be colored\r
+ */\r
+ public static void colorPreLollipopHorizontalProgressBar(ProgressBar progressBar) {\r
+ if (progressBar != null && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {\r
+ int color = progressBar.getResources().getColor(R.color.color_accent);\r
+ progressBar.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);\r
+ progressBar.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);\r
+ }\r
+ }\r
+ \r
+ /**\r
+ * sets the coloring of the given seek bar to color_accent.\r
+ *\r
+ * @param seekBar the seek bar to be colored\r
+ */\r
+ public static void colorPreLollipopHorizontalSeekBar(SeekBar seekBar) {\r
+ if (seekBar != null && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {\r
+ colorPreLollipopHorizontalProgressBar(seekBar);\r
+ \r
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {\r
+ int color = seekBar.getResources().getColor(R.color.color_accent);\r
+ seekBar.getThumb().setColorFilter(color, PorterDuff.Mode.SRC_IN);\r
+ seekBar.getThumb().setColorFilter(color, PorterDuff.Mode.SRC_IN);\r
+ }\r
+ }\r
+ }\r
}\r