Merge pull request #5819 from osmandapp/LiveNowUiImprovements

Add appbar to LiveNowTabFragment
This commit is contained in:
Alexander Sytnyk 2018-08-10 13:20:36 +03:00 committed by GitHub
commit 130ad85f3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 115 additions and 65 deletions

View file

@ -2,10 +2,65 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/card_bg_color">
<LinearLayout
android:id="@+id/title_row"
android:layout_width="match_parent"
android:layout_height="@dimen/action_bar_height"
android:gravity="center_vertical">
<net.osmand.telegram.ui.views.TextViewEx
android:layout_width="0dp"
android:layout_height="@dimen/action_bar_height"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="center_vertical"
android:letterSpacing="@dimen/title_letter_spacing"
android:maxLines="1"
android:paddingLeft="@dimen/content_padding_standard"
android:paddingRight="@dimen/content_padding_standard"
android:text="@string/live_now"
android:textColor="@color/app_bar_title_light"
android:textSize="@dimen/title_text_size"
app:typeface="@string/font_roboto_mono_bold" />
<ImageView
android:id="@+id/options"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/content_padding_standard"
android:layout_marginRight="@dimen/content_padding_standard"
android:background="?attr/selectableItemBackgroundBorderless"
android:paddingLeft="@dimen/content_padding_half"
android:paddingRight="@dimen/content_padding_half"
tools:src="@drawable/ic_action_other_menu"
tools:tint="@color/icon_light"
tools:visibility="visible" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/action_bar_descr_bottom_margin"
android:paddingLeft="@dimen/content_padding_standard"
android:paddingRight="@dimen/content_padding_standard"
android:text="@string/set_time_description"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/descr_text_size" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

View file

@ -58,7 +58,8 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
savedInstanceState: Bundle?
): View? {
val mainView = inflater.inflate(R.layout.fragment_live_now_tab, container, false)
AndroidUtils.addStatusBarPadding19v(context!!, mainView)
val appBarLayout = mainView.findViewById<View>(R.id.app_bar_layout)
AndroidUtils.addStatusBarPadding19v(context!!, appBarLayout)
adapter = LiveNowListAdapter()
mainView.findViewById<RecyclerView>(R.id.recycler_view).apply {
layoutManager = LinearLayoutManager(context)
@ -74,6 +75,9 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
}
})
}
(activity as MainActivity).setupOptionsBtn(mainView.findViewById<ImageView>(R.id.options))
openOsmAndBtn = mainView.findViewById<View>(R.id.open_osmand_btn).apply {
setOnClickListener {
activity?.packageManager?.getLaunchIntentForPackage(OsmandAidlHelper.OSMAND_PACKAGE_NAME)

View file

@ -10,10 +10,10 @@ import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter
import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.ListPopupWindow
import android.view.Gravity
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import android.widget.*
import net.osmand.PlatformUtil
import net.osmand.telegram.R
import net.osmand.telegram.TelegramApplication
@ -255,11 +255,57 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
}
telegramHelper.init()
}
private fun logoutTelegram(silent: Boolean = false) {
if (telegramHelper.getTelegramAuthorizationState() == TelegramHelper.TelegramAuthorizationState.READY) {
telegramHelper.logout()
} else if (!silent) {
Toast.makeText(this, R.string.not_logged_in, Toast.LENGTH_SHORT).show()
}
}
fun closeTelegram() {
telegramHelper.close()
}
fun setupOptionsBtn(imageView: ImageView) {
imageView.setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu))
imageView.setOnClickListener { showOptionsPopupMenu(imageView) }
}
fun showOptionsPopupMenu(anchor: View) {
val menuList = ArrayList<String>()
val settings = getString(R.string.shared_string_settings)
val logout = getString(R.string.shared_string_logout)
val login = getString(R.string.shared_string_login)
menuList.add(settings)
@Suppress("NON_EXHAUSTIVE_WHEN")
when (telegramHelper.getTelegramAuthorizationState()) {
TelegramHelper.TelegramAuthorizationState.READY -> menuList.add(logout)
TelegramHelper.TelegramAuthorizationState.CLOSED -> menuList.add(login)
}
ListPopupWindow(this@MainActivity).apply {
isModal = true
anchorView = anchor
setContentWidth(AndroidUtils.getPopupMenuWidth(this@MainActivity, menuList))
setDropDownGravity(Gravity.END or Gravity.TOP)
setAdapter(ArrayAdapter(this@MainActivity, R.layout.popup_list_text_item, menuList))
setOnItemClickListener { _, _, position, _ ->
when (position) {
menuList.indexOf(settings) -> {
supportFragmentManager?.also { SettingsDialogFragment.showInstance(it) }
}
menuList.indexOf(logout) -> logoutTelegram()
menuList.indexOf(login) -> loginTelegram()
}
dismiss()
}
show()
}
}
private fun runOnUi(action: (() -> Unit)) {
if (!paused) {
runOnUiThread(action)

View file

@ -10,7 +10,6 @@ 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.*
@ -114,16 +113,12 @@ class MyLocationTabFragment : Fragment(), TelegramListener, ChatLiveMessagesList
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(this) }
optionsBtn = mainView.findViewById<ImageView>(R.id.options)
with(activity as MainActivity) {
setupOptionsBtn(optionsBtn)
setupOptionsBtn(mainView.findViewById<ImageView>(R.id.options_title))
}
mainView.findViewById<ImageView>(R.id.options_title).apply {
setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu))
setOnClickListener { showPopupMenu(this) }
}
imageContainer = mainView.findViewById<FrameLayout>(R.id.image_container)
titleContainer = mainView.findViewById<LinearLayout>(R.id.title_container).apply {
AndroidUtils.addStatusBarPadding19v(context, this)
@ -259,56 +254,6 @@ class MyLocationTabFragment : Fragment(), TelegramListener, ChatLiveMessagesList
actionButtonsListener?.switchButtonsVisibility(false)
}
private fun showPopupMenu(anchor: View) {
val ctx = context ?: return
val menuList = ArrayList<String>()
val settings = getString(R.string.shared_string_settings)
val logout = getString(R.string.shared_string_logout)
val login = getString(R.string.shared_string_login)
menuList.add(settings)
@Suppress("NON_EXHAUSTIVE_WHEN")
when (telegramHelper.getTelegramAuthorizationState()) {
TelegramHelper.TelegramAuthorizationState.READY -> menuList.add(logout)
TelegramHelper.TelegramAuthorizationState.CLOSED -> menuList.add(login)
}
ListPopupWindow(ctx).apply {
isModal = true
anchorView = anchor
setContentWidth(AndroidUtils.getPopupMenuWidth(ctx, menuList))
setDropDownGravity(Gravity.END or Gravity.TOP)
setAdapter(ArrayAdapter(ctx, R.layout.popup_list_text_item, menuList))
setOnItemClickListener { _, _, position, _ ->
when (position) {
menuList.indexOf(settings) -> {
fragmentManager?.also { SettingsDialogFragment.showInstance(it) }
}
menuList.indexOf(logout) -> logoutTelegram()
menuList.indexOf(login) -> loginTelegram()
}
dismiss()
}
show()
}
}
private 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()
}
}
private fun loginTelegram() {
if (telegramHelper.getTelegramAuthorizationState() != TelegramHelper.TelegramAuthorizationState.CLOSED) {
telegramHelper.logout()
}
telegramHelper.init()
}
private fun adjustText() {
val gravity = if (appBarCollapsed) Gravity.START else Gravity.CENTER
val padding = if (appBarCollapsed) textMarginSmall else textMarginBig