This repository has been archived by the owner on Sep 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9e2fc5
commit 4e3b3ec
Showing
19 changed files
with
228 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
core/src/main/java/com/afollestad/materialdialogs/internal/message/CustomUrlSpan.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...src/main/java/com/afollestad/materialdialogs/internal/message/LinkTransformationMethod.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
52 changes: 52 additions & 0 deletions
52
core/src/main/java/com/afollestad/materialdialogs/message/DialogMessageSettings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.