Skip to content

Commit e832daa

Browse files
committed
Share tasks
Signed-off-by: koenidv <[email protected]>
1 parent 00998d7 commit e832daa

File tree

6 files changed

+125
-86
lines changed

6 files changed

+125
-86
lines changed

app/src/main/java/de/koenidv/sph/adapters/TasksAdapter.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.koenidv.sph.adapters
22

33
import android.app.Activity
4+
import android.content.Intent
45
import android.view.LayoutInflater
56
import android.view.View
67
import android.view.ViewGroup
@@ -39,6 +40,7 @@ class TasksAdapter(private val tasks: MutableList<Task>,
3940

4041
val pin = sheet.findViewById<TextView>(R.id.pinTextView)
4142
val unpin = sheet.findViewById<TextView>(R.id.unpinTextView)
43+
val share = sheet.findViewById<TextView>(R.id.shareTextView)
4244

4345
// Only show applicable options
4446
if (task.isPinned) pin?.visibility = View.GONE
@@ -69,6 +71,20 @@ class TasksAdapter(private val tasks: MutableList<Task>,
6971
sheet.dismiss()
7072
}
7173

74+
share?.setOnClickListener {
75+
sheet.dismiss()
76+
// Share task description as plaintext
77+
val text = SphPlanner.applicationContext().getString(R.string.tasks_share_template)
78+
.replace("%course", CoursesDb.getInstance().getFullname(task.id_course))
79+
.replace("%description", task.description)
80+
val sendIntent: Intent = Intent().apply {
81+
action = Intent.ACTION_SEND
82+
putExtra(Intent.EXTRA_TEXT, text)
83+
this.type = "text/plain"
84+
}
85+
activity.startActivity(Intent.createChooser(sendIntent, null))
86+
}
87+
7288
sheet.show()
7389
}
7490

@@ -81,7 +97,7 @@ class TasksAdapter(private val tasks: MutableList<Task>,
8197
}
8298

8399
MaterialDialog(activity, BottomSheet()).show {
84-
datePicker(currentDate = currentCalendar) { dialog, calendar ->
100+
datePicker(currentDate = currentCalendar) { _, calendar ->
85101
val newDate = Date(calendar.timeInMillis)
86102
// Update db and dataset
87103
TasksDb.getInstance().setDueDate(task.taskId, newDate)

app/src/main/java/de/koenidv/sph/parsing/RawParser.kt

Lines changed: 92 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -682,98 +682,106 @@ class RawParser {
682682
*/
683683
fun parseTimetable(rawResponse: String): List<Lesson> {
684684
val returnList = mutableListOf<Lesson>()
685-
// Extract table using jsoup
686-
val doc = Jsoup.parse(rawResponse)
687-
val table = doc.select("div.plan tbody")[0]
688-
// Table is split up into rows of hours (one or multiple)
689-
// There is one row for each hour, even if there aren't any lesson
690-
// However, there isn't a cell if values overlap from the previous hour
691-
// And there also insn't any attribute to let us know which day the lesson is on, if a cell has been skipped
692-
// The rowspan attribute (number of hours) will be the same for all entries within a cell
693-
// Remember the number of rows to skip for each day..
694-
val hoursSkipped = mutableListOf(0, 0, 0, 0, 0)
695-
var rowspanRaw: String
696-
var rowspan: Int
697-
var rowspanInner: Int
698-
var currentHour = 1
699-
var currentDay: Int
700-
var currentDayRaw: Int
701-
var cells: Elements
702-
var lessons: Elements
703-
var gmbId: String
704-
var courseId: String
705-
var teacherId: String
706-
var room: String
707685

708-
// For each hour
709-
for (row in table.select("tr")) {
710-
cells = row.select("td")
711-
// First column is always a description, including time
712-
// todo get lesson times
713-
currentDay = -1
714-
currentDayRaw = 1
715-
// For every day, also skip non-existent columns
716-
while (currentDay <= 4) {
717-
// Skip first column
718-
if (currentDay != -1) {
719-
// Only if this hour was not overridden by last hour
720-
if (hoursSkipped[currentDay] == 0) {
721-
// Remember if this overrides the next hour
722-
rowspanRaw = cells[currentDayRaw].attr("rowspan") ?: "1"
723-
if (rowspanRaw == "") rowspanRaw = "1"
724-
rowspan = rowspanRaw.toInt() - 1
725-
hoursSkipped[currentDay] = rowspan
726-
727-
// Find lessons within this cell
728-
lessons = cells[currentDayRaw].select("div.stunde")
729-
currentDayRaw++
730-
731-
// Add each lesson
732-
for (lesson in lessons) {
733-
rowspanInner = 0
734-
735-
// Extract data
736-
gmbId = lesson.select("b").text().trim()
737-
teacherId = lesson.select("small").text().trim()
738-
room = lesson.toString().substring(
739-
lesson.toString().indexOf("</b>") + 4,
740-
lesson.toString().indexOf("<small")
741-
).replace("<br>", "").trim()
742-
courseId = IdParser().getCourseIdWithGmb(gmbId, teacherId, false)
743-
744-
// Add each lesson to the return list
745-
// Individually, if rowspan is larger than 1
746-
while (rowspanInner <= rowspan) {
747-
// Check for duplicate courses with different rooms
748-
if (returnList.any {
686+
// Return empty list if content is not what we expected
687+
try {
688+
689+
// Extract table using jsoup
690+
val doc = Jsoup.parse(rawResponse)
691+
val table = doc.select("div.plan tbody")[0]
692+
// Table is split up into rows of hours (one or multiple)
693+
// There is one row for each hour, even if there aren't any lesson
694+
// However, there isn't a cell if values overlap from the previous hour
695+
// And there also insn't any attribute to let us know which day the lesson is on, if a cell has been skipped
696+
// The rowspan attribute (number of hours) will be the same for all entries within a cell
697+
// Remember the number of rows to skip for each day..
698+
val hoursSkipped = mutableListOf(0, 0, 0, 0, 0)
699+
var rowspanRaw: String
700+
var rowspan: Int
701+
var rowspanInner: Int
702+
var currentHour = 1
703+
var currentDay: Int
704+
var currentDayRaw: Int
705+
var cells: Elements
706+
var lessons: Elements
707+
var gmbId: String
708+
var courseId: String
709+
var teacherId: String
710+
var room: String
711+
712+
// For each hour
713+
for (row in table.select("tr")) {
714+
cells = row.select("td")
715+
// First column is always a description, including time
716+
// todo get lesson times
717+
currentDay = -1
718+
currentDayRaw = 1
719+
// For every day, also skip non-existent columns
720+
while (currentDay <= 4) {
721+
// Skip first column
722+
if (currentDay != -1) {
723+
// Only if this hour was not overridden by last hour
724+
if (hoursSkipped[currentDay] == 0) {
725+
// Remember if this overrides the next hour
726+
rowspanRaw = cells[currentDayRaw].attr("rowspan") ?: "1"
727+
if (rowspanRaw == "") rowspanRaw = "1"
728+
rowspan = rowspanRaw.toInt() - 1
729+
hoursSkipped[currentDay] = rowspan
730+
731+
// Find lessons within this cell
732+
lessons = cells[currentDayRaw].select("div.stunde")
733+
currentDayRaw++
734+
735+
// Add each lesson
736+
for (lesson in lessons) {
737+
rowspanInner = 0
738+
739+
// Extract data
740+
gmbId = lesson.select("b").text().trim()
741+
teacherId = lesson.select("small").text().trim()
742+
room = lesson.toString().substring(
743+
lesson.toString().indexOf("</b>") + 4,
744+
lesson.toString().indexOf("<small")
745+
).replace("<br>", "").trim()
746+
courseId = IdParser().getCourseIdWithGmb(gmbId, teacherId, false)
747+
748+
// Add each lesson to the return list
749+
// Individually, if rowspan is larger than 1
750+
while (rowspanInner <= rowspan) {
751+
// Check for duplicate courses with different rooms
752+
if (returnList.any {
753+
it.idCourse == courseId
754+
&& it.day == currentDay
755+
&& it.hour == currentHour + rowspanInner
756+
}) {
757+
// Course was already added, but with a different room
758+
// Update the course with this room added
759+
returnList.find {
749760
it.idCourse == courseId
750761
&& it.day == currentDay
751762
&& it.hour == currentHour + rowspanInner
752-
}) {
753-
// Course was already added, but with a different room
754-
// Update the course with this room added
755-
returnList.find {
756-
it.idCourse == courseId
757-
&& it.day == currentDay
758-
&& it.hour == currentHour + rowspanInner
759-
}!!.room += ", $room"
760-
} else {
761-
// Just add the lesson to the list
762-
returnList.add(Lesson(
763-
courseId,
764-
currentDay,
765-
currentHour + rowspanInner,
766-
room
767-
))
763+
}!!.room += ", $room"
764+
} else {
765+
// Just add the lesson to the list
766+
returnList.add(Lesson(
767+
courseId,
768+
currentDay,
769+
currentHour + rowspanInner,
770+
room
771+
))
772+
}
773+
rowspanInner++
768774
}
769-
rowspanInner++
770775
}
771-
}
772-
} else hoursSkipped[currentDay]--
776+
} else hoursSkipped[currentDay]--
777+
}
778+
currentDay++
773779
}
774-
currentDay++
780+
currentHour++
775781
}
776-
currentHour++
782+
} catch (e: java.lang.IndexOutOfBoundsException) {
783+
Log.d(TAG, "Timetable parsing failed!")
784+
Log.d(TAG, e.stackTraceToString())
777785
}
778786

779787
return returnList

app/src/main/java/de/koenidv/sph/ui/OnboardingSupportlistFragment.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ class OnboardingSupportlistFragment : Fragment() {
107107
}
108108
if (!features.contains("Stundenplan")) {
109109
allFeatures = false
110-
usableFeatures = true
111110
featurelistText = featurelistText.replace("%timetable", crossmarkText)
112111
} else {
113112
someFeatures = true

app/src/main/res/layout/sheet_manage_task.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,18 @@
3333
app:drawableStartCompat="@drawable/ic_unpin"
3434
app:drawableTint="?attr/colorOnSurface" />
3535

36+
<TextView
37+
android:id="@+id/shareTextView"
38+
android:layout_width="match_parent"
39+
android:layout_height="wrap_content"
40+
android:background="?attr/selectableItemBackground"
41+
android:drawablePadding="16dp"
42+
android:gravity="center_vertical"
43+
android:padding="16dp"
44+
android:text="@string/attachments_options_share"
45+
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
46+
android:textSize="16sp"
47+
app:drawableStartCompat="@drawable/ic_send"
48+
app:drawableTint="?attr/colorOnSurface" />
49+
3650
</LinearLayout>

app/src/main/res/values-de/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,5 +233,6 @@
233233
<string name="tasks_due_tomorrow">Morgen</string>
234234
<string name="tasks_due_overdue">Überfällig</string>
235235
<string name="tasks_due_setdate">Fälligkeitsdatum hinzufügen</string>
236+
<string name="tasks_share_template">Aufgabe für %course: %description</string>
236237

237238
</resources>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
<item quantity="one">%d more undone task</item>
152152
<item quantity="other">%d more undone tasks</item>
153153
</plurals>
154+
<string name="tasks_share_template">Task for %course: %description</string>
154155

155156
<!-- Attachments -->
156157
<string name="attachments_pins_title">Pinned attachments</string>

0 commit comments

Comments
 (0)