Skip to content

Commit

Permalink
Added values to some more elements of the transfer item view
Browse files Browse the repository at this point in the history
  • Loading branch information
JuancaG05 committed Jul 21, 2022
1 parent 413ba80 commit b52342b
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* ownCloud Android client application
*
* @author Juan Carlos Garrote Gascón
*
* Copyright (C) 2022 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.owncloud.android.extensions

import androidx.annotation.StringRes
import com.owncloud.android.R
import com.owncloud.android.domain.transfers.model.OCTransfer
import com.owncloud.android.domain.transfers.model.TransferResult
import com.owncloud.android.domain.transfers.model.TransferStatus

@StringRes
fun OCTransfer.statusToStringRes(): Int {
return when (status) {
// Really uploading, bind the progress bar to listen for progress updates
TransferStatus.TRANSFER_IN_PROGRESS -> R.string.uploader_upload_in_progress_ticker
TransferStatus.TRANSFER_SUCCEEDED -> R.string.uploads_view_upload_status_succeeded
TransferStatus.TRANSFER_QUEUED -> R.string.uploads_view_upload_status_queued
TransferStatus.TRANSFER_FAILED -> when (lastResult) {
TransferResult.CREDENTIAL_ERROR -> R.string.uploads_view_upload_status_failed_credentials_error
TransferResult.FOLDER_ERROR -> R.string.uploads_view_upload_status_failed_folder_error
TransferResult.FILE_NOT_FOUND -> R.string.uploads_view_upload_status_failed_localfile_error
TransferResult.FILE_ERROR -> R.string.uploads_view_upload_status_failed_file_error
TransferResult.PRIVILEGES_ERROR -> R.string.uploads_view_upload_status_failed_permission_error
TransferResult.NETWORK_CONNECTION -> R.string.uploads_view_upload_status_failed_connection_error
TransferResult.DELAYED_FOR_WIFI -> R.string.uploads_view_upload_status_waiting_for_wifi
TransferResult.CONFLICT_ERROR -> R.string.uploads_view_upload_status_conflict
TransferResult.SERVICE_INTERRUPTED -> R.string.uploads_view_upload_status_service_interrupted
TransferResult.SERVICE_UNAVAILABLE -> R.string.service_unavailable
TransferResult.QUOTA_EXCEEDED -> R.string.failed_upload_quota_exceeded_text
TransferResult.SSL_RECOVERABLE_PEER_UNVERIFIED -> R.string.ssl_certificate_not_trusted
TransferResult.UNKNOWN -> R.string.uploads_view_upload_status_unknown_fail
// Should not get here; cancelled uploads should be wiped out
TransferResult.CANCELLED -> R.string.uploads_view_upload_status_cancelled
// Should not get here; status should be UPLOAD_SUCCESS
TransferResult.UPLOADED -> R.string.uploads_view_upload_status_succeeded
// We don't know the specific forbidden error message because it is not being saved in transfers storage
TransferResult.SPECIFIC_FORBIDDEN -> R.string.uploader_upload_forbidden
// We don't know the specific unavailable service error message because it is not being saved in transfers storage
TransferResult.SPECIFIC_SERVICE_UNAVAILABLE -> R.string.service_unavailable
// We don't know the specific unsupported media type error message because it is not being saved in transfers storage
TransferResult.SPECIFIC_UNSUPPORTED_MEDIA_TYPE -> R.string.uploads_view_unsupported_media_type
// Should not get here; status should be not null
null -> R.string.uploads_view_upload_status_unknown_fail
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,23 @@ import android.text.format.DateUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import com.owncloud.android.R
import com.owncloud.android.authentication.AccountUtils
import com.owncloud.android.databinding.UploadListItemBinding
import com.owncloud.android.db.PreferenceManager
import com.owncloud.android.datamodel.ThumbnailsCacheManager
import com.owncloud.android.datamodel.ThumbnailsCacheManager.AsyncThumbnailDrawable
import com.owncloud.android.datamodel.ThumbnailsCacheManager.ThumbnailGenerationTask
import com.owncloud.android.domain.files.model.OCFile
import com.owncloud.android.domain.transfers.model.OCTransfer
import com.owncloud.android.domain.transfers.model.TransferStatus
import com.owncloud.android.extensions.statusToStringRes
import com.owncloud.android.lib.common.OwnCloudAccount
import com.owncloud.android.ui.activity.FileActivity
import com.owncloud.android.utils.DisplayUtils
import com.owncloud.android.utils.MimetypeIconUtil
import timber.log.Timber
import java.io.File

class TransfersAdapter : RecyclerView.Adapter<TransfersAdapter.TransferItemViewHolder>() {
Expand All @@ -56,8 +66,9 @@ class TransfersAdapter : RecyclerView.Adapter<TransfersAdapter.TransferItemViewH

uploadRemotePath.text = holder.itemView.context.getString(R.string.app_name) + remoteFile.parent

uploadFileSize.text = DisplayUtils.bytesToHumanReadable(transfer.fileSize, holder.itemView.context) + ", "
uploadFileSize.text = DisplayUtils.bytesToHumanReadable(transfer.fileSize, holder.itemView.context)

uploadDate.isVisible = transfer.transferEndTimestamp != null && transfer.status != TransferStatus.TRANSFER_FAILED
transfer.transferEndTimestamp?.let {
val dateString = DisplayUtils.getRelativeDateTimeString(
holder.itemView.context,
Expand All @@ -66,12 +77,95 @@ class TransfersAdapter : RecyclerView.Adapter<TransfersAdapter.TransferItemViewH
DateUtils.WEEK_IN_MILLIS,
0
)
uploadDate.text = dateString
uploadDate.text = ", $dateString"
}

uploadAccount.text = transfer.accountName
try {
val account = AccountUtils.getOwnCloudAccountByName(holder.itemView.context, transfer.accountName)
val oca = OwnCloudAccount(account, holder.itemView.context)
val accountName = oca.displayName + " @ " +
DisplayUtils.convertIdn(account.name.substring(account.name.lastIndexOf("@") + 1), false)
uploadAccount.text = accountName
} catch (e: Exception) {
Timber.w("Couldn't get display name for account, using old style")
uploadAccount.text = transfer.accountName
}

uploadStatus.text = transfer.status.name
uploadStatus.isVisible = transfer.status != TransferStatus.TRANSFER_SUCCEEDED
uploadStatus.text = "" + holder.itemView.context.getString(transfer.statusToStringRes())

val fakeFileToCheatThumbnailsCacheManagerInterface = OCFile(
owner = transfer.accountName,
length = transfer.fileSize,
modificationTimestamp = 0,
remotePath = transfer.remotePath,
mimeType = MimetypeIconUtil.getBestMimeTypeByFilename(transfer.localPath),
storagePath = transfer.localPath,
)
val allowedToCreateNewThumbnail = ThumbnailsCacheManager.cancelPotentialThumbnailWork(
fakeFileToCheatThumbnailsCacheManagerInterface,
thumbnail
)
val parentActivity = holder.itemView.context as FileActivity
if (fakeFileToCheatThumbnailsCacheManagerInterface.isImage
&& fakeFileToCheatThumbnailsCacheManagerInterface.remoteId != null
&& transfer.status == TransferStatus.TRANSFER_SUCCEEDED
) {
// Thumbnail in cache?
var thumbnailImage = ThumbnailsCacheManager
.getBitmapFromDiskCache(fakeFileToCheatThumbnailsCacheManagerInterface.remoteId.toString())
if (thumbnailImage != null && !fakeFileToCheatThumbnailsCacheManagerInterface.needsToUpdateThumbnail) {
thumbnail.setImageBitmap(thumbnailImage)
} else {
// Generate new thumbnail
if (allowedToCreateNewThumbnail) {
val task = ThumbnailGenerationTask(thumbnail, parentActivity.account)
if (thumbnailImage == null) {
thumbnailImage = ThumbnailsCacheManager.mDefaultImg
}
val asyncDrawable = AsyncThumbnailDrawable(
parentActivity.resources,
thumbnailImage,
task
)
thumbnail.setImageDrawable(asyncDrawable)
task.execute(fakeFileToCheatThumbnailsCacheManagerInterface)
Timber.v("Executing task to generate a new thumbnail")
}
}
if (MimetypeIconUtil.getBestMimeTypeByFilename(transfer.localPath) == "image/png") {
thumbnail.setBackgroundColor(holder.itemView.context.getColor(R.color.background_color))
}
} else if (fakeFileToCheatThumbnailsCacheManagerInterface.isImage) {
val file = File(transfer.localPath)
// Thumbnail in cache?
var thumbnailImage = ThumbnailsCacheManager.getBitmapFromDiskCache(file.hashCode().toString())
if (thumbnailImage != null) {
thumbnail.setImageBitmap(thumbnailImage)
} else {
// Generate new thumbnail
if (allowedToCreateNewThumbnail) {
val task = ThumbnailGenerationTask(thumbnail)
thumbnailImage = ThumbnailsCacheManager.mDefaultImg
val asyncDrawable = AsyncThumbnailDrawable(
parentActivity.resources,
thumbnailImage,
task
)
thumbnail.setImageDrawable(asyncDrawable)
task.execute(file)
Timber.v("Executing task to generate a new thumbnail")
}
}
if (MimetypeIconUtil.getBestMimeTypeByFilename(transfer.localPath).equals("image/png", ignoreCase = true)) {
thumbnail.setBackgroundColor(holder.itemView.context.getColor(R.color.background_color))
}
} else {
thumbnail.setImageResource(
MimetypeIconUtil.getFileTypeIconId(MimetypeIconUtil.getBestMimeTypeByFilename(transfer.localPath), fileName)
)
}
// TODO: progress bar, upload right button
}
}

Expand Down
21 changes: 9 additions & 12 deletions owncloudApp/src/main/res/layout/upload_list_item.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ListItemLayout"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:paddingTop="@dimen/standard_half_padding"
android:paddingBottom="@dimen/standard_half_padding"
android:filterTouchesWhenObscured="true"
>
android:filterTouchesWhenObscured="true">

<FrameLayout
android:layout_width="60dp"
Expand All @@ -21,7 +20,7 @@
android:layout_width="@dimen/file_icon_size"
android:layout_height="@dimen/file_icon_size"
android:layout_gravity="center"
android:src="@drawable/ic_menu_archive" />
tools:src="@drawable/ic_menu_archive" />

</FrameLayout>

Expand All @@ -41,7 +40,7 @@
android:ellipsize="middle"
android:singleLine="true"
android:textColor="@color/textColor"
android:text="@string/placeholder_filename"
tools:text="@string/placeholder_filename"
android:textSize="16sp" />

<LinearLayout
Expand All @@ -56,25 +55,23 @@
android:textColor="@color/list_item_lastmod_and_filesize_text"
android:ellipsize="middle"
android:singleLine="true"
android:text="@string/placeholder_filesize"
tools:text="@string/placeholder_filesize"
android:textSize="12sp" />

<TextView
android:id="@+id/upload_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/list_item_lastmod_and_filesize_text"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:text="@string/placeholder_timestamp"
tools:text="@string/placeholder_timestamp"
android:textSize="12sp" />

<TextView
android:id="@+id/upload_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/list_item_lastmod_and_filesize_text"
android:text="@string/uploads_view_upload_status_succeeded"
tools:text="@string/uploads_view_upload_status_succeeded"
android:textSize="12sp" />

</LinearLayout>
Expand All @@ -92,7 +89,7 @@
android:layout_height="wrap_content"
android:textColor="@color/list_item_lastmod_and_filesize_text"
android:singleLine="true"
android:text="@string/auth_username"
tools:text="@string/auth_username"
android:textSize="12dip" />

<TextView
Expand Down
1 change: 1 addition & 0 deletions owncloudApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
<string name="uploads_view_upload_status_service_interrupted">App was terminated</string>
<string name="uploads_view_upload_status_unknown_fail">Unknown error</string>
<string name="uploads_view_upload_status_waiting_for_wifi">Waiting for wifi connectivity</string>
<string name="uploads_view_upload_status_queued">Enqueued</string>
<string name="uploads_view_later_waiting_to_upload">Waiting to upload</string>
<string name="uploads_view_unsupported_media_type">Unsupported media type</string>
<string name="downloader_download_canceled_ticker">Download cancelled</string>
Expand Down

0 comments on commit b52342b

Please sign in to comment.