Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

remove long click download action #2882

Merged
merged 4 commits into from
Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Improvements:
- Kotlin Code Improvement in VectorSettingsPreferencesFragment.kt
- Remove redundant !! , Replace it with null safe operators in VectorSettingsPreferencesFragment.kt
- `Redact` has been renamed to `Remove` to match riot/web (#2871)
- Remove long click download action in MediaViewer (#2882)


Other changes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import im.vector.Matrix;
import im.vector.R;
import im.vector.VectorApp;
import im.vector.adapters.VectorMediasViewerAdapter;
import im.vector.adapters.VectorMediaViewerAdapter;
import im.vector.db.VectorContentProvider;
import im.vector.util.PermissionsToolsKt;
import im.vector.util.SlidableMediaInfo;
Expand All @@ -68,7 +68,7 @@ public class VectorMediaViewerActivity extends MXCActionBarActivity {
private ViewPager mViewPager;

// the pager adapter
private VectorMediasViewerAdapter mAdapter;
private VectorMediaViewerAdapter mAdapter;

// the medias list
private List<SlidableMediaInfo> mMediasList;
Expand Down Expand Up @@ -162,7 +162,7 @@ public void initUiAndData() {
int maxImageWidth = intent.getIntExtra(KEY_THUMBNAIL_WIDTH, 0);
int maxImageHeight = intent.getIntExtra(VectorMediaViewerActivity.KEY_THUMBNAIL_HEIGHT, 0);

mAdapter = new VectorMediasViewerAdapter(this, mSession, mSession.getMediaCache(), mMediasList, maxImageWidth, maxImageHeight);
mAdapter = new VectorMediaViewerAdapter(this, mSession, mSession.getMediaCache(), mMediasList, maxImageWidth, maxImageHeight);
mViewPager.setAdapter(mAdapter);
mViewPager.setPageTransformer(true, new DepthPageTransformer());
mAdapter.autoPlayItemAt(position);
Expand Down Expand Up @@ -338,9 +338,6 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
if (requestCode == PermissionsToolsKt.PERMISSION_REQUEST_CODE) {
// Request comes from here
onAction(mPendingPosition, mPendingAction);
} else if (requestCode == PermissionsToolsKt.PERMISSION_REQUEST_OTHER) {
// Request comes from adapter
mAdapter.downloadMediaAndExportToDownloads();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
package im.vector.adapters;

import android.content.Context;
import android.content.DialogInterface;
import android.media.MediaPlayer;
import android.net.Uri;
import android.support.v4.view.PagerAdapter;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -53,17 +51,14 @@
import java.util.List;

import im.vector.R;
import im.vector.activity.CommonActivityUtils;
import im.vector.activity.VectorMediaViewerActivity;
import im.vector.util.PermissionsToolsKt;
import im.vector.util.SlidableMediaInfo;
import im.vector.view.PieFractionView;

/**
* An images slider
*/
public class VectorMediasViewerAdapter extends PagerAdapter {
private static final String LOG_TAG = VectorMediasViewerAdapter.class.getSimpleName();
public class VectorMediaViewerAdapter extends PagerAdapter {
private static final String LOG_TAG = VectorMediaViewerAdapter.class.getSimpleName();

private final Context mContext;

Expand All @@ -89,12 +84,12 @@ public class VectorMediasViewerAdapter extends PagerAdapter {

private int mAutoPlayItemAt = -1;

public VectorMediasViewerAdapter(Context context,
MXSession session,
MXMediaCache mediasCache,
List<SlidableMediaInfo> mediaMessagesList,
int maxImageWidth,
int maxImageHeight) {
public VectorMediaViewerAdapter(Context context,
MXSession session,
MXMediaCache mediasCache,
List<SlidableMediaInfo> mediaMessagesList,
int maxImageWidth,
int maxImageHeight) {
mContext = context;
mSession = session;
mMediasCache = mediasCache;
Expand Down Expand Up @@ -407,22 +402,6 @@ public Object instantiateItem(final ViewGroup container, final int position) {
final View videoLayout = view.findViewById(R.id.media_slider_video_layout);
final ImageView thumbView = view.findViewById(R.id.media_slider_video_thumbnail);

imageView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
onLongClickOnMedia();
return true;
}
});

thumbView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
onLongClickOnMedia();
return true;
}
});

final SlidableMediaInfo mediaInfo = mMediasMessagesList.get(position);
String mediaUrl = mediaInfo.mMediaUrl;

Expand Down Expand Up @@ -604,90 +583,6 @@ private void playVideo(View pageView, VideoView videoView, File videoFile, Strin
}
}

/**
* Download the current media file, and export it to the Download folder of the device
*/
public void downloadMediaAndExportToDownloads() {
if (((VectorMediaViewerActivity) mContext).checkWritePermission(PermissionsToolsKt.PERMISSION_REQUEST_OTHER)) {
final SlidableMediaInfo mediaInfo = mMediasMessagesList.get(mLatestPrimaryItemPosition);

if (mMediasCache.isMediaCached(mediaInfo.mMediaUrl, mediaInfo.mMimeType)) {
mMediasCache.createTmpDecryptedMediaFile(mediaInfo.mMediaUrl, mediaInfo.mMimeType, mediaInfo.mEncryptedFileInfo, new SimpleApiCallback<File>() {
@Override
public void onSuccess(File file) {
if (null != file) {
CommonActivityUtils.saveMediaIntoDownloads(mContext, file, null, mediaInfo.mMimeType, new SimpleApiCallback<String>() {
@Override
public void onSuccess(String path) {
Toast.makeText(mContext, R.string.media_slider_saved, Toast.LENGTH_LONG).show();
}
});
}
}
});
} else {
downloadVideo(mLatestPrimaryView, mLatestPrimaryItemPosition, true);
final String downloadId = mMediasCache.downloadMedia(mContext,
mSession.getHomeServerConfig(),
mediaInfo.mMediaUrl,
mediaInfo.mMimeType,
mediaInfo.mEncryptedFileInfo);

if (null != downloadId) {
mMediasCache.addDownloadListener(downloadId, new MXMediaDownloadListener() {
@Override
public void onDownloadError(String downloadId, JsonElement jsonElement) {
MatrixError error = JsonUtils.toMatrixError(jsonElement);

if ((null != error) && error.isSupportedErrorCode()) {
Toast.makeText(mContext, error.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
}

@Override
public void onDownloadComplete(String aDownloadId) {
if (aDownloadId.equals(downloadId)) {
if (mMediasCache.isMediaCached(mediaInfo.mMediaUrl, mediaInfo.mMimeType)) {
mMediasCache.createTmpDecryptedMediaFile(mediaInfo.mMediaUrl, mediaInfo.mMimeType, mediaInfo.mEncryptedFileInfo,
new SimpleApiCallback<File>() {
@Override
public void onSuccess(File file) {
if (null != file) {
CommonActivityUtils.saveMediaIntoDownloads(mContext, file, null, mediaInfo.mMimeType,
new SimpleApiCallback<String>() {
@Override
public void onSuccess(String path) {
Toast.makeText(mContext, R.string.media_slider_saved, Toast.LENGTH_LONG).show();
}
});
}
}
});
}
}
}
});
}
}
}
}

/**
* Long click management: propose user to save media to the Downloads folder of the device
*/
private void onLongClickOnMedia() {
new AlertDialog.Builder(mContext)
.setMessage(R.string.media_slider_saved_message)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
downloadMediaAndExportToDownloads();
}
})
.setNegativeButton(R.string.no, null)
.show();
}

/**
* Load the video items
*
Expand Down
1 change: 0 additions & 1 deletion vector/src/main/java/im/vector/util/PermissionsTools.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ const val PERMISSION_REQUEST_CODE_AUDIO_CALL = 571
const val PERMISSION_REQUEST_CODE_VIDEO_CALL = 572
const val PERMISSION_REQUEST_CODE_EXPORT_KEYS = 573
const val PERMISSION_REQUEST_CODE_CHANGE_AVATAR = 574
const val PERMISSION_REQUEST_OTHER = 600

/**
* Log the used permissions statuses.
Expand Down