Browse Source

3.0.0-alpha4

Aidan Follestad 5 years ago
parent
commit
4e3b3ec2e2

+ 7 - 7
README.md

@@ -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'
 }
 ```
 
@@ -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'
 }
 ```
  
@@ -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'
 }
 ```
 
@@ -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'
 }
 ```
 
@@ -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'
 }
 ```
 
@@ -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'
 }
 ```
 
@@ -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'
 }
 ```

+ 19 - 1
RELEASE_NOTES.md

@@ -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 

+ 1 - 1
bottomsheets/src/main/res/layout/md_dialog_base_no_buttons.xml

@@ -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"

+ 4 - 5
core/src/main/java/com/afollestad/materialdialogs/MaterialDialog.kt

@@ -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
@@ -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
   }

+ 1 - 0
core/src/main/java/com/afollestad/materialdialogs/internal/main/DialogLayout.kt

@@ -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

+ 29 - 0
core/src/main/java/com/afollestad/materialdialogs/internal/message/CustomUrlSpan.kt

@@ -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)
+}

+ 11 - 12
core/src/main/java/com/afollestad/materialdialogs/internal/main/DialogContentLayout.kt → core/src/main/java/com/afollestad/materialdialogs/internal/message/DialogContentLayout.kt

@@ -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
@@ -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
 
@@ -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) {
@@ -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)
     }
   }
 

+ 59 - 0
core/src/main/java/com/afollestad/materialdialogs/internal/message/LinkTransformationMethod.kt

@@ -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
+}

+ 52 - 0
core/src/main/java/com/afollestad/materialdialogs/message/DialogMessageSettings.kt

@@ -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)
+  }
+}

+ 1 - 1
core/src/main/res/layout/md_dialog_base.xml

@@ -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"

+ 2 - 2
dependencies.gradle

@@ -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',

+ 1 - 1
documentation/BOTTOMSHEETS.md

@@ -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'
 }
 ```
 

+ 1 - 1
documentation/COLOR.md

@@ -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'
 }
 ```
 

+ 32 - 10
documentation/CORE.md

@@ -4,19 +4,20 @@
 
 1. [Gradle Dependency](#gradle-dependency)
 2. [Basics](#basics)
-3. [Action Buttons](#action-buttons)
-4. [Adding an Icon](#adding-an-icon)
-5. [Callbacks](#callbacks)
-6. [Dismissing](#dismissing)
-7. [Lists](#lists)
+3. [Customizing the Message](#customizing-the-message)
+4. [Action Buttons](#action-buttons)
+5. [Adding an Icon](#adding-an-icon)
+6. [Callbacks](#callbacks)
+7. [Dismissing](#dismissing)
+8. [Lists](#lists)
     1. [Plain](#plain)
     2. [Single Choice](#single-choice)
     3. [Multiple Choice](#multiple-choice)
     4. [Custom Adapters](#custom-adapters)
-8. [Checkbox Prompts](#checkbox-prompts)
-9. [Custom Views](#custom-views)
-10. [Miscellaneous](#miscellaneous)
-11. [Theming](#theming)
+9. [Checkbox Prompts](#checkbox-prompts)
+10. [Custom Views](#custom-views)
+11. [Miscellaneous](#miscellaneous)
+12. [Theming](#theming)
     1. [Light and Dark](#light-and-dark)
     2. [Background Color](#background-color)
     3. [Ripple Color](#ripple-color)
@@ -35,7 +36,7 @@ core and normal-use functionality.
 ```gradle
 dependencies {
   ...
-  implementation 'com.afollestad.material-dialogs:core:3.0.0-alpha2'
+  implementation 'com.afollestad.material-dialogs:core:3.0.0-alpha4'
 }
 ```
 
@@ -73,6 +74,27 @@ val dialog = MaterialDialog(this)
 dialog.show()
 ```
 
+## Customizing the Message
+
+The `message` function lets you trail it with a lambda, which exposes certain built-in modifiers 
+along with allowing you to act on the `TextView` directly.
+
+```kotlin
+MaterialDialog(this).show {
+  ...
+  message(R.string.your_message) {
+      html() // format, color, etc. with tags in string
+      html { link ->  // same as above, but... 
+        // Invokes a callback when a URL is clicked instead of auto opening it in a browser
+      }
+      lineSpacing(1.4f) // modifies line spacing, default is 1.0f
+      
+      // You can directly act on the message TextView as well
+      val textView = messageTextView
+  }
+}
+```
+
 ## Action Buttons
 
 There are simple methods for adding action buttons:

+ 1 - 1
documentation/DATETIME.md

@@ -16,7 +16,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-alpha2'
+  implementation 'com.afollestad.material-dialogs:datetime:3.0.0-alpha4'
 }
 ```
 

+ 1 - 1
documentation/FILES.md

@@ -23,7 +23,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-alpha2'
+  implementation 'com.afollestad.material-dialogs:files:3.0.0-alpha4'
 }
 ```
 

+ 1 - 1
documentation/INPUT.md

@@ -19,7 +19,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-alpha2'
+  implementation 'com.afollestad.material-dialogs:input:3.0.0-alpha4'
 }
 ```
 

+ 1 - 1
documentation/LIFECYCLE.md

@@ -15,7 +15,7 @@ The `lifecycle` module contains extensions to make dialogs work with AndroidX li
 ```gradle
 dependencies {
   ...
-  implementation 'com.afollestad.material-dialogs:lifecycle:3.0.0-alpha2'
+  implementation 'com.afollestad.material-dialogs:lifecycle:3.0.0-alpha4'
 }
 ```
 

+ 4 - 5
sample/src/main/java/com/afollestad/materialdialogssample/MainActivity.kt

@@ -178,11 +178,10 @@ class MainActivity : AppCompatActivity() {
     basic_html_content.setOnClickListener {
       MaterialDialog(this).show {
         title(R.string.app_name)
-        message(
-            R.string.htmlContent,
-            html = true,
-            lineHeightMultiplier = 1.4f
-        )
+        message(R.string.htmlContent) {
+          html { toast("Clicked link: $it") }
+          lineSpacing(1.4f)
+        }
         positiveButton(R.string.agree)
         negativeButton(R.string.disagree)
         debugMode(debugMode)