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)
}
}
attachmentLayout.visibility = View.VISIBLE
} else {
imageAttachment.visibility = View.GONE
textAttachment.visibility = View.GONE
attachmentLayout.visibility = View.GONE
}
}
viewModel.uploadError.observe {
@ -448,7 +449,7 @@ class ChatActivity: BottomSheetActivity(),
stickerBehavior = BottomSheetBehavior.from(stickerKeyboard)
sendButton.setOnClickListener {
val media = viewModel.media.value?.get(0)
val media = viewModel.getSingleMedia()
serviceClient.sendChatMessage( MessageToSend(
editText.text.toString(),
@ -960,13 +961,13 @@ class ChatActivity: BottomSheetActivity(),
return
}
super.onBackPressed()
finish()
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
android.R.id.home -> {
onBackPressed()
finish()
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.MediaUploader
import com.keylesspalace.tusky.components.compose.ComposeActivity
import com.keylesspalace.tusky.db.AccountManager
import com.keylesspalace.tusky.db.AppDatabase
import com.keylesspalace.tusky.network.MastodonApi
@ -19,4 +20,10 @@ open class ChatViewModel
private val db: AppDatabase
) : 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_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="@dimen/actionbar_elevation"
app:layout_collapseMode="pin">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="match_parent"
>
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
>
<ImageView
android:id="@+id/chatAvatar"
android:layout_width="?attr/actionBarSize"
android:layout_height="wrap_content"
android:elevation="@dimen/actionbar_elevation"
app:layout_collapseMode="pin">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:padding="8dp"
android:contentDescription="@string/action_view_profile"
android:importantForAccessibility="no"
android:scaleType="centerCrop"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/avatar_default" />
<androidx.emoji.widget.EmojiTextView
android:id="@+id/chatTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:importantForAccessibility="no"
android:maxLines="1"
android:paddingEnd="@dimen/status_display_name_padding_end"
android:textColor="?android:textColorPrimary"
android:textSize="?attr/status_text_large"
android:textStyle="normal|bold"
tools:text="Ente r the void you foooooo" />
<TextView
android:id="@+id/chatUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:importantForAccessibility="no"
android:maxLines="1"
android:textColor="?android:textColorSecondary"
android:textSize="?attr/status_text_large"
tools:text="\@Entenhausen@birbsarecooooooooooool.site" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/composeLayout"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/appbar" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@+id/composeLayout"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />
<com.keylesspalace.tusky.view.BackgroundMessageView
android:id="@+id/messageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@+id/composeLayout"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/appbar"
tools:visibility="visible"
app:layout_constrainedHeight="true" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/composeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="?attr/colorSurface"
android:animateLayoutChanges="true"
android:paddingTop="4dp"
android:paddingBottom="4dp"
app:layout_constraintTop_toBottomOf="@+id/recycler"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
<FrameLayout
>
<ImageView
android:id="@+id/chatAvatar"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:padding="8dp"
android:contentDescription="@string/action_view_profile"
android:importantForAccessibility="no"
android:scaleType="centerCrop"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/avatar_default" />
<androidx.emoji.widget.EmojiTextView
android:id="@+id/chatTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:importantForAccessibility="no"
android:maxLines="1"
android:paddingEnd="@dimen/status_display_name_padding_end"
android:textColor="?android:textColorPrimary"
android:textSize="?attr/status_text_large"
android:textStyle="normal|bold"
tools:text="Ente r the void you foooooo" />
<TextView
android:id="@+id/chatUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:importantForAccessibility="no"
android:maxLines="1"
android:textColor="?android:textColorSecondary"
android:textSize="?attr/status_text_large"
tools:text="\@Entenhausen@birbsarecooooooooooool.site" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/composeLayout"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/appbar" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@+id/composeLayout"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />
<com.keylesspalace.tusky.view.BackgroundMessageView
android:id="@+id/messageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@+id/composeLayout"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/appbar"
tools:visibility="visible"
app:layout_constrainedHeight="true" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/composeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="?attr/colorSurface"
android:animateLayoutChanges="true"
android:paddingTop="4dp"
android:paddingBottom="4dp"
app:layout_constraintTop_toBottomOf="@+id/recycler"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
<FrameLayout
android:id="@+id/attachmentLayout"
android:layout_width="@dimen/compose_media_preview_size"
android:layout_height="@dimen/compose_media_preview_size"
@ -112,15 +108,12 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
tools:visibility="visible">
<com.keylesspalace.tusky.components.compose.view.ProgressImageView
android:id="@+id/imageAttachment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
tools:visibility="visible"
/>
tools:visibility="visible" />
<com.keylesspalace.tusky.components.compose.view.ProgressTextView
android:id="@+id/textAttachment"
android:layout_width="match_parent"
@ -130,11 +123,8 @@
android:marqueeRepeatLimit="-1"
android:singleLine="true"
android:textSize="?attr/status_text_small"
tools:visibility="visible"
/>
tools:visibility="visible" />
</FrameLayout>
<ImageButton
android:id="@+id/attachmentButton"
style="@style/TuskyImageButton"
@ -146,11 +136,10 @@
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/attachmentLayout"
app:srcCompat="@drawable/ic_attach_file_24dp" />
<com.keylesspalace.tusky.components.compose.view.EditTextTyped
android:id="@+id/editText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="0dp"
android:textSize="?attr/status_text_large"
android:singleLine="false"
android:background="@null"
@ -161,43 +150,37 @@
android:lineSpacingMultiplier="1.1"
android:textColorHint="?android:attr/textColorTertiary"
app:layout_constraintEnd_toStartOf="@+id/emojiButton"
app:layout_constraintRight_toLeftOf="@id/emojiButton"
app:layout_constraintStart_toEndOf="@+id/attachmentButton"
app:layout_constraintTop_toBottomOf="@id/attachmentLayout"
app:layout_constraintBottom_toBottomOf="parent"
tools:text="Just landed in L.A." />
<ImageButton
android:id="@+id/emojiButton"
style="@style/TuskyImageButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginEnd="4dp"
android:contentDescription="@string/action_emoji_keyboard"
android:tooltipText="@string/action_emoji_keyboard"
app:srcCompat="@drawable/ic_emoji_24dp"
app:layout_constraintTop_toBottomOf="@id/attachmentLayout"
app:layout_constraintRight_toLeftOf="@id/stickerButton"
/>
<ImageButton
android:id="@+id/stickerButton"
style="@style/TuskyImageButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginEnd="4dp"
android:contentDescription="@string/action_sticker"
android:tooltipText="@string/action_sticker"
app:srcCompat="@drawable/ic_sticker"
app:layout_constraintTop_toBottomOf="@id/attachmentLayout"
app:layout_constraintRight_toLeftOf="@id/sendButton"
/>
<ImageButton
android:id="@+id/sendButton"
style="@style/TuskyImageButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginEnd="4dp"
android:contentDescription="@string/action_send"
android:tooltipText="@string/action_send"
app:srcCompat="@drawable/ic_send_24dp"
@ -217,7 +200,6 @@
android:paddingStart="16dp"
android:paddingTop="8dp"
android:paddingEnd="16dp"
android:paddingBottom="@dimen/compose_activity_bottom_bar_height"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" />
@ -228,7 +210,6 @@
android:layout_height="300dp"
android:background="?attr/colorSurface"
android:elevation="12dp"
android:paddingBottom="@dimen/compose_activity_bottom_bar_height"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" />
@ -243,7 +224,6 @@
android:paddingStart="16dp"
android:paddingTop="8dp"
android:paddingEnd="16dp"
android:paddingBottom="52dp"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
@ -269,4 +249,5 @@
</LinearLayout>
<include layout="@layout/item_status_bottom_sheet" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Loading…
Cancel
Save