Skip to content

Commit

Permalink
Merge pull request #17 from Priyansh-Kedia/issue_15
Browse files Browse the repository at this point in the history
Issue 15
  • Loading branch information
pknotfound authored Feb 14, 2022
2 parents 6f1f2eb + 8d60b3c commit da1029d
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 5 deletions.
28 changes: 28 additions & 0 deletions OGParser/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'maven-publish'
}


android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
Expand Down Expand Up @@ -59,3 +61,29 @@ dependencies {
// implementation "androidx.lifecycle:lifecycle-extensions:${lifecycle_version}"
// implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:${lifecycle_version}"
}

afterEvaluate {
publishing {
publications {
// Creates a Maven publication called "release".
release(MavenPublication) {
// Applies the component for the release build variant.
from components.release

// You can then customize attributes of the publication as shown below.
groupId = 'com.github.Priyansh-Kedia'
artifactId = 'final'
version = '2.5.3'
}
// Creates a Maven publication called “debug”.
debug(MavenPublication) {
// Applies the component for the debug build variant.
from components.debug

groupId = 'com.github.Priyansh-Kedia'
artifactId = 'final-debug'
version = '2.5.3'
}
}
}
}
10 changes: 8 additions & 2 deletions OGParser/src/main/java/com/kedia/ogparser/JsoupNetworkCall.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.kedia.ogparser

import android.util.Log
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.jsoup.Jsoup

class JsoupNetworkCall {
Expand Down Expand Up @@ -62,6 +60,14 @@ class JsoupNetworkCall {
}
}
}

if (openGraphResult!!.title.isNullOrEmpty())
openGraphResult!!.title = doc.title()
if (openGraphResult!!.description.isNullOrEmpty())
openGraphResult!!.description = if (doc.select("meta[name=description]").size != 0) doc.select("meta[name=description]")
.first().attr("content") else ""
if (openGraphResult!!.url.isNullOrEmpty())
openGraphResult!!.url = getBaseUrl(url)
} catch (e: Exception) {
e.printStackTrace()
return null
Expand Down
9 changes: 7 additions & 2 deletions OGParser/src/main/java/com/kedia/ogparser/SharedPrefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.kedia.ogparser

import android.content.Context
import android.content.SharedPreferences
import android.util.Log
import androidx.preference.PreferenceManager

class SharedPrefs(context: Context) {
Expand Down Expand Up @@ -87,8 +88,12 @@ class SharedPrefs(context: Context) {
val title = getTitle(url)
val description = getDescription(url)
val image = getImage(url)

return title.isNotEmpty() && description.isNotEmpty() && image.isNotEmpty()
return title.isNotEmpty() &&
title.equals("null").not() &&
description.isNotEmpty() &&
description.equals("null").not() &&
image.isNotEmpty() &&
image.equals("null").not()
}

}
8 changes: 8 additions & 0 deletions OGParser/src/main/java/com/kedia/ogparser/UtilityFunctions.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package com.kedia.ogparser

import java.net.URI
import java.net.URL

fun checkNullParserResult(openGraphResult: OpenGraphResult?): Boolean {
return (openGraphResult?.title.isNullOrEmpty() ||
openGraphResult?.title.equals("null")) &&
(openGraphResult?.description.isNullOrEmpty() ||
openGraphResult?.description.equals(
"null"
))
}

fun getBaseUrl(urlString: String): String {
val url: URL = URI.create(urlString).toURL()
return url.protocol.toString() + "://" + url.authority + "/"
}
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ dependencies {
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// implementation 'com.github.Priyansh-Kedia:OpenGraphParser:3f0d7dfb11'

}
5 changes: 4 additions & 1 deletion app/src/main/java/com/kedia/opengraphpreview/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class MainActivity : AppCompatActivity(), OpenGraphCallback {
"https://chat.whatsapp.com/DdWAKRkt2VfAmd4OS47y7P",
"https://www.reddit.com/r/MachineLearning/comments/s3mjqf/deep_learning_interviews_hundreds_of_fully_solved/?utm_medium=android_app&utm_source=share",
"https://instagram.com/fcbarcelona?utm_medium=copy_link",
"https://www.facebook.com/groups/777946865955982/permalink/1385110621906267/"
"https://www.facebook.com/groups/777946865955982/permalink/1385110621906267/",
"https://www.youtube.com/",
"https://www.instagram.com/",
"https://klusterapp.io/kluster/message?message_id=7244&channel_id=2247&Channel_name=new-channel-with-spa&kluster_id=64"
)

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down

0 comments on commit da1029d

Please sign in to comment.