-
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.
- 닉네임 변경 화면 및 변경하고 돌아왔을 때 완료 팝업 구현
- Loading branch information
Showing
9 changed files
with
625 additions
and
348 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
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
84 changes: 83 additions & 1 deletion
84
app/src/main/java/com/ftw/hometerview/ui/updatenickname/UpdateNicknameActivity.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 |
---|---|---|
@@ -1,12 +1,94 @@ | ||
package com.ftw.hometerview.ui.updatenickname | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import android.content.Intent | ||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.os.Parcelable | ||
import android.util.Log | ||
import android.view.View | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.lifecycleScope | ||
import androidx.lifecycle.repeatOnLifecycle | ||
import com.ftw.hometerview.R | ||
import com.ftw.hometerview.databinding.ActivityBuildingReviewBinding | ||
import com.ftw.hometerview.databinding.ActivityUpdateNickNameBinding | ||
import com.ftw.hometerview.ui.buildinglist.BuildingListActivity | ||
import com.ftw.hometerview.ui.main.MainActivity | ||
import com.ftw.hometerview.ui.main.MainViewModel | ||
import com.ftw.hometerview.ui.searchcompanyresult.SearchCompanyResultActivity | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import kotlinx.coroutines.launch | ||
import kotlinx.parcelize.Parcelize | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
class UpdateNicknameActivity : AppCompatActivity() { | ||
|
||
companion object { | ||
val UPDATE_NICKNAME_RESULT_KEY = "UPDATE_NICKNAME_RESULT_KEY" | ||
fun newIntent(context: Context, nickname: String): Intent { | ||
return Intent(context, UpdateNicknameActivity::class.java) | ||
.putExtra(UPDATE_NICKNAME_RESULT_KEY, nickname) | ||
} | ||
} | ||
|
||
@Inject | ||
lateinit var viewModel: UpdateNicknameViewModel | ||
|
||
private lateinit var binding: ActivityUpdateNickNameBinding | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_update_nick_name) | ||
|
||
binding = DataBindingUtil.setContentView<ActivityUpdateNickNameBinding>( | ||
this, | ||
R.layout.activity_update_nick_name | ||
).apply { | ||
viewModel = this@UpdateNicknameActivity.viewModel | ||
} | ||
|
||
val nickname = intent.getStringExtra(UPDATE_NICKNAME_RESULT_KEY) ?: return | ||
viewModel.nickname.value = nickname | ||
observe() | ||
} | ||
|
||
fun observe() { | ||
lifecycleScope.launch { | ||
repeatOnLifecycle(Lifecycle.State.STARTED) { | ||
viewModel.nickname.collect { | ||
binding.lengthTextview.text = getString(R.string.written_nickname_length, it.length) | ||
} | ||
} | ||
} | ||
lifecycleScope.launch { | ||
repeatOnLifecycle(Lifecycle.State.STARTED) { | ||
viewModel.event.collect { event -> | ||
when (event) { | ||
UpdateNicknameViewModel.Event.None -> {} | ||
is UpdateNicknameViewModel.Event.OnClickNext -> { | ||
onClickNextFromThirdStepSearchCompany(event.nickname) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun onClickNextFromThirdStepSearchCompany(nickname: String) { | ||
setResult( | ||
Activity.RESULT_OK, | ||
Intent().putExtra(UPDATE_NICKNAME_RESULT_KEY, nickname) | ||
) | ||
|
||
Log.d("1232123", "onClickNextFromThirdStepSearchCompany: $nickname") | ||
finish() | ||
} | ||
|
||
@Parcelize | ||
private data class Argument( | ||
val nickname: String | ||
) : Parcelable | ||
} |
36 changes: 13 additions & 23 deletions
36
app/src/main/java/com/ftw/hometerview/ui/updatenickname/UpdateNicknameViewModel.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 |
---|---|---|
@@ -1,37 +1,27 @@ | ||
package com.ftw.hometerview.ui.updatenickname | ||
|
||
import com.ftw.domain.entity.Company | ||
import com.ftw.domain.entity.LocationReview | ||
import com.ftw.domain.entity.User | ||
import com.ftw.domain.usecase.review.GetLocationReviewsUseCase | ||
import com.ftw.domain.usecase.user.GetCachedUserUseCase | ||
import com.ftw.hometerview.dispatcher.Dispatcher | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.catch | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.launch | ||
|
||
class UpdateNicknameViewModel( | ||
dispatcher: Dispatcher, | ||
private val getCachedUserUseCase: GetCachedUserUseCase | ||
dispatcher: Dispatcher | ||
) { | ||
|
||
private val _user: MutableStateFlow<User> = MutableStateFlow(User.NONE) | ||
val user: StateFlow<User> = _user.asStateFlow() | ||
sealed class Event { | ||
object None : Event() | ||
class OnClickNext(val nickname: String) : Event() | ||
} | ||
|
||
private val _event: MutableStateFlow<Event> = MutableStateFlow(Event.None) | ||
val event: StateFlow<Event> = _event.asStateFlow() | ||
|
||
val nickname: MutableStateFlow<String> = MutableStateFlow("") | ||
|
||
init { | ||
CoroutineScope(dispatcher.ui()).launch { | ||
flow { | ||
emit(getCachedUserUseCase()) | ||
} | ||
.catch { emit(User("", Company.NONE)) } | ||
.collect { | ||
_user.value = it | ||
} | ||
|
||
} | ||
fun onClickUpdateComplete() { | ||
_event.value = Event.OnClickNext(nickname.value) | ||
_event.value = Event.None | ||
} | ||
} |
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,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<translate | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:duration="1000" | ||
android:fromYDelta="-90%" | ||
android:toYDelta="0"> | ||
</translate> |
Oops, something went wrong.