Skip to content

Commit

Permalink
Merge pull request #13548 from wordpress-mobile/fix/remote-video-copy
Browse files Browse the repository at this point in the history
WP Stories: changed flow for remote media from WP site to be copied locally
  • Loading branch information
aforcier authored Dec 4, 2020
2 parents d5f9e63 + 8b2c56c commit 41d7e74
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,7 @@ private void doMediaIdsSelected(ArrayList<Long> mediaIds, @NonNull PhotoPickerMe
if (mediaIds != null && mediaIds.size() > 0) {
if (mBrowserType == MediaBrowserType.WP_STORIES_MEDIA_PICKER) {
// TODO WPSTORIES add TRACKS (see how it's tracked below? maybe do along the same lines)
Intent data = new Intent()
.putExtra(MediaBrowserActivity.RESULT_IDS, ListUtils.toLongArray(mediaIds))
.putExtra(ARG_BROWSER_TYPE, mBrowserType)
.putExtra(MediaPickerConstants.EXTRA_MEDIA_SOURCE, source.name());
setResult(RESULT_OK, data);
finish();
getPickerFragment().mediaIdsSelectedFromWPMediaPicker(mediaIds);
} else {
// if user chose a featured image, track image picked event
if (mBrowserType == MediaBrowserType.FEATURED_IMAGE_PICKER) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,10 @@ class PhotoPickerFragment : Fragment() {
viewModel.urisSelectedFromSystemPicker(uris.map { UriWrapper(it) })
}

fun mediaIdsSelectedFromWPMediaPicker(mediaIds: List<Long>) {
viewModel.mediaIdsSelectedFromWPMediaPicker(mediaIds)
}

companion object {
private const val KEY_LAST_TAPPED_ICON = "last_tapped_icon"
private const val KEY_SELECTED_POSITIONS = "selected_positions"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.wordpress.android.ui.photopicker

import android.Manifest.permission
import android.net.Uri
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import kotlinx.coroutines.CoroutineDispatcher
Expand Down Expand Up @@ -41,6 +42,7 @@ import org.wordpress.android.ui.photopicker.PhotoPickerViewModel.BottomBarUiMode
import org.wordpress.android.ui.photopicker.PhotoPickerViewModel.BottomBarUiModel.BottomBar.NONE
import org.wordpress.android.ui.photopicker.PhotoPickerViewModel.PopupMenuUiModel.PopupMenuItem
import org.wordpress.android.ui.posts.editor.media.CopyMediaToAppStorageUseCase
import org.wordpress.android.ui.posts.editor.media.GetMediaModelUseCase
import org.wordpress.android.ui.utils.UiString
import org.wordpress.android.ui.utils.UiString.UiStringRes
import org.wordpress.android.ui.utils.UiString.UiStringText
Expand Down Expand Up @@ -75,7 +77,8 @@ class PhotoPickerViewModel @Inject constructor(
private val permissionsHandler: PermissionsHandler,
private val tenorFeatureConfig: TenorFeatureConfig,
private val resourceProvider: ResourceProvider,
private val copyMediaToAppStorageUseCase: CopyMediaToAppStorageUseCase
private val copyMediaToAppStorageUseCase: CopyMediaToAppStorageUseCase,
private val getMediaModelUseCase: GetMediaModelUseCase
) : ScopedViewModel(mainDispatcher) {
private val _navigateToPreview = MutableLiveData<Event<UriWrapper>>()
private val _onInsert = MutableLiveData<Event<List<UriWrapper>>>()
Expand Down Expand Up @@ -478,6 +481,18 @@ class PhotoPickerViewModel @Inject constructor(
}

fun urisSelectedFromSystemPicker(uris: List<UriWrapper>) {
copySelectedUrisLocally(uris)
}

fun mediaIdsSelectedFromWPMediaPicker(mediaIds: List<Long>) {
launch {
val mediaModels = getMediaModelUseCase
.loadMediaByRemoteId(requireNotNull(site), mediaIds)
copySelectedUrisLocally(mediaModels.map { UriWrapper(Uri.parse(it.url)) })
}
}

fun copySelectedUrisLocally(uris: List<UriWrapper>) {
launch {
_showProgressDialog.value = ProgressDialogUiModel.Visible(R.string.uploading_title) {
_showProgressDialog.postValue(ProgressDialogUiModel.Hidden)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.wordpress.android.ui.photopicker.PhotoPickerViewModel.PhotoListUiMode
import org.wordpress.android.ui.photopicker.PhotoPickerViewModel.PhotoPickerUiState
import org.wordpress.android.ui.photopicker.PhotoPickerViewModel.SoftAskViewUiModel
import org.wordpress.android.ui.posts.editor.media.CopyMediaToAppStorageUseCase
import org.wordpress.android.ui.posts.editor.media.GetMediaModelUseCase
import org.wordpress.android.ui.utils.UiString
import org.wordpress.android.ui.utils.UiString.UiStringRes
import org.wordpress.android.ui.utils.UiString.UiStringText
Expand All @@ -50,6 +51,7 @@ class PhotoPickerViewModelTest : BaseUnitTest() {
@Mock lateinit var context: Context
@Mock lateinit var resourceProvider: ResourceProvider
@Mock lateinit var copyMediaToAppStorageUseCase: CopyMediaToAppStorageUseCase
@Mock lateinit var getMediaModelUseCase: GetMediaModelUseCase
private lateinit var viewModel: PhotoPickerViewModel
private var uiStates = mutableListOf<PhotoPickerUiState>()
private var navigateEvents = mutableListOf<Event<UriWrapper>>()
Expand All @@ -71,7 +73,8 @@ class PhotoPickerViewModelTest : BaseUnitTest() {
permissionsHandler,
tenorFeatureConfig,
resourceProvider,
copyMediaToAppStorageUseCase
copyMediaToAppStorageUseCase,
getMediaModelUseCase
)
uiStates.clear()
firstItem = PhotoPickerItem(1, uriWrapper1, false)
Expand Down

0 comments on commit 41d7e74

Please sign in to comment.