mirror of
https://github.com/pppscn/SmsForwarder
synced 2024-11-09 19:10:51 +00:00
优化:在选择Web客户端目录的时候弹出授权管理所有文件访问的权限 #332
This commit is contained in:
parent
103b1f5839
commit
0bb562b43d
@ -1,5 +1,6 @@
|
|||||||
package com.idormy.sms.forwarder.fragment
|
package com.idormy.sms.forwarder.fragment
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
@ -308,30 +309,48 @@ class ServerFragment : BaseFragment<FragmentServerBinding?>(), View.OnClickListe
|
|||||||
XToastUtils.info(String.format(getString(R.string.copied_to_clipboard), url))
|
XToastUtils.info(String.format(getString(R.string.copied_to_clipboard), url))
|
||||||
}
|
}
|
||||||
R.id.btn_path_picker -> {
|
R.id.btn_path_picker -> {
|
||||||
val downloadPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).path
|
// 申请储存权限
|
||||||
val dirList = listSubDir(downloadPath)
|
XXPermissions.with(this)
|
||||||
if (dirList.isEmpty()) {
|
.permission(Permission.MANAGE_EXTERNAL_STORAGE).request(object : OnPermissionCallback {
|
||||||
XToastUtils.error(String.format(getString(R.string.download_first), downloadPath))
|
@SuppressLint("SetTextI18n")
|
||||||
return
|
override fun onGranted(permissions: List<String>, all: Boolean) {
|
||||||
}
|
val downloadPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).path
|
||||||
MaterialDialog.Builder(requireContext()).title(getString(R.string.select_web_client_directory)).content(String.format(getString(R.string.root_directory), downloadPath)).items(dirList).itemsCallbackSingleChoice(0) { _: MaterialDialog?, _: View?, _: Int, text: CharSequence ->
|
val dirList = listSubDir(downloadPath)
|
||||||
val webPath = "$downloadPath/$text"
|
if (dirList.isEmpty()) {
|
||||||
binding!!.etWebPath.setText(webPath)
|
XToastUtils.error(String.format(getString(R.string.download_first), downloadPath))
|
||||||
HttpServerUtils.serverWebPath = webPath
|
return
|
||||||
|
}
|
||||||
|
MaterialDialog.Builder(requireContext()).title(getString(R.string.select_web_client_directory)).content(String.format(getString(R.string.root_directory), downloadPath)).items(dirList).itemsCallbackSingleChoice(0) { _: MaterialDialog?, _: View?, _: Int, text: CharSequence ->
|
||||||
|
val webPath = "$downloadPath/$text"
|
||||||
|
binding!!.etWebPath.setText(webPath)
|
||||||
|
HttpServerUtils.serverWebPath = webPath
|
||||||
|
|
||||||
XToastUtils.info(getString(R.string.restarting_httpserver))
|
XToastUtils.info(getString(R.string.restarting_httpserver))
|
||||||
Intent(appContext, HttpService::class.java).also {
|
Intent(appContext, HttpService::class.java).also {
|
||||||
if (ServiceUtils.isServiceRunning("com.idormy.sms.forwarder.service.HttpService")) {
|
if (ServiceUtils.isServiceRunning("com.idormy.sms.forwarder.service.HttpService")) {
|
||||||
appContext?.stopService(it)
|
appContext?.stopService(it)
|
||||||
Thread.sleep(500)
|
Thread.sleep(500)
|
||||||
appContext?.startService(it)
|
appContext?.startService(it)
|
||||||
} else {
|
} else {
|
||||||
appContext?.startService(it)
|
appContext?.startService(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
refreshButtonText()
|
||||||
|
true // allow selection
|
||||||
|
}.positiveText(R.string.select).negativeText(R.string.cancel).show()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
refreshButtonText()
|
override fun onDenied(permissions: List<String>, never: Boolean) {
|
||||||
true // allow selection
|
if (never) {
|
||||||
}.positiveText(R.string.select).negativeText(R.string.cancel).show()
|
XToastUtils.error(R.string.toast_denied_never)
|
||||||
|
// 如果是被永久拒绝就跳转到应用权限系统设置页面
|
||||||
|
XXPermissions.startPermissionActivity(requireContext(), permissions)
|
||||||
|
} else {
|
||||||
|
XToastUtils.error(R.string.toast_denied)
|
||||||
|
}
|
||||||
|
binding!!.etWebPath.setText(getString(R.string.storage_permission_tips))
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user