Improve WikivoyageArticleDialogFragment stability

This commit is contained in:
Alex Sytnyk 2018-04-11 00:16:09 +03:00
parent c51f1b74b0
commit 41bd390b3c
2 changed files with 12 additions and 10 deletions

View file

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

View file

@ -52,7 +52,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
private long cityId = NO_VALUE;
private ArrayList<String> langs;
private String selectedLang;
private String contentsJson;
private WikivoyageArticle article;
private TextView selectedLangTv;
private WebView contentWebView;
@ -99,17 +99,22 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
contentsBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fm = getFragmentManager();
if (article == null || fm == null) {
return;
}
Bundle args = new Bundle();
args.putString(WikivoyageArticleContentsFragment.CONTENTS_JSON_KEY, contentsJson);
args.putString(WikivoyageArticleContentsFragment.CONTENTS_JSON_KEY, article.getContentsJson());
WikivoyageArticleContentsFragment fragment = new WikivoyageArticleContentsFragment();
fragment.setUsedOnMap(false);
fragment.setArguments(args);
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.setText(getString(R.string.shared_string_save));
saveBtn.setCompoundDrawablesWithIntrinsicBounds(
null, null, getActiveIcon(R.drawable.ic_action_read_later), null
);
@ -183,17 +188,14 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
selectedLang = langs.get(0);
}
selectedLangTv.setText(Algorithms.capitalizeFirstLetter(selectedLang));
WikivoyageArticle article = getMyApplication().getWikivoyageDbHelper()
.getArticle(cityId, selectedLang);
article = getMyApplication().getWikivoyageDbHelper().getArticle(cityId, selectedLang);
if (article == null) {
return;
}
contentsJson = article.getContentsJson();
WikivoyageLocalDataHelper.getInstance(getMyApplication()).addToHistory(article);
selectedLangTv.setText(Algorithms.capitalizeFirstLetter(selectedLang));
contentWebView.loadDataWithBaseURL(getBaseUrl(), createHtmlContent(article), "text/html", "UTF-8", null);
}