|
6 | 6 | import android.app.NotificationManager; |
7 | 7 | import android.app.PendingIntent; |
8 | 8 | import android.app.Service; |
9 | | -import android.content.ContentResolver; |
10 | | -import android.content.ContentUris; |
11 | 9 | import android.content.BroadcastReceiver; |
12 | 10 | import android.content.Context; |
13 | 11 | import android.content.Intent; |
|
26 | 24 | import androidx.core.content.ContextCompat; |
27 | 25 | import androidx.preference.PreferenceManager; |
28 | 26 |
|
29 | | -import android.database.Cursor; |
30 | | - |
31 | 27 | import net.osmtracker.OSMTracker; |
32 | 28 | import net.osmtracker.R; |
33 | 29 | import net.osmtracker.activity.TrackLogger; |
34 | 30 | import net.osmtracker.db.DataHelper; |
35 | 31 | import net.osmtracker.db.TrackContentProvider; |
36 | | -import net.osmtracker.db.model.Track; |
37 | 32 | import net.osmtracker.listener.PressureListener; |
38 | 33 | import net.osmtracker.listener.SensorListener; |
39 | 34 |
|
@@ -114,7 +109,6 @@ public class GPSLogger extends Service implements LocationListener { |
114 | 109 | */ |
115 | 110 | private PressureListener pressureListener = new PressureListener(); |
116 | 111 |
|
117 | | - |
118 | 112 | /** |
119 | 113 | * Receives Intent for way point and notes tracking, and stop/start logging. |
120 | 114 | */ |
@@ -324,31 +318,13 @@ public void onDestroy() { |
324 | 318 | super.onDestroy(); |
325 | 319 | } |
326 | 320 |
|
327 | | - private long getSegIdFor(long trackId) { |
328 | | - ContentResolver cr = getContentResolver(); |
329 | | - try(Cursor cursor = |
330 | | - cr.query(ContentUris.withAppendedId(TrackContentProvider.CONTENT_URI_TRACK, trackId), |
331 | | - null, null, null, null)) { |
332 | | - |
333 | | - if (! cursor.moveToFirst()) { |
334 | | - Log.v(TAG, "Track "+trackId+" not found"); |
335 | | - return 0; // <--- Early return --- |
336 | | - } |
337 | | - |
338 | | - return Track |
339 | | - .build(trackId, cursor, cr, true) |
340 | | - .getMaxSegId(); |
341 | | - } |
342 | | - } |
343 | | - |
344 | 321 | /** |
345 | 322 | * Start GPS tracking. |
346 | 323 | */ |
347 | 324 | private void startTracking(long trackId) { |
348 | 325 | currentTrackId = trackId; |
349 | | - currentSegmentId = getSegIdFor(trackId)+1; |
350 | | - Log.v(TAG, "Starting track logging for track #" + trackId + |
351 | | - "/" + currentSegmentId); |
| 326 | + currentSegmentId = DataHelper.getSegmentIdFor(trackId, getContentResolver()) + 1; |
| 327 | + Log.v(TAG, "Starting track logging for track #" + trackId + " segment #" +"/" + currentSegmentId); |
352 | 328 | // Refresh notification with correct Track ID |
353 | 329 | NotificationManager nmgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
354 | 330 | nmgr.notify(NOTIFICATION_ID, getNotification()); |
|
0 commit comments