no impl set

This commit is contained in:
LUX-Timber 2024-04-10 16:04:25 +08:00
parent ed89859d3a
commit deb979c591
14 changed files with 466 additions and 48 deletions

View File

@ -3,20 +3,7 @@
<component name="deploymentTargetDropDown">
<value>
<entry key="app">
<State>
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="C:\Users\timbe\.android\avd\Pixel_8_API_34.avd" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2024-04-09T09:40:09.789743200Z" />
</State>
<State />
</entry>
</value>
</component>

View File

@ -23,6 +23,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SetDetailsActivity" />
</application>
</manifest>

View File

@ -1,6 +1,7 @@
package com.timber.soft.myemoticon
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
@ -10,16 +11,17 @@ import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.cardview.widget.CardView
import androidx.core.content.ContentProviderCompat.requireContext
import androidx.core.content.ContextCompat.startActivity
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager.VERTICAL
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestOptions
import com.timber.soft.myemoticon.model.ChildDataModel
import com.timber.soft.myemoticon.model.RootDataModel
import com.timber.soft.myemoticon.tools.AppVal
class MainViewPagerFragment(private val rootModel: RootDataModel) : Fragment() {
override fun onCreateView(
@ -28,20 +30,26 @@ class MainViewPagerFragment(private val rootModel: RootDataModel) : Fragment() {
val view = inflater.inflate(R.layout.fragment_main, container, false)
val recyclerViewList: RecyclerView = view.findViewById(R.id.recycler_list)
recyclerViewList.layoutManager = StaggeredGridLayoutManager(2, VERTICAL)
val pagerAdapter = MainHomeCardAdapter(requireContext(),
val pagerAdapter = MainHomeCardAdapter(
requireContext(),
rootModel,
object : OnItemClickListener {
override fun onItemClick(position: Int, childModel: ChildDataModel) {
// val intent = Intent(requireContext(), DetailsActivity::class.java)
// intent.putExtra("KEY_EXTRA", dataModel)
// startActivity(intent)
Log.d("onClick", "item has been click!")
}
})
OnItemClickListenerImpl(requireContext())
)
recyclerViewList.adapter = pagerAdapter
return view
}
}
class OnItemClickListenerImpl(private val mcontext: Context) : OnItemClickListener {
override fun onItemClick(position: Int, childModel: ChildDataModel) {
val intent = Intent(mcontext, SetDetailsActivity::class.java)
intent.putExtra(AppVal.KEY_EXTRA, childModel)
startActivity(mcontext, intent, null)
Log.d("onClick", "item has been click!")
}
}
interface OnItemClickListener {
@ -77,7 +85,7 @@ class MainHomeCardAdapter(
holder.recyclerPreview.layoutManager = StaggeredGridLayoutManager(2, VERTICAL)
val customList = mutableListOf<String>()
val customList = mutableListOf<String>()
customList.addAll(childModel.previewList)
customList.add("xxx")
@ -86,14 +94,8 @@ class MainHomeCardAdapter(
customList,
childModel.count,
childModel,
object : OnItemClickListener {
override fun onItemClick(position: Int, childModel: ChildDataModel) {
// val intent = Intent(requireContext(), DetailsActivity::class.java)
// intent.putExtra("KEY_EXTRA", dataModel)
// startActivity(intent)
Log.d("onClick", "item has been click!")
}
})
OnItemClickListenerImpl(context)
)
holder.recyclerPreview.adapter = cardImgAdapter
@ -126,20 +128,20 @@ class CardImgAdapter(
return urlList.size
}
override fun onBindViewHolder(holder: ImgViewHolder, position: Int) {
val preUrl: String = urlList[position]
try {
Glide.with(context).load(preUrl)
// 淡入动画
.transition(DrawableTransitionOptions.withCrossFade())
// 加载失败占位图
.into(holder.preCardImg)
} catch (e: Exception) {
e.printStackTrace()
if (preUrl != "xxx"){
try {
Glide.with(context).load(preUrl)
.transition(DrawableTransitionOptions.withCrossFade())
.into(holder.preCardImg)
} catch (e: Exception) {
e.printStackTrace()
}
}
if (position == urlList.size-1) {
if (position == urlList.size - 1) {
holder.preCardCount.visibility = View.VISIBLE
holder.preCardCount.text = "+" + imgCount
} else {

View File

@ -0,0 +1,161 @@
package com.timber.soft.myemoticon
import android.content.Context
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.timber.soft.myemoticon.databinding.ActivityDetailsBinding
import com.timber.soft.myemoticon.model.ChildDataModel
import com.timber.soft.myemoticon.tools.AppTools
import com.timber.soft.myemoticon.tools.AppTools.downLoadFile
import com.timber.soft.myemoticon.tools.AppTools.dpCovertPx
import com.timber.soft.myemoticon.tools.AppVal
import com.timber.soft.myemoticon.tools.DownloadListener
import java.io.File
class SetDetailsActivity : AppCompatActivity(), DownloadListener {
private lateinit var binding: ActivityDetailsBinding
private lateinit var identifierName: String
private lateinit var dataModel: ChildDataModel
private var data: MutableList<File> = mutableListOf()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityDetailsBinding.inflate(layoutInflater)
val view = binding.root
setContentView(view)
// 设置Padding上边距留出沉浸式状态栏空间
binding.root.setPadding(0, dpCovertPx(this), 0, 0)
// 设置沉浸式状态栏
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.decorView.systemUiVisibility =
(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE) or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
window.statusBarColor = Color.TRANSPARENT
}
dataModel = intent.getSerializableExtra(AppVal.KEY_EXTRA) as ChildDataModel
identifierName = dataModel.identifierName
binding.backBt.setOnClickListener() {
finish()
}
/**
* TODO no implement
*/
binding.addIconBt.setOnClickListener() {
}
binding.emoTitle.text = dataModel.title
val cacheDir = cacheDir
val newPath: String = "$cacheDir/$identifierName"
val zipUrl = dataModel.zipUrl
val file = File(newPath)
if (!file.exists()) {
downLoadFile(this@SetDetailsActivity, zipUrl, newPath, this)
} else {
initImgData(newPath)
}
val stickerDetailsAdapter = StickerDetailsAdapter(
this@SetDetailsActivity, data
)
binding.recyclerSticker.adapter = stickerDetailsAdapter
binding.recyclerSticker.layoutManager = GridLayoutManager(this@SetDetailsActivity, 3)
}
override fun downloadListener(
isDownloadSuccess: Boolean, isUnzipSuccess: Boolean, newPath: String
) {
if (isDownloadSuccess && isUnzipSuccess) {
initImgData(newPath)
} else {
binding.progressBar.visibility = View.GONE
Toast.makeText(
applicationContext, "Check network connection!", Toast.LENGTH_SHORT
).show()
}
}
private fun initImgData(newPath: String) {
val file = File(newPath)
if (!file.exists()) {
binding.progressBar.visibility = View.GONE
Toast.makeText(
applicationContext, "no file", Toast.LENGTH_SHORT
).show()
return
}
val fileList = file.listFiles()
if (fileList == null) {
binding.progressBar.visibility = View.GONE
Toast.makeText(
applicationContext, "no file2", Toast.LENGTH_SHORT
).show()
return
}
for (listFile in fileList) {
val name = listFile.getName()
if (name == "tray.webp") {
Glide.with(this@SetDetailsActivity).load(listFile).into(binding.emoIcon)
} else if (listFile.getName().endsWith(".webp")) {
data.add(listFile)
}
}
binding.progressBar.visibility = View.GONE
}
}
class StickerDetailsAdapter(
private val context: Context, private val data: List<File>
) : RecyclerView.Adapter<StickerDetailsAdapter.StickerViewHolder>() {
inner class StickerViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val stickerImg = itemView.findViewById<ImageView>(R.id.sticker_img)
val stickerIndexTv = itemView.findViewById<TextView>(R.id.sticker_index_tv)
val spaceView = itemView.findViewById<View>(R.id.spaceView)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): StickerViewHolder {
val view = LayoutInflater.from(context).inflate(R.layout.item_details_img, parent, false)
return StickerViewHolder(view)
}
override fun getItemCount(): Int {
return data.size
}
override fun onBindViewHolder(holder: StickerViewHolder, position: Int) {
val preFile = data[position]
Glide.with(context).load(preFile).transition(
DrawableTransitionOptions.withCrossFade()
).into(holder.stickerImg)
holder.stickerIndexTv.setText((position + 1).toString())
if (position == data.size - 1) {
holder.spaceView.visibility = View.VISIBLE
} else {
holder.spaceView.visibility = View.GONE
}
}
}

View File

@ -1,10 +1,18 @@
package com.timber.soft.myemoticon.tools
import android.content.Context
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
import com.google.gson.Gson
import com.timber.soft.myemoticon.model.RootDataModel
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.InputStreamReader
import java.util.zip.ZipFile
object AppTools {
@ -24,4 +32,74 @@ object AppTools {
return Gson().fromJson(jsonString, Array<RootDataModel>::class.java).toList()
}
}
fun downLoadFile(
context: Context,
zipUrl: String,
newPath: String,
listener: DownloadListener
) {
Glide.with(context).downloadOnly().load(zipUrl)
.addListener(object : RequestListener<File> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<File>?,
isFirstResource: Boolean
): Boolean {
listener.downloadListener(false, false, newPath)
return false
}
override fun onResourceReady(
resource: File?,
model: Any?,
target: Target<File>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
val resultBoolean = resource?.let { getUnzipFile(it, newPath) }
if (resultBoolean != null) {
listener.downloadListener(true, resultBoolean, newPath)
}
return false
}
}).preload()
}
private fun getUnzipFile(oldFile: File, newPath: String): Boolean {
return try {
val newFile = File(newPath)
if (!newFile.exists()) {
newFile.mkdir()
}
val absolutePath = oldFile.absolutePath
val zipFile = ZipFile(absolutePath)
val entries = zipFile.entries()
while (entries.hasMoreElements()) {
val entry = entries.nextElement()
val file = File(newPath, entry.name)
if (entry.isDirectory) {
file.mkdirs()
} else {
val outputStream = FileOutputStream(file)
val inputStream = zipFile.getInputStream(entry)
val bytes = ByteArray(1024)
var length = 0
while (inputStream.read(bytes).also { length = it } > 0) {
outputStream.write(bytes, 0, length)
}
outputStream.close()
inputStream.close()
}
}
true
} catch (exception: Exception) {
false
}
}
}
interface DownloadListener {
fun downloadListener(isDownloadSuccess: Boolean, isUnzipSuccess: Boolean, newPath: String)
}

View File

@ -0,0 +1,30 @@
package com.timber.soft.myemoticon.tools
object AppVal {
const val ZIP_KEY = "zip_url_key"
const val identifierName_KEY = "identifierName_key"
const val TITLE_KEY = "title_key"
const val AUTHOR = "emoticon.wasticker.app.provider.StickerProvider"
const val STICKER_ACTION = "com.whatsapp.intent.action.ENABLE_STICKER_PACK"
const val KEY_PACK_ID = "sticker_pack_id"
const val KEY_PACK_AUTHORITY = "sticker_pack_authority"
const val KEY_PACK_NAME = "sticker_pack_name"
const val STICKER_IDENTIFIER = "sticker_pack_identifier"
const val STICKER_NAME = "sticker_pack_name"
const val STICKER_PUBLISHER = "sticker_pack_publisher"
const val STICKER_TRAY = "sticker_pack_icon"
const val ANDROID_LINK = "android_play_store_link"
const val IOS_LINK = "ios_app_download_link"
const val EMAIL = "sticker_pack_publisher_email"
const val WEBSITE_PUBLISH = "sticker_pack_publisher_website"
const val WEBSITE_POLICY = "sticker_pack_privacy_policy_website"
const val WEBSITE_LICENSE = "sticker_pack_license_agreement_website"
const val ANIMATED = "animated_sticker_pack"
const val STICKER_FILE_NAME = "sticker_file_name"
const val STICKER_EMOJI = "sticker_emoji"
const val METADATA = "metadata"
const val METADATA_CODE_FOR_SINGLE_PACK = 2
const val STICKERS = "stickers"
const val STICKERS_CODE = 3
const val KEY_EXTRA = "KEY_EXTRA"
}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="8dp" />
<solid android:color="@color/white" />
</shape>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="8dp" />
<solid android:color="@color/main_color" />
</shape>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="64dp"
android:height="64dp"
android:viewportWidth="1024"
android:viewportHeight="1024">
<path
android:pathData="M631,161.9a42.7,42.7 0,0 1,63.1 57.4l-2.5,2.7 -290,292.2 289.7,287.4a42.7,42.7 0,0 1,2.7 57.6l-2.5,2.8a42.7,42.7 0,0 1,-57.6 2.7l-2.8,-2.5 -320,-317.4a42.7,42.7 0,0 1,-2.7 -57.6l2.5,-2.8 320,-322.6z"
android:fillColor="#111111"/>
</vector>

View File

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="match_parent"
tools:context=".SetDetailsActivity">
<RelativeLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/back_bt"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="2dp"
android:padding="10dp"
android:src="@drawable/svg_back" />
<ImageView
android:id="@+id/emo_icon"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_centerInParent="true"
android:layout_marginStart="20dp"
android:layout_marginTop="9dp"
android:layout_toEndOf="@+id/back_bt"
android:src="@mipmap/ic_launcher_round" />
<TextView
android:id="@+id/emo_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginStart="20dp"
android:layout_toEndOf="@id/emo_icon"
android:gravity="center"
android:text="@string/app_name"
android:textColor="@color/black"
android:textSize="18sp" />
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_sticker"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/main_bg_color"
android:paddingStart="12dp"
android:paddingTop="12dp"
android:paddingEnd="12dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/app_bar"
app:layout_constraintVertical_bias="0.0"
tools:layout_editor_absoluteX="0dp" />
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateTint="@color/main_color"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/add_icon_bt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="60dp"
android:background="@drawable/shape_details_set_button"
android:paddingStart="14dp"
android:paddingTop="4dp"
android:paddingEnd="14dp"
android:paddingBottom="4dp"
android:text="@string/set_to_whatsapp"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="12dp"
android:background="@drawable/shape_details_pre_img"
android:orientation="horizontal"
android:padding="3dp">
<ImageView
android:id="@+id/sticker_img"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_centerInParent="true"
android:scaleType="fitXY"
android:src="@mipmap/ic_launcher" />
<TextView
android:id="@+id/sticker_index_tv"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_alignParentTop="true"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:gravity="center"
android:text="30"
android:textColor="@color/main_color"
android:textSize="13sp" />
</RelativeLayout>
<View
android:id="@+id/spaceView"
android:layout_width="match_parent"
android:layout_height="100dp"
android:visibility="gone" />
</LinearLayout>

View File

@ -14,8 +14,7 @@
android:layout_width="65dp"
android:layout_height="65dp"
android:layout_centerInParent="true"
android:scaleType="fitXY"
android:src="@mipmap/ic_launcher" />
android:scaleType="fitXY" />
<TextView
android:id="@+id/pre_car_count"

View File

@ -5,5 +5,4 @@
<color name="main_color">#FF9800</color>
<color name="main_bg_color">#80BFEFFF</color>
<color name="item_bg_color">#FFE4E1</color>
<color name="color_1c1c1c">#1C1C1C</color>
</resources>

View File

@ -5,4 +5,5 @@
<string name="google_play_link">https://play.google.com/store/apps/details?id=</string>
<string name="item_name">Item Name</string>
<string name="item_count">+66</string>
<string name="set_to_whatsapp">SET TO WHATSAPP</string>
</resources>