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..1abb5c9c26 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,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(R.id.my_location_user_image).apply { + setImageResource(R.drawable.img_my_location_user) + } + + optionsBtn = mainView.findViewById(R.id.options).apply { + setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu)) + setOnClickListener { + showPopupMenu() + } + } + textContainer = mainView.findViewById(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() + 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() 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))