fixed a crash when clicking on the Donate button but there is no browser on the device
This commit is contained in:
parent
017e5d510e
commit
20c78e47f4
3 changed files with 44 additions and 15 deletions
|
|
@ -0,0 +1,41 @@
|
||||||
|
package io.github.sspanak.tt9.preferences.screens.main;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
|
import io.github.sspanak.tt9.R;
|
||||||
|
import io.github.sspanak.tt9.preferences.PreferencesActivity;
|
||||||
|
import io.github.sspanak.tt9.preferences.items.ItemClickable;
|
||||||
|
import io.github.sspanak.tt9.util.Logger;
|
||||||
|
|
||||||
|
class ItemDonate extends ItemClickable {
|
||||||
|
static final String NAME = "donate_link";
|
||||||
|
private final PreferencesActivity activity;
|
||||||
|
|
||||||
|
ItemDonate(Preference preference, PreferencesActivity activity) {
|
||||||
|
super(preference);
|
||||||
|
this.activity = activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemDonate populate() {
|
||||||
|
if (item != null) {
|
||||||
|
String appName = activity.getString(R.string.app_name_short);
|
||||||
|
String url = activity.getString(R.string.donate_url_short);
|
||||||
|
item.setSummary(activity.getString(R.string.donate_summary, appName, url));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean onClick(Preference p) {
|
||||||
|
try {
|
||||||
|
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(activity.getString(R.string.donate_url))));
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Logger.w(getClass().getSimpleName(), "Cannot navigate to the donation page. " + e.getMessage() + " (do you have a browser?)");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -40,15 +40,8 @@ public class MainSettingsScreen extends BaseScreenFragment {
|
||||||
|
|
||||||
|
|
||||||
private void createAboutSection() {
|
private void createAboutSection() {
|
||||||
Preference donate = findPreference("donate_link");
|
(new ItemDonate(findPreference(ItemDonate.NAME), activity)).populate().enableClickHandler();
|
||||||
if (donate != null) {
|
(new ItemVersionInfo(findPreference(ItemVersionInfo.NAME), activity)).populate().enableClickHandler();
|
||||||
String appName = getString(R.string.app_name_short);
|
|
||||||
String url = getString(R.string.donate_url_short);
|
|
||||||
donate.setSummary(getString(R.string.donate_summary, appName, url));
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemVersionInfo debugOptions = new ItemVersionInfo(findPreference(ItemVersionInfo.NAME), activity);
|
|
||||||
debugOptions.populate().enableClickHandler();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,12 +38,7 @@
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
app:key="donate_link"
|
app:key="donate_link"
|
||||||
app:title="@string/donate_title"
|
app:title="@string/donate_title" />
|
||||||
app:summary="@string/donate_summary">
|
|
||||||
<intent
|
|
||||||
android:action="android.intent.action.VIEW"
|
|
||||||
android:data="@string/donate_url" />
|
|
||||||
</Preference>
|
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
app:key="version_info"
|
app:key="version_info"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue