From 4c7780b069c1bf5c7512551a88bcc7d53e98d629 Mon Sep 17 00:00:00 2001 From: F0x1d Date: Sun, 29 Oct 2023 01:36:33 +0300 Subject: [PATCH] [feat]: single activity app now --- app/src/main/AndroidManifest.xml | 24 +++++++----- .../CrashesNotificationsExtensions.kt | 12 ++++-- .../f0x1d/logfox/service/LoggingService.kt | 9 +++-- .../f0x1d/logfox/ui/activity/MainActivity.kt | 32 +++++++++++++--- .../logfox/ui/activity/OpenFileActivity.kt | 22 +++++++++++ .../crashes/CrashDetailsFragment.kt} | 37 +++++++++++-------- .../crashes/{ => list}/AppCrashesFragment.kt | 4 +- .../crashes/{ => list}/CrashesFragment.kt | 4 +- app/src/main/res/navigation/crashes.xml | 31 ++++++++++------ app/src/main/res/navigation/logs.xml | 5 --- app/src/main/res/navigation/nav_graph.xml | 4 +- app/src/main/res/values/themes.xml | 8 ++++ 12 files changed, 131 insertions(+), 61 deletions(-) create mode 100644 app/src/main/java/com/f0x1d/logfox/ui/activity/OpenFileActivity.kt rename app/src/main/java/com/f0x1d/logfox/ui/{activity/CrashDetailsActivity.kt => fragment/crashes/CrashDetailsFragment.kt} (76%) rename app/src/main/java/com/f0x1d/logfox/ui/fragment/crashes/{ => list}/AppCrashesFragment.kt (96%) rename app/src/main/java/com/f0x1d/logfox/ui/fragment/crashes/{ => list}/CrashesFragment.kt (97%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e85233a5..2a0f7ed2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -21,10 +21,23 @@ + + + + + + + + - @@ -40,16 +53,7 @@ - - - - - - - (), } } + override fun onPostCreate(savedInstanceState: Bundle?) { + super.onPostCreate(savedInstanceState) + handleIntent(intent) + } + + override fun onNewIntent(intent: Intent?) { + super.onNewIntent(intent) + handleIntent(intent, onNewIntent = true) + } + + private fun handleIntent(intent: Intent?, onNewIntent: Boolean = false) { + if (onNewIntent) + if (navController.handleDeepLink(intent)) + return + + if (intent == null) return + + if (intent.data == null) return + + when (intent.action) { + Intent.ACTION_VIEW -> navController.navigate( + NavGraphDirections.actionGlobalLogsFragment(fileUri = intent.data) + ) + } + } + override fun onEvent(event: Event) { when (event.type) { MainViewModel.EVENT_TYPE_SETUP -> navController.navigate(NavGraphDirections.actionGlobalSetupFragment()) @@ -99,6 +125,7 @@ class MainActivity: BaseViewModelActivity(), R.id.editFilterFragment -> false R.id.chooseAppFragment -> false R.id.appCrashesFragment -> false + R.id.crashDetailsFragment -> false else -> true } @@ -137,11 +164,6 @@ class MainActivity: BaseViewModelActivity(), } } - override fun onNewIntent(intent: Intent?) { - super.onNewIntent(intent) - navController.handleDeepLink(intent) - } - override fun onDestroy() { super.onDestroy() navController.removeOnDestinationChangedListener(this) diff --git a/app/src/main/java/com/f0x1d/logfox/ui/activity/OpenFileActivity.kt b/app/src/main/java/com/f0x1d/logfox/ui/activity/OpenFileActivity.kt new file mode 100644 index 00000000..ebf36e4a --- /dev/null +++ b/app/src/main/java/com/f0x1d/logfox/ui/activity/OpenFileActivity.kt @@ -0,0 +1,22 @@ +package com.f0x1d.logfox.ui.activity + +import android.content.Intent +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import dagger.hilt.android.AndroidEntryPoint + +@AndroidEntryPoint +class OpenFileActivity: AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + startActivity( + Intent(this, MainActivity::class.java).apply { + action = intent.action + setDataAndType(intent.data, intent.type) + replaceExtras(intent) + } + ) + finish() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/f0x1d/logfox/ui/activity/CrashDetailsActivity.kt b/app/src/main/java/com/f0x1d/logfox/ui/fragment/crashes/CrashDetailsFragment.kt similarity index 76% rename from app/src/main/java/com/f0x1d/logfox/ui/activity/CrashDetailsActivity.kt rename to app/src/main/java/com/f0x1d/logfox/ui/fragment/crashes/CrashDetailsFragment.kt index f360373c..2e880088 100644 --- a/app/src/main/java/com/f0x1d/logfox/ui/activity/CrashDetailsActivity.kt +++ b/app/src/main/java/com/f0x1d/logfox/ui/fragment/crashes/CrashDetailsFragment.kt @@ -1,11 +1,15 @@ -package com.f0x1d.logfox.ui.activity +package com.f0x1d.logfox.ui.fragment.crashes import android.content.Intent import android.net.Uri import android.os.Bundle import android.provider.Settings +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup import androidx.activity.result.contract.ActivityResultContracts -import androidx.activity.viewModels +import androidx.fragment.app.viewModels +import androidx.navigation.fragment.findNavController import com.f0x1d.logfox.R import com.f0x1d.logfox.database.entity.AppCrash import com.f0x1d.logfox.databinding.ActivityCrashDetailsBinding @@ -16,15 +20,15 @@ import com.f0x1d.logfox.extensions.showAreYouSureDeleteDialog import com.f0x1d.logfox.extensions.views.replaceAccessibilityDelegateClassNameWithButton import com.f0x1d.logfox.extensions.views.widgets.loadIcon import com.f0x1d.logfox.extensions.views.widgets.setClickListenerOn -import com.f0x1d.logfox.extensions.views.widgets.setupBackButton -import com.f0x1d.logfox.ui.activity.base.BaseViewModelActivity +import com.f0x1d.logfox.extensions.views.widgets.setupBackButtonForNavController +import com.f0x1d.logfox.ui.fragment.base.BaseViewModelFragment import com.f0x1d.logfox.utils.event.Event import com.f0x1d.logfox.viewmodel.crashes.CrashDetailsViewModel import dagger.hilt.android.AndroidEntryPoint import dev.chrisbanes.insetter.applyInsetter @AndroidEntryPoint -class CrashDetailsActivity: BaseViewModelActivity() { +class CrashDetailsFragment: BaseViewModelFragment() { override val viewModel by viewModels() @@ -34,10 +38,13 @@ class CrashDetailsActivity: BaseViewModelActivity { - copyText(event.consume() ?: return) + requireContext().copyText(event.consume() ?: return) snackbar(R.string.text_copied) } } @@ -80,7 +85,7 @@ class CrashDetailsActivity: BaseViewModelActivity CrashesFragmentDirections.actionCrashesFragmentToCrashDetailsActivity(it.lastCrash.id) + 1 -> CrashesFragmentDirections.actionCrashesFragmentToCrashDetailsFragment(it.lastCrash.id) else -> CrashesFragmentDirections.actionCrashesFragmentToAppCrashesFragment( packageName = it.lastCrash.packageName, appName = it.lastCrash.appName diff --git a/app/src/main/res/navigation/crashes.xml b/app/src/main/res/navigation/crashes.xml index 66ec4b84..4bfaaf9d 100644 --- a/app/src/main/res/navigation/crashes.xml +++ b/app/src/main/res/navigation/crashes.xml @@ -6,11 +6,15 @@ + android:id="@+id/action_crashesFragment_to_crashDetailsFragment" + app:destination="@id/crashDetailsFragment" + app:enterAnim="@anim/nav_default_enter_anim" + app:exitAnim="@anim/nav_default_exit_anim" + app:popEnterAnim="@anim/nav_default_pop_enter_anim" + app:popExitAnim="@anim/nav_default_pop_exit_anim"/> + android:id="@+id/action_appCrashesFragment_to_crashDetailsFragment" + app:destination="@id/crashDetailsFragment" + app:enterAnim="@anim/nav_default_enter_anim" + app:exitAnim="@anim/nav_default_exit_anim" + app:popEnterAnim="@anim/nav_default_pop_enter_anim" + app:popExitAnim="@anim/nav_default_pop_exit_anim"/> - + + - + \ No newline at end of file diff --git a/app/src/main/res/navigation/logs.xml b/app/src/main/res/navigation/logs.xml index 148dc3bb..e234312f 100644 --- a/app/src/main/res/navigation/logs.xml +++ b/app/src/main/res/navigation/logs.xml @@ -8,11 +8,6 @@ android:id="@+id/logsFragment" android:name="com.f0x1d.logfox.ui.fragment.LogsFragment" android:label="LogsFragment" > - - + app:popExitAnim="@anim/nav_default_pop_exit_anim"> @font/google_sans @font/google_sans + + \ No newline at end of file