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
public class NewsPost extends RealmObject { | |
@PrimaryKey | |
@Required | |
private long id; | |
// left nullable as default as example | |
private String author; | |
private String title; | |
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
public class BooksScopeListener extends Fragment { // could go to base class | |
public BooksScopeListener() { | |
setRetainInstance(true); | |
RealmManager.incrementCount(); | |
} | |
@Override | |
public void onDestroy() { | |
RealmManager.decrementCount(); | |
super.onDestroy(); |
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
// initialization | |
Context baseContext = Flow.configure(baseContext, this) // | |
.defaultKey(LoginKey.create()) // | |
.dispatcher(flowDispatcher) // | |
.install(); | |
super.attachBaseContext(baseContext); | |
// manipulation of backstack | |
Flow flow = Flow.get(this); |
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
public interface Dispatcher { | |
/** | |
* Called when the history is about to change. Note that Flow does not consider the | |
* Traversal to be finished, and will not actually update the history, until the callback is | |
* triggered. Traversals cannot be canceled. | |
* | |
* @param callback Must be called to indicate completion of the traversal. | |
*/ | |
void dispatch(@NonNull Traversal traversal, @NonNull TraversalCallback callback); | |
} |
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
@Override | |
public void changeKey(State outgoingState, State incomingState, final Direction direction, | |
Map<Object, Context> incomingContexts, final TraversalCallback callback) { | |
// SAVE STATE FOR VIEW TO BE REMOVED | |
final View previousView = mainActivity.root.getChildAt(0); | |
if(outgoingState != null && previousView != null) { | |
outgoingState.save(previousView); | |
} | |
LayoutKey newKey = incomingState.getKey(); | |
Context internalContext = incomingContexts.get(newKey); |
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
public class BasicKeyParceler implements KeyParceler { | |
@Override | |
@NonNull | |
public Parcelable toParcelable(@NonNull Object key) { | |
return (Parcelable) key; | |
} | |
@Override | |
@NonNull | |
public Object toKey(@NonNull Parcelable parcelable) { |
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
public class SimpleDispatcher implements Dispatcher { | |
@Override | |
public void dispatch(@NonNull Traversal traversal, final @NonNull TraversalCallback callback) { | |
final LayoutKey newKey = traversal.destination.top(); | |
final LayoutKey previousKey = traversal.origin.top(); | |
if(newKey.equals(previousKey)) { // SHORT CIRCUIT ON SAME KEY | |
callback.onTraversalCompleted(); | |
return; | |
} | |
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
public class Email extends RealmObject { | |
public static final String PROPERTY_SUBJECT = "subject"; | |
public static final String PROPERTY_SENDER = "sender"; | |
public static final String PROPERTY_BODY = "body"; | |
public String subject; | |
public Sender sender; | |
public Body body; | |
public Date receivedDateTime; |
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
public class Email extends RealmObject { | |
private String subject; | |
private String senderName; | |
private String bodyContent; | |
private String bodyContentType; | |
private Date receivedDateTime; | |
// getters, setters | |
} |
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
public interface FeedItemInterface | |
extends RealmModel { | |
interface Repository { | |
FeedItemInterface findOne(Realm realm, long id); | |
RealmResults<FeedItemInterface> findAllSortedByRank(Realm realm); | |
FeedItemInterface findOneHighestRank(Realm realm); | |
FeedItemInterface findOneNewestUpdated(Realm realm); | |
} | |
long getId(); |