This commit is contained in:
lunaticbum 2024-09-19 14:24:40 +09:00
parent ea3858ba1f
commit 9342628677
8 changed files with 92 additions and 104 deletions

View File

@ -70,6 +70,7 @@ import androidx.core.view.updatePadding
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.OneTimeWorkRequest
import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager
import com.google.android.material.color.DynamicColors
@ -186,15 +187,18 @@ internal class LauncherActivity : AppCompatActivity() {
.build())
}, delay, TimeUnit.SECONDS)
delay = delay + 3L
// Executors.newSingleThreadScheduledExecutor().schedule({
// mWorkManager?.cancelAllWorkByTag(AppInfoGetter.TAG)
// mWorkManager?.enqueueUniquePeriodicWork(
// AppInfoGetter.TAG, ExistingPeriodicWorkPolicy.CANCEL_AND_REENQUEUE,
// PeriodicWorkRequestBuilder<AppInfoGetter>(12, TimeUnit.HOURS)
// .addTag(AppInfoGetter.TAG)
// .build())
// }, delay, TimeUnit.SECONDS)
// delay = delay + 3L
Executors.newSingleThreadScheduledExecutor().schedule({
mWorkManager?.cancelAllWorkByTag(AppInfoGetter.TAG)
mWorkManager?.enqueueUniquePeriodicWork(
AppInfoGetter.TAG, ExistingPeriodicWorkPolicy.CANCEL_AND_REENQUEUE,
PeriodicWorkRequestBuilder<AppInfoGetter>(12, TimeUnit.HOURS)
.addTag(AppInfoGetter.TAG)
.build())
}, delay, TimeUnit.SECONDS)
delay = delay + 3L
mWorkManager?.enqueue(OneTimeWorkRequest.from(AppInfoGetter::class.java))
}, 5, TimeUnit.SECONDS)
}
@ -1097,4 +1101,3 @@ fun openOpera(schemeString : String) {
lActivity?.startActivity(mapIntent)
}

View File

@ -118,11 +118,6 @@ internal class AppsAdapter(
}
}
data class Packages (
val packageName: String,
val appName: String,
val category : String
)
internal class AppsDiffUtil(
private val oldList: List<AppInfo>, private val newList: List<AppInfo>

View File

@ -115,8 +115,8 @@ internal class LauncherHome : Fragment() {
var home : LauncherHome? = null
var lastedFinishedPageUrl : String = ""
// var recentCalls = arrayListOf<RecentCall>()
var callList = arrayListOf<RecentCall>()
var smsList = arrayListOf<RecentSms>()
// var callList = arrayListOf<RecentCall>()
// var smsList = arrayListOf<RecentSms>()
var listTags = arrayListOf<RssDataInterface>()
}
@ -164,8 +164,8 @@ internal class LauncherHome : Fragment() {
fragManager = lActivity!!.supportFragmentManager
settingsPrefs = requireContext().getSharedPreferences(PREFS_SETTINGS, 0)
batteryReceiver = BatteryReceiver(binding.batteryProgress)
mRecentCallsAdapter = RecentCallsAdapter(callList, requireContext())
mSmsLogsAdapter = SmsLogsAdapter(smsList, requireContext())
mRecentCallsAdapter = RecentCallsAdapter(arrayListOf(), requireContext())
mSmsLogsAdapter = SmsLogsAdapter(arrayListOf(), requireContext())
mNotiAdapter = NotificationItemAdapter(requireContext())
mRssAdapter = RssItemAdapter(requireContext())
@ -173,7 +173,7 @@ internal class LauncherHome : Fragment() {
binding.notiList.addItemDecoration(decoration)
binding.infoList.addItemDecoration(decoration)
binding.missedCalls.isSelected = true
binding.smsList.visibility = View.GONE
binding.infoList.visibility = View.GONE
@ -198,16 +198,12 @@ internal class LauncherHome : Fragment() {
try{binding.notiList.removeOnScrollListener(onScrChanged)}catch (e : Exception){e.printStackTrace()}
binding.notiList.addOnScrollListener(onScrChanged)
workmanager()?.getWorkInfosByTagLiveData(SMS_WORK_TAG)?.observeForever {
commandHandler.removeCallbacks(smsUpdate)
commandHandler.postDelayed(smsUpdate,UPDATE_DELAY)
it.clear()
}
workmanager()?.getWorkInfosByTagLiveData(CALL_WORK_TAG)?.observeForever {
commandHandler.removeCallbacks(callUpdate)
commandHandler.postDelayed(callUpdate,UPDATE_DELAY)
it.clear()
binding.currentMusic?.setOnClickListener {
lActivity?.apply {
packageManager?.apply {
startActivity(getLaunchIntentForPackage("com.google.android.apps.youtube.music"))
}
}
}
GlobalScope.launch {
@ -238,7 +234,7 @@ internal class LauncherHome : Fragment() {
}
}
BLog.LOGE("onCreateView()")
// BLog.LOGE("onCreateView()")
binding.nextBtn.setOnClickListener {
val mAudioManager =
requireContext().getSystemService(AUDIO_SERVICE) as AudioManager
@ -275,10 +271,14 @@ internal class LauncherHome : Fragment() {
}
val hideListView = {
// binding.notiList.visibility = View.GONE
// binding.mainList.visibility = View.GONE
// binding.infoList.visibility = View.GONE
// binding.smsList.visibility = View.GONE
binding.notiList.visibility = View.GONE
binding.mainList.visibility = View.GONE
binding.infoList.visibility = View.GONE
binding.smsList.visibility = View.GONE
binding.otherCheck.isSelected = false
binding.recentSms.isSelected = false
binding.missedCalls.isSelected = false
binding.notice.isSelected = false
}
@ -287,7 +287,7 @@ internal class LauncherHome : Fragment() {
super.onScrollStateChanged(recyclerView, newState)
when (newState) {
RecyclerView.SCROLL_STATE_IDLE -> {
commandHandler.postDelayed(hideListView, UPDATE_DELAY * 5)
commandHandler.postDelayed(hideListView, UPDATE_DELAY * 20)
}
RecyclerView.SCROLL_STATE_DRAGGING -> {
}
@ -315,10 +315,10 @@ internal class LauncherHome : Fragment() {
mNotificationResult = WorkersDb.getRealm().query<NotificationItem>().sort("postTime",Sort.DESCENDING).find()
noticeJob = CoroutineScope(Dispatchers.Default).launch {
mNotificationResult?.asFlow()?.collect { changes: ResultsChange<NotificationItem> ->
BLog.LOGE("changes >>> ${changes}")
// BLog.LOGE("changes >>> ${changes}")
when (changes) {
is UpdatedResults -> {
BLog.LOGE("ResultsChange onNotificationPosted")
// BLog.LOGE("ResultsChange onNotificationPosted")
WorkersDb.getRealm().apply {
lastedNoti = copyFromRealm(changes.list)
}
@ -336,7 +336,6 @@ internal class LauncherHome : Fragment() {
}
fun queryInfos(filter: Collection<RssDataType>? = arrayListOf(RssDataType.GURU,RssDataType.Most,RssDataType.REDDIT_nsfw)) {
BLog.LOGE("${this} ::::: queryInfos >>>> ${filter}")
try { infosJob?.cancel() } catch (e:Exception) {e.printStackTrace()}
mRssDataResult = null
try {
@ -346,7 +345,6 @@ internal class LauncherHome : Fragment() {
WorkersDb.getRealm().apply { writeBlocking {
delete(query<RssData>().query("pubDate < $0",beforeDay(Date(),3)).query("category != $0 || category != $1 ", RssDataType.GURU.name,RssDataType.Most.name).find())
}}
BLog.LOGE("${this} ::::: queryInfos after delete >>>> ")
var rQ = WorkersDb.getRealm().query<RssData>().query("pubDate > $0", beforeDay(Date(),3))
filter!!.forEach {
rQ = rQ.query("category != $0", it.name)
@ -379,7 +377,6 @@ internal class LauncherHome : Fragment() {
}
fun queryInfos(keyword : String, category : ArrayList<String> = arrayListOf()) {
BLog.LOGE("${this} ::::: queryInfos >>>> ${keyword}")
try { infosJob?.cancel() } catch (e:Exception) {e.printStackTrace()}
mRssDataResult = null
try {
@ -389,7 +386,6 @@ internal class LauncherHome : Fragment() {
WorkersDb.getRealm().apply { writeBlocking {
delete(query<RssData>().query("pubDate < $0",beforeDay(Date(),3)).query("category != $0 || category != $1 ", RssDataType.GURU.name,RssDataType.Most.name).find())
}}
BLog.LOGE("${this} ::::: queryInfos after delete >>>> ")
var rQ = WorkersDb.getRealm().query<RssData>().query("pubDate > $0", beforeDay(Date(),3))
if(keyword.length > 0) {
BLog.LOGE("queryInfos it >>> ${keyword}")
@ -425,17 +421,14 @@ internal class LauncherHome : Fragment() {
rQ = rQ.query(queryString)
}
BLog.LOGE("queryInfos rQ.description() >>>>> ${rQ.description()}")
//limit(1000)
mRssDataResult = rQ.sort("pubDate ", Sort.DESCENDING).find()
BLog.LOGE("${this} ::::: queryInfos after query find >>>> ")
infosJob = CoroutineScope(Dispatchers.Default).launch {
mRssDataResult?.asFlow()?.collect { changes: ResultsChange<RssData> ->
commandHandler.removeCallbacks(infoUpdate)
when (changes) {
is InitialResults -> {
BLog.LOGE("${this} ::::: queryInfos after changes size >>>> ${changes.list.size}")
WorkersDb.getRealm().apply {
lasted = copyFromRealm(changes.list)
}
@ -649,11 +642,10 @@ internal class LauncherHome : Fragment() {
if (binding.missedCalls.isSelected) {
WorkersDb.getRealm().apply {
val result = query<RecentCall>().query("callDayTime >= $0", dateParam).sort("callDayTime", Sort.DESCENDING).find()
callList.clear()
callList.addAll(copyFromRealm(result))
binding.missedCalls.text = "최근 통화 [${callList.size}]"
val list = copyFromRealm(result)
binding.missedCalls.text = "최근 통화 [${list.size}]"
binding.mainList.visibility = View.VISIBLE
mRecentCallsAdapter.updateData(callList)
mRecentCallsAdapter.updateData(list)
binding.recentSms.isSelected = false
binding.otherCheck.isSelected = false
binding.notice.isSelected = false
@ -664,13 +656,10 @@ internal class LauncherHome : Fragment() {
.sort("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)
val list = copyFromRealm(result)
mSmsLogsAdapter.updateData(list)
binding.missedCalls.isSelected = false
binding.otherCheck.isSelected = false
binding.notice.isSelected = false
@ -695,7 +684,7 @@ internal class LauncherHome : Fragment() {
binding.notice.text = "알림 센터[${lastedNoti?.size ?: "-"}]"
lastedNoti?.let { mNotiAdapter.updateData(it)}
}
commandHandler.postDelayed(hideListView, UPDATE_DELAY * 5)
commandHandler.postDelayed(hideListView, UPDATE_DELAY * 20)
}
override fun onResume() {
super.onResume()

View File

@ -55,29 +55,34 @@ internal class NotificationItemAdapter (
@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: NotiHolder, position: Int) {
val todo = notiItems[position]
val appInfo = notiItems[position]
try {
holder.view.circlePreview.visibility = View.VISIBLE
var param = holder.view.circlePreview.layoutParams
holder.view.circlePreview.layoutParams = ConstraintLayout.LayoutParams(120,param.height)
val d: Drawable = context.packageManager.getApplicationIcon(todo.pkgName!!)
val d: Drawable = context.packageManager.getApplicationIcon(appInfo.pkgName!!)
holder.view.circlePreview.setImageDrawable(d)
holder.view.title.text = todo.tikerMsg
holder.view.desc.text = todo.pkgName
holder.view.date.text = dateFormat.format(Date(todo.postTime))
holder.view.title.text = appInfo.tikerMsg
holder.view.desc.text = appInfo.pkgName
holder.view.date.text = dateFormat.format(Date(appInfo.postTime))
holder.view.circlePreview.setOnLongClickListener {
WorkersDb.getRealm().writeBlocking {
delete(query<NotificationItem>(NotificationItem::class).query("pkgName == $0",todo.pkgName).find())
delete(query<NotificationItem>(NotificationItem::class).query("pkgName == $0",appInfo.pkgName).find())
}
true
}
lActivity?.packageManager?.apply {
context.startActivity(getLaunchIntentForPackage(appInfo.pkgName!!))
}
} catch (e: PackageManager.NameNotFoundException) {
return
}
}
fun openOpera(schemeString : String) {
val gmmIntentUri = Uri.parse(schemeString)
val mapIntent = Intent(Intent.ACTION_VIEW, gmmIntentUri)
@ -101,44 +106,10 @@ internal class NotificationItemAdapter (
e.printStackTrace()
}
}
fun openNews(schemeString : String) {
val gmmIntentUri = Uri.parse(schemeString)
val mapIntent = Intent(Intent.ACTION_VIEW, gmmIntentUri)
mapIntent.setPackage("com.android.chrome")
lActivity?.startActivity(mapIntent)
}
fun openYouTube(schemeString : String) {
val gmmIntentUri = Uri.parse(schemeString)
val mapIntent = Intent(Intent.ACTION_VIEW, gmmIntentUri)
mapIntent.setPackage("com.google.android.youtube")
lActivity?.startActivity(mapIntent)
}
fun openReddit(schemeString : String) {
val gmmIntentUri = Uri.parse(schemeString)
val mapIntent = Intent(Intent.ACTION_VIEW, gmmIntentUri)
mapIntent.setPackage("com.reddit.frontpage")
lActivity?.startActivity(mapIntent)
}
fun openDotax(schemeString : String) {
val gmmIntentUri = Uri.parse(schemeString)
val mapIntent = Intent(Intent.ACTION_VIEW)
mapIntent.setPackage("net.daum.android.cafe")
mapIntent.setData(gmmIntentUri)
lActivity?.startActivity(mapIntent)
}
}
//fun dp2px(dp: Float): Float {
// val resources: Resources = this.getResources()
// val metrics = resources.displayMetrics
// val px = dp * (metrics.densityDpi.toFloat() / DisplayMetrics.DENSITY_DEFAULT)
// return px
//}
internal class NotiHolder(var view: ListItemWithBinding) : RecyclerView.ViewHolder(view.root)
internal class NotiItemDiffUtil(
var oldList: List<NotificationItem>, var newList: List<NotificationItem>

View File

@ -136,8 +136,8 @@ internal class RecentCallsAdapter(
this.recyclerView = recyclerView
}
fun updateData(newList: ArrayList<RecentCall>) {
val diffUtilResult = DiffUtil.calculateDiff(RecentCallDiffUtil(callList, newList))
fun updateData(newList: Collection<RecentCall>) {
val diffUtilResult = DiffUtil.calculateDiff(RecentCallDiffUtil(callList, newList.toList()))
diffUtilResult.dispatchUpdatesTo(this).apply {
val visibleItemCount = (layoutManager?.findLastVisibleItemPosition() ?: 0) - (layoutManager?.findFirstVisibleItemPosition() ?: 0)
if (visibleItemCount > 0) {
@ -145,8 +145,8 @@ internal class RecentCallsAdapter(
recyclerView?.scrollToPosition(0)
}
}
// callList.clear()
// callList.addAll(newList)
callList.clear()
callList.addAll(newList)
}
}

View File

@ -111,8 +111,8 @@ internal class SmsLogsAdapter(
fun updateData(newList: List<RecentSms>) {
val diffUtilResult = DiffUtil.calculateDiff(SmsDiffUtil(smsList, newList))
diffUtilResult.dispatchUpdatesTo(this)
// smsList.clear()
// smsList.addAll(newList)
smsList.clear()
smsList.addAll(newList)
}
/* update dialog */

View File

@ -3,7 +3,15 @@ package rasel.lunar.launcher.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import androidx.work.OneTimeWorkRequest
import androidx.work.WorkManager
import io.realm.kotlin.ext.query
import rasel.lunar.launcher.model.AppInfo
import rasel.lunar.launcher.utils.BLog
import rasel.lunar.launcher.workers.AppInfoGetter
import rasel.lunar.launcher.workers.WorkersDb
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
class PackageEventReceiver : BroadcastReceiver() {
@ -12,8 +20,32 @@ class PackageEventReceiver : BroadcastReceiver() {
val action = intent.action
BLog.LOGE("action >>>> ${action}")
if (action == Intent.ACTION_PACKAGE_ADDED) {
when(action) {
Intent.ACTION_PACKAGE_ADDED,Intent.ACTION_PACKAGE_INSTALL -> {
startAppInfoGetter(context)
}
Intent.ACTION_PACKAGE_REMOVED -> {
val packageName = intent.data?.schemeSpecificPart
if (packageName?.length ?: 0 > 0) {
WorkersDb.getRealm().writeBlocking {
val result = query<AppInfo>("pkgName == $0", packageName).find()
if (result.size == 1) {
delete(result)
}
}
}
startAppInfoGetter(context)
}
else -> {
}
}
}
fun startAppInfoGetter(context: Context) {
var mWorkManager = WorkManager.getInstance(context)
Executors.newSingleThreadScheduledExecutor().schedule({
mWorkManager.enqueue(OneTimeWorkRequest.from(AppInfoGetter::class.java))
}, 5, TimeUnit.SECONDS)
}
}

View File

@ -15,7 +15,6 @@ 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
import rasel.lunar.launcher.utils.beforeDay
import rasel.lunar.launcher.utils.getContactName
@ -51,7 +50,6 @@ class RecentSmsGetter : BaseGetter {
), Telephony.Sms.DATE + "> ${dateParam}", null, Telephony.Sms.DEFAULT_SORT_ORDER)
if (managedCursor != null && managedCursor.isClosed == false) {
try {
smsList.clear()
val tid = managedCursor.getColumnIndex(Telephony.Sms.THREAD_ID)
val address = managedCursor.getColumnIndex(Telephony.Sms.ADDRESS)
val type = managedCursor.getColumnIndex(Telephony.Sms.TYPE)