Skip to content

Commit

Permalink
Merge pull request #24 from NickM-27/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
NickM-27 authored Feb 1, 2019
2 parents e3bba3d + 4d6cb11 commit 174f107
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 122 deletions.
47 changes: 0 additions & 47 deletions .idea/assetWizardSettings.xml

This file was deleted.

5 changes: 0 additions & 5 deletions .idea/codeStyles/codeStyleConfig.xml

This file was deleted.

7 changes: 0 additions & 7 deletions .idea/dictionaries/nickmowen.xml

This file was deleted.

40 changes: 5 additions & 35 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ On your module's `build.gradle` file add this statement to the `dependencies` se

```groovy
dependencies {
implementation 'com.nick.mowen.linkpreview:linkpreview:2.0'
implementation 'com.nick.mowen.linkpreview:linkpreview:2.1'
}
```

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.10'
ext.kotlin_version = '1.3.20'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0-beta04'
classpath 'com.android.tools.build:gradle:3.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

//For Library
Expand Down
12 changes: 6 additions & 6 deletions linkpreview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 28
versionCode 15
versionName "2.0"
versionCode 17
versionName "2.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -31,7 +31,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

//Other
implementation 'org.jsoup:jsoup:1.11.2'
implementation 'org.jsoup:jsoup:1.11.3'
//noinspection GradleDependency
implementation 'com.github.bumptech.glide:glide:3.8.0'

Expand All @@ -43,8 +43,8 @@ dependencies {

//Testing libraries
testImplementation 'org.jetbrains.kotlin:kotlin-test-junit:1.2.31'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

ext {
Expand All @@ -54,7 +54,7 @@ ext {

publishedGroupId = 'com.nick.mowen.linkpreview'
artifact = 'linkpreview'
libraryVersion = '2.0'
libraryVersion = '2.2'
libraryDescription = 'A convenient view that shows a clickable preview of a link'
siteUrl = 'https://github.com/NickM-27/LinkPreview'
gitUrl = 'https://github.com/NickM-27/LinkPreview.git'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ object BindingAdapter {

@BindingAdapter("parsedLink")
@JvmStatic
fun setParsedLink(view: LinkPreview, link: String) {
view.parseTextForLink(link)
}
fun setParsedLink(view: LinkPreview, link: String) = view.parseTextForLink(link)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,14 @@ package com.nick.mowen.linkpreview.extension
/**
* Checks whether a string is a url by using Regex
*/
fun String.isUrl(): Boolean = this.matches(Regex("https?://(www\\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_+.~#?&/=]*)"))
fun String.isUrl(): Boolean = this.matches(Regex(REGEX_URL))

/**
* Parses the link from the full string
*/
fun String.parseUrl(): String = REGEX_URL.toRegex().find(this)?.value ?: ""

/**
* Regex pattern that matches to standard urls
*/
private const val REGEX_URL = "https?://(www\\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_+.~#?&/=]*)"
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import android.widget.ImageView
import android.widget.TextView
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.net.toUri
import androidx.core.view.isGone
import com.bumptech.glide.Glide
import com.nick.mowen.linkpreview.ImageType
import com.nick.mowen.linkpreview.R
import com.nick.mowen.linkpreview.extension.addLink
import com.nick.mowen.linkpreview.extension.isUrl
import com.nick.mowen.linkpreview.extension.loadImage
import com.nick.mowen.linkpreview.extension.loadLinkMap
import com.nick.mowen.linkpreview.extension.*
import com.nick.mowen.linkpreview.listener.LinkClickListener
import com.nick.mowen.linkpreview.listener.LinkListener
import kotlinx.coroutines.GlobalScope
Expand All @@ -38,6 +36,8 @@ open class LinkPreview : FrameLayout, View.OnClickListener {
var clickListener: LinkClickListener? = null
/** Optional click listener to override click behavior */
var articleColor: Int = Color.CYAN
/** Set whether or not to default to hidden while loading preview */
var hideWhileLoading = false

/** Color of the Chrome CustomTab that is launched on view click */

Expand All @@ -49,7 +49,11 @@ open class LinkPreview : FrameLayout, View.OnClickListener {
bindViews(context)
}

constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) {
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(
context,
attrs,
defStyle
) {
bindViews(context)
}

Expand All @@ -67,7 +71,9 @@ open class LinkPreview : FrameLayout, View.OnClickListener {
if (isInEditMode)
return

visibility = View.GONE
if (hideWhileLoading)
isGone = true

image = findViewById(R.id.preview_image)
text = findViewById(R.id.preview_text)
setOnClickListener(this)
Expand Down Expand Up @@ -164,28 +170,28 @@ open class LinkPreview : FrameLayout, View.OnClickListener {
* @return if a link was found in the text
*/
fun parseTextForLink(text: String): Boolean {
when {
return when {
text.contains("youtube") && text.contains("v=") -> {
val id = text.split("v=")[1].split(" ")[0]
url = "https://www.youtube.com/watch?v=$id"
setText()
return true
true
}
text.contains("youtu.be") -> {
val id = text.split("be/")[1].split(" ")[0]
url = "https://www.youtube.com/watch?v=$id"
setText()
return true
true
}
text.contains("http") -> {
text.split(" ").filter { it.matches(Regex("https?://(www\\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_+.~#?&/=]*)")) }.forEach { url = it }
url = text.parseUrl()
setText()
return true
true
}
else -> {
imageType = ImageType.NONE
visibility = View.GONE
return false
false
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ dependencies {
//Testing Libraries
testImplementation 'org.jetbrains.kotlin:kotlin-test-junit:1.2.31'

androidTestImplementation 'androidx.test:runner:1.1.0-beta02'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-beta02'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

0 comments on commit 174f107

Please sign in to comment.