mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-20 07:21:40 +02:00
Simplify content provider URIs
and remove the variant to get a single user only
This commit is contained in:
@@ -612,13 +612,8 @@ public class OpenScale {
|
||||
return userDAO.selectAll();
|
||||
}
|
||||
|
||||
// As getScaleUser(), but as a Cursor for export via a Content Provider.
|
||||
public Cursor getScaleUserCursor(int userId) {
|
||||
return userDAO.select(userId);
|
||||
}
|
||||
|
||||
// As getScaleMeasurementList(), but as a Cursor for export via a Content Provider.
|
||||
public Cursor getScaleMeasurementListCursor(int userId) {
|
||||
public Cursor getScaleMeasurementListCursor(long userId) {
|
||||
return measurementDAO.selectAll(userId);
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.health.openscale.core.database;
|
||||
|
||||
import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.UriMatcher;
|
||||
@@ -37,9 +38,7 @@ import com.health.openscale.core.OpenScale;
|
||||
* The following URIs are supported:
|
||||
* <ul>
|
||||
* <li><code>content://com.health.openscale.provider/user</code>: list all users.</li>
|
||||
* <li><code>content://com.health.openscale.provider/user/$ID</code>: retrieve single user
|
||||
* by ID.</li>
|
||||
* <li><code>content://com.health.openscale.provider/user/$ID/measurements</code>:
|
||||
* <li><code>content://com.health.openscale.provider/measurements/$ID</code>:
|
||||
* retrieve all measurements for the supplied user ID.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -49,14 +48,12 @@ public class ScaleDatabaseProvider extends android.content.ContentProvider {
|
||||
private static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".provider";
|
||||
|
||||
private static final int MATCH_TYPE_USER_LIST = 1;
|
||||
private static final int MATCH_TYPE_USER_ENTRY = 2;
|
||||
private static final int MATCH_TYPE_USER_MEASUREMENTS = 3;
|
||||
private static final int MATCH_TYPE_MEASUREMENT_LIST = 2;
|
||||
|
||||
|
||||
static {
|
||||
uriMatcher.addURI(AUTHORITY, "user", MATCH_TYPE_USER_LIST);
|
||||
uriMatcher.addURI(AUTHORITY, "user/#", MATCH_TYPE_USER_ENTRY);
|
||||
uriMatcher.addURI(AUTHORITY, "user/#/measurements", MATCH_TYPE_USER_MEASUREMENTS);
|
||||
uriMatcher.addURI(AUTHORITY, "users", MATCH_TYPE_USER_LIST);
|
||||
uriMatcher.addURI(AUTHORITY, "measurements/#", MATCH_TYPE_MEASUREMENT_LIST);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,15 +62,10 @@ public class ScaleDatabaseProvider extends android.content.ContentProvider {
|
||||
case MATCH_TYPE_USER_LIST:
|
||||
return "vnd.android.cursor.dir/vnd." + AUTHORITY + ".user";
|
||||
|
||||
case MATCH_TYPE_USER_ENTRY:
|
||||
return "vnd.android.cursor.item/vnd." + AUTHORITY + ".user";
|
||||
|
||||
case MATCH_TYPE_USER_MEASUREMENTS:
|
||||
return "vnd.android.cursor.item/vnd." + AUTHORITY + ".measurement";
|
||||
|
||||
default:
|
||||
return null;
|
||||
case MATCH_TYPE_MEASUREMENT_LIST:
|
||||
return "vnd.android.cursor.dir/vnd." + AUTHORITY + ".measurement";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -92,14 +84,9 @@ public class ScaleDatabaseProvider extends android.content.ContentProvider {
|
||||
cursor = OpenScale.getInstance().getScaleUserListCursor();
|
||||
break;
|
||||
|
||||
case MATCH_TYPE_USER_ENTRY:
|
||||
cursor = OpenScale.getInstance().getScaleUserCursor(
|
||||
Integer.valueOf(uri.getPathSegments().get(1)));
|
||||
break;
|
||||
|
||||
case MATCH_TYPE_USER_MEASUREMENTS:
|
||||
case MATCH_TYPE_MEASUREMENT_LIST:
|
||||
cursor = OpenScale.getInstance().getScaleMeasurementListCursor(
|
||||
Integer.valueOf(uri.getPathSegments().get(1)));
|
||||
ContentUris.parseId(uri));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@@ -68,5 +68,5 @@ public interface ScaleMeasurementDAO {
|
||||
|
||||
// selectAll() is equivalent to getAll(), but returns a Cursor, for exposing via a ContentProvider.
|
||||
@Query("SELECT id as _ID, datetime, weight, fat, water, muscle FROM scaleMeasurements WHERE userId = :userId AND enabled = 1 ORDER BY datetime DESC")
|
||||
Cursor selectAll(int userId);
|
||||
Cursor selectAll(long userId);
|
||||
}
|
||||
|
@@ -47,12 +47,7 @@ public interface ScaleUserDAO {
|
||||
@Delete
|
||||
void delete(ScaleUser user);
|
||||
|
||||
// selectAll() and select() are equivalent to getall() and get(), but return a Cursor,
|
||||
// for exposing via a ContentProvider.
|
||||
// selectAll() is similar to getAll(), but return a Cursor, for exposing via a ContentProvider.
|
||||
@Query("SELECT id as _ID, username, birthday, bodyHeight, gender, activityLevel FROM scaleUsers")
|
||||
Cursor selectAll();
|
||||
|
||||
@Query("SELECT * FROM scaleUsers WHERE id = :id")
|
||||
Cursor select(int id);
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user