reverse chat direction

This commit is contained in:
Phillip Thelen 2019-10-24 13:28:39 +02:00
parent 28b27f972a
commit 6f541e7189
4 changed files with 16 additions and 37 deletions

View file

@ -149,7 +149,7 @@ android {
multiDexEnabled true
resConfigs "en", "bg", "de", "en-rGB", "es", "fr", "hr-rHR", "in", "it", "iw", "ja", "ko", "lt", "nl", "pl", "pt-rBR", "pt-rPT", "ru", "tr", "zh", "zh-rTW"
versionCode 2271
versionCode 2274
versionName "2.2.1"
}

View file

@ -3,16 +3,11 @@
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
android:layout_height="0dp"
android:layout_weight="1"/>
<com.habitrpg.android.habitica.ui.views.social.ChatBarView
android:id="@+id/chatBarView"
android:layout_width="match_parent"

View file

@ -11,7 +11,6 @@ import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.habitrpg.android.habitica.MainNavDirections
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.components.UserComponent
@ -37,7 +36,7 @@ import kotlinx.android.synthetic.main.tavern_chat_new_entry_item.*
import java.util.concurrent.TimeUnit
import javax.inject.Inject
class ChatFragment : BaseFragment(), SwipeRefreshLayout.OnRefreshListener {
class ChatFragment : BaseFragment() {
var viewModel: GroupViewModel? = null
@ -61,9 +60,10 @@ class ChatFragment : BaseFragment(), SwipeRefreshLayout.OnRefreshListener {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
refreshLayout.setOnRefreshListener(this)
val layoutManager = LinearLayoutManager(context)
layoutManager.reverseLayout = true
layoutManager.stackFromEnd = true
recyclerView.layoutManager = layoutManager
chatAdapter = ChatRecyclerViewAdapter(null, true, null, true)
@ -93,7 +93,7 @@ class ChatFragment : BaseFragment(), SwipeRefreshLayout.OnRefreshListener {
}
})
refresh(false)
refresh()
viewModel?.getChatMessages()?.subscribe(Consumer<RealmResults<ChatMessage>> { this.setChatMessages(it) }, RxErrorHandler.handleEmptyError())?.let { compositeSubscription.add(it) }
@ -137,7 +137,7 @@ class ChatFragment : BaseFragment(), SwipeRefreshLayout.OnRefreshListener {
refreshDisposable = Observable.interval(30, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
refresh(false)
refresh()
}, RxErrorHandler.handleEmptyError())
}
@ -156,16 +156,8 @@ class ChatFragment : BaseFragment(), SwipeRefreshLayout.OnRefreshListener {
chatEditText.setText("@$username $previousText", TextView.BufferType.EDITABLE)
}
override fun onRefresh() {
refresh(true)
}
private fun refresh(isUserInitiated: Boolean) {
if (isUserInitiated) {
refreshLayout.isRefreshing = true
}
private fun refresh() {
viewModel?.retrieveGroupChat {
refreshLayout?.isRefreshing = false
if (isScrolledToTop && recyclerView != null) {
recyclerView.scrollToPosition(0)
}

View file

@ -10,7 +10,6 @@ import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.habitrpg.android.habitica.MainNavDirections
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.components.UserComponent
@ -38,7 +37,7 @@ import kotlinx.android.synthetic.main.tavern_chat_new_entry_item.*
import java.util.concurrent.TimeUnit
import javax.inject.Inject
class ChatListFragment : BaseFragment(), SwipeRefreshLayout.OnRefreshListener {
class ChatListFragment : BaseFragment() {
@Inject
lateinit var socialRepository: SocialRepository
@ -108,9 +107,10 @@ class ChatListFragment : BaseFragment(), SwipeRefreshLayout.OnRefreshListener {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
refreshLayout.setOnRefreshListener(this)
val layoutManager = LinearLayoutManager(context)
layoutManager.reverseLayout = true
layoutManager.stackFromEnd = true
recyclerView.layoutManager = layoutManager
chatAdapter = ChatRecyclerViewAdapter(null, true, user, true)
@ -163,7 +163,7 @@ class ChatListFragment : BaseFragment(), SwipeRefreshLayout.OnRefreshListener {
}
})
refresh(false)
refresh()
}
override fun onDestroyView() {
@ -187,7 +187,7 @@ class ChatListFragment : BaseFragment(), SwipeRefreshLayout.OnRefreshListener {
refreshDisposable = Observable.interval(30, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
refresh(false)
refresh()
}, RxErrorHandler.handleEmptyError())
}
@ -206,17 +206,9 @@ class ChatListFragment : BaseFragment(), SwipeRefreshLayout.OnRefreshListener {
chatEditText.setText("@$username $previousText", TextView.BufferType.EDITABLE)
}
override fun onRefresh() {
refresh(true)
}
private fun refresh(isUserInitiated: Boolean) {
if (isUserInitiated) {
refreshLayout.isRefreshing = true
}
private fun refresh() {
groupId?.let {id ->
socialRepository.retrieveGroupChat(id)
.doOnEvent { _, _ -> refreshLayout?.isRefreshing = false }.subscribe(Consumer {
socialRepository.retrieveGroupChat(id).subscribe(Consumer {
if (isScrolledToTop && recyclerView != null) {
recyclerView.scrollToPosition(0)
}