-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…-REST-API #214 download applications from rest api
- Loading branch information
Showing
25 changed files
with
874 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"formatVersion": 1, | ||
"database": { | ||
"version": 1, | ||
"identityHash": "4f7ae834a52f85a4fcbcfaa3d7d0653f", | ||
"entities": [ | ||
{ | ||
"tableName": "Application", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`packageName` TEXT NOT NULL, `infrastructural` INTEGER, `applicationStatus` TEXT NOT NULL, `id` INTEGER, PRIMARY KEY(`id`))", | ||
"fields": [ | ||
{ | ||
"fieldPath": "packageName", | ||
"columnName": "packageName", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "infrastructural", | ||
"columnName": "infrastructural", | ||
"affinity": "INTEGER", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "applicationStatus", | ||
"columnName": "applicationStatus", | ||
"affinity": "TEXT", | ||
"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, '4f7ae834a52f85a4fcbcfaa3d7d0653f')" | ||
] | ||
} | ||
} |
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
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
13 changes: 13 additions & 0 deletions
13
app/src/main/java/ai/elimu/appstore/rest/ApplicationsService.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,13 @@ | ||
package ai.elimu.appstore.rest; | ||
|
||
import java.util.List; | ||
|
||
import ai.elimu.model.v2.gson.application.ApplicationGson; | ||
import retrofit2.Call; | ||
import retrofit2.http.GET; | ||
|
||
public interface ApplicationsService { | ||
|
||
@GET("applications") | ||
Call<List<ApplicationGson>> listApplications(); | ||
} |
31 changes: 31 additions & 0 deletions
31
app/src/main/java/ai/elimu/appstore/room/EnumConverter.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,31 @@ | ||
package ai.elimu.appstore.room; | ||
|
||
import android.text.TextUtils; | ||
|
||
import androidx.room.TypeConverter; | ||
|
||
import ai.elimu.model.enums.admin.ApplicationStatus; | ||
|
||
/** | ||
* See https://developer.android.com/training/data-storage/room/referencing-data | ||
*/ | ||
public class EnumConverter { | ||
|
||
@TypeConverter | ||
public static ApplicationStatus fromApplicationStatus(String value) { | ||
ApplicationStatus applicationStatus = null; | ||
if (!TextUtils.isEmpty(value)) { | ||
applicationStatus = ApplicationStatus.valueOf(value); | ||
} | ||
return applicationStatus; | ||
} | ||
|
||
@TypeConverter | ||
public static String toApplicationStatus(ApplicationStatus applicationStatus) { | ||
String value = null; | ||
if (applicationStatus != null) { | ||
value = applicationStatus.toString(); | ||
} | ||
return value; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
app/src/main/java/ai/elimu/appstore/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package ai.elimu.appstore.room; | ||
|
||
import ai.elimu.appstore.room.entity.Application; | ||
import ai.elimu.model.v2.gson.application.ApplicationGson; | ||
|
||
public class GsonToRoomConverter { | ||
|
||
public static Application getApplication(ApplicationGson applicationGson) { | ||
if (applicationGson == null) { | ||
return null; | ||
} else { | ||
Application application = new Application(); | ||
|
||
// BaseEntity | ||
application.setId(applicationGson.getId()); | ||
|
||
// Application | ||
application.setPackageName(applicationGson.getPackageName()); | ||
application.setInfrastructural(applicationGson.isInfrastructural()); | ||
application.setApplicationStatus(applicationGson.getApplicationStatus()); | ||
|
||
return application; | ||
} | ||
} | ||
} |
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,55 @@ | ||
package ai.elimu.appstore.room; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.room.Database; | ||
import androidx.room.Room; | ||
import androidx.room.RoomDatabase; | ||
import androidx.room.TypeConverters; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
import ai.elimu.appstore.room.dao.ApplicationDao; | ||
import ai.elimu.appstore.room.entity.Application; | ||
|
||
@Database(version = 1, entities = {Application.class}) | ||
@TypeConverters({EnumConverter.class}) | ||
public abstract class RoomDb extends RoomDatabase { | ||
|
||
public abstract ApplicationDao applicationDao(); | ||
|
||
private static volatile RoomDb INSTANCE; | ||
|
||
public static final ExecutorService databaseWriteExecutor = Executors.newFixedThreadPool(4); | ||
|
||
public static RoomDb getDatabase(final Context context) { | ||
if (INSTANCE == null) { | ||
synchronized (RoomDb.class) { | ||
if (INSTANCE == null) { | ||
INSTANCE = Room | ||
.databaseBuilder( | ||
context.getApplicationContext(), | ||
RoomDb.class, | ||
"appstore_db" | ||
) | ||
// .addMigrations( | ||
// MIGRATION_1_2 | ||
// ) | ||
.build(); | ||
} | ||
} | ||
} | ||
return INSTANCE; | ||
} | ||
|
||
// private static final Migration MIGRATION_1_2 = new Migration(1, 2) { | ||
// @Override | ||
// public void migrate(SupportSQLiteDatabase database) { | ||
// Log.i(getClass().getName(), "migrate (1 --> 2)"); | ||
// String sql = "..."; | ||
// Log.i(getClass().getName(), "sql: " + sql); | ||
// database.execSQL(sql); | ||
// } | ||
// }; | ||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/ai/elimu/appstore/room/dao/ApplicationDao.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.appstore.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.appstore.room.entity.Application; | ||
|
||
@Dao | ||
public interface ApplicationDao { | ||
|
||
@Insert | ||
void insert(Application application); | ||
|
||
@Query("SELECT * FROM Application a WHERE a.id = :id") | ||
Application load(Long id); | ||
|
||
@Query("SELECT * FROM Application a") | ||
List<Application> loadAll(); | ||
|
||
@Update | ||
void update(Application application); | ||
} |
Oops, something went wrong.