mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-09-30 16:52:21 +02:00
ContentProviderUtils.searchMarkers uses MarkerIterator.
This commit is contained in:
@@ -506,8 +506,7 @@ public class ContentProviderUtils {
|
||||
return contentResolver.query(MarkerColumns.CONTENT_URI, projection, selection, selectionArgs, sortOrder);
|
||||
}
|
||||
|
||||
//TODO Use AutoCloseableIterator<Marker>
|
||||
public List<Marker> searchMarkers(Track.Id trackId, String query) {
|
||||
public MarkerIterator searchMarkers(Track.Id trackId, String query) {
|
||||
String selection = null;
|
||||
String[] selectionArgs = null;
|
||||
String sortOrder = null;
|
||||
@@ -525,15 +524,7 @@ public class ContentProviderUtils {
|
||||
sortOrder = MarkerColumns.DEFAULT_SORT_ORDER + " DESC";
|
||||
}
|
||||
|
||||
ArrayList<Marker> markers = new ArrayList<>();
|
||||
try (Cursor cursor = getMarkerCursor(null, selection, selectionArgs, sortOrder, -1)) {
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
markers.add(createMarker(cursor));
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
}
|
||||
return markers;
|
||||
return new MarkerIterator(this, getMarkerCursor(null, selection, selectionArgs, sortOrder, -1));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,13 +11,18 @@ import de.dennisguse.opentracks.data.models.Marker;
|
||||
import de.dennisguse.opentracks.data.models.Track;
|
||||
import de.dennisguse.opentracks.util.AutoCloseableIterator;
|
||||
|
||||
class MarkerIterator extends AutoCloseableIterator<Marker> {
|
||||
public class MarkerIterator extends AutoCloseableIterator<Marker> {
|
||||
|
||||
private static final String TAG = MarkerIterator.class.getSimpleName();
|
||||
|
||||
private final ContentProviderUtils contentProviderUtils;
|
||||
private Cursor cursor;
|
||||
|
||||
MarkerIterator(ContentProviderUtils contentProviderUtils, Cursor cursor) {
|
||||
this.contentProviderUtils = contentProviderUtils;
|
||||
this.cursor = cursor;
|
||||
}
|
||||
|
||||
MarkerIterator(ContentProviderUtils contentProviderUtils, Track.Id trackId, int maxCount) {
|
||||
this.contentProviderUtils = contentProviderUtils;
|
||||
|
||||
|
||||
@@ -26,12 +26,12 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.UiThread;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import de.dennisguse.opentracks.AbstractActivity;
|
||||
import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.data.ContentProviderUtils;
|
||||
import de.dennisguse.opentracks.data.MarkerIterator;
|
||||
import de.dennisguse.opentracks.data.models.Marker;
|
||||
import de.dennisguse.opentracks.data.models.Track;
|
||||
import de.dennisguse.opentracks.databinding.MarkerListBinding;
|
||||
@@ -243,11 +243,11 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
|
||||
|
||||
viewBinding.markerListToolbar.setTitle(Objects.requireNonNullElseGet(searchQuery, () -> getString(R.string.menu_markers)));
|
||||
|
||||
List<Marker> markers = contentProviderUtils.searchMarkers(trackId, searchQuery);
|
||||
MarkerIterator markers = contentProviderUtils.searchMarkers(trackId, searchQuery);
|
||||
|
||||
adapter.swapData(markers);
|
||||
|
||||
if (markers.isEmpty()) {
|
||||
if (markers.getCount() == 0) {
|
||||
viewBinding.markerListEmpty.setVisibility(View.VISIBLE);
|
||||
viewBinding.markerList.setVisibility(View.GONE);
|
||||
} else {
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.util.List;
|
||||
|
||||
import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.data.ContentProviderUtils;
|
||||
import de.dennisguse.opentracks.data.MarkerIterator;
|
||||
import de.dennisguse.opentracks.data.models.Marker;
|
||||
import de.dennisguse.opentracks.databinding.MarkerListItemBinding;
|
||||
import de.dennisguse.opentracks.ui.util.ActivityUtils;
|
||||
@@ -42,7 +43,7 @@ public class MarkerListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
|
||||
private final AppCompatActivity context;
|
||||
private final RecyclerView recyclerView;
|
||||
private List<Marker> markers;
|
||||
private MarkerIterator markerIterator;
|
||||
private final SparseBooleanArray selection;
|
||||
private boolean selectionMode;
|
||||
private ActivityUtils.ContextualActionModeCallback actionModeCallback;
|
||||
@@ -52,10 +53,10 @@ public class MarkerListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
|
||||
private final LruCache<Marker.Id, Bitmap> memoryCache;
|
||||
|
||||
public MarkerListAdapter(AppCompatActivity context, RecyclerView recyclerView, List<Marker> markers) {
|
||||
public MarkerListAdapter(AppCompatActivity context, RecyclerView recyclerView, MarkerIterator markerIterator) {
|
||||
this.context = context;
|
||||
this.recyclerView = recyclerView;
|
||||
this.markers = markers;
|
||||
this.markerIterator = markerIterator;
|
||||
|
||||
selection = new SparseBooleanArray();
|
||||
selectionMode = false;
|
||||
@@ -87,19 +88,19 @@ public class MarkerListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
ViewHolder viewHolder = (ViewHolder) holder;
|
||||
|
||||
viewHolder.bind(markers.get(position));
|
||||
viewHolder.bind(markerIterator.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (markers == null) {
|
||||
if (markerIterator == null) {
|
||||
return 0;
|
||||
}
|
||||
return markers.size();
|
||||
return markerIterator.getCount();
|
||||
}
|
||||
|
||||
public void swapData(List<Marker> markers) {
|
||||
this.markers = markers;
|
||||
public void swapData(MarkerIterator markers) {
|
||||
this.markerIterator = markers;
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@@ -135,8 +136,10 @@ public class MarkerListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
|
||||
public void setAllSelected(boolean isSelected) {
|
||||
if (isSelected) {
|
||||
for (Marker marker : markers) {
|
||||
selection.put((int) marker.id().id(), true);
|
||||
markerIterator.moveToPosition(-1);
|
||||
while (markerIterator.hasNext()) {
|
||||
selection.put((int) markerIterator.get().id().id(), true);
|
||||
markerIterator.next();
|
||||
}
|
||||
} else {
|
||||
selection.clear();
|
||||
|
||||
Reference in New Issue
Block a user