diff --git a/app/src/main/assets/message-print-page.html b/app/src/main/assets/message-print-page.html new file mode 100644 index 00000000..8da7dec6 --- /dev/null +++ b/app/src/main/assets/message-print-page.html @@ -0,0 +1,94 @@ + + +
+ +${it.content}
" + .replace(Regex("[\\n\\r]{2,}"), "")
+ .replace(Regex("[\\n\\r]"), "
")
+
+ val jobName = "Wiadomość " + when {
+ it.sender.isNotEmpty() -> "od ${it.sender}"
+ else -> "do ${it.recipient}"
+ } + " $dateString: ${it.subject.ifBlank { view?.messageNoSubjectString.orEmpty() }} | Wulkanowy"
+
+ view?.apply {
+ val html = printHTML
+ .replace("%SUBJECT%", it.subject.ifBlank { view?.messageNoSubjectString.orEmpty() })
+ .replace("%CONTENT%", messageContent)
+ .replace("%INFO%", infoContent)
+ printDocument(html, jobName)
+ }
+ return true
+ }
+ return false
+ }
+
private fun deleteMessage() {
message?.let { message ->
disposable.add(studentRepository.getCurrentStudent()
diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewView.kt
index 3d620459..0fdb4bda 100644
--- a/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewView.kt
+++ b/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewView.kt
@@ -1,5 +1,7 @@
package io.github.wulkanowy.ui.modules.message.preview
+import android.os.Build
+import androidx.annotation.RequiresApi
import io.github.wulkanowy.data.db.entities.Message
import io.github.wulkanowy.data.db.entities.MessageWithAttachment
import io.github.wulkanowy.ui.base.BaseView
@@ -8,6 +10,10 @@ interface MessagePreviewView : BaseView {
val deleteMessageSuccessString: String
+ val messageNoSubjectString: String
+
+ val printHTML: String
+
fun initView()
fun setMessageWithAttachment(item: MessageWithAttachment)
@@ -34,5 +40,10 @@ interface MessagePreviewView : BaseView {
fun openMessageForward(message: Message?)
+ fun shareText(text: String, subject: String)
+
+ @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
+ fun printDocument(html: String, jobName: String)
+
fun popView()
}
diff --git a/app/src/main/java/io/github/wulkanowy/utils/ContextExtension.kt b/app/src/main/java/io/github/wulkanowy/utils/ContextExtension.kt
index 2b40cb47..cf715e65 100644
--- a/app/src/main/java/io/github/wulkanowy/utils/ContextExtension.kt
+++ b/app/src/main/java/io/github/wulkanowy/utils/ContextExtension.kt
@@ -71,4 +71,17 @@ fun Context.openDialer(phone: String) {
startActivity(intent)
}
+fun Context.shareText(text: String, subject: String?) {
+ val sendIntent: Intent = Intent().apply {
+ action = Intent.ACTION_SEND
+ putExtra(Intent.EXTRA_TEXT, text)
+ if (subject != null) {
+ putExtra(Intent.EXTRA_SUBJECT, subject)
+ }
+ type = "text/plain"
+ }
+ val shareIntent = Intent.createChooser(sendIntent, null)
+ startActivity(shareIntent)
+}
+
fun Context.dpToPx(dp: Float) = dp * resources.displayMetrics.densityDpi / DENSITY_DEFAULT
diff --git a/app/src/main/res/drawable/ic_menu_message_print.xml b/app/src/main/res/drawable/ic_menu_message_print.xml
new file mode 100644
index 00000000..204b0f6e
--- /dev/null
+++ b/app/src/main/res/drawable/ic_menu_message_print.xml
@@ -0,0 +1,13 @@
+