issue 2931 - follow up fixes

Signed-off-by: Julius Linus <juliuslinus1@gmail.com>
This commit is contained in:
rapterjet2004 2023-05-17 15:43:08 -05:00
parent 22b7b8e68a
commit 7f33b7fdfd
2 changed files with 40 additions and 39 deletions

View File

@ -60,26 +60,39 @@ class TranslateActivity : BaseActivity() {
@Inject @Inject
lateinit var userManager: UserManager lateinit var userManager: UserManager
var fromLanguages = arrayOf<String>() private var fromLanguages = arrayOf<String>()
private var toLanguages = arrayOf<String>()
var toLanguages = arrayOf<String>() private var text: String? = null
var text: String? = null
var check: Int = 0
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
binding = ActivityTranslateBinding.inflate(layoutInflater) binding = ActivityTranslateBinding.inflate(layoutInflater)
setupActionBar() setupActionBar()
setContentView(binding.root) setContentView(binding.root)
setupSystemColors() setupSystemColors()
setupTextViews() setupTextViews()
setupSpinners() setupSpinners()
getLanguageOptions() getLanguageOptions()
if(savedInstanceState == null)
{
translate(null, Locale.getDefault().language) translate(null, Locale.getDefault().language)
} else {
binding.translatedMessageTextview.text = savedInstanceState.getString(BundleKeys.SAVED_TRANSLATED_MESSAGE)
}
}
override fun onResume() {
super.onResume()
setItems()
}
override fun onSaveInstanceState(outState: Bundle) {
outState.run {
putString(BundleKeys.SAVED_TRANSLATED_MESSAGE, binding.translatedMessageTextview.text.toString())
}
super.onSaveInstanceState(outState)
} }
private fun setupActionBar() { private fun setupActionBar() {
@ -127,7 +140,6 @@ class TranslateActivity : BaseActivity() {
fromLanguages = fromLanguagesSet.toTypedArray() fromLanguages = fromLanguagesSet.toTypedArray()
toLanguages = toLanguagesSet.toTypedArray() toLanguages = toLanguagesSet.toTypedArray()
fillSpinners() fillSpinners()
} }
@ -146,7 +158,6 @@ class TranslateActivity : BaseActivity() {
fromLanguage fromLanguage
} }
Log.i(TAG, "Url is: $translateURL")
ncApi.translateMessage(credentials, translateURL, text, toLanguage, calculatedFromLanguage) ncApi.translateMessage(credentials, translateURL, text, toLanguage, calculatedFromLanguage)
?.subscribeOn(Schedulers.io()) ?.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread()) ?.observeOn(AndroidSchedulers.mainThread())
@ -197,7 +208,7 @@ class TranslateActivity : BaseActivity() {
} }
private fun getISOFromLanguage(language: String): String { private fun getISOFromLanguage(language: String): String {
if (resources.getString(R.string.translation_device_settings).equals(language)) { if (resources.getString(R.string.translation_device_settings) == language) {
return Locale.getDefault().language return Locale.getDefault().language
} }
@ -208,7 +219,7 @@ class TranslateActivity : BaseActivity() {
val currentUser: User = userManager.currentUser.blockingGet() val currentUser: User = userManager.currentUser.blockingGet()
val json = JSONArray(CapabilitiesUtilNew.getLanguages(currentUser).toString()) val json = JSONArray(CapabilitiesUtilNew.getLanguages(currentUser).toString())
for (i in 0..json.length() - 1) { for (i in 0 until json.length()) {
val current = json.getJSONObject(i) val current = json.getJSONObject(i)
if (current.getString(FROM_LABEL) == language) { if (current.getString(FROM_LABEL) == language) {
return current.getString(FROM_ID) return current.getString(FROM_ID)
@ -223,35 +234,19 @@ class TranslateActivity : BaseActivity() {
viewThemeUtils.material.colorTextInputLayout(binding.toLanguageInputLayout) viewThemeUtils.material.colorTextInputLayout(binding.toLanguageInputLayout)
fillSpinners() fillSpinners()
binding.fromLanguage.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { binding.fromLanguage.onItemClickListener = AdapterView.OnItemClickListener { parent, _, position, _ ->
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
if (++check > 1) {
val fromLabel: String = getISOFromLanguage(parent.getItemAtPosition(position).toString()) val fromLabel: String = getISOFromLanguage(parent.getItemAtPosition(position).toString())
val toLabel: String = getISOFromLanguage(binding.fromLanguage.text.toString()) val toLabel: String = getISOFromLanguage(binding.toLanguage.text.toString())
Log.i(TAG, "fromLanguageSpinner :: $FROM_LABEL = $fromLabel, $TO_LABEL = $ count: $check")
translate(fromLabel, toLabel) translate(fromLabel, toLabel)
} }
}
override fun onNothingSelected(parent: AdapterView<*>) { binding.toLanguage.onItemClickListener = AdapterView.OnItemClickListener { parent, _, position, _ ->
// write code to perform some action
}
}
binding.toLanguage.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
if (++check > 2) {
val toLabel: String = getISOFromLanguage(parent.getItemAtPosition(position).toString()) val toLabel: String = getISOFromLanguage(parent.getItemAtPosition(position).toString())
val fromLabel: String = getISOFromLanguage(binding.fromLanguage.text.toString()) val fromLabel: String = getISOFromLanguage(binding.fromLanguage.text.toString())
Log.i(TAG, "toLanguageSpinner :: $FROM_LABEL = $fromLabel, $TO_LABEL = $toLabel count: $check")
translate(fromLabel, toLabel) translate(fromLabel, toLabel)
} }
}
override fun onNothingSelected(parent: AdapterView<*>) {
// write code to perform some action
}
}
} }
private fun fillSpinners() { private fun fillSpinners() {
@ -270,6 +265,11 @@ class TranslateActivity : BaseActivity() {
} }
} }
private fun setItems() {
binding.fromLanguage.setSimpleItems(fromLanguages)
binding.toLanguage.setSimpleItems(toLanguages)
}
companion object { companion object {
private val TAG = TranslateActivity::class.simpleName private val TAG = TranslateActivity::class.simpleName
private const val FROM_ID = "from" private const val FROM_ID = "from"

View File

@ -89,4 +89,5 @@ object BundleKeys {
const val KEY_SHARE_RECORDING_TO_CHAT_URL = "KEY_SHARE_RECORDING_TO_CHAT_URL" const val KEY_SHARE_RECORDING_TO_CHAT_URL = "KEY_SHARE_RECORDING_TO_CHAT_URL"
const val KEY_GEOCODING_RESULT = "KEY_GEOCODING_RESULT" const val KEY_GEOCODING_RESULT = "KEY_GEOCODING_RESULT"
const val ADD_ACCOUNT = "ADD_ACCOUNT" // temp workaround until conductor is removed const val ADD_ACCOUNT = "ADD_ACCOUNT" // temp workaround until conductor is removed
const val SAVED_TRANSLATED_MESSAGE = "SAVED_TRANSLATED_MESSAGE"
} }