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 1429 #182

Merged
merged 15 commits into from
Oct 13, 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 @@ -16,7 +16,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 = EventName.CreateMedia
override val eventName: EventName = if (entry.isProcessService) EventName.TaskCreateMedia else EventName.CreateMedia
) : Action {

private val repository = OfflineRepository()
Expand All @@ -35,10 +35,11 @@ data class ActionCaptureMedia(
result.map { item ->
repository.scheduleForUpload(
item.uri.toString(),
entry.id,
if (entry.isProcessService) entry.parentId ?: "" else entry.id,
item.filename,
item.description,
item.mimeType
item.mimeType,
entry.isProcessService
)
}
repository.setTotalTransferSize(result.size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@ 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 = EventName.UploadFiles
override val eventName: EventName = if (entry.isProcessService) 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.count() > 0) {
if (result.isNotEmpty()) {
withContext(Dispatchers.IO) {
result.map {
repository.scheduleContentForUpload(context, it, entry.id)
repository.scheduleContentForUpload(
context,
it,
if (entry.isProcessService) entry.parentId ?: "" else entry.id,
entry.isProcessService
)
}
repository.setTotalTransferSize(result.size)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@ 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 = EventName.UploadMedia
override val eventName: EventName = if (entry.isProcessService) 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.count() > 0) {
if (result.isNotEmpty()) {
withContext(Dispatchers.IO) {
result.map {
repository.scheduleContentForUpload(context, it, entry.id)
repository.scheduleContentForUpload(
context,
it,
if (entry.isProcessService) entry.parentId ?: "" else entry.id,
entry.isProcessService
)
}
repository.setTotalTransferSize(result.size)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ internal class ActionCreateViewModel(
private fun makeActions(parent: Entry): List<Action> {
val actions = mutableListOf<Action>()

actions.add(ActionCreateFolder(parent))
if (!parent.isProcessService)
actions.add(ActionCreateFolder(parent))
actions.add(ActionCaptureMedia(parent))
actions.add(ActionUploadMedia(parent))
actions.add(ActionUploadFiles(parent))
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
defaultConfig {
applicationId "com.alfresco.content.app"
versionCode envOrDef('VERSION_CODE', '1') as Integer
versionName "1.4"
versionName "1.5"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package com.alfresco.content.browse.tasks
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.Fragment
import com.alfresco.content.actions.CreateActionsSheet
import com.alfresco.content.browse.R
import com.alfresco.content.browse.tasks.detail.TaskDetailViewState
import com.alfresco.content.data.AnalyticsManager
import com.alfresco.content.data.ContentEntry
import com.alfresco.content.data.Entry
import com.alfresco.content.data.EventName
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.lang.ref.WeakReference
Expand All @@ -26,7 +28,7 @@ abstract class BaseDetailFragment : Fragment(), DeleteContentListener {
/**
* confirmation dialog before deleting the content related to task.
*/
fun deleteContentPrompt(contentEntry: ContentEntry) {
fun deleteContentPrompt(contentEntry: Entry) {
AnalyticsManager().taskEvent(EventName.DeleteTaskAttachment)
val oldDialog = deleteContentDialog.get()
if (oldDialog != null && oldDialog.isShowing) return
Expand All @@ -41,6 +43,18 @@ abstract class BaseDetailFragment : Fragment(), DeleteContentListener {
.show()
deleteContentDialog = WeakReference(dialog)
}

internal fun showCreateSheet(state: TaskDetailViewState) {
AnalyticsManager().taskEvent(EventName.UploadTaskAttachment)
CreateActionsSheet.with(Entry.defaultAPSEntry(state.parent?.id)).show(childFragmentManager, null)
}

/**
* return the stable id of uploading contents
*/
fun stableId(entry: Entry): String =
if (entry.isUpload) entry.boxId.toString()
else entry.id
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,12 @@
package com.alfresco.content.browse.tasks

import android.os.Bundle
import android.os.Parcelable
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.NavHostFragment
import com.alfresco.content.actions.Action
import com.alfresco.content.browse.R
import com.alfresco.content.browse.databinding.ActivityTaskViewerBinding
import com.alfresco.content.data.TaskEntry
import kotlinx.parcelize.Parcelize

/**
* Mark as TaskDetailsArgs class
*/
@Parcelize
data class TaskDetailsArgs(
val taskObj: TaskEntry?
) : Parcelable {
companion object {
const val TASK_OBJ = "taskObj"

/**
* return the TaskDetailsArgs obj
*/
fun with(args: Bundle): TaskDetailsArgs {
return TaskDetailsArgs(
args.getParcelable(TASK_OBJ)
)
}
}
}

/**
* Marked as TaskViewerActivity class
Expand All @@ -42,6 +20,7 @@ class TaskViewerActivity : AppCompatActivity() {
binding = ActivityTaskViewerBinding.inflate(layoutInflater)
setContentView(binding.root)
configureNav()
setupActionToasts()
}

private fun configureNav() {
Expand All @@ -52,4 +31,10 @@ class TaskViewerActivity : AppCompatActivity() {
val graph = inflater.inflate(R.navigation.nav_task_paths)
navController.setGraph(graph, intent.extras)
}

private fun setupActionToasts() = Action.showActionToasts(
lifecycleScope,
findViewById(android.R.id.content),
binding.bottomView
)
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
package com.alfresco.content.browse.tasks.attachments

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.TypedValue
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.isVisible
import androidx.core.view.setMargins
import androidx.recyclerview.widget.RecyclerView
import com.airbnb.epoxy.AsyncEpoxyController
import com.airbnb.mvrx.Loading
import com.airbnb.mvrx.MavericksView
import com.airbnb.mvrx.Success
import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.withState
import com.alfresco.content.actions.ActionOpenWith
Expand All @@ -18,15 +26,16 @@ import com.alfresco.content.browse.databinding.FragmentAttachedFilesBinding
import com.alfresco.content.browse.preview.LocalPreviewActivity
import com.alfresco.content.browse.tasks.BaseDetailFragment
import com.alfresco.content.browse.tasks.detail.TaskDetailViewModel
import com.alfresco.content.browse.tasks.detail.TaskDetailViewState
import com.alfresco.content.data.AnalyticsManager
import com.alfresco.content.data.ContentEntry
import com.alfresco.content.data.Entry
import com.alfresco.content.data.PageView
import com.alfresco.content.data.ParentEntry
import com.alfresco.content.listview.EntryListener
import com.alfresco.content.mimetype.MimeType
import com.alfresco.content.simpleController
import com.alfresco.ui.getDrawableForAttribute
import com.google.android.material.floatingactionbutton.FloatingActionButton

/**
* Marked as AttachedFilesFragment class
Expand Down Expand Up @@ -68,8 +77,9 @@ class AttachedFilesFragment : BaseDetailFragment(), MavericksView, EntryListener
}
}
})
viewModel.getContents()
binding.refreshLayout.setOnRefreshListener {
viewModel.getComments()
viewModel.getContents()
}

viewModel.setListener(this)
Expand All @@ -80,31 +90,57 @@ class AttachedFilesFragment : BaseDetailFragment(), MavericksView, EntryListener
}

override fun invalidate() = withState(viewModel) { state ->

val handler = Handler(Looper.getMainLooper())
binding.loading.isVisible = state.requestDeleteContent is Loading

if (state.requestContents.complete) {
binding.refreshLayout.isRefreshing = false
}
handler.post {
if (state.listContents.size > 4) {
binding.tvNoOfAttachments.visibility = View.VISIBLE
binding.tvNoOfAttachments.text = getString(R.string.text_multiple_attachment, state.listContents.size)
} else {
binding.tvNoOfAttachments.visibility = View.GONE
}
}

epoxyController.requestModelBuild()

if (state.listContents.size > 4) {
binding.tvNoOfAttachments.visibility = View.VISIBLE
binding.tvNoOfAttachments.text = getString(R.string.text_multiple_attachment, state.listContents.size)
} else {
binding.tvNoOfAttachments.visibility = View.GONE
if (state.requestContents is Success) {
binding.clParent.addView(makeFab(requireContext(), state))
}

if (state.listContents.isEmpty()) requireActivity().onBackPressed()

epoxyController.requestModelBuild()
}

private fun makeFab(context: Context, state: TaskDetailViewState) =
FloatingActionButton(context).apply {
layoutParams = CoordinatorLayout.LayoutParams(
CoordinatorLayout.LayoutParams.WRAP_CONTENT,
CoordinatorLayout.LayoutParams.WRAP_CONTENT
).apply {
gravity = Gravity.BOTTOM or Gravity.END
// TODO: define margins
setMargins(
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16f, resources.displayMetrics)
.toInt()
)
}
id = R.id.fab_add_attachments
contentDescription = context.getString(R.string.text_add_attachments)
setImageResource(R.drawable.ic_add_fab)
setOnClickListener {
showCreateSheet(state)
}
}

private fun epoxyController() = simpleController(viewModel) { state ->

if (state.listContents.isNotEmpty()) {
state.listContents.forEach { obj ->
listViewAttachmentRow {
id(obj.id)
id(stableId(obj))
data(obj)
clickListener { model, _, _, _ -> onItemClicked(model.data()) }
deleteContentClickListener { model, _, _, _ -> deleteContentPrompt(model.data()) }
Expand All @@ -113,8 +149,9 @@ class AttachedFilesFragment : BaseDetailFragment(), MavericksView, EntryListener
}
}

private fun onItemClicked(contentEntry: ContentEntry) {
viewModel.execute(ActionOpenWith(Entry.convertContentEntryToEntry(contentEntry, MimeType.isDocFile(contentEntry.mimeType))))
private fun onItemClicked(contentEntry: Entry) {
if (!contentEntry.isUpload)
viewModel.execute(ActionOpenWith(Entry.convertContentEntryToEntry(contentEntry, MimeType.isDocFile(contentEntry.mimeType))))
}

override fun onEntryCreated(entry: ParentEntry) {
Expand Down
Loading