-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Provide sounds of letter-sound correspondences
- Loading branch information
Showing
4 changed files
with
204 additions
and
1 deletion.
There are no files selected for viewing
136 changes: 136 additions & 0 deletions
136
app/src/main/java/ai/elimu/content_provider/provider/SoundContentProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package ai.elimu.content_provider.provider; | ||
|
||
import android.content.ContentProvider; | ||
import android.content.ContentValues; | ||
import android.content.Context; | ||
import android.content.UriMatcher; | ||
import android.database.Cursor; | ||
import android.net.Uri; | ||
import android.util.Log; | ||
|
||
import java.util.List; | ||
|
||
import ai.elimu.content_provider.BuildConfig; | ||
import ai.elimu.content_provider.room.dao.SoundDao; | ||
import ai.elimu.content_provider.room.db.RoomDb; | ||
|
||
public class SoundContentProvider extends ContentProvider { | ||
|
||
private static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".provider.sound_provider"; | ||
private static final String TABLE_SOUNDS = "sounds"; | ||
private static final int CODE_SOUNDS = 1; | ||
private static final int CODE_SOUND_ID = 2; | ||
|
||
private static final int CODE_SOUNDS_BY_LETTER_SOUND_ID = 3; | ||
private static final UriMatcher MATCHER = new UriMatcher(UriMatcher.NO_MATCH); | ||
|
||
static { | ||
MATCHER.addURI(AUTHORITY, TABLE_SOUNDS, CODE_SOUNDS); | ||
MATCHER.addURI(AUTHORITY, TABLE_SOUNDS + "/#", CODE_SOUND_ID); | ||
MATCHER.addURI(AUTHORITY, TABLE_SOUNDS + "/by-letter-sound-id/#", CODE_SOUNDS_BY_LETTER_SOUND_ID); | ||
} | ||
|
||
@Override | ||
public boolean onCreate() { | ||
Log.i(getClass().getName(), "onCreate"); | ||
return true; | ||
} | ||
|
||
@Override | ||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { | ||
Log.i(getClass().getName(), "query"); | ||
|
||
Log.i(getClass().getName(), "uri: " + uri); | ||
Log.i(getClass().getName(), "projection: " + projection); | ||
Log.i(getClass().getName(), "selection: " + selection); | ||
Log.i(getClass().getName(), "selectionArgs: " + selectionArgs); | ||
Log.i(getClass().getName(), "sortOrder: " + sortOrder); | ||
|
||
Context context = getContext(); | ||
Log.i(getClass().getName(), "context: " + context); | ||
if (context == null) { | ||
return null; | ||
} | ||
|
||
RoomDb roomDb = RoomDb.getDatabase(context); | ||
SoundDao soundDao = roomDb.soundDao(); | ||
|
||
final int code = MATCHER.match(uri); | ||
Log.i(getClass().getName(), "code: " + code); | ||
if (code == CODE_SOUNDS) { | ||
final Cursor cursor; | ||
|
||
// Get the Room Cursor | ||
cursor = soundDao.loadAllOrderedByUsageCount_Cursor(); | ||
Log.i(getClass().getName(), "cursor: " + cursor); | ||
|
||
cursor.setNotificationUri(context.getContentResolver(), uri); | ||
|
||
return cursor; | ||
} else if (code == CODE_SOUNDS_BY_LETTER_SOUND_ID) { | ||
// Extract the letter-sound correspondence ID from the URI | ||
List<String> pathSegments = uri.getPathSegments(); | ||
Log.i(getClass().getName(), "pathSegments: " + pathSegments); | ||
String letterSoundIdAsString = pathSegments.get(2); | ||
Long letterSoundId = Long.valueOf(letterSoundIdAsString); | ||
Log.i(getClass().getName(), "letterSoundId: " + letterSoundId); | ||
|
||
final Cursor cursor; | ||
|
||
// Get the Room Cursor | ||
cursor = soundDao.loadAllByLetterSound(letterSoundId); | ||
Log.i(getClass().getName(), "cursor: " + cursor); | ||
|
||
cursor.setNotificationUri(context.getContentResolver(), uri); | ||
|
||
return cursor; | ||
} else if (code == CODE_SOUND_ID) { | ||
// Extract the Sound ID from the URI | ||
List<String> pathSegments = uri.getPathSegments(); | ||
Log.i(getClass().getName(), "pathSegments: " + pathSegments); | ||
String soundIdAsString = pathSegments.get(1); | ||
Long soundId = Long.valueOf(soundIdAsString); | ||
Log.i(getClass().getName(), "soundId: " + soundId); | ||
|
||
final Cursor cursor; | ||
|
||
// Get the Room Cursor | ||
cursor = soundDao.load_Cursor(soundId); | ||
Log.i(getClass().getName(), "cursor: " + cursor); | ||
|
||
cursor.setNotificationUri(context.getContentResolver(), uri); | ||
|
||
return cursor; | ||
} else { | ||
throw new IllegalArgumentException("Unknown URI: " + uri); | ||
} | ||
} | ||
|
||
@Override | ||
public String getType(Uri uri) { | ||
Log.i(getClass().getName(), "getType"); | ||
|
||
throw new UnsupportedOperationException("Not yet implemented"); | ||
} | ||
|
||
@Override | ||
public Uri insert(Uri uri, ContentValues values) { | ||
Log.i(getClass().getName(), "insert"); | ||
|
||
throw new UnsupportedOperationException("Not yet implemented"); | ||
} | ||
|
||
@Override | ||
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { | ||
Log.i(getClass().getName(), "update"); | ||
|
||
throw new UnsupportedOperationException("Not yet implemented"); | ||
} | ||
|
||
@Override | ||
public int delete(Uri uri, String selection, String[] selectionArgs) { | ||
Log.i(getClass().getName(), "delete"); | ||
|
||
throw new UnsupportedOperationException("Not yet implemented"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...s/src/main/java/ai/elimu/content_provider/utils/converter/CursorToSoundGsonConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package ai.elimu.content_provider.utils.converter; | ||
|
||
import android.database.Cursor; | ||
import android.util.Log; | ||
|
||
import java.util.Arrays; | ||
|
||
import ai.elimu.model.v2.gson.content.SoundGson; | ||
|
||
public class CursorToSoundGsonConverter { | ||
|
||
public static SoundGson getSoundGson(Cursor cursor) { | ||
Log.i(CursorToSoundGsonConverter.class.getName(), "getSoundGson"); | ||
|
||
Log.i(CursorToSoundGsonConverter.class.getName(), "Arrays.toString(cursor.getColumnNames()): " + Arrays.toString(cursor.getColumnNames())); | ||
|
||
int columnIndexId = cursor.getColumnIndex("id"); | ||
Long id = cursor.getLong(columnIndexId); | ||
Log.i(CursorToSoundGsonConverter.class.getName(), "id: " + id); | ||
|
||
int columnIndexRevisionNumber = cursor.getColumnIndex("revisionNumber"); | ||
Integer revisionNumber = cursor.getInt(columnIndexRevisionNumber); | ||
Log.i(CursorToSoundGsonConverter.class.getName(), "revisionNumber: " + revisionNumber); | ||
|
||
int columnIndexValueIpa = cursor.getColumnIndex("valueIpa"); | ||
String valueIpa = cursor.getString(columnIndexValueIpa); | ||
Log.i(CursorToSoundGsonConverter.class.getName(), "valueIpa: \"" + valueIpa + "\""); | ||
|
||
SoundGson soundGson = new SoundGson(); | ||
soundGson.setId(id); | ||
soundGson.setRevisionNumber(revisionNumber); | ||
soundGson.setValueIpa(valueIpa); | ||
|
||
return soundGson; | ||
} | ||
} |