Skip to content

Commit

Permalink
PegUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
goku143u committed Jul 20, 2024
1 parent f3571dc commit d75bccd
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 39 deletions.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
91 changes: 65 additions & 26 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions app/src/main/java/dev/pegasus/utils/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,15 @@ class MainActivity : AppCompatActivity() {
binding.mbDateMain.setOnClickListener { startActivity(Intent(this, DateActivity::class.java)) }
binding.mbFileMain.setOnClickListener { startActivity(Intent(this, FileActivity::class.java)) }
}

/*override fun onCreate(savedInstanceState: Bundle?) {
installSplashTheme()
hideStatusBar(1)
enableMaterialDynamicTheme()
super.onCreate(savedInstanceState)
}
override fun onCreated() {
}*/
}
28 changes: 15 additions & 13 deletions pegutils/src/main/java/dev/pegasus/utils/base/ParentActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,26 @@ package dev.pegasus.utils.base
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.core.view.updatePadding
import androidx.viewbinding.ViewBinding
import com.google.android.material.color.DynamicColors
import dev.pegasus.utils.utils.PegasusHelperUtils.TAG

abstract class ParentActivity<T : ViewBinding>(private val bindingFactory: (LayoutInflater) -> T, private val installSplash: Boolean = false) : AppCompatActivity() {
abstract class ParentActivity<T : ViewBinding>(private val bindingFactory: (LayoutInflater) -> T) : AppCompatActivity() {

protected val binding by lazy { bindingFactory(layoutInflater) }
protected var includeTopPadding = true
protected var includeBottomPadding = true

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

if (installSplash) {
installSplashScreen()
}
enableEdgeToEdge()
enableDynamicTheme()

setContentView(binding.root)
setPadding()
hideStatusBar(-1)
onCreated()
}

Expand All @@ -44,7 +36,15 @@ abstract class ParentActivity<T : ViewBinding>(private val bindingFactory: (Layo
}
}

protected open fun enableDynamicTheme() {}
protected open fun installSplashTheme() {
Log.d(TAG, "installSplashTheme: installed")
installSplashScreen()
}

protected open fun enableMaterialDynamicTheme() {
Log.d(TAG, "enableMaterialDynamicTheme: enabling")
DynamicColors.applyToActivityIfAvailable(this)
}

/**
* @param type
Expand All @@ -55,15 +55,17 @@ abstract class ParentActivity<T : ViewBinding>(private val bindingFactory: (Layo
*/

protected open fun hideStatusBar(type: Int) {
Log.d(TAG, "hideStatusBar: Showing/Hiding: Type: $type")
WindowInsetsControllerCompat(window, window.decorView).apply {
systemBarsBehavior = when (type) {
0 -> WindowInsetsControllerCompat.BEHAVIOR_DEFAULT
else -> WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
when (type) {
0 -> show(WindowInsetsCompat.Type.systemBars())
1 -> hide(WindowInsetsCompat.Type.statusBars())
2 -> hide(WindowInsetsCompat.Type.navigationBars())
1 -> hide(WindowInsetsCompat.Type.systemBars())
2 -> hide(WindowInsetsCompat.Type.statusBars())
3 -> hide(WindowInsetsCompat.Type.navigationBars())
else -> hide(WindowInsetsCompat.Type.systemBars())
}
}
Expand Down

0 comments on commit d75bccd

Please sign in to comment.