blob: a0f15bd877c08d9b283e65ecec73ed235f737428 (
plain)
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
|
package net.lacolaco.smileessence.view.page
import androidx.fragment.app.Fragment
import net.lacolaco.smileessence.World
import net.lacolaco.smileessence.activity.MainActivity
import net.lacolaco.smileessence.data.PageInfo
/**
* Note, PageFragment is always attached to a MainActivity.
*/
abstract class PageFragment<out T : PageInfo> : Fragment() {
protected val world by lazy {
World[arguments!!.getLong(KEY_WORLD_USER_ID)]
}
protected val pageInfo by lazy {
val pos = arguments!!.getInt(KEY_PAGE_POSITION, -2)
if (pos == -2)
throw IllegalStateException("KEY_PAGE_POSITION not specified")
@Suppress("UNCHECKED_CAST")
world.pages[pos] as T
}
val mainActivity
get() = super.getActivity() as MainActivity
// Invoked when user click the refresh button.
open fun refresh() {}
companion object {
const val KEY_WORLD_USER_ID = "KEY_WORLD_USER_ID"
const val KEY_PAGE_POSITION = "KEY_PAGE_POSITION"
}
}
|