added a dark theme, see #15

* the app now needs sdkversion 23 now an min
This commit is contained in:
2019-06-24 22:41:45 +02:00
parent 01db6bb451
commit a055f59cc8
17 changed files with 271 additions and 163 deletions

View File

@ -61,26 +61,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
// load mensa, timetable and color
load()
// 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.
Aesthetic.config {
colorPrimary(Color.BLACK)
colorPrimaryDark(Color.BLACK)
colorAccent(Color.parseColor("#3F51B5"))
apply()
}
SettingsFragment().selectCourse(this)
} else {
Aesthetic.config {
colorPrimary(cColorPrimary)
colorPrimaryDark(cColorPrimary)
colorAccent(cColorAccent)
apply()
}
}
initAesthetic()
//init home fragment
val fragmentTransaction: FragmentTransaction = supportFragmentManager.beginTransaction()
@ -146,6 +127,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
fragmentTransaction.commit()
drawer_layout.closeDrawer(GravityCompat.START)
return true
}
@ -208,4 +190,28 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
println("startup completed in $startupTime ms")
}
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.
Aesthetic.config {
activityTheme(R.style.AppTheme)
colorPrimary(Color.BLACK)
colorPrimaryDark(Color.BLACK)
colorAccent(Color.parseColor("#3f51b5"))
apply()
}
SettingsFragment().selectCourse(this)
} else {
Aesthetic.config {
// activityTheme(R.style.AppTheme_Light)
colorPrimary(cColorPrimary)
colorPrimaryDark(cColorPrimary)
colorAccent(cColorAccent)
apply()
}
}
}
}

View File

@ -37,6 +37,10 @@ class CacheController(cont: Context) {
private val context = cont
init {
// TODO move cache check here
}
companion object {
var coursesList = ArrayList<Course>()
var timetables = ArrayList<TimetableWeek>()

View File

@ -60,7 +60,7 @@ class HomeFragment : Fragment() {
val view: View = inflater.inflate(R.layout.fragment_home, container, false)
addMensaMenu().get()
addTimeTable()
addTimeTable().get()
// Inflate the layout for this fragment
return view
@ -75,42 +75,48 @@ class HomeFragment : Fragment() {
val cal = Calendar.getInstance()
val mensaCardView = DayCardView(context!!)
uiThread {
if (cal.get(Calendar.HOUR_OF_DAY) < 15) {
dayMeals = mensaMenu.currentWeek.days[NotRetardedCalendar().getDayOfWeekIndex()].meals
mensaCardView.setDayHeading(resources.getString(R.string.today_date, formatter.format(cal.time)))
} else {
dayMeals = mensaMenu.currentWeek.days[NotRetardedCalendar().getTomorrowWeekIndex()].meals
cal.add(Calendar.DATE, 1)
mensaCardView.setDayHeading(resources.getString(R.string.tomorrow_date, formatter.format(cal.time)))
}
if (dayMeals.size >= 2) {
// get the index of the first meal, not a "Schneller Teller"
loop@ for ((i, meal) in dayMeals.withIndex()) {
if (meal.heading.contains("Essen")) {
val meal1Layout = MealLinearLayout(context)
meal1Layout.setMeal(dayMeals[i])
mensaCardView.getLinLayoutDay().addView(meal1Layout)
val meal2Layout = MealLinearLayout(context)
meal2Layout.setMeal(dayMeals[i + 1])
meal2Layout.disableDivider()
mensaCardView.getLinLayoutDay().addView(meal2Layout)
break@loop
}
if (isAdded) {
if (cal.get(Calendar.HOUR_OF_DAY) < 15) {
dayMeals = mensaMenu.currentWeek.days[NotRetardedCalendar().getDayOfWeekIndex()].meals
mensaCardView.setDayHeading(activity!!.resources.getString(R.string.today_date, formatter.format(cal.time)))
} else {
dayMeals = mensaMenu.currentWeek.days[NotRetardedCalendar().getTomorrowWeekIndex()].meals
cal.add(Calendar.DATE, 1)
mensaCardView.setDayHeading(activity!!.resources.getString(R.string.tomorrow_date, formatter.format(cal.time)))
}
} else {
mensaCardView.getLinLayoutDay().addView(getNoCard(resources.getString(R.string.mensa_closed)))
if (dayMeals.size >= 2) {
// get the index of the first meal, not a "Schneller Teller"
loop@ for ((i, meal) in dayMeals.withIndex()) {
if (meal.heading.contains("Essen")) {
val meal1Layout = MealLinearLayout(context)
meal1Layout.setMeal(dayMeals[i])
mensaCardView.getLinLayoutDay().addView(meal1Layout)
val meal2Layout = MealLinearLayout(context)
meal2Layout.setMeal(dayMeals[i + 1])
meal2Layout.disableDivider()
mensaCardView.getLinLayoutDay().addView(meal2Layout)
break@loop
}
}
} else {
mensaCardView.getLinLayoutDay().addView(getNoCard(resources.getString(R.string.mensa_closed)))
}
linLayout_Home.addView(mensaCardView)
}
linLayout_Home.addView(mensaCardView)
}
}
/**
@ -123,29 +129,30 @@ class HomeFragment : Fragment() {
uiThread {
if (timetables.isNotEmpty() && dayIndex < 6) {
if (isAdded) {
if (timetables.isNotEmpty() && dayIndex < 6) {
// first check the current day
dayCardView = addDayTimetable(timetables[0].days[dayIndex])
dayCardView.setDayHeading(resources.getString(R.string.today_date, formatter.format(cal.time)))
// first check the current day
dayCardView = addDayTimetable(timetables[0].days[dayIndex])
dayCardView.setDayHeading(resources.getString(R.string.today_date, formatter.format(cal.time)))
// if there are no lessons try to find the next day with a lesson
if (dayCardView.getLinLayoutDay().childCount <= 1)
dayCardView = findNextDay(0, dayIndex + 1)
// if there are no lessons try to find the next day with a lesson
if (dayCardView.getLinLayoutDay().childCount <= 1)
dayCardView = findNextDay(0, dayIndex + 1)
linLayout_Home.addView(dayCardView)
} else if (dayIndex == 6) {
// if that's the case it's sunday
dayCardView = findNextDay(1, 0)
linLayout_Home.addView(dayCardView)
} else {
MaterialDialog(context!!)
.title(R.string.error)
.message(R.string.timetable_error)
.show()
// TODO log the error and send feedback
linLayout_Home.addView(dayCardView)
} else if (dayIndex == 6) {
// if that's the case it's sunday
dayCardView = findNextDay(1, 0)
linLayout_Home.addView(dayCardView)
} else {
MaterialDialog(context!!)
.title(R.string.error)
.message(R.string.timetable_error)
.show()
// TODO log the error and send feedback
}
}
}
}

View File

@ -50,6 +50,7 @@ import org.mosad.seil0.projectlaogai.controller.CacheController.Companion.course
import org.mosad.seil0.projectlaogai.controller.TCoRAPIController
import org.mosad.seil0.projectlaogai.hsoparser.DataTypes
import java.util.*
import android.util.TypedValue
/**
* The settings controller class
@ -87,6 +88,14 @@ class SettingsFragment : Fragment() {
txtView_Course.text = cCourse.courseName
txtView_AboutDesc.text = resources.getString(R.string.about_version, BuildConfig.VERSION_NAME, getString(R.string.build_time))
switch_buffet.isChecked = cShowBuffet // init switch
val outValue = TypedValue()
activity!!.theme.resolveAttribute(R.attr.themeName, outValue, true)
if (outValue.string == "dark") {
switch_buffet.setTextColor(activity!!.resources.getColor(R.color.textPrimaryDark, activity!!.theme))
} else {
switch_buffet.setTextColor(activity!!.resources.getColor(R.color.textPrimaryLight, activity!!.theme))
}
}
/**
@ -95,6 +104,19 @@ class SettingsFragment : Fragment() {
private fun initActions() {
linLayoutUser.setOnClickListener {
// open a new dialog
// TODO move and save
// val outValue = TypedValue()
// activity!!.theme.resolveAttribute(R.attr.themeName, outValue, true)
// if (outValue.string == "dark") {
// Aesthetic.config {
// activityTheme(R.style.AppTheme_Light)
// }
// } else {
// Aesthetic.config {
// activityTheme(R.style.AppTheme_Dark)
// }
// }
}
linLayoutCourse.setOnClickListener {

View File

@ -22,7 +22,6 @@
package org.mosad.seil0.projectlaogai.fragments
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@ -94,17 +93,15 @@ class TimeTableFragment : Fragment() {
.show()
}
// TODO only works with android m(23) or higher
// hide the btnCardValue if the user is scrolling down
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
scrollViewTimetable.setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
if (scrollY > oldScrollY) {
faBtnAddLesson.hide()
} else {
faBtnAddLesson.show()
}
scrollViewTimetable.setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
if (scrollY > oldScrollY) {
faBtnAddLesson.hide()
} else {
faBtnAddLesson.show()
}
}
}
}