Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ dependencies {
//Room
def room_version= '2.2.3'
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-ktx:$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"
Expand Down
9 changes: 1 addition & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,7 @@
android:authorities="${applicationId}.categories.contentprovider"
android:exported="false"
android:label="@string/provider_categories"
android:syncable="false" />

<provider
android:authorities="${applicationId}.depicts.contentprovider"
android:name=".upload.structure.depictions.DepictsContentProvider"
android:exported="false"
android:label="@string/provider_depictions"
android:syncable="false"/>
android:syncable="false" />

<provider
android:name=".explore.recentsearches.RecentSearchesContentProvider"
Expand Down
13 changes: 3 additions & 10 deletions app/src/main/java/fr/free/nrw/commons/CommonsApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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 All @@ -16,10 +15,7 @@
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.imagepipeline.core.ImagePipeline;
import com.facebook.imagepipeline.core.ImagePipelineConfig;
import com.facebook.imagepipeline.producers.Consumer;
import com.facebook.imagepipeline.producers.FetchState;
import com.facebook.imagepipeline.producers.NetworkFetcher;
import com.facebook.imagepipeline.producers.ProducerContext;
import com.mapbox.mapboxsdk.Mapbox;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;
Expand All @@ -45,15 +41,14 @@
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;
import fr.free.nrw.commons.logging.LogUtils;
import fr.free.nrw.commons.settings.Prefs;
import fr.free.nrw.commons.upload.FileUtils;
import fr.free.nrw.commons.upload.structure.depictions.DepictionDao;
import fr.free.nrw.commons.utils.ConfigUtils;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.internal.functions.Functions;
Expand Down Expand Up @@ -129,8 +124,7 @@ public AppLanguageLookUpTable getLanguageLookUpTable() {
return languageLookUpTable;
}

@Inject
AppDatabase appDatabase;
@Inject ContributionDao contributionDao;

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

CategoryDao.Table.onDelete(db);
DepictionDao.Table.onDelete(db);
dbOpenHelper.deleteTable(db,CONTRIBUTIONS_TABLE);//Delete the contributions table in the existing db on older versions
appDatabase.getContributionDao().deleteAll();
contributionDao.deleteAll();
BookmarkPicturesDao.Table.onDelete(db);
BookmarkLocationsDao.Table.onDelete(db);
}
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/java/fr/free/nrw/commons/data/DBOpenHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesDao;
import fr.free.nrw.commons.category.CategoryDao;
import fr.free.nrw.commons.explore.recentsearches.RecentSearchesDao;
import fr.free.nrw.commons.upload.structure.depictions.DepictionDao;

public class DBOpenHelper extends SQLiteOpenHelper {

Expand All @@ -29,7 +28,6 @@ public DBOpenHelper(Context context) {
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
CategoryDao.Table.onCreate(sqLiteDatabase);
DepictionDao.Table.onCreate(sqLiteDatabase);
BookmarkPicturesDao.Table.onCreate(sqLiteDatabase);
BookmarkLocationsDao.Table.onCreate(sqLiteDatabase);
RecentSearchesDao.Table.onCreate(sqLiteDatabase);
Expand All @@ -38,7 +36,6 @@ public void onCreate(SQLiteDatabase sqLiteDatabase) {
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int from, int to) {
CategoryDao.Table.onUpdate(sqLiteDatabase, from, to);
DepictionDao.Table.onUpdate(sqLiteDatabase, from, to);
BookmarkPicturesDao.Table.onUpdate(sqLiteDatabase, from, to);
BookmarkLocationsDao.Table.onUpdate(sqLiteDatabase, from, to);
RecentSearchesDao.Table.onUpdate(sqLiteDatabase, from, to);
Expand Down
14 changes: 0 additions & 14 deletions app/src/main/java/fr/free/nrw/commons/db/AppDatabase.java

This file was deleted.

17 changes: 17 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/db/AppDatabase.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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

Copy link
Contributor

Choose a reason for hiding this comment

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

Add java docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do I add javadocs to classes I didn't make? I just converted the file

Copy link
Member

Choose a reason for hiding this comment

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

It would be helpful towards our goal of having docs for all classes (although the person who originally had created the file should indeed have written it, I guess she missed this one).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@misaochan kdoc added

/**
* The database for accessing the respective DAOs
*
*/
@Database(entities = [Contribution::class], version = 1, exportSchema = false)
@TypeConverters(Converters::class)
abstract class AppDatabase : RoomDatabase() {
abstract fun contributionDao(): ContributionDao
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public class CommonsApplicationModule {
private Context applicationContext;
public static final String IO_THREAD="io_thread";
public static final String MAIN_THREAD="main_thread";
private AppDatabase appDatabase;

public CommonsApplicationModule(Context applicationContext) {
this.applicationContext = applicationContext;
Expand Down Expand Up @@ -247,12 +246,11 @@ public QuadTree providesQuadTres() {
@Provides
@Singleton
public AppDatabase provideAppDataBase() {
appDatabase=Room.databaseBuilder(applicationContext, AppDatabase.class, "commons_room.db").build();
return appDatabase;
return Room.databaseBuilder(applicationContext, AppDatabase.class, "commons_room.db").build();
}

@Provides
public ContributionDao providesContributionsDao() {
return appDatabase.getContributionDao();
public ContributionDao providesContributionsDao(AppDatabase appDatabase) {
return appDatabase.contributionDao();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,25 @@
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesContentProvider;
import fr.free.nrw.commons.category.CategoryContentProvider;
import fr.free.nrw.commons.explore.recentsearches.RecentSearchesContentProvider;
import fr.free.nrw.commons.upload.structure.depictions.DepictsContentProvider;

/**
* This Class Represents the Module for dependency injection (using dagger)
* so, if a developer needs to add a new ContentProvider to the commons app
* then that must be mentioned here to inject the dependencies
* then that must be mentioned here to inject the dependencies
*/
@Module
@SuppressWarnings({"WeakerAccess", "unused"})
@SuppressWarnings({ "WeakerAccess", "unused" })
public abstract class ContentProviderBuilderModule {

@ContributesAndroidInjector
abstract CategoryContentProvider bindCategoryContentProvider();
@ContributesAndroidInjector
abstract CategoryContentProvider bindCategoryContentProvider();

@ContributesAndroidInjector
abstract DepictsContentProvider bindDepictsContentProvider();
@ContributesAndroidInjector
abstract RecentSearchesContentProvider bindRecentSearchesContentProvider();

@ContributesAndroidInjector
abstract RecentSearchesContentProvider bindRecentSearchesContentProvider();

@ContributesAndroidInjector
abstract BookmarkPicturesContentProvider bindBookmarkContentProvider();

@ContributesAndroidInjector
abstract BookmarkLocationsContentProvider bindBookmarkLocationContentProvider();
@ContributesAndroidInjector
abstract BookmarkPicturesContentProvider bindBookmarkContentProvider();

@ContributesAndroidInjector
abstract BookmarkLocationsContentProvider bindBookmarkLocationContentProvider();
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Observable<DepictedItem> searchForDepictions(String query, int limit, int
String.valueOf(offset)
)
.flatMap(depictSearchResponse ->Observable.fromIterable(depictSearchResponse.getSearch()))
.map(depictSearchItem -> new DepictedItem(depictSearchItem.getLabel(), depictSearchItem.getDescription(), "", false, depictSearchItem.getId()));
.map(DepictedItem::new);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import fr.free.nrw.commons.upload.UploadModel.UploadItem;
import fr.free.nrw.commons.upload.structure.depictions.DepictModel;
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem;
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem;
import io.reactivex.Observable;
import io.reactivex.Single;

Expand Down Expand Up @@ -230,8 +229,8 @@ public List<DepictedItem> getSelectedDepictions() {
* get all depictions
*/

public Observable<DepictedItem> searchAllEntities(String query, List<String> imageTitleList) {
return depictModel.searchAllEntities(query, imageTitleList);
public Observable<DepictedItem> searchAllEntities(String query) {
return depictModel.searchAllEntities(query);
}

public void setSelectedDepictions(List<String> selectedDepictions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,11 @@ public List<DepictedItem> getSelectedDepictions() {
* Search all depictions from
*
* @param query
* @param imageTitleList
* @return
*/

public Observable<DepictedItem> searchAllEntities(String query, List<String> imageTitleList) {
return remoteDataSource.searchAllEntities(query, imageTitleList);
public Observable<DepictedItem> searchAllEntities(String query) {
return remoteDataSource.searchAllEntities(query);
}

public List<String> getDepictionsEntityIdList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import static fr.free.nrw.commons.di.CommonsApplicationModule.IO_THREAD;
import static fr.free.nrw.commons.di.CommonsApplicationModule.MAIN_THREAD;

import android.util.Log;

import fr.free.nrw.commons.explore.depictions.DepictsClient;
import fr.free.nrw.commons.repository.UploadRepository;
import fr.free.nrw.commons.upload.UploadModel;
Expand Down Expand Up @@ -85,7 +83,6 @@ public void onDepictItemClicked(DepictedItem depictedItem) {
@Override
public void searchForDepictions(String query) {
List<DepictedItem> depictedItemList = new ArrayList<>();
List<String> imageTitleList = getImageTitleList();
Observable<DepictedItem> distinctDepictsObservable = Observable
.fromIterable(repository.getSelectedDepictions())
.subscribeOn(ioScheduler)
Expand All @@ -97,27 +94,22 @@ public void searchForDepictions(String query) {
})
.observeOn(ioScheduler)
.concatWith(
repository.searchAllEntities(query, imageTitleList)
repository.searchAllEntities(query)
)
.distinct();

Disposable searchDepictsDisposable = distinctDepictsObservable
.observeOn(mainThreadScheduler)
.subscribe(
s -> depictedItemList.add(s),
depictedItemList::add,
Timber::e,
() -> {
view.showProgress(false);

if (null == depictedItemList || depictedItemList.isEmpty()) {
if (depictedItemList.isEmpty()) {
view.showError(true);
} else {
view.showError(false);
//Understand this is shitty, but yes, doing it the other way is even worse and adapter positions can not be trusted
for (int position = 0; position < depictedItemList.size();
position++) {
//depictedItemList.get(position).setPosition(position);
}
view.setDepictsList(depictedItemList);
}
}
Expand Down Expand Up @@ -156,18 +148,4 @@ public void fetchThumbnailForEntityId(String entityId, int position) {
view.onImageUrlFetched(response,position);
}));
}

/**
* Returns image title list from UploadItem
* @return
*/
private List<String> getImageTitleList() {
List<String> titleList = new ArrayList<>();
for (UploadModel.UploadItem item : repository.getUploads()) {
if (item.getTitle().isSet()) {
titleList.add(item.getTitle().toString());
}
}
return titleList;
}
}
Loading