-
-
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.
#4 Download Images from REST API (v2)
- Added Image entity to Room - Added REST integration
- Loading branch information
Nya Elimu
committed
Mar 28, 2020
1 parent
30276d3
commit fd52b6a
Showing
15 changed files
with
348 additions
and
75 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
84 changes: 84 additions & 0 deletions
84
app/schemas/ai.elimu.content_provider.room.db.RoomDb/1.json
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,84 @@ | ||
{ | ||
"formatVersion": 1, | ||
"database": { | ||
"version": 1, | ||
"identityHash": "2344eeef50e1c72dc29a552f597f8c6a", | ||
"entities": [ | ||
{ | ||
"tableName": "Image", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `revisionNumber` INTEGER NOT NULL, `id` INTEGER, PRIMARY KEY(`id`))", | ||
"fields": [ | ||
{ | ||
"fieldPath": "title", | ||
"columnName": "title", | ||
"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, '2344eeef50e1c72dc29a552f597f8c6a')" | ||
] | ||
} | ||
} |
46 changes: 0 additions & 46 deletions
46
app/schemas/ai.elimu.content_provider.room.db.RoomDb/1000000.json
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
app/src/main/java/ai/elimu/content_provider/rest/ImagesService.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,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(); | ||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/ai/elimu/content_provider/room/GsonToRoomConverter.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
26 changes: 26 additions & 0 deletions
26
app/src/main/java/ai/elimu/content_provider/room/dao/ImageDao.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,26 @@ | ||
package ai.elimu.content_provider.room.dao; | ||
|
||
import androidx.room.Dao; | ||
import androidx.room.Insert; | ||
import androidx.room.Query; | ||
import androidx.room.Update; | ||
|
||
import java.util.List; | ||
|
||
import ai.elimu.content_provider.room.entity.Image; | ||
|
||
@Dao | ||
public interface ImageDao { | ||
|
||
@Insert | ||
void insert(Image image); | ||
|
||
@Query("SELECT * FROM Image i WHERE i.id = :id") | ||
Image load(Long id); | ||
|
||
@Query("SELECT * FROM Image") | ||
List<Image> loadAll(); | ||
|
||
@Update | ||
void update(Image image); | ||
} |
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
24 changes: 24 additions & 0 deletions
24
app/src/main/java/ai/elimu/content_provider/room/entity/BaseEntity.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,24 @@ | ||
package ai.elimu.content_provider.room.entity; | ||
|
||
import androidx.room.PrimaryKey; | ||
|
||
/** | ||
* For documentation, see https://github.com/elimu-ai/webapp/tree/master/src/main/java/ai/elimu/model | ||
*/ | ||
public class BaseEntity { | ||
|
||
/** | ||
* Reflects the ID stored in the backend webapp's database. Therefore, {@code @PrimaryKey(autoGenerate = true)} is | ||
* not used. | ||
*/ | ||
@PrimaryKey | ||
private Long id; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/ai/elimu/content_provider/room/entity/Content.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,20 @@ | ||
package ai.elimu.content_provider.room.entity; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
/** | ||
* For documentation, see https://github.com/elimu-ai/webapp/tree/master/src/main/java/ai/elimu/model | ||
*/ | ||
public class Content extends BaseEntity { | ||
|
||
@NonNull | ||
private Integer revisionNumber; | ||
|
||
public Integer getRevisionNumber() { | ||
return revisionNumber; | ||
} | ||
|
||
public void setRevisionNumber(Integer revisionNumber) { | ||
this.revisionNumber = revisionNumber; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/ai/elimu/content_provider/room/entity/Image.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,22 @@ | ||
package ai.elimu.content_provider.room.entity; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.room.Entity; | ||
|
||
/** | ||
* For documentation, see https://github.com/elimu-ai/webapp/tree/master/src/main/java/ai/elimu/model | ||
*/ | ||
@Entity | ||
public class Image extends Content { | ||
|
||
@NonNull | ||
private String title; | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
} |
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
Oops, something went wrong.