Skip to content

Commit c6ba781

Browse files
committed
bug fiz
1 parent b7e0369 commit c6ba781

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import kotlin.coroutines.CoroutineContext
88

99
class OpenGraphParser(
1010
private val listener: OpenGraphCallback,
11-
private var showNullOnEmpty: Boolean = true
11+
private var showNullOnEmpty: Boolean = false
1212
) {
1313

1414
private var url: String = ""
@@ -42,7 +42,10 @@ class OpenGraphParser(
4242

4343
fun parse() = launch {
4444
val result = fetchContent()
45-
result?.let { listener.onPostResponse(it) }
45+
result?.let {
46+
Log.d("TAG!!!!", "called here from thread ${Thread.currentThread().name}")
47+
listener.onPostResponse(it)
48+
}
4649
}
4750
}
4851

@@ -100,8 +103,12 @@ class OpenGraphParser(
100103
return@withContext null
101104
}
102105

106+
Log.d("TAG!!!!", openGraphResult.toString())
107+
103108
if (openGraphResult!!.title.isEmpty() && openGraphResult!!.description.isEmpty() && showNullOnEmpty) {
104-
listener.onError("Null or empty response from the server")
109+
launch(Dispatchers.Main) {
110+
listener.onError("Null or empty response from the server")
111+
}
105112
return@withContext null
106113
}
107114

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ class MainActivity : AppCompatActivity(), OpenGraphCallback {
1515
setContentView(R.layout.activity_main)
1616

1717
val openGraphParser = OpenGraphParser(this)
18-
openGraphParser.parse("https://www.you")
18+
openGraphParser.parse("https://www.youtube.com")
1919
}
2020

2121
override fun onPostResponse(openGraphResult: OpenGraphResult) {
2222
tview.text = openGraphResult.toString()
2323
}
2424

2525
override fun onError(error: String) {
26-
tview.text = error
2726
Log.e("TAG!!!!", "$error")
27+
tview.text = error
2828
}
2929
}

0 commit comments

Comments
 (0)