Skip to content

Commit

Permalink
Added ProgressBar
Browse files Browse the repository at this point in the history
Signed-off-by: Smarshal21 <[email protected]>

Added ProgressBar

Signed-off-by: Smarshal21 <[email protected]>

Added ProgressBar

Signed-off-by: Smarshal21 <[email protected]>

added progress bar

Signed-off-by: Smarshal21 <[email protected]>
  • Loading branch information
Smarshal21 committed Nov 14, 2023
1 parent bc58c8e commit 402ad77
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 16 deletions.
8 changes: 6 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 @@ -158,6 +158,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 @@ -2651,12 +2652,15 @@ class ChatActivity :

try {
require(fileUri.isNotEmpty())
UploadAndShareFilesWorker.upload(
upload(
context,
fileUri,
roomToken,
currentConversation?.displayName!!,
metaData
)
) { showProgressBar: Boolean ->
binding.idprogressbar.visibility = if (showProgressBar) View.VISIBLE else View.GONE
}
} 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 @@ -132,6 +132,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import io.reactivex.subjects.BehaviorSubject
import kotlinx.coroutines.DelicateCoroutinesApi
import org.apache.commons.lang3.builder.CompareToBuilder
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
Expand Down Expand Up @@ -1241,11 +1242,26 @@ class ConversationsListActivity :
try {
filesToShare?.forEach {
UploadAndShareFilesWorker.upload(
context,
it,
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 @@ -32,10 +32,12 @@ 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
import androidx.work.OneTimeWorkRequest
import androidx.work.WorkInfo
import androidx.work.WorkManager
import androidx.work.Worker
import androidx.work.WorkerParameters
Expand Down Expand Up @@ -323,11 +325,15 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
}

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

val data: Data = Data.Builder()
.putString(DEVICE_SOURCE_FILE, fileUri)
.putString(ROOM_TOKEN, roomToken)
Expand All @@ -337,7 +343,22 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
val uploadWorker: OneTimeWorkRequest = OneTimeWorkRequest.Builder(UploadAndShareFilesWorker::class.java)
.setInputData(data)
.build()

WorkManager.getInstance().enqueueUniqueWork(fileUri, ExistingWorkPolicy.KEEP, uploadWorker)

WorkManager.getInstance().getWorkInfoByIdLiveData(uploadWorker.id)
.observeForever { workInfo: WorkInfo? ->
if (workInfo != null && workInfo.state == WorkInfo.State.SUCCEEDED) {
progressBarCallback(false)
} else if (workInfo != null && workInfo.state == WorkInfo.State.FAILED) {
progressBarCallback(false)
showToast(context, "File upload failed")
}
}
}

private fun showToast(context: Context, message: String) {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
}
}
}
39 changes: 27 additions & 12 deletions app/src/main/res/layout/activity_chat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@
android:id="@+id/messagesListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="20dp"
android:clipToPadding="false"
android:paddingBottom="20dp"
android:visibility="gone"
app:dateHeaderTextSize="13sp"
app:incomingBubblePaddingBottom="@dimen/message_bubble_corners_vertical_padding"
Expand Down Expand Up @@ -169,11 +169,26 @@
app:outcomingTextSize="@dimen/chat_text_size"
app:outcomingTimeTextSize="12sp"
app:textAutoLink="all"
tools:visibility="visible"/>
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:theme="@style/Button.Primary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/typing_indicator_wrapper"
Expand All @@ -182,11 +197,12 @@
android:layout_marginTop="16dp"
android:layout_marginEnd="64dp"
android:layout_marginBottom="26dp"
android:minHeight="@dimen/min_size_clickable_area"
android:layout_toStartOf="@+id/scrollDownButton"
android:ellipsize="middle"
android:minHeight="@dimen/min_size_clickable_area"
android:text="@string/nc_new_messages"
android:theme="@style/Button.Primary"
app:background="@color/colorPrimary"
android:ellipsize="middle"
app:cornerRadius="@dimen/button_corner_radius"
app:icon="@drawable/ic_baseline_arrow_downward_24px" />

Expand Down Expand Up @@ -226,9 +242,9 @@
android:id="@+id/typing_indicator_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:layout_marginBottom="-19dp">
android:layout_marginBottom="-19dp"
android:orientation="vertical">

<View
android:id="@+id/separator_1"
Expand All @@ -240,15 +256,14 @@
android:id="@+id/typing_indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="2"
android:ellipsize="end"
android:layout_marginStart="@dimen/side_margin"
android:layout_marginEnd="@dimen/side_margin"
android:background="@color/bg_default"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/low_emphasis_text"
tools:text="Marcel is typing"
tools:ignore="Overdraw">
</TextView>
tools:ignore="Overdraw"
tools:text="Marcel is typing"></TextView>

</LinearLayout>

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 @@ -468,6 +468,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

0 comments on commit 402ad77

Please sign in to comment.