Skip to content

Commit

Permalink
issue #161 feat: Compose용 액티비티 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
TTC1018 committed Jul 2, 2023
1 parent c61ef45 commit c05b627
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<activity
android:name=".presentation.totalfilm.TotalFilmActivity"
android:exported="false" />
<activity android:name=".presentation.uploadfilm.UploadFilmComposeActivity"
android:exported="false"
android:theme="@style/Theme.DailyFilm"/>
<activity
android:name=".presentation.uploadfilm.UploadFilmActivity"
android:exported="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.boostcamp.dailyfilm.presentation.calendar.model.DateModel
import com.boostcamp.dailyfilm.presentation.selectvideo.SelectVideoActivity
import com.boostcamp.dailyfilm.presentation.selectvideo.SelectVideoActivity.Companion.DATE_VIDEO_ITEM
import com.boostcamp.dailyfilm.presentation.uploadfilm.UploadFilmActivity
import com.boostcamp.dailyfilm.presentation.uploadfilm.UploadFilmComposeActivity
import com.boostcamp.dailyfilm.presentation.uploadfilm.model.DateAndVideoModel
import com.gowtham.library.utils.CompressOption
import com.gowtham.library.utils.TrimType
Expand Down Expand Up @@ -100,7 +101,7 @@ class TrimVideoActivity : BaseActivity<ActivityTrimViedoBinding>(R.layout.activi

private fun moveToUpload(trimAndVideoModel: DateAndVideoModel, startTime: Long) {
startActivity(
Intent(this, UploadFilmActivity::class.java).apply {
Intent(this, UploadFilmComposeActivity::class.java).apply {
putExtra(DATE_VIDEO_ITEM, trimAndVideoModel)
putExtra(KEY_CALENDAR_INDEX, viewModel.calendarIndex)
putExtra(KEY_INFO_ITEM, viewModel.infoItem)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package com.boostcamp.dailyfilm.presentation.uploadfilm

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.boostcamp.dailyfilm.presentation.calendar.CalendarActivity
import com.boostcamp.dailyfilm.presentation.calendar.DateFragment
import com.boostcamp.dailyfilm.presentation.playfilm.PlayFilmActivity
import com.boostcamp.dailyfilm.presentation.playfilm.PlayFilmFragment
import com.boostcamp.dailyfilm.presentation.playfilm.model.EditState
import com.boostcamp.dailyfilm.presentation.selectvideo.SelectVideoActivity
import com.boostcamp.dailyfilm.presentation.trimvideo.TrimVideoActivity
import com.boostcamp.dailyfilm.presentation.ui.theme.DailyFilmTheme
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import java.io.File

@AndroidEntryPoint
class UploadFilmComposeActivity : ComponentActivity() {

private val viewModel by viewModels<UploadFilmViewModel>()

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

setContent {
DailyFilmTheme {
UploadFilmScreen(viewModel = viewModel)
}
}
}

private fun subscribeUiState() {
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.uploadUiState.collect { uiState ->
when (uiState) {
is UploadUiState.Canceled -> {
if (viewModel.beforeItem != null) {
// 업로드 안 한 영상은 로컬에서도 삭제
deleteLocalFile(viewModel.infoItem?.uri?.path)

// 돌아가기
startActivity(
Intent(
this@UploadFilmComposeActivity,
TrimVideoActivity::class.java
).apply {
putExtra(CalendarActivity.KEY_EDIT_STATE, viewModel.editState.value)
putExtra(SelectVideoActivity.DATE_VIDEO_ITEM, viewModel.beforeItem)
putExtra(PlayFilmFragment.KEY_DATE_MODEL, viewModel.dateModel)
putExtra(DateFragment.KEY_CALENDAR_INDEX, viewModel.calendarIndex)
}
)
}
finish()
}

is UploadUiState.UploadSuccess -> {
when (viewModel.editState.value) {
EditState.EDIT_CONTENT -> {
setResult(
Activity.RESULT_OK,
Intent(
this@UploadFilmComposeActivity,
PlayFilmActivity::class.java
).apply {
putExtra(PlayFilmFragment.KET_EDIT_TEXT, uiState.dateModel.text)
}
)
}
else -> {
setResult(
Activity.RESULT_OK,
Intent(
this@UploadFilmComposeActivity,
CalendarActivity::class.java
).apply {
putExtra(DateFragment.KEY_CALENDAR_INDEX, viewModel.calendarIndex)
putExtra(PlayFilmFragment.KEY_DATE_MODEL, uiState.dateModel)
}
)
}
}
finish()
}

else -> {}
}
}
}
}
}

private fun deleteLocalFile(filePath: String?) {
filePath?.let { File(it).delete() }
}

}

0 comments on commit c05b627

Please sign in to comment.