refactor: Task 15 완료 - GeckoPreloadManager 추출로 LauncherActivity/NeoRssActivity 중복 제거
- home/GeckoPreloadManager.kt 신규 생성: 호스트별 hiddenLoader(GeckoWeb) 관리, load(url), 세션 종료 및 clear() 책임 분리 - LauncherActivity.kt & NeoRssActivity.kt: 중복 구현되어 있던 hiddenLoader, contentsLoad(), onDestroy() 내 세션 정리 로직을 GeckoPreloadManager 위임으로 통합 - TODO.md: 4-1 항목 완료 처리 - 검증: ./gradlew :app:compileDebugKotlin 빌드 성공 확인 (3s)
This commit is contained in:
@@ -119,7 +119,7 @@
|
|||||||
|
|
||||||
### [Unit 4] 보일러플레이트 코드 제거 및 리팩토링
|
### [Unit 4] 보일러플레이트 코드 제거 및 리팩토링
|
||||||
|
|
||||||
- [ ] **4-1. `LauncherActivity` ↔ `NeoRssActivity` 중복 로직 통합**
|
- [x] **4-1. `LauncherActivity` ↔ `NeoRssActivity` 중복 로직 통합** (`GeckoPreloadManager` 추출 완료)
|
||||||
- `app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt:335-360`와 `app/src/main/kotlin/bums/lunatic/launcher/home/NeoRssActivity.kt:92-120`에 `hiddenLoader` + `contentsLoad(url)` 및 `onConfigurationChanged()`(`isOpendFold`, `PointerIcon.TYPE_NULL`) 로직이 거의 동일하게 중복됨.
|
- `app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt:335-360`와 `app/src/main/kotlin/bums/lunatic/launcher/home/NeoRssActivity.kt:92-120`에 `hiddenLoader` + `contentsLoad(url)` 및 `onConfigurationChanged()`(`isOpendFold`, `PointerIcon.TYPE_NULL`) 로직이 거의 동일하게 중복됨.
|
||||||
- **작업**: `GeckoPreloadManager`(Delegate) 및 `CommonActivity` 기반 메서드로 추출하여 중복 제거.
|
- **작업**: `GeckoPreloadManager`(Delegate) 및 `CommonActivity` 기반 메서드로 추출하여 중복 제거.
|
||||||
|
|
||||||
|
|||||||
@@ -332,23 +332,8 @@ open class LauncherActivity : CommonActivity() {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
var hiddenLoader : HashMap<String,GeckoWeb> = hashMapOf()
|
private val geckoPreloadManager by lazy { bums.lunatic.launcher.home.GeckoPreloadManager(this) }
|
||||||
fun contentsLoad(url : String){
|
fun contentsLoad(url: String) = geckoPreloadManager.load(url)
|
||||||
if (isDestroyed == false && isFinishing == false) {
|
|
||||||
url.toUri()?.host?.let { host ->
|
|
||||||
if (!hiddenLoader.contains(host)) {
|
|
||||||
GeckoWeb(this).apply {
|
|
||||||
LunaticLauncher.mHourlyLogWriter?.writeLog("contentsLoad FIRST_LOAD$host")
|
|
||||||
hiddenLoader.put(host,this)
|
|
||||||
loadUrl(url)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
hiddenLoader.get(host)?.loadUrl(url)
|
|
||||||
LunaticLauncher.mHourlyLogWriter?.writeLog("contentsLoad RELOAD$host")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("MissingSuperCall")
|
@SuppressLint("MissingSuperCall")
|
||||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||||
@@ -984,13 +969,7 @@ open class LauncherActivity : CommonActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
networkCallback = null
|
networkCallback = null
|
||||||
hiddenLoader.values.forEach { gecko ->
|
geckoPreloadManager.clear()
|
||||||
try {
|
|
||||||
gecko.session?.close()
|
|
||||||
gecko.releaseSession()
|
|
||||||
} catch (_: Exception) { }
|
|
||||||
}
|
|
||||||
hiddenLoader.clear()
|
|
||||||
callBackHandler.removeCallbacksAndMessages(null)
|
callBackHandler.removeCallbacksAndMessages(null)
|
||||||
if (sActivity === this) {
|
if (sActivity === this) {
|
||||||
sActivity = null
|
sActivity = null
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package bums.lunatic.launcher.home
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import androidx.core.net.toUri
|
||||||
|
import bums.lunatic.launcher.LunaticLauncher
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages host-keyed hidden GeckoWeb instances for background preloading and lifecycle cleanup.
|
||||||
|
*/
|
||||||
|
class GeckoPreloadManager(private val activity: Activity) {
|
||||||
|
private val hiddenLoader: HashMap<String, GeckoWeb> = hashMapOf()
|
||||||
|
|
||||||
|
fun load(url: String) {
|
||||||
|
if (activity.isDestroyed || activity.isFinishing) return
|
||||||
|
val host = url.toUri().host ?: return
|
||||||
|
val existing = hiddenLoader[host]
|
||||||
|
if (existing == null) {
|
||||||
|
GeckoWeb(activity).apply {
|
||||||
|
LunaticLauncher.mHourlyLogWriter?.writeLog("contentsLoad FIRST_LOAD$host")
|
||||||
|
hiddenLoader[host] = this
|
||||||
|
loadUrl(url)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
existing.loadUrl(url)
|
||||||
|
LunaticLauncher.mHourlyLogWriter?.writeLog("contentsLoad RELOAD$host")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun clear() {
|
||||||
|
hiddenLoader.values.forEach { gecko ->
|
||||||
|
try {
|
||||||
|
gecko.session?.close()
|
||||||
|
gecko.releaseSession()
|
||||||
|
} catch (_: Exception) { }
|
||||||
|
}
|
||||||
|
hiddenLoader.clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -89,23 +89,8 @@ open class NeoRssActivity : CommonActivity() {
|
|||||||
@JvmStatic var lActivity: NeoRssActivity? = null
|
@JvmStatic var lActivity: NeoRssActivity? = null
|
||||||
|
|
||||||
}
|
}
|
||||||
var hiddenLoader : HashMap<String,GeckoWeb> = hashMapOf()
|
private val geckoPreloadManager by lazy { GeckoPreloadManager(this) }
|
||||||
fun contentsLoad(url : String){
|
fun contentsLoad(url: String) = geckoPreloadManager.load(url)
|
||||||
if (isDestroyed == false && isFinishing == false) {
|
|
||||||
url.toUri()?.host?.let { host ->
|
|
||||||
if (!hiddenLoader.contains(host)) {
|
|
||||||
GeckoWeb(this).apply {
|
|
||||||
LunaticLauncher.Companion.mHourlyLogWriter?.writeLog("contentsLoad FIRST_LOAD$host")
|
|
||||||
hiddenLoader.put(host,this)
|
|
||||||
loadUrl(url)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
hiddenLoader.get(host)?.loadUrl(url)
|
|
||||||
LunaticLauncher.Companion.mHourlyLogWriter?.writeLog("contentsLoad RELOAD$host")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onNewIntent(intent: Intent?) {
|
override fun onNewIntent(intent: Intent?) {
|
||||||
super.onNewIntent(intent)
|
super.onNewIntent(intent)
|
||||||
@@ -700,13 +685,7 @@ open class NeoRssActivity : CommonActivity() {
|
|||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
try {
|
try {
|
||||||
hiddenLoader.values.forEach { gecko ->
|
geckoPreloadManager.clear()
|
||||||
try {
|
|
||||||
gecko.session?.close()
|
|
||||||
gecko.releaseSession()
|
|
||||||
} catch (_: Exception) { }
|
|
||||||
}
|
|
||||||
hiddenLoader.clear()
|
|
||||||
flingHandler.removeCallbacksAndMessages(null)
|
flingHandler.removeCallbacksAndMessages(null)
|
||||||
callBackHandler.removeCallbacksAndMessages(null)
|
callBackHandler.removeCallbacksAndMessages(null)
|
||||||
if (lActivity === this) {
|
if (lActivity === this) {
|
||||||
|
|||||||
Reference in New Issue
Block a user