Skip to content

Commit

Permalink
정리
Browse files Browse the repository at this point in the history
  • Loading branch information
JuTaK97 committed Jul 2, 2023
1 parent eea75da commit f263b13
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 45 deletions.
3 changes: 1 addition & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ plugins {
id("dagger.hilt.android.plugin")
id("kotlin-kapt")
id("kotlin-parcelize")
id("androidx.navigation.safeargs.kotlin")
id("com.google.firebase.appdistribution")
id("com.google.firebase.crashlytics")
}
Expand Down Expand Up @@ -116,7 +115,7 @@ android {
}

composeOptions {
kotlinCompilerExtensionVersion = "1.4.6"
kotlinCompilerExtensionVersion = "1.4.0"
}
}

Expand Down
50 changes: 15 additions & 35 deletions app/src/main/java/com/wafflestudio/snutt2/views/RNModuleActivity.kt
Original file line number Diff line number Diff line change
@@ -1,64 +1,44 @@
package com.wafflestudio.snutt2.views

import android.app.Activity
import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import com.facebook.hermes.reactexecutor.HermesExecutorFactory
import com.facebook.react.ReactInstanceManager
import com.facebook.react.ReactRootView
import com.facebook.react.common.LifecycleState
import com.facebook.react.shell.MainReactPackage
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import dagger.hilt.android.AndroidEntryPoint
import java.io.File
import java.io.FileOutputStream
import java.net.HttpURLConnection
import java.net.URL

class RNModuleActivity: Activity() {
@AndroidEntryPoint
class RNModuleActivity : AppCompatActivity() {

private val rnViewModel: RNViewModel by viewModels()

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

GlobalScope.launch(Dispatchers.IO) {
val urlConnection = URL("https://snutt-rn-assets.s3.ap-northeast-2.amazonaws.com/android.jsbundle").openConnection() as HttpURLConnection
urlConnection.connect()
val inputStream = urlConnection.inputStream
val outputFile = File(applicationContext.cacheDir, "android.jsbundle")

val outputStream = FileOutputStream(outputFile)
val buffer = ByteArray(1024000)
var bytesRead: Int

while (inputStream.read(buffer).also { bytesRead = it } != -1) {
outputStream.write(buffer, 0, bytesRead)
}
outputStream.close()
inputStream.close()
urlConnection.disconnect()

val jsBundleFile = File(applicationContext.cacheDir, "android.jsbundle")

withContext(Dispatchers.Main) {
rnViewModel.done.observe(this) { done ->
if (done) {
val jsBundleFile = File(applicationContext.cacheDir, "android.jsbundle")
val reactInstanceManager = ReactInstanceManager.builder()
.setApplication(application)
.setCurrentActivity(this@RNModuleActivity)
.setJSBundleFile(jsBundleFile.absolutePath)
.addPackage(MainReactPackage())
.setInitialLifecycleState(LifecycleState.RESUMED)
.setJavaScriptExecutorFactory(HermesExecutorFactory())
.build()

val rootView = ReactRootView(this@RNModuleActivity)
rootView.startReactApplication(reactInstanceManager, "friends", null)
setContentView(rootView)
}
}
}

// val request = DownloadManager.Request(Uri.parse("https://snutt-rn-assets.s3.ap-northeast-2.amazonaws.com/android.jsbundle"))
// .setDestinationInExternalFilesDir(this, Environment.DIRECTORY_DOWNLOADS, "android.jsbundle")
// .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
//
// val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
// downloadManager.enqueue(request)
override fun onDestroy() {
super.onDestroy()
}
}
45 changes: 45 additions & 0 deletions app/src/main/java/com/wafflestudio/snutt2/views/RNViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.wafflestudio.snutt2.views

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.io.File
import java.io.FileOutputStream
import java.net.HttpURLConnection
import java.net.URL
import javax.inject.Inject

@HiltViewModel
class RNViewModel @Inject constructor(
application: Application
) : AndroidViewModel(application) {

private val _done = MutableLiveData(false)
val done: LiveData<Boolean> get() = _done

init {
viewModelScope.launch(Dispatchers.IO) {
val urlConnection = URL("https://snutt-rn-assets.s3.ap-northeast-2.amazonaws.com/android.jsbundle").openConnection() as HttpURLConnection
urlConnection.connect()
val inputStream = urlConnection.inputStream
val outputFile = File(application.applicationContext.cacheDir, "android.jsbundle")

val outputStream = FileOutputStream(outputFile)
val buffer = ByteArray(1024000)
var bytesRead: Int

while (inputStream.read(buffer).also { bytesRead = it } != -1) {
outputStream.write(buffer, 0, bytesRead)
}
outputStream.close()
inputStream.close()
urlConnection.disconnect()
_done.postValue(true)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ fun BookmarkPage(searchViewModel: SearchViewModel) {
override fun handleOnBackPressed() {
if (bottomSheet.isVisible) {
scope.launch { bottomSheet.hide() }
} else
if (navController.currentDestination?.route == NavigationDestination.Bookmark) {
navController.popBackStack()
}
} else if (navController.currentDestination?.route == NavigationDestination.Bookmark) {
navController.popBackStack()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.app.Activity
import android.content.Intent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.ModalBottomSheetLayout
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
Expand Down
3 changes: 1 addition & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:7.0.4")
classpath("com.android.tools.build:gradle:${Deps.Version.AndroidGradle}")
classpath("com.google.gms:google-services:4.3.10")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Deps.Version.Kotlin}")
classpath("com.google.dagger:hilt-android-gradle-plugin:${Deps.Version.Hilt}")
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:${Deps.Version.Navigation}")
classpath("com.google.firebase:firebase-appdistribution-gradle:3.0.0")
classpath("com.google.firebase:firebase-crashlytics-gradle:2.8.1")
}
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object Deps {
const val Paging = "3.1.0"
const val Compose = "1.3.3"
const val ComposeFoundation = "1.3.1"
const val AndroidGradle = "7.0.4"
const val AndroidGradle = "7.4.2"
const val KtLintGradle = "10.2.1"
const val PagingCompose = "1.0.0-alpha14"
}
Expand Down

0 comments on commit f263b13

Please sign in to comment.