From 82ea38542278427e0292b84ada6bd0fe4c8e1f0f Mon Sep 17 00:00:00 2001 From: F0x1d Date: Sun, 20 Aug 2023 18:59:49 +0500 Subject: [PATCH] Fixed ViewPump and filters export --- .../main/java/com/f0x1d/logfox/LogFoxApp.kt | 8 ------- .../com/f0x1d/logfox/di/ViewPumpModule.kt | 21 +++++++++++++++++++ .../logfox/ui/activity/base/BaseActivity.kt | 14 ++++++++++++- .../f0x1d/logfox/utils/ExportImportUtils.kt | 8 +++---- app/src/main/res/menu/edit_filter_menu.xml | 1 - 5 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 app/src/main/java/com/f0x1d/logfox/di/ViewPumpModule.kt diff --git a/app/src/main/java/com/f0x1d/logfox/LogFoxApp.kt b/app/src/main/java/com/f0x1d/logfox/LogFoxApp.kt index e6c3ee2f..dbe1ae80 100644 --- a/app/src/main/java/com/f0x1d/logfox/LogFoxApp.kt +++ b/app/src/main/java/com/f0x1d/logfox/LogFoxApp.kt @@ -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 @@ -34,12 +32,6 @@ class LogFoxApp: Application() { applyTheme(appPreferences.nightTheme) - ViewPump.init( - ViewPump.builder() - .addInterceptor(FontsInterceptor(this)) - .build() - ) - DynamicColors.applyToActivitiesIfAvailable(this) notificationManagerCompat.apply { diff --git a/app/src/main/java/com/f0x1d/logfox/di/ViewPumpModule.kt b/app/src/main/java/com/f0x1d/logfox/di/ViewPumpModule.kt new file mode 100644 index 00000000..e99e5337 --- /dev/null +++ b/app/src/main/java/com/f0x1d/logfox/di/ViewPumpModule.kt @@ -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() +} \ No newline at end of file diff --git a/app/src/main/java/com/f0x1d/logfox/ui/activity/base/BaseActivity.kt b/app/src/main/java/com/f0x1d/logfox/ui/activity/base/BaseActivity.kt index 09dec5ae..06cf5b47 100644 --- a/app/src/main/java/com/f0x1d/logfox/ui/activity/base/BaseActivity.kt +++ b/app/src/main/java/com/f0x1d/logfox/ui/activity/base/BaseActivity.kt @@ -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: AppCompatActivity() { @@ -32,10 +37,17 @@ abstract class BaseActivity: 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(android.R.id.content).snackbar(text) protected fun snackbar(id: Int) = snackbar(getString(id)) +} + +@EntryPoint +@InstallIn(SingletonComponent::class) +interface BaseActivityEntryPoint { + fun viewPump(): ViewPump } \ No newline at end of file diff --git a/app/src/main/java/com/f0x1d/logfox/utils/ExportImportUtils.kt b/app/src/main/java/com/f0x1d/logfox/utils/ExportImportUtils.kt index 1d9806da..f8a2a468 100644 --- a/app/src/main/java/com/f0x1d/logfox/utils/ExportImportUtils.kt +++ b/app/src/main/java/com/f0x1d/logfox/utils/ExportImportUtils.kt @@ -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 @@ -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>(String(it.readBytes()), object : TypeToken>() {}.type) filtersRepository.createAll(filters) } fun OutputStream.exportFilters(context: Context, filters: List) = 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()) } @@ -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) diff --git a/app/src/main/res/menu/edit_filter_menu.xml b/app/src/main/res/menu/edit_filter_menu.xml index b3557327..ae6f22af 100644 --- a/app/src/main/res/menu/edit_filter_menu.xml +++ b/app/src/main/res/menu/edit_filter_menu.xml @@ -6,7 +6,6 @@ android:id="@+id/export_item" android:title="@string/export" android:icon="@drawable/ic_export" - android:visible="false" app:showAsAction="always" /> \ No newline at end of file