Skip to content

Commit

Permalink
增加通知优化图标过滤搜索功能,更新版本到 1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
fankes committed Feb 15, 2022
1 parent 850a382 commit d117a9a
Show file tree
Hide file tree
Showing 15 changed files with 265 additions and 43 deletions.
2 changes: 2 additions & 0 deletions .idea/misc.xml

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

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# MIUI 原生通知图标

![Eclipse Marketplace](https://img.shields.io/badge/build-pending-dbab09)
![Eclipse Marketplace](https://img.shields.io/badge/build-passing-brightgreen)
![Eclipse Marketplace](https://img.shields.io/badge/license-AGPL3.0-blue)
![Eclipse Marketplace](https://img.shields.io/badge/version-v1.36-green)
![Eclipse Marketplace](https://img.shields.io/badge/version-v1.5-green)
<br/><br/>
<img src="https://github.com/fankes/MIUINativeNotifyIcon/blob/master/app/src/main/ic_launcher-playstore.png" width = "100" height = "100"/>
<br/>
Expand All @@ -12,7 +12,7 @@ Fix the native notification bar icon function abandoned by the MIUI development
# 开始使用

点击下载最新版本
<a href='https://github.com/fankes/MIUINativeNotifyIcon/releases'>![Eclipse Marketplace](https://img.shields.io/badge/download-v1.36-green)</a>
<a href='https://github.com/fankes/MIUINativeNotifyIcon/releases'>![Eclipse Marketplace](https://img.shields.io/badge/download-v1.5-green)</a>
<br/><br/>
⚠️ 适配说明<br/>

Expand Down
8 changes: 7 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android {

defaultConfig {
applicationId "com.fankes.miui.notify"
minSdk 23
minSdk 28
targetSdk 31
versionCode rootProject.ext.appVersionCode
versionName rootProject.ext.appVersionName
Expand All @@ -42,6 +42,9 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}

/** 移除无效耗时 lint Task */
Expand All @@ -57,6 +60,9 @@ tasks.whenTaskAdded {

dependencies {
implementation "com.github.topjohnwu.libsu:core:3.1.2"
implementation 'androidx.annotation:annotation:1.3.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
compileOnly 'de.robv.android.xposed:api:82'
implementation 'com.highcapable.yukihookapi:api:1.0.1'
ksp 'com.highcapable.yukihookapi:ksp-xposed:1.0.1'
Expand Down
15 changes: 7 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,42 @@
<meta-data
android:name="xposedmodule"
android:value="true" />

<meta-data
android:name="xposeddescription"
android:value="MIUI 状态栏原生图标,修复 12.5、13 后期被破坏的彩色图标。\n开发者:酷安 @星夜不荟" />

<meta-data
android:name="xposedminversion"
android:value="93" />

<activity
android:name="com.fankes.miui.notify.ui.MainActivity"
android:name=".ui.MainActivity"
android:exported="true"
android:screenOrientation="behind">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="de.robv.android.xposed.category.MODULE_SETTINGS" />
</intent-filter>
</activity>

<activity-alias
android:name="com.fankes.miui.notify.Home"
android:name=".Home"
android:enabled="true"
android:exported="true"
android:label="@string/app_name"
android:screenOrientation="behind"
android:targetActivity="com.fankes.miui.notify.ui.MainActivity">

android:targetActivity=".ui.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>

<activity
android:name="com.fankes.miui.notify.ui.ConfigureActivity"
android:name=".ui.ConfigureActivity"
android:exported="false"
android:screenOrientation="behind" />
</application>

</manifest>
24 changes: 24 additions & 0 deletions app/src/main/java/com/fankes/miui/notify/data/LoginDataSource.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.fankes.miui.notify.data

import com.fankes.miui.notify.data.model.LoggedInUser
import java.io.IOException

/**
* Class that handles authentication w/ login credentials and retrieves user information.
*/
class LoginDataSource {

fun login(username: String, password: String): Result<LoggedInUser> {
try {
// TODO: handle loggedInUser authentication
val fakeUser = LoggedInUser(java.util.UUID.randomUUID().toString(), "Jane Doe")
return Result.Success(fakeUser)
} catch (e: Throwable) {
return Result.Error(IOException("Error logging in", e))
}
}

fun logout() {
// TODO: revoke authentication
}
}
46 changes: 46 additions & 0 deletions app/src/main/java/com/fankes/miui/notify/data/LoginRepository.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.fankes.miui.notify.data

import com.fankes.miui.notify.data.model.LoggedInUser

/**
* Class that requests authentication and user information from the remote data source and
* maintains an in-memory cache of login status and user credentials information.
*/

class LoginRepository(val dataSource: LoginDataSource) {

// in-memory cache of the loggedInUser object
var user: LoggedInUser? = null
private set

val isLoggedIn: Boolean
get() = user != null

init {
// If user credentials will be cached in local storage, it is recommended it be encrypted
// @see https://developer.android.com/training/articles/keystore
user = null
}

fun logout() {
user = null
dataSource.logout()
}

fun login(username: String, password: String): Result<LoggedInUser> {
// handle login
val result = dataSource.login(username, password)

if (result is Result.Success) {
setLoggedInUser(result.data)
}

return result
}

private fun setLoggedInUser(loggedInUser: LoggedInUser) {
this.user = loggedInUser
// If user credentials will be cached in local storage, it is recommended it be encrypted
// @see https://developer.android.com/training/articles/keystore
}
}
18 changes: 18 additions & 0 deletions app/src/main/java/com/fankes/miui/notify/data/Result.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.fankes.miui.notify.data

/**
* A generic class that holds a value with its loading status.
* @param <T>
*/
sealed class Result<out T : Any> {

data class Success<out T : Any>(val data: T) : Result<T>()
data class Error(val exception: Exception) : Result<Nothing>()

override fun toString(): String {
return when (this) {
is Success<*> -> "Success[data=$data]"
is Error -> "Error[exception=$exception]"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.fankes.miui.notify.data.model

/**
* Data class that captures user information for logged in users retrieved from LoginRepository
*/
data class LoggedInUser(
val userId: String,
val displayName: String
)
73 changes: 65 additions & 8 deletions app/src/main/java/com/fankes/miui/notify/ui/ConfigureActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import android.widget.ListView
import android.widget.TextView
import android.widget.Toast
import androidx.constraintlayout.utils.widget.ImageFilterView
import androidx.core.view.isVisible
import com.fankes.miui.notify.R
import com.fankes.miui.notify.hook.factory.isAppNotifyHookAllOf
import com.fankes.miui.notify.hook.factory.isAppNotifyHookOf
Expand All @@ -43,30 +44,68 @@ import com.fankes.miui.notify.hook.factory.putAppNotifyHookOf
import com.fankes.miui.notify.params.IconPackParams
import com.fankes.miui.notify.ui.base.BaseActivity
import com.fankes.miui.notify.utils.SystemUITool
import com.fankes.miui.notify.utils.showDialog
import com.fankes.miui.notify.view.MaterialSwitch
import com.google.android.material.textfield.TextInputEditText

class ConfigureActivity : BaseActivity() {

/** 当前筛选条件 */
private var filterText = ""

/** 回调适配器改变 */
private var onChanged: (() -> Unit)? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_config)
/** 返回按钮点击事件 */
findViewById<View>(R.id.title_back_icon).setOnClickListener { onBackPressed() }
/** 设置标题个数文本 */
findViewById<TextView>(R.id.config_title_count_text).text = "已适配 ${IconPackParams.iconDatas.size} 个 APP 的通知图标"
/** 设置搜索按钮点击事件 */
findViewById<View>(R.id.config_title_search).setOnClickListener {
Toast.makeText(this, "后期开放", Toast.LENGTH_SHORT).show()
/** 刷新适配器结果相关 */
refreshAdapterResult()
/** 设置过滤按钮点击事件 */
findViewById<View>(R.id.config_title_filter).setOnClickListener {
showDialog {
title = "按条件过滤"
var editText: TextInputEditText
addView(R.layout.dia_icon_filter).apply {
editText = findViewById<TextInputEditText>(R.id.dia_icon_filter_input_edit).apply {
requestFocus()
invalidate()
if (filterText.isNotBlank()) {
setText(filterText)
setSelection(filterText.length)
}
}
}
confirmButton {
if (editText.text.toString().isNotBlank()) {
filterText = editText.text.toString().trim()
onChanged?.invoke()
refreshAdapterResult()
} else {
Toast.makeText(applicationContext, "条件不能为空", Toast.LENGTH_SHORT).show()
it.performClick()
}
}
cancelButton()
if (filterText.isNotBlank())
neutralButton(text = "清除条件") {
filterText = ""
onChanged?.invoke()
refreshAdapterResult()
}
}
}
/** 设置列表元素和 Adapter */
findViewById<ListView>(R.id.config_list_view).apply {
adapter = object : BaseAdapter() {

private val inflater = LayoutInflater.from(context)

override fun getCount() = IconPackParams.iconDatas.size
override fun getCount() = iconDatas.size

override fun getItem(position: Int) = IconPackParams.iconDatas[position]
override fun getItem(position: Int) = iconDatas[position]

override fun getItemId(position: Int) = position.toLong()

Expand Down Expand Up @@ -118,7 +157,7 @@ class ConfigureActivity : BaseActivity() {
lateinit var switchOpen: MaterialSwitch
lateinit var switchAll: MaterialSwitch
}
}
}.apply { onChanged = { notifyDataSetChanged() } }
}
/** 设置点击事件 */
findViewById<View>(R.id.config_cbr_button).setOnClickListener {
Expand All @@ -134,4 +173,22 @@ class ConfigureActivity : BaseActivity() {
}
}
}

/** 刷新适配器结果相关 */
private fun refreshAdapterResult() {
findViewById<TextView>(R.id.config_title_count_text).text =
if (filterText.isBlank()) "已适配 ${iconDatas.size} 个 APP 的通知图标"
else "${filterText}” 匹配到 ${iconDatas.size} 个结果"
findViewById<View>(R.id.config_list_no_data_view).isVisible = iconDatas.isEmpty()
}

/**
* 当前结果下的图标数组
* @return [Array]
*/
private val iconDatas
get() = if (filterText.isBlank()) IconPackParams.iconDatas
else IconPackParams.iconDatas.filter {
it.appName.lowercase().contains(filterText.lowercase()) || it.packageName.lowercase().contains(filterText.lowercase())
}.toTypedArray()
}
23 changes: 21 additions & 2 deletions app/src/main/java/com/fankes/miui/notify/utils/DialogBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@
*
* This file is Created by fankes on 2022/1/7.
*/
@file:Suppress("unused")
@file:Suppress("unused", "DEPRECATION")

package com.fankes.miui.notify.utils

import android.app.AlertDialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.GradientDrawable

import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import kotlin.math.round

/**
* 构造对话框
Expand All @@ -44,6 +48,8 @@ class DialogBuilder(private val context: Context) {

private var instance: AlertDialog.Builder? = null // 实例对象

private var customLayoutView: View? = null // 自定义布局

init {
instance = AlertDialog.Builder(context, android.R.style.Theme_Material_Light_Dialog)
}
Expand All @@ -65,6 +71,16 @@ class DialogBuilder(private val context: Context) {
instance?.setMessage(value)
}

/**
* 设置对话框自定义布局
* @param resId 属性资源 Id
* @return [View]
*/
fun addView(resId: Int): View {
customLayoutView = LayoutInflater.from(context).inflate(resId, null)
return customLayoutView ?: error("Inflate $resId failed")
}

/**
* 设置对话框确定按钮
* @param text 按钮文本内容
Expand All @@ -91,6 +107,9 @@ class DialogBuilder(private val context: Context) {

/** 显示对话框 */
internal fun show() = instance?.create()?.apply {
val dm = DisplayMetrics()
(context.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay.getMetrics(dm)
customLayoutView?.let { setView(it.apply { minimumWidth = round(dm.widthPixels / 1.3).toInt() }) }
window?.setBackgroundDrawable(GradientDrawable(
GradientDrawable.Orientation.TOP_BOTTOM,
intArrayOf(Color.WHITE, Color.WHITE)
Expand Down
Loading

0 comments on commit d117a9a

Please sign in to comment.