Browse Source

some clean up

* removed unnecessary MainActivity dependencies
pull/20/head
Jannik 3 years ago
parent
commit
e9bdcee443
  1. 41
      app/src/main/java/org/mosad/seil0/projectlaogai/MainActivity.kt
  2. 13
      app/src/main/java/org/mosad/seil0/projectlaogai/fragments/HomeFragment.kt
  3. 7
      app/src/main/java/org/mosad/seil0/projectlaogai/fragments/MensaFragment.kt
  4. 13
      app/src/main/java/org/mosad/seil0/projectlaogai/fragments/TimeTableFragment.kt

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

@ -46,14 +46,17 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
private val mensaParser = MensaParser()
private val timeTableParser = TimeTableParser()
private var weekMenus = ArrayList<Meal>()
private var courseTTLinkList = ArrayList<CourseTTLink>()
private var timeTableCurrentWeek = arrayOf<Array<Lesson>>()
private var timeTableNextWeek = arrayOf<Array<Lesson>>()
private lateinit var course: CourseTTLink
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?) {
Aesthetic.attach(this)
super.onCreate(savedInstanceState)
@ -81,7 +84,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
//init home fragment TODO make a abstract fragment class
val homeFragment = HomeFragment()
homeFragment.setMainActivity(this)
val fragmentTransaction: FragmentTransaction = supportFragmentManager.beginTransaction()
fragmentTransaction.replace(R.id.fragment_container, homeFragment)
fragmentTransaction.commit()
@ -134,21 +136,18 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
when (item.itemId) {
R.id.nav_home -> {
val homeFragment = HomeFragment()
homeFragment.setMainActivity(this)
val fragmentTransaction: FragmentTransaction = supportFragmentManager.beginTransaction()
fragmentTransaction.replace(R.id.fragment_container, homeFragment)
fragmentTransaction.commit()
}
R.id.nav_mensa -> {
val mensaFragment = MensaFragment()
mensaFragment.setMainActivity(this)
val fragmentTransaction: FragmentTransaction = supportFragmentManager.beginTransaction()
fragmentTransaction.replace(R.id.fragment_container, mensaFragment)
fragmentTransaction.commit()
}
R.id.nav_timetable -> {
val timeTableFragment = TimeTableFragment()
timeTableFragment.setMainActivity(this)
val fragmentTransaction: FragmentTransaction = supportFragmentManager.beginTransaction()
fragmentTransaction.replace(R.id.fragment_container, timeTableFragment)
fragmentTransaction.commit()
@ -191,14 +190,14 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
apply()
}
timeTableCurrentWeek = timeTableParser.getTimeTable(course.courseTTLink.replace("http", "https"))
cTimeTableCurrentWeek = timeTableParser.getTimeTable(course.courseTTLink.replace("http", "https"))
}
/**
* save the primary color
*/
fun saveColorPrimary(color : Int) {
val sharedPref = getPreferences(MODE_PRIVATE) ?: return
val sharedPref = getPreferences(MODE_PRIVATE)
with (sharedPref.edit()) {
putInt(getString(R.string.save_key_colorPrimary), color)
apply()
@ -209,12 +208,10 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
* load the mensa menus of the current week
*/
private fun load() {
// load saved course
val sharedPref = getPreferences(MODE_PRIVATE) ?: return
val sharedPref = getPreferences(MODE_PRIVATE)
course = 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")!!,
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")!!,
sharedPref.getString(getString(R.string.save_key_course), "AI3")!!
)
@ -235,12 +232,12 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
val jobMenus = doAsync {
weekMenus = mensaParser.getMensaMenu()
cWeekMenus = mensaParser.getMensaMenu()
}
val jobTTCurrentWeek = doAsync {
try {
timeTableCurrentWeek = timeTableParser.getTimeTable(course.courseTTLink)
cTimeTableCurrentWeek = timeTableParser.getTimeTable(course.courseTTLink)
} catch (e: Exception) {
uiThread {
@ -256,7 +253,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
val jobTTNextWeek = doAsync {
try {
timeTableNextWeek = timeTableParser.getTimeTable(course.courseTTLink.replace("week=0","week=1"))
cTimeTableNextWeek = timeTableParser.getTimeTable(course.courseTTLink.replace("week=0","week=1"))
} catch (e: Exception) {
e.stackTrace
}
@ -273,18 +270,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
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 {
return course
}

13
app/src/main/java/org/mosad/seil0/projectlaogai/fragments/HomeFragment.kt

@ -45,7 +45,6 @@ import java.util.*
class HomeFragment : Fragment() {
private lateinit var linLayoutTimeTable: LinearLayout
private var mainActivity = MainActivity()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
@ -71,9 +70,9 @@ class HomeFragment : Fragment() {
val cal = Calendar.getInstance()
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 {
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 {
txtView_Menu1Heading.text = resources.getString(R.string.meal_1_tomorrow)
txtView_Menu2Heading.text = resources.getString(R.string.meal_2_tomorrow)
@ -122,9 +121,9 @@ class HomeFragment : Fragment() {
private fun addCurrentTimeTable() {
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) {
val lessonCardView = LessonCardView(context!!, null)
@ -162,8 +161,4 @@ class HomeFragment : Fragment() {
}
}
fun setMainActivity(mainActivity: MainActivity) {
this.mainActivity = mainActivity
}
}

7
app/src/main/java/org/mosad/seil0/projectlaogai/fragments/MensaFragment.kt

@ -43,7 +43,6 @@ import java.util.*
class MensaFragment : Fragment() {
private lateinit var linLayoutMensaFragment: LinearLayout
private var mainActivity = MainActivity()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
@ -77,7 +76,7 @@ class MensaFragment : Fragment() {
val cardViewMensaDay = MensaDayCardView(context!!, null)
var add = false
for (meal in mainActivity.getWeekMenu()) {
for (meal in MainActivity.cWeekMenus) {
//println("Day: " + meal.day)
if (meal.day.contains(strDay)) {
@ -112,8 +111,4 @@ class MensaFragment : Fragment() {
}
}
fun setMainActivity(mainActivity: MainActivity) {
this.mainActivity = mainActivity
}
}

13
app/src/main/java/org/mosad/seil0/projectlaogai/fragments/TimeTableFragment.kt

@ -47,7 +47,6 @@ import java.util.*
class TimeTableFragment : Fragment() {
private lateinit var linLayoutTTFragment: LinearLayout
private var mainActivity = MainActivity()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
@ -55,7 +54,7 @@ class TimeTableFragment : Fragment() {
linLayoutTTFragment = view.findViewById(R.id.linLayout_TTFragment)
if (mainActivity.getTimeTableCurrentWeek().isNotEmpty()) {
if (MainActivity.cTimeTableCurrentWeek.isNotEmpty()) {
addCurrentWeek()
} else {
// TODO show card with error msg
@ -82,7 +81,7 @@ class TimeTableFragment : Fragment() {
cardViewTimeTableDay.setDayHeading(formatter.format(calendar.time))
// 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)
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
// 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!)
for(day in 0..(dayIndex - 1)) {
@ -120,7 +119,7 @@ class TimeTableFragment : Fragment() {
cardViewTimeTableDay.setDayHeading(formatter.format(calendar.time))
// 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)
lessonCardView.setBackgroundColor(Color.TRANSPARENT)
@ -143,8 +142,4 @@ class TimeTableFragment : Fragment() {
}
}
fun setMainActivity(mainActivity: MainActivity) {
this.mainActivity = mainActivity
}
}

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