Use correct URIs when attempting to show donate links.

This extracts the functionality from the old AppDetails which prefixes
donation links with the relevant scheme (bitcoin: or litecoin:) or URL
(https://flattr.com/thing/) into the App class.
This commit is contained in:
Peter Serwylo 2016-11-30 22:28:12 +11:00
parent 190cf40ff9
commit 774ca02d22
3 changed files with 28 additions and 12 deletions

View File

@ -1182,13 +1182,13 @@ public class AppDetails extends AppCompatActivity {
url = app.donateURL;
break;
case R.id.bitcoin:
url = "bitcoin:" + app.bitcoinAddr;
url = app.getBitcoinUri();
break;
case R.id.litecoin:
url = "litecoin:" + app.litecoinAddr;
url = app.getLitecoinUri();
break;
case R.id.flattr:
url = "https://flattr.com/thing/" + app.flattrID;
url = app.getFlattrUri();
break;
}
if (url != null) {

View File

@ -12,6 +12,7 @@ import android.database.Cursor;
import android.os.Environment;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
@ -552,6 +553,21 @@ public class App extends ValueObject implements Comparable<App>, Parcelable {
return new AppFilter().filter(this);
}
@Nullable
public String getBitcoinUri() {
return TextUtils.isEmpty(bitcoinAddr) ? null : "bitcoin:" + bitcoinAddr;
}
@Nullable
public String getLitecoinUri() {
return TextUtils.isEmpty(litecoinAddr) ? null : "litecoin:" + litecoinAddr;
}
@Nullable
public String getFlattrUri() {
return TextUtils.isEmpty(flattrID) ? null : "https://flattr.com/thing/" + flattrID;
}
public String getSuggestedVersionName() {
return suggestedVersionName;
}

View File

@ -158,9 +158,9 @@ public class AppDetailsRecyclerViewAdapter
private boolean shouldShowDonate() {
return uriIsSetAndCanBeOpened(mApp.donateURL) ||
uriIsSetAndCanBeOpened(mApp.bitcoinAddr) ||
uriIsSetAndCanBeOpened(mApp.litecoinAddr) ||
uriIsSetAndCanBeOpened(mApp.flattrID);
uriIsSetAndCanBeOpened(mApp.getBitcoinUri()) ||
uriIsSetAndCanBeOpened(mApp.getLitecoinUri()) ||
uriIsSetAndCanBeOpened(mApp.getFlattrUri());
}
public void clearProgress() {
@ -333,18 +333,18 @@ public class AppDetailsRecyclerViewAdapter
}
// Bitcoin
if (uriIsSetAndCanBeOpened(mApp.bitcoinAddr)) {
addLinkItemView(vh.contentView, R.string.menu_bitcoin, R.drawable.ic_bitcoin, "bitcoin:" + mApp.bitcoinAddr);
if (uriIsSetAndCanBeOpened(mApp.getBitcoinUri())) {
addLinkItemView(vh.contentView, R.string.menu_bitcoin, R.drawable.ic_bitcoin, mApp.getBitcoinUri());
}
// Litecoin
if (uriIsSetAndCanBeOpened(mApp.litecoinAddr)) {
addLinkItemView(vh.contentView, R.string.menu_litecoin, R.drawable.ic_litecoin, "litecoin:" + mApp.litecoinAddr);
if (uriIsSetAndCanBeOpened(mApp.getLitecoinUri())) {
addLinkItemView(vh.contentView, R.string.menu_litecoin, R.drawable.ic_litecoin, mApp.getLitecoinUri());
}
// Flattr
if (uriIsSetAndCanBeOpened(mApp.flattrID)) {
addLinkItemView(vh.contentView, R.string.menu_flattr, R.drawable.ic_flattr, "https://flattr.com/thing/" + mApp.flattrID);
if (uriIsSetAndCanBeOpened(mApp.getFlattrUri())) {
addLinkItemView(vh.contentView, R.string.menu_flattr, R.drawable.ic_flattr, mApp.getFlattrUri());
}
} else if (viewType == VIEWTYPE_LINKS) {
final ExpandableLinearLayoutViewHolder vh = (ExpandableLinearLayoutViewHolder) holder;