Skip to content
This repository has been archived by the owner on Sep 3, 2023. It is now read-only.

Commit

Permalink
3.0.0-alpha4
Browse files Browse the repository at this point in the history
  • Loading branch information
afollestad committed May 19, 2019
1 parent a9e2fc5 commit 4e3b3ec
Show file tree
Hide file tree
Showing 19 changed files with 228 additions and 50 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ core and normal-use functionality.
```gradle
dependencies {
...
implementation 'com.afollestad.material-dialogs:core:3.0.0-alpha3'
implementation 'com.afollestad.material-dialogs:core:3.0.0-alpha4'
}
```

Expand All @@ -46,7 +46,7 @@ The `input` module contains extensions to the core module, such as a text input
```gradle
dependencies {
...
implementation 'com.afollestad.material-dialogs:input:3.0.0-alpha3'
implementation 'com.afollestad.material-dialogs:input:3.0.0-alpha4'
}
```

Expand All @@ -63,7 +63,7 @@ The `files` module contains extensions to the core module, such as a file and fo
```gradle
dependencies {
...
implementation 'com.afollestad.material-dialogs:files:3.0.0-alpha3'
implementation 'com.afollestad.material-dialogs:files:3.0.0-alpha4'
}
```

Expand All @@ -80,7 +80,7 @@ The `color` module contains extensions to the core module, such as a color choos
```gradle
dependencies {
...
implementation 'com.afollestad.material-dialogs:color:3.0.0-alpha3'
implementation 'com.afollestad.material-dialogs:color:3.0.0-alpha4'
}
```

Expand All @@ -97,7 +97,7 @@ The `datetime` module contains extensions to make date, time, and date-time pick
```gradle
dependencies {
...
implementation 'com.afollestad.material-dialogs:datetime:3.0.0-alpha3'
implementation 'com.afollestad.material-dialogs:datetime:3.0.0-alpha4'
}
```

Expand All @@ -116,7 +116,7 @@ too!
```gradle
dependencies {
...
implementation 'com.afollestad.material-dialogs:bottomsheets:3.0.0-alpha3'
implementation 'com.afollestad.material-dialogs:bottomsheets:3.0.0-alpha4'
}
```

Expand All @@ -131,6 +131,6 @@ The `lifecycle` module contains extensions to make dialogs work with AndroidX li
```gradle
dependencies {
...
implementation 'com.afollestad.material-dialogs:lifecycle:3.0.0-alpha3'
implementation 'com.afollestad.material-dialogs:lifecycle:3.0.0-alpha4'
}
```
20 changes: 19 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
3.0.0-alpha3
3.0.0-alpha4

Minor API change: The `message(...)` function no longer provides `html` and `lineSpacingMultiplier`
as parameters. Instead, it works like this:

```kotlin
MaterialDialog(this).show {
...
message(R.string.htmlContent) {
html() // or...
html { toast("Clicked link: $it") }

lineSpacing(1.4f)
messageTextView.doSomething() // you can act directly on the TextView
}
}
```

### 3.0.0-alpha3

* The `BottomSheet()` dialog behavior now accepts an optional `LayoutMode` parameter, which you can use
to instruct the bottom sheet to be expandable to the screen height or limit itself to wrap the content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<include layout="@layout/md_dialog_stub_title"/>

<com.afollestad.materialdialogs.internal.main.DialogContentLayout
<com.afollestad.materialdialogs.internal.message.DialogContentLayout
android:id="@+id/md_content_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import com.afollestad.materialdialogs.callbacks.invokeAll
import com.afollestad.materialdialogs.internal.list.DialogAdapter
import com.afollestad.materialdialogs.internal.main.DialogLayout
import com.afollestad.materialdialogs.list.getListAdapter
import com.afollestad.materialdialogs.message.DialogMessageSettings
import com.afollestad.materialdialogs.utils.MDUtil.assertOneSet
import com.afollestad.materialdialogs.utils.MDUtil.resolveDimen
import com.afollestad.materialdialogs.utils.font
Expand Down Expand Up @@ -167,17 +168,15 @@ class MaterialDialog(
fun message(
@StringRes res: Int? = null,
text: CharSequence? = null,
html: Boolean = false,
lineHeightMultiplier: Float = 1f
applySettings: (DialogMessageSettings.() -> Unit)? = null
): MaterialDialog {
assertOneSet("message", text, res)
this.view.contentLayout.setMessage(
dialog = this,
res = res,
text = text,
html = html,
lineHeightMultiplier = lineHeightMultiplier,
typeface = this.bodyFont
typeface = this.bodyFont,
applySettings = applySettings
)
return this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.R
import com.afollestad.materialdialogs.internal.button.DialogActionButtonLayout
import com.afollestad.materialdialogs.internal.button.shouldBeVisible
import com.afollestad.materialdialogs.internal.message.DialogContentLayout
import com.afollestad.materialdialogs.utils.MDUtil.dimenPx
import com.afollestad.materialdialogs.utils.MDUtil.getWidthAndHeight
import com.afollestad.materialdialogs.utils.dp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Designed and developed by Aidan Follestad (@afollestad)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("unused")

package com.afollestad.materialdialogs.internal.message

import android.text.style.URLSpan
import android.view.View

/** @author Aidan Follestad (@afollestad) */
class CustomUrlSpan(
url: String,
private val onLinkClick: (String) -> Unit
) : URLSpan(url) {
override fun onClick(widget: View) = onLinkClick(url)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.afollestad.materialdialogs.internal.main
package com.afollestad.materialdialogs.internal.message

import android.content.Context
import android.graphics.Typeface
import android.text.method.LinkMovementMethod
import android.util.AttributeSet
import android.view.View
import android.view.View.MeasureSpec.AT_MOST
Expand All @@ -38,8 +37,10 @@ import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.R
import com.afollestad.materialdialogs.internal.button.DialogActionButtonLayout
import com.afollestad.materialdialogs.internal.list.DialogRecyclerView
import com.afollestad.materialdialogs.internal.main.DialogLayout
import com.afollestad.materialdialogs.internal.main.DialogScrollView
import com.afollestad.materialdialogs.message.DialogMessageSettings
import com.afollestad.materialdialogs.utils.MDUtil.maybeSetTextColor
import com.afollestad.materialdialogs.utils.MDUtil.resolveString
import com.afollestad.materialdialogs.utils.MDUtil.updatePadding
import com.afollestad.materialdialogs.utils.inflate

Expand Down Expand Up @@ -69,9 +70,8 @@ class DialogContentLayout(
dialog: MaterialDialog,
@StringRes res: Int?,
text: CharSequence?,
html: Boolean,
lineHeightMultiplier: Float,
typeface: Typeface?
typeface: Typeface?,
applySettings: (DialogMessageSettings.() -> Unit)?
) {
addContentScrollView()
if (messageTextView == null) {
Expand All @@ -80,14 +80,13 @@ class DialogContentLayout(
}
}

typeface.let { messageTextView?.typeface = it }
val messageSettings = DialogMessageSettings(dialog, messageTextView!!)
applySettings?.invoke(messageSettings)

messageTextView?.run {
typeface?.let { this.typeface = it }
maybeSetTextColor(dialog.windowContext, R.attr.md_color_content)
setText(text ?: resolveString(dialog, res, html = html))
setLineSpacing(0f, lineHeightMultiplier)
if (html) {
movementMethod = LinkMovementMethod.getInstance()
}
messageSettings.setText(res, text)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Designed and developed by Aidan Follestad (@afollestad)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.afollestad.materialdialogs.internal.message

import android.graphics.Rect
import android.text.Spannable
import android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
import android.text.method.TransformationMethod
import android.text.style.URLSpan
import android.view.View
import android.widget.TextView

/** https://medium.com/@nullthemall/make-textview-open-links-in-customtabs-12fdcf4bb684 */
internal class LinkTransformationMethod(
private val onLinkClick: (link: String) -> Unit
) : TransformationMethod {
override fun getTransformation(
source: CharSequence,
view: View
): CharSequence {
if (view !is TextView) {
return source
} else if (view.text == null || view.text !is Spannable) {
return source
}
val text = view.text as Spannable
val spans = text.getSpans(0, view.length(), URLSpan::class.java)
for (span in spans) {
val start = text.getSpanStart(span)
val end = text.getSpanEnd(span)
val url = span.url

text.removeSpan(span)
text.setSpan(CustomUrlSpan(url, onLinkClick), start, end, SPAN_EXCLUSIVE_EXCLUSIVE)
}
return text
}

override fun onFocusChanged(
view: View,
sourceText: CharSequence,
focused: Boolean,
direction: Int,
previouslyFocusedRect: Rect
) = Unit
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Designed and developed by Aidan Follestad (@afollestad)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.afollestad.materialdialogs.message

import android.text.method.LinkMovementMethod
import android.widget.TextView
import androidx.annotation.StringRes
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.internal.message.LinkTransformationMethod
import com.afollestad.materialdialogs.utils.MDUtil.resolveString

/** @author Aidan Follestad (@afollestad) */
class DialogMessageSettings internal constructor(
private val dialog: MaterialDialog,
val messageTextView: TextView
) {
private var isHtml: Boolean = false

fun lineSpacing(multiplier: Float): DialogMessageSettings {
messageTextView.setLineSpacing(0f, multiplier)
return this
}

fun html(onLinkClick: ((link: String) -> Unit)? = null): DialogMessageSettings {
isHtml = true
if (onLinkClick != null) {
messageTextView.transformationMethod = LinkTransformationMethod(onLinkClick)
}
messageTextView.movementMethod = LinkMovementMethod.getInstance()
return this
}

internal fun setText(
@StringRes res: Int?,
text: CharSequence?
) {
messageTextView.text = text ?: resolveString(dialog, res, html = isHtml)
}
}
2 changes: 1 addition & 1 deletion core/src/main/res/layout/md_dialog_base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<include layout="@layout/md_dialog_stub_title"/>

<com.afollestad.materialdialogs.internal.main.DialogContentLayout
<com.afollestad.materialdialogs.internal.message.DialogContentLayout
android:id="@+id/md_content_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ ext.versions = [
minSdk : 16,
compileSdk : 28,
buildTools : '28.0.3',
publishVersion : '3.0.0-alpha3',
publishVersionCode : 245,
publishVersion : '3.0.0-alpha4',
publishVersionCode : 246,

// Plugins
gradlePlugin : '3.4.0',
Expand Down
2 changes: 1 addition & 1 deletion documentation/BOTTOMSHEETS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ other functionality like showing a grid of items.
```gradle
dependencies {
...
implementation 'com.afollestad.material-dialogs:bottomsheets:3.0.0-alpha2'
implementation 'com.afollestad.material-dialogs:bottomsheets:3.0.0-alpha4'
}
```

Expand Down
2 changes: 1 addition & 1 deletion documentation/COLOR.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The `color` module contains extensions to the core module, such as a color choos
```gradle
dependencies {
...
implementation 'com.afollestad.material-dialogs:color:3.0.0-alpha2'
implementation 'com.afollestad.material-dialogs:color:3.0.0-alpha4'
}
```

Expand Down
Loading

0 comments on commit 4e3b3ec

Please sign in to comment.