├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── dimens.xml
│ │ │ └── styles.xml
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-hdpi
│ │ │ ├── ic_star_black_24dp.png
│ │ │ ├── ic_star_white_24dp.png
│ │ │ ├── ic_clear_white_24dp.png
│ │ │ ├── ic_history_black_18dp.png
│ │ │ ├── ic_history_white_24dp.png
│ │ │ ├── ic_search_white_24dp.png
│ │ │ ├── ic_settings_white_24dp.png
│ │ │ ├── ic_star_border_black_24dp.png
│ │ │ ├── ic_visibility_black_18dp.png
│ │ │ └── ic_visibility_white_24dp.png
│ │ ├── drawable-mdpi
│ │ │ ├── ic_star_black_24dp.png
│ │ │ ├── ic_star_white_24dp.png
│ │ │ ├── ic_clear_white_24dp.png
│ │ │ ├── ic_history_black_18dp.png
│ │ │ ├── ic_history_white_24dp.png
│ │ │ ├── ic_search_white_24dp.png
│ │ │ ├── ic_settings_white_24dp.png
│ │ │ ├── ic_star_border_black_24dp.png
│ │ │ ├── ic_visibility_black_18dp.png
│ │ │ └── ic_visibility_white_24dp.png
│ │ ├── drawable-xhdpi
│ │ │ ├── ic_clear_white_24dp.png
│ │ │ ├── ic_search_white_24dp.png
│ │ │ ├── ic_star_black_24dp.png
│ │ │ ├── ic_star_white_24dp.png
│ │ │ ├── ic_history_black_18dp.png
│ │ │ ├── ic_history_white_24dp.png
│ │ │ ├── ic_settings_white_24dp.png
│ │ │ ├── ic_star_border_black_24dp.png
│ │ │ ├── ic_visibility_black_18dp.png
│ │ │ └── ic_visibility_white_24dp.png
│ │ ├── drawable-xxhdpi
│ │ │ ├── ic_clear_white_24dp.png
│ │ │ ├── ic_star_black_24dp.png
│ │ │ ├── ic_star_white_24dp.png
│ │ │ ├── ic_history_black_18dp.png
│ │ │ ├── ic_history_white_24dp.png
│ │ │ ├── ic_search_white_24dp.png
│ │ │ ├── ic_settings_white_24dp.png
│ │ │ ├── ic_visibility_black_18dp.png
│ │ │ ├── ic_visibility_white_24dp.png
│ │ │ └── ic_star_border_black_24dp.png
│ │ ├── drawable-xxxhdpi
│ │ │ ├── ic_star_black_24dp.png
│ │ │ ├── ic_star_white_24dp.png
│ │ │ ├── ic_clear_white_24dp.png
│ │ │ ├── ic_search_white_24dp.png
│ │ │ ├── ic_history_black_18dp.png
│ │ │ ├── ic_history_white_24dp.png
│ │ │ ├── ic_settings_white_24dp.png
│ │ │ ├── ic_star_border_black_24dp.png
│ │ │ ├── ic_visibility_black_18dp.png
│ │ │ └── ic_visibility_white_24dp.png
│ │ ├── drawable
│ │ │ ├── ic_history_black_18dp_tint.xml
│ │ │ ├── ic_visibility_black_18dp_tint.xml
│ │ │ ├── book_starred_selector.xml
│ │ │ ├── ic_baseline_save_alt_24.xml
│ │ │ ├── baseline_favorite_18.xml
│ │ │ ├── baseline_favorite_24.xml
│ │ │ └── ic_baseline_settings_backup_restore_24.xml
│ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ ├── layout
│ │ │ ├── node_view.xml
│ │ │ ├── outline_node_view.xml
│ │ │ ├── database_management_fragment.xml
│ │ │ ├── activity_reading_story.xml
│ │ │ ├── activity_books.xml
│ │ │ ├── item_book.xml
│ │ │ └── activity_indexing.xml
│ │ ├── layout-sw600dp
│ │ │ ├── node_view.xml
│ │ │ ├── outline_node_view.xml
│ │ │ └── item_book.xml
│ │ └── menu
│ │ │ └── list_menu.xml
│ │ ├── ic_launcher-web.png
│ │ ├── java
│ │ └── net
│ │ │ └── bloople
│ │ │ └── stories
│ │ │ ├── Indexable.kt
│ │ │ ├── StoryParser.kt
│ │ │ ├── IndexViewModel.kt
│ │ │ ├── NodesAdapter.kt
│ │ │ ├── NodesHelper.kt
│ │ │ ├── OutlineAdapter.kt
│ │ │ ├── IndexingTask.kt
│ │ │ ├── BooksSearcher.kt
│ │ │ ├── DatabaseManagementFragment.kt
│ │ │ ├── BooksAdapter.kt
│ │ │ ├── DatabaseHelper.kt
│ │ │ ├── Book.kt
│ │ │ ├── IndexingActivity.kt
│ │ │ ├── CursorRecyclerAdapter.kt
│ │ │ ├── ReadingStoryActivity.kt
│ │ │ └── BooksActivity.kt
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .gitignore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── LICENSE
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Stories
3 |
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | /app/release
9 |
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_star_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-hdpi/ic_star_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_star_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-hdpi/ic_star_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_star_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-mdpi/ic_star_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_star_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-mdpi/ic_star_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_clear_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-hdpi/ic_clear_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_history_black_18dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-hdpi/ic_history_black_18dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_history_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-hdpi/ic_history_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_search_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-hdpi/ic_search_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_clear_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-mdpi/ic_clear_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_history_black_18dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-mdpi/ic_history_black_18dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_history_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-mdpi/ic_history_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_search_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-mdpi/ic_search_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_clear_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xhdpi/ic_clear_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_search_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xhdpi/ic_search_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_star_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xhdpi/ic_star_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_star_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xhdpi/ic_star_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_clear_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xxhdpi/ic_clear_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_star_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xxhdpi/ic_star_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_star_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xxhdpi/ic_star_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_star_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xxxhdpi/ic_star_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_star_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xxxhdpi/ic_star_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_settings_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-hdpi/ic_settings_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_settings_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-mdpi/ic_settings_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_history_black_18dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xhdpi/ic_history_black_18dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_history_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xhdpi/ic_history_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_settings_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xhdpi/ic_settings_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_history_black_18dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xxhdpi/ic_history_black_18dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_history_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xxhdpi/ic_history_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_search_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xxhdpi/ic_search_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_clear_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xxxhdpi/ic_clear_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_search_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xxxhdpi/ic_search_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_star_border_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-hdpi/ic_star_border_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_visibility_black_18dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-hdpi/ic_visibility_black_18dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_visibility_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-hdpi/ic_visibility_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_star_border_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-mdpi/ic_star_border_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_visibility_black_18dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-mdpi/ic_visibility_black_18dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_visibility_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-mdpi/ic_visibility_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_star_border_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xhdpi/ic_star_border_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_visibility_black_18dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xhdpi/ic_visibility_black_18dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_visibility_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xhdpi/ic_visibility_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_settings_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xxhdpi/ic_settings_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_visibility_black_18dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xxhdpi/ic_visibility_black_18dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_visibility_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xxhdpi/ic_visibility_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_history_black_18dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xxxhdpi/ic_history_black_18dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_history_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xxxhdpi/ic_history_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_settings_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xxxhdpi/ic_settings_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_star_border_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xxhdpi/ic_star_border_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_star_border_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xxxhdpi/ic_star_border_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_visibility_black_18dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xxxhdpi/ic_visibility_black_18dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_visibility_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/stories-app/master/app/src/main/res/drawable-xxxhdpi/ic_visibility_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/java/net/bloople/stories/Indexable.kt:
--------------------------------------------------------------------------------
1 | package net.bloople.stories
2 |
3 | internal interface Indexable {
4 | fun onIndexingProgress(progress: Int, max: Int)
5 | fun onIndexingComplete(count: Int)
6 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_history_black_18dp_tint.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_visibility_black_18dp_tint.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Nov 12 16:10:28 AEDT 2019
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-7.0.2-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/book_starred_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_baseline_save_alt_24.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/baseline_favorite_18.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/node_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-sw600dp/node_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-sw600dp/outline_node_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/outline_node_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/baseline_favorite_24.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_baseline_settings_backup_restore_24.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/net/bloople/stories/StoryParser.kt:
--------------------------------------------------------------------------------
1 | package net.bloople.stories
2 |
3 | import java.io.IOException
4 | import java.io.Reader
5 | import java.util.*
6 | import kotlin.Throws
7 |
8 | internal class StoryParser(reader: Reader) {
9 | private val scanner: Scanner
10 |
11 | @Throws(IOException::class)
12 | operator fun hasNext(): Boolean {
13 | return scanner.hasNext()
14 | }
15 |
16 | @Throws(IOException::class)
17 | operator fun next(): String {
18 | return scanner.next()
19 | }
20 |
21 | init {
22 | scanner = Scanner(reader)
23 | scanner.useDelimiter("(?:\r?\n[\u200B\uFEFF]*){2,}+")
24 | }
25 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/database_management_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
14 |
15 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 | android.enableJetifier=true
20 | android.useAndroidX=true
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2016 Brenton Fletcher (http://bloople.net i@bloople.net)
2 |
3 | Permission is hereby granted, free of charge, to any person
4 | obtaining a copy of this software and associated documentation
5 | files (the "Software"), to deal in the Software without
6 | restriction, including without limitation the rights to use,
7 | copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the
9 | Software is furnished to do so, subject to the following
10 | conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 | OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_reading_story.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
17 |
24 |
29 |
30 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'kotlin-android'
4 | }
5 |
6 | android {
7 | compileSdkVersion 31
8 | buildToolsVersion "31.0.0"
9 |
10 | defaultConfig {
11 | applicationId "net.bloople.stories"
12 | minSdkVersion 28
13 | targetSdkVersion 28
14 | final def version = 23
15 | versionCode version
16 | versionName version.toString()
17 | }
18 | compileOptions {
19 | sourceCompatibility JavaVersion.VERSION_1_8
20 | targetCompatibility JavaVersion.VERSION_1_8
21 | }
22 | lintOptions {
23 | abortOnError false
24 | }
25 | buildTypes {
26 | release {
27 | minifyEnabled false
28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
29 | }
30 | debug {
31 | applicationIdSuffix ".debug"
32 | }
33 | }
34 | }
35 |
36 | dependencies {
37 | implementation fileTree(dir: 'libs', include: ['*.jar'])
38 |
39 | implementation "androidx.core:core-ktx:1.7.0"
40 |
41 | implementation 'androidx.recyclerview:recyclerview:1.2.1'
42 | implementation 'androidx.appcompat:appcompat:1.4.0'
43 | implementation 'com.google.android.material:material:1.4.0'
44 |
45 | implementation 'androidx.drawerlayout:drawerlayout:1.1.1'
46 |
47 | final def markwon_version = '4.1.2'
48 | implementation "io.noties.markwon:core:$markwon_version"
49 | }
50 | repositories {
51 | mavenCentral()
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/java/net/bloople/stories/IndexViewModel.kt:
--------------------------------------------------------------------------------
1 | package net.bloople.stories
2 |
3 | import android.app.Application
4 | import android.database.Cursor
5 | import androidx.lifecycle.AndroidViewModel
6 | import androidx.lifecycle.MutableLiveData
7 | import java.util.concurrent.Executors
8 |
9 | class IndexViewModel(application: Application) : AndroidViewModel(application) {
10 | val searchResults: MutableLiveData by lazy {
11 | MutableLiveData().also { resolve() }
12 | }
13 |
14 | val sorterDescription: MutableLiveData by lazy {
15 | MutableLiveData(searcher.description())
16 | }
17 |
18 | private val searcher = BooksSearcher()
19 |
20 | val sortMethod: Int
21 | get() = searcher.sortMethod
22 |
23 | val sortDirectionAsc: Boolean
24 | get() = searcher.sortDirectionAsc
25 |
26 | fun setSearchText(searchText: String) {
27 | searcher.setSearchText(searchText)
28 | resolve()
29 | }
30 |
31 | fun setSort(sortMethod: Int, sortDirectionAsc: Boolean) {
32 | searcher.sortMethod = sortMethod
33 | searcher.sortDirectionAsc = sortDirectionAsc
34 | sorterDescription.value = searcher.description()
35 | resolve()
36 | }
37 |
38 | fun refresh() {
39 | resolve()
40 | }
41 |
42 | private fun resolve() {
43 | val service = Executors.newSingleThreadExecutor()
44 | service.submit { searchResults.postValue(searcher.search(getApplication())) }
45 | }
46 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
22 |
26 |
27 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/list_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/java/net/bloople/stories/NodesAdapter.kt:
--------------------------------------------------------------------------------
1 | package net.bloople.stories
2 |
3 | import android.view.View
4 | import net.bloople.stories.NodesHelper.createNodeView
5 | import io.noties.markwon.Markwon
6 | import androidx.recyclerview.widget.RecyclerView
7 | import android.widget.TextView
8 | import android.view.ViewGroup
9 | import org.commonmark.node.Node
10 | import java.util.ArrayList
11 |
12 | internal class NodesAdapter(private val markwon: Markwon) : RecyclerView.Adapter() {
13 | private val nodes: MutableList
14 |
15 | internal class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
16 | var textView: TextView = view.findViewById(R.id.text_view)
17 | }
18 |
19 | fun addAll(newNodes: List) {
20 | nodes.addAll(newNodes)
21 | notifyItemRangeInserted(nodes.size - 1, newNodes.size)
22 | }
23 |
24 | // Create new views (invoked by the layout manager)
25 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
26 | return ViewHolder(createNodeView(parent))
27 | }
28 |
29 | // Replace the contents of a view (invoked by the layout manager)
30 | override fun onBindViewHolder(holder: ViewHolder, position: Int) {
31 | val tv = holder.textView
32 | markwon.setParsedMarkdown(tv, markwon.render(nodes[position]))
33 | tv.setPadding(
34 | tv.paddingLeft,
35 | if (position == 0) tv.paddingBottom else 0,
36 | tv.paddingRight,
37 | tv.paddingBottom
38 | )
39 | }
40 |
41 | // Return the size of your dataset (invoked by the layout manager)
42 | override fun getItemCount(): Int {
43 | return nodes.size
44 | }
45 |
46 | init {
47 | nodes = ArrayList()
48 | }
49 | }
--------------------------------------------------------------------------------
/app/src/main/java/net/bloople/stories/NodesHelper.kt:
--------------------------------------------------------------------------------
1 | package net.bloople.stories
2 |
3 | import android.view.ViewGroup
4 | import io.noties.markwon.Markwon
5 | import android.widget.TextView
6 | import io.noties.markwon.AbstractMarkwonPlugin
7 | import io.noties.markwon.core.MarkwonTheme
8 | import android.graphics.Typeface
9 | import android.view.LayoutInflater
10 | import android.view.View
11 | import org.commonmark.node.Heading
12 | import org.commonmark.node.Node
13 |
14 | internal object NodesHelper {
15 | private val HEADER_SIZES = floatArrayOf(
16 | 1.5f, 1.4f, 1.3f, 1.2f, 1.1f, 1f
17 | )
18 |
19 | @JvmStatic
20 | fun buildMarkwon(parent: ViewGroup): Markwon {
21 | val nodeView = createNodeView(parent)
22 | val textView = nodeView.findViewById(R.id.text_view)
23 | return Markwon.builder(parent.context).usePlugin(object : AbstractMarkwonPlugin() {
24 | override fun configureTheme(builder: MarkwonTheme.Builder) {
25 | builder.blockMargin(textView.paddingBottom)
26 | builder.blockQuoteColor(textView.currentTextColor)
27 | builder.bulletWidth(Math.round(textView.paddingBottom * 0.4).toInt())
28 | builder.headingBreakHeight(0)
29 | builder.headingTextSizeMultipliers(HEADER_SIZES)
30 | builder.headingTypeface(Typeface.create(textView.typeface, Typeface.BOLD))
31 | builder.thematicBreakColor(textView.currentTextColor)
32 | }
33 | }).build()
34 | }
35 |
36 | @JvmStatic
37 | fun createNodeView(parent: ViewGroup): View {
38 | return LayoutInflater.from(parent.context).inflate(R.layout.node_view, parent,false)
39 | }
40 |
41 | @JvmStatic
42 | fun findFirstHeading(node: Node): Heading? {
43 | if (node is Heading) return node
44 | var node: Node? = node.firstChild
45 | while (node != null) {
46 | val heading = findFirstHeading(node)
47 | if (heading != null) return heading
48 | node = node.next
49 | }
50 | return null
51 | }
52 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_books.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
21 |
31 |
32 |
43 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/app/src/main/java/net/bloople/stories/OutlineAdapter.kt:
--------------------------------------------------------------------------------
1 | package net.bloople.stories
2 |
3 | import io.noties.markwon.Markwon
4 | import androidx.recyclerview.widget.RecyclerView
5 | import android.widget.TextView
6 | import android.view.ViewGroup
7 | import android.view.LayoutInflater
8 | import android.view.View
9 | import org.commonmark.node.Node
10 | import java.util.ArrayList
11 |
12 | internal class OutlineAdapter(private val markwon: Markwon) : RecyclerView.Adapter() {
13 | private val nodes: MutableList
14 | private val nodeIndexes: MutableList
15 |
16 | internal inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
17 | var textView: TextView = view.findViewById(R.id.text_view)
18 |
19 | init {
20 | textView.setOnClickListener { view ->
21 | val activity = view.context as ReadingStoryActivity
22 | activity.scrollToPosition(nodeIndexes[bindingAdapterPosition])
23 | activity.closeDrawers()
24 | }
25 | }
26 | }
27 |
28 | fun addAll(newNodes: List, newNodeIndexes: List) {
29 | nodes.addAll(newNodes)
30 | nodeIndexes.addAll(newNodeIndexes)
31 | notifyItemRangeInserted(nodes.size - 1, newNodes.size)
32 | }
33 |
34 | // Create new views (invoked by the layout manager)
35 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
36 | val view = LayoutInflater.from(parent.context).inflate(R.layout.outline_node_view, parent,false)
37 | return ViewHolder(view)
38 | }
39 |
40 | // Replace the contents of a view (invoked by the layout manager)
41 | override fun onBindViewHolder(holder: ViewHolder, position: Int) {
42 | val tv = holder.textView
43 | markwon.setParsedMarkdown(tv, markwon.render(nodes[position]))
44 | tv.setPadding(
45 | tv.paddingLeft,
46 | if (position == 0) tv.paddingBottom else 0,
47 | tv.paddingRight,
48 | tv.paddingBottom
49 | )
50 | }
51 |
52 | // Return the size of your dataset (invoked by the layout manager)
53 | override fun getItemCount(): Int {
54 | return nodes.size
55 | }
56 |
57 | init {
58 | nodes = ArrayList()
59 | nodeIndexes = ArrayList()
60 | }
61 | }
--------------------------------------------------------------------------------
/app/src/main/java/net/bloople/stories/IndexingTask.kt:
--------------------------------------------------------------------------------
1 | package net.bloople.stories
2 |
3 | import android.content.Context
4 | import android.os.AsyncTask
5 | import java.io.File
6 | import java.io.IOException
7 | import java.util.ArrayList
8 |
9 | internal class IndexingTask(private val context: Context, private val indexable: Indexable) :
10 | AsyncTask() {
11 | private var progress = 0
12 | private var max = 0
13 | private var indexed = 0
14 |
15 | override fun doInBackground(vararg params: String?): Void? {
16 | destroyDeleted()
17 | indexDirectory(File(params[0]!!))
18 | publishProgress(progress, max)
19 | return null
20 | }
21 |
22 | override fun onProgressUpdate(vararg args: Int?) {
23 | indexable.onIndexingProgress(args[0]!!, args[1]!!)
24 | }
25 |
26 | override fun onPostExecute(result: Void?) {
27 | indexable.onIndexingComplete(indexed)
28 | }
29 |
30 | private fun destroyDeleted() {
31 | val db = DatabaseHelper.instance(context)
32 | db.query("books", null, null, null, null, null, null).use {
33 | max += it.count
34 | while(it.moveToNext()) {
35 | val book = Book(it)
36 | val file = File(book.path!!)
37 | if(!file.exists()) book.destroy(context)
38 | progress++
39 | publishProgress(progress, max)
40 | }
41 | }
42 | }
43 |
44 | private fun indexDirectory(directory: File) {
45 | val files = directory.listFiles() ?: return
46 | val filesToIndex = ArrayList()
47 |
48 | for(f in files) {
49 | if(f.isDirectory) {
50 | indexDirectory(f)
51 | }
52 | else {
53 | val name = f.name
54 | val ext = name.substring(name.lastIndexOf('.') + 1)
55 | if(ext == "txt") filesToIndex.add(f)
56 | }
57 | }
58 |
59 | max += filesToIndex.size
60 | publishProgress(progress, max)
61 |
62 | for(f in filesToIndex) indexFile(f)
63 | }
64 |
65 | private fun indexFile(file: File) {
66 | (Book.findByPathOrNull(context, file.canonicalPath) ?: Book()).edit(context) {
67 | val filePath = file.canonicalPath
68 | path = filePath
69 | title = file.name.replace("\\.txt$".toRegex(), "")
70 | mtime = file.lastModified()
71 | size = file.length()
72 | }
73 | progress++
74 | indexed++
75 |
76 | publishProgress(progress, max)
77 | }
78 | }
--------------------------------------------------------------------------------
/app/src/main/java/net/bloople/stories/BooksSearcher.kt:
--------------------------------------------------------------------------------
1 | package net.bloople.stories
2 |
3 | import android.content.Context
4 | import android.database.Cursor
5 | import java.lang.IllegalStateException
6 |
7 | class BooksSearcher internal constructor() {
8 | private var searchText = ""
9 | var sortMethod = SORT_AGE
10 | var sortDirectionAsc = false
11 |
12 | fun setSearchText(inSearchText: String) {
13 | searchText = inSearchText
14 | }
15 |
16 | fun flipSortDirection() {
17 | sortDirectionAsc = !sortDirectionAsc
18 | }
19 |
20 | fun description(): String {
21 | return "Sorted by " + sortMethodDescription().lowercase() + " " + sortDirectionDescription().lowercase()
22 | }
23 |
24 | private fun sortMethodDescription(): String {
25 | return when (sortMethod) {
26 | SORT_ALPHABETIC -> "Title"
27 | SORT_AGE -> "Published Date"
28 | SORT_SIZE -> "Size"
29 | SORT_LAST_OPENED -> "Last Opened At"
30 | SORT_OPENED_COUNT -> "Opened Count"
31 | SORT_STARRED -> "Starred"
32 | else -> throw IllegalStateException("sort_method not in valid range")
33 | }
34 | }
35 |
36 | private fun sortDirectionDescription(): String {
37 | return if (sortDirectionAsc) "Ascending" else "Descending"
38 | }
39 |
40 | private fun orderBy(): String {
41 | var orderBy = ""
42 | when (sortMethod) {
43 | SORT_ALPHABETIC -> orderBy += "title"
44 | SORT_AGE -> orderBy += "mtime"
45 | SORT_SIZE -> orderBy += "size"
46 | SORT_LAST_OPENED -> orderBy += "last_opened_at"
47 | SORT_STARRED -> orderBy += "starred"
48 | SORT_OPENED_COUNT -> orderBy += "opened_count"
49 | }
50 | orderBy += if (sortDirectionAsc) " ASC" else " DESC"
51 | orderBy += ", title ASC"
52 | return orderBy
53 | }
54 |
55 | fun search(context: Context): Cursor {
56 | val db = DatabaseHelper.instance(context)
57 | val cursor: Cursor = if (searchText != "") {
58 | db.query("books", null, "title LIKE ?", arrayOf("%$searchText%"), null, null, orderBy())
59 | } else {
60 | db.query("books", null, null, null, null, null, orderBy())
61 | }
62 | cursor.moveToFirst()
63 | return cursor
64 | }
65 |
66 | companion object {
67 | const val SORT_ALPHABETIC = 0
68 | const val SORT_AGE = 1
69 | const val SORT_SIZE = 2
70 | const val SORT_LAST_OPENED = 3
71 | const val SORT_STARRED = 4
72 | const val SORT_OPENED_COUNT = 5
73 | }
74 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_book.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
17 |
26 |
27 |
31 |
32 |
43 |
44 |
58 |
59 |
60 |
61 |
67 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_indexing.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
19 |
26 |
27 |
28 |
33 |
40 |
41 |
45 |
46 |
53 |
54 |
62 |
63 |
64 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/app/src/main/java/net/bloople/stories/DatabaseManagementFragment.kt:
--------------------------------------------------------------------------------
1 | package net.bloople.stories
2 |
3 | import android.app.Activity
4 | import android.content.Intent
5 | import android.os.Bundle
6 | import android.view.LayoutInflater
7 | import android.view.View
8 | import android.view.ViewGroup
9 | import android.widget.ImageButton
10 | import android.widget.Toast
11 | import androidx.fragment.app.Fragment
12 | import java.io.IOException
13 |
14 | class DatabaseManagementFragment : Fragment() {
15 | private lateinit var importDatabaseButton: ImageButton
16 | private lateinit var exportDatabaseButton: ImageButton
17 |
18 | override fun onCreateView(inflater: LayoutInflater, parent: ViewGroup?, savedInstanceState: Bundle?): View? {
19 | return inflater.inflate(R.layout.database_management_fragment, parent, false)
20 | }
21 |
22 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
23 | super.onViewCreated(view, savedInstanceState)
24 | exportDatabaseButton = view.findViewById(R.id.export_database)
25 | exportDatabaseButton.setOnClickListener { startExport() }
26 | importDatabaseButton = view.findViewById(R.id.import_database)
27 | importDatabaseButton.setOnClickListener { startImport() }
28 | }
29 |
30 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
31 | if(requestCode == REQUEST_CODE_EXPORT && resultCode == Activity.RESULT_OK) completeExport(data)
32 | else if(requestCode == REQUEST_CODE_IMPORT && resultCode == Activity.RESULT_OK) completeImport(data)
33 | }
34 |
35 | private fun startExport() {
36 | val intent = Intent(Intent.ACTION_CREATE_DOCUMENT)
37 | intent.addCategory(Intent.CATEGORY_OPENABLE)
38 | intent.type = "application/vnd.sqlite3"
39 | intent.putExtra(Intent.EXTRA_TITLE, "Stories.db")
40 | startActivityForResult(intent, REQUEST_CODE_EXPORT)
41 | }
42 |
43 | private fun completeExport(data: Intent?) {
44 | try {
45 | val outputStream = requireContext().contentResolver.openOutputStream(data!!.data!!)
46 | DatabaseHelper.exportDatabase(requireContext(), outputStream!!)
47 | Toast.makeText(context, "Database exported successfully", Toast.LENGTH_LONG).show()
48 | }
49 | catch(e: IOException) {
50 | Toast.makeText(context, "Error", Toast.LENGTH_LONG).show()
51 | }
52 | }
53 |
54 | private fun startImport() {
55 | val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
56 | intent.addCategory(Intent.CATEGORY_OPENABLE)
57 | intent.type = "*/*"
58 | startActivityForResult(intent, REQUEST_CODE_IMPORT)
59 | }
60 |
61 | private fun completeImport(data: Intent?) {
62 | try {
63 | val inputStream = requireContext().contentResolver.openInputStream(data!!.data!!)
64 | DatabaseHelper.importDatabase(requireContext(), inputStream!!)
65 | Toast.makeText(context, "Database imported successfully", Toast.LENGTH_LONG).show()
66 | }
67 | catch(e: IOException) {
68 | Toast.makeText(context, "Error", Toast.LENGTH_LONG).show()
69 | }
70 | }
71 |
72 | companion object {
73 | private const val REQUEST_CODE_EXPORT = 0
74 | private const val REQUEST_CODE_IMPORT = 2
75 | }
76 | }
--------------------------------------------------------------------------------
/app/src/main/java/net/bloople/stories/BooksAdapter.kt:
--------------------------------------------------------------------------------
1 | package net.bloople.stories
2 |
3 | import androidx.recyclerview.widget.RecyclerView
4 | import android.widget.TextView
5 | import android.widget.ImageButton
6 | import android.content.Intent
7 | import android.database.Cursor
8 | import android.view.ViewGroup
9 | import android.view.LayoutInflater
10 | import android.view.View
11 | import java.text.DecimalFormat
12 | import java.text.SimpleDateFormat
13 | import java.util.Date
14 | import java.util.Locale
15 | import kotlin.math.log10
16 | import kotlin.math.pow
17 |
18 | internal class BooksAdapter(cursor: Cursor?) : CursorRecyclerAdapter(cursor) {
19 | internal class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
20 | var titleView: TextView
21 | var sizeView: TextView
22 | var ageView: TextView?
23 | var lastOpenedView: TextView
24 | var openedCountView: TextView?
25 | var starView: ImageButton
26 |
27 | init {
28 | view.setOnClickListener { v: View ->
29 | v.context.startActivity(Book.idTo(Intent(v.context, ReadingStoryActivity::class.java), itemId))
30 | }
31 |
32 | titleView = view.findViewById(R.id.story_title)
33 | sizeView = view.findViewById(R.id.story_size)
34 | ageView = view.findViewById(R.id.story_age)
35 | lastOpenedView = view.findViewById(R.id.story_last_opened)
36 | openedCountView = view.findViewById(R.id.story_opened_count)
37 | starView = view.findViewById(R.id.story_star)
38 |
39 | starView.setOnClickListener { v: View ->
40 | Book.edit(v.context, itemId) {
41 | starred = !starred
42 | v.isActivated = starred
43 | }
44 | }
45 | }
46 | }
47 |
48 | private val DATE_FORMAT = SimpleDateFormat("d MMMM yyyy", Locale.getDefault())
49 |
50 | // Create new views (invoked by the layout manager)
51 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
52 | val view = LayoutInflater.from(parent.context).inflate(R.layout.item_book, parent,false)
53 | return ViewHolder(view)
54 | }
55 |
56 | // Replace the contents of a view (invoked by the layout manager)
57 | override fun onBindViewHolder(holder: ViewHolder, cursor: Cursor) {
58 | val book = Book(cursor)
59 | holder.titleView.text = book.title
60 | holder.sizeView.text = getReadableFileSize(book.size)
61 |
62 | holder.ageView?.let { view -> view.text = DATE_FORMAT.format(Date(book.mtime)) }
63 |
64 | val lastOpenedMillis = book.lastOpenedAt
65 | if(lastOpenedMillis > 0L) {
66 | holder.lastOpenedView.text = DATE_FORMAT.format(Date(lastOpenedMillis))
67 | }
68 | else {
69 | holder.lastOpenedView.text = "Never"
70 | }
71 |
72 | holder.openedCountView?.let { view -> view.text = book.openedCount.toString() }
73 |
74 | holder.starView.isActivated = book.starred
75 | }
76 |
77 | companion object {
78 | //Copied from https://github.com/nbsp-team/MaterialFilePicker
79 | fun getReadableFileSize(size: Long): String {
80 | if(size <= 0) return "0"
81 | val units = arrayOf("B", "KB", "MB", "GB", "TB")
82 | val digitGroups = (log10(size.toDouble()) / log10(1024.0)).toInt()
83 | return DecimalFormat("#").format(size / 1024.0.pow(digitGroups.toDouble())) + " " + units[digitGroups]
84 | }
85 | }
86 | }
--------------------------------------------------------------------------------
/app/src/main/java/net/bloople/stories/DatabaseHelper.kt:
--------------------------------------------------------------------------------
1 | package net.bloople.stories
2 |
3 | import android.content.Context
4 | import android.database.sqlite.SQLiteDatabase
5 | import java.io.FileInputStream
6 | import java.io.FileOutputStream
7 | import java.io.IOException
8 | import java.io.InputStream
9 | import java.io.OutputStream
10 |
11 | internal object DatabaseHelper {
12 | private const val DB_NAME = "books"
13 | private lateinit var database: SQLiteDatabase
14 |
15 | private fun obtainDatabase(context: Context): SQLiteDatabase {
16 | val db = context.applicationContext.openOrCreateDatabase(DB_NAME, Context.MODE_PRIVATE, null)
17 | loadSchema(db)
18 | return db
19 | }
20 |
21 | private fun loadSchema(db: SQLiteDatabase) {
22 | db.execSQL(
23 | "CREATE TABLE IF NOT EXISTS books ( " +
24 | "_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
25 | "path TEXT, " +
26 | "title TEXT, " +
27 | "mtime INT DEFAULT 0, " +
28 | "size INTEGER DEFAULT 0, " +
29 | "last_opened_at INTEGER DEFAULT 0, " +
30 | "last_read_position INTEGER DEFAULT 0" +
31 | ")"
32 | )
33 |
34 | if(!hasColumn(db, "books", "starred")) {
35 | db.execSQL("ALTER TABLE books ADD COLUMN starred INT DEFAULT 0")
36 | }
37 |
38 | if(!hasColumn(db, "books", "opened_count")) {
39 | db.execSQL("ALTER TABLE books ADD COLUMN opened_count INTEGER")
40 | db.execSQL("UPDATE books SET opened_count=0")
41 | }
42 | }
43 |
44 | @JvmStatic
45 | @Synchronized
46 | fun instance(context: Context): SQLiteDatabase {
47 | if (!::database.isInitialized) {
48 | database = obtainDatabase(context)
49 | }
50 | return database
51 | }
52 |
53 | @JvmStatic
54 | @Synchronized
55 | fun deleteDatabase(context: Context) {
56 | context.applicationContext.deleteDatabase(DB_NAME)
57 | database = obtainDatabase(context)
58 | }
59 |
60 | @JvmStatic
61 | @Synchronized
62 | fun exportDatabase(context: Context, outputStream: OutputStream) {
63 | val path = instance(context).use { it.path }
64 | database = obtainDatabase(context)
65 |
66 | var inputStream: InputStream? = null
67 | try {
68 | inputStream = FileInputStream(path)
69 | val buffer = ByteArray(1024)
70 | var length: Int
71 | while(inputStream.read(buffer).also { length = it } > 0) {
72 | outputStream.write(buffer, 0, length)
73 | }
74 | }
75 | finally {
76 | inputStream?.close()
77 | outputStream.close()
78 | }
79 | }
80 |
81 | @JvmStatic
82 | @Synchronized
83 | fun importDatabase(context: Context, inputStream: InputStream) {
84 | val path = instance(context).use { it.path }
85 | database = obtainDatabase(context)
86 |
87 | var outputStream: OutputStream? = null
88 | try {
89 | outputStream = FileOutputStream(path)
90 | val buffer = ByteArray(1024)
91 | var length: Int
92 | while(inputStream.read(buffer).also { length = it } > 0) {
93 | outputStream.write(buffer, 0, length)
94 | }
95 | }
96 | finally {
97 | inputStream.close()
98 | outputStream?.close()
99 | }
100 | }
101 |
102 | private fun hasColumn(db: SQLiteDatabase, tableName: String, columnName: String): Boolean {
103 | db.rawQuery("PRAGMA table_info($tableName)", null).use {
104 | while (it.moveToNext()) {
105 | if (it.getString(it.getColumnIndex("name")).equals(columnName)) {
106 | return true
107 | }
108 | }
109 | }
110 | return false
111 | }
112 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout-sw600dp/item_book.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
25 |
26 |
30 |
31 |
42 |
43 |
57 |
58 |
72 |
73 |
86 |
87 |
91 |
92 |
93 |
94 |
100 |
--------------------------------------------------------------------------------
/app/src/main/java/net/bloople/stories/Book.kt:
--------------------------------------------------------------------------------
1 | package net.bloople.stories
2 |
3 | import android.content.ContentValues
4 | import android.content.Context
5 | import android.content.Intent
6 | import android.database.Cursor
7 |
8 | internal class Book {
9 | var _id: Long? = null
10 | var path: String? = null
11 | var title: String? = null
12 | var mtime: Long = 0
13 | var size: Long = 0
14 | var lastOpenedAt: Long = 0
15 | var lastReadPosition = 0
16 | var starred = false
17 | var openedCount = 0
18 |
19 | constructor()
20 | constructor(result: Cursor) {
21 | _id = result.getLong(result.getColumnIndex("_id"))
22 | path = result.getString(result.getColumnIndex("path"))
23 | title = result.getString(result.getColumnIndex("title"))
24 | mtime = result.getLong(result.getColumnIndex("mtime"))
25 | size = result.getLong(result.getColumnIndex("size"))
26 | lastOpenedAt = result.getLong(result.getColumnIndex("last_opened_at"))
27 | lastReadPosition = result.getInt(result.getColumnIndex("last_read_position"))
28 | starred = result.getInt(result.getColumnIndex("starred")) == 1
29 | openedCount = result.getInt(result.getColumnIndex("opened_count"))
30 | }
31 |
32 | fun save(context: Context) {
33 | val values = ContentValues().apply {
34 | put("path", path)
35 | put("title", title)
36 | put("mtime", mtime)
37 | put("size", size)
38 | put("last_opened_at", lastOpenedAt)
39 | put("last_read_position", lastReadPosition)
40 | put("starred", if(starred) 1 else 0)
41 | put("opened_count", openedCount)
42 | }
43 |
44 | val db = DatabaseHelper.instance(context)
45 | if (_id != null) {
46 | db.update("books", values, "_id=?", arrayOf(_id.toString()))
47 | }
48 | else {
49 | _id = db.insert("books", null, values)
50 | }
51 | }
52 |
53 | inline fun edit(context: Context, block: Book.() -> R): R {
54 | return block(this).also { save(context) }
55 | }
56 |
57 | fun destroy(context: Context) {
58 | val db = DatabaseHelper.instance(context)
59 | db.delete("books", "_id=?", arrayOf(_id.toString()))
60 | }
61 |
62 | fun idTo(intent: Intent): Intent {
63 | return intent.apply { putExtra("_id", _id) }
64 | }
65 |
66 | companion object {
67 | inline fun edit(context: Context, id: Long, block: Book.() -> R): R {
68 | val book = find(context, id)
69 | return block(book).also { book.save(context) }
70 | }
71 |
72 | inline fun editOrNull(context: Context, id: Long, block: Book.() -> R?): R? {
73 | val book = findOrNull(context, id) ?: return null
74 | return block(book).also { book.save(context) }
75 | }
76 |
77 | @JvmStatic
78 | fun find(context: Context, id: Long): Book {
79 | val db = DatabaseHelper.instance(context)
80 | db.rawQuery("SELECT * FROM books WHERE _id=?", arrayOf(id.toString())).use {
81 | it.moveToFirst()
82 | return if (it.count > 0) Book(it) else throw NoSuchElementException("Book with id $id not found")
83 | }
84 | }
85 |
86 | fun findOrNull(context: Context, id: Long): Book? {
87 | return try {
88 | find(context, id)
89 | } catch(e: NoSuchElementException) {
90 | null
91 | }
92 | }
93 |
94 | @JvmStatic
95 | fun findByPathOrNull(context: Context, path: String): Book? {
96 | val db = DatabaseHelper.instance(context)
97 | db.rawQuery("SELECT * FROM books WHERE path=?", arrayOf(path)).use {
98 | it.moveToFirst()
99 | return if (it.count > 0) Book(it) else null
100 | }
101 | }
102 |
103 | fun idFrom(intent: Intent?): Long {
104 | return intent!!.getLongExtra("_id", -1).also {
105 | if(it == -1L) throw IllegalArgumentException("Intent missing extra _id of type long")
106 | }
107 | }
108 |
109 | @JvmStatic
110 | fun idTo(intent: Intent, id: Long): Intent {
111 | return intent.apply { putExtra("_id", id) }
112 | }
113 | }
114 | }
--------------------------------------------------------------------------------
/app/src/main/java/net/bloople/stories/IndexingActivity.kt:
--------------------------------------------------------------------------------
1 | package net.bloople.stories
2 |
3 | import android.Manifest
4 | import net.bloople.stories.DatabaseHelper.deleteDatabase
5 | import android.app.Activity
6 | import android.os.Bundle
7 | import android.content.pm.PackageManager
8 | import android.view.inputmethod.EditorInfo
9 | import android.content.Intent
10 | import android.content.SharedPreferences
11 | import android.os.Environment
12 | import android.view.KeyEvent
13 | import android.widget.Button
14 | import android.widget.EditText
15 | import android.widget.ProgressBar
16 | import android.widget.Toast
17 | import androidx.appcompat.app.AppCompatActivity
18 | import androidx.appcompat.widget.Toolbar
19 |
20 | class IndexingActivity : AppCompatActivity(), Indexable {
21 | private lateinit var progressBar: ProgressBar
22 | private lateinit var indexButton: Button
23 | private lateinit var indexRoot: String
24 | private var canAccessFiles = false
25 |
26 | override fun onCreate(savedInstanceState: Bundle?) {
27 | super.onCreate(savedInstanceState)
28 | setContentView(R.layout.activity_indexing)
29 |
30 | val toolbar = findViewById(R.id.toolbar)
31 | setSupportActionBar(toolbar)
32 |
33 | val permission = checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
34 | if(permission == PackageManager.PERMISSION_GRANTED) canAccessFiles = true
35 | else requestPermissions(PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE)
36 |
37 | progressBar = findViewById(R.id.indexing_progress)
38 | indexButton = findViewById(R.id.index_button)
39 | indexButton.setOnClickListener {
40 | indexButton.isEnabled = false
41 | if(canAccessFiles) {
42 | val indexer = IndexingTask(this@IndexingActivity,this@IndexingActivity)
43 | indexer.execute(indexRoot)
44 | }
45 | }
46 |
47 | val deleteIndexButton: Button = findViewById(R.id.delete_index_button)
48 | deleteIndexButton.setOnClickListener {
49 | deleteDatabase(this@IndexingActivity)
50 | Toast.makeText(this@IndexingActivity, "Index deleted.", Toast.LENGTH_SHORT).show()
51 | }
52 |
53 | loadPreferences()
54 |
55 | val indexDirectoryText: EditText = findViewById(R.id.index_directory)
56 | indexDirectoryText.setText(indexRoot)
57 | indexDirectoryText.setOnEditorActionListener { _, actionId, event ->
58 | if(event != null && event.keyCode == KeyEvent.KEYCODE_ENTER || actionId == EditorInfo.IME_ACTION_DONE) {
59 | indexRoot = indexDirectoryText.text.toString()
60 | savePreferences()
61 | }
62 | false
63 | }
64 | }
65 |
66 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
67 | super.onActivityResult(requestCode, resultCode, data)
68 | if(resultCode == RESULT_CANCELED) finish()
69 | }
70 |
71 | override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) {
72 | super.onRequestPermissionsResult(requestCode, permissions, grantResults)
73 | if(requestCode == REQUEST_EXTERNAL_STORAGE && grantResults.isNotEmpty()
74 | && grantResults[0] == PackageManager.PERMISSION_GRANTED) canAccessFiles = true
75 | }
76 |
77 | private fun preferences(): SharedPreferences {
78 | return applicationContext.getSharedPreferences("main", MODE_PRIVATE)
79 | }
80 |
81 | private fun loadPreferences() {
82 | val preferences = preferences()
83 | indexRoot = preferences.getString("index-root", Environment.getExternalStorageDirectory().absolutePath).toString()
84 | }
85 |
86 | private fun savePreferences() {
87 | val editor = preferences().edit()
88 | editor.putString("index-root", indexRoot)
89 | editor.apply()
90 | }
91 |
92 | override fun onIndexingProgress(progress: Int, max: Int) {
93 | progressBar.progress = progress
94 | progressBar.max = max
95 | }
96 |
97 | override fun onIndexingComplete(count: Int) {
98 | setResult(RESULT_OK)
99 | indexButton.isEnabled = true
100 | Toast.makeText(
101 | this@IndexingActivity, "Indexing complete, $count stories indexed.",
102 | Toast.LENGTH_LONG
103 | ).show()
104 | }
105 |
106 | companion object {
107 | // Storage Permissions
108 | private const val REQUEST_EXTERNAL_STORAGE = 1
109 | private val PERMISSIONS_STORAGE = arrayOf(
110 | Manifest.permission.READ_EXTERNAL_STORAGE,
111 | Manifest.permission.WRITE_EXTERNAL_STORAGE
112 | )
113 | }
114 | }
--------------------------------------------------------------------------------
/app/src/main/java/net/bloople/stories/CursorRecyclerAdapter.kt:
--------------------------------------------------------------------------------
1 | package net.bloople.stories
2 |
3 | import android.database.Cursor
4 | import androidx.recyclerview.widget.RecyclerView
5 |
6 | /*
7 | * The MIT License (MIT)
8 | *
9 | * Copyright (c) 2015 ARNAUD FRUGIER
10 | *
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy
12 | * of this software and associated documentation files (the "Software"), to deal
13 | * in the Software without restriction, including without limitation the rights
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | * copies of the Software, and to permit persons to whom the Software is
16 | * furnished to do so, subject to the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be included in all
19 | * copies or substantial portions of the Software.
20 | *
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 | * SOFTWARE.
28 | */
29 |
30 | abstract class CursorRecyclerAdapter(c: Cursor?) : RecyclerView.Adapter() {
31 | private var cursor: Cursor? = null
32 | private var mRowIDColumn = 0
33 |
34 | fun init(c: Cursor?) {
35 | cursor = c
36 | mRowIDColumn = c?.getColumnIndexOrThrow("_id") ?: -1
37 | setHasStableIds(true)
38 | }
39 |
40 | override fun onBindViewHolder(holder: VH, position: Int) {
41 | check(cursor != null) { "this should only be called when the cursor is valid" }
42 | check(cursor!!.moveToPosition(position)) { "couldn't move cursor to position $position" }
43 | onBindViewHolder(holder, cursor!!)
44 | }
45 |
46 | abstract fun onBindViewHolder(holder: VH, cursor: Cursor)
47 |
48 | override fun getItemCount(): Int {
49 | return cursor?.count ?: 0
50 | }
51 |
52 | override fun getItemId(position: Int): Long {
53 | return if(hasStableIds() && cursor != null) {
54 | if(cursor!!.moveToPosition(position)) {
55 | cursor!!.getLong(mRowIDColumn)
56 | }
57 | else {
58 | RecyclerView.NO_ID
59 | }
60 | }
61 | else {
62 | RecyclerView.NO_ID
63 | }
64 | }
65 |
66 | /**
67 | * Change the underlying cursor to a new cursor. If there is an existing cursor it will be
68 | * closed.
69 | *
70 | * @param cursor The new cursor to be used
71 | */
72 | fun changeCursor(cursor: Cursor?) {
73 | val old = swapCursor(cursor)
74 | old?.close()
75 | }
76 |
77 | /**
78 | * Swap in a new Cursor, returning the old Cursor. Unlike
79 | * [.changeCursor], the returned old Cursor is *not*
80 | * closed.
81 | *
82 | * @param newCursor The new cursor to be used.
83 | * @return Returns the previously set Cursor, or null if there wasa not one.
84 | * If the given new Cursor is the same instance is the previously set
85 | * Cursor, null is also returned.
86 | */
87 | fun swapCursor(newCursor: Cursor?): Cursor? {
88 | if(newCursor === cursor) {
89 | return null
90 | }
91 |
92 | val oldCursor = cursor
93 | val itemCount = itemCount
94 | cursor = newCursor
95 | if(newCursor != null) {
96 | mRowIDColumn = newCursor.getColumnIndexOrThrow("_id")
97 | // notify the observers about the new cursor
98 | notifyDataSetChanged()
99 | }
100 | else {
101 | mRowIDColumn = -1
102 | // notify the observers about the lack of a data set
103 | notifyItemRangeRemoved(0, itemCount)
104 | }
105 | return oldCursor
106 | }
107 |
108 | /**
109 | *
110 | * Converts the cursor into a CharSequence. Subclasses should override this
111 | * method to convert their results. The default implementation returns an
112 | * empty String for null values or the default String representation of
113 | * the value.
114 | *
115 | * @param cursor the cursor to convert to a CharSequence
116 | * @return a CharSequence representing the value
117 | */
118 | fun convertToString(cursor: Cursor?): CharSequence {
119 | return cursor?.toString() ?: ""
120 | }
121 |
122 | init {
123 | init(c)
124 | }
125 | }
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/net/bloople/stories/ReadingStoryActivity.kt:
--------------------------------------------------------------------------------
1 | package net.bloople.stories
2 |
3 | import android.app.Activity
4 | import androidx.recyclerview.widget.RecyclerView
5 | import androidx.recyclerview.widget.LinearLayoutManager
6 | import io.noties.markwon.Markwon
7 | import androidx.drawerlayout.widget.DrawerLayout
8 | import android.os.Bundle
9 | import android.os.AsyncTask
10 | import org.commonmark.node.Node
11 | import java.io.BufferedReader
12 | import java.io.FileReader
13 | import java.io.IOException
14 | import java.util.ArrayList
15 |
16 | class ReadingStoryActivity : Activity() {
17 | private lateinit var layoutManager: LinearLayoutManager
18 | private lateinit var markwon: Markwon
19 | private lateinit var adapter: NodesAdapter
20 | private lateinit var drawer: DrawerLayout
21 | private lateinit var outlineAdapter: OutlineAdapter
22 | private var bookId: Long = -1
23 | private var savedReadPosition = 0
24 |
25 | override fun onCreate(savedInstanceState: Bundle?) {
26 | super.onCreate(savedInstanceState)
27 | setContentView(R.layout.activity_reading_story)
28 |
29 | val nodesView: RecyclerView = findViewById(R.id.nodes_view)
30 | nodesView.itemAnimator = null
31 |
32 | layoutManager = LinearLayoutManager(this)
33 | nodesView.layoutManager = layoutManager
34 |
35 | markwon = NodesHelper.buildMarkwon(nodesView)
36 | adapter = NodesAdapter(markwon)
37 | nodesView.adapter = adapter
38 | nodesView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
39 | override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
40 | super.onScrollStateChanged(recyclerView, newState)
41 | if(newState == RecyclerView.SCROLL_STATE_IDLE) savePosition()
42 | }
43 | })
44 |
45 | val sidebar: RecyclerView = findViewById(R.id.sidebar)
46 | val sidebarLayoutManager = LinearLayoutManager(this)
47 | sidebar.layoutManager = sidebarLayoutManager
48 |
49 | outlineAdapter = OutlineAdapter(markwon)
50 | sidebar.adapter = outlineAdapter
51 |
52 | drawer = findViewById(R.id.drawer_layout)
53 |
54 | bookId = Book.idFrom(intent)
55 |
56 | val book = Book.find(this, bookId)
57 | book.edit(this) {
58 | lastOpenedAt = System.currentTimeMillis()
59 | openedCount += 1
60 | }
61 |
62 | val parser = ParseStoryTask()
63 | parser.execute(book)
64 | }
65 |
66 | override fun onStop() {
67 | super.onStop()
68 | Book.edit(this, bookId) { lastOpenedAt = System.currentTimeMillis() }
69 | savePosition()
70 | }
71 |
72 | override fun onBackPressed() {
73 | super.onBackPressed()
74 | finish()
75 | }
76 |
77 | fun savePosition() {
78 | val currentReadPosition = layoutManager.findFirstVisibleItemPosition()
79 | if(savedReadPosition != currentReadPosition) {
80 | Book.edit(this, bookId) { lastReadPosition = currentReadPosition }
81 | savedReadPosition = currentReadPosition
82 | }
83 | }
84 |
85 | fun scrollToPosition(position: Int) {
86 | layoutManager.scrollToPositionWithOffset(position, 0)
87 | }
88 |
89 | fun closeDrawers() {
90 | drawer.closeDrawers()
91 | }
92 |
93 | private inner class ParseStoryTask : AsyncTask?, Void?>() {
94 | var BATCH_SIZE = 50
95 | private var setPosition = false
96 |
97 | override fun doInBackground(vararg bookArgs: Book?): Void? {
98 | val book = bookArgs[0]
99 | try {
100 | val parser = StoryParser(BufferedReader(FileReader(book!!.path)))
101 | var accumulator: MutableList = ArrayList()
102 |
103 | while(parser.hasNext()) {
104 | val node = markwon.parse(parser.next())
105 | if(node.firstChild == null) continue
106 |
107 | accumulator.add(node)
108 |
109 | if(accumulator.size >= BATCH_SIZE) {
110 | publishProgress(accumulator)
111 | accumulator = ArrayList()
112 | }
113 | }
114 |
115 | publishProgress(accumulator)
116 | }
117 | catch(e: IOException) {
118 | e.printStackTrace()
119 | }
120 | return null
121 | }
122 |
123 | override fun onProgressUpdate(vararg nodesArgs: List?) {
124 | val countBefore = adapter.itemCount
125 |
126 | adapter.addAll(nodesArgs[0]!!)
127 |
128 | val outlineNodes: MutableList = ArrayList()
129 | val outlineNodesMap: MutableList = ArrayList()
130 |
131 | for(i in nodesArgs[0]!!.indices) {
132 | val node = nodesArgs[0]!![i]
133 | val heading = NodesHelper.findFirstHeading(node)
134 | if(heading != null) {
135 | outlineNodes.add(heading)
136 | outlineNodesMap.add(countBefore + i)
137 | }
138 | }
139 |
140 | outlineAdapter.addAll(outlineNodes, outlineNodesMap)
141 |
142 | val lastReadPosition = Book.find(this@ReadingStoryActivity, bookId).lastReadPosition
143 | if(!setPosition && adapter.itemCount >= lastReadPosition) {
144 | setPosition = true
145 | savedReadPosition = lastReadPosition
146 | scrollToPosition(lastReadPosition)
147 | }
148 | }
149 |
150 | override fun onPostExecute(result: Void?) {}
151 | }
152 | }
--------------------------------------------------------------------------------
/app/src/main/java/net/bloople/stories/BooksActivity.kt:
--------------------------------------------------------------------------------
1 | package net.bloople.stories
2 |
3 | import androidx.appcompat.app.AppCompatActivity
4 | import androidx.recyclerview.widget.RecyclerView
5 | import androidx.recyclerview.widget.LinearLayoutManager
6 | import android.widget.TextView
7 | import android.os.Bundle
8 | import androidx.lifecycle.ViewModelProvider
9 | import android.view.inputmethod.EditorInfo
10 | import android.content.Intent
11 | import android.database.Cursor
12 | import android.view.KeyEvent
13 | import android.view.Menu
14 | import android.view.MenuItem
15 | import android.view.MotionEvent
16 | import android.view.View
17 | import android.view.inputmethod.InputMethodManager
18 | import android.widget.EditText
19 | import androidx.appcompat.widget.Toolbar
20 | import androidx.core.view.MenuCompat
21 |
22 | class BooksActivity : AppCompatActivity() {
23 | private lateinit var model: IndexViewModel
24 |
25 | override fun onCreate(savedInstanceState: Bundle?) {
26 | super.onCreate(savedInstanceState)
27 | setContentView(R.layout.activity_books)
28 |
29 | model = ViewModelProvider(this).get(IndexViewModel::class.java)
30 |
31 | val toolbar = findViewById(R.id.toolbar)
32 | setSupportActionBar(toolbar)
33 |
34 | val searchResultsToolbar: TextView = findViewById(R.id.search_results_toolbar)
35 |
36 | model.sorterDescription.observe(this, { description: String -> searchResultsToolbar.text = description })
37 |
38 | val searchField: EditText = findViewById(R.id.searchText)
39 | searchField.setOnEditorActionListener { v: TextView, actionId: Int, _: KeyEvent? ->
40 | var handled = false
41 | if(actionId == EditorInfo.IME_ACTION_SEARCH) {
42 | val `in` = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
43 | `in`.hideSoftInputFromWindow(searchField.windowToken, 0)
44 | searchField.clearFocus()
45 |
46 | model.setSearchText(v.text.toString())
47 |
48 | handled = true
49 | }
50 | handled
51 | }
52 |
53 | searchField.setOnTouchListener { _: View?, event: MotionEvent ->
54 | val DRAWABLE_RIGHT = 2
55 | if(event.action == MotionEvent.ACTION_UP) {
56 | val clickIndex = searchField.right - searchField.compoundDrawables[DRAWABLE_RIGHT].bounds.width()
57 | if(event.rawX >= clickIndex) {
58 | searchField.setText("")
59 | searchField.clearFocus()
60 | model.setSearchText("")
61 | return@setOnTouchListener true
62 | }
63 | }
64 | false
65 | }
66 |
67 | val listView: RecyclerView = findViewById(R.id.stories_list)
68 | val adapter = BooksAdapter(null)
69 | listView.adapter = adapter
70 |
71 | val layoutManager = LinearLayoutManager(this)
72 | listView.layoutManager = layoutManager
73 |
74 | model.searchResults.observe(this, { searchResults: Cursor -> adapter.swapCursor(searchResults) })
75 | }
76 |
77 | override fun onRestoreInstanceState(savedInstanceState: Bundle) {
78 | super.onRestoreInstanceState(savedInstanceState)
79 | model.setSort(savedInstanceState.getInt("sortMethod"), savedInstanceState.getBoolean("sortDirectionAsc"))
80 | }
81 |
82 | public override fun onSaveInstanceState(savedInstanceState: Bundle) {
83 | savedInstanceState.putInt("sortMethod", model.sortMethod)
84 | savedInstanceState.putBoolean("sortDirectionAsc", model.sortDirectionAsc)
85 | super.onSaveInstanceState(savedInstanceState)
86 | }
87 |
88 | override fun onCreateOptionsMenu(menu: Menu): Boolean {
89 | super.onCreateOptionsMenu(menu)
90 | val inflater = menuInflater
91 | inflater.inflate(R.menu.list_menu, menu)
92 | MenuCompat.setGroupDividerEnabled(menu, true)
93 | return true
94 | }
95 |
96 | override fun onOptionsItemSelected(menuItem: MenuItem): Boolean {
97 | val sortMethod = model.sortMethod
98 | var newSortMethod = sortMethod
99 |
100 | when(menuItem.itemId) {
101 | R.id.sort_alphabetic -> {
102 | newSortMethod = BooksSearcher.SORT_ALPHABETIC
103 | }
104 | R.id.sort_age -> {
105 | newSortMethod = BooksSearcher.SORT_AGE
106 | }
107 | R.id.sort_size -> {
108 | newSortMethod = BooksSearcher.SORT_SIZE
109 | }
110 | R.id.sort_last_opened -> {
111 | newSortMethod = BooksSearcher.SORT_LAST_OPENED
112 | }
113 | R.id.sort_starred -> {
114 | newSortMethod = BooksSearcher.SORT_STARRED
115 | }
116 | R.id.sort_opened_count -> {
117 | newSortMethod = BooksSearcher.SORT_OPENED_COUNT
118 | }
119 | R.id.manage_indexing -> {
120 | val intent = Intent(this@BooksActivity, IndexingActivity::class.java)
121 | startActivityForResult(intent, REQUEST_CODE_INDEXING)
122 | return true
123 | }
124 | }
125 |
126 | var sortDirectionAsc = model.sortDirectionAsc
127 | if(sortMethod == newSortMethod) sortDirectionAsc = !sortDirectionAsc
128 | model.setSort(newSortMethod, sortDirectionAsc)
129 |
130 | return true
131 | }
132 |
133 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
134 | super.onActivityResult(requestCode, resultCode, data)
135 | if(requestCode == REQUEST_CODE_INDEXING && resultCode == RESULT_OK) {
136 | model.refresh()
137 | }
138 | }
139 |
140 | companion object {
141 | private const val REQUEST_CODE_INDEXING = 0
142 | }
143 | }
--------------------------------------------------------------------------------