Skip to content

Commit

Permalink
Merge pull request #5 from elimu-ai/#4-Download-Images-from-REST-API-…
Browse files Browse the repository at this point in the history
…(v2)

#4 download images from rest api (v2)
  • Loading branch information
nya-elimu authored Mar 28, 2020
2 parents 72858de + ee8a5ef commit fa618fb
Show file tree
Hide file tree
Showing 21 changed files with 636 additions and 95 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ android:

notifications:
email: false
slack: elimu-ai:5hNcmHPFkAETjJZjrkBlNTxr
37 changes: 26 additions & 11 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "ai.elimu.content_provider"
minSdkVersion 24
targetSdkVersion 29
versionCode 1000000
versionName "1.0.0-SNAPSHOT"
versionCode 1000001
versionName "1.0.1-SNAPSHOT"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
Expand All @@ -20,13 +20,25 @@ android {
debug {
applicationIdSuffix ".debug"
versionNameSuffix "-debug"
// buildConfigField("String", "BASE_URL", '"http://eng.test.elimu.ai/rest/v2/"')
buildConfigField("String", "BASE_URL", '"http://fil.test.elimu.ai/rest/v2/"')

// buildConfigField("String", "CONTENT_LANGUAGE", '"eng"')
buildConfigField("String", "CONTENT_LANGUAGE", '"fil"')

// buildConfigField("String", "BASE_URL", '"http://eng.test.elimu.ai"')
buildConfigField("String", "BASE_URL", '"http://fil.test.elimu.ai"')

buildConfigField("String", "REST_URL", '"/rest/v2"')
}
release {
minifyEnabled false
// buildConfigField("String", "BASE_URL", '"http://eng.elimu.ai/rest/v2/"')
buildConfigField("String", "BASE_URL", '"http://fil.elimu.ai/rest/v2/"')

// buildConfigField("String", "CONTENT_LANGUAGE", '"eng"')
buildConfigField("String", "CONTENT_LANGUAGE", '"fil"')

// buildConfigField("String", "BASE_URL", '"http://eng.elimu.ai"')
buildConfigField("String", "BASE_URL", '"http://fil.elimu.ai"')

buildConfigField("String", "REST_URL", '"/rest/v2"')
}
}
compileOptions {
Expand All @@ -38,10 +50,13 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'ai.elimu:model:1.2.41'
implementation 'ai.elimu:model:1.2.44'
implementation 'commons-io:commons-io:2.5'
implementation 'com.google.android.material:material:1.1.0'

// AndroidX
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.2.1'
implementation 'androidx.navigation:navigation-ui:2.2.1'
Expand All @@ -52,9 +67,9 @@ dependencies {
implementation 'com.squareup.retrofit2:converter-gson:2.7.2'

// Room components
implementation "androidx.room:room-runtime:2.2.4"
annotationProcessor "androidx.room:room-compiler:2.2.4"
androidTestImplementation "androidx.room:room-testing:2.2.4"
implementation "androidx.room:room-runtime:2.2.5"
annotationProcessor "androidx.room:room-compiler:2.2.5"
androidTestImplementation "androidx.room:room-testing:2.2.5"

testImplementation 'junit:junit:4.12'

Expand Down
90 changes: 90 additions & 0 deletions app/schemas/ai.elimu.content_provider.room.db.RoomDb/1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "05d677d0a581904e1213ed08adbc51d1",
"entities": [
{
"tableName": "Image",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `imageFormat` TEXT NOT NULL, `revisionNumber` INTEGER NOT NULL, `id` INTEGER, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "imageFormat",
"columnName": "imageFormat",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "revisionNumber",
"columnName": "revisionNumber",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "StoryBook",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `description` TEXT, `revisionNumber` INTEGER NOT NULL, `id` INTEGER, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "description",
"columnName": "description",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "revisionNumber",
"columnName": "revisionNumber",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '05d677d0a581904e1213ed08adbc51d1')"
]
}
}
46 changes: 0 additions & 46 deletions app/schemas/ai.elimu.content_provider.room.db.RoomDb/1000000.json

This file was deleted.

90 changes: 90 additions & 0 deletions app/schemas/ai.elimu.content_provider.room.db.RoomDb/2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "05d677d0a581904e1213ed08adbc51d1",
"entities": [
{
"tableName": "Image",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `imageFormat` TEXT NOT NULL, `revisionNumber` INTEGER NOT NULL, `id` INTEGER, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "imageFormat",
"columnName": "imageFormat",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "revisionNumber",
"columnName": "revisionNumber",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "StoryBook",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `description` TEXT, `revisionNumber` INTEGER NOT NULL, `id` INTEGER, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "description",
"columnName": "description",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "revisionNumber",
"columnName": "revisionNumber",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '05d677d0a581904e1213ed08adbc51d1')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void onCreate() {
super.onCreate();

retrofit = new Retrofit.Builder()
.baseUrl(BuildConfig.BASE_URL)
.baseUrl(BuildConfig.BASE_URL + BuildConfig.REST_URL + "/")
.addConverterFactory(GsonConverterFactory.create())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ai.elimu.content_provider.rest;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.GET;

public interface ImagesService {

@GET("content/images")
Call<ResponseBody> listImages();
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
package ai.elimu.content_provider.room;

import ai.elimu.content_provider.room.entity.Image;
import ai.elimu.content_provider.room.entity.StoryBook;
import ai.elimu.model.gson.content.StoryBookGson;
import ai.elimu.model.gson.content.multimedia.ImageGson;

public class GsonToRoomConverter {

public static Image getImage(ImageGson imageGson) {
if (imageGson == null) {
return null;
} else {
Image image = new Image();

// BaseEntity
image.setId(imageGson.getId());

// Content
image.setRevisionNumber(imageGson.getRevisionNumber());

// Image
image.setTitle(imageGson.getTitle());
image.setImageFormat(imageGson.getImageFormat());

return image;
}
}

public static StoryBook getStoryBook(StoryBookGson storyBookGson) {
if (storyBookGson == null) {
return null;
} else {
StoryBook storyBook = new StoryBook();

// BaseEntity
storyBook.setId(storyBookGson.getId());

// Content
storyBook.setRevisionNumber(storyBookGson.getRevisionNumber());

// StoryBook
storyBook.setTitle(storyBookGson.getTitle());
storyBook.setDescription(storyBookGson.getDescription());

Expand Down
Loading

0 comments on commit fa618fb

Please sign in to comment.