-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sample app! #97
+1,405
−0
Merged
Sample app! #97
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b1864af
Stub a basic android sample scaffolding
ZacSweers ffcfd62
Stub a basic android sample scaffolding
ZacSweers 879ba72
Add fleshed out mainactivity and kotlinactivity examples
ZacSweers c7b93b4
Add recipes for AutoDisposeActivities
ZacSweers e7e1ba2
Fix missing symmetries in activity events
ZacSweers 2e302b8
Put kotlin at end of file name for better consistency later
ZacSweers 1b26e56
Add message to after-destroy exceptions for clarity
ZacSweers e1fdb29
Add base class details
ZacSweers 8b0e752
Add Fragment demo
ZacSweers 20f5d3c
Add View demo
ZacSweers 6d16ee1
Add AutoDisposeViewHolder demo
ZacSweers 8e25ff3
Better nullability annotations handling
ZacSweers be7d5ee
Suppress a couple more
ZacSweers a2d0972
More idiomatic kotlin in AutoDisposeView + lazy
ZacSweers 7b717f3
Cleaner When's
ZacSweers 4fe6424
Fix dependencies
ZacSweers 92670ec
Fix capitalization
ZacSweers 9b25402
More idiomatic unbindernotifier handling
ZacSweers 31acfeb
Document the corresponding event methods
ZacSweers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2017. Uber Technologies | ||
* | ||
* 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. | ||
*/ | ||
|
||
buildscript { | ||
repositories { | ||
jcenter() | ||
google() | ||
} | ||
|
||
dependencies { | ||
classpath deps.build.gradlePlugins.android | ||
classpath deps.build.gradlePlugins.kotlin | ||
} | ||
} | ||
|
||
apply plugin: 'com.android.application' | ||
apply plugin: 'kotlin-android' | ||
|
||
android { | ||
compileSdkVersion deps.build.compileSdkVersion | ||
buildToolsVersion deps.build.buildToolsVersion | ||
|
||
defaultConfig { | ||
minSdkVersion deps.build.minSdkVersion | ||
targetSdkVersion deps.build.targetSdkVersion | ||
} | ||
compileOptions { | ||
// TODO Go to 1.8 + D8 on AGP 3.x | ||
sourceCompatibility JavaVersion.VERSION_1_7 | ||
targetCompatibility JavaVersion.VERSION_1_7 | ||
} | ||
sourceSets { | ||
main.java.srcDirs += 'src/main/kotlin' | ||
} | ||
} | ||
|
||
dependencies { | ||
compile project(':autodispose') | ||
compile project(':autodispose-android') | ||
compile project(':autodispose-android-archcomponents') | ||
compile project(':autodispose-kotlin') | ||
compile 'com.android.support:appcompat-v7:26.1.0' | ||
compile 'com.android.support.constraint:constraint-layout:1.0.2' | ||
compile 'com.android.support:design:26.+' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ Copyright (c) 2017. Uber Technologies | ||
~ | ||
~ 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. | ||
--> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
package="com.uber.autodispose.sample"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:hardwareAccelerated="true" | ||
android:label="@string/app_name" | ||
android:icon="@mipmap/ic_launcher" | ||
android:roundIcon="@mipmap/ic_launcher" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.AppCompat.Light.NoActionBar" | ||
android:fullBackupContent="@null" | ||
tools:ignore="GoogleAppIndexingWarning"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:label="@string/app_name" | ||
android:theme="@style/Theme.AppCompat.Light.NoActionBar"> | ||
|
||
<intent-filter> | ||
<category android:name="android.intent.category.DEFAULT"/> | ||
<action android:name="android.intent.action.MAIN"/> | ||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
<activity | ||
android:name=".KotlinActivity" | ||
android:label="@string/app_name_kotlin" | ||
android:theme="@style/Theme.AppCompat.Light.NoActionBar"> | ||
|
||
<intent-filter> | ||
<category android:name="android.intent.category.DEFAULT"/> | ||
<action android:name="android.intent.action.MAIN"/> | ||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
72 changes: 72 additions & 0 deletions
72
sample/src/main/java/android/support/v7/widget/BindAwareViewHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2017. Uber Technologies | ||
* | ||
* 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 android.support.v7.widget; | ||
|
||
import android.view.View; | ||
|
||
/** | ||
* A bind-aware {@link RecyclerView.ViewHolder} implementation that knows when it's bound or | ||
* unbound. | ||
* <p> | ||
* Disclaimer: This is in no way supported and THIS COULD BREAK AT ANY TIME. Left for research. | ||
*/ | ||
public abstract class BindAwareViewHolder extends RecyclerView.ViewHolder { | ||
|
||
public BindAwareViewHolder(View itemView) { | ||
super(itemView); | ||
} | ||
|
||
protected void onBind() { | ||
|
||
} | ||
|
||
protected void onUnbind() { | ||
|
||
} | ||
|
||
@Override void setFlags(int flags, int mask) { | ||
boolean wasBound = isBound(); | ||
super.setFlags(flags, mask); | ||
notifyBinding(wasBound, isBound()); | ||
} | ||
|
||
@Override void addFlags(int flags) { | ||
boolean wasBound = isBound(); | ||
super.addFlags(flags); | ||
notifyBinding(wasBound, isBound()); | ||
} | ||
|
||
@Override void clearPayload() { | ||
boolean wasBound = isBound(); | ||
super.clearPayload(); | ||
notifyBinding(wasBound, isBound()); | ||
} | ||
|
||
@Override void resetInternal() { | ||
boolean wasBound = isBound(); | ||
super.resetInternal(); | ||
notifyBinding(wasBound, isBound()); | ||
} | ||
|
||
private void notifyBinding(boolean previousBound, boolean currentBound) { | ||
if (previousBound && !currentBound) { | ||
onUnbind(); | ||
} else if (!previousBound && currentBound) { | ||
onBind(); | ||
} | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
sample/src/main/java/com/uber/autodispose/recipes/AutoDisposeActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright (c) 2017. Uber Technologies | ||
* | ||
* 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 com.uber.autodispose.recipes; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import com.uber.autodispose.LifecycleEndedException; | ||
import com.uber.autodispose.LifecycleScopeProvider; | ||
import io.reactivex.Observable; | ||
import io.reactivex.functions.Function; | ||
import io.reactivex.subjects.BehaviorSubject; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* An {@link Activity} example implementation for making one implement {@link | ||
* LifecycleScopeProvider}. One would normally use this as a base activity class to extend others | ||
* from. | ||
*/ | ||
public abstract class AutoDisposeActivity extends Activity | ||
implements LifecycleScopeProvider<AutoDisposeActivity.ActivityEvent> { | ||
|
||
public enum ActivityEvent { | ||
CREATE, START, RESUME, PAUSE, STOP, DESTROY | ||
} | ||
|
||
private static Function<ActivityEvent, ActivityEvent> CORRESPONDING_EVENTS = | ||
new Function<ActivityEvent, ActivityEvent>() { | ||
@Override public ActivityEvent apply(ActivityEvent activityEvent) throws Exception { | ||
switch (activityEvent) { | ||
case CREATE: | ||
return ActivityEvent.DESTROY; | ||
case START: | ||
return ActivityEvent.STOP; | ||
case RESUME: | ||
return ActivityEvent.PAUSE; | ||
case PAUSE: | ||
return ActivityEvent.STOP; | ||
case STOP: | ||
return ActivityEvent.DESTROY; | ||
default: | ||
throw new LifecycleEndedException("Cannot bind to Activity lifecycle after destroy."); | ||
} | ||
} | ||
}; | ||
|
||
private final BehaviorSubject<ActivityEvent> lifecycleEvents = BehaviorSubject.create(); | ||
|
||
@Override public Observable<ActivityEvent> lifecycle() { | ||
return lifecycleEvents.hide(); | ||
} | ||
|
||
@Override public Function<ActivityEvent, ActivityEvent> correspondingEvents() { | ||
return CORRESPONDING_EVENTS; | ||
} | ||
|
||
@Nullable @Override public ActivityEvent peekLifecycle() { | ||
return lifecycleEvents.getValue(); | ||
} | ||
|
||
@Override protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
lifecycleEvents.onNext(ActivityEvent.CREATE); | ||
} | ||
|
||
@Override protected void onStart() { | ||
super.onStart(); | ||
lifecycleEvents.onNext(ActivityEvent.START); | ||
} | ||
|
||
@Override protected void onResume() { | ||
super.onResume(); | ||
lifecycleEvents.onNext(ActivityEvent.RESUME); | ||
} | ||
|
||
@Override protected void onPause() { | ||
lifecycleEvents.onNext(ActivityEvent.PAUSE); | ||
super.onPause(); | ||
} | ||
|
||
@Override protected void onStop() { | ||
lifecycleEvents.onNext(ActivityEvent.STOP); | ||
super.onStop(); | ||
} | ||
|
||
@Override protected void onDestroy() { | ||
lifecycleEvents.onNext(ActivityEvent.DESTROY); | ||
super.onDestroy(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd split these events into two separate sequences, so it'll be easier to understand, why startup methods have symmetric shutdown ones as a counterpart, while shutdown methods are having sequential shutdown ones.