Skip to content

Commit

Permalink
Mobileapps 1083 (#92)
Browse files Browse the repository at this point in the history
* added localization strings

* update session unavailable string

* sync functionality added
  • Loading branch information
aman-alfresco authored Mar 5, 2022
1 parent 5f776f4 commit 1ef6456
Show file tree
Hide file tree
Showing 24 changed files with 632 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ data class ActionUploadExtensionFiles(
if (!list.isNullOrEmpty()) {
withContext(Dispatchers.IO) {
list.map {
repository.scheduleContentForUpload(context, it, entry.id)
repository.scheduleContentForUpload(context, it, entry.id, true)
}
}
repository.setTotalTransferSize(entry.parentId)
} else {
throw CancellationException("User Cancellation")
}
Expand All @@ -38,8 +39,10 @@ data class ActionUploadExtensionFiles(
override fun copy(_entry: Entry): ActionExtension = copy(entry = _entry)

override fun showToast(view: View, anchorView: View?) {
println("Upload Extension Files List Size === " + repository.buildTransferList().size)
MaterialAlertDialogBuilder(view.context)
.setTitle(view.resources.getString(R.string.action_upload_queue_title))
.setCancelable(false)
.setMessage(view.resources.getString(R.string.action_upload_queue_subtitle))
.setPositiveButton(view.resources.getString(R.string.action_upload_queue_ok_button)) { _, _ ->
(view.context as AppCompatActivity).finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ data class ActionUploadFiles(
result.map {
repository.scheduleContentForUpload(context, it, entry.id)
}
repository.setTotalTransferSize(entry.parentId)
}
} else {
throw CancellationException("User Cancellation")
Expand All @@ -36,8 +37,9 @@ data class ActionUploadFiles(

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

override fun showToast(view: View, anchorView: View?) =
override fun showToast(view: View, anchorView: View?) {
Action.showToast(view, anchorView, R.string.action_upload_media_toast)
}

private companion object {
val MIME_TYPES = arrayOf("*/*")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ data class ActionUploadMedia(
result.map {
repository.scheduleContentForUpload(context, it, entry.id)
}
repository.setTotalTransferSize(entry.parentId)
}
} else {
throw CancellationException("User Cancellation")
Expand Down
10 changes: 2 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@
android:logo="@drawable/ic_launcher_foreground"
android:windowSoftInputMode="adjustResize">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
Expand All @@ -41,11 +35,11 @@
android:name=".activity.SplashActivity"
android:theme="@style/Theme.Alfresco.Splash"
android:exported="true">
<!--<intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>-->
</intent-filter>
</activity>
<activity
android:name=".activity.MainActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class ExtensionActivity : AppCompatActivity(), MavericksView, ActionPermission {
dialog = MaterialAlertDialogBuilder(this)
.setTitle(title)
.setMessage(message)
.setCancelable(false)
.setNegativeButton(negative, null)
.setPositiveButton(positive) { _, _ ->
when (type) {
Expand All @@ -173,6 +174,7 @@ class ExtensionActivity : AppCompatActivity(), MavericksView, ActionPermission {
dialog = MaterialAlertDialogBuilder(this)
.setTitle(title)
.setMessage(message)
.setCancelable(false)
.setPositiveButton(positive) { _, _ ->
when (type) {
AlertType.TYPE_NO_LOGIN -> {
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/navigation/nav_bottom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@
<deepLink app:uri="alfresco://content/search/folder/{id}?title={title}" />
</fragment>

<fragment
android:id="@+id/nav_transfer_files"
android:name="com.alfresco.content.browse.transfer.TransferFilesFragment"
android:label="Transfers">
<argument
android:name="extension"
app:argType="boolean"
android:defaultValue="false"/>
<argument
android:name="title"
app:argType="string"
android:defaultValue=""/>
<deepLink app:uri="alfresco://content/transfer_files/{extension}?title={title}" />
</fragment>

<fragment
android:id="@+id/nav_folder"
android:name="com.alfresco.content.browse.BrowseFragment"
Expand Down
2 changes: 1 addition & 1 deletion auth/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@

<!-- Login App dialog -->
<string name="auth_login_app_title">Session unavailable</string>
<string name="auth_login_app_subtitle">Please launch Alfresco Mobile Workspace before continuing.</string>
<string name="auth_login_app_subtitle">Tap to launch Alfresco Mobile Workspace.</string>
<string name="auth_login_app_ok_button">Ok</string>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@ import android.view.Gravity
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.os.bundleOf
import androidx.core.view.setMargins
import androidx.navigation.fragment.findNavController
import androidx.transition.ChangeBounds
import androidx.transition.Fade
import androidx.transition.TransitionManager
import androidx.transition.TransitionSet
import com.airbnb.mvrx.withState
import com.alfresco.content.actions.CreateActionsSheet
import com.alfresco.content.data.Entry
import com.alfresco.content.fragmentViewModelWithArgs
import com.alfresco.content.listview.ListFragment
import com.alfresco.content.navigateTo
import com.alfresco.content.navigateToContextualSearch
import com.alfresco.content.navigateToUploadFilesPath
import com.google.android.material.floatingactionbutton.FloatingActionButton
import kotlinx.parcelize.Parcelize

Expand Down Expand Up @@ -62,16 +68,77 @@ class BrowseFragment : ListFragment<BrowseViewModel, BrowseViewState>() {
}
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
withState(viewModel) { state ->
if (state.path == getString(R.string.nav_path_recents)) {
viewModel.refreshTransfersSize()
viewModel.observeTransferUploads()
bannerTransferData?.setOnClickListener {
findNavController().navigateToUploadFilesPath(true, requireContext().getString(R.string.title_transfers))
}
} else bannerTransferData?.visibility = View.GONE
}
}

override fun invalidate() {
super.invalidate()

withState(viewModel) { state ->
if (state.path == getString(R.string.nav_path_recents)) {
updateBanner(state.totalTransfersSize, state.uploadTransferList.size)
}

if (viewModel.canAddItems(state)) {
(view as ViewGroup).addView(makeFab(requireContext()))
}
}
}

private fun updateBanner(totalSize: Int, pendingFilesCount: Int) {

println("BrowseFragment.updateBanner $totalSize $pendingFilesCount")

if (pendingFilesCount == 0) {
hideBanner(0)
return
}
bannerTransferData?.visibility = View.VISIBLE

val uploadFileCount = totalSize - pendingFilesCount
val percentage = (uploadFileCount.toFloat().div(totalSize.toFloat())).times(100)

if (totalSize > 1) {
if (pendingFilesCount != 0)
tvUploadingFiles?.text = String.format(getString(com.alfresco.content.listview.R.string.upload_file_text_multiple), pendingFilesCount)
else tvUploadingFiles?.text = String.format(getString(com.alfresco.content.listview.R.string.upload_complete_text_multiple), totalSize)
} else {
if (pendingFilesCount != 0)
tvUploadingFiles?.text = String.format(getString(com.alfresco.content.listview.R.string.upload_file_text_single), pendingFilesCount)
else tvUploadingFiles?.text = String.format(getString(com.alfresco.content.listview.R.string.upload_complete_text_single), totalSize)
}

tvPercentage?.text = String.format(getString(com.alfresco.content.listview.R.string.upload_percentage_text), percentage.toInt())

percentageFiles?.progress = percentage.toInt()

if (pendingFilesCount == 0)
hideBanner(1000)
}

private fun hideBanner(millis: Long) {
bannerTransferData?.postDelayed({
bannerTransferData?.apply {
TransitionManager.beginDelayedTransition(
this, TransitionSet()
.addTransition(Fade())
.addTransition(ChangeBounds())
)
bannerTransferData?.visibility = View.GONE
}
}, millis)
}

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.menu_browse, menu)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,21 @@ class BrowseViewModel(
) : ListViewModel<BrowseViewState>(state) {

private var observeUploadsJob: Job? = null
private var observeTransferUploadsJob: Job? = null
private val browseRepository = BrowseRepository()
var onUploadQueue: (() -> Unit)? = null
private val offlineRepository = OfflineRepository()

init {
fetchInitial()

withState {
if (it.sortOrder == BrowseViewState.SortOrder.ByModifiedDate) {
BrowseViewState.ModifiedGroup.prepare(context)
}
}
if (state.path == context.getString(R.string.nav_path_recents)) {
offlineRepository.updateTransferSize(offlineRepository.buildTransferList().size)
setState { copy(totalTransfersSize = offlineRepository.getTotalTransfersSize()) }
}

if (state.path == context.getString(R.string.nav_path_favorites)) {
val types = setOf(Entry.Type.FILE, Entry.Type.FOLDER)
Expand Down Expand Up @@ -79,6 +83,11 @@ class BrowseViewModel(
// TODO
}

/**
* refresh totalTransferSize count
*/
fun refreshTransfersSize() = setState { copy(totalTransfersSize = offlineRepository.getTotalTransfersSize()) }

@Suppress("UNUSED_PARAMETER")
private fun refresh(ignored: Entry) = refresh() // TODO: why?

Expand Down Expand Up @@ -151,9 +160,9 @@ class BrowseViewModel(

private suspend fun loadResults(path: String, item: String?, skipCount: Int, maxItems: Int): Flow<ResponsePaging> {
return when (path) {
context.getString(R.string.nav_path_recents) ->
context.getString(R.string.nav_path_recents) -> {
SearchRepository()::getRecents.asFlow(skipCount, maxItems)

}
context.getString(R.string.nav_path_favorites) ->
FavoritesRepository()::getFavorites.asFlow(skipCount, maxItems)

Expand All @@ -172,7 +181,7 @@ class BrowseViewModel(
context.getString(R.string.nav_path_folder) ->
BrowseRepository()::fetchFolderItems.asFlow(requireNotNull(item), skipCount, maxItems)

context.getString(R.string.nav_path_extension), context.getString(R.string.nav_path_folder_extension) ->
context.getString(R.string.nav_path_extension) ->
BrowseRepository()::fetchExtensionFolderItems.asFlow(requireNotNull(item), skipCount, maxItems)

context.getString(R.string.nav_path_site) ->
Expand Down Expand Up @@ -201,6 +210,22 @@ class BrowseViewModel(
}
}

/**
* observer for transfer uploads
*/
fun observeTransferUploads() {

observeTransferUploadsJob?.cancel()
observeTransferUploadsJob = OfflineRepository().observeTransferUploads()
.execute {
if (it is Success) {
updateTransferUploads(it())
} else {
this
}
}
}

override fun emptyMessageArgs(state: ListViewState) =
when ((state as BrowseViewState).path) {
context.getString(R.string.nav_path_recents) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ data class BrowseViewState(
override val hasMoreItems: Boolean = false,
override val request: Async<ResponsePaging> = Uninitialized,
val baseEntries: List<Entry> = emptyList(),
val uploads: List<Entry> = emptyList()
val uploads: List<Entry> = emptyList(),
val uploadTransferList: List<Entry> = emptyList(),
val totalTransfersSize: Int = 0
) : ListViewState {

constructor(args: BrowseArgs) : this(args.path, args.id)
Expand Down Expand Up @@ -58,6 +60,13 @@ data class BrowseViewState(
}
}

/**
* update transfer list after uploading entries to server
*/
fun updateTransferUploads(uploads: List<Entry>): BrowseViewState {
return copy(uploadTransferList = uploads)
}

private fun copyIncludingUploads(
entries: List<Entry>,
uploads: List<Entry>,
Expand Down
Loading

0 comments on commit 1ef6456

Please sign in to comment.