Commit ba9b5a2b authored by wanglei's avatar wanglei

...

parent 439b1930
...@@ -63,5 +63,12 @@ dependencies { ...@@ -63,5 +63,12 @@ dependencies {
implementation("androidx.media3:media3-exoplayer:1.4.0") implementation("androidx.media3:media3-exoplayer:1.4.0")
implementation("androidx.media3:media3-ui:1.4.0") implementation("androidx.media3:media3-ui:1.4.0")
//网络请求和解析
implementation("com.google.code.gson:gson:2.11.0")
// define a BOM and its version
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.12.0"))
// define any required OkHttp artifacts without version
implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")
} }
\ No newline at end of file
...@@ -19,3 +19,11 @@ ...@@ -19,3 +19,11 @@
# If you keep the line number information, uncomment this to # If you keep the line number information, uncomment this to
# hide the original source file name. # hide the original source file name.
#-renamesourcefileattribute SourceFile #-renamesourcefileattribute SourceFile
-keep class com.google.gson.reflect.** { *; }
-keep class com.google.gson.stream.** { *; }
-keepattributes *Annotation*
-keep class * extends com.google.gson.TypeAdapter
-keep class * extends com.google.gson.JsonSerializer
-keep class * extends com.google.gson.Deserializer
-keep class com.google.gson.TypeAdapters{*;}
\ No newline at end of file
package com.base.browserwhite.bean package com.base.browserwhite.bean
import android.graphics.drawable.Drawable import com.google.gson.Gson
import android.net.Uri import com.google.gson.reflect.TypeToken
import org.json.JSONObject
import java.lang.reflect.Type
class WebSiteBean(
data class WebCategoryBean(
val id: Int,
val name: String,
val iconUrl: String,
)
data class WebSiteGroupBean(
val category_id: Int = 0,
val category_name: String = "",
val items: List<WebSiteBean> = listOf()
)
data class WebSiteBean(
val id: Int = 0,
val icon_url: String = "",
val url: String = "",
val name: String = "", val name: String = "",
val icon: Int = 0, val desc: String = "",
val iconUri: Uri = Uri.EMPTY
) { ) {
var localIcon: Int = 0
var increase = false var increase = false
} }
fun webCategoryBeanList(json: String): ArrayList<WebCategoryBean> {
val jsonObject = JSONObject(json)
val dataJsonObject = jsonObject.getJSONObject("data")
val categoryList = dataJsonObject.getJSONArray("category_list")
val list = arrayListOf<WebCategoryBean>()
for (i in 0 until categoryList.length()) {
val webSiteBeanJsonObject = categoryList.getJSONObject(i)
val id = webSiteBeanJsonObject.getInt("id")
val name = webSiteBeanJsonObject.getString("name")
val iconUrl = webSiteBeanJsonObject.getString("icon_url")
list.add(WebCategoryBean(id, name, iconUrl))
}
return list
}
fun webSiteGroupBeanList(json: String): List<WebSiteGroupBean> {
val jsonObject = JSONObject(json)
val dataJsonObject = jsonObject.getJSONObject("data")
val groupsList = dataJsonObject.getJSONArray("groups")
val webSiteGroupBeanType: Type = object : TypeToken<List<WebSiteGroupBean>>() {}.type
return Gson().fromJson(groupsList.toString(), webSiteGroupBeanType)
}
...@@ -2,6 +2,8 @@ package com.base.browserwhite.ui.activity.mediabrowser ...@@ -2,6 +2,8 @@ package com.base.browserwhite.ui.activity.mediabrowser
import android.content.Intent import android.content.Intent
import android.graphics.Color import android.graphics.Color
import android.os.Build
import android.provider.Settings
import androidx.activity.addCallback import androidx.activity.addCallback
import androidx.core.view.updatePadding import androidx.core.view.updatePadding
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
...@@ -14,6 +16,9 @@ import com.base.browserwhite.ui.activity.BaseActivity ...@@ -14,6 +16,9 @@ import com.base.browserwhite.ui.activity.BaseActivity
import com.base.browserwhite.ui.adapter.MediaAdapter import com.base.browserwhite.ui.adapter.MediaAdapter
import com.base.browserwhite.ui.fragment.FileFragment import com.base.browserwhite.ui.fragment.FileFragment
import com.base.browserwhite.utils.BarUtils import com.base.browserwhite.utils.BarUtils
import com.base.browserwhite.utils.IntentEx.installAokAction
import com.base.browserwhite.utils.IntentEx.viewAudioAction
import com.base.browserwhite.utils.IntentEx.viewDocumentAction
import com.base.browserwhite.utils.LogEx import com.base.browserwhite.utils.LogEx
import com.base.browserwhite.utils.MediaStoreUtils.getMediaAudio import com.base.browserwhite.utils.MediaStoreUtils.getMediaAudio
import com.base.browserwhite.utils.MediaStoreUtils.getMediaFile import com.base.browserwhite.utils.MediaStoreUtils.getMediaFile
...@@ -71,7 +76,33 @@ class MediaBrowserActivity : BaseActivity<ActivityMediaBrowserBinding>() { ...@@ -71,7 +76,33 @@ class MediaBrowserActivity : BaseActivity<ActivityMediaBrowserBinding>() {
} }
"Document", "APK", "Music", "Zip" -> { "Document", "APK", "Music", "Zip" -> {
adapter = MediaAdapter(2, moreAction = { view, bean -> adapter = MediaAdapter(2,
clickAction = { bean ->
if (tittle == "Document") {
this.viewDocumentAction(bean.uri, bean.mimeType)
}
if (tittle == "APK") {
try {
this.installAokAction(bean.uri)
} catch (e: Exception) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val intent = Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES)
launcher.launch(intent) {
runCatching {
this.installAokAction(bean.uri)
}
}
}
}
}
if (tittle == "Zip") {
}
if (tittle == "Music") {
this.viewAudioAction(bean.uri, bean.mimeType)
}
},
moreAction = { view, bean ->
FileFragment.moreAction(this, view, bean, adapter) FileFragment.moreAction(this, view, bean, adapter)
}) })
binding.rv.layoutManager = LinearLayoutManager(this) binding.rv.layoutManager = LinearLayoutManager(this)
......
...@@ -3,17 +3,26 @@ package com.base.browserwhite.ui.activity.webstore ...@@ -3,17 +3,26 @@ package com.base.browserwhite.ui.activity.webstore
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.graphics.Color import android.graphics.Color
import androidx.core.view.updatePadding import androidx.core.view.updatePadding
import androidx.lifecycle.lifecycleScope
import com.base.browserwhite.bean.WebCategoryBean
import com.base.browserwhite.bean.WebSiteGroupBean
import com.base.browserwhite.bean.webCategoryBeanList
import com.base.browserwhite.bean.webSiteGroupBeanList
import com.base.browserwhite.databinding.ActivityWevStoreBinding import com.base.browserwhite.databinding.ActivityWevStoreBinding
import com.base.browserwhite.databinding.ItemTabWebstoreBinding import com.base.browserwhite.databinding.ItemTabWebstoreBinding
import com.base.browserwhite.ui.activity.BaseActivity import com.base.browserwhite.ui.activity.BaseActivity
import com.base.browserwhite.utils.AssetUtils.readJsonFromAsset
import com.base.browserwhite.utils.BarUtils import com.base.browserwhite.utils.BarUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
class WevStoreActivity : BaseActivity<ActivityWevStoreBinding>() { class WevStoreActivity : BaseActivity<ActivityWevStoreBinding>() {
override val binding: ActivityWevStoreBinding by lazy { override val binding: ActivityWevStoreBinding by lazy {
ActivityWevStoreBinding.inflate(layoutInflater) ActivityWevStoreBinding.inflate(layoutInflater)
} }
private val webCategoryBean: ArrayList<WebCategoryBean> = arrayListOf()
private val webSiteGroupBean: ArrayList<WebSiteGroupBean> = arrayListOf()
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun initView() { override fun initView() {
...@@ -21,11 +30,24 @@ class WevStoreActivity : BaseActivity<ActivityWevStoreBinding>() { ...@@ -21,11 +30,24 @@ class WevStoreActivity : BaseActivity<ActivityWevStoreBinding>() {
BarUtils.setStatusBarColor(this, Color.TRANSPARENT) BarUtils.setStatusBarColor(this, Color.TRANSPARENT)
binding.root.updatePadding(top = BarUtils.getStatusBarHeight()) binding.root.updatePadding(top = BarUtils.getStatusBarHeight())
repeat(5) { initData()
val itemTab = ItemTabWebstoreBinding.inflate(layoutInflater) }
itemTab.tv.text = "Socialize"
binding.tabLayout.addView(itemTab.root) private fun initData() = lifecycleScope.launch(Dispatchers.IO) {
val json = readJsonFromAsset("navigateWebsiteCfg.json")
val beanList = webCategoryBeanList(json)
webCategoryBean.addAll(beanList)
val list = webSiteGroupBeanList(json)
webSiteGroupBean.addAll(list)
launch(Dispatchers.Main) {
webCategoryBean.forEach { bean ->
val tabBinding = ItemTabWebstoreBinding.inflate(layoutInflater)
tabBinding.tv.text = bean.name
binding.tabLayout.addView(tabBinding.root)
}
} }
} }
} }
\ No newline at end of file
package com.base.browserwhite.ui.adapter
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.base.browserwhite.bean.WebSiteGroupBean
class WebSiteGroupAdapter : RecyclerView.Adapter<WebSiteGroupAdapter.GroupViewHolder>() {
val beanList = arrayListOf<WebSiteGroupBean>()
inner class GroupViewHolder(view: View) : ViewHolder(view)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GroupViewHolder {
TODO("Not yet implemented")
}
override fun getItemCount(): Int {
return beanList.size
}
override fun onBindViewHolder(holder: GroupViewHolder, position: Int) {
TODO("Not yet implemented")
}
}
\ No newline at end of file
...@@ -32,7 +32,7 @@ class WebsiteAdapter(val click: (bean: WebSiteBean) -> Unit) : RecyclerView.Adap ...@@ -32,7 +32,7 @@ class WebsiteAdapter(val click: (bean: WebSiteBean) -> Unit) : RecyclerView.Adap
override fun onBindViewHolder(holder: WebSiteViewHolder, position: Int) { override fun onBindViewHolder(holder: WebSiteViewHolder, position: Int) {
val binding = ItemWebsiteGridBinding.bind(holder.itemView) val binding = ItemWebsiteGridBinding.bind(holder.itemView)
val bean = beanList[position] val bean = beanList[position]
binding.ivIcon.setImageResource(bean.icon) binding.ivIcon.setImageResource(bean.localIcon)
binding.tvName.text = bean.name binding.tvName.text = bean.name
holder.canDrag = !bean.increase holder.canDrag = !bean.increase
binding.root.setOnClickListener { binding.root.setOnClickListener {
......
...@@ -48,17 +48,20 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() { ...@@ -48,17 +48,20 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
val recommendWebSite = listOf( val recommendWebSite = listOf(
WebSiteBean("Amazon", R.mipmap.amazon), WebSiteBean(name = "Amazon").apply { localIcon = R.mipmap.amazon },
WebSiteBean("Youtube", R.mipmap.youtube), WebSiteBean(name = "Youtube").apply { localIcon = R.mipmap.youtube },
WebSiteBean("ChatGPT", R.mipmap.chatgpt), WebSiteBean(name = "ChatGPT").apply { localIcon = R.mipmap.chatgpt },
WebSiteBean("Bing", R.mipmap.bing), WebSiteBean(name = "Bing").apply { localIcon = R.mipmap.bing },
WebSiteBean("Twitter", R.mipmap.twitter), WebSiteBean(name = "Twitter").apply { localIcon = R.mipmap.twitter },
WebSiteBean("Wikipedia", R.mipmap.wikipedia), WebSiteBean(name = "Wikipedia").apply { localIcon = R.mipmap.wikipedia },
WebSiteBean("Facebook", R.mipmap.facebook), WebSiteBean(name = "Facebook").apply { localIcon = R.mipmap.facebook },
WebSiteBean("Ebay", R.mipmap.ebay), WebSiteBean(name = "Ebay").apply { localIcon = R.mipmap.ebay },
WebSiteBean("Tiktok", R.mipmap.tiktok), WebSiteBean(name = "Tiktok").apply { localIcon = R.mipmap.tiktok },
WebSiteBean("Whatsapp", R.mipmap.whatsapp), WebSiteBean(name = "Whatsapp").apply { localIcon = R.mipmap.whatsapp },
WebSiteBean("Increase", R.mipmap.increase).apply { increase = true }, WebSiteBean(name = "Increase").apply {
localIcon = R.mipmap.increase
increase = true
},
) )
websiteAdapter.setData(recommendWebSite) websiteAdapter.setData(recommendWebSite)
} }
......
package com.base.browserwhite.utils
import android.content.Context
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
object AssetUtils {
fun Context.readJsonFromAsset(fileName: String): String {
var json = ""
try {
val assetManager = this.assets
val inputStream = assetManager.open(fileName)
val reader = BufferedReader(InputStreamReader(inputStream))
var line: String?
val jsonString = StringBuilder()
while (reader.readLine().also { line = it } != null) {
jsonString.append(line)
}
reader.close()
inputStream.close()
json = jsonString.toString()
} catch (e: IOException) {
e.printStackTrace()
}
return json
}
}
\ No newline at end of file
...@@ -6,14 +6,14 @@ import android.content.Intent ...@@ -6,14 +6,14 @@ import android.content.Intent
import android.net.Uri import android.net.Uri
import android.widget.Toast import android.widget.Toast
@SuppressLint("QueryPermissionsNeeded")
object IntentEx { object IntentEx {
@SuppressLint("QueryPermissionsNeeded")
fun Context.shareAction(uri: Uri, mimeType: String) { fun Context.shareAction(uri: Uri, mimeType: String) {
val shareIntent = Intent().apply { val shareIntent = Intent().apply {
action = Intent.ACTION_SEND action = Intent.ACTION_SEND
type = mimeType type = mimeType
putExtra(Intent.EXTRA_STREAM,uri) putExtra(Intent.EXTRA_STREAM, uri)
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
// 可以添加更多额外信息,如主题、文本等 // 可以添加更多额外信息,如主题、文本等
} }
...@@ -24,4 +24,47 @@ object IntentEx { ...@@ -24,4 +24,47 @@ object IntentEx {
Toast.makeText(this, "no app can share the file", Toast.LENGTH_SHORT).show() Toast.makeText(this, "no app can share the file", Toast.LENGTH_SHORT).show()
} }
} }
fun Context.viewDocumentAction(uri: Uri, mimeType: String) {
val viewIntent = Intent().apply {
action = Intent.ACTION_VIEW
setDataAndType(uri, mimeType)
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
// 可以添加更多额外信息,如主题、文本等
}
val chooserIntent = Intent.createChooser(viewIntent, "Share File")
if (chooserIntent.resolveActivity(this.packageManager) != null) {
this.startActivity(viewIntent)
} else {
Toast.makeText(this, "no app can open the file", Toast.LENGTH_SHORT).show()
}
}
fun Context.viewAudioAction(uri: Uri, mimeType: String) {
// 构建一个Intent,使用ACTION_VIEW操作
val intent = Intent(Intent.ACTION_VIEW)
intent.setDataAndType(uri, mimeType)
// 设置标志,以便Intent可以选择其他应用来完成这个操作
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
// 尝试启动Intent
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent)
} else {
// 如果没有应用可以处理这个Intent,可以在这里处理错误
// 例如,显示一个Toast消息
Toast.makeText(this, "no app can play the audio", Toast.LENGTH_SHORT).show()
}
}
fun Context.installAokAction(uri: Uri) {
val installIntent = Intent(Intent.ACTION_VIEW)
installIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
installIntent.setDataAndType(uri, "application/vnd.android.package-archive")
installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(installIntent)
}
} }
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#0571ED" />
<corners android:radius="2dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#F3F4F6" />
<corners android:radius="10dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginHorizontal="6dp"
android:layout_marginVertical="5dp"
android:background="@drawable/bg_f3f4f6_10"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp"
tools:ignore="ContentDescription" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginHorizontal="8dp"
android:layout_weight="1"
android:text="Reddit"
android:textSize="17sp"
tools:ignore="HardcodedText" />
<ImageView
android:id="@+id/iv_select_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="15dp"
tools:ignore="ContentDescription"
tools:src="@mipmap/w_tianjia" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="12dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:orientation="horizontal">
<View
android:layout_width="4dp"
android:layout_height="15dp"
android:layout_gravity="center_vertical"
android:background="@drawable/bg_0571ed_16" />
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="6dp"
android:textColor="@color/black"
android:textSize="17sp"
android:textStyle="bold"
tools:text="Socialize" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_marginTop="10dp"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="2"
tools:listitem="@layout/item_website_grid_2" />
</LinearLayout>
\ 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