Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
9dfcaa5
Create utility class for contribution process
neslihanturan Jun 16, 2018
41c239e
implement method to save five from given URİ
neslihanturan Jun 16, 2018
78128be
Add file utilities for directory checks
neslihanturan Jun 16, 2018
31a95d9
Add ContributionUtils for saving file during upload
neslihanturan Jun 16, 2018
e33a714
Change method call acordingly with handleImagePicked() method
neslihanturan Jun 23, 2018
6652abf
Call method to save file temproarily when a photo to upload is chosen…
neslihanturan Jun 23, 2018
fd84760
Call method to save file temproarily when a photo to upload is chosen…
neslihanturan Jun 23, 2018
44440bb
Arrange method call
neslihanturan Jun 23, 2018
fcb7628
Write a method to save file temporarily during upload process. It wil…
neslihanturan Jun 23, 2018
b2c71da
Add a method to save a file to a given path from a content provider Uri
neslihanturan Jun 23, 2018
84bbf2a
On openAssetFileDescriptor method, use URi from temporarily saved fil…
neslihanturan Jun 23, 2018
c714161
Edit uploadContribution method so that it will use FileInputStream fr…
neslihanturan Jun 23, 2018
1c00113
Make it work
neslihanturan Jun 23, 2018
8adcdf6
Code cleanup
neslihanturan Jun 23, 2018
07ed936
Add directory cleaner method
neslihanturan Jun 23, 2018
d63b784
Call temp directory cleaner method at the end of uplpoad process
neslihanturan Jun 23, 2018
d28d307
Use FileInputStream insted
neslihanturan Jun 23, 2018
9c2cb08
Add directory cleaner method
neslihanturan Jun 23, 2018
9a812d1
Add file removal method
neslihanturan Jun 26, 2018
cff1a3c
Use external directory instead
neslihanturan Jun 27, 2018
de3b732
Make destination file name flexible
neslihanturan Jun 27, 2018
c6deb5c
Make it work with share action coming from another activity
neslihanturan Jun 27, 2018
1261136
Make it work for Multiple hare Activity
neslihanturan Jun 27, 2018
af8bd73
Code cleanup
neslihanturan Jun 27, 2018
dcb2f43
Solve camera issue
neslihanturan Jul 1, 2018
2f64bb2
Fix camera crash
neslihanturan Jul 7, 2018
53ffa6e
Cleanup
neslihanturan Jul 7, 2018
bff29e5
Revert change of commenting out posibly useles code, because I am not…
neslihanturan Jul 12, 2018
8e1e94a
Use timestamp in temoorary file names, so that we wont never create s…
neslihanturan Jul 12, 2018
c9b772a
Code cleanup
neslihanturan Jul 12, 2018
b4a8594
Add nullable annotation to handleImagePicked method uri parameter
neslihanturan Jul 12, 2018
e0692b9
Add Nullable anotation to method
neslihanturan Jul 12, 2018
67747d3
Code cleanup
neslihanturan Jul 12, 2018
93365df
Bugfix: use uri.getPath() instead uri.toString
neslihanturan Jul 12, 2018
ec8aac9
Remove unecesarry file saving operation, which was added accidentally
neslihanturan Jul 12, 2018
c4e41e5
Fix travis fail
neslihanturan Jul 12, 2018
03c1b2f
Remove temp file if upload gets failed and file is still there
neslihanturan Jul 13, 2018
74fe7f9
Code cleanup:Remove unused parameters from removeTempFile method
neslihanturan Jul 13, 2018
019a0fa
Empty temp directory on app create, in case some of files are still t…
neslihanturan Jul 13, 2018
e5ae5d3
Add null check to array to prevent NPE on first run
neslihanturan Jul 16, 2018
b6b0f9b
Fix multiple uploads bug
neslihanturan Jul 16, 2018
f804d25
Remove file if upload is succeed
neslihanturan Jul 16, 2018
94054bc
Add external storage utility methods
neslihanturan Jul 23, 2018
8cd5754
Check external file permission before saving files temporarily
neslihanturan Jul 23, 2018
aabdf8a
finish activity if permission is not granted
neslihanturan Jul 23, 2018
21dbc02
Add log lines
neslihanturan Jul 23, 2018
ad4feaa
Remove files even if user decides to go back without sharing
neslihanturan Jul 23, 2018
f3fd7a4
Add easy null check
neslihanturan Jul 23, 2018
6d8c73f
Change storage permission settings in singe upload fragment too
neslihanturan Jul 24, 2018
456401f
Finish app if permission is not granted
neslihanturan Jul 24, 2018
8f0b687
Code optimisation
neslihanturan Jul 24, 2018
2ed23d0
Remove temp file if upload process never is finalised on activity stop
neslihanturan Jul 26, 2018
ec192c5
Bugfix maybe contribution is never created
neslihanturan Jul 26, 2018
fe69194
Fix conflicts
neslihanturan Jul 28, 2018
44d4e49
Fix travis build
neslihanturan Jul 28, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import fr.free.nrw.commons.di.ApplicationlessInjection;
import fr.free.nrw.commons.modifications.ModifierSequenceDao;
import fr.free.nrw.commons.upload.FileUtils;
import fr.free.nrw.commons.utils.ContributionUtils;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import timber.log.Timber;
Expand Down Expand Up @@ -68,7 +69,6 @@ public class CommonsApplication extends MultiDexApplication {
@Override
public void onCreate() {
super.onCreate();

ApplicationlessInjection
.getInstance(this)
.getCommonsApplicationComponent()
Expand All @@ -81,6 +81,8 @@ public void onCreate() {
if (setupLeakCanary() == RefWatcher.DISABLED) {
return;
}
// Empty temp directory in case some temp files are created and never removed.
ContributionUtils.emptyTemporaryDirectory();

Timber.plant(new Timber.DebugTree());

Expand Down
14 changes: 4 additions & 10 deletions app/src/main/java/fr/free/nrw/commons/MediaWikiImageView.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,10 @@ public void setMedia(Media media) {
return;
}

if(media.getFilename() != null) {
if (thumbnailUrlCache.get(media.getFilename()) != null) {
setImageUrl(thumbnailUrlCache.get(media.getFilename()));
} else {
setImageUrl(null);
currentThumbnailTask = new ThumbnailFetchTask(media, mwApi);
currentThumbnailTask.execute(media.getFilename());
}
} else { // local image
setImageUrl(media.getLocalUri().toString());
if (media.getFilename() != null && thumbnailUrlCache.get(media.getFilename()) != null) {
setImageUrl(thumbnailUrlCache.get(media.getFilename()));
} else {
setImageUrl(null);
currentThumbnailTask = new ThumbnailFetchTask(media, mwApi);
currentThumbnailTask.execute(media.getFilename());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public Contribution[] newArray(int i) {
private String decimalCoords;
private boolean isMultiple;
private String wikiDataEntityId;
private Uri contentProviderUri;

public Contribution(Uri contentUri, String filename, Uri localUri, String imageUrl, Date timestamp,
int state, long dataLength, Date dateUploaded, long transferred,
Expand Down Expand Up @@ -236,4 +237,12 @@ public String getWikiDataEntityId() {
public void setWikiDataEntityId(String wikiDataEntityId) {
this.wikiDataEntityId = wikiDataEntityId;
}

public void setContentProviderUri(Uri contentProviderUri) {
this.contentProviderUri = contentProviderUri;
}

public Uri getContentProviderUri() {
return contentProviderUri;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.FileProvider;
import android.util.Log;

import java.io.File;
import java.util.Date;
Expand All @@ -28,8 +30,8 @@

public class ContributionController {

private static final int SELECT_FROM_GALLERY = 1;
private static final int SELECT_FROM_CAMERA = 2;
public static final int SELECT_FROM_GALLERY = 1;
public static final int SELECT_FROM_CAMERA = 2;

private Fragment fragment;

Expand Down Expand Up @@ -91,16 +93,15 @@ public void startGalleryPick() {
fragment.startActivityForResult(pickImageIntent, SELECT_FROM_GALLERY);
}

public void handleImagePicked(int requestCode, Intent data, boolean isDirectUpload, String wikiDataEntityId) {
Timber.d("Is direct upload %s and the Wikidata entity ID is %s", isDirectUpload, wikiDataEntityId);
public void handleImagePicked(int requestCode, @Nullable Uri uri, boolean isDirectUpload, String wikiDataEntityId) {
FragmentActivity activity = fragment.getActivity();
Timber.d("handleImagePicked() called with onActivityResult()");
Intent shareIntent = new Intent(activity, ShareActivity.class);
shareIntent.setAction(ACTION_SEND);
switch (requestCode) {
case SELECT_FROM_GALLERY:
//Handles image picked from gallery
Uri imageData = data.getData();
Uri imageData = uri;
shareIntent.setType(activity.getContentResolver().getType(imageData));
shareIntent.putExtra(EXTRA_STREAM, imageData);
shareIntent.putExtra(EXTRA_SOURCE, SOURCE_GALLERY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import fr.free.nrw.commons.quiz.QuizChecker;
import fr.free.nrw.commons.settings.Prefs;
import fr.free.nrw.commons.upload.UploadService;
import fr.free.nrw.commons.utils.ContributionUtils;
import fr.free.nrw.commons.utils.ViewUtil;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
Expand Down Expand Up @@ -199,6 +200,9 @@ public void deleteUpload(int i) {
Contribution c = contributionDao.fromCursor(allContributions);
if (c.getState() == STATE_FAILED) {
Timber.d("Deleting failed contrib %s", c.toString());
// If upload fails and then user decides to cancel upload at all, which means contribution
// object will be deleted. So we have to delete temp file for that contribution.
ContributionUtils.removeTemporaryFile(c.getLocalUri());
contributionDao.delete(c);
} else {
Timber.d("Skipping deletion for non-failed contrib %s", c.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
Expand All @@ -31,6 +33,7 @@
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
import fr.free.nrw.commons.nearby.NearbyActivity;
import fr.free.nrw.commons.utils.ContributionUtils;
import timber.log.Timber;

import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
Expand Down Expand Up @@ -117,7 +120,13 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Timber.d("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
requestCode, resultCode, data);
controller.handleImagePicked(requestCode, data, false, null);
if (requestCode == ContributionController.SELECT_FROM_CAMERA) {
// If coming from camera, pass null as uri. Because camera photos get saved to a
// fixed directory
controller.handleImagePicked(requestCode, null, false, null);
} else {
controller.handleImagePicked(requestCode, data.getData(), false, null);
}
} else {
Timber.e("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
requestCode, resultCode, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
import fr.free.nrw.commons.wikidata.WikidataEditListenerImpl;

import static android.content.Context.MODE_PRIVATE;
import static fr.free.nrw.commons.contributions.ContributionsContentProvider.CONTRIBUTION_AUTHORITY;
import static fr.free.nrw.commons.explore.recentsearches.RecentSearchesContentProvider.RECENT_SEARCH_AUTHORITY;
import static fr.free.nrw.commons.modifications.ModificationsContentProvider.MODIFICATIONS_AUTHORITY;

@Module
@SuppressWarnings({"WeakerAccess", "unused"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand Down Expand Up @@ -51,6 +52,7 @@
import fr.free.nrw.commons.category.QueryContinue;
import fr.free.nrw.commons.notification.Notification;
import fr.free.nrw.commons.notification.NotificationUtils;
import fr.free.nrw.commons.utils.ContributionUtils;
import in.yuvi.http.fluent.Http;
import io.reactivex.Observable;
import io.reactivex.Single;
Expand Down Expand Up @@ -856,25 +858,30 @@ public UploadResult uploadFile(String filename,
long dataLength,
String pageContents,
String editSummary,
final ProgressListener progressListener) throws IOException {
final ProgressListener progressListener,
Uri fileUri,
Uri contentProviderUri) throws IOException {

ApiResult result = api.upload(filename, file, dataLength, pageContents, editSummary, progressListener::onProgress);

Log.e("WTF", "Result: " + result.toString());

String resultStatus = result.getString("/api/upload/@result");

if (!resultStatus.equals("Success")) {
String errorCode = result.getString("/api/error/@code");
Timber.e(errorCode);
return new UploadResult(resultStatus, errorCode);
} else {
// If success we have to remove file from temp directory
ContributionUtils.removeTemporaryFile(fileUri);
Date dateUploaded = parseMWDate(result.getString("/api/upload/imageinfo/@timestamp"));
String canonicalFilename = "File:" + result.getString("/api/upload/@filename").replace("_", " "); // Title vs Filename
String imageUrl = result.getString("/api/upload/imageinfo/@url");
return new UploadResult(resultStatus, dateUploaded, canonicalFilename, imageUrl);
}
}


@Override
@NonNull
public Single<Integer> getUploadCount(String userName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.free.nrw.commons.mwapi;

import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

Expand Down Expand Up @@ -54,7 +55,7 @@ public interface MediaWikiApi {
List<String> searchCategory(String title, int offset);

@NonNull
UploadResult uploadFile(String filename, InputStream file, long dataLength, String pageContents, String editSummary, ProgressListener progressListener) throws IOException;
UploadResult uploadFile(String filename, InputStream file, long dataLength, String pageContents, String editSummary, ProgressListener progressListener, Uri fileUri, Uri contentProviderUri) throws IOException;

@Nullable
String edit(String editToken, String processedPageContent, String filename, String summary) throws IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.contributions.ContributionController;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.utils.ContributionUtils;
import fr.free.nrw.commons.utils.UriDeserializer;
import timber.log.Timber;

Expand Down Expand Up @@ -147,7 +148,13 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Timber.d("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
requestCode, resultCode, data);
controller.handleImagePicked(requestCode, data, true, directPrefs.getString(WIKIDATA_ENTITY_ID_PREF, null));
if (requestCode == ContributionController.SELECT_FROM_CAMERA) {
// If coming from camera, pass null as uri. Because camera photos get saved to a
// fixed directory
controller.handleImagePicked(requestCode, null, true, null);
} else {
controller.handleImagePicked(requestCode, data.getData(), true, null);
}
} else {
Timber.e("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
requestCode, resultCode, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.Utils;
import fr.free.nrw.commons.contributions.ContributionController;
import fr.free.nrw.commons.utils.ContributionUtils;
import fr.free.nrw.commons.utils.UriDeserializer;
import fr.free.nrw.commons.utils.ViewUtil;
import timber.log.Timber;
Expand Down Expand Up @@ -765,10 +766,17 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);


if (resultCode == RESULT_OK) {
Timber.d("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
requestCode, resultCode, data);
controller.handleImagePicked(requestCode, data, true, directPrefs.getString(WIKIDATA_ENTITY_ID_PREF, null));
if (requestCode == ContributionController.SELECT_FROM_CAMERA) {
// If coming from camera, pass null as uri. Because camera photos get saved to a
// fixed directory
controller.handleImagePicked(requestCode, null, true, null);
} else {
controller.handleImagePicked(requestCode, data.getData(), true, null);
}
} else {
Timber.e("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
requestCode, resultCode, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;

import java.io.BufferedReader;
import java.io.File;
Expand Down
Loading