Skip to content

Commit

Permalink
fix: widget update
Browse files Browse the repository at this point in the history
  • Loading branch information
Syn-McJ committed Aug 18, 2023
1 parent 9b96607 commit 26a5be6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.bitcoinj.core.Coin;
import org.bitcoinj.utils.Fiat;
import org.bitcoinj.utils.MonetaryFormat;
import org.bitcoinj.wallet.Wallet;
import org.bitcoinj.wallet.Wallet.BalanceType;
import org.dash.wallet.common.Configuration;
import org.dash.wallet.common.data.WalletUIConfig;
Expand Down Expand Up @@ -90,13 +89,12 @@ public void onAppWidgetOptionsChanged(final Context context, final AppWidgetMana
}
}

public static void updateWidgets(final Context context, final Wallet wallet) {
public static void updateWidgets(final Context context, final Coin balance) {
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
final ComponentName providerName = new ComponentName(context, WalletBalanceWidgetProvider.class);
try {
final int[] appWidgetIds = appWidgetManager.getAppWidgetIds(providerName);
if (appWidgetIds.length > 0) {
final Coin balance = wallet.getBalance(BalanceType.ESTIMATED);
updateWidgets(context, appWidgetManager, appWidgetIds, balance);
}
} catch (final RuntimeException x) {// system server dead?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,8 @@ private int percentageSync() {
}

private void updateAppWidget() {
WalletBalanceWidgetProvider.updateWidgets(BlockchainServiceImpl.this, application.getWallet());
Coin balance = application.getWallet().getBalance(Wallet.BalanceType.ESTIMATED);
WalletBalanceWidgetProvider.updateWidgets(BlockchainServiceImpl.this, balance);
}

public void forceForeground() {
Expand Down
3 changes: 3 additions & 0 deletions wallet/src/de/schildbach/wallet/ui/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.content.Intent
import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import dagger.hilt.android.AndroidEntryPoint
import de.schildbach.wallet.WalletBalanceWidgetProvider
import de.schildbach.wallet.ui.main.WalletActivity
import de.schildbach.wallet.ui.more.AboutActivity
import de.schildbach.wallet_test.R
Expand Down Expand Up @@ -104,6 +105,8 @@ class SettingsActivity : LockScreenActivity() {
private fun setSelectedCurrency(code: String) {
lifecycleScope.launch {
walletUIConfig.set(WalletUIConfig.SELECTED_CURRENCY, code)
val balance = walletData.getWalletBalance()
WalletBalanceWidgetProvider.updateWidgets(this@SettingsActivity, balance)
}
}
}
2 changes: 0 additions & 2 deletions wallet/src/de/schildbach/wallet/ui/main/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ class MainViewModel @Inject constructor(
}
.onEach(_exchangeRate::postValue)
.launchIn(viewModelScope)

// WalletBalanceWidgetProvider.updateWidgets(mAppContext, mWallet) TODO
}

fun logEvent(event: String) {
Expand Down
3 changes: 2 additions & 1 deletion wallet/src/de/schildbach/wallet/ui/main/WalletActivityExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ object WalletActivityExt {
).show(this) { result: Boolean? ->
if (result != null && result) {
viewModel.setExchangeCurrencyCodeDetected(newCurrencyCode)
WalletBalanceWidgetProvider.updateWidgets(this, walletData.wallet)
val balance = walletData.getWalletBalance()
WalletBalanceWidgetProvider.updateWidgets(this, balance)
} else {
viewModel.setExchangeCurrencyCodeDetected(null)
}
Expand Down

0 comments on commit 26a5be6

Please sign in to comment.