Skip to content

Commit

Permalink
✨ Upload icon features
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanren1225 committed Mar 5, 2022
1 parent 90dc78a commit 3231106
Show file tree
Hide file tree
Showing 21 changed files with 177,186 additions and 34 deletions.
1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107,295 changes: 107,295 additions & 0 deletions app/proguard/mapping.txt

Large diffs are not rendered by default.

60,314 changes: 60,314 additions & 0 deletions app/proguard/seeds.txt

Large diffs are not rendered by default.

9,220 changes: 9,220 additions & 0 deletions app/proguard/unused.txt

Large diffs are not rendered by default.

Binary file added app/release/app-release.apk
Binary file not shown.
20 changes: 20 additions & 0 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": 3,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "ren.imyan.app_tracker",
"variantName": "release",
"elements": [
{
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 2,
"versionName": "0.0.2",
"outputFile": "app-release.apk"
}
],
"elementType": "File"
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ui.AboutActivity"/>
</application>

</manifest>
28 changes: 28 additions & 0 deletions app/src/main/java/ren/imyan/app_tracker/common/ktx/BitmapKtx.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ren.imyan.app_tracker.common.ktx

import android.content.Context
import android.graphics.Bitmap
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.FileOutputStream

fun Bitmap.toFile(fileName:String):File?{
var file: File? = null
return try {
file = File(get<Context>().cacheDir.path+File.separator+fileName)
file.createNewFile()

ByteArrayOutputStream().use {
this.compress(Bitmap.CompressFormat.JPEG,80,it)
val bitmapData = it.toByteArray()
FileOutputStream(file).use { fos->
fos.write(bitmapData)
fos.flush()
fos.close()
file
}
}
}catch (e:Exception){
file
}
}
12 changes: 8 additions & 4 deletions app/src/main/java/ren/imyan/app_tracker/net/AppTrackerApi.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package ren.imyan.app_tracker.net

import okhttp3.MultipartBody
import okhttp3.RequestBody
import ren.imyan.app_tracker.net.request.SubmitAppRequest
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.POST
import retrofit2.http.*

interface AppTrackerApi {
@POST("new")
suspend fun submitApp(@Body appInfo: SubmitAppRequest): Response<Unit>
@POST("appInfo")
suspend fun submitAppInfo(@Body appInfo: SubmitAppRequest): Response<Unit>

@POST("appIcon")
suspend fun submitAppIcon(@Query("packageName") packageName:String,@Body icon: RequestBody):Response<Unit>
}
16 changes: 14 additions & 2 deletions app/src/main/java/ren/imyan/app_tracker/net/AppTrackerRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,34 @@ package ren.imyan.app_tracker.net
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.asRequestBody
import ren.imyan.app_tracker.common.ktx.get
import ren.imyan.app_tracker.model.AppInfo
import ren.imyan.app_tracker.net.request.SubmitAppRequest
import retrofit2.Retrofit
import java.io.File

class AppTrackerRepo {
private val api by lazy { get<Retrofit>().create(AppTrackerApi::class.java) }

suspend fun upload(info: AppInfo) =
suspend fun submitAppInfo(info: AppInfo) =
flow {
val appInfo = SubmitAppRequest(
activityName = info.activityName,
appName = info.appName,
packageName = info.packageName,
signature = "app-tracker"
)
emit(api.submitApp(appInfo))
emit(api.submitAppInfo(appInfo))
}.flowOn(Dispatchers.IO)

suspend fun submitAppIcon(packageName:String,icon: File) =
flow{
val iconFile = icon.asRequestBody("image/jpeg".toMediaTypeOrNull());
emit(api.submitAppIcon(packageName,iconFile))
}.flowOn(Dispatchers.IO)
}
2 changes: 1 addition & 1 deletion app/src/main/java/ren/imyan/app_tracker/net/NetModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ val netModule = module {
single {
Retrofit.Builder()
.client(get())
.baseUrl("https://bot.k2t3k.tk/api/")
.baseUrl("https://test.k2t3k.tk/api/")
.addConverterFactory(MoshiConverterFactory.create())
.build()
}
Expand Down
32 changes: 32 additions & 0 deletions app/src/main/java/ren/imyan/app_tracker/ui/AboutActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ren.imyan.app_tracker.ui

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import ren.imyan.app_tracker.R

class AboutActivity:AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.action_about)

findViewById<TextView>(R.id.textView2).setOnClickListener {
val intent = Intent().apply {
action = Intent.ACTION_VIEW
data = Uri.parse("https://github.com/Oblatum/App-Tracker-for-Icon-Pack-Client-Side-Android-Version");
}
startActivity(intent)
}

findViewById<Button>(R.id.ali).setOnClickListener {
val intent = Intent().apply {
action = Intent.ACTION_VIEW
data = Uri.parse("https://qr.alipay.com/fkx11504wccj8dgl2dc41d1");
}
startActivity(intent)
}
}
}
78 changes: 58 additions & 20 deletions app/src/main/java/ren/imyan/app_tracker/ui/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ren.imyan.app_tracker.ui

import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Color
import android.view.Menu
import android.view.MenuItem
Expand Down Expand Up @@ -92,29 +94,50 @@ class MainActivity : BaseActivity() {
}

send.setOnClickListener {
@Suppress("UNCHECKED_CAST")
val checkedList = (appList.models as List<AppInfo>).filter { it.isCheck }
if (checkedList.isEmpty()) {
return@setOnClickListener
}

dialog.show(supportFragmentManager, "upload")
dialog.setTotal(checkedList.size)

viewModel.dispatch(MainAction.Upload(checkedList))
viewModel.uiEvent.onEach {
when (it) {
is MainEvent.UpdateProgress -> dialog.updateProgress(it.progress)
MainEvent.DismissDialog -> {
dialog.dismiss()
Toast.makeText(this@MainActivity, "上传完成", Toast.LENGTH_SHORT).show()
val selectItems = arrayOf(
"只上传 APP 信息",
"只上传 APP 图标",
"都上传"
)

val selectDialog = MaterialAlertDialogBuilder(this@MainActivity).apply {
setItems(selectItems){_,index ->
@Suppress("UNCHECKED_CAST")
val checkedList = (binding.appList.models as List<AppInfo>).filter { it.isCheck }
if (checkedList.isEmpty()) {
return@setItems
}
MainEvent.UploadFail -> {
dialog.dismiss()
Toast.makeText(this@MainActivity, "上传失败", Toast.LENGTH_SHORT).show()

dialog.show(supportFragmentManager, "upload")
dialog.setTotal(checkedList.size)

when(index){
0 -> {
viewModel.dispatch(MainAction.SubmitAppInfo(checkedList))
}
1 -> {
val appIconMap = mutableMapOf<String, Bitmap>()
checkedList.forEach {
if(it.packageName != null && it.icon != null) {
appIconMap[it.packageName] = it.icon
}
}
viewModel.dispatch(MainAction.SubmitAppIcon(appIconMap))
}
2-> {
dialog.showTitle()
val appIconMap = mutableMapOf<String, Bitmap>()
checkedList.forEach {
if(it.packageName != null && it.icon != null) {
appIconMap[it.packageName] = it.icon
}
}
viewModel.dispatch(MainAction.SubmitAll(checkedList,appIconMap))
}
}
}
}.launchIn(this@MainActivity.lifecycleScope)
}
selectDialog.show()
}
}
}
Expand All @@ -136,6 +159,20 @@ class MainActivity : BaseActivity() {
else -> {}
}
}
viewModel.uiEvent.onEach {
when (it) {
is MainEvent.UpdateProgress -> dialog.updateProgress(it.progress)
MainEvent.DismissDialog -> {
dialog.dismiss()
Toast.makeText(this@MainActivity, "上传完成", Toast.LENGTH_SHORT).show()
}
MainEvent.UploadFail -> {
dialog.dismiss()
Toast.makeText(this@MainActivity, "上传失败", Toast.LENGTH_SHORT).show()
}
MainEvent.SwitchTitle -> dialog.switchTitle()
}
}.launchIn(this@MainActivity.lifecycleScope)
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
Expand Down Expand Up @@ -178,6 +215,7 @@ class MainActivity : BaseActivity() {
R.id.only_user_app -> viewModel.dispatch(MainAction.FilterApp(FilterAppType.User))
R.id.only_system_app -> viewModel.dispatch(MainAction.FilterApp(FilterAppType.System))
R.id.all_app -> viewModel.dispatch(MainAction.FilterApp(FilterAppType.All))
R.id.about -> startActivity(Intent(this,AboutActivity::class.java))
}
return super.onOptionsItemSelected(item)
}
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/ren/imyan/app_tracker/ui/MainView.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ren.imyan.app_tracker.ui

import android.graphics.Bitmap
import ren.imyan.app_tracker.FilterAppType
import ren.imyan.app_tracker.base.BaseLoad
import ren.imyan.app_tracker.base.UiAction
Expand All @@ -13,12 +14,19 @@ data class MainData(

sealed class MainEvent : UiEvent {
data class UpdateProgress(val progress: Int) : MainEvent()
object SwitchTitle : MainEvent()
object DismissDialog : MainEvent()
object UploadFail : MainEvent()
}

sealed class MainAction : UiAction {
data class Upload(val infoList: List<AppInfo>? = null) : MainAction()
data class SubmitAppInfo(val infoList: List<AppInfo>? = null) : MainAction()
data class SubmitAppIcon(val iconMap: Map<String, Bitmap>? = null) : MainAction()
data class SubmitAll(
val infoList: List<AppInfo>? = null,
val iconMap: Map<String, Bitmap>? = null
) : MainAction()

data class FilterApp(val type: FilterAppType) : MainAction()
data class Search(val type: String) : MainAction()
}
Loading

0 comments on commit 3231106

Please sign in to comment.