improve my location ui

This commit is contained in:
Chumva 2018-07-12 16:38:20 +03:00
parent 78d78036d5
commit 7e6a377dca
6 changed files with 149 additions and 12 deletions

View file

@ -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"

View file

@ -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">

View file

@ -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>

View file

@ -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
}
}

View file

@ -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,9 @@ 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 textContainer: LinearLayout
private lateinit var title: TextView
private lateinit var description: TextView
@ -85,10 +91,26 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
appBarCollapsed = collapsed
adjustText()
adjustSearchBox()
adjustOptionsImage()
}
}
}
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 {
setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu))
setOnClickListener {
showPopupMenu(this@MyLocationTabFragment)
}
}
textContainer = mainView.findViewById<LinearLayout>(R.id.text_container).apply {
if (Build.VERSION.SDK_INT >= 16) {
layoutTransition.enableTransitionType(LayoutTransition.CHANGING)
@ -125,6 +147,72 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
return mainView
}
private fun showPopupMenu(holder: MyLocationTabFragment) {
val ctx = holder.context
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))
}
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)
ListPopupWindow(ctx).apply {
isModal = true
anchorView = holder.optionsImage
setContentWidth(Math.max(minWidth, itemWidth))
setDropDownGravity(Gravity.END or Gravity.TOP)
setAdapter(ArrayAdapter(ctx, 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()
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()
}
}
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()
@ -185,6 +273,14 @@ 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

View file

@ -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))