Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix : QA 반영 #235

Merged
merged 18 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
package com.dongyang.android.youdongknowme.ui.view.depart

import android.content.Intent
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import androidx.recyclerview.widget.LinearLayoutManager
import com.dongyang.android.youdongknowme.R
import com.dongyang.android.youdongknowme.databinding.ActivityDepartBinding
import com.dongyang.android.youdongknowme.standard.base.BaseActivity
import com.dongyang.android.youdongknowme.ui.adapter.DepartAdapter
import com.dongyang.android.youdongknowme.ui.view.main.MainActivity
import org.koin.androidx.viewmodel.ext.android.viewModel
import timber.log.Timber


class DepartActivity : BaseActivity<ActivityDepartBinding, DepartViewModel>(), DepartClickListener {


override val layoutResourceId: Int = R.layout.activity_depart
override val viewModel: DepartViewModel by viewModel()
private lateinit var adapter: DepartAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,16 @@ class OnboardingDepartActivity : BaseActivity<ActivityOnboardingDepartBinding, D
setSpanText(binding.tvOnboardingDepartTitleMain, startIdx = 0, endIdx = 5)
}

override fun initDataBinding() = Unit
override fun initDataBinding() {

viewModel.selectDepartPosition.observe(this) { position ->
if (position != -1 && position < searchList.size) {
adapter.submitPosition(position)
binding.etOnboardingDepartSearch.setText(searchList[position])
binding.etOnboardingDepartSearch.setSelection(binding.etOnboardingDepartSearch.text.length)
}
}
}

override fun initAfterBinding() {
binding.ibOnboardingDepartSearchClear.setOnClickListener {
Expand All @@ -64,14 +73,13 @@ class OnboardingDepartActivity : BaseActivity<ActivityOnboardingDepartBinding, D
override fun afterTextChanged(editable: Editable?) {
val searchText =
binding.etOnboardingDepartSearch.text.toString().replace("\\s".toRegex(), "")
searchList = ArrayList<String>()
searchList.clear()

if (searchText.isEmpty()) {
adapter.submitList(emptyList)
binding.ibOnboardingDepartSearchClear.isVisible=false
binding.ibOnboardingDepartSearchClear.isVisible = false
} else {
// 검색 단어를 포함하는지 확인
binding.ibOnboardingDepartSearchClear.isVisible=true
binding.ibOnboardingDepartSearchClear.isVisible = true
for (item in items) {
if (item.contains(searchText)) {
searchList.add(item)
Expand All @@ -88,17 +96,6 @@ class OnboardingDepartActivity : BaseActivity<ActivityOnboardingDepartBinding, D
}
})

viewModel.selectDepartPosition.observe(this) {
adapter.submitPosition(it)

if (it != -1) {
binding.etOnboardingDepartSearch.setText(
searchList[viewModel.selectDepartPosition.value ?: 0]
)
binding.etOnboardingDepartSearch.setSelection(binding.etOnboardingDepartSearch.text.length)
}
}

binding.btnOnboardingDepartNext.setOnClickListener {
getDepart(searchList)
}
Expand Down Expand Up @@ -155,7 +152,7 @@ class OnboardingDepartActivity : BaseActivity<ActivityOnboardingDepartBinding, D
// 확인 버튼을 누르면 내부 DB에 학과를 담고 메인 액티비티로 이동
private fun getDepart(items: ArrayList<String>) {
if (viewModel.selectDepartPosition.value != -1) {
viewModel.setDepartment(items[viewModel.selectDepartPosition.value ?: 0])
viewModel.setDepartment(items[0])
val intent = Intent(this, OnboardingKeywordActivity::class.java)
startActivity(intent)
finish()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.dongyang.android.youdongknowme.ui.view.keyword

import android.content.Intent
import android.content.res.ColorStateList
import android.widget.Toast
import androidx.core.content.ContextCompat
Expand All @@ -9,7 +8,6 @@ import com.dongyang.android.youdongknowme.R
import com.dongyang.android.youdongknowme.data.local.entity.KeywordEntity
import com.dongyang.android.youdongknowme.databinding.ActivityKeywordBinding
import com.dongyang.android.youdongknowme.standard.base.BaseActivity
import com.dongyang.android.youdongknowme.ui.view.setting.OnboardingPermissionActivity
import com.google.android.material.chip.Chip
import com.google.android.material.chip.ChipGroup
import org.koin.androidx.viewmodel.ext.android.viewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ import androidx.lifecycle.viewModelScope
import com.dongyang.android.youdongknowme.data.local.entity.KeywordEntity
import com.dongyang.android.youdongknowme.data.repository.KeywordRepository
import com.dongyang.android.youdongknowme.standard.base.BaseViewModel
import com.google.firebase.messaging.FirebaseMessaging
import kotlinx.coroutines.launch

class KeywordViewModel(
private val keywordRepository: KeywordRepository
) : BaseViewModel() {

private val firebaseMessaging = FirebaseMessaging.getInstance()

private val _localKeywordList: MutableLiveData<List<KeywordEntity>> = MutableLiveData()
val localKeywordList: LiveData<List<KeywordEntity>> get() = _localKeywordList

Expand All @@ -37,14 +34,12 @@ class KeywordViewModel(
viewModelScope.launch {
keywordRepository.updateUserKeywords(true, localKeyword.name)
}
firebaseMessaging.subscribeToTopic(localKeyword.englishName)
}
} else {
if (localKeyword.isSubscribe) {
viewModelScope.launch {
keywordRepository.updateUserKeywords(false, localKeyword.name)
}
firebaseMessaging.unsubscribeFromTopic(localKeyword.englishName)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.plusAssign
import androidx.navigation.ui.setupWithNavController
import com.dongyang.android.youdongknowme.R
import com.dongyang.android.youdongknowme.data.local.SharedPreference
import com.dongyang.android.youdongknowme.databinding.ActivityMainBinding
import com.dongyang.android.youdongknowme.standard.base.BaseActivity
import com.dongyang.android.youdongknowme.ui.view.util.KeepStateNavigator
Expand Down Expand Up @@ -34,8 +33,6 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>() {
navController.navigatorProvider += navigator
navController.setGraph(R.navigation.dmu_navigation)
binding.mainNvBottom.setupWithNavController(navController)

viewModel.checkFirstLaunch()
}

override fun initDataBinding() {
Expand All @@ -47,21 +44,19 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>() {
override fun initAfterBinding() = Unit

private fun getFcmToken() {
viewModel.setIsFirstLaunch(false)
FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
if (task.isSuccessful) {
viewModel.setFCMToken(task.result).run { viewModel.setInitToken() }
Timber.d("first ${task.result}")
Timber.d("token ${task.result}")
} else {
return@addOnCompleteListener
}
val token = task.result
SharedPreference.setFcmToken(token)

Timber.d("token : ${token}")
}
}

companion object {

fun createIntent(context: Context): Intent {
return Intent(context, MainActivity::class.java)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.dongyang.android.youdongknowme.standard.base.BaseViewModel
import com.dongyang.android.youdongknowme.standard.network.NetworkResult
import com.dongyang.android.youdongknowme.ui.view.util.Event
import kotlinx.coroutines.launch
import timber.log.Timber

class MainViewModel(private val mainRepository: MainRepository) : BaseViewModel() {
private val _errorState: MutableLiveData<Event<Int>> = MutableLiveData()
Expand All @@ -33,44 +32,49 @@ class MainViewModel(private val mainRepository: MainRepository) : BaseViewModel(
private val _isFirstLaunch: MutableLiveData<Boolean> = MutableLiveData(false)
val isFirstLaunch: LiveData<Boolean> get() = _isFirstLaunch

init{
init {
checkFirstLaunch()
getUserDepart()
getUserTopic()
}

fun checkFirstLaunch() {
private fun checkFirstLaunch() {
if (mainRepository.getIsFirstLaunch()) {
_isFirstLaunch.value = true
}
}

fun setFCMToken(token: String){
mainRepository.setFCMToken(token)
_FCMToken.value = token
}

private fun getUserDepart(){
private fun getUserDepart() {
_myDepartment.value = mainRepository.getUserDepartment()
}

private fun getUserTopic(){
private fun getUserTopic() {
viewModelScope.launch {
_myTopics.value = mainRepository.getUserTopic()
}
}

fun setFCMToken(token: String) {
mainRepository.setFCMToken(token)
_FCMToken.value = token
}

fun setIsFirstLaunch(boolean: Boolean) {
mainRepository.setIsFirstLaunch(boolean)
}

fun setInitToken() {
_isLoading.postValue(true)

viewModelScope.launch {
when (val result = mainRepository.setUserToken(Token(
token = FCMToken.value.toString(),
department = myDepartment.value ?: "",
topics = myTopics.value ?: emptyList()
)
when (val result = mainRepository.setUserToken(
Token(
token = FCMToken.value.toString(),
department = myDepartment.value ?: "",
topics = myTopics.value ?: emptyList()
)
)) {
is NetworkResult.Success -> {
Timber.d("first ${FCMToken.value.toString()}")
mainRepository.setIsFirstLaunch(false)
_isFirstLaunch.postValue(false)
_isLoading.postValue(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,60 @@ package com.dongyang.android.youdongknowme.ui.view.setting
import android.Manifest
import android.content.pm.PackageManager
import android.content.res.ColorStateList
import android.os.Build
import androidx.core.content.ContextCompat
import com.dongyang.android.youdongknowme.R
import com.dongyang.android.youdongknowme.databinding.ActivityOnboardingPermissionBinding
import com.dongyang.android.youdongknowme.standard.base.BaseActivity
import com.dongyang.android.youdongknowme.ui.view.main.MainActivity
import org.koin.androidx.viewmodel.ext.android.viewModel


class OnboardingPermissionActivity :
BaseActivity<ActivityOnboardingPermissionBinding, SettingViewModel>() {

override val layoutResourceId: Int = R.layout.activity_onboarding_permission
override val viewModel: SettingViewModel by viewModel()

override fun initStartView() {
viewModel.checkAccessAlarm()
viewModel.getUserDepartment()
setPermissionSwitch(false)

setPermissionSwitch(false)
setSpanText(binding.tvPermissionTitleMain, startIdx = 0, endIdx = 9)
}

override fun initDataBinding() = Unit

override fun initAfterBinding() {
binding.btnPermissionComplete.setOnClickListener {
val intent = MainActivity.createIntent(this@OnboardingPermissionActivity)
startActivity(intent)
finish()
}
}

binding.switchPermission.setOnCheckedChangeListener { compoundButton, _ ->
if (compoundButton.isChecked) {
// 권환 확인 전 스위치 초기화
binding.switchPermission.isChecked = false
override fun initDataBinding() = Unit

// 온보딩 알림 스위치를 활성화
if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(
this, Manifest.permission.POST_NOTIFICATIONS
)
) {
// 알림 권한이 허용 상태
setPermissionSwitch(true)
override fun initAfterBinding() {
binding.switchPermission.setOnCheckedChangeListener { compoundButton, _ ->
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (compoundButton.isChecked) {
if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(
this, Manifest.permission.POST_NOTIFICATIONS
)
) {
setPermissionSwitch(true)
} else {
val dialog = PermissionDialog(
getString(R.string.dialog_permission_title),
getString(R.string.dialog_permission_content),
this.packageName
)
dialog.show(supportFragmentManager, "CustomDialog")
}
} else {

// 알림 권한이 미허용 상태
val dialog = PermissionDialog(getString(R.string.dialog_permission_title), getString(R.string.dialog_permission_content), this.packageName)
dialog.show(supportFragmentManager, "CustomDialog")
setPermissionSwitch(false)
}
} else {
// 온보딩 알림 스위치 비활성화
setPermissionSwitch(false)
if (compoundButton.isChecked) {
setPermissionSwitch(true)
} else {
setPermissionSwitch(false)
}
}
}
}
Expand All @@ -70,8 +72,6 @@ class OnboardingPermissionActivity :
ColorStateList.valueOf(ContextCompat.getColor(this, resources))
binding.switchPermission.setTextColor(getColor(resources))
binding.mvSwitchPermission.strokeColor = getColor(resources)

binding.switchPermission.isChecked = isChecked
viewModel.setIsAccessUniversityAlarm(isChecked)
viewModel.setIsAccessDepartAlarm(isChecked)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package com.dongyang.android.youdongknowme.ui.view.splash

import android.Manifest
import android.annotation.SuppressLint
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.view.View
import androidx.annotation.RequiresApi
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope
Expand All @@ -28,11 +27,6 @@ class SplashActivity : BaseActivity<ActivitySplashBinding, SplashViewModel>() {
private var intentJob: Job? = null

override fun initStartView() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val content: View = findViewById(android.R.id.content)
content.viewTreeObserver.addOnPreDrawListener { false }
}

viewModel.checkFirstLaunch()
}

Expand All @@ -52,6 +46,7 @@ class SplashActivity : BaseActivity<ActivitySplashBinding, SplashViewModel>() {
}
}

@RequiresApi(Build.VERSION_CODES.TIRAMISU)
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<String>,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<!-- Customize your theme here. -->
</style>

<style name="Theme.YouDongKnowMe.Splash" parent="Theme.YouDongKnowMe"></style>
<style name="Theme.YouDongKnowMe.Splash" parent="Theme.YouDongKnowMe" />

<!-- 달력 연, 월 스타일 지정 -->
<style name="CalendarHeader">
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.4.2' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
id "com.google.gms.google-services" version "4.3.10" apply false
id "com.google.gms.google-services" version "4.3.14" apply false
}

task clean(type: Delete) {
Expand Down
Loading