Added Bitcoin donation

Refs #11
This commit is contained in:
M66B 2015-10-30 19:21:10 +01:00
parent 357dcd0a73
commit e45fc2381a
3 changed files with 42 additions and 9 deletions

View File

@ -33,6 +33,7 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
@ -56,7 +57,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
private static final int REQUEST_DONATION = 2;
// adb shell pm clear com.android.vending
private static final String SKU_DONATE = "donation"; // "android.test.purchased";
private static final String SKU_DONATE = "donation"; // "android.test.purchased"
private static final String ACTION_DONATE = "eu.faircode.netguard.DONATE";
@Override
@ -371,6 +372,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
View view = inflater.inflate(R.layout.about, null);
TextView tvVersion = (TextView) view.findViewById(R.id.tvVersion);
final Button btnDonate = (Button) view.findViewById(R.id.btnDonate);
final ImageView ivBitcoin = (ImageView) view.findViewById(R.id.ivBitcoin);
final TextView tvThanks = (TextView) view.findViewById(R.id.tvThanks);
// Show version
@ -389,12 +391,11 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
}
});
// Handle donate
// Handle IAB
btnDonate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
// Start IAB
Bundle bundle = billingService.getBuyIntent(3, getPackageName(), SKU_DONATE, "inapp", "");
Log.i(TAG, "Billing.getBuyIntent");
Util.logBundle(TAG, bundle);
@ -416,6 +417,18 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
}
});
// Handle Bitcoin
final Intent bitcoin = new Intent(Intent.ACTION_VIEW);
bitcoin.setData(Uri.parse("bitcoin:1NTdeAhWXTiQRTMVvusscHXguACok5KQpw?label=M66B"));
final boolean hasBitCoin = (bitcoin.resolveActivity(getPackageManager()) != null);
ivBitcoin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(bitcoin);
}
});
// Handle donated
final BroadcastReceiver onDonated = new BroadcastReceiver() {
@Override
@ -490,11 +503,15 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
Toast.makeText(ActivityMain.this, ex.toString(), Toast.LENGTH_LONG).show();
} else if (result != null) {
} else if (result == null)
ivBitcoin.setVisibility(hasBitCoin ? View.VISIBLE : View.GONE);
else {
// Show donate/donated
Bundle bundle = (Bundle) result;
ArrayList<String> skus = bundle.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
btnDonate.setVisibility(skus.contains(SKU_DONATE) ? View.GONE : View.VISIBLE);
ivBitcoin.setVisibility(hasBitCoin && !skus.contains(SKU_DONATE) ? View.VISIBLE : View.GONE);
tvThanks.setVisibility(skus.contains(SKU_DONATE) ? View.VISIBLE : View.GONE);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -45,14 +45,30 @@
android:text="@string/app_copyright"
android:textAppearance="@android:style/TextAppearance.Material.Small" />
<Button
android:id="@+id/btnDonate"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"
android:text="@string/title_donate"
android:visibility="gone" />
android:layout_marginTop="16dp">
<Button
android:id="@+id/btnDonate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/title_donate"
android:visibility="gone" />
<ImageView
android:id="@+id/ivBitcoin"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="20dp"
android:src="@drawable/bitcoin"
android:visibility="gone" />
</LinearLayout>
<TextView
android:id="@+id/tvThanks"