-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #286 from boostcampwm-2022/chore/buildSrc
buildSrc 에서 version catalog 방식으로 변경
- Loading branch information
Showing
29 changed files
with
876 additions
and
581 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
146 changes: 146 additions & 0 deletions
146
app/src/main/java/com/lighthouse/utils/log/ComponentLogger.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 |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package com.lighthouse.utils.log | ||
|
||
import android.app.Activity | ||
import android.app.Application | ||
import android.content.Context | ||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.FragmentActivity | ||
import androidx.fragment.app.FragmentManager | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
private const val loggerTag = "Logger" | ||
|
||
private inline val <T : Any> T.javaClassName: String | ||
get() = javaClass.name | ||
|
||
private fun Fragment.printLifecycle(lifecycleScope: String) { | ||
Timber.tag(loggerTag).d("[Fragment] $lifecycleScope - $javaClassName(${hashCode()})") | ||
} | ||
|
||
private fun Activity.printLifecycle(lifecycleScope: String) { | ||
Timber.tag(loggerTag).d("[Activity] $lifecycleScope - $javaClassName(${hashCode()})") | ||
} | ||
|
||
class ComponentLogger @Inject constructor() { | ||
fun initialize(application: Application) { | ||
application.registerActivityLifecycleCallbacks( | ||
object : Application.ActivityLifecycleCallbacks { | ||
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) { | ||
activity.printLifecycle("onCreate") | ||
handleActivity(activity) | ||
} | ||
|
||
override fun onActivityStarted(activity: Activity) { | ||
activity.printLifecycle("onStart") | ||
} | ||
|
||
override fun onActivityResumed(activity: Activity) { | ||
activity.printLifecycle("onResume") | ||
} | ||
|
||
override fun onActivityPaused(activity: Activity) { | ||
activity.printLifecycle("onPause") | ||
} | ||
|
||
override fun onActivityStopped(activity: Activity) { | ||
activity.printLifecycle("onStop") | ||
} | ||
|
||
override fun onActivitySaveInstanceState( | ||
activity: Activity, | ||
savedInstanceState: Bundle | ||
) { | ||
activity.printLifecycle("onSaveInstance") | ||
} | ||
|
||
override fun onActivityDestroyed(activity: Activity) { | ||
activity.printLifecycle("onDestroy") | ||
} | ||
} | ||
) | ||
} | ||
|
||
private fun handleActivity(activity: Activity) { | ||
if (activity is FragmentActivity) { | ||
activity.supportFragmentManager.registerFragmentLifecycleCallbacks( | ||
object : FragmentManager.FragmentLifecycleCallbacks() { | ||
override fun onFragmentAttached( | ||
fm: FragmentManager, | ||
f: Fragment, | ||
context: Context | ||
) { | ||
super.onFragmentAttached(fm, f, context) | ||
f.printLifecycle("onAttach") | ||
} | ||
|
||
override fun onFragmentCreated( | ||
fm: FragmentManager, | ||
f: Fragment, | ||
savedInstanceState: Bundle? | ||
) { | ||
super.onFragmentCreated(fm, f, savedInstanceState) | ||
f.printLifecycle("onCreate") | ||
} | ||
|
||
override fun onFragmentViewCreated( | ||
fm: FragmentManager, | ||
f: Fragment, | ||
v: View, | ||
savedInstanceState: Bundle? | ||
) { | ||
super.onFragmentViewCreated(fm, f, v, savedInstanceState) | ||
f.printLifecycle("onViewCreated") | ||
} | ||
|
||
override fun onFragmentStarted(fm: FragmentManager, f: Fragment) { | ||
super.onFragmentStarted(fm, f) | ||
f.printLifecycle("onStart") | ||
} | ||
|
||
override fun onFragmentResumed(fm: FragmentManager, f: Fragment) { | ||
super.onFragmentResumed(fm, f) | ||
f.printLifecycle("onResume") | ||
} | ||
|
||
override fun onFragmentPaused(fm: FragmentManager, f: Fragment) { | ||
super.onFragmentPaused(fm, f) | ||
f.printLifecycle("onPause") | ||
} | ||
|
||
override fun onFragmentStopped(fm: FragmentManager, f: Fragment) { | ||
super.onFragmentStopped(fm, f) | ||
f.printLifecycle("onStop") | ||
} | ||
|
||
override fun onFragmentSaveInstanceState( | ||
fm: FragmentManager, | ||
f: Fragment, | ||
outState: Bundle | ||
) { | ||
super.onFragmentSaveInstanceState(fm, f, outState) | ||
f.printLifecycle("onSaveInstance") | ||
} | ||
|
||
override fun onFragmentViewDestroyed(fm: FragmentManager, f: Fragment) { | ||
super.onFragmentViewDestroyed(fm, f) | ||
f.printLifecycle("onViewDestroy") | ||
} | ||
|
||
override fun onFragmentDestroyed(fm: FragmentManager, f: Fragment) { | ||
super.onFragmentDestroyed(fm, f) | ||
f.printLifecycle("onDestroy") | ||
} | ||
|
||
override fun onFragmentDetached(fm: FragmentManager, f: Fragment) { | ||
super.onFragmentDetached(fm, f) | ||
f.printLifecycle("onDetach") | ||
} | ||
}, | ||
true | ||
) | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/lighthouse/utils/log/CustomTimberTree.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.lighthouse.utils.log | ||
|
||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
class CustomTimberTree @Inject constructor() : Timber.DebugTree() { | ||
override fun createStackElementTag(element: StackTraceElement): String { | ||
return "${element.className}:${element.lineNumber}#${element.methodName}" | ||
} | ||
} |
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 @@ | ||
/build |
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 @@ | ||
/build |
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,45 @@ | ||
plugins { | ||
`kotlin-dsl` // enable the Kotlin-DSL | ||
} | ||
|
||
group = "com.lighthouse.beep.buildlogic" | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_11 | ||
targetCompatibility = JavaVersion.VERSION_11 | ||
} | ||
|
||
dependencies { | ||
compileOnly(libs.android.gradlePlugin) | ||
compileOnly(libs.kotlin.gradlePlugin) | ||
compileOnly(libs.hilt.gradlePlugin) | ||
} | ||
|
||
gradlePlugin { | ||
plugins { | ||
register("androidApplication") { | ||
id = "beep.android.application" | ||
implementationClass = "AndroidApplicationConventionPlugin" | ||
} | ||
register("androidApplicationCompose") { | ||
id = "beep.android.application.compose" | ||
implementationClass = "AndroidApplicationComposeConventionPlugin" | ||
} | ||
register("androidLibrary") { | ||
id = "beep.android.library" | ||
implementationClass = "AndroidLibraryConventionPlugin" | ||
} | ||
register("androidLibraryCompose") { | ||
id = "beep.android.library.compose" | ||
implementationClass = "AndroidLibraryComposeConventionPlugin" | ||
} | ||
register("androidHilt") { | ||
id = "beep.android.hilt" | ||
implementationClass = "AndroidHiltConventionPlugin" | ||
} | ||
register("javaLibrary") { | ||
id = "beep.java.library" | ||
implementationClass = "JavaLibraryConventionPlugin" | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
build-logic/convention/src/main/java/AndroidApplicationComposeConventionPlugin.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension | ||
import com.lighthouse.convention.configureAndroidCompose | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.getByType | ||
|
||
class AndroidApplicationComposeConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
pluginManager.apply("com.android.application") | ||
val extension = extensions.getByType<BaseAppModuleExtension>() | ||
configureAndroidCompose(extension) | ||
} | ||
} | ||
} |
Oops, something went wrong.