Skip to content

Commit

Permalink
Fix issues with translations menu button
Browse files Browse the repository at this point in the history
 - it is not inflated for user's own posts but we didn't check for that
 - some servers return language codes in uppercase and it wasn't
matching Java's lowercase code when it should have
  • Loading branch information
charlag committed Mar 9, 2024
1 parent ef86899 commit a9e54b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,13 @@ class SearchStatusesFragment : SearchFragment<StatusViewData.Concrete>(), Status
)
}

val translateItem = popup.menu.findItem(R.id.status_translate)
translateItem.isVisible =
status.language != Locale.getDefault().language && viewModel.supportsTranslation()
translateItem.setTitle(if (statusViewData.translation != null) R.string.action_show_original else R.string.action_translate)
// translation not there for your own posts
popup.menu.findItem(R.id.status_translate)?.let { translateItem ->
translateItem.isVisible =
!status.language.equals(Locale.getDefault().language, ignoreCase = true)
&& viewModel.supportsTranslation()
translateItem.setTitle(if (statusViewData.translation != null) R.string.action_show_original else R.string.action_translate)
}

popup.setOnMenuItemClickListener { item ->
when (item.itemId) {
Expand Down
15 changes: 9 additions & 6 deletions app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,13 @@ abstract class SFragment : Fragment(), Injectable {
)
}

val translateItem = menu.findItem(R.id.status_translate)
translateItem.isVisible =
onMoreTranslate != null && status.language != Locale.getDefault().language && instanceInfoRepository.cachedInstanceInfoOrFallback.translationEnabled == true
translateItem.setTitle(if (translation != null) R.string.action_show_original else R.string.action_translate)
// translation not there for your own posts
menu.findItem(R.id.status_translate)?.let { translateItem ->
translateItem.isVisible = onMoreTranslate != null
&& !status.language.equals(Locale.getDefault().language, ignoreCase = true)
&& instanceInfoRepository.cachedInstanceInfoOrFallback.translationEnabled == true
translateItem.setTitle(if (translation != null) R.string.action_show_original else R.string.action_translate)
}

popup.setOnMenuItemClickListener { item: MenuItem ->
when (item.itemId) {
Expand Down Expand Up @@ -271,8 +274,8 @@ abstract class SFragment : Fragment(), Injectable {
Context.CLIPBOARD_SERVICE
) as ClipboardManager
).apply {
setPrimaryClip(ClipData.newPlainText(null, statusUrl))
}
setPrimaryClip(ClipData.newPlainText(null, statusUrl))
}
return@setOnMenuItemClickListener true
}

Expand Down

0 comments on commit a9e54b9

Please sign in to comment.