Skip to content

Commit

Permalink
Merge pull request #97 from elimu-ai/96-Create-Android-library
Browse files Browse the repository at this point in the history
96 create android library
  • Loading branch information
nya-elimu authored Nov 29, 2020
2 parents 58e5333 + e50f808 commit f2c678a
Show file tree
Hide file tree
Showing 12 changed files with 570 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'ai.elimu:model:2.0.24'
implementation 'ai.elimu:model:2.0.27'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.android.material:material:1.2.1'
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {

}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:4.1.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
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
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
include ':app'
include ':utils'
rootProject.name='elimu.ai Analytics'
1 change: 1 addition & 0 deletions utils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
51 changes: 51 additions & 0 deletions utils/build.gradle
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"
}
}
}
5 changes: 5 additions & 0 deletions utils/src/main/AndroidManifest.xml
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>
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 utils/src/main/java/ai/elimu/analytics/utils/ContentProviderUtil.java
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;
}
}
Loading

0 comments on commit f2c678a

Please sign in to comment.