Fixes crash

bs
Laurent 5 years ago
parent 1ce9ee3ee3
commit 199d38f35f
  1. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SubscriptionFragment.kt
  2. 32
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/ScreenSlidePageFragment.kt

@ -181,7 +181,7 @@ class SubscriptionFragment : BaseFragment(), SkuDetailsResponseListener, Purchas
override fun getCount(): Int = this.dataSource.size
override fun getItem(position: Int): Fragment {
val d = this.dataSource[position]
return ScreenSlidePageFragment(d.iconResId, d.titleResId, d.descResId)
return ScreenSlidePageFragment.newInstance(d.iconResId, d.titleResId, d.descResId)
}
/**

@ -6,9 +6,30 @@ import android.view.View
import android.view.ViewGroup
import kotlinx.android.synthetic.main.fragment_screen_slide_page.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PAIllegalStateException
class ScreenSlidePageFragment(var iconResId: Int, var titleResId: Int, var descriptionResId: Int) : BaseFragment() {
class ScreenSlidePageFragment : BaseFragment() {
private enum class BundleKey(var key: String) {
ICON("icon"),
TITLE("title"),
DESCRIPTION("description")
}
companion object {
fun newInstance(iconResId: Int, titleResId: Int, descriptionResId: Int): ScreenSlidePageFragment {
val f = ScreenSlidePageFragment()
val bundle = Bundle()
bundle.putInt(BundleKey.ICON.key, iconResId)
bundle.putInt(BundleKey.TITLE.key, titleResId)
bundle.putInt(BundleKey.DESCRIPTION.key, descriptionResId)
f.arguments = bundle
return f
}
}
override fun onCreateView(
inflater: LayoutInflater,
@ -19,9 +40,11 @@ class ScreenSlidePageFragment(var iconResId: Int, var titleResId: Int, var descr
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
this.icon.setImageResource(this.iconResId)
this.title.text = requireContext().getString(this.titleResId)
this.description.text = requireContext().getString(this.descriptionResId)
val bundle = arguments ?: throw PAIllegalStateException("No bundle found")
this.icon.setImageResource(bundle.getInt(BundleKey.ICON.key))
this.title.text = requireContext().getString(bundle.getInt(BundleKey.TITLE.key))
this.description.text = requireContext().getString(bundle.getInt(BundleKey.DESCRIPTION.key))
}
/**
@ -31,7 +54,6 @@ class ScreenSlidePageFragment(var iconResId: Int, var titleResId: Int, var descr
view?.findViewById<View>(R.id.title)?.translationX = position
view?.findViewById<View>(R.id.icon)?.translationX = position
view?.findViewById<View>(R.id.description)?.translationX = position * 2f
}
}

Loading…
Cancel
Save