1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-03 19:41:46 +02:00

Make some static stuff non-static (potentially fixes instant run problem and leaks)

This commit is contained in:
Andreas Shimokawa 2016-12-07 23:13:51 +01:00
parent 259eb51784
commit ed38e524bf
4 changed files with 11 additions and 12 deletions

View File

@ -37,7 +37,6 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceService; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceService;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser; import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService; import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils; import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs; import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
@ -78,14 +77,14 @@ public class GBApplication extends Application {
return dir.getAbsolutePath(); return dir.getAbsolutePath();
} }
}; };
private static DeviceManager deviceManager;
private DeviceManager deviceManager;
public static void quit() { public static void quit() {
GB.log("Quitting Gadgetbridge...", GB.INFO, null); GB.log("Quitting Gadgetbridge...", GB.INFO, null);
Intent quitIntent = new Intent(GBApplication.ACTION_QUIT); Intent quitIntent = new Intent(GBApplication.ACTION_QUIT);
LocalBroadcastManager.getInstance(context).sendBroadcast(quitIntent); LocalBroadcastManager.getInstance(context).sendBroadcast(quitIntent);
GBApplication.deviceService().quit(); GBApplication.deviceService().quit();
GB.removeAllNotifications(context);
} }
public GBApplication() { public GBApplication() {
@ -151,7 +150,7 @@ public class GBApplication extends Application {
*/ */
private boolean hasBusyDevice() { private boolean hasBusyDevice() {
List<GBDevice> devices = getDeviceManager().getDevices(); List<GBDevice> devices = getDeviceManager().getDevices();
for (GBDevice device: devices) { for (GBDevice device : devices) {
if (device.isBusy()) { if (device.isBusy()) {
return true; return true;
} }
@ -201,7 +200,7 @@ public class GBApplication extends Application {
* when that was not successful * when that was not successful
* If acquiring was successful, callers must call #releaseDB when they * If acquiring was successful, callers must call #releaseDB when they
* are done (from the same thread that acquired the lock! * are done (from the same thread that acquired the lock!
* * <p>
* Callers must not hold a reference to the returned instance because it * Callers must not hold a reference to the returned instance because it
* will be invalidated at some point. * will be invalidated at some point.
* *
@ -269,7 +268,7 @@ public class GBApplication extends Application {
@TargetApi(Build.VERSION_CODES.M) @TargetApi(Build.VERSION_CODES.M)
public static boolean isPriorityNumber(int priorityType, String number) { public static boolean isPriorityNumber(int priorityType, String number) {
NotificationManager.Policy notificationPolicy = notificationManager.getNotificationPolicy(); NotificationManager.Policy notificationPolicy = notificationManager.getNotificationPolicy();
if(priorityType == Policy.PRIORITY_CATEGORY_MESSAGES) { if (priorityType == Policy.PRIORITY_CATEGORY_MESSAGES) {
if ((notificationPolicy.priorityCategories & Policy.PRIORITY_CATEGORY_MESSAGES) == Policy.PRIORITY_CATEGORY_MESSAGES) { if ((notificationPolicy.priorityCategories & Policy.PRIORITY_CATEGORY_MESSAGES) == Policy.PRIORITY_CATEGORY_MESSAGES) {
return isPrioritySender(notificationPolicy.priorityMessageSenders, number); return isPrioritySender(notificationPolicy.priorityMessageSenders, number);
} }
@ -421,6 +420,7 @@ public class GBApplication extends Application {
theme.resolveAttribute(android.R.attr.textColor, typedValue, true); theme.resolveAttribute(android.R.attr.textColor, typedValue, true);
return typedValue.data; return typedValue.data;
} }
public static int getBackgroundColor(Context context) { public static int getBackgroundColor(Context context) {
TypedValue typedValue = new TypedValue(); TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme(); Resources.Theme theme = context.getTheme();
@ -436,7 +436,7 @@ public class GBApplication extends Application {
return gbPrefs; return gbPrefs;
} }
public static DeviceManager getDeviceManager() { public DeviceManager getDeviceManager() {
return deviceManager; return deviceManager;
} }
} }

View File

@ -13,9 +13,8 @@ public class GBEnvironment {
return env; return env;
} }
public static GBEnvironment createDeviceEnvironment() { static GBEnvironment createDeviceEnvironment() {
GBEnvironment env = new GBEnvironment(); return new GBEnvironment();
return env;
} }
public final boolean isTest() { public final boolean isTest() {

View File

@ -98,7 +98,7 @@ public class ControlCenter extends GBActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_controlcenter); setContentView(R.layout.activity_controlcenter);
deviceManager = GBApplication.getDeviceManager(); deviceManager = ((GBApplication)getApplication()).getDeviceManager();
hintTextView = (TextView) findViewById(R.id.hintTextView); hintTextView = (TextView) findViewById(R.id.hintTextView);
ListView deviceListView = (ListView) findViewById(R.id.deviceListView); ListView deviceListView = (ListView) findViewById(R.id.deviceListView);

View File

@ -190,7 +190,7 @@ public class DbManagementActivity extends GBActivity {
} }
private void selectDeviceForMergingActivityDatabaseInto(final DeviceSelectionCallback callback) { private void selectDeviceForMergingActivityDatabaseInto(final DeviceSelectionCallback callback) {
GBDevice connectedDevice = GBApplication.getDeviceManager().getSelectedDevice(); GBDevice connectedDevice = ((GBApplication)getApplication()).getDeviceManager().getSelectedDevice();
if (connectedDevice == null) { if (connectedDevice == null) {
callback.invoke(null); callback.invoke(null);
return; return;