Merge pull request #5663 from osmandapp/MyLocationUiImprovements
Improve my location UI
This commit is contained in:
commit
5930856428
6 changed files with 124 additions and 12 deletions
|
@ -12,12 +12,27 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:background="?attr/card_bg_color">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/my_location_image"
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/my_location_image_height"
|
||||
android:background="@android:color/holo_green_light"
|
||||
app:layout_scrollFlags="scroll"/>
|
||||
app:layout_scrollFlags="scroll">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/my_location_bg_image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/img_my_location_roadbg" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/my_location_user_image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:paddingTop="@dimen/content_padding_standard"
|
||||
tools:src="@drawable/img_my_location_user" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/text_container"
|
||||
|
@ -28,7 +43,7 @@
|
|||
android:paddingLeft="@dimen/my_location_text_sides_margin"
|
||||
android:paddingRight="@dimen/my_location_text_sides_margin">
|
||||
|
||||
<FrameLayout
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/action_bar_height">
|
||||
|
||||
|
@ -37,13 +52,27 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="@string/start_location_sharing"
|
||||
android:textColor="?attr/ctrl_active_color"
|
||||
android:textSize="@dimen/title_text_size"
|
||||
app:typeface="@string/font_roboto_mono_bold"/>
|
||||
|
||||
</FrameLayout>
|
||||
<ImageView
|
||||
android:id="@+id/options"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:paddingLeft="@dimen/content_padding_half"
|
||||
android:paddingRight="@dimen/content_padding_half"
|
||||
android:visibility="gone"
|
||||
tools:src="@drawable/ic_action_other_menu"
|
||||
tools:tint="@color/icon_light"
|
||||
tools:visiblity="visible" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/description"
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:background="?attr/card_bg_color"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
|
|
@ -25,7 +25,9 @@
|
|||
<item name="primary_btn_bg">@drawable/primary_btn_bg_light</item>
|
||||
<item name="primary_btn_text_color">@color/primary_btn_text_light</item>
|
||||
<item name="secondary_btn_bg">@drawable/secondary_btn_bg_light</item>
|
||||
|
||||
<item name="android:windowTranslucentStatus">true</item>
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="bottom_nav_shadow">@drawable/bg_bottom_bar_shadow_with_line_day</item>
|
||||
</style>
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ object TelegramUiHelper {
|
|||
app: TelegramApplication,
|
||||
iv: ImageView?,
|
||||
photoPath: String?,
|
||||
placeholderId: Int = R.drawable.ic_group
|
||||
placeholderId: Int = R.drawable.img_user_picture
|
||||
) {
|
||||
if (iv == null) {
|
||||
return
|
||||
|
@ -26,7 +26,7 @@ object TelegramUiHelper {
|
|||
bitmap = app.uiUtils.getCircleBitmap(photoPath)
|
||||
}
|
||||
if (bitmap == null) {
|
||||
drawable = app.uiUtils.getThemedIcon(placeholderId)
|
||||
drawable = app.uiUtils.getIcon(placeholderId)
|
||||
}
|
||||
if (bitmap != null) {
|
||||
iv.setImageBitmap(bitmap)
|
||||
|
@ -43,7 +43,7 @@ object TelegramUiHelper {
|
|||
val res = ChatItem().apply {
|
||||
chatTitle = chat.title
|
||||
photoPath = chat.photo?.small?.local?.path
|
||||
placeholderId = R.drawable.ic_group
|
||||
placeholderId = R.drawable.img_user_picture
|
||||
}
|
||||
val type = chat.type
|
||||
if (type is TdApi.ChatTypePrivate || type is TdApi.ChatTypeSecret) {
|
||||
|
@ -98,7 +98,7 @@ object TelegramUiHelper {
|
|||
chatTitle = chat.title
|
||||
name = content.name
|
||||
latLon = LatLon(content.lat, content.lon)
|
||||
placeholderId = R.drawable.ic_group
|
||||
placeholderId = R.drawable.img_user_picture
|
||||
}
|
||||
} else {
|
||||
null
|
||||
|
@ -123,7 +123,7 @@ object TelegramUiHelper {
|
|||
}
|
||||
latLon = LatLon(content.location.latitude, content.location.longitude)
|
||||
photoPath = helper.getUserPhotoPath(user)
|
||||
placeholderId = R.drawable.ic_group
|
||||
placeholderId = R.drawable.img_user_picture
|
||||
userId = message.senderUserId
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.osmand.telegram.ui
|
||||
|
||||
import android.animation.*
|
||||
import android.graphics.Paint
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
|
@ -8,6 +9,7 @@ import android.support.design.widget.AppBarLayout
|
|||
import android.support.v4.app.Fragment
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.support.v7.widget.ListPopupWindow
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.*
|
||||
import android.widget.*
|
||||
|
@ -17,6 +19,7 @@ import net.osmand.telegram.helpers.TelegramHelper
|
|||
import net.osmand.telegram.helpers.TelegramHelper.TelegramListener
|
||||
import net.osmand.telegram.helpers.TelegramUiHelper
|
||||
import net.osmand.telegram.ui.MyLocationTabFragment.MyLocationListAdapter.ChatViewHolder
|
||||
import net.osmand.telegram.utils.AndroidUtils
|
||||
import org.drinkless.td.libcore.telegram.TdApi
|
||||
|
||||
private const val SELECTED_CHATS_KEY = "selected_chats"
|
||||
|
@ -34,6 +37,8 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
private val telegramHelper get() = app.telegramHelper
|
||||
|
||||
private lateinit var appBarLayout: AppBarLayout
|
||||
private lateinit var userImage: ImageView
|
||||
private lateinit var optionsBtn: ImageView
|
||||
private lateinit var textContainer: LinearLayout
|
||||
private lateinit var title: TextView
|
||||
private lateinit var description: TextView
|
||||
|
@ -85,10 +90,22 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
appBarCollapsed = collapsed
|
||||
adjustText()
|
||||
adjustSearchBox()
|
||||
optionsBtn.visibility = if (collapsed) View.VISIBLE else View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
userImage = mainView.findViewById<ImageView>(R.id.my_location_user_image).apply {
|
||||
setImageResource(R.drawable.img_my_location_user)
|
||||
}
|
||||
|
||||
optionsBtn = mainView.findViewById<ImageView>(R.id.options).apply {
|
||||
setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu))
|
||||
setOnClickListener {
|
||||
showPopupMenu()
|
||||
}
|
||||
}
|
||||
|
||||
textContainer = mainView.findViewById<LinearLayout>(R.id.text_container).apply {
|
||||
if (Build.VERSION.SDK_INT >= 16) {
|
||||
layoutTransition.enableTransitionType(LayoutTransition.CHANGING)
|
||||
|
@ -125,6 +142,60 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
return mainView
|
||||
}
|
||||
|
||||
|
||||
private fun showPopupMenu() {
|
||||
val menuList = ArrayList<String>()
|
||||
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)
|
||||
}
|
||||
val paint = Paint()
|
||||
paint.textSize = resources.getDimensionPixelSize(R.dimen.list_item_title_text_size).toFloat()
|
||||
val textWidth = paint.measureText(menuList[0])
|
||||
val itemWidth = textWidth.toInt() + AndroidUtils.dpToPx(context!!, 32F)
|
||||
val minWidth = AndroidUtils.dpToPx(context!!, 100F)
|
||||
|
||||
ListPopupWindow(context!!).apply {
|
||||
isModal = true
|
||||
anchorView = optionsBtn
|
||||
setContentWidth(Math.max(minWidth, itemWidth))
|
||||
setDropDownGravity(Gravity.END or Gravity.TOP)
|
||||
setAdapter(ArrayAdapter(context, R.layout.popup_list_text_item, menuList))
|
||||
setOnItemClickListener { _, _, position, _ ->
|
||||
when (position) {
|
||||
menuList.indexOf(logout) -> {
|
||||
logoutTelegram()
|
||||
}
|
||||
menuList.indexOf(login) -> {
|
||||
loginTelegram()
|
||||
}
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
show()
|
||||
}
|
||||
}
|
||||
|
||||
fun logoutTelegram(silent: Boolean = false) {
|
||||
if (telegramHelper.getTelegramAuthorizationState() == TelegramHelper.TelegramAuthorizationState.READY) {
|
||||
telegramHelper.logout()
|
||||
} else {
|
||||
if (!silent) {
|
||||
Toast.makeText(context, R.string.not_logged_in, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun loginTelegram() {
|
||||
if (telegramHelper.getTelegramAuthorizationState() != TelegramHelper.TelegramAuthorizationState.CLOSED) {
|
||||
telegramHelper.logout()
|
||||
}
|
||||
telegramHelper.init()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
updateList()
|
||||
|
|
|
@ -59,6 +59,15 @@ object AndroidUtils {
|
|||
).toInt()
|
||||
}
|
||||
|
||||
fun getStatusBarHeight(ctx: Context): Int {
|
||||
var result = 0
|
||||
val resourceId = ctx.resources.getIdentifier("status_bar_height", "dimen", "android")
|
||||
if (resourceId > 0) {
|
||||
result = ctx.resources.getDimensionPixelSize(resourceId)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
fun getAttrColor(ctx: Context, @AttrRes attrId: Int, @ColorInt defaultColor: Int = 0): Int {
|
||||
val ta = ctx.theme.obtainStyledAttributes(intArrayOf(attrId))
|
||||
|
|
Loading…
Reference in a new issue