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:
		| @ -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 { | ||||
|  | ||||
| @ -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("•") | ||||
|             it.text = HtmlCompat.fromHtml("•", HtmlCompat.FROM_HTML_MODE_LEGACY) | ||||
|             it.textSize = 35f | ||||
|             it.setTextColor(Color.parseColor("#cccccc")) | ||||
|             linLayoutDots.addView(it) | ||||
|  | ||||
| @ -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() | ||||
|     } | ||||
|  | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user