Add the ability to add article to saved / remove article from saved
This commit is contained in:
parent
41bd390b3c
commit
f0d327d609
1 changed files with 26 additions and 5 deletions
|
@ -55,6 +55,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
|
|||
private WikivoyageArticle article;
|
||||
|
||||
private TextView selectedLangTv;
|
||||
private TextView saveBtn;
|
||||
private WebView contentWebView;
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
|
@ -113,11 +114,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
|
|||
}
|
||||
});
|
||||
|
||||
TextView saveBtn = (TextView) mainView.findViewById(R.id.save_button);
|
||||
saveBtn.setText(getString(R.string.shared_string_save));
|
||||
saveBtn.setCompoundDrawablesWithIntrinsicBounds(
|
||||
null, null, getActiveIcon(R.drawable.ic_action_read_later), null
|
||||
);
|
||||
saveBtn = (TextView) mainView.findViewById(R.id.save_button);
|
||||
|
||||
contentWebView = (WebView) mainView.findViewById(R.id.content_web_view);
|
||||
contentWebView.getSettings().setJavaScriptEnabled(true);
|
||||
|
@ -150,6 +147,29 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
|
|||
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) {
|
||||
if (langs == null) {
|
||||
return;
|
||||
|
@ -195,6 +215,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
|
|||
|
||||
WikivoyageLocalDataHelper.getInstance(getMyApplication()).addToHistory(article);
|
||||
|
||||
updateSaveButton();
|
||||
selectedLangTv.setText(Algorithms.capitalizeFirstLetter(selectedLang));
|
||||
contentWebView.loadDataWithBaseURL(getBaseUrl(), createHtmlContent(article), "text/html", "UTF-8", null);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue