Fixed crash when uploading image via share without login

This commit is contained in:
Shridhar Goel 2018-06-28 16:10:36 +05:30
parent 7adf79c07d
commit e7270783e4
2 changed files with 36 additions and 20 deletions

View file

@ -64,6 +64,7 @@ import javax.inject.Named;
import butterknife.ButterKnife;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.auth.AuthenticatedActivity;
import fr.free.nrw.commons.auth.LoginActivity;
import fr.free.nrw.commons.auth.SessionManager;
import fr.free.nrw.commons.caching.CacheController;
import fr.free.nrw.commons.category.CategorizationFragment;
@ -152,23 +153,33 @@ public class ShareActivity
/**
* Called when user taps the submit button.
*/
@Override
public void uploadActionInitiated(String title, String description) {
this.title = title;
this.description = description;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Check for Storage permission that is required for upload.
// Do not allow user to proceed without permission, otherwise will crash
if (needsToRequestStoragePermission()) {
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
REQUEST_PERM_ON_SUBMIT_STORAGE);
if(sessionManager.getCurrentAccount()!=null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Check for Storage permission that is required for upload.
// Do not allow user to proceed without permission, otherwise will crash
if (needsToRequestStoragePermission()) {
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
REQUEST_PERM_ON_SUBMIT_STORAGE);
} else {
uploadBegins();
}
} else {
uploadBegins();
}
} else {
uploadBegins();
}
else //Send user to login activity
{
Toast.makeText(this, "You need to login first!", Toast.LENGTH_SHORT).show();
Intent loginIntent=new Intent(ShareActivity.this, LoginActivity.class);
startActivity(loginIntent);
}
}
@ -182,6 +193,7 @@ public class ShareActivity
!= PackageManager.PERMISSION_GRANTED);
}
private void uploadBegins() {
getFileMetadata(locationPermitted);
@ -194,12 +206,14 @@ public class ShareActivity
Timber.d("Cache the categories found");
}
uploadController.startUpload(title, mediaUri, description, mimeType, source, decimalCoords, c -> {
ShareActivity.this.contribution = c;
showPostUpload();
});
uploadController.startUpload(title, mediaUri, description, mimeType, source, decimalCoords, c -> {
ShareActivity.this.contribution = c;
showPostUpload();
});
}
private void showPostUpload() {
if (categorizationFragment == null) {
categorizationFragment = new CategorizationFragment();

View file

@ -22,6 +22,7 @@ import java.util.concurrent.Executors;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.HandlerService;
import fr.free.nrw.commons.auth.LoginActivity;
import fr.free.nrw.commons.auth.SessionManager;
import fr.free.nrw.commons.contributions.Contribution;
import fr.free.nrw.commons.settings.Prefs;
@ -94,16 +95,17 @@ public class UploadController {
public void startUpload(String title, Uri mediaUri, String description, String mimeType, String source, String decimalCoords, ContributionUploadProgress onComplete) {
Contribution contribution;
//TODO: Modify this to include coords
contribution = new Contribution(mediaUri, null, title, description, -1,
null, null, sessionManager.getCurrentAccount().name,
CommonsApplication.DEFAULT_EDIT_SUMMARY, decimalCoords);
//TODO: Modify this to include coords
contribution = new Contribution(mediaUri, null, title, description, -1,
null, null, sessionManager.getCurrentAccount().name,
CommonsApplication.DEFAULT_EDIT_SUMMARY, decimalCoords);
contribution.setTag("mimeType", mimeType);
contribution.setSource(source);
contribution.setTag("mimeType", mimeType);
contribution.setSource(source);
//Calls the next overloaded method
startUpload(contribution, onComplete);
//Calls the next overloaded method
startUpload(contribution, onComplete);
}
/**