some clean up
* removed unnecessary MainActivity dependencies
This commit is contained in:
parent
b214cfccb2
commit
e9bdcee443
|
@ -46,14 +46,17 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
private val mensaParser = MensaParser()
|
private val mensaParser = MensaParser()
|
||||||
private val timeTableParser = TimeTableParser()
|
private val timeTableParser = TimeTableParser()
|
||||||
|
|
||||||
private var weekMenus = ArrayList<Meal>()
|
|
||||||
private var courseTTLinkList = ArrayList<CourseTTLink>()
|
private var courseTTLinkList = ArrayList<CourseTTLink>()
|
||||||
private var timeTableCurrentWeek = arrayOf<Array<Lesson>>()
|
|
||||||
private var timeTableNextWeek = arrayOf<Array<Lesson>>()
|
|
||||||
|
|
||||||
private lateinit var course: CourseTTLink
|
private lateinit var course: CourseTTLink
|
||||||
private var color: Int = Color.BLACK
|
private var color: Int = Color.BLACK
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
var cWeekMenus = ArrayList<Meal>()
|
||||||
|
var cTimeTableCurrentWeek = arrayOf<Array<Lesson>>()
|
||||||
|
var cTimeTableNextWeek = arrayOf<Array<Lesson>>()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
Aesthetic.attach(this)
|
Aesthetic.attach(this)
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
@ -81,7 +84,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
|
|
||||||
//init home fragment TODO make a abstract fragment class
|
//init home fragment TODO make a abstract fragment class
|
||||||
val homeFragment = HomeFragment()
|
val homeFragment = HomeFragment()
|
||||||
homeFragment.setMainActivity(this)
|
|
||||||
val fragmentTransaction: FragmentTransaction = supportFragmentManager.beginTransaction()
|
val fragmentTransaction: FragmentTransaction = supportFragmentManager.beginTransaction()
|
||||||
fragmentTransaction.replace(R.id.fragment_container, homeFragment)
|
fragmentTransaction.replace(R.id.fragment_container, homeFragment)
|
||||||
fragmentTransaction.commit()
|
fragmentTransaction.commit()
|
||||||
|
@ -134,21 +136,18 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.nav_home -> {
|
R.id.nav_home -> {
|
||||||
val homeFragment = HomeFragment()
|
val homeFragment = HomeFragment()
|
||||||
homeFragment.setMainActivity(this)
|
|
||||||
val fragmentTransaction: FragmentTransaction = supportFragmentManager.beginTransaction()
|
val fragmentTransaction: FragmentTransaction = supportFragmentManager.beginTransaction()
|
||||||
fragmentTransaction.replace(R.id.fragment_container, homeFragment)
|
fragmentTransaction.replace(R.id.fragment_container, homeFragment)
|
||||||
fragmentTransaction.commit()
|
fragmentTransaction.commit()
|
||||||
}
|
}
|
||||||
R.id.nav_mensa -> {
|
R.id.nav_mensa -> {
|
||||||
val mensaFragment = MensaFragment()
|
val mensaFragment = MensaFragment()
|
||||||
mensaFragment.setMainActivity(this)
|
|
||||||
val fragmentTransaction: FragmentTransaction = supportFragmentManager.beginTransaction()
|
val fragmentTransaction: FragmentTransaction = supportFragmentManager.beginTransaction()
|
||||||
fragmentTransaction.replace(R.id.fragment_container, mensaFragment)
|
fragmentTransaction.replace(R.id.fragment_container, mensaFragment)
|
||||||
fragmentTransaction.commit()
|
fragmentTransaction.commit()
|
||||||
}
|
}
|
||||||
R.id.nav_timetable -> {
|
R.id.nav_timetable -> {
|
||||||
val timeTableFragment = TimeTableFragment()
|
val timeTableFragment = TimeTableFragment()
|
||||||
timeTableFragment.setMainActivity(this)
|
|
||||||
val fragmentTransaction: FragmentTransaction = supportFragmentManager.beginTransaction()
|
val fragmentTransaction: FragmentTransaction = supportFragmentManager.beginTransaction()
|
||||||
fragmentTransaction.replace(R.id.fragment_container, timeTableFragment)
|
fragmentTransaction.replace(R.id.fragment_container, timeTableFragment)
|
||||||
fragmentTransaction.commit()
|
fragmentTransaction.commit()
|
||||||
|
@ -191,14 +190,14 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
apply()
|
apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
timeTableCurrentWeek = timeTableParser.getTimeTable(course.courseTTLink.replace("http", "https"))
|
cTimeTableCurrentWeek = timeTableParser.getTimeTable(course.courseTTLink.replace("http", "https"))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* save the primary color
|
* save the primary color
|
||||||
*/
|
*/
|
||||||
fun saveColorPrimary(color : Int) {
|
fun saveColorPrimary(color : Int) {
|
||||||
val sharedPref = getPreferences(MODE_PRIVATE) ?: return
|
val sharedPref = getPreferences(MODE_PRIVATE)
|
||||||
with (sharedPref.edit()) {
|
with (sharedPref.edit()) {
|
||||||
putInt(getString(R.string.save_key_colorPrimary), color)
|
putInt(getString(R.string.save_key_colorPrimary), color)
|
||||||
apply()
|
apply()
|
||||||
|
@ -209,12 +208,10 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
* load the mensa menus of the current week
|
* load the mensa menus of the current week
|
||||||
*/
|
*/
|
||||||
private fun load() {
|
private fun load() {
|
||||||
|
|
||||||
// load saved course
|
// load saved course
|
||||||
val sharedPref = getPreferences(MODE_PRIVATE) ?: return
|
val sharedPref = getPreferences(MODE_PRIVATE)
|
||||||
course = CourseTTLink(
|
course = CourseTTLink(
|
||||||
sharedPref.getString(getString(R.string.save_key_courseTTLink),
|
sharedPref.getString(getString(R.string.save_key_courseTTLink), "https://www.hs-offenburg.de/index.php?id=6627&class=class&iddV=DA64F6FE-9DDB-429E-A677-05D0D40CB636&week=0")!!,
|
||||||
"https://www.hs-offenburg.de/index.php?id=6627&class=class&iddV=DA64F6FE-9DDB-429E-A677-05D0D40CB636&week=0")!!,
|
|
||||||
sharedPref.getString(getString(R.string.save_key_course), "AI3")!!
|
sharedPref.getString(getString(R.string.save_key_course), "AI3")!!
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -235,12 +232,12 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
}
|
}
|
||||||
|
|
||||||
val jobMenus = doAsync {
|
val jobMenus = doAsync {
|
||||||
weekMenus = mensaParser.getMensaMenu()
|
cWeekMenus = mensaParser.getMensaMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
val jobTTCurrentWeek = doAsync {
|
val jobTTCurrentWeek = doAsync {
|
||||||
try {
|
try {
|
||||||
timeTableCurrentWeek = timeTableParser.getTimeTable(course.courseTTLink)
|
cTimeTableCurrentWeek = timeTableParser.getTimeTable(course.courseTTLink)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|
||||||
uiThread {
|
uiThread {
|
||||||
|
@ -256,7 +253,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
|
|
||||||
val jobTTNextWeek = doAsync {
|
val jobTTNextWeek = doAsync {
|
||||||
try {
|
try {
|
||||||
timeTableNextWeek = timeTableParser.getTimeTable(course.courseTTLink.replace("week=0","week=1"))
|
cTimeTableNextWeek = timeTableParser.getTimeTable(course.courseTTLink.replace("week=0","week=1"))
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.stackTrace
|
e.stackTrace
|
||||||
}
|
}
|
||||||
|
@ -273,18 +270,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
||||||
return courseTTLinkList
|
return courseTTLinkList
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTimeTableCurrentWeek(): Array<Array<Lesson>> {
|
|
||||||
return timeTableCurrentWeek
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getTimeTableNextWeek(): Array<Array<Lesson>> {
|
|
||||||
return timeTableNextWeek
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getWeekMenu(): ArrayList<Meal>{
|
|
||||||
return weekMenus
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getCourse(): CourseTTLink {
|
fun getCourse(): CourseTTLink {
|
||||||
return course
|
return course
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,6 @@ import java.util.*
|
||||||
class HomeFragment : Fragment() {
|
class HomeFragment : Fragment() {
|
||||||
|
|
||||||
private lateinit var linLayoutTimeTable: LinearLayout
|
private lateinit var linLayoutTimeTable: LinearLayout
|
||||||
private var mainActivity = MainActivity()
|
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
|
|
||||||
|
@ -71,9 +70,9 @@ class HomeFragment : Fragment() {
|
||||||
val cal = Calendar.getInstance()
|
val cal = Calendar.getInstance()
|
||||||
|
|
||||||
if (cal.get(Calendar.HOUR_OF_DAY) < 15) {
|
if (cal.get(Calendar.HOUR_OF_DAY) < 15) {
|
||||||
dayMenus = MensaParser().getMensaMenuDay(mainActivity.getWeekMenu(), cal.get(Calendar.DAY_OF_WEEK))
|
dayMenus = MensaParser().getMensaMenuDay(MainActivity.cWeekMenus, cal.get(Calendar.DAY_OF_WEEK))
|
||||||
} else {
|
} else {
|
||||||
dayMenus = MensaParser().getMensaMenuDay(mainActivity.getWeekMenu(), cal.get(Calendar.DAY_OF_WEEK) + 1)
|
dayMenus = MensaParser().getMensaMenuDay(MainActivity.cWeekMenus, cal.get(Calendar.DAY_OF_WEEK) + 1)
|
||||||
uiThread {
|
uiThread {
|
||||||
txtView_Menu1Heading.text = resources.getString(R.string.meal_1_tomorrow)
|
txtView_Menu1Heading.text = resources.getString(R.string.meal_1_tomorrow)
|
||||||
txtView_Menu2Heading.text = resources.getString(R.string.meal_2_tomorrow)
|
txtView_Menu2Heading.text = resources.getString(R.string.meal_2_tomorrow)
|
||||||
|
@ -122,9 +121,9 @@ class HomeFragment : Fragment() {
|
||||||
private fun addCurrentTimeTable() {
|
private fun addCurrentTimeTable() {
|
||||||
val dayIndex = NotRetardedCalendar().getDayOfWeekIndex()
|
val dayIndex = NotRetardedCalendar().getDayOfWeekIndex()
|
||||||
|
|
||||||
if (mainActivity.getTimeTableCurrentWeek().isNotEmpty() && dayIndex < 6) {
|
if (MainActivity.cTimeTableCurrentWeek.isNotEmpty() && dayIndex < 6) {
|
||||||
|
|
||||||
val timeTableDay = mainActivity.getTimeTableCurrentWeek()[dayIndex]
|
val timeTableDay = MainActivity.cTimeTableCurrentWeek[dayIndex]
|
||||||
|
|
||||||
for (i in 0..5) {
|
for (i in 0..5) {
|
||||||
val lessonCardView = LessonCardView(context!!, null)
|
val lessonCardView = LessonCardView(context!!, null)
|
||||||
|
@ -162,8 +161,4 @@ class HomeFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setMainActivity(mainActivity: MainActivity) {
|
|
||||||
this.mainActivity = mainActivity
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,6 @@ import java.util.*
|
||||||
class MensaFragment : Fragment() {
|
class MensaFragment : Fragment() {
|
||||||
|
|
||||||
private lateinit var linLayoutMensaFragment: LinearLayout
|
private lateinit var linLayoutMensaFragment: LinearLayout
|
||||||
private var mainActivity = MainActivity()
|
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
|
|
||||||
|
@ -77,7 +76,7 @@ class MensaFragment : Fragment() {
|
||||||
val cardViewMensaDay = MensaDayCardView(context!!, null)
|
val cardViewMensaDay = MensaDayCardView(context!!, null)
|
||||||
var add = false
|
var add = false
|
||||||
|
|
||||||
for (meal in mainActivity.getWeekMenu()) {
|
for (meal in MainActivity.cWeekMenus) {
|
||||||
//println("Day: " + meal.day)
|
//println("Day: " + meal.day)
|
||||||
if (meal.day.contains(strDay)) {
|
if (meal.day.contains(strDay)) {
|
||||||
|
|
||||||
|
@ -112,8 +111,4 @@ class MensaFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setMainActivity(mainActivity: MainActivity) {
|
|
||||||
this.mainActivity = mainActivity
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,6 @@ import java.util.*
|
||||||
class TimeTableFragment : Fragment() {
|
class TimeTableFragment : Fragment() {
|
||||||
|
|
||||||
private lateinit var linLayoutTTFragment: LinearLayout
|
private lateinit var linLayoutTTFragment: LinearLayout
|
||||||
private var mainActivity = MainActivity()
|
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
|
|
||||||
|
@ -55,7 +54,7 @@ class TimeTableFragment : Fragment() {
|
||||||
|
|
||||||
linLayoutTTFragment = view.findViewById(R.id.linLayout_TTFragment)
|
linLayoutTTFragment = view.findViewById(R.id.linLayout_TTFragment)
|
||||||
|
|
||||||
if (mainActivity.getTimeTableCurrentWeek().isNotEmpty()) {
|
if (MainActivity.cTimeTableCurrentWeek.isNotEmpty()) {
|
||||||
addCurrentWeek()
|
addCurrentWeek()
|
||||||
} else {
|
} else {
|
||||||
// TODO show card with error msg
|
// TODO show card with error msg
|
||||||
|
@ -82,7 +81,7 @@ class TimeTableFragment : Fragment() {
|
||||||
cardViewTimeTableDay.setDayHeading(formatter.format(calendar.time))
|
cardViewTimeTableDay.setDayHeading(formatter.format(calendar.time))
|
||||||
|
|
||||||
// for each lessen of the day
|
// for each lessen of the day
|
||||||
for((i, lesson) in mainActivity.getTimeTableCurrentWeek()[day].withIndex()) {
|
for((i, lesson) in MainActivity.cTimeTableCurrentWeek[day].withIndex()) {
|
||||||
val lessonCardView = LessonCardView(context!!, null)
|
val lessonCardView = LessonCardView(context!!, null)
|
||||||
lessonCardView.setBackgroundColor(Color.TRANSPARENT)
|
lessonCardView.setBackgroundColor(Color.TRANSPARENT)
|
||||||
|
|
||||||
|
@ -111,7 +110,7 @@ class TimeTableFragment : Fragment() {
|
||||||
|
|
||||||
// TODO if there is no lesson at one day , show a no lesson card
|
// TODO if there is no lesson at one day , show a no lesson card
|
||||||
// add next weeks days, max number = dayIndex, if timetable was loaded
|
// add next weeks days, max number = dayIndex, if timetable was loaded
|
||||||
if (mainActivity.getTimeTableNextWeek().isNotEmpty()) {
|
if (MainActivity.cTimeTableNextWeek.isNotEmpty()) {
|
||||||
calendar.add(Calendar.DATE,1) // before this we are at a sunday (no lecture on sundays!)
|
calendar.add(Calendar.DATE,1) // before this we are at a sunday (no lecture on sundays!)
|
||||||
|
|
||||||
for(day in 0..(dayIndex - 1)) {
|
for(day in 0..(dayIndex - 1)) {
|
||||||
|
@ -120,7 +119,7 @@ class TimeTableFragment : Fragment() {
|
||||||
cardViewTimeTableDay.setDayHeading(formatter.format(calendar.time))
|
cardViewTimeTableDay.setDayHeading(formatter.format(calendar.time))
|
||||||
|
|
||||||
// for each lessen of the day
|
// for each lessen of the day
|
||||||
for((i, lesson) in mainActivity.getTimeTableNextWeek()[day].withIndex()) {
|
for((i, lesson) in MainActivity.cTimeTableNextWeek[day].withIndex()) {
|
||||||
val lessonCardView = LessonCardView(context!!, null)
|
val lessonCardView = LessonCardView(context!!, null)
|
||||||
lessonCardView.setBackgroundColor(Color.TRANSPARENT)
|
lessonCardView.setBackgroundColor(Color.TRANSPARENT)
|
||||||
|
|
||||||
|
@ -143,8 +142,4 @@ class TimeTableFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setMainActivity(mainActivity: MainActivity) {
|
|
||||||
this.mainActivity = mainActivity
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue