chats: fix media upload, fix back button

main
Alibek Omarov 4 years ago
parent 159f0f0615
commit d8ffcaec30
  1. 11
      app/src/main/java/com/keylesspalace/tusky/components/chat/ChatActivity.kt
  2. 7
      app/src/main/java/com/keylesspalace/tusky/components/chat/ChatViewModel.kt
  3. 209
      app/src/main/res/layout/activity_chat.xml

@ -390,9 +390,10 @@ class ChatActivity: BottomSheetActivity(),
.into(imageAttachment) .into(imageAttachment)
} }
} }
attachmentLayout.visibility = View.VISIBLE
} else { } else {
imageAttachment.visibility = View.GONE attachmentLayout.visibility = View.GONE
textAttachment.visibility = View.GONE
} }
} }
viewModel.uploadError.observe { viewModel.uploadError.observe {
@ -448,7 +449,7 @@ class ChatActivity: BottomSheetActivity(),
stickerBehavior = BottomSheetBehavior.from(stickerKeyboard) stickerBehavior = BottomSheetBehavior.from(stickerKeyboard)
sendButton.setOnClickListener { sendButton.setOnClickListener {
val media = viewModel.media.value?.get(0) val media = viewModel.getSingleMedia()
serviceClient.sendChatMessage( MessageToSend( serviceClient.sendChatMessage( MessageToSend(
editText.text.toString(), editText.text.toString(),
@ -960,13 +961,13 @@ class ChatActivity: BottomSheetActivity(),
return return
} }
super.onBackPressed() finish()
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
android.R.id.home -> { android.R.id.home -> {
onBackPressed() finish()
return true return true
} }
} }

@ -2,6 +2,7 @@ package com.keylesspalace.tusky.components.chat
import com.keylesspalace.tusky.components.common.CommonComposeViewModel import com.keylesspalace.tusky.components.common.CommonComposeViewModel
import com.keylesspalace.tusky.components.common.MediaUploader import com.keylesspalace.tusky.components.common.MediaUploader
import com.keylesspalace.tusky.components.compose.ComposeActivity
import com.keylesspalace.tusky.db.AccountManager import com.keylesspalace.tusky.db.AccountManager
import com.keylesspalace.tusky.db.AppDatabase import com.keylesspalace.tusky.db.AppDatabase
import com.keylesspalace.tusky.network.MastodonApi import com.keylesspalace.tusky.network.MastodonApi
@ -19,4 +20,10 @@ open class ChatViewModel
private val db: AppDatabase private val db: AppDatabase
) : CommonComposeViewModel(api, accountManager, mediaUploader, db) { ) : CommonComposeViewModel(api, accountManager, mediaUploader, db) {
fun getSingleMedia() : ComposeActivity.QueuedMedia? {
return if(media.value?.isNotEmpty() == true)
media.value?.get(0)
else null
}
} }

@ -7,103 +7,99 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/appbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:elevation="@dimen/actionbar_elevation" >
app:layout_collapseMode="pin"> <com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="wrap_content"
> android:elevation="@dimen/actionbar_elevation"
app:layout_collapseMode="pin">
<ImageView <androidx.appcompat.widget.Toolbar
android:id="@+id/chatAvatar" android:id="@+id/toolbar"
android:layout_width="?attr/actionBarSize" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
android:padding="8dp" >
android:contentDescription="@string/action_view_profile" <ImageView
android:importantForAccessibility="no" android:id="@+id/chatAvatar"
android:scaleType="centerCrop" android:layout_width="?attr/actionBarSize"
app:layout_constraintStart_toStartOf="parent" android:layout_height="?attr/actionBarSize"
app:layout_constraintTop_toTopOf="parent" android:padding="8dp"
tools:src="@drawable/avatar_default" /> android:contentDescription="@string/action_view_profile"
android:importantForAccessibility="no"
<androidx.emoji.widget.EmojiTextView android:scaleType="centerCrop"
android:id="@+id/chatTitle" app:layout_constraintStart_toStartOf="parent"
android:layout_width="wrap_content" app:layout_constraintTop_toTopOf="parent"
android:layout_height="wrap_content" tools:src="@drawable/avatar_default" />
android:ellipsize="end" <androidx.emoji.widget.EmojiTextView
android:importantForAccessibility="no" android:id="@+id/chatTitle"
android:maxLines="1" android:layout_width="wrap_content"
android:paddingEnd="@dimen/status_display_name_padding_end" android:layout_height="wrap_content"
android:textColor="?android:textColorPrimary" android:ellipsize="end"
android:textSize="?attr/status_text_large" android:importantForAccessibility="no"
android:textStyle="normal|bold" android:maxLines="1"
tools:text="Ente r the void you foooooo" /> android:paddingEnd="@dimen/status_display_name_padding_end"
android:textColor="?android:textColorPrimary"
<TextView android:textSize="?attr/status_text_large"
android:id="@+id/chatUsername" android:textStyle="normal|bold"
android:layout_width="wrap_content" tools:text="Ente r the void you foooooo" />
android:layout_height="wrap_content" <TextView
android:ellipsize="end" android:id="@+id/chatUsername"
android:importantForAccessibility="no" android:layout_width="wrap_content"
android:maxLines="1" android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary" android:ellipsize="end"
android:textSize="?attr/status_text_large" android:importantForAccessibility="no"
tools:text="\@Entenhausen@birbsarecooooooooooool.site" /> android:maxLines="1"
</androidx.appcompat.widget.Toolbar> android:textColor="?android:textColorSecondary"
</com.google.android.material.appbar.AppBarLayout> android:textSize="?attr/status_text_large"
tools:text="\@Entenhausen@birbsarecooooooooooool.site" />
<androidx.recyclerview.widget.RecyclerView </androidx.appcompat.widget.Toolbar>
android:id="@+id/recycler" </com.google.android.material.appbar.AppBarLayout>
android:layout_width="0dp" <androidx.recyclerview.widget.RecyclerView
android:layout_height="0dp" android:id="@+id/recycler"
app:layout_constraintBottom_toTopOf="@+id/composeLayout" android:layout_width="0dp"
app:layout_constraintLeft_toLeftOf="parent" android:layout_height="0dp"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintBottom_toTopOf="@+id/composeLayout"
app:layout_constraintTop_toBottomOf="@id/appbar" /> app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
<ProgressBar app:layout_constraintTop_toBottomOf="@id/appbar" />
android:id="@+id/progressBar" <ProgressBar
android:layout_width="wrap_content" android:id="@+id/progressBar"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:visibility="gone" android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/composeLayout" android:visibility="gone"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintBottom_toTopOf="@+id/composeLayout"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintRight_toRightOf="parent"
tools:visibility="visible" /> app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />
<com.keylesspalace.tusky.view.BackgroundMessageView <com.keylesspalace.tusky.view.BackgroundMessageView
android:id="@+id/messageView" android:id="@+id/messageView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:visibility="gone" android:visibility="gone"
app:layout_constraintBottom_toTopOf="@+id/composeLayout" app:layout_constraintBottom_toTopOf="@+id/composeLayout"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/appbar" app:layout_constraintTop_toBottomOf="@id/appbar"
tools:visibility="visible" tools:visibility="visible"
app:layout_constrainedHeight="true" /> app:layout_constrainedHeight="true" />
<androidx.constraintlayout.widget.ConstraintLayout
<androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/composeLayout"
android:id="@+id/composeLayout" android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:orientation="horizontal"
android:orientation="horizontal" android:background="?attr/colorSurface"
android:background="?attr/colorSurface" android:animateLayoutChanges="true"
android:animateLayoutChanges="true" android:paddingTop="4dp"
android:paddingTop="4dp" android:paddingBottom="4dp"
android:paddingBottom="4dp" app:layout_constraintTop_toBottomOf="@+id/recycler"
app:layout_constraintTop_toBottomOf="@+id/recycler" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintBottom_toBottomOf="parent">
app:layout_constraintBottom_toBottomOf="parent"> <FrameLayout
<FrameLayout
android:id="@+id/attachmentLayout" android:id="@+id/attachmentLayout"
android:layout_width="@dimen/compose_media_preview_size" android:layout_width="@dimen/compose_media_preview_size"
android:layout_height="@dimen/compose_media_preview_size" android:layout_height="@dimen/compose_media_preview_size"
@ -112,15 +108,12 @@
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
tools:visibility="visible"> tools:visibility="visible">
<com.keylesspalace.tusky.components.compose.view.ProgressImageView <com.keylesspalace.tusky.components.compose.view.ProgressImageView
android:id="@+id/imageAttachment" android:id="@+id/imageAttachment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:visibility="gone" android:visibility="gone"
tools:visibility="visible" tools:visibility="visible" />
/>
<com.keylesspalace.tusky.components.compose.view.ProgressTextView <com.keylesspalace.tusky.components.compose.view.ProgressTextView
android:id="@+id/textAttachment" android:id="@+id/textAttachment"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -130,11 +123,8 @@
android:marqueeRepeatLimit="-1" android:marqueeRepeatLimit="-1"
android:singleLine="true" android:singleLine="true"
android:textSize="?attr/status_text_small" android:textSize="?attr/status_text_small"
tools:visibility="visible" tools:visibility="visible" />
/>
</FrameLayout> </FrameLayout>
<ImageButton <ImageButton
android:id="@+id/attachmentButton" android:id="@+id/attachmentButton"
style="@style/TuskyImageButton" style="@style/TuskyImageButton"
@ -146,11 +136,10 @@
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/attachmentLayout" app:layout_constraintTop_toBottomOf="@id/attachmentLayout"
app:srcCompat="@drawable/ic_attach_file_24dp" /> app:srcCompat="@drawable/ic_attach_file_24dp" />
<com.keylesspalace.tusky.components.compose.view.EditTextTyped <com.keylesspalace.tusky.components.compose.view.EditTextTyped
android:id="@+id/editText" android:id="@+id/editText"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="0dp"
android:textSize="?attr/status_text_large" android:textSize="?attr/status_text_large"
android:singleLine="false" android:singleLine="false"
android:background="@null" android:background="@null"
@ -161,43 +150,37 @@
android:lineSpacingMultiplier="1.1" android:lineSpacingMultiplier="1.1"
android:textColorHint="?android:attr/textColorTertiary" android:textColorHint="?android:attr/textColorTertiary"
app:layout_constraintEnd_toStartOf="@+id/emojiButton" app:layout_constraintEnd_toStartOf="@+id/emojiButton"
app:layout_constraintRight_toLeftOf="@id/emojiButton"
app:layout_constraintStart_toEndOf="@+id/attachmentButton" app:layout_constraintStart_toEndOf="@+id/attachmentButton"
app:layout_constraintTop_toBottomOf="@id/attachmentLayout" app:layout_constraintTop_toBottomOf="@id/attachmentLayout"
app:layout_constraintBottom_toBottomOf="parent"
tools:text="Just landed in L.A." /> tools:text="Just landed in L.A." />
<ImageButton <ImageButton
android:id="@+id/emojiButton" android:id="@+id/emojiButton"
style="@style/TuskyImageButton" style="@style/TuskyImageButton"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_marginEnd="4dp"
android:contentDescription="@string/action_emoji_keyboard" android:contentDescription="@string/action_emoji_keyboard"
android:tooltipText="@string/action_emoji_keyboard" android:tooltipText="@string/action_emoji_keyboard"
app:srcCompat="@drawable/ic_emoji_24dp" app:srcCompat="@drawable/ic_emoji_24dp"
app:layout_constraintTop_toBottomOf="@id/attachmentLayout" app:layout_constraintTop_toBottomOf="@id/attachmentLayout"
app:layout_constraintRight_toLeftOf="@id/stickerButton" app:layout_constraintRight_toLeftOf="@id/stickerButton"
/> />
<ImageButton <ImageButton
android:id="@+id/stickerButton" android:id="@+id/stickerButton"
style="@style/TuskyImageButton" style="@style/TuskyImageButton"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_marginEnd="4dp"
android:contentDescription="@string/action_sticker" android:contentDescription="@string/action_sticker"
android:tooltipText="@string/action_sticker" android:tooltipText="@string/action_sticker"
app:srcCompat="@drawable/ic_sticker" app:srcCompat="@drawable/ic_sticker"
app:layout_constraintTop_toBottomOf="@id/attachmentLayout" app:layout_constraintTop_toBottomOf="@id/attachmentLayout"
app:layout_constraintRight_toLeftOf="@id/sendButton" app:layout_constraintRight_toLeftOf="@id/sendButton"
/> />
<ImageButton <ImageButton
android:id="@+id/sendButton" android:id="@+id/sendButton"
style="@style/TuskyImageButton" style="@style/TuskyImageButton"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_marginEnd="4dp"
android:contentDescription="@string/action_send" android:contentDescription="@string/action_send"
android:tooltipText="@string/action_send" android:tooltipText="@string/action_send"
app:srcCompat="@drawable/ic_send_24dp" app:srcCompat="@drawable/ic_send_24dp"
@ -217,7 +200,6 @@
android:paddingStart="16dp" android:paddingStart="16dp"
android:paddingTop="8dp" android:paddingTop="8dp"
android:paddingEnd="16dp" android:paddingEnd="16dp"
android:paddingBottom="@dimen/compose_activity_bottom_bar_height"
app:behavior_hideable="true" app:behavior_hideable="true"
app:behavior_peekHeight="0dp" app:behavior_peekHeight="0dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" /> app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" />
@ -228,7 +210,6 @@
android:layout_height="300dp" android:layout_height="300dp"
android:background="?attr/colorSurface" android:background="?attr/colorSurface"
android:elevation="12dp" android:elevation="12dp"
android:paddingBottom="@dimen/compose_activity_bottom_bar_height"
app:behavior_hideable="true" app:behavior_hideable="true"
app:behavior_peekHeight="0dp" app:behavior_peekHeight="0dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" /> app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" />
@ -243,7 +224,6 @@
android:paddingStart="16dp" android:paddingStart="16dp"
android:paddingTop="8dp" android:paddingTop="8dp"
android:paddingEnd="16dp" android:paddingEnd="16dp"
android:paddingBottom="52dp"
app:behavior_hideable="true" app:behavior_hideable="true"
app:behavior_peekHeight="0dp" app:behavior_peekHeight="0dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"> app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
@ -269,4 +249,5 @@
</LinearLayout> </LinearLayout>
<include layout="@layout/item_status_bottom_sheet" /> <include layout="@layout/item_status_bottom_sheet" />
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>
Loading…
Cancel
Save