This commit is contained in:
lunaticbum 2024-09-19 18:08:07 +09:00
parent 301b21b8ab
commit 3fae93db8e
8 changed files with 219 additions and 34 deletions

View File

@ -91,6 +91,7 @@ dependencies {
implementation ("org.apache.commons:commons-text:1.12.0") implementation ("org.apache.commons:commons-text:1.12.0")
implementation("com.squareup.okhttp:okhttp:2.7.5") implementation("com.squareup.okhttp:okhttp:2.7.5")
implementation("com.google.android.gms:play-services-location:21.0.1") implementation("com.google.android.gms:play-services-location:21.0.1")
implementation("com.google.android.gms:play-services-tasks:18.2.0")
// implementation ("androidx.window:window:1.0.0") // implementation ("androidx.window:window:1.0.0")
// implementation("io.github.vaneproject:hanguleditor:1.0.0") // implementation("io.github.vaneproject:hanguleditor:1.0.0")
} }

View File

@ -50,6 +50,8 @@ import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.work.OneTimeWorkRequest
import androidx.work.WorkManager
import io.realm.kotlin.ext.query import io.realm.kotlin.ext.query
import io.realm.kotlin.notifications.InitialResults import io.realm.kotlin.notifications.InitialResults
import io.realm.kotlin.notifications.ResultsChange import io.realm.kotlin.notifications.ResultsChange
@ -61,12 +63,14 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import okhttp3.ConnectionPool
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import okhttp3.ResponseBody
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONObject import org.json.JSONObject
import rasel.lunar.launcher.LauncherActivity.Companion.CALL_WORK_TAG
import rasel.lunar.launcher.LauncherActivity.Companion.SMS_WORK_TAG
import rasel.lunar.launcher.LauncherActivity.Companion.lActivity import rasel.lunar.launcher.LauncherActivity.Companion.lActivity
import rasel.lunar.launcher.LauncherActivity.Companion.workmanager
import rasel.lunar.launcher.R import rasel.lunar.launcher.R
import rasel.lunar.launcher.databinding.LauncherHomeBinding import rasel.lunar.launcher.databinding.LauncherHomeBinding
import rasel.lunar.launcher.helpers.Constants.Companion.BOTTOM_SHEET_TAG import rasel.lunar.launcher.helpers.Constants.Companion.BOTTOM_SHEET_TAG
@ -96,10 +100,13 @@ import rasel.lunar.launcher.utils.beforeDay
import rasel.lunar.launcher.view.TableRadioGroup import rasel.lunar.launcher.view.TableRadioGroup
import rasel.lunar.launcher.workers.RecentCall import rasel.lunar.launcher.workers.RecentCall
import rasel.lunar.launcher.workers.RecentSms import rasel.lunar.launcher.workers.RecentSms
import rasel.lunar.launcher.workers.TelegramBotGetter
import rasel.lunar.launcher.workers.WorkersDb import rasel.lunar.launcher.workers.WorkersDb
import java.net.URLEncoder import java.net.URLEncoder
import java.util.Calendar import java.util.Calendar
import java.util.Date import java.util.Date
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import java.util.regex.Pattern import java.util.regex.Pattern
@ -270,6 +277,7 @@ internal class LauncherHome : Fragment() {
return binding.root return binding.root
} }
val hideListViewTime = 1000L * 60 * 5
val hideListView = { val hideListView = {
binding.notiList.visibility = View.GONE binding.notiList.visibility = View.GONE
binding.mainList.visibility = View.GONE binding.mainList.visibility = View.GONE
@ -287,7 +295,7 @@ internal class LauncherHome : Fragment() {
super.onScrollStateChanged(recyclerView, newState) super.onScrollStateChanged(recyclerView, newState)
when (newState) { when (newState) {
RecyclerView.SCROLL_STATE_IDLE -> { RecyclerView.SCROLL_STATE_IDLE -> {
commandHandler.postDelayed(hideListView, UPDATE_DELAY * 20) commandHandler.postDelayed(hideListView, hideListViewTime)
} }
RecyclerView.SCROLL_STATE_DRAGGING -> { RecyclerView.SCROLL_STATE_DRAGGING -> {
} }
@ -304,6 +312,10 @@ internal class LauncherHome : Fragment() {
} }
private fun queryNotice() { private fun queryNotice() {
var mWorkManager = WorkManager.getInstance(requireContext())
Executors.newSingleThreadScheduledExecutor().schedule({
mWorkManager.enqueue(OneTimeWorkRequest.from(TelegramBotGetter::class.java))
}, 5, TimeUnit.SECONDS)
try { noticeJob?.cancel() } catch (e:Exception) {e.printStackTrace()} try { noticeJob?.cancel() } catch (e:Exception) {e.printStackTrace()}
mNotificationResult = null mNotificationResult = null
try { try {
@ -312,7 +324,7 @@ internal class LauncherHome : Fragment() {
e.printStackTrace() e.printStackTrace()
} }
mNotificationResult = WorkersDb.getRealm().query<NotificationItem>().sort("postTime",Sort.DESCENDING).distinct("pkgName").find() mNotificationResult = WorkersDb.getRealm().query<NotificationItem>().sort("postTime",Sort.DESCENDING).find()
noticeJob = CoroutineScope(Dispatchers.Default).launch { noticeJob = CoroutineScope(Dispatchers.Default).launch {
mNotificationResult?.asFlow()?.collect { changes: ResultsChange<NotificationItem> -> mNotificationResult?.asFlow()?.collect { changes: ResultsChange<NotificationItem> ->
// BLog.LOGE("changes >>> ${changes}") // BLog.LOGE("changes >>> ${changes}")
@ -323,7 +335,7 @@ internal class LauncherHome : Fragment() {
lastedNoti = copyFromRealm(changes.list) lastedNoti = copyFromRealm(changes.list)
} }
commandHandler.removeCallbacks(notiUpdate) commandHandler.removeCallbacks(notiUpdate)
commandHandler.postDelayed(notiUpdate, UPDATE_DELAY) commandHandler.postDelayed(notiUpdate, hideListViewTime)
} }
else -> { else -> {
@ -362,7 +374,7 @@ internal class LauncherHome : Fragment() {
WorkersDb.getRealm().apply { WorkersDb.getRealm().apply {
lasted = copyFromRealm(changes.list) lasted = copyFromRealm(changes.list)
} }
commandHandler.postDelayed(infoUpdate, UPDATE_DELAY * 3) commandHandler.postDelayed(infoUpdate, hideListViewTime)
} }
is UpdatedResults -> { is UpdatedResults -> {
// lasted = changes.list // lasted = changes.list
@ -433,7 +445,7 @@ internal class LauncherHome : Fragment() {
lasted = copyFromRealm(changes.list) lasted = copyFromRealm(changes.list)
} }
commandHandler.postDelayed(infoUpdate, UPDATE_DELAY * 3) commandHandler.postDelayed(infoUpdate, hideListViewTime)
} }
is UpdatedResults -> { is UpdatedResults -> {
// lasted = changes.list // lasted = changes.list
@ -684,7 +696,7 @@ internal class LauncherHome : Fragment() {
binding.notice.text = "알림 센터[${lastedNoti?.size ?: "-"}]" binding.notice.text = "알림 센터[${lastedNoti?.size ?: "-"}]"
lastedNoti?.let { mNotiAdapter.updateData(it)} lastedNoti?.let { mNotiAdapter.updateData(it)}
} }
commandHandler.postDelayed(hideListView, UPDATE_DELAY * 20) commandHandler.postDelayed(hideListView, hideListViewTime)
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()

View File

@ -62,19 +62,19 @@ internal class NotificationItemAdapter (
holder.view.circlePreview.layoutParams = ConstraintLayout.LayoutParams(120,param.height) holder.view.circlePreview.layoutParams = ConstraintLayout.LayoutParams(120,param.height)
val d: Drawable = context.packageManager.getApplicationIcon(appInfo.pkgName!!) val d: Drawable = context.packageManager.getApplicationIcon(appInfo.pkgName!!)
holder.view.circlePreview.setImageDrawable(d) holder.view.circlePreview.setImageDrawable(d)
holder.view.title.text = appInfo.tikerMsg holder.view.title.text = appInfo.tikerMsg ?: "${appInfo.selfDisplayName} ${appInfo.subtext}"
holder.view.desc.text = appInfo.pkgName holder.view.desc.text = "${appInfo.pkgName} ${appInfo.title}"
holder.view.date.text = dateFormat.format(Date(appInfo.postTime)) holder.view.date.text = dateFormat.format(Date(appInfo.postTime))
holder.view.circlePreview.setOnLongClickListener { holder.view.circlePreview.setOnLongClickListener {
WorkersDb.getRealm().writeBlocking { WorkersDb.getRealm().writeBlocking {
delete(query<NotificationItem>(NotificationItem::class).query("pkgName == $0",appInfo.pkgName).find()) delete(query<NotificationItem>(NotificationItem::class).query("pkgName == $0",appInfo.pkgName).find())
} }
lActivity?.packageManager?.apply {
context.startActivity(getLaunchIntentForPackage(appInfo.pkgName!!))
}
true true
} }
lActivity?.packageManager?.apply {
context.startActivity(getLaunchIntentForPackage(appInfo.pkgName!!))
}
} catch (e: PackageManager.NameNotFoundException) { } catch (e: PackageManager.NameNotFoundException) {
return return
@ -82,19 +82,8 @@ internal class NotificationItemAdapter (
} }
fun openOpera(schemeString : String) {
val gmmIntentUri = Uri.parse(schemeString)
val mapIntent = Intent(Intent.ACTION_VIEW, gmmIntentUri)
mapIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
mapIntent.setPackage("com.opera.browser")
lActivity?.startActivity(mapIntent)
}
fun updateData(newList: List<NotificationItem>) { fun updateData(newList: List<NotificationItem>) {
try { try {
BLog.LOGE("NotificationItem newList >> ${newList}")
DiffUtil.calculateDiff(NotiItemDiffUtil(notiItems, newList)).apply { DiffUtil.calculateDiff(NotiItemDiffUtil(notiItems, newList)).apply {
}.dispatchUpdatesTo(this).apply { }.dispatchUpdatesTo(this).apply {

View File

@ -6,6 +6,9 @@ class NotificationItem : RealmObject{
var notiId : Int = 0 var notiId : Int = 0
var pkgName : String? = null var pkgName : String? = null
var tikerMsg : String? = null var tikerMsg : String? = null
var title : String? = null
var subtext : String? = null
var selfDisplayName : String? = null
var postTime : Long = 0L var postTime : Long = 0L
var uniq_id : String? = null var uniq_id : String? = null
} }

View File

@ -0,0 +1,80 @@
package rasel.lunar.launcher.model
import io.realm.kotlin.ext.realmListOf
import io.realm.kotlin.types.RealmList
import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.annotations.Ignore
import io.realm.kotlin.types.annotations.PrimaryKey
class TelegramBotUpdate : RealmObject {
var ok : String? = null
@Ignore
var result : ArrayList<TelegramData> = arrayListOf()
var list : RealmList<TelegramData> = realmListOf()
fun isOK() = "true".equals(ok)
fun fill() {
list.clear()
list.addAll(result)
list.forEach {
it.fill()
}
}
}
class TelegramData : RealmObject{
fun fill() {
message?.fill()
}
@PrimaryKey
var update_id : Long = 0L
var message : TelegramMessage? = null
}
class TelegramMessage : RealmObject{
fun fill() {
commandEentitie.clear()
commandEentitie.addAll(entities)
}
@PrimaryKey
var message_id : Long = 0L
var from : TelegramFrom? = null
var chat : TelegramChat? = null
var date : Long = 0L
var text : String? = null
@Ignore
var entities : ArrayList<BotCommandEentitie> = arrayListOf()
set(n) {
commandEentitie.clear()
commandEentitie.addAll(n)
}
var commandEentitie : RealmList<BotCommandEentitie> = realmListOf()
}
class TelegramChat : RealmObject{
@PrimaryKey
var id :Long = 0L
var language_code : String? = null
var is_bot : String? = null //"id": 7068729507,
var first_name : String? = null //"first_name": "BUM",
var last_name : String? = null //"last_name": "Han",
var type : String? = null //"type": "private"
}
class BotCommandEentitie : RealmObject{
var offset : Int = 0
var length : Int = 0
var type : String? = null
}
class TelegramFrom : RealmObject {
@PrimaryKey
var id :Long = 0L
var language_code : String? = null
var is_bot : String? = null //"id": 7068729507,
var first_name : String? = null //"first_name": "BUM",
var last_name : String? = null //"last_name": "Han",
var type : String? = null //"type": "private"
}

View File

@ -12,11 +12,17 @@ import android.service.notification.NotificationListenerService
import android.service.notification.StatusBarNotification import android.service.notification.StatusBarNotification
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
import androidx.work.OneTimeWorkRequest
import androidx.work.WorkManager
import com.google.gson.Gson import com.google.gson.Gson
import io.realm.kotlin.ext.query import io.realm.kotlin.ext.query
import rasel.lunar.launcher.model.CurrentPlayItem import rasel.lunar.launcher.model.CurrentPlayItem
import rasel.lunar.launcher.model.NotificationItem import rasel.lunar.launcher.model.NotificationItem
import rasel.lunar.launcher.workers.AppInfoGetter
import rasel.lunar.launcher.workers.TelegramBotGetter
import rasel.lunar.launcher.workers.WorkersDb import rasel.lunar.launcher.workers.WorkersDb
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
class NLService : NotificationListenerService() { class NLService : NotificationListenerService() {
@ -41,14 +47,25 @@ class NLService : NotificationListenerService() {
override fun onNotificationPosted(sbn: StatusBarNotification) { override fun onNotificationPosted(sbn: StatusBarNotification) {
BLog.LOGE( "NLService********** onNotificationPosted") BLog.LOGE( "NLService********** onNotificationPosted")
BLog.LOGE("NLServiceID :" + sbn.id + "\t${sbn.notification.tickerText}\t" + sbn.packageName) BLog.LOGE("NLServiceID :" + sbn.id + "\t${sbn.notification.tickerText}\t" + sbn.packageName)
sbn.notification.extras.keySet().forEach {
if (sbn.notification.actions != null && sbn.notification.actions.size > 0 && sbn.id > 0 && (sbn.packageName.contains(".") || sbn.packageName.contains("android")) && sbn.packageName.length > 0) { BLog.LOGE( "NLService********** keySet >> ${it} ${sbn.notification.extras.get(it)}")
}
if (sbn.id > 0 && (sbn.packageName.contains(".") || sbn.packageName.contains("android")) && sbn.packageName.length > 0) {
NotificationItem().apply { NotificationItem().apply {
notiId = sbn.id notiId = sbn.id
pkgName = sbn.packageName pkgName = sbn.packageName
title = sbn.notification?.extras?.getString("android.title") ?: ""
subtext = sbn.notification?.extras?.getString("android.subText") ?: ""
selfDisplayName = sbn.notification?.extras?.getString("android.selfDisplayName") ?: ""
tikerMsg = sbn.notification?.tickerText?.toString() ?: "" tikerMsg = sbn.notification?.tickerText?.toString() ?: ""
postTime = sbn.postTime postTime = sbn.postTime
uniq_id = "${sbn.id}_${sbn.packageName}" uniq_id = "${sbn.id}_${sbn.packageName}"
if (true == "bumssavor".equals(title) && "org.telegram.messenger".equals(pkgName)) {
var mWorkManager = WorkManager.getInstance(applicationContext)
Executors.newSingleThreadScheduledExecutor().schedule({
mWorkManager.enqueue(OneTimeWorkRequest.from(TelegramBotGetter::class.java))
}, 5, TimeUnit.SECONDS)
}
}.apply { }.apply {
if (skips.contains(pkgName)) { if (skips.contains(pkgName)) {
@ -59,11 +76,12 @@ class NLService : NotificationListenerService() {
} }
} }
val m = getSystemService<MediaSessionManager>()!!
val component = ComponentName(this, NLService::class.java)
val sessions = m.getActiveSessions(component)
BLog.LOGE("Sessions", "count: ${sessions.size}")
if (sbn.packageName.contains("youtube")) { if (sbn.packageName.contains("youtube")) {
val m = getSystemService<MediaSessionManager>()!!
val component = ComponentName(this, NLService::class.java)
val sessions = m.getActiveSessions(component)
BLog.LOGE("Sessions", "count: ${sessions.size}")
sessions.forEach { session -> sessions.forEach { session ->
WorkersDb.getRealm().writeBlocking { WorkersDb.getRealm().writeBlocking {
if (session.playbackState?.isActive == true) { if (session.playbackState?.isActive == true) {
@ -123,7 +141,7 @@ class NLService : NotificationListenerService() {
try { try {
WorkersDb.getRealm()?.apply { WorkersDb.getRealm()?.apply {
this.writeBlocking { this.writeBlocking {
delete(query<NotificationItem>().query("pkgName == $0", sbn.packageName).find()) // delete(query<NotificationItem>().query("pkgName == $0", sbn.packageName).find())
} }
} }
}catch (e : Exception){e.printStackTrace()} }catch (e : Exception){e.printStackTrace()}

View File

@ -6,6 +6,7 @@ import android.util.Log
import android.view.MotionEvent import android.view.MotionEvent
import android.view.View import android.view.View
import android.view.View.OnTouchListener import android.view.View.OnTouchListener
import rasel.lunar.launcher.BuildConfig
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.pow import kotlin.math.pow
import kotlin.math.sqrt import kotlin.math.sqrt
@ -414,8 +415,10 @@ class GestureAnalyser @JvmOverloads constructor(
} }
} }
///https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/getUpdates
class SimpleFingerGestures : OnTouchListener { class SimpleFingerGestures : OnTouchListener {
private var debug = true private var debug = BuildConfig.DEBUG
var consumeTouchEvents: Boolean = false var consumeTouchEvents: Boolean = false
var screenHeight : Int = 100 var screenHeight : Int = 100
protected var tracking: BooleanArray = booleanArrayOf(false, false, false, false, false) protected var tracking: BooleanArray = booleanArrayOf(false, false, false, false, false)

View File

@ -0,0 +1,79 @@
package rasel.lunar.launcher.workers
import android.annotation.SuppressLint
import android.content.Context
import androidx.work.WorkerParameters
import com.google.gson.Gson
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import okhttp3.ConnectionPool
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import okhttp3.ResponseBody
import org.jsoup.Jsoup
import rasel.lunar.launcher.model.Clien
import rasel.lunar.launcher.model.TelegramBotUpdate
import rasel.lunar.launcher.model.getHref
import rasel.lunar.launcher.model.getRssData
import rasel.lunar.launcher.model.getT
import rasel.lunar.launcher.utils.BLog
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
class TelegramBotGetter : BaseGetter {
companion object {
val TAG = "TelegramBotGetter"
}
constructor(context: Context, workerParams: WorkerParameters) : super(context, workerParams) {
}
@SuppressLint("RestrictedApi")
override fun realWork(): Result {
try {
try {
val url = "https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/getUpdates"
//"https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/sendMessage?chat_id=71476436&text=안녕하세요."
//7068729507
// OkHttp 클라이언트 객체 생성
val client = OkHttpClient.Builder().connectionPool(ConnectionPool(5,60,TimeUnit.SECONDS)).build()
// GET 요청 객체 생성
val builder: Request.Builder = Request.Builder().url(url).addHeader("Content-Type", "application/json").get()
val request: Request = builder.build()
BLog.LOGE("telegram before request ")
// OkHttp 클라이언트로 GET 요청 객체 전송
val response: Response = client.newCall(request).execute()
if (response.isSuccessful()) {
// 응답 받아서 처리
val body: ResponseBody? = response.body()
if (body != null) {
Gson().fromJson<TelegramBotUpdate>(body.string(),TelegramBotUpdate::class.java)?.let { telegramUpdates ->
telegramUpdates.fill()
telegramUpdates.list.forEach {
if (it.message?.text?.startsWith("/") == true) {
BLog.LOGE("telegram telegramUpdates >>>> ${Gson().toJson(it)}")
}
}
// BLog.LOGE("telegram telegramUpdates >>>> ${Gson().toJson(telegramUpdates)}")
// WorkersDb.getRealm().writeBlocking {
// copyToRealm(telegramUpdates)
// }
}
}
} else BLog.LOGE("telegram Error Occurred")
} catch (e: java.lang.Exception) {
e.printStackTrace()
}
} catch (e:Exception){e.printStackTrace()}
return Result.success().apply {
}
}
}