Merge branch 'master' into dependency-injection

This commit is contained in:
Paul Hawke 2017-09-29 22:32:00 -05:00
commit c2b21eb575
45 changed files with 219 additions and 74 deletions

View file

@ -10,6 +10,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
@ -25,6 +26,7 @@ import android.widget.Toast;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.drawee.view.SimpleDraweeView;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@ -61,9 +63,9 @@ import static fr.free.nrw.commons.upload.ExistingFileAsync.Result.NO_DUPLICATE;
* Activity for the title/desc screen after image is selected. Also starts processing image
* GPS coordinates or user location (if enabled in Settings) for category suggestions.
*/
public class ShareActivity
extends AuthenticatedActivity
implements SingleUploadFragment.OnUploadActionInitiated,
public class ShareActivity
extends AuthenticatedActivity
implements SingleUploadFragment.OnUploadActionInitiated,
OnCategoriesSaveHandler {
private static final int REQUEST_PERM_ON_CREATE_STORAGE = 1;
@ -129,7 +131,7 @@ public class ShareActivity
// and permission is not obtained.
return !FileUtils.isSelfOwned(getApplicationContext(), mediaUri)
&& (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED);
!= PackageManager.PERMISSION_GRANTED);
}
private void uploadBegins() {
@ -151,7 +153,7 @@ public class ShareActivity
}
private void showPostUpload() {
if(categorizationFragment == null) {
if (categorizationFragment == null) {
categorizationFragment = new CategorizationFragment();
}
getSupportFragmentManager().beginTransaction()
@ -161,7 +163,7 @@ public class ShareActivity
@Override
public void onCategoriesSave(List<String> categories) {
if(categories.size() > 0) {
if (categories.size() > 0) {
ModifierSequence categoriesSequence = new ModifierSequence(contribution.getContentUri());
categoriesSequence.queueModifier(new CategoryModifier(categories.toArray(new String[]{})));
@ -187,7 +189,7 @@ public class ShareActivity
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if(contribution != null) {
if (contribution != null) {
outState.putParcelable("contribution", contribution);
}
}
@ -195,7 +197,7 @@ public class ShareActivity
@Override
public void onBackPressed() {
super.onBackPressed();
if(categorizationFragment != null && categorizationFragment.isVisible()) {
if (categorizationFragment != null && categorizationFragment.isVisible()) {
EventLog.schema(CommonsApplication.EVENT_CATEGORIZATION_ATTEMPT, mwApi, prefs)
.param("username", sessionManager.getCurrentAccount().name)
.param("categories-count", categorizationFragment.getCurrentSelectedCount())
@ -232,7 +234,7 @@ public class ShareActivity
setContentView(R.layout.activity_share);
ButterKnife.bind(this);
initBack();
backgroundImageView = (SimpleDraweeView)findViewById(R.id.backgroundImage);
backgroundImageView = (SimpleDraweeView) findViewById(R.id.backgroundImage);
backgroundImageView.setHierarchy(GenericDraweeHierarchyBuilder
.newInstance(getResources())
.setPlaceholderImage(VectorDrawableCompat.create(getResources(),
@ -258,7 +260,7 @@ public class ShareActivity
backgroundImageView.setImageURI(mediaUri);
}
if (savedInstanceState != null) {
if (savedInstanceState != null) {
contribution = savedInstanceState.getParcelable("contribution");
}
@ -283,7 +285,7 @@ public class ShareActivity
if (useNewPermissions && (!storagePermitted || !locationPermitted)) {
if (!storagePermitted && !locationPermitted) {
String permissionRationales =
getResources().getString(R.string.storage_permission_rationale) + "\n"
getResources().getString(R.string.read_storage_permission_rationale) + "\n"
+ getResources().getString(R.string.location_permission_rationale);
snackbar = requestPermissionUsingSnackBar(
permissionRationales,
@ -296,7 +298,7 @@ public class ShareActivity
textView.setMaxLines(3);
} else if (!storagePermitted) {
requestPermissionUsingSnackBar(
getString(R.string.storage_permission_rationale),
getString(R.string.read_storage_permission_rationale),
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
REQUEST_PERM_ON_CREATE_STORAGE);
} else if (!locationPermitted) {
@ -311,7 +313,7 @@ public class ShareActivity
SingleUploadFragment shareView = (SingleUploadFragment) getSupportFragmentManager().findFragmentByTag("shareView");
categorizationFragment = (CategorizationFragment) getSupportFragmentManager().findFragmentByTag("categorization");
if(shareView == null && categorizationFragment == null) {
if (shareView == null && categorizationFragment == null) {
shareView = new SingleUploadFragment();
getSupportFragmentManager()
.beginTransaction()
@ -421,12 +423,25 @@ public class ShareActivity
// in older devices getPath() may fail depending on the source URI
// creating and using a copy of the file seems to work instead.
// TODO: there might be a more proper solution than this
String copyPath = getApplicationContext().getCacheDir().getAbsolutePath()
+ "/" + new Date().getTime() + ".jpg";
String copyPath = null;
try {
ParcelFileDescriptor descriptor
= getContentResolver().openFileDescriptor(mediaUri, "r");
if (descriptor != null) {
boolean useExtStorage = prefs.getBoolean("useExternalStorage", true);
if (useExtStorage) {
copyPath = Environment.getExternalStorageDirectory().toString()
+ "/CommonsApp/" + new Date().getTime() + ".jpg";
File newFile = new File(Environment.getExternalStorageDirectory().toString() + "/CommonsApp");
newFile.mkdir();
FileUtils.copy(
descriptor.getFileDescriptor(),
copyPath);
Timber.d("Filepath (copied): %s", copyPath);
return copyPath;
}
copyPath = getApplicationContext().getCacheDir().getAbsolutePath()
+ "/" + new Date().getTime() + ".jpg";
FileUtils.copy(
descriptor.getFileDescriptor(),
copyPath);
@ -443,6 +458,7 @@ public class ShareActivity
/**
* Gets coordinates for category suggestions, either from EXIF data or user location
*
* @param gpsEnabled if true use GPS
*/
private void getFileMetadata(boolean gpsEnabled) {
@ -478,7 +494,7 @@ public class ShareActivity
* Then initiates the calls to MediaWiki API through an instance of MwVolleyApi.
*/
public void useImageCoords() {
if(decimalCoords != null) {
if (decimalCoords != null) {
Timber.d("Decimal coords of image: %s", decimalCoords);
// Only set cache for this point if image has coords
@ -512,8 +528,7 @@ public class ShareActivity
try {
imageObj.unregisterLocationManager();
Timber.d("Unregistered locationManager");
}
catch (NullPointerException e) {
} catch (NullPointerException e) {
Timber.d("locationManager does not exist, not unregistered");
}
}
@ -528,7 +543,7 @@ public class ShareActivity
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
if(categorizationFragment!=null && categorizationFragment.isVisible()) {
if (categorizationFragment != null && categorizationFragment.isVisible()) {
categorizationFragment.showBackButtonDialog();
} else {
onBackPressed();