Skip to content

Shift contributions to use Room DB #3324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9e0b8f0
Part of #3127
ashishkumar468 Jan 13, 2020
d37148e
Sync with master
ashishkumar468 Feb 4, 2020
3d54774
Save and Fetch contributions via RoomDAO
ashishkumar468 Feb 4, 2020
899885c
Bugfixes, fixed test cases, injected schedulers for ContributionsPres…
ashishkumar468 Feb 23, 2020
ac33ee6
removed stetho
ashishkumar468 Feb 23, 2020
d31fbfc
Fixed ReviewHelperTest cases
ashishkumar468 Feb 23, 2020
5e060bd
Fixed test cases in DeleteHelperTest
ashishkumar468 Feb 23, 2020
85d99a0
Fetch all contributions [TODO add pagination to use this, maybe later…
ashishkumar468 Feb 23, 2020
37f17b6
Update Schema false in AppDatabase
ashishkumar468 Feb 24, 2020
509ea43
removed parameter from fetchControbutions
ashishkumar468 Feb 24, 2020
c8962a2
Merge branch 'master' into refactor/contributions-to-room
ashishkumar468 Feb 24, 2020
1424776
Added logs for fetch contributions
ashishkumar468 Feb 24, 2020
6a52241
Fixed test case ContributionsPresenter
ashishkumar468 Feb 24, 2020
e7140e1
Added an autogenerate primary key, submit save contributions on executor
ashishkumar468 Feb 24, 2020
2714df2
fixed getItemAtPosition
ashishkumar468 Feb 24, 2020
9d99527
MainActivity Config changes +=orientation
ashishkumar468 Feb 25, 2020
52c086f
BugFixes
ashishkumar468 Mar 4, 2020
adaa33c
Remove un-nescessary null check on contributions in ContributionsList…
ashishkumar468 Mar 4, 2020
c347200
removed ContributionsListFragment [not-implemeted]
ashishkumar468 Mar 4, 2020
adb6d70
Review suggested changes
ashishkumar468 Mar 4, 2020
8e33730
wip
ashishkumar468 Mar 4, 2020
3d91895
delete existing contributions table (from the existing db) on upgrade
ashishkumar468 Mar 4, 2020
0d87140
remove un-nescessary null checks in test classes
ashishkumar468 Mar 4, 2020
3081989
shifted media to be a local variable in ReviewHelperTest
ashishkumar468 Mar 4, 2020
0c4c783
removed captured folder
ashishkumar468 Mar 4, 2020
2985b1c
Dispose composite disposables in UploadService
ashishkumar468 Mar 5, 2020
faf9f41
replaced size check with isEmpty ContributionsPresenter
ashishkumar468 Mar 5, 2020
48c998b
transform saveContributions to a Completable
ashishkumar468 Mar 5, 2020
5d484c1
Addressed comments in review
ashishkumar468 Mar 6, 2020
dc4d76a
Provide Gson to Converters from the CommonsApplicationComponent
ashishkumar468 Mar 9, 2020
7f1c82b
use static method instead of field instead of static field to provide…
ashishkumar468 Mar 9, 2020
1181a81
Modified gitignore to exclude captures/*
ashishkumar468 Mar 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ app/src/main/jniLibs
#Below removes all the HTML files related to OpenCV documentation. The documentation can be otherwise found at:
#https://docs.opencv.org/3.3.0/
/libraries/opencv/javadoc/
captures/*
7 changes: 7 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,14 @@ dependencies {

//swipe_layout
implementation 'com.daimajia.swipelayout:library:1.2.0@aar'

//Room
def room_version= '2.2.3'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

versions should be specified in gradle.properteries and be in CONSTANT_CASE

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not find any such thing in the developer docs, based on the project scope it could be in the project's build.gradle or app's build.gradle, can you share relevant doc links for the same

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am following the example of the project. I don't see any other dependency declared like this but I do see leakcanary, dagger, kotlin & butterknife declared in gradle.properties.

It also just so happens that gradle.properties is the best place to put them, particularly in a multi module project.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seannemann21 AFAIK, for multi-module projects, project-level build.gradle should be the place for such things

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, best practise advice is to configure your projects using a precompiled script or a plugin in your buildsrc folder. The best place to keep your version numbers is in gradle.properties, buildsrc is a bit annoying becuse any change in there cause a recompilation of the entire project.
Use buildsrc
Proper versioning and great library

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, well that would need pulling out other dependencies from project build.gradle and app build.gradle as well, right?, Should we not create a separate issue for the same and take it from there?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps, but I am reviewing this addition. If you define a version put it in gradle.properties with the rest of them, as is evidently project style.

implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version" // For Kotlin use kapt instead of annotationProcessor
implementation 'com.squareup.retrofit2:retrofit:2.7.1'
implementation "androidx.room:room-rxjava2:$room_version"
testImplementation "androidx.arch.core:core-testing:2.1.0"
}

android {
Expand Down
20 changes: 1 addition & 19 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
android:name=".contributions.MainActivity"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:configChanges="screenSize|keyboard" />
android:configChanges="screenSize|keyboard|orientation" />
<activity
android:name=".settings.SettingsActivity"
android:label="@string/title_activity_settings" />
Expand Down Expand Up @@ -150,18 +150,6 @@
android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
</service>
<service
android:name=".contributions.ContributionsSyncService"
android:exported="true"
android:process=":sync">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>

<meta-data
android:name="android.content.SyncAdapter"
android:resource="@xml/contributions_sync_adapter" />
</service>

<service
android:name="org.acra.sender.SenderService"
Expand All @@ -177,12 +165,6 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
<provider
android:name=".contributions.ContributionsContentProvider"
android:authorities="${applicationId}.contributions.contentprovider"
android:exported="false"
android:label="@string/provider_contributions"
android:syncable="true" />

<provider
android:name=".category.CategoryContentProvider"
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/java/fr/free/nrw/commons/CommonsApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.app.NotificationManager;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.Build;
import android.os.Process;
import android.util.Log;
Expand Down Expand Up @@ -44,8 +45,8 @@
import fr.free.nrw.commons.category.CategoryDao;
import fr.free.nrw.commons.concurrency.BackgroundPoolExceptionHandler;
import fr.free.nrw.commons.concurrency.ThreadPoolService;
import fr.free.nrw.commons.contributions.ContributionDao;
import fr.free.nrw.commons.data.DBOpenHelper;
import fr.free.nrw.commons.db.AppDatabase;
import fr.free.nrw.commons.di.ApplicationlessInjection;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.logging.FileLoggingTree;
Expand All @@ -60,6 +61,7 @@
import okhttp3.OkHttpClient;
import timber.log.Timber;

import static fr.free.nrw.commons.data.DBOpenHelper.CONTRIBUTIONS_TABLE;
import static org.acra.ReportField.ANDROID_VERSION;
import static org.acra.ReportField.APP_VERSION_CODE;
import static org.acra.ReportField.APP_VERSION_NAME;
Expand Down Expand Up @@ -126,6 +128,9 @@ public AppLanguageLookUpTable getLanguageLookUpTable() {
return languageLookUpTable;
}

@Inject
AppDatabase appDatabase;

/**
* Used to declare and initialize various components and dependencies
*/
Expand Down Expand Up @@ -306,11 +311,13 @@ private void updateAllDatabases() {
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();

CategoryDao.Table.onDelete(db);
ContributionDao.Table.onDelete(db);
dbOpenHelper.deleteTable(db,CONTRIBUTIONS_TABLE);//Delete the contributions table in the existing db on older versions
appDatabase.getContributionDao().deleteAll();
BookmarkPicturesDao.Table.onDelete(db);
BookmarkLocationsDao.Table.onDelete(db);
}


/**
* Interface used to get log-out events
*/
Expand Down
45 changes: 24 additions & 21 deletions app/src/main/java/fr/free/nrw/commons/Media.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.room.Entity;
import androidx.room.PrimaryKey;

import org.apache.commons.lang3.StringUtils;
import org.wikipedia.dataclient.mwapi.MwQueryPage;
Expand All @@ -26,6 +28,7 @@
import fr.free.nrw.commons.utils.CommonsDateUtil;
import fr.free.nrw.commons.utils.MediaDataExtractorUtil;

@Entity
public class Media implements Parcelable {

public static final Media EMPTY = new Media("");
Expand All @@ -42,25 +45,25 @@ public Media[] newArray(int i) {
};

// Primary metadata fields
protected Uri localUri;
private String thumbUrl;
protected String imageUrl;
protected String filename;
protected String description; // monolingual description on input...
protected String discussion;
protected long dataLength;
protected Date dateCreated;
protected @Nullable Date dateUploaded;
protected int width;
protected int height;
protected String license;
protected String licenseUrl;
protected String creator;
protected ArrayList<String> categories; // as loaded at runtime?
protected boolean requestedDeletion;
private Map<String, String> descriptions; // multilingual descriptions as loaded
private HashMap<String, Object> tags = new HashMap<>();
private @Nullable LatLng coordinates;
public Uri localUri;
public String thumbUrl;
public String imageUrl;
public String filename;
public String description; // monolingual description on input...
public String discussion;
long dataLength;
public Date dateCreated;
@Nullable public Date dateUploaded;
public int width;
public int height;
public String license;
public String licenseUrl;
public String creator;
public ArrayList<String> categories; // as loaded at runtime?
public boolean requestedDeletion;
public HashMap<String, String> descriptions; // multilingual descriptions as loaded
public HashMap<String, String> tags = new HashMap<>();
@Nullable public LatLng coordinates;

/**
* Provides local constructor
Expand Down Expand Up @@ -118,7 +121,7 @@ public Media(Parcel in) {
dateCreated = (Date) in.readSerializable();
dateUploaded = (Date) in.readSerializable();
creator = in.readString();
tags = (HashMap<String, Object>) in.readSerializable();
tags = (HashMap<String, String>) in.readSerializable();
width = in.readInt();
height = in.readInt();
license = in.readString();
Expand Down Expand Up @@ -218,7 +221,7 @@ public Object getTag(String key) {
* @param key Media key
* @param value Media value
*/
public void setTag(String key, Object value) {
public void setTag(String key, String value) {
tags.put(key, value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import androidx.annotation.NonNull;
import androidx.annotation.StringDef;
import androidx.room.Entity;
import androidx.room.PrimaryKey;

import org.apache.commons.lang3.StringUtils;

Expand All @@ -21,6 +23,7 @@

import static java.lang.annotation.RetentionPolicy.SOURCE;

@Entity(tableName = "contribution")
public class Contribution extends Media {

//{{According to Exif data|2009-01-09}}
Expand Down Expand Up @@ -54,17 +57,19 @@ public Contribution[] newArray(int i) {
public static final String SOURCE_CAMERA = "camera";
public static final String SOURCE_GALLERY = "gallery";
public static final String SOURCE_EXTERNAL = "external";

private Uri contentUri;
private String source;
private String editSummary;
private int state;
private long transferred;
private String decimalCoords;
private boolean isMultiple;
private String wikiDataEntityId;
private Uri contentProviderUri;
private String dateCreatedSource;
@PrimaryKey (autoGenerate = true)
@NonNull
public long _id;
public Uri contentUri;
public String source;
public String editSummary;
public int state;
public long transferred;
public String decimalCoords;
public boolean isMultiple;
public String wikiDataEntityId;
public Uri contentProviderUri;
public String dateCreatedSource;

public Contribution(Uri contentUri, String filename, Uri localUri, String imageUrl, Date dateCreated,
int state, long dataLength, Date dateUploaded, long transferred,
Expand Down
Loading