Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions rxandroid/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
// Multi-module modules aren't really supported
version = rootProject.version

configurations {
// This is a rough approximation of Android plug-in's 'provided' configuration, where
// you can give compile-time only dependencies.
compileOnly
}

dependencies {
compileOnly "com.google.auto.value:auto-value:1.0-rc1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we get this converted to an Android library (#81) we'll be able to use the apt plugin and actually see the generated source in the IDE so it doesn't appear red.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

test {
testLogging {
exceptionFormat "full"
Expand All @@ -9,3 +19,9 @@ test {
}
}

sourceSets {
main {
compileClasspath += configurations.compileOnly
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@
package rx.android.view;

import android.widget.CompoundButton;
import com.google.auto.value.AutoValue;

public class OnCheckedChangeEvent {
public final CompoundButton view;
public final boolean value;
@AutoValue
public abstract class OnCheckedChangeEvent {
public abstract CompoundButton view();
public abstract boolean value();

public OnCheckedChangeEvent(final CompoundButton view) {
this(view, view.isChecked());
public static OnCheckedChangeEvent create(final CompoundButton view) {
return create(view, view.isChecked());
}

public OnCheckedChangeEvent(final CompoundButton view, final boolean value) {
this.view = view;
this.value = value;
public static OnCheckedChangeEvent create(final CompoundButton view, final boolean value) {
return new AutoValue_OnCheckedChangeEvent(view, value);
}
}
11 changes: 7 additions & 4 deletions rxandroid/src/main/java/rx/android/view/OnClickEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@

import android.view.View;

public class OnClickEvent {
public final View view;
import com.google.auto.value.AutoValue;

public OnClickEvent(final View view) {
this.view = view;
@AutoValue
public abstract class OnClickEvent {
public abstract View view();

public static OnClickEvent create(View view) {
return new AutoValue_OnClickEvent(view);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void call(final Subscriber<? super OnClickEvent> observer) {
final View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(final View clicked) {
observer.onNext(new OnClickEvent(view));
observer.onNext(OnClickEvent.create(view));
}
};

Expand All @@ -55,7 +55,7 @@ public void call() {
});

if (emitInitialValue) {
observer.onNext(new OnClickEvent(view));
observer.onNext(OnClickEvent.create(view));
}

composite.addOnClickListener(listener);
Expand Down
20 changes: 10 additions & 10 deletions rxandroid/src/main/java/rx/android/widget/OnItemClickEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
import android.widget.Adapter;
import android.widget.AdapterView;

public class OnItemClickEvent {
public final AdapterView<?> parent;
public final View view;
public final int position;
public final long id;
import com.google.auto.value.AutoValue;

public OnItemClickEvent(AdapterView<?> parent, View view, int position, long id) {
this.parent = parent;
this.view = view;
this.position = position;
this.id = id;
@AutoValue
public abstract class OnItemClickEvent {
abstract public AdapterView<?> parent();
abstract public View view();
abstract public int position();
abstract public long id();

public static OnItemClickEvent create(AdapterView<?> parent, View view, int position, long id) {
return new AutoValue_OnItemClickEvent(parent, view, position, id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,70 +16,19 @@

import android.widget.AbsListView;

public class OnListViewScrollEvent {
public final AbsListView listView;
public final int scrollState;
public final int firstVisibleItem;
public final int visibleItemCount;
public final int totalItemCount;
import com.google.auto.value.AutoValue;

public OnListViewScrollEvent(
AbsListView listView, int scrollState, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
this.listView = listView;
this.scrollState = scrollState;
this.firstVisibleItem = firstVisibleItem;
this.visibleItemCount = visibleItemCount;
this.totalItemCount = totalItemCount;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

OnListViewScrollEvent that = (OnListViewScrollEvent) o;

if (firstVisibleItem != that.firstVisibleItem) {
return false;
}
if (scrollState != that.scrollState) {
return false;
}
if (totalItemCount != that.totalItemCount) {
return false;
}
if (visibleItemCount != that.visibleItemCount) {
return false;
}
if (!listView.equals(that.listView)) {
return false;
}
@AutoValue
public abstract class OnListViewScrollEvent {
public abstract AbsListView listView();
public abstract int scrollState();
public abstract int firstVisibleItem();
public abstract int visibleItemCount();
public abstract int totalItemCount();

return true;
}

@Override
public int hashCode() {
int result = listView.hashCode();
result = 31 * result + scrollState;
result = 31 * result + firstVisibleItem;
result = 31 * result + visibleItemCount;
result = 31 * result + totalItemCount;
return result;
public static OnListViewScrollEvent create(
AbsListView listView, int scrollState, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
return new AutoValue_OnListViewScrollEvent(listView, scrollState, firstVisibleItem, visibleItemCount, totalItemCount);
}

@Override
public String toString() {
return "OnListViewScrollEvent{" +
"listView=" + listView +
", scrollState=" + scrollState +
", firstVisibleItem=" + firstVisibleItem +
", visibleItemCount=" + visibleItemCount +
", totalItemCount=" + totalItemCount +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void call(final Subscriber<? super OnItemClickEvent> observer) {
final AbsListView.OnItemClickListener listener = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
observer.onNext(new OnItemClickEvent(parent, view, position, id));
observer.onNext(OnItemClickEvent.create(parent, view, position, id));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void call(final Subscriber<? super OnCheckedChangeEvent> observer) {
final CompoundButton.OnCheckedChangeListener listener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton view, final boolean checked) {
observer.onNext(new OnCheckedChangeEvent(button, checked));
observer.onNext(OnCheckedChangeEvent.create(button, checked));
}
};

Expand All @@ -57,7 +57,7 @@ public void call() {
});

if (emitInitialValue) {
observer.onNext(new OnCheckedChangeEvent(button));
observer.onNext(OnCheckedChangeEvent.create(button));
}

composite.addOnCheckedChangeListener(listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void onScrollStateChanged(AbsListView view, int scrollState) {

@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
OnListViewScrollEvent event = new OnListViewScrollEvent(view, this.currentScrollState, firstVisibleItem,
OnListViewScrollEvent event = OnListViewScrollEvent.create(view, this.currentScrollState, firstVisibleItem,
visibleItemCount, totalItemCount);
observer.onNext(event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void call(final Subscriber<? super OnTextChangeEvent> observer) {
final TextWatcher watcher = new SimpleTextWatcher() {
@Override
public void afterTextChanged(final Editable editable) {
observer.onNext(new OnTextChangeEvent(input));
observer.onNext(OnTextChangeEvent.create(input));
}
};

Expand All @@ -50,7 +50,7 @@ public void call() {
});

if (emitInitialValue) {
observer.onNext(new OnTextChangeEvent(input));
observer.onNext(OnTextChangeEvent.create(input));
}

input.addTextChangedListener(watcher);
Expand Down
18 changes: 10 additions & 8 deletions rxandroid/src/main/java/rx/android/widget/OnTextChangeEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
import android.text.SpannableString;
import android.widget.TextView;

public class OnTextChangeEvent {
public final TextView view;
public final CharSequence text;
import com.google.auto.value.AutoValue;

public OnTextChangeEvent(final TextView view) {
this(view, new SpannableString(view.getText()));
@AutoValue
public abstract class OnTextChangeEvent {
public abstract TextView view();
public abstract CharSequence text();

public static OnTextChangeEvent create(final TextView view) {
return create(view, new SpannableString(view.getText()));
}

public OnTextChangeEvent(final TextView view, final CharSequence text) {
this.view = view;
this.text = text;
public static OnTextChangeEvent create(final TextView view, final CharSequence text) {
return new AutoValue_OnTextChangeEvent(view, text);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
@RunWith(RobolectricTestRunner.class)
public class OperatorViewClickTest {
private static OnClickEvent mkMockedEvent(final View view) {
return refEq(new OnClickEvent(view));
return refEq(OnClickEvent.create(view));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,9 @@ private void performTestAdapterViewClickAllViewsEmitAllEvents(AdapterView<? exte
final InOrder inOrder = inOrder(observer);

for (int i = 0; i < adapter.getCount(); i++) {
adapterView.performItemClick(any(View.class), i, i);
inOrder.verify(observer, times(1)).onNext(new OnItemClickEvent(adapterView, any(View.class), i, i));
View fakeItem = new View(adapterView.getContext());
adapterView.performItemClick(fakeItem, i, i);
inOrder.verify(observer, times(1)).onNext(OnItemClickEvent.create(adapterView, fakeItem, i, i));
}

subscription.unsubscribe();
Expand Down Expand Up @@ -313,9 +314,10 @@ private void performTestAdapterViewMultipleSubscriptionsClickAllViewsEmitAllEven

final int count = adapter.getCount();
for (int i = 0; i < count; i++) {
adapterView.performItemClick(any(View.class), i, i);
inOrder1.verify(observer1, times(1)).onNext(new OnItemClickEvent(adapterView, any(View.class), i, i));
inOrder2.verify(observer2, times(1)).onNext(new OnItemClickEvent(adapterView, any(View.class), i, i));
View fakeItem = new View(adapterView.getContext());
adapterView.performItemClick(fakeItem, i, i);
inOrder1.verify(observer1, times(1)).onNext(OnItemClickEvent.create(adapterView, fakeItem, i, i));
inOrder2.verify(observer2, times(1)).onNext(OnItemClickEvent.create(adapterView, fakeItem, i, i));
}

subscription1.unsubscribe();
Expand All @@ -342,9 +344,10 @@ private void performTestAdapterViewMultipleSubscriptionsClickAllViewsEmitAllEven

final int count = adapter.getCount();
for (int i = 0; i < count; i++) {
adapterView.performItemClick(any(View.class), i, i);
View fakeItem = new View(adapterView.getContext());
adapterView.performItemClick(fakeItem, i, i);
inOrder1.verify(observer1, never()).onNext(any(OnItemClickEvent.class));
inOrder2.verify(observer2, times(1)).onNext(new OnItemClickEvent(adapterView, any(View.class), i, i));
inOrder2.verify(observer2, times(1)).onNext(OnItemClickEvent.create(adapterView, fakeItem, i, i));
}
subscription2.unsubscribe();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@RunWith(RobolectricTestRunner.class)
public class OperatorCompoundButtonInputTest {
private static OnCheckedChangeEvent mkMockedEvent(final CompoundButton button, final boolean value) {
return refEq(new OnCheckedChangeEvent(button, value));
return refEq(OnCheckedChangeEvent.create(button, value));
}

private static CompoundButton mkCompoundButton(final boolean value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public boolean matches(final Object argument) {

final OnTextChangeEvent event = (OnTextChangeEvent) argument;

if (event.view != view) {
if (event.view() != view) {
return false;
}

return TextUtils.equals(event.text, text);
return TextUtils.equals(event.text(), text);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
.subscribe(new Action1<OnListViewScrollEvent>() {
@Override
public void call(OnListViewScrollEvent event) {
if (event.totalItemCount == 0) {
if (event.totalItemCount() == 0) {
return;
}

int progress =
(int) ((100.0 * (event.firstVisibleItem + event.visibleItemCount)) / event.totalItemCount);
(int) ((100.0 * (event.firstVisibleItem() + event.visibleItemCount())) / event.totalItemCount());
progressBar.setProgress(progress);
}
});
Expand Down