|
@@ -1,34 +1,40 @@
|
|
|
/**
|
|
|
- * ownCloud Android client application
|
|
|
+ * ownCloud Android client application
|
|
|
*
|
|
|
- * @author Bartek Przybylski
|
|
|
- * @author masensio
|
|
|
- * @author David A. Velasco
|
|
|
- * Copyright (C) 2011 Bartek Przybylski
|
|
|
- * Copyright (C) 2016 ownCloud Inc.
|
|
|
+ * @author Bartek Przybylski
|
|
|
+ * @author masensio
|
|
|
+ * @author David A. Velasco
|
|
|
+ * Copyright (C) 2011 Bartek Przybylski
|
|
|
+ * Copyright (C) 2016 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 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 <http://www.gnu.org/licenses/>.
|
|
|
+ * 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 <http://www.gnu.org/licenses/>.
|
|
|
*/
|
|
|
package com.owncloud.android.ui.fragment;
|
|
|
|
|
|
+import android.accounts.Account;
|
|
|
+import android.accounts.AuthenticatorException;
|
|
|
+import android.accounts.OperationCanceledException;
|
|
|
import android.app.Activity;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.content.SharedPreferences;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Looper;
|
|
|
import android.preference.PreferenceManager;
|
|
|
+import android.support.annotation.NonNull;
|
|
|
+import android.support.design.widget.BottomNavigationView;
|
|
|
import android.support.v4.widget.DrawerLayout;
|
|
|
import android.support.v4.widget.SwipeRefreshLayout;
|
|
|
import android.util.SparseBooleanArray;
|
|
@@ -42,6 +48,7 @@ import android.view.ViewGroup;
|
|
|
import android.widget.AbsListView;
|
|
|
import android.widget.AdapterView;
|
|
|
import android.widget.ListView;
|
|
|
+import android.widget.RelativeLayout;
|
|
|
import android.widget.TextView;
|
|
|
import android.widget.Toast;
|
|
|
|
|
@@ -51,7 +58,14 @@ import com.owncloud.android.authentication.AccountUtils;
|
|
|
import com.owncloud.android.datamodel.FileDataStorageManager;
|
|
|
import com.owncloud.android.datamodel.OCFile;
|
|
|
import com.owncloud.android.files.FileMenuFilter;
|
|
|
+import com.owncloud.android.lib.common.OwnCloudAccount;
|
|
|
+import com.owncloud.android.lib.common.OwnCloudClient;
|
|
|
+import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
|
|
+import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
|
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
|
|
+import com.owncloud.android.lib.resources.files.SearchOperation;
|
|
|
+import com.owncloud.android.lib.resources.files.ToggleFavoriteOperation;
|
|
|
+import com.owncloud.android.lib.resources.shares.GetRemoteSharesOperation;
|
|
|
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
|
|
import com.owncloud.android.ui.activity.FileActivity;
|
|
|
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
|
@@ -63,15 +77,26 @@ import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
|
|
|
import com.owncloud.android.ui.dialog.CreateFolderDialogFragment;
|
|
|
import com.owncloud.android.ui.dialog.RemoveFilesDialogFragment;
|
|
|
import com.owncloud.android.ui.dialog.RenameFileDialogFragment;
|
|
|
+import com.owncloud.android.ui.events.ChangeMenuEvent;
|
|
|
+import com.owncloud.android.ui.events.DummyDrawerEvent;
|
|
|
+import com.owncloud.android.ui.events.FavoriteEvent;
|
|
|
+import com.owncloud.android.ui.events.MenuItemClickEvent;
|
|
|
+import com.owncloud.android.ui.events.SearchEvent;
|
|
|
import com.owncloud.android.ui.helpers.SparseBooleanArrayParcelable;
|
|
|
-import com.owncloud.android.ui.interfaces.ExtendedListFragmentInterface;
|
|
|
+import com.owncloud.android.ui.interfaces.OCFileListFragmentInterface;
|
|
|
import com.owncloud.android.ui.preview.PreviewImageFragment;
|
|
|
import com.owncloud.android.ui.preview.PreviewMediaFragment;
|
|
|
import com.owncloud.android.ui.preview.PreviewTextFragment;
|
|
|
import com.owncloud.android.utils.DisplayUtils;
|
|
|
import com.owncloud.android.utils.FileStorageUtils;
|
|
|
|
|
|
+import org.greenrobot.eventbus.EventBus;
|
|
|
+import org.greenrobot.eventbus.Subscribe;
|
|
|
+import org.greenrobot.eventbus.ThreadMode;
|
|
|
+import org.parceler.Parcels;
|
|
|
+
|
|
|
import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -80,7 +105,7 @@ import java.util.List;
|
|
|
*
|
|
|
* TODO refactor to get rid of direct dependency on FileDisplayActivity
|
|
|
*/
|
|
|
-public class OCFileListFragment extends ExtendedListFragment implements ExtendedListFragmentInterface {
|
|
|
+public class OCFileListFragment extends ExtendedListFragment implements OCFileListFragmentInterface {
|
|
|
|
|
|
private static final String TAG = OCFileListFragment.class.getSimpleName();
|
|
|
|
|
@@ -94,6 +119,8 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
private static final String KEY_FILE = MY_PACKAGE + ".extra.FILE";
|
|
|
private static final String KEY_FAB_EVER_CLICKED = "FAB_EVER_CLICKED";
|
|
|
|
|
|
+ private static final String KEY_CURRENT_SEARCH_TYPE = "CURRENT_SEARCH_TYPE";
|
|
|
+
|
|
|
private static final String GRID_IS_PREFERED_PREFERENCE = "gridIsPrefered";
|
|
|
|
|
|
private static final String DIALOG_CREATE_FOLDER = "DIALOG_CREATE_FOLDER";
|
|
@@ -116,6 +143,19 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
private ActionMode mActiveActionMode;
|
|
|
private OCFileListFragment.MultiChoiceModeListener mMultiChoiceModeListener;
|
|
|
|
|
|
+ private BottomNavigationView bottomNavigationView;
|
|
|
+
|
|
|
+ private SearchType currentSearchType;
|
|
|
+
|
|
|
+ private enum MenuItemAddRemove {
|
|
|
+ DO_NOTHING, REMOVE_SORT, REMOVE_GRID_AND_SORT, ADD_SORT, ADD_GRID_AND_SORT, ADD_GRID_AND_SORT_WITH_SEARCH,
|
|
|
+ REMOVE_SEARCH
|
|
|
+ }
|
|
|
+
|
|
|
+ private MenuItemAddRemove menuItemAddRemoveValue = MenuItemAddRemove.DO_NOTHING;
|
|
|
+
|
|
|
+ private ArrayList<MenuItem> mOriginalMenuItems = new ArrayList<>();
|
|
|
+
|
|
|
@Override
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
@@ -157,6 +197,36 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
Log_OC.i(TAG, "onCreateView() start");
|
|
|
View v = super.onCreateView(inflater, container, savedInstanceState);
|
|
|
+ bottomNavigationView = (BottomNavigationView) v.findViewById(R.id.bottom_navigation_view);
|
|
|
+
|
|
|
+ if (savedInstanceState != null) {
|
|
|
+ currentSearchType = Parcels.unwrap(savedInstanceState.getParcelable(KEY_CURRENT_SEARCH_TYPE));
|
|
|
+ } else {
|
|
|
+ currentSearchType = SearchType.NO_SEARCH;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (getResources().getBoolean(R.bool.bottom_toolbar_enabled)) {
|
|
|
+ bottomNavigationView.setVisibility(View.VISIBLE);
|
|
|
+ prepareBottomNavigationView();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!getResources().getBoolean(R.bool.bottom_toolbar_enabled) || savedInstanceState != null) {
|
|
|
+
|
|
|
+ final View fabView = v.findViewById(R.id.fab_main);
|
|
|
+ final RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)
|
|
|
+ fabView.getLayoutParams();
|
|
|
+ layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 1);
|
|
|
+ Handler handler = new Handler();
|
|
|
+ handler.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ fabView.setLayoutParams(layoutParams);
|
|
|
+ fabView.invalidate();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
Bundle args = getArguments();
|
|
|
boolean allowContextualActions = (args != null) && args.getBoolean(ARG_ALLOW_CONTEXTUAL_ACTIONS, false);
|
|
|
if (allowContextualActions) {
|
|
@@ -166,6 +236,48 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
return v;
|
|
|
}
|
|
|
|
|
|
+ private void prepareBottomNavigationView() {
|
|
|
+ if (getResources().getBoolean(R.bool.use_home)) {
|
|
|
+ bottomNavigationView.getMenu().findItem(R.id.nav_bar_files).setTitle(getResources().
|
|
|
+ getString(R.string.drawer_item_home));
|
|
|
+ bottomNavigationView.getMenu().findItem(R.id.nav_bar_files).setIcon(R.drawable.ic_home);
|
|
|
+ }
|
|
|
+
|
|
|
+ bottomNavigationView.setOnNavigationItemSelectedListener(
|
|
|
+ new BottomNavigationView.OnNavigationItemSelectedListener() {
|
|
|
+ @Override
|
|
|
+ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
|
|
+ switch (item.getItemId()) {
|
|
|
+ case R.id.nav_bar_files:
|
|
|
+ EventBus.getDefault().post(new MenuItemClickEvent(item));
|
|
|
+ menuItemAddRemoveValue = MenuItemAddRemove.ADD_GRID_AND_SORT_WITH_SEARCH;
|
|
|
+ if (getActivity() != null) {
|
|
|
+ getActivity().invalidateOptionsMenu();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case R.id.nav_bar_favorites:
|
|
|
+ EventBus.getDefault().post(new SearchEvent("", SearchOperation.SearchType.FAVORITE_SEARCH,
|
|
|
+ SearchEvent.UnsetType.UNSET_DRAWER));
|
|
|
+ break;
|
|
|
+ case R.id.nav_bar_photos:
|
|
|
+ EventBus.getDefault().post(new SearchEvent("image/%",
|
|
|
+ SearchOperation.SearchType.CONTENT_TYPE_SEARCH, SearchEvent.UnsetType.UNSET_DRAWER));
|
|
|
+ break;
|
|
|
+ case R.id.nav_bar_settings:
|
|
|
+ EventBus.getDefault().post(new MenuItemClickEvent(item));
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public void onDetach() {
|
|
@@ -211,12 +323,12 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
|
|
|
// detect if a mini FAB has ever been clicked
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
|
|
- if(prefs.getLong(KEY_FAB_EVER_CLICKED, 0) > 0) {
|
|
|
+ if (prefs.getLong(KEY_FAB_EVER_CLICKED, 0) > 0) {
|
|
|
miniFabClicked = true;
|
|
|
}
|
|
|
|
|
|
// add labels to the min FABs when none of them has ever been clicked on
|
|
|
- if(!miniFabClicked) {
|
|
|
+ if (!miniFabClicked) {
|
|
|
setFabLabels();
|
|
|
} else {
|
|
|
removeFabLabels();
|
|
@@ -328,13 +440,13 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
/**
|
|
|
* records a click on a mini FAB and thus:
|
|
|
* <ol>
|
|
|
- * <li>persists the click fact</li>
|
|
|
- * <li>removes the mini FAB labels</li>
|
|
|
+ * <li>persists the click fact</li>
|
|
|
+ * <li>removes the mini FAB labels</li>
|
|
|
* </ol>
|
|
|
*/
|
|
|
private void recordMiniFabClick() {
|
|
|
// only record if it hasn't been done already at some other time
|
|
|
- if(!miniFabClicked) {
|
|
|
+ if (!miniFabClicked) {
|
|
|
final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
|
|
sp.edit().putLong(KEY_FAB_EVER_CLICKED, 1).apply();
|
|
|
miniFabClicked = true;
|
|
@@ -370,7 +482,7 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
* and closed.
|
|
|
*/
|
|
|
private class MultiChoiceModeListener
|
|
|
- implements AbsListView.MultiChoiceModeListener, DrawerLayout.DrawerListener {
|
|
|
+ implements AbsListView.MultiChoiceModeListener, DrawerLayout.DrawerListener {
|
|
|
|
|
|
private static final String KEY_ACTION_MODE_CLOSED_BY_DRAWER = "KILLED_ACTION_MODE";
|
|
|
private static final String KEY_SELECTION_WHEN_CLOSED_BY_DRAWER = "CHECKED_ITEMS";
|
|
@@ -399,16 +511,16 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
* When the navigation drawer is closed, action mode is recovered in the same state as was
|
|
|
* when the drawer was (started to be) opened.
|
|
|
*
|
|
|
- * @param drawerView Navigation drawer just closed.
|
|
|
+ * @param drawerView Navigation drawer just closed.
|
|
|
*/
|
|
|
@Override
|
|
|
public void onDrawerClosed(View drawerView) {
|
|
|
- if (mSelectionWhenActionModeClosedByDrawer !=null && mActionModeClosedByDrawer) {
|
|
|
- for (int i = 0; i< mSelectionWhenActionModeClosedByDrawer.size(); i++) {
|
|
|
+ if (mSelectionWhenActionModeClosedByDrawer != null && mActionModeClosedByDrawer) {
|
|
|
+ for (int i = 0; i < mSelectionWhenActionModeClosedByDrawer.size(); i++) {
|
|
|
if (mSelectionWhenActionModeClosedByDrawer.valueAt(i)) {
|
|
|
getListView().setItemChecked(
|
|
|
- mSelectionWhenActionModeClosedByDrawer.keyAt(i),
|
|
|
- true
|
|
|
+ mSelectionWhenActionModeClosedByDrawer.keyAt(i),
|
|
|
+ true
|
|
|
);
|
|
|
}
|
|
|
}
|
|
@@ -420,7 +532,7 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
* If the action mode is active when the navigation drawer starts to move, the action
|
|
|
* mode is closed and the selection stored to be recovered when the drawer is closed.
|
|
|
*
|
|
|
- * @param newState One of STATE_IDLE, STATE_DRAGGING or STATE_SETTLING.
|
|
|
+ * @param newState One of STATE_IDLE, STATE_DRAGGING or STATE_SETTLING.
|
|
|
*/
|
|
|
@Override
|
|
|
public void onDrawerStateChanged(int newState) {
|
|
@@ -470,16 +582,16 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
List<OCFile> checkedFiles = mAdapter.getCheckedItems(getListView());
|
|
|
final int checkedCount = checkedFiles.size();
|
|
|
String title = getResources().getQuantityString(
|
|
|
- R.plurals.items_selected_count,
|
|
|
- checkedCount,
|
|
|
- checkedCount
|
|
|
+ R.plurals.items_selected_count,
|
|
|
+ checkedCount,
|
|
|
+ checkedCount
|
|
|
);
|
|
|
mode.setTitle(title);
|
|
|
FileMenuFilter mf = new FileMenuFilter(
|
|
|
- checkedFiles,
|
|
|
- ((FileActivity) getActivity()).getAccount(),
|
|
|
- mContainerActivity,
|
|
|
- getActivity()
|
|
|
+ checkedFiles,
|
|
|
+ ((FileActivity) getActivity()).getAccount(),
|
|
|
+ mContainerActivity,
|
|
|
+ getActivity()
|
|
|
);
|
|
|
mf.filter(menu);
|
|
|
return true;
|
|
@@ -505,7 +617,7 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
DisplayUtils.colorToolbarProgressBar(getActivity(), mProgressBarColor);
|
|
|
|
|
|
// show FAB on multi selection mode exit
|
|
|
- if(!mHideFab) {
|
|
|
+ if (!mHideFab) {
|
|
|
setFabEnabled(true);
|
|
|
}
|
|
|
}
|
|
@@ -515,7 +627,7 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
outState.putBoolean(KEY_ACTION_MODE_CLOSED_BY_DRAWER, mActionModeClosedByDrawer);
|
|
|
if (mSelectionWhenActionModeClosedByDrawer != null) {
|
|
|
SparseBooleanArrayParcelable sbap = new SparseBooleanArrayParcelable(
|
|
|
- mSelectionWhenActionModeClosedByDrawer
|
|
|
+ mSelectionWhenActionModeClosedByDrawer
|
|
|
);
|
|
|
outState.putParcelable(KEY_SELECTION_WHEN_CLOSED_BY_DRAWER, sbap);
|
|
|
}
|
|
@@ -523,11 +635,11 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
|
|
|
public void loadStateFrom(Bundle savedInstanceState) {
|
|
|
mActionModeClosedByDrawer = savedInstanceState.getBoolean(
|
|
|
- KEY_ACTION_MODE_CLOSED_BY_DRAWER,
|
|
|
- mActionModeClosedByDrawer
|
|
|
+ KEY_ACTION_MODE_CLOSED_BY_DRAWER,
|
|
|
+ mActionModeClosedByDrawer
|
|
|
);
|
|
|
SparseBooleanArrayParcelable sbap = savedInstanceState.getParcelable(
|
|
|
- KEY_SELECTION_WHEN_CLOSED_BY_DRAWER
|
|
|
+ KEY_SELECTION_WHEN_CLOSED_BY_DRAWER
|
|
|
);
|
|
|
if (sbap != null) {
|
|
|
mSelectionWhenActionModeClosedByDrawer = sbap.getSparseBooleanArray();
|
|
@@ -544,7 +656,7 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
mMultiChoiceModeListener.loadStateFrom(savedInstanceState);
|
|
|
}
|
|
|
setMultiChoiceModeListener(mMultiChoiceModeListener);
|
|
|
- ((FileActivity)getActivity()).addDrawerListener(mMultiChoiceModeListener);
|
|
|
+ ((FileActivity) getActivity()).addDrawerListener(mMultiChoiceModeListener);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -554,12 +666,74 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
public void onSaveInstanceState(Bundle outState) {
|
|
|
super.onSaveInstanceState(outState);
|
|
|
outState.putParcelable(KEY_FILE, mFile);
|
|
|
+ outState.putParcelable(KEY_CURRENT_SEARCH_TYPE, Parcels.wrap(currentSearchType));
|
|
|
mMultiChoiceModeListener.storeStateIn(outState);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void onPrepareOptionsMenu (Menu menu) {
|
|
|
+ public void onPrepareOptionsMenu(Menu menu) {
|
|
|
+ Menu mMenu = menu;
|
|
|
+
|
|
|
+ if (mOriginalMenuItems.size() == 0) {
|
|
|
+ mOriginalMenuItems.add(mMenu.findItem(R.id.action_switch_view));
|
|
|
+ mOriginalMenuItems.add(mMenu.findItem(R.id.action_sort));
|
|
|
+ mOriginalMenuItems.add(mMenu.findItem(R.id.action_search));
|
|
|
+ }
|
|
|
+
|
|
|
changeGridIcon(menu); // this is enough if the option stays out of the action bar
|
|
|
+
|
|
|
+ MenuItem menuItemOrig;
|
|
|
+
|
|
|
+ if (menuItemAddRemoveValue.equals(MenuItemAddRemove.ADD_SORT)) {
|
|
|
+ if (menu.findItem(R.id.action_sort) == null) {
|
|
|
+ menuItemOrig = mOriginalMenuItems.get(1);
|
|
|
+ menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(),
|
|
|
+ menuItemOrig.getTitle());
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (menuItemAddRemoveValue.equals(MenuItemAddRemove.ADD_GRID_AND_SORT))
|
|
|
+
|
|
|
+ {
|
|
|
+ if (menu.findItem(R.id.action_switch_view) == null) {
|
|
|
+ menuItemOrig = mOriginalMenuItems.get(0);
|
|
|
+ menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(),
|
|
|
+ menuItemOrig.getTitle());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (menu.findItem(R.id.action_sort) == null) {
|
|
|
+ menuItemOrig = mOriginalMenuItems.get(1);
|
|
|
+ menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(),
|
|
|
+ menuItemOrig.getTitle());
|
|
|
+ }
|
|
|
+ } else if (menuItemAddRemoveValue.equals(MenuItemAddRemove.REMOVE_SEARCH)) {
|
|
|
+ menu.removeItem(R.id.action_search);
|
|
|
+ } else if (menuItemAddRemoveValue.equals(MenuItemAddRemove.ADD_GRID_AND_SORT_WITH_SEARCH)) {
|
|
|
+ if (menu.findItem(R.id.action_switch_view) == null) {
|
|
|
+ menuItemOrig = mOriginalMenuItems.get(0);
|
|
|
+ menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(),
|
|
|
+ menuItemOrig.getTitle());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (menu.findItem(R.id.action_sort) == null) {
|
|
|
+ menuItemOrig = mOriginalMenuItems.get(1);
|
|
|
+ menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(),
|
|
|
+ menuItemOrig.getTitle());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (menu.findItem(R.id.action_search) == null) {
|
|
|
+ menuItemOrig = mOriginalMenuItems.get(2);
|
|
|
+ menu.add(menuItemOrig.getGroupId(), menuItemOrig.getItemId(), menuItemOrig.getOrder(),
|
|
|
+ menuItemOrig.getTitle());
|
|
|
+ }
|
|
|
+ } else if (menuItemAddRemoveValue.equals(MenuItemAddRemove.REMOVE_SORT)) {
|
|
|
+ menu.removeItem(R.id.action_sort);
|
|
|
+ menu.removeItem(R.id.action_search);
|
|
|
+ } else if (menuItemAddRemoveValue.equals(MenuItemAddRemove.REMOVE_GRID_AND_SORT)) {
|
|
|
+ menu.removeItem(R.id.action_sort);
|
|
|
+ menu.removeItem(R.id.action_switch_view);
|
|
|
+ menu.removeItem(R.id.action_search);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -611,6 +785,7 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
@Override
|
|
|
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
|
|
|
OCFile file = (OCFile) mAdapter.getItem(position);
|
|
|
+
|
|
|
if (file != null) {
|
|
|
if (file.isFolder()) {
|
|
|
// update state and view of this fragment
|
|
@@ -623,9 +798,9 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
} else { /// Click on a file
|
|
|
if (PreviewImageFragment.canBePreviewed(file)) {
|
|
|
// preview image - it handles the download, if needed
|
|
|
- ((FileDisplayActivity)mContainerActivity).startImagePreview(file);
|
|
|
- } else if (PreviewTextFragment.canBePreviewed(file)){
|
|
|
- ((FileDisplayActivity)mContainerActivity).startTextPreview(file);
|
|
|
+ ((FileDisplayActivity) mContainerActivity).startImagePreview(file);
|
|
|
+ } else if (PreviewTextFragment.canBePreviewed(file)) {
|
|
|
+ ((FileDisplayActivity) mContainerActivity).startTextPreview(file);
|
|
|
} else if (file.isDown()) {
|
|
|
if (PreviewMediaFragment.canBePreviewed(file)) {
|
|
|
// media preview
|
|
@@ -650,8 +825,8 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
/**
|
|
|
* Start the appropriate action(s) on the currently selected files given menu selected by the user.
|
|
|
*
|
|
|
- * @param menuId Identifier of the action menu selected by the user
|
|
|
- * @return 'true' if the menu selection started any action, 'false' otherwise.
|
|
|
+ * @param menuId Identifier of the action menu selected by the user
|
|
|
+ * @return 'true' if the menu selection started any action, 'false' otherwise.
|
|
|
*/
|
|
|
public boolean onFileActionChosen(int menuId) {
|
|
|
final ArrayList<OCFile> checkedFiles = mAdapter.getCheckedItems(getListView());
|
|
@@ -713,12 +888,20 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
((FileDisplayActivity) mContainerActivity).cancelTransference(checkedFiles);
|
|
|
return true;
|
|
|
}
|
|
|
- case R.id.action_favorite_file: {
|
|
|
- mContainerActivity.getFileOperationsHelper().toggleFavorites(checkedFiles, true);
|
|
|
+ case R.id.action_keep_files_offline: {
|
|
|
+ mContainerActivity.getFileOperationsHelper().toogleOfflineFiles(checkedFiles, true);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ case R.id.action_unset_keep_files_offline: {
|
|
|
+ mContainerActivity.getFileOperationsHelper().toogleOfflineFiles(checkedFiles, false);
|
|
|
return true;
|
|
|
}
|
|
|
- case R.id.action_unfavorite_file: {
|
|
|
- mContainerActivity.getFileOperationsHelper().toggleFavorites(checkedFiles, false);
|
|
|
+ case R.id.action_favorite: {
|
|
|
+ mContainerActivity.getFileOperationsHelper().toggleFavoriteFiles(checkedFiles, true);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ case R.id.action_unset_favorite: {
|
|
|
+ mContainerActivity.getFileOperationsHelper().toggleFavoriteFiles(checkedFiles, false);
|
|
|
return true;
|
|
|
}
|
|
|
case R.id.action_move: {
|
|
@@ -752,11 +935,11 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
/**
|
|
|
* Calls {@link OCFileListFragment#listDirectory(OCFile, boolean, boolean)} with a null parameter
|
|
|
*/
|
|
|
- public void listDirectory(boolean onlyOnDevice, boolean fromSearch){
|
|
|
+ public void listDirectory(boolean onlyOnDevice, boolean fromSearch) {
|
|
|
listDirectory(null, onlyOnDevice, fromSearch);
|
|
|
}
|
|
|
|
|
|
- public void refreshDirectory(){
|
|
|
+ public void refreshDirectory() {
|
|
|
listDirectory(getCurrentFile(), MainApp.isOnlyOnDevice(), false);
|
|
|
}
|
|
|
|
|
@@ -846,7 +1029,7 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
updateFooter();
|
|
|
// decide grid vs list view
|
|
|
OwnCloudVersion version = AccountUtils.getServerVersion(
|
|
|
- ((FileActivity)mContainerActivity).getAccount());
|
|
|
+ ((FileActivity) mContainerActivity).getAccount());
|
|
|
if (version != null && version.supportsRemoteThumbnails() &&
|
|
|
isGridViewPreferred(mFile)) {
|
|
|
switchToGridView();
|
|
@@ -858,7 +1041,7 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
}
|
|
|
|
|
|
private void invalidateActionMode() {
|
|
|
- if(mActiveActionMode != null){
|
|
|
+ if (mActiveActionMode != null) {
|
|
|
mActiveActionMode.invalidate();
|
|
|
}
|
|
|
}
|
|
@@ -918,10 +1101,11 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
/**
|
|
|
* 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 Folder to check.
|
|
|
- * @return 'true' is folder should be shown in grid mode, 'false' if list mode is preferred.
|
|
|
+ *
|
|
|
+ * @param file Folder to check.
|
|
|
+ * @return 'true' is folder should be shown in grid mode, 'false' if list mode is preferred.
|
|
|
*/
|
|
|
- public boolean isGridViewPreferred(OCFile file){
|
|
|
+ public boolean isGridViewPreferred(OCFile file) {
|
|
|
if (file != null) {
|
|
|
OCFile fileToTest = file;
|
|
|
OCFile parentDir;
|
|
@@ -969,14 +1153,16 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void changeGridIcon(Menu menu){
|
|
|
+ private void changeGridIcon(Menu menu) {
|
|
|
MenuItem menuItem = menu.findItem(R.id.action_switch_view);
|
|
|
- if (isGridViewPreferred(mFile)){
|
|
|
- menuItem.setTitle(getString(R.string.action_switch_list_view));
|
|
|
- menuItem.setIcon(R.drawable.ic_view_list);
|
|
|
- } else {
|
|
|
- menuItem.setTitle(getString(R.string.action_switch_grid_view));
|
|
|
- menuItem.setIcon(R.drawable.ic_view_module);
|
|
|
+ if (menuItem != null) {
|
|
|
+ if (isGridViewPreferred(mFile)) {
|
|
|
+ menuItem.setTitle(getString(R.string.action_switch_list_view));
|
|
|
+ menuItem.setIcon(R.drawable.ic_view_list);
|
|
|
+ } else {
|
|
|
+ menuItem.setTitle(getString(R.string.action_switch_grid_view));
|
|
|
+ menuItem.setIcon(R.drawable.ic_view_module);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -990,7 +1176,7 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
switchToGridView();
|
|
|
}
|
|
|
|
|
|
- private void saveGridAsPreferred(boolean setGrid){
|
|
|
+ private void saveGridAsPreferred(boolean setGrid) {
|
|
|
SharedPreferences setting = getActivity().getSharedPreferences(
|
|
|
GRID_IS_PREFERED_PREFERENCE, Context.MODE_PRIVATE
|
|
|
);
|
|
@@ -999,4 +1185,194 @@ public class OCFileListFragment extends ExtendedListFragment implements Extended
|
|
|
editor.putBoolean(String.valueOf(mFile.getFileId()), setGrid);
|
|
|
editor.apply();
|
|
|
}
|
|
|
+
|
|
|
+ private void unsetAllMenuItems(final boolean unsetDrawer) {
|
|
|
+ new Handler(Looper.getMainLooper()).post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ if (unsetDrawer) {
|
|
|
+ EventBus.getDefault().post(new DummyDrawerEvent());
|
|
|
+ } else {
|
|
|
+ if (bottomNavigationView != null) {
|
|
|
+ bottomNavigationView.getMenu().findItem(R.id.nav_bar_files).setChecked(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
+ public void onMessageEvent(ChangeMenuEvent changeMenuEvent) {
|
|
|
+ menuItemAddRemoveValue = MenuItemAddRemove.ADD_GRID_AND_SORT_WITH_SEARCH;
|
|
|
+ if (getActivity() != null) {
|
|
|
+ getActivity().invalidateOptionsMenu();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Subscribe(threadMode = ThreadMode.BACKGROUND)
|
|
|
+ public void onMessageEvent(FavoriteEvent event) {
|
|
|
+ Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(MainApp.getAppContext());
|
|
|
+
|
|
|
+ OwnCloudAccount ocAccount = null;
|
|
|
+ try {
|
|
|
+ ocAccount = new OwnCloudAccount(
|
|
|
+ currentAccount,
|
|
|
+ MainApp.getAppContext()
|
|
|
+ );
|
|
|
+
|
|
|
+ OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
|
|
|
+ getClientFor(ocAccount, MainApp.getAppContext());
|
|
|
+
|
|
|
+ ToggleFavoriteOperation toggleFavoriteOperation = new ToggleFavoriteOperation(event.shouldFavorite,
|
|
|
+ event.remotePath);
|
|
|
+ RemoteOperationResult remoteOperationResult = toggleFavoriteOperation.execute(mClient);
|
|
|
+
|
|
|
+ if (remoteOperationResult.isSuccess()) {
|
|
|
+ mAdapter.setFavoriteAttributeForItemID(event.remoteId, event.shouldFavorite);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
|
|
|
+ Log_OC.e(TAG, "Account not found", e);
|
|
|
+ } catch (AuthenticatorException e) {
|
|
|
+ Log_OC.e(TAG, "Authentication failed", e);
|
|
|
+ } catch (IOException e) {
|
|
|
+ Log_OC.e(TAG, "IO error", e);
|
|
|
+ } catch (OperationCanceledException e) {
|
|
|
+ Log_OC.e(TAG, "Operation has been canceled", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Subscribe(threadMode = ThreadMode.BACKGROUND)
|
|
|
+ public void onMessageEvent(SearchEvent event) {
|
|
|
+ setEmptyListLoadingMessage();
|
|
|
+ mAdapter.setData(new ArrayList<>(), SearchType.NO_SEARCH);
|
|
|
+
|
|
|
+ if (event.getUnsetType().equals(SearchEvent.UnsetType.UNSET_BOTTOM_NAV_BAR)) {
|
|
|
+ unsetAllMenuItems(false);
|
|
|
+ } else if (event.getUnsetType().equals(SearchEvent.UnsetType.UNSET_DRAWER)) {
|
|
|
+ unsetAllMenuItems(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (event.getSearchType().equals(SearchOperation.SearchType.FILE_SEARCH)) {
|
|
|
+ currentSearchType = SearchType.FILE_SEARCH;
|
|
|
+
|
|
|
+ } else if (event.getSearchType().equals(SearchOperation.SearchType.CONTENT_TYPE_SEARCH)) {
|
|
|
+ if (event.getSearchQuery().equals("image/%")) {
|
|
|
+ currentSearchType = SearchType.PHOTO_SEARCH;
|
|
|
+ } else if (event.getSearchQuery().equals("video/%")) {
|
|
|
+ currentSearchType = SearchType.VIDEO_SEARCH;
|
|
|
+ }
|
|
|
+ } else if (event.getSearchType().equals(SearchOperation.SearchType.FAVORITE_SEARCH)) {
|
|
|
+ currentSearchType = SearchType.FAVORITE_SEARCH;
|
|
|
+ } else if (event.getSearchType().equals(SearchOperation.SearchType.RECENTLY_ADDED_SEARCH)) {
|
|
|
+ currentSearchType = SearchType.RECENTLY_ADDED_SEARCH;
|
|
|
+ } else if (event.getSearchType().equals(SearchOperation.SearchType.RECENTLY_MODIFIED_SEARCH)) {
|
|
|
+ currentSearchType = SearchType.RECENTLY_MODIFIED_SEARCH;
|
|
|
+ } else if (event.getSearchType().equals(SearchOperation.SearchType.SHARED_SEARCH)) {
|
|
|
+ currentSearchType = SearchType.SHARED_FILTER;
|
|
|
+ }
|
|
|
+
|
|
|
+ Runnable switchViewsRunnable = new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ if (isGridViewPreferred(mFile) && !isGridEnabled()) {
|
|
|
+ switchToGridView();
|
|
|
+ } else if (!isGridViewPreferred(mFile) && isGridEnabled()) {
|
|
|
+ switchToListView();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(MainApp.getAppContext());
|
|
|
+
|
|
|
+ try {
|
|
|
+ OwnCloudAccount ocAccount = new OwnCloudAccount(
|
|
|
+ currentAccount,
|
|
|
+ MainApp.getAppContext()
|
|
|
+ );
|
|
|
+
|
|
|
+ OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
|
|
|
+ getClientFor(ocAccount, MainApp.getAppContext());
|
|
|
+ if (!currentSearchType.equals(SearchType.SHARED_FILTER)) {
|
|
|
+ SearchOperation operation = new SearchOperation(event.getSearchQuery(), event.getSearchType());
|
|
|
+ RemoteOperationResult remoteOperationResult = operation.execute(mClient);
|
|
|
+ if (remoteOperationResult.isSuccess() && remoteOperationResult.getData() != null) {
|
|
|
+ mAdapter.setData(remoteOperationResult.getData(), currentSearchType);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ GetRemoteSharesOperation operation = new GetRemoteSharesOperation();
|
|
|
+ RemoteOperationResult remoteOperationResult = operation.execute(mClient);
|
|
|
+ if (remoteOperationResult.isSuccess() && remoteOperationResult.getData() != null) {
|
|
|
+ mAdapter.setData(remoteOperationResult.getData(), currentSearchType);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (event.getSearchType().equals(SearchOperation.SearchType.FILE_SEARCH)) {
|
|
|
+ setEmptyListMessage(SearchType.FILE_SEARCH);
|
|
|
+
|
|
|
+ } else if (event.getSearchType().equals(SearchOperation.SearchType.CONTENT_TYPE_SEARCH)) {
|
|
|
+ if (event.getSearchQuery().equals("image/%")) {
|
|
|
+ setEmptyListMessage(SearchType.PHOTO_SEARCH);
|
|
|
+ menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_GRID_AND_SORT;
|
|
|
+ } else if (event.getSearchQuery().equals("video/%")) {
|
|
|
+ setEmptyListMessage(SearchType.VIDEO_SEARCH);
|
|
|
+ menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SEARCH;
|
|
|
+ }
|
|
|
+ } else if (event.getSearchType().equals(SearchOperation.SearchType.FAVORITE_SEARCH)) {
|
|
|
+ setEmptyListMessage(SearchType.FAVORITE_SEARCH);
|
|
|
+ menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SORT;
|
|
|
+ } else if (event.getSearchType().equals(SearchOperation.SearchType.RECENTLY_ADDED_SEARCH)) {
|
|
|
+ setEmptyListMessage(SearchType.RECENTLY_ADDED_SEARCH);
|
|
|
+ menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SORT;
|
|
|
+ } else if (event.getSearchType().equals(SearchOperation.SearchType.RECENTLY_MODIFIED_SEARCH)) {
|
|
|
+ setEmptyListMessage(SearchType.RECENTLY_MODIFIED_SEARCH);
|
|
|
+ menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SORT;
|
|
|
+ } else if (event.getSearchType().equals(SearchOperation.SearchType.SHARED_SEARCH)) {
|
|
|
+ setEmptyListMessage(SearchType.SHARED_FILTER);
|
|
|
+ menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SEARCH;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!currentSearchType.equals(SearchType.FILE_SEARCH) && getActivity() != null) {
|
|
|
+ getActivity().invalidateOptionsMenu();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (currentSearchType.equals(SearchType.PHOTO_SEARCH)) {
|
|
|
+ new Handler(Looper.getMainLooper()).post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ switchToGridView();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else if (currentSearchType.equals(SearchType.NO_SEARCH) || currentSearchType.equals(
|
|
|
+ SearchType.REGULAR_FILTER)) {
|
|
|
+ new Handler(Looper.getMainLooper()).post(switchViewsRunnable);
|
|
|
+ } else {
|
|
|
+ new Handler(Looper.getMainLooper()).post(switchViewsRunnable);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
|
|
|
+ Log_OC.e(TAG, "Account not found", e);
|
|
|
+ } catch (AuthenticatorException e) {
|
|
|
+ Log_OC.e(TAG, "Authentication failed", e);
|
|
|
+ } catch (IOException e) {
|
|
|
+ Log_OC.e(TAG, "IO error", e);
|
|
|
+ } catch (OperationCanceledException e) {
|
|
|
+ Log_OC.e(TAG, "Operation has been canceled", e);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onStart() {
|
|
|
+ super.onStart();
|
|
|
+ EventBus.getDefault().register(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onStop() {
|
|
|
+ EventBus.getDefault().unregister(this);
|
|
|
+ super.onStop();
|
|
|
+ }
|
|
|
}
|