Skip to content

Commit

Permalink
[feat]: dock slide animation
Browse files Browse the repository at this point in the history
  • Loading branch information
F0x1d committed Oct 6, 2023
1 parent 5e8112a commit 05f05a2
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 21 deletions.
17 changes: 17 additions & 0 deletions app/src/main/java/com/f0x1d/logfox/extensions/APIExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.f0x1d.logfox.extensions

import android.os.Build

val isAtLeastAndroid13 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU

val gesturesAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
val contrastedNavBarAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1

val notificationsChannelsAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
val shouldRequestNotificationsPermission = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
val startForegroundServiceAvailable = notificationsChannelsAvailable

val canPickJSON = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R

val uiModeManagerAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
val mutablePendingIntentAvailable = uiModeManagerAvailable
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.f0x1d.logfox.extensions

import android.Manifest
import android.annotation.SuppressLint
import android.app.ActivityManager
import android.app.NotificationManager
import android.app.UiModeManager
Expand All @@ -10,7 +11,6 @@ import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.os.Build
import android.widget.Toast
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.app.NotificationManagerCompat
Expand Down Expand Up @@ -50,9 +50,10 @@ fun Context.startLoggingAndServiceIfCan(loggingRepository: LoggingRepository, ap
}
}

@SuppressLint("NewApi")
fun Context.startLoggingService() {
Intent(this, LoggingService::class.java).also {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
if (startForegroundServiceAvailable)
startForegroundService(it)
else
startService(it)
Expand Down Expand Up @@ -103,7 +104,8 @@ fun Context.sendKillApp() = sendService(LoggingService.ACTION_KILL_SERVICE)
fun Context.sendStopService() = sendService(LoggingService.ACTION_STOP_SERVICE)
private fun Context.sendService(action: String) = startService(Intent(this, LoggingService::class.java).setAction(action))

fun Context.hasNotificationsPermission() = if (Build.VERSION.SDK_INT >= 33)
@SuppressLint("InlinedApi")
fun Context.hasNotificationsPermission() = if (shouldRequestNotificationsPermission)
ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED
else
true
Expand All @@ -113,8 +115,9 @@ fun Context.doIfPermitted(block: NotificationManagerCompat.() -> Unit) = if (has
else
Unit

@SuppressLint("NewApi")
fun Context.applyTheme(nightMode: Int, force: Boolean = false) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (uiModeManagerAvailable) {
if (force) uiModeManager.setApplicationNightMode(
if (nightMode != 0) nightMode else UiModeManager.MODE_NIGHT_CUSTOM
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.app.Service
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import com.f0x1d.logfox.ui.activity.MainActivity

Expand All @@ -20,7 +19,7 @@ const val STOP_RECORDING_INTENT_ID = 6
const val OPEN_APP_INTENT_ID = 7
const val SHIZUKU_PERMISSION_REQUEST_ID = 8

val pendingIntentFlags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
val pendingIntentFlags = if (mutablePendingIntentAvailable)
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
else
PendingIntent.FLAG_UPDATE_CURRENT
Expand Down
68 changes: 64 additions & 4 deletions app/src/main/java/com/f0x1d/logfox/ui/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@ package com.f0x1d.logfox.ui.activity
import android.Manifest
import android.annotation.SuppressLint
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.view.View
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.constraintlayout.widget.ConstraintSet
import androidx.navigation.NavController
import androidx.navigation.NavDestination
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
import androidx.transition.ChangeBounds
import androidx.transition.Transition
import androidx.transition.Transition.TransitionListener
import androidx.transition.TransitionManager
import com.f0x1d.logfox.NavGraphDirections
import com.f0x1d.logfox.R
import com.f0x1d.logfox.databinding.ActivityMainBinding
import com.f0x1d.logfox.extensions.contrastedNavBarAvailable
import com.f0x1d.logfox.extensions.gesturesAvailable
import com.f0x1d.logfox.extensions.hasNotificationsPermission
import com.f0x1d.logfox.ui.activity.base.BaseViewModelActivity
import com.f0x1d.logfox.utils.event.Event
Expand All @@ -29,6 +36,33 @@ class MainActivity: BaseViewModelActivity<MainViewModel, ActivityMainBinding>(),

private val requestNotificationPermissionLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()) {}

private var barShown = false
private val barScene by lazy {
ConstraintSet().apply {
clone(this@MainActivity, R.layout.activity_main)
}
}
private val noBarScene by lazy {
ConstraintSet().apply {
clone(this@MainActivity, R.layout.activity_main_no_bar)
}
}
private val changeBoundsTransition by lazy {
ChangeBounds().apply {
duration = resources.getInteger(androidx.navigation.ui.R.integer.config_navAnimTime).toLong()

addListener(object : TransitionListener {
override fun onTransitionStart(transition: Transition) {}
override fun onTransitionEnd(transition: Transition) {
TransitionManager.endTransitions(binding.root)
}
override fun onTransitionCancel(transition: Transition) {}
override fun onTransitionPause(transition: Transition) {}
override fun onTransitionResume(transition: Transition) {}
})
}
}

override fun inflateBinding() = ActivityMainBinding.inflate(layoutInflater)

@SuppressLint("InlinedApi")
Expand Down Expand Up @@ -74,13 +108,39 @@ class MainActivity: BaseViewModelActivity<MainViewModel, ActivityMainBinding>(),
R.id.filtersFragment -> false
R.id.editFilterFragment -> false
R.id.chooseAppFragment -> false

else -> true
}
val animateBarTransition = when (destination.id) {
R.id.setupFragment -> false

else -> true
}

if (!gesturesAvailable && contrastedNavBarAvailable) {
window.navigationBarColor = when (barShown) {
true -> Color.TRANSPARENT

else -> getColor(R.color.navbar_transparent_background)
}
}

if (this.barShown != barShown) {
this.barShown = barShown

binding.root.also {
if (animateBarTransition) TransitionManager.beginDelayedTransition(
it,
changeBoundsTransition
)

binding.barView?.visibility = when (barShown) {
true -> View.VISIBLE
val scene = when (barShown) {
true -> barScene

else -> View.GONE
else -> noBarScene
}
scene.applyTo(it)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package com.f0x1d.logfox.ui.activity.base

import android.content.Context
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat
import androidx.viewbinding.ViewBinding
import com.f0x1d.logfox.R
import com.f0x1d.logfox.extensions.contrastedNavBarAvailable
import com.f0x1d.logfox.extensions.gesturesAvailable
import com.f0x1d.logfox.extensions.snackbar
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
Expand All @@ -28,10 +29,10 @@ abstract class BaseActivity<T : ViewBinding>: AppCompatActivity() {
WindowCompat.setDecorFitsSystemWindows(window, false)

window.navigationBarColor = when {
Build.VERSION.SDK_INT < Build.VERSION_CODES.O_MR1 -> getColor(
!contrastedNavBarAvailable -> getColor(
R.color.transparent_black
)
Build.VERSION.SDK_INT < Build.VERSION_CODES.Q -> getColor(
!gesturesAvailable -> getColor(
R.color.navbar_transparent_background
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.f0x1d.logfox.ui.fragment.filters

import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand All @@ -12,6 +11,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.f0x1d.logfox.R
import com.f0x1d.logfox.adapter.FiltersAdapter
import com.f0x1d.logfox.databinding.FragmentFiltersBinding
import com.f0x1d.logfox.extensions.canPickJSON
import com.f0x1d.logfox.extensions.setClickListenerOn
import com.f0x1d.logfox.extensions.showAreYouSureDialog
import com.f0x1d.logfox.ui.fragment.base.BaseViewModelFragment
Expand Down Expand Up @@ -68,7 +68,7 @@ class FiltersFragment: BaseViewModelFragment<FiltersViewModel, FragmentFiltersBi
}
}
setClickListenerOn(R.id.import_item) {
importFiltersLauncher.launch(arrayOf(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) "application/json" else "*/*"))
importFiltersLauncher.launch(arrayOf(if (canPickJSON) "application/json" else "*/*"))
}
setClickListenerOn(R.id.export_all_item) {
exportFiltersLauncher.launch("filters.json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package com.f0x1d.logfox.ui.fragment.settings

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import androidx.preference.Preference
import com.f0x1d.logfox.BuildConfig
import com.f0x1d.logfox.LogFoxApp
import com.f0x1d.logfox.R
import com.f0x1d.logfox.extensions.hasNotificationsPermission
import com.f0x1d.logfox.extensions.notificationsChannelsAvailable
import com.f0x1d.logfox.ui.fragment.settings.base.BasePreferenceFragment
import com.f0x1d.logfox.utils.preferences.AppPreferences
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -37,7 +37,7 @@ class SettingsNotificationsFragment: BasePreferenceFragment() {
}

findPreference<Preference>("pref_logging_notification")?.apply {
isVisible = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
isVisible = notificationsChannelsAvailable

setOnPreferenceClickListener {
startActivity(Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS).apply {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.f0x1d.logfox.ui.fragment.settings

import android.os.Build
import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import androidx.preference.Preference
import androidx.preference.SwitchPreferenceCompat
import com.f0x1d.logfox.R
import com.f0x1d.logfox.extensions.isAtLeastAndroid13
import com.f0x1d.logfox.extensions.observeAndUpdateSummaryForList
import com.f0x1d.logfox.extensions.setupAsListPreference
import com.f0x1d.logfox.extensions.toast
Expand Down Expand Up @@ -99,6 +99,4 @@ class SettingsServiceFragment: BasePreferenceFragment() {
.setPositiveButton(android.R.string.ok, null)
.show()
}
}

val isAtLeastAndroid13 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
}
30 changes: 30 additions & 0 deletions app/src/main/res/layout-land/activity_main_no_bar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host_fragment_content_main"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/navigation_rail"
app:layout_constraintBottom_toBottomOf="parent"
app:navGraph="@navigation/nav_graph" />

<com.f0x1d.logfox.ui.view.CustomApplyInsetsNavigationRailView
android:id="@+id/navigation_rail"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:itemTextAppearanceActive="@style/LogFoxBottomNavigationViewTextStyle"
app:itemTextAppearanceInactive="@style/LogFoxBottomNavigationViewTextStyle"
app:menu="@menu/main_menu"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
30 changes: 30 additions & 0 deletions app/src/main/res/layout/activity_main_no_bar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host_fragment_content_main"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/bottom_navigation"
app:navGraph="@navigation/nav_graph" />

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:itemTextAppearanceActive="@style/LogFoxBottomNavigationViewTextStyle"
app:itemTextAppearanceInactive="@style/LogFoxBottomNavigationViewTextStyle"
app:menu="@menu/main_menu"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 05f05a2

Please sign in to comment.