chats: implement creating new chat through account activity
This commit is contained in:
parent
0f6d0eaff0
commit
f8475f8615
|
@ -1,9 +1,11 @@
|
|||
<resources>
|
||||
<!-- HUSKY SPECIFIC STRINGS -->
|
||||
<string name="chats">Chats</string>
|
||||
<string name="chat_our_last_message">You: %s</string>
|
||||
<string name="action_mark_as_read">Mark as read</string>
|
||||
<string name="chat_our_last_message"><b>You</b></string>
|
||||
|
||||
<string name="error_chat_recipient_unavailable">Recipient does not support Chats</string>
|
||||
|
||||
<string name="action_mark_as_read">Mark as read</string>
|
||||
<string name="action_reply_to">Reply to</string>
|
||||
<string name="action_emoji_react">React</string>
|
||||
<string name="action_emoji_unreact">Remove reaction</string>
|
||||
|
@ -12,7 +14,8 @@
|
|||
<string name="action_disable_formatting_syntax">Disable %s</string>
|
||||
<string name="action_sticker">Stickers</string>
|
||||
<string name="action_open_in_external_app">Open in external app</string>
|
||||
<string name="action_chat">Open a chat</string>
|
||||
<string name="action_chat">Open chat</string>
|
||||
<string name="action_expand_menu">Expand menu</string>
|
||||
|
||||
<string name="title_emoji_reacted_by">%s reacted by</string>
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
|
||||
package com.keylesspalace.tusky
|
||||
|
||||
import android.animation.Animator
|
||||
import android.animation.AnimatorListenerAdapter
|
||||
import android.animation.ArgbEvaluator
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
|
@ -27,6 +29,7 @@ import android.view.Menu
|
|||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.activity.viewModels
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.Px
|
||||
|
@ -34,6 +37,7 @@ import androidx.appcompat.app.AlertDialog
|
|||
import androidx.core.app.ActivityOptionsCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.emoji.text.EmojiCompat
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
|
@ -48,6 +52,7 @@ import com.google.android.material.snackbar.Snackbar
|
|||
import com.google.android.material.tabs.TabLayout
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
import com.keylesspalace.tusky.adapter.AccountFieldAdapter
|
||||
import com.keylesspalace.tusky.components.chat.ChatActivity
|
||||
import com.keylesspalace.tusky.components.compose.ComposeActivity
|
||||
import com.keylesspalace.tusky.components.report.ReportActivity
|
||||
import com.keylesspalace.tusky.di.ViewModelFactory
|
||||
|
@ -61,8 +66,11 @@ import com.keylesspalace.tusky.interfaces.ReselectableFragment
|
|||
import com.keylesspalace.tusky.pager.AccountPagerAdapter
|
||||
import com.keylesspalace.tusky.util.*
|
||||
import com.keylesspalace.tusky.viewmodel.AccountViewModel
|
||||
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider.from
|
||||
import com.uber.autodispose.autoDispose
|
||||
import dagger.android.DispatchingAndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import kotlinx.android.synthetic.main.activity_account.*
|
||||
import kotlinx.android.synthetic.main.view_account_moved.*
|
||||
import java.text.NumberFormat
|
||||
|
@ -160,7 +168,6 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI
|
|||
accountMuteButton.hide()
|
||||
accountFollowsYouTextView.hide()
|
||||
|
||||
|
||||
// setup the RecyclerView for the account fields
|
||||
accountFieldList.isNestedScrollingEnabled = false
|
||||
accountFieldList.layoutManager = LinearLayoutManager(this)
|
||||
|
@ -279,6 +286,7 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI
|
|||
accountFloatingActionButton.show()
|
||||
}
|
||||
if (verticalOffset < oldOffset) {
|
||||
hideFabMenu()
|
||||
accountFloatingActionButton.hide()
|
||||
}
|
||||
}
|
||||
|
@ -494,6 +502,57 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI
|
|||
}
|
||||
}
|
||||
|
||||
private fun FloatingActionButton.menuAnimate(show: Boolean) {
|
||||
val height = this.height.toFloat()
|
||||
|
||||
if(show) {
|
||||
visibility = View.VISIBLE
|
||||
alpha = 0.0f
|
||||
translationY = height
|
||||
|
||||
animate().setDuration(200)
|
||||
.translationY(0.0f)
|
||||
.alpha(1.0f)
|
||||
.setListener(object : AnimatorListenerAdapter() {}) // seems listener is saved, so reset it here
|
||||
.start()
|
||||
} else {
|
||||
animate().setDuration(200)
|
||||
.translationY(height)
|
||||
.alpha(0.0f)
|
||||
.setListener(object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: Animator?) {
|
||||
visibility = View.GONE
|
||||
super.onAnimationEnd(animation)
|
||||
}
|
||||
})
|
||||
.start()
|
||||
}
|
||||
}
|
||||
|
||||
private fun hideFabMenu() {
|
||||
openedFabMenu = false
|
||||
|
||||
accountFloatingActionButton.animate().setDuration(200)
|
||||
.rotation(0.0f).start()
|
||||
accountFloatingActionButtonChat.menuAnimate(openedFabMenu)
|
||||
accountFloatingActionButtonMention.menuAnimate(openedFabMenu)
|
||||
|
||||
}
|
||||
|
||||
var openedFabMenu = false
|
||||
private fun animateFabMenu() {
|
||||
if(openedFabMenu) {
|
||||
hideFabMenu()
|
||||
} else {
|
||||
openedFabMenu = true
|
||||
|
||||
accountFloatingActionButton.animate().setDuration(200)
|
||||
.rotation(135.0f).start()
|
||||
accountFloatingActionButtonChat.menuAnimate(openedFabMenu)
|
||||
accountFloatingActionButtonMention.menuAnimate(openedFabMenu)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update account stat info
|
||||
*/
|
||||
|
@ -504,7 +563,28 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI
|
|||
accountFollowingTextView.text = numberFormat.format(account.followingCount)
|
||||
accountStatusesTextView.text = numberFormat.format(account.statusesCount)
|
||||
|
||||
accountFloatingActionButton.setOnClickListener { mention() }
|
||||
accountFloatingActionButtonMention.setOnClickListener { mention() }
|
||||
|
||||
if(account.pleroma?.acceptsChatMessages == true) {
|
||||
accountFloatingActionButtonChat.setOnClickListener {
|
||||
mastodonApi.createChat(account.id)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.autoDispose(from(this, Lifecycle.Event.ON_DESTROY))
|
||||
.subscribe({
|
||||
val intent = ChatActivity.getIntent(this@AccountActivity, it)
|
||||
startActivityWithSlideInAnimation(intent)
|
||||
}, {
|
||||
Toast.makeText(this@AccountActivity, getString(R.string.error_generic), Toast.LENGTH_SHORT).show()
|
||||
})
|
||||
}
|
||||
} else {
|
||||
accountFloatingActionButtonChat.backgroundTintList = ColorStateList.valueOf(Color.GRAY)
|
||||
accountFloatingActionButtonChat.setOnClickListener {
|
||||
Toast.makeText(this@AccountActivity, getString(R.string.error_chat_recipient_unavailable), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
accountFloatingActionButton.setOnClickListener { animateFabMenu() }
|
||||
|
||||
accountFollowButton.setOnClickListener {
|
||||
if (viewModel.isSelf) {
|
||||
|
@ -611,6 +691,7 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI
|
|||
updateFollowButton()
|
||||
|
||||
if (blocking || viewModel.isSelf) {
|
||||
hideFabMenu()
|
||||
accountFloatingActionButton.hide()
|
||||
accountMuteButton.hide()
|
||||
accountSubscribeButton.hide()
|
||||
|
@ -624,6 +705,7 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI
|
|||
}
|
||||
|
||||
} else {
|
||||
hideFabMenu()
|
||||
accountFloatingActionButton.hide()
|
||||
accountFollowButton.hide()
|
||||
accountMuteButton.hide()
|
||||
|
@ -827,6 +909,10 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI
|
|||
} else null
|
||||
}
|
||||
|
||||
override fun onActionButtonHidden() {
|
||||
hideFabMenu()
|
||||
}
|
||||
|
||||
override fun androidInjector() = dispatchingAndroidInjector
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -98,6 +98,7 @@ data class StringField (
|
|||
)
|
||||
|
||||
data class PleromaAccount(
|
||||
@SerializedName("accepts_chat_messages") val acceptsChatMessages: Boolean? = null,
|
||||
@SerializedName("is_moderator") val isModerator: Boolean? = null,
|
||||
@SerializedName("is_admin") val isAdmin: Boolean? = null
|
||||
)
|
||||
|
|
|
@ -474,6 +474,7 @@ public class TimelineFragment extends SFragment implements
|
|||
if (hideFab) {
|
||||
if (dy > 0 && composeButton.isShown()) {
|
||||
composeButton.hide(); // hides the button if we're scrolling down
|
||||
activity.onActionButtonHidden();
|
||||
} else if (dy < 0 && !composeButton.isShown()) {
|
||||
composeButton.show(); // shows it if we are scrolling up
|
||||
}
|
||||
|
|
|
@ -23,4 +23,6 @@ public interface ActionButtonActivity {
|
|||
/* return the ActionButton of the Activity to hide or show it on scroll */
|
||||
@Nullable
|
||||
FloatingActionButton getActionButton();
|
||||
|
||||
default void onActionButtonHidden() {}
|
||||
}
|
||||
|
|
|
@ -390,14 +390,38 @@
|
|||
android:background="?android:windowBackground"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/accountFloatingActionButtonChat"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:layout_marginBottom="128dp"
|
||||
android:contentDescription="@string/action_chat"
|
||||
android:visibility="gone"
|
||||
app:fabSize="mini"
|
||||
app:srcCompat="@drawable/ic_email_24dp" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/accountFloatingActionButtonMention"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:contentDescription="@string/action_mention"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:layout_marginBottom="80dp"
|
||||
android:visibility="gone"
|
||||
app:fabSize="mini"
|
||||
app:srcCompat="@drawable/ic_create_24dp" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/accountFloatingActionButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="16dp"
|
||||
android:contentDescription="@string/action_mention"
|
||||
app:srcCompat="@drawable/ic_create_24dp" />
|
||||
android:contentDescription="@string/action_expand_menu"
|
||||
app:srcCompat="@drawable/ic_plus_24dp" />
|
||||
|
||||
<include layout="@layout/item_status_bottom_sheet" />
|
||||
|
||||
|
|
Loading…
Reference in New Issue