|
@@ -1,13 +1,15 @@
|
|
|
-package im.angry.openeuicc.ui
|
|
|
|
|
|
|
+package im.angry.openeuicc.util
|
|
|
|
|
|
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
|
import androidx.fragment.app.Fragment
|
|
import androidx.fragment.app.Fragment
|
|
|
import im.angry.openeuicc.core.EuiccChannel
|
|
import im.angry.openeuicc.core.EuiccChannel
|
|
|
-import im.angry.openeuicc.util.*
|
|
|
|
|
|
|
|
|
|
-interface EuiccFragmentMarker: OpenEuiccContextMarker
|
|
|
|
|
|
|
+interface EuiccChannelFragmentMarker: OpenEuiccContextMarker
|
|
|
|
|
|
|
|
-fun <T> newInstanceEuicc(clazz: Class<T>, slotId: Int, portId: Int, addArguments: Bundle.() -> Unit = {}): T where T: Fragment, T: EuiccFragmentMarker {
|
|
|
|
|
|
|
+// We must use extension functions because there is no way to add bounds to the type of "self"
|
|
|
|
|
+// in the definition of an interface, so the only way is to limit where the extension functions
|
|
|
|
|
+// can be applied.
|
|
|
|
|
+fun <T> newInstanceEuicc(clazz: Class<T>, slotId: Int, portId: Int, addArguments: Bundle.() -> Unit = {}): T where T: Fragment, T: EuiccChannelFragmentMarker {
|
|
|
val instance = clazz.newInstance()
|
|
val instance = clazz.newInstance()
|
|
|
instance.arguments = Bundle().apply {
|
|
instance.arguments = Bundle().apply {
|
|
|
putInt("slotId", slotId)
|
|
putInt("slotId", slotId)
|
|
@@ -17,12 +19,12 @@ fun <T> newInstanceEuicc(clazz: Class<T>, slotId: Int, portId: Int, addArguments
|
|
|
return instance
|
|
return instance
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-val <T> T.slotId: Int where T: Fragment, T: EuiccFragmentMarker
|
|
|
|
|
|
|
+val <T> T.slotId: Int where T: Fragment, T: EuiccChannelFragmentMarker
|
|
|
get() = requireArguments().getInt("slotId")
|
|
get() = requireArguments().getInt("slotId")
|
|
|
-val <T> T.portId: Int where T: Fragment, T: EuiccFragmentMarker
|
|
|
|
|
|
|
+val <T> T.portId: Int where T: Fragment, T: EuiccChannelFragmentMarker
|
|
|
get() = requireArguments().getInt("portId")
|
|
get() = requireArguments().getInt("portId")
|
|
|
|
|
|
|
|
-val <T> T.channel: EuiccChannel where T: Fragment, T: EuiccFragmentMarker
|
|
|
|
|
|
|
+val <T> T.channel: EuiccChannel where T: Fragment, T: EuiccChannelFragmentMarker
|
|
|
get() =
|
|
get() =
|
|
|
euiccChannelManager.findEuiccChannelByPortBlocking(slotId, portId)!!
|
|
euiccChannelManager.findEuiccChannelByPortBlocking(slotId, portId)!!
|
|
|
|
|
|