diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
index 2b754eb..0c0c338 100644
--- a/.idea/deploymentTargetDropDown.xml
+++ b/.idea/deploymentTargetDropDown.xml
@@ -3,20 +3,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 7f3cf09..d84299f 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -23,6 +23,8 @@
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/timber/soft/myemoticon/MainViewPagerFragment.kt b/app/src/main/java/com/timber/soft/myemoticon/MainFragment.kt
similarity index 75%
rename from app/src/main/java/com/timber/soft/myemoticon/MainViewPagerFragment.kt
rename to app/src/main/java/com/timber/soft/myemoticon/MainFragment.kt
index efa1a9d..c85cc5a 100644
--- a/app/src/main/java/com/timber/soft/myemoticon/MainViewPagerFragment.kt
+++ b/app/src/main/java/com/timber/soft/myemoticon/MainFragment.kt
@@ -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()
+ val customList = mutableListOf()
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 {
diff --git a/app/src/main/java/com/timber/soft/myemoticon/SetDetailsActivity.kt b/app/src/main/java/com/timber/soft/myemoticon/SetDetailsActivity.kt
new file mode 100644
index 0000000..1a154c2
--- /dev/null
+++ b/app/src/main/java/com/timber/soft/myemoticon/SetDetailsActivity.kt
@@ -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 = 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
+
+) : RecyclerView.Adapter() {
+
+ inner class StickerViewHolder(view: View) : RecyclerView.ViewHolder(view) {
+ val stickerImg = itemView.findViewById(R.id.sticker_img)
+ val stickerIndexTv = itemView.findViewById(R.id.sticker_index_tv)
+ val spaceView = itemView.findViewById(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
+ }
+ }
+
+}
diff --git a/app/src/main/java/com/timber/soft/myemoticon/tools/AppTools.kt b/app/src/main/java/com/timber/soft/myemoticon/tools/AppTools.kt
index b846a66..a68b9ad 100644
--- a/app/src/main/java/com/timber/soft/myemoticon/tools/AppTools.kt
+++ b/app/src/main/java/com/timber/soft/myemoticon/tools/AppTools.kt
@@ -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::class.java).toList()
}
-}
\ No newline at end of file
+ fun downLoadFile(
+ context: Context,
+ zipUrl: String,
+ newPath: String,
+ listener: DownloadListener
+ ) {
+ Glide.with(context).downloadOnly().load(zipUrl)
+ .addListener(object : RequestListener {
+ override fun onLoadFailed(
+ e: GlideException?,
+ model: Any?,
+ target: Target?,
+ isFirstResource: Boolean
+ ): Boolean {
+ listener.downloadListener(false, false, newPath)
+ return false
+ }
+
+ override fun onResourceReady(
+ resource: File?,
+ model: Any?,
+ target: Target?,
+ 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)
+}
diff --git a/app/src/main/java/com/timber/soft/myemoticon/tools/AppVal.kt b/app/src/main/java/com/timber/soft/myemoticon/tools/AppVal.kt
new file mode 100644
index 0000000..cce0b17
--- /dev/null
+++ b/app/src/main/java/com/timber/soft/myemoticon/tools/AppVal.kt
@@ -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"
+}
\ No newline at end of file
diff --git a/app/src/main/res/drawable/shape_details_pre_img.xml b/app/src/main/res/drawable/shape_details_pre_img.xml
new file mode 100644
index 0000000..fc78e2d
--- /dev/null
+++ b/app/src/main/res/drawable/shape_details_pre_img.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/shape_details_set_button.xml b/app/src/main/res/drawable/shape_details_set_button.xml
new file mode 100644
index 0000000..7fd8e2d
--- /dev/null
+++ b/app/src/main/res/drawable/shape_details_set_button.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/svg_back.xml b/app/src/main/res/drawable/svg_back.xml
new file mode 100644
index 0000000..c41a79c
--- /dev/null
+++ b/app/src/main/res/drawable/svg_back.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/app/src/main/res/layout/activity_details.xml b/app/src/main/res/layout/activity_details.xml
new file mode 100644
index 0000000..13d18ca
--- /dev/null
+++ b/app/src/main/res/layout/activity_details.xml
@@ -0,0 +1,90 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/item_details_img.xml b/app/src/main/res/layout/item_details_img.xml
new file mode 100644
index 0000000..9bb28c4
--- /dev/null
+++ b/app/src/main/res/layout/item_details_img.xml
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/item_home_card_img.xml b/app/src/main/res/layout/item_home_card_img.xml
index 15b95d1..7b89f6a 100644
--- a/app/src/main/res/layout/item_home_card_img.xml
+++ b/app/src/main/res/layout/item_home_card_img.xml
@@ -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" />
#FF9800
#80BFEFFF
#FFE4E1
- #1C1C1C
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 945a3ff..e769d8c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -5,4 +5,5 @@
https://play.google.com/store/apps/details?id=
Item Name
+66
+ SET TO WHATSAPP
\ No newline at end of file