Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
wei.mao committed Feb 18, 2019
1 parent d3ad580 commit 106f415
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 29 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.cdts.oreo.ui.view.actionsheet

import android.Manifest
import android.content.Intent
import android.support.test.InstrumentationRegistry
import android.support.test.rule.ActivityTestRule
import android.support.test.rule.GrantPermissionRule
import android.support.test.runner.AndroidJUnit4
import com.cdts.oreo.BaseTestCase
import com.cdts.oreo.test.MainTestActivity
import com.cdts.oreo.ui.router.ORRouter
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith


@RunWith(AndroidJUnit4::class)
class ORPhtoActionSheetTests: BaseTestCase() {
@get:Rule
var activityRule: ActivityTestRule<MainTestActivity> = ActivityTestRule(MainTestActivity::class.java,true,false)

@get:Rule
val permissionRuleCamera = GrantPermissionRule.grant(Manifest.permission.CAMERA)
@get:Rule
val permissionRuleWriteExternalStorage = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE)

@Test
fun testActionSheet() {

val context = InstrumentationRegistry.getInstrumentation().targetContext
activityRule.launchActivity(Intent(context, MainTestActivity::class.java))

GlobalScope.launch(Dispatchers.Main) {
val dialog = ORPhotoActionSheet.showPhoto(ORRouter.topActivity()) {_,_,_ ->}
delay(2000)
dialog.dismiss()
delay(1000)
ORPhotoActionSheet.showCamera(ORRouter.topActivity()) {_,_,_ ->}
delay(1000)
signal()
}

await()

val intent = Intent(context, MainTestActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
ORRouter.topActivity().startActivity(intent)

GlobalScope.launch(Dispatchers.Main) {
delay(1000)
ORPhotoActionSheet.showFile(ORRouter.topActivity()) {_,_,_ ->}
delay(1000)
signal()
}

await()

ORRouter.topActivity().startActivity(intent)

GlobalScope.launch(Dispatchers.Main) {
delay(1000)
ORPhotoActionSheet.showLibrary(ORRouter.topActivity()) {_,_,_ ->}
delay(1000)
signal()
}

await()

val intent2 = Intent(context, MainTestActivity::class.java)
intent2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
ORRouter.topActivity().startActivity(intent2)

GlobalScope.launch(Dispatchers.Main) {
delay(1000)
signal()
}

await()
}
}
3 changes: 2 additions & 1 deletion oreo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">

<activity android:name=".test.MainTestActivity"></activity>
<activity android:name=".test.MainTestActivity" android:launchMode="singleTask"></activity>
<activity android:name=".test.TestParamsActivity"></activity>
<activity android:name=".test.TestWebViewActivity"></activity>

Expand All @@ -14,4 +14,5 @@
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
</manifest>
12 changes: 8 additions & 4 deletions oreo/src/main/java/com/cdts/oreo/data/permission/ORPermission.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ object ORPermission {
val rxPermissions = RxPermissions(ORRouter.topActivity())
if (Looper.getMainLooper() != Looper.myLooper()) {
ORRouter.topActivity().runOnUiThread {
rxPermissions.request(*perms).subscribe { granted ->
rxPermissions.request(*perms).subscribe ({ granted ->
complete(granted)
}
}, {
complete(false)
})
}
} else {
rxPermissions.request(*perms).subscribe { granted ->
rxPermissions.request(*perms).subscribe ({ granted ->
complete(granted)
}
}, {
complete(false)
})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,6 @@ import io.reactivex.Observable
open class ORBaseViewModel: ViewModel() {

companion object {

@Suppress("UNCHECKED_CAST")
inline fun<reified V: ViewModel, R> createViewModel(activity: FragmentActivity, repository: R, crossinline factory: (R) -> V): V {
return ViewModelProviders.of(activity, object: ViewModelProvider.Factory {
override fun <T: ViewModel?> create(modelClass: Class<T>): T {
return factory(repository) as T
}
}).get(V::class.java)
}
@Suppress("UNCHECKED_CAST")
inline fun<reified V: ViewModel, R> createViewModel(fragment: Fragment, repository: R, crossinline factory: (R) -> V): V {
return ViewModelProviders.of(fragment, object: ViewModelProvider.Factory {
override fun <T: ViewModel?> create(modelClass: Class<T>): T {
return factory(repository) as T
}
}).get(V::class.java)
}
@Suppress("UNCHECKED_CAST")
inline fun<reified V: ViewModel> createViewModel(activity: FragmentActivity, crossinline factory: () -> V): V {
return ViewModelProviders.of(activity, object: ViewModelProvider.Factory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object ORPhotoActionSheet {
private const val REQUEST_CODE_CAMERA = 0xa1
private const val REQUEST_CODE_FILE = 0xa2

fun showPhoto(activity: Activity, completion: (success: Boolean, uri: Uri?, error: ORError?) -> Unit) {
fun showPhoto(activity: Activity, completion: (success: Boolean, uri: Uri?, error: ORError?) -> Unit): ActionSheetDialog {

val items = arrayOf("Camera", "Image Library")
val dialog = ActionSheetDialog(ORRouter.topActivity(), items, null)
Expand All @@ -47,6 +47,7 @@ object ORPhotoActionSheet {
}
dialog.dismiss()
}
return dialog
}

fun showCamera(activity: Activity, completion: (success: Boolean, uri: Uri?, error: ORError?) -> Unit) {
Expand Down

0 comments on commit 106f415

Please sign in to comment.