diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index c269702..2b88b8f 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -27,26 +27,6 @@
android:name=".MainActivity"
android:exported="false"
android:windowSoftInputMode="adjustResize" />
-
-
-
-
-
-
\ No newline at end of file
+
diff --git a/app/src/main/java/com/example/helponizer/AboutFragment.kt b/app/src/main/java/com/example/helponizer/AboutFragment.kt
new file mode 100644
index 0000000..19dc8f4
--- /dev/null
+++ b/app/src/main/java/com/example/helponizer/AboutFragment.kt
@@ -0,0 +1,12 @@
+package com.example.helponizer
+
+import android.os.Bundle
+import android.view.View
+import androidx.fragment.app.Fragment
+
+class AboutFragment : Fragment(R.layout.fragment_about) {
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+ TextSizeManager.applyTo(view)
+ }
+}
diff --git a/app/src/main/java/com/example/helponizer/BaseActivity.kt b/app/src/main/java/com/example/helponizer/BaseActivity.kt
deleted file mode 100644
index 33e60bc..0000000
--- a/app/src/main/java/com/example/helponizer/BaseActivity.kt
+++ /dev/null
@@ -1,168 +0,0 @@
-package com.example.helponizer
-
-import android.content.Intent
-import android.graphics.drawable.Animatable2
-import android.graphics.drawable.AnimatedVectorDrawable
-import android.os.Bundle
-import android.view.View
-import android.view.ViewGroup
-import android.widget.FrameLayout
-import android.widget.ImageView
-import androidx.appcompat.app.AppCompatActivity
-import androidx.core.view.ViewCompat
-import androidx.core.view.WindowInsetsCompat
-import androidx.core.view.WindowInsetsControllerCompat
-import androidx.vectordrawable.graphics.drawable.Animatable2Compat
-import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
-import com.google.android.material.bottomnavigation.BottomNavigationView
-
-open class BaseActivity : AppCompatActivity() {
-
- override fun onCreate(savedInstanceState: Bundle?) {
- ThemeManager.apply(this)
- super.onCreate(savedInstanceState)
- }
-
- override fun setContentView(layoutResID: Int) {
- val wrapper = layoutInflater.inflate(R.layout.activity_base, null)
- val content = wrapper.findViewById(R.id.baseContent)
- layoutInflater.inflate(layoutResID, content, true)
- super.setContentView(wrapper)
- }
-
- override fun onContentChanged() {
- super.onContentChanged()
- setupBottomNavigation()
- }
-
- override fun onPostCreate(savedInstanceState: Bundle?) {
- super.onPostCreate(savedInstanceState)
- WindowInsetsControllerCompat(window, window.decorView)
- .isAppearanceLightStatusBars = true
- }
-
- private fun setupBottomNavigation() {
- val bottomNav = findViewById(R.id.bottomNav) ?: return
- val currentScreenId = when (this) {
- is MainActivity -> R.id.nav_home
- is Raspisanie -> R.id.nav_schedule
- is Informaition -> R.id.nav_tips
- is Settings -> R.id.nav_settings
- is funny -> R.id.nav_party
- else -> 0
- }
- val selectedId = if (currentScreenId != 0) currentScreenId else R.id.nav_home
-
- bottomNav.setOnItemSelectedListener(null)
- bottomNav.setOnItemReselectedListener(null)
- bottomNav.selectedItemId = selectedId
-
- bottomNav.setOnItemSelectedListener { item ->
- if (item.itemId == currentScreenId) {
- animateNavIcon(bottomNav, item.itemId)
- false
- } else {
- navigateFromBottomNav(bottomNav, item.itemId)
- }
- }
- bottomNav.setOnItemReselectedListener { item ->
- if (item.itemId == currentScreenId) {
- animateNavIcon(bottomNav, item.itemId)
- } else {
- navigateFromBottomNav(bottomNav, item.itemId)
- }
- }
-
- val baseLeft = bottomNav.paddingLeft
- val baseTop = bottomNav.paddingTop
- val baseRight = bottomNav.paddingRight
- val baseBottom = bottomNav.paddingBottom
- ViewCompat.setOnApplyWindowInsetsListener(bottomNav) { view, insets ->
- val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
- view.setPadding(
- baseLeft + systemBars.left,
- baseTop,
- baseRight + systemBars.right,
- baseBottom + systemBars.bottom
- )
- insets
- }
- ViewCompat.requestApplyInsets(bottomNav)
- animateNavIcon(bottomNav, selectedId)
- }
-
- private fun animateNavIcon(
- bottomNav: BottomNavigationView,
- itemId: Int,
- finishOnEnd: Boolean = false
- ) {
- bottomNav.post {
- val itemView = bottomNav.findViewById(itemId)
- val image = findImageView(itemView) ?: return@post
- when (val drawable = image.drawable) {
- is AnimatedVectorDrawable -> {
- if (finishOnEnd) drawable.registerAnimationCallback(frameworkFinishOnEnd(bottomNav))
- drawable.start()
- }
- is AnimatedVectorDrawableCompat -> {
- if (finishOnEnd) drawable.registerAnimationCallback(compatFinishOnEnd(bottomNav))
- drawable.start()
- }
- }
- }
- }
-
- private fun frameworkFinishOnEnd(bottomNav: BottomNavigationView): Animatable2.AnimationCallback {
- return object : Animatable2.AnimationCallback() {
- override fun onAnimationEnd(drawable: android.graphics.drawable.Drawable?) {
- finishAfterAnimation(bottomNav)
- }
- }
- }
-
- private fun compatFinishOnEnd(bottomNav: BottomNavigationView): Animatable2Compat.AnimationCallback {
- return object : Animatable2Compat.AnimationCallback() {
- override fun onAnimationEnd(drawable: android.graphics.drawable.Drawable?) {
- finishAfterAnimation(bottomNav)
- }
- }
- }
-
- private fun finishAfterAnimation(bottomNav: BottomNavigationView) {
- bottomNav.post {
- if (!isFinishing) finish()
- }
- }
-
- private fun findImageView(view: View?): ImageView? {
- if (view == null) return null
- if (view is ImageView) return view
- if (view is ViewGroup) {
- for (index in 0 until view.childCount) {
- val found = findImageView(view.getChildAt(index))
- if (found != null) return found
- }
- }
- return null
- }
-
- private fun navigateFromBottomNav(bottomNav: BottomNavigationView, itemId: Int): Boolean {
- val target = when (itemId) {
- R.id.nav_home -> MainActivity::class.java
- R.id.nav_schedule -> Raspisanie::class.java
- R.id.nav_tips -> Informaition::class.java
- R.id.nav_settings -> Settings::class.java
- R.id.nav_party -> funny::class.java
- else -> return false
- }
- animateNavIcon(bottomNav, itemId, finishOnEnd = true)
- startActivityWithTransition(Intent(this, target))
- return true
- }
-
- protected fun startActivityWithTransition(intent: Intent) {
- startActivity(intent)
- @Suppress("DEPRECATION")
- overridePendingTransition(0, 0)
- }
-}
diff --git a/app/src/main/java/com/example/helponizer/HomeFragment.kt b/app/src/main/java/com/example/helponizer/HomeFragment.kt
new file mode 100644
index 0000000..6390e97
--- /dev/null
+++ b/app/src/main/java/com/example/helponizer/HomeFragment.kt
@@ -0,0 +1,15 @@
+package com.example.helponizer
+
+import android.os.Bundle
+import android.view.View
+import androidx.fragment.app.Fragment
+
+class HomeFragment : Fragment(R.layout.fragment_home) {
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+ view.findViewById(R.id.buttonAbout).setOnClickListener {
+ (activity as? MainActivity)?.openAbout()
+ }
+ TextSizeManager.applyTo(view)
+ }
+}
diff --git a/app/src/main/java/com/example/helponizer/IconAnimator.kt b/app/src/main/java/com/example/helponizer/IconAnimator.kt
index c2b04ac..ee52aaa 100644
--- a/app/src/main/java/com/example/helponizer/IconAnimator.kt
+++ b/app/src/main/java/com/example/helponizer/IconAnimator.kt
@@ -1,10 +1,12 @@
package com.example.helponizer
+import android.graphics.drawable.Animatable2
import android.graphics.drawable.AnimatedVectorDrawable
import android.graphics.drawable.Drawable
import android.graphics.drawable.LayerDrawable
import android.view.View
import androidx.annotation.DrawableRes
+import androidx.vectordrawable.graphics.drawable.Animatable2Compat
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
import com.google.android.material.button.MaterialButton
import java.util.WeakHashMap
@@ -13,18 +15,42 @@ object IconAnimator {
private val animatables = WeakHashMap()
fun setup(button: MaterialButton, @DrawableRes resId: Int) {
- val avd = androidx.core.content.ContextCompat.getDrawable(button.context, resId) as? AnimatedVectorDrawable
+ val avd = androidx.core.content.ContextCompat.getDrawable(button.context, resId)
+ as? AnimatedVectorDrawable
button.icon = avd
val drawn = findAnimatedVector(button.icon) ?: avd ?: return
drawn.callback = button
animatables[button] = drawn
}
- fun start(view: View) {
- val drawable = animatables[view as? MaterialButton]
+ fun start(view: View, onEnd: (() -> Unit)? = null) {
+ val drawable = animatables[view as? MaterialButton] ?: return
when (drawable) {
- is AnimatedVectorDrawableCompat -> drawable.start()
- is AnimatedVectorDrawable -> drawable.start()
+ is AnimatedVectorDrawableCompat -> {
+ if (onEnd != null) {
+ val callback = object : Animatable2Compat.AnimationCallback() {
+ override fun onAnimationEnd(d: Drawable?) {
+ drawable.unregisterAnimationCallback(this)
+ onEnd()
+ }
+ }
+ drawable.registerAnimationCallback(callback)
+ }
+ drawable.start()
+ }
+
+ is AnimatedVectorDrawable -> {
+ if (onEnd != null) {
+ val callback = object : Animatable2.AnimationCallback() {
+ override fun onAnimationEnd(d: Drawable?) {
+ drawable.unregisterAnimationCallback(this)
+ onEnd()
+ }
+ }
+ drawable.registerAnimationCallback(callback)
+ }
+ drawable.start()
+ }
}
}
diff --git a/app/src/main/java/com/example/helponizer/MainActivity.kt b/app/src/main/java/com/example/helponizer/MainActivity.kt
index 030fe64..d3d677b 100644
--- a/app/src/main/java/com/example/helponizer/MainActivity.kt
+++ b/app/src/main/java/com/example/helponizer/MainActivity.kt
@@ -1,37 +1,233 @@
package com.example.helponizer
-import android.content.Intent
+import android.graphics.drawable.AnimatedVectorDrawable
import android.os.Bundle
+import android.util.TypedValue
import android.view.View
+import android.view.ViewGroup
+import android.widget.FrameLayout
+import android.widget.ImageView
+import androidx.activity.OnBackPressedCallback
import androidx.activity.enableEdgeToEdge
+import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
+import androidx.core.view.WindowInsetsControllerCompat
+import androidx.fragment.app.Fragment
+import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
+import com.google.android.material.bottomnavigation.BottomNavigationView
+
+class MainActivity : AppCompatActivity() {
+
+ private lateinit var bottomNav: BottomNavigationView
+ private lateinit var screenContainer: FrameLayout
+ private var currentTag: String = TAG_HOME
-class MainActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
+ ThemeManager.apply(this)
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)
- ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { view, insets ->
- val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
- view.setPadding(
- systemBars.left,
- systemBars.top,
- systemBars.right,
- 0
- )
- insets
+ bottomNav = findViewById(R.id.bottomNav)
+ screenContainer = findViewById(R.id.screenContainer)
+ applyInsets()
+ applySystemBarAppearance()
+
+ val initialTag = savedInstanceState?.getString(STATE_TAG) ?: TAG_HOME
+ currentTag = initialTag
+ bottomNav.selectedItemId = navIdForTag(initialTag)
+
+ bottomNav.setOnItemSelectedListener { item ->
+ val tag = tagForNav(item.itemId) ?: return@setOnItemSelectedListener false
+ if (tag == currentTag) {
+ animateNavIcon(item.itemId)
+ false
+ } else {
+ showScreen(tag, animateIcon = false)
+ animateNavIcon(item.itemId)
+ true
+ }
+ }
+ bottomNav.setOnItemReselectedListener { item ->
+ animateNavIcon(item.itemId)
+ if (currentTag == TAG_ABOUT && item.itemId == R.id.nav_home) {
+ showScreen(TAG_HOME, animateIcon = false)
+ }
}
- findViewById(R.id.buttonAbout).setOnClickListener {
- startActivityWithTransition(Intent(this, infoProgram::class.java))
- finish()
+ showScreen(initialTag, animateIcon = false)
+ if (savedInstanceState == null) {
+ animateNavIcon(navIdForTag(initialTag))
}
+
+ onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
+ override fun handleOnBackPressed() {
+ if (currentTag == TAG_ABOUT) {
+ showScreen(TAG_HOME)
+ } else {
+ finish()
+ }
+ }
+ })
}
override fun onResume() {
super.onResume()
- TextSizeManager.applyTo(findViewById(R.id.main))
+ supportFragmentManager.findFragmentByTag(currentTag)
+ ?.view
+ ?.let { TextSizeManager.applyTo(it) }
+ }
+
+ override fun onSaveInstanceState(outState: Bundle) {
+ outState.putString(STATE_TAG, currentTag)
+ super.onSaveInstanceState(outState)
+ }
+
+ fun openAbout() {
+ if (currentTag == TAG_ABOUT) return
+ showScreen(TAG_ABOUT, animateIcon = false)
+ }
+
+ private fun showScreen(tag: String, animateIcon: Boolean = true) {
+ val manager = supportFragmentManager
+ val transaction = manager.beginTransaction().setReorderingAllowed(true)
+ var target = manager.findFragmentByTag(tag)
+
+ for (knownTag in ALL_TAGS) {
+ val fragment = manager.findFragmentByTag(knownTag) ?: continue
+ if (knownTag == tag) {
+ transaction.show(fragment)
+ } else {
+ transaction.hide(fragment)
+ }
+ }
+
+ if (target == null) {
+ target = createFragment(tag)
+ transaction.add(R.id.screenContainer, target, tag)
+ }
+
+ transaction.commitNow()
+ currentTag = tag
+ target.view?.let { TextSizeManager.applyTo(it) }
+
+ if (animateIcon) {
+ animateNavIcon(navIdForTag(tag))
+ }
+ }
+
+ private fun createFragment(tag: String): Fragment = when (tag) {
+ TAG_HOME -> HomeFragment()
+ TAG_SCHEDULE -> ScheduleFragment()
+ TAG_TIPS -> TipsFragment()
+ TAG_SETTINGS -> SettingsFragment()
+ TAG_PARTY -> PartyFragment()
+ TAG_ABOUT -> AboutFragment()
+ else -> error("Unknown screen: $tag")
+ }
+
+ private fun tagForNav(itemId: Int): String? = when (itemId) {
+ R.id.nav_home -> TAG_HOME
+ R.id.nav_schedule -> TAG_SCHEDULE
+ R.id.nav_tips -> TAG_TIPS
+ R.id.nav_settings -> TAG_SETTINGS
+ R.id.nav_party -> TAG_PARTY
+ else -> null
+ }
+
+ private fun navIdForTag(tag: String): Int = when (tag) {
+ TAG_SCHEDULE -> R.id.nav_schedule
+ TAG_TIPS -> R.id.nav_tips
+ TAG_SETTINGS -> R.id.nav_settings
+ TAG_PARTY -> R.id.nav_party
+ else -> R.id.nav_home
+ }
+
+ private fun applyInsets() {
+ val navLeft = bottomNav.paddingLeft
+ val navTop = bottomNav.paddingTop
+ val navRight = bottomNav.paddingRight
+ val navBottom = bottomNav.paddingBottom
+
+ ViewCompat.setOnApplyWindowInsetsListener(bottomNav) { view, insets ->
+ val bars = insets.getInsets(
+ WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()
+ )
+ view.setPadding(
+ navLeft + bars.left,
+ navTop,
+ navRight + bars.right,
+ navBottom + bars.bottom
+ )
+ insets
+ }
+
+ ViewCompat.setOnApplyWindowInsetsListener(screenContainer) { view, insets ->
+ val bars = insets.getInsets(
+ WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()
+ )
+ view.setPadding(bars.left, bars.top, bars.right, 0)
+ insets
+ }
+
+ ViewCompat.requestApplyInsets(bottomNav)
+ ViewCompat.requestApplyInsets(screenContainer)
+ }
+
+ private fun applySystemBarAppearance() {
+ val value = TypedValue()
+ val lightStatusBar = if (
+ theme.resolveAttribute(android.R.attr.windowLightStatusBar, value, true)
+ ) {
+ value.data != 0
+ } else {
+ true
+ }
+ WindowInsetsControllerCompat(window, window.decorView).apply {
+ isAppearanceLightStatusBars = lightStatusBar
+ isAppearanceLightNavigationBars = true
+ }
+ }
+
+ private fun animateNavIcon(itemId: Int) {
+ bottomNav.post {
+ val itemView = bottomNav.findViewById(itemId) ?: return@post
+ val image = findImageView(itemView) ?: return@post
+ when (val drawable = image.drawable) {
+ is AnimatedVectorDrawable -> drawable.start()
+ is AnimatedVectorDrawableCompat -> drawable.start()
+ }
+ }
+ }
+
+ private fun findImageView(view: View?): ImageView? {
+ if (view == null) return null
+ if (view is ImageView) return view
+ if (view is ViewGroup) {
+ for (index in 0 until view.childCount) {
+ val found = findImageView(view.getChildAt(index))
+ if (found != null) return found
+ }
+ }
+ return null
+ }
+
+ companion object {
+ private const val STATE_TAG = "helponizer_screen_tag"
+ private const val TAG_HOME = "screen_home"
+ private const val TAG_SCHEDULE = "screen_schedule"
+ private const val TAG_TIPS = "screen_tips"
+ private const val TAG_SETTINGS = "screen_settings"
+ private const val TAG_PARTY = "screen_party"
+ private const val TAG_ABOUT = "screen_about"
+ private val ALL_TAGS = listOf(
+ TAG_HOME,
+ TAG_SCHEDULE,
+ TAG_TIPS,
+ TAG_SETTINGS,
+ TAG_PARTY,
+ TAG_ABOUT
+ )
}
}
diff --git a/app/src/main/java/com/example/helponizer/PartyFragment.kt b/app/src/main/java/com/example/helponizer/PartyFragment.kt
new file mode 100644
index 0000000..b36aed8
--- /dev/null
+++ b/app/src/main/java/com/example/helponizer/PartyFragment.kt
@@ -0,0 +1,12 @@
+package com.example.helponizer
+
+import android.os.Bundle
+import android.view.View
+import androidx.fragment.app.Fragment
+
+class PartyFragment : Fragment(R.layout.fragment_party) {
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+ TextSizeManager.applyTo(view)
+ }
+}
diff --git a/app/src/main/java/com/example/helponizer/Raspisanie.kt b/app/src/main/java/com/example/helponizer/ScheduleFragment.kt
similarity index 69%
rename from app/src/main/java/com/example/helponizer/Raspisanie.kt
rename to app/src/main/java/com/example/helponizer/ScheduleFragment.kt
index e343735..d3d8839 100644
--- a/app/src/main/java/com/example/helponizer/Raspisanie.kt
+++ b/app/src/main/java/com/example/helponizer/ScheduleFragment.kt
@@ -10,10 +10,8 @@ import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.ProgressBar
import android.widget.TextView
-import androidx.activity.enableEdgeToEdge
import androidx.core.content.ContextCompat
-import androidx.core.view.ViewCompat
-import androidx.core.view.WindowInsetsCompat
+import androidx.fragment.app.Fragment
import com.google.android.material.button.MaterialButton
import com.google.android.material.card.MaterialCardView
import java.time.DayOfWeek
@@ -23,7 +21,7 @@ import java.util.Locale
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
-class Raspisanie : BaseActivity() {
+class ScheduleFragment : Fragment(R.layout.fragment_schedule) {
private lateinit var scheduleList: LinearLayout
private lateinit var scheduleProgress: ProgressBar
private lateinit var scheduleStatus: TextView
@@ -32,37 +30,26 @@ class Raspisanie : BaseActivity() {
private val ruLocale = Locale.forLanguageTag("ru")
private val dayDateFormat = DateTimeFormatter.ofPattern("dd.MM", ruLocale)
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- enableEdgeToEdge()
- setContentView(R.layout.activity_raspisanie)
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
- scheduleList = findViewById(R.id.scheduleList)
- scheduleProgress = findViewById(R.id.scheduleProgress)
- scheduleStatus = findViewById(R.id.scheduleStatus)
- scheduleRetryButton = findViewById(R.id.scheduleRetryButton)
-
- ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { view, insets ->
- val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
- view.setPadding(systemBars.left, systemBars.top, systemBars.right, 0)
- insets
- }
+ scheduleList = view.findViewById(R.id.scheduleList)
+ scheduleProgress = view.findViewById(R.id.scheduleProgress)
+ scheduleStatus = view.findViewById(R.id.scheduleStatus)
+ scheduleRetryButton = view.findViewById(R.id.scheduleRetryButton)
scheduleRetryButton.setOnClickListener { loadSchedule() }
+ TextSizeManager.applyTo(view)
loadSchedule()
}
- override fun onResume() {
- super.onResume()
- TextSizeManager.applyTo(findViewById(R.id.main))
- }
-
override fun onDestroy() {
executor.shutdownNow()
super.onDestroy()
}
private fun loadSchedule() {
+ val host = activity ?: return
scheduleProgress.visibility = View.VISIBLE
scheduleStatus.visibility = View.GONE
scheduleRetryButton.visibility = View.GONE
@@ -72,9 +59,13 @@ class Raspisanie : BaseActivity() {
try {
val monday = LocalDate.now().with(DayOfWeek.MONDAY)
val days = ScheduleRepository.fetchWeek(monday, monday.plusDays(5))
- runOnUiThread { renderSchedule(days) }
+ host.runOnUiThread {
+ if (isAdded && view != null) renderSchedule(days)
+ }
} catch (e: Exception) {
- runOnUiThread { renderError() }
+ host.runOnUiThread {
+ if (isAdded && view != null) renderError()
+ }
}
}
}
@@ -113,13 +104,17 @@ class Raspisanie : BaseActivity() {
}
private fun applyTextSize() {
- TextSizeManager.applyTo(findViewById(R.id.main))
+ view?.let { TextSizeManager.applyTo(it) }
}
private fun addDayHeader(day: ScheduleDay) {
- val header = TextView(this).apply {
+ val header = TextView(requireContext()).apply {
layoutParams = marginParams(topDp = 18, bottomDp = 8)
- text = getString(R.string.schedule_day_header, getString(dayNameRes(day.dayOfWeek)), day.date.format(dayDateFormat))
+ text = getString(
+ R.string.schedule_day_header,
+ getString(dayNameRes(day.dayOfWeek)),
+ day.date.format(dayDateFormat)
+ )
setTextColor(resolveColor(com.google.android.material.R.attr.colorOnSurface, Color.BLACK))
setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f)
setTypeface(typeface, Typeface.BOLD)
@@ -129,40 +124,56 @@ class Raspisanie : BaseActivity() {
}
private fun createLessonCard(lesson: ScheduleLesson): MaterialCardView {
- val card = MaterialCardView(this).apply {
+ val card = MaterialCardView(requireContext()).apply {
layoutParams = marginParams(topDp = 8, bottomDp = 8)
radius = 18f * resources.displayMetrics.density
cardElevation = 1f * resources.displayMetrics.density
strokeWidth = (1 * resources.displayMetrics.density).toInt()
- strokeColor = resolveColor(com.google.android.material.R.attr.colorSurfaceVariant, Color.LTGRAY)
- setCardBackgroundColor(resolveColor(com.google.android.material.R.attr.colorSurface, Color.WHITE))
+ strokeColor = resolveColor(
+ com.google.android.material.R.attr.colorSurfaceVariant,
+ Color.LTGRAY
+ )
+ setCardBackgroundColor(
+ resolveColor(com.google.android.material.R.attr.colorSurface, Color.WHITE)
+ )
isClickable = false
}
- val content = LinearLayout(this).apply {
+ val content = LinearLayout(requireContext()).apply {
orientation = LinearLayout.VERTICAL
setPadding(18.dp, 16.dp, 18.dp, 16.dp)
}
- val titleRow = LinearLayout(this).apply {
+ val titleRow = LinearLayout(requireContext()).apply {
orientation = LinearLayout.HORIZONTAL
gravity = Gravity.CENTER_VERTICAL
}
titleRow.addView(
- TextView(this).apply {
- layoutParams = LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)
+ TextView(requireContext()).apply {
+ layoutParams = LinearLayout.LayoutParams(
+ 0,
+ ViewGroup.LayoutParams.WRAP_CONTENT,
+ 1f
+ )
text = getString(R.string.schedule_pair, lesson.number)
- setTextColor(resolveColor(androidx.appcompat.R.attr.colorPrimary, Color.DKGRAY))
+ setTextColor(
+ resolveColor(androidx.appcompat.R.attr.colorPrimary, Color.DKGRAY)
+ )
setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f)
setTypeface(typeface, Typeface.BOLD)
}
)
titleRow.addView(
- TextView(this).apply {
+ TextView(requireContext()).apply {
text = getString(R.string.schedule_time, lesson.startAt, lesson.endAt)
- setTextColor(resolveColor(com.google.android.material.R.attr.colorOnSurfaceVariant, Color.DKGRAY))
+ setTextColor(
+ resolveColor(
+ com.google.android.material.R.attr.colorOnSurfaceVariant,
+ Color.DKGRAY
+ )
+ )
setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f)
}
)
@@ -177,22 +188,26 @@ class Raspisanie : BaseActivity() {
}
private fun createLineView(line: ScheduleLine): LinearLayout {
- val container = LinearLayout(this).apply {
+ val container = LinearLayout(requireContext()).apply {
orientation = LinearLayout.VERTICAL
setPadding(0, 10.dp, 0, 0)
}
container.addView(
- TextView(this).apply {
+ TextView(requireContext()).apply {
text = line.subject.ifBlank { getString(R.string.schedule_unknown) }
- setTextColor(resolveColor(com.google.android.material.R.attr.colorOnSurface, Color.BLACK))
+ setTextColor(
+ resolveColor(com.google.android.material.R.attr.colorOnSurface, Color.BLACK)
+ )
setTextSize(TypedValue.COMPLEX_UNIT_SP, 17f)
setTypeface(typeface, Typeface.BOLD)
setLineSpacing(3f * resources.displayMetrics.density, 1f)
}
)
- val room = listOf(line.roomNumber, line.roomName).filter { it.isNotBlank() }.joinToString(" · ")
+ val room = listOf(line.roomNumber, line.roomName)
+ .filter { it.isNotBlank() }
+ .joinToString(" · ")
if (room.isNotBlank()) {
container.addView(metaText(getString(R.string.schedule_room, room)))
}
@@ -213,9 +228,14 @@ class Raspisanie : BaseActivity() {
}
private fun metaText(text: String): TextView {
- return TextView(this).apply {
+ return TextView(requireContext()).apply {
this.text = text
- setTextColor(resolveColor(com.google.android.material.R.attr.colorOnSurfaceVariant, Color.DKGRAY))
+ setTextColor(
+ resolveColor(
+ com.google.android.material.R.attr.colorOnSurfaceVariant,
+ Color.DKGRAY
+ )
+ )
setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f)
setLineSpacing(2f * resources.displayMetrics.density, 1f)
setPadding(0, 3.dp, 0, 0)
@@ -243,9 +263,14 @@ class Raspisanie : BaseActivity() {
}
private fun resolveColor(attr: Int, fallback: Int): Int {
+ val ctx = requireContext()
val value = TypedValue()
- if (!theme.resolveAttribute(attr, value, true)) return fallback
- return if (value.resourceId != 0) ContextCompat.getColor(this, value.resourceId) else value.data
+ if (!ctx.theme.resolveAttribute(attr, value, true)) return fallback
+ return if (value.resourceId != 0) {
+ ContextCompat.getColor(ctx, value.resourceId)
+ } else {
+ value.data
+ }
}
private val Int.dp: Int
diff --git a/app/src/main/java/com/example/helponizer/Settings.kt b/app/src/main/java/com/example/helponizer/SettingsFragment.kt
similarity index 58%
rename from app/src/main/java/com/example/helponizer/Settings.kt
rename to app/src/main/java/com/example/helponizer/SettingsFragment.kt
index b4f8b03..e063859 100644
--- a/app/src/main/java/com/example/helponizer/Settings.kt
+++ b/app/src/main/java/com/example/helponizer/SettingsFragment.kt
@@ -3,6 +3,7 @@ package com.example.helponizer
import android.Manifest
import android.app.NotificationChannel
import android.app.NotificationManager
+import android.content.Context
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.media.MediaPlayer
@@ -10,20 +11,19 @@ import android.os.Build
import android.os.Bundle
import android.view.View
import android.widget.Toast
-import androidx.activity.enableEdgeToEdge
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import androidx.core.content.edit
-import androidx.core.view.ViewCompat
-import androidx.core.view.WindowInsetsCompat
+import androidx.fragment.app.Fragment
import com.google.android.material.button.MaterialButton
-class Settings : BaseActivity() {
+class SettingsFragment : Fragment(R.layout.fragment_settings) {
private var player: MediaPlayer? = null
private lateinit var prefs: SharedPreferences
private var notificationsEnabled = false
+ private var themeChangePending = false
private val requestPermissionLauncher = registerForActivityResult(
ActivityResultContracts.RequestPermission()
@@ -31,69 +31,69 @@ class Settings : BaseActivity() {
if (granted) {
showNotification()
} else {
+ val ctx = context ?: return@registerForActivityResult
Toast.makeText(
- this,
+ ctx,
R.string.notification_permission_denied,
Toast.LENGTH_SHORT
).show()
}
}
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- enableEdgeToEdge()
- setContentView(R.layout.activity_settings)
- ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
- val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
- v.setPadding(systemBars.left, systemBars.top, systemBars.right, 0)
- insets
- }
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
- prefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE)
+ prefs = requireContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
notificationsEnabled = prefs.getBoolean(
KEY_NOTIFICATIONS,
prefs.getInt("shet", 0) == 1
)
- updateNotificationButton()
- IconAnimator.setup(findViewById(R.id.buttonTheme), R.drawable.avd_palette)
- IconAnimator.setup(findViewById(R.id.buttonSound), R.drawable.avd_sound)
- IconAnimator.setup(findViewById(R.id.buttonTextUp), R.drawable.avd_text_up)
- IconAnimator.setup(findViewById(R.id.buttonTextDown), R.drawable.avd_text_down)
- findViewById(R.id.buttonTheme).setOnClickListener {
- IconAnimator.start(it)
- ThemeManager.next(this)
- it.postDelayed({ recreate() }, 250)
+ val themeButton = view.findViewById(R.id.buttonTheme)
+ IconAnimator.setup(themeButton, R.drawable.avd_palette)
+ themeButton.setOnClickListener {
+ if (themeChangePending) return@setOnClickListener
+ themeChangePending = true
+ ThemeManager.next(requireContext())
+ IconAnimator.start(themeButton) { recreateForTheme() }
+ themeButton.postDelayed({ recreateForTheme() }, 500L)
}
- findViewById(R.id.buttonSound).setOnClickListener {
+ val soundButton = view.findViewById(R.id.buttonSound)
+ IconAnimator.setup(soundButton, R.drawable.avd_sound)
+ soundButton.setOnClickListener {
IconAnimator.start(it)
player?.release()
- player = MediaPlayer.create(this, R.raw.click)
+ player = MediaPlayer.create(requireContext(), R.raw.click)
player?.start()
}
- findViewById(R.id.buttonTextUp).setOnClickListener {
+ val textUpButton = view.findViewById(R.id.buttonTextUp)
+ IconAnimator.setup(textUpButton, R.drawable.avd_text_up)
+ textUpButton.setOnClickListener {
IconAnimator.start(it)
- TextSizeManager.increase(this)
- TextSizeManager.applyTo(findViewById(R.id.main))
+ TextSizeManager.increase(requireContext())
+ TextSizeManager.applyTo(requireView())
}
- findViewById(R.id.buttonTextDown).setOnClickListener {
+ val textDownButton = view.findViewById(R.id.buttonTextDown)
+ IconAnimator.setup(textDownButton, R.drawable.avd_text_down)
+ textDownButton.setOnClickListener {
IconAnimator.start(it)
- TextSizeManager.decrease(this)
- TextSizeManager.applyTo(findViewById(R.id.main))
+ TextSizeManager.decrease(requireContext())
+ TextSizeManager.applyTo(requireView())
}
- findViewById(R.id.buttonNotification).setOnClickListener {
+ updateNotificationButton()
+ view.findViewById(R.id.buttonNotification).setOnClickListener {
notificationsEnabled = !notificationsEnabled
prefs.edit { putBoolean(KEY_NOTIFICATIONS, notificationsEnabled) }
updateNotificationButton()
- IconAnimator.start(findViewById(R.id.buttonNotification))
+ IconAnimator.start(it)
if (notificationsEnabled) {
if (ContextCompat.checkSelfPermission(
- this,
+ requireContext(),
Manifest.permission.POST_NOTIFICATIONS
) == PackageManager.PERMISSION_GRANTED
) {
@@ -102,13 +102,21 @@ class Settings : BaseActivity() {
requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
}
} else {
- NotificationManagerCompat.from(this).cancel(NOTIFICATION_ID)
+ NotificationManagerCompat.from(requireContext()).cancel(NOTIFICATION_ID)
}
}
+
+ TextSizeManager.applyTo(view)
+ }
+
+ private fun recreateForTheme() {
+ if (!themeChangePending || !isAdded) return
+ themeChangePending = false
+ requireActivity().recreate()
}
private fun updateNotificationButton() {
- val button = findViewById(R.id.buttonNotification)
+ val button = requireView().findViewById(R.id.buttonNotification)
button.text = getString(
if (notificationsEnabled) R.string.settings_notification_on
else R.string.settings_notification_off
@@ -121,28 +129,25 @@ class Settings : BaseActivity() {
}
private fun showNotification() {
+ val ctx = context ?: return
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
CHANNEL_ID,
getString(R.string.notification_channel_name),
NotificationManager.IMPORTANCE_DEFAULT
)
- getSystemService(NotificationManager::class.java).createNotificationChannel(channel)
+ ctx.getSystemService(NotificationManager::class.java)
+ .createNotificationChannel(channel)
}
- val notification = NotificationCompat.Builder(this, CHANNEL_ID)
+ val notification = NotificationCompat.Builder(ctx, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(getString(R.string.notification_title))
.setContentText(getString(R.string.notification_message))
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.build()
- NotificationManagerCompat.from(this).notify(NOTIFICATION_ID, notification)
- }
-
- override fun onResume() {
- super.onResume()
- TextSizeManager.applyTo(findViewById(R.id.main))
+ NotificationManagerCompat.from(ctx).notify(NOTIFICATION_ID, notification)
}
override fun onDestroy() {
diff --git a/app/src/main/java/com/example/helponizer/Informaition.kt b/app/src/main/java/com/example/helponizer/TipsFragment.kt
similarity index 64%
rename from app/src/main/java/com/example/helponizer/Informaition.kt
rename to app/src/main/java/com/example/helponizer/TipsFragment.kt
index 6904368..d380a1f 100644
--- a/app/src/main/java/com/example/helponizer/Informaition.kt
+++ b/app/src/main/java/com/example/helponizer/TipsFragment.kt
@@ -2,24 +2,14 @@ package com.example.helponizer
import android.os.Bundle
import android.view.View
-import androidx.activity.enableEdgeToEdge
-import androidx.core.view.ViewCompat
-import androidx.core.view.WindowInsetsCompat
+import androidx.fragment.app.Fragment
import androidx.viewpager2.widget.ViewPager2
-class Informaition : BaseActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- enableEdgeToEdge()
- setContentView(R.layout.activity_informaition)
+class TipsFragment : Fragment(R.layout.fragment_tips) {
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
- ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { view, insets ->
- val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
- view.setPadding(systemBars.left, systemBars.top, systemBars.right, 0)
- insets
- }
-
- val pager = findViewById(R.id.tipsPager)
+ val pager = view.findViewById(R.id.tipsPager)
pager.orientation = ViewPager2.ORIENTATION_HORIZONTAL
pager.offscreenPageLimit = 1
pager.adapter = TipsAdapter(
@@ -62,14 +52,8 @@ class Informaition : BaseActivity() {
)
)
)
- }
- override fun onResume() {
- super.onResume()
- val root = findViewById(R.id.main)
- TextSizeManager.applyTo(root)
- findViewById(R.id.tipsPager).post {
- TextSizeManager.applyTo(root)
- }
+ TextSizeManager.applyTo(view)
+ pager.post { TextSizeManager.applyTo(view) }
}
}
diff --git a/app/src/main/java/com/example/helponizer/funny.kt b/app/src/main/java/com/example/helponizer/funny.kt
deleted file mode 100644
index 4de093c..0000000
--- a/app/src/main/java/com/example/helponizer/funny.kt
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.example.helponizer
-
-import android.os.Bundle
-import android.view.View
-import androidx.activity.enableEdgeToEdge
-import androidx.core.view.ViewCompat
-import androidx.core.view.WindowInsetsCompat
-
-class funny : BaseActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- enableEdgeToEdge()
- setContentView(R.layout.activity_funny)
-
- val root = findViewById(R.id.main)
- val baseLeft = root.paddingLeft
- val baseTop = root.paddingTop
- val baseRight = root.paddingRight
- val baseBottom = root.paddingBottom
- ViewCompat.setOnApplyWindowInsetsListener(root) { view, insets ->
- val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
- view.setPadding(
- baseLeft + systemBars.left,
- baseTop + systemBars.top,
- baseRight + systemBars.right,
- baseBottom
- )
- insets
- }
- }
-
- override fun onResume() {
- super.onResume()
- TextSizeManager.applyTo(findViewById(R.id.main))
- }
-}
diff --git a/app/src/main/java/com/example/helponizer/infoProgram.kt b/app/src/main/java/com/example/helponizer/infoProgram.kt
deleted file mode 100644
index 9d85761..0000000
--- a/app/src/main/java/com/example/helponizer/infoProgram.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.example.helponizer
-
-import android.os.Bundle
-import androidx.activity.enableEdgeToEdge
-import androidx.core.view.ViewCompat
-import androidx.core.view.WindowInsetsCompat
-
-class infoProgram : BaseActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- enableEdgeToEdge()
- setContentView(R.layout.activity_info_program)
-
- ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { view, insets ->
- val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
- view.setPadding(systemBars.left, systemBars.top, systemBars.right, 0)
- insets
- }
- }
-
- override fun onResume() {
- super.onResume()
- TextSizeManager.applyTo(findViewById(R.id.main))
- }
-}
diff --git a/app/src/main/res/layout/activity_base.xml b/app/src/main/res/layout/activity_base.xml
deleted file mode 100644
index 6fb4887..0000000
--- a/app/src/main/res/layout/activity_base.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
-
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 55192b1..90f0987 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -1,108 +1,29 @@
-
+ android:clipChildren="true"
+ android:orientation="vertical">
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ android:background="?android:attr/colorBackground"
+ android:minHeight="80dp"
+ app:elevation="0dp"
+ app:itemTextAppearanceActive="@style/TextAppearance.Helponizer.BottomNav"
+ app:itemTextAppearanceInactive="@style/TextAppearance.Helponizer.BottomNav"
+ app:labelVisibilityMode="labeled"
+ app:menu="@menu/bottom_nav_menu" />
+
diff --git a/app/src/main/res/layout/activity_info_program.xml b/app/src/main/res/layout/fragment_about.xml
similarity index 98%
rename from app/src/main/res/layout/activity_info_program.xml
rename to app/src/main/res/layout/fragment_about.xml
index 3badc29..15e7bc2 100644
--- a/app/src/main/res/layout/activity_info_program.xml
+++ b/app/src/main/res/layout/fragment_about.xml
@@ -7,7 +7,7 @@
android:layout_height="match_parent"
android:background="?android:attr/colorBackground"
android:fillViewport="true"
- tools:context=".infoProgram">
+ tools:context=".AboutFragment">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_funny.xml b/app/src/main/res/layout/fragment_party.xml
similarity index 96%
rename from app/src/main/res/layout/activity_funny.xml
rename to app/src/main/res/layout/fragment_party.xml
index 257ac2d..688a0d8 100644
--- a/app/src/main/res/layout/activity_funny.xml
+++ b/app/src/main/res/layout/fragment_party.xml
@@ -10,7 +10,7 @@
android:paddingTop="32dp"
android:paddingEnd="24dp"
android:paddingBottom="24dp"
- tools:context=".funny">
+ tools:context=".PartyFragment">
+ tools:context=".ScheduleFragment">
+ tools:context=".SettingsFragment">
+ tools:context=".TipsFragment">