From caf5601a71aca54d922a17d66df26739e1ea51a5 Mon Sep 17 00:00:00 2001 From: lunaticbum <> Date: Fri, 15 Nov 2024 17:48:20 +0900 Subject: [PATCH] ... --- .../bums/lunatic/launcher/LauncherActivity.kt | 60 ++++------------ .../bums/lunatic/launcher/feeds/Feeds.kt | 58 ++++++++-------- .../lunatic/launcher/helpers/PrefHelper.kt | 2 + .../lunatic/launcher/home/LauncherHome.kt | 22 ++++-- .../launcher/home/adapters/RssFeedsParser.kt | 2 +- .../launcher/home/adapters/RssItemAdapter.kt | 3 + .../home/adapters/WeatherDressAdatper.kt | 2 +- .../launcher/settings/SettingsActivity.kt | 4 +- .../childs/{TimeDate.kt => TopInfos.kt} | 56 ++++++++++++--- .../settings/childs/WeatherSettings.kt | 28 +++++++- .../lunatic/launcher/view/DateTimeView.kt | 9 ++- .../lunatic/launcher/workers/BaseGetter.kt | 1 + .../launcher/workers/LocationUpdateService.kt | 68 ++++--------------- .../launcher/workers/NewsFeedsGetter.kt | 1 - .../launcher/workers/OpenWeatherGetter.kt | 3 +- .../main/res/layout/item_rec_hourly_dress.xml | 55 ++++++++++----- app/src/main/res/layout/launcher_home.xml | 2 + app/src/main/res/layout/settings_activity.xml | 2 +- .../main/res/layout/settings_time_date.xml | 11 ++- app/src/main/res/layout/settings_weather.xml | 2 +- app/src/main/res/layout/weather_book.xml | 4 +- 21 files changed, 217 insertions(+), 178 deletions(-) rename app/src/main/kotlin/bums/lunatic/launcher/settings/childs/{TimeDate.kt => TopInfos.kt} (57%) diff --git a/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt b/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt index a3631c6..afc9654 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt @@ -68,6 +68,7 @@ import androidx.core.view.updatePadding import androidx.recyclerview.widget.RecyclerView import androidx.viewpager2.widget.ViewPager2 import androidx.work.ExistingPeriodicWorkPolicy +import androidx.work.ListenableWorker import androidx.work.OneTimeWorkRequest import androidx.work.PeriodicWorkRequestBuilder import androidx.work.WorkManager @@ -185,21 +186,12 @@ internal class LauncherActivity : AppCompatActivity() { .addTag(ContactInfoGetter.TAG) .build()) }, delay, TimeUnit.SECONDS) - delay = delay + 3L -// Executors.newSingleThreadScheduledExecutor().schedule({ -// mWorkManager?.cancelAllWorkByTag(AppInfoGetter.TAG) -// mWorkManager?.enqueueUniquePeriodicWork( -// AppInfoGetter.TAG, ExistingPeriodicWorkPolicy.CANCEL_AND_REENQUEUE, -// PeriodicWorkRequestBuilder(12, TimeUnit.HOURS) -// .addTag(AppInfoGetter.TAG) -// .build()) -// }, delay, TimeUnit.SECONDS) -// delay = delay + 3L Executors.newSingleThreadScheduledExecutor().schedule({ mWorkManager?.enqueue(OneTimeWorkRequest.from(AppInfoGetter::class.java)) }, 5, TimeUnit.SECONDS) } + fun runWeatherGetter() { Executors.newSingleThreadScheduledExecutor().schedule({ mWorkManager?.enqueue(OneTimeWorkRequest.from(OpenWeatherGetter::class.java)) @@ -212,14 +204,10 @@ internal class LauncherActivity : AppCompatActivity() { }, 5, TimeUnit.SECONDS) } + val defaultDelay = 10L + fun refreshFeeds() { -// Fri, 15 11 2024 15:06:28 +0900 -// Fri, 15 11 2024 15:28:04 +0900 - var parseDateFormat2: SimpleDateFormat = SimpleDateFormat("E, dd MM yyyy HH:mm:ss zz", Locale.ENGLISH) - BLog.LOGE("TEST DATE FORMAT ${parseDateFormat2.format(Date())}") - var parseDateFormat3: SimpleDateFormat = SimpleDateFormat("E, dd MM yyyy HH:mm:ss ZZ", Locale.ENGLISH) - BLog.LOGE("TEST DATE FORMAT ${parseDateFormat3.format(Date())}") - var delay = 5L + var delay = defaultDelay Executors.newSingleThreadScheduledExecutor().schedule({ mWorkManager?.cancelAllWorkByTag(FEDDS_WORK_TAG) mWorkManager?.enqueueUniquePeriodicWork( @@ -228,7 +216,7 @@ internal class LauncherActivity : AppCompatActivity() { .addTag(FEDDS_WORK_TAG) .build()) }, delay, TimeUnit.SECONDS) - delay= delay + 5 + delay += defaultDelay Executors.newSingleThreadScheduledExecutor().schedule({ mWorkManager?.cancelAllWorkByTag(YT_WORK_TAG) mWorkManager?.enqueueUniquePeriodicWork( @@ -237,7 +225,7 @@ internal class LauncherActivity : AppCompatActivity() { .addTag(YT_WORK_TAG) .build()) }, delay, TimeUnit.SECONDS) - delay= delay + 5 + delay += defaultDelay Executors.newSingleThreadScheduledExecutor().schedule({ mWorkManager?.cancelAllWorkByTag(REDDIT_WORK_TAG) mWorkManager?.enqueueUniquePeriodicWork( @@ -246,7 +234,7 @@ internal class LauncherActivity : AppCompatActivity() { .addTag(REDDIT_WORK_TAG) .build()) }, delay, TimeUnit.SECONDS) - delay= delay + 5 + delay += defaultDelay Executors.newSingleThreadScheduledExecutor().schedule({ mWorkManager?.cancelAllWorkByTag(COMIC_WORK_TAG) mWorkManager?.enqueueUniquePeriodicWork( @@ -255,7 +243,7 @@ internal class LauncherActivity : AppCompatActivity() { .addTag(COMIC_WORK_TAG) .build()) }, delay, TimeUnit.SECONDS) - delay= delay + 5 + delay += defaultDelay Executors.newSingleThreadScheduledExecutor().schedule({ mWorkManager?.cancelAllWorkByTag(COMIC2_WORK_TAG) mWorkManager?.enqueueUniquePeriodicWork( @@ -264,7 +252,7 @@ internal class LauncherActivity : AppCompatActivity() { .addTag(COMIC2_WORK_TAG) .build()) }, delay, TimeUnit.SECONDS) - delay= delay + 5 + delay += defaultDelay Executors.newSingleThreadScheduledExecutor().schedule({ mWorkManager?.cancelAllWorkByTag(ClienGetter.TAG) mWorkManager?.enqueueUniquePeriodicWork( @@ -273,7 +261,7 @@ internal class LauncherActivity : AppCompatActivity() { .addTag(ClienGetter.TAG) .build()) }, delay, TimeUnit.SECONDS) - delay= delay + 5 + delay += defaultDelay Executors.newSingleThreadScheduledExecutor().schedule({ mWorkManager?.cancelAllWorkByTag(DCGetter.TAG) mWorkManager?.enqueueUniquePeriodicWork( @@ -282,7 +270,7 @@ internal class LauncherActivity : AppCompatActivity() { .addTag(DCGetter.TAG) .build()) }, delay, TimeUnit.SECONDS) - delay= delay + 5 + delay += defaultDelay Executors.newSingleThreadScheduledExecutor().schedule({ mWorkManager?.cancelAllWorkByTag(RuliWebGetter.TAG) mWorkManager?.enqueueUniquePeriodicWork( @@ -291,7 +279,7 @@ internal class LauncherActivity : AppCompatActivity() { .addTag(RuliWebGetter.TAG) .build()) }, delay, TimeUnit.SECONDS) - delay= delay + 5 + delay += defaultDelay Executors.newSingleThreadScheduledExecutor().schedule({ mWorkManager?.cancelAllWorkByTag(TheQooGetter.TAG) mWorkManager?.enqueueUniquePeriodicWork( @@ -300,7 +288,7 @@ internal class LauncherActivity : AppCompatActivity() { .addTag(TheQooGetter.TAG) .build()) }, delay, TimeUnit.SECONDS) - delay= delay + 5 + delay += defaultDelay Executors.newSingleThreadScheduledExecutor().schedule({ mWorkManager?.cancelAllWorkByTag(ArcaGetter.TAG) mWorkManager?.enqueueUniquePeriodicWork( @@ -311,26 +299,6 @@ internal class LauncherActivity : AppCompatActivity() { }, delay, TimeUnit.SECONDS) -// val weatherDelay = 3L -// Executors.newSingleThreadScheduledExecutor().schedule({ -// //de574a260b1f474d99955729241909 -// mWorkManager?.cancelAllWorkByTag(LocationGetter.TAG) -// mWorkManager?.enqueueUniquePeriodicWork( -// LocationGetter.TAG, ExistingPeriodicWorkPolicy.CANCEL_AND_REENQUEUE, -// PeriodicWorkRequestBuilder(PrefLong.longTimePeriod.get(), TimeUnit.MINUTES) -// .addTag(LocationGetter.TAG) -// .build()) -// }, weatherDelay, TimeUnit.SECONDS) - -// Executors.newSingleThreadScheduledExecutor().schedule({ -// //de574a260b1f474d99955729241909 -// mWorkManager?.cancelAllWorkByTag(OpenWeatherGetter.TAG) -// mWorkManager?.enqueueUniquePeriodicWork( -// OpenWeatherGetter.TAG, ExistingPeriodicWorkPolicy.CANCEL_AND_REENQUEUE, -// PeriodicWorkRequestBuilder(midTimePeriod, TimeUnit.MINUTES) -// .addTag(OpenWeatherGetter.TAG) -// .build()) -// }, weatherDelay + 3, TimeUnit.SECONDS) } 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 1a6b4c3..0e1d566 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/feeds/Feeds.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/feeds/Feeds.kt @@ -261,17 +261,17 @@ internal class Feeds : Fragment() , CommadCallabck { home?.queryInfos(keyword = cmd[1]) } "jf" -> { - consoleLog("on Cmd JF") -// CoroutineScope(Dispatchers.IO).launch { -// consoleLog("${cmd[0]} Start ${cmd[1]}") -// String.format(String(Base64.getMimeDecoder().decode("aHR0cHM6Ly9qYXZtb3N0LnRvL3NlYXJjaC9tb3ZpZS8lcw==".toByteArray())),cmd[1]).getJ().let { doc -> FeedParseManager.parse(doc){consoleLog(it)} } -// consoleLog("current j req() ${WorkersDb.getRealm().query("category == $0", RssDataType.GURU.name).find().size}") -// consoleLog("${cmd[0]} END ${cmd[1]}") -// } + CoroutineScope(Dispatchers.IO).launch { + consoleLog("${cmd[0]} Start ${cmd[1]}") + String.format(String(Base64.getMimeDecoder().decode("aHR0cHM6Ly9qYXZtb3N0LnRvL3NlYXJjaC9tb3ZpZS8lcw==".toByteArray())),cmd[1]).getJ().let { doc -> FeedParseManager.parse(doc){consoleLog(it)} } + consoleLog("current j req() ${WorkersDb.getRealm().query("category == $0", RssDataType.GURU.name).find().size}") + consoleLog("${cmd[0]} END ${cmd[1]}") + } + CoroutineScope(Dispatchers.IO).launch { consoleLog("on Cmd JF with MOST") consoleLog("${cmd[0]} Start ${cmd[1]}") - String.format(String(Base64.getMimeDecoder().decode("aHR0cHM6Ly9rcjcwLnNvZ2lybC5zby8/cz0lcw==".toByteArray())),cmd[1]).getJ().let { doc -> FeedParseManager.parse(doc){consoleLog(it)} } + String.format(String(Base64.getMimeDecoder().decode("aHR0cHM6Ly9rcjcxLnNvZ2lybC5zby8/cz0lcw==".toByteArray())),cmd[1]).getJ().let { doc -> FeedParseManager.parse(doc){consoleLog(it)} } consoleLog("current j req() ${WorkersDb.getRealm().query("category == $0", RssDataType.MOST.name).find().size}") consoleLog("${cmd[0]} END ${cmd[1]}") } @@ -478,28 +478,28 @@ internal class Feeds : Fragment() , CommadCallabck { CoroutineScope(Dispatchers.IO).launch { var isOk = false // plist.forEach { - if (!isOk) { - try { - Jsoup.connect(jGuruMain) - .userAgent("Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.5414.117 Mobile Safari/537.36") - .referrer("http://www.google.com") - .header("Accept-Language", "it-IT,en;q=0.8,en-US;q=0.6,de;q=0.4,it;q=0.2,es;q=0.2") - .header("Connection", "keep-alive") - .header("scheme", "https") - .header("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8") - .header("accept-encoding", "gzip, deflate, br") - .header("cache-control", "no-cache") - .header("pragma", "no-cache") - .header("upgrade-insecure-requests", "1") - .ignoreContentType(true) - .timeout(30000).execute().let { - BLog.LOGE("DOC -> ${it}") - isOk = true - } - } catch (e: Exception) { - e.printStackTrace() - } + if (!isOk) { + try { + Jsoup.connect(jGuruMain) + .userAgent("Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.5414.117 Mobile Safari/537.36") + .referrer("http://www.google.com") + .header("Accept-Language", "it-IT,en;q=0.8,en-US;q=0.6,de;q=0.4,it;q=0.2,es;q=0.2") + .header("Connection", "keep-alive") + .header("scheme", "https") + .header("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8") + .header("accept-encoding", "gzip, deflate, br") + .header("cache-control", "no-cache") + .header("pragma", "no-cache") + .header("upgrade-insecure-requests", "1") + .ignoreContentType(true) + .timeout(30000).execute().let { + BLog.LOGE("DOC -> ${it}") + isOk = true + } + } catch (e: Exception) { + e.printStackTrace() } + } // } BLog.LOGE("last state ${isOk}") } diff --git a/app/src/main/kotlin/bums/lunatic/launcher/helpers/PrefHelper.kt b/app/src/main/kotlin/bums/lunatic/launcher/helpers/PrefHelper.kt index c8ebcba..781af71 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/helpers/PrefHelper.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/helpers/PrefHelper.kt @@ -33,6 +33,8 @@ enum class PrefLong(val def : Long) : PrefKey { } enum class PrefBoolean : PrefKey { + displayBattery, + displayDateTime, location, rootPermisssion, isConnectedCar, 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 e9d770f..2da93e0 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/home/LauncherHome.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/home/LauncherHome.kt @@ -496,7 +496,7 @@ internal class LauncherHome : Fragment() { } fun updateQuery(q: RealmQuery) { - mRssDataResult = q.sort("pubDate ", Sort.DESCENDING).limit(300).distinct("chosung").find() + mRssDataResult = q.sort("pubDate ", Sort.DESCENDING).limit(300).distinct("title").find() infosJob = CoroutineScope(Dispatchers.Default).launch { mRssDataResult?.asFlow()?.collect { changes: ResultsChange -> commandHandler.removeCallbacks(hideListView) @@ -522,7 +522,7 @@ internal class LauncherHome : Fragment() { } fun queryInfos( - filter: Collection? = arrayListOf(), noLimit: Boolean = false + filter: Collection? = arrayListOf(RssDataType.GURU, RssDataType.MOST,RssDataType.REDDIT_NSFW), noLimit: Boolean = false ) { beforeQuery() var rQ = WorkersDb.getRealm().query().query("read < $0", nomoreShowCount) @@ -545,6 +545,16 @@ internal class LauncherHome : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + + PrefBoolean.displayDateTime.get().letTrue { + binding.time.visibility = View.VISIBLE + } + + + PrefBoolean.displayBattery.get().letTrue { + binding.batteryProgress.visibility = View.VISIBLE + } + binding.batteryProgress.setOnTouchListener(SimpleFingerGestures(context = requireContext(), binding.batteryProgress, mFingerGestureListener)) binding.root.setOnTouchListener(SimpleFingerGestures(context = requireContext(), binding.root, mFingerGestureListener)) binding.functionLayer.setOnTouchListener(SimpleFingerGestures(context = requireContext(), binding.functionLayer, mFingerGestureListener)) @@ -597,7 +607,7 @@ internal class LauncherHome : Fragment() { binding.otherCheck -> { if (binding.otherCheck.isSelected) { - if (rssStateVote() || lasted?.size ?: 0 < 200) { + if (rssStateVote()) { queryInfos() } else { binding.otherCheck.isSelected = false @@ -649,15 +659,15 @@ internal class LauncherHome : Fragment() { val input = viewInflated.findViewById(R.id.input) as EditText val categoryz = viewInflated.findViewById(R.id.categoryz) as TableRadioGroup - categoryz.setMaxColumns(5) - categoryz.setMaxRows(5) + categoryz.setMaxColumns(3) + categoryz.setMaxRows(8) categoryz.setOnCheckedChangeListener(object : TableRadioGroup.OnCheckedChangeListener { override fun onCheckedChanged(group: TableRadioGroup?, checkedId: Int) { } }) var idx = 0 - RssDataType.values().reversed().toList().chunked(5).forEach { + RssDataType.values().reversed().toList().chunked(3).forEach { var tb = TableRow(requireContext()) it.forEach { c -> if (c.equals(RssDataType.NO_DATA) == false) { diff --git a/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/RssFeedsParser.kt b/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/RssFeedsParser.kt index 14e1197..782248e 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/RssFeedsParser.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/RssFeedsParser.kt @@ -100,7 +100,7 @@ object RssFeedsParser { link = readLink(parser) } else if (name == "pubDate") { val dateStr = readDate(parser) - try { date = parseDateFormat.parse(dateStr)?.time ?: 0L } catch (e : Exception) { date = 0L } finally { BLog.LOGE("readFeed >>> parse 1 date ${date}") } + try { date = parseDateFormat.parse(dateStr)?.time ?: 0L } catch (e : Exception) { date = 0L } if (date == 0L) { try { date = parseDateFormat2.parse(dateStr)?.time ?: 0L } catch (e: Exception) { } } } else if (name == "description") { desc = readDesc(parser) diff --git a/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/RssItemAdapter.kt b/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/RssItemAdapter.kt index 59a73a3..b6755b5 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/RssItemAdapter.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/RssItemAdapter.kt @@ -69,6 +69,9 @@ internal class RssItemAdapter ( WorkersDb.getRealm().apply { writeBlocking { rss.read = rss.read + 1 + if(rss.getCho()?.length ?: 0 < 1) { + rss.chosung = rss.title + } copyToRealm(rss,UpdatePolicy.ALL) } } diff --git a/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/WeatherDressAdatper.kt b/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/WeatherDressAdatper.kt index 1e4bcc7..96f66ad 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/WeatherDressAdatper.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/WeatherDressAdatper.kt @@ -64,7 +64,7 @@ class WeatherDressAdatper (private val dataSet: ArrayList) : RecyclerView. this@apply.isSelected = false } } - holder.viewItem.imgDress.setImageLevel(it.temp_c.toInt()) + holder.viewItem.imgWeather.setImageLevel(it.temp_c.toInt()) } } diff --git a/app/src/main/kotlin/bums/lunatic/launcher/settings/SettingsActivity.kt b/app/src/main/kotlin/bums/lunatic/launcher/settings/SettingsActivity.kt index 7b3905a..8764184 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/settings/SettingsActivity.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/settings/SettingsActivity.kt @@ -36,7 +36,7 @@ import bums.lunatic.launcher.settings.childs.Appearances import bums.lunatic.launcher.settings.childs.Apps import bums.lunatic.launcher.settings.childs.HomeSettings import bums.lunatic.launcher.settings.childs.Misc -import bums.lunatic.launcher.settings.childs.TimeDate +import bums.lunatic.launcher.settings.childs.TopInfos import bums.lunatic.launcher.settings.childs.WeatherSettings import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.color.DynamicColors @@ -65,7 +65,7 @@ internal class SettingsActivity : AppCompatActivity() { /* launch child settings dialogs on button clicks */ binding.timeDate.setOnClickListener { - TimeDate().show(supportFragmentManager, BOTTOM_SHEET_TAG) + TopInfos().show(supportFragmentManager, BOTTOM_SHEET_TAG) } binding.weather.setOnClickListener { diff --git a/app/src/main/kotlin/bums/lunatic/launcher/settings/childs/TimeDate.kt b/app/src/main/kotlin/bums/lunatic/launcher/settings/childs/TopInfos.kt similarity index 57% rename from app/src/main/kotlin/bums/lunatic/launcher/settings/childs/TimeDate.kt rename to app/src/main/kotlin/bums/lunatic/launcher/settings/childs/TopInfos.kt index 613cc66..7f26822 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/settings/childs/TimeDate.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/settings/childs/TopInfos.kt @@ -26,36 +26,67 @@ import android.view.ViewGroup import androidx.core.widget.doAfterTextChanged import bums.lunatic.launcher.R import bums.lunatic.launcher.databinding.SettingsTimeDateBinding -import bums.lunatic.launcher.helpers.Constants.Companion.DEFAULT_DATE_FORMAT -import bums.lunatic.launcher.helpers.Constants.Companion.KEY_DATE_FORMAT -import bums.lunatic.launcher.helpers.Constants.Companion.KEY_TIME_FORMAT -import bums.lunatic.launcher.settings.SettingsActivity.Companion.settingsPrefs +import bums.lunatic.launcher.helpers.PrefBoolean +import bums.lunatic.launcher.helpers.PrefHelper +import bums.lunatic.launcher.helpers.PrefString +import bums.lunatic.launcher.utils.BLog import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.dialog.MaterialAlertDialogBuilder +import com.google.gson.Gson import java.text.SimpleDateFormat import java.util.Date -import java.util.Objects import kotlin.system.exitProcess -internal class TimeDate : BottomSheetDialogFragment() { +internal class TopInfos : BottomSheetDialogFragment() { private lateinit var binding : SettingsTimeDateBinding private var settingsChanged: Boolean = false override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { binding = SettingsTimeDateBinding.inflate(inflater, container, false) + + binding.useBattery.isChecked = PrefBoolean.displayBattery.get(true) + binding.useDateTime.isChecked = PrefBoolean.displayDateTime.get(true) + BLog.LOGE("PrefHelper.getSettings() >>> ${Gson().toJson(PrefHelper.getSettings())}") + binding.useBattery.setOnCheckedChangeListener { button, b -> + PrefBoolean.displayBattery.set(b) + settingsChanged = true + } + + updateViews() + + binding.useDateTime.setOnCheckedChangeListener { button, b -> + PrefBoolean.displayDateTime.set(b) + settingsChanged = true + updateViews() + } + + + binding.timeFormat.setText(PrefString.defaultTimeFormat.get("a HH:mm:ss")) + binding.dateFormat.setText(PrefString.defaultDateFormat.get("yyyy년 MM월 W주차 dd일 E요일")) + binding.previewDateTime.defaultTimeFormat = PrefString.defaultTimeFormat.get("a HH:mm:ss") + binding.previewDateTime.defaultDateFormat = PrefString.defaultDateFormat.get("yyyy년 MM월 W주차 dd일 E요일") binding.timeFormat.doAfterTextChanged { try { SimpleDateFormat(it.toString()).format(Date()) - binding.previewDateTime + binding.previewDateTime.defaultTimeFormat = it.toString() + settingsChanged = true + PrefString.defaultTimeFormat.set(it.toString()) } catch (e : Exception) { } } binding.dateFormat.doAfterTextChanged { try { - it.toString() + try { + SimpleDateFormat(it.toString()).format(Date()) + binding.previewDateTime.defaultDateFormat = it.toString() + settingsChanged = true + PrefString.defaultDateFormat.set(it.toString()) + } catch (e : Exception) { + + } } catch (e : Exception) { } @@ -63,7 +94,14 @@ internal class TimeDate : BottomSheetDialogFragment() { return binding.root } - + fun updateViews() { + with(if (binding.useBattery.isChecked) View.VISIBLE else View.GONE){ + binding.timeFormat.visibility = this + binding.dateFormat.visibility = this + binding.previewDateTime.visibility = this + binding.previewDateTime.visibility = this + } + } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) (requireDialog() as BottomSheetDialog).dismissWithAnimation = true diff --git a/app/src/main/kotlin/bums/lunatic/launcher/settings/childs/WeatherSettings.kt b/app/src/main/kotlin/bums/lunatic/launcher/settings/childs/WeatherSettings.kt index 40ee38a..8cdaeb2 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/settings/childs/WeatherSettings.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/settings/childs/WeatherSettings.kt @@ -24,6 +24,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.core.widget.doOnTextChanged +import bums.lunatic.launcher.R import bums.lunatic.launcher.databinding.SettingsWeatherBinding import bums.lunatic.launcher.helpers.Constants.Companion.KEY_CITY_NAME import bums.lunatic.launcher.helpers.Constants.Companion.KEY_OWM_API @@ -34,10 +35,28 @@ import bums.lunatic.launcher.helpers.PrefString import bums.lunatic.launcher.settings.SettingsActivity.Companion.settingsPrefs import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import com.google.android.material.dialog.MaterialAlertDialogBuilder import java.util.Objects +import kotlin.system.exitProcess +open class SettingChild : BottomSheetDialogFragment() { + protected var settingsChanged: Boolean = false + override fun onDismiss(dialog: DialogInterface) { + super.onDismiss(dialog) + if (settingsChanged) { + MaterialAlertDialogBuilder(requireActivity()) + .setTitle(R.string.restart_now) + .setMessage(R.string.restart_message) + .setPositiveButton(R.string.restart) { _, _ -> + exitProcess(0) + } + .setNeutralButton(R.string.later, null) + .show() + } + } +} -internal class WeatherSettings : BottomSheetDialogFragment() { +internal class WeatherSettings : SettingChild() { private lateinit var binding : SettingsWeatherBinding @@ -49,11 +68,14 @@ internal class WeatherSettings : BottomSheetDialogFragment() { binding.inputOwm.setText(PrefString.weatherApiKey.get("")) binding.inputOwm.doOnTextChanged { text, start, before, count -> PrefString.weatherApiKey.set(text.toString()) + settingsChanged = true } binding.dress.isChecked = PrefBoolean.weatherDress.get(false) binding.weather.isChecked = PrefBoolean.weatherState.get(false) - binding.weather.setOnCheckedChangeListener { buttonView, isChecked -> PrefBoolean.weatherState.set(isChecked)} - binding.dress.setOnCheckedChangeListener { buttonView, isChecked -> PrefBoolean.weatherDress.set(isChecked)} + binding.weather.setOnCheckedChangeListener { buttonView, isChecked -> PrefBoolean.weatherState.set(isChecked) + settingsChanged = true} + binding.dress.setOnCheckedChangeListener { buttonView, isChecked -> PrefBoolean.weatherDress.set(isChecked) + settingsChanged = true} return binding.root } 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 1ba145a..f908787 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/view/DateTimeView.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/view/DateTimeView.kt @@ -17,20 +17,25 @@ import android.util.AttributeSet import android.view.View import androidx.appcompat.widget.AppCompatTextView import bums.lunatic.launcher.R +import bums.lunatic.launcher.helpers.PrefString import java.text.SimpleDateFormat import java.util.Date class DateTimeView : AppCompatTextView { lateinit var mHandler : Handler - var defaultTimeFormat = "a HH:mm:ss" + var defaultTimeFormat = PrefString.defaultTimeFormat.get("a HH:mm:ss") + set(value) { field = value + simpleTimeFormat = SimpleDateFormat(defaultTimeFormat) } - var defaultDateFormat = "yyyy년 MM월 W주차 dd일 E요일" + var defaultDateFormat = PrefString.defaultDateFormat.get("yyyy년 MM월 W주차 dd일 E요일") set(value) { field = value + simpleDateFormat = SimpleDateFormat(defaultDateFormat) } + var simpleTimeFormat = SimpleDateFormat(defaultTimeFormat) var simpleDateFormat = SimpleDateFormat(defaultDateFormat) var runable = { diff --git a/app/src/main/kotlin/bums/lunatic/launcher/workers/BaseGetter.kt b/app/src/main/kotlin/bums/lunatic/launcher/workers/BaseGetter.kt index 7c4b9c2..e3de126 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/workers/BaseGetter.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/workers/BaseGetter.kt @@ -20,6 +20,7 @@ open abstract class BaseGetter : Worker { return cal.timeInMillis } } + val USAGT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Safari/605.1.15" val now = Date() val limitDateTime = beforeDay(now,3) 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 73ee6df..28f7b4a 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/workers/LocationUpdateService.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/workers/LocationUpdateService.kt @@ -166,66 +166,26 @@ class LocationUpdateService : Service(), LocationListener { PrefLong.locationDistance.get(200).toFloat(), this ) -// val fusedLocationClient = LocationServices.getFusedLocationProviderClient(this) -// fusedLocationClient.lastLocation.addOnSuccessListener { location -> -// if (location != null) { -// Toast.makeText( -// applicationContext, -// java.lang.Double.toString(location.latitude) + location.longitude + "from method", -// Toast.LENGTH_LONG -// ).show() -// longitude = location.longitude -// latitude = location.latitude -// runWeatherGetter() -// pushLocation(this.applicationContext, location.latitude, location.longitude) -// } -// } + val fusedLocationClient = LocationServices.getFusedLocationProviderClient(this) + fusedLocationClient.lastLocation.addOnSuccessListener { location -> + if (location != null) { + Toast.makeText( + applicationContext, + java.lang.Double.toString(location.latitude) + location.longitude + "from method", + Toast.LENGTH_LONG + ).show() + longitude = location.longitude + latitude = location.latitude + runWeatherGetter() + pushLocation(this.applicationContext, location.latitude, location.longitude) + } + } } catch (e : Exception) { } } - private val location: Location? - get() { - if (ActivityCompat.checkSelfPermission( - this, - Manifest.permission.ACCESS_FINE_LOCATION - ) != - PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission( - this, - Manifest.permission.ACCESS_COARSE_LOCATION - ) - != PackageManager.PERMISSION_GRANTED - ) { - } - locationManager = applicationContext - .getSystemService(LOCATION_SERVICE) as LocationManager - checkGPS = locationManager!! - .isProviderEnabled(LocationManager.GPS_PROVIDER) - checkNetwork = locationManager!! - .isProviderEnabled(LocationManager.NETWORK_PROVIDER) - locationManager?.requestLocationUpdates(LocationManager.GPS_PROVIDER, PrefLong.locationTimePeriod.get(30), PrefLong.locationDistance.get(200).toFloat(), this) - if (locationManager != null) { - val fusedLocationClient = LocationServices.getFusedLocationProviderClient(this) - fusedLocationClient.lastLocation.addOnSuccessListener { location -> - if (location != null) { - Toast.makeText( - applicationContext, - java.lang.Double.toString(location.latitude) + location.longitude + "from method", - Toast.LENGTH_LONG - ).show() - longitude = location.longitude - latitude = location.latitude - runWeatherGetter() - pushLocation(this.applicationContext, location.latitude, location.longitude) - } - } - } - return loc - } - - diff --git a/app/src/main/kotlin/bums/lunatic/launcher/workers/NewsFeedsGetter.kt b/app/src/main/kotlin/bums/lunatic/launcher/workers/NewsFeedsGetter.kt index d685628..57f4005 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/workers/NewsFeedsGetter.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/workers/NewsFeedsGetter.kt @@ -25,7 +25,6 @@ class NewsFeedsGetter : BaseGetter { feddsUrls.addAll(RssList.getFeedUrls()) for (url in feddsUrls) { - BLog.LOGE("start newsFeeds Load By url >>>> ${url}") for (it in RssFeedsParser.getFeeds(url)) { if (it.pubDate() >= limitDateTime) { temp.add(it.getRssData()) diff --git a/app/src/main/kotlin/bums/lunatic/launcher/workers/OpenWeatherGetter.kt b/app/src/main/kotlin/bums/lunatic/launcher/workers/OpenWeatherGetter.kt index 0a24311..4a5a6ec 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/workers/OpenWeatherGetter.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/workers/OpenWeatherGetter.kt @@ -2,6 +2,7 @@ package bums.lunatic.launcher.workers import android.content.Context import androidx.work.WorkerParameters +import bums.lunatic.launcher.helpers.PrefString import bums.lunatic.launcher.model.WeatherForcast import bums.lunatic.launcher.model.WeatherInfoManager import bums.lunatic.launcher.utils.BLog @@ -53,7 +54,7 @@ class OpenWeatherGetter(context: Context, workerParams: WorkerParameters) : Base .create() .getForecast( // weatherApi ver = VER_WEATHERAPI, - key = KEY_WEATHERAPI, + key = PrefString.weatherApiKey.get(), q = "$latitude,$longitude", days = (System.currentTimeMillis() % 5L).toInt().toString() )?.execute()?.let { response -> diff --git a/app/src/main/res/layout/item_rec_hourly_dress.xml b/app/src/main/res/layout/item_rec_hourly_dress.xml index 3fda746..4e24fd4 100644 --- a/app/src/main/res/layout/item_rec_hourly_dress.xml +++ b/app/src/main/res/layout/item_rec_hourly_dress.xml @@ -3,51 +3,70 @@ - + android:layout_height="90dp" + android:gravity="center"> + - + \ No newline at end of file diff --git a/app/src/main/res/layout/launcher_home.xml b/app/src/main/res/layout/launcher_home.xml index 189fd54..feaea6d 100644 --- a/app/src/main/res/layout/launcher_home.xml +++ b/app/src/main/res/layout/launcher_home.xml @@ -13,6 +13,7 @@ android:layout_height="wrap_content" android:layout_margin="@dimen/default_layout_margin" android:indeterminate="false" + android:visibility="gone" style="@style/normal" android:text="빠떼뤼 ~> 0%" app:layout_constraintRight_toRightOf="parent" @@ -25,6 +26,7 @@ android:background="@drawable/base_bg" android:text="this is init sentence" android:id="@+id/time" + android:visibility="gone" android:gravity="center" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" diff --git a/app/src/main/res/layout/settings_activity.xml b/app/src/main/res/layout/settings_activity.xml index f552cee..24699e4 100644 --- a/app/src/main/res/layout/settings_activity.xml +++ b/app/src/main/res/layout/settings_activity.xml @@ -45,7 +45,7 @@ style="@style/Widget.Material3.Button.ElevatedButton" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="@string/time_date" + android:text="Display Info" android:textAllCaps="true" android:textStyle="bold" /> diff --git a/app/src/main/res/layout/settings_time_date.xml b/app/src/main/res/layout/settings_time_date.xml index bc7aaf7..0d0f9d4 100644 --- a/app/src/main/res/layout/settings_time_date.xml +++ b/app/src/main/res/layout/settings_time_date.xml @@ -6,11 +6,20 @@ android:layout_height="wrap_content" android:padding="@dimen/twelve"> + + diff --git a/app/src/main/res/layout/settings_weather.xml b/app/src/main/res/layout/settings_weather.xml index 918a403..937558d 100644 --- a/app/src/main/res/layout/settings_weather.xml +++ b/app/src/main/res/layout/settings_weather.xml @@ -52,7 +52,7 @@ android:id="@+id/weatherTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="재생중인 곡" + android:text="날씨 보기" android:textSize="@dimen/normalText" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" diff --git a/app/src/main/res/layout/weather_book.xml b/app/src/main/res/layout/weather_book.xml index 2dc8535..8b23a0b 100644 --- a/app/src/main/res/layout/weather_book.xml +++ b/app/src/main/res/layout/weather_book.xml @@ -8,7 +8,7 @@ + android:layout_height="120dp">