Skip to content

Commit

Permalink
Refactoring and Update UI
Browse files Browse the repository at this point in the history
  • Loading branch information
n00byara committed May 8, 2024
1 parent 9303569 commit a9c58cc
Show file tree
Hide file tree
Showing 46 changed files with 524 additions and 497 deletions.
10 changes: 10 additions & 0 deletions .idea/deploymentTargetSelector.xml

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

2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
minSdk = 30
targetSdk = 34
versionCode = 1
versionName = "3.0.4"
versionName = "3.0.5"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
tools:targetApi="31" >

<receiver
android:name=".components.service.BootReceiver"
android:name=".service.BootReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
Expand All @@ -28,7 +28,7 @@
</receiver>

<service
android:name=".components.service.NotificationService"
android:name=".service.NotificationService"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"
android:exported="true">
<intent-filter>
Expand All @@ -37,7 +37,7 @@
</service>

<activity
android:name=".components.permission.PermissionRequestActivity"
android:name=".permission.PermissionRequestActivity"
android:exported="false"
android:screenOrientation="portrait"
android:theme="@style/Theme.NotificationCode" />
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/assets/xposed_init
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ru.n00byara.notificationcode.components.hook.Hook_YukiHookXposedInit
ru.n00byara.notificationcode.hook.Hook_YukiHookXposedInit
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package ru.n00byara.notificationcode.components.application
package ru.n00byara.notificationcode.application

import android.content.Context
import android.content.pm.PackageManager

class ApplicationsList(private val context: Context) {
private val pm = context.packageManager
private val allInstalledApplications = pm.getInstalledApplications(PackageManager.GET_META_DATA)
private val pm = this.context.packageManager
private val allInstalledApplications = this.pm.getInstalledApplications(PackageManager.GET_META_DATA)

fun getApplications(): List<InstalledAppInfo> {
var result = mutableListOf<InstalledAppInfo>()
val result = mutableListOf<InstalledAppInfo>()

allInstalledApplications.forEach { applicationInfo ->
this.allInstalledApplications.forEach { applicationInfo ->
val appInfo = InstalledAppInfo(this.pm, applicationInfo)

if (!appInfo.isSystem && appInfo.name != "Shazam") {
Expand All @@ -22,9 +22,9 @@ class ApplicationsList(private val context: Context) {
}

fun getAllApplications(): List<InstalledAppInfo> {
var result = mutableListOf<InstalledAppInfo>()
val result = mutableListOf<InstalledAppInfo>()

allInstalledApplications.forEach { applicationInfo ->
this.allInstalledApplications.forEach { applicationInfo ->
val appInfo = InstalledAppInfo(this.pm, applicationInfo)

if (!appInfo.isSystem) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ru.n00byara.notificationcode.application

import android.content.Context
import android.content.pm.ApplicationInfo
import com.highcapable.yukihookapi.hook.factory.prefs
import com.highcapable.yukihookapi.hook.xposed.application.ModuleApplication
import ru.n00byara.notificationcode.Constants

class HookedAppInfo(private val hookedContext: Context) {
val prefs = ModuleApplication().prefs(Constants.SETTINGS_NAME)
val isActive: Boolean
val isSystem: Boolean
val name: String
val packageName: String

init {
val pm = this.hookedContext.packageManager
val applicationInfo = this.hookedContext.applicationInfo

this.name = applicationInfo.loadLabel(pm).toString()
this.packageName = applicationInfo.packageName
this.isSystem = !((applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM) == 0)
this.isActive = this.prefs.getBoolean(Constants.APPLICATION_PREF + packageName)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ru.n00byara.notificationcode.application

import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import ru.n00byara.notificationcode.Constants
import ru.n00byara.notificationcode.settings.Settings

class InstalledAppInfo(private val pm: PackageManager, private val applicationInfo: ApplicationInfo) {
val settings = Settings()
val name: String
val icon: Drawable
val isSystem: Boolean
val packageName: String
val isActive: Boolean

init {
this.name = this.applicationInfo.loadLabel(this.pm).toString()
this.packageName = this.applicationInfo.packageName
this.isSystem = !((this.applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM) == 0)
this.isActive = this.settings.getBoolean(Constants.APPLICATION_PREF + packageName)
this.icon = this.applicationInfo.loadIcon(this.pm)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.n00byara.notificationcode.components.clip
package ru.n00byara.notificationcode.clip

import android.content.ClipData
import android.content.ClipboardManager
Expand All @@ -25,14 +25,13 @@ class Clip(
private var found = false

init {

if (contentTitle != null) {
addToClipBoard("${contentTitle} ${contentText}")
if (this.contentTitle != null) {
this.addToClipBoard("${this.contentTitle} ${this.contentText}")
} else {
val text = getText()

text?.let { contentText ->
addToClipBoard(contentText)
this.addToClipBoard(contentText)
}
}
}
Expand Down Expand Up @@ -79,7 +78,7 @@ class Clip(
this.matcher = pattern.matcher(this.contentText)
this.found = matcher.matches()

if (this.found) return matcher.group(2) + matcher.group(3)
if (this.found) return this.matcher.group(2) + this.matcher.group(3)

return null
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.n00byara.notificationcode.components.clip
package ru.n00byara.notificationcode.clip

object RegExps {
val regExps = listOf(
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package ru.n00byara.notificationcode.components.hook
package ru.n00byara.notificationcode.hook

import com.highcapable.yukihookapi.YukiHookAPI.encase
import com.highcapable.yukihookapi.annotation.xposed.InjectYukiHookWithXposed
import com.highcapable.yukihookapi.hook.xposed.proxy.IYukiHookXposedInit
import ru.n00byara.notificationcode.Constants

import ru.n00byara.notificationcode.components.hook.entity.SystemUIHooker
import ru.n00byara.notificationcode.hook.entity.SystemUIHooker

@InjectYukiHookWithXposed
object Hook : IYukiHookXposedInit {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.n00byara.notificationcode.components.hook.entity
package ru.n00byara.notificationcode.hook.entity

import android.app.Notification
import android.content.Context
Expand All @@ -11,8 +11,8 @@ import com.highcapable.yukihookapi.hook.type.android.Notification_BuilderClass
import com.highcapable.yukihookapi.hook.type.android.ParcelClass
import com.highcapable.yukihookapi.hook.xposed.application.ModuleApplication
import ru.n00byara.notificationcode.Constants
import ru.n00byara.notificationcode.components.application.HookedAppInfo
import ru.n00byara.notificationcode.components.clip.Clip
import ru.n00byara.notificationcode.application.HookedAppInfo
import ru.n00byara.notificationcode.clip.Clip

object SystemUIHooker : YukiBaseHooker() {
override fun onHook() {
Expand Down Expand Up @@ -40,7 +40,11 @@ object SystemUIHooker : YukiBaseHooker() {
if (appInfo.isSystem) {
notification.extras?.let { extras ->
extras.getCharSequence(Constants.EXTRA_TEXT)?.let { contentText ->
Clip(appContext!!, contentText, prefs = prefs)
Clip(
context = appContext!!,
contentText = contentText,
prefs = prefs
)
}
}
} else {
Expand All @@ -50,14 +54,23 @@ object SystemUIHooker : YukiBaseHooker() {
if (appInfo.name == Constants.SHAZAM_APP_NAME && notification.getChannelId() == Constants.SHAZAM_CHANNEL_ID) {
val contentTitle = extras.getCharSequence(Constants.EXTRA_TITLE)

Clip(appContext!!, contentText, contentTitle, prefs = prefs)
Clip(
context = appContext!!,
contentText = contentText,
contentTitle = contentTitle,
prefs = prefs
)
} else {
Clip(appContext!!, contentText, prefs = prefs)
Clip(
context = appContext!!,
contentText = contentText,
prefs = prefs
)
}
}
}
} else {
// .. ??
// Do nothing
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.n00byara.notificationcode.components.permission
package ru.n00byara.notificationcode.permission

import android.content.Context
import android.content.Intent
Expand All @@ -8,12 +8,12 @@ class Permission(private val context: Context) {
fun requestPermissions() {
val intent = Intent(this.context, PermissionRequestActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
this.context.startActivity(intent)
}

fun checkPermission(): Boolean {
val notificationListener =
arrayOf(Settings.Secure.getString(context.contentResolver, "enabled_notification_listeners")).joinToString()
arrayOf(Settings.Secure.getString(this.context.contentResolver, "enabled_notification_listeners")).joinToString()

return notificationListener.contains(this.context.packageName)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.n00byara.notificationcode.components.permission
package ru.n00byara.notificationcode.permission

import android.content.Intent
import android.os.Bundle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.n00byara.notificationcode.components.service
package ru.n00byara.notificationcode.service

import android.content.BroadcastReceiver
import android.content.Context
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
package ru.n00byara.notificationcode.components.service
package ru.n00byara.notificationcode.service

import android.service.notification.NotificationListenerService
import android.service.notification.StatusBarNotification
import com.highcapable.yukihookapi.hook.factory.prefs
import com.highcapable.yukihookapi.hook.xposed.application.ModuleApplication
import ru.n00byara.notificationcode.Constants
import ru.n00byara.notificationcode.components.application.ApplicationsList
import ru.n00byara.notificationcode.components.clip.Clip
import ru.n00byara.notificationcode.application.ApplicationsList
import ru.n00byara.notificationcode.clip.Clip

class NotificationService : NotificationListenerService() {
val prefs = ModuleApplication.appContext.prefs(Constants.SETTINGS_NAME)
override fun onNotificationPosted(sbn: StatusBarNotification) {
val applicationsList = ApplicationsList(this.baseContext).getAllApplications()
val appInfo = applicationsList.find { it.packageName == sbn.packageName }

if (prefs.getInt(Constants.USE_CASE) == 1) {
if (this.prefs.getInt(Constants.USE_CASE) == 1) {
appInfo?.let { appInfo ->
val notification = sbn.notification

if (appInfo.isSystem) {
notification.extras?.let { extras ->
extras.getCharSequence(Constants.EXTRA_TEXT)?.let { contentText ->
Clip(this.baseContext, contentText, prefs = prefs)
Clip(
context = this.baseContext,
contentText = contentText,
prefs = this.prefs
)
}
}
} else {
Expand All @@ -31,14 +35,22 @@ class NotificationService : NotificationListenerService() {
if (appInfo.name == Constants.SHAZAM_APP_NAME && notification.channelId == Constants.SHAZAM_CHANNEL_ID) {
val contentTitle = extras.getCharSequence(Constants.EXTRA_TITLE)

Clip(this.baseContext, contentText, contentTitle, prefs = prefs)
Clip(
context = this.baseContext,
contentText = contentText,
contentTitle = contentTitle,
prefs = this.prefs
)
} else {
Clip(this.baseContext, contentText, prefs = prefs)
Clip(context = this.baseContext,
contentText = contentText,
prefs = this.prefs
)
}
}
}
} else {
// .. ??
// Do nothing
}
}
}
Expand Down
Loading

0 comments on commit a9c58cc

Please sign in to comment.