From: tobiasKaminsky Date: Sun, 23 Aug 2015 16:51:12 +0000 (+0200) Subject: Merge branch 'develop' of github.com:owncloud/android into switchListVsGrid X-Git-Tag: beta-20151122~25^2~7 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/7bd8443c183905a686b8e0c55258c97dcbbbd2fe?hp=-c Merge branch 'develop' of github.com:owncloud/android into switchListVsGrid icon is now always visible --- 7bd8443c183905a686b8e0c55258c97dcbbbd2fe diff --combined owncloud-android-library index dbc8c325,dbc8c325..c8f6e5ad --- a/owncloud-android-library +++ b/owncloud-android-library @@@ -1,1 -1,1 +1,1 @@@ --Subproject commit dbc8c325d74f3f7e8da8236c5abe77a141ae4019 ++Subproject commit c8f6e5ad57ee27fdac39c7b14eb6ab1942a92d49 diff --combined res/drawable-hdpi/ic_view_list.png index 00000000,00000000..64ad8e14 new file mode 100644 Binary files differ diff --combined res/drawable-hdpi/ic_view_module.png index 00000000,00000000..7982e383 new file mode 100644 Binary files differ diff --combined res/drawable-mdpi/ic_view_list.png index 00000000,00000000..4aca55c6 new file mode 100644 Binary files differ diff --combined res/drawable-mdpi/ic_view_module.png index 00000000,00000000..f308a32b new file mode 100644 Binary files differ diff --combined res/drawable-xhdpi/ic_view_list.png index 00000000,00000000..b81d9102 new file mode 100644 Binary files differ diff --combined res/drawable-xhdpi/ic_view_module.png index 00000000,00000000..b3548535 new file mode 100644 Binary files differ diff --combined res/menu/main_menu.xml index 8743512e,236bfd6e..b4316347 --- a/res/menu/main_menu.xml +++ b/res/menu/main_menu.xml @@@ -35,11 -35,6 +35,12 @@@ android:title="@string/actionbar_mkdir" android:contentDescription="@string/actionbar_mkdir"/> + Settings Logs Close + Open General More Accounts @@@ -207,9 -208,9 +208,9 @@@ "Do you really want to remove %1$s?" "Do you really want to remove %1$s and its contents?" Local only - Local contents only - Remove from server - Remote and local + Local only + From server + Remote & local "Removal succeeded" "Removal failed" Enter a new name @@@ -268,8 -269,8 +269,8 @@@ File conflict Which files do you want to keep? If you select both versions, the local file will have a number added to its name. Keep both - Use local version - Use server version + local version + server version Image preview This image cannot be shown @@@ -357,6 -358,5 +358,6 @@@ %1$d files %1$d files, 1 folder %1$d files, %2$d folders - + Switch to grid view + Switch to list view diff --combined src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 10ae9c66,9c1d0661..5df6c61c --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@@ -26,7 -26,7 +26,7 @@@ import android.accounts.Account import android.accounts.AccountManager; import android.accounts.AuthenticatorException; import android.annotation.TargetApi; - import android.app.AlertDialog; + import android.support.v7.app.AlertDialog; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ContentResolver; @@@ -48,12 -48,15 +48,15 @@@ import android.provider.OpenableColumns import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; + import android.support.v4.content.ContextCompat; import android.support.v4.view.GravityCompat; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; - import android.view.Window; + import android.widget.ProgressBar; + import android.widget.RelativeLayout; + import android.widget.TextView; import android.widget.Toast; import com.owncloud.android.MainApp; @@@ -120,6 -123,7 +123,7 @@@ public class FileDisplayActivity extend private boolean mDualPane; private View mLeftFragmentContainer; private View mRightFragmentContainer; + private ProgressBar mProgressBar; private static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW"; private static final String KEY_SYNC_IN_PROGRESS = "SYNC_IN_PROGRESS"; @@@ -146,13 -150,11 +150,12 @@@ private static String DIALOG_CERT_NOT_SAVED = "DIALOG_CERT_NOT_SAVED"; private OCFile mWaitingToSend; + private Menu mOptionsMenu; + - @Override protected void onCreate(Bundle savedInstanceState) { Log_OC.v(TAG, "onCreate() start"); - requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); // this calls onAccountChanged() when ownCloud Account // is valid @@@ -185,6 -187,11 +188,11 @@@ // Navigation Drawer initDrawer(); + mProgressBar = (ProgressBar) findViewById(R.id.progressBar); + mProgressBar.setIndeterminateDrawable( + ContextCompat.getDrawable(this, + R.drawable.actionbar_progress_indeterminate_horizontal)); + mDualPane = getResources().getBoolean(R.bool.large_land_layout); mLeftFragmentContainer = findViewById(R.id.left_fragment_container); mRightFragmentContainer = findViewById(R.id.right_fragment_container); @@@ -197,8 -204,11 +205,11 @@@ // according to the official // documentation - setSupportProgressBarIndeterminateVisibility(mSyncInProgress - /*|| mRefreshSharesInProgress*/); + // enable ActionBar app icon to behave as action to toggle nav drawer + //getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(true); + + mProgressBar.setIndeterminate(mSyncInProgress); // always AFTER setContentView(...) ; to work around bug in its implementation setBackgroundText(); @@@ -210,7 -220,6 +221,6 @@@ protected void onStart() { Log_OC.v(TAG, "onStart() start"); super.onStart(); - getSupportActionBar().setIcon(DisplayUtils.getSeasonalIconId()); Log_OC.v(TAG, "onStart() end"); } @@@ -251,7 -260,16 +261,16 @@@ file = getStorageManager().getFileByPath(OCFile.ROOT_PATH); // never returns null } setFile(file); - + + if (mAccountWasSet) { + RelativeLayout navigationDrawerLayout = (RelativeLayout) findViewById(R.id.left_drawer); + if (navigationDrawerLayout != null && getAccount() != null) { + TextView username = (TextView) navigationDrawerLayout.findViewById(R.id.drawer_username); + int lastAtPos = getAccount().name.lastIndexOf("@"); + username.setText(getAccount().name.substring(0, lastAtPos)); + } + } + if (!stateWasRecovered) { Log_OC.d(TAG, "Initializing Fragments in onAccountChanged.."); initFragmentsWithFile(); @@@ -298,12 -316,6 +317,12 @@@ cleanSecondFragment(); } + if (DisplayUtils.isGridView(getFile(), getStorageManager())){ + switchToGridView(); + } else { + switchToListView(); + } + } else { Log_OC.wtf(TAG, "initFragments() called with invalid NULLs!"); if (getAccount() == null) { @@@ -467,6 -479,6 +486,7 @@@ 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); } @@@ -475,16 -487,6 +495,12 @@@ public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_menu, menu); + mOptionsMenu = menu; + + MenuItem menuItem = mOptionsMenu.findItem(R.id.action_switch_view); + - 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)); - } ++ changeGridIcon(); + return true; } @@@ -552,18 -554,6 +568,23 @@@ builder.create().show(); break; } + case R.id.action_switch_view:{ + if (isGridView()){ - item.setTitle(getApplicationContext().getString(R.string.action_switch_list_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_grid_view)); ++ 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); } @@@ -757,30 -747,27 +778,42 @@@ @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 @@@ -966,8 -953,10 +999,10 @@@ } removeStickyBroadcast(intent); Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress); - setSupportProgressBarIndeterminateVisibility(mSyncInProgress - /*|| mRefreshSharesInProgress*/); + mProgressBar.setIndeterminate(mSyncInProgress); + //mProgressBar.setVisibility((mSyncInProgress) ? View.VISIBLE : View.INVISIBLE); + //setSupportProgressBarIndeterminateVisibility(mSyncInProgress + /*|| mRefreshSharesInProgress*/ //); setBackgroundText(); @@@ -1063,7 -1052,8 +1098,8 @@@ startImagePreview(getFile()); } // TODO what about other kind of previews? } - + + mProgressBar.setIndeterminate(false); } finally { if (intent != null) { removeStickyBroadcast(intent); @@@ -1172,16 -1162,6 +1208,15 @@@ cleanSecondFragment(); // Sync Folder startSyncFolderOperation(directory, false); + + MenuItem menuItem = mOptionsMenu.findItem(R.id.action_switch_view); + ++ changeGridIcon(); + if (DisplayUtils.isGridView(directory, getStorageManager())){ - menuItem.setTitle(getApplicationContext().getString(R.string.action_switch_list_view)); + switchToGridView(); + } else { - menuItem.setTitle(getApplicationContext().getString(R.string.action_switch_grid_view)); + switchToListView(); + } } /** @@@ -1211,7 -1191,6 +1246,6 @@@ } - @Override protected ServiceConnection newTransferenceServiceConnection() { return new ListServiceConnection(); @@@ -1583,8 -1562,7 +1617,7 @@@ getApplicationContext() ); synchFolderOp.execute(getAccount(), MainApp.getAppContext(), this, null, null); - - setSupportProgressBarIndeterminateVisibility(true); + mProgressBar.setIndeterminate(true); setBackgroundText(); } @@@ -1726,13 -1704,6 +1759,13 @@@ private void sortByName(boolean ascending){ getListOfFilesFragment().sortByName(ascending); } + private boolean isGridView(){ return getListOfFilesFragment().isGridView(); } + private void switchToGridView() { + getListOfFilesFragment().switchToGridView(); + } + private void switchToListView() { + getListOfFilesFragment().switchToListView(); + } public void allFilesOption() { browseToRoot(); diff --combined src/com/owncloud/android/ui/fragment/ExtendedListFragment.java index c883ceec,937a50d0..001d48fd --- a/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java +++ b/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java @@@ -97,7 -97,7 +97,7 @@@ public class ExtendedListFragment exten } - protected void switchToGridView() { + public void switchToGridView() { if ((mCurrentListView == mListView)) { mListView.setAdapter(null); @@@ -112,8 -112,8 +112,8 @@@ mCurrentListView = mGridView; } } - - protected void switchToListView() { + + public void switchToListView() { if (mCurrentListView == mGridView) { mGridView.setAdapter(null); mRefreshGridLayout.setVisibility(View.GONE); @@@ -127,13 -127,6 +127,13 @@@ mCurrentListView = mListView; } } + + public boolean isGridView(){ + if (mAdapter instanceof FileListListAdapter) { + return ((FileListListAdapter) mAdapter).isGridMode(); + } + return false; + } @Override @@@ -345,9 -338,9 +345,9 @@@ } private void onCreateSwipeToRefresh(SwipeRefreshLayout refreshLayout) { - // Colors in animations: background - refreshLayout.setColorScheme(R.color.background_color, R.color.background_color, - R.color.background_color, R.color.background_color); + // Colors in animations + refreshLayout.setColorSchemeResources(R.color.color_accent, R.color.primary, + R.color.primary_dark); refreshLayout.setOnRefreshListener(this); } diff --combined src/com/owncloud/android/ui/fragment/OCFileListFragment.java index a33fab38,fbb209e5..ac06fc7e --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@@ -29,11 -29,13 +29,13 @@@ import android.content.Intent import android.os.Bundle; import android.support.v4.widget.SwipeRefreshLayout; import android.view.ContextMenu; + import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.AdapterContextMenuInfo; + import android.widget.PopupMenu; import com.owncloud.android.R; import com.owncloud.android.authentication.AccountUtils; @@@ -48,11 -50,12 +50,12 @@@ import com.owncloud.android.ui.activity import com.owncloud.android.ui.activity.OnEnforceableRefreshListener; import com.owncloud.android.ui.adapter.FileListListAdapter; import com.owncloud.android.ui.dialog.ConfirmationDialogFragment; + import com.owncloud.android.ui.dialog.FileActionsDialogFragment; import com.owncloud.android.ui.dialog.RemoveFileDialogFragment; import com.owncloud.android.ui.dialog.RenameFileDialogFragment; import com.owncloud.android.ui.preview.PreviewImageFragment; import com.owncloud.android.ui.preview.PreviewMediaFragment; -import com.owncloud.android.utils.DialogMenuItem; +import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.FileStorageUtils; /** @@@ -60,7 -63,7 +63,7 @@@ * * TODO refactor to get rid of direct dependency on FileDisplayActivity */ - public class OCFileListFragment extends ExtendedListFragment { + public class OCFileListFragment extends ExtendedListFragment implements FileActionsDialogFragment.FileActionsDialogFragmentListener { private static final String TAG = OCFileListFragment.class.getSimpleName(); @@@ -140,9 -143,62 +143,62 @@@ ); setListAdapter(mAdapter); - registerForContextMenu(); + registerLongClickListener(); } + private void registerLongClickListener() { + getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { + public boolean onItemLongClick(AdapterView arg0, View v, + int index, long arg3) { + showFileAction(index); + return true; + } + }); + } + + + private void showFileAction(int fileIndex) { + Bundle args = getArguments(); + PopupMenu pm = new PopupMenu(getActivity(),null); + Menu menu = pm.getMenu(); + + boolean allowContextualActions = + (args == null) ? true : args.getBoolean(ARG_ALLOW_CONTEXTUAL_ACTIONS, true); + + if (allowContextualActions) { + MenuInflater inflater = getActivity().getMenuInflater(); + + inflater.inflate(R.menu.file_actions_menu, menu); + OCFile targetFile = (OCFile) mAdapter.getItem(fileIndex); + + if (mContainerActivity.getStorageManager() != null) { + FileMenuFilter mf = new FileMenuFilter( + targetFile, + mContainerActivity.getStorageManager().getAccount(), + mContainerActivity, + getActivity() + ); + mf.filter(menu); + } + + /// TODO break this direct dependency on FileDisplayActivity... if possible + MenuItem item = menu.findItem(R.id.action_open_file_with); + FileFragment frag = ((FileDisplayActivity)getActivity()).getSecondFragment(); + if (frag != null && frag instanceof FileDetailFragment && + frag.getFile().getFileId() == targetFile.getFileId()) { + item = menu.findItem(R.id.action_see_details); + if (item != null) { + item.setVisible(false); + item.setEnabled(false); + } + } + + FileActionsDialogFragment dialog = FileActionsDialogFragment.newInstance(menu, fileIndex); + dialog.setTargetFragment(this, 0); + dialog.show(getFragmentManager(), FileActionsDialogFragment.FTAG_FILE_ACTIONS); + } + } + /** * Saves the current listed folder. */ @@@ -155,7 -211,7 +211,7 @@@ /** * Call this, when the user presses the up button. * - * Tries to move up the current folder one level. If the parent folder was removed from the + * Tries to move up the current folder one level. If the parent folder was removed from the * database, it continues browsing up until finding an existing folders. * * return Count of folder levels browsed up. @@@ -244,7 -300,6 +300,6 @@@ @Override public void onCreateContextMenu ( ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, v, menuInfo); Bundle args = getArguments(); boolean allowContextualActions = (args == null) ? true : args.getBoolean(ARG_ALLOW_CONTEXTUAL_ACTIONS, true); @@@ -275,21 -330,16 +330,19 @@@ 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; @@@ -312,14 -362,14 +365,14 @@@ dialog.show(getFragmentManager(), ConfirmationDialogFragment.FTAG_CONFIRMATION); return true; } - case R.id.action_download_file: + case R.id.action_download_file: case R.id.action_sync_file: { mContainerActivity.getFileOperationsHelper().syncFile(mTargetFile); return true; } case R.id.action_cancel_download: case R.id.action_cancel_upload: { - ((FileDisplayActivity)mContainerActivity).cancelTransference(mTargetFile); + ((FileDisplayActivity) mContainerActivity).cancelTransference(mTargetFile); return true; } case R.id.action_see_details: { @@@ -330,8 -380,8 +383,8 @@@ // Obtain the file if (!mTargetFile.isDown()) { // Download the file Log_OC.d(TAG, mTargetFile.getRemotePath() + " : File must be downloaded"); - ((FileDisplayActivity)mContainerActivity).startDownloadForSending(mTargetFile); - + ((FileDisplayActivity) mContainerActivity).startDownloadForSending(mTargetFile); + } else { mContainerActivity.getFileOperationsHelper().sendDownloadedFile(mTargetFile); } @@@ -345,16 -395,30 +398,30 @@@ getActivity().startActivityForResult(action, FileDisplayActivity.ACTION_MOVE_FILES); return true; } - case R.id.action_favorite_file:{ + case R.id.action_favorite_file: { mContainerActivity.getFileOperationsHelper().toggleFavorite(mTargetFile, true); return true; } - case R.id.action_unfavorite_file:{ + case R.id.action_unfavorite_file: { mContainerActivity.getFileOperationsHelper().toggleFavorite(mTargetFile, false); return true; } default: - return super.onContextItemSelected(item); + return false; + } + } + + /** + * {@inhericDoc} + */ + @Override + public boolean onContextItemSelected (MenuItem item) { + AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); + boolean matched = onFileActionChosen(item.getItemId(), ((AdapterContextMenuInfo) item.getMenuInfo()).position); + if(!matched) { + return super.onContextItemSelected(item); + } else { + return matched; } } @@@ -402,7 -466,7 +469,7 @@@ if (directory == null) return; // no files, wait for sync } } - + // If that's not a directory -> List its parent if(!directory.isFolder()){ @@@ -445,8 -509,9 +512,9 @@@ 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(); } @@@ -493,7 -558,6 +561,6 @@@ return output; } - public void sortByName(boolean descending) { mAdapter.setSortOrder(FileStorageUtils.SORT_NAME, descending); } @@@ -505,6 -569,4 +572,4 @@@ public void sortBySize(boolean descending) { mAdapter.setSortOrder(FileStorageUtils.SORT_SIZE, descending); } - - } diff --combined src/com/owncloud/android/utils/DisplayUtils.java index 1662a726,3ae36e44..b835f8b6 --- a/src/com/owncloud/android/utils/DisplayUtils.java +++ b/src/com/owncloud/android/utils/DisplayUtils.java @@@ -22,7 -22,6 +22,7 @@@ package com.owncloud.android.utils; +import java.io.File; import java.net.IDN; import java.text.DateFormat; import java.util.Arrays; @@@ -36,16 -35,18 +36,19 @@@ import java.util.Vector import android.annotation.TargetApi; import android.app.Activity; import android.content.Context; -import android.graphics.Color; +import android.content.SharedPreferences; import android.graphics.Point; + import android.graphics.PorterDuff; import android.os.Build; import android.text.format.DateUtils; import android.view.Display; import android.webkit.MimeTypeMap; + import android.widget.ProgressBar; + import android.widget.SeekBar; import com.owncloud.android.MainApp; import com.owncloud.android.R; +import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; /** @@@ -377,64 -378,32 +380,93 @@@ public class DisplayUtils } /** + * Determines if user set folder to grid or list view. If folder is not set itself, + * it finds a parent that is set (at least root is set). + * @param file + * @param storageManager + * @return + */ + public static boolean isGridView(OCFile file, FileDataStorageManager storageManager){ + if (file != null) { + OCFile fileToTest = file; + OCFile parentDir = null; + String parentPath = null; + + SharedPreferences setting = MainApp.getAppContext().getSharedPreferences( + "viewMode", Context.MODE_PRIVATE); + + if (setting.contains(fileToTest.getRemoteId())) { + return setting.getBoolean(fileToTest.getRemoteId(), false); + } else { + do { + if (fileToTest.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) { + parentPath = new File(fileToTest.getRemotePath()).getParent(); + parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : + parentPath + OCFile.PATH_SEPARATOR; + parentDir = storageManager.getFileByPath(parentPath); + } else { + parentDir = storageManager.getFileByPath(OCFile.ROOT_PATH); + } + + while (parentDir == null) { + parentPath = new File(parentPath).getParent(); + parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : + parentPath + OCFile.PATH_SEPARATOR; + parentDir = storageManager.getFileByPath(parentPath); + } + fileToTest = parentDir; + } while (endWhile(parentDir, setting)); + return setting.getBoolean(fileToTest.getRemoteId(), false); + } + } else { + return false; + } + } + + private static boolean endWhile(OCFile parentDir, SharedPreferences setting) { + if (parentDir.getRemotePath().compareToIgnoreCase(OCFile.ROOT_PATH) == 0) { + return false; + } else { + return !setting.contains(parentDir.getRemoteId()); + } + } + + public static void setViewMode(OCFile file, boolean setGrid){ + SharedPreferences setting = MainApp.getAppContext().getSharedPreferences( + "viewMode", Context.MODE_PRIVATE); + + SharedPreferences.Editor editor = setting.edit(); + editor.putBoolean(file.getRemoteId(), setGrid); + editor.commit(); + } + ++ /** + * sets the coloring of the given progress bar to color_accent. + * + * @param progressBar the progress bar to be colored + */ + public static void colorPreLollipopHorizontalProgressBar(ProgressBar progressBar) { + if (progressBar != null && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + int color = progressBar.getResources().getColor(R.color.color_accent); + progressBar.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN); + progressBar.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN); + } + } + + /** + * sets the coloring of the given seek bar to color_accent. + * + * @param seekBar the seek bar to be colored + */ + public static void colorPreLollipopHorizontalSeekBar(SeekBar seekBar) { + if (seekBar != null && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + colorPreLollipopHorizontalProgressBar(seekBar); + + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + int color = seekBar.getResources().getColor(R.color.color_accent); + seekBar.getThumb().setColorFilter(color, PorterDuff.Mode.SRC_IN); + seekBar.getThumb().setColorFilter(color, PorterDuff.Mode.SRC_IN); + } + } + } }