Created
May 7, 2019 20:11
-
-
Save Younes-Charfaoui/791d1b7e172611ad69117a4553d441fd to your computer and use it in GitHub Desktop.
Activity that uses AppIntro Slidrs
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
package com.example.introsliders | |
import android.content.Intent | |
import android.os.Bundle | |
import android.util.Log | |
import androidx.fragment.app.Fragment | |
import com.github.paolorotolo.appintro.AppIntro | |
import com.github.paolorotolo.appintro.AppIntro2Fragment | |
import com.github.paolorotolo.appintro.model.SliderPage | |
import com.github.paolorotolo.appintro.model.SliderPagerBuilder | |
class WelcomeActivity : AppIntro() { | |
private lateinit var manager: PreferencesManager | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
manager = PreferencesManager(this) | |
if (manager.isFirstRun()) { | |
showIntroSlides() | |
} else { | |
goToMain() | |
} | |
} | |
private fun showIntroSlides() { | |
manager.setFirstRun() | |
val pageOne = SliderPagerBuilder() | |
.title(getString(R.string.slide_one_top_text)) | |
.description(getString(R.string.slide_one_down_text)) | |
.imageDrawable(R.drawable.logo) | |
.bgColor(getColor(R.color.slide_one)) | |
.build() | |
val pageTwo = SliderPagerBuilder() | |
.title(getString(R.string.slide_two_top_text)) | |
.description(getString(R.string.slide_two_down_text)) | |
.imageDrawable(R.drawable.notebook_with_logo) | |
.bgColor(getColor(R.color.slide_two)) | |
.build() | |
val pageThree = SliderPagerBuilder() | |
.title(getString(R.string.slide_three_top_text)) | |
.description(getString(R.string.slide_three_down_text)) | |
.imageDrawable(R.drawable.bow_classic_brown) | |
.bgColor(getColor(R.color.slide_three)) | |
.build() | |
val pageFour = SliderPagerBuilder() | |
.title(getString(R.string.slide_four_top_text)) | |
.description(getString(R.string.slide_four_down_text)) | |
.imageDrawable(R.drawable.taget_and_arrow) | |
.bgColor(getColor(R.color.slide_four)) | |
.build() | |
addSlide(AppIntro2Fragment.newInstance(pageOne)) | |
addSlide(AppIntro2Fragment.newInstance(pageTwo)) | |
addSlide(AppIntro2Fragment.newInstance(pageThree)) | |
addSlide(AppIntro2Fragment.newInstance(pageFour)) | |
showStatusBar(false) | |
setFadeAnimation() | |
} | |
private fun goToMain() { | |
startActivity(Intent(this, MainActivity::class.java)) | |
} | |
override fun onSkipPressed(currentFragment: Fragment?) { | |
super.onSkipPressed(currentFragment) | |
goToMain() | |
} | |
override fun onDonePressed(currentFragment: Fragment?) { | |
super.onDonePressed(currentFragment) | |
goToMain() | |
} | |
override fun onSlideChanged(oldFragment: Fragment?, newFragment: Fragment?) { | |
super.onSlideChanged(oldFragment, newFragment) | |
Log.d("Hello", "Changed") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think for your code to work,
WelcomeActivity
needs to be the launch activity in the manifest. It will work fine but it's not the recommended way in the official docs here : https://github.com/AppIntro/AppIntro#basic-usage (last paragraph). I, find it a bit of a waste to makeWelcomeActivity
as the launch activity knowing that it will be only true the first time.Honestly I couldn't find a better way to manage this. I kept the main activity as a launch activity as recommended in the docs like this :
Works fine but that's not optimal because, while being on the first intro screen, clicking on the android back button will skip to the main activity instead of doing nothing. Putting
setContentView(R.layout.activity_main)
in an else block does not run any of the two activities and I do not know exactly why.So, I could not find the perfect solution to satisfies everything.