mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 22:03:55 +01:00
Shift contributions to use Room DB (#3324)
* Part of #3127 * Added Room Dependency * Shifted ContributionsDao to use RoomDB * Save and Fetch contributions via RoomDAO * Bugfixes, fixed test cases, injected schedulers for ContributionsPresenter * removed stetho * Fixed ReviewHelperTest cases * Fixed test cases in DeleteHelperTest * Fetch all contributions [TODO add pagination to use this, maybe later in a seperate PR] * Update Schema false in AppDatabase * removed parameter from fetchControbutions * Added logs for fetch contributions * Fixed test case ContributionsPresenter * Added an autogenerate primary key, submit save contributions on executor * fixed getItemAtPosition * MainActivity Config changes +=orientation * BugFixes * Make AppDataBase Singleton * Set _id as autogenerate primary key [replacing the previously used filename, seems like they are not unique] * Replace Execxutor Utils with Subscribers on Singles in UploadService * BugFix, Upload Progress * Remove un-nescessary null check on contributions in ContributionsListAdapter * removed ContributionsListFragment [not-implemeted] * Review suggested changes * removed un-nescessary null checks * provide ContributionsDao * Minor bug fixes * wip * delete existing contributions table (from the existing db) on upgrade * remove un-nescessary null checks in test classes * shifted media to be a local variable in ReviewHelperTest * removed captured folder * Dispose composite disposables in UploadService * replaced size check with isEmpty ContributionsPresenter * transform saveContributions to a Completable * Addressed comments in review * Typo in Contributions * ReasonBuilderTest (create media object instead of mocking) * Use global Gson object instead of creating a new one in Converters * Provide Gson to Converters from the CommonsApplicationComponent * use static method instead of field instead of static field to provide GSON in Converters * Modified gitignore to exclude captures/*
This commit is contained in:
parent
642ed51c8c
commit
99c6f5f105
35 changed files with 557 additions and 1296 deletions
14
app/src/main/java/fr/free/nrw/commons/db/AppDatabase.java
Normal file
14
app/src/main/java/fr/free/nrw/commons/db/AppDatabase.java
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package fr.free.nrw.commons.db;
|
||||
|
||||
import androidx.room.Database;
|
||||
import androidx.room.RoomDatabase;
|
||||
import androidx.room.TypeConverters;
|
||||
|
||||
import fr.free.nrw.commons.contributions.Contribution;
|
||||
import fr.free.nrw.commons.contributions.ContributionDao;
|
||||
|
||||
@Database(entities = {Contribution.class}, version = 1, exportSchema = false)
|
||||
@TypeConverters({Converters.class})
|
||||
abstract public class AppDatabase extends RoomDatabase {
|
||||
public abstract ContributionDao getContributionDao();
|
||||
}
|
||||
76
app/src/main/java/fr/free/nrw/commons/db/Converters.java
Normal file
76
app/src/main/java/fr/free/nrw/commons/db/Converters.java
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
package fr.free.nrw.commons.db;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import androidx.room.TypeConverter;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.wikipedia.json.GsonUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.di.ApplicationlessInjection;
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
|
||||
public class Converters {
|
||||
|
||||
public static Gson getGson() {
|
||||
return ApplicationlessInjection.getInstance(CommonsApplication.getInstance()).getCommonsApplicationComponent().gson();
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public static Date fromTimestamp(Long value) {
|
||||
return value == null ? null : new Date(value);
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public static Long dateToTimestamp(Date date) {
|
||||
return date == null ? null : date.getTime();
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public static Uri fromString(String value) {
|
||||
return value == null ? null : Uri.parse(value);
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public static String uriToString(Uri uri) {
|
||||
return uri == null ? null : uri.toString();
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public static String listObjectToString(ArrayList<String> objectList) {
|
||||
return objectList == null ? null : getGson().toJson(objectList);
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public static ArrayList<String> stringToArrayListObject(String objectList) {
|
||||
return objectList == null ? null : getGson().fromJson(objectList,new TypeToken<ArrayList<String>>(){}.getType());
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public static String mapObjectToString(HashMap<String,String> objectList) {
|
||||
return objectList == null ? null : getGson().toJson(objectList);
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public static HashMap<String,String> stringToMap(String objectList) {
|
||||
return objectList == null ? null : getGson().fromJson(objectList,new TypeToken<HashMap<String,String>>(){}.getType());
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public static String latlngObjectToString(LatLng latlng) {
|
||||
return latlng == null ? null : getGson().toJson(latlng);
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public static LatLng stringToLatLng(String objectList) {
|
||||
return objectList == null ? null : getGson().fromJson(objectList,LatLng.class);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue