mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-21 20:45:29 +03:00
Start unique work
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
e04f2362e3
commit
088e6fd79f
3 changed files with 47 additions and 16 deletions
|
@ -21,13 +21,16 @@ import android.view.MenuItem
|
|||
import android.view.View
|
||||
import android.view.View.GONE
|
||||
import android.view.View.VISIBLE
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.fragment.app.FragmentTransaction
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.work.Data
|
||||
import androidx.work.ExistingWorkPolicy
|
||||
import androidx.work.OneTimeWorkRequest
|
||||
import androidx.work.WorkInfo
|
||||
import androidx.work.WorkManager
|
||||
import autodagger.AutoInjector
|
||||
import com.afollestad.materialdialogs.LayoutMode.WRAP_CONTENT
|
||||
|
@ -635,17 +638,40 @@ class ConversationInfoActivity :
|
|||
}
|
||||
|
||||
private fun leaveConversation() {
|
||||
workerData?.let {
|
||||
WorkManager.getInstance(context).enqueue(
|
||||
OneTimeWorkRequest.Builder(
|
||||
LeaveConversationWorker::class
|
||||
.java
|
||||
).setInputData(it).build()
|
||||
)
|
||||
workerData?.let { data ->
|
||||
val workRequest = OneTimeWorkRequest.Builder(LeaveConversationWorker::class.java)
|
||||
.setInputData(data)
|
||||
.build()
|
||||
|
||||
val intent = Intent(context, MainActivity::class.java)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
startActivity(intent)
|
||||
|
||||
WorkManager.getInstance(context)
|
||||
.enqueueUniqueWork(
|
||||
"leave_conversation_work",
|
||||
ExistingWorkPolicy.REPLACE,
|
||||
workRequest
|
||||
)
|
||||
|
||||
|
||||
WorkManager.getInstance(context).getWorkInfoByIdLiveData(workRequest.id)
|
||||
.observe(this, { workInfo: WorkInfo? ->
|
||||
if (workInfo != null) {
|
||||
when (workInfo.state) {
|
||||
WorkInfo.State.SUCCEEDED -> {
|
||||
|
||||
val intent = Intent(context, MainActivity::class.java)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
startActivity(intent)
|
||||
}
|
||||
WorkInfo.State.FAILED -> {
|
||||
|
||||
Toast.makeText(context, R.string.nc_last_moderator_leaving_room_warning, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
else -> {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ import androidx.work.WorkerParameters
|
|||
import autodagger.AutoInjector
|
||||
import com.nextcloud.talk.api.NcApi
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
|
||||
import com.nextcloud.talk.models.json.generic.GenericOverall
|
||||
import com.nextcloud.talk.users.UserManager
|
||||
import com.nextcloud.talk.utils.ApiUtils
|
||||
|
@ -39,10 +38,10 @@ class LeaveConversationWorker(val context: Context, workerParams: WorkerParamete
|
|||
|
||||
|
||||
override fun doWork(): Result {
|
||||
sharedApplication!!.componentApplication.inject(this)
|
||||
val data = inputData
|
||||
val conversationToken = data.getString(BundleKeys.KEY_ROOM_TOKEN)
|
||||
val currentUser = userManager.currentUser.blockingGet()
|
||||
lateinit var workResult:Result
|
||||
|
||||
if (currentUser != null) {
|
||||
val credentials = getCredentials(currentUser.username, currentUser.token)
|
||||
|
@ -58,10 +57,9 @@ class LeaveConversationWorker(val context: Context, workerParams: WorkerParamete
|
|||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe(object : Observer<GenericOverall?> {
|
||||
var disposable: Disposable? = null
|
||||
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
disposable = d
|
||||
|
||||
}
|
||||
|
||||
override fun onNext(p0: GenericOverall) {
|
||||
|
@ -70,15 +68,19 @@ class LeaveConversationWorker(val context: Context, workerParams: WorkerParamete
|
|||
|
||||
override fun onError(e: Throwable) {
|
||||
Log.e(TAG, "failed to remove self from room", e)
|
||||
if(e.message?.contains("HTTP 400") == true){
|
||||
workResult = Result.failure()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
disposable!!.dispose()
|
||||
workResult = Result.success()
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return Result.success()
|
||||
return workResult
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -505,6 +505,9 @@ How to translate with transifex:
|
|||
<string name="nc_delete_message">Delete</string>
|
||||
<string name="nc_delete_message_leaked_to_matterbridge">Message deleted successfully, but it might have been leaked to other services</string>
|
||||
<string name="startCallForbidden">You are not allowed to start a call</string>
|
||||
<string name="nc_last_moderator_leaving_room_warning">
|
||||
You need to promote a new moderator before you can leave the conversation
|
||||
</string>
|
||||
|
||||
<string name="share">Share</string>
|
||||
<string name="send_to">Send to</string>
|
||||
|
|
Loading…
Reference in a new issue