-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
231e687
commit 7b05b2e
Showing
34 changed files
with
718 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package cn.super12138.todo.utils | ||
|
||
import android.content.Context | ||
import android.os.SystemClock | ||
import android.view.View | ||
import android.widget.Toast | ||
import cn.super12138.todo.ToDoApp | ||
|
||
private var clickInterval = 400L | ||
private var lastTime = 0L | ||
|
||
/** | ||
* 延迟点击 | ||
*/ | ||
fun View.setOnIntervalClickListener(onIntervalClickListener: (View) -> Unit) { | ||
this.setOnClickListener { | ||
if (SystemClock.elapsedRealtime() - lastTime > clickInterval) { | ||
lastTime = SystemClock.elapsedRealtime() | ||
onIntervalClickListener.invoke(it) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Toast | ||
*/ | ||
fun String.showToast( | ||
context: Context = ToDoApp.context, | ||
duration: Int = Toast.LENGTH_SHORT | ||
) { | ||
Toast.makeText(context, this, duration).show() | ||
} | ||
|
||
fun Int.showToast(context: Context = ToDoApp.context, duration: Int = Toast.LENGTH_SHORT) { | ||
Toast.makeText(context, this, duration).show() | ||
} |
1 change: 0 additions & 1 deletion
1
app/src/main/kotlin/cn/super12138/todo/views/all/AllTasksActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
app/src/main/kotlin/cn/super12138/todo/views/welcome/WelcomeActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
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 | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.commit | ||
import androidx.lifecycle.Observer | ||
import cn.super12138.todo.R | ||
import cn.super12138.todo.constant.GlobalValues | ||
import cn.super12138.todo.databinding.ActivityWelcomeBinding | ||
import cn.super12138.todo.utils.VibrationUtils | ||
import cn.super12138.todo.utils.setOnIntervalClickListener | ||
import cn.super12138.todo.views.BaseActivity | ||
import cn.super12138.todo.views.main.MainActivity | ||
import cn.super12138.todo.views.welcome.pages.IntroPage | ||
import cn.super12138.todo.views.welcome.pages.ProgressPage | ||
import cn.super12138.todo.views.welcome.pages.ToDoBtnPage | ||
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) | ||
|
||
val previousBtn = binding.previousBtn | ||
val nextBtn = binding.nextBtn | ||
val centerBtn = binding.centerBtn | ||
|
||
val currentPage = viewModel.currentPage // 0: Intro 1: Progress 2: ToDo Btn 3: ToDo Item | ||
|
||
centerBtn.setOnIntervalClickListener { | ||
VibrationUtils.performHapticFeedback(it) | ||
|
||
centerBtn.hide() | ||
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 | ||
} | ||
} | ||
|
||
previousBtn.setOnIntervalClickListener { | ||
VibrationUtils.performHapticFeedback(it) | ||
|
||
currentPage.value = currentPage.value?.minus(1) | ||
} | ||
|
||
nextBtn.setOnIntervalClickListener { | ||
VibrationUtils.performHapticFeedback(it) | ||
|
||
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 { | ||
text = getString(R.string.start) | ||
icon = AppCompatResources.getDrawable( | ||
this@WelcomeActivity, | ||
R.drawable.ic_arrow_forward | ||
) | ||
show() | ||
} | ||
nextBtn.hide() | ||
previousBtn.hide() | ||
} | ||
|
||
in 1..2 -> { | ||
centerBtn.hide() | ||
previousBtn.show() | ||
nextBtn.show() | ||
} | ||
|
||
3 -> { | ||
centerBtn.apply { | ||
text = getString(R.string.enter_app) | ||
icon = AppCompatResources.getDrawable( | ||
this@WelcomeActivity, | ||
R.drawable.ic_focus | ||
) | ||
show() | ||
} | ||
previousBtn.show() | ||
nextBtn.hide() | ||
} | ||
|
||
else -> { | ||
if (page > 3) currentPage.value = 3 | ||
|
||
if (page < 0) currentPage.value = 0 | ||
} | ||
} | ||
}) | ||
|
||
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) { | ||
override fun handleOnBackPressed() { | ||
if (currentPage.value == 0) { | ||
finish() | ||
} else { | ||
currentPage.value = currentPage.value?.minus(1) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
override fun getViewBinding(): ActivityWelcomeBinding { | ||
return ActivityWelcomeBinding.inflate(layoutInflater) | ||
} | ||
|
||
private fun getCurrentPage(pageIndex: Int): Fragment { | ||
return when (pageIndex) { | ||
0 -> IntroPage() | ||
1 -> ProgressPage() | ||
2 -> ToDoBtnPage() | ||
3 -> ToDoItemPage() | ||
else -> IntroPage() | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/kotlin/cn/super12138/todo/views/welcome/WelcomeViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package cn.super12138.todo.views.welcome | ||
|
||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
|
||
class WelcomeViewModel : ViewModel() { | ||
val currentPage = MutableLiveData<Int>(0) | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/kotlin/cn/super12138/todo/views/welcome/pages/BasePage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cn.super12138.todo.views.welcome.pages | ||
|
||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import com.google.android.material.transition.MaterialSharedAxis | ||
|
||
open class BasePage : Fragment() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
enterTransition = MaterialSharedAxis(MaterialSharedAxis.X, /* forward= */ true) | ||
returnTransition = MaterialSharedAxis(MaterialSharedAxis.X, /* forward= */ false) | ||
exitTransition = MaterialSharedAxis(MaterialSharedAxis.X, /* forward= */ true) | ||
reenterTransition = MaterialSharedAxis(MaterialSharedAxis.X, /* forward= */ false) | ||
} | ||
} |
Oops, something went wrong.