Refactor some code
This commit is contained in:
parent
57fd20ef9e
commit
2914d883bf
4 changed files with 25 additions and 25 deletions
|
@ -230,9 +230,9 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
|
||||||
private String createHtmlContent(@NonNull WikivoyageArticle article) {
|
private String createHtmlContent(@NonNull WikivoyageArticle article) {
|
||||||
StringBuilder sb = new StringBuilder(HEADER_INNER);
|
StringBuilder sb = new StringBuilder(HEADER_INNER);
|
||||||
|
|
||||||
String articleImageTitle = article.getImageTitle();
|
String imageTitle = article.getImageTitle();
|
||||||
if (!TextUtils.isEmpty(articleImageTitle)&&getSettings().WIKIVOYAGE_SHOW_IMAGES.get()) {
|
if (!TextUtils.isEmpty(imageTitle) && getSettings().WIKIVOYAGE_SHOW_IMAGES.get()) {
|
||||||
String url = WikivoyageArticle.getImageUrl(articleImageTitle, false);
|
String url = WikivoyageArticle.getImageUrl(imageTitle, false);
|
||||||
sb.append("<div class=\"title-image\" style=\"background-image: url(").append(url).append(")\"></div>");
|
sb.append("<div class=\"title-image\" style=\"background-image: url(").append(url).append(")\"></div>");
|
||||||
}
|
}
|
||||||
sb.append("<div class=\"main\">\n");
|
sb.append("<div class=\"main\">\n");
|
||||||
|
|
|
@ -41,6 +41,15 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
|
||||||
|
|
||||||
setupToolbar((Toolbar) mainView.findViewById(R.id.toolbar));
|
setupToolbar((Toolbar) mainView.findViewById(R.id.toolbar));
|
||||||
|
|
||||||
|
mainView.findViewById(R.id.options_button).setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
WikivoyageOptionsBottomSheetDialogFragment fragment = new WikivoyageOptionsBottomSheetDialogFragment();
|
||||||
|
fragment.setUsedOnMap(false);
|
||||||
|
fragment.show(getChildFragmentManager(), WikivoyageOptionsBottomSheetDialogFragment.TAG);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
int searchColorId = nightMode ? R.color.icon_color : R.color.ctx_menu_title_color_dark;
|
int searchColorId = nightMode ? R.color.icon_color : R.color.ctx_menu_title_color_dark;
|
||||||
((TextView) mainView.findViewById(R.id.search_hint)).setTextColor(getResolvedColor(searchColorId));
|
((TextView) mainView.findViewById(R.id.search_hint)).setTextColor(getResolvedColor(searchColorId));
|
||||||
((ImageView) mainView.findViewById(R.id.search_icon))
|
((ImageView) mainView.findViewById(R.id.search_icon))
|
||||||
|
@ -53,15 +62,6 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mainView.findViewById(R.id.options_button).setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
OptionsImagesCacheHistoryBottomSheetDialogFragment fragment = new OptionsImagesCacheHistoryBottomSheetDialogFragment();
|
|
||||||
fragment.setUsedOnMap(false);
|
|
||||||
fragment.show(getChildFragmentManager(), OptionsImagesCacheHistoryBottomSheetDialogFragment.TAG);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
final LockableViewPager viewPager = (LockableViewPager) mainView.findViewById(R.id.view_pager);
|
final LockableViewPager viewPager = (LockableViewPager) mainView.findViewById(R.id.view_pager);
|
||||||
viewPager.setOffscreenPageLimit(2);
|
viewPager.setOffscreenPageLimit(2);
|
||||||
viewPager.setSwipeLocked(true);
|
viewPager.setSwipeLocked(true);
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||||
|
@ -15,36 +16,35 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||||
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
|
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
|
||||||
|
|
||||||
public class OptionsImagesCacheHistoryBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
|
public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
|
||||||
|
|
||||||
public final static String TAG = "OptionsImagesCasheBottomSheetDialogFragment";
|
public final static String TAG = "WikivoyageOptionsBottomSheetDialogFragment";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createMenuItems(Bundle savedInstanceState) {
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
|
final OsmandApplication app = getMyApplication();
|
||||||
|
final OsmandSettings.CommonPreference<Boolean> showImagesPref = app.getSettings().WIKIVOYAGE_SHOW_IMAGES;
|
||||||
|
|
||||||
items.add(new TitleItem(getString(R.string.shared_string_options)));
|
items.add(new TitleItem(getString(R.string.shared_string_options)));
|
||||||
|
|
||||||
boolean showImages = getMyApplication().getSettings().WIKIVOYAGE_SHOW_IMAGES.get();
|
BaseBottomSheetItem showImagesItem = new BottomSheetItemWithCompoundButton.Builder()
|
||||||
|
.setChecked(showImagesPref.get())
|
||||||
BaseBottomSheetItem showWebviewImagesItem = new BottomSheetItemWithCompoundButton.Builder()
|
|
||||||
.setChecked(showImages)
|
|
||||||
.setIcon(getContentIcon(R.drawable.ic_type_img))
|
.setIcon(getContentIcon(R.drawable.ic_type_img))
|
||||||
.setTitle(getString(R.string.show_images))
|
.setTitle(getString(R.string.show_images))
|
||||||
.setLayoutId(R.layout.bottom_sheet_item_with_switch)
|
.setLayoutId(R.layout.bottom_sheet_item_with_switch)
|
||||||
.setOnClickListener(new View.OnClickListener() {
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
OsmandSettings settings = getMyApplication().getSettings();
|
showImagesPref.set(!showImagesPref.get());
|
||||||
settings.WIKIVOYAGE_SHOW_IMAGES.set(!settings.WIKIVOYAGE_SHOW_IMAGES.get());
|
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.create();
|
.create();
|
||||||
items.add(showWebviewImagesItem);
|
items.add(showImagesItem);
|
||||||
|
|
||||||
BaseBottomSheetItem clearCacheItem = new BottomSheetItemWithDescription.Builder()
|
BaseBottomSheetItem clearCacheItem = new BottomSheetItemWithDescription.Builder()
|
||||||
.setDescription(getString(R.string.shared_string_clear))
|
.setDescription(getString(R.string.shared_string_clear))
|
||||||
.setTitle(getString(R.string.images_cache)+":")
|
.setTitle(getString(R.string.images_cache) + ":")
|
||||||
.setLayoutId(R.layout.bottom_sheet_item_with_right_descr)
|
.setLayoutId(R.layout.bottom_sheet_item_with_right_descr)
|
||||||
.setOnClickListener(new View.OnClickListener() {
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -65,7 +65,7 @@ public class OptionsImagesCacheHistoryBottomSheetDialogFragment extends MenuBott
|
||||||
.setOnClickListener(new View.OnClickListener() {
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
WikivoyageLocalDataHelper.getInstance(getMyApplication()).clearHistory();
|
WikivoyageLocalDataHelper.getInstance(app).clearHistory();
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
})
|
})
|
|
@ -74,8 +74,8 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
|
||||||
if (item instanceof WikivoyageSearchResult) {
|
if (item instanceof WikivoyageSearchResult) {
|
||||||
WikivoyageSearchResult searchRes = (WikivoyageSearchResult) item;
|
WikivoyageSearchResult searchRes = (WikivoyageSearchResult) item;
|
||||||
Picasso.get()
|
Picasso.get()
|
||||||
.load(app.getSettings().WIKIVOYAGE_SHOW_IMAGES.get() ?
|
.load(app.getSettings().WIKIVOYAGE_SHOW_IMAGES.get()
|
||||||
WikivoyageArticle.getImageUrl(searchRes.getImageTitle(), true) : null)
|
? WikivoyageArticle.getImageUrl(searchRes.getImageTitle(), true) : null)
|
||||||
.transform(new CropCircleTransformation())
|
.transform(new CropCircleTransformation())
|
||||||
.placeholder(placeholder)
|
.placeholder(placeholder)
|
||||||
.into(holder.icon);
|
.into(holder.icon);
|
||||||
|
|
Loading…
Reference in a new issue