2020-02-25 15:25:45 +01:00
/ * *
* ProjectLaogai
*
* Copyright 2019 - 2020 < seil0 @mosad . xyz >
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston ,
* MA 02110 - 1301 , USA .
*
* /
2020-02-23 20:09:27 +01:00
package org.mosad.seil0.projectlaogai
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.view.View
2020-08-11 17:09:46 +02:00
import android.widget.EditText
2020-02-23 20:09:27 +01:00
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
2020-02-25 15:25:45 +01:00
import androidx.core.text.HtmlCompat
2020-02-23 20:09:27 +01:00
import androidx.viewpager.widget.ViewPager
2020-02-25 15:25:45 +01:00
import com.afollestad.materialdialogs.callbacks.onDismiss
2020-02-23 20:09:27 +01:00
import kotlinx.android.synthetic.main.activity_onboarding.*
import org.mosad.seil0.projectlaogai.fragments.SettingsFragment
import org.mosad.seil0.projectlaogai.onboarding.ViewPagerAdapter
class OnboardingActivity : AppCompatActivity ( ) {
companion object {
2020-08-11 17:09:46 +02:00
val layouts = intArrayOf ( R . layout . fragment _on _welcome , R . layout . fragment _on _course , R . layout . fragment _on _login )
2020-02-23 20:09:27 +01:00
}
private lateinit var viewPager : ViewPager
private lateinit var viewPagerAdapter : ViewPagerAdapter
private lateinit var linLayoutDots : LinearLayout
private lateinit var dots : Array < TextView >
2020-08-11 17:09:46 +02:00
private lateinit var editTextEmail : EditText
private lateinit var editTextPassword : EditText
2020-02-23 20:09:27 +01:00
override fun onCreate ( savedInstanceState : Bundle ? ) {
super . onCreate ( savedInstanceState )
setContentView ( R . layout . activity _onboarding )
viewPager = findViewById ( R . id . viewPager )
linLayoutDots = findViewById ( R . id . linLayout _Dots )
addBottomDots ( 0 )
viewPagerAdapter = ViewPagerAdapter ( this )
viewPager . adapter = viewPagerAdapter
viewPager . addOnPageChangeListener ( viewPagerPageChangeListener )
2020-08-11 17:09:46 +02:00
// we don't use the skip button, instead we use the start button to skip the last fragment
btn _Skip . visibility = View . GONE
2020-02-23 20:09:27 +01:00
}
2020-02-25 15:25:45 +01:00
fun btnNextClick ( @Suppress ( " UNUSED_PARAMETER " ) v : View ) {
2020-02-23 20:09:27 +01:00
if ( viewPager . currentItem < layouts . size - 1 ) {
viewPager . currentItem ++
} else {
launchHomeScreen ( )
}
}
2020-02-25 15:25:45 +01:00
fun btnSkipClick ( @Suppress ( " UNUSED_PARAMETER " ) v : View ) {
2020-02-23 20:09:27 +01:00
launchHomeScreen ( )
}
2020-02-25 15:25:45 +01:00
fun btnSelectCourseClick ( @Suppress ( " UNUSED_PARAMETER " ) v : View ) {
SettingsFragment ( ) . selectCourse ( this ) . show {
onDismiss {
2020-08-11 17:09:46 +02:00
btnNextClick ( v ) // show the next fragment
2020-02-25 15:25:45 +01:00
}
}
2020-02-23 20:09:27 +01:00
}
2020-08-11 17:09:46 +02:00
fun btnLoginClick ( @Suppress ( " UNUSED_PARAMETER " ) v : View ) {
editTextEmail = findViewById ( R . id . editText _email )
editTextPassword = findViewById ( R . id . editText _password )
// get login credentials from gui
val email = editTextEmail . text . toString ( )
val password = editTextPassword . text . toString ( )
println ( " Login: $email : $password " )
// call LoginController
//launchHomeScreen()
}
2020-02-23 20:09:27 +01:00
private fun addBottomDots ( currentPage : Int ) {
dots = Array ( layouts . size ) { TextView ( this ) }
linLayoutDots . removeAllViews ( )
dots . forEach {
2020-02-25 15:25:45 +01:00
it . text = HtmlCompat . fromHtml ( " • " , HtmlCompat . FROM _HTML _MODE _LEGACY )
2020-02-23 20:09:27 +01:00
it . textSize = 35f
it . setTextColor ( Color . parseColor ( " #cccccc " ) )
linLayoutDots . addView ( it )
}
if ( dots . isNotEmpty ( ) )
dots [ currentPage ] . setTextColor ( Color . parseColor ( " #000000 " ) )
}
private fun launchHomeScreen ( ) {
startActivity ( Intent ( this , MainActivity :: class . java ) )
2020-02-27 12:13:46 +01:00
finish ( )
2020-02-23 20:09:27 +01:00
}
private var viewPagerPageChangeListener : ViewPager . OnPageChangeListener = object : ViewPager . OnPageChangeListener {
override fun onPageSelected ( position : Int ) {
addBottomDots ( position )
2020-08-11 17:09:46 +02:00
// changing the next button text to skip for the login fragment
2020-02-23 20:09:27 +01:00
if ( position == layouts . size - 1 ) {
2020-08-11 17:09:46 +02:00
btn _Next . text = getString ( R . string . skip )
2020-02-23 20:09:27 +01:00
btn _Next . visibility = View . VISIBLE
btn _Skip . visibility = View . GONE
} else {
btn _Next . visibility = View . GONE
btn _Skip . visibility = View . GONE
}
}
override fun onPageScrolled ( arg0 : Int , arg1 : Float , arg2 : Int ) { }
override fun onPageScrollStateChanged ( arg0 : Int ) { }
}
}