mirror of
https://github.com/zhanghai/MaterialFiles
synced 2024-07-09 03:55:50 +00:00
[Feature] Add quick settings tile placement for FTP server.
Fixes: #671
This commit is contained in:
parent
39a46f4376
commit
65456a326d
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Hai Zhang <dreaming.in.code.zh@gmail.com>
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
package me.zhanghai.android.files.ftpserver
|
||||
|
||||
import android.app.StatusBarManager
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.util.AttributeSet
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.annotation.StyleRes
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.preference.Preference
|
||||
import me.zhanghai.android.files.R
|
||||
import me.zhanghai.android.files.compat.getSystemServiceCompat
|
||||
import me.zhanghai.android.files.compat.mainExecutorCompat
|
||||
import me.zhanghai.android.files.util.requestAddTileService
|
||||
import me.zhanghai.android.files.util.showToast
|
||||
|
||||
class FtpServerAddTilePreference : Preference {
|
||||
constructor(context: Context) : super(context)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet?, @AttrRes defStyleAttr: Int) : super(
|
||||
context, attrs, defStyleAttr
|
||||
)
|
||||
|
||||
constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet?,
|
||||
@AttrRes defStyleAttr: Int,
|
||||
@StyleRes defStyleRes: Int
|
||||
) : super(context, attrs, defStyleAttr, defStyleRes)
|
||||
|
||||
init {
|
||||
isPersistent = false
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
||||
override fun onClick() {
|
||||
val statusBarManager = context.getSystemServiceCompat(StatusBarManager::class.java)
|
||||
statusBarManager.requestAddTileService(
|
||||
FtpServerTileService::class.java, context.mainExecutorCompat
|
||||
) { result ->
|
||||
val resultRes = when (result) {
|
||||
StatusBarManager.TILE_ADD_REQUEST_RESULT_TILE_NOT_ADDED ->
|
||||
return@requestAddTileService
|
||||
StatusBarManager.TILE_ADD_REQUEST_RESULT_TILE_ALREADY_ADDED ->
|
||||
R.string.ftp_server_add_tile_result_already_added
|
||||
StatusBarManager.TILE_ADD_REQUEST_RESULT_TILE_ADDED ->
|
||||
R.string.ftp_server_add_tile_result_added
|
||||
else -> R.string.ftp_server_add_tile_result_error
|
||||
}
|
||||
context.showToast(resultRes)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Hai Zhang <dreaming.in.code.zh@gmail.com>
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
package me.zhanghai.android.files.util
|
||||
|
||||
import android.app.StatusBarManager
|
||||
import android.content.ComponentName
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.drawable.Icon
|
||||
import android.os.Build
|
||||
import android.service.quicksettings.TileService
|
||||
import androidx.annotation.RequiresApi
|
||||
import me.zhanghai.android.files.app.application
|
||||
import me.zhanghai.android.files.app.packageManager
|
||||
import java.util.concurrent.Executor
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
||||
fun StatusBarManager.requestAddTileService(
|
||||
serviceClass: Class<out TileService>,
|
||||
resultExecutor: Executor,
|
||||
resultCallback: (Int) -> Unit
|
||||
) {
|
||||
val application = application
|
||||
val componentName = ComponentName(application, serviceClass)
|
||||
val packageManager = packageManager
|
||||
val serviceInfo = packageManager.getServiceInfo(
|
||||
componentName,
|
||||
PackageManager.MATCH_DIRECT_BOOT_AWARE or PackageManager.MATCH_DIRECT_BOOT_UNAWARE
|
||||
)
|
||||
val label = serviceInfo.loadLabel(packageManager)
|
||||
val icon = Icon.createWithResource(application, serviceInfo.iconResource)
|
||||
requestAddTileService(componentName, label, icon, resultExecutor, resultCallback)
|
||||
}
|
10
app/src/main/res/values-v33/donottranslate_prefs.xml
Normal file
10
app/src/main/res/values-v33/donottranslate_prefs.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright (c) 2023 Hai Zhang <dreaming.in.code.zh@gmail.com>
|
||||
~ All Rights Reserved.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<bool name="pref_visible_ftp_server_add_tile">true</bool>
|
||||
</resources>
|
|
@ -522,6 +522,10 @@
|
|||
<string name="ftp_server_url_summary_no_local_inet_address">无法获取本地 IP 地址</string>
|
||||
<string name="ftp_server_url_menu_copy_url">复制网址</string>
|
||||
<string name="ftp_server_url_menu_copy_password">复制密码</string>
|
||||
<string name="ftp_server_add_tile_title">添加到“快捷设置”</string>
|
||||
<string name="ftp_server_add_tile_result_added">已将“FTP 服务器”添加到“快捷设置”</string>
|
||||
<string name="ftp_server_add_tile_result_already_added">“FTP 服务器”已被添加到“快捷设置”</string>
|
||||
<string name="ftp_server_add_tile_result_error">将“FTP 服务器”添加到“快捷设置”时发生错误</string>
|
||||
<string name="ftp_server_configuration_title">配置</string>
|
||||
<string name="ftp_server_anonymous_login_title">匿名登录</string>
|
||||
<string name="ftp_server_username_title">用户名</string>
|
||||
|
|
|
@ -522,6 +522,10 @@
|
|||
<string name="ftp_server_url_summary_no_local_inet_address">無法擷取本機 IP 位址</string>
|
||||
<string name="ftp_server_url_menu_copy_url">複製網址</string>
|
||||
<string name="ftp_server_url_menu_copy_password">複製密碼</string>
|
||||
<string name="ftp_server_add_tile_title">加入「快速設定」選單</string>
|
||||
<string name="ftp_server_add_tile_result_added">已將「FTP 伺服器」加入「快速設定」選單</string>
|
||||
<string name="ftp_server_add_tile_result_already_added">「FTP 伺服器」已被加入「快速設定」選單</string>
|
||||
<string name="ftp_server_add_tile_result_error">將「FTP 伺服器」加入「快速設定」選單時發生錯誤</string>
|
||||
<string name="ftp_server_configuration_title">配置</string>
|
||||
<string name="ftp_server_anonymous_login_title">匿名登入</string>
|
||||
<string name="ftp_server_username_title">使用者名稱</string>
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
<string name="pref_key_create_archive_type">key_create_archive_type</string>
|
||||
|
||||
<string name="pref_key_ftp_server_state">key_ftp_server_state</string>
|
||||
<bool name="pref_visible_ftp_server_add_tile">false</bool>
|
||||
<string name="pref_key_ftp_server_anonymous_login">key_ftp_server_anonymous_login</string>
|
||||
<bool name="pref_default_value_ftp_server_anonymous_login">true</bool>
|
||||
<string name="pref_key_ftp_server_username">key_ftp_server_username</string>
|
||||
|
|
|
@ -653,6 +653,10 @@
|
|||
<string name="ftp_server_url_summary_no_local_inet_address">Cannot retrieve local IP address</string>
|
||||
<string name="ftp_server_url_menu_copy_url">Copy URL</string>
|
||||
<string name="ftp_server_url_menu_copy_password">Copy password</string>
|
||||
<string name="ftp_server_add_tile_title">Add to Quick Settings</string>
|
||||
<string name="ftp_server_add_tile_result_added">\"FTP server\" has been added to Quick Settings</string>
|
||||
<string name="ftp_server_add_tile_result_already_added">\"FTP server\" is already added to Quick Settings</string>
|
||||
<string name="ftp_server_add_tile_result_error">Error while adding \"FTP server\" to Quick Settings</string>
|
||||
<string name="ftp_server_configuration_title">Configuration</string>
|
||||
<string name="ftp_server_anonymous_login_title">Anonymous login</string>
|
||||
<string name="ftp_server_username_title">Username</string>
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
<me.zhanghai.android.files.ftpserver.FtpServerUrlPreference
|
||||
android:title="@string/ftp_server_url_title" />
|
||||
|
||||
<me.zhanghai.android.files.ftpserver.FtpServerAddTilePreference
|
||||
android:title="@string/ftp_server_add_tile_title"
|
||||
app:isPreferenceVisible="@bool/pref_visible_ftp_server_add_tile" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/ftp_server_configuration_title"
|
||||
android:dependency="@string/pref_key_ftp_server_state">
|
||||
|
|
Loading…
Reference in New Issue
Block a user