Fix memory leak(s). (#2674)

This commit is contained in:
Dmitry Brant 2019-03-19 15:59:33 -04:00 committed by Adam Jones
parent d1ae88ca8b
commit 351109440f
6 changed files with 24 additions and 37 deletions

View file

@ -572,7 +572,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
*/
private void registerLocationUpdates() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (locationManager.isLocationPermissionGranted()) {
if (locationManager.isLocationPermissionGranted(requireContext())) {
locationManager.registerLocationManager();
} else {
// Should we show an explanation?
@ -666,7 +666,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
private void checkLocationPermission() {
Timber.d("Checking location permission");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (locationManager.isLocationPermissionGranted()) {
if (locationManager.isLocationPermissionGranted(requireContext())) {
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
} else {
// Should we show an explanation?

View file

@ -21,9 +21,6 @@ import timber.log.Timber;
* Custom card view for nearby notification card view on main screen, above contributions list
*/
public class NearbyNotificationCardView extends SwipableCardView {
private Context context;
private Button permissionRequestButton;
private LinearLayout contentLayout;
private TextView notificationTitle;
@ -37,21 +34,18 @@ public class NearbyNotificationCardView extends SwipableCardView {
public NearbyNotificationCardView(@NonNull Context context) {
super(context);
this.context = context;
cardViewVisibilityState = CardViewVisibilityState.INVISIBLE;
init();
}
public NearbyNotificationCardView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
this.context = context;
cardViewVisibilityState = CardViewVisibilityState.INVISIBLE;
init();
}
public NearbyNotificationCardView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context = context;
cardViewVisibilityState = CardViewVisibilityState.INVISIBLE;
init();
}
@ -60,7 +54,7 @@ public class NearbyNotificationCardView extends SwipableCardView {
* Initializes views and action listeners
*/
private void init() {
View rootView = inflate(context, R.layout.nearby_card_view, this);
View rootView = inflate(getContext(), R.layout.nearby_card_view, this);
permissionRequestButton = rootView.findViewById(R.id.permission_request_button);
contentLayout = rootView.findViewById(R.id.content_layout);
@ -79,7 +73,7 @@ public class NearbyNotificationCardView extends SwipableCardView {
protected void onAttachedToWindow() {
super.onAttachedToWindow();
// If you don't setVisibility after getting layout params, then you will se an empty space in place of nearby NotificationCardView
if (((MainActivity)context).defaultKvStore.getBoolean("displayNearbyCardView", true) && this.cardViewVisibilityState == NearbyNotificationCardView.CardViewVisibilityState.READY) {
if (((MainActivity)getContext()).defaultKvStore.getBoolean("displayNearbyCardView", true) && this.cardViewVisibilityState == NearbyNotificationCardView.CardViewVisibilityState.READY) {
this.setVisibility(VISIBLE);
} else {
this.setVisibility(GONE);
@ -88,14 +82,14 @@ public class NearbyNotificationCardView extends SwipableCardView {
private void setActionListeners() {
this.setOnClickListener(view -> ((MainActivity)context).viewPager.setCurrentItem(1));
this.setOnClickListener(view -> ((MainActivity)getContext()).viewPager.setCurrentItem(1));
}
@Override public boolean onSwipe(View view) {
view.setVisibility(GONE);
// Save shared preference for nearby card view accordingly
((MainActivity) context).defaultKvStore.putBoolean("displayNearbyCardView", false);
ViewUtil.showLongToast(context,
((MainActivity) getContext()).defaultKvStore.putBoolean("displayNearbyCardView", false);
ViewUtil.showLongToast(getContext(),
getResources().getString(R.string.nearby_notification_dismiss_message));
return true;
}