Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide letter-sound correspondences to other apps #112

Merged
merged 13 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/gradle-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
java: [11, 17]
java: [17]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand Down
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ apply plugin: 'com.android.application'
apply plugin: 'org.ajoberstar.grgit'

android {
compileSdk 33
namespace 'ai.elimu.content_provider'
compileSdk 34

defaultConfig {
applicationId "ai.elimu.content_provider"
minSdkVersion 24
targetSdkVersion 33
targetSdkVersion 34
versionCode 1002021
versionName "1.2.21-SNAPSHOT"
setProperty("archivesBaseName", "${applicationId}-${versionCode}")
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ai.elimu.content_provider">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />

Expand Down Expand Up @@ -33,6 +32,11 @@
android:authorities="${applicationId}.provider.letter_provider"
android:enabled="true"
android:exported="true" />
<provider
android:name=".provider.LetterSoundContentProvider"
android:authorities="${applicationId}.provider.letter_sound_provider"
android:enabled="true"
android:exported="true" />
<provider
android:name=".provider.WordContentProvider"
android:authorities="${applicationId}.provider.word_provider"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
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.LetterSoundDao;
import ai.elimu.content_provider.room.db.RoomDb;

public class LetterSoundContentProvider extends ContentProvider {

private static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".provider.letter_sound_provider";
private static final String TABLE_LETTER_SOUNDS = "letter_sounds";
private static final int CODE_LETTER_SOUNDS = 1;
private static final int CODE_LETTER_SOUND_ID = 2;
private static final UriMatcher MATCHER = new UriMatcher(UriMatcher.NO_MATCH);

static {
MATCHER.addURI(AUTHORITY, TABLE_LETTER_SOUNDS, CODE_LETTER_SOUNDS);
MATCHER.addURI(AUTHORITY, TABLE_LETTER_SOUNDS + "/#", CODE_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);
LetterSoundDao letterSoundDao = roomDb.letterSoundDao();

final int code = MATCHER.match(uri);
Log.i(getClass().getName(), "code: " + code);
if (code == CODE_LETTER_SOUNDS) {
final Cursor cursor;

// Get the Room Cursor
cursor = letterSoundDao.loadAll_Cursor();
Log.i(getClass().getName(), "cursor: " + cursor);

cursor.setNotificationUri(context.getContentResolver(), uri);

return cursor;
} else if (code == CODE_LETTER_SOUND_ID) {
// Extract the LetterSound ID from the URI
List<String> pathSegments = uri.getPathSegments();
Log.i(getClass().getName(), "pathSegments: " + pathSegments);
String idAsString = pathSegments.get(1);
Long id = Long.valueOf(idAsString);
Log.i(getClass().getName(), "id: " + id);

final Cursor cursor;

// Get the Room Cursor
cursor = letterSoundDao.load_Cursor(id);
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");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ai.elimu.content_provider.room.dao;

import android.database.Cursor;

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
Expand All @@ -14,9 +16,15 @@ public interface LetterSoundDao {
@Insert
void insert(LetterSound letterSound);

@Query("SELECT * FROM LetterSound WHERE id = :id")
Cursor load_Cursor(Long id);

@Query("SELECT * FROM LetterSound")
List<LetterSound> loadAll();

@Query("SELECT * FROM LetterSound")
Cursor loadAll_Cursor();

@Query("DELETE FROM LetterSound")
void deleteAll();
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.3'
classpath 'com.android.tools.build:gradle:8.1.4'
classpath 'org.ajoberstar.grgit:grgit-gradle:5.0.0'

// NOTE: Do not place your application dependencies here; they belong
Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ org.gradle.jvmargs=-Xmx1536m
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false

Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
28 changes: 19 additions & 9 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

#
# Copyright 2015-2021 the original authors.
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,10 +32,10 @@
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions $var�, �${var}�, �${var:-default}�, �${var+SET},
# ${var#prefix}�, �${var%suffix}, and $( cmd );
# * compound commands having a testable exit status, especially case;
# * various built-in commands including command�, �set, and ulimit.
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
Expand All @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,10 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
Expand Down Expand Up @@ -143,12 +143,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -205,6 +209,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
15 changes: 9 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
25 changes: 3 additions & 22 deletions utils/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
plugins {
id 'com.android.library'
id 'maven-publish'
}

android {
compileSdk 33
namespace 'ai.elimu.content_provider.utils'
compileSdk 34

defaultConfig {
minSdkVersion 24
targetSdkVersion 33
targetSdkVersion 34
versionCode 1002021
versionName "1.2.21-SNAPSHOT"
setProperty("archivesBaseName", "utils-${versionName}")
Expand All @@ -29,22 +29,3 @@ dependencies {
implementation 'com.github.elimu-ai:model:model-2.0.66' // See https://jitpack.io/#elimu-ai/model
implementation 'com.github.elimu-ai:analytics:3.1.11@aar' // See https://jitpack.io/#elimu-ai/analytics
}

// See https://docs.gradle.org/current/dsl/org.gradle.api.publish.maven.MavenPublication.html
// Usage: ./gradlew clean build publish -PmavenUsername=***** -PmavenPassword=*****
publishing {
publications {
utils(MavenPublication) {
groupId 'ai.elimu.content_provider'
artifactId 'utils'
version '1.2.21-SNAPSHOT'
artifact("${buildDir}/outputs/aar/utils-${version}-release.aar")
}
}
repositories {
maven {
credentials(PasswordCredentials)
url "https://maven.pkg.github.com/elimu-ai/content-provider"
}
}
}
Loading