Fixed main button text issue for good
This commit is contained in:
parent
c98f8875f6
commit
308a0a08d3
@ -177,7 +177,7 @@ public class Daedalus extends Application {
|
||||
}
|
||||
|
||||
public static void setRulesChanged() {
|
||||
if (instance.isServiceActivated() &&
|
||||
if (DaedalusVpnService.isActivated() &&
|
||||
getPrefs().getBoolean("settings_allow_dynamic_rule_reload", false)) {
|
||||
initHostsResolver();
|
||||
}
|
||||
@ -209,44 +209,11 @@ public class Daedalus extends Application {
|
||||
return new Intent(this, DaedalusVpnService.class);
|
||||
}
|
||||
|
||||
|
||||
public boolean isAppOnForeground() {
|
||||
// Returns a list of application processes that are running on the
|
||||
// device
|
||||
|
||||
ActivityManager activityManager = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
|
||||
String packageName = getApplicationContext().getPackageName();
|
||||
|
||||
List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager
|
||||
.getRunningAppProcesses();
|
||||
if (appProcesses == null)
|
||||
return false;
|
||||
|
||||
for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
|
||||
// The name of the process that this object is associated with.
|
||||
if (appProcess.processName.equals(packageName)
|
||||
&& appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void deactivateService() {
|
||||
startService(getServiceIntent().setAction(DaedalusVpnService.ACTION_DEACTIVATE));
|
||||
stopService(getServiceIntent());
|
||||
}
|
||||
|
||||
public boolean isServiceActivated() {
|
||||
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
||||
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
|
||||
if (DaedalusVpnService.class.getName().equals(service.service.getClassName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void updateShortcut(Context context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||
Log.d("Daedalus", "Updating shortcut");
|
||||
|
@ -178,7 +178,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||
if (result == Activity.RESULT_OK) {
|
||||
DaedalusVpnService.primaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getPrimary());
|
||||
DaedalusVpnService.secondaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getSecondary());
|
||||
|
||||
Daedalus.getInstance().startService(Daedalus.getInstance().getServiceIntent().setAction(DaedalusVpnService.ACTION_ACTIVATE));
|
||||
updateMainButton(R.string.button_text_deactivate);
|
||||
Daedalus.updateShortcut(Daedalus.getInstance());
|
||||
|
@ -10,6 +10,7 @@ import android.widget.Button;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.R;
|
||||
import org.itxtech.daedalus.activity.MainActivity;
|
||||
import org.itxtech.daedalus.service.DaedalusVpnService;
|
||||
|
||||
/**
|
||||
* Daedalus Project
|
||||
@ -28,11 +29,11 @@ public class HomeFragment extends ToolbarFragment {
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_main, container, false);
|
||||
|
||||
Button but = (Button) view.findViewById(R.id.button_activate);
|
||||
Button but = view.findViewById(R.id.button_activate);
|
||||
but.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (Daedalus.getInstance().isServiceActivated()) {
|
||||
if (DaedalusVpnService.isActivated()) {
|
||||
Daedalus.getInstance().deactivateService();
|
||||
} else {
|
||||
startActivity(new Intent(getActivity(), MainActivity.class)
|
||||
@ -51,15 +52,17 @@ public class HomeFragment extends ToolbarFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
updateUserInterface();
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
if (isVisibleToUser) {
|
||||
updateUserInterface();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateUserInterface() {
|
||||
Log.d("DMainFragment", "updateInterface");
|
||||
Button but = (Button) getView().findViewById(R.id.button_activate);
|
||||
if (Daedalus.getInstance().isServiceActivated()) {
|
||||
Button but = getView().findViewById(R.id.button_activate);
|
||||
if (DaedalusVpnService.isActivated()) {
|
||||
but.setText(R.string.button_text_deactivate);
|
||||
} else {
|
||||
but.setText(R.string.button_text_activate);
|
||||
|
@ -16,6 +16,7 @@ import android.widget.TextView;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.R;
|
||||
import org.itxtech.daedalus.activity.ConfigActivity;
|
||||
import org.itxtech.daedalus.service.DaedalusVpnService;
|
||||
import org.itxtech.daedalus.util.Rule;
|
||||
|
||||
import java.io.File;
|
||||
@ -236,7 +237,7 @@ public class RulesFragment extends ToolbarFragment implements Toolbar.OnMenuItem
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if ((!Daedalus.getPrefs().getBoolean("settings_allow_dynamic_rule_reload", false) &&
|
||||
!Daedalus.getInstance().isServiceActivated()) ||
|
||||
!DaedalusVpnService.isActivated()) ||
|
||||
Daedalus.getPrefs().getBoolean("settings_allow_dynamic_rule_reload", false)) {
|
||||
Rule rule = Rule.getRuleById(id);
|
||||
if (rule != null) {
|
||||
|
@ -5,7 +5,6 @@ import android.os.Build;
|
||||
import android.service.quicksettings.Tile;
|
||||
import android.service.quicksettings.TileService;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.R;
|
||||
import org.itxtech.daedalus.activity.MainActivity;
|
||||
|
||||
@ -25,7 +24,7 @@ public class DaedalusTileService extends TileService {
|
||||
|
||||
@Override
|
||||
public void onClick() {
|
||||
boolean activate = Daedalus.getInstance().isServiceActivated();
|
||||
boolean activate = DaedalusVpnService.isActivated();
|
||||
|
||||
Intent intent = new Intent(getApplicationContext(), MainActivity.class)
|
||||
.setAction(Intent.ACTION_VIEW)
|
||||
@ -40,7 +39,7 @@ public class DaedalusTileService extends TileService {
|
||||
}
|
||||
|
||||
private void updateTile() {
|
||||
boolean activate = Daedalus.getInstance().isServiceActivated();
|
||||
boolean activate = DaedalusVpnService.isActivated();
|
||||
|
||||
Tile tile = getQsTile();
|
||||
tile.setLabel(getString(R.string.quick_toggle));
|
||||
|
@ -63,6 +63,12 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
||||
|
||||
public HashMap<String, String> dnsServers;
|
||||
|
||||
private static boolean activated = false;
|
||||
|
||||
public static boolean isActivated() {
|
||||
return activated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
@ -73,6 +79,7 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
||||
if (intent != null) {
|
||||
switch (intent.getAction()) {
|
||||
case ACTION_ACTIVATE:
|
||||
activated = true;
|
||||
if (Daedalus.getPrefs().getBoolean("settings_notification", true)) {
|
||||
|
||||
NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
@ -130,6 +137,7 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
private void stopThread() {
|
||||
Log.d(TAG, "stopThread");
|
||||
activated = false;
|
||||
boolean shouldRefresh = false;
|
||||
try {
|
||||
if (this.descriptor != null) {
|
||||
@ -165,7 +173,7 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
||||
Logger.info("Daedalus VPN service has stopped");
|
||||
}
|
||||
|
||||
if (shouldRefresh && MainActivity.getInstance() != null && Daedalus.getInstance().isAppOnForeground()) {
|
||||
if (shouldRefresh && MainActivity.getInstance() != null) {
|
||||
MainActivity.getInstance().startActivity(new Intent(getApplicationContext(), MainActivity.class)
|
||||
.putExtra(MainActivity.LAUNCH_ACTION, MainActivity.LAUNCH_ACTION_AFTER_DEACTIVATE));
|
||||
} else if (shouldRefresh) {
|
||||
@ -173,7 +181,6 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRevoke() {
|
||||
stopThread();
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.itxtech.daedalus.util;
|
||||
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.service.DaedalusVpnService;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@ -104,7 +105,7 @@ public class Rule {
|
||||
}
|
||||
|
||||
public boolean isServiceAndUsing() {
|
||||
return Daedalus.getInstance().isServiceActivated() && isUsing();
|
||||
return DaedalusVpnService.isActivated() && isUsing();
|
||||
}
|
||||
|
||||
public void addToConfig() {
|
||||
|
@ -2,6 +2,7 @@ package org.itxtech.daedalus.util.server;
|
||||
|
||||
import android.content.Context;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.service.DaedalusVpnService;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
@ -141,6 +142,6 @@ public class DNSServerHelper {
|
||||
}
|
||||
|
||||
public static boolean isInUsing(CustomDNSServer server) {
|
||||
return Daedalus.getInstance().isServiceActivated() && (server.getId().equals(getPrimary()) || server.getId().equals(getSecondary()));
|
||||
return DaedalusVpnService.isActivated() && (server.getId().equals(getPrimary()) || server.getId().equals(getSecondary()));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user