From 384881bf071c88ad5040f70aa68915078a6b8e97 Mon Sep 17 00:00:00 2001 From: lunaticbum <> Date: Wed, 11 Sep 2024 18:28:11 +0900 Subject: [PATCH] .... --- .../rasel/lunar/launcher/LauncherActivity.kt | 2 - .../rasel/lunar/launcher/home/LauncherHome.kt | 36 ++++++++-------- .../lunar/launcher/workers/RecentSmsGetter.kt | 41 ++++++++++++++++--- .../rasel/lunar/launcher/workers/WorkersDb.kt | 2 +- 4 files changed, 54 insertions(+), 27 deletions(-) diff --git a/app/src/main/kotlin/rasel/lunar/launcher/LauncherActivity.kt b/app/src/main/kotlin/rasel/lunar/launcher/LauncherActivity.kt index 3d0272d..3fae753 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/LauncherActivity.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/LauncherActivity.kt @@ -71,8 +71,6 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.Observer import androidx.recyclerview.widget.RecyclerView import androidx.viewpager2.widget.ViewPager2 -import androidx.window.layout.FoldingFeature -import androidx.window.layout.WindowLayoutInfo import androidx.work.ExistingPeriodicWorkPolicy import androidx.work.PeriodicWorkRequestBuilder import androidx.work.WorkManager diff --git a/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt b/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt index 425bd23..79163cf 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt @@ -144,8 +144,7 @@ internal class LauncherHome : Fragment() { val commandHandler = Handler(Looper.getMainLooper()) val smsUpdate = Runnable { - BLog.LOGE("observeForever smsList.size >>> ${smsList.size}") - binding.recentSms.text = "최근 문자 [${smsList.size}]" + chooseAdpater() } @@ -606,41 +605,40 @@ internal class LauncherHome : Fragment() { binding.notice.isSelected = false } } else if(binding.recentSms.isSelected){ - if (smsList.size > 0) { - try { - smsList.sortByDescending { it.rcvDate } - binding.smsList.visibility = View.VISIBLE -// Handler(Looper.getMainLooper()).post { - binding.smsList.visibility = View.VISIBLE - mSmsLogsAdapter.updateData(smsList) - binding.missedCalls.isSelected = false - binding.otherCheck.isSelected = false - binding.notice.isSelected = false -// } - } catch (e : Exception) { + WorkersDb.getRealm().apply { + val result = query().query("rcvDate >= $0 OR pstDate >= $0 ", dateParam) + .sort(Pair("pstDate",Sort.DESCENDING),Pair("rcvDate", Sort.DESCENDING)).find() + if (result.size > 0) { + try { + BLog.LOGE("observeForever smsList.size >>> ${result.size}") + binding.recentSms.text = "최근 문자 [${result.size}]" + binding.smsList.visibility = View.VISIBLE + smsList.clear() + smsList.addAll(copyFromRealm(result)) + mSmsLogsAdapter.updateData(smsList) + binding.missedCalls.isSelected = false + binding.otherCheck.isSelected = false + binding.notice.isSelected = false + } catch (e: Exception) { + } } } } else if(binding.otherCheck.isSelected) { -// Handler(Looper.getMainLooper()).post { binding.missedCalls.isSelected = false binding.recentSms.isSelected = false binding.notice.isSelected = false binding.infoList.visibility = View.VISIBLE binding.otherCheck.text = "최근 정보[${lasted?.size ?: "-"}]" lasted?.let { mRssAdapter.updateData(it) } - -// } } else if(binding.notice.isSelected) { -// Handler(Looper.getMainLooper()).post { binding.missedCalls.isSelected = false binding.recentSms.isSelected = false binding.otherCheck.isSelected = false binding.notiList.visibility = View.VISIBLE binding.notice.text = "알림 센터[${lastedNoti?.size ?: "-"}]" lastedNoti?.let { mNotiAdapter.updateData(it)} -// } } commandHandler.postDelayed(hideListView, UPDATE_DELAY * 5) } diff --git a/app/src/main/kotlin/rasel/lunar/launcher/workers/RecentSmsGetter.kt b/app/src/main/kotlin/rasel/lunar/launcher/workers/RecentSmsGetter.kt index 5df95c3..8e2e2ef 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/workers/RecentSmsGetter.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/workers/RecentSmsGetter.kt @@ -8,6 +8,12 @@ import android.net.Uri import android.provider.Telephony import androidx.work.WorkerParameters import com.google.gson.Gson +import io.realm.kotlin.ext.query +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 import rasel.lunar.launcher.LauncherActivity.Companion.lActivity import rasel.lunar.launcher.home.LauncherHome.Companion.smsList import rasel.lunar.launcher.utils.BLog @@ -30,7 +36,7 @@ class RecentSmsGetter : BaseGetter { @SuppressLint("RestrictedApi") override fun realWork(): Result { - var dateParam = beforeDay(Date(),7).toString() + var dateParam = beforeDay(Date(),30).toString() val managedCursor = lActivity?.contentResolver?.query( Telephony.Sms.CONTENT_URI, arrayOf( Telephony.Sms.THREAD_ID, @@ -83,7 +89,13 @@ class RecentSmsGetter : BaseGetter { log.isMms = false // BLog.LOGE("RecentSmsGetter resultData put ${phNumber +"_"+ reciveDate} >>> ${log.toJson()}") log.sender = getContactName(applicationContext.contentResolver,phNumber) ?: "" - smsList.add(log) + WorkersDb.getRealm().apply { + if (query("id == $0", id).find().size == 0) { + writeBlocking { + copyToRealm(log) + } + } + } } } catch (e: Exception) { @@ -100,7 +112,8 @@ class RecentSmsGetter : BaseGetter { } -internal class RecentSms { +internal class RecentSms : RealmObject { + @PrimaryKey var id : String = "" var isMms : Boolean = false var addr : String = "" @@ -109,6 +122,11 @@ internal class RecentSms { var pstDate : Long = 0L var body : String = "" var person : String = "" + var images : RealmList = realmListOf() + var videos : RealmList = realmListOf() + var audios : RealmList = realmListOf() + var texts : RealmList = realmListOf() + @Ignore var mmsContents : HashMap> = hashMapOf() var sender : String = "" @@ -133,10 +151,16 @@ internal class RecentSms { this.id = id this.rcvDate = date this.mmsContents = body + this.images.addAll(mmsContents.get("image")!!) + this.audios.addAll(mmsContents.get("audio")!!) + this.texts.addAll(mmsContents.get("text")!!) + this.videos.addAll(mmsContents.get("video")!!) this.addr = sender this.isMms = true } + constructor() + fun toJson() : String { return Gson().toJson(this) } @@ -301,7 +325,7 @@ internal class MmsQueryHelper( fun convertData(cursor: Cursor?) { cursor ?: return - val dateTime = beforeDay(Date(),7) + val dateTime = beforeDay(Date(),30) cursor.use { if (cursor.moveToFirst()) { do { @@ -310,7 +334,14 @@ internal class MmsQueryHelper( }.getOrNull() data?.let { if (it?.pstDate ?: 0L > dateTime || it?.rcvDate ?: 0L > dateTime) { - smsList.add(it) + WorkersDb.getRealm().apply { + if (query("id == $0", it.id).find().size == 0) { + writeBlocking { + copyToRealm(it) + } + } + } +// smsList.add(it) } } } while (cursor.moveToNext()) diff --git a/app/src/main/kotlin/rasel/lunar/launcher/workers/WorkersDb.kt b/app/src/main/kotlin/rasel/lunar/launcher/workers/WorkersDb.kt index f20d157..fa0a826 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/workers/WorkersDb.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/workers/WorkersDb.kt @@ -17,7 +17,7 @@ import kotlin.reflect.KClass object WorkersDb { - val clazz : Set> = setOf(RssData::class, NotificationItem::class, AppInfo::class,SimpleContact::class, RecentCall::class) + val clazz : Set> = setOf(RssData::class, NotificationItem::class, AppInfo::class,SimpleContact::class, RecentCall::class, RecentSms::class) val schemaVersion : Long = 0L private var pRealm : Realm? = null