From 401dba6d83052cf0c9c60a74e8460e356f39bcb2 Mon Sep 17 00:00:00 2001
From: MChen321 <76930316+MChen321@users.noreply.github.com>
Date: Thu, 8 Sep 2022 21:05:30 -0500
Subject: Added a clear search bar text button (#1063)
---
.../infinityforreddit/activities/SearchActivity.java | 12 ++++++++++++
app/src/main/res/drawable-xhdpi/ic_cancel_24dp.xml | 10 ++++++++++
app/src/main/res/layout/activity_search.xml | 10 ++++++++++
3 files changed, 32 insertions(+)
create mode 100644 app/src/main/res/drawable-xhdpi/ic_cancel_24dp.xml
(limited to 'app/src/main')
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java
index cf28ff85..f9fa34f3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java
@@ -92,6 +92,8 @@ public class SearchActivity extends BaseActivity {
Toolbar toolbar;
@BindView(R.id.search_edit_text_search_activity)
EditText searchEditText;
+ @BindView(R.id.clear_search_edit_view_search_activity)
+ ImageView clearSearchTextImageView;
@BindView(R.id.link_handler_image_view_search_activity)
ImageView linkHandlerImageView;
@BindView(R.id.subreddit_name_relative_layout_search_activity)
@@ -154,6 +156,8 @@ public class SearchActivity extends BaseActivity {
setSupportActionBar(toolbar);
+ clearSearchTextImageView.setVisibility(View.GONE);
+
searchOnlySubreddits = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_SUBREDDITS, false);
searchOnlyUsers = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_USERS, false);
@@ -236,6 +240,9 @@ public class SearchActivity extends BaseActivity {
}
});
+ clearSearchTextImageView.setVisibility(View.VISIBLE);
+ } else {
+ clearSearchTextImageView.setVisibility(View.GONE);
}
}
});
@@ -250,6 +257,10 @@ public class SearchActivity extends BaseActivity {
return false;
});
+ clearSearchTextImageView.setOnClickListener(view -> {
+ searchEditText.getText().clear();
+ });
+
linkHandlerImageView.setOnClickListener(view -> {
if (!searchEditText.getText().toString().equals("")) {
Intent intent = new Intent(this, LinkResolverActivity.class);
@@ -378,6 +389,7 @@ public class SearchActivity extends BaseActivity {
int toolbarPrimaryTextAndIconColorColor = mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor();
searchEditText.setTextColor(toolbarPrimaryTextAndIconColorColor);
searchEditText.setHintTextColor(mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor());
+ clearSearchTextImageView.setColorFilter(mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor(), android.graphics.PorterDuff.Mode.SRC_IN);
linkHandlerImageView.setColorFilter(mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor(), android.graphics.PorterDuff.Mode.SRC_IN);
int colorAccent = mCustomThemeWrapper.getColorAccent();
searchInTextView.setTextColor(colorAccent);
diff --git a/app/src/main/res/drawable-xhdpi/ic_cancel_24dp.xml b/app/src/main/res/drawable-xhdpi/ic_cancel_24dp.xml
new file mode 100644
index 00000000..b20b903f
--- /dev/null
+++ b/app/src/main/res/drawable-xhdpi/ic_cancel_24dp.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/layout/activity_search.xml b/app/src/main/res/layout/activity_search.xml
index 8d4055ca..3e68d158 100644
--- a/app/src/main/res/layout/activity_search.xml
+++ b/app/src/main/res/layout/activity_search.xml
@@ -39,6 +39,16 @@
android:inputType="textNoSuggestions"
android:imeOptions="actionSearch" />
+
+