kunfei 3 years ago
parent
commit
2f32b9f377

+ 11 - 0
app/src/main/java/io/legado/app/ui/document/FileManageActivity.kt

@@ -5,12 +5,14 @@ import android.os.Bundle
 import android.view.ViewGroup
 import androidx.activity.viewModels
 import androidx.appcompat.widget.SearchView
+import androidx.core.content.FileProvider
 import androidx.recyclerview.widget.LinearLayoutManager
 import androidx.recyclerview.widget.RecyclerView
 import io.legado.app.R
 import io.legado.app.base.VMBaseActivity
 import io.legado.app.base.adapter.ItemViewHolder
 import io.legado.app.base.adapter.RecyclerAdapter
+import io.legado.app.constant.AppConst
 import io.legado.app.databinding.ActivityFileManageBinding
 import io.legado.app.databinding.ItemFileBinding
 import io.legado.app.databinding.ItemPathPickerBinding
@@ -19,6 +21,7 @@ import io.legado.app.ui.document.utils.FilePickerIcon
 import io.legado.app.ui.widget.recycler.VerticalDivider
 import io.legado.app.utils.ConvertUtils
 import io.legado.app.utils.applyTint
+import io.legado.app.utils.openFileUri
 import io.legado.app.utils.viewbindingdelegate.viewBinding
 import java.io.File
 
@@ -141,6 +144,14 @@ class FileManageActivity : VMBaseActivity<ActivityFileManageBinding, FileManageV
                         viewModel.subDocs.add(item)
                         pathAdapter.setItems(viewModel.subDocs)
                         viewModel.upFiles(item)
+                    } else {
+                        openFileUri(
+                            FileProvider.getUriForFile(
+                                this@FileManageActivity,
+                                AppConst.authority,
+                                item
+                            )
+                        )
                     }
                 }
             }

+ 13 - 11
app/src/main/java/io/legado/app/ui/widget/SelectActionBar.kt

@@ -32,19 +32,21 @@ class SelectActionBar @JvmOverloads constructor(
         .inflate(LayoutInflater.from(context), this, true)
 
     init {
-        setBackgroundColor(context.bottomBackground)
-        elevation = context.elevation
-        binding.cbSelectedAll.setTextColor(primaryTextColor)
-        TintHelper.setTint(binding.cbSelectedAll, context.accentColor, !bgIsLight)
-        binding.ivMenuMore.setColorFilter(disabledColor, PorterDuff.Mode.SRC_IN)
-        binding.cbSelectedAll.setOnCheckedChangeListener { buttonView, isChecked ->
-            if (buttonView.isPressed) {
-                callBack?.selectAll(isChecked)
+        if (!isInEditMode) {
+            setBackgroundColor(context.bottomBackground)
+            elevation = context.elevation
+            binding.cbSelectedAll.setTextColor(primaryTextColor)
+            TintHelper.setTint(binding.cbSelectedAll, context.accentColor, !bgIsLight)
+            binding.ivMenuMore.setColorFilter(disabledColor, PorterDuff.Mode.SRC_IN)
+            binding.cbSelectedAll.setOnCheckedChangeListener { buttonView, isChecked ->
+                if (buttonView.isPressed) {
+                    callBack?.selectAll(isChecked)
+                }
             }
+            binding.btnRevertSelection.setOnClickListener { callBack?.revertSelection() }
+            binding.btnSelectActionMain.setOnClickListener { callBack?.onClickSelectBarMainAction() }
+            binding.ivMenuMore.setOnClickListener { selMenu?.show() }
         }
-        binding.btnRevertSelection.setOnClickListener { callBack?.revertSelection() }
-        binding.btnSelectActionMain.setOnClickListener { callBack?.onClickSelectBarMainAction() }
-        binding.ivMenuMore.setOnClickListener { selMenu?.show() }
     }
 
     fun setMainActionText(text: String) = binding.run {

+ 3 - 0
app/src/main/java/io/legado/app/utils/ContextExtensions.kt

@@ -304,6 +304,7 @@ fun Context.openUrl(url: String) {
         startActivity(IntentHelp.getBrowserIntent(url))
     } catch (e: Exception) {
         toastOnUi(e.localizedMessage ?: "open url error")
+        e.printOnDebug()
     }
 }
 
@@ -312,6 +313,7 @@ fun Context.openUrl(uri: Uri) {
         startActivity(IntentHelp.getBrowserIntent(uri))
     } catch (e: Exception) {
         toastOnUi(e.localizedMessage ?: "open url error")
+        e.printOnDebug()
     }
 }
 
@@ -328,6 +330,7 @@ fun Context.openFileUri(uri: Uri, type: String? = null) {
         startActivity(intent)
     } catch (e: Exception) {
         toastOnUi(e.stackTraceStr)
+        e.printOnDebug()
     }
 }
 

+ 10 - 6
app/src/main/java/io/legado/app/utils/IntentType.kt

@@ -7,21 +7,25 @@ import java.io.File
 @Keep
 object IntentType {
 
-    fun from(uri: Uri): String? {
+    fun from(uri: Uri): String {
         return from(uri.toString())
     }
 
-    fun from(file: File): String? {
+    fun from(file: File): String {
         return from(file.absolutePath)
     }
 
-    fun from(path: String?): String? {
-        return when (path?.substringAfterLast(".")?.lowercase()) {
+    fun from(path: String?): String {
+        val suffix = path
+            ?.substringAfterLast(File.separator)
+            ?.substringAfterLast(".", "")
+            ?.lowercase()
+        return when (suffix) {
             "m4a", "mp3", "mid", "xmf", "ogg", "wav" -> "video/*"
             "3gp", "mp4" -> "audio/*"
             "jpg", "gif", "png", "jpeg", "bmp" -> "image/*"
-            "txt", "json" -> "text/plain"
-            else -> appIntentType?.from(path)
+            "", "txt", "json", "log" -> "text/plain"
+            else -> appIntentType?.from(path) ?: "*/*"
         }
     }
 

+ 2 - 8
app/src/main/res/layout/activity_file_manage.xml

@@ -10,7 +10,7 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         app:layout_constraintTop_toTopOf="parent"
-        app:contentInsetStartWithNavigation="0dp"
+        app:contentInsetRight="24dp"
         app:contentLayout="@layout/view_search" />
 
     <!--path-->
@@ -28,7 +28,7 @@
         android:layout_width="match_parent"
         android:layout_height="0dp"
         android:layout_weight="1"
-        app:layout_constraintBottom_toTopOf="@id/select_action_bar"
+        app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintTop_toBottomOf="@id/rv_path">
 
         <io.legado.app.ui.widget.recycler.scroller.FastScrollRecyclerView
@@ -50,10 +50,4 @@
 
     </FrameLayout>
 
-    <io.legado.app.ui.widget.SelectActionBar
-        android:id="@+id/select_action_bar"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        app:layout_constraintBottom_toBottomOf="parent" />
-
 </androidx.constraintlayout.widget.ConstraintLayout>