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

[ADD] Navigator 추가 #336

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
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
@@ -0,0 +1,6 @@
package com.runnect.runnect.navigator.base

object Extras {
// common
const val PUBLIC_COURSE_ID = "PUBLIC_COURSE_ID"
}
12 changes: 12 additions & 0 deletions app/src/main/java/com/runnect/runnect/navigator/base/Navigator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.runnect.runnect.navigator.base

import android.app.Activity
import android.content.Intent

interface Navigator {
fun navigateFrom(
activity: Activity,
intentBuilder: Intent.() -> Intent = { this },
withFinish: Boolean = false,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.runnect.runnect.navigator.feature.detail

import com.runnect.runnect.navigator.base.Navigator

interface CourseDetailNavigator : Navigator
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.runnect.runnect.data.dto.CourseData
import com.runnect.runnect.databinding.ActivityCourseDetailBinding
import com.runnect.runnect.domain.entity.CourseDetail
import com.runnect.runnect.domain.entity.EditableCourseDetail
import com.runnect.runnect.navigator.base.Extras
import com.runnect.runnect.presentation.MainActivity
import com.runnect.runnect.presentation.countdown.CountDownActivity
import com.runnect.runnect.presentation.detail.CourseDetailRootScreen.COURSE_DISCOVER
Expand Down Expand Up @@ -98,7 +99,7 @@ class CourseDetailActivity :
intent.getCompatibleSerializableExtra<CourseDetailRootScreen>(EXTRA_ROOT_SCREEN)?.let {
rootScreen = it
}
publicCourseId = intent.getIntExtra(EXTRA_PUBLIC_COURSE_ID, -1)
publicCourseId = intent.getIntExtra(Extras.PUBLIC_COURSE_ID,-1)
Timber.tag("intent-publicCourseId").d("$publicCourseId")
}

Expand Down Expand Up @@ -167,7 +168,11 @@ class CourseDetailActivity :
intent?.let { newIntent ->
newIntent.getCompatibleSerializableExtra<CourseDetailRootScreen>(EXTRA_ROOT_SCREEN)
?.let { rootScreen = it }
publicCourseId = newIntent.getIntExtra(EXTRA_PUBLIC_COURSE_ID, -1)

publicCourseId = newIntent.getIntExtra(
Extras.PUBLIC_COURSE_ID,
-1
)
getCourseDetail()
}
}
Expand Down Expand Up @@ -620,7 +625,6 @@ class CourseDetailActivity :
private const val RES_STAMP_TYPE = "drawable"

private const val EXTRA_ROOT_SCREEN = "rootScreen"
private const val EXTRA_PUBLIC_COURSE_ID = "publicCourseId"
private const val EXTRA_COURSE_DATA = "CourseData"
private const val EXTRA_FRAGMENT_REPLACEMENT_DIRECTION = "fragmentReplacementDirection"
private const val EXTRA_FROM_COURSE_DETAIL = "fromCourseDetail"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.runnect.runnect.presentation.detail.navigator.impl

import com.runnect.runnect.navigator.feature.detail.CourseDetailNavigator
import android.app.Activity
import android.content.Intent
import com.runnect.runnect.presentation.detail.CourseDetailActivity
import com.runnect.runnect.util.extension.startActivityWithAnimation
import javax.inject.Inject

internal class CourseDetailNavigatorImpl @Inject constructor() : CourseDetailNavigator {
override fun navigateFrom(
activity: Activity,
intentBuilder: Intent.() -> Intent,
withFinish: Boolean
) {
activity.startActivityWithAnimation<CourseDetailActivity>(
intentBuilder = intentBuilder,
withFinish = withFinish,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.runnect.runnect.presentation.detail.navigator.module

import com.runnect.runnect.navigator.feature.detail.CourseDetailNavigator
import com.runnect.runnect.presentation.detail.navigator.impl.CourseDetailNavigatorImpl
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
internal abstract class CourseDetailNavigatorModule {

@Singleton
@Binds
abstract fun bindDetailNavigator(navigator: CourseDetailNavigatorImpl): CourseDetailNavigator
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,28 @@ import android.content.Intent
import android.os.Bundle
import androidx.activity.viewModels
import androidx.core.view.isVisible
import com.runnect.runnect.navigator.feature.detail.CourseDetailNavigator
import com.runnect.runnect.R
import com.runnect.runnect.binding.BindingActivity
import com.runnect.runnect.databinding.ActivityProfileBinding
import com.runnect.runnect.presentation.detail.CourseDetailActivity
import com.runnect.runnect.navigator.base.Extras
import com.runnect.runnect.presentation.state.UiStateV2
import com.runnect.runnect.util.analytics.Analytics
import com.runnect.runnect.util.analytics.EventName.VIEW_USER_PROFILE
import com.runnect.runnect.util.extension.applyScreenEnterAnimation
import com.runnect.runnect.util.extension.showSnackbar
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class ProfileActivity : BindingActivity<ActivityProfileBinding>(R.layout.activity_profile) {

@Inject
lateinit var detailNavigator: CourseDetailNavigator

private val viewModel: ProfileViewModel by viewModels()
private lateinit var adapter: ProfileCourseAdapter
private var userId: Int = -1

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.vm = viewModel
Expand Down Expand Up @@ -56,12 +62,13 @@ class ProfileActivity : BindingActivity<ActivityProfileBinding>(R.layout.activit
}

private fun navigateToCourseDetail(courseId: Int) {
Intent(this@ProfileActivity, CourseDetailActivity::class.java).apply {
putExtra(EXTRA_PUBLIC_COURSE_ID, courseId)
addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
startActivity(this)
}
applyScreenEnterAnimation()
detailNavigator.navigateFrom(
this,
intentBuilder = {
putExtra(Extras.PUBLIC_COURSE_ID, courseId)
addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
},
)
}

private fun initBackButtonClickListener() {
Expand Down Expand Up @@ -140,6 +147,5 @@ class ProfileActivity : BindingActivity<ActivityProfileBinding>(R.layout.activit

companion object {
private const val EXTRA_COURSE_USER_ID = "courseUserId"
private const val EXTRA_PUBLIC_COURSE_ID = "publicCourseId"
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
package com.runnect.runnect.util.extension

import android.app.Activity
import android.content.Intent
import com.runnect.runnect.R

/**
* 애니메이션과 함께 새로운 액티비티를 시작합니다.
*
* @param intentBuilder 새로 시작할 액티비티의 [Intent]
* @param withFinish 현재 액티비티를 종료할 지 여부
*/
inline fun <reified T : Activity> Activity.startActivityWithAnimation(
intentBuilder: Intent.() -> Intent = { this },
withFinish: Boolean = false,
) {
startActivity(intentBuilder(Intent(this, T::class.java)))
applyScreenEnterAnimation()

if (withFinish) finish()
}

fun Activity.navigateToPreviousScreenWithAnimation() {
finish()
applyScreenExitAnimation()
Expand Down
Loading