Fix night mode issues with search and categories (#2213)

This commit is contained in:
Adam Jones 2019-01-01 10:55:46 +00:00 committed by Vivek Maskara
parent 55113b3018
commit 5317063689
4 changed files with 4 additions and 36 deletions

View file

@ -58,16 +58,9 @@ public class SearchActivity extends NavigationBaseActivity implements MediaDetai
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean currentThemeIsDark = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("theme", false);
setContentView(R.layout.activity_search);
ButterKnife.bind(this);
initDrawer();
if (currentThemeIsDark) {
searchView.setBackgroundResource(R.color.vpi__bright_foreground_disabled_holo_dark);
tabLayout.setBackgroundResource(R.color.vpi__bright_foreground_disabled_holo_dark);
toolbar.setBackgroundResource(R.color.vpi__bright_foreground_disabled_holo_dark);
viewPager.setBackgroundResource(R.color.vpi__bright_foreground_disabled_holo_dark);
}
setTitle(getString(R.string.title_activity_search));
toolbar.setNavigationOnClickListener(v->onBackPressed());
supportFragmentManager = getSupportFragmentManager();

View file

@ -1,8 +1,6 @@
package fr.free.nrw.commons.explore.recentsearches;
import android.content.Context;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
@ -34,7 +32,6 @@ public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
ArrayAdapter adapter;
@BindView(R.id.recent_searches_delete_button)
ImageView recent_searches_delete_button;
boolean currentThemeIsDark = false;
@BindView(R.id.recent_searches_text_view)
TextView recent_searches_text_view;
@ -68,13 +65,12 @@ public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
.create()
.show();
});
currentThemeIsDark = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("theme", false);
setAdapterForThemes(getContext(), currentThemeIsDark);
adapter = new ArrayAdapter<>(requireContext(), R.layout.item_recent_searches, recentSearches);
recentSearchesList.setAdapter(adapter);
recentSearchesList.setOnItemClickListener((parent, view, position, id) -> (
(SearchActivity)getContext()).updateText(recentSearches.get(position)));
adapter.notifyDataSetChanged();
updateRecentSearches();
return rootView;
}
@ -84,8 +80,7 @@ public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
*/
@Override
public void onResume() {
recentSearches = recentSearchesDao.recentSearches(10);
adapter.notifyDataSetChanged();
updateRecentSearches();
super.onResume();
}
@ -94,8 +89,6 @@ public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
*/
public void updateRecentSearches() {
recentSearches = recentSearchesDao.recentSearches(10);
setAdapterForThemes(getContext(), currentThemeIsDark);
recentSearchesList.setAdapter(adapter);
adapter.notifyDataSetChanged();
if(!recentSearches.isEmpty()) {
@ -103,12 +96,4 @@ public class RecentSearchesFragment extends CommonsDaggerSupportFragment {
recent_searches_text_view.setText(R.string.search_recent_header);
}
}
private void setAdapterForThemes(Context context, boolean currentThemeIsDark) {
if (currentThemeIsDark) {
adapter = new ArrayAdapter<String>(context, R.layout.item_recent_searches_dark_theme, recentSearches);
} else {
adapter = new ArrayAdapter<String>(context, R.layout.item_recent_searches, recentSearches);
}
}
}

View file

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="@+id/textView1"
android:layout_width="match_parent"
android:background="@color/item_white_background"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="@dimen/standard_gap"

View file

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/vpi__bright_foreground_disabled_holo_dark"
android:padding="@dimen/standard_gap"
android:text="@string/search_commons"
android:textAppearance="?android:attr/textAppearanceMedium" />