Create "My Location" and "Live now" tabs

This commit is contained in:
Alex Sytnyk 2018-06-20 18:01:15 +03:00
parent 0619c13f24
commit 7827509e7a
6 changed files with 103 additions and 10 deletions

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<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"
@ -19,7 +20,7 @@
android:scrollbars="vertical"/>
<net.osmand.telegram.ui.views.LockableViewPager
android:id="@+id/pager"
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
@ -39,9 +40,6 @@
android:layout_height="wrap_content"
android:visibility="visible"
app:itemBackground="?attr/bg_color"
app:menu="@menu/bottom_navigation_menu"
tools:itemIconTint="@color/ctrl_active_color_light"
tools:itemTextColor="@color/ctrl_active_color_light"
tools:visibility="visible" />
app:menu="@menu/bottom_navigation_menu"/>
</LinearLayout>

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Live Now"/>
</LinearLayout>

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="My Location"/>
</LinearLayout>

View file

@ -0,0 +1,16 @@
package net.osmand.telegram.ui
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import net.osmand.telegram.R
class LiveNowTabFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val mainView = inflater.inflate(R.layout.fragment_live_now_tab, container, false)
return mainView
}
}

View file

@ -8,8 +8,11 @@ import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Bundle
import android.support.design.widget.BottomNavigationView
import android.support.v4.app.ActivityCompat
import android.support.v4.app.DialogFragment
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.*
@ -21,6 +24,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.views.LockableViewPager
import net.osmand.telegram.utils.AndroidUtils
import org.drinkless.td.libcore.telegram.TdApi
@ -33,6 +37,9 @@ class MainActivity : AppCompatActivity(), TelegramListener {
private const val LOGIN_MENU_ID = 0
private const val LOGOUT_MENU_ID = 1
private const val PROGRESS_MENU_ID = 2
private const val MY_LOCATION_TAB_POS = 0
private const val LIVE_NOW_TAB_POS = 1
}
private val log = PlatformUtil.getLog(TelegramHelper::class.java)
@ -70,6 +77,25 @@ class MainActivity : AppCompatActivity(), TelegramListener {
adapter = chatViewAdapter
}
val viewPager = findViewById<LockableViewPager>(R.id.view_pager).apply {
swipeLocked = true
offscreenPageLimit = 2
adapter = ViewPagerAdapter(supportFragmentManager)
}
findViewById<BottomNavigationView>(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
}
if (pos != -1 && pos != viewPager.currentItem) {
viewPager.currentItem = pos
return@setOnNavigationItemSelectedListener true
}
false
}
if (!LoginDialogFragment.welcomeDialogShown) {
LoginDialogFragment.showWelcomeDialog(supportFragmentManager)
}
@ -373,6 +399,15 @@ class MainActivity : AppCompatActivity(), TelegramListener {
}
}
class ViewPagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) {
private val fragments = listOf(MyLocationTabFragment(), LiveNowTabFragment())
override fun getItem(position: Int) = fragments[position]
override fun getCount() = fragments.size
}
inner class ChatsAdapter :
RecyclerView.Adapter<ChatsAdapter.ViewHolder>() {

View file

@ -0,0 +1,16 @@
package net.osmand.telegram.ui
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import net.osmand.telegram.R
class MyLocationTabFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val mainView = inflater.inflate(R.layout.fragment_my_location_tab, container, false)
return mainView
}
}