...
 
Commits (8)
......@@ -151,11 +151,11 @@ dependencies {
compile 'com.android.support:preference-v7:28.0.0'
// AndroidX Libraries
implementation 'androidx.work:work-runtime:2.0.0'
implementation group: 'androidx.appcompat', name: 'appcompat', version: '1.0.2'
implementation 'androidx.work:work-runtime:2.3.1'
implementation group: 'androidx.appcompat', name: 'appcompat', version: '1.1.0'
// Material Design Libraries
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.android.material:material:1.1.0'
}
allprojects {
......
......@@ -17,7 +17,7 @@ public class ASiSTConstants {
public static final int NOTIFICATION_ID_UPDATE = 6951;
public static final String DB_NAME = "ASiST.db";
public static final int DB_VERSION = 9; // DB_Version 4 ab myTU Version
public static final int DB_VERSION = 11; // DB_Version 4 ab myTU Version
public static final String FEEDBACK_LECTURER_MODE = "feedback.lecturer.mode";
......
package de.bps.asist.core.manager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import de.bps.asist.module.AbstractAsistModule;
public class ASiSTModuleManager {
private static final ASiSTModuleManager INSTANCE = new ASiSTModuleManager();
private List<AbstractAsistModule> modules = new ArrayList<>();
Map<Class<? extends AbstractAsistModule>, AbstractAsistModule> modules = createNewModuleMap();
private ASiSTModuleManager(){
}
......@@ -19,30 +22,26 @@ public class ASiSTModuleManager {
}
public void resetModuleList(){
modules = new ArrayList<>();
modules = createNewModuleMap();
}
public void register(AbstractAsistModule module){
modules.add(module);
modules.put(module.getClass(), module);
}
public <T extends AbstractAsistModule> T getModule( Class<T> moduleClass, T defaultValue ) {
T resultModule = defaultValue;
for ( AbstractAsistModule registeredModule: this.modules ) {
if( moduleClass.isInstance( registeredModule ) ) {
defaultValue = (T)registeredModule;
break;
}
}
return resultModule;
return modules.containsKey(moduleClass) ? (T)modules.get(moduleClass) : defaultValue;
}
public <T extends AbstractAsistModule> T getModule( Class<T> moduleClass) {
return this.getModule(moduleClass, null);
return (T)modules.get(moduleClass);
}
public List<AbstractAsistModule> getModules() {
return modules;
return new ArrayList<>(modules.values());
}
}
protected Map<Class<? extends AbstractAsistModule>, AbstractAsistModule> createNewModuleMap() {
return Collections.synchronizedMap(new LinkedHashMap<Class<? extends AbstractAsistModule>, AbstractAsistModule>());
}
}
\ No newline at end of file
......@@ -3,10 +3,19 @@ package de.bps.asist.core.manager.database;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import androidx.annotation.NonNull;
import androidx.work.Constraints;
import androidx.work.NetworkType;
import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkManager;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
......@@ -15,14 +24,17 @@ import de.bps.asist.context.ASiSTConstants;
import de.bps.asist.core.database.AbstractDatabaseObject;
import de.bps.asist.core.manager.ASiSTModuleManager;
import de.bps.asist.module.AbstractAsistModule;
import de.bps.asist.module.timetable.TimetableModule;
public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
private final List<AbstractAsistModule> modules;
private Context context;
public DatabaseHelper(final Context context) {
super(context, ASiSTConstants.DB_NAME, null, ASiSTConstants.DB_VERSION);
modules = ASiSTModuleManager.getInstance().getModules();
this.context = context.getApplicationContext();
}
@Override
......@@ -45,6 +57,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
@Override
public void onUpgrade(final SQLiteDatabase database, final ConnectionSource connectionSource, final int oldVersion, final int newVersion) {
logger.info("Update cache database from version %s to %s", oldVersion, newVersion);
if (newVersion == 7) {
final Set<Class<? extends AbstractDatabaseObject>> classes = new HashSet<>();
for (final AbstractAsistModule module : modules) {
......@@ -85,8 +99,54 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
if(oldVersion < 9)
{
logger.info("Update database to version 9");
logger.info("Add type column to course table");
database.execSQL("ALTER TABLE 'course' ADD COLUMN type INTEGER NOT NULL DEFAULT (0);");
logger.info("Database update successfully to version 9");
}
if (oldVersion < 10) {
logger.info("Update database to version 10");
logger.info("Reinitialize timetable tables");
TimetableModule timetableModule = ASiSTModuleManager.getInstance().getModule(TimetableModule.class);
try {
for (Class<? extends AbstractDatabaseObject> timetableModuleDatabaseClass : timetableModule.getDatabaseClasses()) {
logger.info("Reinitialize table of class {}", timetableModuleDatabaseClass.getCanonicalName());
TableUtils.dropTable(getConnectionSource(), timetableModuleDatabaseClass, false);
TableUtils.createTableIfNotExists(getConnectionSource(), timetableModuleDatabaseClass);
}
logger.info("Reinitializing of timetable tables successfully");
logger.info("Start updating timetable data");
WorkManager.getInstance().enqueue(
new OneTimeWorkRequest.Builder(UpdateTimetableDatas.class)
.setConstraints(
new Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build())
.addTag("TimetableDatabaseUpdate")
.build()
);
} catch (SQLException sqlException) {
logger.error(sqlException, "Upgrade cache database to version 10 failed");
}
}
logger.info("Database update successfully to version {}", newVersion);
}
private class UpdateTimetableDatas extends Worker {
public UpdateTimetableDatas(@NonNull Context context, @NonNull WorkerParameters params) {
super(context, params);
}
@Override
public @NonNull Result doWork() {
try {
ASiSTModuleManager.getInstance().getModule(TimetableModule.class).updateData(getApplicationContext());
return Result.success();
} catch (Throwable throwable) {
return Result.retry();
}
}
}
}
......@@ -71,7 +71,7 @@ public class Course extends AbstractDatabaseObject implements IListItem {
@AsistColumnDescription(position = 2)
@AsistDescription
@ASiSTDetail(i18nKey = "timetable_lecturer_title", position = 6)
@DatabaseField
@DatabaseField(defaultValue = "0", canBeNull = false)
private Integer type;
public Course() {
......