Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NTV-572 :Migrate WebViewViewModel/DownloadBetaViewModel/HelpViewModel…
… related classes to kotlin (#1652) * Rename .java to .kt * Migrate Classes * Add test cases Co-authored-by: Isabel Martin <arkariang@gmail.com>
- Loading branch information
Showing
9 changed files
with
154 additions
and
142 deletions.
There are no files selected for viewing
35 changes: 0 additions & 35 deletions
35
app/src/main/java/com/kickstarter/viewmodels/DownloadBetaViewModel.java
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/kickstarter/viewmodels/DownloadBetaViewModel.kt
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,29 @@ | ||
package com.kickstarter.viewmodels | ||
|
||
import com.kickstarter.libs.ActivityViewModel | ||
import com.kickstarter.libs.Environment | ||
import com.kickstarter.services.apiresponses.InternalBuildEnvelope | ||
import com.kickstarter.ui.IntentKey | ||
import com.kickstarter.ui.activities.DownloadBetaActivity | ||
import com.kickstarter.viewmodels.inputs.DownloadBetaViewModelInputs | ||
import com.kickstarter.viewmodels.outputs.DownloadBetaViewModelOutputs | ||
import rx.Observable | ||
import rx.subjects.BehaviorSubject | ||
|
||
class DownloadBetaViewModel(environment: Environment) : | ||
ActivityViewModel<DownloadBetaActivity>(environment), | ||
DownloadBetaViewModelInputs, | ||
DownloadBetaViewModelOutputs { | ||
|
||
val outputs: DownloadBetaViewModelOutputs = this | ||
private val internalBuildEnvelope = BehaviorSubject.create<InternalBuildEnvelope>() | ||
|
||
init { | ||
intent() | ||
.map<InternalBuildEnvelope> { it.getParcelableExtra(IntentKey.INTERNAL_BUILD_ENVELOPE) } | ||
.ofType(InternalBuildEnvelope::class.java) | ||
.compose(bindToLifecycle()) | ||
.subscribe(internalBuildEnvelope) | ||
} | ||
override fun internalBuildEnvelope(): Observable<InternalBuildEnvelope> = internalBuildEnvelope | ||
} |
13 changes: 0 additions & 13 deletions
13
app/src/main/java/com/kickstarter/viewmodels/HelpViewModel.java
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/kickstarter/viewmodels/HelpViewModel.kt
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,7 @@ | ||
package com.kickstarter.viewmodels | ||
|
||
import com.kickstarter.libs.ActivityViewModel | ||
import com.kickstarter.libs.Environment | ||
import com.kickstarter.ui.activities.HelpActivity | ||
|
||
class HelpViewModel(environment: Environment) : ActivityViewModel<HelpActivity>(environment) |
52 changes: 0 additions & 52 deletions
52
app/src/main/java/com/kickstarter/viewmodels/WebViewViewModel.java
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
app/src/main/java/com/kickstarter/viewmodels/WebViewViewModel.kt
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,50 @@ | ||
package com.kickstarter.viewmodels | ||
|
||
import com.kickstarter.libs.ActivityViewModel | ||
import com.kickstarter.libs.Environment | ||
import com.kickstarter.ui.IntentKey | ||
import com.kickstarter.ui.activities.WebViewActivity | ||
import rx.Observable | ||
import rx.subjects.BehaviorSubject | ||
|
||
interface WebViewViewModel { | ||
interface Outputs { | ||
/** Emits a string to display in the toolbar. */ | ||
fun toolbarTitle(): Observable<String> | ||
|
||
/** Emits a URL to load in the web view. */ | ||
fun url(): Observable<String> | ||
} | ||
|
||
class ViewModel(environment: Environment) : | ||
ActivityViewModel<WebViewActivity >(environment), | ||
Outputs { | ||
|
||
private val toolbarTitle = BehaviorSubject.create<String>() | ||
private val url = BehaviorSubject.create<String>() | ||
|
||
val outputs: Outputs = this | ||
|
||
override fun toolbarTitle(): Observable<String> { | ||
return toolbarTitle | ||
} | ||
|
||
override fun url(): Observable<String> { | ||
return url | ||
} | ||
|
||
init { | ||
intent() | ||
.map { it.getStringExtra(IntentKey.TOOLBAR_TITLE) } | ||
.ofType(String::class.java) | ||
.compose(bindToLifecycle()) | ||
.subscribe { toolbarTitle.onNext(it) } | ||
|
||
intent() | ||
.map { it.getStringExtra(IntentKey.URL) } | ||
.ofType(String::class.java) | ||
.compose(bindToLifecycle()) | ||
.subscribe { url.onNext(it) } | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/test/java/com/kickstarter/viewmodels/DownloadBetaViewModelTest.kt
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,29 @@ | ||
package com.kickstarter.viewmodels | ||
|
||
import android.content.Intent | ||
import com.kickstarter.KSRobolectricTestCase | ||
import com.kickstarter.services.apiresponses.InternalBuildEnvelope | ||
import com.kickstarter.ui.IntentKey | ||
import org.junit.Test | ||
import rx.observers.TestSubscriber | ||
|
||
class DownloadBetaViewModelTest : KSRobolectricTestCase() { | ||
|
||
private lateinit var vm: DownloadBetaViewModel | ||
private val internalBuildEnvelope = TestSubscriber<InternalBuildEnvelope>() | ||
|
||
fun setUpEnvironment() { | ||
vm = DownloadBetaViewModel(environment()) | ||
vm.outputs.internalBuildEnvelope().subscribe(internalBuildEnvelope) | ||
} | ||
|
||
@Test | ||
fun testInternalBuildEnvelope() { | ||
setUpEnvironment() | ||
|
||
val internalEnvelope = InternalBuildEnvelope.builder().newerBuildAvailable(true).build() | ||
vm.intent(Intent().putExtra(IntentKey.INTERNAL_BUILD_ENVELOPE, internalEnvelope)) | ||
|
||
internalBuildEnvelope.assertValueCount(1) | ||
} | ||
} |
42 changes: 0 additions & 42 deletions
42
app/src/test/java/com/kickstarter/viewmodels/WebViewViewModelTest.java
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
app/src/test/java/com/kickstarter/viewmodels/WebViewViewModelTest.kt
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,39 @@ | ||
package com.kickstarter.viewmodels | ||
|
||
import android.content.Intent | ||
import com.kickstarter.KSRobolectricTestCase | ||
import com.kickstarter.libs.Environment | ||
import com.kickstarter.ui.IntentKey | ||
import org.junit.Test | ||
import rx.observers.TestSubscriber | ||
|
||
class WebViewViewModelTest : KSRobolectricTestCase() { | ||
private lateinit var vm: WebViewViewModel.ViewModel | ||
private val toolbarTitle = TestSubscriber<String>() | ||
private val url = TestSubscriber<String>() | ||
|
||
private fun setUpEnvironment(environment: Environment) { | ||
vm = WebViewViewModel.ViewModel(environment) | ||
|
||
vm.outputs.toolbarTitle().subscribe(toolbarTitle) | ||
vm.outputs.url().subscribe(url) | ||
} | ||
|
||
@Test | ||
fun testToolbarTitle() { | ||
val toolbarTitle = "some body once told me" | ||
setUpEnvironment(environment()) | ||
|
||
vm.intent(Intent().putExtra(IntentKey.TOOLBAR_TITLE, toolbarTitle)) | ||
this.toolbarTitle.assertValues(toolbarTitle) | ||
} | ||
|
||
@Test | ||
fun testUrl() { | ||
val url = "d.rip" | ||
setUpEnvironment(environment()) | ||
|
||
vm.intent(Intent().putExtra(IntentKey.URL, url)) | ||
this.url.assertValues(url) | ||
} | ||
} |