diff --git a/app/src/main/java/de/domjos/unitrackermobile/activities/LocalSyncActivity.java b/app/src/main/java/de/domjos/unitrackermobile/activities/LocalSyncActivity.java index d7b36085..e522c822 100644 --- a/app/src/main/java/de/domjos/unitrackermobile/activities/LocalSyncActivity.java +++ b/app/src/main/java/de/domjos/unitrackermobile/activities/LocalSyncActivity.java @@ -24,7 +24,9 @@ import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; +import android.widget.EditText; import android.widget.ExpandableListView; +import android.widget.ImageButton; import android.widget.Spinner; import androidx.annotation.NonNull; @@ -54,6 +56,9 @@ public final class LocalSyncActivity extends AbstractActivity { private Settings settings; private Activity activity; + private EditText txtLocalSyncSearch; + private ImageButton cmdLocalSyncSearch; + public LocalSyncActivity() { super(R.layout.local_sync_activity); } @@ -86,6 +91,15 @@ public void onNothingSelected(AdapterView parent) { } }); + + this.cmdLocalSyncSearch.setOnClickListener(v -> { + String search = this.txtLocalSyncSearch.getText().toString().trim(); + if (!search.isEmpty()) { + this.reload(search); + } else { + this.reload(); + } + }); } @Override @@ -114,6 +128,9 @@ protected void initControls() { this.expLvLocalSync = this.findViewById(R.id.expLvLocalSync); + this.txtLocalSyncSearch = this.findViewById(R.id.txtLocalSyncSearch); + this.cmdLocalSyncSearch = this.findViewById(R.id.cmdLocalSyncSearch); + try { Helper.isStoragePermissionGranted(LocalSyncActivity.this); this.reloadProjects(this.spLocalSyncBugTracker.getSelectedItemPosition()); @@ -170,6 +187,11 @@ private void reloadProjects(int position) throws Exception { @Override protected void reload() { + this.reload(""); + } + + + private void reload(String search) { try { String bugTracker; String project; @@ -198,7 +220,7 @@ protected void reload() { } project = LocalSyncTask.renameToPathPart(pro.getTitle()); - LocalSyncAdapter localSyncAdapter = new LocalSyncAdapter(this.settings.getLocalSyncPath() + File.separatorChar + bugTracker + File.separatorChar + project, LocalSyncActivity.this); + LocalSyncAdapter localSyncAdapter = new LocalSyncAdapter(this.settings.getLocalSyncPath() + File.separatorChar + bugTracker + File.separatorChar + project, LocalSyncActivity.this, search); this.expLvLocalSync.setAdapter(localSyncAdapter); localSyncAdapter.notifyDataSetChanged(); } catch (Exception ex) { diff --git a/app/src/main/java/de/domjos/unitrackermobile/adapter/LocalSyncAdapter.java b/app/src/main/java/de/domjos/unitrackermobile/adapter/LocalSyncAdapter.java index 0753b243..9d7ec717 100644 --- a/app/src/main/java/de/domjos/unitrackermobile/adapter/LocalSyncAdapter.java +++ b/app/src/main/java/de/domjos/unitrackermobile/adapter/LocalSyncAdapter.java @@ -43,11 +43,13 @@ public class LocalSyncAdapter extends BaseExpandableListAdapter { private List>> content; private Context context; private String path; + private String search; - public LocalSyncAdapter(String path, Context context) { + public LocalSyncAdapter(String path, Context context, String search) { super(); this.context = context; this.path = path; + this.search = search; this.reload(); } @@ -144,30 +146,36 @@ public boolean isChildSelectable(int groupPosition, int childPosition) { private void reload() { this.content = new LinkedList<>(); - for (File content : new File(this.path).listFiles()) { - if (content.isDirectory()) { - List children = new LinkedList<>(); - for (File child : content.listFiles()) { - if (child.isFile()) { - if (child.getAbsolutePath().endsWith(".pdf")) { - children.add(child.getName()); - break; + File tmp = new File(this.path); + if (tmp.exists()) { + for (File content : tmp.listFiles()) { + if (content.getName().toLowerCase().contains(this.search.trim().toLowerCase())) { + if (content.isDirectory()) { + List children = new LinkedList<>(); + + for (File child : content.listFiles()) { + if (child.isFile()) { + if (child.getAbsolutePath().endsWith(".pdf")) { + children.add(child.getName()); + break; + } + } } - } - } - for (File child : content.listFiles()) { - if (child.isDirectory()) { - if (child.getAbsolutePath().contains("attachments")) { - for (File attachment : child.listFiles()) { - children.add(attachment.getName()); + for (File child : content.listFiles()) { + if (child.isDirectory()) { + if (child.getAbsolutePath().contains("attachments")) { + for (File attachment : child.listFiles()) { + children.add(attachment.getName()); + } + break; + } } - break; } + + this.content.add(new AbstractMap.SimpleEntry<>(content.getName(), children)); } } - - this.content.add(new AbstractMap.SimpleEntry<>(content.getName(), children)); } } } diff --git a/app/src/main/res/layout/local_sync_activity.xml b/app/src/main/res/layout/local_sync_activity.xml index 6df82e50..d0c9756c 100644 --- a/app/src/main/res/layout/local_sync_activity.xml +++ b/app/src/main/res/layout/local_sync_activity.xml @@ -34,6 +34,35 @@ android:layout_alignParentTop="true" android:background="@drawable/controls_background"> + + + + + + + + +