Add licence headers and optimize/theme translation layout

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2023-05-17 09:35:42 +02:00
parent 5bc0f82398
commit ac0f8608a7
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
11 changed files with 272 additions and 106 deletions

View File

@ -3239,7 +3239,6 @@ class ChatActivity :
val intent = Intent(this, TranslateActivity::class.java)
intent.putExtras(bundle)
startActivity(intent)
}
private fun hasVisibleItems(message: ChatMessage): Boolean {

View File

@ -1,3 +1,22 @@
/*
* Nextcloud Talk application
*
* @author Julius Linus
* Copyright (C) 2023 Julius Linus <julius.linus@nextcloud.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.models.json.translations
import android.os.Parcelable

View File

@ -1,3 +1,22 @@
/*
* Nextcloud Talk application
*
* @author Julius Linus
* Copyright (C) 2023 Julius Linus <julius.linus@nextcloud.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.models.json.translations
import android.os.Parcelable

View File

@ -1,3 +1,22 @@
/*
* Nextcloud Talk application
*
* @author Julius Linus
* Copyright (C) 2023 Julius Linus <julius.linus@nextcloud.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.models.json.translations
import android.os.Parcelable
@ -10,7 +29,7 @@ import kotlinx.parcelize.Parcelize
class TranslationsOverall(
@JsonField(name = ["ocs"])
var ocs: TranslateOCS?
) : Parcelable {
// This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
constructor() : this(null)
}
) : Parcelable {
// This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
constructor() : this(null)
}

View File

@ -1,4 +1,24 @@
/*
* Nextcloud Talk application
*
* @author Julius Linus
* Copyright (C) 2023 Julius Linus <julius.linus@nextcloud.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.translate
import android.app.AlertDialog
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
@ -27,14 +47,8 @@ import org.json.JSONArray
import java.util.Locale
import javax.inject.Inject
// TODO include license at top of the file
@AutoInjector(NextcloudTalkApplication::class)
class TranslateActivity : BaseActivity()
{
class TranslateActivity : BaseActivity() {
private lateinit var binding: ActivityTranslateBinding
@Inject
@ -47,10 +61,9 @@ class TranslateActivity : BaseActivity()
var toLanguages = arrayOf<String>()
var text : String? = null
var check : Int = 0
var text: String? = null
var check: Int = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -59,6 +72,7 @@ class TranslateActivity : BaseActivity()
setupActionBar()
setContentView(binding.root)
setupSystemColors()
setupTextViews()
setupSpinners()
getLanguageOptions()
@ -73,7 +87,7 @@ class TranslateActivity : BaseActivity()
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)
supportActionBar?.setIcon(ColorDrawable(resources!!.getColor(R.color.transparent)))
supportActionBar?.title = "Translation"
supportActionBar?.title = resources!!.getString(R.string.translation)
viewThemeUtils.material.themeToolbar(binding.translationToolbar)
}
@ -81,6 +95,9 @@ class TranslateActivity : BaseActivity()
val original = binding.originalMessageTextview
val translation = binding.translatedMessageTextview
viewThemeUtils.talk.themeIncomingMessageBubble(original, grouped = true, deleted = false)
viewThemeUtils.talk.themeIncomingMessageBubble(translation, grouped = true, deleted = false)
original.movementMethod = ScrollingMovementMethod()
translation.movementMethod = ScrollingMovementMethod()
@ -89,19 +106,17 @@ class TranslateActivity : BaseActivity()
text = bundle?.getString(BundleKeys.KEY_TRANSLATE_MESSAGE)
}
private fun getLanguageOptions() {
val currentUser : User = userManager.currentUser.blockingGet()
val json = JSONArray(CapabilitiesUtilNew.getLanguages(currentUser).toString())
Log.i("TranslateActivity", "json is: ${json.toString()}")
val currentUser: User = userManager.currentUser.blockingGet()
val json = JSONArray(CapabilitiesUtilNew.getLanguages(currentUser).toString())
Log.i("TranslateActivity", "json is: $json")
var fromLanguagesSet = mutableSetOf<String>("Detect Language")
var toLanguagesSet = mutableSetOf<String>("Device Settings")
val fromLanguagesSet = mutableSetOf("Detect Language")
val toLanguagesSet = mutableSetOf("Device Settings")
for( i in 0..json.length()-1) {
for (i in 0..json.length() - 1) {
val current = json.getJSONObject(i)
if(current.getString("from") != Locale.getDefault().language)
{
if (current.getString("from") != Locale.getDefault().language) {
toLanguagesSet.add(current.getString("fromLabel"))
}
@ -111,25 +126,32 @@ class TranslateActivity : BaseActivity()
fromLanguages = fromLanguagesSet.toTypedArray()
toLanguages = toLanguagesSet.toTypedArray()
binding.fromLanguageSpinner.adapter = ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item,
fromLanguages)
binding.toLanguageSpinner.adapter = ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item,
toLanguages)
binding.fromLanguageSpinner.adapter = ArrayAdapter(
this, android.R.layout.simple_spinner_dropdown_item,
fromLanguages
)
binding.toLanguageSpinner.adapter = ArrayAdapter(
this, android.R.layout.simple_spinner_dropdown_item,
toLanguages
)
}
private fun enableSpinners(value : Boolean) {
private fun enableSpinners(value: Boolean) {
binding.fromLanguageSpinner.isEnabled = value
binding.toLanguageSpinner.isEnabled = value
}
private fun translate(fromLanguage: String?, toLanguage : String) {
val currentUser : User = userManager.currentUser.blockingGet()
val credentials : String = ApiUtils.getCredentials(currentUser.username, currentUser.token)
private fun translate(fromLanguage: String?, toLanguage: String) {
val currentUser: User = userManager.currentUser.blockingGet()
val credentials: String = ApiUtils.getCredentials(currentUser.username, currentUser.token)
val translateURL = currentUser.baseUrl +
"/ocs/v2.php/translation/translate?text=$text&toLanguage=$toLanguage" +
if(fromLanguage != null && fromLanguage != "") { "&fromLanguage=$fromLanguage" } else {""}
if (fromLanguage != null && fromLanguage != "") {
"&fromLanguage=$fromLanguage"
} else {
""
}
Log.i("TranslateActivity", "Url is: $translateURL")
ncApi.translateMessage(credentials, translateURL)
@ -165,17 +187,15 @@ class TranslateActivity : BaseActivity()
enableSpinners(true)
}
private fun getISOFromLanguage(language: String) : String {
if(language == "Device Settings") {
private fun getISOFromLanguage(language: String): String {
if (language == "Device Settings") {
return Locale.getDefault().language
}
val currentUser: User = userManager.currentUser.blockingGet()
val json = JSONArray(CapabilitiesUtilNew.getLanguages(currentUser).toString())
val currentUser : User = userManager.currentUser.blockingGet()
val json = JSONArray(CapabilitiesUtilNew.getLanguages(currentUser).toString())
for( i in 0..json.length()-1) {
for (i in 0..json.length() - 1) {
val current = json.getJSONObject(i)
if (current.getString("fromLabel") == language) {
return current.getString("from")
@ -185,20 +205,25 @@ class TranslateActivity : BaseActivity()
return ""
}
private fun setupSpinners() {
binding.fromLanguageSpinner.adapter = ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item,
fromLanguages)
binding.toLanguageSpinner.adapter = ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item,
toLanguages)
binding.fromLanguageSpinner.adapter = ArrayAdapter(
this, android.R.layout.simple_spinner_dropdown_item,
fromLanguages
)
binding.toLanguageSpinner.adapter = ArrayAdapter(
this, android.R.layout.simple_spinner_dropdown_item,
toLanguages
)
binding.fromLanguageSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
if(++check > 1) {
var fromLabel : String = getISOFromLanguage(parent.getItemAtPosition(position).toString())
var toLabel : String = getISOFromLanguage(binding.toLanguageSpinner.selectedItem.toString())
Log.i("TranslateActivity", "fromLanguageSpinner :: fromLabel = $fromLabel, toLabel = $ count: " +
"$check")
if (++check > 1) {
val fromLabel: String = getISOFromLanguage(parent.getItemAtPosition(position).toString())
val toLabel: String = getISOFromLanguage(binding.toLanguageSpinner.selectedItem.toString())
Log.i(
"TranslateActivity", "fromLanguageSpinner :: fromLabel = $fromLabel, toLabel = $ count: " +
"$check"
)
translate(fromLabel, toLabel)
}
}
@ -210,11 +235,13 @@ class TranslateActivity : BaseActivity()
binding.toLanguageSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
if(++check > 2) {
var toLabel : String = getISOFromLanguage(parent.getItemAtPosition(position).toString())
var fromLabel : String = getISOFromLanguage(binding.fromLanguageSpinner.selectedItem.toString())
Log.i("TranslateActivity", "toLanguageSpinner :: fromLabel = $fromLabel, toLabel = $toLabel " +
"count: $check")
if (++check > 2) {
val toLabel: String = getISOFromLanguage(parent.getItemAtPosition(position).toString())
val fromLabel: String = getISOFromLanguage(binding.fromLanguageSpinner.selectedItem.toString())
Log.i(
"TranslateActivity", "toLanguageSpinner :: fromLabel = $fromLabel, toLabel = $toLabel " +
"count: $check"
)
translate(fromLabel, toLabel)
}
}
@ -223,8 +250,5 @@ class TranslateActivity : BaseActivity()
// write code to perform some action
}
}
}
}

View File

@ -65,7 +65,7 @@ class TalkSpecificViewThemeUtils @Inject constructor(
private val appcompat: AndroidXViewThemeUtils
) :
ViewThemeUtilsBase(schemes) {
fun themeIncomingMessageBubble(bubble: ViewGroup, grouped: Boolean, deleted: Boolean) {
fun themeIncomingMessageBubble(bubble: View, grouped: Boolean, deleted: Boolean) {
val resources = bubble.resources
var bubbleResource = R.drawable.shape_incoming_message
@ -88,7 +88,7 @@ class TalkSpecificViewThemeUtils @Inject constructor(
ViewCompat.setBackground(bubble, bubbleDrawable)
}
fun themeOutgoingMessageBubble(bubble: ViewGroup, grouped: Boolean, deleted: Boolean) {
fun themeOutgoingMessageBubble(bubble: View, grouped: Boolean, deleted: Boolean) {
withScheme(bubble) { scheme ->
val bgBubbleColor = if (deleted) {
ColorUtils.setAlphaComponent(scheme.surfaceVariant, HALF_ALPHA_INT)

View File

@ -219,7 +219,5 @@ object CapabilitiesUtilNew {
return null
}
const val DEFAULT_CHAT_SIZE = 1000
}

View File

@ -0,0 +1,25 @@
<!--
@author Google LLC
Copyright (C) 2023 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="#61FFFFFF"
android:pathData="M376,720L320,664L504,480L320,296L376,240L616,480L376,720Z"/>
</vector>

View File

@ -1,5 +1,26 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12.87,15.07l-2.54,-2.51 0.03,-0.03c1.74,-1.94 2.98,-4.17 3.71,-6.53L17,6L17,4h-7L10,2L8,2v2L1,4v1.99h11.17C11.5,7.92 10.44,9.75 9,11.35 8.07,10.32 7.3,9.19 6.69,8h-2c0.73,1.63 1.73,3.17 2.98,4.56l-5.09,5.02L4,19l5,-5 3.11,3.11 0.76,-2.04zM18.5,10h-2L12,22h2l1.12,-3h4.75L21,22h2l-4.5,-12zM15.88,17l1.62,-4.33L19.12,17h-3.24z"/>
<!--
@author Google LLC
Copyright (C) 2023 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#000000"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M12.87,15.07l-2.54,-2.51 0.03,-0.03c1.74,-1.94 2.98,-4.17 3.71,-6.53L17,6L17,4h-7L10,2L8,2v2L1,4v1.99h11.17C11.5,7.92 10.44,9.75 9,11.35 8.07,10.32 7.3,9.19 6.69,8h-2c0.73,1.63 1.73,3.17 2.98,4.56l-5.09,5.02L4,19l5,-5 3.11,3.11 0.76,-2.04zM18.5,10h-2L12,22h2l1.12,-3h4.75L21,22h2l-4.5,-12zM15.88,17l1.62,-4.33L19.12,17h-3.24z" />
</vector>

View File

@ -0,0 +1,25 @@
<!--
@author Google LLC
Copyright (C) 2023 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="#61000000"
android:pathData="M376,720L320,664L504,480L320,296L376,240L616,480L376,720Z"/>
</vector>

View File

@ -1,16 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Nextcloud Talk application
~
~ @author Julius Linus
~ Copyright (C) 2023 Julius Linus <julius.linus@nextcloud.com>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:weightSum="2"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/translation_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/translation_toolbar"
android:layout_width="match_parent"
@ -21,44 +41,38 @@
app:navigationIconTint="@color/fontAppbar"
app:popupTheme="@style/appActionBarPopupMenu"
app:titleTextColor="@color/fontAppbar"
tools:title="" >
tools:title="">
</com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.AppBarLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal"
android:padding="@dimen/standard_padding">
<Spinner
android:id="@+id/fromLanguageSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/grey_200"
android:layout_marginRight="@dimen/standard_margin"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:backgroundTint="@color/medium_emphasis_text"
android:background="@drawable/ic_chevron_right"
/>
android:layout_height="@dimen/min_size_clickable_area"
android:layout_weight="1"
android:background="@color/grey_200" />
<ImageView
android:layout_width="@dimen/min_size_clickable_area"
android:layout_height="@dimen/min_size_clickable_area"
android:contentDescription="@null"
android:src="@drawable/ic_chevron_right" />
<Spinner
android:id="@+id/toLanguageSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/fromLanguageSpinner"
android:background="@color/grey_200"
android:layout_marginLeft="@dimen/standard_margin"
/>
android:layout_height="@dimen/min_size_clickable_area"
android:layout_weight="1"
android:background="@color/grey_200" />
</LinearLayout>
@ -66,27 +80,31 @@
android:id="@+id/original_message_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/standard_margin"
android:layout_marginEnd="@dimen/standard_margin"
android:layout_marginBottom="@dimen/standard_margin"
android:layout_weight="1"
android:textSize="@dimen/message_text_size"
android:textColor="@color/nc_incoming_text_default"
android:padding="@dimen/dialog_padding"
android:layout_margin="@dimen/standard_margin"
android:background="@drawable/shape_grouped_incoming_message"
android:padding="@dimen/dialog_padding"
android:scrollbars="vertical"
android:text="" />
android:text=""
android:textColor="@color/nc_incoming_text_default"
android:textSize="@dimen/message_text_size" />
<TextView
android:id="@+id/translated_message_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/standard_margin"
android:layout_marginStart="@dimen/standard_margin"
android:layout_marginEnd="@dimen/standard_margin"
android:layout_marginBottom="@dimen/standard_margin"
android:layout_weight="1"
android:scrollbars="vertical"
android:padding="@dimen/dialog_padding"
android:background="@drawable/shape_grouped_incoming_message"
android:padding="@dimen/dialog_padding"
android:scrollbars="vertical"
android:text=""
android:textSize="@dimen/message_text_size"
android:textColor="@color/nc_incoming_text_default"
android:textSize="@dimen/message_text_size"
android:visibility="visible" />
<ProgressBar
@ -96,5 +114,4 @@
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>