Skip to content

Commit

Permalink
Fixed ViewPump and filters export
Browse files Browse the repository at this point in the history
  • Loading branch information
F0x1d committed Aug 20, 2023
1 parent a32a06d commit 82ea385
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
8 changes: 0 additions & 8 deletions app/src/main/java/com/f0x1d/logfox/LogFoxApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import androidx.core.app.NotificationManagerCompat
import com.f0x1d.logfox.extensions.applyTheme
import com.f0x1d.logfox.extensions.notificationManagerCompat
import com.f0x1d.logfox.utils.preferences.AppPreferences
import com.f0x1d.logfox.utils.view.FontsInterceptor
import com.google.android.material.color.DynamicColors
import dagger.hilt.android.HiltAndroidApp
import io.github.inflationx.viewpump.ViewPump
import kotlinx.coroutines.MainScope
import javax.inject.Inject

Expand All @@ -34,12 +32,6 @@ class LogFoxApp: Application() {

applyTheme(appPreferences.nightTheme)

ViewPump.init(
ViewPump.builder()
.addInterceptor(FontsInterceptor(this))
.build()
)

DynamicColors.applyToActivitiesIfAvailable(this)

notificationManagerCompat.apply {
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/com/f0x1d/logfox/di/ViewPumpModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.f0x1d.logfox.di

import android.app.Application
import com.f0x1d.logfox.utils.view.FontsInterceptor
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import io.github.inflationx.viewpump.ViewPump
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object ViewPumpModule {

@Provides
@Singleton
fun provideViewPump(application: Application) = ViewPump.builder()
.addInterceptor(FontsInterceptor(application))
.build()
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import androidx.core.view.WindowCompat
import androidx.viewbinding.ViewBinding
import com.f0x1d.logfox.R
import com.f0x1d.logfox.extensions.snackbar
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
import dagger.hilt.android.EntryPointAccessors
import dagger.hilt.components.SingletonComponent
import io.github.inflationx.viewpump.ViewPump
import io.github.inflationx.viewpump.ViewPumpContextWrapper

abstract class BaseActivity<T : ViewBinding>: AppCompatActivity() {
Expand All @@ -32,10 +37,17 @@ abstract class BaseActivity<T : ViewBinding>: AppCompatActivity() {
}

override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase))
val viewPump = EntryPointAccessors.fromApplication(newBase, BaseActivityEntryPoint::class.java).viewPump()
super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase, viewPump))
}

protected fun snackbar(text: String) = findViewById<View>(android.R.id.content).snackbar(text)

protected fun snackbar(id: Int) = snackbar(getString(id))
}

@EntryPoint
@InstallIn(SingletonComponent::class)
interface BaseActivityEntryPoint {
fun viewPump(): ViewPump
}
8 changes: 4 additions & 4 deletions app/src/main/java/com/f0x1d/logfox/utils/ExportImportUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import com.f0x1d.logfox.repository.logging.FiltersRepository
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import dagger.hilt.EntryPoint
import dagger.hilt.EntryPoints
import dagger.hilt.InstallIn
import dagger.hilt.android.EntryPointAccessors
import dagger.hilt.components.SingletonComponent
import java.io.File
import java.io.InputStream
Expand All @@ -17,14 +17,14 @@ import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream

fun InputStream.importFilters(context: Context, filtersRepository: FiltersRepository) = use {
val gson = EntryPointAccessors.fromApplication(context, ExportImportUtilsEntryPoint::class.java).gson()
val gson = EntryPoints.get(context, ExportImportUtilsEntryPoint::class.java).gson()

val filters = gson.fromJson<List<UserFilter>>(String(it.readBytes()), object : TypeToken<List<UserFilter>>() {}.type)
filtersRepository.createAll(filters)
}

fun OutputStream.exportFilters(context: Context, filters: List<UserFilter>) = use {
val gson = EntryPointAccessors.fromApplication(context, ExportImportUtilsEntryPoint::class.java).gson()
val gson = EntryPoints.get(context, ExportImportUtilsEntryPoint::class.java).gson()

it.write(gson.toJson(filters).encodeToByteArray())
}
Expand All @@ -38,7 +38,7 @@ fun OutputStream.exportLogToZip(context: Context, logFile: String) = exportToZip
}

private fun OutputStream.exportToZip(context: Context, block: ZipOutputStream.() -> Unit) = use {
val device = EntryPointAccessors.fromApplication(context, ExportImportUtilsEntryPoint::class.java).device()
val device = EntryPoints.get(context, ExportImportUtilsEntryPoint::class.java).device()

ZipOutputStream(this).use { zipOutputStream ->
block.invoke(zipOutputStream)
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/menu/edit_filter_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
android:id="@+id/export_item"
android:title="@string/export"
android:icon="@drawable/ic_export"
android:visible="false"
app:showAsAction="always" />

</menu>

0 comments on commit 82ea385

Please sign in to comment.