-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Mobileapps 1314 (#146) * added screen to view all attached files related to a task * added attachment screen and preview for attachment * add analytics for attached files screen * if the file is already available on the device then it will open its preview directly otherwise download it first. * codacy correction * code merging
- Loading branch information
1 parent
461d8a4
commit 9a1a40a
Showing
26 changed files
with
452 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...se/src/main/kotlin/com/alfresco/content/browse/tasks/attachments/AttachedFilesFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package com.alfresco.content.browse.tasks.attachments | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.airbnb.epoxy.AsyncEpoxyController | ||
import com.airbnb.mvrx.MavericksView | ||
import com.airbnb.mvrx.activityViewModel | ||
import com.airbnb.mvrx.withState | ||
import com.alfresco.content.actions.ActionOpenWith | ||
import com.alfresco.content.browse.R | ||
import com.alfresco.content.browse.databinding.FragmentAttachedFilesBinding | ||
import com.alfresco.content.browse.preview.LocalPreviewActivity | ||
import com.alfresco.content.browse.tasks.detail.TaskDetailViewModel | ||
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.listview.EntryListener | ||
import com.alfresco.content.simpleController | ||
import com.alfresco.ui.getDrawableForAttribute | ||
|
||
/** | ||
* Marked as AttachedFilesFragment class | ||
*/ | ||
class AttachedFilesFragment : Fragment(), MavericksView, EntryListener { | ||
|
||
val viewModel: TaskDetailViewModel by activityViewModel() | ||
private lateinit var binding: FragmentAttachedFilesBinding | ||
private val epoxyController: AsyncEpoxyController by lazy { epoxyController() } | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
binding = FragmentAttachedFilesBinding.inflate(inflater, container, false) | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
AnalyticsManager().screenViewEvent(PageView.AttachedFiles) | ||
|
||
binding.toolbar.apply { | ||
navigationContentDescription = getString(R.string.label_navigation_back) | ||
navigationIcon = requireContext().getDrawableForAttribute(R.attr.homeAsUpIndicator) | ||
setNavigationOnClickListener { requireActivity().onBackPressed() } | ||
title = resources.getString(R.string.title_attached_files) | ||
} | ||
|
||
binding.recyclerView.setController(epoxyController) | ||
|
||
epoxyController.adapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { | ||
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) { | ||
if (positionStart == 0) { | ||
// @see: https://github.com/airbnb/epoxy/issues/224 | ||
binding.recyclerView.layoutManager?.scrollToPosition(0) | ||
} | ||
} | ||
}) | ||
binding.refreshLayout.setOnRefreshListener { | ||
viewModel.getComments() | ||
} | ||
|
||
viewModel.setListener(this) | ||
} | ||
|
||
override fun invalidate() = withState(viewModel) { state -> | ||
if (state.requestContents.complete) { | ||
binding.refreshLayout.isRefreshing = false | ||
} | ||
|
||
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 | ||
} | ||
} | ||
|
||
private fun epoxyController() = simpleController(viewModel) { state -> | ||
|
||
if (state.listContents.isNotEmpty()) { | ||
state.listContents.forEach { obj -> | ||
listViewAttachmentRow { | ||
id(obj.id) | ||
data(obj) | ||
clickListener { model, _, _, _ -> onItemClicked(model.data()) } | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun onItemClicked(contentEntry: ContentEntry) { | ||
viewModel.execute(ActionOpenWith(Entry.convertContentEntryToEntry(contentEntry))) | ||
} | ||
|
||
override fun onEntryCreated(entry: Entry) { | ||
if (isAdded) | ||
entry.mimeType?.let { | ||
startActivity( | ||
Intent(requireActivity(), LocalPreviewActivity::class.java) | ||
.putExtra(LocalPreviewActivity.KEY_PATH, entry.path) | ||
.putExtra(LocalPreviewActivity.KEY_MIME_TYPE, it) | ||
.putExtra(LocalPreviewActivity.KEY_TITLE, entry.name) | ||
) | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...se/src/main/kotlin/com/alfresco/content/browse/tasks/attachments/ListViewAttachmentRow.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.alfresco.content.browse.tasks.attachments | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.LayoutInflater | ||
import android.widget.FrameLayout | ||
import androidx.core.content.res.ResourcesCompat | ||
import com.airbnb.epoxy.CallbackProp | ||
import com.airbnb.epoxy.ModelProp | ||
import com.airbnb.epoxy.ModelView | ||
import com.alfresco.content.browse.databinding.ViewListAttachmentRowBinding | ||
import com.alfresco.content.data.ContentEntry | ||
import com.alfresco.content.mimetype.MimeType | ||
|
||
/** | ||
* Marked as ListViewAttachmentRow class | ||
*/ | ||
@ModelView(autoLayout = ModelView.Size.MATCH_WIDTH_WRAP_HEIGHT) | ||
class ListViewAttachmentRow @JvmOverloads constructor( | ||
context: Context, | ||
attrs: AttributeSet? = null, | ||
defStyleAttr: Int = 0 | ||
) : FrameLayout(context, attrs, defStyleAttr) { | ||
|
||
private val binding = ViewListAttachmentRowBinding.inflate(LayoutInflater.from(context), this) | ||
|
||
/** | ||
* set the content data on list row | ||
*/ | ||
@ModelProp | ||
fun setData(data: ContentEntry) { | ||
binding.tvName.text = data.name | ||
binding.iconFile.setImageDrawable(ResourcesCompat.getDrawable(resources, MimeType.with(data.mimeType).icon, context.theme)) | ||
} | ||
|
||
/** | ||
* list row click listener | ||
*/ | ||
@CallbackProp | ||
fun setClickListener(listener: OnClickListener?) { | ||
setOnClickListener(listener) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
browse/src/main/kotlin/com/alfresco/content/browse/tasks/comments/ListViewCommentRow.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.alfresco.content.browse.tasks.comments | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.LayoutInflater | ||
import android.widget.FrameLayout | ||
import com.airbnb.epoxy.ModelProp | ||
import com.airbnb.epoxy.ModelView | ||
import com.alfresco.content.DATE_FORMAT_1 | ||
import com.alfresco.content.DATE_FORMAT_4 | ||
import com.alfresco.content.browse.databinding.ViewListCommentRowBinding | ||
import com.alfresco.content.data.CommentEntry | ||
import com.alfresco.content.getDateZoneFormat | ||
|
||
/** | ||
* Marked as ListViewCommentRow class | ||
*/ | ||
@ModelView(autoLayout = ModelView.Size.MATCH_WIDTH_WRAP_HEIGHT) | ||
class ListViewCommentRow @JvmOverloads constructor( | ||
context: Context, | ||
attrs: AttributeSet? = null, | ||
defStyleAttr: Int = 0 | ||
) : FrameLayout(context, attrs, defStyleAttr) { | ||
|
||
private val binding = ViewListCommentRowBinding.inflate(LayoutInflater.from(context), this) | ||
|
||
/** | ||
* set the comment row on list row | ||
*/ | ||
@ModelProp | ||
fun setData(data: CommentEntry) { | ||
binding.tvName.text = data.userDetails?.name | ||
binding.tvUserInitial.text = data.userDetails?.nameInitial | ||
binding.tvComment.text = data.message | ||
binding.tvDate.text = if (data.created != null) data.created?.toLocalDate().toString().getDateZoneFormat(DATE_FORMAT_1, DATE_FORMAT_4) else "" | ||
} | ||
} |
Oops, something went wrong.