From 87263747f32af9fd5a030ff5e19883c68f83394c Mon Sep 17 00:00:00 2001 From: lunaticbum <> Date: Tue, 10 Sep 2024 18:50:34 +0900 Subject: [PATCH] ... --- .../rasel/lunar/launcher/home/LauncherHome.kt | 32 ++++++++------- .../lunar/launcher/model/CommunityData.kt | 6 +++ .../launcher/todos/MissedCallsAdapter.kt | 26 +++++++++--- .../lunar/launcher/todos/SmsLogsAdapter.kt | 16 +++++++- .../rasel/lunar/launcher/utils/DataUtils.kt | 24 ++++++----- .../rasel/lunar/launcher/utils/JamoUtils.kt | 40 +++++++++++++++++++ .../launcher/workers/RecentCallGetter.kt | 26 +++++------- .../lunar/launcher/workers/RecentSmsGetter.kt | 4 +- app/src/main/res/color/sms_board.xml | 6 +++ app/src/main/res/drawable/sms_bg.xml | 5 +-- app/src/main/res/layout/calllog_item.xml | 37 +++++++++++++++++ 11 files changed, 166 insertions(+), 56 deletions(-) create mode 100644 app/src/main/kotlin/rasel/lunar/launcher/utils/JamoUtils.kt create mode 100644 app/src/main/res/color/sms_board.xml create mode 100644 app/src/main/res/layout/calllog_item.xml 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 04c51c8..74c30ac 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt @@ -97,6 +97,7 @@ import rasel.lunar.launcher.todos.NotificationItemAdapter import rasel.lunar.launcher.todos.RssItemAdapter import rasel.lunar.launcher.todos.SmsLogsAdapter import rasel.lunar.launcher.utils.BLog +import rasel.lunar.launcher.utils.JamoUtils import rasel.lunar.launcher.utils.RssList.jGuruMain import rasel.lunar.launcher.utils.SimpleFingerGestures import rasel.lunar.launcher.utils.beforeDay @@ -122,7 +123,7 @@ internal class LauncherHome : Fragment() { companion object { var home : LauncherHome? = null var lastedFinishedPageUrl : String = "" - var recentCalls = hashMapOf() + var recentCalls = arrayListOf() var callList = arrayListOf() var smsList = arrayListOf() var listTags = arrayListOf() @@ -180,7 +181,7 @@ internal class LauncherHome : Fragment() { mRssAdapter = RssItemAdapter(requireContext()) val decoration = DividerItemDecoration(requireContext(), DividerItemDecoration.VERTICAL) - binding.mainList.addItemDecoration(decoration) + binding.notiList.addItemDecoration(decoration) binding.infoList.addItemDecoration(decoration) binding.missedCalls.isSelected = true @@ -188,7 +189,7 @@ internal class LauncherHome : Fragment() { binding.infoList.visibility = View.GONE binding.notiList.layoutManager = LinearLayoutManager(requireContext()) - binding.mainList.layoutManager = LinearLayoutManager(requireContext()) + binding.mainList.layoutManager = GridLayoutManager(requireContext(),2) binding.smsList.layoutManager = GridLayoutManager(requireContext(),2) binding.infoList.layoutManager = LinearLayoutManager(requireContext()) @@ -351,8 +352,13 @@ internal class LauncherHome : Fragment() { var rQ = WorkersDb.getRealm().query().query("pubDate > $0", beforeDay(Date(),3)) if(keyword.length > 0) keyword.split("").forEach { - rQ = rQ.query("title CONTAINS $0 OR title CONTAINS $1", it.toUpperCase(), it.toLowerCase()) + if (Character.codePointAt(it, 0) in 0xAC00..0xD79D) { + rQ = rQ.query("title CONTAINS $0 OR chosung CONTAINS $1 ", it, JamoUtils.splitOne(it)) + } else { + rQ = rQ.query("title CONTAINS $0 OR title CONTAINS $1", it.toUpperCase(), it.toLowerCase()) + } } + category?.let { rQ = rQ.query("category == $0", it) } @@ -571,18 +577,14 @@ internal class LauncherHome : Fragment() { if (recentCalls.size > 0) { try { callList.clear() - recentCalls.forEach { t, u -> - callList.add(u) - }.apply { - callList.sortByDescending { it.date } + callList.addAll(recentCalls) + callList.sortByDescending { it.date } // Handler(Looper.getMainLooper()).post { - binding.mainList.visibility = View.VISIBLE - mMissedCallsAdapter.updateData(callList) - binding.recentSms.isSelected = false - binding.otherCheck.isSelected = false - binding.notice.isSelected = false -// } - } + binding.mainList.visibility = View.VISIBLE + mMissedCallsAdapter.updateData(callList) + binding.recentSms.isSelected = false + binding.otherCheck.isSelected = false + binding.notice.isSelected = false } catch (e : Exception) { } diff --git a/app/src/main/kotlin/rasel/lunar/launcher/model/CommunityData.kt b/app/src/main/kotlin/rasel/lunar/launcher/model/CommunityData.kt index eaeb93f..9064c02 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/model/CommunityData.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/model/CommunityData.kt @@ -5,6 +5,7 @@ import io.realm.kotlin.types.annotations.Ignore import io.realm.kotlin.types.annotations.PrimaryKey import org.jsoup.select.Elements import rasel.lunar.launcher.utils.BLog +import rasel.lunar.launcher.utils.JamoUtils import rasel.lunar.launcher.utils.afterDay import rasel.lunar.launcher.utils.beforeDay import java.text.SimpleDateFormat @@ -192,6 +193,9 @@ class RssData : RealmObject, RssDataInterface { var thumbnail : String? = null var pubDate : Long = 0L var category : String? = null + + var chosung : String? = null + @Ignore var mRssDataType : RssDataType? = null override fun title(): String { @@ -200,6 +204,8 @@ class RssData : RealmObject, RssDataInterface { if(title?.length ?: 0 > 30) title?.substring(0,30).plus("...") else title ?: "" } else -> title ?: "" + }.apply { + chosung = JamoUtils.split(this).joinToString { "" } } } diff --git a/app/src/main/kotlin/rasel/lunar/launcher/todos/MissedCallsAdapter.kt b/app/src/main/kotlin/rasel/lunar/launcher/todos/MissedCallsAdapter.kt index db2d85c..3c57a21 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/todos/MissedCallsAdapter.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/todos/MissedCallsAdapter.kt @@ -22,6 +22,7 @@ import android.annotation.SuppressLint import android.content.Context import android.content.Intent import android.net.Uri +import android.provider.CallLog import android.provider.ContactsContract import android.view.LayoutInflater import android.view.View @@ -32,6 +33,7 @@ import androidx.recyclerview.widget.RecyclerView import com.google.android.material.bottomsheet.BottomSheetDialog import rasel.lunar.launcher.LauncherActivity.Companion.lActivity import rasel.lunar.launcher.R +import rasel.lunar.launcher.databinding.CalllogItemBinding import rasel.lunar.launcher.databinding.ListItemBinding import rasel.lunar.launcher.databinding.TodoDialogBinding import rasel.lunar.launcher.helpers.UniUtils.Companion.copyToClipboard @@ -49,7 +51,7 @@ internal class MissedCallsAdapter( private val currentFragment = lActivity!!.supportFragmentManager.findFragmentById(R.id.mainFragmentsContainer) override fun onCreateViewHolder(viewGroup: ViewGroup, i: Int): MissedCallsHolder { - val binding = ListItemBinding.inflate(LayoutInflater.from(viewGroup.context), viewGroup, false) + val binding = CalllogItemBinding.inflate(LayoutInflater.from(viewGroup.context), viewGroup, false) return MissedCallsHolder(binding) } @@ -61,14 +63,26 @@ internal class MissedCallsAdapter( @SuppressLint("SetTextI18n") override fun onBindViewHolder(holder: MissedCallsHolder, position: Int) { val todo = callList[position] - holder.view.itemText.text = "\u25CF ${if(todo.name.equals("unknown")) todo.number else { todo.name}} , ${todo.typeString} : ${todo.count} : ${todo.date}" + holder.view.name.text = if(todo.name.equals("unknown")) todo.number else { todo.name} + when (todo.type) { +// CallLog.Calls.INCOMING_TYPE -> { dir = "INCOMING_TYPE" } +// CallLog.Calls.OUTGOING_TYPE -> { dir = "OUTGOING_TYPE" } + CallLog.Calls.MISSED_TYPE -> { holder.view.root.isSelected = true } +// CallLog.Calls.VOICEMAIL_TYPE -> { dir = "VOICEMAIL_TYPE" } +// CallLog.Calls.REJECTED_TYPE -> { dir = "REJECTED_TYPE" } +// CallLog.Calls.BLOCKED_TYPE -> { dir = "BLOCKED_TYPE" } +// CallLog.Calls.ANSWERED_EXTERNALLY_TYPE -> { dir = "ANSWERED_EXTERNALLY_TYPE" } + else -> { holder.view.root.isSelected = false } + } +// "\u25CF ${} , ${todo.typeString} : ${todo.count} : ${todo.date}" + holder.view.type.text = todo.typeString /* multiline texts are enabled for TodoManager */ - holder.view.itemText.isSingleLine = false + holder.view.date.text = todo.date /* launch edit or update dialog on item click */ - holder.view.itemText.setOnClickListener { updateDialog(position) } + holder.view.root.setOnClickListener { updateDialog(position) } /* copy texts on long click */ - holder.view.itemText.setOnLongClickListener { + holder.view.root.setOnLongClickListener { // copyToClipboard(context, todo.name) var cId = getContactId(lActivity!!.contentResolver, todo.number) @@ -85,7 +99,7 @@ internal class MissedCallsAdapter( } - inner class MissedCallsHolder(var view: ListItemBinding) : RecyclerView.ViewHolder(view.root) + inner class MissedCallsHolder(var view: CalllogItemBinding) : RecyclerView.ViewHolder(view.root) /* update dialog */ private fun updateDialog(position: Int) { diff --git a/app/src/main/kotlin/rasel/lunar/launcher/todos/SmsLogsAdapter.kt b/app/src/main/kotlin/rasel/lunar/launcher/todos/SmsLogsAdapter.kt index 390f2ed..dba485f 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/todos/SmsLogsAdapter.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/todos/SmsLogsAdapter.kt @@ -32,6 +32,7 @@ import rasel.lunar.launcher.R import rasel.lunar.launcher.databinding.ListItemBinding import rasel.lunar.launcher.databinding.SmsItemBinding import rasel.lunar.launcher.utils.BLog +import rasel.lunar.launcher.utils.getContactName import rasel.lunar.launcher.workers.RecentSms import java.text.SimpleDateFormat import java.util.Date @@ -55,10 +56,14 @@ internal class SmsLogsAdapter( @SuppressLint("SetTextI18n") override fun onBindViewHolder(holder: SmsLogHolder, position: Int) { val todo = smsList[position] + var name = getContactName(lActivity!!.contentResolver,todo.person) + if (name == null) { + getContactName(lActivity!!.contentResolver,todo.addr) + } if(todo.isMms) { var body = todo.mmsContents.get("text")?.joinToString("\n")?.replace("\n"," ") body = if (body?.length ?: 0 > 60) body?.substring(0,60).plus("...") else body - holder.view.itemText.text = "\u25CF ${todo.person} ${todo.addr} : ${ + holder.view.itemText.text = "\u25CF ${if(name != null && name.length > 0) name else if(todo.person != null && todo.person.length > 0){todo.person} else todo.addr} : ${ SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format( Date( Math.max( @@ -70,7 +75,7 @@ internal class SmsLogsAdapter( } : ${todo.type}" holder.view.contents.text = "${body}" } else { - holder.view.itemText.text = "\u25CF ${todo.person} ${todo.addr} : ${ + holder.view.itemText.text = "\u25CF ${if(name != null && name.length > 0) name else if(todo.person != null && todo.person.length > 0){todo.person} else todo.addr} : ${ SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format( Date( Math.max( @@ -80,9 +85,15 @@ internal class SmsLogsAdapter( ) ) } : ${todo.type}" + + + + holder.view.contents.text = "${todo.body}" } + + /* multiline texts are enabled for TodoManager */ // holder.view.itemText.isSingleLine = false /* launch edit or update dialog on item click */ @@ -95,6 +106,7 @@ internal class SmsLogsAdapter( true } + holder.view.root.isActivated = if(holder.view.itemText.text.contains("#CMAS#")) true else false } diff --git a/app/src/main/kotlin/rasel/lunar/launcher/utils/DataUtils.kt b/app/src/main/kotlin/rasel/lunar/launcher/utils/DataUtils.kt index 7637396..b744025 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/utils/DataUtils.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/utils/DataUtils.kt @@ -2,6 +2,7 @@ package rasel.lunar.launcher.utils import android.content.ContentResolver import android.net.Uri +import android.provider.ContactsContract import android.provider.ContactsContract.PhoneLookup import java.util.Calendar @@ -38,20 +39,21 @@ fun afterDay(date: Date?, day: Int): Long { fun getContactName(contentResolver: ContentResolver, phoneNumber: String?): String? { - val cr = contentResolver - val uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)) - val cursor = - cr.query(uri, arrayOf(PhoneLookup.DISPLAY_NAME), null, null, null) - ?: return null var contactName: String? = null - if (cursor.moveToFirst()) { - contactName = cursor.getString(cursor.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME)) - } + if (phoneNumber != null && phoneNumber.length > 0) { + val cr = contentResolver + val uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)) + val cursor = + cr.query(uri, arrayOf(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME), null, null, null) + ?: return null + if (cursor.moveToFirst()) { + contactName = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)) + } - if (cursor != null && !cursor.isClosed) { - cursor.close() + if (cursor != null && !cursor.isClosed) { + cursor.close() + } } - return contactName } diff --git a/app/src/main/kotlin/rasel/lunar/launcher/utils/JamoUtils.kt b/app/src/main/kotlin/rasel/lunar/launcher/utils/JamoUtils.kt new file mode 100644 index 0000000..49bfb65 --- /dev/null +++ b/app/src/main/kotlin/rasel/lunar/launcher/utils/JamoUtils.kt @@ -0,0 +1,40 @@ +package rasel.lunar.launcher.utils + +import android.annotation.SuppressLint + +object JamoUtils { + val CHOSUNG = listOf( + "ㄱ", "ㄲ", "ㄴ", "ㄷ", "ㄸ", "ㄹ", "ㅁ", "ㅂ", "ㅃ", + "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅉ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ", + ) + val JUNGSUNG = listOf( + "ㅏ", "ㅐ", "ㅑ", "ㅒ", "ㅓ", "ㅔ", "ㅕ", "ㅖ", "ㅗ", "ㅘ", + "ㅙ", "ㅚ", "ㅛ", "ㅜ", "ㅝ", "ㅞ", "ㅟ", "ㅠ", "ㅡ", "ㅢ", "ㅣ", + ) + val JONGSUNG = listOf( + "", "ㄱ", "ㄲ", "ᆪ", "ᆫ", "ᆬ", "ᆭ", "ㄷ", + "ㄹ", "ᆰ", "ᆱ", "ᆲ", "ᆳ", "ᆴ", "ᆵ", "ᆶ", "ㅁ", "ㅂ", "ᆹ", "ᆺ", "ᆻ", "ᆼ", + "ᆽ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ", + ) + + fun split(target: String): List { + return target.split("") + .filter(String::isNotEmpty) + .map(JamoUtils::splitOne) + .toList() + } + + @SuppressLint("SuspiciousIndentation") + fun splitOne(target: String): String { + val codePoint = Character.codePointAt(target, 0) + return if (codePoint in 0xAC00..0xD79D) { + val startValue = codePoint - 0xAC00 + val jong = startValue % 28 + val jung = (startValue - jong) / 28 % 21 + val cho = ((startValue - jong) / 28 - jung) / 21 + CHOSUNG[cho] + } else { + "" + } + } +} \ No newline at end of file diff --git a/app/src/main/kotlin/rasel/lunar/launcher/workers/RecentCallGetter.kt b/app/src/main/kotlin/rasel/lunar/launcher/workers/RecentCallGetter.kt index 263fa1f..8ca23c5 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/workers/RecentCallGetter.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/workers/RecentCallGetter.kt @@ -44,7 +44,7 @@ class RecentCallGetter : BaseGetter { @SuppressLint("RestrictedApi") override fun realWork(): Result { - var dateParam = beforeDay(Date(),3).toString() + var dateParam = beforeDay(Date(),7).toString() var managedCursor = lActivity?.contentResolver?.query( CallLog.Calls.CONTENT_URI, arrayOf( CallLog.Calls.NUMBER, @@ -82,22 +82,14 @@ class RecentCallGetter : BaseGetter { CallLog.Calls.BLOCKED_TYPE -> { dir = "BLOCKED_TYPE" } CallLog.Calls.ANSWERED_EXTERNALLY_TYPE -> { dir = "ANSWERED_EXTERNALLY_TYPE" } } - var missed: RecentCall = if (recentCalls.containsKey(phNumber)) { - recentCalls.get(phNumber)!!.apply { - count = count + 1 - } - } else { - RecentCall( - 1, - callerName, - phNumber, - dircode, - dir, - SimpleDateFormat("yyy/MM/dd-HH:mm:ss").format(callDayTime) - ) - } -// BLog.LOGE("missed put >>> ${missed.toJson()}") - recentCalls.put(phNumber, missed) + recentCalls.add(RecentCall( + 1, + callerName, + phNumber, + dircode, + dir, + SimpleDateFormat("yyy/MM/dd-HH:mm:ss").format(callDayTime) + )) } 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 f960500..5df95c3 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/workers/RecentSmsGetter.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/workers/RecentSmsGetter.kt @@ -30,7 +30,7 @@ class RecentSmsGetter : BaseGetter { @SuppressLint("RestrictedApi") override fun realWork(): Result { - var dateParam = beforeDay(Date(),3).toString() + var dateParam = beforeDay(Date(),7).toString() val managedCursor = lActivity?.contentResolver?.query( Telephony.Sms.CONTENT_URI, arrayOf( Telephony.Sms.THREAD_ID, @@ -301,7 +301,7 @@ internal class MmsQueryHelper( fun convertData(cursor: Cursor?) { cursor ?: return - val dateTime = beforeDay(Date(),3) + val dateTime = beforeDay(Date(),7) cursor.use { if (cursor.moveToFirst()) { do { diff --git a/app/src/main/res/color/sms_board.xml b/app/src/main/res/color/sms_board.xml new file mode 100644 index 0000000..84290e2 --- /dev/null +++ b/app/src/main/res/color/sms_board.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/sms_bg.xml b/app/src/main/res/drawable/sms_bg.xml index 6945c6a..befcca3 100644 --- a/app/src/main/res/drawable/sms_bg.xml +++ b/app/src/main/res/drawable/sms_bg.xml @@ -1,8 +1,7 @@ - - - + + \ No newline at end of file diff --git a/app/src/main/res/layout/calllog_item.xml b/app/src/main/res/layout/calllog_item.xml new file mode 100644 index 0000000..c56c8e1 --- /dev/null +++ b/app/src/main/res/layout/calllog_item.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + \ No newline at end of file