Skip to content

Commit

Permalink
Merge pull request #9 from urakalee/origin
Browse files Browse the repository at this point in the history
支持 kotlin, 使用 DayOne 模式的标签操作
  • Loading branch information
Shouheng88 authored Jul 29, 2018
2 parents 6a06e7f + 206fb8f commit 3cbf06c
Show file tree
Hide file tree
Showing 24 changed files with 566 additions and 73 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.iml
42 changes: 31 additions & 11 deletions client/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'io.fabric'

android {
Expand Down Expand Up @@ -35,6 +38,14 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
// ref: https://youtrack.jetbrains.com/issue/KT-4779 & https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/-jvm-default/index.html
// ref: https://stackoverflow.com/questions/44141076/compilekotlin-block-in-build-gradle-file-throws-error-could-not-find-method-com
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = '1.8'
freeCompilerArgs = ["-Xenable-jvm-default", "-Xjvm-default=enable"] // enable-jvm-default is only for avoid IDE warning
}
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
Expand All @@ -58,8 +69,10 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
kapt "com.android.databinding:compiler:$androidPluginVersion"
implementation "com.android.support:support-v4:$supportLibVersion"
implementation "com.android.support:design:$supportLibVersion"
implementation "com.android.support:cardview-v7:$supportLibVersion"
Expand All @@ -70,17 +83,21 @@ dependencies {
implementation "com.android.support:customtabs:$supportLibVersion"
implementation "android.arch.lifecycle:runtime:$archVersion"
implementation "android.arch.lifecycle:extensions:$archVersion"
annotationProcessor "android.arch.lifecycle:compiler:$archVersion"
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.github.bumptech.glide:glide:3.7.0'
kapt "android.arch.lifecycle:compiler:$archVersion"
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.github.bumptech.glide:glide:3.8.0'
implementation 'commons-io:commons-io:2.5'
implementation 'com.larswerkman:HoloColorPicker:1.5'
implementation 'org.ocpsoft.prettytime:prettytime:4.0.1.Final'
implementation 'com.github.flavienlaurent.datetimepicker:library:0.0.2'
implementation 'com.github.clans:fab:1.6.4'
implementation 'com.balysv.materialmenu:material-menu:2.0.0'
implementation 'com.afollestad.material-dialogs:core:0.9.4.5'
implementation 'com.afollestad.material-dialogs:commons:0.9.4.5'
implementation('com.afollestad.material-dialogs:core:0.9.4.5') {
exclude group: 'com.android.support', module: 'support-v13'
}
implementation('com.afollestad.material-dialogs:commons:0.9.4.5') {
exclude group: 'com.android.support', module: 'support-v13'
}
implementation 'com.koushikdutta.ion:ion:2.1.7'
implementation 'com.github.oxoooo:pull-back-layout:1.0.1'
implementation 'com.squareup.okhttp3:okhttp:3.8.0'
Expand All @@ -92,9 +109,12 @@ dependencies {
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30'
implementation 'com.github.lecho:hellocharts-android:v1.5.8'
implementation 'com.andrognito.pinlockview:pinlockview:2.1.0'
compile('com.crashlytics.sdk.android:crashlytics:2.8.0@aar') {
implementation('com.crashlytics.sdk.android:crashlytics:2.9.4@aar') {
transitive = true
}
implementation('com.crashlytics.sdk.android:answers:1.4.2@aar') {
transitive = true;
}
implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'joda-time:joda-time:2.9.9'
implementation 'com.github.Kennyc1012:BottomSheet:2.4.0'
Expand All @@ -107,8 +127,8 @@ dependencies {
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
implementation 'top.zibin:Luban:1.1.3'
compile project(path: ':colorful')
compile project(path: ':photoview')
compile project(path: ':markdown')
implementation project(path: ':colorful')
implementation project(path: ':photoview')
implementation project(path: ':markdown')
implementation files('libs/BaiduLBS_Android.jar')
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,26 @@ public class UserPreferences extends BasePreferences {
defaultFabOrders.add(FabSortItem.FILE);

defaultMarkdownFormats = new LinkedList<>();
defaultMarkdownFormats.add(MarkdownFormat.ITALIC);
defaultMarkdownFormats.add(MarkdownFormat.BOLD);
defaultMarkdownFormats.add(MarkdownFormat.QUOTE);
defaultMarkdownFormats.add(MarkdownFormat.CODE_BLOCK);
defaultMarkdownFormats.add(MarkdownFormat.STRIKE);
defaultMarkdownFormats.add(MarkdownFormat.HORIZONTAL_LINE);
defaultMarkdownFormats.add(MarkdownFormat.H1);
defaultMarkdownFormats.add(MarkdownFormat.H2);
defaultMarkdownFormats.add(MarkdownFormat.H3);
defaultMarkdownFormats.add(MarkdownFormat.H4);
defaultMarkdownFormats.add(MarkdownFormat.H5);
defaultMarkdownFormats.add(MarkdownFormat.H6);
defaultMarkdownFormats.add(MarkdownFormat.XML);
defaultMarkdownFormats.add(MarkdownFormat.NUMBER_LIST);

defaultMarkdownFormats.add(MarkdownFormat.NORMAL_LIST);
defaultMarkdownFormats.add(MarkdownFormat.MARK);
// defaultMarkdownFormats.add(MarkdownFormat.NUMBER_LIST);
// defaultMarkdownFormats.add(MarkdownFormat.CHECKBOX_OUTLINE);
defaultMarkdownFormats.add(MarkdownFormat.CHECKBOX);
defaultMarkdownFormats.add(MarkdownFormat.CHECKBOX_OUTLINE);

defaultMarkdownFormats.add(MarkdownFormat.INDENT);
defaultMarkdownFormats.add(MarkdownFormat.DEDENT);
defaultMarkdownFormats.add(MarkdownFormat.QUOTE);
defaultMarkdownFormats.add(MarkdownFormat.XML);
defaultMarkdownFormats.add(MarkdownFormat.CODE_BLOCK);

defaultMarkdownFormats.add(MarkdownFormat.STRIKE);
defaultMarkdownFormats.add(MarkdownFormat.HORIZONTAL_LINE);

defaultMarkdownFormats.add(MarkdownFormat.ITALIC);
defaultMarkdownFormats.add(MarkdownFormat.BOLD);
defaultMarkdownFormats.add(MarkdownFormat.MARK); // not standard markdown

defaultMarkdownFormats.add(MarkdownFormat.MATH_JAX);
defaultMarkdownFormats.add(MarkdownFormat.SUB_SCRIPT);
defaultMarkdownFormats.add(MarkdownFormat.SUPER_SCRIPT);
Expand Down
11 changes: 6 additions & 5 deletions client/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "com.android.tools.build:gradle:${project.androidPluginVersion}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${project.kotlinVersion}"
classpath 'io.fabric.tools:gradle:1.25.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -22,7 +23,7 @@ allprojects {
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com/"}
maven { url "https://maven.google.com/" }
}
}

Expand All @@ -32,8 +33,8 @@ ext {
targetSdkVersion = compileSdkVersion
minSdkVersion = 17

supportLibVersion = '27.0.2'
archVersion = '1.0.0'
supportLibVersion = '27.1.1'
archVersion = '1.1.1'
}

task clean(type: Delete) {
Expand Down
4 changes: 4 additions & 0 deletions client/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-Xjvm-default=enable

androidPluginVersion=3.0.1
kotlinVersion=1.2.50
Empty file modified client/gradlew
100644 → 100755
Empty file.
6 changes: 5 additions & 1 deletion markdown/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.github.dcendents.android-maven'

android {
Expand All @@ -24,10 +27,11 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
implementation "com.android.support:appcompat-v7:$supportLibVersion"
implementation "com.android.support:design:$supportLibVersion"
testImplementation 'junit:junit:4.12'
Expand Down
57 changes: 57 additions & 0 deletions markdown/src/main/java/me/urakalee/markdown/Indent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package me.urakalee.markdown

/**
* @author Uraka.Lee
*/
class Indent constructor(c: String?) {

var indent: Boolean = !c.isNullOrEmpty()
private set
var content: String = c ?: ""
private set
val length: Int
get() = content.length
private val equivalentLength: Int
get() {
var l = 0
for (c in content) {
if (c == ' ') {
l += 1
} else if (c == '\t') {
val rem = l.rem(TAB_SIZE)
l += TAB_SIZE - rem
}

}
return l
}
var level: Int = 0

fun indent(): Indent {
var l = equivalentLength
val rem = l.rem(TAB_SIZE)
l += TAB_SIZE - rem
content = " ".repeat(l)
indent = true
return this
}

fun dedent(): Indent {
if (!indent) return this
var l = equivalentLength
val rem = l.rem(TAB_SIZE)
l -= if (rem == 0) {
TAB_SIZE
} else {
rem
}
content = " ".repeat(l)
indent = content.isNotEmpty()
return this
}

companion object {

val TAB_SIZE = 4
}
}
32 changes: 32 additions & 0 deletions markdown/src/main/java/me/urakalee/markdown/Mark.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package me.urakalee.markdown

import me.urakalee.markdown.handler.*

/**
* @author Uraka.Lee
*/
enum class Mark(val pattern: Regex, val defaultMark: String, val handler: MarkHandler) {

NONE(Regex(""), "", NoneHandler),
H(Regex("#+"), "#", HeaderHandler),
LI(Regex("[-*]"), "-", ListHandler),
LO(Regex("\\d\\."), "1.", ListHandler),
LA(Regex("[a-z]\\."), "a.", ListHandler),
TD(Regex("- \\[[x ]]", RegexOption.IGNORE_CASE), "- [ ]", TodoHandler),
QT(Regex(">"), ">", QuoteHandler);

companion object {

private fun fromString(s: String): Mark {
return values().firstOrNull {
s.matches(it.pattern)
} ?: NONE
}

fun handle(inputMark: Mark, source: String): String {
return Mark.fromString(source).let {
it.handler.handleMark(inputMark, source, it)
}
}
}
}
52 changes: 52 additions & 0 deletions markdown/src/main/java/me/urakalee/markdown/MarkHandler.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package me.urakalee.markdown

/**
* @author Uraka.Lee
*/
interface MarkHandler {

/**
* @return targetMark on input [Mark.H]
*/
fun handleHeader(inputMark: Mark, source: String, sourceMark: Mark): String {
return defaultMark(inputMark)
}

/**
* @return targetMark on input [Mark.LI]
*/
fun handleList(inputMark: Mark, source: String, sourceMark: Mark): String {
return defaultMark(inputMark)
}

/**
* @return targetMark on input [Mark.TD]
*/
fun handleTodo(inputMark: Mark, source: String, sourceMark: Mark): String {
return defaultMark(inputMark)
}

/**
* @return targetMark on input [Mark.QT]
*/
fun handleQuote(inputMark: Mark, source: String, sourceMark: Mark): String {
return defaultMark(inputMark)
}

private fun defaultMark(mark: Mark): String {
return mark.defaultMark
}

/**
* @return targetMark
*/
fun handleMark(inputMark: Mark, source: String, sourceMark: Mark): String {
return when (inputMark) {
Mark.H -> handleHeader(inputMark, source, sourceMark)
Mark.LI -> handleList(inputMark, source, sourceMark)
Mark.TD -> handleTodo(inputMark, source, sourceMark)
Mark.QT -> handleQuote(inputMark, source, sourceMark)
else -> source
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package me.urakalee.markdown.handler

import me.urakalee.markdown.Mark
import me.urakalee.markdown.MarkHandler

/**
* @author Uraka.Lee
*/
object HeaderHandler : MarkHandler {

override fun handleHeader(inputMark: Mark, source: String, sourceMark: Mark): String {
return if (source.length < 6) "$source${Mark.H.defaultMark}" else Mark.H.defaultMark
}
}
27 changes: 27 additions & 0 deletions markdown/src/main/java/me/urakalee/markdown/handler/ListHandler.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package me.urakalee.markdown.handler

import me.urakalee.markdown.Mark
import me.urakalee.markdown.MarkHandler

/**
* @author Uraka.Lee
*/
object ListHandler : MarkHandler {

override fun handleList(inputMark: Mark, source: String, sourceMark: Mark): String {
return when (sourceMark) {
Mark.LI -> {
Mark.LO.defaultMark
}
Mark.LO -> {
Mark.LA.defaultMark
}
Mark.LA -> {
Mark.LI.defaultMark
}
else -> {
super.handleList(inputMark, source, sourceMark)
}
}
}
}
Loading

0 comments on commit 3cbf06c

Please sign in to comment.