@@ -3,8 +3,12 @@ package org.fossify.notes.activities
33import android.accounts.NetworkErrorException
44import android.annotation.SuppressLint
55import android.content.ActivityNotFoundException
6- import android.content.Context
76import android.content.Intent
7+ import android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK
8+ import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
9+ import android.content.Intent.FLAG_ACTIVITY_NO_HISTORY
10+ import android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION
11+ import android.content.Intent.FLAG_GRANT_WRITE_URI_PERMISSION
812import android.content.pm.ShortcutInfo
913import android.content.pm.ShortcutManager
1014import android.graphics.drawable.Icon
@@ -372,15 +376,17 @@ class MainActivity : SimpleActivity() {
372376
373377 override fun onActivityResult (requestCode : Int , resultCode : Int , resultData : Intent ? ) {
374378 super .onActivityResult(requestCode, resultCode, resultData)
375- if (requestCode == PICK_OPEN_FILE_INTENT && resultCode == RESULT_OK && resultData != null && resultData.data != null ) {
376- importUri(resultData.data!! )
377- } else if (requestCode == PICK_EXPORT_FILE_INTENT && resultCode == RESULT_OK && resultData != null && resultData.data != null && mNotes.isNotEmpty()) {
378- val takeFlags =
379- Intent .FLAG_GRANT_READ_URI_PERMISSION or Intent .FLAG_GRANT_WRITE_URI_PERMISSION
380- applicationContext.contentResolver.takePersistableUriPermission(
381- resultData.data!! , takeFlags
382- )
383- showExportFilePickUpdateDialog(resultData.dataString!! , getCurrentNoteValue())
379+ if (resultCode != RESULT_OK || resultData?.data == null ) return
380+
381+ val dataUri = resultData.data!!
382+ when (requestCode) {
383+ PICK_OPEN_FILE_INTENT -> importUri(dataUri)
384+ PICK_EXPORT_FILE_INTENT -> if (mNotes.isNotEmpty()) {
385+ applicationContext.contentResolver.takePersistableUriPermission(
386+ dataUri, FLAG_GRANT_READ_URI_PERMISSION or FLAG_GRANT_WRITE_URI_PERMISSION
387+ )
388+ showExportFilePickUpdateDialog(resultData.dataString!! , getCurrentNoteValue())
389+ }
384390 }
385391 }
386392
@@ -402,7 +408,7 @@ class MainActivity : SimpleActivity() {
402408 try {
403409 shortcutManager.dynamicShortcuts = listOf (newTextNote, newChecklist)
404410 config.lastHandledShortcutColor = appIconColor
405- } catch (ignored : Exception ) {
411+ } catch (_ : Exception ) {
406412 }
407413 }
408414 }
@@ -694,10 +700,8 @@ class MainActivity : SimpleActivity() {
694700 return getNoteIndexWithId(noteIdToOpen)
695701 }
696702
697- private fun currentNotesView () = if (binding.viewPager == null ) {
698- null
699- } else {
700- mAdapter?.getCurrentNotesView(binding.viewPager.currentItem)
703+ private fun currentNotesView (): MyEditText ? {
704+ return mAdapter?.getCurrentNotesView(binding.viewPager.currentItem)
701705 }
702706
703707 private fun displayRenameDialog () {
@@ -932,8 +936,7 @@ class MainActivity : SimpleActivity() {
932936 true
933937 } else {
934938 try {
935- val takeFlags =
936- Intent .FLAG_GRANT_READ_URI_PERMISSION or Intent .FLAG_GRANT_WRITE_URI_PERMISSION
939+ val takeFlags = FLAG_GRANT_READ_URI_PERMISSION or FLAG_GRANT_WRITE_URI_PERMISSION
937940 applicationContext.contentResolver.takePersistableUriPermission(uri, takeFlags)
938941 true
939942 } catch (e: Exception ) {
@@ -1216,7 +1219,7 @@ class MainActivity : SimpleActivity() {
12161219 val jobName = mCurrentNote.title
12171220 val printAdapter = webView.createPrintDocumentAdapter(jobName)
12181221
1219- (getSystemService(Context . PRINT_SERVICE ) as ? PrintManager )?.apply {
1222+ (getSystemService(PRINT_SERVICE ) as ? PrintManager )?.apply {
12201223 try {
12211224 print (jobName, printAdapter, PrintAttributes .Builder ().build())
12221225 } catch (e: IllegalStateException ) {
@@ -1361,8 +1364,12 @@ class MainActivity : SimpleActivity() {
13611364 }
13621365
13631366 private fun shareText () {
1364- val text =
1365- if (mCurrentNote.type == NoteType .TYPE_TEXT ) getCurrentNoteText() else mCurrentNote.value
1367+ val text = if (mCurrentNote.type == NoteType .TYPE_TEXT ) {
1368+ getCurrentNoteText()
1369+ } else {
1370+ mCurrentNote.value
1371+ }
1372+
13661373 if (text.isNullOrEmpty()) {
13671374 toast(R .string.cannot_share_empty_text)
13681375 return
@@ -1393,7 +1400,7 @@ class MainActivity : SimpleActivity() {
13931400 intent.action = Intent .ACTION_VIEW
13941401 intent.putExtra(OPEN_NOTE_ID , note.id)
13951402 intent.flags =
1396- intent.flags or Intent . FLAG_ACTIVITY_NEW_TASK or Intent . FLAG_ACTIVITY_CLEAR_TASK or Intent . FLAG_ACTIVITY_NO_HISTORY
1403+ intent.flags or FLAG_ACTIVITY_NEW_TASK or FLAG_ACTIVITY_CLEAR_TASK or FLAG_ACTIVITY_NO_HISTORY
13971404
13981405 val shortcut = ShortcutInfo .Builder (this , note.hashCode().toString())
13991406 .setShortLabel(mCurrentNote.title)
0 commit comments