Skip to content

Commit

Permalink
style(#333): ktlint 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
jaehan4707 committed May 11, 2024
1 parent 6188f72 commit eb5af49
Show file tree
Hide file tree
Showing 18 changed files with 538 additions and 533 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
object ConnectivityManagerModule {

@Singleton
@Provides
fun provideConnectivityManager(@ApplicationContext context: Context): ConnectivityManager {
fun provideConnectivityManager(
@ApplicationContext context: Context,
): ConnectivityManager {
return context.getSystemService(ConnectivityManager::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,34 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import javax.inject.Inject

class NetworkManager @Inject constructor(private val connectivityManager: ConnectivityManager) {

private val _isConnected = MutableStateFlow(false)
val isConnected: StateFlow<Boolean> = _isConnected

private val request: NetworkRequest = NetworkRequest.Builder()
.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED)
.addCapability(NET_CAPABILITY_INTERNET)
.build()

private val networkCallback = object : ConnectivityManager.NetworkCallback() {
override fun onAvailable(network: Network) {
_isConnected.value = true
class NetworkManager
@Inject
constructor(private val connectivityManager: ConnectivityManager) {
private val _isConnected = MutableStateFlow(false)
val isConnected: StateFlow<Boolean> = _isConnected

private val request: NetworkRequest =
NetworkRequest.Builder()
.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED)
.addCapability(NET_CAPABILITY_INTERNET)
.build()

private val networkCallback =
object : ConnectivityManager.NetworkCallback() {
override fun onAvailable(network: Network) {
_isConnected.value = true
}

override fun onLost(network: Network) {
_isConnected.value = false
}
}

fun registerNetworkCallback() {
connectivityManager.registerNetworkCallback(request, networkCallback)
}

override fun onLost(network: Network) {
_isConnected.value = false
fun unRegisterNetworkCallback() {
connectivityManager.unregisterNetworkCallback(networkCallback)
}
}

fun registerNetworkCallback() {
connectivityManager.registerNetworkCallback(request, networkCallback)
}

fun unRegisterNetworkCallback() {
connectivityManager.unregisterNetworkCallback(networkCallback)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,47 @@ import javax.inject.Inject

@HiltViewModel
open class BaseActivityViewModel
@Inject
constructor(
private val logoutEventRepository: LogoutEventRepository,
private val networkManager: NetworkManager,
) : ViewModel() {
private val _events = MutableSharedFlow<ViewEvent>()
val events: SharedFlow<ViewEvent> = _events.asSharedFlow()
private val _isConnected = MutableStateFlow(false)
val isConnected: StateFlow<Boolean> = _isConnected
@Inject
constructor(
private val logoutEventRepository: LogoutEventRepository,
private val networkManager: NetworkManager,
) : ViewModel() {
private val _events = MutableSharedFlow<ViewEvent>()
val events: SharedFlow<ViewEvent> = _events.asSharedFlow()
private val _isConnected = MutableStateFlow(false)
val isConnected: StateFlow<Boolean> = _isConnected

init {
networkManager.registerNetworkCallback()
observerNetworkConnection()
}
init {
networkManager.registerNetworkCallback()
observerNetworkConnection()
}

private fun sendLogoutEvent() {
viewModelScope.launch {
logoutEventRepository.logout().collect { logoutEvent ->
if (logoutEvent) {
_events.emit(ViewEvent.Logout)
private fun sendLogoutEvent() {
viewModelScope.launch {
logoutEventRepository.logout().collect { logoutEvent ->
if (logoutEvent) {
_events.emit(ViewEvent.Logout)
}
}
}
}
}

private fun observerNetworkConnection() {
viewModelScope.launch {
networkManager.isConnected.collectLatest { isConnected ->
_isConnected.update { isConnected }
private fun observerNetworkConnection() {
viewModelScope.launch {
networkManager.isConnected.collectLatest { isConnected ->
_isConnected.update { isConnected }
}
}
}
}

fun logout() {
viewModelScope.launch {
logoutEventRepository.logout()
fun logout() {
viewModelScope.launch {
logoutEventRepository.logout()
}
}
}

override fun onCleared() {
super.onCleared()
networkManager.unRegisterNetworkCallback()
override fun onCleared() {
super.onCleared()
networkManager.unRegisterNetworkCallback()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ fun BoardListScreen(
}) { innerPadding ->
BoxWithConstraints(
modifier =
Modifier
.padding(innerPadding)
.fillMaxWidth(),
Modifier
.padding(innerPadding)
.fillMaxWidth(),
) {
BoardListComponent(
uiState = uiState,
Expand Down Expand Up @@ -158,12 +158,12 @@ fun BoardThumbnail(
placeholder = painterResource(id = R.drawable.ic_placeholder),
error = painterResource(id = R.drawable.ic_placeholder),
modifier =
Modifier
.size(width = 100.dp, height = 100.dp)
.clip(CircleShape)
.clickable {
navigateToMindMap(board.id, board.name)
},
Modifier
.size(width = 100.dp, height = 100.dp)
.clip(CircleShape)
.clickable {
navigateToMindMap(board.id, board.name)
},
contentScale = ContentScale.Crop,
)
}
Expand Down
Loading

0 comments on commit eb5af49

Please sign in to comment.