aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMarvin Borner2018-07-24 20:28:02 +0200
committerMarvin Borner2018-07-24 20:28:02 +0200
commit43fb95de3fb3e825a6cbf0de68bd965556b73a75 (patch)
tree25f57c44ffa61e487886d7588755c3d17895c0ec
parenteda695878d61ef761546295682afe4a450697d3d (diff)
Added tab layout
-rw-r--r--app/src/main/java/com/beam_messenger/beam_messenger/MainActivity.kt109
1 files changed, 107 insertions, 2 deletions
diff --git a/app/src/main/java/com/beam_messenger/beam_messenger/MainActivity.kt b/app/src/main/java/com/beam_messenger/beam_messenger/MainActivity.kt
index d708a98..1686589 100644
--- a/app/src/main/java/com/beam_messenger/beam_messenger/MainActivity.kt
+++ b/app/src/main/java/com/beam_messenger/beam_messenger/MainActivity.kt
@@ -1,22 +1,127 @@
package com.beam_messenger.beam_messenger
+import android.app.ActivityOptions
+import android.content.Intent
import android.os.Bundle
import android.support.design.widget.Snackbar
+import android.support.design.widget.TabLayout
+import android.support.v4.app.Fragment
+import android.support.v4.app.FragmentManager
+import android.support.v4.app.FragmentPagerAdapter
import android.support.v7.app.AppCompatActivity
-
+import android.transition.Fade
+import android.view.*
import kotlinx.android.synthetic.main.activity_main.*
+import kotlinx.android.synthetic.main.fragment_main.view.*
class MainActivity : AppCompatActivity() {
+ /**
+ * The [android.support.v4.view.PagerAdapter] that will provide
+ * fragments for each of the sections. We use a
+ * {@link FragmentPagerAdapter} derivative, which will keep every
+ * loaded fragment in memory. If this becomes too memory intensive, it
+ * may be best to switch to a
+ * [android.support.v4.app.FragmentStatePagerAdapter].
+ */
+ private var mSectionsPagerAdapter: SectionsPagerAdapter? = null
+
override fun onCreate(savedInstanceState: Bundle?) {
+ with(window) {
+ requestFeature(Window.FEATURE_CONTENT_TRANSITIONS)
+ exitTransition = Fade()
+ }
+
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
+
setSupportActionBar(toolbar)
+ // Create the adapter that will return a fragment for each of the three
+ // primary sections of the activity.
+ mSectionsPagerAdapter = SectionsPagerAdapter(supportFragmentManager)
+
+ // Set up the ViewPager with the sections adapter.
+ container.adapter = mSectionsPagerAdapter
+
+ container.addOnPageChangeListener(TabLayout.TabLayoutOnPageChangeListener(tabs))
+ tabs.addOnTabSelectedListener(TabLayout.ViewPagerOnTabSelectedListener(container))
fab.setOnClickListener { view ->
- Snackbar.make(view, "Sorry, this feature is currently unavailable.", Snackbar.LENGTH_LONG)
+ Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show()
}
}
+
+ override fun onCreateOptionsMenu(menu: Menu): Boolean {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ menuInflater.inflate(R.menu.menu_main, menu)
+ return true
+ }
+
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
+ // Handle action bar item clicks here. The action bar will
+ // automatically handle clicks on the Home/Up button, so long
+ // as you specify a parent activity in AndroidManifest.xml.
+ val id = item.itemId
+
+ if (id == R.id.action_settings) {
+ val intent = Intent(this@MainActivity, LoginActivity::class.java)
+ startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle())
+ }
+
+ return super.onOptionsItemSelected(item)
+ }
+
+
+ /**
+ * A [FragmentPagerAdapter] that returns a fragment corresponding to
+ * one of the sections/tabs/pages.
+ */
+ inner class SectionsPagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) {
+
+ override fun getItem(position: Int): Fragment {
+ // getItem is called to instantiate the fragment for the given page.
+ // Return a PlaceholderFragment (defined as a static inner class below).
+ return PlaceholderFragment.newInstance(position + 1)
+ }
+
+ override fun getCount(): Int {
+ // Show 3 total pages.
+ return 3
+ }
+ }
+
+ /**
+ * A placeholder fragment containing a simple view.
+ */
+ class PlaceholderFragment : Fragment() {
+
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?): View? {
+ val rootView = inflater.inflate(R.layout.fragment_main, container, false)
+ rootView.section_label.text = getString(R.string.section_format, arguments?.getInt(ARG_SECTION_NUMBER))
+ return rootView
+ }
+
+ companion object {
+ /**
+ * The fragment argument representing the section number for this
+ * fragment.
+ */
+ private val ARG_SECTION_NUMBER = "section_number"
+
+ /**
+ * Returns a new instance of this fragment for the given section
+ * number.
+ */
+ fun newInstance(sectionNumber: Int): PlaceholderFragment {
+ val fragment = PlaceholderFragment()
+ val args = Bundle()
+ args.putInt(ARG_SECTION_NUMBER, sectionNumber)
+ fragment.arguments = args
+ return fragment
+ }
+ }
+ }
}