Ask the user to install a PDF reader

This commit is contained in:
2020-02-08 18:51:16 +01:00
committed by Matte23
parent 3a1e213442
commit ec5460afb0
4 changed files with 39 additions and 2 deletions

View File

@@ -28,6 +28,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ImageButton import android.widget.ImageButton
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.item_attachment.view.* import kotlinx.android.synthetic.main.item_attachment.view.*
import net.underdesk.circolapp.R import net.underdesk.circolapp.R
@@ -59,7 +60,22 @@ class AttachmentAdapter(
holder.viewButton.setOnClickListener { holder.viewButton.setOnClickListener {
val viewIntent = Intent(Intent.ACTION_VIEW) val viewIntent = Intent(Intent.ACTION_VIEW)
viewIntent.setDataAndType(Uri.parse(attachmentsUrls[position]), "application/pdf") viewIntent.setDataAndType(Uri.parse(attachmentsUrls[position]), "application/pdf")
context.startActivity(viewIntent) if (viewIntent.resolveActivity(context.packageManager) != null) {
context.startActivity(viewIntent)
} else {
val builder = AlertDialog.Builder(context)
builder.apply {
setTitle(R.string.dialog_install_pdf_reader_title)
setMessage(R.string.dialog_install_pdf_reader_content)
setPositiveButton(
R.string.dialog_ok
) { dialog, _ ->
dialog.dismiss()
}
}
builder.create().show()
}
} }
holder.downloadButton.setOnClickListener { holder.downloadButton.setOnClickListener {

View File

@@ -146,7 +146,22 @@ class CircularLetterAdapter(
holder.viewButton.setOnClickListener { holder.viewButton.setOnClickListener {
val viewIntent = Intent(Intent.ACTION_VIEW) val viewIntent = Intent(Intent.ACTION_VIEW)
viewIntent.setDataAndType(Uri.parse(circulars[position].url), "application/pdf") viewIntent.setDataAndType(Uri.parse(circulars[position].url), "application/pdf")
context.startActivity(viewIntent) if (viewIntent.resolveActivity(context.packageManager) != null) {
context.startActivity(viewIntent)
} else {
val builder = AlertDialog.Builder(context)
builder.apply {
setTitle(R.string.dialog_install_pdf_reader_title)
setMessage(R.string.dialog_install_pdf_reader_content)
setPositiveButton(
R.string.dialog_ok
) { dialog, _ ->
dialog.dismiss()
}
}
builder.create().show()
}
} }
holder.downloadButton.setOnClickListener { holder.downloadButton.setOnClickListener {

View File

@@ -45,6 +45,9 @@
Le circolari sono scritte e pubblicate dal Liceo Scientifico Maria Curie di Pinerolo, e sono scaricate direttamente da https://curiepinerolo.edu.it/.\n Le circolari sono scritte e pubblicate dal Liceo Scientifico Maria Curie di Pinerolo, e sono scaricate direttamente da https://curiepinerolo.edu.it/.\n
Questi documenti sono rilasciati secondo la licenza "Attribution-NonCommercial-ShareAlike 3.0 Unported" (CC BY-NC-SA 3.0)(https://creativecommons.org/licenses/by-nc-sa/3.0/), come specificato in questa pagina: https://curiepinerolo.edu.it/note-legali/</string> Questi documenti sono rilasciati secondo la licenza "Attribution-NonCommercial-ShareAlike 3.0 Unported" (CC BY-NC-SA 3.0)(https://creativecommons.org/licenses/by-nc-sa/3.0/), come specificato in questa pagina: https://curiepinerolo.edu.it/note-legali/</string>
<string name="dialog_install_pdf_reader_title">Lettore PDF non installato</string>
<string name="dialog_install_pdf_reader_content">Installa un lettore di PDF per aprire le circolari</string>
<string name="dialog_title_permission_required">Autorizzazioni richieste</string> <string name="dialog_title_permission_required">Autorizzazioni richieste</string>
<string name="dialog_message_permission_write">È necessaria la tua autorizzazione per salvare questa circolare nella memoria interna</string> <string name="dialog_message_permission_write">È necessaria la tua autorizzazione per salvare questa circolare nella memoria interna</string>

View File

@@ -46,6 +46,9 @@
Circulars letters are written by the Liceo Scientifico Maria Curie Pinerolo, and are downloaded directly from https://curiepinerolo.edu.it/.\n Circulars letters are written by the Liceo Scientifico Maria Curie Pinerolo, and are downloaded directly from https://curiepinerolo.edu.it/.\n
Those documents are released under the "Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)(https://creativecommons.org/licenses/by-nc-sa/3.0/), as specified in this page: https://curiepinerolo.edu.it/note-legali</string> Those documents are released under the "Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)(https://creativecommons.org/licenses/by-nc-sa/3.0/), as specified in this page: https://curiepinerolo.edu.it/note-legali</string>
<string name="dialog_install_pdf_reader_title">PDF reader not found</string>
<string name="dialog_install_pdf_reader_content">Please install an external application to open circular letters</string>
<string name="dialog_title_permission_required">Permission required</string> <string name="dialog_title_permission_required">Permission required</string>
<string name="dialog_message_permission_write">We need your permission to save this circular letter to local storage</string> <string name="dialog_message_permission_write">We need your permission to save this circular letter to local storage</string>