-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from andrzejchm/release/0.1.3
0.1.3 -> master
- Loading branch information
Showing
11 changed files
with
126 additions
and
58 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
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
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
39 changes: 39 additions & 0 deletions
39
.../main/java/io/appflate/droidmvp/ParcelableAndSerializablePresentationModelSerializer.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,39 @@ | ||
package io.appflate.droidmvp; | ||
|
||
import android.os.Bundle; | ||
import android.os.Parcelable; | ||
import java.io.Serializable; | ||
|
||
/** | ||
* Created by andrzejchm on 10/08/16. | ||
*/ | ||
public class ParcelableAndSerializablePresentationModelSerializer<M> | ||
implements PresentationModelSerializer<M> { | ||
public M restorePresentationModel(Bundle savedInstanceState, String presentationModelKey) { | ||
if (savedInstanceState != null) { | ||
Object potentialPresentationModel = savedInstanceState.get(presentationModelKey); | ||
try { | ||
return (M) potentialPresentationModel; | ||
} catch (ClassCastException ex) { | ||
throw new IllegalStateException(String.format( | ||
"We expected a presentationModel saved in the bundle under the key: \"%s\", but was: %s", | ||
presentationModelKey, | ||
potentialPresentationModel.toString())); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override public void savePresentationModel(Bundle outState, String presentationModelKey, | ||
M presentationModel) { | ||
if (presentationModel instanceof Parcelable) { | ||
outState.putParcelable(presentationModelKey, (Parcelable) presentationModel); | ||
} else if (presentationModel instanceof Serializable) { | ||
outState.putSerializable(presentationModelKey, (Serializable) presentationModel); | ||
} else { | ||
throw new IllegalArgumentException( | ||
"Your presentation model must either implement Parcelable or Serializable interface: " | ||
+ presentationModel.getClass().getCanonicalName()); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
library/src/main/java/io/appflate/droidmvp/PresentationModelSerializer.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 io.appflate.droidmvp; | ||
|
||
import android.os.Bundle; | ||
|
||
/** | ||
* Objects of this class are used to serialize and deserialize PresentationModel to/from the Bundle object. | ||
*/ | ||
public interface PresentationModelSerializer<M> { | ||
M restorePresentationModel(Bundle savedInstanceState, String presentationModelKey); | ||
|
||
void savePresentationModel(Bundle outState, String presentationModelKey, M presentationModel); | ||
} |
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
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