Skip to content

Commit

Permalink
Clear code
Browse files Browse the repository at this point in the history
  • Loading branch information
Scorpionstvo committed Jul 10, 2023
1 parent 4b2b91f commit ebdb350
Show file tree
Hide file tree
Showing 55 changed files with 660 additions and 2,343 deletions.
Binary file modified .gradle/7.4/checksums/md5-checksums.bin
Binary file not shown.
Binary file modified .gradle/7.4/checksums/sha1-checksums.bin
Binary file not shown.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ android {
buildFeatures {
viewBinding true
}

buildToolsVersion '32.1.0 rc1'
}

Expand Down Expand Up @@ -117,7 +118,7 @@ dependencies {
implementation 'com.github.CanHub:Android-Image-Cropper:4.3.2'

// Debug
// debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1'

def emojiViewVersion = "1.5.2"
def emojiViewProvider = "GoogleProvider"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.xabber.data_base.dao

import com.xabber.R
import com.xabber.data_base.models.account.AccountStorageItem
import com.xabber.presentation.XabberApplication
import io.realm.kotlin.Realm

class AccountStorageItemDao(private val realm: Realm) {
Expand All @@ -25,7 +27,7 @@ class AccountStorageItemDao(private val realm: Realm) {
fun createAccount(
accountJid: String,
accountName: String,
accountColor: String?,
accountColor: String,
accountHasAvatar: Boolean = false
) {
val accountOrder = defineAccountOrder()
Expand All @@ -34,7 +36,7 @@ class AccountStorageItemDao(private val realm: Realm) {
primary = accountJid
jid = accountJid
order = accountOrder
colorKey = accountColor ?: "blue"
colorKey = accountColor
enabled = true
hasAvatar = accountHasAvatar
username = accountName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.xabber.data_base.models.roster

import com.xabber.R
import com.xabber.presentation.XabberApplication
import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.annotations.PrimaryKey

Expand All @@ -22,7 +23,7 @@ class RosterStorageItem: RealmObject {
var isHidden: Boolean = false
var notes: String? = null
var isSupportOmemo: Boolean = false
var colorKey: String = "blue"
var colorKey: String = XabberApplication.applicationContext().resources.getString(R.string.blue)
var avatarR: Int = R.drawable.dog


Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/xabber/dto/ChatListDto.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.xabber.dto

import android.os.Parcelable
import com.xabber.R
import com.xabber.data_base.models.messages.MessageSendingState
import com.xabber.data_base.models.presences.ResourceStatus
import com.xabber.data_base.models.presences.RosterItemEntity
import com.xabber.presentation.XabberApplication
import kotlinx.parcelize.Parcelize


Expand Down Expand Up @@ -32,7 +34,7 @@ data class ChatListDto(
val drawableId: Int,
val isHide: Boolean = false,
val lastMessageIsOutgoing: Boolean = false,
var colorKey: String = "blue",
var colorKey: String = XabberApplication.applicationContext().resources.getString(R.string.blue),
val isGroup: Boolean = false
) : Comparable<ChatListDto>, Parcelable {
override fun compareTo(other: ChatListDto): Int { // сортировка: сначала запиненные, затем от новых к старым
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import com.xabber.presentation.application.fragments.chatlist.add.NewChatFragmen
import com.xabber.presentation.application.fragments.chatlist.add.NewContactFragment
import com.xabber.presentation.application.fragments.chatlist.add.NewGroupFragment
import com.xabber.presentation.application.fragments.chatlist.forward.ChatListToForwardFragment
import com.xabber.presentation.application.fragments.chatlist.spec_notifications.SpecialNotificationsFragment
import com.xabber.presentation.application.fragments.contacts.*
import com.xabber.presentation.application.fragments.contacts.edit.EditContactFragment
import com.xabber.presentation.application.fragments.discover.DiscoverFragment
Expand All @@ -53,7 +52,7 @@ import com.xabber.presentation.application.manage.DisplayManager
import com.xabber.presentation.application.manage.DisplayManager.getMainContainerWidth
import com.xabber.presentation.application.manage.DisplayManager.isDualScreenMode
import com.xabber.presentation.onboarding.activity.OnBoardingActivity
import com.xabber.utils.MaskManager
import com.xabber.presentation.application.manage.MaskManager
import com.xabber.utils.lockScreenRotation

/**
Expand Down Expand Up @@ -397,10 +396,6 @@ class ApplicationActivity : AppCompatActivity(), Navigator {
launchDetailInStack(ChatListFragment())
}

override fun showSpecialNotificationSettings() {
launchDetail(SpecialNotificationsFragment())
}

override fun showAccount(jid: String) {
launchDetail(AccountFragment.newInstance(jid))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ interface Navigator {

fun showNewGroup(incognito: Boolean)

fun showSpecialNotificationSettings()

fun showContacts()

fun showEditContact(params: ContactAccountParams)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.xabber.presentation.application.BaseViewModel
import com.xabber.presentation.application.contract.navigator
import com.xabber.presentation.application.manage.ColorManager
import com.xabber.presentation.application.manage.DisplayManager
import com.xabber.utils.MaskManager
import com.xabber.presentation.application.manage.MaskManager
import com.xabber.utils.custom.ShapeOfView

/**
Expand All @@ -37,9 +37,8 @@ abstract class BaseFragment(@LayoutRes contentLayoutId: Int) : Fragment(contentL
private var status: ImageView? = null
private var currentJid: String? = null
private var shapeView: ShapeOfView? = null
private val defaultColorKey = "blue"
private lateinit var sh: SharedPreferences
private var currentColorKey = "blue"
private var currentColorKey = ""

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Expand All @@ -50,7 +49,7 @@ abstract class BaseFragment(@LayoutRes contentLayoutId: Int) : Fragment(contentL
sh.registerOnSharedPreferenceChangeListener(this)
val primaryAccount = baseViewModel.getPrimaryAccount()
currentJid = primaryAccount?.jid
currentColorKey = primaryAccount?.colorKey ?: "offline"
currentColorKey = primaryAccount?.colorKey ?: resources.getString(R.string.offline)
setupColor(currentColorKey)

shapeView?.setDrawable(MaskManager.mask)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class AccountFragment : DetailBaseFragment(R.layout.fragment_account) {
private fun changeUiWithAccountData() {
val account = viewModel.getAccount(getJid())
hasAvatar = account?.hasAvatar ?: false
val colorKey = account?.colorKey ?: "blue"
val colorKey = account?.colorKey ?: resources.getString(R.string.blue)
val colorRes = ColorManager.convertColorNameToId(colorKey)
loadBackground(colorRes)
defineColor(colorRes)
Expand Down Expand Up @@ -223,12 +223,12 @@ class AccountFragment : DetailBaseFragment(R.layout.fragment_account) {
when (menuItem.itemId) {
R.id.colors -> {
val dialog = AccountColorDialog.newInstance(
viewModel.getAccount(getJid())?.colorKey ?: "blue"
viewModel.getAccount(getJid())?.colorKey ?: resources.getString(R.string.blue)
)
navigator().showDialogFragment(dialog, "")
}
R.id.generate_qr_code -> {
val color = viewModel.getAccount(getJid())?.colorKey ?: "blue"
val color = viewModel.getAccount(getJid())?.colorKey ?: resources.getString(R.string.blue)
val name = viewModel.getAccount(getJid())?.getAccountName() ?: ""
navigator().showQRCode(
QRCodeParams(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.xabber.databinding.ItemAccountForPreferenceBinding
import com.xabber.dto.AccountDto
import com.xabber.presentation.AppConstants
import com.xabber.presentation.application.manage.ColorManager
import com.xabber.utils.MaskManager
import com.xabber.presentation.application.manage.MaskManager
import io.realm.kotlin.Realm

class AccountViewHolder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AccountViewModel : ViewModel() {
fun addAccount(
accountJid: String,
userName: String,
accountColor: String? = null,
accountColor: String,
accountHasAvatar: Boolean = false, password: String
) {
accountStorageItemDao.createAccount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AccountColorDialog : DialogFragment(), AccountColorPickerAdapter.Listener
private fun initColorList() {
val colors =
resources.obtainTypedArray(R.array.account_500)
val colorKey = arguments?.getString(AppConstants.ACCOUNT_COLOR_KEY) ?: "blue"
val colorKey = arguments?.getString(AppConstants.ACCOUNT_COLOR_KEY) ?: resources.getString(R.string.blue)
val number = ColorManager.convertColorNameToIndex(colorKey)
val adapter = AccountColorPickerAdapter(
this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ import kotlin.experimental.and

class ChatFragment : DetailBaseFragment(R.layout.fragment_chat), MessageAdapter.MenuItemListener,
MessageAdapter.OnViewClickListener,
IncomingMessageVH.BindListener,
ReplySwipeCallback.SwipeAction {
private val binding by viewBinding(FragmentChatBinding::bind)
private val handler = Handler(Looper.getMainLooper())
Expand Down Expand Up @@ -377,7 +376,6 @@ class ChatFragment : DetailBaseFragment(R.layout.fragment_chat), MessageAdapter.
val isGroup = viewModel.loadChat(getParams().id)!!.isGroup
messageAdapter = MessageAdapter(
this,
bindListener = this,
onViewClickListener = this,
messages = ArrayList<MessageDto>(), isGroup = isGroup
)
Expand Down Expand Up @@ -1223,7 +1221,7 @@ class ChatFragment : DetailBaseFragment(R.layout.fragment_chat), MessageAdapter.
binding.chatInput.isEnabled = false
} else {
val color = baseViewModel.getPrimaryAccount()?.colorKey
val c = ColorManager.convertColorNameToId(color ?: "blue")
val c = ColorManager.convertColorNameToId(color ?: resources.getString(R.string.blue))
binding.appbar.setBackgroundResource(c)
// chatAdapter?.setSelectedMode(false)
// binding.chatPanelGroup.isVisible = true
Expand Down Expand Up @@ -1340,23 +1338,23 @@ class ChatFragment : DetailBaseFragment(R.layout.fragment_chat), MessageAdapter.
NotRecording, InitiatedRecording, TouchRecording, NoTouchRecording, StoppedRecording
}

override fun onBind(message: MessageDto?) {
if (message != null) {
val id = message.primary
if (message.isUnread) {
realm.writeBlocking {
val m = this.query(MessageStorageItem::class, "primary = '$id'").first().find()
if (m != null) {
findLatest(m).also {
if (!it!!.isRead) {
it.isRead = true
}
}
}
}
}
}
}
// override fun onBind(message: MessageDto?) {
// if (message != null) {
// val id = message.primary
// if (message.isUnread) {
// realm.writeBlocking {
// val m = this.query(MessageStorageItem::class, "primary = '$id'").first().find()
// if (m != null) {
// findLatest(m).also {
// if (!it!!.isRead) {
// it.isRead = true
// }
// }
// }
// }
// }
// }
// }

override fun onImageOrVideoClick(startPosition: Int, messageId: String) {
val intent = Intent(requireContext(), MediaDetailsActivity::class.java)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.xabber.presentation.application.fragments.chat.message

import android.content.res.Resources
import android.graphics.PorterDuff
import android.graphics.drawable.ShapeDrawable
import android.graphics.drawable.shapes.RoundRectShape
Expand All @@ -19,6 +18,7 @@ import com.xabber.dto.MessageDto
import com.xabber.dto.MessageReferenceDto
import com.xabber.presentation.application.fragments.chat.ChatSettingsManager
import com.xabber.presentation.application.fragments.chat.StatusMaker
import com.xabber.presentation.application.manage.DisplayManager
import com.xabber.utils.StringUtils
import com.xabber.utils.custom.ShapeOfView
import com.xabber.utils.dp
Expand Down Expand Up @@ -70,11 +70,13 @@ class ImageGridBuilder {
messageInfo.setBackgroundResource(timeStampBackground)

val tvTime = view.findViewById<TextView>(R.id.tv_image_sending_time)
val dates = Date(message.sentTimestamp)
val time = StringUtils.getTimeText(view.context, dates)
tvTime.text = time
val date =
Date(if (message.editTimestamp > 0) message.editTimestamp else message.sentTimestamp)
val time = StringUtils.getTimeText(view.context, date)
tvTime.text = if (message.editTimestamp > 0) view.context.resources.getString(R.string.edit) + " $time" else time

val statusIcon = view.findViewById<ImageView>(R.id.iv_image_message_status) // статус сообщения
val statusIcon =
view.findViewById<ImageView>(R.id.iv_image_message_status) // статус сообщения
val iconAndTint = StatusMaker.deliverMessageStatusIcon(message.messageSendingState)
val icon = iconAndTint.first
val tint = iconAndTint.second
Expand Down Expand Up @@ -103,7 +105,7 @@ class ImageGridBuilder {
val isOneImage = imagesSize == 1

val shape = getShapeView(view, index)
val radii = when (index) {
val radii = when (index) { // скругление углов для каждого imageView
0 -> {
if (imagesSize < 5) floatArrayOf(
cornerRadius.dp.toFloat(),
Expand Down Expand Up @@ -194,14 +196,15 @@ class ImageGridBuilder {
val imageView = getImageView(view, index)

if (imageView != null) {
if (imagesSize > 6 && index == 5) imageView.setColorFilter(ContextCompat.getColor(imageView.context, R.color.grey_transparent))
if (imagesSize > 6 && index == 5) imageView.setColorFilter(
ContextCompat.getColor(
imageView.context,
R.color.grey_transparent
)
)
if (isOneImage) { // если картинка одна, загружаем ее учитывая соотношение сторон, но не превышая максимально допустимый размер
val displayMetrics = Resources.getSystem().displayMetrics
val screenWidth = displayMetrics.widthPixels
val screenHeight = displayMetrics.heightPixels

val maxWidth = (screenWidth * 0.8).toInt()
val maxHeight = (screenHeight * 0.5).toInt()
val maxWidth = (DisplayManager.screenWidth() * 0.8).toInt()
val maxHeight = (DisplayManager.screenHeight() * 0.5).toInt()
Glide.with(imageView.context)
.load(image.uri)
.override(maxWidth, maxHeight)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,10 @@ import com.xabber.presentation.application.fragments.chat.MessageVhExtraData

class IncomingMessageVH internal constructor(
itemView: View,
private val listener: MessageAdapter.MenuItemListener?,
onViewClickListener: MessageAdapter.OnViewClickListener?,
val listen: BindListener?, avatarClickListener: OnMessageAvatarClickListener
) : MessageVH(itemView, listener, onViewClickListener) {
menuItemListener: MessageAdapter.MenuItemListener?,
onViewClickListener: MessageAdapter.OnViewClickListener?
) : MessageVH(itemView, menuItemListener, onViewClickListener) {

interface BindListener {
fun onBind(message: MessageDto?)
}

interface OnMessageAvatarClickListener {
fun onMessageAvatarClick(position: Int)
}

override fun bind(message: MessageDto, vhExtraData: MessageVhExtraData) {
super.bind(message, vhExtraData)
Expand Down
Loading

0 comments on commit ebdb350

Please sign in to comment.