Add selected chats list to the "Set time" screen
This commit is contained in:
parent
385ff6dc02
commit
948ffd1b8e
3 changed files with 110 additions and 8 deletions
|
@ -81,18 +81,27 @@
|
|||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"/>
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:paddingTop="9dp"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:scaleType="fitXY"
|
||||
android:src="?attr/bottom_nav_shadow"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/buttons_bottom_bar_height"
|
||||
|
|
|
@ -70,6 +70,25 @@
|
|||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<net.osmand.telegram.ui.views.TextViewEx
|
||||
android:id="@+id/text_in_area"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/dialog_button_height"
|
||||
android:layout_marginEnd="@dimen/image_button_padding"
|
||||
android:layout_marginRight="@dimen/image_button_padding"
|
||||
android:background="?attr/secondary_btn_bg"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:maxLines="1"
|
||||
android:paddingLeft="@dimen/image_button_padding"
|
||||
android:paddingRight="@dimen/image_button_padding"
|
||||
android:textColor="?attr/ctrl_active_color"
|
||||
android:textSize="@dimen/text_button_text_size"
|
||||
android:visibility="gone"
|
||||
app:typeface="@string/font_roboto_medium"
|
||||
tools:text="1 h"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
|
|
@ -3,6 +3,8 @@ package net.osmand.telegram.ui
|
|||
import android.os.Bundle
|
||||
import android.support.v4.app.DialogFragment
|
||||
import android.support.v4.app.FragmentManager
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
@ -11,12 +13,21 @@ import android.widget.TextView
|
|||
import android.widget.Toast
|
||||
import net.osmand.telegram.R
|
||||
import net.osmand.telegram.TelegramApplication
|
||||
import net.osmand.telegram.helpers.TelegramUiHelper
|
||||
import net.osmand.telegram.ui.SetTimeDialogFragment.SetTimeListAdapter.ChatViewHolder
|
||||
import org.drinkless.td.libcore.telegram.TdApi
|
||||
|
||||
class SetTimeDialogFragment : DialogFragment() {
|
||||
|
||||
private val app: TelegramApplication
|
||||
get() = activity?.application as TelegramApplication
|
||||
|
||||
private val telegramHelper get() = app.telegramHelper
|
||||
|
||||
private val adapter = SetTimeListAdapter()
|
||||
|
||||
private val chatIds = HashSet<Long>()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setStyle(DialogFragment.STYLE_NO_FRAME, R.style.AppTheme_NoActionbar)
|
||||
|
@ -27,6 +38,10 @@ class SetTimeDialogFragment : DialogFragment() {
|
|||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
arguments?.apply {
|
||||
chatIds.addAll(getLongArray(CHATS_KEY).toSet())
|
||||
}
|
||||
|
||||
val view = inflater.inflate(R.layout.fragment_set_time_dialog, container)
|
||||
|
||||
view.findViewById<View>(R.id.time_for_all_row).apply {
|
||||
|
@ -39,6 +54,11 @@ class SetTimeDialogFragment : DialogFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
view.findViewById<RecyclerView>(R.id.recycler_view).apply {
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
adapter = this@SetTimeDialogFragment.adapter
|
||||
}
|
||||
|
||||
view.findViewById<TextView>(R.id.secondary_btn).apply {
|
||||
text = getString(R.string.shared_string_back)
|
||||
setOnClickListener {
|
||||
|
@ -56,6 +76,60 @@ class SetTimeDialogFragment : DialogFragment() {
|
|||
return view
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
updateList()
|
||||
}
|
||||
|
||||
private fun updateList() {
|
||||
val chats: MutableList<TdApi.Chat> = mutableListOf()
|
||||
telegramHelper.getChatList().filter { chatIds.contains(it.chatId) }.forEach { orderedChat ->
|
||||
telegramHelper.getChat(orderedChat.chatId)?.also { chats.add(it) }
|
||||
}
|
||||
adapter.chats = chats
|
||||
}
|
||||
|
||||
inner class SetTimeListAdapter : 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]
|
||||
|
||||
TelegramUiHelper.setupPhoto(app, holder.icon, chat.photo?.small?.local?.path)
|
||||
holder.title?.text = chat.title
|
||||
holder.description?.text = "Some description" // FIXME
|
||||
holder.textInArea?.apply {
|
||||
visibility = View.VISIBLE
|
||||
text = "1 h"
|
||||
}
|
||||
holder.bottomShadow?.visibility = View.GONE
|
||||
holder.itemView.setOnClickListener {
|
||||
Toast.makeText(context, chat.title, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
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 textInArea: TextView? = view.findViewById(R.id.text_in_area)
|
||||
val bottomShadow: View? = view.findViewById(R.id.bottom_shadow)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private const val TAG = "SetTimeDialogFragment"
|
||||
|
|
Loading…
Reference in a new issue