From 8bd74d968d5fc6689c93b906e2c322434d17baf0 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 29 Mar 2018 16:05:23 +0300 Subject: [PATCH] Use ContextThemeWrapper for view inflating; add method "isNightMode" to BaseOsmAndDialogFragment --- .../plus/base/BaseOsmAndDialogFragment.java | 7 +++++++ .../WikivoyageArticleDialogFragment.java | 15 +++++++++++---- .../WikivoyageExploreDialogFragment.java | 11 +++++++++-- .../search/SearchRecyclerViewAdapter.java | 6 ++++-- .../search/WikivoyageSearchDialogFragment.java | 6 +++--- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/base/BaseOsmAndDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/BaseOsmAndDialogFragment.java index cca02d1cfd..79f21ac682 100644 --- a/OsmAnd/src/net/osmand/plus/base/BaseOsmAndDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/BaseOsmAndDialogFragment.java @@ -61,4 +61,11 @@ public class BaseOsmAndDialogFragment extends DialogFragment { protected OsmandSettings getSettings() { return getMyApplication().getSettings(); } + + protected boolean isNightMode(boolean usedOnMap) { + if (usedOnMap) { + return getMyApplication().getDaynightHelper().isNightModeForMapControls(); + } + return !getSettings().isLightContent(); + } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageArticleDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageArticleDialogFragment.java index c660694394..f04d9febc8 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageArticleDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageArticleDialogFragment.java @@ -1,14 +1,17 @@ package net.osmand.plus.wikivoyage; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.FragmentManager; import android.support.v7.widget.Toolbar; +import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.webkit.WebView; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.base.BaseOsmAndDialogFragment; import net.osmand.plus.wikivoyage.data.WikivoyageArticle; @@ -22,8 +25,12 @@ public class WikivoyageArticleDialogFragment extends BaseOsmAndDialogFragment { @Nullable @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - final View mainView = inflater.inflate(R.layout.fragment_wikivoyage_article_dialog, container); + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + final OsmandApplication app = getMyApplication(); + final int themeRes = isNightMode(false) ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + + final View mainView = LayoutInflater.from(new ContextThemeWrapper(app, themeRes)) + .inflate(R.layout.fragment_wikivoyage_article_dialog, container, false); Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.toolbar); toolbar.setNavigationIcon(getContentIcon(R.drawable.ic_arrow_back)); @@ -36,10 +43,10 @@ public class WikivoyageArticleDialogFragment extends BaseOsmAndDialogFragment { }); WikivoyageSearchResult searchResult = (WikivoyageSearchResult) getArguments().getParcelable(SEARCH_RESULT_KEY); + WikivoyageArticle article = app.getWikivoyageDbHelper() + .getArticle(searchResult.getCityId(), searchResult.getLang().get(0)); WebView contentWebView = (WebView) mainView.findViewById(R.id.content_web_view); - WikivoyageArticle article = getMyApplication().getWikivoyageDbHelper() - .getArticle(searchResult.getCityId(), searchResult.getLang().get(0)); contentWebView.loadData(article.getContent(), "text/html", "UTF-8"); return mainView; diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageExploreDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageExploreDialogFragment.java index 6d61239c5d..6281312c10 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageExploreDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageExploreDialogFragment.java @@ -1,14 +1,17 @@ package net.osmand.plus.wikivoyage; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.FragmentManager; import android.support.v7.widget.Toolbar; +import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.base.BaseOsmAndDialogFragment; import net.osmand.plus.wikivoyage.search.WikivoyageSearchDialogFragment; @@ -19,8 +22,12 @@ public class WikivoyageExploreDialogFragment extends BaseOsmAndDialogFragment { @Nullable @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - final View mainView = inflater.inflate(R.layout.fragment_wikivoyage_explore_dialog, container); + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + final OsmandApplication app = getMyApplication(); + final int themeRes = isNightMode(false) ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + + final View mainView = LayoutInflater.from(new ContextThemeWrapper(app, themeRes)) + .inflate(R.layout.fragment_wikivoyage_explore_dialog, container, false); Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.toolbar); toolbar.setNavigationIcon(getContentIcon(R.drawable.ic_arrow_back)); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/search/SearchRecyclerViewAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/search/SearchRecyclerViewAdapter.java index ee1aeee343..607b5dea6f 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/search/SearchRecyclerViewAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/search/SearchRecyclerViewAdapter.java @@ -1,5 +1,6 @@ package net.osmand.plus.wikivoyage.search; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; @@ -23,8 +24,9 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter