Skip to content

Commit

Permalink
#187 Add webview to koin for business
Browse files Browse the repository at this point in the history
  • Loading branch information
wateralsie committed Apr 9, 2024
1 parent 939d89f commit ed8245b
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -59,43 +66,43 @@ 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<View>(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()
}

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<TextView>(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()
Expand All @@ -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)
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() // 알림창 띄우기
}
Expand All @@ -398,8 +410,8 @@ abstract class KoinNavigationDrawerActivity : ActivityBase(),
get() {
val s = text.toString()
val styledText = HtmlCompat.fromHtml(
"<font color='#f7941e'>$s</font>",
HtmlCompat.FROM_HTML_MODE_LEGACY
"<font color='#f7941e'>$s</font>",
HtmlCompat.FROM_HTML_MODE_LEGACY
)
setText(styledText, TextView.BufferType.SPANNABLE) //#f7941e
return this
Expand Down

0 comments on commit ed8245b

Please sign in to comment.