show 'clear contact search' button only if there is a search, closes #27

This commit is contained in:
B. Petersen
2018-09-14 14:49:12 +02:00
parent 2fb6da8100
commit 7f6195eea1
2 changed files with 18 additions and 4 deletions
+2 -1
View File
@@ -33,7 +33,8 @@
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:gravity="center">
android:gravity="center"
android:visibility="invisible">
<ImageView android:id="@+id/search_clear"
android:layout_width="wrap_content"
@@ -48,6 +48,7 @@ public class ContactFilterToolbar extends Toolbar {
@Override
public void onClick(View v) {
searchText.setText("");
displayTogglingView(null);
}
});
@@ -64,14 +65,24 @@ public class ContactFilterToolbar extends Toolbar {
@Override
public void afterTextChanged(Editable s) {
if (!SearchUtil.isEmpty(searchText)) displayTogglingView(clearToggle);
if (!SearchUtil.isEmpty(searchText)) {
displayTogglingView(clearToggle);
}
else {
displayTogglingView(null);
}
notifyListener();
}
});
setLogo(null);
setContentInsetStartWithNavigation(0);
expandTapArea(toggleContainer, clearToggle);
// avoid flickering by setting button_toggle to INVISIBLE in contact_filter_toolbar.xml
// and set it to VISIBLE _after_ choosing to display nothing
// (AnimatingToggle displays the first what will flash shortly otherwise)
toggle.displayQuick(null);
toggle.setVisibility(View.VISIBLE);
}
public void clear() {
@@ -89,7 +100,9 @@ public class ContactFilterToolbar extends Toolbar {
private void displayTogglingView(View view) {
toggle.display(view);
expandTapArea(toggleContainer, view);
if (view!=null) {
expandTapArea(toggleContainer, view);
}
}
private void expandTapArea(final View container, final View child) {