Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobileapps 1313 #163

Merged
merged 4 commits into from
Sep 16, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import androidx.annotation.StringRes
import com.alfresco.Logger
import com.alfresco.content.data.APIEvent
import com.alfresco.content.data.AnalyticsManager
import com.alfresco.content.data.Entry
import com.alfresco.content.data.EventName
import com.alfresco.content.data.ParentEntry
import com.alfresco.events.EventBus
import com.alfresco.events.on
import com.google.android.material.snackbar.Snackbar
Expand All @@ -18,13 +18,13 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

interface Action {
val entry: Entry
val entry: ParentEntry
val icon: Int
val title: Int
val eventName: EventName

suspend fun execute(context: Context): Entry
fun copy(_entry: Entry): Action
suspend fun execute(context: Context): ParentEntry
fun copy(_entry: ParentEntry): Action

fun execute(
context: Context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.alfresco.content.PermissionFragment
import com.alfresco.content.data.Entry
import com.alfresco.content.data.EventName
import com.alfresco.content.data.OfflineRepository
import com.alfresco.content.data.ParentEntry
import kotlin.coroutines.cancellation.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -54,7 +55,7 @@ data class ActionCaptureMedia(
return entry
}

override fun copy(_entry: Entry): Action = copy(entry = _entry)
override fun copy(_entry: ParentEntry): Action = copy(entry = _entry as Entry)

override fun showToast(view: View, anchorView: View?) =
Action.showToast(view, anchorView, R.string.action_upload_media_toast)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.View
import com.alfresco.content.data.BrowseRepository
import com.alfresco.content.data.Entry
import com.alfresco.content.data.EventName
import com.alfresco.content.data.ParentEntry
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
import kotlinx.coroutines.CancellationException
Expand All @@ -27,20 +28,15 @@ data class ActionCreateFolder(
suspendCoroutine {
CreateFolderDialog.Builder(context, false, entry.name)
.onSuccess { title, description ->
it.resume(CreateFolderMetadata(title, description))
it.resume(CreateMetadata(title, description))
}
.onCancel { it.resume(null) }
.show()
}
}

override fun copy(_entry: Entry): Action = copy(entry = _entry)
override fun copy(_entry: ParentEntry): Action = copy(entry = _entry as Entry)

override fun showToast(view: View, anchorView: View?) =
Action.showToast(view, anchorView, R.string.action_create_folder_toast, entry.name)

private data class CreateFolderMetadata(
val name: String,
val description: String
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.alfresco.content.actions

import android.content.Context
import android.view.View
import com.alfresco.content.data.AnalyticsManager
import com.alfresco.content.data.EventName
import com.alfresco.content.data.ParentEntry
import com.alfresco.content.data.TaskEntry
import com.alfresco.content.data.TaskRepository
import kotlin.coroutines.cancellation.CancellationException
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
* Mark as ActionCreateTask class
*/
data class ActionCreateTask(
override var entry: TaskEntry,
override val icon: Int = R.drawable.ic_action_create_folder,
override val title: Int = R.string.action_create_task,
override val eventName: EventName = EventName.CreateTask
) : Action {
override suspend fun execute(context: Context): TaskEntry {
val result = showCreateTaskDialog(context) ?: throw CancellationException("User Cancellation")
AnalyticsManager().taskEvent(eventName)
return TaskRepository().createTask(result.name, result.description)
}

private suspend fun showCreateTaskDialog(context: Context) = withContext(Dispatchers.Main) {
suspendCoroutine {
CreateTaskDialog.Builder(context, entry.name)
.onSuccess { title, description ->
it.resume(CreateMetadata(title, description))
}
.onCancel { it.resume(null) }
.show()
}
}

override fun copy(_entry: ParentEntry): Action = copy(entry = _entry as TaskEntry)

override fun showToast(view: View, anchorView: View?) =
Action.showToast(view, anchorView, R.string.action_create_folder_toast, entry.name)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.alfresco.content.data.BrowseRepository
import com.alfresco.content.data.Entry
import com.alfresco.content.data.EventName
import com.alfresco.content.data.OfflineRepository
import com.alfresco.content.data.ParentEntry
import com.alfresco.content.data.SitesRepository
import com.alfresco.content.data.TrashCanRepository
import com.alfresco.kotlin.ellipsize
Expand Down Expand Up @@ -46,7 +47,7 @@ data class ActionDelete(
}
}

override fun copy(_entry: Entry): Action = copy(entry = _entry)
override fun copy(_entry: ParentEntry): Action = copy(entry = _entry as Entry)

override fun showToast(view: View, anchorView: View?) =
Action.showToast(
Expand All @@ -68,7 +69,7 @@ data class ActionRestore(
return entry
}

override fun copy(_entry: Entry): Action = copy(entry = _entry)
override fun copy(_entry: ParentEntry): Action = copy(entry = _entry as Entry)

override fun showToast(view: View, anchorView: View?) =
Action.showToast(
Expand Down Expand Up @@ -116,7 +117,7 @@ data class ActionDeleteForever(

private suspend inline fun delete(entry: Entry) = TrashCanRepository().deleteForeverEntry(entry)

override fun copy(_entry: Entry): Action = copy(entry = _entry)
override fun copy(_entry: ParentEntry): Action = copy(entry = _entry as Entry)

override fun showToast(view: View, anchorView: View?) =
Action.showToast(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.alfresco.content.data.BrowseRepository
import com.alfresco.content.data.Entry
import com.alfresco.content.data.EventName
import com.alfresco.content.data.OfflineRepository
import com.alfresco.content.data.ParentEntry
import java.io.File
import java.io.FileNotFoundException
import kotlin.coroutines.cancellation.CancellationException
Expand Down Expand Up @@ -131,7 +132,7 @@ data class ActionDownload(
dm?.enqueue(request) ?: throw CancellationException("Missing DownloadManager service.")
}

override fun copy(_entry: Entry): Action = copy(entry = _entry)
override fun copy(_entry: ParentEntry): Action = copy(entry = _entry as Entry)

override fun showToast(view: View, anchorView: View?) =
toastMessage.let { Action.showToast(view, anchorView, it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.View
import com.alfresco.content.data.Entry
import com.alfresco.content.data.EventName
import com.alfresco.content.data.FavoritesRepository
import com.alfresco.content.data.ParentEntry

data class ActionAddFavorite(
override val entry: Entry,
Expand All @@ -19,7 +20,7 @@ data class ActionAddFavorite(
return entry.copy(isFavorite = true)
}

override fun copy(_entry: Entry): Action = copy(entry = _entry)
override fun copy(_entry: ParentEntry): Action = copy(entry = _entry as Entry)

override fun showToast(view: View, anchorView: View?) =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unnecessary code for show toast. Not required.

Action.showToast(view, anchorView, R.string.action_add_favorite_toast)
Expand All @@ -42,7 +43,7 @@ data class ActionRemoveFavorite(
return entry.copy(isFavorite = false)
}

override fun copy(_entry: Entry): Action = copy(entry = _entry)
override fun copy(_entry: ParentEntry): Action = copy(entry = _entry as Entry)

override fun showToast(view: View, anchorView: View?) =
Action.showToast(view, anchorView, R.string.action_remove_favorite_toast)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.View
import com.alfresco.content.data.BrowseRepository
import com.alfresco.content.data.Entry
import com.alfresco.content.data.EventName
import com.alfresco.content.data.ParentEntry
import kotlin.coroutines.cancellation.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -32,7 +33,7 @@ data class ActionMoveFilesFolders(
return entry
}

override fun copy(_entry: Entry): Action = copy(entry = _entry)
override fun copy(_entry: ParentEntry): Action = copy(entry = _entry as Entry)

override fun showToast(view: View, anchorView: View?) =
Action.showToast(view, anchorView, R.string.action_move_toast, entry.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.alfresco.content.data.Entry
import com.alfresco.content.data.EventName
import com.alfresco.content.data.OfflineRepository
import com.alfresco.content.data.OfflineStatus
import com.alfresco.content.data.ParentEntry
import com.alfresco.kotlin.ellipsize

data class ActionAddOffline(
Expand All @@ -22,7 +23,7 @@ data class ActionAddOffline(
return res.copy(offlineStatus = OfflineStatus.UNDEFINED)
}

override fun copy(_entry: Entry): Action = copy(entry = _entry)
override fun copy(_entry: ParentEntry): Action = copy(entry = _entry as Entry)

override fun showToast(view: View, anchorView: View?) =
Action.showToast(
Expand All @@ -44,7 +45,7 @@ data class ActionRemoveOffline(
override suspend fun execute(context: Context) =
repository.removeFromSync(entry)

override fun copy(_entry: Entry): Action = copy(entry = _entry)
override fun copy(_entry: ParentEntry): Action = copy(entry = _entry as Entry)

override fun showToast(view: View, anchorView: View?) =
Action.showToast(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.alfresco.content.data.BrowseRepository
import com.alfresco.content.data.Entry
import com.alfresco.content.data.EventName
import com.alfresco.content.data.OfflineRepository
import com.alfresco.content.data.ParentEntry
import com.alfresco.content.data.TaskRepository
import com.alfresco.content.mimetype.MimeType
import com.alfresco.download.ContentDownloader
Expand Down Expand Up @@ -129,7 +130,7 @@ data class ActionOpenWith(
}
}

override fun copy(_entry: Entry): Action = copy(entry = _entry)
override fun copy(_entry: ParentEntry): Action = copy(entry = _entry as Entry)

override fun showToast(view: View, anchorView: View?) = Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.View
import com.alfresco.content.data.BrowseRepository
import com.alfresco.content.data.Entry
import com.alfresco.content.data.EventName
import com.alfresco.content.data.ParentEntry
import java.io.File
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
Expand Down Expand Up @@ -44,7 +45,7 @@ data class ActionUpdateFileFolder(
}
}

override fun copy(_entry: Entry): Action = copy(entry = _entry)
override fun copy(_entry: ParentEntry): Action = copy(entry = _entry as Entry)

override fun showToast(view: View, anchorView: View?) =
Action.showToast(view, anchorView, R.string.action_rename_file_folder_toast, entry.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.alfresco.content.ContentPickerFragment
import com.alfresco.content.data.Entry
import com.alfresco.content.data.EventName
import com.alfresco.content.data.OfflineRepository
import com.alfresco.content.data.ParentEntry
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -37,7 +38,7 @@ data class ActionUploadFiles(
return entry
}

override fun copy(_entry: Entry): Action = copy(entry = _entry)
override fun copy(_entry: ParentEntry): Action = copy(entry = _entry as Entry)

override fun showToast(view: View, anchorView: View?) {
Action.showToast(view, anchorView, R.string.action_upload_media_toast)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.alfresco.content.ContentPickerFragment
import com.alfresco.content.data.Entry
import com.alfresco.content.data.EventName
import com.alfresco.content.data.OfflineRepository
import com.alfresco.content.data.ParentEntry
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -34,7 +35,7 @@ data class ActionUploadMedia(
return entry
}

override fun copy(_entry: Entry): Action = copy(entry = _entry)
override fun copy(_entry: ParentEntry): Action = copy(entry = _entry as Entry)

override fun showToast(view: View, anchorView: View?) =
Action.showToast(view, anchorView, R.string.action_upload_media_toast)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ class ContextualActionsSheet : BottomSheetDialogFragment(), MavericksView {
actionListLoading { id("loading") }
}
state.actions.forEach {
val entry = it.entry as Entry
actionListRow {
id(it.title)
action(it)
clickListener { _ ->
AnalyticsManager().fileActionEvent(it.entry.mimeType ?: "",
it.entry.name.substringAfterLast(".", ""),
AnalyticsManager().fileActionEvent(entry.mimeType ?: "",
entry.name.substringAfterLast(".", ""),
it.eventName)
viewModel.execute(it)
dismiss()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ internal class ContextualActionsViewModel(

private fun updateState(action: Action) {
setState {
val entry = action.entry as Entry
ContextualActionsState(
action.entry,
makeActions(action.entry),
makeTopActions(action.entry)
entry,
makeActions(entry),
makeTopActions(entry)
)
}
}
Expand Down
Loading