-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from elimu-ai/96-Create-Android-library
96 create android library
- Loading branch information
Showing
12 changed files
with
570 additions
and
4 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Fri Nov 13 19:52:03 CET 2020 | ||
#Wed Nov 18 09:19:17 CET 2020 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
include ':app' | ||
include ':utils' | ||
rootProject.name='elimu.ai Analytics' |
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 @@ | ||
/build |
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,51 @@ | ||
plugins { | ||
id 'com.android.library' | ||
id 'maven-publish' | ||
} | ||
|
||
android { | ||
compileSdkVersion 29 | ||
buildToolsVersion "29.0.3" | ||
|
||
defaultConfig { | ||
minSdkVersion 24 | ||
targetSdkVersion 29 | ||
versionCode 1000007 | ||
versionName "1.0.7" | ||
setProperty("archivesBaseName", "utils-${versionName}") | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation 'ai.elimu:model:2.0.27' | ||
} | ||
|
||
// 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.analytics' | ||
artifactId 'utils' | ||
version '1.0.7' | ||
artifact("${buildDir}/outputs/aar/utils-${version}-release.aar") | ||
} | ||
} | ||
repositories { | ||
maven { | ||
credentials(PasswordCredentials) | ||
// See https://www.jfrog.com/confluence/display/BT/Bintray+REST+API#BintrayRESTAPI-MavenUpload | ||
url "https://api.bintray.com/maven/elimu-ai/maven/analytics.utils/;publish=1" | ||
} | ||
} | ||
} |
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,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="ai.elimu.analytics.utils"> | ||
|
||
</manifest> |
87 changes: 87 additions & 0 deletions
87
utils/src/main/java/ai/elimu/analytics/utils/AssessmentEventUtil.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,87 @@ | ||
package ai.elimu.analytics.utils; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.database.Cursor; | ||
import android.net.Uri; | ||
import android.util.Log; | ||
import android.widget.Toast; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import ai.elimu.analytics.utils.converter.CursorToWordAssessmentEventGsonConverter; | ||
import ai.elimu.model.v2.gson.analytics.WordAssessmentEventGson; | ||
import ai.elimu.model.v2.gson.content.LetterGson; | ||
import ai.elimu.model.v2.gson.content.WordGson; | ||
|
||
public class AssessmentEventUtil { | ||
|
||
public static void reportLetterAssessmentEvent(LetterGson letterGson, Float masteryScore, Long timeSpentMs, Context context, String analyticsApplicationId) { | ||
Log.i(AssessmentEventUtil.class.getName(), "reportLetterAssessmentEvent"); | ||
|
||
Intent broadcastIntent = new Intent(); | ||
broadcastIntent.setAction("ai.elimu.intent.action.LETTER_ASSESSMENT_EVENT"); | ||
broadcastIntent.putExtra("packageName", context.getPackageName()); | ||
broadcastIntent.putExtra("letterId", letterGson.getId()); | ||
broadcastIntent.putExtra("letterText", letterGson.getText()); | ||
broadcastIntent.putExtra("masteryScore", masteryScore); | ||
broadcastIntent.putExtra("timeSpentMs", timeSpentMs); | ||
broadcastIntent.setPackage(analyticsApplicationId); | ||
context.sendBroadcast(broadcastIntent); | ||
} | ||
|
||
public static void reportWordAssessmentEvent(WordGson wordGson, Float masteryScore, Long timeSpentMs, Context context, String analyticsApplicationId) { | ||
Log.i(AssessmentEventUtil.class.getName(), "reportWordAssessmentEvent"); | ||
|
||
Intent broadcastIntent = new Intent(); | ||
broadcastIntent.setAction("ai.elimu.intent.action.WORD_ASSESSMENT_EVENT"); | ||
broadcastIntent.putExtra("packageName", context.getPackageName()); | ||
broadcastIntent.putExtra("wordId", wordGson.getId()); | ||
broadcastIntent.putExtra("wordText", wordGson.getText()); | ||
broadcastIntent.putExtra("masteryScore", masteryScore); | ||
broadcastIntent.putExtra("timeSpentMs", timeSpentMs); | ||
broadcastIntent.setPackage(analyticsApplicationId); | ||
context.sendBroadcast(broadcastIntent); | ||
} | ||
|
||
|
||
public static List<WordAssessmentEventGson> getWordAssessmentEventGsons(Set<Long> idsOfWordsInWordLearningEvents, Context context, String analyticsApplicationId) { | ||
Log.i(AssessmentEventUtil.class.getName(), "getWordAssessmentEventGsons"); | ||
|
||
List<WordAssessmentEventGson> wordAssessmentEventGsons = new ArrayList<>(); | ||
|
||
Uri wordAssessmentEventsUri = Uri.parse("content://" + analyticsApplicationId + ".provider.word_assessment_event_provider/events"); | ||
Log.i(AssessmentEventUtil.class.getName(), "wordAssessmentEventsUri: " + wordAssessmentEventsUri); | ||
Cursor wordAssessmentEventsCursor = context.getContentResolver().query(wordAssessmentEventsUri, null, null, null, null); | ||
Log.i(AssessmentEventUtil.class.getName(), "wordAssessmentEventsCursor: " + wordAssessmentEventsCursor); | ||
if (wordAssessmentEventsCursor == null) { | ||
Log.e(AssessmentEventUtil.class.getName(), "wordAssessmentEventsCursor == null"); | ||
Toast.makeText(context, "wordAssessmentEventsCursor == null", Toast.LENGTH_LONG).show(); | ||
} else { | ||
Log.i(AssessmentEventUtil.class.getName(), "wordAssessmentEventsCursor.getCount(): " + wordAssessmentEventsCursor.getCount()); | ||
if (wordAssessmentEventsCursor.getCount() == 0) { | ||
Log.e(AssessmentEventUtil.class.getName(), "wordAssessmentEventsCursor.getCount() == 0"); | ||
} else { | ||
boolean isLast = false; | ||
while (!isLast) { | ||
wordAssessmentEventsCursor.moveToNext(); | ||
|
||
// Convert from Room to Gson | ||
WordAssessmentEventGson wordAssessmentEventGson = CursorToWordAssessmentEventGsonConverter.getWordAssessmentEventGson(wordAssessmentEventsCursor); | ||
|
||
wordAssessmentEventGsons.add(wordAssessmentEventGson); | ||
|
||
isLast = wordAssessmentEventsCursor.isLast(); | ||
} | ||
|
||
wordAssessmentEventsCursor.close(); | ||
Log.i(AssessmentEventUtil.class.getName(), "wordAssessmentEventsCursor.isClosed(): " + wordAssessmentEventsCursor.isClosed()); | ||
} | ||
} | ||
Log.i(AssessmentEventUtil.class.getName(), "wordAssessmentEventGsons.size(): " + wordAssessmentEventGsons.size()); | ||
|
||
return wordAssessmentEventGsons; | ||
} | ||
} |
134 changes: 134 additions & 0 deletions
134
utils/src/main/java/ai/elimu/analytics/utils/ContentProviderUtil.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,134 @@ | ||
package ai.elimu.analytics.utils; | ||
|
||
import android.content.Context; | ||
import android.database.Cursor; | ||
import android.net.Uri; | ||
import android.util.Log; | ||
import android.widget.Toast; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import ai.elimu.analytics.utils.converter.CursorToWordAssessmentEventGsonConverter; | ||
import ai.elimu.analytics.utils.converter.CursorToWordLearningEventGsonConverter; | ||
import ai.elimu.model.v2.gson.analytics.WordAssessmentEventGson; | ||
import ai.elimu.model.v2.gson.analytics.WordLearningEventGson; | ||
|
||
public class ContentProviderUtil { | ||
|
||
public static List<WordLearningEventGson> getWordLearningEventGsons(Context context, String contentProviderApplicationId) { | ||
Log.i(ContentProviderUtil.class.getName(), "getWordLearningEventGsons"); | ||
|
||
List<WordLearningEventGson> wordLearningEventGsons = new ArrayList<>(); | ||
|
||
Uri wordLearningEventsUri = Uri.parse("content://" + contentProviderApplicationId + ".provider.word_learning_event_provider/events"); | ||
Log.i(ContentProviderUtil.class.getName(), "wordLearningEventsUri: " + wordLearningEventsUri); | ||
Cursor wordLearningEventsCursor = context.getContentResolver().query(wordLearningEventsUri, null, null, null, null); | ||
Log.i(ContentProviderUtil.class.getName(), "wordLearningEventsCursor: " + wordLearningEventsCursor); | ||
if (wordLearningEventsCursor == null) { | ||
Log.e(ContentProviderUtil.class.getName(), "wordLearningEventsCursor == null"); | ||
Toast.makeText(context, "wordLearningEventsCursor == null", Toast.LENGTH_LONG).show(); | ||
} else { | ||
Log.i(ContentProviderUtil.class.getName(), "wordLearningEventsCursor.getCount(): " + wordLearningEventsCursor.getCount()); | ||
if (wordLearningEventsCursor.getCount() == 0) { | ||
Log.e(ContentProviderUtil.class.getName(), "wordLearningEventsCursor.getCount() == 0"); | ||
} else { | ||
boolean isLast = false; | ||
while (!isLast) { | ||
wordLearningEventsCursor.moveToNext(); | ||
|
||
// Convert from Room to Gson | ||
WordLearningEventGson wordLearningEventGson = CursorToWordLearningEventGsonConverter.getWordLearningEventGson(wordLearningEventsCursor); | ||
|
||
wordLearningEventGsons.add(wordLearningEventGson); | ||
|
||
isLast = wordLearningEventsCursor.isLast(); | ||
} | ||
|
||
wordLearningEventsCursor.close(); | ||
Log.i(ContentProviderUtil.class.getName(), "wordLearningEventsCursor.isClosed(): " + wordLearningEventsCursor.isClosed()); | ||
} | ||
} | ||
Log.i(ContentProviderUtil.class.getName(), "wordLearningEventGsons.size(): " + wordLearningEventGsons.size()); | ||
|
||
return wordLearningEventGsons; | ||
} | ||
|
||
public static Set<Long> getIdsOfWordsInWordLearningEvents(Context context, String contentProviderApplicationId) { | ||
Log.i(ContentProviderUtil.class.getName(), "getIdsOfWordsInWordLearningEvents"); | ||
|
||
Set<Long> wordIdsSet = new HashSet<>(); | ||
|
||
Uri wordLearningEventsUri = Uri.parse("content://" + contentProviderApplicationId + ".provider.word_learning_event_provider/events"); | ||
Log.i(ContentProviderUtil.class.getName(), "wordLearningEventsUri: " + wordLearningEventsUri); | ||
Cursor wordLearningEventsCursor = context.getContentResolver().query(wordLearningEventsUri, null, null, null, null); | ||
Log.i(ContentProviderUtil.class.getName(), "wordLearningEventsCursor: " + wordLearningEventsCursor); | ||
if (wordLearningEventsCursor == null) { | ||
Log.e(ContentProviderUtil.class.getName(), "wordLearningEventsCursor == null"); | ||
Toast.makeText(context, "wordLearningEventsCursor == null", Toast.LENGTH_LONG).show(); | ||
} else { | ||
Log.i(ContentProviderUtil.class.getName(), "wordLearningEventsCursor.getCount(): " + wordLearningEventsCursor.getCount()); | ||
if (wordLearningEventsCursor.getCount() == 0) { | ||
Log.e(ContentProviderUtil.class.getName(), "wordLearningEventsCursor.getCount() == 0"); | ||
} else { | ||
boolean isLast = false; | ||
while (!isLast) { | ||
wordLearningEventsCursor.moveToNext(); | ||
|
||
// Convert from Room to Gson | ||
WordLearningEventGson wordLearningEventGson = CursorToWordLearningEventGsonConverter.getWordLearningEventGson(wordLearningEventsCursor); | ||
|
||
wordIdsSet.add(wordLearningEventGson.getWordId()); | ||
|
||
isLast = wordLearningEventsCursor.isLast(); | ||
} | ||
|
||
wordLearningEventsCursor.close(); | ||
Log.i(ContentProviderUtil.class.getName(), "wordLearningEventsCursor.isClosed(): " + wordLearningEventsCursor.isClosed()); | ||
} | ||
} | ||
Log.i(ContentProviderUtil.class.getName(), "wordIdsSet.size(): " + wordIdsSet.size()); | ||
|
||
return wordIdsSet; | ||
} | ||
|
||
public static List<WordAssessmentEventGson> getWordAssessmentEventGsons(Set<Long> idsOfWordsInWordLearningEvents, Context context, String contentProviderApplicationId) { | ||
Log.i(ContentProviderUtil.class.getName(), "getWordAssessmentEventGsons"); | ||
|
||
List<WordAssessmentEventGson> wordAssessmentEventGsons = new ArrayList<>(); | ||
|
||
Uri wordAssessmentEventsUri = Uri.parse("content://" + contentProviderApplicationId + ".provider.word_assessment_event_provider/events"); | ||
Log.i(ContentProviderUtil.class.getName(), "wordAssessmentEventsUri: " + wordAssessmentEventsUri); | ||
Cursor wordAssessmentEventsCursor = context.getContentResolver().query(wordAssessmentEventsUri, null, null, null, null); | ||
Log.i(ContentProviderUtil.class.getName(), "wordAssessmentEventsCursor: " + wordAssessmentEventsCursor); | ||
if (wordAssessmentEventsCursor == null) { | ||
Log.e(ContentProviderUtil.class.getName(), "wordAssessmentEventsCursor == null"); | ||
Toast.makeText(context, "wordAssessmentEventsCursor == null", Toast.LENGTH_LONG).show(); | ||
} else { | ||
Log.i(ContentProviderUtil.class.getName(), "wordAssessmentEventsCursor.getCount(): " + wordAssessmentEventsCursor.getCount()); | ||
if (wordAssessmentEventsCursor.getCount() == 0) { | ||
Log.e(ContentProviderUtil.class.getName(), "wordAssessmentEventsCursor.getCount() == 0"); | ||
} else { | ||
boolean isLast = false; | ||
while (!isLast) { | ||
wordAssessmentEventsCursor.moveToNext(); | ||
|
||
// Convert from Room to Gson | ||
WordAssessmentEventGson wordAssessmentEventGson = CursorToWordAssessmentEventGsonConverter.getWordAssessmentEventGson(wordAssessmentEventsCursor); | ||
|
||
wordAssessmentEventGsons.add(wordAssessmentEventGson); | ||
|
||
isLast = wordAssessmentEventsCursor.isLast(); | ||
} | ||
|
||
wordAssessmentEventsCursor.close(); | ||
Log.i(ContentProviderUtil.class.getName(), "wordAssessmentEventsCursor.isClosed(): " + wordAssessmentEventsCursor.isClosed()); | ||
} | ||
} | ||
Log.i(ContentProviderUtil.class.getName(), "wordAssessmentEventGsons.size(): " + wordAssessmentEventGsons.size()); | ||
|
||
return wordAssessmentEventGsons; | ||
} | ||
} |
Oops, something went wrong.