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
class LoggingLiveDataMethodVisitor( | |
private val methodVisitor: MethodVisitor | |
) : MethodVisitor(ASM9, methodVisitor) { | |
override fun visitMethodInsn( | |
opcode: Int, | |
owner: String?, | |
name: String?, | |
descriptor: String?, | |
isInterface: Boolean |
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
class LoggingLiveDataClassVisitor( | |
private val classVisitor: ClassVisitor | |
) : ClassVisitor(ASM9, classVisitor) { | |
override fun visitMethod( | |
access: Int, | |
name: String?, | |
descriptor: String?, | |
signature: String?, | |
exceptions: Array<out String>? |
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
val classReader = ClassReader(inputBytes) | |
val classWriter = ClassWriter(classReader, 0) | |
val classVisitor = LoggingLiveDataClassVisitor(classWriter) | |
classReader.accept(classVisitor, 0) | |
outputBytes = classWriter.toByteArray() |
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
class LoggingLiveDataTransform(private val logger: Logger) : Transform() { | |
override fun getName(): String = javaClass.simpleName | |
override fun applyToVariant(variant: VariantInfo) = variant.isDebuggable | |
override fun getInputTypes(): Set<QualifiedContent.ContentType> = | |
setOf(QualifiedContent.DefaultContentType.CLASSES) | |
override fun getScopes(): MutableSet<in QualifiedContent.Scope> = |
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
project.plugins.withType(AppPlugin::class.java) { plugin -> | |
project.extensions.configure(AppExtension::class.java) { appExtension -> | |
appExtension.registerTransform(LoggingLiveDataTransform(project.logger)) | |
} | |
} |
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
viewModel.currentTime.observe(this) { | |
Log.d("LiveDataDebug", "observer called") | |
binding.time.text = it.toString() | |
} |
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
@HiltViewModel | |
class HomeViewModel @Inject constructor( | |
private val redditRepository: RedditRepository | |
) : ViewModel() { | |
private val _reddits: MutableLiveData<RedditListing> = MutableLiveData() | |
val reddits: LiveData<RedditListing> = _reddits | |
init { | |
viewModelScope.launch { |
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
@AndroidEntryPoint | |
class HomeFragment : Fragment() { | |
private val homeViewModel by viewModels<HomeViewModel>() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
Log.i(Constants.FLOW_TAG, "Fragment onCreate...") | |
} |
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
@HiltViewModel | |
class HomeViewModel @Inject constructor( | |
private val redditRepository: RedditRepository | |
) : ViewModel() { | |
val reddits: LiveData<RedditListing> | |
get() = redditRepository.topReddits.asLiveData(context = Dispatchers.IO) | |
} |
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
class RedditRepository @Inject constructor(private val redditService: RedditService) { | |
val topReddits: Flow<RedditListing> = flow { | |
Log.i(FLOW_TAG, "flow running...") | |
emit(redditService.top()) | |
} | |
} |