Created
May 30, 2016 15:51
-
-
Save senneco/fe9ebd67052d9af20a9934fb02bc2c71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.altaine.wagamama.ui.fragment; | |
import android.os.Bundle; | |
import android.support.annotation.Nullable; | |
import android.support.v4.app.Fragment; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import com.arellomobile.mvp.MvpDelegate; | |
/** | |
* Date: 18-Feb-16 | |
* Time: 11:34 | |
* | |
* @author Alexander Blinov | |
*/ | |
public class MvpBaseFragment extends Fragment | |
{ | |
private Bundle mTemporaryBundle;// required for view destroy/restore | |
private MvpDelegate<? extends MvpBaseFragment> mMvpDelegate; | |
public MvpBaseFragment() | |
{ | |
mTemporaryBundle = null; | |
} | |
public void onCreate(Bundle savedInstanceState) | |
{ | |
super.onCreate(savedInstanceState); | |
this.getMvpDelegate().onCreate(savedInstanceState); | |
} | |
@Nullable | |
@Override | |
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) | |
{ | |
if (mTemporaryBundle != null) | |
{ | |
getMvpDelegate().onCreate(mTemporaryBundle); | |
mTemporaryBundle = null; | |
} | |
return super.onCreateView(inflater, container, savedInstanceState); | |
} | |
public void onStart() | |
{ | |
super.onStart(); | |
this.getMvpDelegate().onStart(); | |
} | |
public void onSaveInstanceState(Bundle outState) | |
{ | |
super.onSaveInstanceState(outState); | |
this.getMvpDelegate().onSaveInstanceState(outState); | |
} | |
public void onStop() | |
{ | |
super.onStop(); | |
this.getMvpDelegate().onStop(); | |
} | |
@Override | |
public void onDestroyView() | |
{ | |
super.onDestroyView(); | |
mTemporaryBundle = new Bundle(); | |
this.getMvpDelegate().onSaveInstanceState(mTemporaryBundle); | |
this.getMvpDelegate().onDestroy(); | |
} | |
public MvpDelegate getMvpDelegate() | |
{ | |
if (this.mMvpDelegate == null) | |
{ | |
this.mMvpDelegate = new MvpDelegate<>(this); | |
} | |
return this.mMvpDelegate; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment