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,12 +153,14 @@ 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(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
@ -172,6 +175,14 @@ public class ShareActivity
}
}
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);
}
}
@RequiresApi(16)
private boolean needsToRequestStoragePermission() {
// We need to ask storage permission when
@ -182,6 +193,7 @@ public class ShareActivity
!= PackageManager.PERMISSION_GRANTED);
}
private void uploadBegins() {
getFileMetadata(locationPermitted);
@ -198,8 +210,10 @@ public class ShareActivity
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;
@ -104,6 +105,7 @@ public class UploadController {
//Calls the next overloaded method
startUpload(contribution, onComplete);
}
/**