Skip to content

Commit

Permalink
Added check if email app isn't installed
Browse files Browse the repository at this point in the history
  • Loading branch information
OmGodse committed Feb 25, 2023
1 parent 2097b97 commit b3424c2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
6 changes: 4 additions & 2 deletions app/src/main/java/com/omgodse/notally/MenuDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ class MenuDialog(context: Context) : BottomSheetDialog(context) {
setContentView(scrollView)
}

fun add(title: Int, drawable: Int = 0, onClick: () -> Unit): MenuDialog {
fun add(title: String, drawable: Int = 0, onClick: () -> Unit): MenuDialog {
val item = MenuItemBinding.inflate(layoutInflater, linearLayout, true).root
item.setText(title)
item.text = title
item.setOnClickListener {
dismiss()
onClick()
}
item.setCompoundDrawablesRelativeWithIntrinsicBounds(drawable, 0, 0, 0)
return this
}

fun add(title: Int, drawable: Int = 0, onClick: () -> Unit) = add(context.getString(title), drawable, onClick)
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ abstract class NotallyFragment : Fragment(), ItemListener {

private fun export(baseNote: BaseNote) {
MenuDialog(requireContext())
.add(R.string.pdf) { exportToPDF(baseNote) }
.add(R.string.txt) { exportToTXT(baseNote) }
.add(R.string.json) { exportToJSON(baseNote) }
.add(R.string.html) { exportToHTML(baseNote) }
.add("PDF") { exportToPDF(baseNote) }
.add("TXT") { exportToTXT(baseNote) }
.add("JSON") { exportToJSON(baseNote) }
.add("HTML") { exportToHTML(baseNote) }
.show()
}

Expand Down
28 changes: 15 additions & 13 deletions app/src/main/java/com/omgodse/notally/fragments/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ class Settings : Fragment() {
if (resultCode == Activity.RESULT_OK) {
intent?.data?.let { uri ->
when (requestCode) {
RequestCodeImportXml -> model.importXmlBackup(uri)
RequestCodeImportZip -> model.importZipBackup(uri)
RequestCodeChooseFolder -> model.setAutoBackupPath(uri)
REQUEST_IMPORT_XML -> model.importXmlBackup(uri)
REQUEST_IMPORT_ZIP -> model.importZipBackup(uri)
REQUEST_CHOOSE_FOLDER -> model.setAutoBackupPath(uri)
Constants.RequestCodeExportFile -> model.exportBackup(uri)
}
}
Expand All @@ -119,8 +119,8 @@ class Settings : Fragment() {

private fun importBackup() {
MenuDialog(requireContext())
.add(R.string.zip) { launchImportActivity("application/zip", RequestCodeImportZip) }
.add(R.string.xml) { launchImportActivity("text/xml", RequestCodeImportXml) }
.add("ZIP") { launchImportActivity("application/zip", REQUEST_IMPORT_ZIP) }
.add("XML (Legacy)") { launchImportActivity("text/xml", REQUEST_IMPORT_XML) }
.show()
}

Expand All @@ -146,7 +146,11 @@ class Settings : Fragment() {
intent.putExtra(Intent.EXTRA_STREAM, uri)
}

startActivity(intent)
try {
startActivity(intent)
} catch (exception: ActivityNotFoundException) {
Toast.makeText(requireContext(), R.string.install_an_email, Toast.LENGTH_LONG).show()
}
}

private fun displayLibraries() {
Expand All @@ -170,7 +174,7 @@ class Settings : Fragment() {
.setMessage(R.string.notes_will_be)
.setPositiveButton(R.string.choose_folder) { _, _ ->
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
startActivityForResult(intent, RequestCodeChooseFolder)
startActivityForResult(intent, REQUEST_CHOOSE_FOLDER)
}
.show()
}
Expand Down Expand Up @@ -246,10 +250,8 @@ class Settings : Fragment() {
Toast.makeText(requireContext(), R.string.install_a_browser, Toast.LENGTH_LONG).show()
}
}
}

companion object {
private const val RequestCodeImportXml = 20
private const val RequestCodeImportZip = 21
private const val RequestCodeChooseFolder = 22
}
}
private const val REQUEST_IMPORT_XML = 20
private const val REQUEST_IMPORT_ZIP = 21
private const val REQUEST_CHOOSE_FOLDER = 22
7 changes: 1 addition & 6 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@
<string name="take_note">Take note</string>
<string name="add_label">Add label</string>
<string name="export">Export</string>
<string name="pdf" translatable="false">PDF</string>
<string name="txt" translatable="false">TXT</string>
<string name="zip" translatable="false">ZIP</string>
<string name="html" translatable="false">HTML</string>
<string name="json" translatable="false">JSON</string>
<string name="xml" translatable="false">XML (Legacy)</string>
<string name="view_file">View file</string>
<string name="save_to_device">Save to device</string>
<string name="edit_label">Edit label</string>
Expand Down Expand Up @@ -77,6 +71,7 @@
<string name="invalid_backup">Invalid backup</string>
<string name="imported_backup">Imported backup</string>
<string name="something_went_wrong">Something went wrong. Please try again.</string>
<string name="install_an_email">Install an email app to send feedback</string>
<string name="install_a_browser">Install a browser to open this link</string>

<!-- Settings Page -->
Expand Down

0 comments on commit b3424c2

Please sign in to comment.