-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat]: group crashes of the same app
- Loading branch information
Showing
15 changed files
with
262 additions
and
23 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
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/f0x1d/logfox/di/viewmodel/AppCrashesViewModelModule.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,32 @@ | ||
package com.f0x1d.logfox.di.viewmodel | ||
|
||
import androidx.lifecycle.SavedStateHandle | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.components.ViewModelComponent | ||
import dagger.hilt.android.scopes.ViewModelScoped | ||
import javax.inject.Qualifier | ||
|
||
@Module | ||
@InstallIn(ViewModelComponent::class) | ||
object AppCrashesViewModelModule { | ||
|
||
@Provides | ||
@ViewModelScoped | ||
@PackageName | ||
fun providePackageName(savedStateHandle: SavedStateHandle) = savedStateHandle.get<String>("package_name")!! | ||
|
||
@Provides | ||
@ViewModelScoped | ||
@AppName | ||
fun provideAppName(savedStateHandle: SavedStateHandle) = savedStateHandle.get<String>("app_name") | ||
} | ||
|
||
@Qualifier | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class PackageName | ||
|
||
@Qualifier | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class AppName |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.f0x1d.logfox.model | ||
|
||
import com.f0x1d.logfox.database.entity.AppCrash | ||
|
||
data class AppCrashesCount( | ||
val lastCrash: AppCrash, | ||
val count: Int = 1 | ||
) |
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
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
61 changes: 61 additions & 0 deletions
61
app/src/main/java/com/f0x1d/logfox/ui/fragment/crashes/AppCrashesFragment.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,61 @@ | ||
package com.f0x1d.logfox.ui.fragment.crashes | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.viewModels | ||
import androidx.navigation.fragment.findNavController | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import com.f0x1d.logfox.adapter.CrashesAdapter | ||
import com.f0x1d.logfox.databinding.FragmentAppCrashesBinding | ||
import com.f0x1d.logfox.extensions.showAreYouSureDialog | ||
import com.f0x1d.logfox.ui.fragment.base.BaseViewModelFragment | ||
import com.f0x1d.logfox.utils.dpToPx | ||
import com.f0x1d.logfox.viewmodel.crashes.AppCrashesViewModel | ||
import com.google.android.material.divider.MaterialDividerItemDecoration | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import dev.chrisbanes.insetter.applyInsetter | ||
|
||
@AndroidEntryPoint | ||
class AppCrashesFragment: BaseViewModelFragment<AppCrashesViewModel, FragmentAppCrashesBinding>() { | ||
|
||
override val viewModel by viewModels<AppCrashesViewModel>() | ||
|
||
private val adapter = CrashesAdapter(click = { | ||
findNavController().navigate( | ||
AppCrashesFragmentDirections.actionAppCrashesFragmentToCrashDetailsActivity(it.lastCrash.id) | ||
) | ||
}, delete = { | ||
showAreYouSureDialog { | ||
viewModel.deleteCrash(it.lastCrash) | ||
} | ||
}) | ||
|
||
override fun inflateBinding(inflater: LayoutInflater, container: ViewGroup?) = FragmentAppCrashesBinding.inflate(inflater, container, false) | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
binding.crashesRecycler.applyInsetter { | ||
type(navigationBars = true) { | ||
padding(vertical = true) | ||
} | ||
} | ||
|
||
binding.toolbar.title = viewModel.appName ?: viewModel.packageName | ||
binding.toolbar.setNavigationOnClickListener { findNavController().popBackStack() } | ||
|
||
binding.crashesRecycler.layoutManager = LinearLayoutManager(requireContext()) | ||
binding.crashesRecycler.addItemDecoration(MaterialDividerItemDecoration(requireContext(), LinearLayoutManager.VERTICAL).apply { | ||
dividerInsetStart = 80.dpToPx.toInt() | ||
dividerInsetEnd = 10.dpToPx.toInt() | ||
isLastItemDecorated = false | ||
}) | ||
binding.crashesRecycler.adapter = adapter | ||
|
||
viewModel.crashes.observe(viewLifecycleOwner) { | ||
adapter.submitList(it) | ||
} | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/f0x1d/logfox/viewmodel/crashes/AppCrashesViewModel.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,41 @@ | ||
package com.f0x1d.logfox.viewmodel.crashes | ||
|
||
import android.app.Application | ||
import androidx.lifecycle.asLiveData | ||
import com.f0x1d.logfox.database.AppDatabase | ||
import com.f0x1d.logfox.database.entity.AppCrash | ||
import com.f0x1d.logfox.di.viewmodel.AppName | ||
import com.f0x1d.logfox.di.viewmodel.PackageName | ||
import com.f0x1d.logfox.model.AppCrashesCount | ||
import com.f0x1d.logfox.repository.logging.CrashesRepository | ||
import com.f0x1d.logfox.viewmodel.base.BaseViewModel | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.distinctUntilChanged | ||
import kotlinx.coroutines.flow.flowOn | ||
import kotlinx.coroutines.flow.map | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class AppCrashesViewModel @Inject constructor( | ||
@PackageName val packageName: String, | ||
@AppName val appName: String?, | ||
private val database: AppDatabase, | ||
private val crashesRepository: CrashesRepository, | ||
application: Application | ||
): BaseViewModel(application) { | ||
|
||
val crashes = database.appCrashDao().getAllAsFlow() | ||
.distinctUntilChanged() | ||
.map { crashes -> | ||
crashes.filter { crash -> | ||
crash.packageName == packageName | ||
}.map { | ||
AppCrashesCount(it) | ||
} | ||
} | ||
.flowOn(Dispatchers.IO) | ||
.asLiveData() | ||
|
||
fun deleteCrash(appCrash: AppCrash) = crashesRepository.delete(appCrash) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
<com.google.android.material.appbar.AppBarLayout | ||
android:id="@+id/app_bar_layout" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:fitsSystemWindows="true" | ||
app:liftOnScroll="true"> | ||
|
||
<com.f0x1d.logfox.ui.view.OpenSansToolbar | ||
android:id="@+id/toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="?actionBarSize" | ||
app:title="@string/crashes" | ||
app:titleCentered="true" | ||
app:navigationIconTint="?colorOnSurface" | ||
app:navigationIcon="@drawable/ic_arrow_back"/> | ||
</com.google.android.material.appbar.AppBarLayout> | ||
|
||
<androidx.recyclerview.widget.RecyclerView | ||
android:id="@+id/crashes_recycler" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:clipToPadding="false" | ||
app:layout_behavior="@string/appbar_scrolling_view_behavior"/> | ||
|
||
</androidx.coordinatorlayout.widget.CoordinatorLayout> |
Oops, something went wrong.