|
|
|
@ -12,6 +12,7 @@ import android.view.Gravity |
|
|
|
|
import android.view.LayoutInflater |
|
|
|
|
import android.view.View |
|
|
|
|
import android.view.ViewGroup |
|
|
|
|
import androidx.documentfile.provider.DocumentFile |
|
|
|
|
import androidx.fragment.app.DialogFragment |
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
@ -20,11 +21,13 @@ import io.legado.app.R |
|
|
|
|
import io.legado.app.base.adapter.ItemViewHolder |
|
|
|
|
import io.legado.app.base.adapter.SimpleRecyclerAdapter |
|
|
|
|
import io.legado.app.constant.Bus |
|
|
|
|
import io.legado.app.help.FileHelp |
|
|
|
|
import io.legado.app.help.ImageLoader |
|
|
|
|
import io.legado.app.help.ReadBookConfig |
|
|
|
|
import io.legado.app.help.permission.Permissions |
|
|
|
|
import io.legado.app.help.permission.PermissionsCompat |
|
|
|
|
import io.legado.app.ui.book.read.Help |
|
|
|
|
import io.legado.app.utils.DocumentUtils |
|
|
|
|
import io.legado.app.utils.FileUtils |
|
|
|
|
import io.legado.app.utils.getCompatColor |
|
|
|
|
import io.legado.app.utils.postEvent |
|
|
|
@ -32,6 +35,7 @@ import kotlinx.android.synthetic.main.dialog_read_bg_text.* |
|
|
|
|
import kotlinx.android.synthetic.main.item_bg_image.view.* |
|
|
|
|
import org.jetbrains.anko.sdk27.listeners.onCheckedChange |
|
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
|
import java.io.File |
|
|
|
|
|
|
|
|
|
class BgTextConfigDialog : DialogFragment() { |
|
|
|
|
|
|
|
|
@ -133,17 +137,10 @@ class BgTextConfigDialog : DialogFragment() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun selectImage() { |
|
|
|
|
PermissionsCompat.Builder(this) |
|
|
|
|
.addPermissions(Permissions.READ_EXTERNAL_STORAGE, Permissions.WRITE_EXTERNAL_STORAGE) |
|
|
|
|
.rationale(R.string.bg_image_per) |
|
|
|
|
.onGranted { |
|
|
|
|
val intent = Intent(Intent.ACTION_GET_CONTENT) |
|
|
|
|
intent.addCategory(Intent.CATEGORY_OPENABLE) |
|
|
|
|
intent.type = "image/*" |
|
|
|
|
startActivityForResult(intent, resultSelectBg) |
|
|
|
|
Unit |
|
|
|
|
} |
|
|
|
|
.request() |
|
|
|
|
val intent = Intent(Intent.ACTION_GET_CONTENT) |
|
|
|
|
intent.addCategory(Intent.CATEGORY_OPENABLE) |
|
|
|
|
intent.type = "image/*" |
|
|
|
|
startActivityForResult(intent, resultSelectBg) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class BgAdapter(context: Context) : |
|
|
|
@ -170,11 +167,37 @@ class BgTextConfigDialog : DialogFragment() { |
|
|
|
|
when (requestCode) { |
|
|
|
|
resultSelectBg -> { |
|
|
|
|
if (resultCode == RESULT_OK) { |
|
|
|
|
data?.data?.let { |
|
|
|
|
FileUtils.getPath(requireContext(), it)?.let { path -> |
|
|
|
|
ReadBookConfig.getConfig().setBg(2, path) |
|
|
|
|
ReadBookConfig.upBg() |
|
|
|
|
postEvent(Bus.UP_CONFIG, false) |
|
|
|
|
data?.data?.let { uri -> |
|
|
|
|
if (DocumentFile.isDocumentUri(requireContext(), uri)) { |
|
|
|
|
val doc = DocumentFile.fromSingleUri(requireContext(), uri) |
|
|
|
|
doc?.let { |
|
|
|
|
var file = requireContext().getExternalFilesDir(null) |
|
|
|
|
?: requireContext().filesDir |
|
|
|
|
file = |
|
|
|
|
FileHelp.getFile(file.absolutePath + File.separator + "bg" + File.separator + doc.name) |
|
|
|
|
DocumentUtils.readBytes(requireContext(), uri)?.let { |
|
|
|
|
file.writeBytes(it) |
|
|
|
|
ReadBookConfig.getConfig().setBg(2, file.absolutePath) |
|
|
|
|
ReadBookConfig.upBg() |
|
|
|
|
postEvent(Bus.UP_CONFIG, false) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
PermissionsCompat.Builder(this) |
|
|
|
|
.addPermissions( |
|
|
|
|
Permissions.READ_EXTERNAL_STORAGE, |
|
|
|
|
Permissions.WRITE_EXTERNAL_STORAGE |
|
|
|
|
) |
|
|
|
|
.rationale(R.string.bg_image_per) |
|
|
|
|
.onGranted { |
|
|
|
|
FileUtils.getPath(requireContext(), uri)?.let { path -> |
|
|
|
|
ReadBookConfig.getConfig().setBg(2, path) |
|
|
|
|
ReadBookConfig.upBg() |
|
|
|
|
postEvent(Bus.UP_CONFIG, false) |
|
|
|
|
} |
|
|
|
|
Unit |
|
|
|
|
} |
|
|
|
|
.request() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|