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

Feat : 최초 어플 실행 작업 및 토큰 등록 #217

Merged
merged 21 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
android:theme="@style/Theme.YouDongKnowMe"
android:usesCleartextTraffic="true">
<activity
android:name=".ui.view.permission.OnboardingPermissionActivity"
android:name=".ui.view.setting.OnboardingPermissionActivity"
android:exported="false" />
<activity
android:name=".ui.view.license.LicenseActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@ object SharedPreference {
private const val FCM_TOKEN = "NO_TOKEN"
fun getFCMToken(): String = pref?.getString(FCM_TOKEN, "0") ?: "0"
fun setFcmToken(token: String) = pref?.edit()?.putString(FCM_TOKEN, token)?.apply()

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.dongyang.android.youdongknowme.data.remote.entity

import com.google.gson.annotations.SerializedName

data class Token (
@SerializedName("token")
val token: String,
@SerializedName("department")
val department: String,
@SerializedName("topics")
val topics: List<String>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.dongyang.android.youdongknowme.data.remote.service

import com.dongyang.android.youdongknowme.data.remote.entity.Token
import retrofit2.http.Body
import retrofit2.http.POST

interface TokenService {
@POST("token/v1/dmu/initToken")
suspend fun setInitToken(
@Body data: Token,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class DepartRepository {
SharedPreference.setDepartment(department.name)
SharedPreference.setCode(department.code)
}
fun getIsFirstLaunch(): Boolean = SharedPreference.getIsFirstLaunch()

fun getUserDepartment(): String {
return SharedPreference.getDepartment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,4 @@ class KeywordRepository(
suspend fun updateUserKeywords(isSubscribe: Boolean, name: String) {
keywordDao.updateKeyword(isSubscribe, name)
}

fun getIsFirstLaunch(): Boolean = SharedPreference.getIsFirstLaunch()

fun setIsFirstLaunch(isFirstLaunch: Boolean) {
SharedPreference.setIsFirstLaunch(isFirstLaunch)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.dongyang.android.youdongknowme.data.repository

import com.dongyang.android.youdongknowme.data.local.SharedPreference
import com.dongyang.android.youdongknowme.data.local.dao.KeywordDao
import com.dongyang.android.youdongknowme.data.remote.service.TokenService
import com.dongyang.android.youdongknowme.standard.network.ErrorResponseHandler
import com.dongyang.android.youdongknowme.standard.network.NetworkResult
import com.dongyang.android.youdongknowme.standard.network.RetrofitObject

class MainRepository(
private val keywordDao: KeywordDao,
private val errorResponseHandler: ErrorResponseHandler
) {
fun getIsFirstLaunch(): Boolean = SharedPreference.getIsFirstLaunch()

fun setIsFirstLaunch(isFirstLaunch: Boolean) {
SharedPreference.setIsFirstLaunch(isFirstLaunch)
}

fun getUserDepartment(): String {
return SharedPreference.getDepartment()
}

suspend fun getUserTopic(): List<String> {
val subscribedTopic = keywordDao.getSubscribedKeywords()
return subscribedTopic.map { it.englishName }
}

fun getFCMToken(): String {
return SharedPreference.getFCMToken()
}

fun setFCMToken(token: String) {
SharedPreference.setFcmToken(token)
}

suspend fun setUserToken(
data: com.dongyang.android.youdongknowme.data.remote.entity.Token
): NetworkResult<Unit> {
return try {
val response = RetrofitObject.getNetwork().create(TokenService::class.java)
.setInitToken(data)
NetworkResult.Success(response)
} catch (exception: Exception) {
val error = errorResponseHandler.getError(exception)
NetworkResult.Error(error)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.dongyang.android.youdongknowme.data.repository.AlarmRepository
import com.dongyang.android.youdongknowme.data.repository.CafeteriaRepository
import com.dongyang.android.youdongknowme.data.repository.DepartRepository
import com.dongyang.android.youdongknowme.data.repository.KeywordRepository
import com.dongyang.android.youdongknowme.data.repository.MainRepository
import com.dongyang.android.youdongknowme.data.repository.NoticeRepository
import com.dongyang.android.youdongknowme.data.repository.ScheduleRepository
import com.dongyang.android.youdongknowme.data.repository.SettingRepository
Expand All @@ -20,6 +21,7 @@ import com.dongyang.android.youdongknowme.ui.view.depart.DepartViewModel
import com.dongyang.android.youdongknowme.ui.view.detail.DetailViewModel
import com.dongyang.android.youdongknowme.ui.view.keyword.KeywordViewModel
import com.dongyang.android.youdongknowme.ui.view.license.LicenseViewModel
import com.dongyang.android.youdongknowme.ui.view.main.MainViewModel
import com.dongyang.android.youdongknowme.ui.view.notice.NoticeViewModel
import com.dongyang.android.youdongknowme.ui.view.schedule.ScheduleViewModel
import com.dongyang.android.youdongknowme.ui.view.search.SearchViewModel
Expand Down Expand Up @@ -98,6 +100,9 @@ val viewModelModule = module {
viewModel {
SearchViewModel(get())
}
viewModel{
MainViewModel(get())
}
}

val repositoryModule = module {
Expand Down Expand Up @@ -125,6 +130,9 @@ val repositoryModule = module {
single {
CafeteriaRepository(get())
}
single{
MainRepository(get(), get())
}
}

val utilModule = module {
Expand All @@ -135,23 +143,23 @@ val utilModule = module {

private val defaultKeywordList = arrayListOf(
KeywordEntity("시험", "exam", false),
KeywordEntity("수강", "course", false),
KeywordEntity("특강", "lecture", false),
KeywordEntity("계절학기", "season", false),
KeywordEntity("휴학", "leave", false),
KeywordEntity("복학", "return", false),
KeywordEntity("졸업", "graduation", false),
KeywordEntity("전과", "transfer", false),
KeywordEntity("학기포기", "drop", false),
KeywordEntity("수강", "signup", false),
KeywordEntity("특강", "speciallecture", false),
KeywordEntity("계절학기", "seasonalsemester", false),
KeywordEntity("휴학", "leaveofabsence", false),
KeywordEntity("복학", "returntoschool", false),
KeywordEntity("졸업", "graduate", false),
KeywordEntity("전과", "switchmajors", false),
KeywordEntity("학기포기", "givingupthesemester", false),
KeywordEntity("장학", "scholarship", false),
KeywordEntity("국가장학", "nationalScholarship", false),
KeywordEntity("등록", "tuition", false),
KeywordEntity("채용", "recruitment", false),
KeywordEntity("국가장학", "nationalscholarship", false),
KeywordEntity("등록", "registration", false),
KeywordEntity("채용", "employment", false),
KeywordEntity("공모전", "contest", false),
KeywordEntity("대회", "competition", false),
KeywordEntity("현장실습", "field", false),
KeywordEntity("봉사", "service", false),
KeywordEntity("현장실습", "fieldtraining", false),
KeywordEntity("봉사", "volunteer", false),
KeywordEntity("기숙사", "dormitory", false),
KeywordEntity("동아리", "club", false),
KeywordEntity("학생회", "studentCouncil", false),
KeywordEntity("동아리", "group", false),
KeywordEntity("학생회", "studentcouncil", false),
)
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,4 @@ object CODE {
const val HOTEL_TOURISM_CODE = 604
const val MANAGEMENT_INFORMATION_CODE = 605
const val BIG_DATA_MANAGEMENT_CODE = 606


}
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,56 @@ sealed class Department(
) {
object Mechanical : Department("기계공학과", CODE.MECHANICAL_ENGINE_CODE)
object MechanicalDesign : Department("기계설계공학과", CODE.MECHANICAL_DESIGN_CODE)
object Automation : Department("로봇공학과", CODE.ROBOT_ENGINE_CODE)
object Robot : Department("자동화공학과", CODE.AUTOMATION_ENGINE_CODE)
object Electrical : Department("전기공학과", CODE.ELECTRICAL_ENGINE_CODE)
object InfoElectrical : Department("정보전자공학과", CODE.INFO_ELECTRONIC_ENGINE_CODE)
object Semiconductor : Department("반도체전자공학과", CODE.SEMICONDUCTOR_ENGINE_CODE)
object InfoCommunication : Department("정보통신공학과", CODE.INFO_COMMUNICATION_ENGINE_CODE)
object FireManagement : Department("소방안전관리과", CODE.FIRE_MANAGEMENT_CODE)
object ComputerSoftware : Department("컴퓨터소프트웨어공학과", CODE.COMPUTER_SOFTWARE_ENGINE_CODE)
object ComputerInfo : Department("컴퓨터정보공학과", CODE.COMPUTER_INFO_ENGINE_CODE)
object ComputerSoftware : Department("컴퓨터소프트웨어공학과", CODE.COMPUTER_SOFTWARE_ENGINE_CODE)
object Artificial : Department("인공지능소프트웨어학과", CODE.ARTIFICIAL_ENGINE_CODE)
object Biochemical : Department("생명화학공학과", CODE.BIOCHEMICAL_ENGINE_CODE)
object BioConvergence : Department("바이오융합공학과", CODE.BIO_CONVERGENCE_ENGINE_CODE)
object Architecture : Department("건축과", CODE.ARCHITECTURE_CODE)
object InteriorDesign : Department("실내건축디자인과", CODE.INTERIOR_DESIGN_CODE)
object VisualDesign : Department("시각디자인과", CODE.VISUAL_DESIGN_CODE)
object ArVrContent : Department("AR-VR콘텐츠디자인과", CODE.AR_VR_CONTENT_CODE)
object ArVrContents : Department("AR-VR콘텐츠디자인과", CODE.AR_VR_CONTENT_CODE)
object Business : Department("경영학과", CODE.BUSINESS_ADMINISTRATION_CODE)
object TaxAccounting : Department("세무회계학과", CODE.TAX_ACCOUNTING_CODE)
object DistributionMarketing : Department("유통마케팅학과", CODE.DISTRIBUTION_MARKETING_CODE)
object HotelTourism : Department("호텔관광학과", CODE.HOTEL_TOURISM_CODE)
object ManagementInformation : Department("경영정보학과", CODE.MANAGEMENT_INFORMATION_CODE)
object BusinessInfo : Department("경영정보학과", CODE.MANAGEMENT_INFORMATION_CODE)
object BigDataManagement : Department("빅데이터경영과", CODE.BIG_DATA_MANAGEMENT_CODE)
object Robot : Department("로봇공학과", CODE.ROBOT_ENGINE_CODE)
object Automation : Department("자동화공학과", CODE.AUTOMATION_ENGINE_CODE)

companion object {
fun getDepartment(department: String): Department {
return when (department) {
"경영학과" -> Business
"경영정보학과" -> ManagementInformation
"기계공학과" -> Mechanical
"기계설계공학과" -> MechanicalDesign
"로봇공학과" -> Robot
"자동화공학과" -> Automation
"전기공학과" -> Electrical
"정보전자공학과" -> InfoElectrical
"반도체전자공학과" -> Semiconductor
"정보통신공학과" -> InfoCommunication
"소방안전관리과" -> FireManagement
"컴퓨터소프트웨어공학과" -> ComputerSoftware
"컴퓨터정보공학과" -> ComputerInfo
"컴퓨터소프트웨어공학과" -> ComputerSoftware
"인공지능소프트웨어학과" -> Artificial
"생명화학공학과" -> Biochemical
"바이오융합공학과" -> BioConvergence
"건축과" -> Architecture
"실내건축디자인과" -> InteriorDesign
"시각디자인과" -> VisualDesign
"AR-VR콘텐츠디자인과" -> ArVrContent
"AR-VR콘텐츠디자인과" -> ArVrContents
"경영학과" -> Business
"세무회계학과" -> TaxAccounting
"유통마케팅학과" -> DistributionMarketing
"호텔관광학과" -> HotelTourism
"경영정보학과" -> BusinessInfo
"빅데이터경영과" -> BigDataManagement
"로봇공학과" -> Robot
"자동화공학과" -> Automation
else -> throw IllegalArgumentException("올바른 타입이 아닙니다.")
}
}
Expand All @@ -64,25 +64,27 @@ sealed class Department(
return arrayListOf(
Mechanical,
MechanicalDesign,
Automation,
Robot,
Electrical,
InfoElectrical,
Semiconductor,
InfoCommunication,
ComputerSoftware,
ComputerInfo,
FireManagement,
ComputerInfo,
ComputerSoftware,
Artificial,
Biochemical,
BioConvergence,
Architecture,
InteriorDesign,
VisualDesign,
ArVrContent,
ArVrContents,
Business,
TaxAccounting,
DistributionMarketing,
HotelTourism,
ManagementInformation,
BusinessInfo,
BigDataManagement
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import com.dongyang.android.youdongknowme.data.repository.DepartRepository
import com.dongyang.android.youdongknowme.standard.base.BaseViewModel

class DepartViewModel(private val departRepository: DepartRepository) : BaseViewModel() {

private val _isFirstLaunch: MutableLiveData<Boolean> = MutableLiveData(false)
val isFirstLaunch: LiveData<Boolean> get() = _isFirstLaunch

private val _myDepartment: MutableLiveData<String> = MutableLiveData()
val myDepartment: LiveData<String> get() = _myDepartment

Expand All @@ -31,10 +27,4 @@ class DepartViewModel(private val departRepository: DepartRepository) : BaseView
fun setSelectPosition(position: Int) {
_selectDepartPosition.postValue(position)
}

fun checkFirstLaunch() {
if (departRepository.getIsFirstLaunch()) {
_isFirstLaunch.value = true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class OnboardingDepartActivity : BaseActivity<ActivityOnboardingDepartBinding, D
private var emptyList = arrayListOf<String>("")

override fun initStartView() {
viewModel.checkFirstLaunch()

// 학과 리스트
items =
resources.getStringArray(R.array.dmu_department_list).toCollection(ArrayList<String>())
Expand Down Expand Up @@ -60,7 +58,8 @@ class OnboardingDepartActivity : BaseActivity<ActivityOnboardingDepartBinding, D
override fun onTextChanged(charSequence: CharSequence?, i: Int, i1: Int, i2: Int) = Unit

override fun afterTextChanged(editable: Editable?) {
val searchText = binding.etOnboardingDepartSearch.text.toString().replace("\\s".toRegex(), "")
val searchText =
binding.etOnboardingDepartSearch.text.toString().replace("\\s".toRegex(), "")
searchList = ArrayList<String>()

if (searchText.isEmpty()) {
Expand Down Expand Up @@ -99,16 +98,9 @@ class OnboardingDepartActivity : BaseActivity<ActivityOnboardingDepartBinding, D
private fun getDepart(items: ArrayList<String>) {
return binding.btnOnboardingDepartNext.setOnClickListener {
viewModel.setDepartment(items[viewModel.selectDepartPosition.value ?: 0])
if (viewModel.isFirstLaunch.value == true) {
val intent = Intent(this, OnboardingKeywordActivity::class.java)
startActivity(intent)
finish()
} else {
val intent = Intent(this, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(intent)
finish()
}
val intent = Intent(this, OnboardingKeywordActivity::class.java)
startActivity(intent)
finish()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ class KeywordActivity : BaseActivity<ActivityKeywordBinding, KeywordViewModel>()
}

override fun initAfterBinding() {
viewModel.checkFirstLaunch()
viewModel.getLocalKeywordList()

binding.btnKeywordComplete.setOnClickListener {
viewModel.subscribeCheckedKeyword()
setResult(RESULT_OK)
finish()
}
Expand All @@ -48,7 +46,6 @@ class KeywordActivity : BaseActivity<ActivityKeywordBinding, KeywordViewModel>()
}

private fun setCheckChipChange(vararg chipGroups: ChipGroup) {

for (chipGroup in chipGroups) {
for (index in 0 until chipGroup.childCount) {
val chip: Chip = chipGroup.getChildAt(index) as Chip
Expand Down
Loading
Loading