add url input to use user's lobechat mirror
This commit is contained in:
parent
38d2280c93
commit
dac1709acd
9 changed files with 101 additions and 36 deletions
|
|
@ -2,7 +2,7 @@
|
|||
<project version="4">
|
||||
<component name="deploymentTargetSelector">
|
||||
<selectionStates>
|
||||
<SelectionState runConfigName="app">
|
||||
<SelectionState runConfigName="Unnamed">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
</SelectionState>
|
||||
</selectionStates>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,12 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
|
||||
<!-- 允许应用访问互联网 -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
|
||||
|
||||
<!-- 添加 namespace -->
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
|
@ -18,9 +25,4 @@
|
|||
</activity>
|
||||
</application>
|
||||
|
||||
<!-- 允许应用访问互联网 -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
</manifest>
|
||||
|
|
|
|||
|
|
@ -18,23 +18,24 @@ import android.view.View
|
|||
import androidx.appcompat.app.AlertDialog
|
||||
import android.util.Log
|
||||
import android.provider.Settings
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var webView: WebView
|
||||
private var filePathCallback: ValueCallback<Array<Uri>>? = null
|
||||
private lateinit var fileChooserLauncher: ActivityResultLauncher<Intent>
|
||||
|
||||
private lateinit var urlInputLayout: ConstraintLayout
|
||||
private lateinit var urlInput: EditText
|
||||
private lateinit var loadUrlButton: Button
|
||||
private var filePathCallback: ValueCallback<Array<Uri>>? = null
|
||||
private lateinit var fileChooserLauncher: ActivityResultLauncher<Intent>
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
// 初始化视图组件
|
||||
webView = findViewById(R.id.webview)
|
||||
webView = findViewById(R.id.webView)
|
||||
urlInputLayout = findViewById(R.id.urlInputLayout)
|
||||
urlInput = findViewById(R.id.urlInput)
|
||||
loadUrlButton = findViewById(R.id.loadUrlButton)
|
||||
|
||||
|
|
@ -80,9 +81,6 @@ class MainActivity : AppCompatActivity() {
|
|||
});
|
||||
""".trimIndent(), null
|
||||
)
|
||||
// 隐藏输入框和按钮
|
||||
urlInput.visibility = View.GONE
|
||||
loadUrlButton.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -122,6 +120,10 @@ class MainActivity : AppCompatActivity() {
|
|||
|
||||
// 加载用户输入的 URL
|
||||
webView.loadUrl(url)
|
||||
|
||||
// 切换视图:隐藏 URL 输入部分并显示 WebView
|
||||
urlInputLayout.visibility = View.GONE
|
||||
webView.visibility = View.VISIBLE
|
||||
} else {
|
||||
Toast.makeText(this, "Please enter a valid URL", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
|
|
|||
13
app/src/main/res/drawable/button_rounded_background.xml
Normal file
13
app/src/main/res/drawable/button_rounded_background.xml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/black"/> <!-- 按钮的背景颜色,可以更改为你喜欢的颜色 -->
|
||||
<corners android:radius="12dp"/> <!-- 设置圆角半径,12dp 可以根据需要进行调整 -->
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:color="@color/grey_light"/> <!-- 按钮的边框颜色,可以修改 -->
|
||||
<padding
|
||||
android:left="12dp"
|
||||
android:top="8dp"
|
||||
android:right="12dp"
|
||||
android:bottom="8dp"/> <!-- 设置按钮的内边距 -->
|
||||
</shape>
|
||||
BIN
app/src/main/res/drawable/ic_logo.png
Normal file
BIN
app/src/main/res/drawable/ic_logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.1 KiB |
6
app/src/main/res/drawable/search_box_background.xml
Normal file
6
app/src/main/res/drawable/search_box_background.xml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/grey_light"/>
|
||||
<corners android:radius="12dp"/>
|
||||
<stroke android:width="1dp" android:color="@color/black"/>
|
||||
</shape>
|
||||
|
|
@ -1,29 +1,67 @@
|
|||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/urlInput"
|
||||
<!-- URL 输入部分,包括 Logo、URL 输入框和提交按钮 -->
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/urlInputLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Enter your server URL"
|
||||
android:inputType="textUri"
|
||||
android:padding="16dp"
|
||||
android:layout_margin="16dp"
|
||||
android:layout_alignParentTop="true"/>
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<Button
|
||||
android:id="@+id/loadUrlButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Load URL"
|
||||
android:layout_below="@id/urlInput"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginStart="16dp"/>
|
||||
<!-- Logo 图片 -->
|
||||
<ImageView
|
||||
android:id="@+id/appLogo"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="200dp"
|
||||
android:layout_marginTop="32dp"
|
||||
android:contentDescription="App Logo"
|
||||
android:src="@drawable/ic_logo"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<!-- 输入框,用于输入 URL -->
|
||||
<EditText
|
||||
android:id="@+id/urlInput"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:background="@drawable/search_box_background"
|
||||
android:hint="Enter your server URL"
|
||||
android:inputType="textUri"
|
||||
android:padding="12dp"
|
||||
android:textColor="@android:color/black"
|
||||
android:textColorHint="@color/black"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/appLogo" />
|
||||
|
||||
<!-- 提交按钮,用于加载用户输入的 URL -->
|
||||
<Button
|
||||
android:id="@+id/loadUrlButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="提交"
|
||||
app:layout_constraintTop_toBottomOf="@id/urlInput"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:layout_marginTop="16dp"
|
||||
android:textColor="#fff"
|
||||
android:background="@drawable/button_rounded_background"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<!-- WebView 控件,用于显示加载的网页 -->
|
||||
<WebView
|
||||
android:id="@+id/webview"
|
||||
android:id="@+id/webView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@id/loadUrlButton"/>
|
||||
</RelativeLayout>
|
||||
android:visibility="gone"/> <!-- 默认隐藏 WebView,直到用户点击提交按钮 -->
|
||||
|
||||
</FrameLayout>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@
|
|||
<color name="purple_700">#FF3700B3</color>
|
||||
<color name="teal_200">#FF03DAC5</color>
|
||||
<color name="teal_700">#FF018786</color>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="black">#0D0D0D</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
<color name="grey">#F4F4F4</color>
|
||||
<color name="grey_light">#f8f8f8</color>
|
||||
<color name="border">#9b9b9b</color>
|
||||
</resources>
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
<resources>
|
||||
<string name="app_name">lobchat</string>
|
||||
<string name="enter_your_server_url">Enter your server URL</string>
|
||||
</resources>
|
||||
Loading…
Reference in a new issue