1
0
Fork 0

fixed a crash when clicking on the Donate button but there is no browser on the device

This commit is contained in:
sspanak 2024-10-24 13:04:49 +03:00 committed by Dimo Karaivanov
parent 017e5d510e
commit 20c78e47f4
3 changed files with 44 additions and 15 deletions

View file

@ -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;
}
}
}

View file

@ -40,15 +40,8 @@ public class MainSettingsScreen extends BaseScreenFragment {
private void createAboutSection() {
Preference donate = findPreference("donate_link");
if (donate != null) {
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();
(new ItemDonate(findPreference(ItemDonate.NAME), activity)).populate().enableClickHandler();
(new ItemVersionInfo(findPreference(ItemVersionInfo.NAME), activity)).populate().enableClickHandler();
}

View file

@ -38,12 +38,7 @@
<Preference
app:key="donate_link"
app:title="@string/donate_title"
app:summary="@string/donate_summary">
<intent
android:action="android.intent.action.VIEW"
android:data="@string/donate_url" />
</Preference>
app:title="@string/donate_title" />
<Preference
app:key="version_info"