Add action buttons bar to the main screen
This commit is contained in:
parent
f183a39797
commit
b724cf67de
4 changed files with 102 additions and 10 deletions
|
@ -27,6 +27,35 @@
|
|||
|
||||
</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:id="@+id/bottom_navigation"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
|
||||
<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>
|
||||
|
||||
<!-- Text sizes -->
|
||||
|
|
|
@ -17,6 +17,8 @@ import android.support.v7.widget.AppCompatTextView
|
|||
import android.support.v7.widget.RecyclerView
|
||||
import android.support.v7.widget.SwitchCompat
|
||||
import android.view.*
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import net.osmand.PlatformUtil
|
||||
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.ui.LoginDialogFragment.LoginDialogType
|
||||
import net.osmand.telegram.ui.MyLocationTabFragment.ActionButtonsListener
|
||||
import net.osmand.telegram.ui.views.LockableViewPager
|
||||
import net.osmand.telegram.utils.AndroidUtils
|
||||
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 LIVE_NOW_TAB_POS = 1
|
||||
|
||||
class MainActivity : AppCompatActivity(), TelegramListener {
|
||||
class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListener {
|
||||
|
||||
private val log = PlatformUtil.getLog(TelegramHelper::class.java)
|
||||
|
||||
|
@ -54,6 +57,11 @@ class MainActivity : AppCompatActivity(), TelegramListener {
|
|||
|
||||
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?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
@ -66,7 +74,8 @@ class MainActivity : AppCompatActivity(), TelegramListener {
|
|||
adapter = ViewPagerAdapter(supportFragmentManager)
|
||||
}
|
||||
|
||||
findViewById<BottomNavigationView>(R.id.bottom_navigation).setOnNavigationItemSelectedListener {
|
||||
bottomNav = findViewById<BottomNavigationView>(R.id.bottom_navigation).apply {
|
||||
setOnNavigationItemSelectedListener {
|
||||
var pos = -1
|
||||
when (it.itemId) {
|
||||
R.id.action_my_location -> pos = MY_LOCATION_TAB_POS
|
||||
|
@ -78,6 +87,22 @@ class MainActivity : AppCompatActivity(), TelegramListener {
|
|||
}
|
||||
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) {
|
||||
LoginDialogFragment.showWelcomeDialog(supportFragmentManager)
|
||||
|
@ -110,6 +135,9 @@ class MainActivity : AppCompatActivity(), TelegramListener {
|
|||
if (fragment is TelegramListener) {
|
||||
listeners.add(WeakReference(fragment))
|
||||
}
|
||||
if (fragment is MyLocationTabFragment) {
|
||||
myLocationTabFragment = fragment
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
val presentChatTitles = telegramHelper.getChatTitles()
|
||||
settings.removeNonexistingChats(presentChatTitles)
|
||||
|
|
|
@ -49,11 +49,18 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
|
||||
private val selectedChats = HashSet<Long>()
|
||||
|
||||
private var actionButtonsListener: ActionButtonsListener? = null
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
val activity = activity
|
||||
if (activity is ActionButtonsListener) {
|
||||
actionButtonsListener = activity
|
||||
}
|
||||
|
||||
textMarginSmall = resources.getDimensionPixelSize(R.dimen.content_padding_standard)
|
||||
textMarginBig = resources.getDimensionPixelSize(R.dimen.my_location_text_sides_margin)
|
||||
searchBoxHeight = resources.getDimensionPixelSize(R.dimen.search_box_height)
|
||||
|
@ -61,6 +68,9 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
|
||||
savedInstanceState?.apply {
|
||||
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)
|
||||
|
@ -164,6 +174,16 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
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() {
|
||||
val gravity = if (appBarCollapsed) Gravity.START else Gravity.CENTER
|
||||
val padding = if (appBarCollapsed) textMarginSmall else textMarginBig
|
||||
|
@ -270,6 +290,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
|
|||
} else {
|
||||
selectedChats.remove(chat.id)
|
||||
}
|
||||
actionButtonsListener?.switchButtonsVisibility(selectedChats.isNotEmpty())
|
||||
}
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
interface ActionButtonsListener {
|
||||
fun switchButtonsVisibility(visible: Boolean)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue