pull/66/head
kunfei 5 years ago
parent d41a19bb13
commit b6691472bf
  1. 3
      app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt
  2. 31
      app/src/main/java/io/legado/app/utils/DocumentUtils.kt

@ -6,6 +6,7 @@ import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.text.InputType import android.text.InputType
import android.view.View import android.view.View
import androidx.documentfile.provider.DocumentFile
import androidx.preference.EditTextPreference import androidx.preference.EditTextPreference
import androidx.preference.ListPreference import androidx.preference.ListPreference
import androidx.preference.Preference import androidx.preference.Preference
@ -167,9 +168,11 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference
when (requestCode) { when (requestCode) {
oldDataRequestCode -> if (resultCode == RESULT_OK) { oldDataRequestCode -> if (resultCode == RESULT_OK) {
data?.data?.let { data?.data?.let {
DocumentFile.fromTreeUri(requireContext(), it)?.listFiles()?.forEach {
} }
} }
} }
} }
} }
}

@ -0,0 +1,31 @@
package io.legado.app.utils
import android.content.Context
import android.net.Uri
object DocumentUtils {
fun readText(context: Context, uri: Uri): String? {
readBytes(context, uri)?.let {
return String(it)
}
return null
}
fun readBytes(context: Context, uri: Uri): ByteArray? {
try {
context.contentResolver.openInputStream(uri)?.let {
val len: Int = it.available()
val buffer = ByteArray(len)
it.read(buffer)
it.close()
return buffer
}
} catch (e: Exception) {
e.printStackTrace()
}
return null
}
}
Loading…
Cancel
Save