mirror of https://github.com/m2049r/xmrwallet.git
Background Sync Implementation
This commit is contained in:
parent
932de3ba9d
commit
869973ad5d
|
@ -35,6 +35,7 @@ import android.view.View;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Switch;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
@ -104,6 +105,8 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
|
||||||
|
|
||||||
private long streetMode = 0;
|
private long streetMode = 0;
|
||||||
private boolean isLockMode = false;
|
private boolean isLockMode = false;
|
||||||
|
private SharedPreferences sharedPreferences ;
|
||||||
|
private boolean enableBkgSync;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPasswordChanged(String newPassword) {
|
public void onPasswordChanged(String newPassword) {
|
||||||
|
@ -318,11 +321,39 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
|
||||||
} else {
|
} else {
|
||||||
onEnableLockMode();
|
onEnableLockMode();
|
||||||
}
|
}
|
||||||
|
} else if (itemId == R.id.action_background_sync) {
|
||||||
|
showToggleDialog();
|
||||||
} else
|
} else
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
return true;
|
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
|
@Override
|
||||||
public boolean isLockMode() { return isLockMode; }
|
public boolean isLockMode() { return isLockMode; }
|
||||||
|
|
||||||
|
@ -330,6 +361,10 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
|
||||||
isLockMode = true;
|
isLockMode = true;
|
||||||
enableStreetMode(true);
|
enableStreetMode(true);
|
||||||
updateStreetMode();
|
updateStreetMode();
|
||||||
|
|
||||||
|
if(getWallet() != null && enableBkgSync) {
|
||||||
|
getWallet().startBackgroundSync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateStreetMode() {
|
private void updateStreetMode() {
|
||||||
|
@ -348,6 +383,10 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
|
||||||
runOnUiThread(() -> {
|
runOnUiThread(() -> {
|
||||||
enableStreetMode(false);
|
enableStreetMode(false);
|
||||||
updateStreetMode();
|
updateStreetMode();
|
||||||
|
|
||||||
|
if(getWallet() != null) {
|
||||||
|
getWallet().stopBackgroundSync(password);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -431,6 +470,9 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
|
||||||
|
|
||||||
startWalletService();
|
startWalletService();
|
||||||
Timber.d("onCreate() done.");
|
Timber.d("onCreate() done.");
|
||||||
|
|
||||||
|
sharedPreferences = getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
|
||||||
|
enableBkgSync = sharedPreferences.getBoolean("toggleState", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showNet() {
|
public void showNet() {
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingHorizontal="30dp">
|
||||||
|
|
||||||
|
<!-- Text at the top -->
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/topTextView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:text="Background Sync enables users to keep their wallets syncing in the background using only their view-keys, and having their spend key wiped from memory."
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
|
|
||||||
|
<!-- Layout for the text and switch -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
android:paddingStart="20dp">
|
||||||
|
|
||||||
|
<!-- Text on the left -->
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/leftTextView"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Enable Background Sync"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
|
|
||||||
|
<!-- Switch on the right -->
|
||||||
|
<Switch
|
||||||
|
android:id="@+id/toggleSwitch"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="end" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
|
@ -54,4 +54,9 @@
|
||||||
android:title="@string/pocketchange_title"
|
android:title="@string/pocketchange_title"
|
||||||
app:showAsAction="never" />
|
app:showAsAction="never" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_background_sync"
|
||||||
|
android:orderInCategory="900"
|
||||||
|
android:title="@string/background_sync"
|
||||||
|
app:showAsAction="never" />
|
||||||
</menu>
|
</menu>
|
|
@ -499,4 +499,5 @@
|
||||||
|
|
||||||
<string name="label_apply">APPLY</string>
|
<string name="label_apply">APPLY</string>
|
||||||
<string name="menu_lockmode">Lock Mode</string>
|
<string name="menu_lockmode">Lock Mode</string>
|
||||||
|
<string name="background_sync">Background Sync</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue