Skip to content

Commit

Permalink
Trying to minimize Context leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
devgianlu committed Feb 27, 2019
1 parent f92b9f9 commit 62e4fcb
Show file tree
Hide file tree
Showing 15 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class AddDownloadBundlesAdapter extends RecyclerView.Adapter<AddDownloadB
private final Context context;

public AddDownloadBundlesAdapter(Context context, Listener listener) {
this.context = context;
this.context = context.getApplicationContext();
this.inflater = LayoutInflater.from(context);
this.listener = listener;
this.bundles = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class DirectDownloadsAdapter extends RecyclerView.Adapter<DirectDownloads
private final FetchHelper.StartListener restartListener;

public DirectDownloadsAdapter(Context context, FetchHelper helper, List<Download> downloads, FetchHelper.StartListener restartListener) {
this.context = context;
this.context = context.getApplicationContext();
this.inflater = LayoutInflater.from(context);
this.downloads = FetchDownloadWrapper.wrap(downloads);
this.helper = helper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class DownloadCardsAdapter extends OrderedRecyclerViewAdapter<DownloadCar

public DownloadCardsAdapter(Context context, List<DownloadWithUpdate> objs, Listener listener) {
super(objs, SortBy.STATUS);
this.context = context;
this.context = context.getApplicationContext();
this.listener = listener;
this.inflater = LayoutInflater.from(context);
this.broadcastManager = LocalBroadcastManager.getInstance(context);
Expand Down Expand Up @@ -239,7 +239,7 @@ private int indexOf(String gid) {
}

public void activityDestroying(@NonNull Context context) {
context.unbindService(this);
context.getApplicationContext().unbindService(this);
if (broadcastManager != null) broadcastManager.unregisterReceiver(receiver);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class OptionsAdapter extends RecyclerView.Adapter<OptionsAdapter.ViewHold
private final Context context;

private OptionsAdapter(@NonNull Context context, List<Option> options, Listener listener) {
this.context = context;
this.context = context.getApplicationContext();
this.originalOptions = options;
this.options = new ArrayList<>(options);
this.inflater = LayoutInflater.from(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class RadioConditionsAdapter extends ArrayAdapter<MultiProfile.Connectivi

public RadioConditionsAdapter(@NonNull Context context, @NonNull List<MultiProfile.ConnectivityCondition> objects) {
super(context, R.layout.item_radio_condition, objects);
this.context = context;
this.context = context.getApplicationContext();
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class SpinnerConditionsAdapter extends ArrayAdapter<MultiProfile.Connecti

public SpinnerConditionsAdapter(@NonNull Context context, @NonNull List<MultiProfile.ConnectivityCondition> objects) {
super(context, android.R.layout.simple_spinner_dropdown_item, objects);
this.context = context;
this.context = context.getApplicationContext();
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/gianlu/aria2app/Main/MainProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class MainProvider extends PayloadProvider<DownloadsAndGlobalStats> {

MainProvider(Context context) throws Aria2Helper.InitializingException {
super(context, Wants.downloadsAndStats());
super(context.getApplicationContext(), Wants.downloadsAndStats());
}

@NonNull
Expand All @@ -25,7 +25,7 @@ protected PayloadUpdater<DownloadsAndGlobalStats> requireUpdater(@NonNull Contex

private class Updater extends PayloadUpdater<DownloadsAndGlobalStats> implements AbstractClient.OnResult<DownloadsAndGlobalStats> {
Updater(Context context) throws Aria2Helper.InitializingException {
super(context, MainProvider.this);
super(context.getApplicationContext(), MainProvider.this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static void invalidate() {
public static FetchHelper get(@NonNull Context context) throws InitializationException {
if (instance == null) {
try {
instance = new FetchHelper(context);
instance = new FetchHelper(context.getApplicationContext());
} catch (GeneralSecurityException | ProfilesManager.NoCurrentProfileException | IOException | Aria2Helper.InitializingException ex) {
throw new InitializationException(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public abstract class PayloadProvider<P> implements PayloadUpdater.OnPayload<P>
protected P lastPayload;

public PayloadProvider(@NonNull Context context, @NonNull Wants<P> provides) throws Aria2Helper.InitializingException {
this.updater = requireUpdater(context);
this.updater = requireUpdater(context.getApplicationContext());
this.provides = provides;
this.requireListeners = new HashSet<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private OptionsManager(@NonNull Context context) {

@NonNull
public static OptionsManager get(@NonNull Context context) {
if (instance == null) instance = new OptionsManager(context);
if (instance == null) instance = new OptionsManager(context.getApplicationContext());
return instance;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private ProfilesManager(Context context) {

@NonNull
public static ProfilesManager get(Context context) {
if (instance == null) instance = new ProfilesManager(context);
if (instance == null) instance = new ProfilesManager(context.getApplicationContext());
return instance;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public abstract class BaseTester<T> implements Runnable {
private final PublishListener<T> listener;

BaseTester(Context context, MultiProfile.UserProfile profile, @Nullable PublishListener<T> listener) {
this.context = context;
this.context = context.getApplicationContext();
this.profile = profile;
this.listener = listener;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TestersFlow extends Thread implements BaseTester.PublishListener {

@SuppressWarnings("unchecked")
public TestersFlow(@NonNull Context context, @NonNull MultiProfile.UserProfile profile, @NonNull ITestFlow listener) {
this.context = context;
this.context = context.getApplicationContext();
this.listener = listener;
this.testers = new LinkedList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ private static class ToggleNotificationHelper implements ServiceConnection {
private final MessengerPayload payload;

private ToggleNotificationHelper(@NonNull Context context, @NonNull String gid, @NonNull Mode mode) {
this.context = context;
this.context = context.getApplicationContext();
this.payload = new MessengerPayload(gid, mode);
}

Expand Down

0 comments on commit 62e4fcb

Please sign in to comment.