Skip to content

Commit 4109b1c

Browse files
authored
Merge pull request #29 from NickM-27/develop
3.3
2 parents 3a89d0f + 35ef9bf commit 4109b1c

File tree

8 files changed

+284
-123
lines changed

8 files changed

+284
-123
lines changed

.idea/gradle.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ On your module's `build.gradle` file add this statement to the `dependencies` se
1818

1919
```groovy
2020
dependencies {
21-
implementation 'com.nick.mowen.linkpreview:linkpreview:3.2'
21+
implementation 'com.nick.mowen.linkpreview:linkpreview:3.3'
2222
}
2323
```
2424

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
jcenter()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.5.1'
10+
classpath 'com.android.tools.build:gradle:3.6.0-beta03'
1111
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1212

1313
// For Library
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Fri Jul 12 19:03:54 PDT 2019
1+
#Wed Nov 06 08:42:52 MST 2019
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-all.zip

linkpreview/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ android {
99
defaultConfig {
1010
minSdkVersion 19
1111
targetSdkVersion 29
12-
versionCode 23
13-
versionName "3.2"
12+
versionCode 24
13+
versionName "3.3"
1414
vectorDrawables.useSupportLibrary = true
1515
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1616
}
@@ -38,14 +38,14 @@ android {
3838
dependencies {
3939

4040
// AndroidX
41-
implementation 'com.google.android.material:material:1.1.0-beta01'
41+
implementation 'com.google.android.material:material:1.1.0-beta02'
4242
implementation 'androidx.core:core-ktx:1.1.0'
4343
implementation 'androidx.browser:browser:1.0.0'
4444
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
4545

4646
// Other
4747
implementation 'org.jsoup:jsoup:1.12.1'
48-
implementation 'io.coil-kt:coil:0.7.0'
48+
implementation 'io.coil-kt:coil:0.8.0'
4949

5050
// Kotlin
5151
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
@@ -65,7 +65,7 @@ ext {
6565

6666
publishedGroupId = 'com.nick.mowen.linkpreview'
6767
artifact = 'linkpreview'
68-
libraryVersion = '3.2'
68+
libraryVersion = '3.3'
6969
libraryDescription = 'A convenient view that shows a clickable preview of a link'
7070
siteUrl = 'https://github.com/NickM-27/LinkPreview'
7171
gitUrl = 'https://github.com/NickM-27/LinkPreview.git'

linkpreview/out.map

Lines changed: 248 additions & 106 deletions
Large diffs are not rendered by default.

linkpreview/src/main/java/com/nick/mowen/linkpreview/view/LinkCardView.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import android.content.Context
44
import android.content.Intent
55
import android.graphics.Color
66
import android.util.AttributeSet
7-
import android.util.Log
87
import android.view.LayoutInflater
98
import android.view.View
109
import android.widget.FrameLayout
@@ -20,17 +19,22 @@ import com.nick.mowen.linkpreview.databinding.CardBinding
2019
import com.nick.mowen.linkpreview.extension.*
2120
import com.nick.mowen.linkpreview.listener.CardListener
2221
import com.nick.mowen.linkpreview.listener.LinkClickListener
23-
import kotlinx.coroutines.GlobalScope
24-
import kotlinx.coroutines.launch
22+
import kotlinx.coroutines.*
2523

2624
@Suppress("MemberVisibilityCanBePrivate") // Leave values as protected for extensibility
2725
open class LinkCardView : FrameLayout, View.OnClickListener {
2826

2927
protected lateinit var binding: CardBinding
28+
/** Coroutine Job */
29+
private val linkJob = Job()
30+
/** Coroutine Scope */
31+
private val linkScope = CoroutineScope(Dispatchers.Main + linkJob)
3032
/** Map of cached links and their image url */
3133
private var linkMap: HashMap<Int, String> = hashMapOf()
3234
/** Type of image to handle in specific way */
3335
private var imageType = ImageType.NONE
36+
/** */
37+
private val thing = 0
3438
/** Parsed URL */
3539
protected var url = ""
3640
/** Optional listener for load callbacks */
@@ -121,7 +125,12 @@ open class LinkCardView : FrameLayout, View.OnClickListener {
121125
try {
122126
isVisible = true
123127
imageType = ImageType.DEFAULT
124-
GlobalScope.launch { loadCardData(url, linkMap, url.hashCode(), loadListener) }
128+
linkScope.launch {
129+
if (linkScope.isActive)
130+
linkScope.cancel()
131+
132+
loadCardData(url, linkMap, url.hashCode(), loadListener)
133+
}
125134
} catch (e: Exception) {
126135
e.printStackTrace()
127136
imageType = ImageType.NONE
@@ -179,7 +188,6 @@ open class LinkCardView : FrameLayout, View.OnClickListener {
179188

180189
fun setCardData(data: CardData) {
181190
binding.data = data
182-
Log.e("ERROR?", "The data is $data")
183191
binding.executePendingBindings()
184192
}
185193
}

linkpreview/src/main/java/com/nick/mowen/linkpreview/view/LinkPreview.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ import com.nick.mowen.linkpreview.databinding.PreviewBinding
1818
import com.nick.mowen.linkpreview.extension.*
1919
import com.nick.mowen.linkpreview.listener.LinkClickListener
2020
import com.nick.mowen.linkpreview.listener.LinkListener
21-
import kotlinx.coroutines.GlobalScope
22-
import kotlinx.coroutines.launch
21+
import kotlinx.coroutines.*
2322

2423
@Suppress("MemberVisibilityCanBePrivate") // Leave values as protected for extensibility
2524
open class LinkPreview : FrameLayout, View.OnClickListener {
2625

2726
protected lateinit var binding: PreviewBinding
27+
/** Coroutine Job */
28+
private val linkJob = Job()
29+
/** Coroutine Scope */
30+
private val linkScope = CoroutineScope(Dispatchers.Main + linkJob)
2831
/** Map of cached links and their image url */
2932
private var linkMap: HashMap<Int, String> = hashMapOf()
3033
/** Type of image to handle in specific way */
@@ -132,7 +135,12 @@ open class LinkPreview : FrameLayout, View.OnClickListener {
132135
visibility = View.VISIBLE
133136
binding.previewText.text = url
134137
imageType = ImageType.DEFAULT
135-
GlobalScope.launch { loadImage(url, linkMap, url.hashCode(), loadListener) }
138+
linkScope.launch {
139+
if (linkScope.isActive)
140+
linkScope.cancel()
141+
142+
loadImage(url, linkMap, url.hashCode(), loadListener)
143+
}
136144
} catch (e: Exception) {
137145
e.printStackTrace()
138146
imageType = ImageType.NONE

0 commit comments

Comments
 (0)