Commit e1957e67 authored by wanglei's avatar wanglei

...

parent ca612317
......@@ -51,6 +51,7 @@ dependencies {
implementation("com.airbnb.android:lottie:6.4.0")
implementation("com.github.bumptech.glide:glide:4.16.0")
implementation("com.github.angcyo.DslTablayout:TabLayout:3.5.5")
implementation("de.hdodenhof:circleimageview:3.1.0")
//相机
val cameraxVersion = "1.2.2"
......
......@@ -15,6 +15,7 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<application
android:name=".MyApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
......
package com.base.browserwhite.bean
import android.content.Context
import com.base.browserwhite.utils.AssetUtils.WebsiteJson
import com.base.browserwhite.utils.AssetUtils.readJsonFromAsset
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import org.json.JSONObject
......@@ -29,6 +32,14 @@ data class WebSiteBean(
var increase = false
}
val webCategoryBeanList by lazy {
webCategoryBeanList(WebsiteJson)
}
val webSiteGroupBeanList by lazy {
webSiteGroupBeanList(WebsiteJson)
}
fun webCategoryBeanList(json: String): ArrayList<WebCategoryBean> {
val jsonObject = JSONObject(json)
......
......@@ -68,6 +68,9 @@ class WebBrowserActivity : BaseActivity<ActivityWebBrowserBinding>() {
currentFragment?.goForward()
}
}
binding.ivHome.setOnClickListener {
finishToMain()
}
}
private fun addNewWebSite(uri: String) {
......
......@@ -60,11 +60,8 @@ class WevStoreActivity : BaseActivity<ActivityWevStoreBinding>() {
}
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)
webCategoryBean.addAll(webCategoryBeanList)
webSiteGroupBean.addAll(webSiteGroupBeanList)
val imageSize = this@WevStoreActivity.resources.getDimensionPixelSize(R.dimen.dp_30)
launch(Dispatchers.Main) {
......@@ -98,7 +95,7 @@ class WevStoreActivity : BaseActivity<ActivityWevStoreBinding>() {
binding.tabLayout.addView(tabBinding.root)
}
adapter.setData(list)
adapter.setData(webSiteGroupBeanList)
}
}
......
package com.base.browserwhite.ui.adapter
import android.annotation.SuppressLint
import android.graphics.Color
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.base.browserwhite.R
......@@ -12,6 +14,7 @@ import com.base.browserwhite.databinding.ItemWebsiteGridBinding
import com.base.browserwhite.utils.LogEx
import com.base.browserwhite.utils.XmlEx.inflate
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
class WebsiteAdapter(val uiType: Int = 0, val click: (bean: WebSiteBean) -> Unit) :
RecyclerView.Adapter<WebsiteAdapter.WebSiteViewHolder>() {
......@@ -43,7 +46,20 @@ class WebsiteAdapter(val uiType: Int = 0, val click: (bean: WebSiteBean) -> Unit
when (uiType) {
0 -> {
val binding = ItemWebsiteGridBinding.bind(holder.itemView)
binding.ivIcon.setImageResource(bean.localIcon)
if (bean.name == "Increase") {
binding.ivAdd.visibility = View.VISIBLE
binding.ivIcon.visibility = View.GONE
binding.ivAdd.setImageResource(bean.localIcon)
} else {
binding.ivIcon.visibility = View.VISIBLE
binding.ivAdd.visibility = View.GONE
val bordIconName = arrayOf("Ebay", "Bing")
if (bordIconName.contains(bean.name)) {
binding.ivIcon.borderColor = ContextCompat.getColor(context, R.color.color_cbcdd7)
binding.ivIcon.borderWidth = 1
}
Glide.with(context).load(bean.icon_url).into(binding.ivIcon)
}
binding.tvName.text = bean.name
holder.canDrag = !bean.increase
binding.root.setOnClickListener {
......@@ -64,9 +80,10 @@ class WebsiteAdapter(val uiType: Int = 0, val click: (bean: WebSiteBean) -> Unit
}
@SuppressLint("NotifyDataSetChanged")
fun setData(webSiteList: List<WebSiteBean>) {
fun setData(webSiteList: List<WebSiteBean>, addBean: WebSiteBean? = null) {
beanList.clear()
beanList.addAll(webSiteList)
addBean?.let { beanList.add(it) }
notifyDataSetChanged()
}
......
......@@ -12,6 +12,7 @@ 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.bean.WebSiteBean
import com.base.browserwhite.bean.webSiteGroupBeanList
import com.base.browserwhite.databinding.FragmentHomeBinding
import com.base.browserwhite.service.StayNotificationService.Companion.restartStartStayNotification
import com.base.browserwhite.ui.activity.scanqrc.ScanQRCActivity
......@@ -20,6 +21,7 @@ import com.base.browserwhite.ui.activity.webstore.WevStoreActivity
import com.base.browserwhite.ui.adapter.WebsiteAdapter
import com.base.browserwhite.ui.views.DialogViews.showSearchEngineDialog
import com.base.browserwhite.ui.views.itemtouch.MyItemTouchHelperCallBack
import com.base.browserwhite.utils.AppPreferences
class HomeFragment : BaseFragment<FragmentHomeBinding>() {
......@@ -46,24 +48,17 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
itemTouchHelper = ItemTouchHelper(MyItemTouchHelperCallBack())
itemTouchHelper.attachToRecyclerView(binding.rvWeb)
val defaultWebSiteName =
arrayOf("Amazon", "Youtube", "ChatGPT", "Bing", "Twitter", "Wikipedia", "Facebook", "Ebay", "Tiktok", "Whatsapp")
val recommendWebSite = listOf(
WebSiteBean(name = "Amazon").apply { localIcon = R.mipmap.amazon },
WebSiteBean(name = "Youtube").apply { localIcon = R.mipmap.youtube },
WebSiteBean(name = "ChatGPT").apply { localIcon = R.mipmap.chatgpt },
WebSiteBean(name = "Bing").apply { localIcon = R.mipmap.bing },
WebSiteBean(name = "Twitter").apply { localIcon = R.mipmap.twitter },
WebSiteBean(name = "Wikipedia").apply { localIcon = R.mipmap.wikipedia },
WebSiteBean(name = "Facebook").apply { localIcon = R.mipmap.facebook },
WebSiteBean(name = "Ebay").apply { localIcon = R.mipmap.ebay },
WebSiteBean(name = "Tiktok").apply { localIcon = R.mipmap.tiktok },
WebSiteBean(name = "Whatsapp").apply { localIcon = R.mipmap.whatsapp },
WebSiteBean(name = "Increase").apply {
val recommendWebSite = webSiteGroupBeanList.flatMap { it.items }.filter { bean ->
val defaultValue = defaultWebSiteName.contains(bean.name)
AppPreferences.getInstance().getBoolean("${bean.id}_${bean.name}", defaultValue)
}
websiteAdapter.setData(recommendWebSite, WebSiteBean(name = "Increase").apply {
localIcon = R.mipmap.increase
increase = true
},
)
websiteAdapter.setData(recommendWebSite)
})
}
override fun setListener() {
......
package com.base.browserwhite.utils;
import android.content.Context;
import android.content.SharedPreferences;
import com.base.browserwhite.MyApplication;
import java.util.Set;
public class AppPreferences {
private static AppPreferences sInstance;
private SharedPreferences sharedPreferences;
private static final String PREF_FILE_NAME = "app_prefs"; // 偏好文件名
private AppPreferences(Context context) {
sharedPreferences = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
}
public static synchronized AppPreferences getInstance() {
if (sInstance == null) {
sInstance = new AppPreferences(MyApplication.context.getApplicationContext());
}
return sInstance;
}
// 通用 put 方法
public void put(String key, Object value) {
if (value instanceof Integer) {
sharedPreferences.edit().putInt(key, (Integer) value).apply();
} else if (value instanceof Long) {
sharedPreferences.edit().putLong(key, (Long) value).apply();
} else if (value instanceof Float) {
sharedPreferences.edit().putFloat(key, (Float) value).apply();
} else if (value instanceof Boolean) {
sharedPreferences.edit().putBoolean(key, (Boolean) value).apply();
} else if (value instanceof String) {
sharedPreferences.edit().putString(key, (String) value).apply();
} else if (value instanceof Double){
sharedPreferences.edit().putString(key, (String) value.toString()).apply();
} else if(value instanceof Set){
sharedPreferences.edit().putStringSet(key, (Set<String>) value).apply();
}else {
throw new IllegalArgumentException("Unsupported type: " + value.getClass());
}
}
public void put(String key, Object value, boolean isCommit) {
SharedPreferences.Editor editor = sharedPreferences.edit();
if (value instanceof Integer) {
editor.putInt(key, (Integer) value);
} else if (value instanceof Long) {
editor.putLong(key, (Long) value);
} else if (value instanceof Float) {
editor.putFloat(key, (Float) value);
} else if (value instanceof Boolean) {
editor.putBoolean(key, (Boolean) value);
} else if (value instanceof String) {
editor.putString(key, (String) value);
} else if(value instanceof Set){
sharedPreferences.edit().putStringSet(key, (Set<String>) value).apply();
} else {
throw new IllegalArgumentException("Unsupported type: " + value.getClass());
}
// 根据 isCommit 参数的值决定使用 commit() 还是 apply()
if (isCommit) {
editor.commit();
} else {
editor.apply();
}
}
// 存入整数
public void putInt(String key, int value) {
sharedPreferences.edit().putInt(key, value).apply();
}
public void putStringSet(String key, Set value) {
sharedPreferences.edit().putStringSet(key, value).apply();
}
public Set<String> getStringSet(String key, Set<String> defaultValue){
return sharedPreferences.getStringSet(key, defaultValue);
}
// 获取整数
public int getInt(String key, int defaultValue) {
return sharedPreferences.getInt(key, defaultValue);
}
// 存入长整数
public void putLong(String key, long value) {
sharedPreferences.edit().putLong(key, value).apply();
}
// 获取长整数
public long getLong(String key, long defaultValue) {
return sharedPreferences.getLong(key, defaultValue);
}
// 存入浮点数
public void putFloat(String key, float value) {
sharedPreferences.edit().putFloat(key, value).apply();
}
// 获取浮点数
public float getFloat(String key, float defaultValue) {
return sharedPreferences.getFloat(key, defaultValue);
}
// 存入布尔值
public void putBoolean(String key, boolean value) {
sharedPreferences.edit().putBoolean(key, value).apply();
}
// 获取布尔值
public boolean getBoolean(String key, boolean defaultValue) {
return sharedPreferences.getBoolean(key, defaultValue);
}
// 存入字符串
public void putString(String key, String value) {
sharedPreferences.edit().putString(key, value).apply();
}
// 获取字符串
public String getString(String key, String defaultValue) {
return sharedPreferences.getString(key, defaultValue);
}
// 检查某个键是否存在
public boolean contains(String key) {
return sharedPreferences.contains(key);
}
// 移除某个键
public void remove(String key) {
sharedPreferences.edit().remove(key).apply();
}
// 清除所有数据
public void clear() {
sharedPreferences.edit().clear().apply();
}
}
\ No newline at end of file
package com.base.browserwhite.utils
import android.content.Context
import com.base.browserwhite.MyApplication
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
object AssetUtils {
val WebsiteJson by lazy {
MyApplication.context.readJsonFromAsset("navigateWebsiteCfg.json")
}
fun Context.readJsonFromAsset(fileName: String): String {
var json = ""
try {
......
<?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"
......@@ -8,21 +9,37 @@
android:focusable="true"
android:orientation="vertical">
<ImageView
android:id="@+id/iv_icon"
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:padding="8dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/iv_icon"
android:layout_width="60dp"
android:layout_height="60dp"
app:civ_circle_background_color="#FDFDFD"
tools:ignore="ContentDescription"
tools:src="@mipmap/amazon" />
<ImageView
android:id="@+id/iv_add"
android:layout_width="60dp"
android:layout_height="60dp"
android:visibility="gone"
app:civ_circle_background_color="#FDFDFD"
tools:ignore="ContentDescription"
tools:src="@mipmap/amazon" />
</FrameLayout>
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8.5dp"
android:layout_marginBottom="5dp"
android:textColor="@color/black"
android:textSize="13sp"
......
......@@ -3,4 +3,5 @@
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="black_a_70">#B3000000</color>
<color name="color_cbcdd7">#cbcdd7</color>
</resources>
\ 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