added color saving
** WARNING this contains issues, many issues **
This commit is contained in:
parent
e69354af96
commit
87bf614d28
|
@ -32,12 +32,16 @@ dependencies {
|
|||
implementation 'androidx.appcompat:appcompat:1.0.2'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'com.google.android.material:material:1.0.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
|
||||
implementation 'org.jsoup:jsoup:1.11.3'
|
||||
implementation 'org.jetbrains.anko:anko-commons:0.10.8'
|
||||
implementation 'com.afollestad:aesthetic:1.0.0-beta05'
|
||||
implementation 'com.afollestad.material-dialogs:core:2.0.0-rc3'
|
||||
implementation 'com.afollestad.material-dialogs:color:2.0.0-rc3'
|
||||
implementation 'com.afollestad.material-dialogs:core:2.0.0-rc5'
|
||||
implementation 'com.afollestad.material-dialogs:color:2.0.0-rc5'
|
||||
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.0'
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.0'
|
||||
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test:runner:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
|
||||
|
|
|
@ -35,6 +35,9 @@ import com.afollestad.materialdialogs.MaterialDialog
|
|||
import com.google.android.material.navigation.NavigationView
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import kotlinx.android.synthetic.main.app_bar_main.*
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.jetbrains.anko.doAsync
|
||||
import org.jetbrains.anko.uiThread
|
||||
import org.mosad.seil0.projectlaogai.fragments.*
|
||||
|
@ -48,10 +51,15 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
|||
|
||||
private var weekMenus = ArrayList<Meal>()
|
||||
private var courseTTLinkList = ArrayList<CourseTTLink>()
|
||||
private var timeTableCurrentWeek = arrayOf<Array<Lesson>>()
|
||||
private var timeTableNextWeek = arrayOf<Array<Lesson>>()
|
||||
//private var timeTableCurrentWeek = arrayOf<Array<Lesson>>()
|
||||
//private var timeTableNextWeek = arrayOf<Array<Lesson>>()
|
||||
private lateinit var timeTableCurrentWeek : Array<Array<Lesson>>
|
||||
private lateinit var timeTableNextWeek: Array<Array<Lesson>>
|
||||
|
||||
private lateinit var course: CourseTTLink
|
||||
private var color: Int = Color.BLACK
|
||||
|
||||
private var ls = Lesson("","","", "")
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
Aesthetic.attach(this)
|
||||
|
@ -59,24 +67,26 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
|||
setContentView(R.layout.activity_main)
|
||||
setSupportActionBar(toolbar)
|
||||
|
||||
// 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.YELLOW)
|
||||
colorPrimary(Color.BLACK)
|
||||
apply()
|
||||
}
|
||||
} else {
|
||||
Aesthetic.config {
|
||||
colorPrimary(Color.YELLOW)
|
||||
colorPrimaryDark(Color.YELLOW)
|
||||
colorPrimary(color)
|
||||
colorPrimaryDark(color)
|
||||
apply()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// load mensa and timetable
|
||||
load()
|
||||
|
||||
|
||||
//init home fragment TODO make a abstract fragment class
|
||||
val homeFragment = HomeFragment()
|
||||
|
@ -193,6 +203,17 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
|||
timeTableCurrentWeek = timeTableParser.getTimeTable(course.courseTTLink.replace("http", "https"))
|
||||
}
|
||||
|
||||
/**
|
||||
* save the primary color
|
||||
*/
|
||||
fun saveColorPrimary(color : Int) {
|
||||
val sharedPref = getPreferences(MODE_PRIVATE) ?: return
|
||||
with (sharedPref.edit()) {
|
||||
putInt(getString(R.string.save_key_colorPrimary), color)
|
||||
apply()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* load the mensa menus of the current week
|
||||
*/
|
||||
|
@ -206,11 +227,53 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
|||
sharedPref.getString(getString(R.string.save_key_course), "AI3")!!
|
||||
)
|
||||
|
||||
// load saved color
|
||||
color = sharedPref.getInt(getString(R.string.save_key_colorPrimary), Color.BLACK)
|
||||
|
||||
/**
|
||||
* load mensa, course timetable and courselist from the swfr/hso website
|
||||
* TODO make an API see https://git.mosad.xyz/Seil0/TheCitadelofRicks
|
||||
*/
|
||||
val time = measureTimeMillis {
|
||||
|
||||
runBlocking {
|
||||
/* getting the course list should be faster than the timetable,
|
||||
* we need have time until the user opens the dialog
|
||||
*/
|
||||
val jobTTLinkList = GlobalScope.launch {
|
||||
courseTTLinkList = timeTableParser.getCourseTTLinks()
|
||||
}
|
||||
|
||||
val jobTTNextWeek = GlobalScope.launch {
|
||||
timeTableNextWeek = timeTableParser.getTimeTable(course.courseTTLink.replace("week=0","week=1"))
|
||||
println("next: " + timeTableNextWeek.size)
|
||||
println(timeTableNextWeek)
|
||||
println(ls.lessonSubject)
|
||||
timeTableParser.printTimeTableWeek(timeTableNextWeek) // Wieso sind die daten hier noch im array
|
||||
}
|
||||
|
||||
val jobTTCurrentWeek = GlobalScope.launch {
|
||||
timeTableCurrentWeek = timeTableParser.getTimeTable(course.courseTTLink)
|
||||
}
|
||||
|
||||
val jobMenus = GlobalScope.launch {
|
||||
weekMenus = mensaParser.getMensaMenu()
|
||||
}
|
||||
|
||||
|
||||
|
||||
jobTTLinkList.join() // wait until child coroutine completes
|
||||
jobTTNextWeek.join()
|
||||
jobTTCurrentWeek.join()
|
||||
jobMenus.join()
|
||||
|
||||
println("next end:" + timeTableNextWeek.size)
|
||||
println(timeTableNextWeek)
|
||||
timeTableParser.printTimeTableWeek(timeTableNextWeek) // und hier nicht mehr
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
/* getting the course list should be faster than the timetable,
|
||||
* we need have time until the user opens the dialog
|
||||
*/
|
||||
|
@ -218,9 +281,14 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
|||
courseTTLinkList = timeTableParser.getCourseTTLinks()
|
||||
}
|
||||
|
||||
doAsync {
|
||||
val t0 = doAsync {
|
||||
try {
|
||||
timeTableNextWeek = timeTableParser.getTimeTable(course.courseTTLink.replace("week=0","week=1"))
|
||||
ls = timeTableNextWeek[0][0]
|
||||
println("next: " + timeTableNextWeek.size)
|
||||
println(timeTableNextWeek)
|
||||
println(ls.lessonSubject)
|
||||
timeTableParser.printTimeTableWeek(timeTableNextWeek)
|
||||
} catch (e: Exception) {
|
||||
e.stackTrace
|
||||
}
|
||||
|
@ -233,6 +301,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
|||
val t2 = doAsync {
|
||||
try {
|
||||
timeTableCurrentWeek = timeTableParser.getTimeTable(course.courseTTLink)
|
||||
println("current: " + timeTableCurrentWeek.size)
|
||||
timeTableParser.printTimeTableWeek(timeTableCurrentWeek)
|
||||
} catch (e: Exception) {
|
||||
|
||||
uiThread {
|
||||
|
@ -246,11 +316,17 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
|||
}
|
||||
}
|
||||
|
||||
t0.get()
|
||||
t1.get()
|
||||
t2.get()
|
||||
|
||||
println("next end:" + timeTableNextWeek.size)
|
||||
println(timeTableNextWeek)
|
||||
timeTableParser.printTimeTableWeek(timeTableNextWeek)
|
||||
println(ls.lessonSubject)
|
||||
}
|
||||
println("Completed in $time ms")
|
||||
|
||||
println(ls.lessonSubject)
|
||||
}
|
||||
|
||||
fun getCourseTTLinkList(): ArrayList<CourseTTLink>{
|
||||
|
@ -273,4 +349,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
|||
return course
|
||||
}
|
||||
|
||||
fun getColorPrimary(): Int {
|
||||
return color
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -130,13 +130,15 @@ class SettingsFragment : Fragment() {
|
|||
|
||||
MaterialDialog(context!!)
|
||||
.title(R.string.primary_color)
|
||||
.colorChooser(colors, initialSelection = Color.BLACK) { _, color ->
|
||||
.colorChooser(colors, initialSelection = mainActivity.getColorPrimary()) { _, color ->
|
||||
viewPrimaryColor.setBackgroundColor(color)
|
||||
Aesthetic.config {
|
||||
colorPrimary(color)
|
||||
colorPrimaryDark(color)
|
||||
apply()
|
||||
}
|
||||
|
||||
mainActivity.saveColorPrimary(color)
|
||||
}
|
||||
.positiveButton(R.string.select)
|
||||
.show()
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.mosad.seil0.projectlaogai.MainActivity
|
|||
import org.mosad.seil0.projectlaogai.R
|
||||
import org.mosad.seil0.projectlaogai.hsoparser.DataTypes
|
||||
import org.mosad.seil0.projectlaogai.hsoparser.NotRetardedCalendar
|
||||
import org.mosad.seil0.projectlaogai.hsoparser.TimeTableParser
|
||||
import org.mosad.seil0.projectlaogai.uicomponents.LessonCardView
|
||||
import org.mosad.seil0.projectlaogai.uicomponents.MensaDayCardView
|
||||
import java.text.SimpleDateFormat
|
||||
|
@ -72,6 +73,9 @@ class TimeTableFragment : Fragment() {
|
|||
val formatter = SimpleDateFormat("E dd.MM", Locale.GERMANY) // TODO change to android call when min api is 24
|
||||
val calendar = Calendar.getInstance()
|
||||
|
||||
println(mainActivity.getTimeTableCurrentWeek().size)
|
||||
println(mainActivity.getTimeTableNextWeek().size)
|
||||
|
||||
doAsync {
|
||||
|
||||
uiThread {
|
||||
|
@ -91,11 +95,21 @@ class TimeTableFragment : Fragment() {
|
|||
lessonCardView.getTxtViewLesson().append(lesson.lessonRoom)
|
||||
lessonCardView.getTxtViewTime().text = DataTypes().getTime()[i]
|
||||
|
||||
// only add the lesson if it contains data
|
||||
if(lessonCardView.getTxtViewLesson().text.length > 2)
|
||||
cardViewTimeTableDay.getLinLayoutMensaDay().addView(lessonCardView)
|
||||
}
|
||||
|
||||
calendar.add(Calendar.DATE,1)
|
||||
|
||||
// if the day contains no lessons add a text "No lesson today"
|
||||
if (cardViewTimeTableDay.getLinLayoutMensaDay().childCount <= 1) {
|
||||
val lessonCardView = LessonCardView(context!!, null)
|
||||
lessonCardView.setBackgroundColor(Color.TRANSPARENT)
|
||||
lessonCardView.getTxtViewLesson().text = resources.getString(R.string.no_lesson_today)
|
||||
cardViewTimeTableDay.getLinLayoutMensaDay().addView(lessonCardView)
|
||||
}
|
||||
|
||||
linLayoutTTFragment.addView(cardViewTimeTableDay)
|
||||
}
|
||||
|
||||
|
@ -108,6 +122,9 @@ class TimeTableFragment : Fragment() {
|
|||
val cardViewTimeTableDay = MensaDayCardView(context!!, null)
|
||||
cardViewTimeTableDay.setDayHeading(formatter.format(calendar.time))
|
||||
|
||||
//val ttp = TimeTableParser()
|
||||
//ttp.printTimeTableWeek(mainActivity.getTimeTableNextWeek())
|
||||
|
||||
// for each lessen of the day
|
||||
for((i, lesson) in mainActivity.getTimeTableNextWeek()[day].withIndex()) {
|
||||
val lessonCardView = LessonCardView(context!!, null)
|
||||
|
|
|
@ -137,7 +137,7 @@
|
|||
<View
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp" android:id="@+id/view_PrimaryColor"
|
||||
android:background="@color/colorPrimary"/>
|
||||
android:background="?colorPrimary"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -4,14 +4,15 @@
|
|||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/nav_header_height"
|
||||
android:background="?colorPrimary"
|
||||
android:background="@color/colorPrimary"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark"
|
||||
android:orientation="vertical"
|
||||
android:gravity="bottom">
|
||||
android:gravity="bottom"
|
||||
android:id="@+id/nav_header_main">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<string name="no_meal_today">heute keine Essensausgabe</string>
|
||||
<string name="no_meal_tomorrow">morgen keine Essensausgabe</string>
|
||||
<string name="no_more_food">Diese Woche keine weitere Essensausgabe</string>
|
||||
<string name="no_lesson_today">heute keine Vorlesung</string>
|
||||
<string name="no_lesson_today">heute keine Vorlesung!</string>
|
||||
<string name="error">Fehler</string>
|
||||
<string name="no_tt_error">Stundenplan konnte nicht geladen werden!</string>
|
||||
<string name="gen_tt_error">Allgemeiner Stundenplan Fehler!"</string>
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<string name="no_meal_tomorrow">Mensa closed tomorrow</string>
|
||||
<string name="no_more_food">No more Food this week</string>
|
||||
|
||||
<string name="no_lesson_today">"no lecture today "</string>
|
||||
<string name="no_lesson_today">"No lecture today!"</string>
|
||||
<string name="error">Error</string>
|
||||
<string name="no_tt_error">Could not load timetable!"</string>
|
||||
<string name="gen_tt_error">There was an error with the timetable!"</string>
|
||||
|
@ -51,4 +51,5 @@
|
|||
|
||||
<string name="save_key_course" translatable="false">org.mosad.seil0.projectlaogai.course</string>
|
||||
<string name="save_key_courseTTLink" translatable="false">org.mosad.seil0.projectlaogai.courseTTLink</string>
|
||||
<string name="save_key_colorPrimary" translatable="false">org.mosad.seil0.projectlaogai.colorPrimary</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue