Onboarding [Part 2]
* call the onboarding activity on first start * reworked selectCourse(() to work outside of the SettingsFragment * closes #36
This commit is contained in:
parent
e15bf95b85
commit
ccc0f0f2bc
|
@ -11,7 +11,7 @@ android {
|
||||||
minSdkVersion 23
|
minSdkVersion 23
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 15
|
versionCode 15
|
||||||
versionName "0.5.1"
|
versionName "0.5.90"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
resValue "string", "build_time", buildTime()
|
resValue "string", "build_time", buildTime()
|
||||||
setProperty("archivesBaseName", "projectlaogai-$versionName")
|
setProperty("archivesBaseName", "projectlaogai-$versionName")
|
||||||
|
@ -48,6 +48,7 @@ dependencies {
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'
|
||||||
|
implementation 'androidx.core:core:1.2.0'
|
||||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
|
||||||
|
@ -61,7 +62,7 @@ dependencies {
|
||||||
|
|
||||||
implementation 'org.apache.commons:commons-lang3:3.9'
|
implementation 'org.apache.commons:commons-lang3:3.9'
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.13'
|
||||||
androidTestImplementation 'androidx.test:runner:1.2.0'
|
androidTestImplementation 'androidx.test:runner:1.2.0'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,9 +97,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
// open the activeFragment, default is the HomeFragment
|
// open the activeFragment, default is the HomeFragment
|
||||||
fragmentTransaction.replace(R.id.fragment_container, activeFragment)
|
fragmentTransaction.replace(R.id.fragment_container, activeFragment)
|
||||||
fragmentTransaction.commit()
|
fragmentTransaction.commit()
|
||||||
|
|
||||||
//println("starting Onboarding")
|
|
||||||
//startActivity(Intent(this, OnboardingActivity::class.java))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onNewIntent(intent: Intent) {
|
override fun onNewIntent(intent: Intent) {
|
||||||
|
@ -184,13 +181,14 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
private fun initAesthetic() {
|
private fun initAesthetic() {
|
||||||
// If we haven't set any defaults, do that now
|
// If we haven't set any defaults, do that now
|
||||||
if (Aesthetic.isFirstTime) {
|
if (Aesthetic.isFirstTime) {
|
||||||
// this is executed on the first app start, use this to show tutorial etc.
|
// set the default theme at the first app start
|
||||||
Aesthetic.config {
|
Aesthetic.config {
|
||||||
activityTheme(R.style.AppTheme_Light)
|
activityTheme(R.style.AppTheme_Light)
|
||||||
apply()
|
apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingsFragment().selectCourse(this) // FIXME this is not working
|
// show the onboarding activity
|
||||||
|
startActivity(Intent(this, OnboardingActivity::class.java))
|
||||||
}
|
}
|
||||||
|
|
||||||
Aesthetic.config {
|
Aesthetic.config {
|
||||||
|
|
|
@ -1,19 +1,41 @@
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
package org.mosad.seil0.projectlaogai
|
package org.mosad.seil0.projectlaogai
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.Html
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.text.HtmlCompat
|
||||||
import androidx.viewpager.widget.ViewPager
|
import androidx.viewpager.widget.ViewPager
|
||||||
|
import com.afollestad.materialdialogs.callbacks.onDismiss
|
||||||
import kotlinx.android.synthetic.main.activity_onboarding.*
|
import kotlinx.android.synthetic.main.activity_onboarding.*
|
||||||
import org.mosad.seil0.projectlaogai.fragments.SettingsFragment
|
import org.mosad.seil0.projectlaogai.fragments.SettingsFragment
|
||||||
import org.mosad.seil0.projectlaogai.onboarding.ViewPagerAdapter
|
import org.mosad.seil0.projectlaogai.onboarding.ViewPagerAdapter
|
||||||
|
|
||||||
|
|
||||||
class OnboardingActivity : AppCompatActivity() {
|
class OnboardingActivity : AppCompatActivity() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -40,7 +62,7 @@ class OnboardingActivity : AppCompatActivity() {
|
||||||
btn_Skip.visibility = View.GONE // without the the skip button is visible
|
btn_Skip.visibility = View.GONE // without the the skip button is visible
|
||||||
}
|
}
|
||||||
|
|
||||||
fun btnNextClick(v: View) {
|
fun btnNextClick(@Suppress("UNUSED_PARAMETER")v: View) {
|
||||||
if (viewPager.currentItem < layouts.size - 1) {
|
if (viewPager.currentItem < layouts.size - 1) {
|
||||||
viewPager.currentItem++
|
viewPager.currentItem++
|
||||||
} else {
|
} else {
|
||||||
|
@ -48,12 +70,16 @@ class OnboardingActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun btnSkipClick(v: View) {
|
fun btnSkipClick(@Suppress("UNUSED_PARAMETER")v: View) {
|
||||||
launchHomeScreen()
|
launchHomeScreen()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun btnSelectCourseClick(v: View) {
|
fun btnSelectCourseClick(@Suppress("UNUSED_PARAMETER")v: View) {
|
||||||
SettingsFragment().selectCourse(this) // TODO
|
SettingsFragment().selectCourse(this).show {
|
||||||
|
onDismiss {
|
||||||
|
launchHomeScreen() // launch the home-screen activity after the dialog is dismissed
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addBottomDots(currentPage: Int) {
|
private fun addBottomDots(currentPage: Int) {
|
||||||
|
@ -61,7 +87,7 @@ class OnboardingActivity : AppCompatActivity() {
|
||||||
linLayoutDots.removeAllViews()
|
linLayoutDots.removeAllViews()
|
||||||
|
|
||||||
dots.forEach {
|
dots.forEach {
|
||||||
it.text = Html.fromHtml("•")
|
it.text = HtmlCompat.fromHtml("•", HtmlCompat.FROM_HTML_MODE_LEGACY)
|
||||||
it.textSize = 35f
|
it.textSize = 35f
|
||||||
it.setTextColor(Color.parseColor("#cccccc"))
|
it.setTextColor(Color.parseColor("#cccccc"))
|
||||||
linLayoutDots.addView(it)
|
linLayoutDots.addView(it)
|
||||||
|
|
|
@ -30,9 +30,11 @@ import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.Switch
|
import android.widget.Switch
|
||||||
|
import android.widget.TextView
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import com.afollestad.aesthetic.Aesthetic
|
import com.afollestad.aesthetic.Aesthetic
|
||||||
import com.afollestad.materialdialogs.MaterialDialog
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
|
import com.afollestad.materialdialogs.callbacks.onDismiss
|
||||||
import com.afollestad.materialdialogs.color.colorChooser
|
import com.afollestad.materialdialogs.color.colorChooser
|
||||||
import com.afollestad.materialdialogs.customview.customView
|
import com.afollestad.materialdialogs.customview.customView
|
||||||
import com.afollestad.materialdialogs.list.listItems
|
import com.afollestad.materialdialogs.list.listItems
|
||||||
|
@ -67,6 +69,7 @@ class SettingsFragment : Fragment() {
|
||||||
private lateinit var linLayoutPrimaryColor: LinearLayout
|
private lateinit var linLayoutPrimaryColor: LinearLayout
|
||||||
private lateinit var linLayoutAccentColor: LinearLayout
|
private lateinit var linLayoutAccentColor: LinearLayout
|
||||||
private lateinit var switchBuffet: Switch
|
private lateinit var switchBuffet: Switch
|
||||||
|
private lateinit var txtViewCourse: TextView
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
|
|
||||||
|
@ -80,6 +83,8 @@ class SettingsFragment : Fragment() {
|
||||||
linLayoutPrimaryColor = view.findViewById(R.id.linLayout_PrimaryColor)
|
linLayoutPrimaryColor = view.findViewById(R.id.linLayout_PrimaryColor)
|
||||||
linLayoutAccentColor = view.findViewById(R.id.linLayout_AccentColor)
|
linLayoutAccentColor = view.findViewById(R.id.linLayout_AccentColor)
|
||||||
switchBuffet = view.findViewById(R.id.switch_buffet)
|
switchBuffet = view.findViewById(R.id.switch_buffet)
|
||||||
|
// if we call txtView_Course via KAE view binding it'll result in a NPE in the onDismissed call
|
||||||
|
txtViewCourse = view.findViewById(R.id.txtView_Course)
|
||||||
|
|
||||||
initActions()
|
initActions()
|
||||||
|
|
||||||
|
@ -128,7 +133,11 @@ class SettingsFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
linLayoutCourse.setOnClickListener {
|
linLayoutCourse.setOnClickListener {
|
||||||
selectCourse(context!!)
|
selectCourse(context!!).show {
|
||||||
|
onDismiss {
|
||||||
|
txtViewCourse.text = cCourse.courseName // update txtView after the dialog is dismissed
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
linLayoutAbout.setOnClickListener {
|
linLayoutAbout.setOnClickListener {
|
||||||
|
@ -229,21 +238,21 @@ class SettingsFragment : Fragment() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun selectCourse(context: Context) {
|
fun selectCourse(context: Context) : MaterialDialog {
|
||||||
val courseNameList = ArrayList<String>()
|
val courseNameList = ArrayList<String>()
|
||||||
coursesList.forEach { (_, courseName) ->
|
coursesList.forEach { (_, courseName) ->
|
||||||
courseNameList.add(courseName)
|
courseNameList.add(courseName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// open a new dialog
|
// return a new course selection dialog
|
||||||
MaterialDialog(context)
|
return MaterialDialog(context)
|
||||||
.title(R.string.select_course)
|
.title(R.string.select_course)
|
||||||
.listItems(items = courseNameList) { _, index, _ ->
|
.listItems(items = courseNameList) { _, index, _ ->
|
||||||
|
|
||||||
val dialog = MaterialDialog(context).cancelable(false)
|
val loadingDialog = MaterialDialog(context).cancelable(false)
|
||||||
.cancelOnTouchOutside(false)
|
.cancelOnTouchOutside(false)
|
||||||
.customView(R.layout.dialog_loading)
|
.customView(R.layout.dialog_loading)
|
||||||
dialog.show()
|
loadingDialog.show()
|
||||||
|
|
||||||
GlobalScope.launch(Dispatchers.Default) {
|
GlobalScope.launch(Dispatchers.Default) {
|
||||||
PreferencesController.saveCourse(context, coursesList[index]) // save the course
|
PreferencesController.saveCourse(context, coursesList[index]) // save the course
|
||||||
|
@ -259,13 +268,11 @@ class SettingsFragment : Fragment() {
|
||||||
CacheController.readTimetable(cCourse.courseName, 1, context)
|
CacheController.readTimetable(cCourse.courseName, 1, context)
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
dialog.dismiss()
|
loadingDialog.dismiss()
|
||||||
txtView_Course.text = cCourse.courseName // update txtView
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
.show()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue