Skip to content

Commit

Permalink
fixed a crash when clicking on the Donate button but there is no brow…
Browse files Browse the repository at this point in the history
…ser on the device
  • Loading branch information
sspanak committed Oct 24, 2024
1 parent 76ea491 commit d869bd4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,8 @@ public void onResume() {


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();
}


Expand Down
7 changes: 1 addition & 6 deletions app/src/main/res/xml/prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit d869bd4

Please sign in to comment.