From 7e6a377dca4ff36dcc47152620adbb5e39b37311 Mon Sep 17 00:00:00 2001 From: Chumva Date: Thu, 12 Jul 2018 16:38:20 +0300 Subject: [PATCH] improve my location ui --- .../res/layout/fragment_my_location_tab.xml | 41 ++++++-- .../res/layout/fragment_set_time_dialog.xml | 1 + OsmAnd-telegram/res/values/styles.xml | 4 +- .../telegram/helpers/TelegramUiHelper.kt | 10 +- .../telegram/ui/MyLocationTabFragment.kt | 96 +++++++++++++++++++ .../net/osmand/telegram/utils/AndroidUtils.kt | 9 ++ 6 files changed, 149 insertions(+), 12 deletions(-) diff --git a/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml b/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml index 452bb8174a..b4a432f12b 100644 --- a/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml +++ b/OsmAnd-telegram/res/layout/fragment_my_location_tab.xml @@ -12,12 +12,27 @@ android:layout_height="wrap_content" android:background="?attr/card_bg_color"> - + app:layout_scrollFlags="scroll"> + + + + + + - @@ -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"/> - + + + diff --git a/OsmAnd-telegram/res/values/styles.xml b/OsmAnd-telegram/res/values/styles.xml index 3b5918d5cc..dd8b658005 100644 --- a/OsmAnd-telegram/res/values/styles.xml +++ b/OsmAnd-telegram/res/values/styles.xml @@ -25,7 +25,9 @@ @drawable/primary_btn_bg_light @color/primary_btn_text_light @drawable/secondary_btn_bg_light - + true + false + true @drawable/bg_bottom_bar_shadow_with_line_day diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt index 0d3b2ba73b..3fc146af37 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt @@ -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 } } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt index 714e7ec779..7af327c5d4 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt @@ -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(R.id.my_location_bg_image).apply { + setImageResource(R.drawable.img_my_location_roadbg) + } + + userImage = mainView.findViewById(R.id.my_location_user_image).apply { + setImageResource(R.drawable.img_my_location_user) + } + + optionsImage = mainView.findViewById(R.id.options).apply { + setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu)) + setOnClickListener { + showPopupMenu(this@MyLocationTabFragment) + } + } + textContainer = mainView.findViewById(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() + 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 diff --git a/OsmAnd-telegram/src/net/osmand/telegram/utils/AndroidUtils.kt b/OsmAnd-telegram/src/net/osmand/telegram/utils/AndroidUtils.kt index 71f96fdd02..477e4efe00 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/utils/AndroidUtils.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/utils/AndroidUtils.kt @@ -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))