remove adjustOptionsImage and refactor showPopupMenu
This commit is contained in:
parent
7e6a377dca
commit
cad6730906
1 changed files with 21 additions and 46 deletions
|
@ -37,9 +37,8 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
private val telegramHelper get() = app.telegramHelper
|
||||
|
||||
private lateinit var appBarLayout: AppBarLayout
|
||||
private lateinit var backgroundImage: ImageView
|
||||
private lateinit var userImage: ImageView
|
||||
private lateinit var optionsImage: ImageView
|
||||
private lateinit var optionsBtn: ImageView
|
||||
private lateinit var textContainer: LinearLayout
|
||||
private lateinit var title: TextView
|
||||
private lateinit var description: TextView
|
||||
|
@ -91,23 +90,19 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
appBarCollapsed = collapsed
|
||||
adjustText()
|
||||
adjustSearchBox()
|
||||
adjustOptionsImage()
|
||||
optionsBtn.visibility = if (collapsed) View.VISIBLE else View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
backgroundImage = mainView.findViewById<ImageView>(R.id.my_location_bg_image).apply {
|
||||
setImageResource(R.drawable.img_my_location_roadbg)
|
||||
}
|
||||
|
||||
userImage = mainView.findViewById<ImageView>(R.id.my_location_user_image).apply {
|
||||
setImageResource(R.drawable.img_my_location_user)
|
||||
}
|
||||
|
||||
optionsImage = mainView.findViewById<ImageView>(R.id.options).apply {
|
||||
optionsBtn = mainView.findViewById<ImageView>(R.id.options).apply {
|
||||
setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu))
|
||||
setOnClickListener {
|
||||
showPopupMenu(this@MyLocationTabFragment)
|
||||
showPopupMenu()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,47 +143,35 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
}
|
||||
|
||||
|
||||
private fun showPopupMenu(holder: MyLocationTabFragment) {
|
||||
val ctx = holder.context
|
||||
|
||||
private fun showPopupMenu() {
|
||||
val menuList = ArrayList<String>()
|
||||
when (telegramHelper.getTelegramAuthorizationState()) {
|
||||
TelegramHelper.TelegramAuthorizationState.UNKNOWN,
|
||||
TelegramHelper.TelegramAuthorizationState.WAIT_PARAMETERS,
|
||||
TelegramHelper.TelegramAuthorizationState.WAIT_PHONE_NUMBER,
|
||||
TelegramHelper.TelegramAuthorizationState.WAIT_CODE,
|
||||
TelegramHelper.TelegramAuthorizationState.WAIT_PASSWORD,
|
||||
TelegramHelper.TelegramAuthorizationState.LOGGING_OUT,
|
||||
TelegramHelper.TelegramAuthorizationState.CLOSING -> Toast.makeText(context, "${telegramHelper.getTelegramAuthorizationState()}", Toast.LENGTH_SHORT).show()
|
||||
TelegramHelper.TelegramAuthorizationState.READY -> menuList.add(0, getString(R.string.shared_string_logout))
|
||||
TelegramHelper.TelegramAuthorizationState.CLOSED -> menuList.add(0, getString(R.string.shared_string_login))
|
||||
val logout = getString(R.string.shared_string_logout)
|
||||
val login = getString(R.string.shared_string_login)
|
||||
if (telegramHelper.getTelegramAuthorizationState() == TelegramHelper.TelegramAuthorizationState.READY) {
|
||||
menuList.add(0, logout)
|
||||
} else if (telegramHelper.getTelegramAuthorizationState() == TelegramHelper.TelegramAuthorizationState.CLOSED) {
|
||||
menuList.add(0, login)
|
||||
}
|
||||
menuList.add(getString(R.string.shared_string_settings))
|
||||
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)
|
||||
val textWidth = paint.measureText(menuList[0])
|
||||
val itemWidth = textWidth.toInt() + AndroidUtils.dpToPx(context!!, 32F)
|
||||
val minWidth = AndroidUtils.dpToPx(context!!, 100F)
|
||||
|
||||
ListPopupWindow(ctx).apply {
|
||||
ListPopupWindow(context!!).apply {
|
||||
isModal = true
|
||||
anchorView = holder.optionsImage
|
||||
anchorView = optionsBtn
|
||||
setContentWidth(Math.max(minWidth, itemWidth))
|
||||
setDropDownGravity(Gravity.END or Gravity.TOP)
|
||||
setAdapter(ArrayAdapter(ctx, R.layout.popup_list_text_item, menuList))
|
||||
setAdapter(ArrayAdapter(context, R.layout.popup_list_text_item, menuList))
|
||||
setOnItemClickListener { _, _, position, _ ->
|
||||
when (position) {
|
||||
menuList.indexOf(getString(R.string.shared_string_logout)) -> {
|
||||
Toast.makeText(context, "$position - ${menuList[position]}", Toast.LENGTH_SHORT).show()
|
||||
menuList.indexOf(logout) -> {
|
||||
logoutTelegram()
|
||||
}
|
||||
menuList.indexOf(getString(R.string.shared_string_settings)) -> {
|
||||
Toast.makeText(context, "$position - ${menuList[position]}", Toast.LENGTH_SHORT).show()
|
||||
|
||||
} menuList.indexOf(getString(R.string.shared_string_login)) -> {
|
||||
Toast.makeText(context, "$position - ${menuList[position]}", Toast.LENGTH_SHORT).show()
|
||||
loginTelegram()
|
||||
}
|
||||
menuList.indexOf(login) -> {
|
||||
loginTelegram()
|
||||
}
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
|
@ -273,14 +256,6 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
actionButtonsListener?.switchButtonsVisibility(false)
|
||||
}
|
||||
|
||||
private fun adjustOptionsImage() {
|
||||
if (appBarCollapsed) {
|
||||
optionsImage.visibility = View.VISIBLE
|
||||
} else {
|
||||
optionsImage.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
private fun adjustText() {
|
||||
val gravity = if (appBarCollapsed) Gravity.START else Gravity.CENTER
|
||||
val padding = if (appBarCollapsed) textMarginSmall else textMarginBig
|
||||
|
|
Loading…
Reference in a new issue