Skip to content

Commit

Permalink
[MIN-52] feat : 로그인 api 통신 구현 및 테스트 완료 (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
KDW03 committed Mar 27, 2023
1 parent 147103f commit 1f65d9e
Show file tree
Hide file tree
Showing 41 changed files with 673 additions and 210 deletions.
17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ dependencies {
kapt "com.google.dagger:hilt-android-compiler:$rootProject.hiltVersion"


// Navigation
api "androidx.navigation:navigation-fragment-ktx:$rootProject.nav_version"
api "androidx.navigation:navigation-ui-ktx:$rootProject.nav_version"


implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'com.google.android.material:material:1.8.0'
Expand Down
25 changes: 13 additions & 12 deletions app/src/main/java/com/najudoryeong/mineme/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package com.najudoryeong.mineme

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.activity.viewModels
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.AppBarConfiguration
Expand All @@ -14,29 +14,33 @@ import androidx.navigation.ui.setupWithNavController
import com.najudoryeong.mineme.common_ui.MainActivityUtil
import com.najudoryeong.mineme.databinding.ActivityMainBinding
import dagger.hilt.android.AndroidEntryPoint
import com.najudoryeong.mineme.story.R.id.storyFragment
import com.najudoryeong.mineme.home.R.id.homeFragment
import com.najudoryeong.mineme.home.ui.HomeFragment
import com.najudoryeong.mineme.setting.fragment.ui.SettingFragment
import com.najudoryeong.mineme.story.ui.StoryFragment


// 하위 모듈이 MainViewModel 코드에 접근할 수 있게 MainViewModelUtil 상속 구현
@AndroidEntryPoint
class MainActivity : AppCompatActivity(), MainActivityUtil {

private lateinit var binding: ActivityMainBinding
private lateinit var appBarConfiguration: AppBarConfiguration
private lateinit var binding: ActivityMainBinding
private lateinit var navController: NavController
private val model: MainViewModel by viewModels()
private val mainViewModel: MainViewModel by viewModels()


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
binding.viewModel = model
binding.viewModel = mainViewModel

initAppBar()
initBottomNav()
}

override fun onSupportNavigateUp(): Boolean {
return navController.navigateUp() || super.onSupportNavigateUp()
}

private fun initBottomNav() {
val navHostFragment =
Expand All @@ -46,20 +50,19 @@ class MainActivity : AppCompatActivity(), MainActivityUtil {
// appbar 구성 요소 설정
// 바텀네비게이션과 연결하면 해당 프래그먼트에 네비게이션으로는 backButton x
appBarConfiguration = AppBarConfiguration(
setOf(homeFragment, storyFragment, R.id.nav_setting)
setOf(R.id.nav_home, com.najudoryeong.mineme.story.R.id.storyFragment, R.id.nav_setting)
)

// navController 와 actionbar 연결
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration)
// NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration)
NavigationUI.setupActionBarWithNavController(this, navController)
binding.bottomNavigationView.run {
setupWithNavController(navController)
itemIconTintList = null
}

}



private fun initAppBar() {
setSupportActionBar(binding.toolbar)
supportActionBar?.run {
Expand All @@ -71,7 +74,6 @@ class MainActivity : AppCompatActivity(), MainActivityUtil {

private fun showAppBar() {
binding.bottomAppBar.visibility = View.VISIBLE
binding.fab.visibility = View.VISIBLE
binding.topAppBar.visibility = View.VISIBLE
}

Expand All @@ -84,7 +86,6 @@ class MainActivity : AppCompatActivity(), MainActivityUtil {

override fun setVisibilityBottomAppbar(visibilityMode: Int) {
binding.bottomAppBar.visibility = visibilityMode
binding.fab.visibility = visibilityMode
}

override fun setVisibilityTopAppBar(visibilityMode: Int) {
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/com/najudoryeong/mineme/MainViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.najudoryeong.mineme


import androidx.lifecycle.ViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow



class MainViewModel : ViewModel() {


}
/*
private val _toolbarTitle = MutableLiveData<String>()
val toolbarTitle: LiveData<String>
Expand All @@ -33,4 +35,3 @@ class MainViewModel : ViewModel() {
_visibilityTopAppBar.value = visibilityMode
}
*/
}
18 changes: 1 addition & 17 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:elevation="9dp"
app:fabAlignmentMode="center"
app:fabAnchorMode="cradle"
app:removeEmbeddedFabElevation="false">

app:elevation="9dp">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
Expand All @@ -72,18 +68,6 @@

</com.google.android.material.bottomappbar.BottomAppBar>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginBottom="20dp"
android:contentDescription="TODO"
android:src="@drawable/bottom_center"
app:fabSize="normal"
app:layout_anchor="@id/bottomAppBar"
app:maxImageSize="47dp"
app:tint="@null" />


</androidx.coordinatorlayout.widget.CoordinatorLayout>

Expand Down
12 changes: 1 addition & 11 deletions app/src/main/res/menu/bottom_nav_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,7 @@
android:id="@+id/nav_story"
android:icon="@drawable/bottom_story_on_off"
android:title="" />

<item
android:id="@+id/placeholder"
android:title="" />

<!-- todo fix -->
<item
android:id="@+id/fix"
android:icon="@drawable/bottom_story_on_off"
android:title="" />


<item
android:id="@+id/nav_setting"
android:icon="@drawable/bottom_setting_on_off"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.navigation.NavController
import androidx.navigation.Navigation
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.fragment.findNavController

abstract class BaseFragment<T : ViewDataBinding>(val fragment: FragmentInfoUtil) : Fragment() {
abstract class BaseFragment<T : ViewDataBinding>(
val fragment: FragmentInfoUtil,
) : Fragment() {
private var _binding: T? = null
val binding get() = _binding!!

// baseFragment를 상속받은 fragment에서만 제한된 작업 initView 에서 진행
abstract fun initView()

open fun menuClick(){}
open fun backClick() : Boolean = false

Expand All @@ -29,6 +33,7 @@ abstract class BaseFragment<T : ViewDataBinding>(val fragment: FragmentInfoUtil)
_binding = DataBindingUtil.inflate(inflater, fragment.layoutID, container, false)
//activity는 MainActivity를 가르킴
//MainViewModelUtil 통해 MainViewModel 코드에 접근

//todo methode
(activity as MainActivityUtil).run {
setToolbarTitle(getString(fragment.toolbarText))
Expand Down Expand Up @@ -69,7 +74,6 @@ abstract class BaseFragment<T : ViewDataBinding>(val fragment: FragmentInfoUtil)

override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
val navController = findNavController()

with(navController) {
when (menuItem.itemId) {
android.R.id.home -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DialogForDateNoDay(context: Context,

binding = DialogForDatepickerNoDayBinding.inflate(layoutInflater).apply {

pickerYear.maxValue = 2099
pickerYear.maxValue = 2050
pickerYear.minValue = 1980

pickerYear.value = calendar.get(Calendar.YEAR)
Expand Down
1 change: 1 addition & 0 deletions common-ui/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="margin_normal">21dp</dimen>
<dimen name="padding_normal">21dp</dimen>
<dimen name="btn_corner">21dp</dimen>
<dimen name="dialog_radius">17dp</dimen>
<dimen name="basic_spacingExtra">4sp</dimen>
Expand Down
1 change: 1 addition & 0 deletions common-ui/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ todo 공통 사용 리소스 common_ui
</style>

<style name="basic_btn">
<item name="android:textSize">17sp</item>
<item name="android:background">@drawable/btn_shape</item>
<item name="android:fontFamily">@font/cafe24_ssurround_air</item>
<item name="android:gravity">center</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package com.najudoryeong.mineme.common.data.dto
data class LoginRequest(
val accessToken: String,
val providerType: String,
val userName: String
)
val username : String ="dowoo"
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import com.najudoryeong.mineme.common.data.entity.LoginData

data class LoginResponse(
val success: Boolean,
val data: LoginData
val data: LoginData,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package com.najudoryeong.mineme.common.data.source

import com.najudoryeong.mineme.common.data.dto.LoginRequest
import com.najudoryeong.mineme.common.data.dto.LoginResponse
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.POST

interface AuthService {
@POST("api/v1/oauth/login")
suspend fun login(@Body loginRequest: LoginRequest): LoginResponse
@POST("api/v1/auth/kakao")
suspend fun postToken(@Body loginRequest: LoginRequest): Response<LoginResponse>
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.najudoryeong.mineme.common.di

import com.najudoryeong.mineme.common.data.source.AuthService
import com.najudoryeong.mineme.common.data.source.UserService
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand All @@ -19,10 +18,12 @@ class NetworkModule {
return retrofit.create(AuthService::class.java)
}

/*
@Singleton
@Provides
fun provideUserService(retrofit: Retrofit): UserService {
return retrofit.create(UserService::class.java)
}
*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.najudoryeong.mineme.common.domain.usecase

import com.najudoryeong.mineme.common.data.dto.LoginRequest
import com.najudoryeong.mineme.common.data.dto.LoginResponse
import com.najudoryeong.mineme.common.data.source.AuthService
import retrofit2.Response
import javax.inject.Inject

class AuthUseCase @Inject constructor(
private val authService: AuthService
){
suspend fun login(token: String, providerType: String = "KAKAO"): Response<LoginResponse> {
return authService.postToken(LoginRequest(token, providerType))
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.najudoryeong.mineme.foundation.util

const val BASE_URL = "http://13.125.67.47:18080/"
const val BASE_URL = "https://dev.mineme.works/"

4 changes: 4 additions & 0 deletions home/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ dependencies {
kapt "com.google.dagger:hilt-android-compiler:$rootProject.hiltVersion"


// Navigation
api "androidx.navigation:navigation-fragment-ktx:$rootProject.nav_version"
api "androidx.navigation:navigation-ui-ktx:$rootProject.nav_version"

implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'com.google.android.material:material:1.8.0'
Expand Down
Loading

0 comments on commit 1f65d9e

Please sign in to comment.