make user wait for service to finish

This commit is contained in:
m2049r 2017-08-30 23:35:16 +02:00
parent 5b38cc438c
commit 78c053f4e8
3 changed files with 12 additions and 11 deletions

View File

@ -40,6 +40,7 @@ import android.widget.Toast;
import com.m2049r.xmrwallet.model.Wallet;
import com.m2049r.xmrwallet.model.WalletManager;
import com.m2049r.xmrwallet.service.WalletService;
import com.m2049r.xmrwallet.util.Helper;
import java.io.File;
@ -77,6 +78,10 @@ public class LoginActivity extends AppCompatActivity
@Override
public void onWalletSelected(final String walletName) {
if (WalletService.Running) {
Toast.makeText(this, getString(R.string.service_busy), Toast.LENGTH_SHORT).show();
return;
}
Log.d(TAG, "selected wallet is ." + walletName + ".");
// now it's getting real, check if wallet exists
String walletPath = Helper.getWalletPath(this, walletName);

View File

@ -19,10 +19,7 @@ package com.m2049r.xmrwallet.service;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
@ -30,13 +27,11 @@ import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import com.m2049r.xmrwallet.R;
import com.m2049r.xmrwallet.WalletActivity;
import com.m2049r.xmrwallet.model.PendingTransaction;
import com.m2049r.xmrwallet.model.TransactionHistory;
import com.m2049r.xmrwallet.model.Wallet;
import com.m2049r.xmrwallet.model.WalletListener;
import com.m2049r.xmrwallet.model.WalletManager;
@ -44,6 +39,8 @@ import com.m2049r.xmrwallet.util.Helper;
import com.m2049r.xmrwallet.util.TxData;
public class WalletService extends Service {
public static boolean Running = false;
final static String TAG = "WalletService";
final static int NOTIFICATION_ID = 2049;
@ -400,9 +397,6 @@ public class WalletService extends Service {
@Override
public void onCreate() {
//mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//showNotification();
// We are using a HandlerThread and a Looper to avoid loading and closing
// concurrency
MoneroHandlerThread thread = new MoneroHandlerThread("WalletService",
@ -419,8 +413,6 @@ public class WalletService extends Service {
@Override
public void onDestroy() {
Log.d(TAG, "onDestroy()");
// Cancel the persistent notification.
//mNM.cancel(NOTIFICATION);
if (this.listener != null) {
Log.w(TAG, "onDestroy() with active listener");
// no need to stop() here because the wallet closing should have been triggered
@ -438,7 +430,8 @@ public class WalletService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// when the activity satrts the service, it expects to start it for a new wallet
Running = true;
// when the activity starts the service, it expects to start it for a new wallet
// the service is possibly still occupied with saving the last opened wallet
// so we queue the open request
// this should not matter since the old activity is not getting updates
@ -514,6 +507,7 @@ public class WalletService extends Service {
}
stopForeground(true);
stopSelf();
Running = false;
}
private Wallet loadWallet(String walletName, String walletPassword) {

View File

@ -22,6 +22,8 @@
<string name="status_transaction_failed">Transaction failed!</string>
<string name="status_transaction_prepare_failed">Could not create transaction!</string>
<string name="service_busy">I am still busy with your last wallet &#8230;</string>
<string name="prompt_password">Password for</string>
<string name="bad_password">Bad password!</string>
<string name="bad_wallet">Wallet does not exists!</string>