Search in sources :

Example 1 with Optional

use of java8.util.Optional in project samourai-wallet-android by Samourai-Wallet.

the class WhirlpoolNotificationService method listenService.

private void listenService() {
    try {
        Optional<WhirlpoolWallet> whirlpoolWalletOpt = androidWhirlpoolWalletService.getWhirlpoolWallet();
        if (!whirlpoolWalletOpt.isPresent()) {
            // whirlpool wallet not opened yet
            return;
        }
        // whirlpool wallet is opened
        WhirlpoolWallet whirlpoolWallet = whirlpoolWalletOpt.get();
        updateNotification();
        Disposable stateDisposable = whirlpoolWallet.getMixingState().getObservable().observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(mixingState -> updateNotification());
        Disposable repeatedChecks = Observable.fromCallable(() -> true).repeatWhen(completed -> completed.delay(3, TimeUnit.SECONDS)).subscribe(aBoolean -> {
            updateNotification();
            notifySuccessMixes(whirlpoolWallet.getMixingState());
        }, er -> {
        });
        compositeDisposable.add(repeatedChecks);
        compositeDisposable.add(stateDisposable);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) ActivityManager(android.app.ActivityManager) Context(android.content.Context) Coin(org.bitcoinj.core.Coin) Intent(android.content.Intent) FormatsUtil.getBTCDecimalFormat(com.samourai.wallet.util.FormatsUtil.getBTCDecimalFormat) PendingIntent(android.app.PendingIntent) Optional(java8.util.Optional) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) IBinder(android.os.IBinder) ArrayList(java.util.ArrayList) WhirlpoolWallet(com.samourai.whirlpool.client.wallet.WhirlpoolWallet) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) WHIRLPOOL_CHANNEL(com.samourai.wallet.SamouraiApplication.WHIRLPOOL_CHANNEL) Log(android.util.Log) WhirlpoolUtxoStatus(com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxoStatus) NotificationManager(android.app.NotificationManager) WhirlpoolUtxo(com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo) Service(android.app.Service) AndroidWhirlpoolWalletService(com.samourai.whirlpool.client.wallet.AndroidWhirlpoolWalletService) R(com.samourai.wallet.R) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) GROUP_ALERT_SUMMARY(android.support.v4.app.NotificationCompat.GROUP_ALERT_SUMMARY) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) NotificationCompat(android.support.v4.app.NotificationCompat) MixingState(com.samourai.whirlpool.client.wallet.beans.MixingState) WHIRLPOOL_NOTIFICATIONS(com.samourai.wallet.SamouraiApplication.WHIRLPOOL_NOTIFICATIONS) Notification(android.app.Notification) WhirlpoolWallet(com.samourai.whirlpool.client.wallet.WhirlpoolWallet)

Aggregations

ActivityManager (android.app.ActivityManager)1 Notification (android.app.Notification)1 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Service (android.app.Service)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IBinder (android.os.IBinder)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 GROUP_ALERT_SUMMARY (android.support.v4.app.NotificationCompat.GROUP_ALERT_SUMMARY)1 Log (android.util.Log)1 R (com.samourai.wallet.R)1 WHIRLPOOL_CHANNEL (com.samourai.wallet.SamouraiApplication.WHIRLPOOL_CHANNEL)1 WHIRLPOOL_NOTIFICATIONS (com.samourai.wallet.SamouraiApplication.WHIRLPOOL_NOTIFICATIONS)1 FormatsUtil.getBTCDecimalFormat (com.samourai.wallet.util.FormatsUtil.getBTCDecimalFormat)1 AndroidWhirlpoolWalletService (com.samourai.whirlpool.client.wallet.AndroidWhirlpoolWalletService)1 WhirlpoolWallet (com.samourai.whirlpool.client.wallet.WhirlpoolWallet)1 MixingState (com.samourai.whirlpool.client.wallet.beans.MixingState)1 WhirlpoolUtxo (com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo)1 WhirlpoolUtxoStatus (com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxoStatus)1