Skip to content

Commit

Permalink
refactoring into more submodules
Browse files Browse the repository at this point in the history
removed default syntax highlighter
  • Loading branch information
markusressel committed Aug 26, 2018
1 parent fc99926 commit 6242970
Show file tree
Hide file tree
Showing 37 changed files with 331 additions and 238 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ android {

dependencies {
implementation project(':library')
implementation project(':markdown')

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/de/markusressel/kodeeditor/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package de.markusressel.kodeeditor
import android.os.AsyncTask
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import de.markusressel.kodeeditor.library.markdown.MarkdownSyntaxHighlighter
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
Expand All @@ -12,11 +13,14 @@ class MainActivity : AppCompatActivity() {
.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

codeEditorView
.setSyntaxHighlighter(MarkdownSyntaxHighlighter())
codeEditorView
.setText("# Topic 1\n" + "\n" + "This is a *simple* demo text written in **Markdown**")

doAsync {
Thread.sleep(5000)
Thread
.sleep(5000)
runOnUiThread {
codeEditorView
.setText("# Topic 1\n" + "\n" + "This is a *simple* demo text written in **Markdown**\n\n\nTEST\n" + "\n" + "\n" + "TEST\n" + "\n" + "\n" + "TEST")
Expand Down
2 changes: 2 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ android {
}

dependencies {
api project(':syntaxhighlighter')

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// api 'org.jetbrains.kotlinx:kotlinx-coroutines-android:0.25.0'

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.util.Log
import com.jakewharton.rxbinding2.widget.RxTextView
import com.trello.rxlifecycle2.kotlin.bindToLifecycle
import de.markusressel.kodeeditor.library.syntaxhighlighter.SyntaxHighlighter
import de.markusressel.kodeeditor.library.syntaxhighlighter.markdown.MarkdownSyntaxHighlighter
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.rxkotlin.subscribeBy
Expand All @@ -16,7 +15,13 @@ import java.util.concurrent.TimeUnit

class CodeEditText : AppCompatEditText {

var syntaxHighlighter: SyntaxHighlighter = MarkdownSyntaxHighlighter()
var syntaxHighlighter: SyntaxHighlighter? = null
set(value) {
field = value
initSyntaxHighlighter()
}


private var highlightingTimeout = 50L to TimeUnit.MILLISECONDS

private var highlightingDisposable: Disposable? = null
Expand All @@ -34,22 +39,28 @@ class CodeEditText : AppCompatEditText {
}

private fun reinit() {
initSyntaxHighlighter()
}

private fun initSyntaxHighlighter() {
highlightingDisposable
?.dispose()

highlightingDisposable = RxTextView
.afterTextChangeEvents(this)
.debounce(highlightingTimeout.first, highlightingTimeout.second)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.bindToLifecycle(this)
.subscribeBy(onNext = {
// syntax highlighting
refreshSyntaxHighlighting()
}, onError = {
Log
.e(TAG, "Error while refreshing syntax highlighting", it)
})
if (syntaxHighlighter != null) {
highlightingDisposable = RxTextView
.afterTextChangeEvents(this)
.debounce(highlightingTimeout.first, highlightingTimeout.second)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.bindToLifecycle(this)
.subscribeBy(onNext = {
// syntax highlighting
refreshSyntaxHighlighting()
}, onError = {
Log
.e(TAG, "Error while refreshing syntax highlighting", it)
})
}
}

/**
Expand All @@ -76,8 +87,16 @@ class CodeEditText : AppCompatEditText {

@Synchronized
fun refreshSyntaxHighlighting() {
if (syntaxHighlighter == null) {
Log
.w(TAG, "No syntax highlighter is set!")
}

syntaxHighlighter
.highlight(text)
?.let {
it
.highlight(text)
}
}

companion object {
Expand Down
1 change: 1 addition & 0 deletions markdown/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
39 changes: 39 additions & 0 deletions markdown/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 28



defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
implementation project(':syntaxhighlighter')

implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
mavenCentral()
}
Loading

0 comments on commit 6242970

Please sign in to comment.