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 all 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 @@ -63,6 +63,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: 2 additions & 2 deletions app/src/main/java/fr/free/nrw/commons/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@

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 java.util.Locale;
import java.util.regex.Pattern;

import androidx.annotation.NonNull;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.core.content.ContextCompat;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.settings.Prefs;
import fr.free.nrw.commons.utils.ViewUtil;
import timber.log.Timber;

import static android.widget.Toast.LENGTH_SHORT;
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
Expand Up @@ -100,7 +100,7 @@ ContentValues toContentValues(Contribution contribution) {
cv.put(Table.COLUMN_UPLOADED, contribution.getDateUploaded().getTime());
}
cv.put(Table.COLUMN_LENGTH, contribution.getDataLength());
//This was always meant to store the date created..If somehow date created is not fetched while actually saving the contribution, lets save today's date
//This was always meant to store the date created..If somehow date created is not fetched while actually saving the contribution, lets saveValue today's date
cv.put(Table.COLUMN_TIMESTAMP, contribution.getDateCreated()==null?System.currentTimeMillis():contribution.getDateCreated().getTime());
cv.put(Table.COLUMN_STATE, contribution.getState());
cv.put(Table.COLUMN_TRANSFERRED, contribution.getTransferred());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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.widget.PicOfDayAppWidget;


Expand All @@ -27,7 +28,7 @@
ActivityBuilderModule.class,
FragmentBuilderModule.class,
ServiceBuilderModule.class,
ContentProviderBuilderModule.class
ContentProviderBuilderModule.class, UploadModule.class
})
public interface CommonsApplicationComponent extends AndroidInjector<ApplicationlessInjection> {
void inject(CommonsApplication application);
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 @@ -18,6 +18,9 @@
import fr.free.nrw.commons.nearby.NearbyMapFragment;
import fr.free.nrw.commons.review.ReviewImageFragment;
import fr.free.nrw.commons.settings.SettingsFragment;
import fr.free.nrw.commons.upload.categories.UploadCategoriesFragment;
import fr.free.nrw.commons.upload.license.MediaLicenseFragment;
import fr.free.nrw.commons.upload.mediaDetails.UploadMediaDetailFragment;

@Module
@SuppressWarnings({"WeakerAccess", "unused"})
Expand Down Expand Up @@ -71,4 +74,12 @@ public abstract class FragmentBuilderModule {
@ContributesAndroidInjector
abstract ReviewImageFragment bindReviewOutOfContextFragment();

@ContributesAndroidInjector
abstract UploadMediaDetailFragment bindUploadMediaDetailFragment();

@ContributesAndroidInjector
abstract UploadCategoriesFragment bindUploadCategoriesFragment();

@ContributesAndroidInjector
abstract MediaLicenseFragment bindMediaLicenseFragment();
}
11 changes: 0 additions & 11 deletions app/src/main/java/fr/free/nrw/commons/explore/SearchActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
import com.google.android.material.tabs.TabLayout;
import com.jakewharton.rxbinding2.view.RxView;
import com.jakewharton.rxbinding2.widget.RxSearchView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.jakewharton.rxbinding2.view.RxView;
import com.jakewharton.rxbinding2.widget.RxSearchView;
import fr.free.nrw.commons.Media;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.explore.categories.SearchCategoryFragment;
Expand All @@ -33,13 +29,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import io.reactivex.disposables.Disposable;
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 @@ -56,9 +56,6 @@
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import org.apache.commons.lang3.StringUtils;
import org.wikipedia.util.DateUtil;
import org.wikipedia.util.StringUtil;
import timber.log.Timber;

import static android.view.View.GONE;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package fr.free.nrw.commons.repository;

import androidx.annotation.Nullable;
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;

/**
* The Local Data Source for UploadRepository, fetches and returns data from local db/shared prefernces
*/

@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;
}


/**
* Fetches and returns the string list of valid licenses
*
* @return
*/
public List<String> getLicenses() {
return uploadModel.getLicenses();
}

/**
* Returns the number of Upload Items
*
* @return
*/
public int getCount() {
return uploadModel.getCount();
}

/**
* Fetches and return the selected license for the current upload
*
* @return
*/
public String getSelectedLicense() {
return uploadModel.getSelectedLicense();
}

/**
* Set selected license for the current upload
*
* @param licenseName
*/
public void setSelectedLicense(String licenseName) {
uploadModel.setSelectedLicense(licenseName);
}

/**
* Updates the current upload item
*
* @param index
* @param uploadItem
*/
public void updateUploadItem(int index, UploadItem uploadItem) {
uploadModel.updateUploadItem(index, uploadItem);
}

/**
* upload is halted, cleanup the acquired resources
*/
public void cleanUp() {
uploadModel.cleanUp();
}

/**
* Deletes the upload item at the current index
*
* @param filePath
*/
public void deletePicture(String filePath) {
uploadModel.deletePicture(filePath);
}

/**
* Fethces and returns the previous upload item, if any, returns null otherwise
*
* @param index
* @return
*/
@Nullable
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) {
return uploadModel.getItems().get(index - 1);
}
return null; //There is no previous item to copy details
}

/**
* saves boolean value in default store
*
* @param key
* @param value
*/
public void saveValue(String key, boolean value) {
defaultKVStore.putBoolean(key, value);
}

/**
* saves string value in default store
*
* @param key
* @param value
*/
public void saveValue(String key, String value) {
defaultKVStore.putString(key, value);
}

/**
* Fetches and returns string value from the default store
*
* @param key
* @param defaultValue
* @return
*/
public String getValue(String key, String defaultValue) {
return defaultKVStore.getString(key, defaultValue);
}

/**
* Fetches and returns boolean value from the default store
*
* @param key
* @param defaultValue
* @return
*/
public boolean getValue(String key, boolean defaultValue) {
return defaultKVStore.getBoolean(key, defaultValue);
}
}
Loading