|
@@ -1,21 +1,20 @@
|
|
|
/**
|
|
|
- * ownCloud Android client application
|
|
|
- *
|
|
|
- * Copyright (C) 2012 Bartek Przybylski
|
|
|
- * Copyright (C) 2012-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 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/>.
|
|
|
- *
|
|
|
+ * ownCloud Android client application
|
|
|
+ * <p>
|
|
|
+ * Copyright (C) 2012 Bartek Przybylski
|
|
|
+ * Copyright (C) 2012-2016 ownCloud Inc.
|
|
|
+ * <p>
|
|
|
+ * 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.
|
|
|
+ * <p>
|
|
|
+ * 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.
|
|
|
+ * <p>
|
|
|
+ * 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;
|
|
@@ -24,8 +23,10 @@ import android.animation.LayoutTransition;
|
|
|
import android.app.Activity;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
|
+import android.os.Looper;
|
|
|
import android.support.annotation.DrawableRes;
|
|
|
import android.support.annotation.StringRes;
|
|
|
+import android.support.design.widget.BottomNavigationView;
|
|
|
import android.support.v4.app.Fragment;
|
|
|
import android.support.v4.view.MenuItemCompat;
|
|
|
import android.support.v4.widget.SwipeRefreshLayout;
|
|
@@ -66,16 +67,28 @@ import java.util.ArrayList;
|
|
|
import third_parties.in.srain.cube.GridViewWithHeaderAndFooter;
|
|
|
|
|
|
import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
|
|
|
+import static com.owncloud.android.ui.fragment.ExtendedListFragment.SearchType.FAVORITE_SEARCH;
|
|
|
+import static com.owncloud.android.ui.fragment.ExtendedListFragment.SearchType.FAVORITE_SEARCH_FILTER;
|
|
|
+import static com.owncloud.android.ui.fragment.ExtendedListFragment.SearchType.FILE_SEARCH;
|
|
|
+import static com.owncloud.android.ui.fragment.ExtendedListFragment.SearchType.NO_SEARCH;
|
|
|
+import static com.owncloud.android.ui.fragment.ExtendedListFragment.SearchType.PHOTO_SEARCH;
|
|
|
+import static com.owncloud.android.ui.fragment.ExtendedListFragment.SearchType.RECENTLY_ADDED_SEARCH;
|
|
|
+import static com.owncloud.android.ui.fragment.ExtendedListFragment.SearchType.RECENTLY_ADDED_SEARCH_FILTER;
|
|
|
+import static com.owncloud.android.ui.fragment.ExtendedListFragment.SearchType.RECENTLY_MODIFIED_SEARCH;
|
|
|
+import static com.owncloud.android.ui.fragment.ExtendedListFragment.SearchType.RECENTLY_MODIFIED_SEARCH_FILTER;
|
|
|
+import static com.owncloud.android.ui.fragment.ExtendedListFragment.SearchType.REGULAR_FILTER;
|
|
|
+import static com.owncloud.android.ui.fragment.ExtendedListFragment.SearchType.VIDEO_SEARCH;
|
|
|
+import static com.owncloud.android.ui.fragment.ExtendedListFragment.SearchType.VIDEO_SEARCH_FILTER;
|
|
|
|
|
|
public class ExtendedListFragment extends Fragment
|
|
|
implements OnItemClickListener, OnEnforceableRefreshListener, SearchView.OnQueryTextListener {
|
|
|
|
|
|
protected static final String TAG = ExtendedListFragment.class.getSimpleName();
|
|
|
|
|
|
- protected static final String KEY_SAVED_LIST_POSITION = "SAVED_LIST_POSITION";
|
|
|
+ protected static final String KEY_SAVED_LIST_POSITION = "SAVED_LIST_POSITION";
|
|
|
|
|
|
private static final String KEY_INDEXES = "INDEXES";
|
|
|
- private static final String KEY_FIRST_POSITIONS= "FIRST_POSITIONS";
|
|
|
+ private static final String KEY_FIRST_POSITIONS = "FIRST_POSITIONS";
|
|
|
private static final String KEY_TOPS = "TOPS";
|
|
|
private static final String KEY_HEIGHT_CELL = "HEIGHT_CELL";
|
|
|
private static final String KEY_EMPTY_LIST_MESSAGE = "EMPTY_LIST_MESSAGE";
|
|
@@ -114,6 +127,25 @@ public class ExtendedListFragment extends Fragment
|
|
|
protected SearchView searchView;
|
|
|
private Handler handler = new Handler();
|
|
|
|
|
|
+ protected Menu mMenu;
|
|
|
+
|
|
|
+ public enum SearchType {
|
|
|
+ NO_SEARCH,
|
|
|
+ REGULAR_FILTER,
|
|
|
+ FILE_SEARCH,
|
|
|
+ FAVORITE_SEARCH,
|
|
|
+ FAVORITE_SEARCH_FILTER,
|
|
|
+ VIDEO_SEARCH,
|
|
|
+ VIDEO_SEARCH_FILTER,
|
|
|
+ PHOTO_SEARCH,
|
|
|
+ PHOTOS_SEARCH_FILTER,
|
|
|
+ RECENTLY_MODIFIED_SEARCH,
|
|
|
+ RECENTLY_MODIFIED_SEARCH_FILTER,
|
|
|
+ RECENTLY_ADDED_SEARCH,
|
|
|
+ RECENTLY_ADDED_SEARCH_FILTER
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
protected void setListAdapter(BaseAdapter listAdapter) {
|
|
|
mAdapter = listAdapter;
|
|
|
mCurrentListView.setAdapter(listAdapter);
|
|
@@ -160,12 +192,13 @@ public class ExtendedListFragment extends Fragment
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public boolean isGridEnabled(){
|
|
|
+ public boolean isGridEnabled() {
|
|
|
return (mCurrentListView != null && mCurrentListView.equals(mGridView));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
+ mMenu = menu;
|
|
|
final MenuItem item = menu.findItem(R.id.action_search);
|
|
|
searchView = (SearchView) MenuItemCompat.getActionView(item);
|
|
|
searchView.setOnQueryTextListener(this);
|
|
@@ -200,6 +233,17 @@ public class ExtendedListFragment extends Fragment
|
|
|
public void run() {
|
|
|
if (getActivity() != null && !(getActivity() instanceof FolderPickerActivity)) {
|
|
|
setFabEnabled(!hasFocus);
|
|
|
+
|
|
|
+ if (getResources().getBoolean(R.bool.bottom_toolbar_enabled)) {
|
|
|
+ BottomNavigationView bottomNavigationView = (BottomNavigationView) getActivity().
|
|
|
+ findViewById(R.id.bottom_navigation_view);
|
|
|
+ if (hasFocus) {
|
|
|
+ bottomNavigationView.setVisibility(View.GONE);
|
|
|
+ } else {
|
|
|
+ bottomNavigationView.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}, 100);
|
|
@@ -220,9 +264,10 @@ public class ExtendedListFragment extends Fragment
|
|
|
|
|
|
if (currentVisibility != oldVisibility) {
|
|
|
if (currentVisibility == View.VISIBLE) {
|
|
|
- setEmptyListMessage(true);
|
|
|
+
|
|
|
+ setEmptyListMessage(SearchType.REGULAR_FILTER);
|
|
|
} else {
|
|
|
- setEmptyListMessage(false);
|
|
|
+ setEmptyListMessage(NO_SEARCH);
|
|
|
}
|
|
|
|
|
|
oldVisibility = currentVisibility;
|
|
@@ -284,11 +329,11 @@ public class ExtendedListFragment extends Fragment
|
|
|
if ((activity = getActivity()) != null) {
|
|
|
if (activity instanceof FileDisplayActivity) {
|
|
|
((FileDisplayActivity) activity).refreshListOfFilesFragment(true);
|
|
|
- } else if (activity instanceof UploadFilesActivity){
|
|
|
+ } else if (activity instanceof UploadFilesActivity) {
|
|
|
LocalFileListAdapter localFileListAdapter = (LocalFileListAdapter) mAdapter;
|
|
|
localFileListAdapter.filter(query);
|
|
|
} else if (activity instanceof FolderPickerActivity) {
|
|
|
- ((FolderPickerActivity)activity).refreshListOfFilesFragment(true);
|
|
|
+ ((FolderPickerActivity) activity).refreshListOfFilesFragment(true);
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -305,7 +350,7 @@ public class ExtendedListFragment extends Fragment
|
|
|
View v = inflater.inflate(R.layout.list_fragment, null);
|
|
|
setupEmptyList(v);
|
|
|
|
|
|
- mListView = (ExtendedListView)(v.findViewById(R.id.list_root));
|
|
|
+ mListView = (ExtendedListView) (v.findViewById(R.id.list_root));
|
|
|
mListView.setOnItemClickListener(this);
|
|
|
mListFooterView = inflater.inflate(R.layout.list_footer, null, false);
|
|
|
|
|
@@ -366,23 +411,23 @@ public class ExtendedListFragment extends Fragment
|
|
|
@Override
|
|
|
public void onActivityCreated(Bundle savedInstanceState) {
|
|
|
super.onActivityCreated(savedInstanceState);
|
|
|
-
|
|
|
+
|
|
|
if (savedInstanceState != null) {
|
|
|
mIndexes = savedInstanceState.getIntegerArrayList(KEY_INDEXES);
|
|
|
mFirstPositions = savedInstanceState.getIntegerArrayList(KEY_FIRST_POSITIONS);
|
|
|
mTops = savedInstanceState.getIntegerArrayList(KEY_TOPS);
|
|
|
mHeightCell = savedInstanceState.getInt(KEY_HEIGHT_CELL);
|
|
|
setMessageForEmptyList(savedInstanceState.getString(KEY_EMPTY_LIST_MESSAGE));
|
|
|
-
|
|
|
+
|
|
|
} else {
|
|
|
mIndexes = new ArrayList<>();
|
|
|
mFirstPositions = new ArrayList<>();
|
|
|
mTops = new ArrayList<>();
|
|
|
mHeightCell = 0;
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public void onSaveInstanceState(Bundle savedInstanceState) {
|
|
|
super.onSaveInstanceState(savedInstanceState);
|
|
@@ -400,10 +445,10 @@ public class ExtendedListFragment extends Fragment
|
|
|
* Calculates the position of the item that will be used as a reference to
|
|
|
* reposition the visible items in the list when the device is turned to
|
|
|
* other position.
|
|
|
- *
|
|
|
+ *
|
|
|
* The current policy is take as a reference the visible item in the center
|
|
|
* of the screen.
|
|
|
- *
|
|
|
+ *
|
|
|
* @return The position in the list of the visible item in the center of the
|
|
|
* screen.
|
|
|
*/
|
|
@@ -421,25 +466,25 @@ public class ExtendedListFragment extends Fragment
|
|
|
* Restore index and position
|
|
|
*/
|
|
|
protected void restoreIndexAndTopPosition() {
|
|
|
- if (mIndexes.size() > 0) {
|
|
|
+ if (mIndexes.size() > 0) {
|
|
|
// needs to be checked; not every browse-up had a browse-down before
|
|
|
-
|
|
|
+
|
|
|
int index = mIndexes.remove(mIndexes.size() - 1);
|
|
|
- final int firstPosition = mFirstPositions.remove(mFirstPositions.size() -1);
|
|
|
+ final int firstPosition = mFirstPositions.remove(mFirstPositions.size() - 1);
|
|
|
int top = mTops.remove(mTops.size() - 1);
|
|
|
|
|
|
Log_OC.v(TAG, "Setting selection to position: " + firstPosition + "; top: "
|
|
|
+ top + "; index: " + index);
|
|
|
|
|
|
- if (mCurrentListView!= null && mCurrentListView.equals(mListView)) {
|
|
|
- if (mHeightCell*index <= mListView.getHeight()) {
|
|
|
+ if (mCurrentListView != null && mCurrentListView.equals(mListView)) {
|
|
|
+ if (mHeightCell * index <= mListView.getHeight()) {
|
|
|
mListView.setSelectionFromTop(firstPosition, top);
|
|
|
} else {
|
|
|
mListView.setSelectionFromTop(index, 0);
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
- if (mHeightCell*index <= mGridView.getHeight()) {
|
|
|
+ if (mHeightCell * index <= mGridView.getHeight()) {
|
|
|
mGridView.setSelection(firstPosition);
|
|
|
//mGridView.smoothScrollToPosition(firstPosition);
|
|
|
} else {
|
|
@@ -450,29 +495,29 @@ public class ExtendedListFragment extends Fragment
|
|
|
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/*
|
|
|
* Save index and top position
|
|
|
*/
|
|
|
protected void saveIndexAndTopPosition(int index) {
|
|
|
-
|
|
|
+
|
|
|
mIndexes.add(index);
|
|
|
-
|
|
|
+
|
|
|
int firstPosition = mCurrentListView.getFirstVisiblePosition();
|
|
|
mFirstPositions.add(firstPosition);
|
|
|
-
|
|
|
+
|
|
|
View view = mCurrentListView.getChildAt(0);
|
|
|
- int top = (view == null) ? 0 : view.getTop() ;
|
|
|
+ int top = (view == null) ? 0 : view.getTop();
|
|
|
|
|
|
mTops.add(top);
|
|
|
-
|
|
|
+
|
|
|
// Save the height of a cell
|
|
|
mHeightCell = (view == null || mHeightCell != 0) ? mHeightCell : view.getHeight();
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
- public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
|
|
|
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
// to be @overriden
|
|
|
}
|
|
|
|
|
@@ -501,7 +546,7 @@ public class ExtendedListFragment extends Fragment
|
|
|
public void setOnRefreshListener(OnEnforceableRefreshListener listener) {
|
|
|
mOnRefreshListener = listener;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* Disables swipe gesture.
|
|
@@ -526,7 +571,7 @@ public class ExtendedListFragment extends Fragment
|
|
|
* @param enabled Desired visibility for the FAB.
|
|
|
*/
|
|
|
public void setFabEnabled(boolean enabled) {
|
|
|
- if(enabled) {
|
|
|
+ if (enabled) {
|
|
|
mFabMain.setVisibility(View.VISIBLE);
|
|
|
} else {
|
|
|
mFabMain.setVisibility(View.GONE);
|
|
@@ -555,22 +600,52 @@ public class ExtendedListFragment extends Fragment
|
|
|
mEmptyListMessage.setText(message);
|
|
|
mEmptyListIcon.setImageResource(icon);
|
|
|
|
|
|
- mEmptyListIcon.setVisibility(View.VISIBLE);
|
|
|
- mEmptyListProgress.setVisibility(View.GONE);
|
|
|
+ new Handler(Looper.getMainLooper()).post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ mEmptyListIcon.setVisibility(View.VISIBLE);
|
|
|
+ mEmptyListProgress.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void setEmptyListMessage(boolean isSearch) {
|
|
|
- if (isSearch) {
|
|
|
- setMessageForEmptyList(R.string.file_list_empty_headline_search,
|
|
|
- R.string.file_list_empty_search, R.drawable.ic_search_light_grey);
|
|
|
-
|
|
|
- } else {
|
|
|
+ public void setEmptyListMessage(SearchType searchType) {
|
|
|
+ if (searchType == NO_SEARCH) {
|
|
|
setMessageForEmptyList(
|
|
|
R.string.file_list_empty_headline,
|
|
|
R.string.file_list_empty,
|
|
|
R.drawable.ic_list_empty_folder
|
|
|
);
|
|
|
+ } else if (searchType == FILE_SEARCH) {
|
|
|
+ setMessageForEmptyList(R.string.file_list_empty_headline_server_search,
|
|
|
+ R.string.file_list_empty, R.drawable.ic_search_light_grey);
|
|
|
+ } else if (searchType == FAVORITE_SEARCH) {
|
|
|
+ setMessageForEmptyList(R.string.file_list_empty_headline_server_search,
|
|
|
+ R.string.file_list_empty_favorites, R.drawable.ic_search_light_grey);
|
|
|
+ } else if (searchType == VIDEO_SEARCH) {
|
|
|
+ setMessageForEmptyList(R.string.file_list_empty_headline_server_search_videos,
|
|
|
+ R.string.file_list_empty_text_videos, R.drawable.ic_search_light_grey);
|
|
|
+ } else if (searchType == PHOTO_SEARCH) {
|
|
|
+ setMessageForEmptyList(R.string.file_list_empty_headline_server_search_photos,
|
|
|
+ R.string.file_list_empty_text_photos, R.drawable.ic_search_light_grey);
|
|
|
+ } else if (searchType == RECENTLY_MODIFIED_SEARCH) {
|
|
|
+ setMessageForEmptyList(R.string.file_list_empty_headline_server_search,
|
|
|
+ R.string.file_list_empty_recently_modified, R.drawable.ic_search_light_grey);
|
|
|
+ } else if (searchType == RECENTLY_ADDED_SEARCH) {
|
|
|
+ setMessageForEmptyList(R.string.file_list_empty_headline_server_search,
|
|
|
+ R.string.file_list_empty_recently_added, R.drawable.ic_search_light_grey);
|
|
|
+ } else if (searchType == REGULAR_FILTER) {
|
|
|
+ setMessageForEmptyList(R.string.file_list_empty_headline_search,
|
|
|
+ R.string.file_list_empty_search, R.drawable.ic_search_light_grey);
|
|
|
+ } else if (searchType == FAVORITE_SEARCH_FILTER) {
|
|
|
+
|
|
|
+ } else if (searchType == VIDEO_SEARCH_FILTER) {
|
|
|
+
|
|
|
+ } else if (searchType == RECENTLY_MODIFIED_SEARCH_FILTER) {
|
|
|
+
|
|
|
+ } else if (searchType == RECENTLY_ADDED_SEARCH_FILTER) {
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -582,14 +657,19 @@ public class ExtendedListFragment extends Fragment
|
|
|
mEmptyListHeadline.setText(R.string.file_list_loading);
|
|
|
mEmptyListMessage.setText("");
|
|
|
|
|
|
- mEmptyListIcon.setVisibility(View.GONE);
|
|
|
- mEmptyListProgress.setVisibility(View.VISIBLE);
|
|
|
+ new Handler(Looper.getMainLooper()).post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ mEmptyListIcon.setVisibility(View.GONE);
|
|
|
+ mEmptyListProgress.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Get the text of EmptyListMessage TextView.
|
|
|
- *
|
|
|
+ *
|
|
|
* @return String empty text view text-value
|
|
|
*/
|
|
|
public String getEmptyViewText() {
|
|
@@ -632,7 +712,7 @@ public class ExtendedListFragment extends Fragment
|
|
|
protected void setFooterEnabled(boolean enabled) {
|
|
|
if (enabled) {
|
|
|
if (mGridView.getFooterViewCount() == 0 && mGridView.isCorrectAdapter()) {
|
|
|
- if (mGridFooterView.getParent() != null ) {
|
|
|
+ if (mGridFooterView.getParent() != null) {
|
|
|
((ViewGroup) mGridFooterView.getParent()).removeView(mGridFooterView);
|
|
|
}
|
|
|
mGridView.addFooterView(mGridFooterView, null, false);
|
|
@@ -640,7 +720,7 @@ public class ExtendedListFragment extends Fragment
|
|
|
mGridFooterView.invalidate();
|
|
|
|
|
|
if (mListView.getFooterViewsCount() == 0) {
|
|
|
- if (mListFooterView.getParent() != null ) {
|
|
|
+ if (mListFooterView.getParent() != null) {
|
|
|
((ViewGroup) mListFooterView.getParent()).removeView(mListFooterView);
|
|
|
}
|
|
|
mListView.addFooterView(mListFooterView, null, false);
|
|
@@ -660,8 +740,8 @@ public class ExtendedListFragment extends Fragment
|
|
|
*/
|
|
|
protected void setFooterText(String text) {
|
|
|
if (text != null && text.length() > 0) {
|
|
|
- ((TextView)mListFooterView.findViewById(R.id.footerText)).setText(text);
|
|
|
- ((TextView)mGridFooterView.findViewById(R.id.footerText)).setText(text);
|
|
|
+ ((TextView) mListFooterView.findViewById(R.id.footerText)).setText(text);
|
|
|
+ ((TextView) mGridFooterView.findViewById(R.id.footerText)).setText(text);
|
|
|
setFooterEnabled(true);
|
|
|
|
|
|
} else {
|