From 1b2c1f593ba8bfac9f22b42e78afe4e0e3d73ef0 Mon Sep 17 00:00:00 2001 From: lunaticbum <> Date: Fri, 18 Oct 2024 17:46:50 +0900 Subject: [PATCH] ... --- .../bums/lunatic/launcher/feeds/Feeds.kt | 4 +- .../lunatic/launcher/helpers/Constants.kt | 2 +- .../lunatic/launcher/home/LauncherHome.kt | 33 ++++++++- .../lunatic/launcher/qaccess/QuickAccess.kt | 61 +++++++++++++++-- .../lunatic/launcher/view/DateTimeView.kt | 36 ++++++++++ .../launcher/workers/LocationUpdateService.kt | 68 +++++++++---------- .../launcher/workers/RecentCallGetter.kt | 2 +- .../launcher/workers/RecentSmsGetter.kt | 3 +- 8 files changed, 161 insertions(+), 48 deletions(-) diff --git a/app/src/main/kotlin/bums/lunatic/launcher/feeds/Feeds.kt b/app/src/main/kotlin/bums/lunatic/launcher/feeds/Feeds.kt index 2f5eb67..3d1c278 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/feeds/Feeds.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/feeds/Feeds.kt @@ -421,8 +421,8 @@ internal class Feeds : Fragment() , CommadCallabck { } "reqmax" -> { refreshFeeds() - RecentCallGetter.dayRange = 30 - RecentSmsGetter.dayRange = 30 + RecentCallGetter.dayRange = 365 + RecentSmsGetter.dayRange = 365 refreshDeviceData() consoleLog("excute refreshFeeds()") } diff --git a/app/src/main/kotlin/bums/lunatic/launcher/helpers/Constants.kt b/app/src/main/kotlin/bums/lunatic/launcher/helpers/Constants.kt index 854ede2..56f1852 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/helpers/Constants.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/helpers/Constants.kt @@ -72,7 +72,7 @@ internal class Constants { const val DEFAULT_ICON_PACK = "default_icon_pack" const val DEFAULT_GRID_COLUMNS = 4 const val DEFAULT_SCROLLBAR_HEIGHT = 400 - const val MAX_SHORTCUTS = 6 + const val MAX_SHORTCUTS = 8 const val MAX_FAVORITE_APPS = 6 const val BOTTOM_SHEET_TAG = "rasel.lunar.launcher.TAG" diff --git a/app/src/main/kotlin/bums/lunatic/launcher/home/LauncherHome.kt b/app/src/main/kotlin/bums/lunatic/launcher/home/LauncherHome.kt index 8e79183..1ebe49c 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/home/LauncherHome.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/home/LauncherHome.kt @@ -246,7 +246,26 @@ internal class LauncherHome : Fragment() { } }) - binding.favAppsGroup.setOnClickListener { searchData() } + binding.favAppsGroup.setOnClickListener { + if (binding.otherCheck.isSelected) { + searchData() + } +// else if (binding.otherCheck.isSelected) { +// searchData() +// } +// else if (binding.otherCheck.isSelected) { +// searchData() +// } +// else if (binding.otherCheck.isSelected) { +// searchData() +// } +// else if (binding.otherCheck.isSelected) { +// searchData() +// } + else { + QuickAccess().show(fragManager, BOTTOM_SHEET_TAG) + } + } try{binding.mainList.removeOnScrollListener(onScrChanged)}catch (e : Exception){e.printStackTrace()} binding.mainList.addOnScrollListener(onScrChanged) @@ -949,6 +968,11 @@ internal class LauncherHome : Fragment() { gestureDuration: Long, gestureDistance: Double ): Boolean { +// if (targetView.equals(binding.time)) { +// val mClockIntent = Intent(AlarmClock.ACTION_SHOW_ALARMS) +// mClockIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) +// startActivity(mClockIntent) +// } return false } @@ -958,6 +982,9 @@ internal class LauncherHome : Fragment() { gestureDuration: Long, gestureDistance: Double ): Boolean { + if (targetView.equals(binding.time)) { + + } return false } @@ -1082,7 +1109,9 @@ internal class LauncherHome : Fragment() { /* gestures on battery progress indicator area */ @SuppressLint("ClickableViewAccessibility") private fun batteryProgressGestures() { - binding.batteryProgress.setOnTouchListener(SimpleFingerGestures(context = requireContext(), binding.batteryProgress , mFingerGestureListener)) + binding.batteryProgress.setOnClickListener { startActivity( Intent(android.provider.Settings.ACTION_SETTINGS))} +// binding.time.setOnTouchListener(SimpleFingerGestures(context = requireContext(), binding.time , mFingerGestureListener)) +// binding.batteryProgress.setOnTouchListener(SimpleFingerGestures(context = requireContext(), binding.batteryProgress , mFingerGestureListener)) } /* gestures on to-do area */ diff --git a/app/src/main/kotlin/bums/lunatic/launcher/qaccess/QuickAccess.kt b/app/src/main/kotlin/bums/lunatic/launcher/qaccess/QuickAccess.kt index 25c07bd..7f7a9a2 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/qaccess/QuickAccess.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/qaccess/QuickAccess.kt @@ -45,6 +45,7 @@ import androidx.appcompat.widget.LinearLayoutCompat import androidx.core.content.ContextCompat import bums.lunatic.launcher.LauncherActivity.Companion.lActivity import bums.lunatic.launcher.R +import bums.lunatic.launcher.apps.SimpleContact import bums.lunatic.launcher.databinding.QuickAccessBinding import bums.lunatic.launcher.databinding.ShortcutMakerBinding import bums.lunatic.launcher.helpers.ColorPicker @@ -58,12 +59,20 @@ import bums.lunatic.launcher.helpers.Constants.Companion.PREFS_SHORTCUTS import bums.lunatic.launcher.helpers.Constants.Companion.SEPARATOR import bums.lunatic.launcher.helpers.Constants.Companion.SHORTCUT_TYPE_PHONE import bums.lunatic.launcher.helpers.Constants.Companion.SHORTCUT_TYPE_URL +import bums.lunatic.launcher.model.AppInfo +import bums.lunatic.launcher.settings.childs.Apps +import bums.lunatic.launcher.utils.BLog +import bums.lunatic.launcher.workers.WorkersDb import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.button.MaterialButtonToggleGroup import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.slider.Slider import com.google.android.material.textview.MaterialTextView +import io.realm.kotlin.ext.query +import io.realm.kotlin.query.RealmResults +import java.text.SimpleDateFormat +import java.util.Date import java.util.Objects import kotlin.properties.Delegates @@ -240,14 +249,31 @@ internal class QuickAccess : BottomSheetDialogFragment() { /* type is url */ if (shortcutType == SHORTCUT_TYPE_URL) { var url = intentString + BLog.LOGE("intentString >>>> ${intentString}") /* add http before the url if it doesn't have http/https prefix */ - if (!url.startsWith("http://") && !url.startsWith("https://")) { - url = "http://$intentString" + if (!url.startsWith("http")) { +// url = "http://$intentString" + /* open the url */ + WorkersDb.getRealm().apply { + var result = query("appName CONTAINS $0 OR koreanName CONTAINS $0", url).find() + if (result.size == 1) { + result.first().pkgName?.let { + try { + context?.startActivity(context?.packageManager?.getLaunchIntentForPackage(it)) + }catch (e : Exception) {} + } + } else { + lActivity!!.startActivity( + Intent(Intent.ACTION_VIEW, Uri.parse(url)).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + ) + } + } + } else { + lActivity!!.startActivity( + Intent(Intent.ACTION_VIEW, Uri.parse(url)).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + ) } - /* open the url */ - lActivity!!.startActivity( - Intent(Intent.ACTION_VIEW, Uri.parse(url)).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - ) + /* type is contact */ } else if (shortcutType == SHORTCUT_TYPE_PHONE) { /* if the necessary permission is not granted already, @@ -256,12 +282,33 @@ internal class QuickAccess : BottomSheetDialogFragment() { lActivity!!.requestPermissions(arrayOf(Manifest.permission.CALL_PHONE), 1) } else { /* make phone call */ + + WorkersDb.getRealm().writeBlocking { + BLog.LOGE(">>>> ${query().query("phoneNumber CONTAINS $0", intentString).description()}") + var result : RealmResults? = null + if (intentString.startsWith("0")) { + result = query().query("phoneNumber CONTAINS $0 or phoneNumber CONTAINS $1", intentString, intentString.removeRange(0,1)).find() + } else { + result = query().query("phoneNumber CONTAINS $0", intentString).find() + } + BLog.LOGE(">>>> ${result.size}") + if(result.size > 0){ + result.forEach { + it.touchCount = 1 + it.touchCount + it.lastedTouchDateTime = System.currentTimeMillis() + } + } + } lActivity!!.startActivity( Intent(Intent.ACTION_DIAL, Uri.parse("tel:$intentString")) ) } } - this.dismiss() + try { + this.dismissAllowingStateLoss() + } catch (e : Exception) { + + } } /* reset the shortcut on long click */ diff --git a/app/src/main/kotlin/bums/lunatic/launcher/view/DateTimeView.kt b/app/src/main/kotlin/bums/lunatic/launcher/view/DateTimeView.kt index 1fb5746..e69d1d3 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/view/DateTimeView.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/view/DateTimeView.kt @@ -1,13 +1,20 @@ package bums.lunatic.launcher.view import android.content.Context +import android.content.Intent +import android.net.Uri import android.os.Handler import android.os.Looper +import android.provider.AlarmClock import android.text.SpannableString import android.text.SpannableStringBuilder import android.text.Spanned +import android.text.TextPaint +import android.text.method.LinkMovementMethod import android.text.style.AbsoluteSizeSpan +import android.text.style.ClickableSpan import android.util.AttributeSet +import android.view.View import androidx.appcompat.widget.AppCompatTextView import java.text.SimpleDateFormat import java.util.Date @@ -44,15 +51,44 @@ class DateTimeView : AppCompatTextView { val now = Date(System.currentTimeMillis()) val time = SpannableString(simpleTimeFormat.format(now)) val date = SpannableString(simpleDateFormat.format(now)) + val mClickableSpan = object: ClickableSpan(){ + override fun updateDrawState(textPaint: TextPaint) { +// textPaint.color = this@MainActivity.getColor(R.color.blue) + textPaint.isUnderlineText = false + } + + override fun onClick(v: View) { + val mClockIntent = Intent(AlarmClock.ACTION_SHOW_ALARMS) + mClockIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + context.startActivity(mClockIntent) + } + } + val mClickableSpan2 = object: ClickableSpan(){ + override fun updateDrawState(textPaint: TextPaint) { +// textPaint.color = this@MainActivity.getColor(R.color.blue) + textPaint.isUnderlineText = false + } + + override fun onClick(v: View) { + val intent = Intent(Intent.ACTION_MAIN) + intent.addCategory(Intent.CATEGORY_APP_CALENDAR) + context.startActivity(intent) + } + } + spannableBuilder.append(time) spannableBuilder.setSpan(AbsoluteSizeSpan(48,true), 0, time.length , Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) + spannableBuilder.setSpan(mClickableSpan, 0, time.length , Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) spannableBuilder.append("\n") spannableBuilder.append(date) var start = time.length + "\n".length spannableBuilder.setSpan(AbsoluteSizeSpan(30,true), start , start+date.length , Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) + spannableBuilder.setSpan(mClickableSpan2, start , start+date.length , Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) mHandler.removeCallbacks(runable) setText(spannableBuilder) mHandler.postDelayed(runable, DateTimeView.DALEY) + setMovementMethod(LinkMovementMethod.getInstance()); + } companion object { diff --git a/app/src/main/kotlin/bums/lunatic/launcher/workers/LocationUpdateService.kt b/app/src/main/kotlin/bums/lunatic/launcher/workers/LocationUpdateService.kt index fd05286..b1cf794 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/workers/LocationUpdateService.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/workers/LocationUpdateService.kt @@ -51,46 +51,46 @@ class LocationUpdateService : Service(), LocationListener { WorkersDb.getRealm()?.apply { LocationLog().let { loc -> loc.fillData(it) - var list = query().sort("time", Sort.DESCENDING).find() - (list.size == 0 || (list.size > 0 && list.first().time < System.currentTimeMillis() - (1000L * 60L * 10L))).letTrue { - Executors.newSingleThreadScheduledExecutor().schedule({ - try { - //////-1002450229641 - val url = PrefString.locationApi.get() - if (url.length > 10) { - val client = OkHttpClient.Builder() - .connectionPool(ConnectionPool(5, 60, TimeUnit.SECONDS)) - .build() +// var list = query().sort("time", Sort.DESCENDING).find() +// (list.size == 0 || (list.size > 0 && list.first().time < (System.currentTimeMillis() - (1000L * 60L * 10L)) && list.first().mLatitude )).letTrue { + Executors.newSingleThreadScheduledExecutor().schedule({ + try { + //////-1002450229641 + val url = PrefString.locationApi.get() + if (url.length > 10) { + 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() - builder.method( - "POST", RequestBody.create( - MediaType.parse("application/text"), - Base64.getEncoder().encode( - Gson().toJson(this@apply).toByteArray() - ) + // GET 요청 객체 생성 + val builder: Request.Builder = Request.Builder().url(url) + .addHeader("Content-Type", "application/json").get() + builder.method( + "POST", RequestBody.create( + MediaType.parse("application/text"), + Base64.getEncoder().encode( + Gson().toJson(this@apply).toByteArray() ) ) - val request: Request = builder.build() + ) + 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) { + 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) { - } - } else BLog.LOGE("telegram Error Occurred") - } - } catch (e: java.lang.Exception) { - e.printStackTrace() + } + } else BLog.LOGE("telegram Error Occurred") } - }, 5, TimeUnit.SECONDS) - } + } catch (e: java.lang.Exception) { + e.printStackTrace() + } + }, 5, TimeUnit.SECONDS) +// } writeBlocking { copyToRealm(loc) } diff --git a/app/src/main/kotlin/bums/lunatic/launcher/workers/RecentCallGetter.kt b/app/src/main/kotlin/bums/lunatic/launcher/workers/RecentCallGetter.kt index dde51e8..d7e6d83 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/workers/RecentCallGetter.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/workers/RecentCallGetter.kt @@ -50,7 +50,7 @@ class RecentCall : RealmObject { class RecentCallGetter : BaseGetter { companion object{ - var dayRange = BaseGetter.defaultDay + var dayRange = BaseGetter.defaultDay val TAG = "RecentCallGetter" val dateFormat = SimpleDateFormat("yyy/MM/dd-HH:mm:ss") } diff --git a/app/src/main/kotlin/bums/lunatic/launcher/workers/RecentSmsGetter.kt b/app/src/main/kotlin/bums/lunatic/launcher/workers/RecentSmsGetter.kt index 89268a7..6df0c4c 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/workers/RecentSmsGetter.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/workers/RecentSmsGetter.kt @@ -10,6 +10,7 @@ import androidx.work.WorkerParameters import bums.lunatic.launcher.LauncherActivity.Companion.lActivity import bums.lunatic.launcher.utils.beforeDay import bums.lunatic.launcher.utils.getContactName +import bums.lunatic.launcher.workers.RecentSmsGetter.Companion.dayRange import com.google.gson.Gson import io.realm.kotlin.ext.query import io.realm.kotlin.ext.realmListOf @@ -339,7 +340,7 @@ internal class MmsQueryHelper( fun convertData(cursor: Cursor?) { cursor ?: return - val dateTime = beforeDay(Date(),30) + val dateTime = beforeDay(Date(), dayRange) cursor.use { if (cursor.moveToFirst()) { do {