diff --git a/OsmAnd-telegram/res/layout/activity_main.xml b/OsmAnd-telegram/res/layout/activity_main.xml index b99649a1b4..5118492b0c 100644 --- a/OsmAnd-telegram/res/layout/activity_main.xml +++ b/OsmAnd-telegram/res/layout/activity_main.xml @@ -27,6 +27,35 @@ + + + + + + + + + + 48dp + 56dp + 0.01 diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt index a9a0143c4e..f6cd589c61 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt @@ -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> = 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,17 +74,34 @@ class MainActivity : AppCompatActivity(), TelegramListener { adapter = ViewPagerAdapter(supportFragmentManager) } - findViewById(R.id.bottom_navigation).setOnNavigationItemSelectedListener { - var pos = -1 - when (it.itemId) { - R.id.action_my_location -> pos = MY_LOCATION_TAB_POS - R.id.action_live_now -> pos = LIVE_NOW_TAB_POS + bottomNav = findViewById(R.id.bottom_navigation).apply { + setOnNavigationItemSelectedListener { + var pos = -1 + when (it.itemId) { + R.id.action_my_location -> pos = MY_LOCATION_TAB_POS + R.id.action_live_now -> pos = LIVE_NOW_TAB_POS + } + if (pos != -1 && pos != viewPager.currentItem) { + viewPager.currentItem = pos + return@setOnNavigationItemSelectedListener true + } + false } - if (pos != -1 && pos != viewPager.currentItem) { - viewPager.currentItem = pos - return@setOnNavigationItemSelectedListener true + } + + buttonsBar = findViewById(R.id.buttons_bar).apply { + findViewById(R.id.primary_btn).apply { + text = getString(R.string.shared_string_continue) + setOnClickListener { + myLocationTabFragment?.onPrimaryBtnClick() + } + } + findViewById(R.id.secondary_btn).apply { + text = getString(R.string.shared_string_cancel) + setOnClickListener { + myLocationTabFragment?.onSecondaryBtnClick() + } } - false } if (!LoginDialogFragment.welcomeDialogShown) { @@ -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) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt index 3dcaa1f52e..af42721c76 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt @@ -49,11 +49,18 @@ class MyLocationTabFragment : Fragment(), TelegramListener { private val selectedChats = HashSet() + 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) + } }