-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
423 additions
and
65 deletions.
There are no files selected for viewing
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
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
101 changes: 101 additions & 0 deletions
101
moxy-android/src/main/java/com/arellomobile/mvp/MvpDialogFragment.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.arellomobile.mvp; | ||
|
||
import android.app.DialogFragment; | ||
import android.app.Fragment; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
|
||
/** | ||
* Date: 17-Dec-16 | ||
* Time: 21:58 | ||
* | ||
* @author Konstantin Tckhovrebov | ||
*/ | ||
@SuppressWarnings("ConstantConditions") | ||
public class MvpDialogFragment extends DialogFragment { | ||
|
||
private boolean mIsStateSaved; | ||
private MvpDelegate<? extends MvpDialogFragment> mMvpDelegate; | ||
|
||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
getMvpDelegate().onCreate(savedInstanceState); | ||
} | ||
|
||
public void onResume() { | ||
super.onResume(); | ||
|
||
mIsStateSaved = false; | ||
|
||
getMvpDelegate().onAttach(); | ||
} | ||
|
||
public void onSaveInstanceState(Bundle outState) { | ||
super.onSaveInstanceState(outState); | ||
|
||
mIsStateSaved = true; | ||
|
||
getMvpDelegate().onSaveInstanceState(outState); | ||
getMvpDelegate().onDetach(); | ||
} | ||
|
||
@Override | ||
public void onStop() { | ||
super.onStop(); | ||
|
||
getMvpDelegate().onDetach(); | ||
} | ||
|
||
@Override | ||
public void onDestroyView() { | ||
super.onDestroyView(); | ||
|
||
getMvpDelegate().onDetach(); | ||
getMvpDelegate().onDestroyView(); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
super.onDestroy(); | ||
|
||
//We leave the screen and respectively all fragments will be destroyed | ||
if (getActivity().isFinishing()) { | ||
getMvpDelegate().onDestroy(); | ||
return; | ||
} | ||
|
||
// When we rotate device isRemoving() return true for fragment placed in backstack | ||
// http://stackoverflow.com/questions/34649126/fragment-back-stack-and-isremoving | ||
if (mIsStateSaved) { | ||
mIsStateSaved = false; | ||
return; | ||
} | ||
|
||
// See https://github.com/Arello-Mobile/Moxy/issues/24 | ||
boolean anyParentIsRemoving = false; | ||
|
||
if (Build.VERSION.SDK_INT >= 17) { | ||
Fragment parent = getParentFragment(); | ||
while (!anyParentIsRemoving && parent != null) { | ||
anyParentIsRemoving = parent.isRemoving(); | ||
parent = parent.getParentFragment(); | ||
} | ||
} | ||
|
||
if (isRemoving() || anyParentIsRemoving) { | ||
getMvpDelegate().onDestroy(); | ||
} | ||
} | ||
|
||
/** | ||
* @return The {@link MvpDelegate} being used by this Fragment. | ||
*/ | ||
public MvpDelegate getMvpDelegate() { | ||
if (mMvpDelegate == null) { | ||
mMvpDelegate = new MvpDelegate<>(this); | ||
} | ||
|
||
return mMvpDelegate; | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
moxy-android/stub-android/src/main/java/android/app/DialogFragment.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package android.app; | ||
|
||
/** | ||
* Date: 17-Dec-16 | ||
* Time: 21:58 | ||
* | ||
* @author Konstantin Tckhovrebov | ||
*/ | ||
public class DialogFragment extends Fragment { | ||
|
||
} |
97 changes: 97 additions & 0 deletions
97
moxy-app-compat/src/main/java/com/arellomobile/mvp/MvpAppCompatDialogFragment.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.arellomobile.mvp; | ||
|
||
import android.os.Bundle; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v7.app.AppCompatDialogFragment; | ||
|
||
/** | ||
* Date: 17-Dec-16 | ||
* Time: 21:55 | ||
* | ||
* @author Konstantin Tckhovrebov | ||
*/ | ||
@SuppressWarnings({"ConstantConditions", "unused"}) | ||
public class MvpAppCompatDialogFragment extends AppCompatDialogFragment { | ||
|
||
private boolean mIsStateSaved; | ||
private MvpDelegate<? extends MvpAppCompatDialogFragment> mMvpDelegate; | ||
|
||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
getMvpDelegate().onCreate(savedInstanceState); | ||
} | ||
|
||
public void onResume() { | ||
super.onResume(); | ||
|
||
mIsStateSaved = false; | ||
|
||
getMvpDelegate().onAttach(); | ||
} | ||
|
||
public void onSaveInstanceState(Bundle outState) { | ||
super.onSaveInstanceState(outState); | ||
|
||
mIsStateSaved = true; | ||
|
||
getMvpDelegate().onSaveInstanceState(outState); | ||
getMvpDelegate().onDetach(); | ||
} | ||
|
||
@Override | ||
public void onStop() { | ||
super.onStop(); | ||
|
||
getMvpDelegate().onDetach(); | ||
} | ||
|
||
@Override | ||
public void onDestroyView() { | ||
super.onDestroyView(); | ||
|
||
getMvpDelegate().onDetach(); | ||
getMvpDelegate().onDestroyView(); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
super.onDestroy(); | ||
|
||
//We leave the screen and respectively all fragments will be destroyed | ||
if (getActivity().isFinishing()) { | ||
getMvpDelegate().onDestroy(); | ||
return; | ||
} | ||
|
||
// When we rotate device isRemoving() return true for fragment placed in backstack | ||
// http://stackoverflow.com/questions/34649126/fragment-back-stack-and-isremoving | ||
if (mIsStateSaved) { | ||
mIsStateSaved = false; | ||
return; | ||
} | ||
|
||
// See https://github.com/Arello-Mobile/Moxy/issues/24 | ||
boolean anyParentIsRemoving = false; | ||
Fragment parent = getParentFragment(); | ||
while (!anyParentIsRemoving && parent != null) { | ||
anyParentIsRemoving = parent.isRemoving(); | ||
parent = parent.getParentFragment(); | ||
} | ||
|
||
if (isRemoving() || anyParentIsRemoving) { | ||
getMvpDelegate().onDestroy(); | ||
} | ||
} | ||
|
||
/** | ||
* @return The {@link MvpDelegate} being used by this Fragment. | ||
*/ | ||
public MvpDelegate getMvpDelegate() { | ||
if (mMvpDelegate == null) { | ||
mMvpDelegate = new MvpDelegate<>(this); | ||
} | ||
|
||
return mMvpDelegate; | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
moxy-app-compat/stub-appcompat/src/main/java/android/support/v4/app/DialogFragment.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package android.support.v4.app; | ||
|
||
/** | ||
* Date: 17-Dec-16 | ||
* Time: 21:58 | ||
* | ||
* @author Konstantin Tckhovrebov | ||
*/ | ||
public class DialogFragment extends Fragment { | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...p-compat/stub-appcompat/src/main/java/android/support/v7/app/AppCompatDialogFragment.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package android.support.v7.app; | ||
|
||
import android.support.v4.app.DialogFragment; | ||
|
||
/** | ||
* Date: 17-Dec-16 | ||
* Time: 21:58 | ||
* | ||
* @author Konstantin Tckhovrebov | ||
*/ | ||
public class AppCompatDialogFragment extends DialogFragment { | ||
} |
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
Oops, something went wrong.