mirror of
https://github.com/readrops/Readrops.git
synced 2025-02-11 09:20:51 +01:00
Add WebViewActivity to open item link in webview
This commit is contained in:
parent
2671fdcbbd
commit
232a9f1efa
@ -16,12 +16,12 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
android:usesCleartextTraffic="true"
|
||||
tools:ignore="GoogleAppIndexingWarning">
|
||||
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
|
||||
<activity android:name=".activities.WebViewActivity"></activity>
|
||||
|
||||
<service android:name=".utils.feedscolors.FeedsColorsIntentService" />
|
||||
|
||||
<activity android:name=".activities.SettingsActivity" />
|
||||
|
||||
<activity
|
||||
android:name=".activities.SplashActivity"
|
||||
android:theme="@style/SplashTheme">
|
||||
@ -31,32 +31,27 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".activities.AccountTypeListActivity" />
|
||||
|
||||
<activity
|
||||
android:name=".activities.AddAccountActivity"
|
||||
android:label="@string/add_account" />
|
||||
|
||||
<activity
|
||||
android:name=".activities.ManageFeedsFoldersActivity"
|
||||
android:label="@string/manage_feeds_folders"
|
||||
android:parentActivityName=".activities.MainActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
|
||||
<activity
|
||||
android:name=".activities.MainActivity"
|
||||
android:label="@string/articles"
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
|
||||
<activity
|
||||
android:name=".activities.ItemActivity"
|
||||
android:parentActivityName=".activities.MainActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
|
||||
<activity
|
||||
android:name=".activities.AddFeedActivity"
|
||||
android:label="@string/add_feed_title"
|
||||
android:parentActivityName=".activities.MainActivity" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -0,0 +1,78 @@
|
||||
package com.readrops.app.activities
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import android.webkit.WebResourceRequest
|
||||
import android.webkit.WebSettings
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import com.readrops.app.R
|
||||
import com.readrops.app.databinding.ActivityWebViewBinding
|
||||
|
||||
class WebViewActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityWebViewBinding
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = DataBindingUtil.setContentView(this, R.layout.activity_web_view)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
|
||||
title = ""
|
||||
setWebViewSettings()
|
||||
|
||||
val url: String = intent.getStringExtra(WEB_URL)
|
||||
binding.webView.loadUrl(url)
|
||||
}
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
fun setWebViewSettings() {
|
||||
val settings: WebSettings = binding.webView.settings
|
||||
|
||||
settings.javaScriptEnabled = true
|
||||
settings.setSupportZoom(true)
|
||||
|
||||
binding.webView.webViewClient = object : WebViewClient() {
|
||||
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
|
||||
binding.webView.loadUrl(request?.url.toString())
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onPageFinished(view: WebView?, url: String?) {
|
||||
title = view?.title
|
||||
supportActionBar?.subtitle = Uri.parse(view?.url).host
|
||||
|
||||
super.onPageFinished(view, url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (binding.webView.canGoBack())
|
||||
binding.webView.goBack()
|
||||
else
|
||||
super.onBackPressed()
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
|
||||
when (item?.itemId) {
|
||||
android.R.id.home -> {
|
||||
if (binding.webView.canGoBack())
|
||||
binding.webView.goBack()
|
||||
else
|
||||
finish()
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val WEB_URL = "webUrl"
|
||||
}
|
||||
}
|
17
app/src/main/res/layout/activity_web_view.xml
Normal file
17
app/src/main/res/layout/activity_web_view.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="com.readrops.app.activities.WebViewActivity">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<WebView
|
||||
android:id="@+id/web_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</layout>
|
Loading…
x
Reference in New Issue
Block a user