mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Fixed crash when uploading image via share without login
This commit is contained in:
parent
7adf79c07d
commit
e7270783e4
2 changed files with 36 additions and 20 deletions
|
|
@ -64,6 +64,7 @@ import javax.inject.Named;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.auth.AuthenticatedActivity;
|
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.auth.SessionManager;
|
||||||
import fr.free.nrw.commons.caching.CacheController;
|
import fr.free.nrw.commons.caching.CacheController;
|
||||||
import fr.free.nrw.commons.category.CategorizationFragment;
|
import fr.free.nrw.commons.category.CategorizationFragment;
|
||||||
|
|
@ -152,23 +153,33 @@ public class ShareActivity
|
||||||
/**
|
/**
|
||||||
* Called when user taps the submit button.
|
* Called when user taps the submit button.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void uploadActionInitiated(String title, String description) {
|
public void uploadActionInitiated(String title, String description) {
|
||||||
|
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if(sessionManager.getCurrentAccount()!=null) {
|
||||||
// Check for Storage permission that is required for upload.
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
// Do not allow user to proceed without permission, otherwise will crash
|
// Check for Storage permission that is required for upload.
|
||||||
if (needsToRequestStoragePermission()) {
|
// Do not allow user to proceed without permission, otherwise will crash
|
||||||
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
|
if (needsToRequestStoragePermission()) {
|
||||||
REQUEST_PERM_ON_SUBMIT_STORAGE);
|
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
|
||||||
|
REQUEST_PERM_ON_SUBMIT_STORAGE);
|
||||||
|
} else {
|
||||||
|
uploadBegins();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
uploadBegins();
|
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);
|
!= PackageManager.PERMISSION_GRANTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void uploadBegins() {
|
private void uploadBegins() {
|
||||||
getFileMetadata(locationPermitted);
|
getFileMetadata(locationPermitted);
|
||||||
|
|
||||||
|
|
@ -194,12 +206,14 @@ public class ShareActivity
|
||||||
Timber.d("Cache the categories found");
|
Timber.d("Cache the categories found");
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadController.startUpload(title, mediaUri, description, mimeType, source, decimalCoords, c -> {
|
uploadController.startUpload(title, mediaUri, description, mimeType, source, decimalCoords, c -> {
|
||||||
ShareActivity.this.contribution = c;
|
ShareActivity.this.contribution = c;
|
||||||
showPostUpload();
|
showPostUpload();
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void showPostUpload() {
|
private void showPostUpload() {
|
||||||
if (categorizationFragment == null) {
|
if (categorizationFragment == null) {
|
||||||
categorizationFragment = new CategorizationFragment();
|
categorizationFragment = new CategorizationFragment();
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import java.util.concurrent.Executors;
|
||||||
|
|
||||||
import fr.free.nrw.commons.CommonsApplication;
|
import fr.free.nrw.commons.CommonsApplication;
|
||||||
import fr.free.nrw.commons.HandlerService;
|
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.auth.SessionManager;
|
||||||
import fr.free.nrw.commons.contributions.Contribution;
|
import fr.free.nrw.commons.contributions.Contribution;
|
||||||
import fr.free.nrw.commons.settings.Prefs;
|
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) {
|
public void startUpload(String title, Uri mediaUri, String description, String mimeType, String source, String decimalCoords, ContributionUploadProgress onComplete) {
|
||||||
Contribution contribution;
|
Contribution contribution;
|
||||||
|
|
||||||
//TODO: Modify this to include coords
|
//TODO: Modify this to include coords
|
||||||
contribution = new Contribution(mediaUri, null, title, description, -1,
|
contribution = new Contribution(mediaUri, null, title, description, -1,
|
||||||
null, null, sessionManager.getCurrentAccount().name,
|
null, null, sessionManager.getCurrentAccount().name,
|
||||||
CommonsApplication.DEFAULT_EDIT_SUMMARY, decimalCoords);
|
CommonsApplication.DEFAULT_EDIT_SUMMARY, decimalCoords);
|
||||||
|
|
||||||
contribution.setTag("mimeType", mimeType);
|
contribution.setTag("mimeType", mimeType);
|
||||||
contribution.setSource(source);
|
contribution.setSource(source);
|
||||||
|
|
||||||
|
//Calls the next overloaded method
|
||||||
|
startUpload(contribution, onComplete);
|
||||||
|
|
||||||
//Calls the next overloaded method
|
|
||||||
startUpload(contribution, onComplete);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue