mirror of
https://github.com/nextcloud/android.git
synced 2024-11-24 06:05:42 +03:00
Add search functionality
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
cbc10e9ba2
commit
5b64d5bb5a
2 changed files with 49 additions and 13 deletions
|
@ -705,6 +705,8 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private UploaderAdapter uploadAdapter;
|
||||||
|
|
||||||
private void populateDirectoryList() {
|
private void populateDirectoryList() {
|
||||||
setupEmptyList();
|
setupEmptyList();
|
||||||
setupToolbar();
|
setupToolbar();
|
||||||
|
@ -746,14 +748,14 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
||||||
|
|
||||||
files = sortFileList(files);
|
files = sortFileList(files);
|
||||||
|
|
||||||
List<Map<String, Object>> data = new LinkedList<>();
|
List<Map<String, OCFile>> data = new LinkedList<>();
|
||||||
for (OCFile f : files) {
|
for (OCFile f : files) {
|
||||||
Map<String, Object> h = new HashMap<>();
|
Map<String, OCFile> h = new HashMap<>();
|
||||||
h.put("dirname", f);
|
h.put("dirname", f);
|
||||||
data.add(h);
|
data.add(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
UploaderAdapter sa = new UploaderAdapter(this,
|
uploadAdapter = new UploaderAdapter(this,
|
||||||
data,
|
data,
|
||||||
R.layout.uploader_list_item_layout,
|
R.layout.uploader_list_item_layout,
|
||||||
new String[]{"dirname"},
|
new String[]{"dirname"},
|
||||||
|
@ -763,7 +765,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
||||||
syncedFolderProvider,
|
syncedFolderProvider,
|
||||||
viewThemeUtils);
|
viewThemeUtils);
|
||||||
|
|
||||||
binding.list.setAdapter(sa);
|
binding.list.setAdapter(uploadAdapter);
|
||||||
binding.list.setVisibility(View.VISIBLE);
|
binding.list.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
MaterialButton btnChooseFolder = binding.uploaderChooseFolder;
|
MaterialButton btnChooseFolder = binding.uploaderChooseFolder;
|
||||||
|
@ -1025,11 +1027,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
||||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextSubmit(String query) {
|
public boolean onQueryTextSubmit(String query) {
|
||||||
UnifiedSearchFragment unifiedSearchFragment = UnifiedSearchFragment.Companion.newInstance(query);
|
uploadAdapter.filter(query);
|
||||||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
|
||||||
transaction.addToBackStack(null);
|
|
||||||
transaction.replace(R.id.upload_files_layout, unifiedSearchFragment, TAG_LIST_OF_FILES);
|
|
||||||
transaction.commit();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,10 +43,13 @@ import com.owncloud.android.utils.DisplayUtils;
|
||||||
import com.owncloud.android.utils.MimeTypeUtil;
|
import com.owncloud.android.utils.MimeTypeUtil;
|
||||||
import com.owncloud.android.utils.theme.ViewThemeUtils;
|
import com.owncloud.android.utils.theme.ViewThemeUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static java.util.Collections.addAll;
|
||||||
|
|
||||||
public class UploaderAdapter extends SimpleAdapter {
|
public class UploaderAdapter extends SimpleAdapter {
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
@ -54,10 +57,13 @@ public class UploaderAdapter extends SimpleAdapter {
|
||||||
private final FileDataStorageManager mStorageManager;
|
private final FileDataStorageManager mStorageManager;
|
||||||
private final LayoutInflater inflater;
|
private final LayoutInflater inflater;
|
||||||
private final ViewThemeUtils viewThemeUtils;
|
private final ViewThemeUtils viewThemeUtils;
|
||||||
private SyncedFolderProvider syncedFolderProvider;
|
private final SyncedFolderProvider syncedFolderProvider;
|
||||||
|
|
||||||
|
private final List<Map<String, OCFile>> originalData;
|
||||||
|
private final List<Map<String, OCFile>> filteredData;
|
||||||
|
|
||||||
public UploaderAdapter(Context context,
|
public UploaderAdapter(Context context,
|
||||||
List<? extends Map<String, ?>> data,
|
List<Map<String, OCFile>> data,
|
||||||
int resource,
|
int resource,
|
||||||
String[] from,
|
String[] from,
|
||||||
int[] to,
|
int[] to,
|
||||||
|
@ -72,6 +78,39 @@ public class UploaderAdapter extends SimpleAdapter {
|
||||||
this.syncedFolderProvider = syncedFolderProvider;
|
this.syncedFolderProvider = syncedFolderProvider;
|
||||||
inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
this.viewThemeUtils = viewThemeUtils;
|
this.viewThemeUtils = viewThemeUtils;
|
||||||
|
|
||||||
|
originalData = data;
|
||||||
|
filteredData = new ArrayList<>(originalData);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void filter(String query) {
|
||||||
|
filteredData.clear();
|
||||||
|
|
||||||
|
for (Map<String, OCFile> data : originalData) {
|
||||||
|
OCFile file = data.get("dirname");
|
||||||
|
String fileName = file.getFileName();
|
||||||
|
|
||||||
|
if (fileName.toLowerCase().contains(query.toLowerCase())) {
|
||||||
|
filteredData.add(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return filteredData.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getItem(int position) {
|
||||||
|
return filteredData.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getItemId(int position) {
|
||||||
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -81,8 +120,7 @@ public class UploaderAdapter extends SimpleAdapter {
|
||||||
vi = inflater.inflate(R.layout.uploader_list_item_layout, parent, false);
|
vi = inflater.inflate(R.layout.uploader_list_item_layout, parent, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
HashMap<String, OCFile> data = (HashMap<String, OCFile>) getItem(position);
|
OCFile file = ((HashMap<String, OCFile>) getItem(position)).get("dirname");
|
||||||
OCFile file = data.get("dirname");
|
|
||||||
|
|
||||||
TextView filename = vi.findViewById(R.id.filename);
|
TextView filename = vi.findViewById(R.id.filename);
|
||||||
filename.setText(file.getFileName());
|
filename.setText(file.getFileName());
|
||||||
|
|
Loading…
Reference in a new issue