Skip to content

Fixing UI bugs with Chat Preview #5140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions app/src/main/java/com/nextcloud/talk/ui/ComposeChatAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package com.nextcloud.talk.ui

import android.content.Context
import android.content.ContextWrapper
import android.util.Log
import android.view.View.TEXT_ALIGNMENT_VIEW_START
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
Expand Down Expand Up @@ -90,7 +89,6 @@ import coil.compose.AsyncImage
import com.elyeproj.loaderviewlibrary.LoaderImageView
import com.elyeproj.loaderviewlibrary.LoaderTextView
import com.nextcloud.talk.R
import com.nextcloud.talk.activities.MainActivity
import com.nextcloud.talk.adapters.messages.PreviewMessageViewHolder.Companion.KEY_MIMETYPE
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
Expand All @@ -107,6 +105,7 @@ import com.nextcloud.talk.models.json.opengraph.Reference
import com.nextcloud.talk.ui.theme.ViewThemeUtils
import com.nextcloud.talk.users.UserManager
import com.nextcloud.talk.utils.DateUtils
import com.nextcloud.talk.utils.DisplayUtils
import com.nextcloud.talk.utils.DrawableUtils.getDrawableResourceIdForMimeType
import com.nextcloud.talk.utils.message.MessageUtils
import com.nextcloud.talk.utils.preview.ComposePreviewUtils
Expand Down Expand Up @@ -214,16 +213,7 @@ class ComposeChatAdapter(
val items = mutableStateListOf<ChatMessage>()
val currentUser: User = viewModel.userManager.currentUser.blockingGet()
val colorScheme = viewModel.viewThemeUtils.getColorScheme(viewModel.context)
val highEmphasisColorInt = viewModel.context.resources.getColor(R.color.high_emphasis_text, null)

fun Context.findMainActivityOrNull(): MainActivity? {
var context = this
while (context is ContextWrapper) {
if (context is MainActivity) return context
context = context.baseContext
}
return null
}
val highEmphasisColorInt = if (DisplayUtils.isAppThemeDarkMode(viewModel.context)) Color.White.toArgb() else Color.Black.toArgb()

fun addMessages(messages: MutableList<ChatMessage>, append: Boolean) {
if (messages.isEmpty()) return
Expand Down
26 changes: 23 additions & 3 deletions app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,19 @@ import com.nextcloud.talk.ui.theme.ViewThemeUtils
import com.nextcloud.talk.utils.ApiUtils.getUrlForAvatar
import com.nextcloud.talk.utils.ApiUtils.getUrlForFederatedAvatar
import com.nextcloud.talk.utils.ApiUtils.getUrlForGuestAvatar
import com.nextcloud.talk.utils.preferences.AppPreferencesImpl
import com.nextcloud.talk.utils.text.Spans.MentionChipSpan
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import org.greenrobot.eventbus.EventBus
import third.parties.fresco.BetterImageSpan
import java.text.DateFormat
import java.util.Date
import java.util.regex.Pattern

object DisplayUtils {
private val TAG = DisplayUtils::class.java.getSimpleName()
private val TAG = DisplayUtils::class.java.simpleName
private const val INDEX_LUMINATION = 2
private const val HSL_SIZE = 3
private const val MAX_LIGHTNESS = 0.92
Expand All @@ -89,6 +93,22 @@ object DisplayUtils {
return currentNightMode == Configuration.UI_MODE_NIGHT_YES
}

@OptIn(ExperimentalCoroutinesApi::class)
fun isAppThemeDarkMode(context: Context): Boolean =
runBlocking {
val appPreferences = AppPreferencesImpl(context)
val themeKey = context.resources.getString(R.string.nc_settings_theme_key)
val theme = appPreferences.readString(themeKey).first()
return@runBlocking when (theme) {
"night_no" -> false
"night_yes" -> true
"battery_saver" -> true
else ->
return@runBlocking isDarkModeOn(context)
}
}


fun setClickableString(string: String, url: String, textView: TextView) {
val spannableString = SpannableString(string)
spannableString.setSpan(
Expand Down Expand Up @@ -161,7 +181,7 @@ object DisplayUtils {
viewThemeUtils.material.colorChipDrawable(context, chip)
}
val config = context.resources.configuration
chip.setLayoutDirection(config.layoutDirection)
chip.layoutDirection = config.layoutDirection
val drawable: Int
val isCall = "call" == type || "calls" == type
val isGroup = "groups" == type || "user-group" == type
Expand Down Expand Up @@ -215,7 +235,7 @@ object DisplayUtils {
// A hack to refresh the chip icon
emojiEditText?.post {
emojiEditText.setTextKeepState(
emojiEditText.getText(),
emojiEditText.text,
TextView.BufferType.SPANNABLE
)
}
Expand Down
Loading