Skip to content

Commit

Permalink
solve bug 0000266
Browse files Browse the repository at this point in the history
  • Loading branch information
domjos1994 committed Aug 25, 2019
1 parent 247f762 commit 8681786
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ public class LocalSyncAdapter extends BaseExpandableListAdapter {
private List<Map.Entry<String, List<String>>> 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();
}

Expand Down Expand Up @@ -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<String> 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<String> 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));
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/res/layout/local_sync_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,35 @@
android:layout_alignParentTop="true"
android:background="@drawable/controls_background">

<TableRow>

<TextView
android:layout_weight="3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/search_content" />

<EditText
android:id="@+id/txtLocalSyncSearch"
android:layout_weight="6"
android:layout_width="0dp"
android:hint="@string/search_content"
android:inputType="text"
android:layout_height="wrap_content"
android:autofillHints="@string/search_content"
tools:targetApi="o" />

<ImageButton
android:id="@+id/cmdLocalSyncSearch"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:contentDescription="@string/search_content"
app:srcCompat="@drawable/ic_search_black_24dp" />
</TableRow>

<TableRow>

<TextView
Expand Down

0 comments on commit 8681786

Please sign in to comment.