Skip to content
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

Feature/refractor uploads [WIP] #2887

Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3684710
Fix duplicate param information (#2515)
maskaravivek Feb 25, 2019
e90049b
Bug fix issue #2476 (#2526)
ashishkumar468 Feb 27, 2019
cf1faf4
Versioning and changelog for v2.10.2 (#2531)
misaochan Feb 28, 2019
27683a7
Bugfix/issue 2580 (#2584)
ashishkumar468 Mar 15, 2019
468f0b7
Bug Fix #2585 (#2647)
ashishkumar468 Mar 18, 2019
fbf7cd5
Bug Fix issue #2648 (#2678)
ashishkumar468 Mar 20, 2019
01f6c99
BugFix issue #2652 (#2706)
ashishkumar468 Mar 22, 2019
963072e
BugFix issue #2711 (#2712)
ashishkumar468 Mar 22, 2019
6ea1c81
BugFix #2718 (#2719)
ashishkumar468 Mar 23, 2019
5fdb6fc
Fix #2791: NPE when nominating for deletion and leaving screen (#2792)
ashishkumar468 Mar 30, 2019
314ebd8
Bug Fix issue #2789 (#2790)
ashishkumar468 Apr 1, 2019
03e3d05
BugFix #2720 (#2831)
ashishkumar468 Apr 2, 2019
70a715d
ui fixes, wip, upload
ashishkumar468 Apr 15, 2019
ad8ca71
*Issue #2886, BugFix #2832[wip]
ashishkumar468 Apr 16, 2019
fe80c12
* updated interfaces names to follow names suffixed with Contract
ashishkumar468 Apr 17, 2019
b5c4210
card view elevation
ashishkumar468 Apr 17, 2019
87d7b0d
view pager disabled swipe
ashishkumar468 Apr 17, 2019
22ce2e2
bug fix, duplicate image
ashishkumar468 Apr 17, 2019
7718cd8
used existing non-swipable view pager
ashishkumar468 Apr 22, 2019
3177162
Avoid image view resize with keyboard, added adjustPan and stateVisib…
ashishkumar468 Apr 22, 2019
e648119
retain UploadBaseFragment instances on orientation changes
ashishkumar468 Apr 22, 2019
cbafd76
* Added test cases for UploadMediaPresenter
ashishkumar468 Apr 22, 2019
0a10178
categories presenter test cased wip
ashishkumar468 Apr 23, 2019
70ee5ee
Added CategoriesPresenter test
ashishkumar468 Apr 24, 2019
07870a5
* Added the logic to show open map (with to be uploaded image's coord…
ashishkumar468 May 5, 2019
00819a4
codacy suggested changes * added java docs
ashishkumar468 May 5, 2019
a40a1c3
Added travis_wait fot android-wait-for-emulator
ashishkumar468 May 6, 2019
3485d3e
Synced with master
ashishkumar468 May 6, 2019
2f5c83f
ranamed interface onResponseCallback to Callback
ashishkumar468 May 6, 2019
51943a3
* Added api to delete picture in UploadModel
ashishkumar468 May 7, 2019
de9d681
* Added tests for UploadPresenter
ashishkumar468 May 8, 2019
72b0f5e
* Made the upload add descriptions visible when keyboard visible
ashishkumar468 May 8, 2019
c2e294a
Added JavaDocs, review suggested changes
ashishkumar468 May 9, 2019
697948c
Merge branch 'master' into feature/refractor_uploads
ashishkumar468 May 10, 2019
bf9d180
Fix dagger injection
maskaravivek May 10, 2019
020938b
Merge pull request #1 from maskaravivek/uploadDagger
ashishkumar468 May 10, 2019
24f8c46
use DialogUtil to show info in descriptions
ashishkumar468 May 10, 2019
8ef415a
Merge branch 'feature/refractor_uploads' of https://github.com/ashish…
ashishkumar468 May 10, 2019
7121ccf
use activity context for DialogUtil
ashishkumar468 May 10, 2019
f893b8f
Minor changes
maskaravivek May 10, 2019
59bac5b
Merge pull request #2 from maskaravivek/minorChanges
ashishkumar468 May 10, 2019
3286816
resolved merge conflicts with master
ashishkumar468 May 24, 2019
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
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ dependencies {
testImplementation 'org.robolectric:robolectric:3.7.1'
testImplementation 'com.nhaarman:mockito-kotlin:1.5.0'
testImplementation 'com.squareup.okhttp3:mockwebserver:3.10.0'
testImplementation "org.powermock:powermock-module-junit4:2.0.0-beta.5"
testImplementation "org.powermock:powermock-api-mockito2:2.0.0-beta.5"

// Android testing
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$KOTLIN_VERSION"
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@
</activity>
<activity android:name=".WelcomeActivity" />

<activity android:name=".upload.UploadActivity"
<activity
android:name=".upload.UploadActivity"
android:configChanges="orientation|screenSize|keyboard"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:configChanges="orientation|screenSize|keyboard">
android:windowSoftInputMode="adjustResize"
>
<intent-filter android:label="@string/intent_share_upload_label">
<action android:name="android.intent.action.SEND" />

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/fr/free/nrw/commons/BasePresenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
/**
* Base presenter, enforcing contracts to atach and detach view
*/
public interface BasePresenter {
public interface BasePresenter<T> {
/**
* Until a view is attached, it is open to listen events from the presenter
*/
void onAttachView(MvpView view);
void onAttachView(T view);

/**
* Detaching a view makes sure that the view no more receives events from the presenter
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

import org.wikipedia.dataclient.WikiSite;
import org.wikipedia.page.PageTitle;
import fr.free.nrw.commons.location.LatLng;
Copy link
Member

Choose a reason for hiding this comment

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

Unused imports?

import fr.free.nrw.commons.utils.ViewUtil;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;

import java.util.Locale;
import java.util.regex.Pattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* success and error
*/
@Singleton
public class CampaignsPresenter implements BasePresenter {
public class CampaignsPresenter implements BasePresenter<ICampaignsView> {
private final OkHttpJsonApiClient okHttpJsonApiClient;

private ICampaignsView view;
Expand All @@ -40,8 +40,9 @@ public CampaignsPresenter(OkHttpJsonApiClient okHttpJsonApiClient) {
this.okHttpJsonApiClient = okHttpJsonApiClient;
}

@Override public void onAttachView(MvpView view) {
this.view = (ICampaignsView) view;
@Override
public void onAttachView(ICampaignsView view) {
this.view=view;
}

@Override public void onDetachView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import io.reactivex.Observable;
import timber.log.Timber;

public class CategoriesModel implements CategoryClickedListener {
public class CategoriesModel{
private static final int SEARCH_CATS_LIMIT = 25;

private final MediaWikiApi mwApi;
Expand Down Expand Up @@ -186,8 +186,7 @@ private Observable<CategoryItem> recentCategories() {
//endregion

//region Category Selection
@Override
public void categoryClicked(CategoryItem item) {
public void onCategoryItemClicked(CategoryItem item) {
if (item.isSelected()) {
selectCategory(item);
updateCategoryCount(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public CategoryItem[] newArray(int i) {
}
};

CategoryItem(String name, boolean selected) {
public CategoryItem(String name, boolean selected) {
this.name = name;
this.selected = selected;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package fr.free.nrw.commons.di;

import javax.inject.Singleton;

import dagger.Component;
import dagger.android.AndroidInjectionModule;
import dagger.android.AndroidInjector;
Expand All @@ -15,7 +13,12 @@
import fr.free.nrw.commons.review.ReviewController;
import fr.free.nrw.commons.settings.SettingsFragment;
import fr.free.nrw.commons.upload.FileProcessor;
import fr.free.nrw.commons.upload.UploadModule;
import fr.free.nrw.commons.upload.categories.UploadCategoriesFragment;
import fr.free.nrw.commons.upload.license.MediaLicenseFragment;
import fr.free.nrw.commons.upload.mediaDetails.UploadMediaDetailFragment;
import fr.free.nrw.commons.widget.PicOfDayAppWidget;
import javax.inject.Singleton;


@Singleton
Expand All @@ -27,7 +30,7 @@
ActivityBuilderModule.class,
FragmentBuilderModule.class,
ServiceBuilderModule.class,
ContentProviderBuilderModule.class
ContentProviderBuilderModule.class, UploadModule.class
})
public interface CommonsApplicationComponent extends AndroidInjector<ApplicationlessInjection> {
void inject(CommonsApplication application);
Expand All @@ -51,6 +54,12 @@ public interface CommonsApplicationComponent extends AndroidInjector<Application

void inject(PicOfDayAppWidget picOfDayAppWidget);

void inject(UploadCategoriesFragment uploadCategoriesFragment);
Copy link
Member

Choose a reason for hiding this comment

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

No need to declare inject method for fragment classes. If the fragment extends CommonsDaggerSupportFragment then, the injection can be used directly.

Copy link
Member

Choose a reason for hiding this comment

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

No need to define the fragments here. Add them in FragmentBuilderModule


void inject(MediaLicenseFragment mediaLicenseFragment);

void inject(UploadMediaDetailFragment uploadMediaDetailFragment);

void inject(ContributionViewHolder viewHolder);

@Component.Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import com.google.gson.Gson;

import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -36,6 +39,8 @@
@SuppressWarnings({"WeakerAccess", "unused"})
public class CommonsApplicationModule {
private Context applicationContext;
public static final String IO_THREAD="io_thread";
public static final String MAIN_THREAD="main_thread";

public CommonsApplicationModule(Context applicationContext) {
this.applicationContext = applicationContext;
Expand Down Expand Up @@ -171,4 +176,16 @@ public WikidataEditListener provideWikidataEditListener() {
public boolean provideIsBetaVariant() {
return ConfigUtils.isBetaFlavour();
}

@Named(IO_THREAD)
@Provides
public Scheduler providesIoThread(){
return Schedulers.io();
}

@Named(MAIN_THREAD)
@Provides
public Scheduler providesMainThread(){
return AndroidSchedulers.mainThread();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import io.reactivex.disposables.Disposable;
Copy link
Member

Choose a reason for hiding this comment

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

Unused?

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
* Represents search screen of this app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
import org.apache.commons.lang3.StringUtils;
import org.wikipedia.util.DateUtil;
import org.wikipedia.util.StringUtil;
import java.io.IOException;
Copy link
Member

Choose a reason for hiding this comment

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

Unused?

import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;
import javax.inject.Inject;
import javax.inject.Provider;
import timber.log.Timber;

import static android.view.View.GONE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@
import fr.free.nrw.commons.utils.NetworkUtils;
import fr.free.nrw.commons.utils.PermissionUtils;
import fr.free.nrw.commons.utils.ViewUtil;
import javax.inject.Inject;
Copy link
Member

Choose a reason for hiding this comment

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

Unused?

import javax.inject.Named;
import timber.log.Timber;

import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
import static android.content.Context.DOWNLOAD_SERVICE;
import static fr.free.nrw.commons.Utils.handleWebUrl;
import static android.content.Intent.ACTION_VIEW;
import static android.widget.Toast.LENGTH_SHORT;

public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment implements ViewPager.OnPageChangeListener {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package fr.free.nrw.commons.repository;

import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.upload.UploadModel;
import fr.free.nrw.commons.upload.UploadModel.UploadItem;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

@Singleton
public class UploadLocalDataSource {
Copy link
Member

Choose a reason for hiding this comment

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

Add java docs. For class and methods


private final UploadModel uploadModel;
private JsonKvStore defaultKVStore;

@Inject
public UploadLocalDataSource(
@Named("default_preferences") JsonKvStore defaultKVStore,
UploadModel uploadModel) {
this.defaultKVStore = defaultKVStore;
this.uploadModel = uploadModel;
}


public List<String> getLicenses() {
return uploadModel.getLicenses();
}

public String getFromDefaultKvStore(String key, String defaultValue) {
return defaultKVStore.getString(key, defaultValue);
}

public void saveInDefaultKvStore(String key, String value) {
defaultKVStore.putString(key, value);
}

public int getCount() {
return uploadModel.getCount();
}

public String getSelectedLicense() {
return uploadModel.getSelectedLicense();
}

public void setSelectedLicense(String licenseName) {
uploadModel.setSelectedLicense(licenseName);
}

public void updateUploadItem(int index, UploadItem uploadItem) {
uploadModel.updateUploadItem(index, uploadItem);
}

public void saveInDirectKvStore(String key, boolean value) {
defaultKVStore.putBoolean(key, value);
}

public void cleanUp() {
uploadModel.cleanUp();
}

public void deletePicture(String filePath) {
uploadModel.deletePicture(filePath);
}

public UploadItem getPreviousUploadItem(int index) {
Copy link
Member

Choose a reason for hiding this comment

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

Annotate as Nullable

if(index-1>=0){
Copy link
Member

Choose a reason for hiding this comment

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

Fix formatting. There are formatting issues at other places too. Please check once.

return uploadModel.getItems().get(index-1);
}
return null; //There is no previous item to copy details
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package fr.free.nrw.commons.repository;

import fr.free.nrw.commons.category.CategoriesModel;
import fr.free.nrw.commons.category.CategoryItem;
import fr.free.nrw.commons.contributions.Contribution;
import fr.free.nrw.commons.filepicker.UploadableFile;
import fr.free.nrw.commons.nearby.Place;
import fr.free.nrw.commons.upload.SimilarImageInterface;
import fr.free.nrw.commons.upload.UploadController;
import fr.free.nrw.commons.upload.UploadModel;
import fr.free.nrw.commons.upload.UploadModel.UploadItem;
import io.reactivex.Observable;
import io.reactivex.Single;
import java.util.Comparator;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
public class UploadRemoteDataSource {
Copy link
Member

Choose a reason for hiding this comment

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

Add java docs


private UploadModel uploadModel;
private UploadController uploadController;
private CategoriesModel categoriesModel;

@Inject
public UploadRemoteDataSource(UploadModel uploadModel, UploadController uploadController,
CategoriesModel categoriesModel) {
this.uploadModel = uploadModel;
this.uploadController = uploadController;
this.categoriesModel = categoriesModel;
}

public Observable<Contribution> buildContributions() {
return uploadModel.buildContributions();
}

public void startUpload(Contribution contribution) {
uploadController.startUpload(contribution);
}

public List<UploadItem> getUploads() {
return uploadModel.getUploads();
}

public void prepareService() {
uploadController.prepareService();
}

public void cleanup() {
uploadController.cleanup();
}

public List<CategoryItem> getSelectedCategories() {
return categoriesModel.getSelectedCategories();
}

public Observable<CategoryItem> searchAll(String query, List<String> imageTitleList) {
return categoriesModel.searchAll(query, imageTitleList);
}

public Observable<CategoryItem> searchCategories(String query, List<String> imageTitleList) {
return categoriesModel.searchCategories(query, imageTitleList);
}

public Observable<CategoryItem> defaultCategories(List<String> imageTitleList) {
return categoriesModel.defaultCategories(imageTitleList);
}

public List<String> getCategoryStringList() {
return categoriesModel.getCategoryStringList();
}

public void setSelectedCategories(List<String> categoryStringList) {
uploadModel.setSelectedCategories(categoryStringList);
}

public void onCategoryClicked(CategoryItem categoryItem) {
categoriesModel.onCategoryItemClicked(categoryItem);
}

public Comparator<CategoryItem> sortBySimilarity(String query) {
return categoriesModel.sortBySimilarity(query);
}

public boolean containsYear(String name) {
return categoriesModel.containsYear(name);
}

public Observable<UploadItem> preProcessImage(UploadableFile uploadableFile, Place place,
String source, SimilarImageInterface similarImageInterface) {
return uploadModel.preProcessImage(uploadableFile,place,source,similarImageInterface);
}

public Single<Integer> getImageQuality(UploadItem uploadItem, boolean shouldValidateTitle) {
return uploadModel.getImageQuality(uploadItem,shouldValidateTitle);
}
}
Loading