Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#191/feature/jsp/navigation #192

Merged
merged 7 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 26 additions & 15 deletions app/src/main/java/com/android/mediproject/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.android.mediproject

import android.os.Bundle
import android.view.ViewGroup.MarginLayoutParams
import android.view.ViewTreeObserver
import androidx.activity.viewModels
Expand All @@ -12,6 +13,7 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.NavigationUiSaveStateControl
import androidx.navigation.ui.setupWithNavController
import com.android.mediproject.core.common.uiutil.LayoutController
import com.android.mediproject.core.common.uiutil.SystemBarColorAnalyzer
Expand All @@ -33,12 +35,13 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>(ActivityMa
@Inject lateinit var layoutController: LayoutController
@Inject lateinit var systemBarController: SystemBarController
@Inject lateinit var internetNetworkListener: InternetNetworkListener

private val systemBarColorAnalyzer = SystemBarColorAnalyzer
@Inject lateinit var systemBarColorAnalyzer: SystemBarColorAnalyzer

override val activityViewModel: MainViewModel by viewModels()
private lateinit var navController: NavController


@OptIn(NavigationUiSaveStateControl::class)
override fun afterBinding() {
systemBarController.init(this, window, this)
systemBarColorAnalyzer.init(this, systemBarController, lifecycle)
Expand All @@ -51,18 +54,7 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>(ActivityMa
}

binding.apply {
val navHostFragment = supportFragmentManager.findFragmentById(R.id.fragmentContainerView) as NavHostFragment
navController = navHostFragment.navController

bottomNav.apply {
itemIconTintList = null
setupWithNavController(navController)
background = null
menu.getItem(2).isEnabled = false
}
R.array.hideBottomNavDestinationIds
setDestinationListener()

initNav()
viewModel = activityViewModel.apply {
repeatOnStarted { eventFlow.collect { handleEvent(it) } }
}
Expand Down Expand Up @@ -95,9 +87,23 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>(ActivityMa
installSplashScreen()
}

private fun initNav() {
binding.apply {
val navHostFragment = supportFragmentManager.findFragmentById(fragmentContainerView.id) as NavHostFragment
navController = navHostFragment.navController

bottomNav.apply {
itemIconTintList = null
background = null
menu.getItem(2).isEnabled = false
bottomNav.setupWithNavController(navController)
}
setDestinationListener()
}
}

pknujsp marked this conversation as resolved.
Show resolved Hide resolved
private fun setDestinationListener() {
val hideBottomNavDestinationIds = activityViewModel.getHideBottomNavDestinationIds(resources)

navController.addOnDestinationChangedListener { _, destination, arg ->
log(arg.toString())
bottomVisible(destination.id !in hideBottomNavDestinationIds)
Expand Down Expand Up @@ -142,4 +148,9 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>(ActivityMa
}
}

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putInt(activityViewModel.lastSelectedBottomNavFragmentIdKey, binding.bottomNav.selectedItemId)
}

}
22 changes: 17 additions & 5 deletions app/src/main/java/com/android/mediproject/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.android.mediproject
import MutableEventFlow
import android.content.res.Resources
import androidx.annotation.ArrayRes
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import asEventFlow
import com.android.mediproject.core.domain.sign.GetAccountStateUseCase
Expand All @@ -14,10 +15,26 @@ import javax.inject.Inject
@HiltViewModel
class MainViewModel @Inject constructor(
private val getAccountStateUseCase: GetAccountStateUseCase,
private val savedStateHandle: SavedStateHandle,
) : BaseViewModel() {
val lastSelectedBottomNavFragmentIdKey = "lastSelectedBottomNavFragmentId"

private val _eventFlow = MutableEventFlow<MainEvent>()
val eventFlow = _eventFlow.asEventFlow()

private val _selectedBottomNavFragmentId = MutableEventFlow<Int>(replay = 1)
val selectedBottomNavFragmentId = _selectedBottomNavFragmentId.asEventFlow()

init {
viewModelScope.launch {
getAccountStateUseCase.loadAccountState()
if (savedStateHandle.keys().isNotEmpty()) {
savedStateHandle.get<Int>(lastSelectedBottomNavFragmentIdKey)?.let {
_selectedBottomNavFragmentId.emit(it)
}
}
}
}

fun getHideBottomNavDestinationIds(resources: Resources): Set<Int> = resources.getArray(R.array.hideBottomNavDestinationIds)

Expand All @@ -36,11 +53,6 @@ class MainViewModel @Inject constructor(
fun event(event: MainEvent) = viewModelScope.launch { _eventFlow.emit(event) }
fun aicamera() = event(MainEvent.AICamera())

init {
viewModelScope.launch {
getAccountStateUseCase.loadAccountState()
}
}

sealed class MainEvent {
data class AICamera(val unit: Unit? = null) : MainEvent()
pknujsp marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/main_nav" />
app:navGraph="@navigation/main_nav"
app:defaultNavHost="true" />

<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottomAppBar"
Expand Down Expand Up @@ -78,4 +78,4 @@
</androidx.coordinatorlayout.widget.CoordinatorLayout>

</FrameLayout>
</layout>
</layout>
2 changes: 1 addition & 1 deletion app/src/main/res/menu/main_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
android:id="@id/etc_nav"
android:title="@string/etc"
android:icon="@drawable/menu_selector_etc_color" />
</menu>
</menu>
3 changes: 1 addition & 2 deletions app/src/main/res/navigation/main_nav.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
android:id="@+id/main_nav"
app:startDestination="@id/intro_nav">


<include app:graph="@navigation/mypage_nav" />
<include app:graph="@navigation/etc_nav" />
<include app:graph="@navigation/intro_nav" />
Expand All @@ -16,4 +15,4 @@
<include app:graph="@navigation/medicine_details_nav" />
<include app:graph="@navigation/search_medicines_nav" />

</navigation>
</navigation>
1 change: 0 additions & 1 deletion core/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ dependencies {
implementation(libs.kotlinx.coroutines.android)
implementation(project(":core:model"))
implementation(libs.kotlinx.serialization.json)
//implementation(libs.kotlinx.datetime)
implementation(libs.kotlin.reflection)
implementation(libs.bundles.glides)
implementation(libs.lottie)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import android.text.style.StyleSpan
import android.text.style.UnderlineSpan
import androidx.core.text.toSpanned
import com.android.mediproject.core.common.R
import com.android.mediproject.core.model.medicine.medicinedetailinfo.MedicineDetailInfo
import com.android.mediproject.core.model.remote.granule.GranuleIdentificationInfoDto
import com.android.mediproject.core.model.medicine.medicinedetailinfo.MedicineDetatilInfoDto
import com.android.mediproject.core.model.util.XMLParsedResult
import java.lang.ref.WeakReference
import javax.inject.Inject
Expand Down Expand Up @@ -75,11 +75,11 @@ class MedicineInfoMapper @Inject constructor() {
/**
* ์˜์•ฝํ’ˆ ๊ธฐ๋ณธ ์ •๋ณด ๋ฐ์ดํ„ฐ๋ฅผ UI์— ๋งž๊ฒŒ ๋ณ€ํ™˜
*/
fun toMedicineInfo(medicineDetatilInfoDto: MedicineDetatilInfoDto): Spanned {
fun toMedicineInfo(medicineDetailInfo: MedicineDetailInfo): Spanned {
val stringBuilder = WeakReference(StringBuilder())

return stringBuilder.get()?.let { builder ->
with(medicineDetatilInfoDto) {
with(medicineDetailInfo) {
builder.append("<p><b>์˜์•ฝํ’ˆ ์ด๋ฆ„:</b> $itemName</p>").append("<p><b>์˜์•ฝํ’ˆ ์˜๋ฌธ ์ด๋ฆ„:</b> $itemEnglishName</p>")
.append("<p><b>์˜์•ฝํ’ˆ ์‹œํ€€์Šค ๋ฒˆํ˜ธ:</b> $itemSequence</p>").append("<p><b>์˜์•ฝํ’ˆ ํ—ˆ๊ฐ€ ๋‚ ์งœ:</b> $itemPermitDate</p>")
.append("<p><b>์ œ์กฐ์‚ฌ ์ด๋ฆ„:</b> $entpName</p>").append("<p><b>์ œ์กฐ์‚ฌ ์˜๋ฌธ ์ด๋ฆ„:</b> $entpEnglishName</p>")
Expand Down Expand Up @@ -188,13 +188,15 @@ class MedicineInfoMapper @Inject constructor() {

fun initHeaderSpan(context: Context, text: String): SpannableStringBuilder {
return SpannableStringBuilder(text).apply {
val underline1Idx = text.indexOf(context.getString(R.string.highlightWord1)) to text.indexOf(context.getString(R.string.highlightWord1)) + 2
val underline1Idx =
text.indexOf(context.getString(R.string.highlightWord1)) to text.indexOf(context.getString(R.string.highlightWord1)) + 2

setSpan(UnderlineSpan(), underline1Idx.first, underline1Idx.second, Spanned.SPAN_INCLUSIVE_INCLUSIVE)
setSpan(StyleSpan(Typeface.BOLD), underline1Idx.first, underline1Idx.second, Spanned.SPAN_INCLUSIVE_INCLUSIVE)
setSpan(RelativeSizeSpan(TEXT_SIZE_PERCENT), underline1Idx.first, underline1Idx.second, Spanned.SPAN_INCLUSIVE_INCLUSIVE)

val underline2Idx = text.indexOf(context.getString(R.string.highlightWord2)) to text.indexOf(context.getString(R.string.highlightWord2)) + 2
val underline2Idx =
text.indexOf(context.getString(R.string.highlightWord2)) to text.indexOf(context.getString(R.string.highlightWord2)) + 2

setSpan(UnderlineSpan(), underline2Idx.first, underline2Idx.second, Spanned.SPAN_INCLUSIVE_INCLUSIVE)
setSpan(StyleSpan(Typeface.BOLD), underline2Idx.first, underline2Idx.second, Spanned.SPAN_INCLUSIVE_INCLUSIVE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ import kotlinx.coroutines.cancel
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.plus
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withContext
import javax.inject.Inject
import javax.inject.Singleton
import kotlin.coroutines.resume
import kotlin.properties.Delegates

@Singleton
@SuppressLint("InternalInsetResource", "DiscouragedApi")
object SystemBarColorAnalyzer {
class SystemBarColorAnalyzer @Inject constructor() {
private val waitLock = Mutex()
private var waiting: Job? = null
private val coroutineScope = MainScope() + CoroutineName("SystemBarColorAnalyzer")
Expand All @@ -48,9 +52,21 @@ object SystemBarColorAnalyzer {
private val statusBarHeight = resource.getDimensionPixelSize(resource.getIdentifier("status_bar_height", "dimen", "android"))
private val navigationBarHeight = resource.getDimensionPixelSize(resource.getIdentifier("navigation_bar_height", "dimen", "android"))

private const val criteriaColor = 140
private val criteriaColor = 140
private var systemBarController: SystemBarController? = null

private val _statusBarColor = MutableSharedFlow<SystemBarStyler.SystemBarColor>(
onBufferOverflow = BufferOverflow.DROP_OLDEST, replay = 1,
extraBufferCapacity = 5,
)
val statusBarColor = _statusBarColor.asSharedFlow()

private val _navigationBarColor = MutableSharedFlow<SystemBarStyler.SystemBarColor>(
onBufferOverflow = BufferOverflow.DROP_OLDEST, replay = 1,
extraBufferCapacity = 5,
)
val navigationBarColor = _navigationBarColor.asSharedFlow()

init {
coroutineScope.launch(Dispatchers.Default) {
onChangedFragmentFlow.collect {
Expand Down Expand Up @@ -83,7 +99,8 @@ object SystemBarColorAnalyzer {
statusBarBitmap.recycle()
navigationBarBitmap.recycle()

Log.d("wap", "${System.currentTimeMillis() - start}MS, status : $statusBarColor, nav : $navigationBarColor")
_statusBarColor.emit(statusBarColor)
_navigationBarColor.emit(navigationBarColor)

return statusBarColor to navigationBarColor
}
Expand Down Expand Up @@ -145,7 +162,7 @@ object SystemBarColorAnalyzer {
waitLock.withLock {
if (waiting?.isActive == true) waiting?.cancel()
waiting = launch(Dispatchers.Default) {
delay(70)
delay(80)
pknujsp marked this conversation as resolved.
Show resolved Hide resolved
onChangedFragmentFlow.emit(Unit)
}
}
Expand Down
Loading