Send all images in the webpage to the Image fragment.

This commit is contained in:
davidoskky 2020-12-14 15:29:54 +01:00
parent 3de95ba6e4
commit cda09a4e8a
4 changed files with 19 additions and 6 deletions

View File

@ -102,6 +102,7 @@ dependencies {
implementation "androidx.browser:browser:$android_version" implementation "androidx.browser:browser:$android_version"
implementation "androidx.cardview:cardview:$android_version" implementation "androidx.cardview:cardview:$android_version"
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha5' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha5'
implementation 'org.jsoup:jsoup:1.13.1'
//multidex //multidex
implementation 'androidx.multidex:multidex:2.0.1' implementation 'androidx.multidex:multidex:2.0.1'

View File

@ -5,6 +5,7 @@ import android.net.Uri
import android.os.Parcel import android.os.Parcel
import android.os.Parcelable import android.os.Parcelable
import android.text.Html import android.text.Html
import org.jsoup.Jsoup
import apps.amine.bou.readerforselfoss.utils.Config import apps.amine.bou.readerforselfoss.utils.Config
import apps.amine.bou.readerforselfoss.utils.isEmptyOrNullOrNullString import apps.amine.bou.readerforselfoss.utils.isEmptyOrNullOrNullString
@ -128,6 +129,15 @@ data class Item(
return constructUrl(config, "thumbnails", thumbnail) 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 { fun getTitleDecoded(): String {
return Html.fromHtml(title).toString() return Html.fromHtml(title).toString()
} }

View File

@ -53,6 +53,7 @@ import retrofit2.Callback
import retrofit2.Response import retrofit2.Response
import java.net.MalformedURLException import java.net.MalformedURLException
import java.net.URL import java.net.URL
import kotlin.collections.ArrayList
import kotlin.concurrent.thread import kotlin.concurrent.thread
class ArticleFragment : Fragment() { class ArticleFragment : Fragment() {
@ -65,6 +66,7 @@ class ArticleFragment : Fragment() {
private lateinit var contentSource: String private lateinit var contentSource: String
private lateinit var contentImage: String private lateinit var contentImage: String
private lateinit var contentTitle: String private lateinit var contentTitle: String
private lateinit var allImages : ArrayList<String>
private lateinit var editor: SharedPreferences.Editor private lateinit var editor: SharedPreferences.Editor
private lateinit var fab: FloatingActionButton private lateinit var fab: FloatingActionButton
private lateinit var appColors: AppColors private lateinit var appColors: AppColors
@ -116,6 +118,7 @@ class ArticleFragment : Fragment() {
contentTitle = allItems[pageNumber.toInt()].getTitleDecoded() contentTitle = allItems[pageNumber.toInt()].getTitleDecoded()
contentImage = allItems[pageNumber.toInt()].getThumbnail(activity!!) contentImage = allItems[pageNumber.toInt()].getThumbnail(activity!!)
contentSource = allItems[pageNumber.toInt()].sourceAndDateText() contentSource = allItems[pageNumber.toInt()].sourceAndDateText()
allImages = allItems[pageNumber.toInt()].getImages()
prefs = PreferenceManager.getDefaultSharedPreferences(activity) prefs = PreferenceManager.getDefaultSharedPreferences(activity)
editor = prefs.edit() editor = prefs.edit()
@ -545,10 +548,9 @@ class ArticleFragment : Fragment() {
fun performClick(): Boolean { fun performClick(): Boolean {
if (rootView!!.webcontent.hitTestResult.type == WebView.HitTestResult.IMAGE_TYPE || if (rootView!!.webcontent.hitTestResult.type == WebView.HitTestResult.IMAGE_TYPE ||
rootView!!.webcontent.hitTestResult.type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_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>() val position : Int = allImages.indexOf(rootView!!.webcontent.hitTestResult.extra)
allImages.add(rootView!!.webcontent.hitTestResult.extra.toString())
val position : Int = 0
fragmentManager!!.beginTransaction().replace(R.id.reader_activity_view, ImageFragment.newInstance(position, allImages)).addToBackStack(null).commit() fragmentManager!!.beginTransaction().replace(R.id.reader_activity_view, ImageFragment.newInstance(position, allImages)).addToBackStack(null).commit()
return false return false

View File

@ -9,7 +9,7 @@ import kotlinx.android.synthetic.main.fragment_article.view.webcontent
class ImageFragment : Fragment() { class ImageFragment : Fragment() {
private lateinit var position: Number private var position: Int = 0
private lateinit var allImages: ArrayList<String> private lateinit var allImages: ArrayList<String>
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -31,7 +31,7 @@ class ImageFragment : Fragment() {
view.webcontent.settings.setSupportZoom(true) view.webcontent.settings.setSupportZoom(true)
view.webcontent.settings.setBuiltInZoomControls(true) view.webcontent.settings.setBuiltInZoomControls(true)
view.webcontent.settings.setDisplayZoomControls(false) view.webcontent.settings.setDisplayZoomControls(false)
view.webcontent.loadUrl(allImages[0]) view.webcontent.loadUrl(allImages[position])
return view return view
} }