Compare commits
10 Commits
v172202040
...
3de95ba6e4
Author | SHA1 | Date | |
---|---|---|---|
3de95ba6e4 | |||
47f00dc694 | |||
584c6869b5 | |||
b0c4b010a2 | |||
e08fc2604f | |||
41386adf4e | |||
59c307323f | |||
41e825bc50 | |||
0bab675560 | |||
55ced4a5fb |
@@ -1,24 +1,22 @@
|
||||
package apps.amine.bou.readerforselfoss.fragments
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.content.res.ColorStateList
|
||||
import android.content.res.TypedArray
|
||||
import android.graphics.Typeface
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.preference.PreferenceManager
|
||||
import android.view.InflateException
|
||||
import android.view.*
|
||||
import androidx.browser.customtabs.CustomTabsIntent
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.widget.NestedScrollView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.webkit.WebSettings
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
@@ -44,6 +42,8 @@ import apps.amine.bou.readerforselfoss.utils.openItemUrl
|
||||
import apps.amine.bou.readerforselfoss.utils.shareLink
|
||||
import apps.amine.bou.readerforselfoss.utils.sourceAndDateText
|
||||
import apps.amine.bou.readerforselfoss.utils.succeeded
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import com.github.rubensousa.floatingtoolbar.FloatingToolbar
|
||||
@@ -410,6 +410,23 @@ class ArticleFragment : Fragment() {
|
||||
rootView!!.webcontent.settings.loadWithOverviewMode = true
|
||||
rootView!!.webcontent.settings.javaScriptEnabled = false
|
||||
|
||||
rootView!!.webcontent.webViewClient = object : WebViewClient() {
|
||||
override fun shouldOverrideUrlLoading(view: WebView?, url : String): Boolean {
|
||||
if (rootView!!.webcontent.hitTestResult.type != WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
|
||||
rootView!!.context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
val gestureDetector = GestureDetector(activity, object : GestureDetector.SimpleOnGestureListener() {
|
||||
override fun onSingleTapUp(e: MotionEvent?): Boolean {
|
||||
return performClick()
|
||||
}
|
||||
})
|
||||
|
||||
rootView!!.webcontent.setOnTouchListener { _, event -> gestureDetector.onTouchEvent(event)}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
rootView!!.webcontent.settings.layoutAlgorithm =
|
||||
WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING
|
||||
@@ -525,5 +542,19 @@ 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
|
||||
|
||||
fragmentManager!!.beginTransaction().replace(R.id.reader_activity_view, ImageFragment.newInstance(position, allImages)).addToBackStack(null).commit()
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,64 @@
|
||||
package apps.amine.bou.readerforselfoss.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.*
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
import apps.amine.bou.readerforselfoss.R
|
||||
import kotlinx.android.synthetic.main.fragment_article.view.webcontent
|
||||
|
||||
class ImageFragment : Fragment() {
|
||||
|
||||
private lateinit var position: Number
|
||||
private lateinit var allImages: ArrayList<String>
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setHasOptionsMenu(true)
|
||||
|
||||
position = arguments!!.getInt("position")
|
||||
allImages = arguments!!.getStringArrayList("allImages")
|
||||
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
(activity as AppCompatActivity).supportActionBar?.setDisplayShowTitleEnabled(false)
|
||||
val view : View = inflater.inflate(R.layout.fragment_image, container, false)
|
||||
|
||||
view.webcontent.visibility = View.VISIBLE
|
||||
view.webcontent.settings.setLoadWithOverviewMode(true)
|
||||
view.webcontent.settings.setUseWideViewPort(true)
|
||||
view.webcontent.settings.setSupportZoom(true)
|
||||
view.webcontent.settings.setBuiltInZoomControls(true)
|
||||
view.webcontent.settings.setDisplayZoomControls(false)
|
||||
view.webcontent.loadUrl(allImages[0])
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
menu.clear()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
(activity as AppCompatActivity).supportActionBar?.setDisplayShowTitleEnabled(true)
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val ARG_POSITION = "position"
|
||||
private const val ARG_IMAGES = "allImages"
|
||||
|
||||
fun newInstance(
|
||||
position: Int,
|
||||
allImages: ArrayList<String>
|
||||
): ImageFragment {
|
||||
val fragment = ImageFragment()
|
||||
val args = Bundle()
|
||||
args.putInt(ARG_POSITION, position)
|
||||
args.putStringArrayList(ARG_IMAGES, allImages)
|
||||
fragment.arguments = args
|
||||
return fragment
|
||||
}
|
||||
}
|
||||
}
|
12
app/src/main/res/layout/fragment_image.xml
Normal file
12
app/src/main/res/layout/fragment_image.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<WebView
|
||||
android:id="@+id/webcontent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
</WebView>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
Reference in New Issue
Block a user