Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2018-04-10 23:47:09 +02:00
commit fcb5703db7
5 changed files with 50 additions and 24 deletions

View file

@ -127,13 +127,13 @@
android:paddingLeft="@dimen/bottom_sheet_content_padding_small" android:paddingLeft="@dimen/bottom_sheet_content_padding_small"
android:paddingRight="@dimen/bottom_sheet_content_padding_small" android:paddingRight="@dimen/bottom_sheet_content_padding_small"
android:paddingTop="@dimen/context_menu_padding_margin_tiny" android:paddingTop="@dimen/context_menu_padding_margin_tiny"
android:text="@string/shared_string_save"
android:textColor="?attr/wikivoyage_active_color" android:textColor="?attr/wikivoyage_active_color"
android:textSize="@dimen/default_desc_text_size" android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium" osmand:typeface="@string/font_roboto_medium"
tools:drawableRight="@drawable/ic_action_read_later_fill" tools:drawableRight="@drawable/ic_action_read_later_fill"
tools:drawableTint="?attr/wikivoyage_active_color" tools:drawableTint="?attr/wikivoyage_active_color"
tools:ignore="UnusedAttribute"/> tools:ignore="UnusedAttribute"
tools:text="Save"/>
</LinearLayout> </LinearLayout>

View file

@ -1,4 +1,4 @@
package net.osmand.plus.wikivoyage; package net.osmand.plus.wikivoyage.article;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -47,6 +47,10 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag
} }
String contentsJson = args.getString(CONTENTS_JSON_KEY); String contentsJson = args.getString(CONTENTS_JSON_KEY);
if (contentsJson == null) {
return;
}
ContentsContainer contentsContainer = ContentsJsonParser.parseJsonContents(contentsJson); ContentsContainer contentsContainer = ContentsJsonParser.parseJsonContents(contentsJson);
if (contentsContainer == null) { if (contentsContainer == null) {
return; return;
@ -157,9 +161,8 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag
boolean isLastChild, View convertView, ViewGroup parent) { boolean isLastChild, View convertView, ViewGroup parent) {
String childText = (String) getChild(groupPosition, childPosition); String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) { if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this.context convertView = LayoutInflater.from(context)
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); .inflate(R.layout.wikivoyage_contents_list_item, parent, false);
convertView = infalInflater.inflate(R.layout.wikivoyage_contents_list_item, parent, false);
} }
TextView txtListChild = (TextView) convertView.findViewById(R.id.item_label); TextView txtListChild = (TextView) convertView.findViewById(R.id.item_label);
txtListChild.setText(childText); txtListChild.setText(childText);
@ -197,9 +200,8 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag
View convertView, ViewGroup parent) { View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition); String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) { if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this.context convertView = LayoutInflater.from(context)
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); .inflate(R.layout.wikivoyage_contents_list_item, parent, false);
convertView = infalInflater.inflate(R.layout.wikivoyage_contents_list_item, parent, false);
} }
TextView lblListHeader = (TextView) convertView.findViewById(R.id.item_label); TextView lblListHeader = (TextView) convertView.findViewById(R.id.item_label);
lblListHeader.setText(headerTitle); lblListHeader.setText(headerTitle);

View file

@ -1,4 +1,4 @@
package net.osmand.plus.wikivoyage; package net.osmand.plus.wikivoyage.article;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Intent; import android.content.Intent;
@ -23,6 +23,7 @@ import android.widget.TextView;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment;
import net.osmand.plus.wikivoyage.data.WikivoyageArticle; import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper; import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -51,9 +52,10 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
private long cityId = NO_VALUE; private long cityId = NO_VALUE;
private ArrayList<String> langs; private ArrayList<String> langs;
private String selectedLang; private String selectedLang;
private String contentsJson; private WikivoyageArticle article;
private TextView selectedLangTv; private TextView selectedLangTv;
private TextView saveBtn;
private WebView contentWebView; private WebView contentWebView;
@SuppressLint("SetJavaScriptEnabled") @SuppressLint("SetJavaScriptEnabled")
@ -98,20 +100,21 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
contentsBtn.setOnClickListener(new View.OnClickListener() { contentsBtn.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
FragmentManager fm = getFragmentManager();
if (article == null || fm == null) {
return;
}
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(WikivoyageArticleContentsFragment.CONTENTS_JSON_KEY, contentsJson); args.putString(WikivoyageArticleContentsFragment.CONTENTS_JSON_KEY, article.getContentsJson());
WikivoyageArticleContentsFragment fragment = new WikivoyageArticleContentsFragment(); WikivoyageArticleContentsFragment fragment = new WikivoyageArticleContentsFragment();
fragment.setUsedOnMap(false); fragment.setUsedOnMap(false);
fragment.setArguments(args); fragment.setArguments(args);
fragment.setTargetFragment(WikivoyageArticleDialogFragment.this, 0); fragment.setTargetFragment(WikivoyageArticleDialogFragment.this, 0);
fragment.show(getFragmentManager(), WikivoyageArticleContentsFragment.TAG); fragment.show(fm, WikivoyageArticleContentsFragment.TAG);
} }
}); });
TextView saveBtn = (TextView) mainView.findViewById(R.id.save_button); saveBtn = (TextView) mainView.findViewById(R.id.save_button);
saveBtn.setCompoundDrawablesWithIntrinsicBounds(
null, null, getActiveIcon(R.drawable.ic_action_read_later), null
);
contentWebView = (WebView) mainView.findViewById(R.id.content_web_view); contentWebView = (WebView) mainView.findViewById(R.id.content_web_view);
contentWebView.getSettings().setJavaScriptEnabled(true); contentWebView.getSettings().setJavaScriptEnabled(true);
@ -144,6 +147,29 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
return nightMode ? R.color.status_bar_wikivoyage_article_dark : R.color.status_bar_wikivoyage_article_light; return nightMode ? R.color.status_bar_wikivoyage_article_dark : R.color.status_bar_wikivoyage_article_light;
} }
private void updateSaveButton() {
if (article != null) {
final WikivoyageLocalDataHelper helper = WikivoyageLocalDataHelper.getInstance(getMyApplication());
final boolean saved = helper.isArticleSaved(article);
Drawable icon = getActiveIcon(saved ? R.drawable.ic_action_read_later_fill : R.drawable.ic_action_read_later);
saveBtn.setText(getString(saved ? R.string.shared_string_delete : R.string.shared_string_save));
saveBtn.setCompoundDrawablesWithIntrinsicBounds(null, null, icon, null);
saveBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (article != null) {
if (saved) {
helper.removeArticleFromSaved(article);
} else {
helper.addArticleToSaved(article);
}
updateSaveButton();
}
}
});
}
}
private void showPopupLangMenu(View view) { private void showPopupLangMenu(View view) {
if (langs == null) { if (langs == null) {
return; return;
@ -182,17 +208,15 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
selectedLang = langs.get(0); selectedLang = langs.get(0);
} }
selectedLangTv.setText(Algorithms.capitalizeFirstLetter(selectedLang)); article = getMyApplication().getWikivoyageDbHelper().getArticle(cityId, selectedLang);
WikivoyageArticle article = getMyApplication().getWikivoyageDbHelper()
.getArticle(cityId, selectedLang);
if (article == null) { if (article == null) {
return; return;
} }
contentsJson = article.getContentsJson();
WikivoyageLocalDataHelper.getInstance(getMyApplication()).addToHistory(article); WikivoyageLocalDataHelper.getInstance(getMyApplication()).addToHistory(article);
updateSaveButton();
selectedLangTv.setText(Algorithms.capitalizeFirstLetter(selectedLang));
contentWebView.loadDataWithBaseURL(getBaseUrl(), createHtmlContent(article), "text/html", "UTF-8", null); contentWebView.loadDataWithBaseURL(getBaseUrl(), createHtmlContent(article), "text/html", "UTF-8", null);
} }

View file

@ -32,7 +32,7 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
private final Drawable readIcon; private final Drawable readIcon;
private final Drawable deleteIcon; private final Drawable deleteIcon;
public SavedArticlesRvAdapter(OsmandApplication app) { SavedArticlesRvAdapter(OsmandApplication app) {
this.app = app; this.app = app;
List<WikivoyageArticle> savedArticles = WikivoyageLocalDataHelper.getInstance(app).getSavedArticles(); List<WikivoyageArticle> savedArticles = WikivoyageLocalDataHelper.getInstance(app).getSavedArticles();
if (!savedArticles.isEmpty()) { if (!savedArticles.isEmpty()) {

View file

@ -19,7 +19,7 @@ import android.widget.ProgressBar;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.wikivoyage.WikivoyageArticleDialogFragment; import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment;
import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment; import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment;
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper; import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
import net.osmand.plus.wikivoyage.data.WikivoyageSearchHistoryItem; import net.osmand.plus.wikivoyage.data.WikivoyageSearchHistoryItem;