From ed8245b3750133f9603dffbe79d8e6bf3f147e63 Mon Sep 17 00:00:00 2001 From: wateralsie Date: Tue, 9 Apr 2024 10:58:03 +0900 Subject: [PATCH] #187 Add webview to koin for business --- .../koin/core/activity/WebViewActivity.kt | 2 +- .../KoinNavigationDrawerActivity.kt | 132 ++++++++++-------- 2 files changed, 73 insertions(+), 61 deletions(-) diff --git a/core/src/main/java/in/koreatech/koin/core/activity/WebViewActivity.kt b/core/src/main/java/in/koreatech/koin/core/activity/WebViewActivity.kt index 58505b015..536426432 100644 --- a/core/src/main/java/in/koreatech/koin/core/activity/WebViewActivity.kt +++ b/core/src/main/java/in/koreatech/koin/core/activity/WebViewActivity.kt @@ -18,7 +18,7 @@ class WebViewActivity : ActivityBase(R.layout.activity_webview) { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val title = intent.getStringExtra("title") + val title = intent.getStringExtra("title") ?: "" val url = intent.getStringExtra("url") init(title, url) } diff --git a/koin/src/main/java/in/koreatech/koin/ui/navigation/KoinNavigationDrawerActivity.kt b/koin/src/main/java/in/koreatech/koin/ui/navigation/KoinNavigationDrawerActivity.kt index 97435ac2f..e74a0c573 100644 --- a/koin/src/main/java/in/koreatech/koin/ui/navigation/KoinNavigationDrawerActivity.kt +++ b/koin/src/main/java/in/koreatech/koin/ui/navigation/KoinNavigationDrawerActivity.kt @@ -1,21 +1,5 @@ package `in`.koreatech.koin.ui.navigation -import `in`.koreatech.koin.R -import `in`.koreatech.koin.core.activity.ActivityBase -import `in`.koreatech.koin.core.activity.WebViewActivity -import `in`.koreatech.koin.core.toast.ToastUtil -import `in`.koreatech.koin.ui.bus.BusActivity -import `in`.koreatech.koin.ui.dining.DiningActivity -import `in`.koreatech.koin.ui.land.LandActivity -import `in`.koreatech.koin.ui.login.LoginActivity -import `in`.koreatech.koin.ui.main.activity.MainActivity -import `in`.koreatech.koin.ui.navigation.state.MenuState -import `in`.koreatech.koin.ui.navigation.viewmodel.KoinNavigationDrawerViewModel -import `in`.koreatech.koin.ui.store.activity.StoreActivity -import `in`.koreatech.koin.ui.timetable.TimetableActivity -import `in`.koreatech.koin.ui.timetable.TimetableAnonymousActivity -import `in`.koreatech.koin.ui.userinfo.UserInfoActivity -import `in`.koreatech.koin.util.ext.* import android.content.Intent import android.graphics.Typeface import android.net.Uri @@ -33,13 +17,36 @@ import androidx.drawerlayout.widget.DrawerLayout import com.google.android.material.navigation.NavigationView import dagger.hilt.android.AndroidEntryPoint import `in`.koreatech.koin.BuildConfig +import `in`.koreatech.koin.R +import `in`.koreatech.koin.core.activity.ActivityBase +import `in`.koreatech.koin.core.activity.WebViewActivity +import `in`.koreatech.koin.core.toast.ToastUtil import `in`.koreatech.koin.data.constant.URLConstant import `in`.koreatech.koin.domain.model.user.User +import `in`.koreatech.koin.ui.bus.BusActivity +import `in`.koreatech.koin.ui.dining.DiningActivity +import `in`.koreatech.koin.ui.land.LandActivity +import `in`.koreatech.koin.ui.login.LoginActivity +import `in`.koreatech.koin.ui.main.activity.MainActivity import `in`.koreatech.koin.ui.navigation.contract.GotoAskFormContract +import `in`.koreatech.koin.ui.navigation.state.MenuState +import `in`.koreatech.koin.ui.navigation.viewmodel.KoinNavigationDrawerViewModel +import `in`.koreatech.koin.ui.store.activity.StoreActivity +import `in`.koreatech.koin.ui.timetable.TimetableActivity +import `in`.koreatech.koin.ui.timetable.TimetableAnonymousActivity +import `in`.koreatech.koin.ui.userinfo.UserInfoActivity +import `in`.koreatech.koin.util.ext.addDrawerListener +import `in`.koreatech.koin.util.ext.blueStatusBar +import `in`.koreatech.koin.util.ext.closeDrawer +import `in`.koreatech.koin.util.ext.isDrawerOpened +import `in`.koreatech.koin.util.ext.observeLiveData +import `in`.koreatech.koin.util.ext.toggleDrawer +import `in`.koreatech.koin.util.ext.whiteStatusBar +import `in`.koreatech.koin.util.ext.windowWidth @AndroidEntryPoint abstract class KoinNavigationDrawerActivity : ActivityBase(), - NavigationView.OnNavigationItemSelectedListener { + NavigationView.OnNavigationItemSelectedListener { protected abstract val menuState: MenuState val drawerLayoutId get() = R.id.drawer_layout @@ -59,21 +66,21 @@ abstract class KoinNavigationDrawerActivity : ActivityBase(), private val menus by lazy { listOf( - R.id.navi_item_store, - R.id.navi_item_bus, R.id.navi_item_dining, - R.id.navi_item_timetable, R.id.navi_item_land, - R.id.navi_item_owner + R.id.navi_item_store, + R.id.navi_item_bus, R.id.navi_item_dining, + R.id.navi_item_timetable, R.id.navi_item_land, + R.id.navi_item_owner ).map { findViewById(it) }.zip( - listOf( - MenuState.Store, - MenuState.Bus, - MenuState.Dining, - MenuState.Timetable, - MenuState.Land, - MenuState.Owner - ) + listOf( + MenuState.Store, + MenuState.Bus, + MenuState.Dining, + MenuState.Timetable, + MenuState.Land, + MenuState.Owner + ) ) { view, state -> state to view }.toMap() @@ -81,21 +88,21 @@ abstract class KoinNavigationDrawerActivity : ActivityBase(), private val menuTextViews by lazy { listOf( - R.id.navi_item_store_textview, - R.id.navi_item_bus_textview, R.id.navi_item_dining_textview, - R.id.navi_item_timetable_textview, R.id.navi_item_land_textview + R.id.navi_item_store_textview, + R.id.navi_item_bus_textview, R.id.navi_item_dining_textview, + R.id.navi_item_timetable_textview, R.id.navi_item_land_textview ).map { findViewById(it).apply { changeMenuFont(this) } }.zip( - listOf( - MenuState.Store, - MenuState.Bus, - MenuState.Dining, - MenuState.Timetable, - MenuState.Land - ) + listOf( + MenuState.Store, + MenuState.Bus, + MenuState.Dining, + MenuState.Timetable, + MenuState.Land + ) ) { view, state -> state to view }.toMap() @@ -112,10 +119,15 @@ abstract class KoinNavigationDrawerActivity : ActivityBase(), menus.forEach { (state, view) -> view.setOnClickListener { when (state) { - MenuState.Owner -> startActivity(Intent(Intent.ACTION_VIEW, Uri.parse( - if (BuildConfig.IS_DEBUG) URLConstant.OWNER_URL_STAGE - else URLConstant.OWNER_URL_PRODUCTION - ))) + MenuState.Owner -> { + Intent(this, WebViewActivity::class.java).apply { + putExtra( + "url", + if (BuildConfig.IS_DEBUG) URLConstant.OWNER_URL_STAGE + else URLConstant.OWNER_URL_PRODUCTION + ) + }.run(::startActivity) + } else -> { koinNavigationDrawerViewModel.selectMenu(state) @@ -152,7 +164,7 @@ abstract class KoinNavigationDrawerActivity : ActivityBase(), super.onAttachedToWindow() leftNavigationView.layoutParams = - leftNavigationView.layoutParams.apply { width = windowWidth } + leftNavigationView.layoutParams.apply { width = windowWidth } } override fun onBackPressed() { @@ -359,20 +371,20 @@ abstract class KoinNavigationDrawerActivity : ActivityBase(), fun showLoginRequestDialog() { val builder = AlertDialog.Builder(this) builder.setTitle("회원 전용 서비스") - .setMessage("로그인이 필요한 서비스입니다.\n로그인 하시겠습니까?") - .setCancelable(false) - .setPositiveButton("확인") { dialog, _ -> - val intent = Intent( - this, - LoginActivity::class.java - ) - intent.putExtra("FIRST_LOGIN", false) - startActivity(intent) - overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.fade_out) - } - .setNegativeButton("취소") { dialog, _ -> - dialog.cancel() - } + .setMessage("로그인이 필요한 서비스입니다.\n로그인 하시겠습니까?") + .setCancelable(false) + .setPositiveButton("확인") { dialog, _ -> + val intent = Intent( + this, + LoginActivity::class.java + ) + intent.putExtra("FIRST_LOGIN", false) + startActivity(intent) + overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.fade_out) + } + .setNegativeButton("취소") { dialog, _ -> + dialog.cancel() + } val dialog = builder.create() // 알림창 객체 생성 dialog.show() // 알림창 띄우기 } @@ -398,8 +410,8 @@ abstract class KoinNavigationDrawerActivity : ActivityBase(), get() { val s = text.toString() val styledText = HtmlCompat.fromHtml( - "$s", - HtmlCompat.FROM_HTML_MODE_LEGACY + "$s", + HtmlCompat.FROM_HTML_MODE_LEGACY ) setText(styledText, TextView.BufferType.SPANNABLE) //#f7941e return this