Fixed duplicated updateShortcut calls

This commit is contained in:
PeratX 2017-04-17 21:55:09 +08:00
parent 139ed2d77a
commit a57b2f742e
3 changed files with 8 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -99,6 +100,7 @@ public class MainActivity extends AppCompatActivity {
} }
private void updateUserInterface(Intent intent) { private void updateUserInterface(Intent intent) {
Log.d("MainActivity", "Updating user interface");
int launchAction = intent.getIntExtra(LAUNCH_ACTION, LAUNCH_ACTION_NONE); int launchAction = intent.getIntExtra(LAUNCH_ACTION, LAUNCH_ACTION_NONE);
if (launchAction == LAUNCH_ACTION_ACTIVATE) { if (launchAction == LAUNCH_ACTION_ACTIVATE) {
Daedalus.updateShortcut(this); Daedalus.updateShortcut(this);

View File

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.util.Log; import android.util.Log;
import android.widget.Button; import android.widget.Button;
import org.itxtech.daedalus.Daedalus;
import org.itxtech.daedalus.R; import org.itxtech.daedalus.R;
import org.itxtech.daedalus.activity.MainActivity; import org.itxtech.daedalus.activity.MainActivity;
import org.itxtech.daedalus.activity.SettingsActivity; import org.itxtech.daedalus.activity.SettingsActivity;
@ -32,6 +33,7 @@ public class StatusBarBroadcastReceiver extends BroadcastReceiver {
Intent serviceIntent = new Intent(context, DaedalusVpnService.class); Intent serviceIntent = new Intent(context, DaedalusVpnService.class);
context.startService(serviceIntent.setAction(DaedalusVpnService.ACTION_DEACTIVATE)); context.startService(serviceIntent.setAction(DaedalusVpnService.ACTION_DEACTIVATE));
context.stopService(serviceIntent); context.stopService(serviceIntent);
Daedalus.updateShortcut(context);
if (MainActivity.getInstance() != null) { if (MainActivity.getInstance() != null) {
((Button) MainActivity.getInstance().findViewById(R.id.button_activate)).setText(R.string.button_text_activate); ((Button) MainActivity.getInstance().findViewById(R.id.button_activate)).setText(R.string.button_text_activate);
} }

View File

@ -140,12 +140,14 @@ public class DaedalusVpnService extends VpnService implements Runnable {
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void stopThread() { private void stopThread() {
boolean shouldRefresh = false;
try { try {
if (this.descriptor != null) { if (this.descriptor != null) {
this.descriptor.close(); this.descriptor.close();
this.descriptor = null; this.descriptor = null;
} }
if (this.mThread != null) { if (this.mThread != null) {
shouldRefresh = true;
this.running = false; this.running = false;
this.mThread.interrupt(); this.mThread.interrupt();
if (mInterruptFd != null) { if (mInterruptFd != null) {
@ -166,9 +168,9 @@ public class DaedalusVpnService extends VpnService implements Runnable {
} }
stopSelf(); stopSelf();
if (MainActivity.getInstance() != null && MainActivity.getInstance().isAppOnForeground()) { if (shouldRefresh && MainActivity.getInstance() != null && MainActivity.getInstance().isAppOnForeground()) {
startActivity(new Intent(this, MainActivity.class).putExtra(MainActivity.LAUNCH_ACTION, MainActivity.LAUNCH_ACTION_NONE)); startActivity(new Intent(this, MainActivity.class).putExtra(MainActivity.LAUNCH_ACTION, MainActivity.LAUNCH_ACTION_NONE));
} else { } else if (shouldRefresh) {
Daedalus.updateShortcut(this); Daedalus.updateShortcut(this);
} }
} }