Skip to content

Commit

Permalink
refactor(options/storage): have mediaStorageLocation self-generate
Browse files Browse the repository at this point in the history
allow early access to the File that would otherwise not be ready until after the first
record()

Signed-off-by: Brandon McAnsh <[email protected]>
  • Loading branch information
bmc08gt committed Jul 24, 2020
1 parent b080054 commit b9f6909
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
15 changes: 1 addition & 14 deletions library/src/main/java/dev/bmcreations/scrcast/ScrCast.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,7 @@ class ScrCast private constructor(private val activity: Activity) {
}
}

private val outputDirectory: File?
get() {
val mediaStorageDir = options.storage.mediaStorageLocation
mediaStorageDir.apply {
if (!exists()) {
if (!mkdirs()) {
Log.d("scrcast", "failed to create designated output directory")
return null
}
}
}

return mediaStorageDir
}
private val outputDirectory: File? = options.storage.mediaStorageLocation

private var _outputFile: File? = null
private val outputFile: File?
Expand Down
17 changes: 16 additions & 1 deletion library/src/main/java/dev/bmcreations/scrcast/config/Options.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.os.Build
import android.os.Environment
import android.os.Parcelable
import android.util.DisplayMetrics
import android.util.Log
import kotlinx.android.parcel.Parcelize
import kotlinx.android.parcel.RawValue
import kotlin.jvm.functions.FunctionN
Expand Down Expand Up @@ -174,7 +175,21 @@ data class StorageConfig @JvmOverloads constructor(
* @see [directoryName]
*/
@IgnoredOnParcel
val mediaStorageLocation = File(directory, directoryName)
val mediaStorageLocation: File?
get() {
val location = File(directory, directoryName)
return with(location) {
apply {
if (!exists()) {
if (!mkdirs()) {
Log.d("scrcast", "failed to create designated output directory")
return@with null
}
}
return this
}
}
}
}

/**
Expand Down

0 comments on commit b9f6909

Please sign in to comment.