mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-22 08:13:43 +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();
|
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.
|
// 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);
|
return measurementDAO.selectAll(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.health.openscale.core.database;
|
package com.health.openscale.core.database;
|
||||||
|
|
||||||
|
import android.content.ContentUris;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.UriMatcher;
|
import android.content.UriMatcher;
|
||||||
@@ -37,9 +38,7 @@ import com.health.openscale.core.OpenScale;
|
|||||||
* The following URIs are supported:
|
* The following URIs are supported:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li><code>content://com.health.openscale.provider/user</code>: list all users.</li>
|
* <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
|
* <li><code>content://com.health.openscale.provider/measurements/$ID</code>:
|
||||||
* by ID.</li>
|
|
||||||
* <li><code>content://com.health.openscale.provider/user/$ID/measurements</code>:
|
|
||||||
* retrieve all measurements for the supplied user ID.</li>
|
* retrieve all measurements for the supplied user ID.</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
@@ -49,14 +48,12 @@ public class ScaleDatabaseProvider extends android.content.ContentProvider {
|
|||||||
private static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".provider";
|
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_LIST = 1;
|
||||||
private static final int MATCH_TYPE_USER_ENTRY = 2;
|
private static final int MATCH_TYPE_MEASUREMENT_LIST = 2;
|
||||||
private static final int MATCH_TYPE_USER_MEASUREMENTS = 3;
|
|
||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
uriMatcher.addURI(AUTHORITY, "user", MATCH_TYPE_USER_LIST);
|
uriMatcher.addURI(AUTHORITY, "users", MATCH_TYPE_USER_LIST);
|
||||||
uriMatcher.addURI(AUTHORITY, "user/#", MATCH_TYPE_USER_ENTRY);
|
uriMatcher.addURI(AUTHORITY, "measurements/#", MATCH_TYPE_MEASUREMENT_LIST);
|
||||||
uriMatcher.addURI(AUTHORITY, "user/#/measurements", MATCH_TYPE_USER_MEASUREMENTS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -65,15 +62,10 @@ public class ScaleDatabaseProvider extends android.content.ContentProvider {
|
|||||||
case MATCH_TYPE_USER_LIST:
|
case MATCH_TYPE_USER_LIST:
|
||||||
return "vnd.android.cursor.dir/vnd." + AUTHORITY + ".user";
|
return "vnd.android.cursor.dir/vnd." + AUTHORITY + ".user";
|
||||||
|
|
||||||
case MATCH_TYPE_USER_ENTRY:
|
case MATCH_TYPE_MEASUREMENT_LIST:
|
||||||
return "vnd.android.cursor.item/vnd." + AUTHORITY + ".user";
|
return "vnd.android.cursor.dir/vnd." + AUTHORITY + ".measurement";
|
||||||
|
|
||||||
case MATCH_TYPE_USER_MEASUREMENTS:
|
|
||||||
return "vnd.android.cursor.item/vnd." + AUTHORITY + ".measurement";
|
|
||||||
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -92,14 +84,9 @@ public class ScaleDatabaseProvider extends android.content.ContentProvider {
|
|||||||
cursor = OpenScale.getInstance().getScaleUserListCursor();
|
cursor = OpenScale.getInstance().getScaleUserListCursor();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MATCH_TYPE_USER_ENTRY:
|
case MATCH_TYPE_MEASUREMENT_LIST:
|
||||||
cursor = OpenScale.getInstance().getScaleUserCursor(
|
|
||||||
Integer.valueOf(uri.getPathSegments().get(1)));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MATCH_TYPE_USER_MEASUREMENTS:
|
|
||||||
cursor = OpenScale.getInstance().getScaleMeasurementListCursor(
|
cursor = OpenScale.getInstance().getScaleMeasurementListCursor(
|
||||||
Integer.valueOf(uri.getPathSegments().get(1)));
|
ContentUris.parseId(uri));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@@ -68,5 +68,5 @@ public interface ScaleMeasurementDAO {
|
|||||||
|
|
||||||
// selectAll() is equivalent to getAll(), but returns a Cursor, for exposing via a ContentProvider.
|
// 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")
|
@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
|
@Delete
|
||||||
void delete(ScaleUser user);
|
void delete(ScaleUser user);
|
||||||
|
|
||||||
// selectAll() and select() are equivalent to getall() and get(), but return a Cursor,
|
// selectAll() is similar to getAll(), but return a Cursor, for exposing via a ContentProvider.
|
||||||
// for exposing via a ContentProvider.
|
|
||||||
@Query("SELECT id as _ID, username, birthday, bodyHeight, gender, activityLevel FROM scaleUsers")
|
@Query("SELECT id as _ID, username, birthday, bodyHeight, gender, activityLevel FROM scaleUsers")
|
||||||
Cursor selectAll();
|
Cursor selectAll();
|
||||||
|
|
||||||
@Query("SELECT * FROM scaleUsers WHERE id = :id")
|
|
||||||
Cursor select(int id);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user