-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #307 from Nexters/feature/300
Feature/300 인앱 웹뷰 환경에서 공연 등록하기
- Loading branch information
Showing
16 changed files
with
185 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
domain/src/main/java/com/nexters/boolti/domain/model/TokenPair.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.nexters.boolti.domain.model | ||
|
||
data class TokenPair( | ||
val accessToken: String, | ||
val refreshToken: String, | ||
) { | ||
val isLoggedIn: Boolean = accessToken.isNotBlank() && refreshToken.isNotBlank() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...ava/com/nexters/boolti/presentation/screen/showregistration/ShowRegistrationNavigation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.nexters.boolti.presentation.screen.showregistration | ||
|
||
import androidx.compose.ui.Modifier | ||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.compose.composable | ||
import com.nexters.boolti.presentation.screen.MainDestination | ||
|
||
fun NavGraphBuilder.addShowRegistration( | ||
modifier: Modifier = Modifier, | ||
) { | ||
composable( | ||
route = MainDestination.ShowRegistration.route, | ||
) { | ||
ShowRegistrationScreen( | ||
modifier = modifier, | ||
) | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...in/java/com/nexters/boolti/presentation/screen/showregistration/ShowRegistrationScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.nexters.boolti.presentation.screen.showregistration | ||
|
||
import android.annotation.SuppressLint | ||
import android.net.Uri | ||
import android.view.ViewGroup | ||
import android.webkit.CookieManager | ||
import android.webkit.ValueCallback | ||
import android.webkit.WebChromeClient | ||
import android.webkit.WebStorage | ||
import android.webkit.WebView | ||
import android.webkit.WebViewClient | ||
import androidx.activity.compose.rememberLauncherForActivityResult | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.viewinterop.AndroidView | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import com.nexters.boolti.presentation.BuildConfig | ||
import com.nexters.boolti.presentation.util.BtWebChromeClient | ||
import kotlinx.coroutines.flow.filter | ||
import kotlinx.coroutines.flow.filterNotNull | ||
import timber.log.Timber | ||
|
||
@SuppressLint("SetJavaScriptEnabled") | ||
@Composable | ||
fun ShowRegistrationScreen( | ||
modifier: Modifier = Modifier, | ||
viewModel: ShowRegistrationViewModel = hiltViewModel(), | ||
) { | ||
var filePathCallback: ValueCallback<Array<Uri>>? by remember { mutableStateOf(null) } | ||
val launcher = | ||
rememberLauncherForActivityResult(ActivityResultContracts.OpenMultipleDocuments()) { uris -> | ||
Timber.d("선택한 파일 uri 목록 : $uris") | ||
filePathCallback?.onReceiveValue(uris.toTypedArray()) | ||
} | ||
val domain = BuildConfig.DOMAIN | ||
val url = "https://${domain}/show/add" | ||
|
||
LaunchedEffect(Unit) { | ||
CookieManager.getInstance().removeAllCookies(null) | ||
WebStorage.getInstance().deleteAllData() | ||
|
||
viewModel.tokens | ||
.filterNotNull() | ||
.filter { it.isLoggedIn } | ||
.collect { tokens -> | ||
with(CookieManager.getInstance()) { | ||
setCookie(url, "x-access-token=${tokens.accessToken}") | ||
setCookie(url, "x-refresh-token=${tokens.refreshToken}") | ||
flush() | ||
} | ||
} | ||
} | ||
|
||
AndroidView( | ||
modifier = modifier, | ||
factory = { context -> | ||
WebView(context).apply { | ||
layoutParams = ViewGroup.LayoutParams( | ||
ViewGroup.LayoutParams.MATCH_PARENT, | ||
ViewGroup.LayoutParams.MATCH_PARENT | ||
) | ||
|
||
webViewClient = WebViewClient() | ||
webChromeClient = BtWebChromeClient(launchActivity = { | ||
launcher.launch(arrayOf("image/*")) | ||
}) { callback -> | ||
filePathCallback = callback | ||
} | ||
|
||
settings.javaScriptEnabled = true | ||
settings.domStorageEnabled = true | ||
|
||
loadUrl(url) | ||
|
||
Timber.d("내가 만든 쿠키 : ${CookieManager.getInstance().getCookie(url)}") | ||
} | ||
} | ||
) | ||
} |
16 changes: 16 additions & 0 deletions
16
...java/com/nexters/boolti/presentation/screen/showregistration/ShowRegistrationViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.nexters.boolti.presentation.screen.showregistration | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.nexters.boolti.domain.repository.AuthRepository | ||
import com.nexters.boolti.presentation.extension.stateInUi | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class ShowRegistrationViewModel @Inject constructor( | ||
val authRepository: AuthRepository, | ||
) : ViewModel() { | ||
val tokens = authRepository.getTokens() | ||
.stateInUi(viewModelScope, null) | ||
} |
24 changes: 24 additions & 0 deletions
24
presentation/src/main/java/com/nexters/boolti/presentation/util/BtWebChromeClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.nexters.boolti.presentation.util | ||
|
||
import android.net.Uri | ||
import android.webkit.ValueCallback | ||
import android.webkit.WebChromeClient | ||
import android.webkit.WebView | ||
|
||
class BtWebChromeClient( | ||
private val launchActivity: () -> Unit, | ||
private val setFilePathCallback: (ValueCallback<Array<Uri>>) -> Unit, | ||
) : WebChromeClient() { | ||
override fun onShowFileChooser( | ||
webView: WebView, | ||
filePathCallback: ValueCallback<Array<Uri>>?, | ||
fileChooserParams: FileChooserParams | ||
): Boolean { | ||
if (filePathCallback == null) return false | ||
setFilePathCallback(filePathCallback) | ||
|
||
launchActivity() | ||
|
||
return true | ||
} | ||
} |