Skip to content

Commit da1029d

Browse files
authored
Merge pull request #17 from Priyansh-Kedia/issue_15
Issue 15
2 parents 6f1f2eb + 8d60b3c commit da1029d

6 files changed

Lines changed: 56 additions & 5 deletions

File tree

OGParser/build.gradle

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
plugins {
22
id 'com.android.library'
33
id 'kotlin-android'
4+
id 'maven-publish'
45
}
56

7+
68
android {
79
compileSdkVersion 30
810
buildToolsVersion "30.0.3"
@@ -59,3 +61,29 @@ dependencies {
5961
// implementation "androidx.lifecycle:lifecycle-extensions:${lifecycle_version}"
6062
// implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:${lifecycle_version}"
6163
}
64+
65+
afterEvaluate {
66+
publishing {
67+
publications {
68+
// Creates a Maven publication called "release".
69+
release(MavenPublication) {
70+
// Applies the component for the release build variant.
71+
from components.release
72+
73+
// You can then customize attributes of the publication as shown below.
74+
groupId = 'com.github.Priyansh-Kedia'
75+
artifactId = 'final'
76+
version = '2.5.3'
77+
}
78+
// Creates a Maven publication called “debug”.
79+
debug(MavenPublication) {
80+
// Applies the component for the debug build variant.
81+
from components.debug
82+
83+
groupId = 'com.github.Priyansh-Kedia'
84+
artifactId = 'final-debug'
85+
version = '2.5.3'
86+
}
87+
}
88+
}
89+
}

OGParser/src/main/java/com/kedia/ogparser/JsoupNetworkCall.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.kedia.ogparser
22

33
import android.util.Log
4-
import kotlinx.coroutines.Dispatchers
5-
import kotlinx.coroutines.launch
64
import org.jsoup.Jsoup
75

86
class JsoupNetworkCall {
@@ -62,6 +60,14 @@ class JsoupNetworkCall {
6260
}
6361
}
6462
}
63+
64+
if (openGraphResult!!.title.isNullOrEmpty())
65+
openGraphResult!!.title = doc.title()
66+
if (openGraphResult!!.description.isNullOrEmpty())
67+
openGraphResult!!.description = if (doc.select("meta[name=description]").size != 0) doc.select("meta[name=description]")
68+
.first().attr("content") else ""
69+
if (openGraphResult!!.url.isNullOrEmpty())
70+
openGraphResult!!.url = getBaseUrl(url)
6571
} catch (e: Exception) {
6672
e.printStackTrace()
6773
return null

OGParser/src/main/java/com/kedia/ogparser/SharedPrefs.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.kedia.ogparser
22

33
import android.content.Context
44
import android.content.SharedPreferences
5+
import android.util.Log
56
import androidx.preference.PreferenceManager
67

78
class SharedPrefs(context: Context) {
@@ -87,8 +88,12 @@ class SharedPrefs(context: Context) {
8788
val title = getTitle(url)
8889
val description = getDescription(url)
8990
val image = getImage(url)
90-
91-
return title.isNotEmpty() && description.isNotEmpty() && image.isNotEmpty()
91+
return title.isNotEmpty() &&
92+
title.equals("null").not() &&
93+
description.isNotEmpty() &&
94+
description.equals("null").not() &&
95+
image.isNotEmpty() &&
96+
image.equals("null").not()
9297
}
9398

9499
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
package com.kedia.ogparser
22

3+
import java.net.URI
4+
import java.net.URL
5+
36
fun checkNullParserResult(openGraphResult: OpenGraphResult?): Boolean {
47
return (openGraphResult?.title.isNullOrEmpty() ||
58
openGraphResult?.title.equals("null")) &&
69
(openGraphResult?.description.isNullOrEmpty() ||
710
openGraphResult?.description.equals(
811
"null"
912
))
13+
}
14+
15+
fun getBaseUrl(urlString: String): String {
16+
val url: URL = URI.create(urlString).toURL()
17+
return url.protocol.toString() + "://" + url.authority + "/"
1018
}

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@ dependencies {
4444
testImplementation 'junit:junit:4.+'
4545
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
4646
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
47+
// implementation 'com.github.Priyansh-Kedia:OpenGraphParser:3f0d7dfb11'
4748

4849
}

app/src/main/java/com/kedia/opengraphpreview/MainActivity.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ class MainActivity : AppCompatActivity(), OpenGraphCallback {
2121
"https://chat.whatsapp.com/DdWAKRkt2VfAmd4OS47y7P",
2222
"https://www.reddit.com/r/MachineLearning/comments/s3mjqf/deep_learning_interviews_hundreds_of_fully_solved/?utm_medium=android_app&utm_source=share",
2323
"https://instagram.com/fcbarcelona?utm_medium=copy_link",
24-
"https://www.facebook.com/groups/777946865955982/permalink/1385110621906267/"
24+
"https://www.facebook.com/groups/777946865955982/permalink/1385110621906267/",
25+
"https://www.youtube.com/",
26+
"https://www.instagram.com/",
27+
"https://klusterapp.io/kluster/message?message_id=7244&channel_id=2247&Channel_name=new-channel-with-spa&kluster_id=64"
2528
)
2629

2730
override fun onCreate(savedInstanceState: Bundle?) {

0 commit comments

Comments
 (0)