Use EditText instead of SimpleSearchView in SearchActivity.

This commit is contained in:
Docile-Alligator 2022-06-01 15:41:01 +08:00
parent adb77f44d0
commit f0747c65cb
11 changed files with 64 additions and 93 deletions

View File

@ -164,9 +164,6 @@ dependencies {
// Loading ProgressBar
implementation 'com.lsjwzh:materialloadingprogressbar:0.5.8-RELEASE'
// SearchView
implementation 'com.github.Ferfalk:SimpleSearchView:0.2.0'
// Customizable TextView
implementation 'com.libRG:customtextview:2.4'

View File

@ -539,7 +539,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_CHANGE_POST_LAYOUT:
return R.drawable.ic_post_layout_24dp;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_SEARCH:
return R.drawable.ic_search_black_24dp;
return R.drawable.ic_search_24dp;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_GO_TO_SUBREDDIT:
return R.drawable.ic_subreddit_24dp;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_GO_TO_USER:
@ -639,7 +639,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
fab.setImageResource(R.drawable.ic_post_layout_24dp);
break;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_SEARCH:
fab.setImageResource(R.drawable.ic_search_black_24dp);
fab.setImageResource(R.drawable.ic_search_24dp);
break;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_GO_TO_SUBREDDIT:
fab.setImageResource(R.drawable.ic_subreddit_24dp);

View File

@ -4,12 +4,15 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Menu;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
@ -20,9 +23,6 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;
import com.ferfalk.simplesearchview.SimpleOnQueryTextListener;
import com.ferfalk.simplesearchview.SimpleSearchView;
import com.ferfalk.simplesearchview.SimpleSearchViewListener;
import com.google.android.material.appbar.AppBarLayout;
import com.r0adkll.slidr.Slidr;
@ -86,8 +86,8 @@ public class SearchActivity extends BaseActivity {
AppBarLayout appBarLayout;
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.search_view_search_activity)
SimpleSearchView simpleSearchView;
@BindView(R.id.search_edit_text_search_activity)
EditText searchEditText;
@BindView(R.id.subreddit_name_relative_layout_search_activity)
RelativeLayout subredditNameRelativeLayout;
@BindView(R.id.search_in_text_view_search_activity)
@ -152,18 +152,11 @@ public class SearchActivity extends BaseActivity {
searchOnlyUsers = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_USERS, false);
if (searchOnlySubreddits) {
simpleSearchView.setHint(getText(R.string.search_only_subreddits_hint));
searchEditText.setHint(getText(R.string.search_only_subreddits_hint));
} else if (searchOnlyUsers) {
simpleSearchView.setHint(getText(R.string.search_only_users_hint));
searchEditText.setHint(getText(R.string.search_only_users_hint));
}
simpleSearchView.setOnSearchViewListener(new SimpleSearchViewListener() {
@Override
public void onSearchViewClosed() {
finish();
}
});
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
boolean nsfw = mNsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, false);
@ -189,21 +182,26 @@ public class SearchActivity extends BaseActivity {
finish();
});
simpleSearchView.setOnQueryTextListener(new SimpleOnQueryTextListener() {
searchEditText.addTextChangedListener(new TextWatcher() {
@Override
public boolean onQueryTextSubmit(@NonNull String query) {
search(query);
return true;
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public boolean onQueryTextChange(@NonNull String newText) {
if (!newText.isEmpty()) {
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (!s.toString().trim().isEmpty()) {
if (subredditAutocompleteCall != null) {
subredditAutocompleteCall.cancel();
}
subredditAutocompleteCall = mOauthRetrofit.create(RedditAPI.class).subredditAutocomplete(APIUtils.getOAuthHeader(mAccessToken),
newText, nsfw);
s.toString(), nsfw);
subredditAutocompleteCall.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
@ -228,10 +226,18 @@ public class SearchActivity extends BaseActivity {
}
});
}
}
});
searchEditText.setOnEditorActionListener((v, actionId, event) -> {
if ((actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_SEARCH) || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN )) {
if (!searchEditText.getText().toString().isEmpty()) {
search(searchEditText.getText().toString());
return true;
}
return false;
}
return false;
});
if (savedInstanceState != null) {
@ -243,11 +249,10 @@ public class SearchActivity extends BaseActivity {
} else {
subredditNameTextView.setText(subredditName);
}
bindView();
} else {
query = getIntent().getStringExtra(EXTRA_QUERY);
bindView();
}
bindView();
if (searchOnlySubreddits || searchOnlyUsers) {
subredditNameRelativeLayout.setVisibility(View.GONE);
@ -351,12 +356,9 @@ public class SearchActivity extends BaseActivity {
protected void applyCustomTheme() {
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar);
simpleSearchView.setSearchBackground(new ColorDrawable(mCustomThemeWrapper.getColorPrimary()));
int toolbarPrimaryTextAndIconColorColor = mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor();
simpleSearchView.setIconsColor(toolbarPrimaryTextAndIconColorColor);
simpleSearchView.setTextColor(toolbarPrimaryTextAndIconColorColor);
simpleSearchView.setBackIconColor(toolbarPrimaryTextAndIconColorColor);
simpleSearchView.setHintTextColor(mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor());
searchEditText.setTextColor(toolbarPrimaryTextAndIconColorColor);
searchEditText.setHintTextColor(mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor());
int colorAccent = mCustomThemeWrapper.getColorAccent();
searchInTextView.setTextColor(colorAccent);
subredditNameTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
@ -369,11 +371,10 @@ public class SearchActivity extends BaseActivity {
@Override
protected void onStart() {
super.onStart();
simpleSearchView.showSearch(false);
simpleSearchView.requestFocus();
searchEditText.requestFocus();
if (query != null) {
simpleSearchView.setQuery(query, false);
searchEditText.setText(query);
query = null;
}
@ -388,16 +389,12 @@ public class SearchActivity extends BaseActivity {
super.onPause();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(simpleSearchView.getWindowToken(), 0);
imm.hideSoftInputFromWindow(searchEditText.getWindowToken(), 0);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (data != null && simpleSearchView.onActivityResult(requestCode, resultCode, data)) {
return;
}
if (resultCode == RESULT_OK && data != null) {
if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
subredditName = data.getStringExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
@ -440,13 +437,6 @@ public class SearchActivity extends BaseActivity {
super.onActivityResult(requestCode, resultCode, data);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.search_activity, menu);
simpleSearchView.setMenuItem(menu.findItem(R.id.action_search_search_activity));
return true;
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == android.R.id.home) {

View File

@ -286,7 +286,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
fab.setImageResource(R.drawable.ic_post_layout_24dp);
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SEARCH:
fab.setImageResource(R.drawable.ic_search_black_24dp);
fab.setImageResource(R.drawable.ic_search_24dp);
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_SUBREDDIT:
fab.setImageResource(R.drawable.ic_subreddit_24dp);

View File

@ -299,7 +299,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
fab.setImageResource(R.drawable.ic_post_layout_24dp);
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SEARCH:
fab.setImageResource(R.drawable.ic_search_black_24dp);
fab.setImageResource(R.drawable.ic_search_24dp);
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_SUBREDDIT:
fab.setImageResource(R.drawable.ic_subreddit_24dp);
@ -525,7 +525,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_CHANGE_POST_LAYOUT:
return R.drawable.ic_post_layout_24dp;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SEARCH:
return R.drawable.ic_search_black_24dp;
return R.drawable.ic_search_24dp;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_GO_TO_SUBREDDIT:
return R.drawable.ic_subreddit_24dp;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_GO_TO_USER:

View File

@ -743,7 +743,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_CHANGE_POST_LAYOUT:
return R.drawable.ic_post_layout_24dp;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SEARCH:
return R.drawable.ic_search_black_24dp;
return R.drawable.ic_search_24dp;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_GO_TO_SUBREDDIT:
return R.drawable.ic_subreddit_24dp;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_GO_TO_USER:
@ -853,7 +853,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
fab.setImageResource(R.drawable.ic_post_layout_24dp);
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SEARCH:
fab.setImageResource(R.drawable.ic_search_black_24dp);
fab.setImageResource(R.drawable.ic_search_24dp);
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_SUBREDDIT:
fab.setImageResource(R.drawable.ic_subreddit_24dp);

View File

@ -813,7 +813,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
fab.setImageResource(R.drawable.ic_post_layout_24dp);
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SEARCH:
fab.setImageResource(R.drawable.ic_search_black_24dp);
fab.setImageResource(R.drawable.ic_search_24dp);
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_SUBREDDIT:
fab.setImageResource(R.drawable.ic_subreddit_24dp);
@ -1029,7 +1029,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_CHANGE_POST_LAYOUT:
return R.drawable.ic_post_layout_24dp;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SEARCH:
return R.drawable.ic_search_black_24dp;
return R.drawable.ic_search_24dp;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_GO_TO_SUBREDDIT:
return R.drawable.ic_subreddit_24dp;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_GO_TO_USER:

View File

@ -114,7 +114,7 @@ public class WebViewActivity extends BaseActivity {
protected void applyCustomTheme() {
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar);
Drawable closeIcon = Utils.getTintedDrawable(this, R.drawable.ic_close_black_24dp, mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor());
Drawable closeIcon = Utils.getTintedDrawable(this, R.drawable.ic_close_24dp, mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor());
toolbar.setNavigationIcon(closeIcon);
}

View File

@ -13,32 +13,28 @@
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<FrameLayout
android:id="@+id/toolbar_frame_layout_search_activity"
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:navigationIcon="?attr/homeAsUpIndicator">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<com.ferfalk.simplesearchview.SimpleSearchView
android:id="@+id/search_view_search_activity"
<EditText
android:id="@+id/search_edit_text_search_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:backIconAlpha="1"
app:backIconTint="@android:color/white"
app:cursorColor="@android:color/white"
app:hintColor="#E0E0E0"
app:iconsAlpha="1"
app:iconsTint="@android:color/white"
app:searchBackground="?attr/colorPrimary"
app:voiceSearch="true" />
android:background="#00000000"
android:gravity="top"
android:hint="@string/search"
android:maxLines="1"
android:textSize="?attr/font_20"
android:fontFamily="?attr/font_family"
android:inputType="textNoSuggestions"
android:imeOptions="actionSearch" />
</FrameLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>

View File

@ -113,7 +113,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="8dp"
android:src="@drawable/ic_close_black_24dp"
android:src="@drawable/ic_close_24dp"
android:background="?actionBarItemBackground"
android:clickable="true"
android:focusable="true" />

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:application="ml.docilealligator.infinityforreddit.activities.SearchResultActivity">
<item
android:id="@+id/action_search_search_activity"
android:orderInCategory="1"
android:title="@string/action_search"
android:icon="@drawable/ic_search_toolbar_24dp"
app:showAsAction="ifRoom" />
</menu>