diff --git a/vector/src/main/java/im/vector/app/features/media/AttachmentOverlayView.kt b/vector/src/main/java/im/vector/app/features/media/AttachmentOverlayView.kt index 0b3407c5a4..58d10d2f2d 100644 --- a/vector/src/main/java/im/vector/app/features/media/AttachmentOverlayView.kt +++ b/vector/src/main/java/im/vector/app/features/media/AttachmentOverlayView.kt @@ -30,20 +30,12 @@ class AttachmentOverlayView @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 ) : ConstraintLayout(context, attrs, defStyleAttr), AttachmentEventListener { - /* ========================================================================================== - * Fields - * ========================================================================================== */ - var interactionListener: AttachmentInteractionListener? = null val views: MergeImageAttachmentOverlayBinding private var isPlaying = false private var suspendSeekBarUpdate = false - /* ========================================================================================== - * Init - * ========================================================================================== */ - init { inflate(context, R.layout.merge_image_attachment_overlay, this) views = MergeImageAttachmentOverlayBinding.bind(this) @@ -78,19 +70,11 @@ class AttachmentOverlayView @JvmOverloads constructor( }) } - /* ========================================================================================== - * Public API - * ========================================================================================== */ - fun updateWith(counter: String, senderInfo: String) { views.overlayCounterText.text = counter views.overlayInfoText.text = senderInfo } - /* ========================================================================================== - * Specialization - * ========================================================================================== */ - override fun onEvent(event: AttachmentEvents) { when (event) { is AttachmentEvents.VideoEvent -> { diff --git a/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerActivity.kt b/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerActivity.kt index 72089d0f39..d8c2b83f9b 100644 --- a/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerActivity.kt +++ b/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerActivity.kt @@ -59,10 +59,6 @@ import javax.inject.Inject @AndroidEntryPoint class VectorAttachmentViewerActivity : AttachmentViewerActivity(), AttachmentInteractionListener { - /* ========================================================================================== - * Arguments - * ========================================================================================== */ - @Parcelize data class Args( val roomId: String?, @@ -70,10 +66,6 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), AttachmentInt val sharedTransitionName: String? ) : Parcelable - /* ========================================================================================== - * Dependencies - * ========================================================================================== */ - @Inject lateinit var sessionHolder: ActiveSessionHolder @@ -83,10 +75,6 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), AttachmentInt @Inject lateinit var imageContentRenderer: ImageContentRenderer - /* ========================================================================================== - * Fields - * ========================================================================================== */ - private val viewModel: VectorAttachmentViewerViewModel by viewModel() private val errorFormatter by lazy(LazyThreadSafetyMode.NONE) { singletonEntryPoint().errorFormatter() } private var initialIndex = 0 @@ -103,10 +91,6 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), AttachmentInt viewModel.pendingAction = null } - /* ========================================================================================== - * Lifecycle - * ========================================================================================== */ - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) Timber.i("onCreate Activity ${javaClass.simpleName}") @@ -191,10 +175,6 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), AttachmentInt super.onBackPressed() } - /* ========================================================================================== - * Specialization - * ========================================================================================== */ - override fun shouldAnimateDismiss(): Boolean { return currentPosition != initialIndex } @@ -209,10 +189,6 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), AttachmentInt ActivityCompat.finishAfterTransition(this) } - /* ========================================================================================== - * Private methods - * ========================================================================================== */ - private fun getOtherThemes() = ActivityOtherThemes.VectorAttachmentsPreview /** @@ -284,10 +260,6 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), AttachmentInt Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q || checkPermissions(PERMISSIONS_FOR_WRITING_FILES, this, downloadActionResultLauncher) - /* ========================================================================================== - * Specialization AttachmentInteractionListener - * ========================================================================================== */ - override fun onDismiss() { animateClose() } @@ -329,10 +301,6 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), AttachmentInt } } - /* ========================================================================================== - * COMPANION - * ========================================================================================== */ - companion object { private const val EXTRA_ARGS = "EXTRA_ARGS" private const val EXTRA_IMAGE_DATA = "EXTRA_IMAGE_DATA" diff --git a/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerViewModel.kt b/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerViewModel.kt index caabcc1de3..807c69caff 100644 --- a/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerViewModel.kt @@ -35,10 +35,6 @@ class VectorAttachmentViewerViewModel @AssistedInject constructor( private val downloadMediaUseCase: DownloadMediaUseCase ) : VectorViewModel(initialState) { - /* ========================================================================================== - * Factory - * ========================================================================================== */ - @AssistedFactory interface Factory : MavericksAssistedViewModelFactory { override fun create(initialState: VectorDummyViewState): VectorAttachmentViewerViewModel @@ -46,26 +42,14 @@ class VectorAttachmentViewerViewModel @AssistedInject constructor( companion object : MavericksViewModelFactory by hiltMavericksViewModelFactory() - /* ========================================================================================== - * Public Api - * ========================================================================================== */ - var pendingAction: VectorAttachmentViewerAction? = null - /* ========================================================================================== - * Specialization - * ========================================================================================== */ - override fun handle(action: VectorAttachmentViewerAction) { when (action) { is VectorAttachmentViewerAction.DownloadMedia -> handleDownloadAction(action) } } - /* ========================================================================================== - * Private methods - * ========================================================================================== */ - private fun handleDownloadAction(action: VectorAttachmentViewerAction.DownloadMedia) { // launch in the coroutine scope session to avoid binding the coroutine to the lifecycle of the VM session.coroutineScope.launch { diff --git a/vector/src/main/java/im/vector/app/features/media/domain/usecase/DownloadMediaUseCase.kt b/vector/src/main/java/im/vector/app/features/media/domain/usecase/DownloadMediaUseCase.kt index 6da4e5b419..aca5661a8f 100644 --- a/vector/src/main/java/im/vector/app/features/media/domain/usecase/DownloadMediaUseCase.kt +++ b/vector/src/main/java/im/vector/app/features/media/domain/usecase/DownloadMediaUseCase.kt @@ -23,22 +23,23 @@ import im.vector.app.core.intent.getMimeTypeFromUri import im.vector.app.core.usecase.VectorBaseInOutUseCase import im.vector.app.core.utils.saveMedia import im.vector.app.features.notifications.NotificationUtils -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext +import org.matrix.android.sdk.api.MatrixCoroutineDispatchers import java.io.File import javax.inject.Inject class DownloadMediaUseCase @Inject constructor( @ApplicationContext private val appContext: Context, + private val coroutineDispatchers: MatrixCoroutineDispatchers, private val notificationUtils: NotificationUtils ) : VectorBaseInOutUseCase { - /* ========================================================================================== - * Public API - * ========================================================================================== */ + // TODO + // what about UseCase Interface enforcing single type input? => no interface + // add unit tests + // PR to template structure of a class for discussion - // TODO declare Dispatcher via an Interface provider to be able to unit tests - override suspend fun execute(input: File): Result = withContext(Dispatchers.IO) { + override suspend fun execute(input: File): Result = withContext(coroutineDispatchers.io) { runCatching { saveMedia( context = appContext,