Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
IBMS
/
nativeview
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
bef6b035
authored
Feb 22, 2022
by
huangzhicong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
允许起始页输入要访问的地址
parent
1b2d6adb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
5 deletions
+47
-5
app/src/main/java/com/maxrocky/nativeview/fragment/MainFragment.kt
+14
-0
app/src/main/java/com/maxrocky/nativeview/fragment/StartFragment.kt
+31
-4
app/src/main/res/layout/fragment_start.xml
+2
-1
No files found.
app/src/main/java/com/maxrocky/nativeview/fragment/MainFragment.kt
View file @
bef6b035
...
@@ -71,6 +71,20 @@ class MainFragment : Fragment() {
...
@@ -71,6 +71,20 @@ class MainFragment : Fragment() {
result
:
JsResult
?
result
:
JsResult
?
):
Boolean
=
false
):
Boolean
=
false
}
}
wv
.
webViewClient
=
object
:
WebViewClient
()
{
override
fun
shouldOverrideUrlLoading
(
view
:
WebView
?,
url
:
String
?):
Boolean
{
Log
.
d
(
TAG
,
"shouldOverrideUrlLoading old: $url"
)
return
super
.
shouldOverrideUrlLoading
(
view
,
url
)
}
override
fun
shouldOverrideUrlLoading
(
view
:
WebView
?,
request
:
WebResourceRequest
?
):
Boolean
{
Log
.
d
(
TAG
,
"shouldOverrideUrlLoading new: ${request?.url}"
)
return
super
.
shouldOverrideUrlLoading
(
view
,
request
)
}
}
wv
.
settings
.
apply
{
wv
.
settings
.
apply
{
javaScriptEnabled
=
true
javaScriptEnabled
=
true
}
}
...
...
app/src/main/java/com/maxrocky/nativeview/fragment/StartFragment.kt
View file @
bef6b035
...
@@ -5,13 +5,25 @@ import android.view.LayoutInflater
...
@@ -5,13 +5,25 @@ import android.view.LayoutInflater
import
android.view.View
import
android.view.View
import
android.view.ViewGroup
import
android.view.ViewGroup
import
android.widget.Button
import
android.widget.Button
import
android.widget.TextView
import
android.widget.EditText
import
androidx.datastore.preferences.core.edit
import
androidx.datastore.preferences.core.stringPreferencesKey
import
androidx.fragment.app.Fragment
import
androidx.fragment.app.Fragment
import
androidx.lifecycle.lifecycleScope
import
androidx.navigation.fragment.findNavController
import
androidx.navigation.fragment.findNavController
import
com.maxrocky.nativeview.R
import
com.maxrocky.nativeview.R
import
com.maxrocky.nativeview.utils.dataStore
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.flow.collect
import
kotlinx.coroutines.flow.map
import
kotlinx.coroutines.launch
class
StartFragment
:
Fragment
()
{
class
StartFragment
:
Fragment
()
{
private
lateinit
var
urlTextView
:
TextView
companion
object
{
private
const
val
STORAGE_URL
=
"storage_url"
}
private
lateinit
var
urlEditText
:
EditText
private
lateinit
var
button
:
Button
private
lateinit
var
button
:
Button
override
fun
onCreateView
(
override
fun
onCreateView
(
...
@@ -22,11 +34,26 @@ class StartFragment : Fragment() {
...
@@ -22,11 +34,26 @@ class StartFragment : Fragment() {
override
fun
onViewCreated
(
view
:
View
,
savedInstanceState
:
Bundle
?)
{
override
fun
onViewCreated
(
view
:
View
,
savedInstanceState
:
Bundle
?)
{
super
.
onViewCreated
(
view
,
savedInstanceState
)
super
.
onViewCreated
(
view
,
savedInstanceState
)
url
TextView
=
view
.
findViewById
(
R
.
id
.
url
)
url
EditText
=
view
.
findViewById
(
R
.
id
.
url
)
button
=
view
.
findViewById
(
R
.
id
.
enter
)
button
=
view
.
findViewById
(
R
.
id
.
enter
)
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
val
storageKey
=
stringPreferencesKey
(
STORAGE_URL
)
context
?.
dataStore
?.
data
?.
map
{
it
[
storageKey
]
?:
""
}
?.
collect
{
urlEditText
.
setText
(
it
)
}
}
button
.
setOnClickListener
{
button
.
setOnClickListener
{
val
url
=
urlTextView
.
text
.
trim
().
toString
()
val
url
=
urlEditText
.
text
.
trim
().
toString
()
if
(
url
.
isNotEmpty
())
{
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
val
storageKey
=
stringPreferencesKey
(
STORAGE_URL
)
context
?.
dataStore
?.
edit
{
it
[
storageKey
]
=
url
}
}
}
findNavController
().
navigate
(
findNavController
().
navigate
(
R
.
id
.
action_startFragment_to_mainFragment
,
R
.
id
.
action_startFragment_to_mainFragment
,
MainFragment
.
createStartBundle
(
url
)
MainFragment
.
createStartBundle
(
url
)
...
...
app/src/main/res/layout/fragment_start.xml
View file @
bef6b035
...
@@ -14,13 +14,14 @@
...
@@ -14,13 +14,14 @@
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
/>
app:layout_constraintStart_toStartOf=
"parent"
/>
<
TextView
<
EditText
android:id=
"@+id/url"
android:id=
"@+id/url"
android:layout_width=
"0dp"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"10dp"
android:layout_marginStart=
"10dp"
android:layout_marginEnd=
"20dp"
android:layout_marginEnd=
"20dp"
app:layout_constraintTop_toTopOf=
"@id/url_label"
app:layout_constraintTop_toTopOf=
"@id/url_label"
app:layout_constraintBottom_toBottomOf=
"@id/url_label"
app:layout_constraintStart_toEndOf=
"@id/url_label"
app:layout_constraintStart_toEndOf=
"@id/url_label"
app:layout_constraintEnd_toEndOf=
"parent"
/>
app:layout_constraintEnd_toEndOf=
"parent"
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment