Skip to content

Commit

Permalink
improve content provider for categories
Browse files Browse the repository at this point in the history
  • Loading branch information
mpao committed May 31, 2018
1 parent f9c7e93 commit 77faf80
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static io.github.mpao.florencearchitectures.models.databases.AppContract.AppContractElement.CATEGORY;
import static io.github.mpao.florencearchitectures.models.databases.AppContract.AppContractElement.CONTENT_URI;
import static io.github.mpao.florencearchitectures.models.databases.AppContract.AppContractElement.BUILDINGS_TABLE;
import static io.github.mpao.florencearchitectures.models.databases.AppContract.AppContractElement.MAIN_IMAGE;

public class AppContentProvider extends ContentProvider {

Expand Down Expand Up @@ -95,15 +96,7 @@ public Cursor query(@NonNull Uri uri, String[] projection, String selection, Str
sortOrder);
break;
case CATEGORIES:
cursor = db.query(
BUILDINGS_TABLE,
new String[] {CATEGORY,"count(*) AS count"},
selection,
selectionArgs,
CATEGORY,
null,
CATEGORY
);
cursor = getCategories(db);
break;
default:
throw new UnsupportedOperationException(context.getString(R.string.network_error));
Expand Down Expand Up @@ -150,4 +143,20 @@ public String getType(@NonNull Uri uri) {
throw new UnsupportedOperationException("Not yet implemented");
}

//region Helper Methods
private Cursor getCategories(SQLiteDatabase db){

//sqlite, as mysql, enables multi-selection with a single group by <3
return db.query(
BUILDINGS_TABLE,
new String[] {CATEGORY, MAIN_IMAGE, "count(*) AS count"},
null,
null,
CATEGORY,
null,
CATEGORY
);

}
//endregion
}

0 comments on commit 77faf80

Please sign in to comment.