@@ -28,8 +28,9 @@ import java.io.Serializable
2828 * Created by Anton Knyazev on 04.04.2019.
2929 */
3030
31- private const val KEY_SAVE_RESULT = " omegaSaveResult"
32- private const val KEY_SAVE_DATA = " omegaSaveData"
31+ private const val KEY_SAVE_RESULT = " omegaSaveResult"
32+ private const val KEY_SAVE_DATA = " omegaSaveData"
33+ private const val KEY_SAVE_REQUEST_CODE = " omegaRequestCode"
3334
3435abstract class OmegaDialogFragment : MvpAppCompatDialogFragment (), OmegaComponent {
3536
@@ -43,13 +44,15 @@ abstract class OmegaDialogFragment : MvpAppCompatDialogFragment(), OmegaComponen
4344
4445 private var result: Boolean = false
4546 private var data: Serializable ? = null
47+ private var requestCode: Int = 0
4648
4749 override fun <T : View > findViewById (id : Int ): T ? = view?.findViewById(id)
4850
4951 override fun onCreate (savedInstanceState : Bundle ? ) {
5052 super .onCreate(savedInstanceState)
5153 result = savedInstanceState?.getBoolean(KEY_SAVE_RESULT , result) ? : result
5254 data = savedInstanceState?.getSerializable(KEY_SAVE_DATA ) ? : data
55+ requestCode = savedInstanceState?.getInt(KEY_SAVE_REQUEST_CODE , targetRequestCode) ? : targetRequestCode
5356
5457 setHasOptionsMenu(this ::class .findAnnotation<OmegaMenu >() != null )
5558 this ::class .findAnnotation<OmegaClickViews >()?.let {
@@ -86,6 +89,7 @@ abstract class OmegaDialogFragment : MvpAppCompatDialogFragment(), OmegaComponen
8689 detachChildPresenter()
8790 outState.putBoolean(KEY_SAVE_RESULT , result)
8891 outState.putSerializable(KEY_SAVE_RESULT , data)
92+ outState.putInt(KEY_SAVE_REQUEST_CODE , requestCode)
8993 }
9094
9195 override fun onCreateOptionsMenu (menu : Menu , inflater : MenuInflater ) {
@@ -256,12 +260,9 @@ abstract class OmegaDialogFragment : MvpAppCompatDialogFragment(), OmegaComponen
256260
257261 override fun onDismiss (dialog : DialogInterface ) {
258262 super .onDismiss(dialog)
259- if (isResumed) {
260- val requestCode = targetRequestCode
261- if (requestCode != 0 ) {
262- val omegaComponent = (parentFragment as ? OmegaComponent ) ? : (activity as ? OmegaComponent )
263- omegaComponent?.presenter?.onLaunchResult(requestCode, result, data)
264- }
263+ if (isResumed && requestCode != 0 ) {
264+ val omegaComponent = (parentFragment as ? OmegaComponent ) ? : (activity as ? OmegaComponent )
265+ omegaComponent?.presenter?.onLaunchResult(requestCode, result, data)
265266 }
266267 }
267268
@@ -287,7 +288,7 @@ abstract class OmegaDialogFragment : MvpAppCompatDialogFragment(), OmegaComponen
287288
288289 final override fun <T : View > bind (@IdRes res : Int , initBlock : T .() -> Unit ) = super .bind(res, initBlock)
289290
290- final override fun <T : View > bind (@IdRes vararg ids : Int , initBlock : T .() -> Unit )=
291+ final override fun <T : View > bind (@IdRes vararg ids : Int , initBlock : T .() -> Unit ) =
291292 super .bind(ids = * ids, initBlock = initBlock)
292293
293294 final override fun <T : RecyclerView > bind (res : Int , adapter : RecyclerView .Adapter <* >, initBlock : T .() -> Unit ) =
0 commit comments