Skip to content

Commit

Permalink
Replace log with timber
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuwu committed Dec 21, 2023
1 parent 393a25f commit b247f11
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.arkbuilders.navigator.presentation.screen.gallery

import android.util.Log
import androidx.recyclerview.widget.DiffUtil
import dev.arkbuilders.arkfilepicker.folders.RootAndFav
import dev.arkbuilders.arklib.ResourceId
Expand Down Expand Up @@ -130,7 +129,7 @@ class GalleryPresenter(
HandleGalleryExternalChangesUseCase

override fun onFirstViewAttach() {
Log.d(GALLERY_SCREEN, "first view attached in GalleryPresenter")
Timber.d(GALLERY_SCREEN, "first view attached in GalleryPresenter")
super.onFirstViewAttach()
presenterScope.launch {
viewState.init()
Expand Down Expand Up @@ -223,7 +222,7 @@ class GalleryPresenter(
}

fun onOpenFabClick() = presenterScope.launch {
Log.d(GALLERY_SCREEN, "[open_resource] clicked at position $currentPos")
Timber.d(GALLERY_SCREEN, "[open_resource] clicked at position $currentPos")

val id = currentItem.id()
val path = index.getPath(id)!!
Expand All @@ -239,14 +238,14 @@ class GalleryPresenter(
}

fun onInfoFabClick() = presenterScope.launch {
Log.d(GALLERY_SCREEN, "[info_resource] clicked at position $currentPos")
Timber.d(GALLERY_SCREEN, "[info_resource] clicked at position $currentPos")

val path = index.getPath(currentItem.id())!!
viewState.showInfoAlert(path, currentItem.resource, currentItem.metadata)
}

fun onShareFabClick() = presenterScope.launch {
Log.d(GALLERY_SCREEN, "[share_resource] clicked at position $currentPos")
Timber.d(GALLERY_SCREEN, "[share_resource] clicked at position $currentPos")
val path = index.getPath(currentItem.id())!!

if (currentItem.metadata is Metadata.Link) {
Expand All @@ -259,13 +258,13 @@ class GalleryPresenter(
}

fun onEditFabClick() = presenterScope.launch {
Log.d(GALLERY_SCREEN, "[edit_resource] clicked at position $currentPos")
Timber.d(GALLERY_SCREEN, "[edit_resource] clicked at position $currentPos")
val path = index.getPath(currentItem.id())!!
viewState.editResource(path)
}

fun onRemoveFabClick() = presenterScope.launch(NonCancellable) {
Log.d(GALLERY_SCREEN, "[remove_resource] clicked at position $currentPos")
Timber.d(GALLERY_SCREEN, "[remove_resource] clicked at position $currentPos")
deleteResource(currentItem.id())
galleryItems.removeAt(currentPos)

Expand Down Expand Up @@ -299,7 +298,7 @@ class GalleryPresenter(
)
)

Log.d(GALLERY_SCREEN, "setting new tags $newTags to $currentItem")
Timber.d(GALLERY_SCREEN, "setting new tags $newTags to $currentItem")

tagsStorage.setTags(id, newTags)
tagsStorage.persist()
Expand Down Expand Up @@ -357,7 +356,7 @@ class GalleryPresenter(
}

private suspend fun deleteResource(resource: ResourceId) {
Log.d(GALLERY_SCREEN, "deleting resource $resource")
Timber.d(GALLERY_SCREEN, "deleting resource $resource")

val path = index.getPath(resource)

Expand Down Expand Up @@ -404,7 +403,7 @@ class GalleryPresenter(
}

fun onBackClick() {
Log.d(GALLERY_SCREEN, "quitting from GalleryPresenter")
Timber.d(GALLERY_SCREEN, "quitting from GalleryPresenter")
viewState.notifySelectedChanged(selectedResources)
viewState.exitFullscreen()
router.exit()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.arkbuilders.navigator.presentation.screen.main

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.forEach
import androidx.core.view.isVisible
Expand All @@ -20,6 +19,7 @@ import kotlinx.coroutines.launch
import ru.terrakok.cicerone.NavigatorHolder
import dev.arkbuilders.arkfilepicker.folders.FoldersRepo
import dev.arkbuilders.arkfilepicker.folders.RootAndFav
import timber.log.Timber
import javax.inject.Inject

class MainActivity : AppCompatActivity(R.layout.activity_main) {
Expand Down Expand Up @@ -50,30 +50,30 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
}

fun init() {
Log.d(MAIN, "initializing")
Timber.d(MAIN, "initializing")
binding.bottomNavigation.setOnApplyWindowInsetsListener(null)
binding.bottomNavigation.setOnItemSelectedListener { item ->
when (item.itemId) {
R.id.page_settings -> {
Log.d(MAIN, "switching to Settings screen")
Timber.d(MAIN, "switching to Settings screen")
router.newRootScreen(Screens.SettingsScreen())
true
}

R.id.page_roots -> {
Log.d(MAIN, "switching to Folders screen")
Timber.d(MAIN, "switching to Folders screen")
router.replaceScreen(Screens.FoldersScreen())
true
}

R.id.page_tags -> {
Log.d(MAIN, "switching to Resources screen")
Timber.d(MAIN, "switching to Resources screen")
lifecycleScope.launch {
val folders = foldersRepo.provideFolders()
if (folders.isEmpty()) {
enterResourceFragmentFailed()
} else {
Log.d(MAIN, "switching to Resources screen")
Timber.d(MAIN, "switching to Resources screen")
router.newRootScreen(
Screens.ResourcesScreen(
RootAndFav(
Expand All @@ -89,7 +89,7 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
}

else -> {
Log.w(MAIN, "no handler found")
Timber.w(MAIN, "no handler found")
true
}
}
Expand All @@ -109,7 +109,7 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {

fun setSelectedTab(menuItemID: Int) {
binding.bottomNavigation.apply {
Log.d(
Timber.d(
MAIN,
"tab with id $menuItemID selected," +
"title: ${menu.findItem(menuItemID).title}"
Expand All @@ -125,13 +125,13 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
}

override fun onResumeFragments() {
Log.d(MAIN, "resuming fragments in MainActivity")
Timber.d(MAIN, "resuming fragments in MainActivity")
super.onResumeFragments()
navigatorHolder.setNavigator(navigator)
}

override fun onPause() {
Log.d(MAIN, "pausing MainActivity")
Timber.d(MAIN, "pausing MainActivity")
super.onPause()
navigatorHolder.removeNavigator()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package dev.arkbuilders.navigator.presentation.screen.resources
import android.content.Intent
import android.os.Bundle
import android.os.SystemClock
import android.util.Log
import android.view.MotionEvent
import android.view.View
import androidx.activity.addCallback
Expand Down Expand Up @@ -45,6 +44,7 @@ import dev.arkbuilders.arkfilepicker.folders.RootAndFav
import dev.arkbuilders.arkfilepicker.presentation.onArkPathPicked
import dev.arkbuilders.arklib.ResourceId
import dev.arkbuilders.arklib.user.tags.Tag
import timber.log.Timber
import java.nio.file.Path
import javax.inject.Inject
import kotlin.io.path.Path
Expand All @@ -70,7 +70,7 @@ class ResourcesFragment :
requireArguments()[ROOT_AND_FAV_KEY] as RootAndFav,
requireArguments().getString(SELECTED_TAG_KEY)
).apply {
Log.d(RESOURCES_SCREEN, "creating ResourcesPresenter")
Timber.d(RESOURCES_SCREEN, "creating ResourcesPresenter")
App.instance.appComponent.inject(this)
}
}
Expand Down Expand Up @@ -106,7 +106,7 @@ class ResourcesFragment :
private var isAscending = true

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Log.d(RESOURCES_SCREEN, "view created in ResourcesFragment")
Timber.d(RESOURCES_SCREEN, "view created in ResourcesFragment")
super.onViewCreated(view, savedInstanceState)
tagsLayoutBinding = TagSelectorTagsLayoutBinding.bind(binding.layoutTags)
dragHandlerBinding =
Expand All @@ -122,7 +122,7 @@ class ResourcesFragment :

override fun init(ascending: Boolean, sortByScoresEnabled: Boolean) =
with(binding) {
Log.d(RESOURCES_SCREEN, "initializing ResourcesFragment")
Timber.d(RESOURCES_SCREEN, "initializing ResourcesFragment")

initResultListeners()
initMenuListeners()
Expand Down Expand Up @@ -150,7 +150,7 @@ class ResourcesFragment :
}
dragHandlerBinding
.switchScores.setOnCheckedChangeListener { _, isChecked ->
Log.d(
Timber.d(
RESOURCES_SCREEN,
"sorting by scores " +
"${if (isChecked) "enabled" else "disabled"}"
Expand All @@ -177,7 +177,7 @@ class ResourcesFragment :
}

override fun onResume() {
Log.d(RESOURCES_SCREEN, "resuming in ResourcesFragment")
Timber.d(RESOURCES_SCREEN, "resuming in ResourcesFragment")
super.onResume()
updateDragHandlerBias()
}
Expand Down Expand Up @@ -462,13 +462,13 @@ class ResourcesFragment :
SystemClock.uptimeMillis() - selectorDragStartTime
val travelDelta = selectorDragStartBias - (1f - selectorHeight)
val travelSpeed = 100f * travelDelta / (travelTime / 1000f)
Log.d(
Timber.d(
RESOURCES_SCREEN,
"draggable bar of tags selector was moved:"
"draggable bar of tags selector was moved:\n" +
"delta=${100f * travelDelta}%" +
"time=${travelTime}ms" +
"speed=$travelSpeed%/sec"
)
Log.d(RESOURCES_SCREEN, "delta=${100f * travelDelta}%")
Log.d(RESOURCES_SCREEN, "time=${travelTime}ms")
Log.d(RESOURCES_SCREEN, "speed=$travelSpeed%/sec")

if (travelTime > DRAG_TRAVEL_TIME_THRESHOLD &&
abs(travelDelta) > DRAG_TRAVEL_DELTA_THRESHOLD &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.arkbuilders.navigator.presentation.screen.resources

import android.util.Log
import dev.arkbuilders.arkfilepicker.folders.FoldersRepo
import dev.arkbuilders.arkfilepicker.folders.RootAndFav
import dev.arkbuilders.arklib.ResourceId
Expand Down Expand Up @@ -160,7 +159,7 @@ class ResourcesPresenter(
)

override fun onFirstViewAttach() {
Log.d(RESOURCES_SCREEN, "first view attached in ResourcesPresenter")
Timber.d(RESOURCES_SCREEN, "first view attached in ResourcesPresenter")
super.onFirstViewAttach()

presenterScope.launch {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.arkbuilders.navigator.presentation.screen.resources.adapter

import android.util.Log
import dev.arkbuilders.navigator.data.preferences.PreferenceKey
import dev.arkbuilders.navigator.data.preferences.Preferences
import dev.arkbuilders.navigator.data.utils.LogTags.RESOURCES_SCREEN
Expand Down Expand Up @@ -29,6 +28,7 @@ import dev.arkbuilders.navigator.di.modules.DefaultDispatcher
import dev.arkbuilders.navigator.di.modules.IoDispatcher
import dev.arkbuilders.navigator.di.modules.MainDispatcher
import kotlinx.coroutines.CoroutineDispatcher
import timber.log.Timber
import java.nio.file.Files
import javax.inject.Inject
import kotlin.io.path.notExists
Expand Down Expand Up @@ -90,15 +90,15 @@ class ResourcesGridPresenter(

fun bindView(view: FileItemViewHolder) = runBlocking {
val item = selection[view.position()]
Log.d(RESOURCES_SCREEN, "binding view for resource ${item.id()}")
Timber.d(RESOURCES_SCREEN, "binding view for resource ${item.id()}")

val path = index.getPath(item.id())!!
val score = scoreStorage.getScore(item.id())

view.reset(selectingEnabled, item.isSelected)
view.setText(path.fileName.toString(), shortFileNames)
view.displayScore(sortByScores, score)
Log.d(
Timber.d(
RESOURCES_SCREEN,
"binding score $score for resource ${item.id()}"
)
Expand Down Expand Up @@ -237,7 +237,7 @@ class ResourcesGridPresenter(

suspend fun shuffleResources() = withContext(defaultDispatcher) {
selection = selection.shuffled()
Log.d(
Timber.d(
RESOURCES_SCREEN,
"reordering resources randomly"
)
Expand All @@ -249,7 +249,7 @@ class ResourcesGridPresenter(
suspend fun unShuffleResources() = withContext(defaultDispatcher) {
sortAllResources()
sortSelectionAndUpdateAdapter()
Log.d(
Timber.d(
RESOURCES_SCREEN,
"reordering resources back from random order"
)
Expand Down Expand Up @@ -376,7 +376,7 @@ class ResourcesGridPresenter(
resources = resources.reversed()
}
}
Log.d(
Timber.d(
RESOURCES_SCREEN,
"sorting by $sorting of ${resources.size} " +
"resources took $sortTime milliseconds"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dev.arkbuilders.navigator.presentation.screen.settings

import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -30,6 +29,7 @@ import dev.arkbuilders.navigator.presentation.utils.toast
import dev.arkbuilders.navigator.data.utils.LogTags.SETTINGS_SCREEN
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject

class SettingsFragment : Fragment(R.layout.fragment_settings) {
Expand Down Expand Up @@ -164,7 +164,7 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
companion object {
fun newInstance() =
SettingsFragment().apply {
Log.d(SETTINGS_SCREEN, "creating new instance")
Timber.d(SETTINGS_SCREEN, "creating new instance")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package dev.arkbuilders.navigator.presentation.view

import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.widget.CompoundButton
import com.google.android.material.switchmaterial.SwitchMaterial
import dev.arkbuilders.navigator.data.utils.LogTags.SETTINGS_SCREEN
import timber.log.Timber

class UserSwitchMaterial(
context: Context,
Expand All @@ -17,7 +17,7 @@ class UserSwitchMaterial(
fun setOnUserCheckedChangeListener(
callback: (isChecked: Boolean) -> Unit
) {
Log.d(
Timber.d(
SETTINGS_SCREEN,
"setOnUserCheckedChangeListener: ${this.id}, " + "$isChecked"
)
Expand Down

0 comments on commit b247f11

Please sign in to comment.