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

Added a ProgressBar to display while uploading Pics/Files #3443

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ import com.nextcloud.talk.extensions.loadAvatarOrImagePreview
import com.nextcloud.talk.jobs.DownloadFileToCacheWorker
import com.nextcloud.talk.jobs.ShareOperationWorker
import com.nextcloud.talk.jobs.UploadAndShareFilesWorker
import com.nextcloud.talk.jobs.UploadAndShareFilesWorker.Companion.upload
import com.nextcloud.talk.location.LocationPickerActivity
import com.nextcloud.talk.messagesearch.MessageSearchActivity
import com.nextcloud.talk.models.domain.ConversationModel
Expand Down Expand Up @@ -3254,12 +3255,14 @@ class ChatActivity :

try {
require(fileUri.isNotEmpty())
UploadAndShareFilesWorker.upload(
upload(
fileUri,
room,
currentConversation?.displayName!!,
metaData
)
) { showProgressBar: Boolean ->
binding.idprogressbar.visibility = if (showProgressBar) View.VISIBLE else View.GONE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
binding.idprogressbar.visibility = if (showProgressBar) View.VISIBLE else View.GONE
binding.idprogressbar.visibility = if (showProgressBar) View.VISIBLE else {
chatViewModel.refreshChatParams(
setupFieldsForPullChatMessages(
true,
globalLastKnownFutureMessageId,
true
)
)
View.GONE
}

Breaks with the recent refactoring of ChatActivity. Insert this line to fix it, so that uploaded files show up after sending.

}
} catch (e: IllegalArgumentException) {
context.resources?.getString(R.string.nc_upload_failed)?.let {
Snackbar.make(binding.root, it, Snackbar.LENGTH_LONG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,21 @@ class ConversationsListActivity :
selectedConversation!!.token!!,
selectedConversation!!.displayName!!,
null
)
) { success ->
if (success) {
Snackbar.make(
binding.root,
context.resources.getString(R.string.nc_upload_success),
Snackbar.LENGTH_LONG
).show()
} else {
Snackbar.make(
binding.root,
context.resources.getString(R.string.nc_upload_failed),
Snackbar.LENGTH_LONG
).show()
}
}
}
} catch (e: IllegalArgumentException) {
Snackbar.make(binding.root, context.resources.getString(R.string.nc_upload_failed), Snackbar.LENGTH_LONG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import android.os.Build
import android.os.Bundle
import android.os.SystemClock
import android.util.Log
import android.widget.Toast
import androidx.core.app.NotificationCompat
import androidx.work.Data
import androidx.work.ExistingWorkPolicy
Expand All @@ -35,13 +36,13 @@ import com.nextcloud.talk.upload.chunked.ChunkedFileUploader
import com.nextcloud.talk.upload.chunked.OnDataTransferProgressListener
import com.nextcloud.talk.upload.normal.FileUploader
import com.nextcloud.talk.users.UserManager
import com.nextcloud.talk.utils.CapabilitiesUtil
import com.nextcloud.talk.utils.FileUtils
import com.nextcloud.talk.utils.NotificationUtils
import com.nextcloud.talk.utils.RemoteFileUtils
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_FROM_NOTIFICATION_START_CALL
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_INTERNAL_USER_ID
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN
import com.nextcloud.talk.utils.CapabilitiesUtil
import com.nextcloud.talk.utils.permissions.PlatformPermissionUtil
import com.nextcloud.talk.utils.preferences.AppPreferences
import okhttp3.MediaType.Companion.toMediaTypeOrNull
Expand Down Expand Up @@ -382,7 +383,15 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
}
}

fun upload(fileUri: String, roomToken: String, conversationName: String, metaData: String?) {
fun upload(
fileUri: String,
roomToken: String,
conversationName: String,
metaData: String?,
progressBarCallback: (Boolean) -> Unit
) {
progressBarCallback(true)

val data: Data = Data.Builder()
.putString(DEVICE_SOURCE_FILE, fileUri)
.putString(ROOM_TOKEN, roomToken)
Expand All @@ -395,4 +404,8 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
WorkManager.getInstance().enqueueUniqueWork(fileUri, ExistingWorkPolicy.KEEP, uploadWorker)
}
}

private fun showToast(context: Context, message: String) {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
}
}
16 changes: 16 additions & 0 deletions app/src/main/res/layout/activity_chat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,22 @@
app:textAutoLink="all"
tools:visibility="visible" />

<LinearLayout
android:id="@+id/idprogressbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:gravity="center_vertical"
android:orientation="vertical"
android:visibility="gone"
tools:visibility="visible">

<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</LinearLayout>

<com.nextcloud.ui.popupbubble.PopupBubble
android:id="@+id/popupBubbleView"
android:layout_width="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ How to translate with transifex:
<string name="nc_upload_video_from_cam">Take video</string>
<string name="nc_create_poll">Create poll</string>
<string name="nc_upload_from_cloud">Share from %1$s</string>
<string name="nc_upload_success">Upload Succeeded</string>
<string name="nc_upload_failed">Sorry, upload failed</string>
<string name="nc_upload_choose_local_files">Choose files</string>
<string name="nc_upload_confirm_send_multiple">Send these files to %1$s?</string>
Expand Down
Loading