Skip to content
This repository was archived by the owner on Jul 17, 2019. It is now read-only.
Open
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
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.1.1'
classpath 'com.novoda:bintray-release:0.7.0'

// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -16,8 +16,8 @@ buildscript {

allprojects {
ext {
compileSdkVersion = 26
buildToolVersion = '26.0.2'
compileSdkVersion = 27
buildToolVersion = '27.0.3'
minSdkVersion = 14

//publish
Expand All @@ -43,7 +43,7 @@ allprojects {
kotlinAndroidExtensions = "org.jetbrains.kotlin:kotlin-android-extensions:$kotlinVersion"

//android
supportVersion = '26.1.0'
supportVersion = '27.1.1'
androidSupportAnnotation = "com.android.support:support-annotations:$supportVersion"
androidSupportV4 = "com.android.support:support-v4:$supportVersion"
androidAppCompatV7 = "com.android.support:appcompat-v7:$supportVersion"
Expand Down
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Fri Apr 20 12:48:16 ICT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class RecyclerViewTestActivity : Activity() {

override fun getItemCount(): Int = 1

override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder =
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder =
object : RecyclerView.ViewHolder(child) {}

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ class RecyclerViewTest {
fun adapter() {
val expected = object : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

override fun onBindViewHolder(holder: RecyclerView.ViewHolder?, position: Int) {
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
}

override fun getItemCount(): Int = 1

override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder =
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder =
object : RecyclerView.ViewHolder(View(instrumentation.context)) {}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract class RecyclerViewProxyAdapter<T, VH : RecyclerView.ViewHolder> : Recyc
fun getItem(position: Int) = items[position]
operator fun get(position: Int) = items[position]

override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): VH = createViewHolder.invoke(parent, viewType)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH = createViewHolder.invoke(parent, viewType)

override fun onBindViewHolder(viewHolder: VH, position: Int) {
bindViewHolder.invoke(viewHolder, position, items[position])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ interface SectionModelType<T> {

class SimpleSection<T>(val name: String, override var items: List<T>) : SectionModelType<T>

fun<T, X> List<T>.mapToSection(sectionName: (T) -> X): List<SimpleSection<T>> = groupBy { sectionName(it) }.mapTo(mutableListOf()) {
fun <T, X> List<T>.mapToSection(sectionName: (T) -> X): List<SimpleSection<T>> = groupBy { sectionName(it) }.mapTo(mutableListOf()) {
SimpleSection(it.key.toString(), it.value)
}

fun<T, X> Observable<List<T>>.mapToSection(sectionName: (T) -> X): Observable<List<SimpleSection<T>>> = map { it.mapToSection(sectionName) }
fun <T, X> Observable<List<T>>.mapToSection(sectionName: (T) -> X): Observable<List<SimpleSection<T>>> = map { it.mapToSection(sectionName) }

val SECTION_HEADER_VIEW_TYPE = 1000
val SECTION_ITEM_VIEW_TYPE = 1001
Expand Down Expand Up @@ -66,7 +66,7 @@ abstract class SectionedRecyclerViewProxyAdapter<T, S : SectionModelType<T>, VH
//add upperbound to support last item
_headerPositions.add(Int.MAX_VALUE)

for (index in 0.._headerPositions.size - 1) {
for (index in 0 until _headerPositions.size) {
val headerPosition = _headerPositions[index]
if (headerPosition > position) {
val previousIndex = index - 1
Expand All @@ -79,7 +79,7 @@ abstract class SectionedRecyclerViewProxyAdapter<T, S : SectionModelType<T>, VH
return null
}

override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): VH = createViewHolder.invoke(parent, viewType)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH = createViewHolder.invoke(parent, viewType)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ internal class _DrawerLayout_DrawerListener : DrawerLayout.DrawerListener {
onDrawerClosed = listener
}

override fun onDrawerClosed(drawerView: View?) {
override fun onDrawerClosed(drawerView: View) {
onDrawerClosed?.invoke(drawerView)
}

Expand All @@ -93,15 +93,15 @@ internal class _DrawerLayout_DrawerListener : DrawerLayout.DrawerListener {
onDrawerSlide = listener
}

override fun onDrawerSlide(drawerView: View?, slideOffset: Float) {
override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
onDrawerSlide?.invoke(drawerView, slideOffset)
}

fun onDrawerOpened(listener: (View?) -> Unit) {
onDrawerOpened = listener
}

override fun onDrawerOpened(drawerView: View?) {
override fun onDrawerOpened(drawerView: View) {
onDrawerOpened?.invoke(drawerView)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ val DrawerLayout.rx_drawerElevation: MutableProperty<Float>
return createMainThreadMutableProperty(getter, setter)
}

val DrawerLayout.rx_statusBarBackground: MutableProperty<Drawable>
val DrawerLayout.rx_statusBarBackground: MutableProperty<Drawable?>
get() {
val getter = { statusBarBackgroundDrawable }
val setter: (Drawable) -> Unit = { setStatusBarBackground(it) }
val setter: (Drawable?) -> Unit = { setStatusBarBackground(it) }

return createMainThreadMutableProperty(getter, setter)
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,23 @@ internal class _SlidingPaneLayout_PanelSlideListener : SlidingPaneLayout.PanelSl
onPanelSlide = listener
}

override fun onPanelSlide(panel: View?, slideOffset: Float) {
override fun onPanelSlide(panel: View, slideOffset: Float) {
onPanelSlide?.invoke(panel, slideOffset)
}

fun onPanelClosed(listener: (View?) -> Unit) {
onPanelClosed = listener
}

override fun onPanelClosed(panel: View?) {
override fun onPanelClosed(panel: View) {
onPanelClosed?.invoke(panel)
}

fun onPanelOpened(listener: (View?) -> Unit) {
onPanelOpened = listener
}

override fun onPanelOpened(panel: View?) {
override fun onPanelOpened(panel: View) {
onPanelOpened?.invoke(panel)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.github.kittinunf.reactiveandroid.reactive

import com.github.kittinunf.reactiveandroid.MutablePropertyType
import io.reactivex.Flowable
import io.reactivex.disposables.Disposable

fun <T : R, R> Flowable<T>.bindTo(property: MutablePropertyType<R>): Disposable {
return subscribe {
property.value = it
}
}

fun <T> Flowable<T>.cachedPrevious(): Flowable<Pair<T?, T?>> {
return scan(Pair<T?, T?>(null, null)) { (_, j), item -> j to item }
.skip(1)
}

inline fun <reified T> Flowable<in T>.ofType() = ofType(T::class.java)
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.github.kittinunf.reactiveandroid

import com.github.kittinunf.reactiveandroid.reactive.cachedPrevious
import io.reactivex.Flowable
import org.hamcrest.CoreMatchers
import org.junit.Assert
import org.junit.Test

class FlowableExtension {

@Test
fun cachedPreviousWithInt() {
val ints = Flowable.just(1, 2, 3, 4)
val test = ints.cachedPrevious().test()

Assert.assertThat(test.valueCount(), CoreMatchers.equalTo(4))
val values = test.values()
Assert.assertThat(values[0].second, CoreMatchers.equalTo(1))
Assert.assertThat(values[1] as Pair<Int, Int>, CoreMatchers.equalTo(1 to 2))
Assert.assertThat(values[2] as Pair<Int, Int>, CoreMatchers.equalTo(2 to 3))
Assert.assertThat(values[3] as Pair<Int, Int>, CoreMatchers.equalTo(3 to 4))
}

@Test
fun cachedPreviousWithList() {
val lists = Flowable.just(emptyList(), listOf(1, 2, 3), listOf(1, 2, 3, 4, 5))

val test = lists.cachedPrevious().test()

Assert.assertThat(test.valueCount(), CoreMatchers.equalTo(3))

val values = test.values()
Assert.assertThat(values[0].second, CoreMatchers.equalTo(emptyList()))
Assert.assertThat(values[1] as Pair<List<Int>, List<Int>>, CoreMatchers.equalTo(emptyList<Int>() to listOf(1, 2, 3)))
Assert.assertThat(values[2] as Pair<List<Int>, List<Int>>, CoreMatchers.equalTo(listOf(1, 2, 3) to listOf(1, 2, 3, 4, 5)))
}

@Test
fun cachedPreviousWithListOneItem() {
val list = Flowable.just(listOf(1, 2, 3))

val test = list.cachedPrevious().test()

Assert.assertThat(test.valueCount(), CoreMatchers.equalTo(1))
}
}
24 changes: 14 additions & 10 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ android {
minSdkVersion parent.ext.minSdkVersion
targetSdkVersion parent.ext.compileSdkVersion
versionCode 1

multiDexEnabled true
}

sourceSets {
Expand Down Expand Up @@ -40,14 +42,17 @@ android {
}

dependencies {
compile parent.ext.kotlinStdLib
compile parent.ext.androidAppCompatV7

compile project(':reactiveandroid-ui')
compile project(':reactiveandroid-appcompat-v7')
compile project(':reactiveandroid-support-v4')
compile project(':reactiveandroid-design')
compile 'com.android.support.constraint:constraint-layout:1.0.2'
implementation parent.ext.kotlinStdLib
implementation parent.ext.androidSupportV4
implementation parent.ext.androidAppCompatV7
implementation parent.ext.androidSupportAnnotation

implementation project(':reactiveandroid-ui')
implementation project(':reactiveandroid-appcompat-v7')
implementation project(':reactiveandroid-support-v4')
implementation project(':reactiveandroid-design')
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:multidex:1.0.3'
}

buildscript {
Expand All @@ -59,5 +64,4 @@ buildscript {
classpath parent.ext.kotlinGradlePlugin
classpath parent.ext.kotlinAndroidExtensions
}
}

}
26 changes: 9 additions & 17 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,41 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.kittinunf.reactiveandroid.sample"
>
package="com.github.kittinunf.reactiveandroid.sample">

<application
android:name="android.support.multidex.MultiDexApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
>
<activity
android:name=".view.LandingActivity">
android:theme="@style/AppTheme">
<activity android:name=".view.LandingActivity">
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.MAIN"/>-->
<!--<category android:name="android.intent.category.LAUNCHER"/>-->
<!--</intent-filter>-->
</activity>

<activity
android:name=".view.AddingNumbersActivity"
>
<activity android:name=".view.AddingNumbersActivity">

</activity>

<activity
android:name=".view.LoginActivity"
>
<activity android:name=".view.LoginActivity">

</activity>

<activity
android:name=".view.RecyclerViewActivity"
>
<activity android:name=".view.RecyclerViewActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class PlaceholderFragment : Fragment() {
return inflater.inflate(R.layout.fragment_place_holder, container, false)
}

override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
tvName.text = arguments.getString(ARG_SECTION_NAME, "")
tvName.text = arguments?.getString(ARG_SECTION_NAME, "")
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class ViewPagerFragment : Fragment() {
return inflater.inflate(R.layout.fragment_view_pager, container, false)
}

override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

viewPager.rx_fragmentsStateWith(Observable.just(listOf("section1", "section2", "section3")), fragmentManager,
viewPager.rx_fragmentsStateWith(Observable.just(listOf("section1", "section2", "section3")), fragmentManager!!,
{ position, item ->
PlaceholderFragment.newInstance(item)
},
Expand Down