Commit 5c6f3887 authored by wanglei's avatar wanglei

...

parent 7e2247e0
......@@ -2,11 +2,13 @@ package com.base.browserwhite.ui.fragment
import android.annotation.SuppressLint
import android.app.usage.StorageStatsManager
import android.content.Intent
import android.os.Build
import android.os.Environment
import android.os.StatFs
import android.os.storage.StorageManager
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.base.browserwhite.databinding.FragmentFileBinding
......@@ -39,11 +41,29 @@ class FileFragment : BaseFragment<FragmentFileBinding>() {
FragmentFileBinding.inflate(layoutInflater)
}
@SuppressLint("QueryPermissionsNeeded")
override fun setView() {
showStorage()
adapter = MediaAdapter { view, bean ->
requireContext().showMediaMoreDialog(view, deleteAction = {}, shareAction = {})
requireContext().showMediaMoreDialog(view, deleteAction = {}, shareAction = {
LogEx.logDebug(TAG, "uri=${bean.uri}")
val shareIntent = Intent().apply {
action = Intent.ACTION_SEND
type = bean.mimeType
putExtra(Intent.EXTRA_STREAM, bean.uri)
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
// 可以添加更多额外信息,如主题、文本等
}
val chooserIntent = Intent.createChooser(shareIntent, "Share File")
if (shareIntent.resolveActivity(requireContext().packageManager) != null) {
startActivity(chooserIntent)
} else {
Toast.makeText(requireContext(), "no app can share the file", Toast.LENGTH_SHORT).show()
}
})
}
binding.rvRecent.adapter = adapter
......
......@@ -17,6 +17,7 @@ import com.base.browserwhite.bean.ConstObject.DUCKDUCKGO
import com.base.browserwhite.bean.ConstObject.GOOGLE
import com.base.browserwhite.bean.ConstObject.YAHOO
import com.base.browserwhite.bean.ConstObject.YANDEX
import com.base.browserwhite.databinding.DialogDeleteTipBinding
import com.base.browserwhite.databinding.DialogMediaMoreBinding
import com.base.browserwhite.databinding.DialogMyAccountBinding
import com.base.browserwhite.databinding.DialogPermissonOpenBinding
......@@ -190,8 +191,19 @@ object DialogViews {
}
binding.llShare.setOnClickListener {
dialog.dismiss()
shareAction.invoke()
}
}
fun Context.showDeleteTipDialog() {
val binding = DialogDeleteTipBinding.inflate(LayoutInflater.from(this))
val dialog = AlertDialog.Builder(this).create()
dialog.setView(binding.root)
dialog.show()
dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package com.base.browserwhite.utils
import android.content.Context
import android.database.Cursor
import android.net.Uri
import android.provider.MediaStore
import com.base.browserwhite.bean.ConstObject.MIME_TYPE_APK
import com.base.browserwhite.bean.ConstObject.MIME_TYPE_DOC
......@@ -25,7 +26,7 @@ object MediaStoreUtils {
val list = arrayListOf<MediaBean>()
val projection = arrayOf(
// MediaStore.Files.FileColumns._ID,
MediaStore.Files.FileColumns._ID,
MediaStore.Files.FileColumns.DATA,
// MediaStore.Files.FileColumns.TITLE,
MediaStore.Files.FileColumns.MIME_TYPE,
......@@ -69,7 +70,9 @@ object MediaStoreUtils {
if (cursor != null) {
while (cursor.moveToNext()) {
runCatching {
// val id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns._ID))
val id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns._ID))
val uri = Uri.withAppendedPath(MediaStore.Files.getContentUri("external"), id.toString())
val path = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.DATA))
// val title = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.TITLE))
val mimeType = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.MIME_TYPE))
......@@ -77,7 +80,7 @@ object MediaStoreUtils {
LogEx.logDebug(TAG, "path=$path mimeType=$mimeType")
list.add(
MediaBean(path = path, mimeType = mimeType)
MediaBean(path = path, uri = uri, mimeType = mimeType)
)
}
}
......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:layout_width="300dp"
android:layout_height="150dp"
android:layout_margin="15dp"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="25dp"
app:cardElevation="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tip"
tools:ignore="HardcodedText" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</FrameLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment