diff --git a/app/src/main/java/com/m2049r/xmrwallet/WalletActivity.java b/app/src/main/java/com/m2049r/xmrwallet/WalletActivity.java index 225eea18..587efcc3 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/WalletActivity.java +++ b/app/src/main/java/com/m2049r/xmrwallet/WalletActivity.java @@ -35,6 +35,7 @@ import android.view.View; import android.view.inputmethod.EditorInfo; import android.widget.EditText; import android.widget.TextView; +import android.widget.Switch; import android.widget.Toast; import androidx.annotation.NonNull; @@ -104,6 +105,8 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste private long streetMode = 0; private boolean isLockMode = false; + private SharedPreferences sharedPreferences ; + private boolean enableBkgSync; @Override public void onPasswordChanged(String newPassword) { @@ -318,11 +321,39 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste } else { onEnableLockMode(); } + } else if (itemId == R.id.action_background_sync) { + showToggleDialog(); } else return super.onOptionsItemSelected(item); return true; } + private void showToggleDialog() { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle("Background Sync"); + + // set the custom layout + final View customLayout = getLayoutInflater().inflate(R.layout.toggle_dialog_layout, null); + builder.setView(customLayout); + + // Access the Switch widget and TextView from the inflated layout + final Switch toggleSwitch = customLayout.findViewById(R.id.toggleSwitch); + + // Initialize the toggle button state + toggleSwitch.setChecked(enableBkgSync); + + builder.setPositiveButton("OK", (dialogInterface, which) -> { + // Save the toggle state to SharedPreferences + enableBkgSync = toggleSwitch.isChecked(); + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putBoolean("toggleState", enableBkgSync); + editor.apply(); + }); + + AlertDialog dialog = builder.create(); + dialog.show(); + } + @Override public boolean isLockMode() { return isLockMode; } @@ -330,6 +361,10 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste isLockMode = true; enableStreetMode(true); updateStreetMode(); + + if(getWallet() != null && enableBkgSync) { + getWallet().startBackgroundSync(); + } } private void updateStreetMode() { @@ -348,6 +383,10 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste runOnUiThread(() -> { enableStreetMode(false); updateStreetMode(); + + if(getWallet() != null) { + getWallet().stopBackgroundSync(password); + } }); } @@ -431,6 +470,9 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste startWalletService(); Timber.d("onCreate() done."); + + sharedPreferences = getSharedPreferences("MyPrefs", Context.MODE_PRIVATE); + enableBkgSync = sharedPreferences.getBoolean("toggleState", false); } public void showNet() { diff --git a/app/src/main/res/layout/toggle_dialog_layout.xml b/app/src/main/res/layout/toggle_dialog_layout.xml new file mode 100644 index 00000000..daf9d787 --- /dev/null +++ b/app/src/main/res/layout/toggle_dialog_layout.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/menu/wallet_menu.xml b/app/src/main/res/menu/wallet_menu.xml index dd0549e4..39292ba0 100644 --- a/app/src/main/res/menu/wallet_menu.xml +++ b/app/src/main/res/menu/wallet_menu.xml @@ -54,4 +54,9 @@ android:title="@string/pocketchange_title" app:showAsAction="never" /> + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1f67ff62..f9d49e87 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -499,4 +499,5 @@ APPLY Lock Mode + Background Sync