Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. abstract class FRFragment : Fragment() {
  2. private var wasAdded: Boolean = false
  3.  
  4. fun wasAdded(): Boolean {
  5. return wasAdded
  6. }
  7.  
  8. fun setWasAdded(wasAdded: Boolean) {
  9. this.wasAdded = wasAdded
  10. }
  11.  
  12. val fragmentName = "UNKNOWN FRAGMENT"
  13.  
  14. abstract fun toolbarText(): String?
  15.  
  16. @LayoutRes
  17. private val layoutId: Int
  18.  
  19. init {
  20. layoutId = init()
  21. }
  22.  
  23. @LayoutRes
  24. abstract fun init(): Int
  25.  
  26. abstract fun setupView(rootView: View)
  27.  
  28. override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
  29. val rootView = inflater!!.inflate(layoutId, null)
  30. ButterKnife.setDebug(true)
  31. ButterKnife.bind(this, rootView)
  32. val appbarlayoutfix = rootView.findViewById(R.id.appbarlayoutfix)
  33. val toolbar = rootView.findViewById(R.id.toolbar) as Toolbar?
  34. appbarlayoutfix?.setPadding(0, statusBarHeight, 0, 0)
  35. (toolbar?.findViewById(R.id.main_toolbar_title) as TextView?)?.text = toolbarText()
  36. toolbar?.findViewById(R.id.btn_toolbar_back)?.setOnClickListener { v -> FRFragmentManager.goBack() }
  37.  
  38. setupView(rootView)
  39. return rootView
  40. }
  41.  
  42.  
  43. val statusBarHeight: Int
  44. get() {
  45. var result = 0
  46. val resourceId = context.resources.getIdentifier("status_bar_height", "dimen", "android")
  47. if (resourceId > 0) {
  48. result = context.resources.getDimensionPixelSize(resourceId)
  49. }
  50. return result
  51. }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement