Add action buttons bar to the main screen

This commit is contained in:
Alex Sytnyk 2018-06-27 18:15:25 +03:00
parent f183a39797
commit b724cf67de
4 changed files with 102 additions and 10 deletions

View file

@ -27,6 +27,35 @@
</FrameLayout> </FrameLayout>
<LinearLayout
android:id="@+id/buttons_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/buttons_bottom_bar_height"
android:background="?attr/card_bg_color"
android:gravity="center_vertical"
android:paddingLeft="@dimen/content_padding_half"
android:paddingRight="@dimen/content_padding_half"
android:visibility="gone"
tools:visibility="visible">
<include
layout="@layout/secondary_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<View
android:layout_width="@dimen/content_padding_half"
android:layout_height="match_parent"/>
<include
layout="@layout/primary_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<android.support.design.widget.BottomNavigationView <android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation" android:id="@+id/bottom_navigation"
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -36,6 +36,8 @@
<dimen name="search_box_height">48dp</dimen> <dimen name="search_box_height">48dp</dimen>
<dimen name="buttons_bottom_bar_height">56dp</dimen>
<dimen name="text_button_letter_spacing" format="float">0.01</dimen> <dimen name="text_button_letter_spacing" format="float">0.01</dimen>
<!-- Text sizes --> <!-- Text sizes -->

View file

@ -17,6 +17,8 @@ import android.support.v7.widget.AppCompatTextView
import android.support.v7.widget.RecyclerView import android.support.v7.widget.RecyclerView
import android.support.v7.widget.SwitchCompat import android.support.v7.widget.SwitchCompat
import android.view.* import android.view.*
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import net.osmand.PlatformUtil import net.osmand.PlatformUtil
import net.osmand.telegram.R import net.osmand.telegram.R
@ -24,6 +26,7 @@ import net.osmand.telegram.TelegramApplication
import net.osmand.telegram.helpers.TelegramHelper import net.osmand.telegram.helpers.TelegramHelper
import net.osmand.telegram.helpers.TelegramHelper.* import net.osmand.telegram.helpers.TelegramHelper.*
import net.osmand.telegram.ui.LoginDialogFragment.LoginDialogType import net.osmand.telegram.ui.LoginDialogFragment.LoginDialogType
import net.osmand.telegram.ui.MyLocationTabFragment.ActionButtonsListener
import net.osmand.telegram.ui.views.LockableViewPager import net.osmand.telegram.ui.views.LockableViewPager
import net.osmand.telegram.utils.AndroidUtils import net.osmand.telegram.utils.AndroidUtils
import org.drinkless.td.libcore.telegram.TdApi import org.drinkless.td.libcore.telegram.TdApi
@ -38,7 +41,7 @@ private const val PROGRESS_MENU_ID = 2
private const val MY_LOCATION_TAB_POS = 0 private const val MY_LOCATION_TAB_POS = 0
private const val LIVE_NOW_TAB_POS = 1 private const val LIVE_NOW_TAB_POS = 1
class MainActivity : AppCompatActivity(), TelegramListener { class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListener {
private val log = PlatformUtil.getLog(TelegramHelper::class.java) private val log = PlatformUtil.getLog(TelegramHelper::class.java)
@ -54,6 +57,11 @@ class MainActivity : AppCompatActivity(), TelegramListener {
private val listeners: MutableList<WeakReference<TelegramListener>> = mutableListOf() private val listeners: MutableList<WeakReference<TelegramListener>> = mutableListOf()
private var myLocationTabFragment: MyLocationTabFragment? = null
private lateinit var buttonsBar: LinearLayout
private lateinit var bottomNav: BottomNavigationView
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
@ -66,7 +74,8 @@ class MainActivity : AppCompatActivity(), TelegramListener {
adapter = ViewPagerAdapter(supportFragmentManager) adapter = ViewPagerAdapter(supportFragmentManager)
} }
findViewById<BottomNavigationView>(R.id.bottom_navigation).setOnNavigationItemSelectedListener { bottomNav = findViewById<BottomNavigationView>(R.id.bottom_navigation).apply {
setOnNavigationItemSelectedListener {
var pos = -1 var pos = -1
when (it.itemId) { when (it.itemId) {
R.id.action_my_location -> pos = MY_LOCATION_TAB_POS R.id.action_my_location -> pos = MY_LOCATION_TAB_POS
@ -78,6 +87,22 @@ class MainActivity : AppCompatActivity(), TelegramListener {
} }
false false
} }
}
buttonsBar = findViewById<LinearLayout>(R.id.buttons_bar).apply {
findViewById<TextView>(R.id.primary_btn).apply {
text = getString(R.string.shared_string_continue)
setOnClickListener {
myLocationTabFragment?.onPrimaryBtnClick()
}
}
findViewById<TextView>(R.id.secondary_btn).apply {
text = getString(R.string.shared_string_cancel)
setOnClickListener {
myLocationTabFragment?.onSecondaryBtnClick()
}
}
}
if (!LoginDialogFragment.welcomeDialogShown) { if (!LoginDialogFragment.welcomeDialogShown) {
LoginDialogFragment.showWelcomeDialog(supportFragmentManager) LoginDialogFragment.showWelcomeDialog(supportFragmentManager)
@ -110,6 +135,9 @@ class MainActivity : AppCompatActivity(), TelegramListener {
if (fragment is TelegramListener) { if (fragment is TelegramListener) {
listeners.add(WeakReference(fragment)) listeners.add(WeakReference(fragment))
} }
if (fragment is MyLocationTabFragment) {
myLocationTabFragment = fragment
}
} }
override fun onResume() { override fun onResume() {
@ -207,6 +235,14 @@ class MainActivity : AppCompatActivity(), TelegramListener {
} }
} }
override fun switchButtonsVisibility(visible: Boolean) {
val buttonsVisibility = if (visible) View.VISIBLE else View.GONE
if (buttonsBar.visibility != buttonsVisibility) {
buttonsBar.visibility = buttonsVisibility
bottomNav.visibility = if (visible) View.GONE else View.VISIBLE
}
}
private fun removeNonexistingChatsFromSettings() { private fun removeNonexistingChatsFromSettings() {
val presentChatTitles = telegramHelper.getChatTitles() val presentChatTitles = telegramHelper.getChatTitles()
settings.removeNonexistingChats(presentChatTitles) settings.removeNonexistingChats(presentChatTitles)

View file

@ -49,11 +49,18 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
private val selectedChats = HashSet<Long>() private val selectedChats = HashSet<Long>()
private var actionButtonsListener: ActionButtonsListener? = null
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, inflater: LayoutInflater,
container: ViewGroup?, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
val activity = activity
if (activity is ActionButtonsListener) {
actionButtonsListener = activity
}
textMarginSmall = resources.getDimensionPixelSize(R.dimen.content_padding_standard) textMarginSmall = resources.getDimensionPixelSize(R.dimen.content_padding_standard)
textMarginBig = resources.getDimensionPixelSize(R.dimen.my_location_text_sides_margin) textMarginBig = resources.getDimensionPixelSize(R.dimen.my_location_text_sides_margin)
searchBoxHeight = resources.getDimensionPixelSize(R.dimen.search_box_height) searchBoxHeight = resources.getDimensionPixelSize(R.dimen.search_box_height)
@ -61,6 +68,9 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
savedInstanceState?.apply { savedInstanceState?.apply {
selectedChats.addAll(getLongArray(SELECTED_CHATS_KEY).toSet()) selectedChats.addAll(getLongArray(SELECTED_CHATS_KEY).toSet())
if (selectedChats.isNotEmpty()) {
actionButtonsListener?.switchButtonsVisibility(true)
}
} }
val mainView = inflater.inflate(R.layout.fragment_my_location_tab, container, false) val mainView = inflater.inflate(R.layout.fragment_my_location_tab, container, false)
@ -164,6 +174,16 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
override fun onSendLiveLocationError(code: Int, message: String) { override fun onSendLiveLocationError(code: Int, message: String) {
} }
fun onPrimaryBtnClick() {
Toast.makeText(context, "Continue", Toast.LENGTH_SHORT).show()
}
fun onSecondaryBtnClick() {
selectedChats.clear()
adapter.notifyDataSetChanged()
actionButtonsListener?.switchButtonsVisibility(false)
}
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
@ -270,6 +290,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
} else { } else {
selectedChats.remove(chat.id) selectedChats.remove(chat.id)
} }
actionButtonsListener?.switchButtonsVisibility(selectedChats.isNotEmpty())
} }
} }
holder.bottomShadow?.visibility = if (lastItem) View.VISIBLE else View.GONE holder.bottomShadow?.visibility = if (lastItem) View.VISIBLE else View.GONE
@ -290,4 +311,8 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
val bottomShadow: View? = view.findViewById(R.id.bottom_shadow) val bottomShadow: View? = view.findViewById(R.id.bottom_shadow)
} }
} }
interface ActionButtonsListener {
fun switchButtonsVisibility(visible: Boolean)
}
} }