Replace "show on map switch" with text and popup menu
This commit is contained in:
parent
742a4a6dbf
commit
c77d09acfe
3 changed files with 77 additions and 44 deletions
|
@ -86,7 +86,7 @@
|
||||||
android:paddingRight="@dimen/content_padding_standard"
|
android:paddingRight="@dimen/content_padding_standard"
|
||||||
android:paddingStart="@dimen/list_item_content_margin">
|
android:paddingStart="@dimen/list_item_content_margin">
|
||||||
|
|
||||||
<TextView
|
<net.osmand.telegram.ui.views.TextViewEx
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="@dimen/content_padding_standard"
|
android:layout_marginEnd="@dimen/content_padding_standard"
|
||||||
|
@ -94,13 +94,17 @@
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="@string/show_on_map"
|
android:text="@string/show_on_map"
|
||||||
android:textAppearance="?attr/textAppearanceListItemSecondary"
|
android:textAppearance="?attr/textAppearanceListItemSecondary"
|
||||||
android:textColor="?attr/ctrl_active_color"
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
android:textStyle="bold"/>
|
app:typeface="@string/font_roboto_medium"/>
|
||||||
|
|
||||||
<Switch
|
<net.osmand.telegram.ui.views.TextViewEx
|
||||||
android:id="@+id/show_on_map_switch"
|
android:id="@+id/show_on_map_state"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="?attr/textAppearanceListItemSecondary"
|
||||||
|
android:textColor="?attr/ctrl_active_color"
|
||||||
|
app:typeface="@string/font_roboto_medium"
|
||||||
|
tools:text="All"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
<resources>
|
<resources>
|
||||||
|
<string name="shared_string_all">All</string>
|
||||||
|
<string name="shared_string_off">Off</string>
|
||||||
<string name="set_visible_time_for_all">Set visible time for all</string>
|
<string name="set_visible_time_for_all">Set visible time for all</string>
|
||||||
<string name="hours_and_minutes_format">%1$d h %2$d m</string>
|
<string name="hours_and_minutes_format">%1$d h %2$d m</string>
|
||||||
<string name="minutes_format">%1$d m</string>
|
<string name="minutes_format">%1$d m</string>
|
||||||
|
|
|
@ -1,21 +1,24 @@
|
||||||
package net.osmand.telegram.ui
|
package net.osmand.telegram.ui
|
||||||
|
|
||||||
|
import android.graphics.Paint
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v4.app.Fragment
|
import android.support.v4.app.Fragment
|
||||||
import android.support.v7.widget.LinearLayoutManager
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
|
import android.support.v7.widget.ListPopupWindow
|
||||||
import android.support.v7.widget.RecyclerView
|
import android.support.v7.widget.RecyclerView
|
||||||
|
import android.view.Gravity
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.ArrayAdapter
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.Switch
|
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
|
||||||
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
|
||||||
import net.osmand.telegram.helpers.TelegramHelper.*
|
import net.osmand.telegram.helpers.TelegramHelper.*
|
||||||
import net.osmand.telegram.helpers.TelegramUiHelper
|
import net.osmand.telegram.helpers.TelegramUiHelper
|
||||||
|
import net.osmand.telegram.utils.AndroidUtils
|
||||||
import org.drinkless.td.libcore.telegram.TdApi
|
import org.drinkless.td.libcore.telegram.TdApi
|
||||||
|
|
||||||
private const val CHAT_VIEW_TYPE = 0
|
private const val CHAT_VIEW_TYPE = 0
|
||||||
|
@ -30,7 +33,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
private val osmandHelper get() = app.osmandHelper
|
private val osmandHelper get() = app.osmandHelper
|
||||||
private val settings get() = app.settings
|
private val settings get() = app.settings
|
||||||
|
|
||||||
private val adapter = LiveNowListAdapter()
|
private lateinit var adapter: LiveNowListAdapter
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
|
@ -38,6 +41,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
): View? {
|
||||||
val mainView = inflater.inflate(R.layout.fragment_live_now_tab, container, false)
|
val mainView = inflater.inflate(R.layout.fragment_live_now_tab, container, false)
|
||||||
|
adapter = LiveNowListAdapter()
|
||||||
mainView.findViewById<RecyclerView>(R.id.recycler_view).apply {
|
mainView.findViewById<RecyclerView>(R.id.recycler_view).apply {
|
||||||
layoutManager = LinearLayoutManager(context)
|
layoutManager = LinearLayoutManager(context)
|
||||||
adapter = this@LiveNowTabFragment.adapter
|
adapter = this@LiveNowTabFragment.adapter
|
||||||
|
@ -125,6 +129,9 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
|
|
||||||
inner class LiveNowListAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
inner class LiveNowListAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||||
|
|
||||||
|
private val menuList =
|
||||||
|
listOf(getString(R.string.shared_string_off), getString(R.string.shared_string_all))
|
||||||
|
|
||||||
var items: List<Any> = emptyList()
|
var items: List<Any> = emptyList()
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
|
@ -156,44 +163,14 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
if (item is TdApi.Chat && holder is ChatViewHolder) {
|
if (item is TdApi.Chat && holder is ChatViewHolder) {
|
||||||
val nextItemIsUser = !lastItem && items[position + 1] is TdApi.User
|
val nextItemIsUser = !lastItem && items[position + 1] is TdApi.User
|
||||||
val chatTitle = item.title
|
val chatTitle = item.title
|
||||||
|
val stateTextInd = if (settings.isShowingChatOnMap(chatTitle)) 1 else 0
|
||||||
|
|
||||||
TelegramUiHelper.setupPhoto(app, holder.icon, item.photo?.small?.local?.path)
|
TelegramUiHelper.setupPhoto(app, holder.icon, item.photo?.small?.local?.path)
|
||||||
holder.title?.text = chatTitle
|
holder.title?.text = chatTitle
|
||||||
holder.description?.text = "Chat description" // FIXME
|
holder.description?.text = "Chat description" // FIXME
|
||||||
holder.imageButton?.setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_overflow_menu_white))
|
holder.imageButton?.visibility = View.GONE
|
||||||
holder.imageButton?.setOnClickListener {
|
holder.showOnMapRow?.setOnClickListener { showPopupMenu(holder, chatTitle) }
|
||||||
Toast.makeText(context, "Options", Toast.LENGTH_SHORT).show() // FIXME
|
holder.showOnMapState?.text = menuList[stateTextInd]
|
||||||
}
|
|
||||||
holder.showOnMapRow?.setOnClickListener {
|
|
||||||
holder.showOnMapSwitch?.isChecked = !holder.showOnMapSwitch?.isChecked!!
|
|
||||||
}
|
|
||||||
holder.showOnMapSwitch?.setOnCheckedChangeListener(null)
|
|
||||||
holder.showOnMapSwitch?.isChecked = settings.isShowingChatOnMap(chatTitle)
|
|
||||||
holder.showOnMapSwitch?.setOnCheckedChangeListener { _, isChecked ->
|
|
||||||
settings.showChatOnMap(chatTitle, isChecked)
|
|
||||||
if (settings.hasAnyChatToShowOnMap()) {
|
|
||||||
if (osmandHelper.isOsmandNotInstalled()) {
|
|
||||||
if (isChecked) {
|
|
||||||
activity?.let {
|
|
||||||
MainActivity.OsmandMissingDialogFragment()
|
|
||||||
.show(it.supportFragmentManager, null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (isChecked) {
|
|
||||||
app.showLocationHelper.showChatMessages(chatTitle)
|
|
||||||
} else {
|
|
||||||
app.showLocationHelper.hideChatMessages(chatTitle)
|
|
||||||
}
|
|
||||||
app.showLocationHelper.startShowingLocation()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
app.showLocationHelper.stopShowingLocation()
|
|
||||||
if (!isChecked) {
|
|
||||||
app.showLocationHelper.hideChatMessages(chatTitle)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
holder.bottomDivider?.visibility = if (nextItemIsUser) View.VISIBLE else View.GONE
|
holder.bottomDivider?.visibility = if (nextItemIsUser) View.VISIBLE else View.GONE
|
||||||
holder.bottomShadow?.visibility = if (lastItem) View.VISIBLE else View.GONE
|
holder.bottomShadow?.visibility = if (lastItem) View.VISIBLE else View.GONE
|
||||||
} else if (item is TdApi.User && holder is ContactViewHolder) {
|
} else if (item is TdApi.User && holder is ContactViewHolder) {
|
||||||
|
@ -211,6 +188,56 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
|
|
||||||
override fun getItemCount() = items.size
|
override fun getItemCount() = items.size
|
||||||
|
|
||||||
|
private fun showPopupMenu(holder: ChatViewHolder, chatTitle: String) {
|
||||||
|
val ctx = holder.itemView.context
|
||||||
|
|
||||||
|
val paint = Paint()
|
||||||
|
paint.textSize =
|
||||||
|
resources.getDimensionPixelSize(R.dimen.list_item_title_text_size).toFloat()
|
||||||
|
val textWidth = Math.max(paint.measureText(menuList[0]), paint.measureText(menuList[1]))
|
||||||
|
val itemWidth = textWidth.toInt() + AndroidUtils.dpToPx(ctx, 32F)
|
||||||
|
val minWidth = AndroidUtils.dpToPx(ctx, 100F)
|
||||||
|
|
||||||
|
ListPopupWindow(ctx).apply {
|
||||||
|
isModal = true
|
||||||
|
anchorView = holder.showOnMapState
|
||||||
|
setContentWidth(Math.max(minWidth, itemWidth))
|
||||||
|
setDropDownGravity(Gravity.END or Gravity.TOP)
|
||||||
|
setAdapter(ArrayAdapter(ctx, R.layout.popup_list_text_item, menuList))
|
||||||
|
setOnItemClickListener { _, _, position, _ ->
|
||||||
|
val allSelected = position == 1
|
||||||
|
|
||||||
|
settings.showChatOnMap(chatTitle, allSelected)
|
||||||
|
if (settings.hasAnyChatToShowOnMap()) {
|
||||||
|
if (osmandHelper.isOsmandNotInstalled()) {
|
||||||
|
if (allSelected) {
|
||||||
|
activity?.let {
|
||||||
|
MainActivity.OsmandMissingDialogFragment()
|
||||||
|
.show(it.supportFragmentManager, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (allSelected) {
|
||||||
|
app.showLocationHelper.showChatMessages(chatTitle)
|
||||||
|
} else {
|
||||||
|
app.showLocationHelper.hideChatMessages(chatTitle)
|
||||||
|
}
|
||||||
|
app.showLocationHelper.startShowingLocation()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
app.showLocationHelper.stopShowingLocation()
|
||||||
|
if (!allSelected) {
|
||||||
|
app.showLocationHelper.hideChatMessages(chatTitle)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
holder.showOnMapState?.text = menuList[position]
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inner class ContactViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
|
inner class ContactViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
|
||||||
val icon: ImageView? = view.findViewById(R.id.icon)
|
val icon: ImageView? = view.findViewById(R.id.icon)
|
||||||
val title: TextView? = view.findViewById(R.id.title)
|
val title: TextView? = view.findViewById(R.id.title)
|
||||||
|
@ -224,7 +251,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
val description: TextView? = view.findViewById(R.id.description)
|
val description: TextView? = view.findViewById(R.id.description)
|
||||||
val imageButton: ImageView? = view.findViewById(R.id.image_button)
|
val imageButton: ImageView? = view.findViewById(R.id.image_button)
|
||||||
val showOnMapRow: View? = view.findViewById(R.id.show_on_map_row)
|
val showOnMapRow: View? = view.findViewById(R.id.show_on_map_row)
|
||||||
val showOnMapSwitch: Switch? = view.findViewById(R.id.show_on_map_switch)
|
val showOnMapState: TextView? = view.findViewById(R.id.show_on_map_state)
|
||||||
val bottomDivider: View? = view.findViewById(R.id.bottom_divider)
|
val bottomDivider: View? = view.findViewById(R.id.bottom_divider)
|
||||||
val bottomShadow: View? = view.findViewById(R.id.bottom_shadow)
|
val bottomShadow: View? = view.findViewById(R.id.bottom_shadow)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue