add appbar to LiveNowTabFragment
This commit is contained in:
parent
ee0d79d59a
commit
cf8bdf06c0
5 changed files with 138 additions and 55 deletions
|
@ -2,10 +2,78 @@
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
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/search_icon"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginEnd="@dimen/content_padding_half"
|
||||||
|
android:layout_marginRight="@dimen/content_padding_half"
|
||||||
|
android:paddingLeft="@dimen/content_padding_half"
|
||||||
|
android:paddingRight="@dimen/content_padding_half"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:src="@drawable/ic_action_search_dark"
|
||||||
|
tools:tint="@color/icon_light"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
|
<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
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
|
@ -159,6 +159,19 @@
|
||||||
android:textSize="@dimen/title_text_size"
|
android:textSize="@dimen/title_text_size"
|
||||||
app:typeface="@string/font_roboto_mono_bold" />
|
app:typeface="@string/font_roboto_mono_bold" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/title_search_icon"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginEnd="@dimen/content_padding_half"
|
||||||
|
android:layout_marginRight="@dimen/content_padding_half"
|
||||||
|
android:paddingLeft="@dimen/content_padding_half"
|
||||||
|
android:paddingRight="@dimen/content_padding_half"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:src="@drawable/ic_action_search_dark"
|
||||||
|
tools:tint="@color/icon_light"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/options_title"
|
android:id="@+id/options_title"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package net.osmand.telegram.ui
|
package net.osmand.telegram.ui
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.support.design.widget.AppBarLayout
|
||||||
import android.support.v4.app.Fragment
|
import android.support.v4.app.Fragment
|
||||||
import android.support.v7.widget.LinearLayoutManager
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
import android.support.v7.widget.ListPopupWindow
|
import android.support.v7.widget.ListPopupWindow
|
||||||
|
@ -47,6 +48,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
private lateinit var adapter: LiveNowListAdapter
|
private lateinit var adapter: LiveNowListAdapter
|
||||||
private lateinit var locationViewCache: UpdateLocationViewCache
|
private lateinit var locationViewCache: UpdateLocationViewCache
|
||||||
|
|
||||||
|
private lateinit var appBarLayout: AppBarLayout
|
||||||
private lateinit var openOsmAndBtn: View
|
private lateinit var openOsmAndBtn: View
|
||||||
|
|
||||||
private var location: Location? = null
|
private var location: Location? = null
|
||||||
|
@ -59,7 +61,8 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
): View? {
|
||||||
val mainView = inflater.inflate(R.layout.fragment_live_now_tab, container, false)
|
val mainView = inflater.inflate(R.layout.fragment_live_now_tab, container, false)
|
||||||
AndroidUtils.addStatusBarPadding19v(context!!, mainView)
|
appBarLayout = mainView.findViewById<AppBarLayout>(R.id.app_bar_layout)
|
||||||
|
AndroidUtils.addStatusBarPadding19v(context!!, appBarLayout)
|
||||||
adapter = LiveNowListAdapter()
|
adapter = LiveNowListAdapter()
|
||||||
mainView.findViewById<RecyclerView>(R.id.recycler_view).apply {
|
mainView.findViewById<RecyclerView>(R.id.recycler_view).apply {
|
||||||
layoutManager = LinearLayoutManager(context)
|
layoutManager = LinearLayoutManager(context)
|
||||||
|
@ -75,6 +78,12 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mainView.findViewById<ImageView>(R.id.options).apply {
|
||||||
|
setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu))
|
||||||
|
setOnClickListener { (activity as MainActivity).showOptionsPopupMenu(this) }
|
||||||
|
}
|
||||||
|
|
||||||
openOsmAndBtn = mainView.findViewById<View>(R.id.open_osmand_btn).apply {
|
openOsmAndBtn = mainView.findViewById<View>(R.id.open_osmand_btn).apply {
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
activity?.packageManager?.getLaunchIntentForPackage(OsmandAidlHelper.OSMAND_PACKAGE_NAME)
|
activity?.packageManager?.getLaunchIntentForPackage(OsmandAidlHelper.OSMAND_PACKAGE_NAME)
|
||||||
|
|
|
@ -10,7 +10,10 @@ import android.support.v4.app.FragmentManager
|
||||||
import android.support.v4.app.FragmentPagerAdapter
|
import android.support.v4.app.FragmentPagerAdapter
|
||||||
import android.support.v7.app.AlertDialog
|
import android.support.v7.app.AlertDialog
|
||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
|
import android.support.v7.widget.ListPopupWindow
|
||||||
|
import android.view.Gravity
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.ArrayAdapter
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
@ -255,11 +258,52 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
||||||
}
|
}
|
||||||
telegramHelper.init()
|
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() {
|
fun closeTelegram() {
|
||||||
telegramHelper.close()
|
telegramHelper.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)) {
|
private fun runOnUi(action: (() -> Unit)) {
|
||||||
if (!paused) {
|
if (!paused) {
|
||||||
runOnUiThread(action)
|
runOnUiThread(action)
|
||||||
|
|
|
@ -10,7 +10,6 @@ import android.support.design.widget.AppBarLayout
|
||||||
import android.support.v4.app.Fragment
|
import android.support.v4.app.Fragment
|
||||||
import android.support.v4.content.ContextCompat
|
import android.support.v4.content.ContextCompat
|
||||||
import android.support.v7.widget.LinearLayoutManager
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
import android.support.v7.widget.ListPopupWindow
|
|
||||||
import android.support.v7.widget.RecyclerView
|
import android.support.v7.widget.RecyclerView
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
|
@ -114,12 +113,12 @@ class MyLocationTabFragment : Fragment(), TelegramListener, ChatLiveMessagesList
|
||||||
|
|
||||||
optionsBtn = mainView.findViewById<ImageView>(R.id.options).apply {
|
optionsBtn = mainView.findViewById<ImageView>(R.id.options).apply {
|
||||||
setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu))
|
setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu))
|
||||||
setOnClickListener { showPopupMenu(this) }
|
setOnClickListener { (activity as MainActivity).showOptionsPopupMenu(this) }
|
||||||
}
|
}
|
||||||
|
|
||||||
mainView.findViewById<ImageView>(R.id.options_title).apply {
|
mainView.findViewById<ImageView>(R.id.options_title).apply {
|
||||||
setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu))
|
setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu))
|
||||||
setOnClickListener { showPopupMenu(this) }
|
setOnClickListener { (activity as MainActivity).showOptionsPopupMenu(this) }
|
||||||
}
|
}
|
||||||
|
|
||||||
imageContainer = mainView.findViewById<FrameLayout>(R.id.image_container)
|
imageContainer = mainView.findViewById<FrameLayout>(R.id.image_container)
|
||||||
|
@ -257,56 +256,6 @@ class MyLocationTabFragment : Fragment(), TelegramListener, ChatLiveMessagesList
|
||||||
actionButtonsListener?.switchButtonsVisibility(false)
|
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() {
|
private fun adjustText() {
|
||||||
val gravity = if (appBarCollapsed) Gravity.START else Gravity.CENTER
|
val gravity = if (appBarCollapsed) Gravity.START else Gravity.CENTER
|
||||||
val padding = if (appBarCollapsed) textMarginSmall else textMarginBig
|
val padding = if (appBarCollapsed) textMarginSmall else textMarginBig
|
||||||
|
|
Loading…
Reference in a new issue