mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-23 13:35:33 +03:00
issue 2931 progress
Signed-off-by: Julius Linus <juliuslinus1@gmail.com> Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
0168be395a
commit
9e9c6e81b9
1 changed files with 49 additions and 42 deletions
|
@ -2,14 +2,23 @@ package com.nextcloud.talk.translate
|
|||
import android.graphics.drawable.ColorDrawable
|
||||
import android.os.Bundle
|
||||
import android.text.method.ScrollingMovementMethod
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import autodagger.AutoInjector
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.activities.BaseActivity
|
||||
import com.nextcloud.talk.api.NcApi
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||
import com.nextcloud.talk.data.user.model.User
|
||||
import com.nextcloud.talk.databinding.ActivityTranslateBinding
|
||||
import com.nextcloud.talk.models.json.translations.TranslationsOverall
|
||||
import com.nextcloud.talk.users.UserManager
|
||||
import com.nextcloud.talk.utils.ApiUtils
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys
|
||||
import io.reactivex.Observer
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
|
@ -28,9 +37,7 @@ class TranslateActivity : BaseActivity()
|
|||
@Inject
|
||||
lateinit var userManager: UserManager
|
||||
|
||||
// lateinit var currentUser: User
|
||||
|
||||
// val url : String? = currentUser.baseUrl + "/translation"
|
||||
lateinit var currentUser : User
|
||||
|
||||
var text : String? = null
|
||||
|
||||
|
@ -41,15 +48,12 @@ class TranslateActivity : BaseActivity()
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityTranslateBinding.inflate(layoutInflater)
|
||||
val bundle = intent.extras
|
||||
binding.originalMessageTextview.text = bundle?.getString(BundleKeys.KEY_TRANSLATE_MESSAGE)
|
||||
text = binding.originalMessageTextview.text as String?
|
||||
|
||||
currentUser = userManager.currentUser.blockingGet()
|
||||
setupTextViews()
|
||||
setupActionBar()
|
||||
setupSpinners()
|
||||
setContentView(binding.root)
|
||||
// translate()
|
||||
translate()
|
||||
}
|
||||
|
||||
private fun setupActionBar() {
|
||||
|
@ -71,6 +75,10 @@ class TranslateActivity : BaseActivity()
|
|||
original.movementMethod = ScrollingMovementMethod()
|
||||
translation.movementMethod = ScrollingMovementMethod()
|
||||
|
||||
val bundle = intent.extras
|
||||
binding.originalMessageTextview.text = bundle?.getString(BundleKeys.KEY_TRANSLATE_MESSAGE)
|
||||
text = binding.originalMessageTextview.text as String?
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -82,40 +90,39 @@ class TranslateActivity : BaseActivity()
|
|||
}
|
||||
|
||||
// TODO get this function working
|
||||
// private fun translate() {
|
||||
// val credentials = ApiUtils.getCredentials(currentUser.username, currentUser.token)
|
||||
//
|
||||
// val translateURL = url + "/translate"
|
||||
//
|
||||
//
|
||||
//
|
||||
// ncApi.translateMessage(credentials, translateURL, text, fromLanguage, toLanguage)
|
||||
// ?.subscribeOn(Schedulers.io())
|
||||
// ?.observeOn(AndroidSchedulers.mainThread())
|
||||
// ?.subscribe(object : Observer<TranslationsOverall> {
|
||||
// override fun onSubscribe(d: Disposable) {
|
||||
// // TODO set progress bar to show
|
||||
// binding.translatedMessageTextview.visibility = View.GONE
|
||||
// binding.progressBar.visibility = View.VISIBLE
|
||||
// }
|
||||
//
|
||||
// override fun onNext(translationOverall: TranslationsOverall) {
|
||||
// // TODO hide progress bar
|
||||
// binding.progressBar.visibility = View.GONE
|
||||
// binding.translatedMessageTextview.visibility = View.VISIBLE
|
||||
// binding.translatedMessageTextview.text = translationOverall.ocs?.data?.text
|
||||
// }
|
||||
//
|
||||
// override fun onError(e: Throwable) {
|
||||
// Log.e("TranslateActivity", "Error")
|
||||
// }
|
||||
//
|
||||
// override fun onComplete() {
|
||||
// // not needed?
|
||||
// }
|
||||
// })
|
||||
//
|
||||
// }
|
||||
private fun translate() {
|
||||
val credentials = ApiUtils.getCredentials(currentUser.username, currentUser.token)
|
||||
val translateURL = currentUser.baseUrl + "/translation" + "/translate"
|
||||
|
||||
|
||||
|
||||
ncApi.translateMessage(credentials, translateURL, text, fromLanguage, toLanguage)
|
||||
?.subscribeOn(Schedulers.io())
|
||||
?.observeOn(AndroidSchedulers.mainThread())
|
||||
?.subscribe(object : Observer<TranslationsOverall> {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
// TODO set progress bar to show
|
||||
binding.translatedMessageTextview.visibility = View.GONE
|
||||
binding.progressBar.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
override fun onNext(translationOverall: TranslationsOverall) {
|
||||
// TODO hide progress bar
|
||||
binding.progressBar.visibility = View.GONE
|
||||
binding.translatedMessageTextview.visibility = View.VISIBLE
|
||||
binding.translatedMessageTextview.text = translationOverall.ocs?.data?.text
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
Log.e("TranslateActivity", "Error")
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
// not needed?
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
private fun setupSpinners() {
|
||||
// TODO set spinner options to use array from getLanguageOptions()
|
||||
|
|
Loading…
Reference in a new issue