universal7885: FMRadio: Fix crash and freq mismatch

- For ChannelListFragment, check if the fragment is added to an Activity and run requireactivity()
- For MainFragment, re-fetch the freq every time that fragment is drawn
This commit is contained in:
roynatech2544 2022-10-25 20:48:26 +09:00
commit 13e6667cfd
2 changed files with 10 additions and 5 deletions

View file

@ -62,6 +62,7 @@ class ChannelListFragment :
object : IWaitUntil {
override fun cond(): Boolean = mNativeIF.mDefaultCtl.getValue(GetType.GET_TYPE_FM_MUTEX_LOCKED) == 0
override fun todo() {
if (isAdded()) {
(requireActivity() as MainActivity).getMySupportFragmentManager().apply {
beginTransaction().remove(this@ChannelListFragment).commit()
executePendingTransactions()
@ -70,6 +71,7 @@ class ChannelListFragment :
requireActivity().window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
}
}
}
)
}
}

View file

@ -142,6 +142,9 @@ class MainFragment :
}
)
mFreqSearchDone = true
} else {
val mNewFreq = mFMInterface.mDefaultCtl.getValue(GetType.GET_TYPE_FM_FREQ)
mFMFreq.text = mCleanFormat.format(mNewFreq.toFloat() / 1000)
}
// Update track list and fav button
return mRootView