Use ContextThemeWrapper for view inflating; add method "isNightMode" to BaseOsmAndDialogFragment
This commit is contained in:
parent
3e2db237a8
commit
8bd74d968d
5 changed files with 34 additions and 11 deletions
|
@ -61,4 +61,11 @@ public class BaseOsmAndDialogFragment extends DialogFragment {
|
||||||
protected OsmandSettings getSettings() {
|
protected OsmandSettings getSettings() {
|
||||||
return getMyApplication().getSettings();
|
return getMyApplication().getSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isNightMode(boolean usedOnMap) {
|
||||||
|
if (usedOnMap) {
|
||||||
|
return getMyApplication().getDaynightHelper().isNightModeForMapControls();
|
||||||
|
}
|
||||||
|
return !getSettings().isLightContent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
package net.osmand.plus.wikivoyage;
|
package net.osmand.plus.wikivoyage;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.base.BaseOsmAndDialogFragment;
|
import net.osmand.plus.base.BaseOsmAndDialogFragment;
|
||||||
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
|
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
|
||||||
|
@ -22,8 +25,12 @@ public class WikivoyageArticleDialogFragment extends BaseOsmAndDialogFragment {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
final View mainView = inflater.inflate(R.layout.fragment_wikivoyage_article_dialog, container);
|
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 toolbar = (Toolbar) mainView.findViewById(R.id.toolbar);
|
||||||
toolbar.setNavigationIcon(getContentIcon(R.drawable.ic_arrow_back));
|
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);
|
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);
|
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");
|
contentWebView.loadData(article.getContent(), "text/html", "UTF-8");
|
||||||
|
|
||||||
return mainView;
|
return mainView;
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
package net.osmand.plus.wikivoyage;
|
package net.osmand.plus.wikivoyage;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.base.BaseOsmAndDialogFragment;
|
import net.osmand.plus.base.BaseOsmAndDialogFragment;
|
||||||
import net.osmand.plus.wikivoyage.search.WikivoyageSearchDialogFragment;
|
import net.osmand.plus.wikivoyage.search.WikivoyageSearchDialogFragment;
|
||||||
|
@ -19,8 +22,12 @@ public class WikivoyageExploreDialogFragment extends BaseOsmAndDialogFragment {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
final View mainView = inflater.inflate(R.layout.fragment_wikivoyage_explore_dialog, container);
|
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 toolbar = (Toolbar) mainView.findViewById(R.id.toolbar);
|
||||||
toolbar.setNavigationIcon(getContentIcon(R.drawable.ic_arrow_back));
|
toolbar.setNavigationIcon(getContentIcon(R.drawable.ic_arrow_back));
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.osmand.plus.wikivoyage.search;
|
package net.osmand.plus.wikivoyage.search;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -23,8 +24,9 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<SearchRecycl
|
||||||
this.onItemClickListener = onItemClickListener;
|
this.onItemClickListener = onItemClickListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
|
||||||
View itemView = LayoutInflater.from(viewGroup.getContext())
|
View itemView = LayoutInflater.from(viewGroup.getContext())
|
||||||
.inflate(R.layout.wikivoyage_search_list_item, viewGroup, false);
|
.inflate(R.layout.wikivoyage_search_list_item, viewGroup, false);
|
||||||
itemView.setOnClickListener(onItemClickListener);
|
itemView.setOnClickListener(onItemClickListener);
|
||||||
|
@ -32,7 +34,7 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<SearchRecycl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(ViewHolder viewHolder, int i) {
|
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
|
||||||
WikivoyageSearchResult item = items.get(i);
|
WikivoyageSearchResult item = items.get(i);
|
||||||
// FIXME
|
// FIXME
|
||||||
viewHolder.searchTerm.setText(item.getSearchTerm().toString());
|
viewHolder.searchTerm.setText(item.getSearchTerm().toString());
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package net.osmand.plus.wikivoyage.search;
|
package net.osmand.plus.wikivoyage.search;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
@ -43,11 +44,10 @@ public class WikivoyageSearchDialogFragment extends BaseOsmAndDialogFragment {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
final OsmandApplication app = getMyApplication();
|
final OsmandApplication app = getMyApplication();
|
||||||
searchHelper = new WikivoyageSearchHelper(app);
|
searchHelper = new WikivoyageSearchHelper(app);
|
||||||
final boolean nightMode = !app.getSettings().isLightContent();
|
final int themeRes = isNightMode(false) ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||||
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
|
||||||
|
|
||||||
final View mainView = LayoutInflater.from(new ContextThemeWrapper(app, themeRes))
|
final View mainView = LayoutInflater.from(new ContextThemeWrapper(app, themeRes))
|
||||||
.inflate(R.layout.fragment_wikivoyage_search_dialog, container, false);
|
.inflate(R.layout.fragment_wikivoyage_search_dialog, container, false);
|
||||||
|
|
Loading…
Reference in a new issue