Skip to content

Commit

Permalink
Remove donation preference
Browse files Browse the repository at this point in the history
  • Loading branch information
cpacia committed Mar 19, 2019
1 parent 6140ad7 commit aae9ee6
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "cash.bchd.android_neutrino"
minSdkVersion 24
targetSdkVersion 28
versionCode 8
versionName "v0.1.0-beta8"
versionCode 9
versionName "v0.1.0-beta9"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
42 changes: 41 additions & 1 deletion app/src/main/java/cash/bchd/android_neutrino/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package cash.bchd.android_neutrino;

import android.Manifest;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Rect;
Expand All @@ -16,13 +21,15 @@
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DividerItemDecoration;
Expand Down Expand Up @@ -548,6 +555,37 @@ public void onRateFetched(String formatted) {
}
}

private void maybeSendBackupReminder() {
if (!settings.getBackupReminder() && !settings.getMnemonic().equals("")) {
Intent intent = new Intent(getApplicationContext(), BackupActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);

Notification notification = new NotificationCompat.Builder(getApplicationContext(), "default")
.setSmallIcon(R.drawable.neutrino_small)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setContentTitle("Backup Your Wallet")
.setContentIntent(pendingIntent)
.setDefaults(Notification.DEFAULT_SOUND|Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText("Now that you've received some money it's a good time to back up your wallet recovery phrase."))
.build();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "default";
String description = "default channel";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel("default", name, importance);
channel.setDescription(description);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
notificationManager.notify(5678, notification);
}
settings.setBackupReminder(true);
}
}

private static class StartWalletTask extends AsyncTask<Wallet, Void, String> {
private Wallet wallet;
private final WeakReference<MainActivity> mainActivityRef;
Expand Down Expand Up @@ -580,7 +618,6 @@ public void onBalanceChange(long bal) {
}
if (mainActivity.getApplicationContext() != null) {
try {
System.out.println("Updating balance");
Amount amt = new Amount(bal);
TextView bchBalanceView = mainActivity.findViewById(R.id.bchBalanceView);
String balanceStr = amt.toString() + " BCH";
Expand All @@ -589,6 +626,9 @@ public void onBalanceChange(long bal) {
TextView fiatBalanceView = mainActivity.findViewById(R.id.fiatBalanceView);
fiatBalanceView.setText(fiatAmount);
mainActivity.settings.setLastBalance(bal);
if (bal > 0) {
mainActivity.maybeSendBackupReminder();
}
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public void run() {
intent.putExtra("launchDonationActivity", true);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);

Bitmap myBitmap = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.bchd_logo);
Notification notification = new NotificationCompat.Builder(getApplicationContext(), "default")
.setSmallIcon(R.drawable.neutrino_small)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
Expand All @@ -95,7 +94,7 @@ public void run() {
// or other notification behaviors after this
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
notificationManager.notify(1234, notification);
//notificationManager.notify(1234, notification);
}

settings.setLastNotification(System.currentTimeMillis());
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/cash/bchd/android_neutrino/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class Settings {
private static final String ENCRYPTED_PASSWORD_KEY = "EncryptedPassword";
private static final String FINGERPRINT_IV_KEY = "FingerprintIV";
private static final String LAST_NOTIFICATION_KEY = "LastNotification";
private static final String BACKUP_REMINDER_KEY = "BackupReminder";

SharedPreferences prefs;

Expand Down Expand Up @@ -269,4 +270,15 @@ public long getLastNotification() {
long timestamp = prefs.getLong(LAST_NOTIFICATION_KEY, 0);
return timestamp;
}

public void setBackupReminder(boolean reminded) {
SharedPreferences.Editor editor = this.prefs.edit();
editor.putBoolean(BACKUP_REMINDER_KEY, reminded);
editor.apply();
}

public Boolean getBackupReminder() {
boolean reminded = prefs.getBoolean(BACKUP_REMINDER_KEY, false);
return reminded;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompat;
import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.SwitchPreferenceCompat;
import android.view.View;

import cash.bchd.android_neutrino.wallet.Wallet;
import cash.bchd.android_neutrino.wallet.WalletEventListener;
Expand Down Expand Up @@ -159,6 +160,7 @@ public boolean onPreferenceChange(Preference preference, Object o) {
});

Preference donatePref = (Preference) findPreference("donate");
prefScreen.removePreference(donatePref);
donatePref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void save(Context context) throws Exception {
certOutputSgtream.write(this.cert.getBytes());
certOutputSgtream.close();
}

FileOutputStream outputStream = context.openFileOutput(this.CONFIG_FILE_NAME, Context.MODE_PRIVATE);
outputStream.write(this.getConfigData().getBytes());
outputStream.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ public void onNext(Api.TransactionNotificationsResponse value) {
}
}

boolean hasUnMinedTransactions = false;
if (value.getUnminedTransactionsCount() > 0 || hasMinedTransactions) {
hasUnMinedTransactions = true;
for (Api.TransactionDetails tx : value.getUnminedTransactionsList()) {
for (Api.TransactionDetails.Output output : tx.getCreditsList()) {
AddressListener addrListener = (AddressListener) addressListeners.get(output.getAddress());
Expand All @@ -191,6 +193,9 @@ public void onNext(Api.TransactionNotificationsResponse value) {
TransactionData td = extractTransactionData(tx, 0, System.currentTimeMillis()/1000);
listener.onTransaction(td);
}
}

if (hasMinedTransactions || hasUnMinedTransactions) {
try {
long bal = balance();
listener.onBalanceChange(bal);
Expand Down

0 comments on commit aae9ee6

Please sign in to comment.