repo stringclasses 1k
values | file_url stringlengths 96 373 | file_path stringlengths 11 294 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 6
values | commit_sha stringclasses 1k
values | retrieved_at stringdate 2026-01-04 14:45:56 2026-01-04 18:30:23 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-library/src/main/java/flowless/KeyManager.java | flowless-library/src/main/java/flowless/KeyManager.java | /*
* Copyright 2016 Square Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package flowless;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class KeyManager {
public static final String SERVICE_TAG = "flowless.KEY_MANAGER";
public static KeyManager get(@NonNull Context context) {
//noinspection ResourceType
return (KeyManager) context.getSystemService(SERVICE_TAG);
}
public static KeyManager get(@NonNull View view) {
return get(view.getContext());
}
static final String GLOBAL_KEYS = "GLOBAL_KEYS";
static final String HISTORY_KEYS = "HISTORY_KEYS";
static final String REGISTERED_KEYS = "REGISTERED_KEYS";
/* private */ final Map<Object, State> states = new LinkedHashMap<>();
final Set<Object> globalKeys;
final Set<Object> registeredKeys = new HashSet<>();
KeyManager() {
this(null);
}
KeyManager(Object globalKey) {
if(globalKey == null) {
this.globalKeys = Collections.emptySet();
} else {
this.globalKeys = new LinkedHashSet<>(Arrays.asList(globalKey));
}
}
public boolean hasState(Object key) {
return states.containsKey(key);
}
void addState(State state) {
states.put(state.getKey(), state);
}
public State getState(Object key) {
State state = states.get(key);
if(state == null) {
state = new State(key);
addState(state);
}
return state;
}
public boolean isKeyRegistered(Object key) {
return registeredKeys.contains(key);
}
public boolean registerKey(Object key) {
getState(key); // initialize state if does not exist
return registeredKeys.add(key);
}
public boolean unregisterKey(Object key) {
return registeredKeys.remove(key);
}
void clearNonGlobalStatesExcept(List<Object> keep) {
Iterator<Object> keys = states.keySet().iterator();
while(keys.hasNext()) {
final Object key = keys.next();
if(!globalKeys.contains(key) && !registeredKeys.contains(key) && !keep.contains(key)) {
keys.remove();
}
}
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-library/src/main/java/flowless/Traversal.java | flowless-library/src/main/java/flowless/Traversal.java | /*
* Copyright 2016 Square Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package flowless;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
public /*final*/ class Traversal {
/**
* May be null if this is a traversal into the start state.
*/
@Nullable
public final History origin;
@NonNull
public final History destination;
@NonNull
public final Direction direction;
private final KeyManager keyManager;
Traversal(@Nullable History from, @NonNull History to, @NonNull Direction direction, KeyManager keyManager) {
this.origin = from;
this.destination = to;
this.direction = direction;
this.keyManager = keyManager;
}
/**
* Creates a Context for the given key.
*
* Contexts can be created only for keys at the top of the origin and destination Histories.
*/
@NonNull
public Context createContext(@NonNull Object key, @NonNull Context baseContext) {
return new FlowContextWrapper(key, baseContext);
}
@NonNull
public State getState(@NonNull Object key) {
return keyManager.getState(key);
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-library/src/main/java/flowless/KeyParceler.java | flowless-library/src/main/java/flowless/KeyParceler.java | /*
* Copyright 2013 Square Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package flowless;
import android.os.Parcelable;
import android.support.annotation.NonNull;
/**
* Used by History to convert your key objects to and from instances of
* {@link android.os.Parcelable}.
*/
public interface KeyParceler {
@NonNull
Parcelable toParcelable(@NonNull Object key);
@NonNull
Object toKey(@NonNull Parcelable parcelable);
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-library/src/main/java/flowless/FlowIdlingResource.java | flowless-library/src/main/java/flowless/FlowIdlingResource.java | package flowless;
/**
* Created by Zhuinden on 2016.07.01..
*/
public interface FlowIdlingResource {
void increment();
void decrement();
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-library/src/main/java/flowless/Flow.java | flowless-library/src/main/java/flowless/Flow.java | /*
* Copyright 2013 Square Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package flowless;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Parcelable;
import android.support.annotation.CheckResult;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import java.util.Iterator;
import static flowless.Preconditions.checkArgument;
import static flowless.Preconditions.checkNotNull;
/**
* Holds the current truth, the history of screens, and exposes operations to change it.
*/
public /*final*/ class Flow {
public static final String SERVICE_TAG = "flowless.FLOW_SERVICE";
public static final KeyParceler DEFAULT_KEY_PARCELER = new KeyParceler() { //
@Override
@NonNull
public Parcelable toParcelable(@NonNull Object key) {
return (Parcelable) key;
}
@Override
@NonNull
public Object toKey(@NonNull Parcelable parcelable) {
return parcelable;
}
};
@NonNull
public static Flow get(@NonNull View view) {
return get(view.getContext());
}
@NonNull
public static Flow get(@NonNull Context context) {
// noinspection ResourceType
Flow flow = (Flow) context.getSystemService(Flow.SERVICE_TAG);
if(null == flow) {
throw new IllegalStateException("Context was not wrapped with flow. " + "Make sure attachBaseContext was overridden in your main activity");
}
return flow;
}
@NonNull
public ServiceProvider getServices() {
return serviceProvider;
}
@NonNull
public KeyManager getStates() {
return keyManager;
}
/**
* @return null if context has no Flow key embedded.
*/
@Nullable
public static <T> T getKey(@NonNull Context context) {
return KeyContextWrapper.Methods.getKey(context);
}
/**
* @return null if view's Context has no Flow key embedded.
*/
@Nullable
public static <T> T getKey(@NonNull View view) {
return getKey(view.getContext());
}
@NonNull
public static Installer configure(@NonNull Context baseContext, @NonNull Activity activity) {
return new Installer(baseContext, activity);
}
/**
* Adds a history as an extra to an Intent.
*/
public void addHistoryToIntent(@NonNull Intent intent, @NonNull History history, @NonNull KeyParceler parceler) {
InternalLifecycleIntegration.addHistoryToIntent(intent, history, parceler, keyManager);
}
public static void addHistoryToIntentWithoutState(@NonNull Intent intent, @NonNull History history, @NonNull KeyParceler parceler) {
InternalLifecycleIntegration.addHistoryToIntent(intent, history, parceler, null);
}
/**
* Handles an Intent carrying a History extra.
*
* @return true if the Intent contains a History and it was handled.
*/
@CheckResult
public static boolean onNewIntent(@NonNull Intent intent, @NonNull Activity activity) {
//noinspection ConstantConditions
checkArgument(intent != null, "intent may not be null");
if(intent.hasExtra(InternalLifecycleIntegration.INTENT_KEY)) {
InternalLifecycleIntegration.find(activity).onNewIntent(intent);
return true;
}
return false;
}
private History history;
private Dispatcher dispatcher;
private PendingTraversal pendingTraversal;
final KeyManager keyManager;
final ServiceProvider serviceProvider;
Flow(KeyManager keyManager, ServiceProvider serviceProvider, History history) {
this.keyManager = keyManager;
this.serviceProvider = serviceProvider;
this.history = history;
}
@NonNull
public History getHistory() {
return history;
}
void executePendingTraversal() {
if(pendingTraversal != null && pendingTraversal.state == TraversalState.DISPATCHED) {
PendingTraversal tempTraversal = pendingTraversal;
pendingTraversal.onTraversalCompleted();
tempTraversal.didForceExecute = true;
}
}
void setDispatcher(@NonNull Dispatcher dispatcher) {
setDispatcher(dispatcher, true);
}
/**
* Set the dispatcher, may receive an immediate call to {@link Dispatcher#dispatch}. If a {@link
* Traversal Traversal} is currently in progress with a previous Dispatcher, that Traversal will
* not be affected.
*/
void setDispatcher(@NonNull Dispatcher dispatcher, boolean created) {
this.dispatcher = checkNotNull(dispatcher, "dispatcher");
if((pendingTraversal == null && created) // first create
|| (pendingTraversal != null && pendingTraversal.state == TraversalState.DISPATCHED && pendingTraversal.next == null)) { // pending bootstrap for handling mid-flight
// initialization should occur for current state if views are created or re-created
move(new PendingTraversal() {
@Override
void doExecute() {
bootstrap(history);
}
});
} else if(pendingTraversal == null) { // no-op if the view still exists and nothing to be done
return;
} else if(pendingTraversal.state == TraversalState.DISPATCHED) { // a traversal is in progress
// do nothing, pending traversal will finish
} else if(pendingTraversal.state == TraversalState.ENQUEUED) {
// a traversal was enqueued while we had no dispatcher, run it now.
pendingTraversal.execute();
} else if(pendingTraversal.state == TraversalState.FINISHED) {
if(pendingTraversal.next != null) { //finished with a pending traversal
pendingTraversal = pendingTraversal.next;
pendingTraversal.execute();
} else {
pendingTraversal = null;
}
}
}
/**
* Remove the dispatcher. A noop if the given dispatcher is not the current one.
* <p>
* No further {@link Traversal Traversals}, including Traversals currently enqueued, will execute
* until a new dispatcher is set.
*/
public void removeDispatcher(@NonNull Dispatcher dispatcher) {
// This mechanism protects against out of order calls to this method and setDispatcher
// (e.g. if an outgoing activity is paused after an incoming one resumes).
if(this.dispatcher == checkNotNull(dispatcher, "dispatcher")) {
this.dispatcher = null;
}
}
/**
* Replaces the history with the one given and dispatches in the given direction.
*/
public void setHistory(@NonNull final History history, @NonNull final Direction direction) {
move(new PendingTraversal() {
@Override
void doExecute() {
dispatch(preserveEquivalentPrefix(getHistory(), history), direction);
}
});
}
/**
* Replaces the history with the given key and dispatches in the given direction.
*/
public void replaceHistory(@NonNull final Object key, @NonNull final Direction direction) {
setHistory(getHistory().buildUpon().clear().push(key).build(), direction);
}
/**
* Replaces the top key of the history with the given key and dispatches in the given direction.
*/
public void replaceTop(@NonNull final Object key, @NonNull final Direction direction) {
setHistory(getHistory().buildUpon().pop(1).push(key).build(), direction);
}
/**
* Updates the history such that the given key is at the top and dispatches the updated
* history.
*
* If newTopKey is already at the top of the history, the history will be unchanged, but it will
* be dispatched with direction {@link Direction#REPLACE}.
*
* If newTopKey is already on the history but not at the top, the stack will pop until newTopKey
* is at the top, and the dispatch direction will be {@link Direction#BACKWARD}.
*
* If newTopKey is not already on the history, it will be pushed and the dispatch direction will
* be {@link Direction#FORWARD}.
*
* Objects' equality is always checked using {@link Object#equals(Object)}.
*/
public void set(@NonNull final Object newTopKey) {
move(new PendingTraversal() {
@Override
void doExecute() {
if(newTopKey.equals(history.top())) {
dispatch(history, Direction.REPLACE);
return;
}
History.Builder builder = history.buildUpon();
int count = 0;
// Search backward to see if we already have newTop on the stack
Object preservedInstance = null;
for(Iterator<Object> it = history.reverseIterator(); it.hasNext(); ) {
Object entry = it.next();
// If we find newTop on the stack, pop back to it.
if(entry.equals(newTopKey)) {
for(int i = 0; i < history.size() - count; i++) {
preservedInstance = builder.pop();
}
break;
} else {
count++;
}
}
History newHistory;
if(preservedInstance != null) {
// newTop was on the history. Put the preserved instance back on and dispatch.
builder.push(preservedInstance);
newHistory = builder.build();
dispatch(newHistory, Direction.BACKWARD);
} else {
// newTop was not on the history. Push it on and dispatch.
builder.push(newTopKey);
newHistory = builder.build();
dispatch(newHistory, Direction.FORWARD);
}
}
});
}
/**
* Go back one key.
*
* @return false if going back is not possible.
*/
@CheckResult
public boolean goBack() {
if(pendingTraversal != null && pendingTraversal.state != TraversalState.FINISHED) { //traversal is in progress
return true;
}
boolean canGoBack = history.size() > 1;
if(!canGoBack) {
return false;
}
setHistory(history.buildUpon().pop(1).build(), Direction.BACKWARD);
return true;
}
private void move(PendingTraversal pendingTraversal) {
incrementIdlingResource();
if(this.pendingTraversal == null) {
this.pendingTraversal = pendingTraversal;
// If there is no dispatcher wait until one shows up before executing.
if(dispatcher != null) {
pendingTraversal.execute();
}
} else {
this.pendingTraversal.enqueue(pendingTraversal);
}
decrementIdlingResource();
}
private static History preserveEquivalentPrefix(History current, History proposed) {
Iterator<Object> oldIt = current.reverseIterator();
Iterator<Object> newIt = proposed.reverseIterator();
History.Builder preserving = current.buildUpon().clear();
while(newIt.hasNext()) {
Object newEntry = newIt.next();
if(!oldIt.hasNext()) { // old history cannot contain new history, preserve
preserving.push(newEntry);
break;
}
Object oldEntry = oldIt.next(); // old history contains elements
if(oldEntry.equals(newEntry)) { // preserve previous history if state can exist bound to it
preserving.push(oldEntry);
} else { // if it's not the same, we need the new entry
preserving.push(newEntry);
break;
}
}
while(newIt.hasNext()) { // preserve any additional new elements not found in old history
preserving.push(newIt.next());
}
return preserving.build();
}
boolean hasDispatcher() {
return dispatcher != null;
}
private enum TraversalState {
/**
* {@link PendingTraversal#execute} has not been called.
*/
ENQUEUED,
/**
* {@link PendingTraversal#execute} was called, waiting for {@link
* PendingTraversal#onTraversalCompleted}.
*/
DISPATCHED,
/**
* {@link PendingTraversal#onTraversalCompleted} was called.
*/
FINISHED
}
private abstract class PendingTraversal
implements TraversalCallback {
boolean didForceExecute;
TraversalState state = TraversalState.ENQUEUED;
PendingTraversal next;
History nextHistory;
void enqueue(PendingTraversal pendingTraversal) {
if(this.next == null) {
this.next = pendingTraversal;
} else {
this.next.enqueue(pendingTraversal);
}
}
@Override
public void onTraversalCompleted() {
if(didForceExecute) {
return;
}
incrementIdlingResource();
if(state != TraversalState.DISPATCHED) {
throw new IllegalStateException(state == TraversalState.FINISHED ? "onComplete already called for this transition" : "transition not yet dispatched!");
}
// Is not set by noop and bootstrap transitions.
if(nextHistory != null) {
history = nextHistory;
}
state = TraversalState.FINISHED;
pendingTraversal = next;
if(pendingTraversal == null) {
keyManager.clearNonGlobalStatesExcept(history.asList());
} else if(dispatcher != null) {
pendingTraversal.execute();
}
decrementIdlingResource();
}
void bootstrap(History history) {
if(dispatcher == null) {
throw new AssertionError("Bad doExecute method allowed dispatcher to be cleared");
}
incrementIdlingResource();
dispatcher.dispatch(new Traversal(null, history, Direction.REPLACE, keyManager), this);
decrementIdlingResource();
}
void dispatch(History nextHistory, Direction direction) {
this.nextHistory = checkNotNull(nextHistory, "nextHistory");
if(dispatcher == null) {
throw new AssertionError("Bad doExecute method allowed dispatcher to be cleared");
}
incrementIdlingResource();
dispatcher.dispatch(new Traversal(getHistory(), nextHistory, direction, keyManager), this);
decrementIdlingResource();
}
final void execute() {
incrementIdlingResource();
if(state != TraversalState.ENQUEUED) {
throw new AssertionError("unexpected state " + state);
}
if(dispatcher == null) {
throw new AssertionError("Caller must ensure that dispatcher is set");
}
state = TraversalState.DISPATCHED;
doExecute();
decrementIdlingResource();
}
/**
* Must be synchronous and end with a call to {@link #dispatch} or {@link
* #onTraversalCompleted()}.
*/
abstract void doExecute();
}
// IDLING RESOURCE LOGIC
private static FlowIdlingResource flowIdlingResource = null;
public static void incrementIdlingResource() {
if(flowIdlingResource != null) {
flowIdlingResource.increment();
}
}
public static void decrementIdlingResource() {
if(flowIdlingResource != null) {
flowIdlingResource.decrement();
}
}
public static FlowIdlingResource getFlowIdlingResource() {
return flowIdlingResource;
}
public static void setFlowIdlingResource(FlowIdlingResource _flowIdlingResource) {
flowIdlingResource = _flowIdlingResource;
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-library/src/main/java/flowless/ViewUtils.java | flowless-library/src/main/java/flowless/ViewUtils.java | package flowless;
/*
* Copyright 2013 Square Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import android.view.View;
import android.view.ViewTreeObserver;
public class ViewUtils {
public interface OnMeasuredCallback {
void onMeasured(View view, int width, int height);
}
public static void waitForMeasure(final View view, final OnMeasuredCallback callback) {
int width = view.getWidth();
int height = view.getHeight();
if(width > 0 && height > 0) {
callback.onMeasured(view, width, height);
return;
}
view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
final ViewTreeObserver observer = view.getViewTreeObserver();
if(observer.isAlive()) {
observer.removeOnPreDrawListener(this);
}
callback.onMeasured(view, view.getWidth(), view.getHeight());
return true;
}
});
}
private ViewUtils() {
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-library/src/main/java/flowless/Installer.java | flowless-library/src/main/java/flowless/Installer.java | /*
* Copyright 2016 Square Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package flowless;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
public /*final*/ class Installer {
private final Context baseContext;
private final Activity activity;
private KeyParceler parceler;
private Object defaultKey;
private Dispatcher dispatcher;
private Object globalKey;
Installer(Context baseContext, Activity activity) {
this.baseContext = baseContext;
this.activity = activity;
}
@NonNull
public Installer keyParceler(@Nullable KeyParceler parceler) {
this.parceler = parceler;
return this;
}
@NonNull
public Installer dispatcher(@Nullable Dispatcher dispatcher) {
this.dispatcher = dispatcher;
return this;
}
@NonNull
public Installer defaultKey(@Nullable Object defaultKey) {
this.defaultKey = defaultKey;
return this;
}
public Installer globalKey(@NonNull Object globalKey) {
this.globalKey = globalKey;
return this;
}
@NonNull
public Context install() {
if(InternalLifecycleIntegration.find(activity) != null) {
throw new IllegalStateException("Flow is already installed in this Activity.");
}
if(dispatcher == null) {
throw new IllegalStateException("Dispatcher must be defined, but is missing.");
}
if(defaultKey == null) {
throw new IllegalStateException("Default Key must be defined, but is missing.");
}
if(parceler == null) {
parceler = Flow.DEFAULT_KEY_PARCELER;
}
final Object defState = defaultKey;
final History defaultHistory = History.single(defState);
final Application app = (Application) baseContext.getApplicationContext();
final KeyManager keyManager = new KeyManager(globalKey);
final ServiceProvider serviceProvider = new ServiceProvider();
InternalLifecycleIntegration.install(app, activity, parceler, defaultHistory, dispatcher, serviceProvider, keyManager);
return new InternalContextWrapper(baseContext, activity, globalKey);
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-library/src/main/java/flowless/ActivityUtils.java | flowless-library/src/main/java/flowless/ActivityUtils.java | package flowless;
import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
/**
* Created by Zhuinden on 2016.05.26..
*/
public class ActivityUtils {
public static Activity getActivity(Context context) {
if (context instanceof Activity) {
return (Activity) context;
} else if (context instanceof ContextWrapper) {
Context contextWrapper = context;
while (contextWrapper instanceof ContextWrapper && ((ContextWrapper) context).getBaseContext() != null) {
contextWrapper = ((ContextWrapper) contextWrapper).getBaseContext();
if (contextWrapper instanceof Activity) {
return (Activity) contextWrapper;
}
}
}
throw new IllegalStateException("No activity could be found in [" + context + "]");
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-library/src/main/java/flowless/Direction.java | flowless-library/src/main/java/flowless/Direction.java | /*
* Copyright 2016 Square Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package flowless;
public enum Direction {
FORWARD,
BACKWARD,
REPLACE
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-library/src/main/java/flowless/Preconditions.java | flowless-library/src/main/java/flowless/Preconditions.java | /*
* Copyright (C) 2007 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package flowless;
/*final*/ class Preconditions {
private Preconditions() {
throw new AssertionError();
}
/**
* @throws java.lang.IllegalArgumentException if condition is false.
*/
static void checkArgument(boolean condition, String errorMessage) {
if(!condition) {
throw new IllegalArgumentException(errorMessage);
}
}
/**
* @param reference an object reference
* @return the non-null reference that was validated
* @throws NullPointerException if {@code reference} is null
*/
static <T> T checkNotNull(T reference, String errorMessage, Object... args) {
if(reference == null) {
throw new NullPointerException(String.format(errorMessage, args));
}
return reference;
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-library/src/main/java/flowless/preset/FlowContainerLifecycleListener.java | flowless-library/src/main/java/flowless/preset/FlowContainerLifecycleListener.java | package flowless.preset;
/**
* Created by Zhuinden on 2016.07.01..
*/
public interface FlowContainerLifecycleListener
extends FlowLifecycles.ActivityResultListener, //
FlowLifecycles.BackPressListener, //
FlowLifecycles.CreateDestroyListener, //
FlowLifecycles.StartStopListener, //
FlowLifecycles.ResumePauseListener, //
FlowLifecycles.ViewStatePersistenceListener, //
FlowLifecycles.PreSaveViewStateListener, //
FlowLifecycles.PermissionRequestListener, //
FlowLifecycles.ViewLifecycleListener {
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-library/src/main/java/flowless/preset/DispatcherUtils.java | flowless-library/src/main/java/flowless/preset/DispatcherUtils.java | package flowless.preset;
import android.view.View;
import flowless.Bundleable;
import flowless.Flow;
import flowless.History;
import flowless.State;
import flowless.Traversal;
/**
* Created by Zhuinden on 2016.07.01..
*/
public class DispatcherUtils {
private DispatcherUtils() {
}
public static boolean isPreviousKeySameAsNewKey(History origin, History destination) {
return origin != null && origin.top() != null && origin.top().equals(destination.top());
}
public static <T> T getNewKey(Traversal traversal) {
return traversal.destination.top();
}
public static <T> T getPreviousKey(Traversal traversal) {
T previousKey = null;
if(traversal.origin != null) {
previousKey = traversal.origin.top();
}
return previousKey;
}
private static void persistViewToState(Traversal traversal, View view) {
if(view != null) {
if(view != null && view instanceof FlowLifecycles.PreSaveViewStateListener) {
((FlowLifecycles.PreSaveViewStateListener) view).preSaveViewState();
}
if(Flow.getKey(view.getContext()) != null) {
State outgoingState = traversal.getState(Flow.getKey(view.getContext()));
if(outgoingState != null) {
outgoingState.save(view);
if(view instanceof Bundleable) {
outgoingState.setBundle(((Bundleable) view).toBundle());
}
}
}
}
}
public static void persistViewToStateWithoutNotifyRemoval(Traversal traversal, View view) {
persistViewToState(traversal, view);
}
public static void persistViewToStateAndNotifyRemoval(Traversal traversal, View view) {
persistViewToState(traversal, view);
notifyViewForFlowRemoval(view);
}
public static void restoreViewFromState(Traversal traversal, View view) {
if(view != null) {
if(Flow.getKey(view.getContext()) != null) {
State incomingState = traversal.getState(Flow.getKey(view.getContext()));
if(incomingState != null) {
incomingState.restore(view);
if(view instanceof Bundleable) {
((Bundleable) view).fromBundle(incomingState.getBundle());
}
}
}
if(view instanceof FlowLifecycles.ViewLifecycleListener) {
((FlowLifecycles.ViewLifecycleListener) view).onViewRestored();
}
}
}
public static void notifyViewForFlowRemoval(View previousView) {
if(previousView != null && previousView instanceof FlowLifecycles.ViewLifecycleListener) {
((FlowLifecycles.ViewLifecycleListener) previousView).onViewDestroyed(true);
}
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-library/src/main/java/flowless/preset/ContainerRootDispatcher.java | flowless-library/src/main/java/flowless/preset/ContainerRootDispatcher.java | package flowless.preset;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.CheckResult;
import android.support.annotation.NonNull;
import android.view.ViewGroup;
import flowless.Dispatcher;
import flowless.Flow;
import flowless.Traversal;
import flowless.TraversalCallback;
/**
* Created by Zhuinden on 2016.07.01..
*/
public class ContainerRootDispatcher
extends BaseDispatcher
implements FlowContainerLifecycleListener {
private boolean hasActiveView() {
return rootHolder != null && rootHolder.root != null;
}
@Override
public void onCreate(Bundle bundle) {
if(hasActiveView()) {
FlowLifecycleProvider.onCreate(rootHolder.root, bundle);
}
}
@Override
public void onDestroy() {
if(hasActiveView()) {
FlowLifecycleProvider.onDestroy(rootHolder.root);
}
if(hasActiveView()) {
rootHolder.root = null;
}
}
@Override
public void onResume() {
if(hasActiveView()) {
FlowLifecycleProvider.onResume(rootHolder.root);
}
}
@Override
public void onPause() {
if(hasActiveView()) {
FlowLifecycleProvider.onPause(rootHolder.root);
}
}
@Override
public void onStart() {
if(hasActiveView()) {
FlowLifecycleProvider.onStart(rootHolder.root);
}
}
@Override
public void onStop() {
if(hasActiveView()) {
FlowLifecycleProvider.onStop(rootHolder.root);
}
}
@Override
public void onViewRestored() {
if(hasActiveView()) {
FlowLifecycleProvider.onViewRestored(rootHolder.root);
}
}
@Override
public void onViewDestroyed(boolean removedByFlow) {
if(hasActiveView()) {
FlowLifecycleProvider.onViewDestroyed(rootHolder.root, removedByFlow);
}
}
@Override
public void preSaveViewState() {
if(hasActiveView()) {
FlowLifecycleProvider.preSaveViewState(rootHolder.root);
}
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
if(hasActiveView()) {
FlowLifecycleProvider.onSaveInstanceState(rootHolder.root, outState);
// you must call the ForceBundler manually within the Dispatcher Container
}
}
@Override
@CheckResult
public boolean onBackPressed() {
boolean childHandledEvent = false;
if(hasActiveView()) {
childHandledEvent = FlowLifecycleProvider.onBackPressed(rootHolder.root);
if(childHandledEvent) {
return true;
}
}
Flow flow = Flow.get(baseContext);
return flow.goBack();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(hasActiveView()) {
FlowLifecycleProvider.onActivityResult(rootHolder.root, requestCode, resultCode, data);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if(hasActiveView()) {
FlowLifecycleProvider.onRequestPermissionsResult(rootHolder.root, requestCode, permissions, grantResults);
}
}
@Override
public void dispatch(@NonNull Traversal traversal, @NonNull TraversalCallback traversalCallback) {
ViewGroup root = rootHolder.root;
if(root instanceof Dispatcher) {
Dispatcher dispatchContainer = (Dispatcher) root;
dispatchContainer.dispatch(traversal, traversalCallback);
} else {
throw new IllegalArgumentException("The Root [" + root + "] of a ContainerRootDispatcher must be a Dispatcher.");
}
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-library/src/main/java/flowless/preset/FlowLifecycleProvider.java | flowless-library/src/main/java/flowless/preset/FlowLifecycleProvider.java | package flowless.preset;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.CheckResult;
import android.view.View;
/**
* Created by Zhuinden on 2016.07.01..
*/
public class FlowLifecycleProvider {
private FlowLifecycleProvider() {
// No instance
}
public static void onCreate(View view, Bundle savedInstanceState) {
if(view != null && view instanceof FlowLifecycles.CreateDestroyListener) {
((FlowLifecycles.CreateDestroyListener) view).onCreate(savedInstanceState);
}
}
public static void onStart(View view) {
if(view != null && view instanceof FlowLifecycles.StartStopListener) {
((FlowLifecycles.StartStopListener) view).onStart();
}
}
public static void onResume(View view) {
if(view != null && view instanceof FlowLifecycles.ResumePauseListener) {
((FlowLifecycles.ResumePauseListener) view).onResume();
}
}
public static void onPause(View view) {
if(view != null && view instanceof FlowLifecycles.ResumePauseListener) {
((FlowLifecycles.ResumePauseListener) view).onPause();
}
}
public static void onStop(View view) {
if(view != null && view instanceof FlowLifecycles.StartStopListener) {
((FlowLifecycles.StartStopListener) view).onStop();
}
}
public static void onDestroy(View view) {
if(view != null && view instanceof FlowLifecycles.CreateDestroyListener) {
((FlowLifecycles.CreateDestroyListener) view).onDestroy();
}
if(view != null && view instanceof FlowLifecycles.ViewLifecycleListener) {
((FlowLifecycles.ViewLifecycleListener) view).onViewDestroyed(false);
}
}
@CheckResult
public static boolean onBackPressed(View view) {
if(view != null && view instanceof FlowLifecycles.BackPressListener) {
return ((FlowLifecycles.BackPressListener) view).onBackPressed();
}
return false;
}
public static void onActivityResult(View view, int requestCode, int resultCode, Intent data) {
if(view != null && view instanceof FlowLifecycles.ActivityResultListener) {
((FlowLifecycles.ActivityResultListener) view).onActivityResult(requestCode, resultCode, data);
}
}
public static void onRequestPermissionsResult(View view, int requestCode, String[] permissions, int[] grantResults) {
if(view != null && view instanceof FlowLifecycles.PermissionRequestListener) {
((FlowLifecycles.PermissionRequestListener) view).onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
public static void preSaveViewState(View view) {
if(view != null && view instanceof FlowLifecycles.PreSaveViewStateListener) {
((FlowLifecycles.PreSaveViewStateListener) view).preSaveViewState();
}
}
public static void onSaveInstanceState(View view, Bundle bundle) {
if(view != null && view instanceof FlowLifecycles.ViewStatePersistenceListener) {
((FlowLifecycles.ViewStatePersistenceListener) view).onSaveInstanceState(bundle);
}
}
public static void onViewRestored(View view) {
if(view != null && view instanceof FlowLifecycles.ViewLifecycleListener) {
((FlowLifecycles.ViewLifecycleListener) view).onViewRestored();
}
}
public static void onViewDestroyed(View view, boolean removedByFlow) {
if(view != null && view instanceof FlowLifecycles.ViewLifecycleListener) {
((FlowLifecycles.ViewLifecycleListener) view).onViewDestroyed(removedByFlow);
}
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-library/src/main/java/flowless/preset/FlowLifecycles.java | flowless-library/src/main/java/flowless/preset/FlowLifecycles.java | package flowless.preset;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
/**
* Created by Zhuinden on 2016.07.01..
*/
public interface FlowLifecycles {
public interface BackPressListener {
boolean onBackPressed();
}
public interface CreateDestroyListener {
void onCreate(Bundle bundle);
void onDestroy();
}
public interface StartStopListener {
void onStart();
void onStop();
}
public interface ResumePauseListener {
void onResume();
void onPause();
}
public interface ViewLifecycleListener {
void onViewRestored();
void onViewDestroyed(boolean removedByFlow);
}
public interface PreSaveViewStateListener {
void preSaveViewState();
}
public interface ViewStatePersistenceListener {
void onSaveInstanceState(@NonNull Bundle outState);
}
public interface ActivityResultListener {
void onActivityResult(int requestCode, int resultCode, Intent data);
}
public interface PermissionRequestListener {
void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults);
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-library/src/main/java/flowless/preset/SingleRootDispatcher.java | flowless-library/src/main/java/flowless/preset/SingleRootDispatcher.java | package flowless.preset;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.CheckResult;
import android.support.annotation.Nullable;
import flowless.Flow;
import flowless.ForceBundler;
/**
* Created by Zhuinden on 2016.06.27..
*/
public abstract class SingleRootDispatcher
extends BaseDispatcher
implements FlowContainerLifecycleListener {
private boolean hasActiveView() {
return rootHolder != null && rootHolder.root != null && rootHolder.root.getChildCount() > 0;
}
@Override
public void onCreate(Bundle bundle) {
if(hasActiveView()) {
FlowLifecycleProvider.onCreate(rootHolder.root.getChildAt(0), bundle);
}
}
@Override
public void onDestroy() {
if(hasActiveView()) {
FlowLifecycleProvider.onDestroy(rootHolder.root.getChildAt(0));
}
if(rootHolder != null && rootHolder.root != null) {
rootHolder.root = null;
}
}
@Override
public void onResume() {
if(hasActiveView()) {
FlowLifecycleProvider.onResume(rootHolder.root.getChildAt(0));
}
}
@Override
public void onPause() {
if(hasActiveView()) {
FlowLifecycleProvider.onPause(rootHolder.root.getChildAt(0));
}
}
@Override
public void onStart() {
if(hasActiveView()) {
FlowLifecycleProvider.onStart(rootHolder.root.getChildAt(0));
}
}
@Override
public void onStop() {
if(hasActiveView()) {
FlowLifecycleProvider.onStop(rootHolder.root.getChildAt(0));
}
}
@Override
public void onViewRestored() {
if(hasActiveView()) {
FlowLifecycleProvider.onViewRestored(rootHolder.root.getChildAt(0));
}
}
@Override
public void onViewDestroyed(boolean removedByFlow) {
if(hasActiveView()) {
FlowLifecycleProvider.onViewDestroyed(rootHolder.root.getChildAt(0), removedByFlow);
}
}
@Override
public void preSaveViewState() {
if(hasActiveView()) {
FlowLifecycleProvider.preSaveViewState(rootHolder.getRoot().getChildAt(0));
}
}
@Override
public void onSaveInstanceState(@Nullable Bundle outState) {
if(hasActiveView()) {
FlowLifecycleProvider.onSaveInstanceState(rootHolder.root.getChildAt(0), outState);
// Important: Single Root Dispatcher can handle its child's state directly, but Container Root Dispatcher cannot.
ForceBundler.saveToBundle(rootHolder.root.getChildAt(0));
}
}
@Override
@CheckResult
public boolean onBackPressed() {
boolean childHandledEvent = false;
if(hasActiveView()) {
childHandledEvent = FlowLifecycleProvider.onBackPressed(rootHolder.root.getChildAt(0));
if(childHandledEvent) {
return true;
}
}
Flow flow = Flow.get(baseContext);
return flow.goBack();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(hasActiveView()) {
FlowLifecycleProvider.onActivityResult(rootHolder.root.getChildAt(0), requestCode, resultCode, data);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if(hasActiveView()) {
FlowLifecycleProvider.onRequestPermissionsResult(rootHolder.root.getChildAt(0), requestCode, permissions, grantResults);
}
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-library/src/main/java/flowless/preset/BaseDispatcher.java | flowless-library/src/main/java/flowless/preset/BaseDispatcher.java | package flowless.preset;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.ViewGroup;
import flowless.Dispatcher;
import flowless.Traversal;
import flowless.TraversalCallback;
/**
* Created by Zhuinden on 2016.07.01..
*/
public abstract class BaseDispatcher
implements Dispatcher, FlowLifecycles {
public static class RootHolder {
protected ViewGroup root;
public RootHolder() {
}
public ViewGroup getRoot() {
return root;
}
public void setRoot(ViewGroup root) {
this.root = root;
}
}
protected Context baseContext;
protected final RootHolder rootHolder;
public BaseDispatcher() {
this.rootHolder = createRootHolder();
}
protected RootHolder createRootHolder() {
return new RootHolder();
}
public void setBaseContext(Context baseContext) {
this.baseContext = baseContext;
}
public RootHolder getRootHolder() {
return rootHolder;
}
@Override
public abstract void dispatch(@NonNull Traversal traversal, @NonNull TraversalCallback callback);
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flow-sample-basic/src/main/java/flowless/sample/basic/HelloScreen.java | flow-sample-basic/src/main/java/flowless/sample/basic/HelloScreen.java | /*
* Copyright 2016 Square Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package flowless.sample.basic;
import android.os.Parcel;
import android.os.Parcelable;
final class HelloScreen
implements Parcelable {
final String name;
HelloScreen(String name) {
this.name = name;
}
protected HelloScreen(Parcel in) {
name = in.readString();
}
public static final Creator<HelloScreen> CREATOR = new Creator<HelloScreen>() {
@Override
public HelloScreen createFromParcel(Parcel in) {
return new HelloScreen(in.readString());
}
@Override
public HelloScreen[] newArray(int size) {
return new HelloScreen[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
}
@Override
public boolean equals(Object o) {
if(this == o) {
return true;
}
if(o == null || getClass() != o.getClass()) {
return false;
}
HelloScreen that = (HelloScreen) o;
return name.equals(that.name);
}
@Override
public int hashCode() {
return name.hashCode();
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flow-sample-basic/src/main/java/flowless/sample/basic/BasicDispatcher.java | flow-sample-basic/src/main/java/flowless/sample/basic/BasicDispatcher.java | /*
* Copyright 2016 Square Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package flowless.sample.basic;
import android.app.Activity;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import flowless.Dispatcher;
import flowless.Traversal;
import flowless.TraversalCallback;
final class BasicDispatcher
implements Dispatcher {
private final Activity activity;
BasicDispatcher(Activity activity) {
this.activity = activity;
}
@Override
public void dispatch(@NonNull Traversal traversal, @NonNull TraversalCallback callback) {
Log.d("BasicDispatcher", "dispatching " + traversal);
Object dest = traversal.destination.top();
ViewGroup frame = (ViewGroup) activity.findViewById(R.id.basic_activity_frame);
if(traversal.origin != null) {
if(frame.getChildCount() > 0) {
traversal.getState(traversal.origin.top()).save(frame.getChildAt(0));
frame.removeAllViews();
}
}
@LayoutRes final int layout;
if(dest instanceof HelloScreen) {
layout = R.layout.hello_screen;
} else if(dest instanceof WelcomeScreen) {
layout = R.layout.welcome_screen;
} else {
throw new AssertionError("Unrecognized screen " + dest);
}
View incomingView = LayoutInflater.from(traversal.createContext(dest, activity)) //
.inflate(layout, frame, false);
frame.addView(incomingView);
traversal.getState(traversal.destination.top()).restore(incomingView);
callback.onTraversalCompleted();
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flow-sample-basic/src/main/java/flowless/sample/basic/BasicSampleActivity.java | flow-sample-basic/src/main/java/flowless/sample/basic/BasicSampleActivity.java | /*
* Copyright 2016 Square Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package flowless.sample.basic;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import flowless.Flow;
public class BasicSampleActivity
extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.basic_activity_frame);
}
@Override
protected void attachBaseContext(Context baseContext) {
baseContext = Flow.configure(baseContext, this) //
.dispatcher(new BasicDispatcher(this)) //
.defaultKey(new WelcomeScreen()) //
.install();
super.attachBaseContext(baseContext);
}
@Override
public void onBackPressed() {
if(!Flow.get(this).goBack()) {
super.onBackPressed();
}
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flow-sample-basic/src/main/java/flowless/sample/basic/HelloView.java | flow-sample-basic/src/main/java/flowless/sample/basic/HelloView.java | /*
* Copyright 2016 Square Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package flowless.sample.basic;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import flowless.Flow;
public final class HelloView
extends LinearLayout {
public HelloView(Context context, AttributeSet attrs) {
super(context, attrs);
setOrientation(VERTICAL);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
HelloScreen screen = Flow.getKey(this);
((TextView) findViewById(R.id.hello_name)).setText("Hello " + screen.name);
final TextView counter = (TextView) findViewById(R.id.hello_counter);
findViewById(R.id.hello_increment).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String text = counter.getText().toString();
if(text.isEmpty()) {
text = "0";
}
Integer current = Integer.valueOf(text);
counter.setText(String.valueOf(current + 1));
}
});
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flow-sample-basic/src/main/java/flowless/sample/basic/WelcomeView.java | flow-sample-basic/src/main/java/flowless/sample/basic/WelcomeView.java | /*
* Copyright 2016 Square Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package flowless.sample.basic;
import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import flowless.Flow;
public final class WelcomeView
extends LinearLayout {
public WelcomeView(Context context, AttributeSet attrs) {
super(context, attrs);
setOrientation(VERTICAL);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
EditText nameView = (EditText) findViewById(R.id.welcome_screen_name);
nameView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
Flow.get(view).set(new HelloScreen(view.getText().toString()));
return true;
}
});
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flow-sample-basic/src/main/java/flowless/sample/basic/WelcomeScreen.java | flow-sample-basic/src/main/java/flowless/sample/basic/WelcomeScreen.java | /*
* Copyright 2016 Square Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package flowless.sample.basic;
import android.os.Parcel;
import android.os.Parcelable;
final class WelcomeScreen
implements Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<WelcomeScreen> CREATOR = new Creator<WelcomeScreen>() {
@Override
public WelcomeScreen createFromParcel(Parcel in) {
return new WelcomeScreen();
}
@Override
public WelcomeScreen[] newArray(int size) {
return new WelcomeScreen[size];
}
};
@Override
public boolean equals(Object o) {
return o != null && o instanceof WelcomeScreen;
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/test/java/com/zhuinden/flow_alpha_master_detail/ExampleUnitTest.java | flowless-sample-master-detail/src/test/java/com/zhuinden/flow_alpha_master_detail/ExampleUnitTest.java | package com.zhuinden.flow_alpha_master_detail;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect()
throws Exception {
assertEquals(4, 2 + 2);
}
} | java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/IsMaster.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/IsMaster.java | package com.zhuinden.flow_alpha_master_detail;
/**
* Created by Zhuinden on 2016.04.16..
*/
public interface IsMaster {
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/MainActivity.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/MainActivity.java | package com.zhuinden.flow_alpha_master_detail;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.view.ViewGroup;
import com.zhuinden.flow_alpha_master_detail.paths.FirstKey;
import butterknife.BindView;
import butterknife.ButterKnife;
import flowless.Flow;
import flowless.preset.ContainerRootDispatcher;
public class MainActivity
extends AppCompatActivity {
@BindView(R.id.main_root)
ViewGroup root;
ContainerRootDispatcher flowDispatcher;
@Override
protected void attachBaseContext(Context newBase) {
flowDispatcher = new ContainerRootDispatcher();
newBase = Flow.configure(newBase, this) //
.defaultKey(FirstKey.create()) //
.dispatcher(flowDispatcher) //
.install(); //
flowDispatcher.setBaseContext(this);
super.attachBaseContext(newBase);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
flowDispatcher.getRootHolder().setRoot((ViewGroup)root.getChildAt(0));
}
@Override
public void onBackPressed() {
boolean didGoBack = flowDispatcher.onBackPressed();
if(didGoBack) {
return;
}
super.onBackPressed();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
flowDispatcher.preSaveViewState();
super.onSaveInstanceState(outState);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
flowDispatcher.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
flowDispatcher.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/IsFullScreen.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/IsFullScreen.java | package com.zhuinden.flow_alpha_master_detail;
/**
* Created by Zhuinden on 2016.04.16..
*/
public interface IsFullScreen {
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/MasterDetailContainer.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/MasterDetailContainer.java | package com.zhuinden.flow_alpha_master_detail;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import com.zhuinden.flow_alpha_master_detail.extracted.LayoutKey;
import butterknife.BindView;
import butterknife.ButterKnife;
import flowless.Dispatcher;
import flowless.ForceBundler;
import flowless.Traversal;
import flowless.TraversalCallback;
import flowless.preset.DispatcherUtils;
import flowless.preset.FlowContainerLifecycleListener;
import flowless.preset.FlowLifecycleProvider;
/**
* Created by Zhuinden on 2016.04.16..
*/
public class MasterDetailContainer
extends LinearLayout
implements Dispatcher, FlowContainerLifecycleListener {
public MasterDetailContainer(Context context) {
super(context);
init();
}
public MasterDetailContainer(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public MasterDetailContainer(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
@TargetApi(21)
public MasterDetailContainer(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
private void init() {
}
@BindView(R.id.master_container)
SinglePaneContainer masterContainer;
@BindView(R.id.detail_container)
SinglePaneContainer detailContainer;
@Override
protected void onFinishInflate() {
super.onFinishInflate();
ButterKnife.bind(this);
}
@Override
public void dispatch(@NonNull Traversal traversal, @NonNull TraversalCallback callback) {
if(DispatcherUtils.isPreviousKeySameAsNewKey(traversal.origin, traversal.destination)) { //short circuit on same key
callback.onTraversalCompleted();
return;
}
final LayoutKey newKey = DispatcherUtils.getNewKey(traversal);
final LayoutKey previousKey = DispatcherUtils.getPreviousKey(traversal);
final View newView = com.zhuinden.flow_alpha_master_detail.extracted.DispatcherUtils.createViewFromKey(traversal, newKey, this, ((ContextWrapper)getContext()).getBaseContext());
DispatcherUtils.restoreViewFromState(traversal, newView);
// TODO: animations
if(newKey instanceof IsFullScreen) {
persistMaster(traversal);
persistDetail(traversal);
masterContainer.removeAllViews();
masterContainer.setVisibility(GONE);
detailContainer.removeAllViews();
detailContainer.setVisibility(GONE);
addView(newView, 0);
} else {
if(getChildCount() > 0 && !(getChildAt(0) instanceof SinglePaneContainer)) {
View view = getChildAt(0);
DispatcherUtils.persistViewToStateAndNotifyRemoval(traversal, view);
com.zhuinden.flow_alpha_master_detail.extracted.DispatcherUtils.removeViewFromGroup(view, this);
}
masterContainer.setVisibility(VISIBLE);
detailContainer.setVisibility(VISIBLE);
if(newKey instanceof IsDetail) {
persistDetail(traversal);
detailContainer.removeAllViews();
detailContainer.addView(newView);
if(masterContainer.getChildCount() <= 0) {
final View restoredMasterView = com.zhuinden.flow_alpha_master_detail.extracted.DispatcherUtils.createViewFromKey(traversal, (LayoutKey)(((IsDetail) newKey).getMaster()), masterContainer, ((ContextWrapper)getContext()).getBaseContext());
DispatcherUtils.restoreViewFromState(traversal, restoredMasterView);
masterContainer.addView(restoredMasterView);
}
} else if(newKey instanceof IsMaster) {
persistMaster(traversal);
persistDetail(traversal);
masterContainer.removeAllViews();
detailContainer.removeAllViews();
masterContainer.addView(newView);
}
}
callback.onTraversalCompleted();
}
private void persistDetail(@NonNull Traversal traversal) {
if(detailContainer.getChildCount() > 0) {
DispatcherUtils.persistViewToStateAndNotifyRemoval(traversal, detailContainer.getChildAt(0));
}
}
private void persistMaster(@NonNull Traversal traversal) {
if(masterContainer.getChildCount() > 0) {
DispatcherUtils.persistViewToStateAndNotifyRemoval(traversal, masterContainer.getChildAt(0));
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(masterContainer.getChildCount() > 0) {
masterContainer.onActivityResult(requestCode, resultCode, data);
}
if(detailContainer.getChildCount() > 0) {
detailContainer.onActivityResult(requestCode, resultCode, data);
}
if(getChildCount() > 0 && !(getChildAt(0) instanceof SinglePaneContainer)) {
FlowLifecycleProvider.onActivityResult(getChildAt(0), requestCode, resultCode, data);
}
}
@Override
public boolean onBackPressed() {
boolean didHandle = false;
if(detailContainer.getChildCount() > 0) {
didHandle = detailContainer.onBackPressed();
}
if(didHandle) {
return true;
}
if(masterContainer.getChildCount() > 0) {
didHandle = masterContainer.onBackPressed();
}
if(didHandle) {
return true;
}
if(getChildCount() > 0 && !(getChildAt(0) instanceof SinglePaneContainer)) {
didHandle = FlowLifecycleProvider.onBackPressed(getChildAt(0));
}
return didHandle;
}
@Override
public void onCreate(Bundle bundle) {
if(masterContainer.getChildCount() > 0) {
masterContainer.onCreate(bundle);
}
if(detailContainer.getChildCount() > 0) {
detailContainer.onCreate(bundle);
}
if(getChildCount() > 0 && !(getChildAt(0) instanceof SinglePaneContainer)) {
FlowLifecycleProvider.onCreate(getChildAt(0), bundle);
}
}
@Override
public void onDestroy() {
if(masterContainer.getChildCount() > 0) {
masterContainer.onDestroy();
}
if(detailContainer.getChildCount() > 0) {
detailContainer.onDestroy();
}
if(getChildCount() > 0 && !(getChildAt(0) instanceof SinglePaneContainer)) {
FlowLifecycleProvider.onDestroy(getChildAt(0));
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if(masterContainer.getChildCount() > 0) {
masterContainer.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
if(detailContainer.getChildCount() > 0) {
detailContainer.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
if(getChildCount() > 0 && !(getChildAt(0) instanceof SinglePaneContainer)) {
FlowLifecycleProvider.onRequestPermissionsResult(getChildAt(0), requestCode, permissions, grantResults);
}
}
@Override
public void onResume() {
if(masterContainer.getChildCount() > 0) {
masterContainer.onResume();
}
if(detailContainer.getChildCount() > 0) {
detailContainer.onResume();
}
if(getChildCount() > 0 && !(getChildAt(0) instanceof SinglePaneContainer)) {
FlowLifecycleProvider.onResume(getChildAt(0));
}
}
@Override
public void onPause() {
if(masterContainer.getChildCount() > 0) {
masterContainer.onPause();
}
if(detailContainer.getChildCount() > 0) {
detailContainer.onPause();
}
if(getChildCount() > 0 && !(getChildAt(0) instanceof SinglePaneContainer)) {
FlowLifecycleProvider.onPause(getChildAt(0));
}
}
@Override
public void onStart() {
if(masterContainer.getChildCount() > 0) {
masterContainer.onStart();
}
if(detailContainer.getChildCount() > 0) {
detailContainer.onStart();
}
if(getChildCount() > 0 && !(getChildAt(0) instanceof SinglePaneContainer)) {
FlowLifecycleProvider.onStart(getChildAt(0));
}
}
@Override
public void onStop() {
if(masterContainer.getChildCount() > 0) {
masterContainer.onStop();
}
if(detailContainer.getChildCount() > 0) {
detailContainer.onStop();
}
if(getChildCount() > 0 && !(getChildAt(0) instanceof SinglePaneContainer)) {
FlowLifecycleProvider.onStop(getChildAt(0));
}
}
@Override
public void onViewRestored() {
if(masterContainer.getChildCount() > 0) {
masterContainer.onViewRestored();
}
if(detailContainer.getChildCount() > 0) {
detailContainer.onViewRestored();
}
if(getChildCount() > 0 && !(getChildAt(0) instanceof SinglePaneContainer)) {
FlowLifecycleProvider.onViewRestored(getChildAt(0));
}
}
@Override
public void onViewDestroyed(boolean removedByFlow) {
if(masterContainer.getChildCount() > 0) {
masterContainer.onViewDestroyed(removedByFlow);
}
if(detailContainer.getChildCount() > 0) {
detailContainer.onViewDestroyed(removedByFlow);
}
if(getChildCount() > 0 && !(getChildAt(0) instanceof SinglePaneContainer)) {
FlowLifecycleProvider.onViewDestroyed(getChildAt(0), removedByFlow);
}
}
@Override
public void onSaveInstanceState(@Nullable Bundle outState) {
if(masterContainer.getChildCount() > 0) {
masterContainer.onSaveInstanceState(outState);
}
if(detailContainer.getChildCount() > 0) {
detailContainer.onSaveInstanceState(outState);
}
if(getChildCount() > 0 && !(getChildAt(0) instanceof SinglePaneContainer)) {
FlowLifecycleProvider.onSaveInstanceState(getChildAt(0), outState);
ForceBundler.saveToBundle(getChildAt(0));
}
}
@Override
public void preSaveViewState() {
if(masterContainer.getChildCount() > 0) {
masterContainer.preSaveViewState();
}
if(detailContainer.getChildCount() > 0) {
detailContainer.preSaveViewState();
}
if(getChildCount() > 0 && !(getChildAt(0) instanceof SinglePaneContainer)) {
FlowLifecycleProvider.preSaveViewState(getChildAt(0));
}
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/IsDetail.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/IsDetail.java | package com.zhuinden.flow_alpha_master_detail;
/**
* Created by Zhuinden on 2016.04.16..
*/
public interface IsDetail {
IsMaster getMaster();
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/SinglePaneContainer.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/SinglePaneContainer.java | package com.zhuinden.flow_alpha_master_detail;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import com.zhuinden.flow_alpha_master_detail.extracted.ExampleDispatcher;
import flowless.ActivityUtils;
import flowless.Dispatcher;
import flowless.Traversal;
import flowless.TraversalCallback;
import flowless.preset.FlowContainerLifecycleListener;
import flowless.preset.SingleRootDispatcher;
/**
* Created by Zhuinden on 2016.04.16..
*/
public class SinglePaneContainer
extends FrameLayout
implements Dispatcher, FlowContainerLifecycleListener {
public SinglePaneContainer(Context context) {
super(context);
init();
}
public SinglePaneContainer(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public SinglePaneContainer(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
@TargetApi(21)
public SinglePaneContainer(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
SingleRootDispatcher singleRootDispatcher;
private void init() {
singleRootDispatcher = new ExampleDispatcher();
singleRootDispatcher.getRootHolder().setRoot(this);
singleRootDispatcher.setBaseContext(ActivityUtils.getActivity(getContext()));
}
@Override
public void dispatch(@NonNull Traversal traversal, final @NonNull TraversalCallback callback) {
singleRootDispatcher.dispatch(traversal, callback);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
singleRootDispatcher.onActivityResult(requestCode, resultCode, data);
}
@Override
public boolean onBackPressed() {
return singleRootDispatcher.onBackPressed();
}
@Override
public void onCreate(Bundle bundle) {
singleRootDispatcher.onCreate(bundle);
}
@Override
public void onDestroy() {
singleRootDispatcher.onDestroy();
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
singleRootDispatcher.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
@Override
public void onResume() {
singleRootDispatcher.onResume();
}
@Override
public void onPause() {
singleRootDispatcher.onPause();
}
@Override
public void onStart() {
singleRootDispatcher.onStart();
}
@Override
public void onStop() {
singleRootDispatcher.onStop();
}
@Override
public void onViewRestored() {
singleRootDispatcher.onViewRestored();
}
@Override
public void onViewDestroyed(boolean removedByFlow) {
singleRootDispatcher.onViewDestroyed(removedByFlow);
}
@Override
public void preSaveViewState() {
singleRootDispatcher.preSaveViewState();
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
singleRootDispatcher.onSaveInstanceState(outState);
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/extracted/DispatcherUtils.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/extracted/DispatcherUtils.java | package com.zhuinden.flow_alpha_master_detail.extracted;
import android.animation.Animator;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import flowless.Direction;
import flowless.Traversal;
/**
* Created by Zhuinden on 2016.12.03..
*/
public class DispatcherUtils {
public static void removeViewFromGroup(View previousView, ViewGroup root) {
if(previousView != null) {
root.removeView(previousView);
}
}
public static void addViewToGroupForKey(Direction direction, View view, ViewGroup root, LayoutKey animatedKey) {
if(animatedKey.animation() != null && !animatedKey.animation().showChildOnTopWhenAdded(direction)) {
root.addView(view, 0);
} else {
root.addView(view);
}
}
public static Animator createAnimatorForViews(LayoutKey animatedKey, View previousView, View newView, Direction direction) {
if(previousView == null) {
return null;
}
if(animatedKey.animation() != null) {
return animatedKey.animation().createAnimation(previousView, newView, direction);
}
return null;
}
public static View createViewFromKey(Traversal traversal, LayoutKey newKey, ViewGroup root, Context baseContext) {
Context internalContext = DispatcherUtils.createContextForKey(traversal, newKey, baseContext);
LayoutInflater layoutInflater = LayoutInflater.from(internalContext);
final View newView = layoutInflater.inflate(newKey.layout(), root, false);
return newView;
}
public static Context createContextForKey(Traversal traversal, LayoutKey newKey, Context baseContext) {
return traversal.createContext(newKey, baseContext);
}
public static LayoutKey selectAnimatedKey(Direction direction, LayoutKey previousKey, LayoutKey newKey) {
return direction == Direction.BACKWARD ? (previousKey != null ? previousKey : newKey) : newKey;
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/extracted/LayoutKey.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/extracted/LayoutKey.java | package com.zhuinden.flow_alpha_master_detail.extracted;
import android.os.Parcelable;
import android.support.annotation.LayoutRes;
/**
* Created by Zhuinden on 2016.12.03..
*/
public interface LayoutKey
extends Parcelable {
@LayoutRes
int layout();
FlowAnimation animation();
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/extracted/ExampleDispatcher.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/extracted/ExampleDispatcher.java | package com.zhuinden.flow_alpha_master_detail.extracted;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;
import flowless.Direction;
import flowless.Traversal;
import flowless.TraversalCallback;
import flowless.ViewUtils;
import flowless.preset.SingleRootDispatcher;
/**
* Created by Zhuinden on 2016.12.03..
*/
public class ExampleDispatcher extends SingleRootDispatcher {
@Override
public void dispatch(@NonNull Traversal traversal, final @NonNull TraversalCallback callback) {
final ViewGroup root = rootHolder.getRoot();
if(flowless.preset.DispatcherUtils.isPreviousKeySameAsNewKey(traversal.origin, traversal.destination)) { //short circuit on same key
callback.onTraversalCompleted();
onTraversalCompleted();
return;
}
final LayoutKey newKey = flowless.preset.DispatcherUtils.getNewKey(traversal);
final LayoutKey previousKey = flowless.preset.DispatcherUtils.getPreviousKey(traversal);
final Direction direction = traversal.direction;
final View previousView = root.getChildAt(0);
flowless.preset.DispatcherUtils.persistViewToStateAndNotifyRemoval(traversal, previousView);
final View newView = DispatcherUtils.createViewFromKey(traversal, newKey, root, baseContext);
flowless.preset.DispatcherUtils.restoreViewFromState(traversal, newView);
final LayoutKey animatedKey = DispatcherUtils.selectAnimatedKey(direction, previousKey, newKey);
DispatcherUtils.addViewToGroupForKey(direction, newView, root, animatedKey);
configure(previousKey, newKey);
ViewUtils.waitForMeasure(newView, new ViewUtils.OnMeasuredCallback() {
@Override
public void onMeasured(View view, int width, int height) {
Animator animator = DispatcherUtils.createAnimatorForViews(animatedKey, previousView, newView, direction);
if(animator != null) {
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
finishTransition(previousView, root, callback);
}
});
animator.start();
} else {
finishTransition(previousView, root, callback);
}
}
});
}
protected void configure(LayoutKey previousKey, LayoutKey newKey) {
}
private void finishTransition(View previousView, ViewGroup root, @NonNull TraversalCallback callback) {
DispatcherUtils.removeViewFromGroup(previousView, root);
callback.onTraversalCompleted();
onTraversalCompleted();
}
protected void onTraversalCompleted() {
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/extracted/FlowAnimation.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/extracted/FlowAnimation.java | package com.zhuinden.flow_alpha_master_detail.extracted;
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import java.io.Serializable;
import flowless.Direction;
/**
* Created by Zhuinden on 2016.12.03..
*/
public abstract class FlowAnimation
implements Serializable {
public static FlowAnimation NONE = new FlowAnimation() {
@Nullable
@Override
public Animator createAnimation(@NonNull View previousView, @NonNull View newView, Direction direction) {
return null;
}
@Override
public boolean showChildOnTopWhenAdded(Direction direction) {
return true;
}
};
public static FlowAnimation SEGUE = new FlowAnimation() {
@Nullable
@Override
public Animator createAnimation(@NonNull View previousView, @NonNull View newView, Direction direction) {
if(direction == Direction.REPLACE) {
return null;
}
boolean backward = direction == Direction.BACKWARD;
int fromTranslation = backward ? previousView.getWidth() : -previousView.getWidth();
int toTranslation = backward ? -newView.getWidth() : newView.getWidth();
AnimatorSet set = new AnimatorSet();
set.play(ObjectAnimator.ofFloat(previousView, View.TRANSLATION_X, fromTranslation));
set.play(ObjectAnimator.ofFloat(newView, View.TRANSLATION_X, toTranslation, 0));
return set;
}
@Override
public boolean showChildOnTopWhenAdded(Direction direction) {
return true;
}
};
@Nullable
public abstract Animator createAnimation(@NonNull View previousView, @NonNull View newView, Direction direction);
public abstract boolean showChildOnTopWhenAdded(Direction direction);
@Override
public boolean equals(Object object) {
return object instanceof FlowAnimation || this == object;
}
@Override
public int hashCode() {
return FlowAnimation.class.getName().hashCode();
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/FourthMasterKey.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/FourthMasterKey.java | package com.zhuinden.flow_alpha_master_detail.paths;
import com.google.auto.value.AutoValue;
import com.zhuinden.flow_alpha_master_detail.IsMaster;
import com.zhuinden.flow_alpha_master_detail.R;
import com.zhuinden.flow_alpha_master_detail.extracted.FlowAnimation;
import com.zhuinden.flow_alpha_master_detail.extracted.LayoutKey;
/**
* Created by Zhuinden on 2016.04.16..
*/
@AutoValue
public abstract class FourthMasterKey
implements LayoutKey, IsMaster {
public static FourthMasterKey create() {
return new AutoValue_FourthMasterKey(R.layout.path_fourth_master, FlowAnimation.SEGUE);
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/SecondDetailView.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/SecondDetailView.java | package com.zhuinden.flow_alpha_master_detail.paths;
import android.annotation.TargetApi;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import com.zhuinden.flow_alpha_master_detail.R;
import flowless.Flow;
/**
* Created by Zhuinden on 2016.04.16..
*/
public class SecondDetailView
extends LinearLayout {
public SecondDetailView(Context context) {
super(context);
}
public SecondDetailView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SecondDetailView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(21)
public SecondDetailView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
findViewById(R.id.second_detail_button_full_screen).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Flow.get(v).set(ThirdFullScreenKey.create());
}
});
findViewById(R.id.second_detail_button_detail).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Flow.get(v).set(SecondDetailSecondKey.create());
}
});
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/SecondDetailThirdKey.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/SecondDetailThirdKey.java | package com.zhuinden.flow_alpha_master_detail.paths;
import com.google.auto.value.AutoValue;
import com.zhuinden.flow_alpha_master_detail.IsDetail;
import com.zhuinden.flow_alpha_master_detail.IsMaster;
import com.zhuinden.flow_alpha_master_detail.R;
import com.zhuinden.flow_alpha_master_detail.extracted.FlowAnimation;
import com.zhuinden.flow_alpha_master_detail.extracted.LayoutKey;
/**
* Created by Zhuinden on 2016.04.16..
*/
@AutoValue
public abstract class SecondDetailThirdKey
implements LayoutKey, IsDetail {
@Override
public IsMaster getMaster() {
return SecondMasterKey.create();
}
public static SecondDetailThirdKey create() {
return new AutoValue_SecondDetailThirdKey(R.layout.path_second_detail_third, FlowAnimation.SEGUE);
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/FirstKey.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/FirstKey.java | package com.zhuinden.flow_alpha_master_detail.paths;
import com.google.auto.value.AutoValue;
import com.zhuinden.flow_alpha_master_detail.IsFullScreen;
import com.zhuinden.flow_alpha_master_detail.R;
import com.zhuinden.flow_alpha_master_detail.extracted.FlowAnimation;
import com.zhuinden.flow_alpha_master_detail.extracted.LayoutKey;
/**
* Created by Zhuinden on 2016.04.16..
*/
@AutoValue
public abstract class FirstKey
implements LayoutKey, IsFullScreen {
public static FirstKey create() {
return new AutoValue_FirstKey(R.layout.path_first, FlowAnimation.SEGUE);
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/FourthDetailView.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/FourthDetailView.java | package com.zhuinden.flow_alpha_master_detail.paths;
import android.annotation.TargetApi;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import com.zhuinden.flow_alpha_master_detail.R;
import flowless.Flow;
/**
* Created by Zhuinden on 2016.04.16..
*/
public class FourthDetailView
extends LinearLayout {
public FourthDetailView(Context context) {
super(context);
}
public FourthDetailView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FourthDetailView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(21)
public FourthDetailView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
findViewById(R.id.fourth_detail_start_detail).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Flow.get(v).set(FourthDetailSecondKey.create());
}
});
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/SecondDetailThirdView.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/SecondDetailThirdView.java | package com.zhuinden.flow_alpha_master_detail.paths;
import android.annotation.TargetApi;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
/**
* Created by Zhuinden on 2016.04.16..
*/
public class SecondDetailThirdView
extends LinearLayout {
public SecondDetailThirdView(Context context) {
super(context);
}
public SecondDetailThirdView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SecondDetailThirdView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(21)
public SecondDetailThirdView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/FourthDetailSecondKey.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/FourthDetailSecondKey.java | package com.zhuinden.flow_alpha_master_detail.paths;
import com.google.auto.value.AutoValue;
import com.zhuinden.flow_alpha_master_detail.IsDetail;
import com.zhuinden.flow_alpha_master_detail.IsMaster;
import com.zhuinden.flow_alpha_master_detail.R;
import com.zhuinden.flow_alpha_master_detail.extracted.FlowAnimation;
import com.zhuinden.flow_alpha_master_detail.extracted.LayoutKey;
/**
* Created by Zhuinden on 2016.04.16..
*/
@AutoValue
public abstract class FourthDetailSecondKey
implements LayoutKey, IsDetail {
@Override
public IsMaster getMaster() {
return FourthMasterKey.create();
}
public static FourthDetailSecondKey create() {
return new AutoValue_FourthDetailSecondKey(R.layout.path_fourth_detail_second, FlowAnimation.SEGUE);
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/SecondDetailSecondView.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/SecondDetailSecondView.java | package com.zhuinden.flow_alpha_master_detail.paths;
import android.annotation.TargetApi;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import com.zhuinden.flow_alpha_master_detail.R;
import flowless.Flow;
/**
* Created by Zhuinden on 2016.04.16..
*/
public class SecondDetailSecondView
extends LinearLayout {
public SecondDetailSecondView(Context context) {
super(context);
}
public SecondDetailSecondView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SecondDetailSecondView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(21)
public SecondDetailSecondView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
findViewById(R.id.second_detail_second_button).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Flow.get(v).set(SecondDetailThirdKey.create());
}
});
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/ThirdFullScreenKey.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/ThirdFullScreenKey.java | package com.zhuinden.flow_alpha_master_detail.paths;
import com.google.auto.value.AutoValue;
import com.zhuinden.flow_alpha_master_detail.IsFullScreen;
import com.zhuinden.flow_alpha_master_detail.R;
import com.zhuinden.flow_alpha_master_detail.extracted.FlowAnimation;
import com.zhuinden.flow_alpha_master_detail.extracted.LayoutKey;
/**
* Created by Zhuinden on 2016.04.16..
*/
@AutoValue
public abstract class ThirdFullScreenKey
implements LayoutKey, IsFullScreen {
public static ThirdFullScreenKey create() {
return new AutoValue_ThirdFullScreenKey(R.layout.path_third_fullscreen, FlowAnimation.SEGUE);
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/FourthDetailKey.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/FourthDetailKey.java | package com.zhuinden.flow_alpha_master_detail.paths;
import com.google.auto.value.AutoValue;
import com.zhuinden.flow_alpha_master_detail.IsDetail;
import com.zhuinden.flow_alpha_master_detail.IsMaster;
import com.zhuinden.flow_alpha_master_detail.R;
import com.zhuinden.flow_alpha_master_detail.extracted.FlowAnimation;
import com.zhuinden.flow_alpha_master_detail.extracted.LayoutKey;
/**
* Created by Zhuinden on 2016.04.16..
*/
@AutoValue
public abstract class FourthDetailKey
implements LayoutKey, IsDetail {
@Override
public IsMaster getMaster() {
return FourthMasterKey.create();
}
public static FourthDetailKey create() {
return new AutoValue_FourthDetailKey(R.layout.path_fourth_detail, FlowAnimation.SEGUE);
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/SecondDetailSecondKey.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/SecondDetailSecondKey.java | package com.zhuinden.flow_alpha_master_detail.paths;
import com.google.auto.value.AutoValue;
import com.zhuinden.flow_alpha_master_detail.IsDetail;
import com.zhuinden.flow_alpha_master_detail.IsMaster;
import com.zhuinden.flow_alpha_master_detail.R;
import com.zhuinden.flow_alpha_master_detail.extracted.FlowAnimation;
import com.zhuinden.flow_alpha_master_detail.extracted.LayoutKey;
/**
* Created by Zhuinden on 2016.04.16..
*/
@AutoValue
public abstract class SecondDetailSecondKey
implements LayoutKey, IsDetail {
@Override
public IsMaster getMaster() {
return SecondMasterKey.create();
}
public static SecondDetailSecondKey create() {
return new AutoValue_SecondDetailSecondKey(R.layout.path_second_detail_second, FlowAnimation.SEGUE);
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/SecondMasterKey.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/SecondMasterKey.java | package com.zhuinden.flow_alpha_master_detail.paths;
import com.google.auto.value.AutoValue;
import com.zhuinden.flow_alpha_master_detail.IsMaster;
import com.zhuinden.flow_alpha_master_detail.R;
import com.zhuinden.flow_alpha_master_detail.extracted.FlowAnimation;
import com.zhuinden.flow_alpha_master_detail.extracted.LayoutKey;
/**
* Created by Zhuinden on 2016.04.16..
*/
@AutoValue
public abstract class SecondMasterKey
implements LayoutKey, IsMaster {
public static SecondMasterKey create() {
return new AutoValue_SecondMasterKey(R.layout.path_second_master, FlowAnimation.SEGUE);
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/SecondDetailKey.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/SecondDetailKey.java | package com.zhuinden.flow_alpha_master_detail.paths;
import com.google.auto.value.AutoValue;
import com.zhuinden.flow_alpha_master_detail.IsDetail;
import com.zhuinden.flow_alpha_master_detail.IsMaster;
import com.zhuinden.flow_alpha_master_detail.R;
import com.zhuinden.flow_alpha_master_detail.extracted.FlowAnimation;
import com.zhuinden.flow_alpha_master_detail.extracted.LayoutKey;
/**
* Created by Zhuinden on 2016.04.16..
*/
@AutoValue
public abstract class SecondDetailKey
implements LayoutKey, IsDetail {
@Override
public IsMaster getMaster() {
return SecondMasterKey.create();
}
public static SecondDetailKey create() {
return new AutoValue_SecondDetailKey(R.layout.path_second_detail, FlowAnimation.SEGUE);
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/SecondMasterView.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/SecondMasterView.java | package com.zhuinden.flow_alpha_master_detail.paths;
import android.annotation.TargetApi;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import com.zhuinden.flow_alpha_master_detail.R;
import flowless.Flow;
/**
* Created by Zhuinden on 2016.04.16..
*/
public class SecondMasterView
extends LinearLayout {
public SecondMasterView(Context context) {
super(context);
}
public SecondMasterView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SecondMasterView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(21)
public SecondMasterView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
findViewById(R.id.second_master_button).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Flow.get(v).set(SecondDetailKey.create());
}
});
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/FourthMasterView.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/FourthMasterView.java | package com.zhuinden.flow_alpha_master_detail.paths;
import android.annotation.TargetApi;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import com.zhuinden.flow_alpha_master_detail.R;
import flowless.Flow;
/**
* Created by Zhuinden on 2016.04.16..
*/
public class FourthMasterView
extends LinearLayout {
public FourthMasterView(Context context) {
super(context);
}
public FourthMasterView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FourthMasterView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(21)
public FourthMasterView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
findViewById(R.id.fourth_master_start_detail).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Flow.get(v).set(FourthDetailKey.create());
}
});
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/FourthDetailSecondView.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/FourthDetailSecondView.java | package com.zhuinden.flow_alpha_master_detail.paths;
import android.annotation.TargetApi;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
/**
* Created by Zhuinden on 2016.04.16..
*/
public class FourthDetailSecondView
extends LinearLayout {
public FourthDetailSecondView(Context context) {
super(context);
}
public FourthDetailSecondView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FourthDetailSecondView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(21)
public FourthDetailSecondView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/FirstView.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/FirstView.java | package com.zhuinden.flow_alpha_master_detail.paths;
import android.annotation.TargetApi;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import com.zhuinden.flow_alpha_master_detail.R;
import flowless.Flow;
/**
* Created by Zhuinden on 2016.04.16..
*/
public class FirstView
extends LinearLayout {
public FirstView(Context context) {
super(context);
}
public FirstView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FirstView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(21)
public FirstView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
findViewById(R.id.first_button).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Flow.get(v).set(SecondMasterKey.create());
}
});
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/ThirdFullScreenView.java | flowless-sample-master-detail/src/main/java/com/zhuinden/flow_alpha_master_detail/paths/ThirdFullScreenView.java | package com.zhuinden.flow_alpha_master_detail.paths;
import android.annotation.TargetApi;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import com.zhuinden.flow_alpha_master_detail.R;
import flowless.Flow;
/**
* Created by Zhuinden on 2016.04.16..
*/
public class ThirdFullScreenView
extends LinearLayout {
public ThirdFullScreenView(Context context) {
super(context);
}
public ThirdFullScreenView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ThirdFullScreenView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(21)
public ThirdFullScreenView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
findViewById(R.id.third_full_screen_button).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Flow.get(v).set(FourthMasterKey.create());
}
});
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/main/java/com/google/auto/value/AutoValue.java | flowless-sample-master-detail/src/main/java/com/google/auto/value/AutoValue.java | package com.google.auto.value;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface AutoValue {
/**
* Specifies that AutoValue should generate an implementation of the annotated class or interface,
* to serve as a <i>builder</i> for the value-type class it is nested within. As a simple example,
* here is an alternative way to write the {@code Person} class mentioned in the {@link AutoValue}
* example: <pre>
*
* @AutoValue
* abstract class Person {
* static Builder builder() {
* return new AutoValue_Person.Builder();
* }
*
* abstract String name();
* abstract int id();
*
* @AutoValue.Builder
* interface Builder {
* Builder name(String x);
* Builder id(int x);
* Person build();
* }
* }</pre>
*
* @author Éamonn McManus
*/
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface Builder {
}
} | java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-master-detail/src/androidTest/java/com/zhuinden/flow_alpha_master_detail/ApplicationTest.java | flowless-sample-master-detail/src/androidTest/java/com/zhuinden/flow_alpha_master_detail/ApplicationTest.java | package com.zhuinden.flow_alpha_master_detail;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest
extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
} | java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-single-root/src/test/java/com/zhuinden/flowless_dispatcher_sample/ExampleUnitTest.java | flowless-sample-single-root/src/test/java/com/zhuinden/flowless_dispatcher_sample/ExampleUnitTest.java | package com.zhuinden.flowless_dispatcher_sample;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect()
throws Exception {
assertEquals(4, 2 + 2);
}
} | java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-single-root/src/main/java/com/zhuinden/flowless_dispatcher_sample/MainActivity.java | flowless-sample-single-root/src/main/java/com/zhuinden/flowless_dispatcher_sample/MainActivity.java | package com.zhuinden.flowless_dispatcher_sample;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.view.ViewGroup;
import com.zhuinden.flowless_dispatcher_sample.extracted.ExampleDispatcher;
import butterknife.BindView;
import butterknife.ButterKnife;
import flowless.Flow;
import flowless.preset.SingleRootDispatcher;
public class MainActivity
extends AppCompatActivity {
@BindView(R.id.main_root)
ViewGroup root;
SingleRootDispatcher flowDispatcher;
@Override
protected void attachBaseContext(Context newBase) {
flowDispatcher = new ExampleDispatcher();
newBase = Flow.configure(newBase, this) //
.defaultKey(FirstKey.create()) //
.dispatcher(flowDispatcher) //
.install(); //
flowDispatcher.setBaseContext(this);
super.attachBaseContext(newBase);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
flowDispatcher.getRootHolder().setRoot(root);
}
@Override
public void onBackPressed() {
boolean didGoBack = flowDispatcher.onBackPressed();
if(didGoBack) {
return;
}
super.onBackPressed();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
flowDispatcher.preSaveViewState();
super.onSaveInstanceState(outState);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
flowDispatcher.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
flowDispatcher.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-single-root/src/main/java/com/zhuinden/flowless_dispatcher_sample/FirstKey.java | flowless-sample-single-root/src/main/java/com/zhuinden/flowless_dispatcher_sample/FirstKey.java | package com.zhuinden.flowless_dispatcher_sample;
import com.google.auto.value.AutoValue;
import com.zhuinden.flowless_dispatcher_sample.extracted.FlowAnimation;
import com.zhuinden.flowless_dispatcher_sample.extracted.LayoutKey;
/**
* Created by Zhuinden on 2016.06.28..
*/
@AutoValue
public abstract class FirstKey
implements LayoutKey {
public static FirstKey create() {
return new AutoValue_FirstKey(R.layout.path_first, FlowAnimation.NONE);
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-single-root/src/main/java/com/zhuinden/flowless_dispatcher_sample/SecondKey.java | flowless-sample-single-root/src/main/java/com/zhuinden/flowless_dispatcher_sample/SecondKey.java | package com.zhuinden.flowless_dispatcher_sample;
import com.google.auto.value.AutoValue;
import com.zhuinden.flowless_dispatcher_sample.extracted.FlowAnimation;
import com.zhuinden.flowless_dispatcher_sample.extracted.LayoutKey;
/**
* Created by Zhuinden on 2016.06.28..
*/
@AutoValue
public abstract class SecondKey
implements LayoutKey {
public static SecondKey create() {
return new AutoValue_SecondKey(R.layout.path_second, FlowAnimation.SEGUE);
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-single-root/src/main/java/com/zhuinden/flowless_dispatcher_sample/SecondView.java | flowless-sample-single-root/src/main/java/com/zhuinden/flowless_dispatcher_sample/SecondView.java | package com.zhuinden.flowless_dispatcher_sample;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.RelativeLayout;
import butterknife.ButterKnife;
import flowless.Bundleable;
import flowless.Flow;
import flowless.preset.SingleRootDispatcher;
/**
* Created by Zhuinden on 2016.06.28..
*/
public class SecondView
extends RelativeLayout
implements Bundleable, SingleRootDispatcher.ViewLifecycleListener {
private static final String TAG = "SecondView";
public SecondView(Context context) {
super(context);
init();
}
public SecondView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public SecondView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
@TargetApi(21)
public SecondView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
SecondKey secondKey;
private void init() {
if(!isInEditMode()) {
secondKey = Flow.getKey(this);
Log.i(TAG, "init()");
}
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
Log.i(TAG, "onFinishInflate()");
ButterKnife.bind(this);
}
@Override
public Bundle toBundle() {
Log.i(TAG, "toBundle()");
Bundle bundle = new Bundle();
bundle.putString("blah", "BLEHHH");
return bundle;
}
@Override
public void fromBundle(@Nullable Bundle bundle) {
Log.i(TAG, "fromBundle()");
if(bundle != null) {
Log.i(TAG, "fromBundle() with bundle: [" + bundle.getString("blah") + "]");
}
}
@Override
public void onViewRestored() {
Log.i(TAG, "onViewRestored()");
}
@Override
public void onViewDestroyed(boolean removedByFlow) {
Log.i(TAG, "onViewDestroyed(" + removedByFlow + ")");
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-single-root/src/main/java/com/zhuinden/flowless_dispatcher_sample/FirstView.java | flowless-sample-single-root/src/main/java/com/zhuinden/flowless_dispatcher_sample/FirstView.java | package com.zhuinden.flowless_dispatcher_sample;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;
import butterknife.ButterKnife;
import butterknife.OnClick;
import flowless.Bundleable;
import flowless.Flow;
import flowless.preset.SingleRootDispatcher;
/**
* Created by Zhuinden on 2016.06.28..
*/
public class FirstView
extends RelativeLayout
implements Bundleable, SingleRootDispatcher.ViewLifecycleListener {
private static final String TAG = "FirstView";
public FirstView(Context context) {
super(context);
init();
}
public FirstView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public FirstView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
@TargetApi(21)
public FirstView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
FirstKey firstKey;
public void init() {
if(!isInEditMode()) {
firstKey = Flow.getKey(this);
Log.i(TAG, "init()");
}
}
@OnClick(R.id.first_button)
public void firstButtonClick(View view) {
Flow.get(view).set(SecondKey.create());
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
Log.i(TAG, "onFinishInflate()");
ButterKnife.bind(this);
}
@Override
public Bundle toBundle() {
Log.i(TAG, "toBundle()");
Bundle bundle = new Bundle();
bundle.putString("blah", "BLAH");
return bundle;
}
@Override
public void fromBundle(@Nullable Bundle bundle) {
Log.i(TAG, "fromBundle()");
if(bundle != null) {
Log.i(TAG, "fromBundle() with bundle: [" + bundle.getString("blah") + "]");
}
}
@Override
public void onViewRestored() {
Log.i(TAG, "onViewRestored()");
}
@Override
public void onViewDestroyed(boolean removedByFlow) {
Log.i(TAG, "onViewDestroyed(" + removedByFlow + ")");
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-single-root/src/main/java/com/zhuinden/flowless_dispatcher_sample/extracted/DispatcherUtils.java | flowless-sample-single-root/src/main/java/com/zhuinden/flowless_dispatcher_sample/extracted/DispatcherUtils.java | package com.zhuinden.flowless_dispatcher_sample.extracted;
import android.animation.Animator;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import flowless.Direction;
import flowless.Traversal;
/**
* Created by Zhuinden on 2016.12.03..
*/
class DispatcherUtils {
public static void addViewToGroupForKey(Direction direction, View view, ViewGroup root, LayoutKey animatedKey) {
if(animatedKey.animation() != null && !animatedKey.animation().showChildOnTopWhenAdded(direction)) {
root.addView(view, 0);
} else {
root.addView(view);
}
}
public static Animator createAnimatorForViews(LayoutKey animatedKey, View previousView, View newView, Direction direction) {
if(previousView == null) {
return null;
}
if(animatedKey.animation() != null) {
return animatedKey.animation().createAnimation(previousView, newView, direction);
}
return null;
}
public static View createViewFromKey(Traversal traversal, LayoutKey newKey, ViewGroup root, Context baseContext) {
Context internalContext = DispatcherUtils.createContextForKey(traversal, newKey, baseContext);
LayoutInflater layoutInflater = LayoutInflater.from(internalContext);
final View newView = layoutInflater.inflate(newKey.layout(), root, false);
return newView;
}
public static Context createContextForKey(Traversal traversal, LayoutKey newKey, Context baseContext) {
return traversal.createContext(newKey, baseContext);
}
public static LayoutKey selectAnimatedKey(Direction direction, LayoutKey previousKey, LayoutKey newKey) {
return direction == Direction.BACKWARD ? (previousKey != null ? previousKey : newKey) : newKey;
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-single-root/src/main/java/com/zhuinden/flowless_dispatcher_sample/extracted/LayoutKey.java | flowless-sample-single-root/src/main/java/com/zhuinden/flowless_dispatcher_sample/extracted/LayoutKey.java | package com.zhuinden.flowless_dispatcher_sample.extracted;
import android.os.Parcelable;
import android.support.annotation.LayoutRes;
/**
* Created by Zhuinden on 2016.06.27..
*/
public interface LayoutKey
extends Parcelable {
@LayoutRes
int layout();
FlowAnimation animation();
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-single-root/src/main/java/com/zhuinden/flowless_dispatcher_sample/extracted/ExampleDispatcher.java | flowless-sample-single-root/src/main/java/com/zhuinden/flowless_dispatcher_sample/extracted/ExampleDispatcher.java | package com.zhuinden.flowless_dispatcher_sample.extracted;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;
import flowless.Direction;
import flowless.Traversal;
import flowless.TraversalCallback;
import flowless.ViewUtils;
import flowless.preset.SingleRootDispatcher;
/**
* Created by Zhuinden on 2016.12.03..
*/
public class ExampleDispatcher extends SingleRootDispatcher {
@Override
public void dispatch(@NonNull Traversal traversal, final @NonNull TraversalCallback callback) {
final ViewGroup root = rootHolder.getRoot();
if(flowless.preset.DispatcherUtils.isPreviousKeySameAsNewKey(traversal.origin, traversal.destination)) { //short circuit on same key
callback.onTraversalCompleted();
onTraversalCompleted();
return;
}
final LayoutKey newKey = flowless.preset.DispatcherUtils.getNewKey(traversal);
final LayoutKey previousKey = flowless.preset.DispatcherUtils.getPreviousKey(traversal);
final Direction direction = traversal.direction;
final View previousView = root.getChildAt(0);
flowless.preset.DispatcherUtils.persistViewToStateAndNotifyRemoval(traversal, previousView);
final View newView = DispatcherUtils.createViewFromKey(traversal, newKey, root, baseContext);
flowless.preset.DispatcherUtils.restoreViewFromState(traversal, newView);
final LayoutKey animatedKey = DispatcherUtils.selectAnimatedKey(direction, previousKey, newKey);
DispatcherUtils.addViewToGroupForKey(direction, newView, root, animatedKey);
configure(previousKey, newKey);
ViewUtils.waitForMeasure(newView, new ViewUtils.OnMeasuredCallback() {
@Override
public void onMeasured(View view, int width, int height) {
Animator animator = DispatcherUtils.createAnimatorForViews(animatedKey, previousView, newView, direction);
if(animator != null) {
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
finishTransition(previousView, root, callback);
}
});
animator.start();
} else {
finishTransition(previousView, root, callback);
}
}
});
}
protected void configure(LayoutKey previousKey, LayoutKey newKey) {
}
private void finishTransition(View previousView, ViewGroup root, @NonNull TraversalCallback callback) {
if(previousView != null) {
root.removeView(previousView);
}
callback.onTraversalCompleted();
onTraversalCompleted();
}
protected void onTraversalCompleted() {
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-single-root/src/main/java/com/zhuinden/flowless_dispatcher_sample/extracted/FlowAnimation.java | flowless-sample-single-root/src/main/java/com/zhuinden/flowless_dispatcher_sample/extracted/FlowAnimation.java | package com.zhuinden.flowless_dispatcher_sample.extracted;
/**
* Created by Zhuinden on 2016.12.03..
*/
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import java.io.Serializable;
import flowless.Direction;
/**
* Created by Zhuinden on 2016.06.27..
*/
public abstract class FlowAnimation
implements Serializable {
public static FlowAnimation NONE = new FlowAnimation() {
@Nullable
@Override
public Animator createAnimation(@NonNull View previousView, @NonNull View newView, Direction direction) {
return null;
}
@Override
public boolean showChildOnTopWhenAdded(Direction direction) {
return true;
}
};
public static FlowAnimation SEGUE = new FlowAnimation() {
@Nullable
@Override
public Animator createAnimation(@NonNull View previousView, @NonNull View newView, Direction direction) {
if(direction == Direction.REPLACE) {
return null;
}
boolean backward = direction == Direction.BACKWARD;
int fromTranslation = backward ? previousView.getWidth() : -previousView.getWidth();
int toTranslation = backward ? -newView.getWidth() : newView.getWidth();
AnimatorSet set = new AnimatorSet();
set.play(ObjectAnimator.ofFloat(previousView, View.TRANSLATION_X, fromTranslation));
set.play(ObjectAnimator.ofFloat(newView, View.TRANSLATION_X, toTranslation, 0));
return set;
}
@Override
public boolean showChildOnTopWhenAdded(Direction direction) {
return true;
}
};
@Nullable
public abstract Animator createAnimation(@NonNull View previousView, @NonNull View newView, Direction direction);
public abstract boolean showChildOnTopWhenAdded(Direction direction);
@Override
public boolean equals(Object object) {
return object instanceof FlowAnimation || this == object;
}
@Override
public int hashCode() {
return FlowAnimation.class.getName().hashCode();
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-single-root/src/main/java/com/google/auto/value/AutoValue.java | flowless-sample-single-root/src/main/java/com/google/auto/value/AutoValue.java | package com.google.auto.value;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface AutoValue {
/**
* Specifies that AutoValue should generate an implementation of the annotated class or interface,
* to serve as a <i>builder</i> for the value-type class it is nested within. As a simple example,
* here is an alternative way to write the {@code Person} class mentioned in the {@link AutoValue}
* example: <pre>
*
* @AutoValue
* abstract class Person {
* static Builder builder() {
* return new AutoValue_Person.Builder();
* }
*
* abstract String name();
* abstract int id();
*
* @AutoValue.Builder
* interface Builder {
* Builder name(String x);
* Builder id(int x);
* Person build();
* }
* }</pre>
*
* @author Éamonn McManus
*/
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface Builder {
}
} | java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-sample-single-root/src/androidTest/java/com/zhuinden/flowless_dispatcher_sample/ApplicationTest.java | flowless-sample-single-root/src/androidTest/java/com/zhuinden/flowless_dispatcher_sample/ApplicationTest.java | package com.zhuinden.flowless_dispatcher_sample;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest
extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
} | java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/test/java/com/zhuinden/examplegithubclient/UnitTestSuite.java | flowless-mvp-example/src/test/java/com/zhuinden/examplegithubclient/UnitTestSuite.java | package com.zhuinden.examplegithubclient;
import com.zhuinden.examplegithubclient.presentation.paths.login.LoginTestSuite;
import com.zhuinden.examplegithubclient.presentation.paths.repositories.RepositoriesTestSuite;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
/**
* Created by Zhuinden on 2016.12.19..
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({LoginTestSuite.class, RepositoriesTestSuite.class})
public class UnitTestSuite {
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/test/java/com/zhuinden/examplegithubclient/util/BundleFactoryConfig.java | flowless-mvp-example/src/test/java/com/zhuinden/examplegithubclient/util/BundleFactoryConfig.java | package com.zhuinden.examplegithubclient.util;
/**
* Created by Zhuinden on 2016.12.20..
*/
public class BundleFactoryConfig {
public static void setProvider(BundleFactory.Provider provider) {
BundleFactory.provider = provider;
}
} | java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/test/java/com/zhuinden/examplegithubclient/util/PresenterUtils.java | flowless-mvp-example/src/test/java/com/zhuinden/examplegithubclient/util/PresenterUtils.java | package com.zhuinden.examplegithubclient.util;
/**
* Created by Zhuinden on 2016.12.21..
*/
public class PresenterUtils {
public static <P extends BasePresenter<V>, V extends BasePresenter.ViewContract> void setView(P presenter, V viewContract) {
presenter.view = viewContract;
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/test/java/com/zhuinden/examplegithubclient/presentation/paths/login/LoginTestSuite.java | flowless-mvp-example/src/test/java/com/zhuinden/examplegithubclient/presentation/paths/login/LoginTestSuite.java | package com.zhuinden.examplegithubclient.presentation.paths.login;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
/**
* Created by Zhuinden on 2016.12.21..
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({LoginPresenterTest.class, LoginKeyTest.class})
public class LoginTestSuite {
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/test/java/com/zhuinden/examplegithubclient/presentation/paths/login/LoginKeyTest.java | flowless-mvp-example/src/test/java/com/zhuinden/examplegithubclient/presentation/paths/login/LoginKeyTest.java | package com.zhuinden.examplegithubclient.presentation.paths.login;
import android.os.Parcelable;
import com.zhuinden.examplegithubclient.R;
import com.zhuinden.examplegithubclient.util.ComponentFactory;
import com.zhuinden.examplegithubclient.util.Layout;
import com.zhuinden.examplegithubclient.util.LeftDrawerEnabled;
import com.zhuinden.examplegithubclient.util.Title;
import com.zhuinden.examplegithubclient.util.ToolbarButtonVisibility;
import org.junit.Test;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Created by Zhuinden on 2016.12.20..
*/
public class LoginKeyTest {
private <T> T getValueFromAnnotation(Class<?> annotationClass, Annotation annotation)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
return (T) annotationClass.getMethod("value").invoke(annotation);
}
@Test
public void hasAnnotationTitle()
throws Exception {
assertThat(LoginKey.class.getAnnotation(Title.class)).isNotNull();
assertThat((int) getValueFromAnnotation(Title.class, LoginKey.class.getAnnotation(Title.class))).isEqualTo(R.string.title_login);
}
@Test
public void hasAnnotationLayout()
throws Exception {
assertThat(LoginKey.class.getAnnotation(Layout.class)).isNotNull();
assertThat((int) getValueFromAnnotation(Layout.class, LoginKey.class.getAnnotation(Layout.class))).isEqualTo(R.layout.path_login);
}
@Test
public void hasAnnotationComponentFactory()
throws Exception {
assertThat(LoginKey.class.getAnnotation(ComponentFactory.class)).isNotNull();
assertThat((Class) getValueFromAnnotation(ComponentFactory.class, LoginKey.class.getAnnotation(ComponentFactory.class))).isEqualTo(
LoginComponentFactory.class);
}
@Test
public void hasAnnotationLeftDrawerEnabled()
throws Exception {
assertThat(LoginKey.class.getAnnotation(LeftDrawerEnabled.class)).isNotNull();
assertThat((Boolean) getValueFromAnnotation(LeftDrawerEnabled.class,
LoginKey.class.getAnnotation(LeftDrawerEnabled.class))).isEqualTo(false);
}
@Test
public void hasAnnotationToolbarButtonVisibility()
throws Exception {
assertThat(LoginKey.class.getAnnotation(ToolbarButtonVisibility.class)).isNotNull();
assertThat((Boolean) getValueFromAnnotation(ToolbarButtonVisibility.class,
LoginKey.class.getAnnotation(ToolbarButtonVisibility.class))).isEqualTo(false);
}
@Test
public void create()
throws Exception {
// when
LoginKey loginKey = LoginKey.create();
// then
assertThat(loginKey).isInstanceOf(Parcelable.class);
assertThat(loginKey).isInstanceOf(AutoValue_LoginKey.class);
}
} | java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/test/java/com/zhuinden/examplegithubclient/presentation/paths/login/LoginPresenterTest.java | flowless-mvp-example/src/test/java/com/zhuinden/examplegithubclient/presentation/paths/login/LoginPresenterTest.java | package com.zhuinden.examplegithubclient.presentation.paths.login;
import android.os.Bundle;
import com.zhuinden.examplegithubclient.domain.interactor.LoginInteractor;
import com.zhuinden.examplegithubclient.util.BundleFactory;
import com.zhuinden.examplegithubclient.util.BundleFactoryConfig;
import com.zhuinden.examplegithubclient.util.PresenterUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import io.reactivex.Single;
import io.reactivex.android.plugins.RxAndroidPlugins;
import io.reactivex.schedulers.Schedulers;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Created by Zhuinden on 2016.12.19..
*/
public class LoginPresenterTest {
LoginPresenter loginPresenter;
@Rule
public MockitoRule mockitoRule = MockitoJUnit.rule();
@Mock
LoginPresenter.ViewContract viewContract;
@Mock
LoginInteractor loginInteractor;
@Before
public void init() {
loginPresenter = new LoginPresenter();
// BoltsConfig.configureMocks();
BundleFactoryConfig.setProvider(() -> Mockito.mock(Bundle.class));
RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerCallable -> Schedulers.trampoline());
}
@Test
public void initializeViewWhileLoading()
throws Exception {
// given
loginPresenter.username = "Hello";
loginPresenter.password = "World";
LoginPresenter.isLoading = true;
// when
loginPresenter.attachView(viewContract);
// then
Mockito.verify(viewContract).setUsername("Hello");
Mockito.verify(viewContract).setPassword("World");
Mockito.verify(viewContract).showLoading();
}
@Test
public void initializeViewWhileNotLoading()
throws Exception {
// given
loginPresenter.username = "Hello";
loginPresenter.password = "World";
LoginPresenter.isLoading = false;
// when
loginPresenter.attachView(viewContract);
// then
Mockito.verify(viewContract).setUsername("Hello");
Mockito.verify(viewContract).setPassword("World");
Mockito.verify(viewContract).hideLoading();
}
@Test
public void updateUsername()
throws Exception {
// given
loginPresenter.username = "";
// when
loginPresenter.updateUsername("Hello");
// then
assertThat(loginPresenter.username).isEqualTo("Hello");
}
@Test
public void updatePassword()
throws Exception {
// given
loginPresenter.password = "";
// when
loginPresenter.updatePassword("World");
// then
assertThat(loginPresenter.password).isEqualTo("World");
}
@Test
public void loginCallsInteractor()
throws Exception {
// given
loginPresenter.username = "Hello";
loginPresenter.password = "World";
loginPresenter.loginInteractor = loginInteractor;
PresenterUtils.setView(loginPresenter, viewContract);
Single<Boolean> task = Mockito.mock(Single.class);
Mockito.when(loginInteractor.login("Hello", "World")).thenReturn(task);
// when
loginPresenter.login();
// then
Mockito.verify(loginInteractor).login("Hello", "World");
}
@Test
public void loginSuccess()
throws Exception {
// given
loginPresenter.username = "Hello";
loginPresenter.password = "World";
loginPresenter.loginInteractor = (username, password) -> Single.just(true);
PresenterUtils.setView(loginPresenter, viewContract);
// when
loginPresenter.login();
// then
Mockito.verify(viewContract).showLoading();
Mockito.verify(viewContract, Mockito.atLeastOnce()).hideLoading();
Mockito.verify(viewContract).handleLoginSuccess();
}
@Test
public void loginFailure()
throws Exception {
// given
loginPresenter.username = "Hello";
loginPresenter.password = "World";
loginPresenter.loginInteractor = (username, password) -> Single.just(false);
PresenterUtils.setView(loginPresenter, viewContract);
// when
loginPresenter.login();
// then
Mockito.verify(viewContract).showLoading();
Mockito.verify(viewContract).hideLoading();
Mockito.verify(viewContract).handleLoginError();
}
@Test
public void toBundle()
throws Exception {
// given
loginPresenter.username = "Hello";
loginPresenter.password = "World";
// when
Bundle bundle = loginPresenter.toBundle();
// then
Mockito.verify(bundle).putString("username", "Hello");
Mockito.verify(bundle).putString("password", "World");
Mockito.verifyNoMoreInteractions(bundle);
}
@Test
public void fromBundle()
throws Exception {
// given
loginPresenter.username = "";
loginPresenter.password = "";
Bundle bundle = BundleFactory.create();
Mockito.when(bundle.getString("username")).thenReturn("Hello");
Mockito.when(bundle.getString("password")).thenReturn("World");
// when
loginPresenter.fromBundle(bundle);
// then
assertThat(loginPresenter.username).isEqualTo("Hello");
assertThat(loginPresenter.password).isEqualTo("World");
}
} | java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/test/java/com/zhuinden/examplegithubclient/presentation/paths/repositories/RepositoriesTestSuite.java | flowless-mvp-example/src/test/java/com/zhuinden/examplegithubclient/presentation/paths/repositories/RepositoriesTestSuite.java | package com.zhuinden.examplegithubclient.presentation.paths.repositories;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
/**
* Created by Zhuinden on 2016.12.21..
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({RepositoriesPresenterTest.class})
public class RepositoriesTestSuite {
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/test/java/com/zhuinden/examplegithubclient/presentation/paths/repositories/RepositoriesPresenterTest.java | flowless-mvp-example/src/test/java/com/zhuinden/examplegithubclient/presentation/paths/repositories/RepositoriesPresenterTest.java | package com.zhuinden.examplegithubclient.presentation.paths.repositories;
import com.zhuinden.examplegithubclient.data.repository.GithubRepoRepository;
import com.zhuinden.examplegithubclient.domain.data.response.repositories.GithubRepo;
import com.zhuinden.examplegithubclient.domain.interactor.GetRepositoriesInteractor;
import com.zhuinden.examplegithubclient.util.PresenterUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.List;
import io.reactivex.Single;
import io.reactivex.android.plugins.RxAndroidPlugins;
import io.reactivex.schedulers.Schedulers;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Created by Zhuinden on 2016.12.21..
*/
public class RepositoriesPresenterTest {
RepositoriesPresenter repositoriesPresenter;
@Rule
public MockitoRule mockitoRule = MockitoJUnit.rule();
@Mock
RepositoriesPresenter.ViewContract viewContract;
@Mock
GetRepositoriesInteractor getRepositoriesInteractor;
@Mock
GithubRepoRepository githubRepoRepository;
@Before
public void init() {
repositoriesPresenter = new RepositoriesPresenter();
// BoltsConfig.configureMocks();
RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerCallable -> Schedulers.trampoline());
}
@Test
public void didDownloadAllTrue()
throws Exception {
repositoriesPresenter.downloadedAll = true;
assertThat(repositoriesPresenter.didDownloadAll()).isTrue();
}
@Test
public void didDownloadAllFalse()
throws Exception {
repositoriesPresenter.downloadedAll = false;
assertThat(repositoriesPresenter.didDownloadAll()).isFalse();
}
@Test
public void initializeViewNoData()
throws Exception {
// given
repositoriesPresenter.repositories = null;
repositoriesPresenter.isDownloading = true;
repositoriesPresenter.downloadedAll = false;
repositoriesPresenter.currentPage = 1;
repositoriesPresenter.getRepositoriesInteractor = getRepositoriesInteractor;
repositoriesPresenter.githubRepoRepository = githubRepoRepository;
Single<List<GithubRepo>> task = Mockito.mock(Single.class);
Mockito.when(getRepositoriesInteractor.getRepositories(RepositoriesPresenter.REPO_NAME, 1)).thenReturn(task);
// when
repositoriesPresenter.attachView(viewContract);
// then
assertThat(repositoriesPresenter.isDownloading).isTrue();
Mockito.verify(getRepositoriesInteractor).getRepositories(RepositoriesPresenter.REPO_NAME, 1);
}
@Test
public void initializeViewWithData()
throws Exception {
// given
List<GithubRepo> repositories = new ArrayList<GithubRepo>() {{
add(new GithubRepo());
}};
repositoriesPresenter.repositories = repositories;
repositoriesPresenter.downloadedAll = true;
repositoriesPresenter.isDownloading = false;
repositoriesPresenter.currentPage = 2;
repositoriesPresenter.getRepositoriesInteractor = getRepositoriesInteractor;
repositoriesPresenter.githubRepoRepository = githubRepoRepository;
// when
repositoriesPresenter.attachView(viewContract);
// then
assertThat(repositoriesPresenter.isDownloading).isFalse();
Mockito.verify(getRepositoriesInteractor, Mockito.never()).getRepositories(RepositoriesPresenter.REPO_NAME, 2);
Mockito.verify(viewContract).updateRepositories(repositories);
}
@Test
public void getRepositories()
throws Exception {
// given
List<GithubRepo> repositories = new ArrayList<GithubRepo>() {{
add(new GithubRepo());
}};
repositoriesPresenter.repositories = repositories;
// when
List<GithubRepo> presenterRepos = repositoriesPresenter.getRepositories();
// then
assertThat(repositories).isEqualTo(presenterRepos);
}
@Test
public void openRepository()
throws Exception {
// given
GithubRepo githubRepo = new GithubRepo();
githubRepo.setUrl("blah");
PresenterUtils.setView(repositoriesPresenter, viewContract);
// when
repositoriesPresenter.openRepository(githubRepo);
// then
Mockito.verify(viewContract).openRepository("blah");
}
@Test
public void downloadMoreWhileDownloading()
throws Exception {
// given
repositoriesPresenter.currentPage = 1;
repositoriesPresenter.isDownloading = true;
repositoriesPresenter.getRepositoriesInteractor = getRepositoriesInteractor;
PresenterUtils.setView(repositoriesPresenter, viewContract);
// when
repositoriesPresenter.downloadMore();
// then
Mockito.verify(getRepositoriesInteractor, Mockito.never()).getRepositories(RepositoriesPresenter.REPO_NAME, 1);
}
@Test
public void downloadMoreWhileNotDownloading()
throws Exception {
// given
repositoriesPresenter.currentPage = 1;
repositoriesPresenter.isDownloading = false;
repositoriesPresenter.getRepositoriesInteractor = getRepositoriesInteractor;
PresenterUtils.setView(repositoriesPresenter, viewContract);
Single<List<GithubRepo>> task = Mockito.mock(Single.class);
Mockito.when(getRepositoriesInteractor.getRepositories(RepositoriesPresenter.REPO_NAME, 1)).thenReturn(task);
// when
repositoriesPresenter.downloadMore();
// then
Mockito.verify(getRepositoriesInteractor).getRepositories(RepositoriesPresenter.REPO_NAME, 1);
}
// TODO: FIX TEST
// @Test
// public void downloadWithNoListSetsListAndUpdates() {
// // given
// final List<GithubRepo> repositories = new ArrayList<GithubRepo>() {{
// add(new GithubRepo());
// }};
// repositoriesPresenter.currentPage = 1;
// repositoriesPresenter.repositories = null;
// repositoriesPresenter.isDownloading = false;
// repositoriesPresenter.downloadedAll = false;
// repositoriesPresenter.getRepositoriesInteractor = (user, page) -> Task.call(() -> repositories);
// PresenterUtils.setView(repositoriesPresenter, viewContract);
//
// // when
// repositoriesPresenter.downloadMore();
//
// // then
// assertThat(repositoriesPresenter.currentPage).isEqualTo(2);
// assertThat(repositoriesPresenter.isDownloading).isFalse();
// assertThat(repositoriesPresenter.repositories).isEqualTo(repositories);
// Mockito.verify(viewContract).updateRepositories(repositories);
// }
// TODO: FIX TEST
// @Test
// public void downloadWithListAddsItemsAndUpdates() {
// // given
// final List<GithubRepo> originalRepository = new ArrayList<GithubRepo>() {{
// add(new GithubRepo());
// }};
// final GithubRepo newRepository = new GithubRepo();
// final List<GithubRepo> newRepositories = new ArrayList<GithubRepo>() {{
// add(newRepository);
// }};
// repositoriesPresenter.currentPage = 2;
// repositoriesPresenter.repositories = originalRepository;
// repositoriesPresenter.isDownloading = false;
// repositoriesPresenter.downloadedAll = false;
// repositoriesPresenter.getRepositoriesInteractor = (user, page) -> Task.call(() -> newRepositories);
// PresenterUtils.setView(repositoriesPresenter, viewContract);
//
// // when
// repositoriesPresenter.downloadMore();
//
// // then
// assertThat(repositoriesPresenter.isDownloading).isFalse();
// assertThat(repositoriesPresenter.downloadedAll).isFalse();
// assertThat(repositoriesPresenter.currentPage).isEqualTo(3);
// assertThat(repositoriesPresenter.repositories).isSameAs(originalRepository);
// assertThat(repositoriesPresenter.repositories).contains(newRepository);
// Mockito.verify(viewContract).updateRepositories(originalRepository);
// }
// TODO: FIX TEST
// @Test
// public void downloadingEmptyListSetsDownloadedAll() {
// // given
// final List<GithubRepo> originalRepository = new ArrayList<GithubRepo>() {{
// add(new GithubRepo());
// }};
// final List<GithubRepo> newRepositories = new ArrayList<GithubRepo>();
// repositoriesPresenter.currentPage = 2;
// repositoriesPresenter.repositories = originalRepository;
// repositoriesPresenter.isDownloading = false;
// repositoriesPresenter.downloadedAll = false;
// repositoriesPresenter.getRepositoriesInteractor = (user, page) -> Task.call(() -> newRepositories);
// PresenterUtils.setView(repositoriesPresenter, viewContract);
//
// // when
// repositoriesPresenter.downloadMore();
//
// // then
// assertThat(repositoriesPresenter.isDownloading).isFalse();
// assertThat(repositoriesPresenter.downloadedAll).isTrue();
// assertThat(repositoriesPresenter.currentPage).isEqualTo(2);
// assertThat(repositoriesPresenter.repositories).isSameAs(originalRepository);
// Mockito.verify(viewContract).updateRepositories(originalRepository);
// }
@Test
public void doNotDownloadWhenDownloadedAll() {
// given
repositoriesPresenter.currentPage = 2;
repositoriesPresenter.downloadedAll = true;
repositoriesPresenter.getRepositoriesInteractor = getRepositoriesInteractor;
PresenterUtils.setView(repositoriesPresenter, viewContract);
// when
repositoriesPresenter.downloadMore();
// then
Mockito.verify(getRepositoriesInteractor, Mockito.never()).getRepositories(RepositoriesPresenter.REPO_NAME, 2);
}
} | java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/test/java/flowless/FlowFactory.java | flowless-mvp-example/src/test/java/flowless/FlowFactory.java | package flowless;
/**
* Created by Zhuinden on 2016.12.19..
*/
public class FlowFactory {
public static Flow createFlow(KeyManager keyManager, ServiceProvider serviceProvider, History history) {
return new Flow(keyManager, serviceProvider, history);
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/ToolbarButtonVisibility.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/ToolbarButtonVisibility.java | package com.zhuinden.examplegithubclient.util;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Created by Zhuinden on 2016.12.18..
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
public @interface ToolbarButtonVisibility {
boolean value() default true;
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/Title.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/Title.java | package com.zhuinden.examplegithubclient.util;
import android.support.annotation.StringRes;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Created by Zhuinden on 2016.12.10..
*/
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface Title {
@StringRes int value();
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/Layout.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/Layout.java | package com.zhuinden.examplegithubclient.util;
import android.support.annotation.LayoutRes;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Created by Zhuinden on 2016.12.03..
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
public @interface Layout {
@LayoutRes int value();
} | java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/Presenter.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/Presenter.java | package com.zhuinden.examplegithubclient.util;
/**
* Created by Owner on 2016.12.10.
*/
public interface Presenter<V extends Presenter.ViewContract> {
interface ViewContract {
}
void attachView(V v);
void detachView();
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/BundleFactory.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/BundleFactory.java | package com.zhuinden.examplegithubclient.util;
import android.os.Bundle;
/**
* Created by Zhuinden on 2016.12.20..
*/
public class BundleFactory {
public interface Provider {
Bundle create();
}
static Provider provider = Bundle::new;
public static Bundle create() {
return provider.create();
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/GlideImageView.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/GlideImageView.java | package com.zhuinden.examplegithubclient.util;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.zhuinden.examplegithubclient.R;
import flowless.ViewUtils;
/**
* Created by Zhuinden on 2016.12.10..
*/
public class GlideImageView
extends ImageView {
public GlideImageView(Context context) {
super(context);
init(context, null, -1);
}
public GlideImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs, -1);
}
public GlideImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs, defStyleAttr);
}
@TargetApi(21)
public GlideImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs, defStyleAttr);
}
int drawableResource = 0;
private void init(Context context, AttributeSet attributeSet, int defStyle) {
TypedArray a = null;
if(defStyle != -1) {
a = getContext().obtainStyledAttributes(attributeSet, R.styleable.GlideImageView, defStyle, 0);
} else {
a = getContext().obtainStyledAttributes(attributeSet, R.styleable.GlideImageView);
}
drawableResource = a.getResourceId(R.styleable.GlideImageView_image_resource, 0);
a.recycle();
ViewUtils.waitForMeasure(this, (view, width, height) -> {
if(!isInEditMode()) {
if(drawableResource != 0) {
Glide.with(getContext()).load(drawableResource).dontAnimate().into(GlideImageView.this);
}
} else {
setImageResource(drawableResource);
}
});
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/IsChildOf.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/IsChildOf.java | package com.zhuinden.examplegithubclient.util;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Created by Zhuinden on 2016.12.18..
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
public @interface IsChildOf {
Class<?>[] value();
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/AnnotationCache.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/AnnotationCache.java | package com.zhuinden.examplegithubclient.util;
import android.content.Context;
import com.zhuinden.examplegithubclient.application.injection.ActivityScope;
import com.zhuinden.examplegithubclient.presentation.activity.main.MainComponent;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
/**
* Created by Owner on 2016.12.10.
*/
@ActivityScope
public class AnnotationCache {
public static final String TAG = "AnnotationCache";
public static AnnotationCache getCache(Context context) {
MainComponent mainComponent = DaggerService.getGlobalComponent(context);
return mainComponent.annotationCache();
}
@Inject
public AnnotationCache() {
}
// from flow-sample: https://github.com/Zhuinden/flow-sample/blob/master/src/main/java/com/example/flow/pathview/SimplePathContainer.java#L100-L114
private final Map<Class, Integer> PATH_LAYOUT_CACHE = new LinkedHashMap<>();
private final Map<Class, Integer> PATH_TITLE_CACHE = new LinkedHashMap<>();
private final Map<Class, Class<? extends ComponentFactory.FactoryMethod<?>>> PATH_COMPONENT_FACTORY_CACHE = new LinkedHashMap<>();
private final Map<Class, Boolean> LEFT_DRAWER_STATE_CACHE = new LinkedHashMap<>();
private final Map<Class, Boolean> TOOLBAR_BUTTON_STATE_CACHE = new LinkedHashMap<>();
private final Map<Class, Class<?>[]> IS_CHILD_OF_CACHE = new LinkedHashMap<>();
// from flow-sample: https://github.com/Zhuinden/flow-sample/blob/master/src/main/java/com/example/flow/pathview/SimplePathContainer.java#L100-L114
public int getLayout(Object path) {
return getValueFromAnnotation(PATH_LAYOUT_CACHE, path, Layout.class, false);
}
public int getTitle(Object path) {
return getValueFromAnnotation(PATH_TITLE_CACHE, path, Title.class, false);
}
public ComponentFactory.FactoryMethod<?> getComponentFactory(Object path) {
Class<? extends ComponentFactory.FactoryMethod<?>> value = getValueFromAnnotation(PATH_COMPONENT_FACTORY_CACHE,
path,
ComponentFactory.class,
true);
try {
if(value != null) {
return value.newInstance();
}
} catch(InstantiationException e) {
// shouldn't happen
e.printStackTrace();
} catch(IllegalAccessException e) {
// shouldn't happen
e.printStackTrace();
}
return null;
}
public boolean getLeftDrawerEnabled(Object path) {
Boolean state = getValueFromAnnotation(LEFT_DRAWER_STATE_CACHE, path, LeftDrawerEnabled.class, true);
return state == null ? true : state;
}
public boolean getToolbarButtonVisibility(Object path) {
Boolean state = getValueFromAnnotation(TOOLBAR_BUTTON_STATE_CACHE, path, ToolbarButtonVisibility.class, true);
return state == null ? true : state;
}
// details, details
private <T, A> T getValueFromAnnotation(Map<Class, T> cache, Object path, Class<A> annotationClass, boolean optional) {
Class pathType = path.getClass();
T value = cache.get(pathType);
if(value == null) {
A annotation = (A) pathType.getAnnotation(annotationClass);
if(annotation == null) {
if(!optional) {
throw new IllegalArgumentException(String.format("@%s annotation not found on class %s",
annotationClass.getSimpleName(),
pathType.getName()));
} else {
return null;
}
}
try {
value = (T) annotationClass.getMethod("value").invoke(annotation);
} catch(IllegalAccessException e) {
// shouldn't happen
e.printStackTrace();
} catch(InvocationTargetException e) {
// shouldn't happen
e.printStackTrace();
} catch(NoSuchMethodException e) {
// shouldn't happen
e.printStackTrace();
}
cache.put(pathType, value);
}
return value;
}
public Set<Class<?>> getChildOf(Object path) {
Class<?>[] value = getValueFromAnnotation(IS_CHILD_OF_CACHE, path, IsChildOf.class, true);
if(value != null) {
return new HashSet<>(Arrays.asList(value));
} else {
return Collections.emptySet();
}
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/BasePresenter.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/BasePresenter.java | package com.zhuinden.examplegithubclient.util;
/**
* Created by Owner on 2016.12.10.
*/
public abstract class BasePresenter<V extends Presenter.ViewContract>
implements Presenter<V> {
protected V view;
protected final boolean hasView() {
return view != null;
}
public V getView() {
return view;
}
@Override
public final void attachView(V view) {
this.view = view;
onAttach();
initializeView(view);
}
protected abstract void initializeView(V view);
@Override
public final void detachView() {
onDetach();
this.view = null;
}
protected void onAttach() {
}
protected void onDetach() {
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/TransitionDispatcher.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/TransitionDispatcher.java | package com.zhuinden.examplegithubclient.util;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.transitionseverywhere.TransitionManager;
import java.util.Set;
import flowless.ServiceProvider;
import flowless.Traversal;
import flowless.TraversalCallback;
import flowless.preset.DispatcherUtils;
import flowless.preset.SingleRootDispatcher;
/**
* Created by Zhuinden on 2016.12.02..
*/
public class TransitionDispatcher extends SingleRootDispatcher {
@Override
public void dispatch(@NonNull Traversal traversal, @NonNull TraversalCallback callback) {
if(DispatcherUtils.isPreviousKeySameAsNewKey(traversal.origin, traversal.destination)) { //short circuit on same key
callback.onTraversalCompleted();
return;
}
final Object newKey = DispatcherUtils.getNewKey(traversal);
AnnotationCache annotationCache = AnnotationCache.getCache(baseContext);
int newKeyLayout = annotationCache.getLayout(newKey);
final ViewGroup root = rootHolder.getRoot();
final View previousView = root.getChildAt(0);
DispatcherUtils.persistViewToStateAndNotifyRemoval(traversal, previousView);
Set<Class<?>> parentClasses = annotationCache.getChildOf(newKey);
ServiceProvider serviceProvider = ServiceProvider.get(baseContext);
if(traversal.origin != null) {
for(Object key : traversal.origin) { // retain only current key's and parents' services
boolean hasParent = evaluateIfHasParent(parentClasses, key);
if(!newKey.equals(key) && !hasParent) {
serviceProvider.unbindServices(key);
}
}
}
for(Object key : traversal.destination) { // retain only current key's and parents' services
boolean hasParent = evaluateIfHasParent(parentClasses, key);
if(!newKey.equals(key) && !hasParent) {
serviceProvider.unbindServices(key);
} else {
if(!serviceProvider.hasService(key, DaggerService.TAG)) {
ComponentFactory.FactoryMethod<?> componentFactory = annotationCache.getComponentFactory(key);
if(componentFactory != null) {
serviceProvider.bindService(key, DaggerService.TAG, componentFactory.createComponent(baseContext));
}
}
}
}
Context internalContext = traversal.createContext(newKey, baseContext);
LayoutInflater layoutInflater = LayoutInflater.from(internalContext);
final View newView = layoutInflater.inflate(newKeyLayout, root, false);
DispatcherUtils.restoreViewFromState(traversal, newView);
TransitionManager.beginDelayedTransition(root);
if(previousView != null) {
root.removeView(previousView);
}
root.addView(newView);
callback.onTraversalCompleted();
}
private boolean evaluateIfHasParent(Set<Class<?>> parentClasses, Object key) {
boolean hasParent = false;
for(Class<?> parentClass : parentClasses) {
if(parentClass.isAssignableFrom(key.getClass())) {
hasParent = true;
break;
}
}
return hasParent;
}
} | java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/DaggerService.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/DaggerService.java | package com.zhuinden.examplegithubclient.util;
import android.content.Context;
import com.zhuinden.examplegithubclient.presentation.activity.main.MainKey;
import flowless.ServiceProvider;
/**
* Created by Owner on 2016.12.10.
*/
public class DaggerService {
public static final String TAG = "DaggerService";
@SuppressWarnings("unchecked")
public static <T> T getComponent(Context context) {
//noinspection ResourceType
return (T) ServiceProvider.get(context).getService(context, TAG);
}
@SuppressWarnings("unchecked")
public static <T> T getGlobalComponent(Context context) {
//noinspection ResourceType
return (T) ServiceProvider.get(context).getService(MainKey.KEY, TAG);
}
} | java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/LeftDrawerEnabled.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/LeftDrawerEnabled.java | package com.zhuinden.examplegithubclient.util;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Created by Zhuinden on 2016.12.18..
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
public @interface LeftDrawerEnabled {
boolean value() default true;
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/ComponentFactory.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/ComponentFactory.java | package com.zhuinden.examplegithubclient.util;
import android.content.Context;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Created by Owner on 2016.12.10.
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
public @interface ComponentFactory {
Class<? extends FactoryMethod<?>> value();
interface FactoryMethod<T> {
T createComponent(Context context);
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/FlowlessActivity.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/FlowlessActivity.java | package com.zhuinden.examplegithubclient.util;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import flowless.Dispatcher;
import flowless.Flow;
/**
* Created by Zhuinden on 2016.12.18..
*/
public abstract class FlowlessActivity
extends AppCompatActivity
implements Dispatcher {
protected TransitionDispatcher transitionDispatcher;
@Override
protected void attachBaseContext(Context newBase) {
transitionDispatcher = new TransitionDispatcher();
newBase = Flow.configure(newBase, this) //
.defaultKey(getDefaultKey()) //
.globalKey(getGlobalKey()) //
.dispatcher(this) //
.install(); //
transitionDispatcher.setBaseContext(this);
super.attachBaseContext(newBase);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
transitionDispatcher.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
transitionDispatcher.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
transitionDispatcher.preSaveViewState();
super.onSaveInstanceState(outState);
}
@Override
public void onBackPressed() {
if(transitionDispatcher.onBackPressed()) {
return;
}
super.onBackPressed();
}
protected abstract Object getGlobalKey();
protected abstract Object getDefaultKey();
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/idlingresource/FlowlessIdlingResource.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/idlingresource/FlowlessIdlingResource.java | package com.zhuinden.examplegithubclient.util.idlingresource;
import flowless.FlowIdlingResource;
/**
* Created by Zhuinden on 2016.07.30..
*/
public class FlowlessIdlingResource
implements FlowIdlingResource {
public static final FlowlessIdlingResource INSTANCE = new FlowlessIdlingResource();
private FlowlessIdlingResource() {
}
@Override
public void increment() {
EspressoIdlingResource.increment();
}
@Override
public void decrement() {
EspressoIdlingResource.decrement();
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/idlingresource/EspressoIdlingResource.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/idlingresource/EspressoIdlingResource.java | package com.zhuinden.examplegithubclient.util.idlingresource;
/**
* Created by Zhuinden on 2016.12.19..
*/
import android.support.test.espresso.IdlingResource;
import android.util.Log;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Contains a static reference to {@link IdlingResource}, only available in the 'mock' build type.
*/
public class EspressoIdlingResource {
private static final String RESOURCE = "GLOBAL";
private static SimpleCountingIdlingResource mCountingIdlingResource = new SimpleCountingIdlingResource(RESOURCE);
public static void increment() {
mCountingIdlingResource.increment();
}
public static void decrement() {
mCountingIdlingResource.decrement();
}
public static IdlingResource getIdlingResource() {
return mCountingIdlingResource;
}
/**
* A simple counter implementation of {@link IdlingResource} that determines idleness by
* maintaining an internal counter. When the counter is 0 - it is considered to be idle, when it is
* non-zero it is not idle. This is very similar to the way a {@link java.util.concurrent.Semaphore}
* behaves.
* <p>
* This class can then be used to wrap up operations that while in progress should block tests from
* accessing the UI.
*/
public static final class SimpleCountingIdlingResource
implements IdlingResource {
private static final String TAG = "CountingIdlingResource";
private final String mResourceName;
private final AtomicInteger counter = new AtomicInteger(0);
// written from main thread, read from any thread.
private volatile ResourceCallback resourceCallback;
/**
* Creates a SimpleCountingIdlingResource
*
* @param resourceName the resource name this resource should report to Espresso.
*/
public SimpleCountingIdlingResource(String resourceName) {
if(resourceName == null) {
throw new IllegalArgumentException("The resource is null, when expected not to be!");
}
mResourceName = resourceName;
}
@Override
public String getName() {
return mResourceName;
}
@Override
public boolean isIdleNow() {
return counter.get() == 0;
}
@Override
public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
this.resourceCallback = resourceCallback;
}
/**
* Increments the count of in-flight transactions to the resource being monitored.
*/
public void increment() {
counter.getAndIncrement();
}
/**
* Decrements the count of in-flight transactions to the resource being monitored.
*
* If this operation results in the counter falling below 0 - an exception is raised.
*
* @throws IllegalStateException if the counter is below 0.
*/
public void decrement() {
int counterVal = counter.decrementAndGet();
if(counterVal == 0) {
// we've gone from non-zero to zero. That means we're idle now! Tell espresso.
if(null != resourceCallback) {
resourceCallback.onTransitionToIdle();
}
}
if(counterVal < 0) {
Log.e(TAG, "Counter has been corrupted!");
}
}
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/conditionwatcher/Instruction.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/conditionwatcher/Instruction.java | package com.zhuinden.examplegithubclient.util.conditionwatcher;
import android.os.Bundle;
import com.zhuinden.examplegithubclient.util.BundleFactory;
/**
* Created by F1sherKK on 16/12/15.
*/
public abstract class Instruction {
private Bundle dataContainer = BundleFactory.create();
public final void setData(Bundle dataContainer) {
this.dataContainer = dataContainer;
}
public final Bundle getDataContainer() {
return dataContainer;
}
public abstract String getDescription();
public abstract boolean checkCondition();
} | java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/conditionwatcher/ConditionWatcher.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/util/conditionwatcher/ConditionWatcher.java | package com.zhuinden.examplegithubclient.util.conditionwatcher;
/**
* Created by F1sherKK on 08/10/15.
*/
public class ConditionWatcher {
public static final int CONDITION_NOT_MET = 0;
public static final int CONDITION_MET = 1;
public static final int TIMEOUT = 2;
public static final int DEFAULT_TIMEOUT_LIMIT = 1000 * 60;
public static final int DEFAULT_INTERVAL = 250;
private int timeoutLimit = DEFAULT_TIMEOUT_LIMIT;
private int watchInterval = DEFAULT_INTERVAL;
private static ConditionWatcher conditionWatcher;
private ConditionWatcher() {
super();
}
public static ConditionWatcher getInstance() {
if(conditionWatcher == null) {
conditionWatcher = new ConditionWatcher();
}
return conditionWatcher;
}
public static void waitForCondition(Instruction instruction)
throws Exception {
int status = CONDITION_NOT_MET;
int elapsedTime = 0;
do {
if(instruction.checkCondition()) {
status = CONDITION_MET;
} else {
elapsedTime += getInstance().watchInterval;
Thread.sleep(getInstance().watchInterval);
}
if(elapsedTime == getInstance().timeoutLimit) {
status = TIMEOUT;
break;
}
} while(status != CONDITION_MET);
if(status == TIMEOUT) {
throw new Exception(instruction.getDescription() + " - took more than " + getInstance().timeoutLimit / 1000 + " seconds. Test stopped.");
}
}
public static void setWatchInterval(int watchInterval) {
getInstance().watchInterval = watchInterval;
}
public static void setTimeoutLimit(int ms) {
getInstance().timeoutLimit = ms;
}
} | java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/presentation/activity/main/MainView.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/presentation/activity/main/MainView.java | package com.zhuinden.examplegithubclient.presentation.activity.main;
import android.content.Context;
import android.support.annotation.StringRes;
import android.support.v4.widget.DrawerLayout;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.zhuinden.examplegithubclient.R;
import javax.inject.Inject;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import flowless.ActivityUtils;
import flowless.preset.FlowLifecycles;
/**
* Created by Zhuinden on 2016.12.21..
*/
public class MainView
extends DrawerLayout
implements MainPresenter.ViewContract, FlowLifecycles.ViewLifecycleListener {
public MainView(Context context) {
super(context);
}
public MainView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MainView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@BindView(R.id.root)
ViewGroup root;
@BindView(R.id.toolbar_text)
TextView toolbarText;
@BindView(R.id.toolbar)
ViewGroup toolbar;
@BindView(R.id.toolbar_drawer_toggle)
View drawerToggle;
@BindView(R.id.toolbar_go_previous)
View toolbarGoPrevious;
@Inject
MainPresenter mainPresenter;
@OnClick(R.id.toolbar_drawer_toggle)
public void onClickDrawerToggle() {
mainPresenter.toggleDrawer();
}
@OnClick(R.id.toolbar_go_previous)
public void onClickGoPrevious() {
ActivityUtils.getActivity(getContext()).onBackPressed();
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
if(!isInEditMode()) {
ButterKnife.bind(this);
}
}
@Override
public void disableLeftDrawer() {
setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
}
@Override
public void enableLeftDrawer() {
setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
}
@Override
public void hideDrawerToggle() {
drawerToggle.setVisibility(View.GONE);
}
@Override
public void showDrawerToggle() {
drawerToggle.setVisibility(View.VISIBLE);
}
@Override
public void hideToolbarGoPrevious() {
toolbarGoPrevious.setVisibility(View.GONE);
}
@Override
public void showToolbarGoPrevious() {
toolbarGoPrevious.setVisibility(View.VISIBLE);
}
@Override
public void openDrawer() {
openDrawer(Gravity.LEFT);
}
@Override
public void closeDrawer() {
closeDrawer(Gravity.LEFT);
}
@Override
public void setTitle(@StringRes int title) {
toolbarText.setText(title);
}
public ViewGroup getRoot() {
return root;
}
@Override
public void onViewRestored() {
mainPresenter.attachView(this);
}
@Override
public void onViewDestroyed(boolean removedByFlow) {
mainPresenter.detachView();
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/presentation/activity/main/MainActivity.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/presentation/activity/main/MainActivity.java | package com.zhuinden.examplegithubclient.presentation.activity.main;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import com.zhuinden.examplegithubclient.R;
import com.zhuinden.examplegithubclient.application.injection.config.MainComponentConfig;
import com.zhuinden.examplegithubclient.presentation.paths.login.LoginKey;
import com.zhuinden.examplegithubclient.util.DaggerService;
import com.zhuinden.examplegithubclient.util.FlowlessActivity;
import javax.inject.Inject;
import butterknife.BindView;
import butterknife.ButterKnife;
import flowless.Flow;
import flowless.KeyManager;
import flowless.ServiceProvider;
import flowless.State;
import flowless.Traversal;
import flowless.TraversalCallback;
import flowless.preset.FlowLifecycleProvider;
public class MainActivity
extends FlowlessActivity {
@BindView(R.id.drawer_layout)
MainView mainView;
@BindView(R.id.hidden_toolbar)
Toolbar hiddenToolbar;
@Inject
MainPresenter mainPresenter;
ActionBarDrawerToggle actionBarDrawerToggle;
private boolean didInject = false;
private void injectServices() {
if(didInject) {
return;
}
didInject = true;
Flow flow = Flow.get(getBaseContext());
ServiceProvider serviceProvider = ServiceProvider.get(getBaseContext());
MainKey mainKey = Flow.getKey(getBaseContext());
MainComponent mainComponent;
if(!serviceProvider.hasService(mainKey, DaggerService.TAG)) {
mainComponent = MainComponentConfig.create(flow);
serviceProvider.bindService(mainKey, DaggerService.TAG, mainComponent);
} else {
mainComponent = DaggerService.getGlobalComponent(getBaseContext());
}
mainComponent.inject(this);
KeyManager keyManager = KeyManager.get(getBaseContext());
State state = keyManager.getState(mainKey);
mainPresenter.fromBundle(state.getBundle());
//
mainComponent.inject(mainView);
}
@Override
protected Object getGlobalKey() {
return MainKey.KEY;
}
@Override
protected Object getDefaultKey() {
return LoginKey.create();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
setSupportActionBar(hiddenToolbar);
actionBarDrawerToggle = new ActionBarDrawerToggle(this, mainView, hiddenToolbar, R.string.open, R.string.close) {
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
mainPresenter.openDrawer();
supportInvalidateOptionsMenu();
}
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
mainPresenter.closeDrawer();
supportInvalidateOptionsMenu();
}
};
mainView.setDrawerListener(actionBarDrawerToggle);
actionBarDrawerToggle.setDrawerIndicatorEnabled(false);
transitionDispatcher.getRootHolder().setRoot(mainView.getRoot());
actionBarDrawerToggle.syncState();
}
@Override
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
injectServices();
FlowLifecycleProvider.onViewRestored(mainView);
}
@Override
protected void onDestroy() {
FlowLifecycleProvider.onViewDestroyed(mainView, false);
super.onDestroy();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
actionBarDrawerToggle.onConfigurationChanged(newConfig);
}
@Override
public void onBackPressed() {
if(mainPresenter.onBackPressed()) {
return;
}
super.onBackPressed();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
KeyManager keyManager = KeyManager.get(getBaseContext());
State state = keyManager.getState(Flow.getKey(getBaseContext()));
state.setBundle(mainPresenter.toBundle());
super.onSaveInstanceState(outState);
}
@Override
public void dispatch(@NonNull Traversal traversal, @NonNull TraversalCallback callback) {
injectServices();
mainPresenter.dispatch(traversal, callback);
transitionDispatcher.dispatch(traversal, callback);
}
@Override
public Object getSystemService(String name) {
try {
ServiceProvider serviceProvider = ServiceProvider.get(getBaseContext());
if(serviceProvider.hasService(MainKey.KEY, name)) {
return serviceProvider.getService(MainKey.KEY, name);
}
} catch(IllegalStateException e) { // ServiceProvider and Flow are not initialized before onPostCreate
}
return super.getSystemService(name);
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/presentation/activity/main/MainComponent.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/presentation/activity/main/MainComponent.java | package com.zhuinden.examplegithubclient.presentation.activity.main;
import com.zhuinden.examplegithubclient.application.injection.ActivityScope;
import com.zhuinden.examplegithubclient.application.injection.modules.InteractorModule;
import com.zhuinden.examplegithubclient.application.injection.modules.NavigationModule;
import com.zhuinden.examplegithubclient.application.injection.modules.OkHttpModule;
import com.zhuinden.examplegithubclient.application.injection.modules.RepositoryModule;
import com.zhuinden.examplegithubclient.application.injection.modules.RetrofitModule;
import com.zhuinden.examplegithubclient.application.injection.modules.ServiceModule;
import com.zhuinden.examplegithubclient.data.model.GithubRepoDataSource;
import com.zhuinden.examplegithubclient.data.repository.GithubRepoRepository;
import com.zhuinden.examplegithubclient.domain.interactor.GetRepositoriesInteractor;
import com.zhuinden.examplegithubclient.domain.interactor.LoginInteractor;
import com.zhuinden.examplegithubclient.domain.networking.HeaderInterceptor;
import com.zhuinden.examplegithubclient.domain.service.GithubService;
import com.zhuinden.examplegithubclient.domain.service.retrofit.RetrofitGithubService;
import com.zhuinden.examplegithubclient.util.AnnotationCache;
import dagger.Component;
import flowless.Flow;
import flowless.KeyManager;
import flowless.ServiceProvider;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
/**
* Created by Owner on 2016.12.10.
*/
@ActivityScope
@Component(modules = {OkHttpModule.class, RetrofitModule.class, InteractorModule.class, NavigationModule.class, RepositoryModule.class, ServiceModule.class})
public interface MainComponent {
Flow flow();
ServiceProvider serviceProvider();
KeyManager keyManager();
HeaderInterceptor headerInterceptor();
AnnotationCache annotationCache();
MainPresenter mainPresenter();
OkHttpClient okHttpClient();
RetrofitGithubService retrofitGithubService();
Retrofit retrofit();
GithubService githubService();
GetRepositoriesInteractor getRepositoriesInteractor();
LoginInteractor loginInteractor();
GithubRepoDataSource repositoryDataSource();
GithubRepoRepository repositoryRepository();
void inject(MainActivity mainActivity);
void inject(MainView mainView);
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/presentation/activity/main/MainPresenter.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/presentation/activity/main/MainPresenter.java | package com.zhuinden.examplegithubclient.presentation.activity.main;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import com.zhuinden.examplegithubclient.application.injection.ActivityScope;
import com.zhuinden.examplegithubclient.presentation.paths.login.LoginKey;
import com.zhuinden.examplegithubclient.util.AnnotationCache;
import com.zhuinden.examplegithubclient.util.BasePresenter;
import com.zhuinden.examplegithubclient.util.BundleFactory;
import com.zhuinden.examplegithubclient.util.Presenter;
import java.util.Set;
import javax.inject.Inject;
import flowless.Bundleable;
import flowless.Direction;
import flowless.Dispatcher;
import flowless.Flow;
import flowless.History;
import flowless.Traversal;
import flowless.TraversalCallback;
import flowless.preset.DispatcherUtils;
/**
* Created by Owner on 2016.12.10.
*/
@ActivityScope
public class MainPresenter
extends BasePresenter<MainPresenter.ViewContract>
implements Bundleable, Dispatcher {
@Inject
AnnotationCache annotationCache;
@Inject
Flow flow;
@Inject
public MainPresenter() {
}
@StringRes
int title;
boolean isDrawerOpen;
boolean toolbarGoPreviousVisible;
boolean drawerToggleVisible;
boolean leftDrawerEnabled;
public interface ViewContract
extends Presenter.ViewContract {
void openDrawer();
void closeDrawer();
void setTitle(@StringRes int resourceId);
void enableLeftDrawer();
void disableLeftDrawer();
void hideDrawerToggle();
void showDrawerToggle();
void hideToolbarGoPrevious();
void showToolbarGoPrevious();
}
@Override
protected void initializeView(ViewContract view) {
view.setTitle(title);
if(isDrawerOpen) {
openDrawer();
} else {
closeDrawer();
}
if(toolbarGoPreviousVisible) {
showToolbarGoPrevious();
} else {
hideToolbarGoPrevious();
}
if(drawerToggleVisible) {
showDrawerToggle();
} else {
hideDrawerToggle();
}
if(leftDrawerEnabled) {
enableLeftDrawer();
} else {
disableLeftDrawer();
}
}
public void setTitle(int title) {
this.title = title;
if(hasView()) {
getView().setTitle(title);
}
}
public void goToKey(Object newKey) {
closeDrawer();
if(newKey instanceof LoginKey) {
flow.setHistory(History.single(newKey), Direction.FORWARD);
} else {
flow.set(newKey);
}
}
public boolean onBackPressed() {
if(isDrawerOpen) {
closeDrawer();
return true;
}
return false;
}
public void openDrawer() {
isDrawerOpen = true;
if(hasView()) {
getView().openDrawer();
}
}
public void closeDrawer() {
isDrawerOpen = false;
if(hasView()) {
getView().closeDrawer();
}
}
public void toggleDrawer() {
if(isDrawerOpen) {
closeDrawer();
} else {
openDrawer();
}
}
@Override
public void dispatch(@NonNull Traversal traversal, @NonNull TraversalCallback callback) {
Object newKey = DispatcherUtils.getNewKey(traversal);
setTitle(annotationCache.getTitle(newKey));
boolean isLeftDrawerEnabled = annotationCache.getLeftDrawerEnabled(newKey);
if(isLeftDrawerEnabled) {
enableLeftDrawer();
} else {
disableLeftDrawer();
}
boolean isToolbarButtonVisible = annotationCache.getToolbarButtonVisibility(newKey);
Set<Class<?>> parents = annotationCache.getChildOf(newKey);
if(parents.size() > 0) {
hideDrawerToggle();
showToolbarGoPrevious();
} else {
if(isToolbarButtonVisible) {
showDrawerToggle();
} else {
hideDrawerToggle();
}
hideToolbarGoPrevious();
}
}
private void enableLeftDrawer() {
this.leftDrawerEnabled = true;
if(hasView()) {
view.enableLeftDrawer();
}
}
private void disableLeftDrawer() {
this.leftDrawerEnabled = false;
if(hasView()) {
view.disableLeftDrawer();
}
}
private void hideToolbarGoPrevious() {
this.toolbarGoPreviousVisible = false;
if(hasView()) {
view.hideToolbarGoPrevious();
}
}
private void showToolbarGoPrevious() {
this.toolbarGoPreviousVisible = true;
if(hasView()) {
view.showToolbarGoPrevious();
}
}
private void showDrawerToggle() {
this.drawerToggleVisible = true;
if(hasView()) {
view.showDrawerToggle();
}
}
private void hideDrawerToggle() {
this.drawerToggleVisible = false;
if(hasView()) {
view.hideDrawerToggle();
}
}
@Override
public Bundle toBundle() {
Bundle bundle = BundleFactory.create();
bundle.putBoolean("isDrawerOpen", isDrawerOpen);
bundle.putInt("title", title);
bundle.putBoolean("toolbarGoPreviousVisible", toolbarGoPreviousVisible);
bundle.putBoolean("drawerToggleVisible", drawerToggleVisible);
bundle.putBoolean("leftDrawerEnabled", leftDrawerEnabled);
return bundle;
}
@Override
public void fromBundle(@Nullable Bundle bundle) {
if(bundle != null) {
isDrawerOpen = bundle.getBoolean("isDrawerOpen");
title = bundle.getInt("title");
toolbarGoPreviousVisible = bundle.getBoolean("toolbarGoPreviousVisible");
drawerToggleVisible = bundle.getBoolean("drawerToggleVisible");
leftDrawerEnabled = bundle.getBoolean("leftDrawerEnabled");
}
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/presentation/activity/main/MainKey.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/presentation/activity/main/MainKey.java | package com.zhuinden.examplegithubclient.presentation.activity.main;
import android.os.Parcel;
import android.os.Parcelable;
import flowless.ClassKey;
/**
* Created by Owner on 2016.12.10.
*/
public class MainKey
extends ClassKey
implements Parcelable {
public static final MainKey KEY = new MainKey();
private MainKey() {
}
protected MainKey(Parcel in) {
}
public static final Creator<MainKey> CREATOR = new Creator<MainKey>() {
@Override
public MainKey createFromParcel(Parcel in) {
return new MainKey(in);
}
@Override
public MainKey[] newArray(int size) {
return new MainKey[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/presentation/activity/main/leftdrawer/LeftDrawerView.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/presentation/activity/main/leftdrawer/LeftDrawerView.java | package com.zhuinden.examplegithubclient.presentation.activity.main.leftdrawer;
import android.annotation.TargetApi;
import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
import com.zhuinden.examplegithubclient.R;
import butterknife.BindView;
import butterknife.ButterKnife;
/**
* Created by Zhuinden on 2016.12.10..
*/
public class LeftDrawerView
extends RelativeLayout {
public LeftDrawerView(Context context) {
super(context);
init();
}
public LeftDrawerView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public LeftDrawerView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
@TargetApi(21)
public LeftDrawerView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
private void init() {
if(!isInEditMode()) {
// .
}
}
@BindView(R.id.left_drawer_recycler_view)
RecyclerView recyclerView;
@Override
protected void onFinishInflate() {
super.onFinishInflate();
if(!isInEditMode()) {
ButterKnife.bind(this);
recyclerView.setAdapter(new LeftDrawerAdapter());
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
}
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Zhuinden/flowless | https://github.com/Zhuinden/flowless/blob/a958f08cd91352ad5430fb3bce986e6b132f5cd9/flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/presentation/activity/main/leftdrawer/LeftDrawerItems.java | flowless-mvp-example/src/main/java/com/zhuinden/examplegithubclient/presentation/activity/main/leftdrawer/LeftDrawerItems.java | package com.zhuinden.examplegithubclient.presentation.activity.main.leftdrawer;
import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;
import com.zhuinden.examplegithubclient.R;
import com.zhuinden.examplegithubclient.presentation.paths.about.AboutKey;
import com.zhuinden.examplegithubclient.presentation.paths.login.LoginKey;
import com.zhuinden.examplegithubclient.presentation.paths.repositories.RepositoriesKey;
/**
* Created by Zhuinden on 2016.12.10..
*/
public enum LeftDrawerItems {
REPOSITORIES(R.string.title_repositories, R.drawable.icon_repositories, RepositoriesKey::create),
ABOUT(R.string.title_about, R.drawable.icon_about, AboutKey::create),
LOGOUT(R.string.title_logout, R.drawable.icon_logout, LoginKey::create);
private final int labelId;
private final int imageId;
private final KeyCreator keyCreator;
private LeftDrawerItems(@StringRes int labelId, @DrawableRes int imageId, KeyCreator keyCreator) {
this.labelId = labelId;
this.imageId = imageId;
this.keyCreator = keyCreator;
}
public int getLabelId() {
return labelId;
}
public int getImageId() {
return imageId;
}
public KeyCreator getKeyCreator() {
return keyCreator;
}
static interface KeyCreator {
public Object createKey();
}
}
| java | Apache-2.0 | a958f08cd91352ad5430fb3bce986e6b132f5cd9 | 2026-01-05T02:40:56.157166Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.