我正在开发一个新的应用程序,但问题是,当我单击菜单中的TherapyInformation时,它显示TherapyInformation下面的空白屏幕
但是,在StartSessionFragment上,当用户单击警告图标时,它清晰地显示TherapyInformation,如下图所示。
当用户单击TherapyInformation时,我想要实现的目标是,我想像在StartSessionFragment中那样显示Therapy信息。
在TherapyInformationFragment.kt类之下
class TherapyInformationFragment : BaseMvpFragment(), TherapyInfoView,
OnBackPressed {
override fun showTherapy(therapies: ArrayList<Therapy) {
companion object {
var RED_FLAG = "RED_FLAG"
var YELLOW_FLAG = "YELLOW_FLAG"
var ORANGE_FLAG = "ORANGE_FLAG"
}
val presenter = TherapyInformationPresenter(this)
private var goToSchedule = false
var packages: MutableList<TherapyPackage? = null
var position: Int = 0
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
rootView = inflater.inflate(R.layout.fragment_therapy_information, container,
false)
return rootView
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
if (Build.VERSION.SDK_INT = Build.VERSION_CODES.LOLLIPOP) {
super.onViewCreated(view, savedInstanceState)
}
goToSchedule = arguments?.containsKey("ids") ?: false
if (arguments != null && arguments!!.containsKey("ids"))
presenter.getTherapyInformation(arguments!!.getIntegerArrayList("ids"))
else if (arguments?.containsKey("therapy_package_id") == true)
presenter.getTherapyPackageInformation(arguments?.getInt("therapy_package_id"))
else presenter.getAllTherapyInformation()
initToolbar()
imageBack.setOnClickListener {
if (position 0)
viewPager.setCurrentItem(viewPager.currentItem - 1, true)
}
imageNext.setOnClickListener {
if (position != packages?.lastIndex) {
viewPager.setCurrentItem(viewPager.currentItem + 1, true)
} else {
if (goToSchedule) {
val data = Bundle()
data.putInt(SCREEN_TRANSITION_DIRECTION, Gravity.END)
data.putString(ScheduleFragment.MODE, ScheduleFragment.DIAGNOSTIC_FINISH_MODE)
data.putIntegerArrayList(ScheduleFragment.THERAPY_PACKAGE_IDS,
arrayListOf(*packages!!.map { it.therapyPackageId }.toTypedArray()))
router.navigateTo(Screen.SCHEDULE, data)
}
}
}
}
private fun initToolbar() {
toolbar.setOnNavigateIconClickListener { router.exit() }
toolbar.setOnToolIconClickListener {
openNavDrawer()
}
if (goToSchedule) {
toolbar.setNavigateIcon(0)
toolbar.setToolIcon(0)
}
}
override fun onBackPressed(screen: String?, data: Bundle?): Boolean {
if (goToSchedule) {
router.newRootScreen(Screen.HOME)
}
return goToSchedule
}
private fun actualizeNavArrows() {
if (position == 0) {
imageBack.visibility = View.GONE
} else {
imageBack.visibility = View.VISIBLE
}
if (position == packages?.lastIndex) {
imageNext.visibility = if (goToSchedule) View.VISIBLE else View.GONE
} else {
imageNext.visibility = View.VISIBLE
}
}
override fun showTherapyPackages(packages: List<TherapyPackage) {
this.packages = packages.toMutableList()
viewPager.adapter = object : FragmentPagerAdapter(childFragmentManager) {
override fun getItem(position: Int): Fragment {
val infoText = packages!![position].activeTherapyPackageLevel?.information?.getText
?: ""
val therapyName = packages!![position].title?.getText ?: ""
val fragment = TherapyInfoItem()
val key = packages!![position].key
val bundle = Bundle()
bundle.putString("info", infoText)
bundle.putString("therapyName", therapyName)
bundle.putString("flag", when {
key.endsWith("_rf") - RED_FLAG
key.endsWith("_yf") - YELLOW_FLAG
key.endsWith("_of") - ORANGE_FLAG
else - null
})
fragment.arguments = bundle
return fragment
}
override fun getCount(): Int {
return packages!!.size
}
}
viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
override fun onPageScrollStateChanged(state: Int) {
}
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
}
override fun onPageSelected(position: Int) {
this@TherapyInformationFragment.position = position
actualizeNavArrows()
}
})
actualizeNavArrows()
}
class TherapyInfoItem : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val rootView = inflater.inflate(R.layout.therapy_info_item, container, false)
val infoText = arguments?.getString("info")
val therapyName = arguments?.getString("therapyName")
val text = rootView.findViewById<TextView(R.id.richTextInfo)
val flagContainer = rootView.findViewById<View(R.id.flagsContainer)
val icon = rootView.findViewById<AppCompatImageView(R.id.attentionIcon)
val tvAttention = rootView.findViewById<TextView(R.id.tvAttention)
val tvFlag = rootView.findViewById<TextView(R.id.tvFlag)
infoText?.let {
text.text = Html.fromHtml(it.replace("<div<br</div", "").replace("\n\n",
"").trim()) // with(webView.settings) { //
layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN //
} // webView.isVerticalScrollBarEnabled = false //
val page = HtmlUtils().getStyledPage(infoText, 16f, "#0000ff",
"grotesk_light", 1.2f, 4f) //
webView.loadDataWithBaseURL(HtmlUtils.BASE_LOCAL_URL, page,
HtmlUtils.MIME_TYPE, null, null)
}
arguments?.getString("flag")?.let {
when (it) {
RED_FLAG - {
flagContainer.setBackgroundColor(ResourcesCompat.getColor(resources,
R.color.therapyInfoRedFlag, null))
icon.setImageResource(R.drawable.ic_therapy_info_red_flag_attention)
tvAttention.setTextColor(Color.WHITE)
tvFlag.setTextColor(Color.WHITE)
tvFlag.text = getString(R.string.recieved_red_flag)
}
YELLOW_FLAG - {
flagContainer.setBackgroundColor(ResourcesCompat.getColor(resources,
R.color.therapyInfoYellowFlag, null))
icon.setImageResource(R.drawable.ic_therapy_info_yellow_flag_attention)
tvAttention.setTextColor(Color.BLACK)
tvFlag.setTextColor(Color.BLACK)
tvFlag.text = getString(R.string.recieved_yellow_flag)
}
ORANGE_FLAG - {
flagContainer.setBackgroundColor(ResourcesCompat.getColor(resources,
R.color.therapyInfoOrangeFlag, null))
icon.setImageResource(R.drawable.ic_therapy_info_yellow_flag_attention)
tvAttention.setTextColor(Color.BLACK)
tvFlag.setTextColor(Color.BLACK)
tvFlag.text = getString(R.string.recieved_orange_flag)
}
}
} ?: run { flagContainer.visibility = View.GONE }
// webView.setBackgroundColor(Color.TRANSPARENT)
rootView.findViewById<TextView(R.id.therapyName).text = therapyName
return rootView
}
}
}
below onClick function in StartSessionFragment
private fun updateViewsState() {
tvChangePain.visibility = if (changePain.adapter.dataSet?.size == 1) View.GONE else View.VISIBLE
activeTherapyPackage?.let {
progress.visibility = if (it.activeTherapyPackageLevel?.isOffline() == true) {
activeTherapyPackage?.activeTherapyPackageLevel
?.calculateDownloadFiles()
?.let {
if (it.first == it.second) View.GONE else View.VISIBLE
} ?: View.VISIBLE
} else {
View.GONE
}
if(it.key.endsWith("_rf")) {
attentionIcon.setColorFilter(ContextCompat.getColor(context!!,
R.color.therapyInfoRedFlag))
attentionIcon.setOnClickListener { _ -
val data = Bundle()
data.putInt("therapy_package_id", it.therapyPackageId)
router.navigateTo(Screen.THERAPY_INFO, data)
}
} else if(it.key.endsWith("_yf")) {
attentionIcon.setImageResource(R.drawable.ic_therapy_info_yellow_flag_attention)
attentionIcon.setColorFilter(ContextCompat.getColor(context!!,
R.color.therapyInfoYellowWhiteFlag))
attentionIcon.setOnClickListener { _ -
val data = Bundle()
data.putInt("therapy_package_id", it.therapyPackageId)
router.navigateTo(Screen.THERAPY_INFO,data)
}
}else{
attentionIcon.setImageResource(R.drawable.ic_therapy_info_yellow_flag_attention)
attentionIcon.setColorFilter(ContextCompat.getColor(context!!,
R.color.therapyInfoYellowWhiteFlag))
attentionIcon.setOnClickListener { _ -
val data = Bundle()
data.putInt("therapy_package_id", it.therapyPackageId)
router.navigateTo(Screen.THERAPY_INFO, data)
}
} // hmm, what is the name of the menu item?
attentionIcon.visibility = if (it.key.endsWith("_rf") || it.key.endsWith("_yf") || it.key.endsWith("_of"))
View.VISIBLE
else
View.GONE
}
}
低于TherapyInfoView.kt
interface TherapyInfoView : BaseMvpView {
fun showTherapy(therapies: ArrayList<Therapy>)
fun showTherapyPackages(packages: List<TherapyPackage>)
}
在我的Presenter.kt类下面
class TherapyInformationPresenter(val view: TherapyInfoView) : BaseMvpPresenter() {
val db = TherapyDatabaseV2()
fun getTherapyInformation(ids: List<Int>) {
view.showTherapy((arrayListOf(*ids.map { db.getTherapyById(it) }.mapNotNull { it }.toTypedArray())))
}
fun getAllTherapyInformation() {
view.showTherapy(db.getAllTherapy())
}
fun getTherapyPackageInformation(int: Int?) {
view.showTherapyPackages(db.getPackages())
}
}