Send all images in the webpage to the Image fragment.
This commit is contained in:
parent
3de95ba6e4
commit
cda09a4e8a
@ -102,6 +102,7 @@ dependencies {
|
||||
implementation "androidx.browser:browser:$android_version"
|
||||
implementation "androidx.cardview:cardview:$android_version"
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha5'
|
||||
implementation 'org.jsoup:jsoup:1.13.1'
|
||||
|
||||
//multidex
|
||||
implementation 'androidx.multidex:multidex:2.0.1'
|
||||
|
@ -5,6 +5,7 @@ import android.net.Uri
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import android.text.Html
|
||||
import org.jsoup.Jsoup
|
||||
|
||||
import apps.amine.bou.readerforselfoss.utils.Config
|
||||
import apps.amine.bou.readerforselfoss.utils.isEmptyOrNullOrNullString
|
||||
@ -128,6 +129,15 @@ data class Item(
|
||||
return constructUrl(config, "thumbnails", thumbnail)
|
||||
}
|
||||
|
||||
fun getImages() : ArrayList<String> {
|
||||
var allImages = ArrayList<String>()
|
||||
|
||||
for ( image in Jsoup.parse(content).getElementsByTag("img")) {
|
||||
allImages.add(image.attr("src"))
|
||||
}
|
||||
return allImages
|
||||
}
|
||||
|
||||
fun getTitleDecoded(): String {
|
||||
return Html.fromHtml(title).toString()
|
||||
}
|
||||
|
@ -53,6 +53,7 @@ import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
import java.net.MalformedURLException
|
||||
import java.net.URL
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
class ArticleFragment : Fragment() {
|
||||
@ -65,6 +66,7 @@ class ArticleFragment : Fragment() {
|
||||
private lateinit var contentSource: String
|
||||
private lateinit var contentImage: String
|
||||
private lateinit var contentTitle: String
|
||||
private lateinit var allImages : ArrayList<String>
|
||||
private lateinit var editor: SharedPreferences.Editor
|
||||
private lateinit var fab: FloatingActionButton
|
||||
private lateinit var appColors: AppColors
|
||||
@ -116,6 +118,7 @@ class ArticleFragment : Fragment() {
|
||||
contentTitle = allItems[pageNumber.toInt()].getTitleDecoded()
|
||||
contentImage = allItems[pageNumber.toInt()].getThumbnail(activity!!)
|
||||
contentSource = allItems[pageNumber.toInt()].sourceAndDateText()
|
||||
allImages = allItems[pageNumber.toInt()].getImages()
|
||||
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(activity)
|
||||
editor = prefs.edit()
|
||||
@ -545,10 +548,9 @@ class ArticleFragment : Fragment() {
|
||||
fun performClick(): Boolean {
|
||||
if (rootView!!.webcontent.hitTestResult.type == WebView.HitTestResult.IMAGE_TYPE ||
|
||||
rootView!!.webcontent.hitTestResult.type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
|
||||
//TODO: Transfer all images in the webpage to the Image fragment
|
||||
var allImages = ArrayList<String>()
|
||||
allImages.add(rootView!!.webcontent.hitTestResult.extra.toString())
|
||||
val position : Int = 0
|
||||
|
||||
val position : Int = allImages.indexOf(rootView!!.webcontent.hitTestResult.extra)
|
||||
|
||||
|
||||
fragmentManager!!.beginTransaction().replace(R.id.reader_activity_view, ImageFragment.newInstance(position, allImages)).addToBackStack(null).commit()
|
||||
return false
|
||||
|
@ -9,7 +9,7 @@ import kotlinx.android.synthetic.main.fragment_article.view.webcontent
|
||||
|
||||
class ImageFragment : Fragment() {
|
||||
|
||||
private lateinit var position: Number
|
||||
private var position: Int = 0
|
||||
private lateinit var allImages: ArrayList<String>
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@ -31,7 +31,7 @@ class ImageFragment : Fragment() {
|
||||
view.webcontent.settings.setSupportZoom(true)
|
||||
view.webcontent.settings.setBuiltInZoomControls(true)
|
||||
view.webcontent.settings.setDisplayZoomControls(false)
|
||||
view.webcontent.loadUrl(allImages[0])
|
||||
view.webcontent.loadUrl(allImages[position])
|
||||
|
||||
return view
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user