use class Context directly rather than storing it

Use the WifiStateChangeService.this syntax in order to eliminate
an instance variable.
This commit is contained in:
Hans-Christoph Steiner 2014-05-05 11:38:29 -04:00
parent a9c88bb5d7
commit 17c42e4bd0

View File

@ -21,11 +21,8 @@ import java.util.Locale;
public class WifiStateChangeService extends Service { public class WifiStateChangeService extends Service {
public static final String BROADCAST = "org.fdroid.fdroid.action.WIFI_CHANGE"; public static final String BROADCAST = "org.fdroid.fdroid.action.WIFI_CHANGE";
private Context context;
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
context = this;
new WaitForWifiAsyncTask().execute(); new WaitForWifiAsyncTask().execute();
return START_NOT_STICKY; return START_NOT_STICKY;
} }
@ -60,7 +57,7 @@ public class WifiStateChangeService extends Service {
FDroidApp.bssid = wifiInfo.getBSSID(); FDroidApp.bssid = wifiInfo.getBSSID();
String scheme; String scheme;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(WifiStateChangeService.this);
if (prefs.getBoolean("use_https", false)) if (prefs.getBoolean("use_https", false))
scheme = "https"; scheme = "https";
else else
@ -69,7 +66,7 @@ public class WifiStateChangeService extends Service {
scheme, FDroidApp.ipAddressString, FDroidApp.port); scheme, FDroidApp.ipAddressString, FDroidApp.port);
FDroidApp.localRepo.setUriString(FDroidApp.repo.address); FDroidApp.localRepo.setUriString(FDroidApp.repo.address);
FDroidApp.localRepo.writeIndexPage( FDroidApp.localRepo.writeIndexPage(
Utils.getSharingUri(context, FDroidApp.repo).toString()); Utils.getSharingUri(WifiStateChangeService.this, FDroidApp.repo).toString());
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -79,7 +76,7 @@ public class WifiStateChangeService extends Service {
@Override @Override
protected void onPostExecute(Void result) { protected void onPostExecute(Void result) {
Intent intent = new Intent(BROADCAST); Intent intent = new Intent(BROADCAST);
LocalBroadcastManager.getInstance(context).sendBroadcast(intent); LocalBroadcastManager.getInstance(WifiStateChangeService.this).sendBroadcast(intent);
WifiStateChangeService.this.stopSelf(); WifiStateChangeService.this.stopSelf();
} }
} }