forked from github/szkolny
[Dialog/EventDetails] Add feature for saving events in calendar app.
This commit is contained in:
parent
4ba7997bc1
commit
53675122c6
@ -105,6 +105,10 @@ fun CharSequence?.isNotNullNorEmpty(): Boolean {
|
|||||||
return this != null && this.isNotEmpty()
|
return this != null && this.isNotEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun CharSequence?.isNotNullNorBlank(): Boolean {
|
||||||
|
return this != null && this.isNotBlank()
|
||||||
|
}
|
||||||
|
|
||||||
fun currentTimeUnix() = System.currentTimeMillis() / 1000
|
fun currentTimeUnix() = System.currentTimeMillis() / 1000
|
||||||
|
|
||||||
fun Bundle?.getInt(key: String, defaultValue: Int): Int {
|
fun Bundle?.getInt(key: String, defaultValue: Int): Int {
|
||||||
|
@ -4,6 +4,10 @@
|
|||||||
|
|
||||||
package pl.szczodrzynski.edziennik.ui.dialogs.event
|
package pl.szczodrzynski.edziennik.ui.dialogs.event
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.provider.CalendarContract
|
||||||
|
import android.provider.CalendarContract.Events
|
||||||
|
import android.view.View
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
@ -101,6 +105,21 @@ class EventDetailsDialog(
|
|||||||
Date.fromMillis(event.addedDate).formattedString,
|
Date.fromMillis(event.addedDate).formattedString,
|
||||||
event.sharedByName ?: event.teacherFullName ?: ""
|
event.sharedByName ?: event.teacherFullName ?: ""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
b.editButton.visibility = if (event.addedManually) View.VISIBLE else View.GONE
|
||||||
|
b.editButton.setOnClickListener {
|
||||||
|
EventManualDialog(
|
||||||
|
activity,
|
||||||
|
event.profileId,
|
||||||
|
editingEvent = event,
|
||||||
|
onShowListener = onShowListener,
|
||||||
|
onDismissListener = onDismissListener
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
b.saveInCalendarButton.setOnClickListener {
|
||||||
|
openInCalendar()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showRemoveEventDialog() {
|
private fun showRemoveEventDialog() {
|
||||||
@ -133,7 +152,7 @@ class EventDetailsDialog(
|
|||||||
Toast.makeText(activity, "Unshare + remove own event", Toast.LENGTH_SHORT).show()
|
Toast.makeText(activity, "Unshare + remove own event", Toast.LENGTH_SHORT).show()
|
||||||
|
|
||||||
val response = withContext(Dispatchers.Default) {
|
val response = withContext(Dispatchers.Default) {
|
||||||
api.unshareEvent(event!!)
|
api.unshareEvent(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
response?.errors?.ifNotEmpty {
|
response?.errors?.ifNotEmpty {
|
||||||
@ -165,4 +184,31 @@ class EventDetailsDialog(
|
|||||||
if (activity is MainActivity && activity.navTargetId == MainActivity.DRAWER_ITEM_AGENDA)
|
if (activity is MainActivity && activity.navTargetId == MainActivity.DRAWER_ITEM_AGENDA)
|
||||||
activity.reloadTarget()
|
activity.reloadTarget()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun openInCalendar() { launch {
|
||||||
|
val title = (event.typeName ?: "") +
|
||||||
|
(if (event.typeName.isNotNullNorBlank() && event.subjectLongName.isNotNullNorBlank()) " - " else " ") +
|
||||||
|
(event.subjectLongName ?: "")
|
||||||
|
|
||||||
|
val intent = Intent(Intent.ACTION_EDIT).apply {
|
||||||
|
data = Events.CONTENT_URI
|
||||||
|
putExtra(Events.TITLE, title)
|
||||||
|
putExtra(Events.DESCRIPTION, event.topic)
|
||||||
|
|
||||||
|
if (event.startTime == null) {
|
||||||
|
putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true)
|
||||||
|
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, event.eventDate.inMillis)
|
||||||
|
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, event.eventDate.inMillis)
|
||||||
|
} else {
|
||||||
|
val startTime = event.eventDate.combineWith(event.startTime)
|
||||||
|
val endTime = startTime + 45 * 60 * 1000 /* 45 min */
|
||||||
|
|
||||||
|
putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, false)
|
||||||
|
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, startTime)
|
||||||
|
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
activity.startActivity(intent)
|
||||||
|
}}
|
||||||
}
|
}
|
||||||
|
@ -149,6 +149,34 @@
|
|||||||
android:textAppearance="@style/NavView.TextView.Medium"
|
android:textAppearance="@style/NavView.TextView.Medium"
|
||||||
tools:text="Rozdział II: Panowanie Piastów i Jagiellonów.Przeniesiony z 11 grudnia." />
|
tools:text="Rozdział II: Panowanie Piastów i Jagiellonów.Przeniesiony z 11 grudnia." />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="end"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/editButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="8dp"
|
||||||
|
android:minWidth="0dp"
|
||||||
|
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||||
|
android:text="\uFC92"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:fontFamily="@font/community_material_font_v3_5_95_1" />
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/saveInCalendarButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="8dp"
|
||||||
|
android:minWidth="0dp"
|
||||||
|
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||||
|
android:text="\uFB09"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:fontFamily="@font/community_material_font_v3_5_95_1" />
|
||||||
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</androidx.core.widget.NestedScrollView>
|
</androidx.core.widget.NestedScrollView>
|
||||||
</layout>
|
</layout>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user