Skip to content

Commit 3dbf52d

Browse files
committed
Implemented filtering with a button instead of timer.
1 parent 7084dd2 commit 3dbf52d

File tree

9 files changed

+32
-41
lines changed

9 files changed

+32
-41
lines changed

java/res/drawable-hdpi/filter.png

394 Bytes
Loading

java/res/drawable-ldpi/filter.png

269 Bytes
Loading

java/res/drawable-mdpi/filter.png

291 Bytes
Loading

java/res/drawable-xhdpi/filter.png

437 Bytes
Loading
922 Bytes
Loading
1.23 KB
Loading

java/res/layout/fragment_list_entries.xml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,28 @@
4444
android:text="New"/>
4545
</RelativeLayout>
4646

47-
<EditText
48-
android:id="@+id/editFilter"
47+
<RelativeLayout
4948
android:layout_width="match_parent"
5049
android:layout_height="wrap_content"
51-
android:layout_columnSpan="2"
52-
android:hint="Filter the displayed passwords..."
53-
android:inputType="text"/>
50+
android:orientation="horizontal"
51+
android:layout_marginTop="16dp"
52+
android:weightSum="2">
53+
<EditText
54+
android:id="@+id/editFilter"
55+
android:layout_width="wrap_content"
56+
android:layout_height="wrap_content"
57+
android:layout_columnSpan="2"
58+
android:hint="Filter the displayed passwords..."
59+
android:inputType="text"/>
60+
<Button
61+
android:id="@+id/filterButton"
62+
android:layout_width="wrap_content"
63+
android:layout_height="wrap_content"
64+
android:layout_alignParentRight="true"
65+
android:background="@android:color/transparent"
66+
android:drawableTop="@drawable/filter"
67+
android:text="Filter"/>
68+
</RelativeLayout>
5469

5570
<ListView
5671
android:id="@android:id/list"

java/src/main/java/org/astonbitecode/rustkeylock/fragments/EditConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void onClick(View view) {
6868
String url = nextcloudUrlText.getText() != null ? nextcloudUrlText.getText().toString() : "";
6969
String user = nextcloudUsernameText.getText() != null ? nextcloudUsernameText.getText().toString() : "";
7070
String password = nextcloudPasswordText.getText() != null ? nextcloudPasswordText.getText().toString() : "";
71-
String useSelfSignedCertString = new Boolean(useSelfSignedCert.isChecked()).toString();
71+
String useSelfSignedCertString = Boolean.valueOf(useSelfSignedCert.isChecked()).toString();
7272
Log.d(TAG, "Saving configuration (password not shown here): " + url + ", " + user + ", " + useSelfSignedCertString);
7373

7474
boolean errorsOccured = false;
@@ -118,7 +118,7 @@ private void prepareUiElements(View v) {
118118
passwordText.setText(strings.get(2));
119119
this.nextcloudPasswordText = passwordText;
120120
CheckBox useSsc = (CheckBox) v.findViewById(R.id.editNextcloudUseSelfSignedCert);
121-
useSsc.setChecked(new Boolean(strings.get(3)));
121+
useSsc.setChecked(Boolean.valueOf(strings.get(3)));
122122
this.useSelfSignedCert = useSsc;
123123

124124
TextView dbxTokenLabel = (TextView) v.findViewById(R.id.editConfigurationTokenLabel);

java/src/main/java/org/astonbitecode/rustkeylock/fragments/ListEntries.java

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import android.app.ListFragment;
1919
import android.content.Context;
2020
import android.os.Bundle;
21-
import android.text.Editable;
22-
import android.text.TextWatcher;
2321
import android.util.Log;
2422
import android.view.LayoutInflater;
2523
import android.view.View;
@@ -38,15 +36,14 @@
3836

3937
import java.util.ArrayList;
4038
import java.util.List;
41-
import java.util.Timer;
42-
import java.util.TimerTask;
4339

4440
public class ListEntries extends ListFragment implements OnClickListener, BackButtonHandler {
4541
private static final long serialVersionUID = 8765819759487480794L;
4642
private final String TAG = getClass().getName();
4743
private List<JavaEntry> entries;
4844
private transient EntriesAdapter entriesAdapter;
4945
private String filter;
46+
private transient EditText filterEditText;
5047

5148
public ListEntries() {
5249
this.entries = new ArrayList<>();
@@ -68,38 +65,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
6865
nb.setOnClickListener(this);
6966
Button mmb = (Button) rootView.findViewById(R.id.mainMenuButton);
7067
mmb.setOnClickListener(this);
68+
Button fb = (Button) rootView.findViewById(R.id.filterButton);
69+
fb.setOnClickListener(this);
7170

72-
EditText filterText = (EditText) rootView.findViewById(R.id.editFilter);
73-
filterText.setText(filter);
74-
filterText.addTextChangedListener(new TextWatcher() {
75-
private Timer timer = new Timer();
76-
private final long DELAY = 500;
77-
78-
@Override
79-
public void onTextChanged(CharSequence s, int start, int before, int count) {
80-
// ignore
81-
}
82-
83-
@Override
84-
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
85-
// ignore
86-
}
87-
88-
@Override
89-
public void afterTextChanged(final Editable s) {
90-
timer.cancel();
91-
timer = new Timer();
92-
timer.schedule(new TimerTask() {
93-
@Override
94-
public void run() {
95-
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.EntriesList(s != null ? s.toString() : ""));
96-
}
97-
}, DELAY);
98-
}
99-
});
71+
filterEditText = (EditText) rootView.findViewById(R.id.editFilter);
72+
filterEditText.setText(filter);
10073
if (filter.length() > 0) {
101-
filterText.setFocusableInTouchMode(true);
102-
filterText.requestFocus();
74+
filterEditText.setFocusableInTouchMode(true);
75+
filterEditText.requestFocus();
10376
} else {
10477
// Hide the soft keyboard
10578
final InputMethodManager imm = (InputMethodManager) getActivity()
@@ -132,6 +105,9 @@ public void onClick(View view) {
132105
} else if (view.getId() == R.id.addNewButton) {
133106
Log.d(TAG, "Clicked add new entry");
134107
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.NewEntry());
108+
} else if (view.getId() == R.id.filterButton) {
109+
Log.d(TAG, "Applying filter");
110+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.EntriesList(filterEditText.getText() != null ? filterEditText.getText().toString() : ""));
135111
}
136112
}
137113

0 commit comments

Comments
 (0)