Browse Source

Onboarding [Part 2]

* call the onboarding activity on first start
* reworked selectCourse(() to work outside of the SettingsFragment
* closes #36
pull/46/head
Jannik 2 years ago
parent
commit
ccc0f0f2bc
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 5
      app/build.gradle
  2. 8
      app/src/main/java/org/mosad/seil0/projectlaogai/MainActivity.kt
  3. 40
      app/src/main/java/org/mosad/seil0/projectlaogai/OnboardingActivity.kt
  4. 25
      app/src/main/java/org/mosad/seil0/projectlaogai/fragments/SettingsFragment.kt

5
app/build.gradle

@ -11,7 +11,7 @@ android {
minSdkVersion 23
targetSdkVersion 29
versionCode 15
versionName "0.5.1"
versionName "0.5.90"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
resValue "string", "build_time", buildTime()
setProperty("archivesBaseName", "projectlaogai-$versionName")
@ -48,6 +48,7 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
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.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
@ -61,7 +62,7 @@ dependencies {
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.espresso:espresso-core:3.2.0'
}

8
app/src/main/java/org/mosad/seil0/projectlaogai/MainActivity.kt

@ -97,9 +97,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
// open the activeFragment, default is the HomeFragment
fragmentTransaction.replace(R.id.fragment_container, activeFragment)
fragmentTransaction.commit()
//println("starting Onboarding")
//startActivity(Intent(this, OnboardingActivity::class.java))
}
override fun onNewIntent(intent: Intent) {
@ -184,13 +181,14 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
private fun initAesthetic() {
// If we haven't set any defaults, do that now
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 {
activityTheme(R.style.AppTheme_Light)
apply()
}
SettingsFragment().selectCourse(this) // FIXME this is not working
// show the onboarding activity
startActivity(Intent(this, OnboardingActivity::class.java))
}
Aesthetic.config {

40
app/src/main/java/org/mosad/seil0/projectlaogai/OnboardingActivity.kt

@ -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
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.text.Html
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.text.HtmlCompat
import androidx.viewpager.widget.ViewPager
import com.afollestad.materialdialogs.callbacks.onDismiss
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 {
@ -40,7 +62,7 @@ class OnboardingActivity : AppCompatActivity() {
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) {
viewPager.currentItem++
} else {
@ -48,12 +70,16 @@ class OnboardingActivity : AppCompatActivity() {
}
}
fun btnSkipClick(v: View) {
fun btnSkipClick(@Suppress("UNUSED_PARAMETER")v: View) {
launchHomeScreen()
}
fun btnSelectCourseClick(v: View) {
SettingsFragment().selectCourse(this) // TODO
fun btnSelectCourseClick(@Suppress("UNUSED_PARAMETER")v: View) {
SettingsFragment().selectCourse(this).show {
onDismiss {
launchHomeScreen() // launch the home-screen activity after the dialog is dismissed
}
}
}
private fun addBottomDots(currentPage: Int) {
@ -61,7 +87,7 @@ class OnboardingActivity : AppCompatActivity() {
linLayoutDots.removeAllViews()
dots.forEach {
it.text = Html.fromHtml("&#8226;")
it.text = HtmlCompat.fromHtml("&#8226;", HtmlCompat.FROM_HTML_MODE_LEGACY)
it.textSize = 35f
it.setTextColor(Color.parseColor("#cccccc"))
linLayoutDots.addView(it)

25
app/src/main/java/org/mosad/seil0/projectlaogai/fragments/SettingsFragment.kt

@ -30,9 +30,11 @@ import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.Switch
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.afollestad.aesthetic.Aesthetic
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.callbacks.onDismiss
import com.afollestad.materialdialogs.color.colorChooser
import com.afollestad.materialdialogs.customview.customView
import com.afollestad.materialdialogs.list.listItems
@ -67,6 +69,7 @@ class SettingsFragment : Fragment() {
private lateinit var linLayoutPrimaryColor: LinearLayout
private lateinit var linLayoutAccentColor: LinearLayout
private lateinit var switchBuffet: Switch
private lateinit var txtViewCourse: TextView
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
@ -80,6 +83,8 @@ class SettingsFragment : Fragment() {
linLayoutPrimaryColor = view.findViewById(R.id.linLayout_PrimaryColor)
linLayoutAccentColor = view.findViewById(R.id.linLayout_AccentColor)
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()
@ -128,7 +133,11 @@ class SettingsFragment : Fragment() {
}
linLayoutCourse.setOnClickListener {
selectCourse(context!!)
selectCourse(context!!).show {
onDismiss {
txtViewCourse.text = cCourse.courseName // update txtView after the dialog is dismissed
}
}
}
linLayoutAbout.setOnClickListener {
@ -229,21 +238,21 @@ class SettingsFragment : Fragment() {
}
fun selectCourse(context: Context) {
fun selectCourse(context: Context) : MaterialDialog {
val courseNameList = ArrayList<String>()
coursesList.forEach { (_, courseName) ->
courseNameList.add(courseName)
}
// open a new dialog
MaterialDialog(context)
// return a new course selection dialog
return MaterialDialog(context)
.title(R.string.select_course)
.listItems(items = courseNameList) { _, index, _ ->
val dialog = MaterialDialog(context).cancelable(false)
val loadingDialog = MaterialDialog(context).cancelable(false)
.cancelOnTouchOutside(false)
.customView(R.layout.dialog_loading)
dialog.show()
loadingDialog.show()
GlobalScope.launch(Dispatchers.Default) {
PreferencesController.saveCourse(context, coursesList[index]) // save the course
@ -259,13 +268,11 @@ class SettingsFragment : Fragment() {
CacheController.readTimetable(cCourse.courseName, 1, context)
withContext(Dispatchers.Main) {
dialog.dismiss()
txtView_Course.text = cCourse.courseName // update txtView
loadingDialog.dismiss()
}
}
}
.show()
}
}

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close