Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add state to splash screen (Issue 57) #69

Merged
merged 2 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.android254.droidconKE2020.core.PreferencesImpl
import com.example.android_animation.AndroidAnimation
import com.example.android_animation.enums.Easing
import kotlinx.android.synthetic.main.activity_splash_screen.*
Expand All @@ -17,18 +18,28 @@ class SplashScreenActivity : AppCompatActivity() {
private val MAX_TRANSLATION_X = 310f
private val MAX_TRANSLATION_Y = 170f

private lateinit var preferencesImpl: PreferencesImpl

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash_screen)
startAnimation()
preferencesImpl = PreferencesImpl(this)
val showSplashScreen = preferencesImpl.getShowSplashScreen()
if (showSplashScreen) startAnimation() else navigateToHome()
}

private fun navigateToHome() {
startActivity(Intent(this@SplashScreenActivity, HomeActivity::class.java))
finish()
}

private fun startAnimation() {
AndroidAnimation().apply {
delay = 1000
delay = 300
targetViews(imageViewLogo)
scaleX(MAX_SCALE)
scaleY(MAX_SCALE)
duration = 1000
thenPlay()
easing = Easing.EXP_IN
translateX(MAX_TRANSLATION_X)
Expand All @@ -39,7 +50,7 @@ class SplashScreenActivity : AppCompatActivity() {
thenPlay()
easing = Easing.CIRC_OUT
translateX(-MAX_TRANSLATION_X)
translateY(-MAX_TRANSLATION_Y, delay = 5400)
translateY(-MAX_TRANSLATION_Y, delay = 3500)
scaleX(MIN_SCALE)
scaleY(MIN_SCALE)
rotate(MAX_ROTATION)
Expand All @@ -48,8 +59,8 @@ class SplashScreenActivity : AppCompatActivity() {
scaleY((MIN_SCALE + .2f), 1f, MAX_SCALE, 1f)
alpha(1f)
onAnimationEnd {
startActivity(Intent(this@SplashScreenActivity, HomeActivity::class.java))
finish()
preferencesImpl.setShowSplashScreen(false)
navigateToHome()
}
start()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import android.content.SharedPreferences
interface Preferences {
val sharedPref: SharedPreferences

// fun getUserName(defaultValue: String): String?
// fun setUserName(username: String)
fun getShowSplashScreen(): Boolean
fun setShowSplashScreen(showSplashScreen: Boolean)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class PreferencesImpl(context: Context): Preferences {
}
}

// override fun getUserName(defaultValue: String): String? {
// return sharedPref.getString("userName", defaultValue)
// }
//
// override fun setUserName(username: String) {
// editSharedPref {
// it.putString("userName", username)
// }
// }
override fun getShowSplashScreen(): Boolean {
return sharedPref.getBoolean("showSplashScreen", true)
}

override fun setShowSplashScreen(showSplashScreen: Boolean) {
editSharedPref {
it.putBoolean("showSplashScreen", showSplashScreen)
}
}
}