Skip to content

Commit

Permalink
Optimizations & fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrivoruchko committed Nov 19, 2017
1 parent f24eb4a commit c028fa9
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 21 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ Version 2.x based on Clean Architecture, Android Architecture Components (ViewMo
* [Koin](https://github.com/Ekito/koin)
* [RxJava 1.x](https://github.com/ReactiveX/RxJava/tree/1.x)
* [RxAndroid](https://github.com/ReactiveX/RxAndroid/tree/1.x)
* [RxBinding](https://github.com/JakeWharton/RxBinding/tree/version-one)
* [RxNetty](https://github.com/ReactiveX/RxNetty)
* [RxBroadcast](https://github.com/cantrowitz/RxBroadcast)
* [MaterialDrawer](https://github.com/mikepenz/MaterialDrawer)
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dependencies {
implementation "com.github.iamironz:binaryprefs:$binaryprefs_version"

implementation 'com.cantrowitz:rxbroadcast:1.1.2'
implementation("com.mikepenz:materialdrawer:6.0.1@aar") {
implementation("com.mikepenz:materialdrawer:6.0.2@aar") {
transitive = true
}
implementation 'com.tapadoo.android:alerter:2.0.1'
Expand Down
8 changes: 3 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
buildscript {
ext {
kotlin_version = '1.2.0-rc-39'
build_tools = '27.0.0'
kotlin_version = '1.1.60'
build_tools = '27.0.1'
compile_sdk = 27
min_sdk = 21
target_sdk = 27

version_code = 213
version_name = '2.1.3'

support_version = '27.0.0'
support_version = '27.0.1'
lifecycle_version = '1.0.0'
koin_version = '0.5.2'
rxjava_version = '1.3.3'
Expand All @@ -23,7 +23,6 @@ buildscript {
google()
jcenter()
maven { url "https://maven.fabric.io/public" }
maven { url "http://dl.bintray.com/kotlin/kotlin-eap-1.2" }
}

dependencies {
Expand All @@ -39,7 +38,6 @@ allprojects {
jcenter()
maven { url "https://jitpack.io" }
maven { url 'https://maven.fabric.io/public' }
maven { url "http://dl.bintray.com/kotlin/kotlin-eap-1.2" }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface ImageGenerator {
fun create(display: Display,
mediaProjection: MediaProjection,
scheduler: Scheduler,
event: (event: ImageGeneratorEvent) -> Unit): ImageGenerator
event: ImageGeneratorEvent.() -> Unit): ImageGenerator
}

fun setImageResizeFactor(@IntRange(from = 1, to = 150) factor: Int): ImageGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ImageGeneratorImpl private constructor(
override fun create(display: Display,
mediaProjection: MediaProjection,
scheduler: Scheduler,
event: (event: ImageGeneratorEvent) -> Unit): ImageGenerator =
event: ImageGeneratorEvent.() -> Unit): ImageGenerator =
ImageGeneratorImpl(display, mediaProjection, scheduler, event)

const val STATE_INIT = "STATE_INIT"
Expand All @@ -53,8 +53,8 @@ class ImageGeneratorImpl private constructor(
private val imageThread: HandlerThread by lazy { HandlerThread("ImageGenerator", THREAD_PRIORITY_BACKGROUND) }
private val imageThreadHandler: Handler by lazy { Handler(imageThread.looper) }
private val imageListener: AtomicReference<ImageListener?> = AtomicReference()
private lateinit var imageReader: ImageReader
private lateinit var virtualDisplay: VirtualDisplay
private var imageReader: ImageReader? = null
private var virtualDisplay: VirtualDisplay? = null

private val subscriptions = CompositeSubscription()

Expand Down Expand Up @@ -118,13 +118,13 @@ class ImageGeneratorImpl private constructor(
val screenSize = Point().also { display.getRealSize(it) }
imageListener.set(ImageListener())
imageReader = ImageReader.newInstance(screenSize.x, screenSize.y, PixelFormat.RGBA_8888, 2)
imageReader.setOnImageAvailableListener(imageListener.get(), imageThreadHandler)
.apply { setOnImageAvailableListener(imageListener.get(), imageThreadHandler) }

try {
val densityDpi = DisplayMetrics().also { display.getMetrics(it) }.densityDpi
virtualDisplay = mediaProjection.createVirtualDisplay("ScreenStreamVirtualDisplay",
screenSize.x, screenSize.y, densityDpi,
DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, imageReader.surface, null, null)
DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, imageReader?.surface, null, null)
state.set(STATE_STARTED)
} catch (ex: SecurityException) {
state.set(STATE_ERROR)
Expand All @@ -133,8 +133,8 @@ class ImageGeneratorImpl private constructor(
}

private fun stopDisplayCapture() {
if (::virtualDisplay.isInitialized) virtualDisplay.release()
imageReader.close()
virtualDisplay?.release()
imageReader?.close()
imageListener.get()?.close()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ class FgPresenter constructor(private val settings: Settings,
}

is FgView.FromEvent.StartImageGenerator -> {
imageGenerator = ImageGeneratorImpl.create(fromEvent.display, fromEvent.mediaProjection, eventScheduler) { igEvent ->
when (igEvent) {
imageGenerator = ImageGeneratorImpl.create(fromEvent.display, fromEvent.mediaProjection, eventScheduler) {
when (this) {
is ImageGenerator.ImageGeneratorEvent.OnError -> {
eventBus.sendEvent(EventBus.GlobalEvent.Error(igEvent.error))
Timber.e(igEvent.error, "ImageGenerator: ERROR")
eventBus.sendEvent(EventBus.GlobalEvent.Error(error))
Timber.e(error, "ImageGenerator: ERROR")
}

is ImageGenerator.ImageGeneratorEvent.OnJpegImage -> {
jpegBytesStream.call(igEvent.image)
jpegBytesStream.call(image)
}
}
}.apply {
Expand Down
1 change: 0 additions & 1 deletion domain/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
apply plugin: 'java-library'
apply plugin: 'kotlin'

sourceCompatibility = "1.8"
Expand Down

0 comments on commit c028fa9

Please sign in to comment.