Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
  • Loading branch information
rapterjet2004 committed Sep 29, 2023
1 parent 8cb6807 commit d567867
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedA
import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.databinding.RvItemConversationWithLastMessageBinding
import com.nextcloud.talk.extensions.loadConversationAvatar
import com.nextcloud.talk.extensions.loadNoteToSelfAvatar
import com.nextcloud.talk.extensions.loadSystemAvatar
import com.nextcloud.talk.extensions.loadUserAvatar
import com.nextcloud.talk.models.domain.ConversationModel
import com.nextcloud.talk.models.json.chat.ChatMessage
import com.nextcloud.talk.models.json.conversations.Conversation
import com.nextcloud.talk.models.json.conversations.Conversation.ConversationType
import com.nextcloud.talk.ui.StatusDrawable
import com.nextcloud.talk.ui.theme.ViewThemeUtils
import com.nextcloud.talk.utils.ConversationUtils
import com.nextcloud.talk.utils.DisplayUtils
import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew.hasSpreedFeatureCapability
import eu.davidea.flexibleadapter.FlexibleAdapter
Expand Down Expand Up @@ -181,6 +184,15 @@ class ConversationItem(
}
}

ConversationType.DUMMY -> {
if (ConversationUtils.isNoteToSelfConversation(
ConversationModel.mapToConversationModel(model)
)
) {
holder.binding.dialogAvatar.loadNoteToSelfAvatar()
}
}

ConversationType.ROOM_GROUP_CALL,
ConversationType.FORMER_ONE_TO_ONE,
ConversationType.ROOM_PUBLIC_CALL ->
Expand Down
9 changes: 4 additions & 5 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2230,7 +2230,10 @@ class ChatActivity :
}

private fun checkShowCallButtons() {
if (isReadOnlyConversation() || shouldShowLobby() || isNoteToSelfConversation()) {
if (isReadOnlyConversation() ||
shouldShowLobby() ||
ConversationUtils.isNoteToSelfConversation(currentConversation)
) {
disableCallButtons()
} else {
enableCallButtons()
Expand Down Expand Up @@ -2258,10 +2261,6 @@ class ChatActivity :
return false
}

private fun isNoteToSelfConversation() : Boolean {
return currentConversation != null && currentConversation!!.type == ConversationType.NOTE_TO_SELF
}

private fun disableCallButtons() {
if (CapabilitiesUtilNew.isAbleToCall(conversationUser)) {
if (conversationVoiceCallMenuItem != null && conversationVideoMenuItem != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.databinding.ActivityConversationInfoBinding
import com.nextcloud.talk.events.EventStatus
import com.nextcloud.talk.extensions.loadConversationAvatar
import com.nextcloud.talk.extensions.loadNoteToSelfAvatar
import com.nextcloud.talk.extensions.loadSystemAvatar
import com.nextcloud.talk.extensions.loadUserAvatar
import com.nextcloud.talk.jobs.DeleteConversationWorker
import com.nextcloud.talk.jobs.LeaveConversationWorker
import com.nextcloud.talk.models.domain.ConversationModel
import com.nextcloud.talk.models.json.conversations.Conversation
import com.nextcloud.talk.models.json.conversations.RoomOverall
import com.nextcloud.talk.models.json.converters.EnumNotificationLevelConverter
Expand All @@ -81,6 +83,7 @@ import com.nextcloud.talk.models.json.participants.ParticipantsOverall
import com.nextcloud.talk.repositories.conversations.ConversationsRepository
import com.nextcloud.talk.shareditems.activities.SharedItemsActivity
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.ConversationUtils
import com.nextcloud.talk.utils.DateConstants
import com.nextcloud.talk.utils.DateUtils
import com.nextcloud.talk.utils.bundle.BundleKeys
Expand Down Expand Up @@ -714,8 +717,14 @@ class ConversationInfoActivity :
conversationUser
).setupGuestAccess()
}

binding.notificationSettingsView.notificationSettings.visibility = VISIBLE
if (ConversationUtils.isNoteToSelfConversation(
ConversationModel.mapToConversationModel(conversation!!)
)
) {
binding.notificationSettingsView.notificationSettings.visibility = GONE
} else {
binding.notificationSettingsView.notificationSettings.visibility = VISIBLE
}
}
}

Expand All @@ -731,6 +740,7 @@ class ConversationInfoActivity :

private fun initExpiringMessageOption() {
if (conversation!!.isParticipantOwnerOrModerator &&
!ConversationUtils.isNoteToSelfConversation(ConversationModel.mapToConversationModel(conversation!!)) &&
CapabilitiesUtilNew.hasSpreedFeatureCapability(conversationUser, "message-expiration")
) {
databaseStorageModule?.setMessageExpiration(conversation!!.messageExpiration)
Expand Down Expand Up @@ -828,6 +838,15 @@ class ConversationInfoActivity :
binding.avatarImage.loadSystemAvatar()
}

Conversation.ConversationType.DUMMY -> {
if (ConversationUtils.isNoteToSelfConversation(
ConversationModel.mapToConversationModel(conversation!!)
)
) {
binding.avatarImage.loadNoteToSelfAvatar()
}
}

else -> {
// unused atm
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package com.nextcloud.talk.extensions

import android.graphics.Color
import android.graphics.drawable.Drawable
import android.graphics.drawable.LayerDrawable
import android.os.Build
Expand Down Expand Up @@ -267,6 +268,26 @@ fun ImageView.loadSystemAvatar(): io.reactivex.disposables.Disposable {
)
}

fun ImageView.loadNoteToSelfAvatar(): io.reactivex.disposables.Disposable {
val data: Any = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val layers = arrayOfNulls<Drawable>(2)
layers[0] = ContextCompat.getDrawable(context, R.drawable.ic_launcher_background)
layers[1] = ContextCompat.getDrawable(context, R.drawable.ic_note_to_self).apply {
this?.setTint(Color.WHITE) // TODO get this to fit right
}
val layerDrawable = LayerDrawable(layers)
layerDrawable
} else {
R.mipmap.ic_launcher
}

return DisposableWrapper(
load(data) {
transformations(CircleCropTransformation())
}
)
}

fun ImageView.loadChangelogBotAvatar(): io.reactivex.disposables.Disposable {
return loadSystemAvatar()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ enum class ConversationType {
ROOM_GROUP_CALL,
ROOM_PUBLIC_CALL,
ROOM_SYSTEM,
FORMER_ONE_TO_ONE,
NOTE_TO_SELF
FORMER_ONE_TO_ONE
}

enum class ParticipantType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import android.os.Parcelable
import com.bluelinelabs.logansquare.annotation.JsonField
import com.bluelinelabs.logansquare.annotation.JsonObject
import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.models.domain.ConversationModel
import com.nextcloud.talk.models.json.chat.ChatMessage
import com.nextcloud.talk.models.json.converters.ConversationObjectTypeConverter
import com.nextcloud.talk.models.json.converters.EnumLobbyStateConverter
Expand All @@ -37,6 +38,7 @@ import com.nextcloud.talk.models.json.converters.EnumParticipantTypeConverter
import com.nextcloud.talk.models.json.converters.EnumReadOnlyConversationConverter
import com.nextcloud.talk.models.json.converters.EnumRoomTypeConverter
import com.nextcloud.talk.models.json.participants.Participant.ParticipantType
import com.nextcloud.talk.utils.ConversationUtils
import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew
import kotlinx.parcelize.Parcelize

Expand Down Expand Up @@ -187,7 +189,8 @@ data class Conversation(
fun canModerate(conversationUser: User): Boolean {
return isParticipantOwnerOrModerator &&
!isLockedOneToOne(conversationUser) &&
type != ConversationType.FORMER_ONE_TO_ONE
type != ConversationType.FORMER_ONE_TO_ONE &&
!ConversationUtils.isNoteToSelfConversation(ConversationModel.mapToConversationModel(this))
}

@Deprecated("Use ConversationUtil")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew

object ConversationUtils {
private val TAG = ConversationUtils::class.java.simpleName
private const val NOTE_TO_SELF = "Note to self"

fun isPublic(conversation: ConversationModel): Boolean {
return ConversationType.ROOM_PUBLIC_CALL == conversation.type
Expand All @@ -52,7 +53,8 @@ object ConversationUtils {
fun canModerate(conversation: ConversationModel, conversationUser: User): Boolean {
return isParticipantOwnerOrModerator(conversation) &&
!isLockedOneToOne(conversation, conversationUser) &&
conversation.type != ConversationType.FORMER_ONE_TO_ONE
conversation.type != ConversationType.FORMER_ONE_TO_ONE &&
!isNoteToSelfConversation(conversation)
}

fun isLobbyViewApplicable(conversation: ConversationModel, conversationUser: User): Boolean {
Expand Down Expand Up @@ -86,4 +88,8 @@ object ConversationUtils {
// Fallback for APIv1
}
}

fun isNoteToSelfConversation(currentConversation: ConversationModel?): Boolean {
return currentConversation != null && currentConversation.name == NOTE_TO_SELF
}
}
36 changes: 36 additions & 0 deletions app/src/main/res/drawable/ic_note_to_self.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!--
~ Nextcloud Talk application
~
~ @author Julius Linus
~ Copyright (C) 2023 Julius Linus <julius.linus@nextcloud.com>
~ @author Mario Danic
~ Copyright (C) 2017-2019 Mario Danic <mario@lovelyhq.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/>.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="48"
android:viewportHeight="48">
<group
android:translateX="12"
android:translateY="12"
>
<path
android:fillColor="#ffffff"
android:pathData="M20.71,7.04C21.1,6.65 21.1,6 20.71,5.63L18.37,3.29C18,2.9 17.35,2.9 16.96,3.29L15.12,5.12L18.87,8.87M3,17.25V21H6.75L17.81,9.93L14.06,6.18L3,17.25Z" />
</group>
</vector>

0 comments on commit d567867

Please sign in to comment.