Add chats list to the "My location" tab
This commit is contained in:
parent
50db75c017
commit
4c553ac008
5 changed files with 173 additions and 27 deletions
|
@ -4,8 +4,7 @@
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent">
|
||||||
android:background="?attr/card_bg_color">
|
|
||||||
|
|
||||||
<android.support.design.widget.AppBarLayout
|
<android.support.design.widget.AppBarLayout
|
||||||
android:id="@+id/app_bar_layout"
|
android:id="@+id/app_bar_layout"
|
||||||
|
@ -96,28 +95,12 @@
|
||||||
|
|
||||||
</android.support.design.widget.AppBarLayout>
|
</android.support.design.widget.AppBarLayout>
|
||||||
|
|
||||||
<android.support.v4.widget.NestedScrollView
|
<android.support.v7.widget.RecyclerView
|
||||||
|
android:id="@+id/recycler_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:paddingTop="@dimen/content_padding_small"
|
android:clipToPadding="false"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
android:paddingBottom="@dimen/list_view_bottom_padding"
|
||||||
|
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<View
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="350dp"/>
|
|
||||||
|
|
||||||
<View
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="350dp"
|
|
||||||
android:background="@android:color/holo_blue_light"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</android.support.v4.widget.NestedScrollView>
|
|
||||||
|
|
||||||
</android.support.design.widget.CoordinatorLayout>
|
</android.support.design.widget.CoordinatorLayout>
|
||||||
|
|
|
@ -57,6 +57,15 @@
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/check_box"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="@dimen/content_padding_standard"
|
||||||
|
android:layout_marginRight="@dimen/content_padding_standard"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<dimen name="dialog_button_height">36dp</dimen>
|
<dimen name="dialog_button_height">36dp</dimen>
|
||||||
<dimen name="dialog_button_radius">2dp</dimen>
|
<dimen name="dialog_button_radius">2dp</dimen>
|
||||||
|
|
||||||
<dimen name="list_item_height">60dp</dimen>
|
<dimen name="list_item_height">56dp</dimen>
|
||||||
<dimen name="list_item_height_min">48dp</dimen>
|
<dimen name="list_item_height_min">48dp</dimen>
|
||||||
|
|
||||||
<dimen name="list_item_icon_size">32dp</dimen>
|
<dimen name="list_item_icon_size">32dp</dimen>
|
||||||
|
|
|
@ -411,7 +411,7 @@ class MainActivity : AppCompatActivity(), TelegramListener {
|
||||||
|
|
||||||
class ViewPagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) {
|
class ViewPagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) {
|
||||||
|
|
||||||
private val fragments = listOf(MyLocationTabFragment(), LiveNowTabFragment())
|
private val fragments = listOf<Fragment>(MyLocationTabFragment(), LiveNowTabFragment())
|
||||||
|
|
||||||
override fun getItem(position: Int) = fragments[position]
|
override fun getItem(position: Int) = fragments[position]
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,30 @@
|
||||||
package net.osmand.telegram.ui
|
package net.osmand.telegram.ui
|
||||||
|
|
||||||
import android.animation.*
|
import android.animation.*
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
import android.graphics.drawable.GradientDrawable
|
import android.graphics.drawable.GradientDrawable
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.design.widget.AppBarLayout
|
import android.support.design.widget.AppBarLayout
|
||||||
import android.support.v4.app.Fragment
|
import android.support.v4.app.Fragment
|
||||||
import android.support.v4.content.ContextCompat
|
import android.support.v4.content.ContextCompat
|
||||||
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
|
import android.support.v7.widget.RecyclerView
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
import net.osmand.telegram.R
|
import net.osmand.telegram.R
|
||||||
import net.osmand.telegram.TelegramApplication
|
import net.osmand.telegram.TelegramApplication
|
||||||
|
import net.osmand.telegram.helpers.TelegramHelper
|
||||||
|
import net.osmand.telegram.helpers.TelegramHelper.TelegramListener
|
||||||
|
import net.osmand.telegram.ui.MyLocationTabFragment.MyLocationListAdapter.ChatViewHolder
|
||||||
|
import org.drinkless.td.libcore.telegram.TdApi
|
||||||
|
|
||||||
class MyLocationTabFragment : Fragment() {
|
class MyLocationTabFragment : Fragment(), TelegramListener {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val SELECTED_CHATS_KEY = "selected_chats"
|
||||||
|
}
|
||||||
|
|
||||||
private var textMarginSmall: Int = 0
|
private var textMarginSmall: Int = 0
|
||||||
private var textMarginBig: Int = 0
|
private var textMarginBig: Int = 0
|
||||||
|
@ -22,6 +34,8 @@ class MyLocationTabFragment : Fragment() {
|
||||||
private val app: TelegramApplication
|
private val app: TelegramApplication
|
||||||
get() = activity?.application as TelegramApplication
|
get() = activity?.application as TelegramApplication
|
||||||
|
|
||||||
|
private val telegramHelper get() = app.telegramHelper
|
||||||
|
|
||||||
private lateinit var appBarLayout: AppBarLayout
|
private lateinit var appBarLayout: AppBarLayout
|
||||||
private lateinit var textContainer: LinearLayout
|
private lateinit var textContainer: LinearLayout
|
||||||
private lateinit var title: TextView
|
private lateinit var title: TextView
|
||||||
|
@ -30,9 +44,13 @@ class MyLocationTabFragment : Fragment() {
|
||||||
|
|
||||||
private lateinit var searchBoxBg: GradientDrawable
|
private lateinit var searchBoxBg: GradientDrawable
|
||||||
|
|
||||||
|
private val adapter = MyLocationListAdapter()
|
||||||
|
|
||||||
private var appBarCollapsed = false
|
private var appBarCollapsed = false
|
||||||
private lateinit var appBarOutlineProvider: ViewOutlineProvider
|
private lateinit var appBarOutlineProvider: ViewOutlineProvider
|
||||||
|
|
||||||
|
private val selectedChats = HashSet<Long>()
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
|
@ -43,6 +61,10 @@ class MyLocationTabFragment : Fragment() {
|
||||||
searchBoxHeight = resources.getDimensionPixelSize(R.dimen.search_box_height)
|
searchBoxHeight = resources.getDimensionPixelSize(R.dimen.search_box_height)
|
||||||
searchBoxSidesMargin = resources.getDimensionPixelSize(R.dimen.content_padding_half)
|
searchBoxSidesMargin = resources.getDimensionPixelSize(R.dimen.content_padding_half)
|
||||||
|
|
||||||
|
savedInstanceState?.apply {
|
||||||
|
selectedChats.addAll(getLongArray(SELECTED_CHATS_KEY).toSet())
|
||||||
|
}
|
||||||
|
|
||||||
val mainView = inflater.inflate(R.layout.fragment_my_location_tab, container, false)
|
val mainView = inflater.inflate(R.layout.fragment_my_location_tab, container, false)
|
||||||
|
|
||||||
appBarLayout = mainView.findViewById<AppBarLayout>(R.id.app_bar_layout).apply {
|
appBarLayout = mainView.findViewById<AppBarLayout>(R.id.app_bar_layout).apply {
|
||||||
|
@ -88,13 +110,68 @@ class MyLocationTabFragment : Fragment() {
|
||||||
.setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_search_dark))
|
.setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_search_dark))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mainView.findViewById<RecyclerView>(R.id.recycler_view).apply {
|
||||||
|
layoutManager = LinearLayoutManager(context)
|
||||||
|
adapter = this@MyLocationTabFragment.adapter
|
||||||
|
}
|
||||||
|
|
||||||
return mainView
|
return mainView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
updateList()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSaveInstanceState(outState: Bundle) {
|
||||||
|
super.onSaveInstanceState(outState)
|
||||||
|
outState.putLongArray(SELECTED_CHATS_KEY, selectedChats.toLongArray())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTelegramStatusChanged(
|
||||||
|
prevTelegramAuthorizationState: TelegramHelper.TelegramAuthorizationState,
|
||||||
|
newTelegramAuthorizationState: TelegramHelper.TelegramAuthorizationState
|
||||||
|
) {
|
||||||
|
when (newTelegramAuthorizationState) {
|
||||||
|
TelegramHelper.TelegramAuthorizationState.READY -> {
|
||||||
|
updateList()
|
||||||
|
}
|
||||||
|
TelegramHelper.TelegramAuthorizationState.CLOSED,
|
||||||
|
TelegramHelper.TelegramAuthorizationState.UNKNOWN -> {
|
||||||
|
adapter.chats = emptyList()
|
||||||
|
}
|
||||||
|
else -> Unit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTelegramChatsRead() {
|
||||||
|
updateList()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTelegramChatsChanged() {
|
||||||
|
updateList()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTelegramChatChanged(chat: TdApi.Chat) {
|
||||||
|
updateList()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTelegramUserChanged(user: TdApi.User) {
|
||||||
|
updateList()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTelegramError(code: Int, message: String) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSendLiveLocationError(code: Int, message: String) {
|
||||||
|
}
|
||||||
|
|
||||||
private fun adjustText() {
|
private fun adjustText() {
|
||||||
val gravity = if (appBarCollapsed) Gravity.START else Gravity.CENTER
|
val gravity = if (appBarCollapsed) Gravity.START else Gravity.CENTER
|
||||||
val padding = if (appBarCollapsed) textMarginSmall else textMarginBig
|
val padding = if (appBarCollapsed) textMarginSmall else textMarginBig
|
||||||
textContainer.setPadding(padding, 0, padding, 0)
|
textContainer.apply {
|
||||||
|
setPadding(padding, paddingTop, padding, paddingBottom)
|
||||||
|
}
|
||||||
title.gravity = gravity
|
title.gravity = gravity
|
||||||
description.gravity = gravity
|
description.gravity = gravity
|
||||||
}
|
}
|
||||||
|
@ -138,4 +215,81 @@ class MyLocationTabFragment : Fragment() {
|
||||||
}
|
}
|
||||||
animatorSet.start()
|
animatorSet.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateList() {
|
||||||
|
val chatList = telegramHelper.getChatList()
|
||||||
|
val chats: MutableList<TdApi.Chat> = mutableListOf()
|
||||||
|
for (orderedChat in chatList) {
|
||||||
|
val chat = telegramHelper.getChat(orderedChat.chatId)
|
||||||
|
if (chat != null) {
|
||||||
|
chats.add(chat)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
adapter.chats = chats
|
||||||
|
}
|
||||||
|
|
||||||
|
inner class MyLocationListAdapter : RecyclerView.Adapter<ChatViewHolder>() {
|
||||||
|
|
||||||
|
var chats: List<TdApi.Chat> = emptyList()
|
||||||
|
set(value) {
|
||||||
|
field = value
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChatViewHolder {
|
||||||
|
val view = LayoutInflater.from(parent.context)
|
||||||
|
.inflate(R.layout.user_list_item, parent, false)
|
||||||
|
return ChatViewHolder(view)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: ChatViewHolder, position: Int) {
|
||||||
|
val chat = chats[position]
|
||||||
|
val lastItem = position == itemCount - 1
|
||||||
|
|
||||||
|
var drawable: Drawable? = null
|
||||||
|
var bitmap: Bitmap? = null
|
||||||
|
val chatPhoto = chat.photo?.small
|
||||||
|
if (chatPhoto != null && chatPhoto.local.path.isNotEmpty()) {
|
||||||
|
bitmap = app.uiUtils.getCircleBitmap(chatPhoto.local.path)
|
||||||
|
}
|
||||||
|
if (bitmap == null) {
|
||||||
|
drawable = app.uiUtils.getThemedIcon(R.drawable.ic_group)
|
||||||
|
}
|
||||||
|
if (bitmap != null) {
|
||||||
|
holder.icon?.setImageBitmap(bitmap)
|
||||||
|
} else {
|
||||||
|
holder.icon?.setImageDrawable(drawable)
|
||||||
|
}
|
||||||
|
holder.title?.text = chat.title
|
||||||
|
holder.description?.text = "Some description" // FIXME
|
||||||
|
holder.checkBox?.apply {
|
||||||
|
visibility = View.VISIBLE
|
||||||
|
setOnCheckedChangeListener(null)
|
||||||
|
isChecked = selectedChats.contains(chat.id)
|
||||||
|
setOnCheckedChangeListener { _, isChecked ->
|
||||||
|
if (isChecked) {
|
||||||
|
selectedChats.add(chat.id)
|
||||||
|
} else {
|
||||||
|
selectedChats.remove(chat.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
holder.bottomShadow?.visibility = if (lastItem) View.VISIBLE else View.GONE
|
||||||
|
holder.itemView.setOnClickListener {
|
||||||
|
holder.checkBox?.apply {
|
||||||
|
isChecked = !isChecked
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount() = chats.size
|
||||||
|
|
||||||
|
inner class ChatViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
|
||||||
|
val icon: ImageView? = view.findViewById(R.id.icon)
|
||||||
|
val title: TextView? = view.findViewById(R.id.title)
|
||||||
|
val description: TextView? = view.findViewById(R.id.description)
|
||||||
|
val checkBox: CheckBox? = view.findViewById(R.id.check_box)
|
||||||
|
val bottomShadow: View? = view.findViewById(R.id.bottom_shadow)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue