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

로띠 스플래시 액티비티 추가 #231

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ dependencies {
implementation(libs.core.ktx)
implementation(libs.kotlin.android)
implementation(libs.kotlin.core)
implementation(libs.androidx.splash)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.espresso.core)
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@
tools:targetApi="31">

<activity
android:name=".MainActivity"
android:name=".splash.SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

Expand Down
41 changes: 14 additions & 27 deletions app/src/main/java/com/mashup/dorabangs/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,14 @@ import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.compose.runtime.collectAsState
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import com.mashup.dorabangs.core.designsystem.theme.DorabangsTheme
import com.mashup.dorabangs.navigation.DoraApp
import com.mashup.dorabangs.splash.FirstEntryScreen
import com.mashup.dorabangs.splash.SplashViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : ComponentActivity() {

private val splashViewModel: SplashViewModel by viewModels()
private val overlayPermissionLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (!Settings.canDrawOverlays(this)) {
Expand All @@ -36,32 +31,24 @@ class MainActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
checkPermission()

val userId = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
splashViewModel.checkUserToken(userId)

val firstEntryScreen = intent.getStringExtra("firstEntry")
val url = intent.data?.path?.substring(1).orEmpty()

installSplashScreen().apply {
setKeepOnScreenCondition {
(splashViewModel.isSplashShow.value || splashViewModel.firstEntryScreen.value == FirstEntryScreen.Splash) &&
url.isBlank()
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기 기존에 url받아와서 그냥 비어있는지만 체크하던데,,무슨 기능인지 아는사람?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

나는 몰라!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

스플래시 만든 사람이 모르면 우리도 몰라 !

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ddyeon @Ahn-seokjoo
image
억울하오 억울하오

}

setContent {
val firstEntryScreen = splashViewModel.firstEntryScreen.collectAsState()
if (firstEntryScreen.value != FirstEntryScreen.Splash) {
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
firstEntryScreen?.let {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 firstEntryScreen null인 케이스가 있음? 있다면 빈 화면만 나올 것 같은뎅

if (firstEntryScreen != FirstEntryScreen.Splash.name) {
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager

DorabangsTheme {
DoraApp(
isFirstEntry = firstEntryScreen.value == FirstEntryScreen.Onboarding,
hideKeyboardAction = {
currentFocus?.let {
imm?.hideSoftInputFromWindow(it.windowToken, 0)
}
},
)
DorabangsTheme {
DoraApp(
isFirstEntry = firstEntryScreen == FirstEntryScreen.Onboarding.name,
hideKeyboardAction = {
currentFocus?.let {
imm?.hideSoftInputFromWindow(it.windowToken, 0)
}
},
)
}
}
}
}
Expand Down
39 changes: 39 additions & 0 deletions app/src/main/java/com/mashup/dorabangs/splash/SplashActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.mashup.dorabangs.splash

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.provider.Settings
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.runtime.collectAsState
import com.mashup.dorabangs.MainActivity
import dagger.hilt.android.AndroidEntryPoint

@SuppressLint("CustomSplashScreen")
@AndroidEntryPoint
class SplashActivity : ComponentActivity() {
private val splashViewModel: SplashViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val userId = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
splashViewModel.checkUserToken(userId)

val url = intent.data?.path?.substring(1).orEmpty()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

쓰는데가 없는뎅 ??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

웅 그래서 지우려고햇는데,, 기존에 main에 있떤 코드여서 위에서 물어본건데 아무도 모르면
지웁니다?


setContent {
SplashScreen()

val firstEntryScreen = splashViewModel.firstEntryScreen.collectAsState()
if (firstEntryScreen.value != FirstEntryScreen.Splash) {
val intent = Intent(this, MainActivity::class.java)
intent.putExtra("firstEntry", firstEntryScreen.value.name)
startActivity(intent)
finish()
}
}
}
}
21 changes: 21 additions & 0 deletions app/src/main/java/com/mashup/dorabangs/splash/SplashScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.mashup.dorabangs.splash

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.mashup.dorabangs.core.designsystem.component.util.LottieLoader
import com.mashup.dorabangs.core.designsystem.R as coreR

@Composable
fun SplashScreen() {
Box(modifier = Modifier.fillMaxSize()) {
LottieLoader(
lottieRes = coreR.raw.splash,
modifier = Modifier.align(Alignment.Center).size(126.dp),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import com.mashup.dorabangs.domain.usecase.user.GetUserAccessTokenUseCase
import com.mashup.dorabangs.domain.usecase.user.RegisterUserUseCase
import com.mashup.dorabangs.domain.usecase.user.SetUserAccessTokenUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.withTimeout
import javax.inject.Inject

@HiltViewModel
Expand All @@ -40,19 +40,18 @@ class SplashViewModel @Inject constructor(
token
}.orEmpty()

withTimeout(SPLASH_SCREEN_TIME) {
if (userAccessToken.isNotEmpty()) {
splashShowFlow.value = false
_firstEntryScreen.value = if (getIsFirstEntryUseCase().firstOrNull() != false) FirstEntryScreen.Onboarding else FirstEntryScreen.Home
} else {
// Todo :: 유저 토큰 가져오기 실패에 대한 처리 해줘야함 (Like 토스트 메시지)
}
if (userAccessToken.isNotEmpty()) {
delay(SPLASH_SCREEN_TIME)
splashShowFlow.value = false
_firstEntryScreen.value = if (getIsFirstEntryUseCase().firstOrNull() != false) FirstEntryScreen.Onboarding else FirstEntryScreen.Home
} else {
// Todo :: 유저 토큰 가져오기 실패에 대한 처리 해줘야함 (Like 토스트 메시지)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거도 같이할 생각 없나~

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ㅋㅋ이건 호현오빠한테 토스~

}
}
}

companion object {
private const val SPLASH_SCREEN_TIME = 1000L
private const val SPLASH_SCREEN_TIME = 3000L
}
}

Expand Down
1 change: 1 addition & 0 deletions core/designsystem/src/main/res/raw/splash.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.mashup.dorabangs.domain.model.Folder
import com.mashup.dorabangs.domain.utils.isValidUrl

data class HomeState(
val isLoading: Boolean = false,
val isLoading: Boolean = true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why???

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false로 했더니 액티비티 전환 시 컴포저블 보이고 로딩 도는 이슈가 있어서 바꿨므당

val isScrollLoading: Boolean = false,
val clipBoardState: ClipBoardState = ClipBoardState(),
val tapElements: List<FeedUiModel.DoraChipUiModel> = emptyList(),
Expand Down
Loading