diff --git a/app/src/main/kotlin/rasel/lunar/launcher/apps/AppDrawer.kt b/app/src/main/kotlin/rasel/lunar/launcher/apps/AppDrawer.kt index 16816b5d..813f643f 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/apps/AppDrawer.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/apps/AppDrawer.kt @@ -51,6 +51,10 @@ import rasel.lunar.launcher.helpers.Constants.Companion.KEY_APPS_COUNT import rasel.lunar.launcher.helpers.Constants.Companion.KEY_APPS_LAYOUT import rasel.lunar.launcher.helpers.Constants.Companion.PREFS_APP_NAMES import rasel.lunar.launcher.helpers.Constants.Companion.PREFS_SETTINGS +import rasel.lunar.launcher.helpers.PrefBoolean +import rasel.lunar.launcher.helpers.PrefKey +import rasel.lunar.launcher.helpers.PrefLong +import rasel.lunar.launcher.helpers.letTrue import rasel.lunar.launcher.model.AppInfo import rasel.lunar.launcher.utils.BLog import rasel.lunar.launcher.utils.JamoUtils @@ -202,7 +206,7 @@ internal class AppDrawer : Fragment() { super.onViewCreated(view, savedInstanceState) binding.searchInput.setOnKeyListener { v, keyCode, event -> //contactList.size < 1 && packageList.size < 1 && - if (keyCode == 66 && event.action == KeyEvent.ACTION_UP) { + if(PrefBoolean.useQuickLaunch.get(false) && keyCode == 66 && event.action == KeyEvent.ACTION_UP) { checkResult(binding.searchInput.text.toString()) true }else { @@ -273,9 +277,9 @@ internal class AppDrawer : Fragment() { BLog.LOGE("onResume") fetchApps() - binding.appsCount.visibility = if (settingsPrefs!!.getBoolean(KEY_APPS_COUNT, true)) VISIBLE else GONE + binding.appsCount.visibility = if (PrefBoolean.showAppResultCount.get(false)) VISIBLE else GONE - openSearch() + PrefBoolean.openWithKayboard.get().letTrue { openSearch() } registCancelSearch() // BLog.LOGE("onResume after chechHandler.postDelayed(cancelSearch, 3000L)") } @@ -328,7 +332,8 @@ internal class AppDrawer : Fragment() { } } } - appQuery = newQ.sort(Pair("clickCount", Sort.DESCENDING),Pair("lastUseDate",Sort.DESCENDING)).limit(18).find() + appQuery = newQ.sort(Pair("clickCount", Sort.DESCENDING),Pair("lastUseDate",Sort.DESCENDING)) + .limit(PrefLong.maxQueryCount.get(18L).toInt()).find() appQuery?.let { if(it.size > 0) { WorkersDb.getRealm().apply { @@ -356,7 +361,8 @@ internal class AppDrawer : Fragment() { newQ = newQ.query("name CONTAINS $0 OR chosung CONTAINS $0", keyword) } } - contactQuery = newQ.sort(Pair("touchCount", Sort.DESCENDING),Pair("lastedTouchDateTime",Sort.DESCENDING)).limit(18).find() + contactQuery = newQ.sort(Pair("touchCount", Sort.DESCENDING),Pair("lastedTouchDateTime",Sort.DESCENDING)) + .limit(PrefLong.maxQueryCount.get(18L).toInt()).find() contactQuery?.let { if (it.size > 0) WorkersDb.getRealm().apply { @@ -483,31 +489,6 @@ internal class AppDrawer : Fragment() { } } - private fun setKeyboardPadding() { -// binding.root.viewTreeObserver.addOnGlobalLayoutListener { -// val rect = Rect() -// binding.root.getWindowVisibleDisplayFrame(rect) -// val screenHeight = binding.root.height -// val keyboardHeight = screenHeight - (rect.bottom - rect.top) -// -// when { -// keyboardHeight > screenHeight * 0.15 -> { -// if (!isKeyboardShowing && -// !settingsPrefs!!.getBoolean(KEY_STATUS_BAR, false)) { -// isKeyboardShowing = true -// binding.root.setPadding(0, 0, 0, keyboardHeight) -// } -// } -// else -> { -// if (isKeyboardShowing) { -// isKeyboardShowing = false -// binding.root.setPadding(0, 0, 0, 0) -// } -// } -// } -// } - } - } fun normalize(str: String): String { diff --git a/app/src/main/kotlin/rasel/lunar/launcher/feeds/Feeds.kt b/app/src/main/kotlin/rasel/lunar/launcher/feeds/Feeds.kt index fe5b51bf..120f0e8f 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/feeds/Feeds.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/feeds/Feeds.kt @@ -225,6 +225,18 @@ internal class Feeds : Fragment() , CommadCallabck { if (input.text.toString().trim().contains(" ")) { val cmd = input.text.toString().trim().split(" ") when(cmd[0]) { + "car" -> { + if (cmd[1].trim().length > 2) { + PrefHelper.carName = cmd[1].trim() + } + consoleLog(PrefHelper.carName) + } + "tt" -> { + if (cmd[1].trim().length > 5) { + PrefHelper.telegramSendTarget = cmd[1].trim() + } + consoleLog(PrefHelper.telegramSendTarget) + } "so"-> { CoroutineScope(Dispatchers.IO).launch { consoleLog("${cmd[0]} Start ${cmd[1]}") diff --git a/app/src/main/kotlin/rasel/lunar/launcher/helpers/BleHelper.java b/app/src/main/kotlin/rasel/lunar/launcher/helpers/BleHelper.java deleted file mode 100644 index 7ee6af38..00000000 --- a/app/src/main/kotlin/rasel/lunar/launcher/helpers/BleHelper.java +++ /dev/null @@ -1,22 +0,0 @@ -package rasel.lunar.launcher.helpers; - -import android.annotation.SuppressLint; -import android.bluetooth.BluetoothDevice; - -import java.lang.reflect.Method; - -import rasel.lunar.launcher.utils.BLog; - -public class BleHelper { - @SuppressLint("MissingPermission") - public static boolean isConnected(BluetoothDevice device) { - try { - Method m = device.getClass().getMethod("isConnected", (Class[]) null); - boolean connected = (boolean) m.invoke(device, (Object[]) null); - BLog.INSTANCE.LOGE("D >> " + device.getName() + " || isConnected >>> " + (connected ? "TRUE" : "FALSE")); - return connected; - } catch (Exception e) { - throw new IllegalStateException(e); - } - } -} diff --git a/app/src/main/kotlin/rasel/lunar/launcher/helpers/BluetoothManager.kt b/app/src/main/kotlin/rasel/lunar/launcher/helpers/BluetoothManager.kt index 51005e44..6e36cdb6 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/helpers/BluetoothManager.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/helpers/BluetoothManager.kt @@ -76,7 +76,9 @@ class BluetoothManager { //bondState : 10 (페어링 등록 안됨) BLog.LOGE("getPairedDevices() / name : ${i.name}") BLog.LOGE("getPairedDevices() / bondState : ${i.bondState}") - if(i.name.contains("SOUL") && isConnected(i)) { + val isConnected = isConnected(i) + if(PrefHelper.carName.length > 2 && i.name.equals(PrefHelper.carName) && isConnected != PrefHelper.isConnectedCar) { + PrefHelper.isConnectedCar = isConnected sendToI() } } @@ -85,30 +87,34 @@ class BluetoothManager { fun sendToI() { - CoroutineScope(Dispatchers.IO).launch { - val url = "https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/sendMessage?chat_id=83268260&text=돼지가쏘울레탔다요." - //7068729507 - // OkHttp 클라이언트 객체 생성 - val client = OkHttpClient.Builder() - .connectionPool(ConnectionPool(5, 60, TimeUnit.SECONDS)) - .build() + if (PrefHelper.telegramSendTarget.length > 5) { + CoroutineScope(Dispatchers.IO).launch { + val url = + "https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/sendMessage?chat_id=${PrefHelper.telegramSendTarget}&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() + // GET 요청 객체 생성 + val builder: Request.Builder = Request.Builder().url(url) + .addHeader("Content-Type", "application/json").get() - 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("sendToI 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") + } + BLog.LOGE("sendToI telegram response isSuccessful ${body}") + } else BLog.LOGE("sendToI telegram Error Occurred") + } } } @SuppressLint("MissingPermission") @@ -156,17 +162,11 @@ class BluetoothManager { private var bluetoothreceiver = object : BroadcastReceiver(){ override fun onReceive(context: Context?, intent: Intent?) { var state = intent?.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR) - BLog.LOGE("onReceive() / state : ${state}") val action = intent!!.action - BLog.LOGE("onReceive() / action : ${action}") if (context == null) return if (ActivityCompat.checkSelfPermission(context!!, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) return val device: BluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)!! - BLog.LOGE("onReceive() / device.name : ${device.name}") - BLog.LOGE("onReceive() / device.type : ${device.type}") - if(device.name.contains("SOUL") && isConnected(device)) { - sendToI() - } + getPairedDevices() } } } \ No newline at end of file diff --git a/app/src/main/kotlin/rasel/lunar/launcher/helpers/PrefHelper.kt b/app/src/main/kotlin/rasel/lunar/launcher/helpers/PrefHelper.kt index 6e7c2ba3..749c186d 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/helpers/PrefHelper.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/helpers/PrefHelper.kt @@ -2,6 +2,93 @@ package rasel.lunar.launcher.helpers import android.content.Context import android.content.SharedPreferences +import rasel.lunar.launcher.helpers.PrefHelper.BOOL_PRE +import rasel.lunar.launcher.helpers.PrefHelper.LONG_PRE +import rasel.lunar.launcher.helpers.PrefHelper.STRING_PRE +import rasel.lunar.launcher.helpers.PrefHelper.sharedPreferences +import rasel.lunar.launcher.helpers.PrefKey.TYPE_BOOL +import rasel.lunar.launcher.helpers.PrefKey.TYPE_END +import rasel.lunar.launcher.helpers.PrefKey.TYPE_LONG +import rasel.lunar.launcher.helpers.PrefKey.TYPE_STRING + +enum class PrefString { + locationApi, + telegramBotApi, + telegramMyId, + telegramSendTarget, + carName; + fun set(value : String) = PrefHelper.putString(this.name, value) + fun get(def : String? = null) : String = PrefHelper.getString(this.name, def as? String ?: "") ?: "" +} + +enum class PrefLong { + shortTimePeriod, + longTimePeriod, + midTimePeriod, + maxQueryCount; + fun set(value : Long) = PrefHelper.putLong(this.name, value) + fun get(def : Long? = null) : Long = PrefHelper.getLong(this.name, def as? Long ?: 0L) ?: 0L +} + +enum class PrefBoolean { + location, + isConnectedCar, + useQuickLaunch, + openWithKayboard, + showAppResultCount,; + fun set(value : Boolean) = PrefHelper.putBoolean(this.name, value) + fun get(def : Boolean? = null) : Boolean = PrefHelper.getBoolean(this.name, def as? Boolean ?: false) ?: false +} +enum class PrefKey { + TYPE_STRING, + locationApi, + telegramBotApi, + telegramSendTarget, + carName, + TYPE_LONG, + shortTimePeriod, + longTimePeriod, + midTimePeriod, + maxQueryCount, + TYPE_BOOL, + location, + isConnectedCar, + useQuickLaunch, + openWithKayboard, + showAppResultCount, + TYPE_END; + + fun set(value : Any): Unit { + when(this.ordinal) { + in (TYPE_STRING.ordinal..TYPE_LONG.ordinal) -> { + (value as? String)?.let { PrefHelper.putString(this.name, it) } + } + in (TYPE_LONG.ordinal..TYPE_BOOL.ordinal) -> { + (value as? Long)?.let { PrefHelper.putLong(this.name, it) } + } + in (TYPE_BOOL.ordinal..TYPE_END.ordinal) -> { + (value as? Boolean)?.let { PrefHelper.putBoolean(this.name, it) } + } + else -> {} + } + } + + fun get(def : Any? = null) : Any? { + when(this.ordinal) { + in (TYPE_STRING.ordinal..TYPE_LONG.ordinal) -> { + return PrefHelper.getString(this.name, def as? String ?: "") + } + in (TYPE_LONG.ordinal..TYPE_BOOL.ordinal) -> { + return PrefHelper.getLong(this.name, def as? Long ?: 0L) + } + in (TYPE_BOOL.ordinal..TYPE_END.ordinal) -> { + return PrefHelper.getBoolean(this.name, def as? Boolean ?: false) + } + else -> {} + } + return null + } +} object PrefHelper { val D_PREFIX = "rasel.lunar.launcher.helpers" @@ -12,53 +99,66 @@ object PrefHelper { this.sharedPreferences = SharedPreferences } var sharedPreferences : SharedPreferences? = null + fun getBoolean(key : String, def :Boolean) = this.sharedPreferences?.getBoolean(BOOL_PRE.plus(key),def) ?: def + fun putBoolean(key : String, value :Boolean) = this.sharedPreferences?.edit()?.putBoolean(BOOL_PRE.plus(key),value)?.apply() + fun getLong(key : String, def :Long) = this.sharedPreferences?.getLong(LONG_PRE.plus(key),def) ?: def + fun putLong(key : String, value :Long) = this.sharedPreferences?.edit()?.putLong(LONG_PRE.plus(key),value)?.apply() + fun getString(key : String, def :String) = this.sharedPreferences?.getString(STRING_PRE.plus(key),def) ?: def + fun putString(key : String, value :String) = this.sharedPreferences?.edit()?.putString(STRING_PRE.plus(key),value)?.apply() - fun location(boolean: Boolean) { - sharedPreferences?.edit()?.putBoolean(BOOL_PRE.plus("location"), boolean)?.apply() - } - fun isLocationOn() = sharedPreferences?.getBoolean(BOOL_PRE.plus("location") , false) ?: false + fun location(boolean: Boolean) = PrefKey.location.set(boolean) + fun isLocationOn() = (PrefKey.location.get() as? Boolean) ?: false + var locationApi : String - get() { - return sharedPreferences?.getString(STRING_PRE.plus("location.api"),"") ?: "" - } - set(value) { - sharedPreferences?.edit()?.putString(STRING_PRE.plus("location.api") , value)?.apply() - } + get() = PrefKey.locationApi.get() as? String ?: "" + set(value) = PrefKey.locationApi.set(value) var telegramBotApi : String - get() { - return sharedPreferences?.getString(STRING_PRE.plus("telegram.api"),"") ?: "" - } - set(value) { - sharedPreferences?.edit()?.putString(STRING_PRE.plus("telegram.api") , value)?.apply() - } - + get() = PrefKey.telegramBotApi.get() as? String ?: "" + set(value) = PrefKey.telegramBotApi.set(value) + + var telegramSendTarget : String + get() = PrefKey.telegramSendTarget.get() as? String ?: "" + set(value) = PrefKey.telegramSendTarget.set(value) + + var carName : String + get() = PrefKey.carName.get() as? String ?: "" + set(value) = PrefKey.carName.set(value) + var shortTimePeriod : Long - get() { - return sharedPreferences?.getLong(LONG_PRE.plus("shortTimePeriod"), 20L) ?: 20L - } - set(value) { - sharedPreferences?.edit()?.putLong(LONG_PRE.plus("shortTimePeriod"),value)?.apply() - } + get() = PrefKey.shortTimePeriod.get(20L) as? Long ?: 20L + set(value) = PrefKey.shortTimePeriod.set(value) + var longTimePeriod : Long - get() { - return sharedPreferences?.getLong(LONG_PRE.plus("longTimePeriod"), 60L) ?: 60L - } - set(value) { - sharedPreferences?.edit()?.putLong(LONG_PRE.plus("longTimePeriod"),value)?.apply() - } + get() = PrefKey.longTimePeriod.get(60L) as? Long ?: 60L + set(value) = PrefKey.longTimePeriod.set(value) + var midTimePeriod : Long - get() { - return sharedPreferences?.getLong(LONG_PRE.plus("midTimePeriod"), 30L) ?: 30L - } - set(value) { - sharedPreferences?.edit()?.putLong(LONG_PRE.plus("midTimePeriod"),value)?.apply() - } + get() = PrefKey.midTimePeriod.get(30L) as? Long ?: 30L + set(value) = PrefKey.midTimePeriod.set(value) + + + var isConnectedCar : Boolean + get() = PrefKey.isConnectedCar.get() as? Boolean ?: false + set(value) = PrefKey.isConnectedCar.set(value) + + var useQuickLaunch : Boolean + get() = PrefKey.useQuickLaunch.get() as? Boolean ?: false + set(value) = PrefKey.useQuickLaunch.set(value) + + var openWithKayboard : Boolean + get() = PrefKey.openWithKayboard.get() as? Boolean ?: false + set(value) = PrefKey.openWithKayboard.set(value) + + var showAppResultCount : Boolean + get() = PrefKey.showAppResultCount.get() as? Boolean ?: false + set(value) = PrefKey.showAppResultCount.set(value) + + } - typealias BLOCK = ()->Unit inline fun Boolean.letTrue(block: BLOCK) { if (this) { 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 921cdc28..24e522d4 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/home/LauncherHome.kt @@ -324,8 +324,8 @@ internal class LauncherHome : Fragment() { @SuppressLint("NotifyDataSetChanged") suspend fun queryWeatherWithLoc(){ - WorkersDb.getRealm() - .query() + WorkersDb.getRealm().apply { + query() .query("lat == $0 AND lon == $1", LocationGetter.latitude?.let { BigDecimal.valueOf(it).toDouble() }, LocationGetter.longitude?.let { BigDecimal.valueOf(it).toDouble() } @@ -338,7 +338,7 @@ internal class LauncherHome : Fragment() { mutableListOf().apply { this.addAll( // it.filter(hours) - hours + copyFromRealm(hours) ) } ) @@ -349,7 +349,7 @@ internal class LauncherHome : Fragment() { mutableListOf().apply { this.addAll( // it.filter(hours) - hours + copyFromRealm(hours) ) } ) @@ -362,6 +362,7 @@ internal class LauncherHome : Fragment() { } } } + } // .asFlow() // .collect { changes -> // if (changes.list.size > 0) { diff --git a/app/src/main/kotlin/rasel/lunar/launcher/settings/SettingsActivity.kt b/app/src/main/kotlin/rasel/lunar/launcher/settings/SettingsActivity.kt index 8b4d2c56..ab84c08b 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/settings/SettingsActivity.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/settings/SettingsActivity.kt @@ -19,10 +19,8 @@ package rasel.lunar.launcher.settings import android.annotation.SuppressLint -import android.content.Intent import android.content.SharedPreferences import android.content.res.Resources -import android.net.Uri import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import com.google.android.material.bottomsheet.BottomSheetDialog @@ -39,7 +37,7 @@ import rasel.lunar.launcher.settings.childs.Appearances import rasel.lunar.launcher.settings.childs.Apps import rasel.lunar.launcher.settings.childs.Misc import rasel.lunar.launcher.settings.childs.TimeDate -import rasel.lunar.launcher.settings.childs.TodoSettings +import rasel.lunar.launcher.settings.childs.HomeSettings import rasel.lunar.launcher.settings.childs.WeatherSettings @@ -73,7 +71,7 @@ internal class SettingsActivity : AppCompatActivity() { } binding.todo.setOnClickListener { - TodoSettings().show(supportFragmentManager, BOTTOM_SHEET_TAG) + HomeSettings().show(supportFragmentManager, BOTTOM_SHEET_TAG) } binding.apps.setOnClickListener { diff --git a/app/src/main/kotlin/rasel/lunar/launcher/settings/childs/Apps.kt b/app/src/main/kotlin/rasel/lunar/launcher/settings/childs/Apps.kt index 653848db..66fe8f54 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/settings/childs/Apps.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/settings/childs/Apps.kt @@ -55,6 +55,9 @@ import rasel.lunar.launcher.helpers.Constants.Companion.KEY_ICON_PACK import rasel.lunar.launcher.helpers.Constants.Companion.KEY_KEYBOARD_SEARCH import rasel.lunar.launcher.helpers.Constants.Companion.KEY_QUICK_LAUNCH import rasel.lunar.launcher.helpers.Constants.Companion.KEY_SCROLLBAR_HEIGHT +import rasel.lunar.launcher.helpers.PrefHelper +import rasel.lunar.launcher.helpers.PrefKey +import rasel.lunar.launcher.helpers.PrefLong import rasel.lunar.launcher.helpers.UniUtils.Companion.dpToPx import rasel.lunar.launcher.settings.SettingsActivity.Companion.settingsPrefs import kotlin.system.exitProcess @@ -84,51 +87,46 @@ internal class Apps : BottomSheetDialogFragment() { binding = SettingsAppsBinding.inflate(inflater, container, false) packageManager = requireActivity().packageManager - /* initialize views according to the saved values */ - when (settingsPrefs!!.getBoolean(KEY_KEYBOARD_SEARCH, false)) { - false -> binding.keyboardAutoNegative.isChecked = true - true -> binding.keyboardAutoPositive.isChecked = true + + binding.keyboardAutoGroup.isChecked = PrefHelper.openWithKayboard + binding.keyboardAutoGroup.setOnCheckedChangeListener { c,v -> + settingsChanged = true + PrefHelper.openWithKayboard = v } - when (settingsPrefs!!.getBoolean(KEY_QUICK_LAUNCH, true)) { - true -> binding.quickLaunchPositive.isChecked = true - false -> binding.quickLaunchNegative.isChecked = true + binding.quickLaunchGroup.isChecked = PrefHelper.useQuickLaunch + binding.quickLaunchGroup.setOnCheckedChangeListener { c,v -> + settingsChanged = true + PrefHelper.useQuickLaunch = v } - when (settingsPrefs!!.getBoolean(KEY_APPS_COUNT, true)) { - true -> binding.appsCountPositive.isChecked = true - false -> binding.appsCountNegative.isChecked = true + binding.appsCountGroup.isChecked = PrefHelper.showAppResultCount + binding.appsCountGroup.setOnCheckedChangeListener { c,v -> + settingsChanged = true + PrefHelper.showAppResultCount = v } - when (settingsPrefs!!.getInt(KEY_APPS_LAYOUT, 0)) { - 0 -> { - binding.drawerLayoutList.isChecked = true - binding.appAlignmentGroup.children.forEach { it.isEnabled = true } - binding.iconPackChooser.isEnabled = false - binding.columnsCount.isEnabled = false - } - 1 -> { - binding.drawerLayoutListIcon.isChecked = true - binding.appAlignmentGroup.children.forEach { it.isEnabled = true } - binding.iconPackChooser.isEnabled = true - binding.columnsCount.isEnabled = false - } - 2 -> { - binding.drawerLayoutGrid.isChecked = true - binding.appAlignmentGroup.children.forEach { it.isEnabled = false } - binding.iconPackChooser.isEnabled = true - binding.columnsCount.isEnabled = true - } + + ((PrefKey.maxQueryCount.get(18L) as? Long)?.toFloat() ?: 18F).let { + binding.columnsCountTitle.text = getString(R.string.grid_columns_count) +" [${it.toInt()}]" + binding.columnsCount.value = it } - when (settingsPrefs!!.getInt(KEY_DRAW_ALIGN, Gravity.CENTER)) { - Gravity.CENTER -> binding.appAlignmentCenter.isChecked = true - Gravity.LEFT -> binding.appAlignmentLeft.isChecked = true - Gravity.RIGHT -> binding.appAlignmentRight.isChecked = true + PrefLong.shortTimePeriod.get(20L).let { + binding.shortTimeTitle.text = getString(R.string.shortTimeTitle) +" [${it.toInt()}분 마다]" + binding.shortTime.value = it.toFloat() + } + PrefLong.midTimePeriod.get(30L).let { + binding.middleTimeTitle.text = getString(R.string.middleTimeTitle) +" [${it.toInt()}분 마다]" + binding.middleTime.value = it.toFloat() } - binding.columnsCount.value = Math.min(settingsPrefs!!.getInt(KEY_GRID_COLUMNS, DEFAULT_GRID_COLUMNS).toFloat(), 4f) - binding.scrollbarHeight.value = settingsPrefs!!.getInt(KEY_SCROLLBAR_HEIGHT, DEFAULT_SCROLLBAR_HEIGHT).toFloat() + PrefLong.longTimePeriod.get(60L).let { + binding.longTimeTitle.text = getString(R.string.longTimeTitle) +" [${it.toInt()}분 마다]" + binding.longTime.value = it.toFloat() + } + +// binding.scrollbarHeight.value = settingsPrefs!!.getInt(KEY_SCROLLBAR_HEIGHT, DEFAULT_SCROLLBAR_HEIGHT).toFloat() return binding.root } @@ -138,71 +136,30 @@ internal class Apps : BottomSheetDialogFragment() { super.onViewCreated(view, savedInstanceState) (requireDialog() as BottomSheetDialog).dismissWithAnimation = true - /* change search with keyboard value */ - binding.keyboardAutoGroup.setOnCheckedStateChangeListener { group, _ -> - when (group.checkedChipId) { - binding.keyboardAutoPositive.id -> settingsPrefs!!.edit().putBoolean(KEY_KEYBOARD_SEARCH, true).apply() - binding.keyboardAutoNegative.id -> settingsPrefs!!.edit().putBoolean(KEY_KEYBOARD_SEARCH, false).apply() - } - } - - /* change settings for quick launch */ - binding.quickLaunchGroup.setOnCheckedStateChangeListener { group, _ -> - when (group.checkedChipId) { - binding.quickLaunchPositive.id -> settingsPrefs!!.edit().putBoolean(KEY_QUICK_LAUNCH, true).apply() - binding.quickLaunchNegative.id -> settingsPrefs!!.edit().putBoolean(KEY_QUICK_LAUNCH, false).apply() - } - } - - binding.appsCountGroup.setOnCheckedStateChangeListener { group, _ -> - when (group.checkedChipId) { - binding.appsCountPositive.id -> settingsPrefs!!.edit().putBoolean(KEY_APPS_COUNT, true).apply() - binding.appsCountNegative.id -> settingsPrefs!!.edit().putBoolean(KEY_APPS_COUNT, false).apply() - } - } - - binding.drawerLayoutGroup.setOnCheckedStateChangeListener { group, _ -> - settingsChanged = true - when (group.checkedChipId) { - binding.drawerLayoutList.id -> { - settingsPrefs!!.edit().putInt(KEY_APPS_LAYOUT, 0).apply() - binding.appAlignmentGroup.children.forEach { if (!it.isEnabled) it.isEnabled = true } - binding.iconPackChooser.let { if (it.isEnabled) it.isEnabled = false } - binding.columnsCount.let { if (it.isEnabled) it.isEnabled = false } - } - binding.drawerLayoutListIcon.id -> { - settingsPrefs!!.edit().putInt(KEY_APPS_LAYOUT, 1).apply() - binding.appAlignmentGroup.children.forEach { if (!it.isEnabled) it.isEnabled = true } - binding.iconPackChooser.let { if (!it.isEnabled) it.isEnabled = true } - binding.columnsCount.let { if (it.isEnabled) it.isEnabled = false } - } - binding.drawerLayoutGrid.id -> { - settingsPrefs!!.edit().putInt(KEY_APPS_LAYOUT, 2).apply() - binding.appAlignmentGroup.children.forEach { if (it.isEnabled) it.isEnabled = false } - binding.iconPackChooser.let { if (!it.isEnabled) it.isEnabled = true } - binding.columnsCount.let { if (!it.isEnabled) it.isEnabled = true } - } - } - } - - binding.appAlignmentGroup.setOnCheckedStateChangeListener { group, _ -> - when (group.checkedChipId) { - binding.appAlignmentLeft.id -> settingsPrefs!!.edit().putInt(KEY_DRAW_ALIGN, Gravity.LEFT).apply() - binding.appAlignmentCenter.id -> settingsPrefs!!.edit().putInt(KEY_DRAW_ALIGN, Gravity.CENTER).apply() - binding.appAlignmentRight.id -> settingsPrefs!!.edit().putInt(KEY_DRAW_ALIGN, Gravity.RIGHT).apply() - } - } - - binding.iconPackChooser.setOnClickListener { iconPackChooser() } binding.columnsCount.addOnChangeListener(Slider.OnChangeListener { _, value, _ -> settingsChanged = true - settingsPrefs!!.edit().putInt(KEY_GRID_COLUMNS, value.toInt()).apply() + PrefKey.maxQueryCount.set(value.toLong()) + binding.columnsCountTitle.text = getString(R.string.grid_columns_count) +" [${value.toInt()}]" }) - binding.scrollbarHeight.addOnChangeListener(Slider.OnChangeListener { _, value, _ -> - settingsPrefs!!.edit().putInt(KEY_SCROLLBAR_HEIGHT, value.toInt()).apply() + binding.shortTime.addOnChangeListener(Slider.OnChangeListener { _, value, _ -> + settingsChanged = true + PrefKey.shortTimePeriod.set(value.toLong()) + binding.shortTimeTitle.text = getString(R.string.shortTimeTitle) +" [${value.toInt()}분 마다]" }) + binding.middleTime.addOnChangeListener(Slider.OnChangeListener { _, value, _ -> + settingsChanged = true + PrefKey.midTimePeriod.set(value.toLong()) + binding.middleTimeTitle.text = getString(R.string.middleTimeTitle) +" [${value.toInt()}분 마다]" + }) + binding.longTime.addOnChangeListener(Slider.OnChangeListener { _, value, _ -> + settingsChanged = true + PrefKey.longTimePeriod.set(value.toLong()) + binding.longTimeTitle.text = getString(R.string.longTimeTitle) +" [${value.toInt()}]분 마다]" + }) + + } override fun onDestroyView() { @@ -219,101 +176,4 @@ internal class Apps : BottomSheetDialogFragment() { } } - private fun iconPackChooser() { - if (installedIconPacks.isNotEmpty()) { - var selectedIconPack: String? = null - - val chipGroup = ChipGroup(requireContext()).apply { - layoutParams = LinearLayoutCompat.LayoutParams(WRAP_CONTENT, WRAP_CONTENT) - isSingleSelection = true - isSelectionRequired = true - setOnCheckedStateChangeListener { group, _ -> - selectedIconPack = group.findViewById(group.checkedChipId).tag as String - } - } - - installedIconPacks.indices.forEach { i -> - Chip(requireContext()).apply { - layoutParams = LinearLayoutCompat.LayoutParams(WRAP_CONTENT, WRAP_CONTENT) - setChipDrawable(ChipDrawable.createFromAttributes(requireContext(), null, 0, - com.google.android.material.R.style.Widget_Material3_Chip_Filter_Elevated)) - - text = packageManager?.getApplicationLabel(appInfo(installedIconPacks[i])!!) - tag = installedIconPacks[i] - - if (settingsPrefs!!.getString(KEY_ICON_PACK, DEFAULT_ICON_PACK).equals(tag as String)) { - isChecked = true - } - }.let { chipGroup.addView(it) } - } - - val eightDp = dpToPx(requireContext(), R.dimen.eight) - val linearLayoutCompat = LinearLayoutCompat(requireContext()).apply { - layoutParams = LinearLayoutCompat.LayoutParams(MATCH_PARENT, WRAP_CONTENT) - gravity = Gravity.CENTER - setPadding(eightDp, eightDp, eightDp, eightDp) - addView(chipGroup) - } - - MaterialAlertDialogBuilder(requireActivity()).apply { - setTitle(R.string.choose_icon_pack) - setView(linearLayoutCompat) - setPositiveButton(android.R.string.ok) { dialog, _ -> - when (selectedIconPack) { - null -> dialog.dismiss() - else -> { - if (!selectedIconPack.equals(settingsPrefs!!.getString(KEY_ICON_PACK, DEFAULT_ICON_PACK))) { - settingsChanged = true - settingsPrefs!!.edit().putString(KEY_ICON_PACK, selectedIconPack).apply() - } else { dialog.dismiss() } - - } - } - } - setNeutralButton(R.string.default_) { dialog, _ -> - if (DEFAULT_ICON_PACK != settingsPrefs!!.getString(KEY_ICON_PACK, DEFAULT_ICON_PACK)) { - settingsChanged = true - settingsPrefs!!.edit().putString(KEY_ICON_PACK, DEFAULT_ICON_PACK).apply() - } else { dialog.dismiss() } - } - show() - } - } else { - Toast.makeText(requireContext(), R.string.icon_pack_not_found, Toast.LENGTH_SHORT).show() - } - } - - private val installedIconPacks: ArrayList get() { - val iconPacks = ArrayList() - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - packageManager?.queryIntentActivities( - Intent("org.adw.launcher.THEMES"), - PackageManager.ResolveInfoFlags.of(PackageManager.GET_META_DATA.toLong()) - ) - } else { - @Suppress("DEPRECATION") - (packageManager?.queryIntentActivities( - Intent("org.adw.launcher.THEMES"), PackageManager.GET_META_DATA)) - }.let { - it?.indices?.forEach { i -> - it[i].activityInfo.packageName.let { packageName: String? -> - iconPacks.add(packageName!!) - } - } - } - - return iconPacks - } - - private fun appInfo(packageName: String) : ApplicationInfo? { - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - packageManager?.getApplicationInfo(packageName, - PackageManager.ApplicationInfoFlags.of(PackageManager.GET_META_DATA.toLong())) - } else { - @Suppress("DEPRECATION") - packageManager?.getApplicationInfo(packageName, PackageManager.GET_META_DATA) - } - } - } diff --git a/app/src/main/kotlin/rasel/lunar/launcher/settings/childs/TodoSettings.kt b/app/src/main/kotlin/rasel/lunar/launcher/settings/childs/HomeSettings.kt similarity index 64% rename from app/src/main/kotlin/rasel/lunar/launcher/settings/childs/TodoSettings.kt rename to app/src/main/kotlin/rasel/lunar/launcher/settings/childs/HomeSettings.kt index f3db8932..32d2da6d 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/settings/childs/TodoSettings.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/settings/childs/HomeSettings.kt @@ -22,30 +22,40 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.core.view.children import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.slider.Slider import rasel.lunar.launcher.databinding.SettingsTodoBinding import rasel.lunar.launcher.helpers.Constants.Companion.KEY_TODO_COUNTS import rasel.lunar.launcher.helpers.Constants.Companion.KEY_TODO_LOCK +import rasel.lunar.launcher.helpers.PrefHelper import rasel.lunar.launcher.settings.SettingsActivity.Companion.settingsPrefs -internal class TodoSettings : BottomSheetDialogFragment() { +internal class HomeSettings : BottomSheetDialogFragment() { private lateinit var binding : SettingsTodoBinding override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { binding = SettingsTodoBinding.inflate(inflater, container, false) - /* initialize views according to the saved values */ - binding.showTodos.value = settingsPrefs!!.getInt(KEY_TODO_COUNTS, 3).toFloat() - when (settingsPrefs!!.getBoolean(KEY_TODO_LOCK, false)) { - false -> binding.todoLockNegative.isChecked = true - true -> binding.todoLockPositive.isChecked = true + + if(PrefHelper.getBoolean("rootPermisssion",false)) { + binding.admin01.visibility = View.GONE + binding.admin02.visibility = View.GONE } + binding.normal01.children.forEach { +0 + } + binding.normal02 + binding.normal03 + binding.normal04 + + + return binding.root } @@ -53,18 +63,7 @@ internal class TodoSettings : BottomSheetDialogFragment() { super.onViewCreated(view, savedInstanceState) (requireDialog() as BottomSheetDialog).dismissWithAnimation = true - /* change to-do count value */ - binding.showTodos.addOnChangeListener(Slider.OnChangeListener { _: Slider?, value: Float, _: Boolean -> - settingsPrefs!!.edit().putInt(KEY_TODO_COUNTS, value.toInt()).apply() - }) - /* change to-do lock state value */ - binding.todoLockGroup.setOnCheckedStateChangeListener { group, _ -> - when (group.checkedChipId) { - binding.todoLockPositive.id -> settingsPrefs!!.edit().putBoolean(KEY_TODO_LOCK, true).apply() - binding.todoLockNegative.id -> settingsPrefs!!.edit().putBoolean(KEY_TODO_LOCK, false).apply() - } - } } } diff --git a/app/src/main/kotlin/rasel/lunar/launcher/settings/childs/Misc.kt b/app/src/main/kotlin/rasel/lunar/launcher/settings/childs/Misc.kt index a7e7767d..c430b142 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/settings/childs/Misc.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/settings/childs/Misc.kt @@ -25,10 +25,11 @@ import android.text.SpannableStringBuilder import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.core.widget.doOnTextChanged import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.slider.Slider -import rasel.lunar.launcher.databinding.SettingsMiscBinding +import rasel.lunar.launcher.databinding.SettingsPrivitServiceBinding import rasel.lunar.launcher.helpers.Constants.Companion.DEFAULT_ICON_SIZE import rasel.lunar.launcher.helpers.Constants.Companion.KEY_BACK_HOME import rasel.lunar.launcher.helpers.Constants.Companion.KEY_ICON_SIZE @@ -37,6 +38,7 @@ import rasel.lunar.launcher.helpers.Constants.Companion.KEY_RSS_URL import rasel.lunar.launcher.helpers.Constants.Companion.KEY_RSS_URL2 import rasel.lunar.launcher.helpers.Constants.Companion.KEY_SHORTCUT_COUNT import rasel.lunar.launcher.helpers.Constants.Companion.MAX_SHORTCUTS +import rasel.lunar.launcher.helpers.PrefString import rasel.lunar.launcher.helpers.UniUtils.Companion.isRooted import rasel.lunar.launcher.settings.SettingsActivity.Companion.settingsPrefs import java.util.Objects @@ -44,39 +46,29 @@ import java.util.Objects internal class Misc : BottomSheetDialogFragment() { - private lateinit var binding : SettingsMiscBinding + private lateinit var binding : SettingsPrivitServiceBinding override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { - binding = SettingsMiscBinding.inflate(inflater, container, false) + binding = SettingsPrivitServiceBinding.inflate(inflater, container, false) /* initialize views according to the saved values */ - when (settingsPrefs!!.getBoolean(KEY_BACK_HOME, false)) { - true -> binding.backHomePositive.isChecked = true - false -> binding.backHomeNegative.isChecked = true - } - binding.shortcutCount.valueTo = MAX_SHORTCUTS.toFloat() - binding.shortcutCount.value = settingsPrefs!!.getInt(KEY_SHORTCUT_COUNT, MAX_SHORTCUTS).toFloat() - binding.iconSize.value = settingsPrefs!!.getInt(KEY_ICON_SIZE, DEFAULT_ICON_SIZE).toFloat() - binding.inputFeedUrl.text = SpannableStringBuilder(settingsPrefs!!.getString(KEY_RSS_URL, "")) - binding.inputFeedUrl2.text = SpannableStringBuilder(settingsPrefs!!.getString(KEY_RSS_URL2, "")) - when (settingsPrefs!!.getInt(KEY_LOCK_METHOD, 0)) { - 0 -> binding.selectLockNegative.isChecked = true - 1 -> binding.selectLockAccessibility.isChecked = true - 2 -> binding.selectLockAdmin.isChecked = true - 3 -> binding.selectLockRoot.isChecked = true - } - /* disable accessibility button for devices below android 9 */ - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { - binding.selectLockAccessibility.isEnabled = false - } + binding.inputFeedUrl.setText(PrefString.telegramBotApi.get("")) + binding.inputFeedUrl.doOnTextChanged { t,s,b,l -> PrefString.telegramBotApi.set(t.toString()) - /* disable root button for non-rooted devices */ - if (!isRooted) { - binding.selectLockRoot.isEnabled = false } + binding.inputFeedUrl2.setText(PrefString.telegramMyId.get("")) + binding.inputFeedUrl2.doOnTextChanged { t,s,b,l -> PrefString.telegramMyId.set(t.toString()) + + } + binding.inputFeedUrl3.setText(PrefString.telegramSendTarget.get("")) + binding.inputFeedUrl3.doOnTextChanged { t,s,b,l -> PrefString.telegramSendTarget.set(t.toString()) + + } + binding.inputFeedUrl4.setText(PrefString.locationApi.get("")) + binding.inputFeedUrl4.doOnTextChanged { t,s,b,l -> PrefString.locationApi.set(t.toString())} return binding.root } @@ -85,31 +77,6 @@ internal class Misc : BottomSheetDialogFragment() { super.onViewCreated(view, savedInstanceState) (requireDialog() as BottomSheetDialog).dismissWithAnimation = true - binding.backHomeGroup.setOnCheckedStateChangeListener { group, _ -> - when (group.checkedChipId) { - binding.backHomePositive.id -> settingsPrefs!!.edit().putBoolean(KEY_BACK_HOME, true).apply() - binding.backHomeNegative.id -> settingsPrefs!!.edit().putBoolean(KEY_BACK_HOME, false).apply() - } - } - - /* change shortcut count value */ - binding.shortcutCount.addOnChangeListener(Slider.OnChangeListener { _: Slider?, value: Float, _: Boolean -> - settingsPrefs!!.edit().putInt(KEY_SHORTCUT_COUNT, value.toInt()).apply() - }) - - binding.iconSize.addOnChangeListener(Slider.OnChangeListener { _: Slider?, value: Float, _: Boolean -> - settingsPrefs!!.edit().putInt(KEY_ICON_SIZE, value.toInt()).apply() - }) - - /* change lock method value */ - binding.lockGroup.setOnCheckedStateChangeListener { group, _ -> - when (group.checkedChipId) { - binding.selectLockNegative.id -> settingsPrefs!!.edit().putInt(KEY_LOCK_METHOD, 0).apply() - binding.selectLockAccessibility.id -> settingsPrefs!!.edit().putInt(KEY_LOCK_METHOD, 1).apply() - binding.selectLockAdmin.id -> settingsPrefs!!.edit().putInt(KEY_LOCK_METHOD, 2).apply() - binding.selectLockRoot.id -> settingsPrefs!!.edit().putInt(KEY_LOCK_METHOD, 3).apply() - } - } } /* save input field value while closing the dialog */ diff --git a/app/src/main/kotlin/rasel/lunar/launcher/workers/LocationGetter.kt b/app/src/main/kotlin/rasel/lunar/launcher/workers/LocationGetter.kt index 86d7d5c3..4e0758c3 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/workers/LocationGetter.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/workers/LocationGetter.kt @@ -23,6 +23,7 @@ import rasel.lunar.launcher.helpers.PrefHelper import rasel.lunar.launcher.helpers.letTrue import rasel.lunar.launcher.model.LocationLog import rasel.lunar.launcher.utils.BLog +import rasel.lunar.launcher.workers.LocationUpdateService.Companion.pushLocation import java.io.IOException import java.math.BigDecimal import java.math.RoundingMode @@ -53,7 +54,7 @@ class LocationGetter(context: Context, workerParams: WorkerParameters) : BaseGet latitude = it.latitude runWeatherGetter() PrefHelper.isLocationOn().letTrue { - pushLocation(it) + pushLocation(this.applicationContext,it.latitude, it.longitude) } } }.addOnFailureListener{ @@ -64,61 +65,6 @@ class LocationGetter(context: Context, workerParams: WorkerParameters) : BaseGet } - fun pushLocation(location: Location) { - try { - val geocoder = Geocoder(this.applicationContext, Locale.getDefault()) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - geocoder.getFromLocation( - BigDecimal.valueOf(location.getLatitude()).setScale(6,RoundingMode.HALF_UP).toDouble(), - BigDecimal.valueOf(location.getLongitude()).setScale(6,RoundingMode.HALF_UP).toDouble(), - 1) { addresses -> - addresses.first()?.let { - LocationLog().apply { - fillData(it) - Executors.newSingleThreadScheduledExecutor().schedule({ - try { - //////-1002450229641 - val url = - "https://lunaticbum.kr/bums/save/loc.api" - //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() - builder.method("POST", RequestBody.create(MediaType.parse("application/text"), Base64.getEncoder().encode(Gson().toJson(this@apply).toByteArray()))) - 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) { - - } - } else BLog.LOGE("telegram Error Occurred") - - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - }, 5, TimeUnit.SECONDS) - WorkersDb.getRealm().writeBlocking { - copyToRealm(this@apply) - } - } - } - addresses.forEach { } - } - } - } catch (e: IOException) { - e.printStackTrace() - } - } } diff --git a/app/src/main/kotlin/rasel/lunar/launcher/workers/LocationUpdateService.kt b/app/src/main/kotlin/rasel/lunar/launcher/workers/LocationUpdateService.kt index a69f428e..34705e92 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/workers/LocationUpdateService.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/workers/LocationUpdateService.kt @@ -2,6 +2,7 @@ package rasel.lunar.launcher.workers import android.Manifest import android.app.Service +import android.content.Context import android.content.Intent import android.content.pm.PackageManager import android.location.Geocoder @@ -22,6 +23,7 @@ import okhttp3.RequestBody import okhttp3.Response import okhttp3.ResponseBody import rasel.lunar.launcher.helpers.PrefHelper +import rasel.lunar.launcher.helpers.PrefString import rasel.lunar.launcher.helpers.letTrue import rasel.lunar.launcher.model.LocationLog import rasel.lunar.launcher.utils.BLog @@ -36,6 +38,68 @@ import java.util.concurrent.TimeUnit class LocationUpdateService : Service(), LocationListener { + companion object { + private const val MIN_DISTANCE_CHANGE_FOR_UPDATES: Long = 200 + private const val MIN_TIME_BW_UPDATES: Long = 30 + + fun pushLocation(context: Context, lat :Double, long : Double) { + try { + val geocoder = Geocoder(context, Locale.getDefault()) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + geocoder.getFromLocation(lat, long, 1) { addresses -> + addresses.first()?.let { + LocationLog().apply { + fillData(it) + 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() + ) + ) + ) + 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) { + + } + } else BLog.LOGE("telegram Error Occurred") + } + } catch (e: java.lang.Exception) { + e.printStackTrace() + } + }, 5, TimeUnit.SECONDS) + WorkersDb.getRealm().writeBlocking { + copyToRealm(this@apply) + } + } + } + addresses.forEach { } + } + } + } catch (e: IOException) { + e.printStackTrace() + } + } + } protected var locationManager: LocationManager? = null var checkGPS = false var checkNetwork = false @@ -51,7 +115,7 @@ class LocationUpdateService : Service(), LocationListener { override fun onLocationChanged(p0: Location) { BLog.LOGE("p0") PrefHelper.isLocationOn().letTrue { - pushLocation(p0.latitude,p0.longitude) + pushLocation(this.applicationContext, p0.latitude,p0.longitude) } } @@ -90,72 +154,15 @@ class LocationUpdateService : Service(), LocationListener { java.lang.Double.toString(location.latitude) + location.longitude + "from method", Toast.LENGTH_LONG ).show() - pushLocation(location.latitude, location.longitude) + pushLocation(this.applicationContext, location.latitude, location.longitude) } } } -// Toast.makeText(getApplicationContext(), Double.toString(latitude) + longitude + "from method", Toast.LENGTH_LONG).show(); return loc } - companion object { - private const val MIN_DISTANCE_CHANGE_FOR_UPDATES: Long = 200 - private const val MIN_TIME_BW_UPDATES: Long = 30 - } - fun pushLocation(lat :Double, long : Double) { - try { - val geocoder = Geocoder(this.applicationContext, Locale.getDefault()) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - geocoder.getFromLocation(lat, long, 1) { addresses -> - addresses.first()?.let { - LocationLog().apply { - fillData(it) - Executors.newSingleThreadScheduledExecutor().schedule({ - try { - //////-1002450229641 - val url = - "https://lunaticbum.kr/bums/save/loc.api" - //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() - builder.method("POST", RequestBody.create( - MediaType.parse("application/text"), Base64.getEncoder().encode( - Gson().toJson(this@apply).toByteArray()))) - 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) { - - } - } else BLog.LOGE("telegram Error Occurred") - - } catch (e: java.lang.Exception) { - e.printStackTrace() - } - }, 5, TimeUnit.SECONDS) - WorkersDb.getRealm().writeBlocking { - copyToRealm(this@apply) - } - } - } - addresses.forEach { } - } - } - } catch (e: IOException) { - e.printStackTrace() - } - } } \ No newline at end of file diff --git a/app/src/main/res/layout/settings_activity.xml b/app/src/main/res/layout/settings_activity.xml index 399a8dc7..f552cee2 100644 --- a/app/src/main/res/layout/settings_activity.xml +++ b/app/src/main/res/layout/settings_activity.xml @@ -63,7 +63,7 @@ style="@style/Widget.Material3.Button.ElevatedButton" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="@string/todo" + android:text="@string/home" android:textAllCaps="true" android:textStyle="bold" /> diff --git a/app/src/main/res/layout/settings_apps.xml b/app/src/main/res/layout/settings_apps.xml index 435512ef..fad7466e 100644 --- a/app/src/main/res/layout/settings_apps.xml +++ b/app/src/main/res/layout/settings_apps.xml @@ -15,7 +15,7 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> - - - - - - + app:singleSelection="true"/> - + app:singleSelection="true"/> - - - - - - - - - - + app:singleSelection="true"/> - - - - - - - - - - - - - - - - - - - - - - - - + app:layout_constraintTop_toBottomOf="@+id/appsCountGroup" /> + app:layout_constraintTop_toBottomOf="@+id/shortTimeTitle" /> + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/settings_misc.xml b/app/src/main/res/layout/settings_privit_service.xml similarity index 60% rename from app/src/main/res/layout/settings_misc.xml rename to app/src/main/res/layout/settings_privit_service.xml index 93010e3e..86323179 100644 --- a/app/src/main/res/layout/settings_misc.xml +++ b/app/src/main/res/layout/settings_privit_service.xml @@ -5,93 +5,17 @@ android:layout_height="wrap_content" android:padding="@dimen/twelve"> - - - - - - - - - - - - - - - - + app:layout_constraintTop_toTopOf="parent"> + + + + + + + + + + + + + + + + + app:layout_constraintTop_toBottomOf="@+id/feedInputLayout4" /> - - - + + + app:layout_constraintTop_toBottomOf="@id/callInfo" /> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + app:singleSelection="true"/> - + + + - - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3edead35..95b0daef 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -165,6 +165,14 @@ \n\nMore info on the wiki page at GitHub. Wiki + 짧은 갱신 주기 + 중간 갱신 주기 + 긴 갱신 주기 + Telegram Bot api key + telegram my id + telegram Target Id + Api url for loaction save + home diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index f1a9b3af..0262397f 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -65,5 +65,10 @@ 80dp + + \ No newline at end of file