mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 05:35:39 +03:00
Work on a new approach
This commit is contained in:
parent
ba0dace51f
commit
6a510d96c0
4 changed files with 71 additions and 11 deletions
|
@ -25,7 +25,7 @@
|
|||
android:title="@string/actionbar_search"
|
||||
android:contentDescription="@string/actionbar_search"
|
||||
app:actionViewClass="android.support.v7.widget.SearchView"
|
||||
app:showAsAction="ifRoom|collapseActionView"/>
|
||||
app:showAsAction="always"/>
|
||||
<item
|
||||
android:id="@+id/action_create_dir"
|
||||
android:icon="@drawable/ic_action_create_dir"
|
||||
|
|
|
@ -46,7 +46,10 @@ 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.MenuItemCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
@ -94,6 +97,7 @@ import java.io.File;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import static com.owncloud.android.R.id.searchView;
|
||||
import static com.owncloud.android.db.PreferenceManager.getSortOrder;
|
||||
|
||||
/**
|
||||
|
@ -116,6 +120,7 @@ public class FileDisplayActivity extends HookActivity
|
|||
private static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
|
||||
private static final String KEY_SYNC_IN_PROGRESS = "SYNC_IN_PROGRESS";
|
||||
private static final String KEY_WAITING_TO_SEND = "WAITING_TO_SEND";
|
||||
private static final String KEY_SEARCH_QUERY = "KEY_SEARCH_QUERY";
|
||||
|
||||
public static final String ACTION_DETAILS = "com.owncloud.android.ui.activity.action.DETAILS";
|
||||
|
||||
|
@ -138,7 +143,9 @@ public class FileDisplayActivity extends HookActivity
|
|||
private OCFile mWaitingToSend;
|
||||
|
||||
private Collection<MenuItem> mDrawerMenuItemstoShowHideList;
|
||||
private String searchQuery;
|
||||
|
||||
private SearchView searchView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -160,6 +167,7 @@ public class FileDisplayActivity extends HookActivity
|
|||
mSyncInProgress = savedInstanceState.getBoolean(KEY_SYNC_IN_PROGRESS);
|
||||
mWaitingToSend = (OCFile) savedInstanceState.getParcelable(
|
||||
FileDisplayActivity.KEY_WAITING_TO_SEND);
|
||||
searchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
|
||||
} else {
|
||||
mWaitingToPreview = null;
|
||||
mSyncInProgress = false;
|
||||
|
@ -394,7 +402,7 @@ public class FileDisplayActivity extends HookActivity
|
|||
if (getAccount() != null && getFile() != null) {
|
||||
/// First fragment
|
||||
OCFileListFragment listOfFiles = getListOfFilesFragment();
|
||||
if (listOfFiles != null) {
|
||||
if (listOfFiles != null && TextUtils.isEmpty(searchQuery)) {
|
||||
listOfFiles.listDirectory(getCurrentDir(), MainApp.isOnlyOnDevice());
|
||||
} else {
|
||||
Log_OC.e(TAG, "Still have a chance to lose the initializacion of list fragment >(");
|
||||
|
@ -590,6 +598,9 @@ public class FileDisplayActivity extends HookActivity
|
|||
inflater.inflate(R.menu.main_menu, menu);
|
||||
menu.findItem(R.id.action_create_dir).setVisible(false);
|
||||
|
||||
final MenuItem item = menu.findItem(R.id.action_search);
|
||||
searchView = (SearchView) MenuItemCompat.getActionView(item);
|
||||
|
||||
// populate list of menu items to show/hide when drawer is opened/closed
|
||||
mDrawerMenuItemstoShowHideList = new ArrayList<>(4);
|
||||
mDrawerMenuItemstoShowHideList.add(menu.findItem(R.id.action_sort));
|
||||
|
@ -597,6 +608,18 @@ public class FileDisplayActivity extends HookActivity
|
|||
mDrawerMenuItemstoShowHideList.add(menu.findItem(R.id.action_switch_view));
|
||||
mDrawerMenuItemstoShowHideList.add(menu.findItem(R.id.action_search));
|
||||
|
||||
//focus the SearchView
|
||||
if (!TextUtils.isEmpty(searchQuery)) {
|
||||
searchView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
searchView.setIconified(false);
|
||||
searchView.setQuery(searchQuery, false);
|
||||
searchView.clearFocus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -910,7 +933,9 @@ public class FileDisplayActivity extends HookActivity
|
|||
//outState.putBoolean(FileDisplayActivity.KEY_REFRESH_SHARES_IN_PROGRESS,
|
||||
// mRefreshSharesInProgress);
|
||||
outState.putParcelable(FileDisplayActivity.KEY_WAITING_TO_SEND, mWaitingToSend);
|
||||
|
||||
if (searchView != null) {
|
||||
outState.putString(KEY_SEARCH_QUERY, searchView.getQuery().toString());
|
||||
}
|
||||
Log_OC.v(TAG, "onSaveInstanceState() end");
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,8 @@ import com.owncloud.android.utils.FileStorageUtils;
|
|||
import com.owncloud.android.utils.MimeTypeUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.Vector;
|
||||
|
||||
|
||||
|
@ -455,20 +457,24 @@ public class FileListListAdapter extends BaseAdapter implements FilterableListAd
|
|||
}
|
||||
|
||||
public void filter(String text){
|
||||
|
||||
mFiles = new Vector<>();
|
||||
Set<OCFile> unique = new HashSet<>();
|
||||
unique.addAll(mFilesAll);
|
||||
|
||||
if(text.isEmpty()){
|
||||
mFiles.clear();
|
||||
mFiles.addAll(mFilesAll);
|
||||
mFiles.addAll(unique);
|
||||
} else {
|
||||
ArrayList<OCFile> result = new ArrayList<>();
|
||||
text = text.toLowerCase();
|
||||
for(OCFile file: mFilesAll){
|
||||
for(OCFile file: unique){
|
||||
if(file.getFileName().toLowerCase().contains(text)){
|
||||
result.add(file);
|
||||
}
|
||||
}
|
||||
mFiles.clear();
|
||||
mFiles.addAll(result);
|
||||
}
|
||||
mFiles = FileStorageUtils.sortOcFolder(mFiles);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
@ -483,7 +489,7 @@ public class FileListListAdapter extends BaseAdapter implements FilterableListAd
|
|||
OCFile current;
|
||||
for (int i = 0; i < files.size(); i++) {
|
||||
current = files.get(i);
|
||||
if (!current.isHidden()) {
|
||||
if (!current.isHidden() && !ret.contains(current)) {
|
||||
ret.add(current);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
package com.owncloud.android.ui.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
@ -54,6 +55,8 @@ import java.util.ArrayList;
|
|||
|
||||
import third_parties.in.srain.cube.GridViewWithHeaderAndFooter;
|
||||
|
||||
import static com.owncloud.android.R.id.searchView;
|
||||
|
||||
public class ExtendedListFragment extends Fragment
|
||||
implements OnItemClickListener, OnEnforceableRefreshListener, SearchView.OnQueryTextListener {
|
||||
|
||||
|
@ -98,6 +101,10 @@ public class ExtendedListFragment extends Fragment
|
|||
|
||||
private FilterableListAdapter mAdapter;
|
||||
|
||||
private SearchView searchView;
|
||||
private String searchQuery;
|
||||
private Handler handler = new Handler();
|
||||
|
||||
protected void setListAdapter(FilterableListAdapter listAdapter) {
|
||||
mAdapter = listAdapter;
|
||||
mCurrentListView.setAdapter(listAdapter);
|
||||
|
@ -151,17 +158,37 @@ public class ExtendedListFragment extends Fragment
|
|||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
final MenuItem item = menu.findItem(R.id.action_search);
|
||||
final SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);
|
||||
searchView = (SearchView) MenuItemCompat.getActionView(item);
|
||||
searchView.setOnQueryTextListener(this);
|
||||
|
||||
searchView.setMaxWidth(Integer.MAX_VALUE);
|
||||
searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange(View v, boolean hasFocus) {
|
||||
if (hasFocus) {
|
||||
mFabMain.collapse();
|
||||
}
|
||||
setFabEnabled(!hasFocus);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public boolean onQueryTextChange(String query) {
|
||||
mAdapter.filter(query);
|
||||
public boolean onQueryTextChange(final String query) {
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
searchQuery = query;
|
||||
mAdapter.filter(query);
|
||||
}
|
||||
}, 500);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
searchQuery = query;
|
||||
mAdapter.filter(query);
|
||||
return true;
|
||||
}
|
||||
|
@ -203,6 +230,8 @@ public class ExtendedListFragment extends Fragment
|
|||
|
||||
mCurrentListView = mListView; // list by default
|
||||
if (savedInstanceState != null) {
|
||||
|
||||
|
||||
if (savedInstanceState.getBoolean(KEY_IS_GRID_VISIBLE, false)) {
|
||||
switchToGridView();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue