diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt new file mode 100644 index 00000000..4922a292 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt @@ -0,0 +1,127 @@ +package com.pitchedapps.frost + +import android.os.Bundle +import android.support.design.widget.FloatingActionButton +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.v4.view.ViewPager +import android.support.v7.app.AppCompatActivity +import android.support.v7.widget.Toolbar +import android.view.* +import android.widget.TextView +import butterknife.ButterKnife +import com.pitchedapps.frost.fragments.WebFragment +import com.pitchedapps.frost.utils.Changelog +import com.pitchedapps.frost.utils.bindView + +class MainActivity : AppCompatActivity() { + + private var mSectionsPagerAdapter: SectionsPagerAdapter? = null + val toolbar: Toolbar by bindView(R.id.toolbar) + val viewPager: ViewPager by bindView(R.id.container) + val fab: FloatingActionButton by bindView(R.id.fab) + val tabs: TabLayout by bindView(R.id.tabs) + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + ButterKnife.bind(this) + 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. + viewPager.adapter = mSectionsPagerAdapter + viewPager.offscreenPageLimit = 5 + tabs.setupWithViewPager(viewPager) + + fab.setOnClickListener { view -> + 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. + when (item.itemId) { + R.id.action_settings -> return true + R.id.action_changelog -> Changelog.show(this) + else -> return super.onOptionsItemSelected(item) + } + return true + } + + /** + * 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.findViewById(R.id.section_label) as TextView).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 + } + } + } + + /** + * 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 WebFragment.newInstance() + } + + override fun getCount(): Int { + // Show 3 total pages. + return 3 + } + + override fun getPageTitle(position: Int): CharSequence? { + when (position) { + 0 -> return "SECTION 1" + 1 -> return "SECTION 2" + 2 -> return "SECTION 3" + } + return null + } + } +} |