├── app
├── .gitignore
├── src
│ └── main
│ │ ├── assets
│ │ └── folder
│ │ │ ├── file.txt
│ │ │ ├── folder1
│ │ │ ├── file1.txt
│ │ │ ├── folder2
│ │ │ │ ├── file2.txt
│ │ │ │ ├── folder3
│ │ │ │ │ ├── file3.txt
│ │ │ │ │ ├── font3.ttf
│ │ │ │ │ └── icon3.png
│ │ │ │ ├── font2.ttf
│ │ │ │ └── icon2.png
│ │ │ ├── font1.ttf
│ │ │ └── icon1.png
│ │ │ ├── font.ttf
│ │ │ └── icon.png
│ │ ├── res
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_round.png
│ │ │ └── ic_launcher_foreground.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_round.png
│ │ │ └── ic_launcher_foreground.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_round.png
│ │ │ └── ic_launcher_foreground.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_round.png
│ │ │ └── ic_launcher_foreground.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_round.png
│ │ │ └── ic_launcher_foreground.png
│ │ ├── values
│ │ │ ├── ic_launcher_background.xml
│ │ │ ├── colors.xml
│ │ │ ├── styles.xml
│ │ │ └── strings.xml
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── xml
│ │ │ └── backup_descriptor.xml
│ │ └── layout
│ │ │ ├── activity_main.xml
│ │ │ ├── fragment_core.xml
│ │ │ └── fragment_core_ext.xml
│ │ ├── kotlin
│ │ └── com
│ │ │ └── github
│ │ │ └── jonathanmerritt
│ │ │ └── rxassetmanager
│ │ │ ├── extensions
│ │ │ ├── View.kt
│ │ │ └── Fragment.kt
│ │ │ ├── AssetPath.kt
│ │ │ ├── MainActivity.kt
│ │ │ ├── CoreFragment.kt
│ │ │ ├── RxAssetManagerFragment.kt
│ │ │ └── CoreExtFragment.kt
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── core
├── .gitignore
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── res
│ │ └── values
│ │ │ └── strings.xml
│ │ └── kotlin
│ │ └── com
│ │ └── github
│ │ └── jonathanmerritt
│ │ └── rxassetmanager
│ │ └── core
│ │ ├── IsRxAssetManager.kt
│ │ └── RxAssetManager.kt
├── proguard-rules.pro
└── build.gradle
├── core-ext
├── .gitignore
├── proguard-rules.pro
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── res
│ │ └── values
│ │ │ └── strings.xml
│ │ └── kotlin
│ │ └── com
│ │ └── github
│ │ └── jonathanmerritt
│ │ └── rxassetmanager
│ │ └── core
│ │ └── ext
│ │ ├── extensions
│ │ └── String.kt
│ │ ├── Sorting.kt
│ │ ├── IsRxAssetManager.kt
│ │ └── RxAssetManager.kt
└── build.gradle
├── promo
├── banner.png
└── logo.png
├── gradle
├── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── maven.gradle
├── bintray.gradle
└── dokka.gradle
├── .gitignore
├── RELEASES.md
├── settings.gradle
├── gradle.properties
├── .travis.yml
├── README.md
└── LICENSE.txt
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/core/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/core-ext/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/src/main/assets/folder/file.txt:
--------------------------------------------------------------------------------
1 | Example file.
--------------------------------------------------------------------------------
/app/src/main/assets/folder/folder1/file1.txt:
--------------------------------------------------------------------------------
1 | Example file number one.
--------------------------------------------------------------------------------
/app/src/main/assets/folder/folder1/folder2/file2.txt:
--------------------------------------------------------------------------------
1 | Example file number two.
--------------------------------------------------------------------------------
/app/src/main/assets/folder/folder1/folder2/folder3/file3.txt:
--------------------------------------------------------------------------------
1 | Example file number three.
--------------------------------------------------------------------------------
/promo/banner.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/promo/banner.png
--------------------------------------------------------------------------------
/promo/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/promo/logo.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/assets/folder/font.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/assets/folder/font.ttf
--------------------------------------------------------------------------------
/app/src/main/assets/folder/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/assets/folder/icon.png
--------------------------------------------------------------------------------
/app/src/main/assets/folder/folder1/font1.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/assets/folder/folder1/font1.ttf
--------------------------------------------------------------------------------
/app/src/main/assets/folder/folder1/icon1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/assets/folder/folder1/icon1.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/assets/folder/folder1/folder2/font2.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/assets/folder/folder1/folder2/font2.ttf
--------------------------------------------------------------------------------
/app/src/main/assets/folder/folder1/folder2/icon2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/assets/folder/folder1/folder2/icon2.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #F5F5F5
4 |
--------------------------------------------------------------------------------
/app/src/main/assets/folder/folder1/folder2/folder3/font3.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/assets/folder/folder1/folder2/folder3/font3.ttf
--------------------------------------------------------------------------------
/app/src/main/assets/folder/folder1/folder2/folder3/icon3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonathanMerritt/RxAssetManager/HEAD/app/src/main/assets/folder/folder1/folder2/folder3/icon3.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # IDEA
2 | *.iml
3 | /.idea
4 |
5 | # Gradle
6 | .gradle
7 | build
8 |
9 | # Gradle Android
10 | /local.properties
11 | /gradlew.bat
12 | /gradlew
13 | /publish
14 | /publish.bat
15 |
--------------------------------------------------------------------------------
/RELEASES.md:
--------------------------------------------------------------------------------
1 | ### Minor: v0.6.0
2 | _April 4, 2018_
3 |
4 | - Use kotlin.
5 | - Add dokka and task updates.
6 | - Refactor and update copyright.
7 |
8 |
9 | ### Patch: v0.0.1
10 | _February 19, 2018_
11 |
12 | - Initial release.
13 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 11 01:01:26 EDT 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-rc-1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Jonathan Merritt 11R00TT00R11@GMAIL.COM
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | include ":app", ":core", ":core-ext"
18 |
--------------------------------------------------------------------------------
/core/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
19 |
--------------------------------------------------------------------------------
/core/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 | Core
19 |
20 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/core/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/core-ext/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/core-ext/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
19 |
--------------------------------------------------------------------------------
/core-ext/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 | Core-Ext
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_descriptor.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/com/github/jonathanmerritt/rxassetmanager/extensions/View.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Jonathan Merritt
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.jonathanmerritt.rxassetmanager.extensions
18 |
19 | import android.view.View
20 |
21 | internal infix fun View.click(action: () -> Boolean) = setOnClickListener { action() }
22 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/com/github/jonathanmerritt/rxassetmanager/extensions/Fragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Jonathan Merritt
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.jonathanmerritt.rxassetmanager.extensions
18 |
19 | import androidx.fragment.app.Fragment
20 |
21 | internal inline val Fragment.cacheDir: String get() = context!!.cacheDir.absolutePath
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | #f5f5f5
20 | #FF757575
21 | #FF009688
22 |
23 |
--------------------------------------------------------------------------------
/core-ext/src/main/kotlin/com/github/jonathanmerritt/rxassetmanager/core/ext/extensions/String.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Jonathan Merritt
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.jonathanmerritt.rxassetmanager.core.ext.extensions
18 |
19 | internal fun String.isXml() = isNotBlank() && endsWith(".xml")
20 | internal fun String.isFile() = isNotBlank() && contains(".")
21 | internal fun String.isImage() = isNotBlank() && (endsWith(".jpg") || endsWith(".png") || endsWith(".bmp"))
22 | internal fun String.isFont() = isNotBlank() && (endsWith(".ttf") || endsWith(".otf"))
23 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/com/github/jonathanmerritt/rxassetmanager/AssetPath.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Jonathan Merritt
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.jonathanmerritt.rxassetmanager
18 |
19 | internal const val ROOT = "/"
20 | internal const val MANIFEST = "AndroidManifest.xml"
21 | internal const val FOLDER = "folder"
22 | internal const val FILE = "folder/file.txt"
23 | internal const val ICON = "folder/icon.png"
24 | internal const val FONT = "folder/font.ttf"
25 | internal const val FILE1 = "folder/folder1/file1.txt"
26 | internal const val FONT1 = "folder/folder1/font1.ttf"
27 | internal const val FILE2 = "folder/folder1/folder2/file2.txt"
28 |
--------------------------------------------------------------------------------
/gradle/maven.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Jonathan Merritt 11R00TT00R11@GMAIL.COM
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin : "com.github.dcendents.android-maven"
18 |
19 | group = GROUP
20 |
21 | install.repositories.mavenInstaller {
22 | pom.project {
23 | packaging "aar"
24 | groupId GROUP
25 | artifactId project.name
26 | name project.name
27 | description DESC
28 | url URL
29 |
30 | licenses {
31 | license {
32 | name LICENCE
33 | url LICENCE_URL
34 | }
35 | }
36 |
37 | developers {
38 | developer {
39 | id DEVELOPER
40 | name DEVELOPER
41 | email DEVELOPER_EMAIL
42 | }
43 | }
44 |
45 | scm {
46 | connection SCM
47 | developerConnection SCM_DEV
48 | url URL
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2018 Jonathan Merritt 11R00TT00R11@GMAIL.COM
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | DEVELOPER=jonathanmerritt
18 | DEVELOPER_EMAIL=11r00tt00r11@gmail.com
19 |
20 | GROUP=com.github.jonathanmerritt.rxassetmanager
21 | DESC=An RxJava2 implementation of the Android AssetManager.
22 | LABELS=android, android-library, asset, assets, assetmanager, assetsmanager, android-asset, android-assets, android-asset-manager, android-assets-manager
23 | LICENCE=Apache-2.0
24 | LICENCE_URL=https://github.com/jonathanmerritt/rxassetmanager/blob/master/LICENSE.txt
25 |
26 | URL=https://github.com/jonathanmerritt/rxassetmanager
27 | SCM=scm:git:git://github.com/jonathanmerritt/rxassetmanager.git
28 | SCM_DEV=scm:git:git@github.com/jonathanmerritt/rxassetmanager.git
29 |
30 | android.enableJetifier=true
31 | android.useAndroidX=true
32 | org.gradle.jvmargs=-Xmx1536m
33 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 |
27 |
28 |
29 |
30 |
35 |
36 |
--------------------------------------------------------------------------------
/gradle/bintray.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Jonathan Merritt 11R00TT00R11@GMAIL.COM
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin : "com.jfrog.bintray"
18 |
19 | version = VERSION.name
20 |
21 | bintray {
22 | user = DEVELOPER
23 | key = PASSKEY.bintray
24 | configurations = ["archives"]
25 | publish = true
26 |
27 | pkg {
28 | repo = GROUP
29 | name = project.name
30 | desc = DESC
31 | websiteUrl = URL
32 | issueTrackerUrl = "$URL/issues"
33 | vcsUrl = SCM
34 | licenses = [LICENCE]
35 | labels = LABELS.split(", ")
36 | publicDownloadNumbers = true
37 |
38 | version {
39 | name = VERSION.name
40 | released = new Date()
41 | desc = "Check - $URL/releases"
42 | vcsTag = VERSION.name
43 |
44 | gpg {
45 | sign = true
46 | passphrase = PASSKEY.gpg
47 | }
48 |
49 | mavenCentralSync {
50 | sync = false
51 | user = DEVELOPER
52 | password = PASSKEY.maven
53 | }
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/gradle/dokka.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Jonathan Merritt 11R00TT00R11@GMAIL.COM
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin : "org.jetbrains.dokka-android"
18 |
19 | dokka {
20 | outputFormat = "html"
21 | outputDirectory = "${rootProject.buildDir}/kdoc"
22 | reportUndocumented = false
23 |
24 | externalDocumentationLink {
25 | url = new URL("http://reactivex.io/RxJava/javadoc/")
26 | }
27 |
28 | packageOptions {
29 | prefix = "io.reactivex.android.R"
30 | suppress = true
31 | }
32 |
33 | packageOptions {
34 | prefix = "${GROUP}.core.R"
35 | suppress = true
36 | }
37 |
38 | packageOptions {
39 | prefix = "${GROUP}.core.ext.R"
40 | suppress = true
41 | }
42 | }
43 |
44 | task sourceJar(type : Jar) {
45 | classifier 'sources'
46 | from android.sourceSets.main.java.srcDirs
47 | }
48 |
49 | task dokkaJar(type : Jar) {
50 | group = JavaBasePlugin.DOCUMENTATION_GROUP
51 | description = "Dokka Kdocs"
52 | classifier = "javadoc"
53 | from dokka
54 | }
55 |
56 | artifacts {
57 | archives dokkaJar
58 | archives sourceJar
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
22 |
23 |
33 |
36 |
37 |
40 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/com/github/jonathanmerritt/rxassetmanager/MainActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Jonathan Merritt
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.jonathanmerritt.rxassetmanager
18 |
19 | import android.os.Bundle
20 | import androidx.appcompat.app.AppCompatActivity
21 | import androidx.fragment.app.FragmentStatePagerAdapter
22 | import kotlinx.android.synthetic.main.activity_main.pager
23 | import kotlinx.android.synthetic.main.activity_main.tablayout
24 | import kotlinx.android.synthetic.main.activity_main.toolbar
25 |
26 | class MainActivity : AppCompatActivity() {
27 |
28 | override fun onCreate(savedInstanceState: Bundle?) {
29 | super.onCreate(savedInstanceState)
30 | setContentView(R.layout.activity_main)
31 | setSupportActionBar(toolbar)
32 | tablayout.setupWithViewPager(pager.apply {
33 | adapter = object : FragmentStatePagerAdapter(supportFragmentManager) {
34 | val pairs = arrayOf(R.string.core to CoreFragment(), R.string.core_ext to CoreExtFragment())
35 | override fun getCount() = pairs.size
36 | override fun getPageTitle(position: Int) = getString(pairs[position].first)
37 | override fun getItem(position: Int) = pairs[position].second
38 | }
39 | })
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/core-ext/src/main/kotlin/com/github/jonathanmerritt/rxassetmanager/core/ext/Sorting.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Jonathan Merritt
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.jonathanmerritt.rxassetmanager.core.ext
18 |
19 | /**
20 | * Comparator to sort thru file path/name strings.
21 | *
22 | * This class implements a Comparator, and compares file path/name strings based on its type.
23 | */
24 | sealed class Sorting : Comparator {
25 | override fun compare(f: String?, s: String?) = if (f != null && s != null) when (this) {
26 | is Normal -> 0
27 | is Depth -> compareValuesBy(f, s, { it.length - it.replace("/", "").length })
28 | } else 0
29 | }
30 |
31 | /**
32 | * Will do nothing, denotes no sorting.
33 | *
34 | * Example:
35 | * --------folder/file.txt
36 | * --------folder/folder1/file.txt
37 | * --------folder/folder1/folder2/file.txt
38 | * --------folder/folder1/folder2/file1.txt
39 | * --------folder/folder1/file1.txt
40 | * --------folder/file1.txt
41 | */
42 | object Normal : Sorting()
43 |
44 | /**
45 | * Will sort file path/name strings based on their depth in their directories.
46 | *
47 | * Example:
48 | * --------folder/file.txt
49 | * --------folder/file1.txt
50 | * --------folder/folder1/file.txt
51 | * --------folder/folder1/file1.txt
52 | * --------folder/folder1/folder2/file.txt
53 | * --------folder/folder1/folder2/file1.txt
54 | */
55 | object Depth : Sorting()
56 |
--------------------------------------------------------------------------------
/core/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Jonathan Merritt 11R00TT00R11@GMAIL.COM
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin : "com.android.library"
18 | apply plugin : "kotlin-android"
19 |
20 | android {
21 | compileSdkVersion ANDROID.compile
22 | buildToolsVersion ANDROID.buildTools
23 |
24 | defaultConfig {
25 | minSdkVersion ANDROID.min
26 | targetSdkVersion ANDROID.target
27 | versionCode VERSION.code
28 | versionName VERSION.name
29 |
30 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
31 | }
32 |
33 | buildTypes {
34 | release {
35 | postprocessing {
36 | removeUnusedCode false
37 | removeUnusedResources false
38 | obfuscate false
39 | optimizeCode false
40 | proguardFile "proguard-rules.pro"
41 | }
42 | }
43 | }
44 |
45 | sourceSets {
46 | main.java.srcDirs += "src/main/kotlin"
47 | test.java.srcDirs += "src/test/kotlin"
48 | androidTest.java.srcDirs += "src/androidTest/kotlin"
49 | }
50 |
51 | compileOptions {
52 | sourceCompatibility JavaVersion.VERSION_1_8
53 | targetCompatibility JavaVersion.VERSION_1_8
54 | }
55 | }
56 |
57 | dependencies {
58 | implementation fileTree(dir : "libs", include : ["*.jar"])
59 |
60 | implementation DEPENDENCY.kotlin
61 |
62 | implementation DEPENDENCY.rxjavas
63 | }
64 |
65 | apply from : "../gradle/dokka.gradle"
66 | apply from : "../gradle/bintray.gradle"
67 | apply from : "../gradle/maven.gradle"
68 |
--------------------------------------------------------------------------------
/core-ext/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Jonathan Merritt 11R00TT00R11@GMAIL.COM
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin : "com.android.library"
18 | apply plugin : "kotlin-android"
19 |
20 | android {
21 | compileSdkVersion ANDROID.compile
22 | buildToolsVersion ANDROID.buildTools
23 |
24 | defaultConfig {
25 | minSdkVersion ANDROID.min
26 | targetSdkVersion ANDROID.target
27 | versionCode VERSION.code
28 | versionName VERSION.name
29 |
30 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
31 | }
32 |
33 | buildTypes {
34 | release {
35 | postprocessing {
36 | removeUnusedCode false
37 | removeUnusedResources false
38 | obfuscate false
39 | optimizeCode false
40 | proguardFile "proguard-rules.pro"
41 | }
42 | }
43 | }
44 |
45 | sourceSets {
46 | main.java.srcDirs += "src/main/kotlin"
47 | test.java.srcDirs += "src/test/kotlin"
48 | androidTest.java.srcDirs += "src/androidTest/kotlin"
49 | }
50 |
51 | compileOptions {
52 | sourceCompatibility JavaVersion.VERSION_1_8
53 | targetCompatibility JavaVersion.VERSION_1_8
54 | }
55 | }
56 |
57 | dependencies {
58 | implementation fileTree(dir : "libs", include : ["*.jar"])
59 | api project(":core")
60 |
61 | implementation DEPENDENCY.kotlin
62 |
63 | implementation DEPENDENCY.rxjavas
64 | }
65 |
66 | apply from : "../gradle/dokka.gradle"
67 | apply from : "../gradle/bintray.gradle"
68 | apply from : "../gradle/maven.gradle"
69 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Jonathan Merritt 11R00TT00R11@GMAIL.COM
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin : "com.android.application"
18 | apply plugin : "kotlin-android"
19 | apply plugin : "kotlin-android-extensions"
20 |
21 | android {
22 | compileSdkVersion ANDROID.compile
23 | buildToolsVersion ANDROID.buildTools
24 |
25 | defaultConfig {
26 | minSdkVersion ANDROID.min
27 | targetSdkVersion ANDROID.target
28 | versionCode VERSION.code
29 | versionName VERSION.name
30 |
31 | applicationId GROUP
32 |
33 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
34 | }
35 |
36 | buildTypes {
37 | release {
38 | minifyEnabled false
39 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
40 | }
41 | }
42 |
43 | sourceSets {
44 | main.java.srcDirs += "src/main/kotlin"
45 | test.java.srcDirs += "src/test/kotlin"
46 | androidTest.java.srcDirs += "src/androidTest/kotlin"
47 | }
48 |
49 | compileOptions {
50 | sourceCompatibility JavaVersion.VERSION_1_8
51 | targetCompatibility JavaVersion.VERSION_1_8
52 | }
53 | }
54 |
55 | dependencies {
56 | implementation fileTree(dir : "libs", include : ["*.jar"])
57 | implementation project(":core-ext")
58 |
59 | implementation DEPENDENCY.appcompat
60 | implementation DEPENDENCY.viewpager
61 | implementation DEPENDENCY.coordinatorlayout
62 | implementation DEPENDENCY.material
63 | implementation DEPENDENCY.constraintlayouts
64 |
65 | implementation DEPENDENCY.kotlin
66 |
67 | implementation DEPENDENCY.rxjavas
68 | }
69 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
25 |
26 |
31 |
32 |
39 |
40 |
47 |
48 |
49 |
50 |
56 |
57 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/com/github/jonathanmerritt/rxassetmanager/CoreFragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Jonathan Merritt
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.jonathanmerritt.rxassetmanager
18 |
19 | import com.github.jonathanmerritt.rxassetmanager.extensions.click
20 | import kotlinx.android.synthetic.main.fragment_core.getLocals
21 | import kotlinx.android.synthetic.main.fragment_core.list
22 | import kotlinx.android.synthetic.main.fragment_core.open
23 | import kotlinx.android.synthetic.main.fragment_core.openFd
24 | import kotlinx.android.synthetic.main.fragment_core.openFdPair
25 | import kotlinx.android.synthetic.main.fragment_core.openNonAssetFd
26 | import kotlinx.android.synthetic.main.fragment_core.openNonAssetFdPair
27 | import kotlinx.android.synthetic.main.fragment_core.openPair
28 | import kotlinx.android.synthetic.main.fragment_core.openTypeface
29 | import kotlinx.android.synthetic.main.fragment_core.openTypefacePair
30 | import kotlinx.android.synthetic.main.fragment_core.openXmlResParser
31 | import kotlinx.android.synthetic.main.fragment_core.openXmlResParserPair
32 |
33 | class CoreFragment : RxAssetManagerFragment(R.layout.fragment_core, {
34 | getLocals click { it.getLocales().subscribed() }
35 |
36 | open click { it.open(FILE).subscribed() }
37 | openPair click { it.openPair(FILE).subscribed() }
38 |
39 | openTypeface click { (it openTypeface FONT).subscribed() }
40 | openTypefacePair click { (it openTypefacePair FONT1).subscribed() }
41 |
42 | openFd click { (it openFd FILE1).subscribed() }
43 | openFdPair click { (it openFdPair FILE1).subscribed() }
44 |
45 | list click { it.list().subscribed() }
46 |
47 | openNonAssetFd click { it.openNonAssetFd(path = MANIFEST).subscribed() }
48 | openNonAssetFdPair click { it.openNonAssetFdPair(path = MANIFEST).subscribed() }
49 |
50 | openXmlResParser click { it.openXmlResourceParser(path = MANIFEST).subscribed() }
51 | openXmlResParserPair click { it.openXmlResourceParserPair(path = MANIFEST).subscribed() }
52 | })
53 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/com/github/jonathanmerritt/rxassetmanager/RxAssetManagerFragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Jonathan Merritt
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.jonathanmerritt.rxassetmanager
18 |
19 | import android.os.Bundle
20 | import android.view.LayoutInflater
21 | import android.view.View
22 | import android.view.ViewGroup
23 | import android.widget.Toast.LENGTH_LONG
24 | import android.widget.Toast.makeText
25 | import androidx.appcompat.app.AlertDialog.Builder
26 | import androidx.fragment.app.Fragment
27 | import com.github.jonathanmerritt.rxassetmanager.core.ext.IsRxAssetManager
28 | import com.github.jonathanmerritt.rxassetmanager.core.ext.RxAssetManager
29 | import io.reactivex.Completable
30 | import io.reactivex.Flowable
31 | import io.reactivex.Maybe
32 | import io.reactivex.Observable.never
33 | import io.reactivex.android.schedulers.AndroidSchedulers.mainThread
34 | import io.reactivex.disposables.CompositeDisposable
35 | import io.reactivex.schedulers.Schedulers.io
36 |
37 | abstract class RxAssetManagerFragment(
38 | private val layout: Int,
39 | private val created: RxAssetManagerFragment.(IsRxAssetManager) -> Unit,
40 | private val disposables: CompositeDisposable = CompositeDisposable()) : Fragment() {
41 |
42 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? =
43 | inflater.inflate(layout, container, false)
44 |
45 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
46 | created(this, RxAssetManager(context!!))
47 | super.onViewCreated(view, savedInstanceState)
48 | }
49 |
50 | override fun onStop() {
51 | disposables.clear()
52 | super.onStop()
53 | }
54 |
55 | fun T.subscribed() = disposables.add(when (this) {
56 | is Completable -> toObservable()
57 | is Maybe<*> -> toObservable()
58 | is Flowable<*> -> toObservable()
59 | else -> never()
60 | }
61 | .map(Any::toString)
62 | .toList()
63 | .subscribeOn(io())
64 | .observeOn(mainThread())
65 | .subscribe(
66 | { Builder(context!!).setItems(it.toTypedArray(), { d, _ -> d.dismiss() }).show() },
67 | { makeText(context, it.message, LENGTH_LONG).show() }
68 | ))
69 | }
70 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 | jdk: oraclejdk8
3 |
4 | #sudo: false
5 |
6 | android:
7 | components:
8 | # Uncomment the lines below if you want to
9 | # use the latest revision of Android SDK Tools
10 | - tools
11 | - platform-tools
12 | - tools
13 |
14 | # The BuildTools version used by your project
15 | - build-tools-27.0.3
16 |
17 | # The SDK version used to compile your project
18 | - android-27
19 |
20 | # Additional components
21 | - extra-google-google_play_services
22 | - extra-google-m2repository
23 | - extra-android-m2repository
24 | # - addon-google_apis-google-19
25 |
26 | # Specify at least one system image,
27 | # if you need to run emulator(s) during your tests
28 | - sys-img-armeabi-v7a-android-22
29 | - sys-img-armeabi-v7a-android-17
30 |
31 | #before_script:
32 | # - echo no | android create avd --force -n test -t android-21 --abi armeabi-v7a
33 | # - emulator -avd test -no-skin -no-audio -no-window &
34 | # - android-wait-for-emulator
35 | # - adb shell input keyevent 82 &
36 |
37 | install: skip
38 |
39 | # env:
40 | # global:
41 | # - CACHE_DIR=$([ $TRAVIS_OS_NAME = 'linux' ] && echo "FOO" || echo "BAR")
42 |
43 | # cache:
44 | # directories:
45 | # - $CACHE_DIR
46 |
47 | # env:
48 | # global:
49 | # - PATH=/usr/local/android-sdk/tools/bin:$PATH
50 |
51 | script: skip
52 | # android:
53 | # components:
54 | # - tools
55 | # - platform-tools
56 | # - tools
57 |
58 | # - android-25
59 |
60 | # - build-tools-25.0.2
61 | # - extra
62 | # - extra-google-m2repository
63 | # - extra-android-m2repository
64 | # - extra-android-support
65 |
66 | # jdk: oraclejdk8
67 |
68 | matrix:
69 | include:
70 | - sudo: false
71 | dist: precise
72 | env: DIST=precise STACK=EC2
73 | # - sudo: required
74 | # dist: precise
75 | # env: DIST=precise STACK=GCE
76 | # - sudo: false
77 | # dist: trusty
78 | # env: DIST=trusty STACK=EC2
79 | # - sudo: required
80 | # dist: trusty
81 | # env: DIST=trusty STACK=GCE
82 | # - sudo: false
83 | # dist: trusty
84 | # group: edge
85 | # env: DIST=trusty STACK=EC2 GROUP=edge
86 | # - sudo: required
87 | # dist: trusty
88 | # group: edge
89 | # env: DIST=trusty STACK=GCE GROUP=edge
90 | # - os: osx
91 |
92 |
93 | notifications:
94 | email: false
95 |
96 | # slack:
97 | # rooms:
98 | # - secure: "KZTfjxhkOdDDZYD2ThBILt2ShYtdEee3PudFZlQBfpxG9N470GfxnKVfOl7Odu4lN6cIupwC4S4BnehubEywSR99l60VmfhePUCTqDLYy+iR9+guTvaECdXdaau3jTKhFdu5u60ITsiw5Yb+hwAaGFO0HmQhqR9XVr/U8IGQlok="
99 | # template:
100 | # - "Build <%{build_url}|#%{build_number}> (<%{compare_url}|%{commit}>) of %{repository}@%{branch} by %{author} %{result} in %{duration} (elapsed time: %{elapsed_time}) subject: %{commit_subject} message: %{commit_message} foobar"
101 | # on_success: always
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 | RxAssetManager
19 | Core
20 | Core-Ext
21 |
22 | Get Locals
23 | Open
24 | Open Pair
25 | Open Typeface
26 | Open Typeface Pair
27 | Open Fd
28 | Open Fd Pair
29 | List
30 | Open Non Asset Fd
31 | Open Non Asset Fd Pair
32 | Open Xml Resource Parser
33 | Open Xml Resource Parser Pair
34 |
35 | Open String
36 | Open String Pair
37 | Open Bytes
38 | Open Bytes Pair
39 | Open And Save
40 | Open And Save Pair
41 | Open Bitmap
42 | Open Bitmap Pair
43 | List All
44 | List And Open
45 | List And Open Pair
46 | List And Open String
47 | List And Open String Pair
48 | List And Open Bytes
49 | List And Open Bytes Pair
50 | List, Open And Save
51 | List, Open And Save Pair
52 | List Open Bitmap
53 | List Open Bitmap Pair
54 | List Open Typeface
55 | List Open Typeface Pair
56 | List And Open Fd
57 | List And Open Fd Pair
58 | List And Open Non Asset Fd
59 | List And Open Non Asset Fd Pair
60 | List And Open Xml Resource Parser
61 | List And Open Xml Resource Parser Pair
62 |
63 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/com/github/jonathanmerritt/rxassetmanager/core/IsRxAssetManager.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Jonathan Merritt 11R00TT00R11@GMAIL.COM
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.jonathanmerritt.rxassetmanager.core
18 |
19 | import android.content.res.AssetFileDescriptor
20 | import android.content.res.AssetManager.ACCESS_STREAMING
21 | import android.content.res.XmlResourceParser
22 | import android.graphics.Typeface
23 | import io.reactivex.Completable
24 | import io.reactivex.Completable.complete
25 | import io.reactivex.Flowable
26 | import io.reactivex.Maybe
27 | import io.reactivex.Maybe.empty
28 | import java.io.InputStream
29 |
30 | /**
31 | * Reactive asset manager interface.
32 | *
33 | * This class outlines the main api for the library.
34 | */
35 | interface IsRxAssetManager {
36 | /**
37 | * Companion object used for default parameter values.
38 | */
39 | companion object {
40 | /**
41 | * Default access mode = [ACCESS_STREAMING].
42 | */
43 | const val MODE = ACCESS_STREAMING
44 |
45 | /**
46 | * Default path = "".
47 | */
48 | const val PATH = ""
49 |
50 | /**
51 | * Default file cookie = 0.
52 | */
53 | const val COOKIE = 0
54 | }
55 |
56 | /**
57 | * Defaults to an empty flowable.
58 | */
59 | fun getLocales(): Flowable = Flowable.empty()
60 |
61 | /**
62 | * Defaults to a complete completable.
63 | */
64 | fun close(): Completable = complete()
65 |
66 | /**
67 | * Defaults to an empty maybe.
68 | */
69 | fun open(path: String, mode: Int = MODE): Maybe = empty()
70 |
71 | /**
72 | * Defaults to an empty maybe.
73 | */
74 | fun openPair(path: String, mode: Int = MODE): Maybe> = empty()
75 |
76 | /**
77 | * Defaults to an empty maybe.
78 | */
79 | infix fun openTypeface(path: String): Maybe = empty()
80 |
81 | /**
82 | * Defaults to an empty maybe.
83 | */
84 | infix fun openTypefacePair(path: String): Maybe> = empty()
85 |
86 | /**
87 | * Defaults to an empty maybe.
88 | */
89 | infix fun openFd(path: String): Maybe = empty()
90 |
91 | /**
92 | * Defaults to an empty maybe.
93 | */
94 | infix fun openFdPair(path: String): Maybe> = empty()
95 |
96 | /**
97 | * Defaults to an empty flowable.
98 | */
99 | fun list(path: String = PATH): Flowable = Flowable.empty()
100 |
101 | /**
102 | * Defaults to an empty maybe.
103 | */
104 | fun openNonAssetFd(cookie: Int = COOKIE, path: String): Maybe = empty()
105 |
106 | /**
107 | * Defaults to an empty maybe.
108 | */
109 | fun openNonAssetFdPair(cookie: Int = COOKIE, path: String): Maybe> = empty()
110 |
111 | /**
112 | * Defaults to an empty maybe.
113 | */
114 | fun openXmlResourceParser(cookie: Int = COOKIE, path: String): Maybe = empty()
115 |
116 | /**
117 | * Defaults to an empty maybe.
118 | */
119 | fun openXmlResourceParserPair(cookie: Int = COOKIE, path: String): Maybe> =
120 | empty()
121 | }
122 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/com/github/jonathanmerritt/rxassetmanager/CoreExtFragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Jonathan Merritt
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.jonathanmerritt.rxassetmanager
18 |
19 | import com.github.jonathanmerritt.rxassetmanager.core.ext.Depth
20 | import com.github.jonathanmerritt.rxassetmanager.extensions.cacheDir
21 | import com.github.jonathanmerritt.rxassetmanager.extensions.click
22 | import kotlinx.android.synthetic.main.fragment_core_ext.listAll
23 | import kotlinx.android.synthetic.main.fragment_core_ext.listOpen
24 | import kotlinx.android.synthetic.main.fragment_core_ext.listOpenBitmap
25 | import kotlinx.android.synthetic.main.fragment_core_ext.listOpenBitmapPair
26 | import kotlinx.android.synthetic.main.fragment_core_ext.listOpenBytes
27 | import kotlinx.android.synthetic.main.fragment_core_ext.listOpenBytesPair
28 | import kotlinx.android.synthetic.main.fragment_core_ext.listOpenFd
29 | import kotlinx.android.synthetic.main.fragment_core_ext.listOpenFdPair
30 | import kotlinx.android.synthetic.main.fragment_core_ext.listOpenNonAssetFd
31 | import kotlinx.android.synthetic.main.fragment_core_ext.listOpenNonAssetFdPair
32 | import kotlinx.android.synthetic.main.fragment_core_ext.listOpenPair
33 | import kotlinx.android.synthetic.main.fragment_core_ext.listOpenSave
34 | import kotlinx.android.synthetic.main.fragment_core_ext.listOpenSavePair
35 | import kotlinx.android.synthetic.main.fragment_core_ext.listOpenString
36 | import kotlinx.android.synthetic.main.fragment_core_ext.listOpenStringPair
37 | import kotlinx.android.synthetic.main.fragment_core_ext.listOpenTypeface
38 | import kotlinx.android.synthetic.main.fragment_core_ext.listOpenTypefacePair
39 | import kotlinx.android.synthetic.main.fragment_core_ext.listOpenXmlResourceParser
40 | import kotlinx.android.synthetic.main.fragment_core_ext.listOpenXmlResourceParserPair
41 | import kotlinx.android.synthetic.main.fragment_core_ext.openBitmap
42 | import kotlinx.android.synthetic.main.fragment_core_ext.openBitmapPair
43 | import kotlinx.android.synthetic.main.fragment_core_ext.openBytes
44 | import kotlinx.android.synthetic.main.fragment_core_ext.openBytesPair
45 | import kotlinx.android.synthetic.main.fragment_core_ext.openSave
46 | import kotlinx.android.synthetic.main.fragment_core_ext.openSavePair
47 | import kotlinx.android.synthetic.main.fragment_core_ext.openString
48 | import kotlinx.android.synthetic.main.fragment_core_ext.openStringPair
49 |
50 | class CoreExtFragment : RxAssetManagerFragment(R.layout.fragment_core_ext, {
51 | openString click { it.openString(FILE).subscribed() }
52 | openStringPair click { it.openStringPair(FILE).subscribed() }
53 |
54 | openBytes click { it.openBytes(FILE1).subscribed() }
55 | openBytesPair click { it.openBytesPair(FILE1).subscribed() }
56 |
57 | openSave click { it.openSave(FILE2, to = cacheDir).subscribed() }
58 | openSavePair click { it.openSavePair(FILE2, to = cacheDir).subscribed() }
59 |
60 | openBitmap click { it.openBitmap(ICON).subscribed() }
61 | openBitmapPair click { it.openBitmapPair(ICON).subscribed() }
62 |
63 | listAll click { it.listAll(sorting = Depth).subscribed() }
64 |
65 | listOpen click { it.listOpen(FOLDER, all = true).subscribed() }
66 | listOpenPair click { it.listOpenPair(FOLDER, all = true).subscribed() }
67 |
68 | listOpenString click { it.listOpenString(FOLDER, all = true).subscribed() }
69 | listOpenStringPair click { it.listOpenStringPair(FOLDER, all = true).subscribed() }
70 |
71 | listOpenBytes click { it.listOpenBytes(FOLDER, all = true).subscribed() }
72 | listOpenBytesPair click { it.listOpenBytesPair(FOLDER, all = true).subscribed() }
73 |
74 | listOpenSave click { it.listOpenSave(FOLDER, to = cacheDir, all = true).subscribed() }
75 | listOpenSavePair click { it.listOpenSavePair(FOLDER, to = cacheDir, all = true).subscribed() }
76 |
77 | listOpenBitmap click { it.listOpenBitmap(FOLDER, all = true).subscribed() }
78 | listOpenBitmapPair click { it.listOpenBitmapPair(FOLDER, all = true).subscribed() }
79 |
80 | listOpenTypeface click { it.listOpenTypeface(FOLDER, all = true).subscribed() }
81 | listOpenTypefacePair click { it.listOpenTypefacePair(FOLDER, all = true).subscribed() }
82 |
83 | listOpenFd click { it.listOpenFd(FOLDER, all = true).subscribed() }
84 | listOpenFdPair click { it.listOpenFdPair(FOLDER, all = true).subscribed() }
85 |
86 | listOpenNonAssetFd click { it.listOpenNonAssetFd(path = ROOT).subscribed() }
87 | listOpenNonAssetFdPair click { it.listOpenNonAssetFdPair(path = ROOT).subscribed() }
88 |
89 | listOpenXmlResourceParser click { it.listOpenXmlResourceParser(path = ROOT, all = true).subscribed() }
90 | listOpenXmlResourceParserPair click { it.listOpenXmlResourceParserPair(path = ROOT, all = true).subscribed() }
91 | })
92 |
--------------------------------------------------------------------------------
/core/src/main/kotlin/com/github/jonathanmerritt/rxassetmanager/core/RxAssetManager.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Jonathan Merritt 11R00TT00R11@GMAIL.COM
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.jonathanmerritt.rxassetmanager.core
18 |
19 | import android.content.Context
20 | import android.content.res.AssetFileDescriptor
21 | import android.content.res.AssetManager
22 | import android.content.res.XmlResourceParser
23 | import android.graphics.Typeface
24 | import android.graphics.Typeface.createFromAsset
25 | import io.reactivex.Completable
26 | import io.reactivex.Completable.fromAction
27 | import io.reactivex.Flowable
28 | import io.reactivex.Flowable.fromIterable
29 | import io.reactivex.Maybe
30 | import io.reactivex.Maybe.fromCallable
31 | import java.io.InputStream
32 |
33 | /**
34 | * Reactive asset manager.
35 | *
36 | * This class wraps the android asset manager with rxjava2 types.
37 | * @property manager android asset manager.
38 | * @constructor Creates a RxAssetManager instance.
39 | */
40 | open class RxAssetManager(private val manager: AssetManager) : IsRxAssetManager {
41 |
42 | /**
43 | * Secondary constructor using a context.
44 | * @property context android context.
45 | * @constructor Creates a RxAssetManager instance.
46 | */
47 | constructor(context: Context) : this(context.assets)
48 |
49 | /**
50 | * Gets all locales.
51 | * @return a string flowable.
52 | */
53 | override fun getLocales(): Flowable = fromIterable(manager.locales.asIterable())
54 |
55 | /**
56 | * Closes the asset manager.
57 | * @return a completable.
58 | */
59 | override fun close(): Completable = fromAction(manager::close)
60 |
61 | /**
62 | * Opens an asset input stream.
63 | * @param path asset file path.
64 | * @param mode file access mode.
65 | * @return an input stream maybe.
66 | */
67 | override fun open(path: String, mode: Int): Maybe = fromCallable { manager.open(path, mode) }
68 |
69 | /**
70 | * Opens an asset input stream pair.
71 | * @param path asset file path.
72 | * @param mode file access mode.
73 | * @return a string input stream pair maybe.
74 | */
75 | override fun openPair(path: String, mode: Int): Maybe> =
76 | fromCallable { path to manager.open(path, mode) }
77 |
78 | /**
79 | * Opens an asset font.
80 | * @param path asset file path.
81 | * @return a typeface maybe.
82 | */
83 | override infix fun openTypeface(path: String): Maybe = fromCallable { createFromAsset(manager, path) }
84 |
85 | /**
86 | * Opens an asset font pair.
87 | * @param path asset file path.
88 | * @return a string typeface pair maybe.
89 | */
90 | override infix fun openTypefacePair(path: String): Maybe> =
91 | openTypeface(path).map { path to it }
92 |
93 | /**
94 | * Opens an asset file descriptor.
95 | * @param path asset file path.
96 | * @return an asset file descriptor maybe.
97 | */
98 | override infix fun openFd(path: String): Maybe = fromCallable { manager.openFd(path) }
99 |
100 | /**
101 | * Opens an asset file descriptor pair.
102 | * @param path asset file path.
103 | * @return a string asset file descriptor pair maybe.
104 | */
105 | override infix fun openFdPair(path: String): Maybe> =
106 | fromCallable { path to manager.openFd(path) }
107 |
108 | /**
109 | * Lists asset files.
110 | * @param path assets folder path.
111 | * @return a string flowable.
112 | */
113 | override fun list(path: String): Flowable = fromIterable(manager.list(path).asIterable())
114 |
115 | /**
116 | * Opens a non asset file.
117 | * @param cookie non asset file cookie.
118 | * @param path non asset file path.
119 | * @return an asset file descriptor maybe.
120 | */
121 | override fun openNonAssetFd(cookie: Int, path: String): Maybe =
122 | fromCallable { manager.openNonAssetFd(cookie, path) }
123 |
124 | /**
125 | * Opens a non asset file pair.
126 | * @param cookie non asset file cookie.
127 | * @param path non asset file path.
128 | * @return a string asset file descriptor pair maybe.
129 | */
130 | override fun openNonAssetFdPair(cookie: Int, path: String): Maybe> =
131 | fromCallable { path to manager.openNonAssetFd(cookie, path) }
132 |
133 | /**
134 | * Opens a xml resource parser.
135 | * @param cookie xml file cookie.
136 | * @param path xml file path.
137 | * @return an xml resource parser maybe.
138 | */
139 | override fun openXmlResourceParser(cookie: Int, path: String): Maybe =
140 | fromCallable { manager.openXmlResourceParser(cookie, path) }
141 |
142 | /**
143 | * Opens a xml resource parser pair.
144 | * @param cookie xml file cookie.
145 | * @param path xml file path.
146 | * @return a string xml resource parser pair maybe.
147 | */
148 | override fun openXmlResourceParserPair(cookie: Int, path: String): Maybe> =
149 | fromCallable { path to manager.openXmlResourceParser(cookie, path) }
150 | }
151 |
--------------------------------------------------------------------------------
/core-ext/src/main/kotlin/com/github/jonathanmerritt/rxassetmanager/core/ext/IsRxAssetManager.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Jonathan Merritt 11R00TT00R11@GMAIL.COM
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.jonathanmerritt.rxassetmanager.core.ext
18 |
19 | import android.content.res.AssetFileDescriptor
20 | import android.content.res.XmlResourceParser
21 | import android.graphics.Bitmap
22 | import android.graphics.Typeface
23 | import com.github.jonathanmerritt.rxassetmanager.core.IsRxAssetManager.Companion.COOKIE
24 | import com.github.jonathanmerritt.rxassetmanager.core.IsRxAssetManager.Companion.MODE
25 | import com.github.jonathanmerritt.rxassetmanager.core.IsRxAssetManager.Companion.PATH
26 | import io.reactivex.Flowable
27 | import io.reactivex.Flowable.empty
28 | import io.reactivex.Maybe
29 | import java.io.File
30 | import java.io.InputStream
31 | import com.github.jonathanmerritt.rxassetmanager.core.IsRxAssetManager as isRxAssetManager
32 |
33 | /**
34 | * Reactive asset manager extended interface.
35 | *
36 | * This class outlines the extended api for the library.
37 | */
38 | interface IsRxAssetManager : isRxAssetManager {
39 | /**
40 | * Companion object used for default parameter values.
41 | */
42 | companion object {
43 | /**
44 | * Default list all = false.
45 | */
46 | const val ALL = false
47 | }
48 |
49 | /**
50 | * Defaults to an empty maybe.
51 | */
52 | fun openString(path: String, mode: Int = MODE): Maybe = Maybe.empty()
53 |
54 | /**
55 | * Defaults to an empty maybe.
56 | */
57 | fun openStringPair(path: String, mode: Int = MODE): Maybe> = Maybe.empty()
58 |
59 | /**
60 | * Defaults to an empty maybe.
61 | */
62 | fun openBytes(path: String, mode: Int = MODE): Maybe = Maybe.empty()
63 |
64 | /**
65 | * Defaults to an empty maybe.
66 | */
67 | fun openBytesPair(path: String, mode: Int = MODE): Maybe> = Maybe.empty()
68 |
69 | /**
70 | * Defaults to an empty maybe.
71 | */
72 | fun openSave(path: String, mode: Int = MODE, to: String): Maybe = Maybe.empty()
73 |
74 | /**
75 | * Defaults to an empty maybe.
76 | */
77 | fun openSavePair(path: String, mode: Int = MODE, to: String): Maybe> = Maybe.empty()
78 |
79 | /**
80 | * Defaults to an empty maybe.
81 | */
82 | fun openBitmap(path: String, mode: Int = MODE): Maybe = Maybe.empty()
83 |
84 | /**
85 | * Defaults to an empty maybe.
86 | */
87 | fun openBitmapPair(path: String, mode: Int = MODE): Maybe> = Maybe.empty()
88 |
89 | /**
90 | * Defaults to an empty flowable.
91 | */
92 | fun listAll(path: String = PATH, sorting: Sorting = Normal): Flowable = empty()
93 |
94 | /**
95 | * Defaults to an empty flowable.
96 | */
97 | fun listOpen(path: String = PATH, mode: Int = MODE, all: Boolean = ALL): Flowable =
98 | empty()
99 |
100 | /**
101 | * Defaults to an empty flowable.
102 | */
103 | fun listOpenPair(path: String = PATH, mode: Int = MODE, all: Boolean = ALL):
104 | Flowable> = empty()
105 |
106 | /**
107 | * Defaults to an empty flowable.
108 | */
109 | fun listOpenString(path: String = PATH, mode: Int = MODE, all: Boolean = ALL): Flowable = empty()
110 |
111 | /**
112 | * Defaults to an empty flowable.
113 | */
114 | fun listOpenStringPair(path: String = PATH, mode: Int = MODE, all: Boolean = ALL):
115 | Flowable> = empty()
116 |
117 | /**
118 | * Defaults to an empty flowable.
119 | */
120 | fun listOpenBytes(path: String = PATH, mode: Int = MODE, all: Boolean = ALL): Flowable = empty()
121 |
122 | /**
123 | * Defaults to an empty flowable.
124 | */
125 | fun listOpenBytesPair(path: String = PATH, mode: Int = MODE, all: Boolean = ALL):
126 | Flowable> = empty()
127 |
128 | /**
129 | * Defaults to an empty flowable.
130 | */
131 | fun listOpenSave(path: String = PATH, mode: Int = MODE, to: String, all: Boolean = ALL): Flowable = empty()
132 |
133 | /**
134 | * Defaults to an empty flowable.
135 | */
136 | fun listOpenSavePair(path: String = PATH, mode: Int = MODE, to: String, all: Boolean = ALL):
137 | Flowable> = empty()
138 |
139 | /**
140 | * Defaults to an empty flowable.
141 | */
142 | fun listOpenBitmap(path: String = PATH, mode: Int = MODE, all: Boolean = ALL): Flowable = empty()
143 |
144 | /**
145 | * Defaults to an empty flowable.
146 | */
147 | fun listOpenBitmapPair(path: String = PATH, mode: Int = MODE, all: Boolean = ALL):
148 | Flowable> = empty()
149 |
150 | /**
151 | * Defaults to an empty flowable.
152 | */
153 | fun listOpenTypeface(path: String = PATH, all: Boolean = ALL): Flowable = empty()
154 |
155 | /**
156 | * Defaults to an empty flowable.
157 | */
158 | fun listOpenTypefacePair(path: String = PATH, all: Boolean = ALL): Flowable> = empty()
159 |
160 | /**
161 | * Defaults to an empty flowable.
162 | */
163 | fun listOpenFd(path: String = PATH, all: Boolean = ALL): Flowable = empty()
164 |
165 | /**
166 | * Defaults to an empty flowable.
167 | */
168 | fun listOpenFdPair(path: String = PATH, all: Boolean = ALL): Flowable> =
169 | empty()
170 |
171 | /**
172 | * Defaults to an empty flowable.
173 | */
174 | fun listOpenNonAssetFd(cookie: Int = COOKIE, path: String = PATH,
175 | all: Boolean = ALL): Flowable = empty()
176 |
177 | /**
178 | * Defaults to an empty flowable.
179 | */
180 | fun listOpenNonAssetFdPair(cookie: Int = COOKIE, path: String = PATH, all: Boolean = ALL):
181 | Flowable> = empty()
182 |
183 | /**
184 | * Defaults to an empty flowable.
185 | */
186 | fun listOpenXmlResourceParser(cookie: Int = COOKIE, path: String = PATH, all: Boolean = ALL):
187 | Flowable = empty()
188 |
189 | /**
190 | * Defaults to an empty flowable.
191 | */
192 | fun listOpenXmlResourceParserPair(cookie: Int = COOKIE, path: String = PATH, all: Boolean = ALL):
193 | Flowable> = empty()
194 | }
195 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_core.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
24 |
25 |
29 |
30 |
41 |
42 |
53 |
54 |
65 |
66 |
77 |
78 |
89 |
90 |
101 |
102 |
113 |
114 |
125 |
126 |
137 |
138 |
149 |
150 |
161 |
162 |
173 |
174 |
175 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | [![BINTRAY][BINTRAY-SVG]][BINTRAY]
4 | [![MAVEN-CENTRAL][MAVEN-CENTRAL-SVG]][MAVEN-CENTRAL]
5 | [![TRAVIS-CI][TRAVIS-CI-SVG]][TRAVIS-CI]
6 | [![ANDROID-ARSENAL][ANDROID-ARSENAL-SVG]][ANDROID-ARSENAL]
7 |
8 |
9 | ## What is *RXASSETMANAGER*?
10 | An RxJava2 implementation of the Android AssetManager.
11 |
12 | _Any help or contribution is welcome._
13 |
14 |
15 | ## How do you *GET* it?
16 | Use the `jcenter()` or `mavenCentral()` repository.
17 | ```groovy
18 | repositories {
19 | jcenter()
20 | mavenCentral()
21 | }
22 | ```
23 |
24 | Then pick a module.
25 |
26 | **Core**
27 | ```groovy
28 | dependencies {
29 | implementation "com.github.jonathanmerritt.rxassetmanager:core:x.y.z"
30 | }
31 | ```
32 |
33 | **Core-ext** - includes `:core` automatically.
34 | ```groovy
35 | dependencies {
36 | implementation "com.github.jonathanmerritt.rxassetmanager:core-ext:x.y.z"
37 | }
38 | ```
39 |
40 |
41 | ## How do you *USE* it?
42 | Create an instance.
43 | ```kotlin
44 | val manager = RxAssetManager(context)
45 | ```
46 |
47 | Then open the asset as an InputStream for the given file name/path.
48 |
49 | **Core**
50 | ```kotlin
51 | manager.open("file.txt").subscribe { }
52 | ```
53 |
54 | Or open as InputStreams for the given folder name/path.
55 |
56 | **Core-ext**
57 | ```kotlin
58 | manager.listOpen("folder").subscribe { }
59 | ```
60 |
61 | *Please check the sample app for more examples.*
62 |
63 |
64 | ## What does it *DO*?
65 | Miminally wraps the original android assetmanager into rxjava2 types.
66 |
67 | **Core** - Intended to be a 1:1 copy, it's only diverted from that slighty.
68 |
69 | Function|Parameters|Description|Pair|Returns
70 | ---|---|---|---|---
71 | `getLocales()`|none|Gets all locales.|no|Flowable\
72 | `close()`|none|Closes the asset manager.|no|Completable
73 | `open(String, Int)`|**path**: asset file path, **mode**: file access mode|Opens an asset input stream.|yes|Maybe\
74 | `openTypeface(String)`|**path**: asset file path|Opens an asset font.|yes|Maybe\
75 | `openFd(String)`|**path**: asset file path|Opens an asset file descriptor.|yes|Maybe\
76 | `list(String)`|**path**: asset folder path|Lists asset files.|no|Flowable\
77 | `openNonAssetFd(Int, String)`|**cookie**: non asset file cookie, **path**: non asset file path|Opens a non asset file.|yes|Maybe\
78 | `openXmlResourceParser(Int, String)`|**cookie**: xml file cookie, **path**: xml file path|Opens a xml resource parser.|yes|Maybe\
79 |
80 | **Core-ext** - Extends core while adding more functions, mainly listing chains.
81 |
82 | Function|Parameters|Description|Pair|Returns
83 | ---|---|---|---|---
84 | `openString(String, Int)`|**path**: asset file path, **mode**: file access mode|Opens asset file as string|yes|Maybe\
85 | `openBytes(String, Int)`|**path**: asset file path, **mode**: file access mode|Opens asset file as a byte array|yes|Maybe\
86 | `openSave(String, Int, String)`|**path**: asset file path, **mode**: file access mode, **to**: save to location|Opens and save asset file.|yes|Maybe\
87 | `openBitmap(String, Int)`|**path**: asset file path, **mode**: file access mode|Opens asset file as a bitmap.|yes|Maybe\
88 | `listAll(String, Sorting)`|**path**: asset folder path, **sorting**: comparator object|Lists asset files recursively.|no|Flowable\
89 | `listOpen(String, Int, Boolean)`|**path**: asset folder path, **mode**: file access mode, **all**: list all files|Lists and opens asset files as input streams.|yes|Flowable\
90 | `listOpenString(String, Int, Boolean)`|**path**: asset folder path, **mode**: file access mode, **all**: list all files|Lists and opens asset files as strings.|yes|Flowable\
91 | `listOpenBytes(String, Int, Boolean)`|**path**: asset folder path, **mode**: file access mode, **all**: list all files|Lists and opens asset files as byte arrays.|yes|Flowable\
92 | `listOpenSave(String, Int, String, Boolean)`|**path**: asset folder path, **mode**: file access mode, **to**: save to location, **all**: list all files|Lists, opens and saves asset files.|yes|Flowable\
93 | `listOpenBitmap(String, Int, Boolean)`|**path**: asset folder path, **mode**: file access mode, **all**: list all files|Lists and opens asset files as bitmaps.|yes|Flowable\
94 | `listOpenTypeface(String, Int, Boolean)`|**path**: asset folder path, **mode**: file access mode, **all**: list all files|Lists and opens asset files as type faces.|yes|Flowable\
95 | `listOpenFd(String, Boolean)`|**path**: asset folder path, **all**: list all files|Lists and opens asset files as file descriptors.|yes|Flowable\
96 | `listOpenNonAssetFd(Int, String, Boolean)`|**cookie**: non asset file cookie, **path**: non asset folder path, **all**: list all files|Lists and opens non asset files as file descriptors.|yes|Flowable\
97 | `listOpenXmlResourceParser(Int, String, Boolean)`|**cookie**: xml file cookie, **path**: xml folder path, **all**: list all files|Lists and opens files as xml resource parsers.|yes|Flowable\
98 |
99 |
100 | ## TODOs
101 | **Probable**
102 | - Properly setup scripts for doc and source jars. (*\*partially done*\*)
103 | - Add testing for the app and mocks for the lib. (*\*partially done*\*)
104 | - Make docs descriptive and add comments.
105 | - Use an actual versioning structure(debug, release & dev, beta, production & flavors etc...).
106 | - Put sample app on google play.
107 | - ...
108 |
109 | **Possible**
110 | - ~~Figure out a better build configuration(maybe buildSrc and/or .kts).~~
111 | - Create an advanced fragment in the sample app, for more real examples.
112 | - Consider handling errors in the api(?).
113 | - ...
114 |
115 | ## Credits
116 | - [RxRecipes][RX-RECIPES] by [Scott Meschke][SCOTT-MESCHKE].
117 | - [RxJava][RXJAVA] by [Reactivex-io][REACTIVEXIO]
118 | - [Android][ANDROID] by [Google][GOOGLE]
119 |
120 |
121 | ## [License][LICENSE]
122 | Copyright 2018 Jonathan Merritt 11R00TT00R11@GMAIL.COM
123 |
124 | Licensed under the Apache License, Version 2.0 (the "License");
125 | you may not use this file except in compliance with the License.
126 | You may obtain a copy of the License at
127 |
128 | http://www.apache.org/licenses/LICENSE-2.0
129 |
130 | Unless required by applicable law or agreed to in writing, software
131 | distributed under the License is distributed on an "AS IS" BASIS,
132 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133 | See the License for the specific language governing permissions and
134 | limitations under the License.
135 |
136 | [BINTRAY-SVG]:https://img.shields.io/bintray/v/jonathanmerritt/RxAssetManager/core.svg?style=flat-square&colorB=067EC4&label=Bintray
137 | [BINTRAY]:https://bintray.com/jonathanmerritt/RxAssetManager/core/_latestVersion
138 | [MAVEN-CENTRAL-SVG]: https://img.shields.io/maven-central/v/com.github.jonathanmerritt.rxassetmanager/core.svg?style=flat-square&colorB=067EC4&label=MavenCentral
139 | [MAVEN-CENTRAL]: http://repo1.maven.org/maven2/com/github/jonathanmerritt/rxassetmanager/core
140 | [TRAVIS-CI-SVG]: https://img.shields.io/travis/JonathanMerritt/RxAssetManager.svg?style=flat-square&colorB=067EC4&label=TravisCI
141 | [TRAVIS-CI]: https://travis-ci.org/JonathanMerritt/RxAssetManager
142 | [ANDROID-ARSENAL-SVG]: https://img.shields.io/badge/AndroidArsenal-RxAssetManager-blue.svg?style=flat-square
143 | [ANDROID-ARSENAL]: https://android-arsenal.com/details/1/6855
144 |
145 | [RELEASES]: https://github.com/JonathanMerritt/RxAssetManager/releases
146 | [LICENSE]: https://github.com/JonathanMerritt/RxAssetManager/blob/master/LICENSE.txt
147 | [RX-RECIPES]: https://hackernoon.com/rxrecipes-wrap-your-way-to-rx-fd40eb5254b6
148 | [SCOTT-MESCHKE]: https://github.com/scottmeschke
149 | [RXJAVA]: https://github.com/ReactiveX/RxJava
150 | [REACTIVEXIO]: http://reactivex.io/
151 | [ANDROID]: https://source.android.com/
152 | [GOOGLE]: https://android-developers.googleblog.com/
153 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------
/core-ext/src/main/kotlin/com/github/jonathanmerritt/rxassetmanager/core/ext/RxAssetManager.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Jonathan Merritt 11R00TT00R11@GMAIL.COM
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.jonathanmerritt.rxassetmanager.core.ext
18 |
19 | import android.content.Context
20 | import android.content.res.AssetFileDescriptor
21 | import android.content.res.AssetManager
22 | import android.content.res.XmlResourceParser
23 | import android.graphics.Bitmap
24 | import android.graphics.BitmapFactory
25 | import android.graphics.Typeface
26 | import com.github.jonathanmerritt.rxassetmanager.core.ext.extensions.isFile
27 | import com.github.jonathanmerritt.rxassetmanager.core.ext.extensions.isFont
28 | import com.github.jonathanmerritt.rxassetmanager.core.ext.extensions.isImage
29 | import com.github.jonathanmerritt.rxassetmanager.core.ext.extensions.isXml
30 | import io.reactivex.Flowable
31 | import io.reactivex.Flowable.just
32 | import io.reactivex.Maybe
33 | import java.io.BufferedReader
34 | import java.io.File
35 | import java.io.InputStream
36 | import com.github.jonathanmerritt.rxassetmanager.core.RxAssetManager as rxAssetManager
37 |
38 | /**
39 | * Reactive asset manager extended.
40 | *
41 | * This class extends core.RxAssetManager, and has additional functionality.
42 | */
43 | class RxAssetManager : rxAssetManager, IsRxAssetManager {
44 |
45 | /**
46 | * Main constructor.
47 | *
48 | * @property manager android asset manager.
49 | * @constructor Creates a RxAssetManager instance.
50 | */
51 | constructor(manager: AssetManager) : super(manager)
52 |
53 | /**
54 | * Secondary constructor.
55 | *
56 | * @property context android context.
57 | * @constructor Creates a RxAssetManager instance.
58 | */
59 | constructor(context: Context) : super(context)
60 |
61 | /**
62 | * Opens asset file as string.
63 | * @param path asset file path.
64 | * @param mode file access mode.
65 | * @return a string maybe.
66 | */
67 | override fun openString(path: String, mode: Int): Maybe =
68 | open(path, mode).map { it.bufferedReader().use(BufferedReader::readText) }
69 |
70 | /**
71 | * Opens asset file as string pair.
72 | * @param path asset file path.
73 | * @param mode file access mode.
74 | * @return a string string pair maybe.
75 | */
76 | override fun openStringPair(path: String, mode: Int): Maybe> =
77 | openString(path, mode).map { path to it }
78 |
79 | /**
80 | * Opens asset file as a byte array.
81 | * @param path asset file path.
82 | * @param mode file access mode.
83 | * @return a byte array maybe.
84 | */
85 | override fun openBytes(path: String, mode: Int): Maybe = open(path, mode).map { it.readBytes() }
86 |
87 | /**
88 | * Opens asset file as a byte array pair.
89 | * @param path asset file path.
90 | * @param mode file access mode.
91 | * @return a string byte array pair maybe.
92 | */
93 | override fun openBytesPair(path: String, mode: Int): Maybe> =
94 | openBytes(path, mode).map { path to it }
95 |
96 | /**
97 | * Opens and save asset file.
98 | * @param path asset file path.
99 | * @param mode file access mode.
100 | * @param to save to location.
101 | * @return a file maybe.
102 | */
103 | override fun openSave(path: String, mode: Int, to: String): Maybe =
104 | open(path, mode).map { input ->
105 | File("$to/$path").apply { parentFile.mkdirs().run { outputStream().use { (input::copyTo) } } }
106 | }
107 |
108 | /**
109 | * Opens and save asset file pair.
110 | * @param path asset file path.
111 | * @param mode file access mode.
112 | * @param to save to location.
113 | * @return a string file pair maybe.
114 | */
115 | override fun openSavePair(path: String, mode: Int, to: String): Maybe> =
116 | openSave(path, mode, to).map { path to it }
117 |
118 | /**
119 | * Opens asset file as a bitmap.
120 | * @param path asset file path.
121 | * @param mode file access mode.
122 | * @return a bitmap maybe.
123 | */
124 | override fun openBitmap(path: String, mode: Int): Maybe =
125 | open(path, mode).map(BitmapFactory::decodeStream)
126 |
127 | /**
128 | * Opens asset file as a bitmap pair.
129 | * @param path asset file path.
130 | * @param mode file access mode.
131 | * @return a string bitmap pair maybe.
132 | */
133 | override fun openBitmapPair(path: String, mode: Int): Maybe> =
134 | openBitmap(path, mode).map { path to it }
135 |
136 | /**
137 | * Lists asset files recursively.
138 | * @param path asset file path.
139 | * @return a string flowable.
140 | */
141 | override fun listAll(path: String, sorting: Sorting): Flowable =
142 | listPath(path).flatMap { if (it.isFile()) just(it) else listAll(it, sorting) }.sorted(sorting::compare)
143 |
144 | /**
145 | * Lists and opens asset files as input streams.
146 | * @param path asset folder path.
147 | * @param mode file access mode.
148 | * @param all list all files.
149 | * @return an input stream flowable.
150 | */
151 | override fun listOpen(path: String, mode: Int, all: Boolean): Flowable =
152 | listFiles(path, all).flatMapMaybe { open(it, mode) }
153 |
154 | /**
155 | * Lists and opens asset files as input stream pairs.
156 | * @param path asset folder path.
157 | * @param mode file access mode.
158 | * @param all list all files.
159 | * @return a string input stream pair flowable.
160 | */
161 | override fun listOpenPair(path: String, mode: Int, all: Boolean): Flowable> =
162 | listFiles(path, all).flatMapMaybe { openPair(it, mode) }
163 |
164 | /**
165 | * Lists and opens asset files as strings.
166 | * @param path asset folder path.
167 | * @param mode file access mode.
168 | * @param all list all files.
169 | * @return a string flowable.
170 | */
171 | override fun listOpenString(path: String, mode: Int, all: Boolean): Flowable =
172 | listFiles(path, all).flatMapMaybe { openString(it, mode) }
173 |
174 | /**
175 | * Lists and opens asset files as string pairs.
176 | * @param path asset folder path.
177 | * @param mode file access mode.
178 | * @param all list all files.
179 | * @return a string string pair flowable.
180 | */
181 | override fun listOpenStringPair(path: String, mode: Int, all: Boolean): Flowable> =
182 | listFiles(path, all).flatMapMaybe { openStringPair(it, mode) }
183 |
184 | /**
185 | * Lists and opens asset files as byte arrays.
186 | * @param path asset folder path.
187 | * @param mode file access mode.
188 | * @param all list all files.
189 | * @return a byte array flowable.
190 | */
191 | override fun listOpenBytes(path: String, mode: Int, all: Boolean): Flowable =
192 | listFiles(path, all).flatMapMaybe { openBytes(it, mode) }
193 |
194 | /**
195 | * Lists and opens asset files as byte array pairs.
196 | * @param path asset folder path.
197 | * @param mode file access mode.
198 | * @param all list all files.
199 | * @return a string byte array pair flowable.
200 | */
201 | override fun listOpenBytesPair(path: String, mode: Int, all: Boolean): Flowable> =
202 | listFiles(path, all).flatMapMaybe { openBytesPair(it, mode) }
203 |
204 | /**
205 | * Lists, opens and saves asset files.
206 | * @param path asset folder path.
207 | * @param mode file access mode.
208 | * @param to save to location.
209 | * @param all list all files.
210 | * @return a file flowable.
211 | */
212 | override fun listOpenSave(path: String, mode: Int, to: String, all: Boolean): Flowable =
213 | listFiles(path, all).flatMapMaybe { openSave(it, mode, to) }
214 |
215 | /**
216 | * Lists, opens and saves asset file pairs.
217 | * @param path asset folder path.
218 | * @param mode file access mode.
219 | * @param to save to location.
220 | * @param all list all files.
221 | * @return a string file pair flowable.
222 | */
223 | override fun listOpenSavePair(path: String, mode: Int, to: String, all: Boolean): Flowable> =
224 | listFiles(path, all).flatMapMaybe { openSavePair(it, mode, to) }
225 |
226 | /**
227 | * Lists and opens asset files as bitmaps.
228 | * @param path asset folder path.
229 | * @param mode file access mode.
230 | * @param all list all files.
231 | * @return a bitmap flowable.
232 | */
233 | override fun listOpenBitmap(path: String, mode: Int, all: Boolean): Flowable =
234 | listFiles(path, all).filter(String::isImage).flatMapMaybe { openBitmap(it, mode) }
235 |
236 | /**
237 | * Lists and opens asset files as bitmap pairs.
238 | * @param path asset folder path.
239 | * @param mode file access mode.
240 | * @param all list all files.
241 | * @return a string bitmap pair flowable.
242 | */
243 | override fun listOpenBitmapPair(path: String, mode: Int, all: Boolean): Flowable> =
244 | listFiles(path, all).filter(String::isImage).flatMapMaybe { openBitmapPair(it, mode) }
245 |
246 | /**
247 | * Lists and opens asset files as typefaces.
248 | * @param path asset folder path.
249 | * @param all list all files.
250 | * @return a typeface flowable.
251 | */
252 | override fun listOpenTypeface(path: String, all: Boolean): Flowable =
253 | listFiles(path, all).filter(String::isFont).flatMapMaybe(::openTypeface)
254 |
255 | /**
256 | * Lists and opens asset files as typeface pairs.
257 | * @param path asset folder path.
258 | * @param all list all files.
259 | * @return a string typeface pair flowable.
260 | */
261 | override fun listOpenTypefacePair(path: String, all: Boolean): Flowable> =
262 | listFiles(path, all).filter(String::isFont).flatMapMaybe(::openTypefacePair)
263 |
264 | /**
265 | * Lists and opens asset files as file descriptors.
266 | * @param path asset folder path.
267 | * @param all list all files.
268 | * @return a file descriptor flowable.
269 | */
270 | override fun listOpenFd(path: String, all: Boolean): Flowable =
271 | listFiles(path, all).flatMapMaybe(::openFd)
272 |
273 | /**
274 | * Lists and opens asset files as file descriptor pairs.
275 | * @param path asset folder path.
276 | * @param all list all files.
277 | * @return a string file descriptor pair flowable.
278 | */
279 | override fun listOpenFdPair(path: String, all: Boolean): Flowable> =
280 | listFiles(path, all).flatMapMaybe(::openFdPair)
281 |
282 | /**
283 | * Lists and opens non asset files as file descriptors.
284 | * @param path non asset folder path.
285 | * @param cookie non asset file cookie.
286 | * @param all list all files.
287 | * @return a file descriptor flowable.
288 | */
289 | override fun listOpenNonAssetFd(cookie: Int, path: String, all: Boolean): Flowable =
290 | listFiles(path, all).flatMapMaybe { openNonAssetFd(cookie, it) }
291 |
292 | /**
293 | * Lists and opens non asset files as file descriptor pairs.
294 | * @param path non asset folder path.
295 | * @param cookie non asset file cookie.
296 | * @param all list all files.
297 | * @return a string file descriptor pair flowable.
298 | */
299 | override fun listOpenNonAssetFdPair(cookie: Int, path: String, all: Boolean):
300 | Flowable> =
301 | listFiles(path, all).flatMapMaybe { openNonAssetFdPair(cookie, it) }
302 |
303 | /**
304 | * Lists and opens xml files as xml resource parsers.
305 | * @param path xml folder path.
306 | * @param cookie xml file cookie.
307 | * @param all list all files.
308 | * @return an xml resource parser flowable.
309 | */
310 | override fun listOpenXmlResourceParser(cookie: Int, path: String, all: Boolean): Flowable =
311 | listFiles(path, all).filter(String::isXml).flatMapMaybe { openXmlResourceParser(cookie, it) }
312 |
313 | /**
314 | * Lists and opens xml files as xml resource parser pairs.
315 | * @param path xml folder path.
316 | * @param cookie xml file cookie.
317 | * @param all list all files.
318 | * @return a string xml resource parser pair flowable.
319 | */
320 | override fun listOpenXmlResourceParserPair(cookie: Int, path: String, all: Boolean):
321 | Flowable> =
322 | listFiles(path, all).filter(String::isXml).flatMapMaybe { openXmlResourceParserPair(cookie, it) }
323 |
324 |
325 | // Will list or list all file paths.
326 | private fun listFiles(path: String, all: Boolean): Flowable =
327 | (if (all) listAll(path, Depth) else listPath(path)).filter(String::isFile)
328 |
329 | // Will list paths, then it either combines it into a new path or does nothing.
330 | private fun listPath(path: String): Flowable =
331 | list(path).map { if (path.isNotBlank() && path != "/") "$path/$it" else it }
332 | }
333 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_core_ext.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
24 |
25 |
29 |
30 |
41 |
42 |
53 |
54 |
65 |
66 |
77 |
78 |
89 |
90 |
101 |
102 |
113 |
114 |
125 |
126 |
137 |
138 |
149 |
150 |
161 |
162 |
173 |
174 |
185 |
186 |
197 |
198 |
209 |
210 |
221 |
222 |
233 |
234 |
245 |
246 |
257 |
258 |
269 |
270 |
281 |
282 |
293 |
294 |
305 |
306 |
317 |
318 |
329 |
330 |
341 |
342 |
353 |
354 |
--------------------------------------------------------------------------------