Skip to content

Commit

Permalink
MOBILEAPPS-1735 (#239)
Browse files Browse the repository at this point in the history
* uploaded attachment on the workflow

* added view all attachment screen

* codacy correction

* added content delete feature

* removed delete dialog and added process for offline files
  • Loading branch information
aman-alfresco committed Apr 22, 2023
1 parent 171de53 commit 32d75ac
Show file tree
Hide file tree
Showing 35 changed files with 584 additions and 189 deletions.
16 changes: 15 additions & 1 deletion actions/src/main/kotlin/com/alfresco/content/actions/Action.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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.content.data.UploadServerType
import com.alfresco.events.EventBus
import com.alfresco.events.on
import com.google.android.material.snackbar.Snackbar
Expand Down Expand Up @@ -39,7 +40,9 @@ interface Action {
bus.send(newAction)
} catch (ex: CancellationException) {
// no-op
if (entry is Entry && (entry as Entry).isProcessService && ex.message == ERROR_FILE_SIZE_EXCEED) {
if (entry is Entry && (entry as Entry).uploadServer == UploadServerType.UPLOAD_TO_TASK &&
ex.message == ERROR_FILE_SIZE_EXCEED
) {
bus.send(Error(context.getString(R.string.error_file_size_exceed)))
}
} catch (ex: Exception) {
Expand All @@ -66,6 +69,17 @@ interface Action {
AnalyticsManager().apiTracker(APIEvent.NewFolder, status)
}

/**
* returns the parent ID on the basis of uploading server
*/
fun getParentId(entry: Entry): String {
return when (entry.uploadServer) {
UploadServerType.DEFAULT -> entry.id
UploadServerType.UPLOAD_TO_TASK, UploadServerType.UPLOAD_TO_PROCESS -> entry.parentId ?: ""
else -> ""
}
}

fun showToast(view: View, anchorView: View? = null) {}

fun maxFileNameInToast(view: View) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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.UploadServerType
import kotlin.coroutines.cancellation.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
Expand All @@ -16,7 +17,7 @@ data class ActionCaptureMedia(
override var entry: Entry,
override val icon: Int = R.drawable.ic_action_capture_photo,
override val title: Int = R.string.action_capture_media_title,
override val eventName: EventName = if (entry.isProcessService) EventName.TaskCreateMedia else EventName.CreateMedia
override val eventName: EventName = if (entry.uploadServer == UploadServerType.UPLOAD_TO_TASK) EventName.TaskCreateMedia else EventName.CreateMedia
) : Action {

private val repository = OfflineRepository()
Expand All @@ -35,11 +36,11 @@ data class ActionCaptureMedia(
result.map { item ->
repository.scheduleForUpload(
item.uri.toString(),
if (entry.isProcessService) entry.parentId ?: "" else entry.id,
getParentId(entry),
item.filename,
item.description,
item.mimeType,
entry.isProcessService
entry.uploadServer
)
}
repository.setTotalTransferSize(result.size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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.data.UploadServerType
import com.alfresco.content.mimetype.MimeType
import com.alfresco.download.ContentDownloader
import com.google.android.material.dialog.MaterialAlertDialogBuilder
Expand Down Expand Up @@ -41,16 +42,19 @@ data class ActionOpenWith(
fetchRemoteFile(context)
}

return if (!entry.isProcessService) {
showFileChooserDialog(context, target)
entry
} else {
var path = target.path
if (hasChooser) {
return when (entry.uploadServer) {
UploadServerType.DEFAULT -> {
showFileChooserDialog(context, target)
path = ""
entry
}
else -> {
var path = target.path
if (hasChooser) {
showFileChooserDialog(context, target)
path = ""
}
Entry.updateDownloadEntry(entry, path)
}
Entry.updateDownloadEntry(entry, path)
}
}

Expand All @@ -61,7 +65,7 @@ data class ActionOpenWith(
val client: OkHttpClient?
val output: File

if (entry.isProcessService) {
if (entry.uploadServer == UploadServerType.UPLOAD_TO_TASK) {
uri = TaskRepository().contentUri(entry)
client = TaskRepository().getHttpClient()
output = TaskRepository().getContentDirectory(entry.fileName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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.UploadServerType
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
Expand All @@ -21,28 +22,32 @@ data class ActionUploadFiles(
override var entry: Entry,
override val icon: Int = R.drawable.ic_action_upload,
override val title: Int = R.string.action_upload_files_title,
override val eventName: EventName = if (entry.isProcessService) EventName.TaskUploadFiles else EventName.UploadFiles
override val eventName: EventName = if (entry.uploadServer == UploadServerType.UPLOAD_TO_TASK) EventName.TaskUploadFiles else EventName.UploadFiles
) : Action {

private val repository = OfflineRepository()

override suspend fun execute(context: Context): Entry {
val result = ContentPickerFragment.pickItems(context, MIME_TYPES)
if (result.isNotEmpty()) {
if (entry.isProcessService)
result.forEach {
val fileLength = DocumentFile.fromSingleUri(context, it)?.length() ?: 0L
if (GetMultipleContents.isFileSizeExceed(fileLength)) {
throw CancellationException(ERROR_FILE_SIZE_EXCEED)
when (entry.uploadServer) {
UploadServerType.UPLOAD_TO_TASK, UploadServerType.UPLOAD_TO_PROCESS -> {
result.forEach {
val fileLength = DocumentFile.fromSingleUri(context, it)?.length() ?: 0L
if (GetMultipleContents.isFileSizeExceed(fileLength)) {
throw CancellationException(ERROR_FILE_SIZE_EXCEED)
}
}
}
else -> {}
}
withContext(Dispatchers.IO) {
result.map {
repository.scheduleContentForUpload(
context,
it,
if (entry.isProcessService) entry.parentId ?: "" else entry.id,
isProcessService = entry.isProcessService
getParentId(entry),
uploadServerType = entry.uploadServer
)
}
repository.setTotalTransferSize(result.size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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.UploadServerType
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
Expand All @@ -18,28 +19,32 @@ data class ActionUploadMedia(
override var entry: Entry,
override val icon: Int = R.drawable.ic_action_upload_photo,
override val title: Int = R.string.action_upload_photo_title,
override val eventName: EventName = if (entry.isProcessService) EventName.TaskUploadMedia else EventName.UploadMedia
override val eventName: EventName = if (entry.uploadServer == UploadServerType.UPLOAD_TO_TASK) EventName.TaskUploadMedia else EventName.UploadMedia
) : Action {

private val repository = OfflineRepository()

override suspend fun execute(context: Context): Entry {
val result = ContentPickerFragment.pickItems(context, MIME_TYPES)
if (result.isNotEmpty()) {
if (entry.isProcessService)
result.forEach {
val fileLength = DocumentFile.fromSingleUri(context, it)?.length() ?: 0L
if (GetMultipleContents.isFileSizeExceed(fileLength)) {
throw CancellationException(ERROR_FILE_SIZE_EXCEED)
when (entry.uploadServer) {
UploadServerType.UPLOAD_TO_TASK, UploadServerType.UPLOAD_TO_PROCESS -> {
result.forEach {
val fileLength = DocumentFile.fromSingleUri(context, it)?.length() ?: 0L
if (GetMultipleContents.isFileSizeExceed(fileLength)) {
throw CancellationException(ERROR_FILE_SIZE_EXCEED)
}
}
}
else -> {}
}
withContext(Dispatchers.IO) {
result.map {
repository.scheduleContentForUpload(
context,
it,
if (entry.isProcessService) entry.parentId ?: "" else entry.id,
isProcessService = entry.isProcessService
getParentId(entry),
uploadServerType = entry.uploadServer
)
}
repository.setTotalTransferSize(result.size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ internal class ContextualActionsViewModel(
private fun actionsForOffline(entry: Entry): List<Action> =
listOf(
externalActionsFor(entry),
if (Settings(context).isProcessEnabled && entry.isFile) actionsProcesses(entry) else listOf(),
offlineActionFor(entry)
).flatten()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.airbnb.mvrx.withState
import com.alfresco.content.actions.databinding.SheetActionCreateBinding
import com.alfresco.content.data.AnalyticsManager
import com.alfresco.content.data.Entry
import com.alfresco.content.data.UploadServerType
import com.alfresco.ui.BottomSheetDialogFragment
import kotlinx.coroutines.GlobalScope

Expand Down Expand Up @@ -50,7 +51,7 @@ internal class ActionCreateViewModel(
private fun makeActions(parent: Entry): List<Action> {
val actions = mutableListOf<Action>()

if (!parent.isProcessService)
if (parent.uploadServer == UploadServerType.DEFAULT)
actions.add(ActionCreateFolder(parent))
actions.add(ActionCaptureMedia(parent))
actions.add(ActionUploadMedia(parent))
Expand Down
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ dependencies {
testImplementation libs.junit
androidTestImplementation libs.androidx.test.core
androidTestImplementation libs.androidx.test.espresso.core
// implementation("com.airbnb.android:mavericks-mocking:3.0.1")
}

static Object envOrDef(String varName, Object defaultValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class MainActivity : AppCompatActivity(), MavericksView {
}

viewModel.isProcessEnabled = {
println("MainActivity.onCreate APS Enabled $it")
val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this)
val editor = sharedPrefs.edit()
editor.putBoolean(IS_PROCESS_ENABLED_KEY, it)
Expand Down
1 change: 0 additions & 1 deletion browse/src/main/assets/task.filters.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
{
"label": "filter.option.active",
"query": "active",
"default": true,
"value": "state"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import com.airbnb.mvrx.InternalMavericksApi
import com.airbnb.mvrx.withState
import com.alfresco.content.actions.ActionSyncNow
import com.alfresco.content.browse.R
import com.alfresco.content.browse.processes.sheet.ProcessDefinitionsSheet
import com.alfresco.content.data.Entry
import com.alfresco.content.data.ParentEntry
import com.alfresco.content.fragmentViewModelWithArgs
import com.alfresco.content.listview.ListFragment
import com.alfresco.content.navigateTo
Expand Down Expand Up @@ -99,4 +101,9 @@ class OfflineFragment : ListFragment<OfflineViewModel, OfflineViewState>() {
findNavController().navigateTo(entry)
}
}

override fun onProcessStart(entry: ParentEntry) {
if (isAdded && isVisible)
ProcessDefinitionsSheet.with(entry as Entry).show(parentFragmentManager, null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.airbnb.mvrx.withState
import com.alfresco.content.browse.R
import com.alfresco.content.browse.databinding.FragmentLocalPreviewBinding
import com.alfresco.content.data.Entry
import com.alfresco.content.data.UploadServerType
import com.alfresco.content.fragmentViewModelWithArgs
import com.alfresco.content.mimetype.MimeType
import com.alfresco.content.viewer.common.ChildViewerArgs
Expand Down Expand Up @@ -98,8 +99,12 @@ class LocalPreviewFragment : Fragment(), MavericksView {

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
withState(viewModel) { state ->
if (state.entry?.isProcessService == true)
inflater.inflate(R.menu.menu_preview, menu)
when (state.entry?.uploadServer) {
UploadServerType.UPLOAD_TO_TASK -> {
inflater.inflate(R.menu.menu_preview, menu)
}
else -> {}
}
}
}

Expand All @@ -121,8 +126,6 @@ class LocalPreviewFragment : Fragment(), MavericksView {
ResourcesCompat.getDrawable(resources, type.icon, requireContext().theme)
)

println("mime type ${argsLocal.mimeType}")

val fragment = createViewer(argsLocal.mimeType)
if (fragment != null) {
binding.apply {
Expand Down
Loading

0 comments on commit 32d75ac

Please sign in to comment.