Skip to content

Commit

Permalink
Improve fragment motion
Browse files Browse the repository at this point in the history
  • Loading branch information
Super12138 committed Sep 7, 2024
1 parent 1bf5a83 commit 007668f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ abstract class ToDoRoomDB : RoomDatabase() {
ToDoRoomDB::class.java,
"todo"
).build()

INSTANCE = instance
instance
return instance
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/cn/super12138/todo/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.view.View
import android.widget.Toast
import cn.super12138.todo.ToDoApp

private var clickInterval = 400L
private var clickInterval = 380L
private var lastTime = 0L

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package cn.super12138.todo.views.welcome
import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.view.MotionEvent
import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.activity.viewModels
import androidx.appcompat.content.res.AppCompatResources
Expand All @@ -25,6 +23,7 @@ import cn.super12138.todo.views.welcome.pages.ToDoItemPage

class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
private val viewModel by viewModels<WelcomeViewModel>()

@SuppressLint("ClickableViewAccessibility")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -42,36 +41,34 @@ class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
nextBtn.show()
previousBtn.show()


if (currentPage.value == 3) {
GlobalValues.welcomePage = true
finish()
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
} else {
currentPage.value = 1
nextPage(1)
}
}

previousBtn.setOnIntervalClickListener {
VibrationUtils.performHapticFeedback(it)

supportFragmentManager.popBackStack()

currentPage.value = currentPage.value?.minus(1)
}

nextBtn.setOnIntervalClickListener {
VibrationUtils.performHapticFeedback(it)

nextPage(currentPage.value!!.plus(1))

currentPage.value = currentPage.value?.plus(1)
}

currentPage.observe(this, Observer { page ->
supportFragmentManager.commit {
addToBackStack(System.currentTimeMillis().toString())
hide(supportFragmentManager.fragments.last())
add(R.id.welcome_page_container, getCurrentPage(page))
}

when (page) {
0 -> {
centerBtn.apply {
Expand Down Expand Up @@ -118,6 +115,7 @@ class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
if (currentPage.value == 0) {
finish()
} else {
supportFragmentManager.popBackStack()
currentPage.value = currentPage.value?.minus(1)
}
}
Expand All @@ -137,4 +135,12 @@ class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
else -> IntroPage()
}
}

private fun nextPage(page: Int) {
supportFragmentManager.commit {
addToBackStack(System.currentTimeMillis().toString())
hide(supportFragmentManager.fragments.last())
add(R.id.welcome_page_container, getCurrentPage(page))
}
}
}

0 comments on commit 007668f

Please sign in to comment.