Add search functionality

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2023-11-13 15:18:52 +01:00
parent cbc10e9ba2
commit 5b64d5bb5a
No known key found for this signature in database
GPG key ID: 4E577DC593B59BDF
2 changed files with 49 additions and 13 deletions

View file

@ -705,6 +705,8 @@ public class ReceiveExternalFilesActivity extends FileActivity
}
}
private UploaderAdapter uploadAdapter;
private void populateDirectoryList() {
setupEmptyList();
setupToolbar();
@ -746,14 +748,14 @@ public class ReceiveExternalFilesActivity extends FileActivity
files = sortFileList(files);
List<Map<String, Object>> data = new LinkedList<>();
List<Map<String, OCFile>> data = new LinkedList<>();
for (OCFile f : files) {
Map<String, Object> h = new HashMap<>();
Map<String, OCFile> h = new HashMap<>();
h.put("dirname", f);
data.add(h);
}
UploaderAdapter sa = new UploaderAdapter(this,
uploadAdapter = new UploaderAdapter(this,
data,
R.layout.uploader_list_item_layout,
new String[]{"dirname"},
@ -763,7 +765,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
syncedFolderProvider,
viewThemeUtils);
binding.list.setAdapter(sa);
binding.list.setAdapter(uploadAdapter);
binding.list.setVisibility(View.VISIBLE);
}
MaterialButton btnChooseFolder = binding.uploaderChooseFolder;
@ -1025,11 +1027,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
UnifiedSearchFragment unifiedSearchFragment = UnifiedSearchFragment.Companion.newInstance(query);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.addToBackStack(null);
transaction.replace(R.id.upload_files_layout, unifiedSearchFragment, TAG_LIST_OF_FILES);
transaction.commit();
uploadAdapter.filter(query);
return false;
}

View file

@ -43,10 +43,13 @@ import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.MimeTypeUtil;
import com.owncloud.android.utils.theme.ViewThemeUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static java.util.Collections.addAll;
public class UploaderAdapter extends SimpleAdapter {
private final Context mContext;
@ -54,10 +57,13 @@ public class UploaderAdapter extends SimpleAdapter {
private final FileDataStorageManager mStorageManager;
private final LayoutInflater inflater;
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,
List<? extends Map<String, ?>> data,
List<Map<String, OCFile>> data,
int resource,
String[] from,
int[] to,
@ -72,6 +78,39 @@ public class UploaderAdapter extends SimpleAdapter {
this.syncedFolderProvider = syncedFolderProvider;
inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
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
@ -81,8 +120,7 @@ public class UploaderAdapter extends SimpleAdapter {
vi = inflater.inflate(R.layout.uploader_list_item_layout, parent, false);
}
HashMap<String, OCFile> data = (HashMap<String, OCFile>) getItem(position);
OCFile file = data.get("dirname");
OCFile file = ((HashMap<String, OCFile>) getItem(position)).get("dirname");
TextView filename = vi.findViewById(R.id.filename);
filename.setText(file.getFileName());