mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-18 00:33:07 +02:00
Fix memory leak in SectionResourceCursorAdapter.
This commit is contained in:
@@ -21,7 +21,6 @@ import com.google.android.maps.mytracks.R;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.DataSetObserver;
|
|
||||||
import android.support.v4.widget.ResourceCursorAdapter;
|
import android.support.v4.widget.ResourceCursorAdapter;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -46,25 +45,8 @@ public abstract class SectionResourceCursorAdapter extends ResourceCursorAdapter
|
|||||||
public SectionResourceCursorAdapter(Context context, int layout, Cursor cursor, int flags) {
|
public SectionResourceCursorAdapter(Context context, int layout, Cursor cursor, int flags) {
|
||||||
super(context, layout, cursor, flags);
|
super(context, layout, cursor, flags);
|
||||||
this.layoutInflater = LayoutInflater.from(context);
|
this.layoutInflater = LayoutInflater.from(context);
|
||||||
|
|
||||||
if (cursor != null) {
|
|
||||||
sharedWithMeIndex = getSharedWithMeIndex();
|
|
||||||
cursor.registerDataSetObserver(dataSetObserver);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private DataSetObserver dataSetObserver = new DataSetObserver() {
|
|
||||||
@Override
|
|
||||||
public void onChanged() {
|
|
||||||
sharedWithMeIndex = getSharedWithMeIndex();
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onInvalidated() {
|
|
||||||
sharedWithMeIndex = -1;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
if (getItemViewType(position) == ItemType.TRACK.ordinal()) {
|
if (getItemViewType(position) == ItemType.TRACK.ordinal()) {
|
||||||
@@ -122,15 +104,8 @@ public abstract class SectionResourceCursorAdapter extends ResourceCursorAdapter
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Cursor swapCursor(Cursor newCursor) {
|
public Cursor swapCursor(Cursor newCursor) {
|
||||||
if (getCursor() != null) {
|
|
||||||
getCursor().unregisterDataSetObserver(dataSetObserver);
|
|
||||||
}
|
|
||||||
|
|
||||||
Cursor oldCursor = super.swapCursor(newCursor);
|
Cursor oldCursor = super.swapCursor(newCursor);
|
||||||
if (newCursor != null) {
|
sharedWithMeIndex = getSharedWithMeIndex();
|
||||||
sharedWithMeIndex = getSharedWithMeIndex();
|
|
||||||
newCursor.registerDataSetObserver(dataSetObserver);
|
|
||||||
}
|
|
||||||
return oldCursor;
|
return oldCursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +120,7 @@ public abstract class SectionResourceCursorAdapter extends ResourceCursorAdapter
|
|||||||
do {
|
do {
|
||||||
int sharedWithMe = cursor.getInt(index);
|
int sharedWithMe = cursor.getInt(index);
|
||||||
if (sharedWithMe == 1) {
|
if (sharedWithMe == 1) {
|
||||||
// Returns the index where sharedWithMe == 1
|
// Returns the index where sharedWithMe == 1
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
|
|||||||
Reference in New Issue
Block a user