Skip to content

Commit

Permalink
Merge pull request #29 from NickM-27/develop
Browse files Browse the repository at this point in the history
3.3
  • Loading branch information
NickM-27 authored Nov 15, 2019
2 parents 3a89d0f + 35ef9bf commit 4109b1c
Show file tree
Hide file tree
Showing 8 changed files with 284 additions and 123 deletions.
3 changes: 3 additions & 0 deletions .idea/gradle.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:3.2'
implementation 'com.nick.mowen.linkpreview:linkpreview:3.3'
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.android.tools.build:gradle:3.6.0-beta03'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// For Library
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Jul 12 19:03:54 PDT 2019
#Wed Nov 06 08:42:52 MST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-all.zip
10 changes: 5 additions & 5 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 29
versionCode 23
versionName "3.2"
versionCode 24
versionName "3.3"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -38,14 +38,14 @@ android {
dependencies {

// AndroidX
implementation 'com.google.android.material:material:1.1.0-beta01'
implementation 'com.google.android.material:material:1.1.0-beta02'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.browser:browser:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

// Other
implementation 'org.jsoup:jsoup:1.12.1'
implementation 'io.coil-kt:coil:0.7.0'
implementation 'io.coil-kt:coil:0.8.0'

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

publishedGroupId = 'com.nick.mowen.linkpreview'
artifact = 'linkpreview'
libraryVersion = '3.2'
libraryVersion = '3.3'
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
354 changes: 248 additions & 106 deletions linkpreview/out.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.util.AttributeSet
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
Expand All @@ -20,17 +19,22 @@ import com.nick.mowen.linkpreview.databinding.CardBinding
import com.nick.mowen.linkpreview.extension.*
import com.nick.mowen.linkpreview.listener.CardListener
import com.nick.mowen.linkpreview.listener.LinkClickListener
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.*

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

protected lateinit var binding: CardBinding
/** Coroutine Job */
private val linkJob = Job()
/** Coroutine Scope */
private val linkScope = CoroutineScope(Dispatchers.Main + linkJob)
/** Map of cached links and their image url */
private var linkMap: HashMap<Int, String> = hashMapOf()
/** Type of image to handle in specific way */
private var imageType = ImageType.NONE
/** */
private val thing = 0
/** Parsed URL */
protected var url = ""
/** Optional listener for load callbacks */
Expand Down Expand Up @@ -121,7 +125,12 @@ open class LinkCardView : FrameLayout, View.OnClickListener {
try {
isVisible = true
imageType = ImageType.DEFAULT
GlobalScope.launch { loadCardData(url, linkMap, url.hashCode(), loadListener) }
linkScope.launch {
if (linkScope.isActive)
linkScope.cancel()

loadCardData(url, linkMap, url.hashCode(), loadListener)
}
} catch (e: Exception) {
e.printStackTrace()
imageType = ImageType.NONE
Expand Down Expand Up @@ -179,7 +188,6 @@ open class LinkCardView : FrameLayout, View.OnClickListener {

fun setCardData(data: CardData) {
binding.data = data
Log.e("ERROR?", "The data is $data")
binding.executePendingBindings()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ import com.nick.mowen.linkpreview.databinding.PreviewBinding
import com.nick.mowen.linkpreview.extension.*
import com.nick.mowen.linkpreview.listener.LinkClickListener
import com.nick.mowen.linkpreview.listener.LinkListener
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.*

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

protected lateinit var binding: PreviewBinding
/** Coroutine Job */
private val linkJob = Job()
/** Coroutine Scope */
private val linkScope = CoroutineScope(Dispatchers.Main + linkJob)
/** Map of cached links and their image url */
private var linkMap: HashMap<Int, String> = hashMapOf()
/** Type of image to handle in specific way */
Expand Down Expand Up @@ -132,7 +135,12 @@ open class LinkPreview : FrameLayout, View.OnClickListener {
visibility = View.VISIBLE
binding.previewText.text = url
imageType = ImageType.DEFAULT
GlobalScope.launch { loadImage(url, linkMap, url.hashCode(), loadListener) }
linkScope.launch {
if (linkScope.isActive)
linkScope.cancel()

loadImage(url, linkMap, url.hashCode(), loadListener)
}
} catch (e: Exception) {
e.printStackTrace()
imageType = ImageType.NONE
Expand Down

0 comments on commit 4109b1c

Please sign in to comment.