Skip to content

Commit

Permalink
image support, link colors, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
fennifith committed Jun 3, 2019
1 parent e1dfb27 commit dcc2507
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 15 deletions.
1 change: 1 addition & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dependencies {
implementation "androidx.constraintlayout:constraintlayout:$deps.android.constraintlayout"
implementation "ru.noties.markwon:core:$deps.markwon"
implementation "ru.noties.markwon:html:$deps.markwon"
implementation "ru.noties.markwon:image-okhttp:$deps.markwon"

api project(path: ':api')
}
Expand Down
1 change: 1 addition & 0 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="dev.doubledot.doki">
<uses-permission android:name="android.permission.INTERNET" />
<application>
<activity
android:name="dev.doubledot.doki.ui.DokiActivity"
Expand Down
15 changes: 11 additions & 4 deletions library/src/main/java/dev/doubledot/doki/views/DokiContentView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class DokiContentView @JvmOverloads constructor(
private val contentDeveloperSolutionHeader : TextView? by bind(R.id.contentDeveloperSolutionHeader)
private val contentDeveloperSolution : DokiHtmlTextView? by bind(R.id.contentDeveloperSolution)

private val contentAttribution : TextView? by bind(R.id.contentAttribution)
private val contentAttribution : DokiHtmlTextView? by bind(R.id.contentAttribution)

private val buttonContainer: View? by bind(R.id.buttonContainer)
private val closeBtn: TextView? by bind(R.id.buttonClose)
Expand Down Expand Up @@ -94,13 +94,18 @@ class DokiContentView @JvmOverloads constructor(
contentExplanation?.setTextColor(value)
contentSolution?.setTextColor(value)
contentDeveloperSolution?.setTextColor(value)
contentAttribution?.setTextColor(value)

field = value
}

var buttonsTextColor: Int = context.extractColor(intArrayOf(R.attr.colorAccent))
set(value) {
closeBtn?.setTextColor(value)
contentExplanation?.linkHighlightColor = value
contentSolution?.linkHighlightColor = value
contentDeveloperSolution?.linkHighlightColor = value
contentAttribution?.linkHighlightColor = value
field = value
}

Expand Down Expand Up @@ -212,16 +217,16 @@ class DokiContentView @JvmOverloads constructor(
manufacturerRating?.visibleIf(value.award > 0)
manufacturerRatingHeader?.visibleIf(value.award > 0)

contentExplanation?.setHtmlText(value.explanation)
contentSolution?.setHtmlText(value.user_solution)
contentExplanation?.htmlText = value.explanation
contentSolution?.htmlText = value.user_solution

if (value.dev_solution.isNullOrEmpty()) {
contentDeveloperSolutionHeader?.visibility = GONE
contentDeveloperSolution?.visibility = GONE
} else {
contentDeveloperSolutionHeader?.visibility = VISIBLE
contentDeveloperSolution?.visibility = VISIBLE
contentDeveloperSolution?.setHtmlText(value.dev_solution)
contentDeveloperSolution?.htmlText = value.dev_solution
}

contentLoadingView?.gone()
Expand All @@ -233,6 +238,8 @@ class DokiContentView @JvmOverloads constructor(
inflater.inflate(R.layout.doki_view_content, this, true)
rootBackgroundColor = Color.WHITE

contentAttribution?.htmlText = context.getString(R.string.doki_content_attribution)

initFromAttrs(attrs)
device = Device()
}
Expand Down
25 changes: 19 additions & 6 deletions library/src/main/java/dev/doubledot/doki/views/DokiHtmlTextView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import ru.noties.markwon.html.HtmlPlugin
import ru.noties.markwon.html.HtmlTag
import ru.noties.markwon.html.MarkwonHtmlRenderer
import ru.noties.markwon.html.tag.SimpleTagHandler
import ru.noties.markwon.image.ImagesPlugin
import ru.noties.markwon.image.okhttp.OkHttpImagesPlugin
import kotlin.math.roundToInt


Expand All @@ -25,6 +27,8 @@ class DokiHtmlTextView @JvmOverloads constructor(
) : AppCompatTextView(context, attrs, defStyle) {

private val markwon = Markwon.builder(context)
.usePlugin(ImagesPlugin.create(context))
.usePlugin(OkHttpImagesPlugin.create())
.usePlugin(HtmlPlugin.create())
.usePlugin(object: AbstractMarkwonPlugin() {
override fun configureHtmlRenderer(builder: MarkwonHtmlRenderer.Builder) {
Expand All @@ -37,6 +41,7 @@ class DokiHtmlTextView @JvmOverloads constructor(

override fun configureTheme(builder: MarkwonTheme.Builder) {
builder.headingBreakHeight(0)
.linkColor(linkHighlightColor)
.blockMargin(24f.dpToPx.roundToInt())
.blockQuoteWidth(4f.dpToPx.roundToInt())
.codeBackgroundColor(0x00FFFFFF)
Expand All @@ -45,14 +50,22 @@ class DokiHtmlTextView @JvmOverloads constructor(
})
.build()

init {
movementMethod = LinkMovementMethod.getInstance()
}
var htmlText : String? = null
set(value) {
value?.let {
markwon.setMarkdown(this, value)
}
field = value
}

fun setHtmlText(text: String?) {
text?.let {
markwon.setMarkdown(this, it)
var linkHighlightColor : Int = 0
set(value) {
field = value
htmlText = htmlText
}

init {
movementMethod = LinkMovementMethod.getInstance()
}

}
3 changes: 1 addition & 2 deletions library/src/main/res/layout/doki_view_content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,13 @@
style="@style/Doki.Custom.Body"
tools:text="Solution solution solution solution solution solution solution solution solution solution."/>

<TextView
<dev.doubledot.doki.views.DokiHtmlTextView
android:id="@+id/contentAttribution"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/doki_content_attribution"
android:layout_marginTop="@dimen/twelve_dp"
android:layout_marginBottom="@dimen/twelve_dp"
android:linksClickable="true"
style="@style/Doki.Custom.Subtext"/>

</LinearLayout>
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
<string name="doki_solution">Solution</string>
<string name="doki_dev_solution">Developer Solution</string>

<string name="doki_content_attribution">Content from <a href="https://dontkillmyapp.com/">dontkillmyapp.com</a>, published under the <a href="https://raw.githubusercontent.com/urbandroid-team/dont-kill-my-app/master/LICENCE">Creative Commons Attribution 4.0</a>.</string>
<string name="doki_content_attribution"><![CDATA[Content from <a href="https://dontkillmyapp.com/">dontkillmyapp.com</a>, published under the <a href="https://raw.githubusercontent.com/urbandroid-team/dont-kill-my-app/master/LICENCE">Creative Commons Attribution 4.0</a>.]]></string>
</resources>
3 changes: 1 addition & 2 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
</intent-filter>
</activity>

<activity android:name=".DokiActivity"/>

<activity
android:name=".DokiThemedActivity"
android:theme="@style/DefaultDokiTheme"/>

<activity
android:name=".DokiCustomizedActivity"
android:theme="@style/DokiCustomTheme"/>

</application>
</manifest>

0 comments on commit dcc2507

Please sign in to comment.