Skip to content

Commit

Permalink
[feat]: search in crash logs + small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
F0x1d committed Aug 13, 2024
1 parent 5a07a13 commit 17a525f
Show file tree
Hide file tree
Showing 68 changed files with 330 additions and 411 deletions.
6 changes: 3 additions & 3 deletions app/src/main/kotlin/com/f0x1d/logfox/LogFoxApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import android.app.Application
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationManagerCompat
import com.f0x1d.logfox.context.LOGGING_STATUS_CHANNEL_ID
import com.f0x1d.logfox.context.RECORDING_STATUS_CHANNEL_ID
import com.f0x1d.logfox.context.notificationManagerCompat
import com.f0x1d.logfox.arch.LOGGING_STATUS_CHANNEL_ID
import com.f0x1d.logfox.arch.RECORDING_STATUS_CHANNEL_ID
import com.f0x1d.logfox.arch.notificationManagerCompat
import com.f0x1d.logfox.preferences.shared.AppPreferences
import com.f0x1d.logfox.strings.Strings
import com.google.android.material.color.DynamicColors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.f0x1d.logfox.di.logs
import android.app.PendingIntent
import android.content.Context
import com.f0x1d.feature.logging.service.MainActivityPendingIntentProvider
import com.f0x1d.logfox.intents.makeActivityPendingIntent
import com.f0x1d.logfox.arch.makeActivityPendingIntent
import com.f0x1d.logfox.ui.activity.MainActivity
import dagger.Binds
import dagger.Module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.f0x1d.logfox.di.settings

import android.content.Context
import com.f0x1d.feature.logging.service.LoggingService
import com.f0x1d.logfox.context.sendService
import com.f0x1d.logfox.arch.sendService
import com.f0x1d.logfox.feature.settings.LoggingServiceDelegate
import dagger.Binds
import dagger.Module
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/com/f0x1d/logfox/receiver/BootReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.f0x1d.feature.logging.service.LoggingService
import com.f0x1d.logfox.arch.hasPermissionToReadLogs
import com.f0x1d.logfox.arch.startForegroundServiceAvailable
import com.f0x1d.logfox.context.hasPermissionToReadLogs
import com.f0x1d.logfox.context.toast
import com.f0x1d.logfox.arch.toast
import com.f0x1d.logfox.preferences.shared.AppPreferences
import com.f0x1d.logfox.strings.Strings
import com.f0x1d.logfox.terminals.ShizukuTerminal
Expand Down
13 changes: 8 additions & 5 deletions app/src/main/kotlin/com/f0x1d/logfox/ui/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ import androidx.transition.TransitionManager
import com.f0x1d.logfox.R
import com.f0x1d.logfox.arch.contrastedNavBarAvailable
import com.f0x1d.logfox.arch.gesturesAvailable
import com.f0x1d.logfox.arch.hasNotificationsPermission
import com.f0x1d.logfox.arch.isHorizontalOrientation
import com.f0x1d.logfox.arch.ui.activity.BaseViewModelActivity
import com.f0x1d.logfox.context.hasNotificationsPermission
import com.f0x1d.logfox.context.isHorizontalOrientation
import com.f0x1d.logfox.arch.viewmodel.Event
import com.f0x1d.logfox.databinding.ActivityMainBinding
import com.f0x1d.logfox.model.event.Event
import com.f0x1d.logfox.navigation.Directions
import com.f0x1d.logfox.strings.Strings
import com.f0x1d.logfox.ui.Icons
import com.f0x1d.logfox.viewmodel.MainViewModel
import com.f0x1d.logfox.viewmodel.OpenSetup
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint

Expand Down Expand Up @@ -125,8 +126,10 @@ class MainActivity: BaseViewModelActivity<MainViewModel, ActivityMainBinding>(),
}

override fun onEvent(event: Event) {
when (event.type) {
MainViewModel.EVENT_TYPE_SETUP -> navController.navigate(Directions.action_global_setupFragment)
super.onEvent(event)

when (event) {
is OpenSetup -> navController.navigate(Directions.action_global_setupFragment)
}
}

Expand Down
11 changes: 5 additions & 6 deletions app/src/main/kotlin/com/f0x1d/logfox/viewmodel/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package com.f0x1d.logfox.viewmodel
import android.app.Application
import android.content.Intent
import com.f0x1d.feature.logging.service.LoggingService
import com.f0x1d.logfox.arch.hasPermissionToReadLogs
import com.f0x1d.logfox.arch.startForegroundServiceAvailable
import com.f0x1d.logfox.arch.viewmodel.BaseViewModel
import com.f0x1d.logfox.context.hasPermissionToReadLogs
import com.f0x1d.logfox.arch.viewmodel.Event
import com.f0x1d.logfox.preferences.shared.AppPreferences
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
Expand All @@ -16,10 +17,6 @@ class MainViewModel @Inject constructor(
application: Application,
): BaseViewModel(application) {

companion object {
const val EVENT_TYPE_SETUP = "setup"
}

var askedNotificationsPermission
get() = appPreferences.askedNotificationsPermission
set(value) { appPreferences.askedNotificationsPermission = value }
Expand All @@ -39,7 +36,9 @@ class MainViewModel @Inject constructor(
ctx.startService(it)
}
} else {
sendEvent(EVENT_TYPE_SETUP)
sendEvent(OpenSetup)
}
}
}

data object OpenSetup : Event
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ internal fun DependencyHandlerScope.coreDependencies(withCompose: Boolean = true
implementation(project(":strings"))

implementation(project(":core:core-arch"))
implementation(project(":core:core-context"))
implementation(project(":core:core-database"))
implementation(project(":core:core-datetime"))
implementation(project(":core:core-intents"))
implementation(project(":core:core-io"))
implementation(project(":core:core-navigation"))
implementation(project(":core:core-preferences"))
implementation(project(":core:core-terminals"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<receiver android:name=".receiver.CopyReceiver" />
<receiver android:name="com.f0x1d.logfox.arch.receiver.CopyReceiver" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.f0x1d.logfox.context
package com.f0x1d.logfox.arch

import android.Manifest
import android.annotation.SuppressLint
Expand All @@ -15,7 +15,6 @@ import android.widget.Toast
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService
import com.f0x1d.logfox.arch.shouldRequestNotificationsPermission
import com.f0x1d.logfox.strings.Strings
import java.io.File
import kotlin.system.exitProcess
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.f0x1d.logfox.context
package com.f0x1d.logfox.arch

import android.content.Context
import android.net.Uri
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.f0x1d.logfox.context
package com.f0x1d.logfox.arch

const val LOGGING_STATUS_CHANNEL_ID = "logging"
const val RECORDING_STATUS_CHANNEL_ID = "recording"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.f0x1d.logfox.intents
package com.f0x1d.logfox.arch

import android.app.Activity
import android.app.PendingIntent
Expand All @@ -7,7 +7,6 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.f0x1d.logfox.arch.mutablePendingIntentAvailable

const val CRASH_DETAILS_INTENT_ID = 0
const val COPY_CRASH_INTENT_ID = 1
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.f0x1d.logfox.io
package com.f0x1d.logfox.arch.io

import java.io.OutputStream
import java.util.zip.ZipOutputStream
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.f0x1d.logfox.io
package com.f0x1d.logfox.arch.io

import java.io.File
import java.util.zip.ZipEntry
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.f0x1d.logfox.context.receiver
package com.f0x1d.logfox.arch.receiver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.f0x1d.logfox.context.copyText
import com.f0x1d.logfox.context.notificationManagerCompat
import com.f0x1d.logfox.context.toast
import com.f0x1d.logfox.arch.copyText
import com.f0x1d.logfox.arch.notificationManagerCompat
import com.f0x1d.logfox.arch.toast
import com.f0x1d.logfox.strings.Strings

class CopyReceiver: BroadcastReceiver() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
import com.f0x1d.logfox.arch.ui.base.SimpleLifecycleOwner
import com.f0x1d.logfox.arch.ui.enableEdgeToEdge
import com.f0x1d.logfox.arch.ui.snackbar
import dagger.hilt.EntryPoint
Expand All @@ -14,7 +15,7 @@ import dev.chrisbanes.insetter.applyInsetter
import io.github.inflationx.viewpump.ViewPump
import io.github.inflationx.viewpump.ViewPumpContextWrapper

abstract class BaseActivity<T : ViewBinding>: AppCompatActivity() {
abstract class BaseActivity<T : ViewBinding>: AppCompatActivity(), SimpleLifecycleOwner {

protected lateinit var binding: T

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package com.f0x1d.logfox.arch.ui.activity
import android.os.Bundle
import androidx.viewbinding.ViewBinding
import com.f0x1d.logfox.arch.viewmodel.BaseViewModel
import com.f0x1d.logfox.model.event.Event
import com.f0x1d.logfox.arch.viewmodel.Event
import com.f0x1d.logfox.arch.viewmodel.ShowSnackbar

abstract class BaseViewModelActivity<T : BaseViewModel, D : ViewBinding>: BaseActivity<D>() {

Expand All @@ -12,20 +13,12 @@ abstract class BaseViewModelActivity<T : BaseViewModel, D : ViewBinding>: BaseAc
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

viewModel.eventsData.observe(this) {
if (it.isConsumed) return@observe

onEvent(it)
}

viewModel.snackbarEventsData.observe(this) {
if (it.isConsumed) return@observe
viewModel.eventsFlow.collectWithLifecycle(collector = ::onEvent)
}

it.consume<String>()?.also { message ->
snackbar(message)
}
open fun onEvent(event: Event) {
when (event) {
is ShowSnackbar -> snackbar(event.text)
}
}

open fun onEvent(event: Event) = Unit
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.f0x1d.logfox.arch.ui.base

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.coroutineScope
import androidx.lifecycle.repeatOnLifecycle
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.launch

interface SimpleLifecycleOwner {

val lifecycle: Lifecycle
fun getViewLifecycleOwner(): LifecycleOwner? = null

fun <T> Flow<T>.collectWithLifecycle(
state: Lifecycle.State = Lifecycle.State.STARTED,
collector: FlowCollector<T>,
) {
val lifecycle = getViewLifecycleOwner()?.lifecycle ?: lifecycle

lifecycle.coroutineScope.launch {
lifecycle.repeatOnLifecycle(state) {
collect(collector)
}
}
}
}

interface SimpleFragmentLifecycleOwner : SimpleLifecycleOwner {
override fun getViewLifecycleOwner(): LifecycleOwner
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.viewbinding.ViewBinding
import com.f0x1d.logfox.arch.ui.base.SimpleFragmentLifecycleOwner
import com.f0x1d.logfox.arch.ui.enableEdgeToEdge
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.launch

abstract class BaseBottomSheet<T : ViewBinding>: BottomSheetDialogFragment() {
abstract class BaseBottomSheet<T : ViewBinding>: BottomSheetDialogFragment(), SimpleFragmentLifecycleOwner {

private var mutableBinding: T? = null
protected val binding: T get() = mutableBinding!!
Expand Down Expand Up @@ -49,15 +44,6 @@ abstract class BaseBottomSheet<T : ViewBinding>: BottomSheetDialogFragment() {
return dialog
}

protected fun <T> Flow<T>.collectWithLifecycle(
state: Lifecycle.State = Lifecycle.State.STARTED,
collector: FlowCollector<T>,
) = viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(state) {
collect(collector)
}
}

override fun onDestroyView() {
super.onDestroyView()
mutableBinding = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@ import android.os.Bundle
import android.view.View
import androidx.viewbinding.ViewBinding
import com.f0x1d.logfox.arch.viewmodel.BaseViewModel
import com.f0x1d.logfox.model.event.Event
import com.f0x1d.logfox.arch.viewmodel.Event

abstract class BaseViewModelBottomSheet<T : BaseViewModel, D : ViewBinding>: BaseBottomSheet<D>() {

abstract val viewModel: T

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

viewModel.eventsData.observe(viewLifecycleOwner) {
if (it.isConsumed) return@observe

onEvent(it)
}
viewModel.eventsFlow.collectWithLifecycle(collector = ::onEvent)
}

open fun onEvent(event: Event) = Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.viewbinding.ViewBinding
import com.f0x1d.logfox.arch.ui.base.SimpleFragmentLifecycleOwner
import com.f0x1d.logfox.arch.ui.snackbar
import dev.chrisbanes.insetter.applyInsetter
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.launch

abstract class BaseFragment<T : ViewBinding>: Fragment() {
abstract class BaseFragment<T : ViewBinding>: Fragment(), SimpleFragmentLifecycleOwner {

private var mutableBinding: T? = null
protected val binding: T get() = mutableBinding!!
Expand All @@ -37,15 +32,6 @@ abstract class BaseFragment<T : ViewBinding>: Fragment() {
binding.onViewCreated(view, savedInstanceState)
}

protected fun <T> Flow<T>.collectWithLifecycle(
state: Lifecycle.State = Lifecycle.State.STARTED,
collector: FlowCollector<T>,
) = viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(state) {
collect(collector)
}
}

override fun onDestroyView() {
super.onDestroyView()
mutableBinding = null
Expand Down
Loading

0 comments on commit 17a525f

Please sign in to comment.