diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..17bc1fa
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,3 @@
+[*.kt]
+indent_size = 2
+continuation_indent_size=4
\ No newline at end of file
diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md
new file mode 100644
index 0000000..b7fb96a
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/Bug_report.md
@@ -0,0 +1,28 @@
+---
+name: Bug report
+about: Something is crashing or not working as intended
+
+---
+
+*Please consider making a Pull Request if you are capable of doing so.*
+
+**Library Version:**
+
+2.x.x
+
+**Affected Device(s):**
+
+Google Pixel 3 XL with Android 9.0
+
+**Describe the Bug:**
+
+A clear description of what is the bug is.
+
+**To Reproduce:**
+1.
+2.
+3.
+
+**Expected Behavior:**
+
+A clear description of what you expected to happen.
\ No newline at end of file
diff --git a/.github/ISSUE_TEMPLATE/Feature_request.md b/.github/ISSUE_TEMPLATE/Feature_request.md
new file mode 100644
index 0000000..3b3d325
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/Feature_request.md
@@ -0,0 +1,19 @@
+---
+name: Feature request
+about: Suggest an idea for this project
+
+---
+
+*Please consider making a Pull Request if you are capable of doing so.*
+
+**What module does this apply to?**
+
+Core? Input? Files? Color?
+
+**Description what you'd like to happen:**
+
+A clear description if the feature or behavior you'd like implemented.
+
+**Describe alternatives you've considered:**
+
+A clear description of any alternative solutions you've considered.
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
new file mode 100644
index 0000000..72058a1
--- /dev/null
+++ b/.github/pull_request_template.md
@@ -0,0 +1,8 @@
+### Guidelines
+
+1. You must run the `spotlessApply` task before commiting, either through Android Studio or with `./gradlew spotlessApply`.
+2. A PR should be focused and contained. If you are changing multiple unrelated things, they should be in separate PRs.
+3. A PR should fix a bug or solve a problem - something that only you would use is not necessarily something that should be published.
+4. Give your PR a detailed title and description - look over your code one last time before actually creating the PR. Give it a self-review.
+
+**If you do not follow the guidelines, your PR will be rejected.**
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..161128f
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,183 @@
+
+# Created by https://www.gitignore.io/api/android,intellij,osx,windows,gradle,java
+
+### Android ###
+# Built application files
+*.ap_
+
+# Files for the ART/Dalvik VM
+*.dex
+
+# Java class files
+*.class
+
+# Generated files
+bin/
+gen/
+out/
+
+# Gradle files
+.gradle/
+build/
+
+# Local configuration file (sdk path, etc)
+local.properties
+
+# Proguard folder generated by Eclipse
+proguard/
+
+# Log Files
+*.log
+
+# Android Studio Navigation editor temp files
+.navigation/
+
+# Android Studio captures folder
+captures/
+
+# Intellij
+*.iml
+.idea/workspace.xml
+.idea/libraries
+
+# Keystore files
+*.jks
+
+### Android Patch ###
+gen-external-apklibs
+
+
+### Intellij ###
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+
+# User-specific stuff:
+.idea/workspace.xml
+.idea/tasks.xml
+.idea/dictionaries
+.idea/vcs.xml
+.idea/jsLibraryMappings.xml
+
+# Sensitive or high-churn files:
+.idea/dataSources.ids
+.idea/dataSources.xml
+.idea/dataSources.local.xml
+.idea/sqlDataSources.xml
+.idea/dynamic.xml
+.idea/uiDesigner.xml
+
+# Gradle:
+.idea/gradle.xml
+.idea/libraries
+
+# Mongo Explorer plugin:
+.idea/mongoSettings.xml
+
+## File-based project format:
+*.iws
+
+## Plugin-specific files:
+
+# IntelliJ
+/out/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+
+### Intellij Patch ###
+# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
+
+# *.iml
+# modules.xml
+# .idea/misc.xml
+# *.ipr
+
+
+### OSX ###
+*.DS_Store
+.AppleDouble
+.LSOverride
+
+# Icon must end with two \r
+Icon
+
+
+# Thumbnails
+._*
+
+# Files that might appear in the root of a volume
+.DocumentRevisions-V100
+.fseventsd
+.Spotlight-V100
+.TemporaryItems
+.Trashes
+.VolumeIcon.icns
+.com.apple.timemachine.donotpresent
+
+# Directories potentially created on remote AFP share
+.AppleDB
+.AppleDesktop
+Network Trash Folder
+Temporary Items
+.apdisk
+
+
+### Windows ###
+# Windows image file caches
+Thumbs.db
+ehthumbs.db
+
+# Folder config file
+Desktop.ini
+
+# Recycle Bin used on file shares
+$RECYCLE.BIN/
+
+# Windows Installer files
+*.cab
+*.msi
+*.msm
+*.msp
+
+# Windows shortcuts
+*.lnk
+
+
+### Java ###
+*.class
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.war
+*.ear
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+
+
+### Gradle ###
+.gradle
+/build/
+
+# Ignore Gradle GUI config
+gradle-app.setting
+
+# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
+!gradle-wrapper.jar
+
+# Cache of project
+.gradletasknamecache
+
+# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
+# gradle/wrapper/gradle-wrapper.properties
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..56f4390
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,14 @@
+language: android
+jdk: oraclejdk8
+android:
+ components:
+ - tools
+ - platform-tools
+ - build-tools-28.0.3
+ - android-28
+ - extra-android-support
+ - extra-android-m2repository
+ - extra-google-m2repository
+
+ licenses:
+ - '.+'
\ No newline at end of file
diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644
index 0000000..a4eef3d
--- /dev/null
+++ b/LICENSE.md
@@ -0,0 +1,73 @@
+###### Apache License, Version 2.0 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/
+
+### TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+###### 1. Definitions.
+
+"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
+
+"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
+
+"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
+
+"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
+
+"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
+
+"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
+
+"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
+
+"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
+
+"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
+
+"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
+
+###### 2. Grant of Copyright License.
+
+Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
+
+###### 3. Grant of Patent License.
+
+Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
+
+###### 4. Redistribution.
+
+You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
+
+You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
+
+###### 5. Submission of Contributions.
+
+Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
+
+6. Trademarks.
+
+This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
+
+###### 7. Disclaimer of Warranty.
+
+Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
+
+###### 8. Limitation of Liability.
+
+In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
+
+###### 9. Accepting Warranty or Additional Liability.
+
+While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
+
+### END OF TERMS AND CONDITIONS
+
+### APPENDIX: How to apply the Apache License to your work
+
+To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
+
+### Copyright 2018 Aidan Follestad
+
+Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..885cbf5
--- /dev/null
+++ b/README.md
@@ -0,0 +1,14 @@
+[](https://travis-ci.org/afollestad/mnml)
+[](https://www.apache.org/licenses/LICENSE-2.0.html)
+[](https://www.codacy.com/app/drummeraidan_50/mnml?utm_source=github.com&utm_medium=referral&utm_content=afollestad/mnml&utm_campaign=Badge_Grade)
+
+# MNML
+
+MNML, pronounced "minimal", is a free and simple screen recorder for Android. There are too many
+screen recorders out there now that are badly designed, have too many unnecessary features,
+or have ads.
+
+**Redistributing this app as your own is NOT permitted.**
+
+
+
\ No newline at end of file
diff --git a/app/.gitignore b/app/.gitignore
new file mode 100644
index 0000000..796b96d
--- /dev/null
+++ b/app/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/app/build.gradle b/app/build.gradle
new file mode 100644
index 0000000..68fecf8
--- /dev/null
+++ b/app/build.gradle
@@ -0,0 +1,48 @@
+apply from: '../dependencies.gradle'
+apply plugin: 'com.android.application'
+apply plugin: 'kotlin-android'
+apply plugin: 'kotlin-kapt'
+apply plugin: 'kotlin-android-extensions'
+
+android {
+ compileSdkVersion versions.compileSdk
+ buildToolsVersion versions.buildTools
+
+ defaultConfig {
+ applicationId "com.afollestad.mnmlscreenrecord"
+ minSdkVersion versions.minSdk
+ targetSdkVersion versions.compileSdk
+ versionCode versions.publishVersionCode
+ versionName versions.publishVersion
+ }
+}
+
+dependencies {
+ implementation project(':engine')
+ implementation project(':common')
+ implementation project(':notifications')
+ implementation project(':theming')
+
+ kapt 'androidx.lifecycle:lifecycle-compiler:' + versions.lifecycle
+
+ implementation 'org.koin:koin-androidx-scope:' + versions.koin
+ implementation 'org.koin:koin-androidx-viewmodel:' + versions.koin
+
+ implementation 'com.afollestad.material-dialogs:core:' + versions.materialDialogs
+ implementation 'com.afollestad.material-dialogs:files:' + versions.materialDialogs
+ implementation 'com.afollestad:assent:' + versions.assent
+
+ implementation 'com.github.bumptech.glide:glide:' + versions.glide
+ kapt 'com.github.bumptech.glide:compiler:' + versions.glide
+
+ testImplementation 'junit:junit:' + versions.junit
+ testImplementation 'org.mockito:mockito-core:' + versions.mockito
+ testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:' + versions.mockitoKotlin
+ testImplementation 'com.google.truth:truth:' + versions.truth
+ testImplementation 'androidx.arch.core:core-testing:' + versions.archTesting
+
+ androidTestImplementation 'androidx.test:runner:' + versions.androidxTestRunner
+ androidTestImplementation 'androidx.test:rules:' + versions.androidxTestRunner
+}
+
+apply from: '../spotless.gradle'
\ No newline at end of file
diff --git a/app/release/release/app.aab b/app/release/release/app.aab
new file mode 100644
index 0000000..c3ac87c
Binary files /dev/null and b/app/release/release/app.aab differ
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..5c38166
--- /dev/null
+++ b/app/src/main/AndroidManifest.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/ic_launcher-web.png b/app/src/main/ic_launcher-web.png
new file mode 100644
index 0000000..e3e8380
Binary files /dev/null and b/app/src/main/ic_launcher-web.png differ
diff --git a/app/src/main/java/com/afollestad/mnmlscreenrecord/MainModule.kt b/app/src/main/java/com/afollestad/mnmlscreenrecord/MainModule.kt
new file mode 100644
index 0000000..c93ac0d
--- /dev/null
+++ b/app/src/main/java/com/afollestad/mnmlscreenrecord/MainModule.kt
@@ -0,0 +1,26 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord
+
+import com.afollestad.mnmlscreenrecord.engine.service.BackgroundService.Companion.MAIN_ACTIVITY_CLASS
+import com.afollestad.mnmlscreenrecord.ui.MainActivity
+import org.koin.dsl.module.module
+
+/** @author Aidan Follestad (@afollestad) */
+val mainModule = module {
+
+ single>(name = MAIN_ACTIVITY_CLASS) { MainActivity::class.java }
+}
diff --git a/app/src/main/java/com/afollestad/mnmlscreenrecord/MnmlApp.kt b/app/src/main/java/com/afollestad/mnmlscreenrecord/MnmlApp.kt
new file mode 100644
index 0000000..0976009
--- /dev/null
+++ b/app/src/main/java/com/afollestad/mnmlscreenrecord/MnmlApp.kt
@@ -0,0 +1,52 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+@file:Suppress("unused")
+
+package com.afollestad.mnmlscreenrecord
+
+import android.app.Application
+import com.afollestad.mnmlscreenrecord.BuildConfig.DEBUG
+import com.afollestad.mnmlscreenrecord.common.commonModule
+import com.afollestad.mnmlscreenrecord.common.prefModule
+import com.afollestad.mnmlscreenrecord.engine.engineModule
+import com.afollestad.mnmlscreenrecord.notifications.notificationsModule
+import org.koin.android.ext.android.startKoin
+import timber.log.Timber
+import timber.log.Timber.DebugTree
+
+/** @author Aidan Follestad (@afollestad) */
+class MnmlApp : Application() {
+
+ override fun onCreate() {
+ super.onCreate()
+
+ if (DEBUG) {
+ Timber.plant(DebugTree())
+ }
+
+ val modules = listOf(
+ commonModule,
+ notificationsModule,
+ prefModule,
+ engineModule,
+ mainModule
+ )
+ startKoin(
+ androidContext = this,
+ modules = modules
+ )
+ }
+}
diff --git a/app/src/main/java/com/afollestad/mnmlscreenrecord/ui/AboutDialog.kt b/app/src/main/java/com/afollestad/mnmlscreenrecord/ui/AboutDialog.kt
new file mode 100644
index 0000000..a58ac4e
--- /dev/null
+++ b/app/src/main/java/com/afollestad/mnmlscreenrecord/ui/AboutDialog.kt
@@ -0,0 +1,47 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.ui
+
+import android.app.Dialog
+import android.os.Bundle
+import androidx.appcompat.app.AppCompatActivity
+import androidx.fragment.app.DialogFragment
+import com.afollestad.materialdialogs.MaterialDialog
+import com.afollestad.mnmlscreenrecord.R
+
+/** @author Aidan Follestad (afollestad) */
+class AboutDialog : DialogFragment() {
+
+ companion object {
+ private const val TAG = "[ABOUT_DIALOG]"
+
+ fun show(context: AppCompatActivity) {
+ val dialog = AboutDialog()
+ dialog.show(context.supportFragmentManager, TAG)
+ }
+ }
+
+ override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
+ return MaterialDialog(activity!!)
+ .title(R.string.about)
+ .message(
+ res = R.string.about_body,
+ html = true,
+ lineHeightMultiplier = 1.4f
+ )
+ .positiveButton(R.string.dismiss)
+ }
+}
diff --git a/app/src/main/java/com/afollestad/mnmlscreenrecord/ui/MainActivity.kt b/app/src/main/java/com/afollestad/mnmlscreenrecord/ui/MainActivity.kt
new file mode 100644
index 0000000..d147f23
--- /dev/null
+++ b/app/src/main/java/com/afollestad/mnmlscreenrecord/ui/MainActivity.kt
@@ -0,0 +1,268 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.ui
+
+import android.content.Intent
+import android.content.Intent.ACTION_VIEW
+import android.content.res.ColorStateList.valueOf
+import android.os.Bundle
+import android.provider.Settings.ACTION_MANAGE_OVERLAY_PERMISSION
+import android.provider.Settings.canDrawOverlays
+import androidx.core.content.ContextCompat
+import androidx.recyclerview.widget.GridLayoutManager
+import com.afollestad.assent.Permission.WRITE_EXTERNAL_STORAGE
+import com.afollestad.assent.askForPermissions
+import com.afollestad.assent.isAllGranted
+import com.afollestad.materialdialogs.MaterialDialog
+import com.afollestad.materialdialogs.list.listItems
+import com.afollestad.mnmlscreenrecord.R
+import com.afollestad.mnmlscreenrecord.common.files.FileScanner
+import com.afollestad.mnmlscreenrecord.common.misc.toUri
+import com.afollestad.mnmlscreenrecord.common.misc.toast
+import com.afollestad.mnmlscreenrecord.common.rx.attachLifecycle
+import com.afollestad.mnmlscreenrecord.common.view.onScroll
+import com.afollestad.mnmlscreenrecord.common.view.scopeWhileAttached
+import com.afollestad.mnmlscreenrecord.common.view.showOrHide
+import com.afollestad.mnmlscreenrecord.engine.capture.CaptureEngine
+import com.afollestad.mnmlscreenrecord.engine.loader.Recording
+import com.afollestad.mnmlscreenrecord.engine.loader.RecordingQueryer
+import com.afollestad.mnmlscreenrecord.engine.service.BackgroundService
+import com.afollestad.mnmlscreenrecord.engine.service.BackgroundService.Companion.PERMISSION_DENIED
+import com.afollestad.mnmlscreenrecord.notifications.Notifications
+import com.afollestad.mnmlscreenrecord.notifications.RECORD_ACTION
+import com.afollestad.mnmlscreenrecord.notifications.STOP_ACTION
+import com.afollestad.mnmlscreenrecord.theming.DarkModeSwitchActivity
+import kotlinx.android.synthetic.main.activity_main.fab
+import kotlinx.android.synthetic.main.activity_main.list
+import kotlinx.android.synthetic.main.activity_main.toolbar
+import kotlinx.coroutines.Dispatchers.IO
+import kotlinx.coroutines.Dispatchers.Main
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+import org.koin.android.ext.android.inject
+import java.io.File
+import kotlinx.android.synthetic.main.activity_main.app_toolbar as appToolbar
+import kotlinx.android.synthetic.main.activity_main.empty_view as emptyText
+
+/** @author Aidan Follestad (afollestad) */
+class MainActivity : DarkModeSwitchActivity() {
+ companion object {
+ private const val DRAW_OVER_OTHER_APP_PERMISSION = 68
+ private const val STORAGE_PERMISSION = 64
+ }
+
+ private var isAskingPermissions = false
+
+ private val captureEngine by inject()
+ private val notifications by inject()
+ private val recordingQueryer by inject()
+ private val fileScanner by inject()
+
+ private lateinit var adapter: RecordingAdapter
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_main)
+
+ // Toolbar
+ toolbar.inflateMenu(R.menu.main)
+ toolbar.menu.findItem(R.id.dark_mode_toggle)
+ .isChecked = darkModePref.get()
+ toolbar.setOnMenuItemClickListener { item ->
+ when (item.itemId) {
+ R.id.dark_mode_toggle -> darkModePref.set(!darkModePref.get())
+ R.id.about -> AboutDialog.show(this)
+ }
+ true
+ }
+
+ // Notifications
+ notifications.createChannels()
+
+ // Lifecycle
+ lifecycle.addObserver(recordingQueryer)
+
+ // Recycler View Grid
+ adapter = RecordingAdapter { recording, longClick ->
+ if (longClick) {
+ showRecordingOptions(recording)
+ } else {
+ openRecording(recording)
+ }
+ }
+ list.layoutManager = GridLayoutManager(this, resources.getInteger(R.integer.grid_span))
+ list.adapter = adapter
+ if (!darkModePref.get()) {
+ appToolbar.elevation = resources.getDimension(R.dimen.raised_toolbar_elevation)
+ list.onScroll {
+ if (it > (toolbar.measuredHeight / 2)) {
+ appToolbar.elevation = resources.getDimension(R.dimen.raised_toolbar_elevation)
+ } else {
+ appToolbar.elevation = 0f
+ }
+ }
+ }
+
+ // FAB
+ fab.setOnClickListener {
+ if (captureEngine.isStarted()) {
+ sendBroadcast(Intent(STOP_ACTION))
+ } else {
+ maybeAskForSystemOverlayPermission()
+ if (!isAskingPermissions) {
+ startService(true)
+ }
+ }
+ fab.isEnabled = false
+ }
+ captureEngine.onStart()
+ .subscribe {
+ fab.isEnabled = true
+ invalidateFab()
+ }
+ .attachLifecycle(this)
+ captureEngine.onStop()
+ .subscribe {
+ fab.isEnabled = true
+ invalidateFab()
+ }
+ .attachLifecycle(this)
+ fileScanner.onScan()
+ .subscribe { refreshRecordings() }
+ .attachLifecycle(this)
+ }
+
+ private fun refreshRecordings() {
+ toolbar.scopeWhileAttached(Main) {
+ launch(coroutineContext) {
+ val recordings = withContext(IO) { recordingQueryer.queryRecordings() }
+ adapter.set(recordings)
+ emptyText.showOrHide(recordings.isEmpty())
+ }
+ }
+ }
+
+ override fun onResume() {
+ super.onResume()
+ maybeAskForSystemOverlayPermission()
+ if (!isAskingPermissions) {
+ refreshRecordings()
+ }
+ invalidateFab()
+ notifications.setIsAppOpen(true)
+ }
+
+ override fun onPause() {
+ notifications.setIsAppOpen(false)
+ super.onPause()
+ }
+
+ override fun onActivityResult(
+ requestCode: Int,
+ resultCode: Int,
+ data: Intent?
+ ) {
+ super.onActivityResult(requestCode, resultCode, data)
+ isAskingPermissions = false
+ }
+
+ private fun maybeAskForSystemOverlayPermission() {
+ if (!canDrawOverlays(this)) {
+ isAskingPermissions = true
+ MaterialDialog(this)
+ .title(R.string.overlay_permission_prompt)
+ .message(R.string.overlay_permission_prompt_desc)
+ .cancelOnTouchOutside(false)
+ .positiveButton(R.string.okay) {
+ val intent = Intent(
+ ACTION_MANAGE_OVERLAY_PERMISSION,
+ "package:$packageName".toUri()
+ )
+ startActivityForResult(intent, DRAW_OVER_OTHER_APP_PERMISSION)
+ }
+ .show()
+ } else if (!isAllGranted(WRITE_EXTERNAL_STORAGE)) {
+ isAskingPermissions = true
+ MaterialDialog(this)
+ .title(R.string.storage_permission_prompt)
+ .message(R.string.storage_permission_prompt_desc)
+ .cancelOnTouchOutside(false)
+ .positiveButton(R.string.okay) {
+ askForPermissions(WRITE_EXTERNAL_STORAGE, requestCode = STORAGE_PERMISSION) { res ->
+ isAskingPermissions = false
+ if (!res.isAllGranted(WRITE_EXTERNAL_STORAGE)) {
+ sendBroadcast(Intent(PERMISSION_DENIED))
+ toast(R.string.permission_denied_note)
+ }
+ }
+ }
+ .show()
+ }
+ }
+
+ private fun startService(startRecording: Boolean) =
+ startService(Intent(this, BackgroundService::class.java).apply {
+ if (startRecording) {
+ action = RECORD_ACTION
+ }
+ })
+
+ private fun invalidateFab() {
+ if (captureEngine.isStarted()) {
+ val red = ContextCompat.getColor(this, R.color.red)
+ fab.backgroundTintList = valueOf(red)
+ fab.setIconResource(R.drawable.ic_stop_32dp)
+ fab.setText(R.string.stop_recording)
+ } else {
+ val accent = ContextCompat.getColor(this, R.color.colorAccent)
+ fab.backgroundTintList = valueOf(accent)
+ fab.setIconResource(R.drawable.ic_record_32dp)
+ fab.setText(R.string.start_recording)
+ }
+ }
+
+ private fun openRecording(recording: Recording) {
+ startActivity(Intent(ACTION_VIEW).apply {
+ setDataAndType(recording.toUri(), "video/*")
+ })
+ }
+
+ private fun showRecordingOptions(recording: Recording) {
+ MaterialDialog(this)
+ .title(text = recording.name)
+ .listItems(R.array.recording_options_dialog) { _, index, _ ->
+ when (index) {
+ 0 -> startActivity(Intent(Intent.ACTION_SEND).apply {
+ setDataAndType(recording.toUri(), "video/*")
+ })
+ 1 -> deleteRecording(recording)
+ }
+ }
+ .show()
+ }
+
+ private fun deleteRecording(recording: Recording) {
+ toolbar.scopeWhileAttached(Main) {
+ launch(coroutineContext) {
+ withContext(IO) {
+ File(recording.path).delete()
+ contentResolver.delete(recording.toUri(), null, null)
+ }
+ refreshRecordings()
+ }
+ }
+ }
+}
diff --git a/app/src/main/java/com/afollestad/mnmlscreenrecord/ui/RecordingAdapter.kt b/app/src/main/java/com/afollestad/mnmlscreenrecord/ui/RecordingAdapter.kt
new file mode 100644
index 0000000..929267a
--- /dev/null
+++ b/app/src/main/java/com/afollestad/mnmlscreenrecord/ui/RecordingAdapter.kt
@@ -0,0 +1,94 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.ui
+
+import android.annotation.SuppressLint
+import android.view.LayoutInflater
+import android.view.View
+import android.view.View.OnClickListener
+import android.view.View.OnLongClickListener
+import android.view.ViewGroup
+import androidx.recyclerview.widget.RecyclerView
+import com.afollestad.mnmlscreenrecord.R
+import com.afollestad.mnmlscreenrecord.engine.loader.Recording
+import com.bumptech.glide.Glide
+import com.bumptech.glide.request.RequestOptions
+import kotlinx.android.synthetic.main.list_item_recording.view.details
+import kotlinx.android.synthetic.main.list_item_recording.view.name
+import kotlinx.android.synthetic.main.list_item_recording.view.thumbnail
+
+class RecordingViewHolder(
+ itemView: View,
+ private val adapter: RecordingAdapter
+) : RecyclerView.ViewHolder(itemView), OnClickListener, OnLongClickListener {
+
+ override fun onClick(v: View) = adapter.itemClicked(adapterPosition, false)
+
+ override fun onLongClick(v: View?): Boolean {
+ adapter.itemClicked(adapterPosition, true)
+ return false
+ }
+
+ init {
+ itemView.setOnClickListener(this)
+ itemView.setOnLongClickListener(this)
+ }
+
+ @SuppressLint("SetTextI18n")
+ fun bind(recording: Recording) {
+ Glide.with(itemView.thumbnail)
+ .asBitmap()
+ .apply(RequestOptions().frame(0))
+ .load(recording.toUri())
+ .into(itemView.thumbnail)
+ itemView.name.text = recording.name
+ itemView.details.text = "${recording.sizeString()} – ${recording.timestampString()}"
+ }
+}
+
+/** @author Aidan Follestad (@afollestad) */
+class RecordingAdapter(
+ private val onClick: (recording: Recording, longClick: Boolean) -> Unit
+) : RecyclerView.Adapter() {
+
+ private var recordings = mutableListOf()
+
+ fun itemClicked(
+ position: Int,
+ long: Boolean
+ ) = onClick(recordings[position], long)
+
+ fun set(recordings: List) {
+ this.recordings = recordings.toMutableList()
+ notifyDataSetChanged()
+ }
+
+ override fun onCreateViewHolder(
+ parent: ViewGroup,
+ viewType: Int
+ ): RecordingViewHolder {
+ val view = LayoutInflater.from(parent.context)
+ .inflate(R.layout.list_item_recording, parent, false)
+ return RecordingViewHolder(view, this)
+ }
+
+ override fun getItemCount() = recordings.size
+
+ override fun onBindViewHolder(
+ holder: RecordingViewHolder,
+ position: Int
+ ) = holder.bind(recordings[position])
+}
diff --git a/app/src/main/java/com/afollestad/mnmlscreenrecord/views/SquareImageView.kt b/app/src/main/java/com/afollestad/mnmlscreenrecord/views/SquareImageView.kt
new file mode 100644
index 0000000..b216b59
--- /dev/null
+++ b/app/src/main/java/com/afollestad/mnmlscreenrecord/views/SquareImageView.kt
@@ -0,0 +1,38 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.views
+
+import android.content.Context
+import android.util.AttributeSet
+import androidx.appcompat.widget.AppCompatImageView
+
+/**
+ * Forces the height to match the width.
+ *
+ * @author Aidan Follestad (@afollestad)
+ */
+class SquareImageView(
+ context: Context,
+ attrs: AttributeSet? = null
+) : AppCompatImageView(context, attrs) {
+
+ override fun onMeasure(
+ widthMeasureSpec: Int,
+ heightMeasureSpec: Int
+ ) {
+ super.onMeasure(widthMeasureSpec, widthMeasureSpec)
+ }
+}
diff --git a/app/src/main/res/drawable/accent_ripple.xml b/app/src/main/res/drawable/accent_ripple.xml
new file mode 100644
index 0000000..4c865ac
--- /dev/null
+++ b/app/src/main/res/drawable/accent_ripple.xml
@@ -0,0 +1,3 @@
+
+
diff --git a/app/src/main/res/font/lato.xml b/app/src/main/res/font/lato.xml
new file mode 100644
index 0000000..015fa0c
--- /dev/null
+++ b/app/src/main/res/font/lato.xml
@@ -0,0 +1,7 @@
+
+
+
diff --git a/app/src/main/res/font/lato_bold.xml b/app/src/main/res/font/lato_bold.xml
new file mode 100644
index 0000000..e12d82b
--- /dev/null
+++ b/app/src/main/res/font/lato_bold.xml
@@ -0,0 +1,7 @@
+
+
+
diff --git a/app/src/main/res/font/lato_light.xml b/app/src/main/res/font/lato_light.xml
new file mode 100644
index 0000000..e502755
--- /dev/null
+++ b/app/src/main/res/font/lato_light.xml
@@ -0,0 +1,7 @@
+
+
+
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
new file mode 100644
index 0000000..f2fcc5a
--- /dev/null
+++ b/app/src/main/res/layout/activity_main.xml
@@ -0,0 +1,99 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/list_item_recording.xml b/app/src/main/res/layout/list_item_recording.xml
new file mode 100644
index 0000000..cccaf77
--- /dev/null
+++ b/app/src/main/res/layout/list_item_recording.xml
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml
new file mode 100644
index 0000000..490d19c
--- /dev/null
+++ b/app/src/main/res/menu/main.xml
@@ -0,0 +1,11 @@
+
+
\ No newline at end of file
diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
new file mode 100644
index 0000000..4f600a6
--- /dev/null
+++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
new file mode 100644
index 0000000..4f600a6
--- /dev/null
+++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 0000000..9e197b9
Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
new file mode 100644
index 0000000..b7dd877
Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png differ
diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
new file mode 100644
index 0000000..f71ffd8
Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ
diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 0000000..a14f089
Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
new file mode 100644
index 0000000..23357d7
Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png differ
diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
new file mode 100644
index 0000000..9d45337
Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ
diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..3bb3884
Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
new file mode 100644
index 0000000..37bba08
Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png differ
diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
new file mode 100644
index 0000000..b8de9f2
Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ
diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..549486c
Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
new file mode 100644
index 0000000..f30b976
Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png differ
diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
new file mode 100644
index 0000000..b7a322d
Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ
diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 0000000..b81fe34
Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
new file mode 100644
index 0000000..7de835e
Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png differ
diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
new file mode 100644
index 0000000..80af20d
Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ
diff --git a/app/src/main/res/values-land/integers.xml b/app/src/main/res/values-land/integers.xml
new file mode 100644
index 0000000..dbee2d0
--- /dev/null
+++ b/app/src/main/res/values-land/integers.xml
@@ -0,0 +1,4 @@
+
+
+ 3
+
\ No newline at end of file
diff --git a/app/src/main/res/values-large-land/integers.xml b/app/src/main/res/values-large-land/integers.xml
new file mode 100644
index 0000000..10856fe
--- /dev/null
+++ b/app/src/main/res/values-large-land/integers.xml
@@ -0,0 +1,4 @@
+
+
+ 4
+
\ No newline at end of file
diff --git a/app/src/main/res/values-large/integers.xml b/app/src/main/res/values-large/integers.xml
new file mode 100644
index 0000000..dbee2d0
--- /dev/null
+++ b/app/src/main/res/values-large/integers.xml
@@ -0,0 +1,4 @@
+
+
+ 3
+
\ No newline at end of file
diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml
new file mode 100644
index 0000000..469146f
--- /dev/null
+++ b/app/src/main/res/values/arrays.xml
@@ -0,0 +1,9 @@
+
+
+
+
+ - @string/share
+ - @string/delete
+
+
+
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
new file mode 100644
index 0000000..50d0e79
--- /dev/null
+++ b/app/src/main/res/values/colors.xml
@@ -0,0 +1,4 @@
+
+
+ #E53935
+
\ No newline at end of file
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
new file mode 100644
index 0000000..8f2f84a
--- /dev/null
+++ b/app/src/main/res/values/dimens.xml
@@ -0,0 +1,4 @@
+
+
+ 4dp
+
\ No newline at end of file
diff --git a/app/src/main/res/values/font_certs.xml b/app/src/main/res/values/font_certs.xml
new file mode 100644
index 0000000..d2226ac
--- /dev/null
+++ b/app/src/main/res/values/font_certs.xml
@@ -0,0 +1,17 @@
+
+
+
+ - @array/com_google_android_gms_fonts_certs_dev
+ - @array/com_google_android_gms_fonts_certs_prod
+
+
+ -
+ MIIEqDCCA5CgAwIBAgIJANWFuGx90071MA0GCSqGSIb3DQEBBAUAMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTAeFw0wODA0MTUyMzM2NTZaFw0zNTA5MDEyMzM2NTZaMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTCCASAwDQYJKoZIhvcNAQEBBQADggENADCCAQgCggEBANbOLggKv+IxTdGNs8/TGFy0PTP6DHThvbbR24kT9ixcOd9W+EaBPWW+wPPKQmsHxajtWjmQwWfna8mZuSeJS48LIgAZlKkpFeVyxW0qMBujb8X8ETrWy550NaFtI6t9+u7hZeTfHwqNvacKhp1RbE6dBRGWynwMVX8XW8N1+UjFaq6GCJukT4qmpN2afb8sCjUigq0GuMwYXrFVee74bQgLHWGJwPmvmLHC69EH6kWr22ijx4OKXlSIx2xT1AsSHee70w5iDBiK4aph27yH3TxkXy9V89TDdexAcKk/cVHYNnDBapcavl7y0RiQ4biu8ymM8Ga/nmzhRKya6G0cGw8CAQOjgfwwgfkwHQYDVR0OBBYEFI0cxb6VTEM8YYY6FbBMvAPyT+CyMIHJBgNVHSMEgcEwgb6AFI0cxb6VTEM8YYY6FbBMvAPyT+CyoYGapIGXMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbYIJANWFuGx90071MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADggEBABnTDPEF+3iSP0wNfdIjIz1AlnrPzgAIHVvXxunW7SBrDhEglQZBbKJEk5kT0mtKoOD1JMrSu1xuTKEBahWRbqHsXclaXjoBADb0kkjVEJu/Lh5hgYZnOjvlba8Ld7HCKePCVePoTJBdI4fvugnL8TsgK05aIskyY0hKI9L8KfqfGTl1lzOv2KoWD0KWwtAWPoGChZxmQ+nBli+gwYMzM1vAkP+aayLe0a1EQimlOalO762r0GXO0ks+UeXde2Z4e+8S/pf7pITEI/tP+MxJTALw9QUWEv9lKTk+jkbqxbsh8nfBUapfKqYn0eidpwq2AzVp3juYl7//fKnaPhJD9gs=
+
+
+
+ -
+ MIIEQzCCAyugAwIBAgIJAMLgh0ZkSjCNMA0GCSqGSIb3DQEBBAUAMHQxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtHb29nbGUgSW5jLjEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDAeFw0wODA4MjEyMzEzMzRaFw0zNjAxMDcyMzEzMzRaMHQxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtHb29nbGUgSW5jLjEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDCCASAwDQYJKoZIhvcNAQEBBQADggENADCCAQgCggEBAKtWLgDYO6IIrgqWbxJOKdoR8qtW0I9Y4sypEwPpt1TTcvZApxsdyxMJZ2JORland2qSGT2y5b+3JKkedxiLDmpHpDsz2WCbdxgxRczfey5YZnTJ4VZbH0xqWVW/8lGmPav5xVwnIiJS6HXk+BVKZF+JcWjAsb/GEuq/eFdpuzSqeYTcfi6idkyugwfYwXFU1+5fZKUaRKYCwkkFQVfcAs1fXA5V+++FGfvjJ/CxURaSxaBvGdGDhfXE28LWuT9ozCl5xw4Yq5OGazvV24mZVSoOO0yZ31j7kYvtwYK6NeADwbSxDdJEqO4k//0zOHKrUiGYXtqw/A0LFFtqoZKFjnkCAQOjgdkwgdYwHQYDVR0OBBYEFMd9jMIhF1Ylmn/Tgt9r45jk14alMIGmBgNVHSMEgZ4wgZuAFMd9jMIhF1Ylmn/Tgt9r45jk14aloXikdjB0MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEUMBIGA1UEChMLR29vZ2xlIEluYy4xEDAOBgNVBAsTB0FuZHJvaWQxEDAOBgNVBAMTB0FuZHJvaWSCCQDC4IdGZEowjTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBAUAA4IBAQBt0lLO74UwLDYKqs6Tm8/yzKkEu116FmH4rkaymUIE0P9KaMftGlMexFlaYjzmB2OxZyl6euNXEsQH8gjwyxCUKRJNexBiGcCEyj6z+a1fuHHvkiaai+KL8W1EyNmgjmyy8AW7P+LLlkR+ho5zEHatRbM/YAnqGcFh5iZBqpknHf1SKMXFh4dd239FJ1jWYfbMDMy3NS5CTMQ2XFI1MvcyUTdZPErjQfTbQe3aDQsQcafEQPD+nqActifKZ0Np0IS9L9kR/wbNvyz6ENwPiTrjV2KRkEjH78ZMcUQXg0L3BYHJ3lc69Vs5Ddf9uUGGMYldX3WfMBEmh/9iFBDAaTCK
+
+
+
diff --git a/app/src/main/res/values/integers.xml b/app/src/main/res/values/integers.xml
new file mode 100644
index 0000000..a8bde74
--- /dev/null
+++ b/app/src/main/res/values/integers.xml
@@ -0,0 +1,4 @@
+
+
+ 2
+
\ No newline at end of file
diff --git a/app/src/main/res/values/preloaded_fonts.xml b/app/src/main/res/values/preloaded_fonts.xml
new file mode 100644
index 0000000..7b2ca21
--- /dev/null
+++ b/app/src/main/res/values/preloaded_fonts.xml
@@ -0,0 +1,8 @@
+
+
+
+ - @font/lato
+ - @font/lato_bold
+ - @font/lato_light
+
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
new file mode 100644
index 0000000..b024a58
--- /dev/null
+++ b/app/src/main/res/values/strings.xml
@@ -0,0 +1,37 @@
+
+
+ MNML Screen Recorder
+
+ About
+ Dismiss
+ Aidan Follestad.
+ Website
+ Twitter
+ GitHub
+ LinkedIn
+ This project is open source, and is
+ licensed under Apache 2.0.
+ ]]>
+
+ Overlay Permission Required
+
+ MNML needs permission to draw overlays so that it can display things like countdowns and
+ controls over other apps.
+
+
+ Storage Permission Required
+
+ MNML needs permission to access your phone\'s storage so that recordings can be saved and
+ listed again later.
+
+
+ You won\'t be able to use MNML unless that permission is granted.
+ Okay!
+
+ You have no recordings, yet…
+ 😔
+
+ Dark Mode
+
+
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
new file mode 100644
index 0000000..5fb714c
--- /dev/null
+++ b/app/src/main/res/values/styles.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000..a58cebb
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,29 @@
+apply from: './dependencies.gradle'
+apply from: './versionsPlugin.gradle'
+
+buildscript {
+ apply from: './dependencies.gradle'
+
+ repositories {
+ google()
+ jcenter()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:' + versions.gradlePlugin
+ classpath 'com.diffplug.spotless:spotless-plugin-gradle:' + versions.spotlessPlugin
+ classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:' + versions.kotlin
+ classpath 'com.github.ben-manes:gradle-versions-plugin:' + versions.versionPlugin
+ }
+}
+
+allprojects {
+ repositories {
+ google()
+ jcenter()
+ maven { url "https://dl.bintray.com/drummer-aidan/maven" }
+ }
+
+ tasks.withType(Javadoc).all {
+ enabled = false
+ }
+}
diff --git a/common/.gitignore b/common/.gitignore
new file mode 100644
index 0000000..796b96d
--- /dev/null
+++ b/common/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/common/build.gradle b/common/build.gradle
new file mode 100644
index 0000000..4d137fd
--- /dev/null
+++ b/common/build.gradle
@@ -0,0 +1,35 @@
+apply from: '../dependencies.gradle'
+apply plugin: 'com.android.library'
+apply plugin: 'kotlin-android'
+
+android {
+ compileSdkVersion versions.compileSdk
+
+ defaultConfig {
+ minSdkVersion versions.minSdk
+ targetSdkVersion versions.compileSdk
+ versionCode versions.publishVersionCode
+ versionName versions.publishVersion
+ }
+}
+
+dependencies {
+ api 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:' + versions.kotlin
+ api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:' + versions.coroutines
+ api 'org.jetbrains.kotlinx:kotlinx-coroutines-android:' + versions.coroutines
+
+ api 'androidx.recyclerview:recyclerview:' + versions.androidx
+ api 'androidx.lifecycle:lifecycle-extensions:' + versions.lifecycle
+
+ api 'org.koin:koin-android:' + versions.koin
+ api 'com.jakewharton.timber:timber:' + versions.timber
+
+ api 'com.afollestad:rxkprefs:' + versions.rxkPrefs
+
+ testImplementation 'junit:junit:' + versions.junit
+ testImplementation 'org.mockito:mockito-core:' + versions.mockito
+ testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:' + versions.mockitoKotlin
+ testImplementation 'com.google.truth:truth:' + versions.truth
+}
+
+apply from: '../spotless.gradle'
\ No newline at end of file
diff --git a/common/src/main/AndroidManifest.xml b/common/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..9140029
--- /dev/null
+++ b/common/src/main/AndroidManifest.xml
@@ -0,0 +1,2 @@
+
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/CommonModule.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/CommonModule.kt
new file mode 100644
index 0000000..46c1f8c
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/CommonModule.kt
@@ -0,0 +1,38 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common
+
+import com.afollestad.mnmlscreenrecord.common.Qualifiers.IO_DISPATCHER
+import com.afollestad.mnmlscreenrecord.common.Qualifiers.MAIN_DISPATCHER
+import com.afollestad.mnmlscreenrecord.common.files.FileScanner
+import kotlinx.coroutines.CoroutineDispatcher
+import kotlinx.coroutines.Dispatchers
+import org.koin.dsl.module.module
+
+object Qualifiers {
+ const val MAIN_DISPATCHER = "main_dispatcher"
+ const val IO_DISPATCHER = "io_dispatcher"
+}
+
+/** @author Aidan Follestad (@afollestad) */
+val commonModule = module {
+
+ factory(name = MAIN_DISPATCHER) { Dispatchers.Main }
+
+ factory(name = IO_DISPATCHER) { Dispatchers.IO }
+
+ single { FileScanner(get()) }
+}
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/PrefModule.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/PrefModule.kt
new file mode 100644
index 0000000..fd3f43e
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/PrefModule.kt
@@ -0,0 +1,36 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common
+
+import com.afollestad.mnmlscreenrecord.common.prefs.PrefNames.PREF_COUNTDOWN
+import com.afollestad.mnmlscreenrecord.common.prefs.PrefNames.PREF_DARK_MODE
+import com.afollestad.rxkprefs.RxkPrefs
+import com.afollestad.rxkprefs.rxkPrefs
+import org.koin.dsl.module.module
+
+/** @author Aidan Follestad (@afollestad) */
+val prefModule = module {
+
+ single { rxkPrefs(get(), "settings") }
+
+ factory(name = PREF_DARK_MODE) {
+ get().boolean(PREF_DARK_MODE, false)
+ }
+
+ factory(name = PREF_COUNTDOWN) {
+ get().integer(PREF_COUNTDOWN, 3)
+ }
+}
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/files/FileScanner.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/files/FileScanner.kt
new file mode 100644
index 0000000..5172667
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/files/FileScanner.kt
@@ -0,0 +1,46 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.files
+
+import android.app.Application
+import android.media.MediaScannerConnection.scanFile
+import android.net.Uri
+import io.reactivex.Observable
+import io.reactivex.subjects.PublishSubject
+import java.io.File
+import timber.log.Timber.d as log
+
+typealias UriCallback = ((Uri) -> Unit)?
+
+/** @author Aidan Follestad (@afollestad) */
+class FileScanner(private val app: Application) {
+
+ private var onScanSubject = PublishSubject.create()
+
+ fun onScan(): Observable = onScanSubject
+
+ fun scan(
+ file: File,
+ cb: UriCallback = null
+ ) {
+ log("Scanning $file...")
+ scanFile(app, arrayOf(file.toString()), null) { _, resultUri ->
+ log("Scanned! Result: $resultUri")
+ cb?.invoke(resultUri)
+ onScanSubject.onNext(resultUri)
+ }
+ }
+}
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/intent/Builder.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/intent/Builder.kt
new file mode 100644
index 0000000..83bb469
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/intent/Builder.kt
@@ -0,0 +1,56 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.intent
+
+import android.content.IntentFilter
+import com.afollestad.mnmlscreenrecord.common.intent.Instructions.OnAction
+import com.afollestad.mnmlscreenrecord.common.intent.Instructions.OnCategory
+import com.afollestad.mnmlscreenrecord.common.intent.Instructions.OnDataScheme
+
+/** @author Aidan Follestad (@afollestad) */
+class Builder internal constructor() {
+
+ private val filter = IntentFilter()
+ private val instructions = mutableListOf()
+
+ fun onAction(
+ action: String,
+ execution: Execution
+ ) {
+ filter.addAction(action)
+ instructions.add(OnAction(action, execution))
+ }
+
+ fun onDataScheme(
+ scheme: String,
+ execution: Execution
+ ) {
+ filter.addDataScheme(scheme)
+ instructions.add(OnDataScheme(scheme, execution))
+ }
+
+ fun onCategory(
+ category: String,
+ execution: Execution
+ ) {
+ filter.addCategory(category)
+ instructions.add(OnCategory(category, execution))
+ }
+
+ internal fun filter() = filter
+
+ internal fun instructions() = instructions
+}
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/intent/Instructions.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/intent/Instructions.kt
new file mode 100644
index 0000000..d3c575c
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/intent/Instructions.kt
@@ -0,0 +1,62 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.intent
+
+import android.content.Intent
+
+typealias Execution = (Intent) -> Unit
+
+/** @author Aidan Follestad (@afollestad) */
+sealed class Instructions {
+
+ abstract fun matches(intent: Intent): Boolean
+
+ abstract fun execution(): Execution
+
+ data class OnAction(
+ val action: String,
+ val execution: Execution
+ ) : Instructions() {
+
+ override fun matches(intent: Intent): Boolean {
+ return intent.action == action
+ }
+
+ override fun execution() = execution
+ }
+
+ data class OnDataScheme(
+ val scheme: String,
+ val execution: Execution
+ ) : Instructions() {
+ override fun matches(intent: Intent): Boolean {
+ return intent.data?.scheme == scheme
+ }
+
+ override fun execution() = execution
+ }
+
+ data class OnCategory(
+ val category: String,
+ val execution: Execution
+ ) : Instructions() {
+ override fun matches(intent: Intent): Boolean {
+ return intent.hasCategory(category)
+ }
+
+ override fun execution() = execution
+ }
+}
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/intent/IntentReceiver.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/intent/IntentReceiver.kt
new file mode 100644
index 0000000..8baa096
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/intent/IntentReceiver.kt
@@ -0,0 +1,77 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.intent
+
+import android.content.Context
+import android.content.Intent
+import android.content.IntentFilter
+import androidx.lifecycle.Lifecycle.Event.ON_PAUSE
+import androidx.lifecycle.Lifecycle.Event.ON_RESUME
+import androidx.lifecycle.LifecycleObserver
+import androidx.lifecycle.LifecycleOwner
+import androidx.lifecycle.OnLifecycleEvent
+import android.content.BroadcastReceiver as StockReceiver
+import timber.log.Timber.d as log
+
+/** @author Aidan Follestad (@afollestad) */
+class IntentReceiver(
+ context: T,
+ constructor: Builder.() -> Unit
+) : LifecycleObserver where T : Context, T : LifecycleOwner {
+
+ private val appContext = context.applicationContext
+ private val filter: IntentFilter
+ private val instructions: List
+
+ init {
+ val builder = Builder()
+ constructor(builder)
+ filter = builder.filter()
+ instructions = builder.instructions()
+
+ context.lifecycle.addObserver(this)
+ }
+
+ private val broadcastReceiver = object : StockReceiver() {
+ override fun onReceive(
+ context: Context,
+ intent: Intent
+ ) {
+ log("Received: ${intent.action}")
+ for (ins in instructions) {
+ if (ins.matches(intent)) {
+ log("Intent matches $ins")
+ ins.execution()
+ .invoke(intent)
+ return
+ }
+ }
+ throw IllegalStateException("Shouldn't reach this point")
+ }
+ }
+
+ @OnLifecycleEvent(ON_RESUME)
+ fun start() {
+ log("start()")
+ appContext.registerReceiver(broadcastReceiver, filter)
+ }
+
+ @OnLifecycleEvent(ON_PAUSE)
+ fun stop() {
+ log("stop()")
+ appContext.unregisterReceiver(broadcastReceiver)
+ }
+}
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/lifecycle/SimpleLifecycle.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/lifecycle/SimpleLifecycle.kt
new file mode 100644
index 0000000..78b56cd
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/lifecycle/SimpleLifecycle.kt
@@ -0,0 +1,41 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.lifecycle
+
+import androidx.lifecycle.Lifecycle.Event.ON_CREATE
+import androidx.lifecycle.Lifecycle.Event.ON_DESTROY
+import androidx.lifecycle.Lifecycle.Event.ON_PAUSE
+import androidx.lifecycle.Lifecycle.Event.ON_RESUME
+import androidx.lifecycle.Lifecycle.Event.ON_START
+import androidx.lifecycle.Lifecycle.Event.ON_STOP
+import androidx.lifecycle.LifecycleOwner
+import androidx.lifecycle.LifecycleRegistry
+
+/** @author Aidan Follestad (@afollestad) */
+class SimpleLifecycle(provider: LifecycleOwner) : LifecycleRegistry(provider) {
+
+ fun onCreate() {
+ handleLifecycleEvent(ON_CREATE)
+ handleLifecycleEvent(ON_START)
+ handleLifecycleEvent(ON_RESUME)
+ }
+
+ fun onDestroy() {
+ handleLifecycleEvent(ON_PAUSE)
+ handleLifecycleEvent(ON_STOP)
+ handleLifecycleEvent(ON_DESTROY)
+ }
+}
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/lifecycle/ViewLifecycleOwner.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/lifecycle/ViewLifecycleOwner.kt
new file mode 100644
index 0000000..00d1102
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/lifecycle/ViewLifecycleOwner.kt
@@ -0,0 +1,48 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.lifecycle
+
+import android.view.View
+import android.view.View.OnAttachStateChangeListener
+import androidx.lifecycle.LifecycleOwner
+import com.afollestad.mnmlscreenrecord.common.R
+
+/** @author Aidan Follestad (@afollestad) */
+class ViewLifecycleOwner(view: View) : LifecycleOwner, OnAttachStateChangeListener {
+
+ private val lifecycle = SimpleLifecycle(this)
+
+ init {
+ view.addOnAttachStateChangeListener(this)
+ }
+
+ override fun getLifecycle() = lifecycle
+
+ override fun onViewAttachedToWindow(v: View?) = lifecycle.onCreate()
+
+ override fun onViewDetachedFromWindow(v: View) = lifecycle.onDestroy()
+}
+
+fun View.lifecycleOwner(): LifecycleOwner {
+ val tagOwner = getTag(R.id.view_lifecycle_registry) as? ViewLifecycleOwner
+ return if (tagOwner != null) {
+ tagOwner
+ } else {
+ val newOwner = ViewLifecycleOwner(this)
+ setTag(R.id.view_lifecycle_registry, newOwner)
+ newOwner
+ }
+}
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/livedata/Distinct.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/livedata/Distinct.kt
new file mode 100644
index 0000000..9ed03cf
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/livedata/Distinct.kt
@@ -0,0 +1,54 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.livedata
+
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.MediatorLiveData
+import androidx.lifecycle.Observer
+
+/** @author Aidan Follestad (@afollestad) */
+class DistinctLiveData(source1: LiveData) : MediatorLiveData() {
+
+ private var isInitialized = false
+ private var lastValue: T? = null
+
+ init {
+ super.addSource(source1) {
+ if (!isInitialized) {
+ value = it
+ isInitialized = true
+ lastValue = it
+ } else if (lastValue != it) {
+ value = it
+ lastValue = it
+ }
+ }
+ }
+
+ override fun addSource(
+ source: LiveData,
+ onChanged: Observer
+ ) {
+ throw UnsupportedOperationException()
+ }
+
+ override fun removeSource(toRemote: LiveData) {
+ throw UnsupportedOperationException()
+ }
+}
+
+fun LiveData.distinct(): MediatorLiveData =
+ DistinctLiveData(this)
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/livedata/LiveDataExt.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/livedata/LiveDataExt.kt
new file mode 100644
index 0000000..f3902bc
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/livedata/LiveDataExt.kt
@@ -0,0 +1,25 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.livedata
+
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.Transformations
+
+fun LiveData.map(mapper: (X) -> Y) =
+ Transformations.map(this, mapper)!!
+
+fun LiveData.switchMap(mapper: (X) -> LiveData) =
+ Transformations.switchMap(this, mapper)!!
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/livedata/LiveDataViewExt.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/livedata/LiveDataViewExt.kt
new file mode 100644
index 0000000..ade2aa8
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/livedata/LiveDataViewExt.kt
@@ -0,0 +1,123 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.livedata
+
+import android.view.View
+import android.widget.EditText
+import android.widget.TextView
+import androidx.lifecycle.LifecycleOwner
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.MutableLiveData
+import androidx.lifecycle.Observer
+import com.afollestad.mnmlscreenrecord.common.view.onTextChanged
+import com.afollestad.mnmlscreenrecord.common.view.showOrHide
+import kotlin.math.min
+
+fun EditText.setTextAndMaintainSelection(text: CharSequence) {
+ val formerStart = min(selectionStart, text.length)
+ val formerEnd = min(selectionEnd, text.length)
+ setText(text)
+ if (formerEnd <= formerStart) {
+ setSelection(formerStart)
+ } else {
+ setSelection(formerStart, formerEnd)
+ }
+}
+
+inline fun EditText.attachLiveData(
+ lifecycleOwner: LifecycleOwner,
+ data: MutableLiveData,
+ debounce: Int = 100,
+ pushOutChanges: Boolean = true,
+ pullInChanges: Boolean = false
+) {
+ // Initial value
+ if (T::class == String::class) {
+ if (data.value != null) {
+ this.setText(data.value as? String)
+ } else {
+ data.value = this.text.trim().toString() as T
+ }
+ } else if (T::class == Int::class) {
+ if (data.value != null) {
+ this.setText(data.value.toString())
+ } else {
+ data.value = (this.text.trim().toString().toIntOrNull() ?: 0) as T
+ }
+ }
+ // Out
+ if (pushOutChanges) {
+ when {
+ T::class == Int::class -> {
+ onTextChanged(debounce) { data.postValue(it.trim().toInt() as T) }
+ }
+ T::class == Long::class -> {
+ onTextChanged(debounce) { data.postValue(it.trim().toLong() as T) }
+ }
+ T::class == String::class -> {
+ onTextChanged(debounce) { data.postValue(it as T) }
+ }
+ else -> {
+ throw IllegalArgumentException("Can't send EditText text changes into ${T::class}")
+ }
+ }
+ }
+ // In
+ if (pullInChanges) {
+ data.distinct()
+ .observe(lifecycleOwner, Observer {
+ when {
+ T::class == Int::class -> setText(it as Int)
+ T::class == String::class -> setTextAndMaintainSelection(it as String)
+ }
+ })
+ }
+}
+
+fun LiveData.toViewError(
+ owner: LifecycleOwner,
+ view: View,
+ setter: (String?) -> Unit
+) = observe(owner, Observer { error ->
+ setter(
+ if (error != null) {
+ view.resources.getString(error)
+ } else {
+ null
+ }
+ )
+})
+
+fun LiveData.toViewError(
+ owner: LifecycleOwner,
+ view: EditText
+) = toViewError(owner, view, view::setError)
+
+fun LiveData<*>.toViewText(
+ owner: LifecycleOwner,
+ view: TextView
+) = distinct().observe(owner, Observer {
+ when (it) {
+ is Int -> view.setText(it)
+ is String -> view.text = it
+ else -> throw IllegalStateException("Can't set $it to a text view.")
+ }
+})
+
+fun LiveData.toViewVisibility(
+ owner: LifecycleOwner,
+ view: View
+) = distinct().observe(owner, Observer { view.showOrHide(it) })
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/livedata/TestLiveData.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/livedata/TestLiveData.kt
new file mode 100644
index 0000000..5d070b4
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/livedata/TestLiveData.kt
@@ -0,0 +1,63 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.livedata
+
+import androidx.annotation.CheckResult
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.Observer
+
+/** @author Aidan Follestad (@afollestad) */
+class TestLiveData(data: LiveData) {
+
+ private val receivedValues = mutableListOf()
+ private val observer = Observer { emission ->
+ emission?.let { receivedValues.add(it) }
+ }
+
+ init {
+ data.observeForever(observer)
+ }
+
+ fun assertNoValues() {
+ if (receivedValues.isNotEmpty()) {
+ throw AssertionError("Expected no values, but got: $receivedValues")
+ }
+ }
+
+ fun assertValues(vararg assertValues: T) {
+ val assertList = assertValues.toList()
+ if (!assertList.contentEquals(receivedValues)) {
+ throw AssertionError("Expected $assertList\n\t\tBut got: $receivedValues")
+ }
+ receivedValues.clear()
+ }
+
+ @CheckResult fun values(): List = receivedValues
+
+ private fun List.contentEquals(other: List): Boolean {
+ if (this.size != other.size) {
+ return false
+ }
+ for ((index, value) in this.withIndex()) {
+ if (other[index] != value) {
+ return false
+ }
+ }
+ return true
+ }
+}
+
+@CheckResult fun LiveData.test() = TestLiveData(this)
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/livedata/Zip.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/livedata/Zip.kt
new file mode 100644
index 0000000..f9df2de
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/livedata/Zip.kt
@@ -0,0 +1,102 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.livedata
+
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.MediatorLiveData
+import androidx.lifecycle.Observer
+
+typealias Zipper = (T, K) -> R
+
+/** @author Aidan Follestad (@afollestad) */
+class ZipLiveData(
+ source1: LiveData,
+ source2: LiveData,
+ private val distinctUntilChanged: Boolean,
+ private val resetAfterEmission: Boolean,
+ private val zipper: Zipper
+) : MediatorLiveData() {
+
+ private var data1: T? = null
+ private var data2: K? = null
+ private var lastNotified: R? = null
+
+ init {
+ super.addSource(source1) {
+ if (data1 == it) return@addSource
+ data1 = it
+ maybeNotify()
+ }
+ super.addSource(source2) {
+ if (data2 == it) return@addSource
+ data2 = it
+ maybeNotify()
+ }
+ }
+
+ private fun maybeNotify() {
+ if (data1 != null && data2 != null) {
+ val zippedUp = zipper(data1!!, data2!!)
+
+ if (!distinctUntilChanged || zippedUp != lastNotified) {
+ value = zippedUp
+ lastNotified = zippedUp
+
+ if (resetAfterEmission) {
+ data1 = null
+ data2 = null
+ }
+ }
+ }
+ }
+
+ override fun addSource(
+ source: LiveData,
+ onChanged: Observer
+ ) {
+ throw UnsupportedOperationException()
+ }
+
+ override fun removeSource(toRemote: LiveData) {
+ throw UnsupportedOperationException()
+ }
+}
+
+fun zip(
+ source1: LiveData,
+ source2: LiveData,
+ distinctUntilChanged: Boolean = true,
+ resetAfterEmission: Boolean = false,
+ zipper: Zipper
+) = ZipLiveData(
+ source1 = source1,
+ source2 = source2,
+ distinctUntilChanged = distinctUntilChanged,
+ resetAfterEmission = resetAfterEmission,
+ zipper = zipper
+)
+
+fun zip(
+ source1: LiveData,
+ source2: LiveData,
+ distinctUntilChanged: Boolean = true,
+ resetAfterEmission: Boolean = false
+) = zip(
+ source1 = source1,
+ source2 = source2,
+ distinctUntilChanged = distinctUntilChanged,
+ resetAfterEmission = resetAfterEmission,
+ zipper = { left, right -> Pair(left, right) })
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/ContextExt.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/ContextExt.kt
new file mode 100644
index 0000000..fe1f24f
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/ContextExt.kt
@@ -0,0 +1,43 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.misc
+
+import android.content.Context
+import android.widget.Toast
+import android.widget.Toast.LENGTH_LONG
+
+var toast: Toast? = null
+
+/** @author Aidan Follestad (@afollestad) */
+inline fun Context.systemService(name: String): T {
+ return getSystemService(name) as T
+}
+
+fun Context.toast(message: Int) {
+ toast?.cancel()
+ toast = Toast.makeText(this, message, LENGTH_LONG)
+ .apply {
+ show()
+ }
+}
+
+fun Context.toast(message: String) {
+ toast?.cancel()
+ toast = Toast.makeText(this, message, LENGTH_LONG)
+ .apply {
+ show()
+ }
+}
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/DateExt.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/DateExt.kt
new file mode 100644
index 0000000..73d00a8
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/DateExt.kt
@@ -0,0 +1,36 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.misc
+
+import java.text.SimpleDateFormat
+import java.util.Date
+import java.util.Locale
+
+fun Date.timestampString(): String {
+ if (time <= 0) {
+ return "Invalid"
+ }
+ val df = SimpleDateFormat("MMMMd-hhmmssa", Locale.getDefault())
+ return df.format(this)
+}
+
+fun Long.friendlyDate(): String {
+ if (this <= 0) {
+ return "Invalid"
+ }
+ val df = SimpleDateFormat("MMM d, hh:mm a", Locale.getDefault())
+ return df.format(this)
+}
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/LayoutInflaterExt.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/LayoutInflaterExt.kt
new file mode 100644
index 0000000..97f22e5
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/LayoutInflaterExt.kt
@@ -0,0 +1,26 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.misc
+
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.annotation.LayoutRes
+
+@Suppress("UNCHECKED_CAST")
+fun LayoutInflater.inflate(@LayoutRes res: Int, parent: ViewGroup? = null): T {
+ return inflate(res, parent, false) as T
+}
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/RemoteViewsExt.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/RemoteViewsExt.kt
new file mode 100644
index 0000000..acfb146
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/RemoteViewsExt.kt
@@ -0,0 +1,25 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.misc
+
+import android.view.View.GONE
+import android.view.View.VISIBLE
+import android.widget.RemoteViews
+import androidx.annotation.IdRes
+
+fun RemoteViews.setViewVisibility(@IdRes viewId: Int, visible: Boolean) {
+ setViewVisibility(viewId, if (visible) VISIBLE else GONE)
+}
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/SizeExt.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/SizeExt.kt
new file mode 100644
index 0000000..2f5a480
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/SizeExt.kt
@@ -0,0 +1,29 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.misc
+
+private const val KILOBYTE = 1_024L
+private const val MEGABYTE = 1_048_576L
+private const val GIGABYTE = 1_073_741_824L
+
+fun Long.friendlySize(): String {
+ return when {
+ this >= GIGABYTE -> "${this / GIGABYTE}GB"
+ this >= MEGABYTE -> "${this / MEGABYTE}MB"
+ this >= KILOBYTE -> "${this / KILOBYTE}KB"
+ else -> "${this}B"
+ }
+}
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/StringExt.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/StringExt.kt
new file mode 100644
index 0000000..c51aefc
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/StringExt.kt
@@ -0,0 +1,20 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.misc
+
+import android.net.Uri
+
+fun String.toUri() = Uri.parse(this)!!
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/TimeExt.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/TimeExt.kt
new file mode 100644
index 0000000..1fdd67d
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/TimeExt.kt
@@ -0,0 +1,46 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.misc
+
+import kotlin.math.ceil
+
+const val SECOND: Long = 1000
+const val MINUTE = SECOND * 60
+const val HOUR = MINUTE * 60
+const val DAY = HOUR * 24
+const val WEEK = DAY * 7
+const val MONTH = WEEK * 4
+
+fun Long.timeString() = when {
+ this <= 0 -> "??"
+ this >= MONTH ->
+ "${ceil((this.toFloat() / MONTH.toFloat()).toDouble()).toInt()}mo"
+ this >= WEEK ->
+ "${ceil((this.toFloat() / WEEK.toFloat()).toDouble()).toInt()}w"
+ this >= DAY ->
+ "${ceil((this.toFloat() / DAY.toFloat()).toDouble()).toInt()}d"
+ this >= HOUR ->
+ "${ceil((this.toFloat() / HOUR.toFloat()).toDouble()).toInt()}h"
+ this >= MINUTE -> {
+ val result = "${ceil((this.toFloat() / MINUTE.toFloat()).toDouble()).toInt()}m"
+ if (result == "60m") {
+ "1h"
+ } else {
+ result
+ }
+ }
+ else -> "<1m"
+}
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/WindowManagerExt.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/WindowManagerExt.kt
new file mode 100644
index 0000000..7b13a74
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/misc/WindowManagerExt.kt
@@ -0,0 +1,39 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.misc
+
+import android.util.DisplayMetrics
+import android.view.WindowManager
+import timber.log.Timber
+
+data class DisplayInfo(
+ val width: Int,
+ val height: Int,
+ val density: Int
+)
+
+fun WindowManager.displayInfo(): DisplayInfo {
+ val metrics = DisplayMetrics()
+ defaultDisplay.getRealMetrics(metrics)
+ val info = DisplayInfo(
+ metrics.widthPixels,
+ metrics.heightPixels,
+ metrics.densityDpi
+ )
+ Timber.tag("WindowManagerExt")
+ Timber.d("Display: ${info.width} x ${info.height} @ ${info.density}")
+ return info
+}
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/prefs/PrefNames.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/prefs/PrefNames.kt
new file mode 100644
index 0000000..5af582e
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/prefs/PrefNames.kt
@@ -0,0 +1,22 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.prefs
+
+/** @author Aidan Follestad (@afollestad) */
+object PrefNames {
+ const val PREF_DARK_MODE = "dark_mode"
+ const val PREF_COUNTDOWN = "countdown"
+}
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/rx/RxExt.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/rx/RxExt.kt
new file mode 100644
index 0000000..61b104b
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/rx/RxExt.kt
@@ -0,0 +1,23 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.rx
+
+import io.reactivex.disposables.CompositeDisposable
+import io.reactivex.disposables.Disposable
+
+operator fun CompositeDisposable?.plusAssign(disposable: Disposable) {
+ this?.add(disposable)
+}
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/rx/RxLifecycleExt.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/rx/RxLifecycleExt.kt
new file mode 100644
index 0000000..0a8c43a
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/rx/RxLifecycleExt.kt
@@ -0,0 +1,41 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.rx
+
+import androidx.lifecycle.Lifecycle.Event.ON_DESTROY
+import androidx.lifecycle.LifecycleObserver
+import androidx.lifecycle.LifecycleOwner
+import androidx.lifecycle.OnLifecycleEvent
+import io.reactivex.disposables.Disposable
+
+/** @author Aidan Follestad (afollestad) */
+class LifecycleAwareDisposable(
+ private val disposable: Disposable
+) : LifecycleObserver {
+
+ @OnLifecycleEvent(ON_DESTROY)
+ fun dispose() = disposable.dispose()
+}
+
+/** @author Aidan Follestad (afollestad) */
+fun LifecycleOwner.ownRx(disposable: Disposable) {
+ this.lifecycle.addObserver(LifecycleAwareDisposable(disposable))
+}
+
+/** @author Aidan Follestad (afollestad) */
+fun Disposable.attachLifecycle(lifecycleOwner: LifecycleOwner) {
+ lifecycleOwner.ownRx(this)
+}
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/view/CoroutineExt.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/view/CoroutineExt.kt
new file mode 100644
index 0000000..fe97aed
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/view/CoroutineExt.kt
@@ -0,0 +1,35 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.view
+
+import android.view.View
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.Job
+import kotlin.coroutines.CoroutineContext
+
+fun View.scopeWhileAttached(
+ context: CoroutineContext,
+ exec: CoroutineScope.() -> Unit
+) {
+ val job = Job(context[Job])
+
+ addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
+ override fun onViewAttachedToWindow(v: View) = Unit
+ override fun onViewDetachedFromWindow(v: View) = job.cancel()
+ })
+
+ exec(CoroutineScope(context + job))
+}
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/view/DebouncedOnClickListener.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/view/DebouncedOnClickListener.kt
new file mode 100644
index 0000000..a7744c0
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/view/DebouncedOnClickListener.kt
@@ -0,0 +1,55 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.common.view
+
+import android.view.View
+import java.lang.System.currentTimeMillis
+
+private const val DEFAULT_DEBOUNCE_INTERVAL = 750L
+
+/** @author Aidan Follestad (@afollestad) */
+abstract class DebouncedOnClickListener(
+ private val delayBetweenClicks: Long = DEFAULT_DEBOUNCE_INTERVAL
+) : View.OnClickListener {
+
+ private var lastClickTimestamp = -1L
+
+ @Deprecated(
+ message = "onDebouncedClick should be overridden instead.",
+ replaceWith = ReplaceWith("onDebouncedClick(v)")
+ )
+ override fun onClick(v: View) {
+ val now = currentTimeMillis()
+ if (lastClickTimestamp == -1L || now >= (lastClickTimestamp + delayBetweenClicks)) {
+ onDebouncedClick(v)
+ }
+ lastClickTimestamp = now
+ }
+
+ abstract fun onDebouncedClick(v: View)
+}
+
+/** @author Aidan Follestad (@afollestad) */
+fun View.onDebouncedClick(
+ delayBetweenClicks: Long = DEFAULT_DEBOUNCE_INTERVAL,
+ click: (view: View) -> Unit
+) {
+ setOnClickListener(object : DebouncedOnClickListener(delayBetweenClicks) {
+ override fun onDebouncedClick(v: View) {
+ click(v)
+ }
+ })
+}
diff --git a/common/src/main/java/com/afollestad/mnmlscreenrecord/common/view/ViewExt.kt b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/view/ViewExt.kt
new file mode 100644
index 0000000..6aa4345
--- /dev/null
+++ b/common/src/main/java/com/afollestad/mnmlscreenrecord/common/view/ViewExt.kt
@@ -0,0 +1,148 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+@file:JvmName("LivedataViewExtKt")
+
+package com.afollestad.mnmlscreenrecord.common.view
+
+import android.text.Editable
+import android.text.TextWatcher
+import android.view.View
+import android.view.View.GONE
+import android.view.View.INVISIBLE
+import android.view.View.VISIBLE
+import android.view.ViewGroup
+import android.view.ViewTreeObserver
+import android.widget.EditText
+import androidx.annotation.DimenRes
+import androidx.annotation.IntRange
+import androidx.recyclerview.widget.RecyclerView
+import kotlin.math.abs
+
+data class Size(
+ val width: Int,
+ val height: Int
+)
+
+data class Coordinate(
+ val x: Int,
+ val y: Int
+)
+
+fun Coordinate.isNear(
+ other: Coordinate,
+ threshold: Int
+): Boolean {
+ return abs(x - other.x) <= threshold &&
+ abs(y - other.y) <= threshold
+}
+
+fun View.size() = Size(measuredWidth, measuredHeight)
+
+fun View.locationOnScreen(): Coordinate {
+ val location = IntArray(2)
+ getLocationOnScreen(location)
+ return Coordinate(location[0], location[1])
+}
+
+fun View.show() {
+ visibility = VISIBLE
+}
+
+fun View.conceal() {
+ visibility = INVISIBLE
+}
+
+fun View.hide() {
+ visibility = GONE
+}
+
+fun View.enable() {
+ isEnabled = true
+}
+
+fun View.disable() {
+ isEnabled = false
+}
+
+fun View.childAt(index: Int): T {
+ @Suppress("UNCHECKED_CAST")
+ return (this as ViewGroup).getChildAt(index) as T
+}
+
+fun View.showOrHide(show: Boolean) = if (show) show() else hide()
+
+fun View.onLayout(cb: (view: View) -> Unit) {
+ if (this.viewTreeObserver.isAlive) {
+ this.viewTreeObserver.addOnGlobalLayoutListener(
+ object : ViewTreeObserver.OnGlobalLayoutListener {
+ override fun onGlobalLayout() {
+ cb(this@onLayout)
+ this@onLayout.viewTreeObserver.removeOnGlobalLayoutListener(this)
+ }
+ })
+ }
+}
+
+fun View.dimenFloat(@DimenRes res: Int) = resources.getDimension(res)
+
+fun View.dimenInt(@DimenRes res: Int) = resources.getDimensionPixelSize(res)
+
+fun EditText.onTextChanged(
+ @IntRange(from = 0, to = 10000) debounce: Int = 0,
+ cb: (String) -> Unit
+) {
+ addTextChangedListener(object : TextWatcher {
+ val callbackRunner = Runnable {
+ cb(text.trim().toString())
+ }
+
+ override fun afterTextChanged(s: Editable?) = Unit
+
+ override fun beforeTextChanged(
+ s: CharSequence,
+ start: Int,
+ count: Int,
+ after: Int
+ ) = Unit
+
+ override fun onTextChanged(
+ s: CharSequence,
+ start: Int,
+ before: Int,
+ count: Int
+ ) {
+ removeCallbacks(callbackRunner)
+ if (debounce == 0) {
+ callbackRunner.run()
+ } else {
+ postDelayed(callbackRunner, debounce.toLong())
+ }
+ }
+ })
+}
+
+fun RecyclerView.onScroll(scroll: (Int) -> Unit) {
+ addOnScrollListener(object : RecyclerView.OnScrollListener() {
+ override fun onScrolled(
+ recyclerView: RecyclerView,
+ dx: Int,
+ dy: Int
+ ) {
+ super.onScrolled(recyclerView, dx, dy)
+ scroll(computeVerticalScrollOffset())
+ }
+ })
+}
diff --git a/common/src/main/res/values/ids.xml b/common/src/main/res/values/ids.xml
new file mode 100644
index 0000000..00db210
--- /dev/null
+++ b/common/src/main/res/values/ids.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/dependencies.gradle b/dependencies.gradle
new file mode 100644
index 0000000..102433f
--- /dev/null
+++ b/dependencies.gradle
@@ -0,0 +1,35 @@
+ext.versions = [
+ minSdk : 26,
+ compileSdk : 28,
+ buildTools : '28.0.3',
+ publishVersion : '1.0.0',
+ publishVersionCode: 1,
+
+ gradlePlugin : '3.2.1',
+ spotlessPlugin : '3.16.0',
+ versionPlugin : '0.20.0',
+
+ kotlin : '1.3.10',
+ coroutines : '1.0.1',
+ koin : '1.0.2',
+
+ androidx : '1.0.0',
+ lifecycle : '2.0.0',
+
+ rxBinding : '3.0.0-alpha1',
+ glide : '4.8.0',
+
+ materialDialogs : '2.0.0-rc3',
+ rxkPrefs : '1.2.0',
+ assent : '2.2.0',
+
+ timber : '4.7.1',
+ junit : '4.12',
+ mockito : '2.23.0',
+ mockitoKotlin : '2.0.0-RC1',
+ truth : '0.42',
+
+ androidxTestRunner: '1.1.0',
+ androidxTest : '1.1.0',
+ archTesting : '2.0.0'
+]
diff --git a/engine/.gitignore b/engine/.gitignore
new file mode 100644
index 0000000..796b96d
--- /dev/null
+++ b/engine/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/engine/build.gradle b/engine/build.gradle
new file mode 100644
index 0000000..0a7984c
--- /dev/null
+++ b/engine/build.gradle
@@ -0,0 +1,39 @@
+apply from: '../dependencies.gradle'
+apply plugin: 'com.android.library'
+apply plugin: 'kotlin-android'
+
+android {
+ compileSdkVersion versions.compileSdk
+
+ defaultConfig {
+ minSdkVersion versions.minSdk
+ targetSdkVersion versions.compileSdk
+ versionCode versions.publishVersionCode
+ versionName versions.publishVersion
+ }
+}
+
+dependencies {
+ implementation project(':common')
+ implementation project(':notifications')
+ implementation project(':theming')
+
+ api 'androidx.appcompat:appcompat:' + versions.androidx
+ api 'com.google.android.material:material:' + versions.androidx
+
+ api 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:' + versions.kotlin
+ api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:' + versions.coroutines
+ api 'org.jetbrains.kotlinx:kotlinx-coroutines-android:' + versions.coroutines
+
+ api 'androidx.lifecycle:lifecycle-extensions:' + versions.lifecycle
+
+ api 'org.koin:koin-android:' + versions.koin
+ api 'com.jakewharton.timber:timber:' + versions.timber
+
+ testImplementation 'junit:junit:' + versions.junit
+ testImplementation 'org.mockito:mockito-core:' + versions.mockito
+ testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:' + versions.mockitoKotlin
+ testImplementation 'com.google.truth:truth:' + versions.truth
+}
+
+apply from: '../spotless.gradle'
\ No newline at end of file
diff --git a/engine/src/main/AndroidManifest.xml b/engine/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..8975cb7
--- /dev/null
+++ b/engine/src/main/AndroidManifest.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/EngineModule.kt b/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/EngineModule.kt
new file mode 100644
index 0000000..f2ede58
--- /dev/null
+++ b/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/EngineModule.kt
@@ -0,0 +1,53 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.engine
+
+import android.app.Application
+import android.content.Context
+import android.content.Context.MEDIA_PROJECTION_SERVICE
+import android.media.projection.MediaProjectionManager
+import android.view.LayoutInflater
+import android.view.WindowManager
+import androidx.appcompat.view.ContextThemeWrapper
+import com.afollestad.mnmlscreenrecord.common.misc.systemService
+import com.afollestad.mnmlscreenrecord.common.prefs.PrefNames.PREF_COUNTDOWN
+import com.afollestad.mnmlscreenrecord.engine.capture.CaptureEngine
+import com.afollestad.mnmlscreenrecord.engine.loader.RecordingQueryer
+import com.afollestad.mnmlscreenrecord.engine.overlay.OverlayManager
+import org.koin.dsl.module.module
+
+/** @author Aidan Follestad (@afollestad) */
+val engineModule = module {
+
+ factory {
+ val themedContext = ContextThemeWrapper(get(), R.style.AppTheme)
+ LayoutInflater.from(themedContext)
+ }
+
+ factory {
+ get().systemService(Context.WINDOW_SERVICE)
+ }
+
+ single {
+ get().systemService(MEDIA_PROJECTION_SERVICE)
+ }
+
+ factory { RecordingQueryer(get()) }
+
+ single { CaptureEngine(get(), get()) }
+
+ factory { OverlayManager(get(), get(), get(name = PREF_COUNTDOWN)) }
+}
diff --git a/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/capture/CaptureEngine.kt b/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/capture/CaptureEngine.kt
new file mode 100644
index 0000000..fa3fda7
--- /dev/null
+++ b/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/capture/CaptureEngine.kt
@@ -0,0 +1,204 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.engine.capture
+
+import android.annotation.SuppressLint
+import android.app.Activity
+import android.content.Context
+import android.content.Intent
+import android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK
+import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
+import android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR
+import android.hardware.display.VirtualDisplay
+import android.media.MediaRecorder
+import android.media.MediaRecorder.OutputFormat.MPEG_4
+import android.media.MediaRecorder.VideoEncoder.H264
+import android.media.MediaRecorder.VideoSource.SURFACE
+import android.media.projection.MediaProjection
+import android.media.projection.MediaProjectionManager
+import android.os.Environment.getExternalStorageDirectory
+import android.os.Handler
+import android.view.WindowManager
+import androidx.lifecycle.Lifecycle.Event.ON_DESTROY
+import androidx.lifecycle.LifecycleObserver
+import androidx.lifecycle.OnLifecycleEvent
+import com.afollestad.mnmlscreenrecord.common.misc.timestampString
+import io.reactivex.Observable
+import io.reactivex.subjects.PublishSubject
+import java.io.File
+import java.util.Date
+import timber.log.Timber.d as log
+
+const val CAPTURE_FOLDER_NAME = "MNML Screen Recorder"
+
+/** @author Aidan Follestad (@afollestad) */
+class CaptureEngine(
+ private val windowManager: WindowManager,
+ private val projectionManager: MediaProjectionManager
+) : LifecycleObserver {
+
+ private lateinit var recordingInfo: RecordingInfo
+ private val handler = Handler()
+
+ private var recorder: MediaRecorder? = null
+ private var projection: MediaProjection? = null
+ private var display: VirtualDisplay? = null
+ private var pendingFile: File? = null
+ private var onStart = PublishSubject.create()
+ private var onStop = PublishSubject.create()
+ private var isStarted: Boolean = false
+
+ fun onStart(): Observable = onStart
+
+ fun onStop(): Observable = onStop
+
+ fun isStarted() = isStarted
+
+ fun start(context: Context) {
+ log("start($context)")
+ recordingInfo = RecordingInfo.get(context, windowManager)
+ createAndPrepareRecorder(recordingInfo)
+
+ if (projection == null) {
+ log("Projection is null, requesting permission...")
+ context.startActivity(
+ Intent(context, CapturePermissionActivity::class.java)
+ .addFlags(FLAG_ACTIVITY_NEW_TASK or FLAG_ACTIVITY_MULTIPLE_TASK)
+ )
+ return
+ }
+
+ createVirtualDisplayAndStart(recordingInfo)
+ }
+
+ fun requestPermission(
+ context: Activity,
+ requestCode: Int
+ ) = context.startActivityForResult(projectionManager.createScreenCaptureIntent(), requestCode)
+
+ fun onActivityResult(
+ resultCode: Int,
+ data: Intent
+ ) {
+ log("onActivityResult($resultCode, $data)")
+ projection = projectionManager.getMediaProjection(resultCode, data)
+ .apply {
+ registerCallback(projectionCallback, null)
+ }
+ createVirtualDisplayAndStart(recordingInfo)
+ }
+
+ fun cancel() {
+ if (pendingFile == null) {
+ return
+ }
+ log("cancel()")
+ pendingFile?.delete()
+ pendingFile = null
+ stop()
+ }
+
+ fun deleteLastRecording() {
+ pendingFile?.delete()
+ pendingFile = null
+ }
+
+ @OnLifecycleEvent(ON_DESTROY)
+ fun stop() {
+ if (recorder == null) {
+ return
+ }
+ isStarted = false
+ log("stop()")
+
+ try {
+ projection?.stop()
+ recorder?.stop()
+ } catch (e: Exception) {
+ log("Got an exception when releasing the media recorder... ${e.message}")
+ e.printStackTrace()
+ }
+
+ recorder?.release()
+ recorder = null
+ display?.release()
+ display = null
+ projection = null
+
+ pendingFile?.let {
+ log("Recorded to $it")
+ onStop.onNext(it)
+ }
+ }
+
+ private fun createAndPrepareRecorder(recordingInfo: RecordingInfo) {
+ recorder = MediaRecorder().apply {
+ setVideoSource(SURFACE)
+ setOutputFormat(MPEG_4)
+ setVideoFrameRate(recordingInfo.frameRate)
+ setVideoEncoder(H264)
+ setVideoSize(recordingInfo.width, recordingInfo.height)
+ setVideoEncodingBitRate(8 * 1000 * 1000)
+
+ val outputFolder = File(getExternalStorageDirectory(), CAPTURE_FOLDER_NAME).apply {
+ mkdirs()
+ }
+ val now = Date().timestampString()
+ val outputFile = File(outputFolder, "MNML-$now.mp4")
+ pendingFile = outputFile
+ setOutputFile(outputFile)
+
+ try {
+ prepare()
+ log("Media recorder prepared")
+ } catch (e: Throwable) {
+ throw RuntimeException("Unable to prepare the MediaRecorder", e)
+ }
+ }
+ }
+
+ @SuppressLint("CheckResult")
+ private fun createVirtualDisplayAndStart(recordingInfo: RecordingInfo) {
+ display = createVirtualDisplay(recordingInfo)
+ // Tiny delay so we don't record the cast "start now" dialog.
+ handler.postDelayed({
+ recorder!!.start()
+ }, 150)
+ onStart.onNext(Unit)
+ isStarted = true
+ log("Media recorder started")
+ }
+
+ private fun createVirtualDisplay(recordingInfo: RecordingInfo): VirtualDisplay {
+ return projection!!.createVirtualDisplay(
+ "MNMLCaptureEngine",
+ recordingInfo.width,
+ recordingInfo.height,
+ recordingInfo.density,
+ VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
+ recorder!!.surface,
+ null,
+ null
+ )
+ }
+
+ private val projectionCallback = object : MediaProjection.Callback() {
+ override fun onStop() {
+ log("Got onStop() in projection callback")
+ this@CaptureEngine.stop()
+ }
+ }
+}
diff --git a/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/capture/CapturePermissionActivity.kt b/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/capture/CapturePermissionActivity.kt
new file mode 100644
index 0000000..5619a83
--- /dev/null
+++ b/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/capture/CapturePermissionActivity.kt
@@ -0,0 +1,60 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.engine.capture
+
+import android.content.Intent
+import android.os.Bundle
+import androidx.appcompat.app.AppCompatActivity
+import com.afollestad.mnmlscreenrecord.common.misc.toast
+import com.afollestad.mnmlscreenrecord.engine.service.BackgroundService.Companion.PERMISSION_DENIED
+import org.koin.android.ext.android.inject
+
+/** @author Aidan Follestad (@afollestad) */
+class CapturePermissionActivity : AppCompatActivity() {
+
+ companion object {
+ const val PROJECTION_REQUEST = 97
+ }
+
+ private val captureEngine by inject()
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ captureEngine.requestPermission(this,
+ PROJECTION_REQUEST
+ )
+ }
+
+ override fun onActivityResult(
+ requestCode: Int,
+ resultCode: Int,
+ data: Intent?
+ ) {
+ super.onActivityResult(requestCode, resultCode, data)
+ when {
+ requestCode != PROJECTION_REQUEST -> return
+ resultCode != RESULT_OK -> {
+ toast("Screen cast permission was denied to MNML!")
+ captureEngine.cancel()
+ sendBroadcast(Intent(PERMISSION_DENIED))
+ }
+ else -> {
+ data?.let { captureEngine.onActivityResult(resultCode, it) }
+ }
+ }
+ finish()
+ }
+}
diff --git a/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/capture/RecordingInfo.kt b/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/capture/RecordingInfo.kt
new file mode 100644
index 0000000..4576798
--- /dev/null
+++ b/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/capture/RecordingInfo.kt
@@ -0,0 +1,105 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.engine.capture
+
+import android.content.Context
+import android.content.res.Configuration.ORIENTATION_LANDSCAPE
+import android.media.CamcorderProfile
+import android.media.CamcorderProfile.QUALITY_HIGH
+import android.view.WindowManager
+import com.afollestad.mnmlscreenrecord.common.misc.DisplayInfo
+import com.afollestad.mnmlscreenrecord.common.misc.displayInfo
+import com.afollestad.mnmlscreenrecord.engine.capture.RecordingInfo.Companion
+import timber.log.Timber
+
+data class RecordingInfo(
+ val width: Int,
+ val height: Int,
+ val frameRate: Int,
+ val density: Int
+) {
+ companion object
+}
+
+fun Companion.get(
+ context: Context,
+ windowManager: WindowManager
+): RecordingInfo {
+ val displayInfo = windowManager.displayInfo()
+
+ val configuration = context.resources.configuration
+ val isLandscape = configuration.orientation == ORIENTATION_LANDSCAPE
+ log("Display landscape: $isLandscape")
+
+ // Get the best camera profile available. We assume MediaRecorder supports the highest.
+ val camcorderProfile = CamcorderProfile.get(QUALITY_HIGH)
+ val cameraWidth = camcorderProfile?.videoFrameWidth ?: -1
+ val cameraHeight = camcorderProfile?.videoFrameHeight ?: -1
+ val cameraFrameRate = camcorderProfile?.videoFrameRate ?: 30
+ log("Camera size: $cameraWidth x $cameraHeight frameRate: $cameraFrameRate")
+
+ val sizePercentage = 100 // TODO
+ log("Size percentage: $sizePercentage")
+
+ return calculateRecordingInfo(
+ displayInfo, isLandscape, cameraWidth, cameraHeight,
+ cameraFrameRate, sizePercentage
+ )
+}
+
+private fun Companion.log(message: String) {
+ Timber.tag("RecordingInfo")
+ Timber.d(message)
+}
+
+private fun Companion.calculateRecordingInfo(
+ displayInfo: DisplayInfo,
+ isLandscapeDevice: Boolean,
+ cameraWidth: Int,
+ cameraHeight: Int,
+ cameraFrameRate: Int,
+ sizePercentage: Int
+): RecordingInfo {
+ // Scale the display size before any maximum size calculations.
+ val displayWidth = displayInfo.width * sizePercentage / 100
+ val displayHeight = displayInfo.height * sizePercentage / 100
+
+ if (cameraWidth == -1 && cameraHeight == -1) {
+ // No cameras. Fall back to the display size.
+ return RecordingInfo(
+ displayWidth, displayHeight, cameraFrameRate, displayInfo.density
+ )
+ }
+
+ var frameWidth = if (isLandscapeDevice) cameraWidth else cameraHeight
+ var frameHeight = if (isLandscapeDevice) cameraHeight else cameraWidth
+ if (frameWidth >= displayWidth && frameHeight >= displayHeight) {
+ // Frame can hold the entire display. Use exact values.
+ return RecordingInfo(
+ displayWidth, displayHeight, cameraFrameRate, displayInfo.density
+ )
+ }
+
+ // Calculate new width or height to preserve aspect ratio.
+ if (isLandscapeDevice) {
+ frameWidth = displayWidth * frameHeight / displayHeight
+ } else {
+ frameHeight = displayHeight * frameWidth / displayWidth
+ }
+ return RecordingInfo(
+ frameWidth, frameHeight, cameraFrameRate, displayInfo.density
+ )
+}
diff --git a/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/loader/Recording.kt b/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/loader/Recording.kt
new file mode 100644
index 0000000..02943d2
--- /dev/null
+++ b/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/loader/Recording.kt
@@ -0,0 +1,48 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.engine.loader
+
+import android.database.Cursor
+import com.afollestad.mnmlscreenrecord.common.misc.friendlyDate
+import com.afollestad.mnmlscreenrecord.common.misc.friendlySize
+import com.afollestad.mnmlscreenrecord.common.misc.toUri
+
+/** @author Aidan Follestad (@afollestad) */
+data class Recording(
+ val id: Long,
+ val path: String,
+ val name: String,
+ val timestamp: Long,
+ val size: Long
+) {
+ companion object {
+ fun pull(cursor: Cursor): Recording {
+ return Recording(
+ id = cursor.getLong(cursor.getColumnIndex("_id")),
+ path = cursor.getString(cursor.getColumnIndex("_data")),
+ name = cursor.getString(cursor.getColumnIndex("title")),
+ timestamp = cursor.getLong(cursor.getColumnIndex("date_added")),
+ size = cursor.getLong(cursor.getColumnIndex("_size"))
+ )
+ }
+ }
+
+ fun sizeString() = size.friendlySize()
+
+ fun timestampString() = timestamp.friendlyDate()
+
+ fun toUri() = "$VIDEOS_URI/$id".toUri()
+}
diff --git a/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/loader/RecordingQueryer.kt b/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/loader/RecordingQueryer.kt
new file mode 100644
index 0000000..84e61d5
--- /dev/null
+++ b/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/loader/RecordingQueryer.kt
@@ -0,0 +1,76 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.engine.loader
+
+import android.annotation.SuppressLint
+import android.app.Application
+import androidx.lifecycle.Lifecycle.Event.ON_START
+import androidx.lifecycle.Lifecycle.Event.ON_STOP
+import androidx.lifecycle.LifecycleObserver
+import androidx.lifecycle.OnLifecycleEvent
+import com.afollestad.mnmlscreenrecord.common.misc.toUri
+import com.afollestad.mnmlscreenrecord.engine.capture.CAPTURE_FOLDER_NAME
+
+const val VIDEOS_URI = "content://media/external/video/media"
+
+class RecordingQueryer(app: Application) : LifecycleObserver {
+
+ private var isStarted = false
+ private var isQuerying = false
+ private val contentResolver = app.contentResolver
+
+ @OnLifecycleEvent(ON_START)
+ fun onStart() {
+ isStarted = true
+ }
+
+ @OnLifecycleEvent(ON_STOP)
+ fun onStop() {
+ isStarted = false
+ }
+
+ @SuppressLint("Recycle")
+ fun queryRecordings(): List {
+ if (!isStarted) {
+ return emptyList()
+ }
+ isQuerying = true
+
+ val cursor = contentResolver.query(
+ VIDEOS_URI.toUri(), // uri
+ null, // projection
+ "bucket_display_name = ?", // selection
+ arrayOf(CAPTURE_FOLDER_NAME), // selectionArgs
+ "date_added DESC" // sortOrder
+ )!!
+
+ cursor.use {
+ return mutableListOf().also { list ->
+ if (it.moveToFirst()) {
+ do {
+ if (!isStarted) {
+ break
+ }
+ list.add(Recording.pull(it))
+ } while (cursor.moveToNext())
+ }
+ isQuerying = false
+ }
+ }
+ }
+
+ fun isQuerying() = isQuerying
+}
diff --git a/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/overlay/OverlayManager.kt b/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/overlay/OverlayManager.kt
new file mode 100644
index 0000000..54269d7
--- /dev/null
+++ b/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/overlay/OverlayManager.kt
@@ -0,0 +1,78 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.engine.overlay
+
+import android.graphics.PixelFormat.TRANSLUCENT
+import android.view.LayoutInflater
+import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
+import android.view.WindowManager
+import android.view.WindowManager.LayoutParams
+import android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
+import android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
+import android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
+import android.widget.TextView
+import com.afollestad.mnmlscreenrecord.common.misc.inflate
+import com.afollestad.mnmlscreenrecord.engine.R
+import com.afollestad.rxkprefs.Pref
+
+/** @author Aidan Follestad (@afollestad) **/
+class OverlayManager(
+ private val windowManager: WindowManager,
+ private val layoutInflater: LayoutInflater,
+ private val countdownPref: Pref
+) {
+ companion object {
+ private const val SECOND = 1000L
+ }
+
+ fun countdown(finished: () -> Unit) {
+ val time = countdownPref.get()
+ if (time <= 0) {
+ finished()
+ return
+ }
+
+ val textView: TextView = layoutInflater.inflate(R.layout.countdown_textview)
+ textView.text = "$time"
+
+ val params = LayoutParams(
+ WRAP_CONTENT, // width
+ WRAP_CONTENT, // height
+ TYPE_APPLICATION_OVERLAY, // type
+ FLAG_NOT_FOCUSABLE or FLAG_NOT_TOUCH_MODAL, // flags
+ TRANSLUCENT // format
+ )
+ windowManager.addView(textView, params)
+
+ nextCountdown(textView, time, finished)
+ }
+
+ private fun nextCountdown(
+ view: TextView,
+ nextSecond: Int,
+ finished: () -> Unit
+ ) {
+ view.text = "$nextSecond"
+ if (nextSecond == 0) {
+ windowManager.removeView(view)
+ finished()
+ return
+ }
+ view.postDelayed({
+ nextCountdown(view, nextSecond - 1, finished)
+ }, SECOND)
+ }
+}
diff --git a/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/service/BackgroundService.kt b/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/service/BackgroundService.kt
new file mode 100644
index 0000000..33d8e9e
--- /dev/null
+++ b/engine/src/main/java/com/afollestad/mnmlscreenrecord/engine/service/BackgroundService.kt
@@ -0,0 +1,141 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.engine.service
+
+import android.app.Service
+import android.content.Intent
+import android.content.Intent.ACTION_SCREEN_OFF
+import android.os.IBinder
+import androidx.lifecycle.LifecycleOwner
+import com.afollestad.mnmlscreenrecord.common.files.FileScanner
+import com.afollestad.mnmlscreenrecord.common.intent.IntentReceiver
+import com.afollestad.mnmlscreenrecord.common.lifecycle.SimpleLifecycle
+import com.afollestad.mnmlscreenrecord.common.rx.attachLifecycle
+import com.afollestad.mnmlscreenrecord.engine.capture.CaptureEngine
+import com.afollestad.mnmlscreenrecord.engine.overlay.OverlayManager
+import com.afollestad.mnmlscreenrecord.notifications.DELETE_ACTION
+import com.afollestad.mnmlscreenrecord.notifications.EXIT_ACTION
+import com.afollestad.mnmlscreenrecord.notifications.Notifications
+import com.afollestad.mnmlscreenrecord.notifications.RECORD_ACTION
+import com.afollestad.mnmlscreenrecord.notifications.STOP_ACTION
+import org.koin.android.ext.android.inject
+import timber.log.Timber.d as log
+
+/** @author Aidan Follestad (@afollestad) */
+class BackgroundService : Service(), LifecycleOwner {
+
+ companion object {
+ private const val ID = 77
+
+ const val PERMISSION_DENIED =
+ "com.afollestad.mnmlscreenrecord.service.PERMISSION_DENIED"
+ const val MAIN_ACTIVITY_CLASS = "main_activity_class"
+ }
+
+ private val lifecycle = SimpleLifecycle(this)
+ private val overlayManager by inject()
+ private val notifications by inject()
+ private val captureEngine by inject()
+ private val uriScanner by inject()
+ private val mainActivityClass by inject>(name = MAIN_ACTIVITY_CLASS)
+
+ override fun onBind(intent: Intent?): IBinder? = null
+
+ override fun onStartCommand(
+ intent: Intent?,
+ flags: Int,
+ startId: Int
+ ): Int {
+ log("onStartCommand(${intent?.action})")
+ if (intent?.action == RECORD_ACTION) {
+ overlayManager.countdown {
+ captureEngine.start(this@BackgroundService)
+ updateForeground(true)
+ }
+ }
+ return START_STICKY
+ }
+
+ override fun onCreate() {
+ super.onCreate()
+ log("onCreate()")
+
+ // Intent broadcasts
+ IntentReceiver(this) {
+ onAction(PERMISSION_DENIED) {
+ updateForeground(false)
+ }
+ onAction(ACTION_SCREEN_OFF) {
+ captureEngine.stop()
+ }
+ onAction(STOP_ACTION) {
+ captureEngine.stop()
+ }
+ onAction(DELETE_ACTION) {
+ captureEngine.deleteLastRecording()
+ notifications.cancelPostRecordNotification()
+ }
+ onAction(EXIT_ACTION) {
+ captureEngine.cancel()
+ stopForeground(true)
+ stopSelf()
+ }
+ }
+
+ // Lifecycle observers
+ lifecycle.run {
+ addObserver(captureEngine)
+ }
+
+ // Foreground notification
+ updateForeground(false)
+ lifecycle.onCreate()
+
+ captureEngine.onStop()
+ .subscribe { file ->
+ updateForeground(false)
+ uriScanner.scan(file) { resultUri ->
+ notifications.showPostRecordNotification(resultUri)
+ }
+ }
+ .attachLifecycle(this)
+ }
+
+ override fun onDestroy() {
+ log("onDestroy()")
+ lifecycle.onDestroy()
+ super.onDestroy()
+ }
+
+ override fun getLifecycle() = lifecycle
+
+ private fun updateForeground(recording: Boolean) {
+ val action = if (recording) {
+ STOP_ACTION
+ } else {
+ EXIT_ACTION
+ }
+ startForeground(
+ ID,
+ notifications.createWidgetServiceNotification(
+ mainActivity = mainActivityClass,
+ backgroundService = this::class.java,
+ action = action,
+ isRecording = recording
+ )
+ )
+ }
+}
diff --git a/engine/src/main/res/layout/countdown_textview.xml b/engine/src/main/res/layout/countdown_textview.xml
new file mode 100644
index 0000000..f386eb2
--- /dev/null
+++ b/engine/src/main/res/layout/countdown_textview.xml
@@ -0,0 +1,15 @@
+
+
diff --git a/engine/src/main/res/values/colors.xml b/engine/src/main/res/values/colors.xml
new file mode 100644
index 0000000..391944f
--- /dev/null
+++ b/engine/src/main/res/values/colors.xml
@@ -0,0 +1,4 @@
+
+
+ #E53935
+
diff --git a/engine/src/main/res/xml/provider_paths.xml b/engine/src/main/res/xml/provider_paths.xml
new file mode 100644
index 0000000..77112de
--- /dev/null
+++ b/engine/src/main/res/xml/provider_paths.xml
@@ -0,0 +1,6 @@
+
+
+
+
diff --git a/gradle.properties b/gradle.properties
new file mode 100644
index 0000000..3cf2d32
--- /dev/null
+++ b/gradle.properties
@@ -0,0 +1,18 @@
+# Project-wide Gradle settings.
+# IDE (e.g. Android Studio) users:
+# Gradle settings configured through the IDE *will override*
+# any settings specified in this file.
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+org.gradle.jvmargs=-Xmx1536m
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
+# Kotlin code style for this project: "official" or "obsolete":
+kotlin.code.style=official
+
+android.enableJetifier=true
+android.useAndroidX=true
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..f6b961f
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..9a4163a
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,5 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
new file mode 100755
index 0000000..cccdd3d
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,172 @@
+#!/usr/bin/env sh
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+ echo "$*"
+}
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+ NONSTOP* )
+ nonstop=true
+ ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Escape application args
+save () {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
+}
+APP_ARGS=$(save "$@")
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
+if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
+ cd "$(dirname "$0")"
+fi
+
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 0000000..e95643d
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,84 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/notifications/.gitignore b/notifications/.gitignore
new file mode 100644
index 0000000..796b96d
--- /dev/null
+++ b/notifications/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/notifications/build.gradle b/notifications/build.gradle
new file mode 100644
index 0000000..6d753f8
--- /dev/null
+++ b/notifications/build.gradle
@@ -0,0 +1,30 @@
+apply from: '../dependencies.gradle'
+apply plugin: 'com.android.library'
+apply plugin: 'kotlin-android'
+
+android {
+ compileSdkVersion versions.compileSdk
+
+ defaultConfig {
+ minSdkVersion versions.minSdk
+ targetSdkVersion versions.compileSdk
+ versionCode versions.publishVersionCode
+ versionName versions.publishVersion
+ }
+}
+
+dependencies {
+ implementation project(':common')
+
+ api 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:' + versions.kotlin
+
+ api 'org.koin:koin-android:' + versions.koin
+ api 'com.jakewharton.timber:timber:' + versions.timber
+
+ testImplementation 'junit:junit:' + versions.junit
+ testImplementation 'org.mockito:mockito-core:' + versions.mockito
+ testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:' + versions.mockitoKotlin
+ testImplementation 'com.google.truth:truth:' + versions.truth
+}
+
+apply from: '../spotless.gradle'
\ No newline at end of file
diff --git a/notifications/src/main/AndroidManifest.xml b/notifications/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..f24d8cc
--- /dev/null
+++ b/notifications/src/main/AndroidManifest.xml
@@ -0,0 +1,2 @@
+
diff --git a/notifications/src/main/java/com/afollestad/mnmlscreenrecord/notifications/Channel.kt b/notifications/src/main/java/com/afollestad/mnmlscreenrecord/notifications/Channel.kt
new file mode 100644
index 0000000..dad06e1
--- /dev/null
+++ b/notifications/src/main/java/com/afollestad/mnmlscreenrecord/notifications/Channel.kt
@@ -0,0 +1,40 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.notifications
+
+import androidx.core.app.NotificationManagerCompat.IMPORTANCE_DEFAULT
+import androidx.core.app.NotificationManagerCompat.IMPORTANCE_HIGH
+
+/** @author Aidan Follestad (@afollestad) */
+enum class Channel(
+ val id: String,
+ val title: String,
+ val description: String,
+ val importance: Int
+) {
+ FOREGROUND_SERVICE(
+ "foreground_services",
+ "Foreground Services",
+ "Notifications for persistent controls.",
+ IMPORTANCE_DEFAULT
+ ),
+ VIDEO_RECORDED(
+ "video_recorded",
+ "After Video Recording",
+ "Used to display a notification when you've finished recording a screen capture.",
+ IMPORTANCE_HIGH
+ )
+}
diff --git a/notifications/src/main/java/com/afollestad/mnmlscreenrecord/notifications/Notifications.kt b/notifications/src/main/java/com/afollestad/mnmlscreenrecord/notifications/Notifications.kt
new file mode 100644
index 0000000..f59e668
--- /dev/null
+++ b/notifications/src/main/java/com/afollestad/mnmlscreenrecord/notifications/Notifications.kt
@@ -0,0 +1,232 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.notifications
+
+import android.app.Application
+import android.app.Notification
+import android.app.NotificationChannel
+import android.app.NotificationManager
+import android.app.PendingIntent
+import android.app.PendingIntent.FLAG_CANCEL_CURRENT
+import android.content.Intent
+import android.content.Intent.ACTION_SEND
+import android.content.Intent.ACTION_VIEW
+import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
+import android.media.MediaMetadataRetriever
+import android.net.Uri
+import android.widget.RemoteViews
+import androidx.core.app.NotificationCompat
+import com.afollestad.mnmlscreenrecord.common.misc.setViewVisibility
+import kotlinx.coroutines.Dispatchers.IO
+import kotlinx.coroutines.Dispatchers.Unconfined
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.GlobalScope
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+import timber.log.Timber.d as log
+
+const val RECORD_ACTION = "com.afollestad.mnmlscreenrecord.service.START_RECORDING"
+const val STOP_ACTION = "com.afollestad.mnmlscreenrecord.service.STOP_RECORDING"
+const val DELETE_ACTION = "com.afollestad.mnmlscreenrecord.service.DELETE_RECORDING"
+const val EXIT_ACTION = "com.afollestad.mnmlscreenrecord.service.EXIT_FOREGROUND"
+
+interface Notifications {
+
+ fun setIsAppOpen(open: Boolean)
+
+ fun createChannels()
+
+ fun createWidgetServiceNotification(
+ mainActivity: Class<*>,
+ backgroundService: Class<*>,
+ action: String,
+ isRecording: Boolean
+ ): Notification
+
+ fun showPostRecordNotification(uri: Uri)
+
+ fun cancelPostRecordNotification()
+}
+
+/** @author Aidan Follestad (@afollestad) */
+class RealNotifications(
+ private val app: Application,
+ private val stockManager: NotificationManager
+) : Notifications {
+
+ companion object {
+ private const val ID_POST_RECORD = 33
+
+ private const val MAIN_ACTIVITY_REQUEST = 90
+ private const val RECORD_REQUEST = 91
+ private const val STOP_REQUEST = 92
+ private const val EXIT_REQUEST = 93
+
+ private const val VIEW_REQUEST = 94
+ private const val SHARE_REQUEST = 95
+ private const val DELETE_REQUEST = 96
+ }
+
+ private var isAppOpen: Boolean = false
+
+ override fun setIsAppOpen(open: Boolean) {
+ log("Is app open? $open")
+ isAppOpen = open
+ }
+
+ override fun createChannels() {
+ Channel.values()
+ .forEach(this::createChannel)
+ }
+
+ override fun createWidgetServiceNotification(
+ mainActivity: Class<*>,
+ backgroundService: Class<*>,
+ action: String,
+ isRecording: Boolean
+ ): Notification {
+ val channel = Channel.FOREGROUND_SERVICE.id
+ val contentText = if (isRecording) {
+ R.string.recording_notification_text
+ } else {
+ R.string.widget_service_notification_text
+ }
+
+ val appIntent = PendingIntent.getActivity(
+ app,
+ MAIN_ACTIVITY_REQUEST,
+ Intent(app, mainActivity).addFlags(FLAG_ACTIVITY_NEW_TASK),
+ FLAG_CANCEL_CURRENT
+ )
+ val recordIntent = PendingIntent.getService(
+ app,
+ RECORD_REQUEST,
+ Intent(app, backgroundService).setAction(RECORD_ACTION),
+ FLAG_CANCEL_CURRENT
+ )
+
+ val remoteViews = RemoteViews(
+ "com.afollestad.mnmlscreenrecord",
+ R.layout.foreground_notification
+ ).apply {
+ setOnClickPendingIntent(R.id.action_record, recordIntent)
+ setViewVisibility(R.id.action_record, !isRecording)
+ setOnClickPendingIntent(R.id.action_stop, broadcast(STOP_REQUEST, STOP_ACTION))
+ setViewVisibility(R.id.action_stop, isRecording)
+ setOnClickPendingIntent(R.id.action_exit, broadcast(EXIT_REQUEST, EXIT_ACTION))
+ }
+
+ return NotificationCompat.Builder(app, channel)
+ .apply {
+ setSmallIcon(R.drawable.ic_record_32dp)
+ setContentIntent(appIntent)
+ setStyle(NotificationCompat.DecoratedCustomViewStyle())
+ setCustomContentView(remoteViews)
+ setContentTitle(app.getString(R.string.app_name))
+ setContentText(app.getString(contentText))
+ }
+ .build()
+ }
+
+ @ExperimentalCoroutinesApi
+ override fun showPostRecordNotification(uri: Uri) {
+ if (isAppOpen) {
+ log("App is open, won't create a post-record notification.")
+ return
+ }
+
+ log("Creating post-record notification for: $uri")
+ val channel = Channel.VIDEO_RECORDED.id
+ val viewPendingIntent = PendingIntent.getActivity(
+ app,
+ VIEW_REQUEST,
+ Intent(ACTION_VIEW).apply {
+ setDataAndType(uri, "video/*")
+ },
+ FLAG_CANCEL_CURRENT
+ )
+ val sharePendingIntent = PendingIntent.getActivity(
+ app,
+ SHARE_REQUEST,
+ Intent(ACTION_SEND).apply {
+ setDataAndType(uri, "video/*")
+ },
+ FLAG_CANCEL_CURRENT
+ )
+ val deletePendingIntent = broadcast(DELETE_REQUEST, DELETE_ACTION)
+ val notification = NotificationCompat.Builder(app, channel)
+ .setSmallIcon(R.drawable.ic_video_32dp)
+ .setContentTitle(app.getString(R.string.app_name))
+ .setContentText(app.getString(R.string.video_recorded_notification_text))
+ .setContentIntent(viewPendingIntent)
+ .setAutoCancel(true)
+ .addAction(
+ R.drawable.ic_share_32dp,
+ app.getString(R.string.share),
+ sharePendingIntent
+ )
+ .addAction(
+ R.drawable.ic_delete_32dp,
+ app.getString(R.string.delete),
+ deletePendingIntent
+ )
+ stockManager.notify(ID_POST_RECORD, notification.build())
+
+ GlobalScope.launch(Unconfined) {
+ delay(250)
+ val bitmap = withContext(IO) {
+ val retriever = MediaMetadataRetriever()
+ retriever.setDataSource(app, uri)
+ retriever.frameAtTime
+ }
+ val updatedNotification = notification
+ .apply {
+ setLargeIcon(bitmap)
+ setStyle(
+ NotificationCompat.BigPictureStyle()
+ .bigPicture(bitmap)
+ )
+ }
+ .build()
+ stockManager.notify(ID_POST_RECORD, updatedNotification)
+ }
+ }
+
+ override fun cancelPostRecordNotification() {
+ stockManager.cancel(ID_POST_RECORD)
+ }
+
+ private fun createChannel(channel: Channel) {
+ val newChannel = NotificationChannel(
+ channel.id,
+ channel.title,
+ channel.importance
+ ).apply { description = channel.description }
+ stockManager.createNotificationChannel(newChannel)
+ log("Created notification channel ${channel.id}")
+ }
+
+ private fun broadcast(
+ code: Int,
+ action: String
+ ) = PendingIntent.getBroadcast(
+ app,
+ code,
+ Intent(action),
+ FLAG_CANCEL_CURRENT
+ )
+}
diff --git a/notifications/src/main/java/com/afollestad/mnmlscreenrecord/notifications/NotificationsModule.kt b/notifications/src/main/java/com/afollestad/mnmlscreenrecord/notifications/NotificationsModule.kt
new file mode 100644
index 0000000..2e53521
--- /dev/null
+++ b/notifications/src/main/java/com/afollestad/mnmlscreenrecord/notifications/NotificationsModule.kt
@@ -0,0 +1,32 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.notifications
+
+import android.app.Application
+import android.app.NotificationManager
+import android.content.Context.NOTIFICATION_SERVICE
+import com.afollestad.mnmlscreenrecord.common.misc.systemService
+import org.koin.dsl.module.module
+
+/** @author Aidan Follestad (@afollestad) */
+val notificationsModule = module {
+
+ factory {
+ get().systemService(NOTIFICATION_SERVICE)
+ }
+
+ single { RealNotifications(get(), get()) } bind Notifications::class
+}
diff --git a/notifications/src/main/res/drawable/ic_close_32dp.xml b/notifications/src/main/res/drawable/ic_close_32dp.xml
new file mode 100644
index 0000000..ae66e89
--- /dev/null
+++ b/notifications/src/main/res/drawable/ic_close_32dp.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/notifications/src/main/res/drawable/ic_delete_32dp.xml b/notifications/src/main/res/drawable/ic_delete_32dp.xml
new file mode 100644
index 0000000..b57d5a0
--- /dev/null
+++ b/notifications/src/main/res/drawable/ic_delete_32dp.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/notifications/src/main/res/drawable/ic_record_32dp.xml b/notifications/src/main/res/drawable/ic_record_32dp.xml
new file mode 100644
index 0000000..2dffcfe
--- /dev/null
+++ b/notifications/src/main/res/drawable/ic_record_32dp.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/notifications/src/main/res/drawable/ic_share_32dp.xml b/notifications/src/main/res/drawable/ic_share_32dp.xml
new file mode 100644
index 0000000..67a9e63
--- /dev/null
+++ b/notifications/src/main/res/drawable/ic_share_32dp.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/notifications/src/main/res/drawable/ic_stop_32dp.xml b/notifications/src/main/res/drawable/ic_stop_32dp.xml
new file mode 100644
index 0000000..54b2f9a
--- /dev/null
+++ b/notifications/src/main/res/drawable/ic_stop_32dp.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/notifications/src/main/res/drawable/ic_video_32dp.xml b/notifications/src/main/res/drawable/ic_video_32dp.xml
new file mode 100644
index 0000000..e0ee823
--- /dev/null
+++ b/notifications/src/main/res/drawable/ic_video_32dp.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/notifications/src/main/res/layout/foreground_notification.xml b/notifications/src/main/res/layout/foreground_notification.xml
new file mode 100644
index 0000000..5939eae
--- /dev/null
+++ b/notifications/src/main/res/layout/foreground_notification.xml
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/notifications/src/main/res/values/strings.xml b/notifications/src/main/res/values/strings.xml
new file mode 100644
index 0000000..537ea55
--- /dev/null
+++ b/notifications/src/main/res/values/strings.xml
@@ -0,0 +1,20 @@
+
+ MNML Screen Recorder
+ MNML
+
+
+ The recorder service is running. Tap to open the app.
+
+ Stop Service
+
+ Record
+ Stop
+ Your screen is currently being captured…
+
+ Video recorded successfully! Tap to view and share.
+
+
+ Share
+ Delete
+
+
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..dcccc9a
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1 @@
+include ':app', ':engine', ':common', ':notifications', ':theming'
diff --git a/spotless.gradle b/spotless.gradle
new file mode 100644
index 0000000..fba51c4
--- /dev/null
+++ b/spotless.gradle
@@ -0,0 +1,17 @@
+apply plugin: "com.diffplug.gradle.spotless"
+spotless {
+ java {
+ target "**/*.java"
+ trimTrailingWhitespace()
+ removeUnusedImports()
+ googleJavaFormat()
+ endWithNewline()
+ }
+ kotlin {
+ target "**/*.kt"
+ ktlint().userData(['indent_size': '2', 'continuation_indent_size': '2'])
+ licenseHeaderFile '../spotless.license.kt'
+ trimTrailingWhitespace()
+ endWithNewline()
+ }
+}
\ No newline at end of file
diff --git a/spotless.license.kt b/spotless.license.kt
new file mode 100644
index 0000000..e10880e
--- /dev/null
+++ b/spotless.license.kt
@@ -0,0 +1,15 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
\ No newline at end of file
diff --git a/theming/.gitignore b/theming/.gitignore
new file mode 100644
index 0000000..796b96d
--- /dev/null
+++ b/theming/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/theming/build.gradle b/theming/build.gradle
new file mode 100644
index 0000000..0c3f7a9
--- /dev/null
+++ b/theming/build.gradle
@@ -0,0 +1,26 @@
+apply from: '../dependencies.gradle'
+apply plugin: 'com.android.library'
+apply plugin: 'kotlin-android'
+
+android {
+ compileSdkVersion versions.compileSdk
+
+ defaultConfig {
+ minSdkVersion versions.minSdk
+ targetSdkVersion versions.compileSdk
+ versionCode versions.publishVersionCode
+ versionName versions.publishVersion
+ }
+}
+
+dependencies {
+ implementation project(':common')
+
+ api 'androidx.appcompat:appcompat:' + versions.androidx
+ api 'com.google.android.material:material:' + versions.androidx
+
+ api 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:' + versions.kotlin
+ api 'com.jakewharton.timber:timber:' + versions.timber
+}
+
+apply from: '../spotless.gradle'
\ No newline at end of file
diff --git a/theming/src/main/AndroidManifest.xml b/theming/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..b8d3bd6
--- /dev/null
+++ b/theming/src/main/AndroidManifest.xml
@@ -0,0 +1,2 @@
+
diff --git a/theming/src/main/java/com/afollestad/mnmlscreenrecord/theming/DarkModeSwitchActivity.kt b/theming/src/main/java/com/afollestad/mnmlscreenrecord/theming/DarkModeSwitchActivity.kt
new file mode 100644
index 0000000..5cbd913
--- /dev/null
+++ b/theming/src/main/java/com/afollestad/mnmlscreenrecord/theming/DarkModeSwitchActivity.kt
@@ -0,0 +1,51 @@
+/**
+ * Designed and developed by Aidan Follestad (@afollestad)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.afollestad.mnmlscreenrecord.theming
+
+import android.os.Bundle
+import androidx.appcompat.app.AppCompatActivity
+import com.afollestad.mnmlscreenrecord.common.prefs.PrefNames.PREF_DARK_MODE
+import com.afollestad.mnmlscreenrecord.common.rx.attachLifecycle
+import com.afollestad.rxkprefs.Pref
+import org.koin.android.ext.android.inject
+import timber.log.Timber.d as log
+
+/** @author Aidan Follestad (afollestad) */
+abstract class DarkModeSwitchActivity : AppCompatActivity() {
+
+ private var isDark: Boolean = false
+ protected val darkModePref by inject>(name = PREF_DARK_MODE)
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ isDark = darkModePref.get()
+ setTheme(themeRes())
+ super.onCreate(savedInstanceState)
+
+ darkModePref.observe()
+ .filter { it != isDark }
+ .subscribe {
+ log("Theme changed, recreating Activity.")
+ recreate()
+ }
+ .attachLifecycle(this)
+ }
+
+ private fun themeRes() = if (darkModePref.get()) {
+ R.style.AppTheme_Dark
+ } else {
+ R.style.AppTheme
+ }
+}
diff --git a/theming/src/main/res/values-v27/styles.xml b/theming/src/main/res/values-v27/styles.xml
new file mode 100644
index 0000000..bef5463
--- /dev/null
+++ b/theming/src/main/res/values-v27/styles.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
diff --git a/theming/src/main/res/values/attrs.xml b/theming/src/main/res/values/attrs.xml
new file mode 100644
index 0000000..5de9a28
--- /dev/null
+++ b/theming/src/main/res/values/attrs.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/theming/src/main/res/values/colors.xml b/theming/src/main/res/values/colors.xml
new file mode 100644
index 0000000..cdbe9f8
--- /dev/null
+++ b/theming/src/main/res/values/colors.xml
@@ -0,0 +1,19 @@
+
+
+
+ #E5E5E5
+ #202123
+
+ #FFFFFF
+ #333333
+
+ #FFFFFF
+ #F5F5F5
+
+ #212121
+ #000000
+
+ #2979FF
+ #402979FF
+
+
diff --git a/theming/src/main/res/values/styles.xml b/theming/src/main/res/values/styles.xml
new file mode 100644
index 0000000..c3e056b
--- /dev/null
+++ b/theming/src/main/res/values/styles.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
diff --git a/versionsPlugin.gradle b/versionsPlugin.gradle
new file mode 100644
index 0000000..1062c5f
--- /dev/null
+++ b/versionsPlugin.gradle
@@ -0,0 +1,14 @@
+apply plugin: "com.github.ben-manes.versions"
+
+dependencyUpdates.resolutionStrategy {
+ componentSelection { rules ->
+ rules.all { ComponentSelection selection ->
+ boolean rejected = ['alpha', 'beta', 'rc', 'cr', 'm'].any { qualifier ->
+ selection.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-]*/
+ }
+ if (rejected) {
+ selection.reject('Not stable')
+ }
+ }
+ }
+}