From edce58ab035d2db81c80fab5cb66e26f019d9246 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Fri, 28 Aug 2015 12:09:59 +0200 Subject: [PATCH] Fixed UI issues due to dark theme and appcompat. Corrects dialog colors on dark theme, fixes #224. Corrects display of contextual action bar and search entry box. --- app/build.gradle | 15 ++-- .../core/app/settings/SystemSettings.java | 6 ++ .../core/gui/navigation/SetLabelDialog.java | 5 +- .../navigation/SetStorageLocationDialog.java | 5 +- .../gui/navigation/SetTrackersDialog.java | 5 +- .../navigation/SetTransferRatesDialog.java | 9 +- .../core/gui/search/SearchActivity.java | 83 ++++++++++--------- .../gui/search/SearchResultsFragment.java | 4 +- app/src/main/res/layout/activity_search.xml | 9 +- build.gradle | 2 +- 10 files changed, 85 insertions(+), 58 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 3a9cba58..a6cbe016 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,14 +2,15 @@ apply plugin: 'com.android.application' apply plugin: 'android-apt' android { - compileSdkVersion 22 - buildToolsVersion '21.1.2' + compileSdkVersion 23 + buildToolsVersion '23.0.0' + useLibrary 'org.apache.http.legacy' defaultConfig { minSdkVersion 15 - targetSdkVersion 22 - versionCode 222 - versionName '2.5.2' + targetSdkVersion 23 + versionCode 223 + versionName '2.5.3' } buildTypes { release { @@ -37,8 +38,8 @@ dependencies { compile 'com.j256.ormlite:ormlite-core:4.48' compile 'com.j256.ormlite:ormlite-android:4.48' compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3' - compile 'com.android.support:appcompat-v7:22.2.0' - compile 'com.android.support:support-annotations:22.2.0' + compile 'com.android.support:appcompat-v7:23.0.0' + compile 'com.android.support:support-annotations:23.0.0' compile 'com.getbase:floatingactionbutton:1.8.0' compile 'com.afollestad:material-dialogs:0.6.3.3' compile 'com.nispok:snackbar:2.10.6' diff --git a/app/src/main/java/org/transdroid/core/app/settings/SystemSettings.java b/app/src/main/java/org/transdroid/core/app/settings/SystemSettings.java index 31449136..ee696c5f 100644 --- a/app/src/main/java/org/transdroid/core/app/settings/SystemSettings.java +++ b/app/src/main/java/org/transdroid/core/app/settings/SystemSettings.java @@ -27,6 +27,8 @@ import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; +import com.afollestad.materialdialogs.Theme; + /** * Allows instantiation of the settings specified in R.xml.pref_system. * @author Eric Kok @@ -62,6 +64,10 @@ public class SystemSettings { return prefs.getBoolean("system_usedarktheme", false); } + public Theme getMaterialDialogtheme() { + return useDarkTheme() ? Theme.DARK: Theme.LIGHT; + } + /** * Returns the date when we last checked transdroid.org for the latest app version. * @return The date/time when the {@link AppUpdateService} checked on the server for updates diff --git a/app/src/main/java/org/transdroid/core/gui/navigation/SetLabelDialog.java b/app/src/main/java/org/transdroid/core/gui/navigation/SetLabelDialog.java index 1a949580..beea01d6 100644 --- a/app/src/main/java/org/transdroid/core/gui/navigation/SetLabelDialog.java +++ b/app/src/main/java/org/transdroid/core/gui/navigation/SetLabelDialog.java @@ -30,6 +30,7 @@ import com.nispok.snackbar.Snackbar; import com.nispok.snackbar.SnackbarManager; import org.transdroid.R; +import org.transdroid.core.app.settings.SystemSettings_; import java.util.Iterator; import java.util.List; @@ -71,7 +72,7 @@ public class SetLabelDialog { public void onNeutral(MaterialDialog dialog) { onLabelPickedListener.onLabelPicked(null); } - }).build(); + }).theme(SystemSettings_.getInstance_(context).getMaterialDialogtheme()).build(); if (currentLabels.size() == 0) { // Hide the list (and its label) if there are no labels yet @@ -93,7 +94,7 @@ public class SetLabelDialog { } public interface OnLabelPickedListener { - public void onLabelPicked(String newLabel); + void onLabelPicked(String newLabel); } } diff --git a/app/src/main/java/org/transdroid/core/gui/navigation/SetStorageLocationDialog.java b/app/src/main/java/org/transdroid/core/gui/navigation/SetStorageLocationDialog.java index 583d0622..6befd3e5 100644 --- a/app/src/main/java/org/transdroid/core/gui/navigation/SetStorageLocationDialog.java +++ b/app/src/main/java/org/transdroid/core/gui/navigation/SetStorageLocationDialog.java @@ -24,6 +24,7 @@ import android.widget.EditText; import com.afollestad.materialdialogs.MaterialDialog; import org.transdroid.R; +import org.transdroid.core.app.settings.SystemSettings_; public class SetStorageLocationDialog { @@ -44,11 +45,11 @@ public class SetStorageLocationDialog { // User is done editing and requested to update given the text input onStorageLocationUpdatedListener.onStorageLocationUpdated(locationText.getText().toString()); } - }).show(); + }).theme(SystemSettings_.getInstance_(context).getMaterialDialogtheme()).show(); } public interface OnStorageLocationUpdatedListener { - public void onStorageLocationUpdated(String newLocation); + void onStorageLocationUpdated(String newLocation); } } diff --git a/app/src/main/java/org/transdroid/core/gui/navigation/SetTrackersDialog.java b/app/src/main/java/org/transdroid/core/gui/navigation/SetTrackersDialog.java index a33eceb7..14f54fbf 100644 --- a/app/src/main/java/org/transdroid/core/gui/navigation/SetTrackersDialog.java +++ b/app/src/main/java/org/transdroid/core/gui/navigation/SetTrackersDialog.java @@ -25,6 +25,7 @@ import android.widget.EditText; import com.afollestad.materialdialogs.MaterialDialog; import org.transdroid.R; +import org.transdroid.core.app.settings.SystemSettings_; import java.util.Arrays; import java.util.List; @@ -48,11 +49,11 @@ public class SetTrackersDialog extends DialogFragment { // User is done editing and requested to update given the text input onTrackersUpdatedListener.onTrackersUpdated(Arrays.asList(trackersText.getText().toString().split("\n"))); } - }).show(); + }).theme(SystemSettings_.getInstance_(context).getMaterialDialogtheme()).show(); } public interface OnTrackersUpdatedListener { - public void onTrackersUpdated(List updatedTrackers); + void onTrackersUpdated(List updatedTrackers); } } diff --git a/app/src/main/java/org/transdroid/core/gui/navigation/SetTransferRatesDialog.java b/app/src/main/java/org/transdroid/core/gui/navigation/SetTransferRatesDialog.java index c69867f7..0b4c1dbd 100644 --- a/app/src/main/java/org/transdroid/core/gui/navigation/SetTransferRatesDialog.java +++ b/app/src/main/java/org/transdroid/core/gui/navigation/SetTransferRatesDialog.java @@ -26,6 +26,7 @@ import android.widget.TextView; import com.afollestad.materialdialogs.MaterialDialog; import org.transdroid.R; +import org.transdroid.core.app.settings.SystemSettings_; public class SetTransferRatesDialog { @@ -62,7 +63,7 @@ public class SetTransferRatesDialog { public void onNeutral(MaterialDialog dialog) { onRatesPickedListener.resetRates(); } - }).build(); + }).theme(SystemSettings_.getInstance_(context).getMaterialDialogtheme()).build(); bindButtons(dialog.getCustomView(), maxSpeedDown, R.id.down1Button, R.id.down2Button, R.id.down3Button, R.id.down4Button, R.id.down5Button, R.id.down6Button, R.id.down7Button, R.id.down8Button, R.id.down9Button, R.id.down0Button); @@ -98,11 +99,11 @@ public class SetTransferRatesDialog { * Listener interface to the user having picked or wanting to resets the current maximum transfer speeds; */ public interface OnRatesPickedListener { - public void onRatesPicked(int maxDownloadSpeed, int maxUploadSpeed); + void onRatesPicked(int maxDownloadSpeed, int maxUploadSpeed); - public void resetRates(); + void resetRates(); - public void onInvalidNumber(); + void onInvalidNumber(); } } diff --git a/app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java b/app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java index 1021c696..4d82026e 100644 --- a/app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java @@ -16,16 +16,12 @@ */ package org.transdroid.core.gui.search; -import android.annotation.TargetApi; import android.app.SearchManager; import android.content.Intent; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.provider.SearchRecentSuggestions; import android.support.v4.view.MenuItemCompat; -import android.support.v7.app.ActionBar; -import android.support.v7.app.ActionBarActivity; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.Menu; @@ -35,6 +31,7 @@ import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; import android.widget.SearchView; +import android.widget.Spinner; import android.widget.TextView; import org.androidannotations.annotations.AfterViews; @@ -42,7 +39,6 @@ import org.androidannotations.annotations.Bean; import org.androidannotations.annotations.EActivity; import org.androidannotations.annotations.FragmentById; import org.androidannotations.annotations.OptionsItem; -import org.androidannotations.annotations.OptionsMenu; import org.androidannotations.annotations.SystemService; import org.androidannotations.annotations.ViewById; import org.transdroid.R; @@ -62,11 +58,12 @@ import java.util.List; * @author Eric Kok */ @EActivity(R.layout.activity_search) -@OptionsMenu(R.menu.activity_search) -public class SearchActivity extends AppCompatActivity implements ActionBar.OnNavigationListener { +public class SearchActivity extends AppCompatActivity { @ViewById protected Toolbar searchToolbar; + @ViewById + protected Spinner sitesSpinner; @FragmentById(R.id.searchresults_fragment) protected SearchResultsFragment fragmentResults; @ViewById @@ -84,14 +81,6 @@ public class SearchActivity extends AppCompatActivity implements ActionBar.OnNav private List searchSites; private SearchSetting lastUsedSite; - private OnItemClickListener onSearchSiteClicked = new OnItemClickListener() { - - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - lastUsedSite = searchSites.get(position); - refreshSearch(); - } - }; private String lastUsedQuery; @Override @@ -106,8 +95,14 @@ public class SearchActivity extends AppCompatActivity implements ActionBar.OnNav @AfterViews protected void init() { + searchToolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha); + searchToolbar.setNavigationOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + TorrentsActivity_.intent(SearchActivity.this).flags(Intent.FLAG_ACTIVITY_CLEAR_TOP).start(); + } + }); setSupportActionBar(searchToolbar); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Get the user query, as coming from the standard SearchManager handleIntent(getIntent()); @@ -133,6 +128,7 @@ public class SearchActivity extends AppCompatActivity implements ActionBar.OnNav // Allow site selection via list (on large screens) or action bar spinner if (searchsitesList != null) { // The current layout has a dedicated list view to select the search site + sitesSpinner.setVisibility(View.GONE); SearchSitesAdapter searchSitesAdapter = SearchSitesAdapter_.getInstance_(this); searchSitesAdapter.update(searchSites); searchsitesList.setAdapter(searchSitesAdapter); @@ -145,26 +141,31 @@ public class SearchActivity extends AppCompatActivity implements ActionBar.OnNav } } else { // Use the action bar spinner to select sites - getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); - getSupportActionBar().setDisplayShowTitleEnabled(false); - getSupportActionBar().setListNavigationCallbacks(new SearchSettingsDropDownAdapter(searchToolbar.getContext(), searchSites), this); + sitesSpinner.setVisibility(View.VISIBLE); + sitesSpinner.setAdapter(new SearchSettingsDropDownAdapter(searchToolbar.getContext(), searchSites)); + sitesSpinner.setOnItemSelectedListener(onSearchSiteSelected); // Select the last used site; this also starts the search! if (lastUsedPosition >= 0) { - getSupportActionBar().setSelectedNavigationItem(lastUsedPosition); + sitesSpinner.setSelection(lastUsedPosition); + lastUsedSite = searchSites.get(lastUsedPosition); + refreshSearch(); } } + invalidateOptionsMenu(); } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); + // Manually insert the actions into the main torrent and secondary actions toolbars + searchToolbar.inflateMenu(R.menu.activity_search); // Add an expandable SearchView to the action bar MenuItem item = menu.findItem(R.id.action_search); final SearchView searchView = new SearchView(searchToolbar.getContext()); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setQueryRefinementEnabled(true); - //searchView.setIconified(false); + searchView.setIconified(false); searchView.setIconifiedByDefault(false); MenuItemCompat.setActionView(item, searchView); searchMenu = item; @@ -176,9 +177,9 @@ public class SearchActivity extends AppCompatActivity implements ActionBar.OnNav super.onPrepareOptionsMenu(menu); boolean searchInstalled = searchHelper.isTorrentSearchInstalled(); - menu.findItem(R.id.action_search).setVisible(searchInstalled); - menu.findItem(R.id.action_refresh).setVisible(searchInstalled); - menu.findItem(R.id.action_downloadsearch).setVisible(!searchInstalled); + searchToolbar.getMenu().findItem(R.id.action_search).setVisible(searchInstalled); + searchToolbar.getMenu().findItem(R.id.action_refresh).setVisible(searchInstalled); + searchToolbar.getMenu().findItem(R.id.action_downloadsearch).setVisible(!searchInstalled); if (searchsitesList != null) { searchsitesList.setVisibility(searchInstalled ? View.VISIBLE : View.GONE); } @@ -222,18 +223,25 @@ public class SearchActivity extends AppCompatActivity implements ActionBar.OnNav return true; } - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - @OptionsItem(android.R.id.home) - protected void navigateUp() { - TorrentsActivity_.intent(this).flags(Intent.FLAG_ACTIVITY_CLEAR_TOP).start(); - } + private OnItemClickListener onSearchSiteClicked = new OnItemClickListener() { - @Override - public boolean onNavigationItemSelected(int itemPosition, long itemId) { - lastUsedSite = searchSites.get(itemPosition); - refreshSearch(); - return true; - } + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + lastUsedSite = searchSites.get(position); + refreshSearch(); + } + }; + private AdapterView.OnItemSelectedListener onSearchSiteSelected = new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + lastUsedSite = searchSites.get(position); + refreshSearch(); + } + + @Override + public void onNothingSelected(AdapterView parent) { + } + }; /** * Extracts the query string from the search {@link Intent} @@ -278,8 +286,9 @@ public class SearchActivity extends AppCompatActivity implements ActionBar.OnNav // Save the search site currently used to search for future usage applicationSettings.setLastUsedSearchSite(lastUsedSite); // Update the activity title (only shown on large devices) - getSupportActionBar().setTitle( - NavigationHelper.buildCondensedFontString(getString(R.string.search_queryonsite, lastUsedQuery, lastUsedSite.getName()))); + if (sitesSpinner.getVisibility() == View.GONE) + searchToolbar.setTitle( + NavigationHelper.buildCondensedFontString(getString(R.string.search_queryonsite, lastUsedQuery, lastUsedSite.getName()))); // Ask the results fragment to start a search for the specified query fragmentResults.startSearch(lastUsedQuery, (SearchSite) lastUsedSite); diff --git a/app/src/main/java/org/transdroid/core/gui/search/SearchResultsFragment.java b/app/src/main/java/org/transdroid/core/gui/search/SearchResultsFragment.java index 65ff59f7..217cc624 100644 --- a/app/src/main/java/org/transdroid/core/gui/search/SearchResultsFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/search/SearchResultsFragment.java @@ -20,7 +20,7 @@ import android.app.Fragment; import android.content.Context; import android.content.Intent; import android.net.Uri; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.view.ActionMode; import android.view.Menu; @@ -153,7 +153,7 @@ public class SearchResultsFragment extends Fragment { public boolean onCreateActionMode(ActionMode mode, Menu menu) { // Show contextual action bar to add items in batch mode mode.getMenuInflater().inflate(R.menu.fragment_searchresults_cab, menu); - Context themedContext = ((ActionBarActivity) getActivity()).getSupportActionBar().getThemedContext(); + Context themedContext = ((AppCompatActivity) getActivity()).getSupportActionBar().getThemedContext(); selectionManagerMode = new SelectionManagerMode(themedContext, resultsList, R.plurals.search_resutlsselected); selectionManagerMode.onCreateActionMode(mode, menu); return true; diff --git a/app/src/main/res/layout/activity_search.xml b/app/src/main/res/layout/activity_search.xml index d4a93c52..d10c00b0 100644 --- a/app/src/main/res/layout/activity_search.xml +++ b/app/src/main/res/layout/activity_search.xml @@ -26,7 +26,14 @@ style="@style/DefaultToolbar" android:layout_width="match_parent" android:layout_height="wrap_content" - android:minHeight="?attr/actionBarSize" /> + android:minHeight="?attr/actionBarSize"> + + + +