-
Notifications
You must be signed in to change notification settings - Fork 1
/
MainActivity.kt
93 lines (70 loc) · 2.63 KB
/
MainActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.demo.themoviedb
import android.app.Activity
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import com.demo.themoviedb.base.BaseActivity
import com.demo.themoviedb.comman.BackButtonListener
import com.demo.themoviedb.comman.RouterProvider
import com.demo.themoviedb.presenter.MainPresenter
import com.demo.themoviedb.view.contract.MainContract
import com.demo.themoviedb.view.fragments.PopularFragment
import com.demo.themoviedb.view.fragments.TopRatedFragment
import com.demo.themoviedb.view.fragments.UpcomingFragment
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.view_toolbar.*
import ru.terrakok.cicerone.Router
class MainActivity : BaseActivity(), RouterProvider, MainContract.View {
private var mPresenter: MainContract.Presenter? = null
private var mActivity: Activity? = null
companion object {
val TAG: String = "MainActivity"
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//Init presenter
mPresenter = MainPresenter(this)
//set default fragment
selectTab(PopularFragment.getNewInstance(), "PopularFragment")
}
/**
* Initialize the bottom navigation
*/
override fun initViews() {
mActivity = this
bottomNavBar.setOnNavigationItemSelectedListener {
when (it.itemId) {
R.id.menu_popular -> {
selectTab(PopularFragment.getNewInstance(), "PopularFragment")
true
}
R.id.menu_top_rated -> {
selectTab(TopRatedFragment.newInstance(), "TopRatedFragment")
true
}
R.id.menu_upcoming -> {
selectTab(UpcomingFragment.newInstance(), "UpcomingFragment")
true
}
else -> false
}
}
}
override fun onResume() {
super.onResume()
mPresenter?.onViewCreated()
}
override fun getToolbarInstance(): Toolbar? = tool_bar
private fun selectTab(fragment: Fragment, fmTag: String) {
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.ab_container, fragment,fmTag)
transaction.addToBackStack(null)
transaction.commit()
}
override fun onBackPressed() {
mPresenter?.onBackPressed()
}
override val router: Router = MyApp.INSTANCE.cicerone.router
}