Merge pull request #1825 from nextcloud/setPictureAs

"set picture as" with resized images
This commit is contained in:
Mario Đanić 2017-12-11 22:21:40 +01:00 committed by GitHub
commit 3c45e99ca1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 36 deletions

View file

@ -1449,9 +1449,6 @@ public class FileDisplayActivity extends HookActivity
case OCFileListFragment.DOWNLOAD_SEND:
sendDownloadedFile();
break;
case OCFileListFragment.DOWNLOAD_SET_AS:
setPictureAs();
break;
default:
// do nothing
break;
@ -1609,7 +1606,7 @@ public class FileDisplayActivity extends HookActivity
mUploaderBinder = null;
}
}
};
}
private MediaServiceConnection newMediaConnection(){
return new MediaServiceConnection();
@ -1639,7 +1636,7 @@ public class FileDisplayActivity extends HookActivity
mMediaServiceBinder = null;
}
}
};
}
/**
* Updates the view associated to the activity after the finish of some operation over files
@ -1986,12 +1983,6 @@ public class FileDisplayActivity extends HookActivity
mWaitingToSend = null;
}
private void setPictureAs() {
getFileOperationsHelper().setPictureAs(mWaitingToSend);
mWaitingToSend = null;
}
/**
* Requests the download of the received {@link OCFile} , updates the UI
* to monitor the download progress and prepares the activity to send the file

View file

@ -129,7 +129,6 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
public static final String DOWNLOAD_BEHAVIOUR = "DOWNLOAD_BEHAVIOUR";
public static final String DOWNLOAD_SEND = "DOWNLOAD_SEND";
public static final String DOWNLOAD_SET_AS = "DOWNLOAD_SET_AS";
public static final String SEARCH_EVENT = "SEARCH_EVENT";
@ -985,12 +984,7 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
}
}
case R.id.action_set_as_wallpaper: {
if (singleFile.isDown()) {
mContainerActivity.getFileOperationsHelper().setPictureAs(singleFile);
} else {
Log_OC.d(TAG, singleFile.getRemotePath() + " : File must be downloaded");
((FileDisplayActivity) mContainerActivity).startDownloadForSending(singleFile, DOWNLOAD_SET_AS);
}
mContainerActivity.getFileOperationsHelper().setPictureAs(singleFile, getView());
return true;
}
}

View file

@ -30,9 +30,10 @@ import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.content.FileProvider;
import android.view.View;
import android.webkit.MimeTypeMap;
import android.widget.Toast;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
@ -56,6 +57,7 @@ import com.owncloud.android.ui.events.FavoriteEvent;
import com.owncloud.android.ui.events.SyncEventFinished;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.UriUtils;
import org.greenrobot.eventbus.EventBus;
@ -580,32 +582,36 @@ public class FileOperationsHelper {
}
}
public void setPictureAs(OCFile file) {
public void setPictureAs(OCFile file, View view) {
if (file != null) {
if (file.isDown()) {
Context context = MainApp.getAppContext();
Context context = MainApp.getAppContext();
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
Uri uri;
try {
try {
if (file.isDown()) {
File externalFile = new File(file.getStoragePath());
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
Uri sendUri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
sendUri = FileProvider.getUriForFile(context,
uri = FileProvider.getUriForFile(context,
context.getResources().getString(R.string.file_provider_authority), externalFile);
} else {
sendUri = Uri.fromFile(externalFile);
uri = Uri.fromFile(externalFile);
}
intent.setDataAndType(sendUri, file.getMimetype());
intent.putExtra("mimeType", file.getMimetype());
mFileActivity.startActivityForResult(Intent.createChooser(intent,
mFileActivity.getString(R.string.set_as)), 200);
} catch (ActivityNotFoundException exception) {
Toast.makeText(context, R.string.picture_set_as_no_app, Toast.LENGTH_LONG).show();
} else {
uri = Uri.parse(UriUtils.URI_CONTENT_SCHEME +
context.getResources().getString(R.string.image_cache_provider_authority) +
file.getRemotePath());
}
intent.setDataAndType(uri, file.getMimetype());
mFileActivity.startActivityForResult(Intent.createChooser(intent,
mFileActivity.getString(R.string.set_as)), 200);
intent.setDataAndType(uri, file.getMimetype());
} catch (ActivityNotFoundException exception) {
Snackbar.make(view, R.string.picture_set_as_no_app, Snackbar.LENGTH_LONG).show();
}
} else {
Log_OC.wtf(TAG, "Trying to send a NULL OCFile");

View file

@ -452,7 +452,7 @@ public class PreviewImageFragment extends FileFragment {
return true;
case R.id.action_set_as_wallpaper:
mContainerActivity.getFileOperationsHelper().setPictureAs(getFile());
mContainerActivity.getFileOperationsHelper().setPictureAs(getFile(), getImageView());
return true;
default: