Skip to content

Commit

Permalink
Allows to share text or text/plain files to open a new text note.
Browse files Browse the repository at this point in the history
  • Loading branch information
coderPaddyS committed Nov 3, 2023
1 parent 342be76 commit 39bbe1f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
26 changes: 25 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,31 @@
android:name=".ui.notes.TextNoteActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/title_textnote"
android:parentActivityName=".ui.main.MainActivity" />
android:parentActivityName=".ui.main.MainActivity"
android:exported="true">

<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SENDTO" />

<data android:scheme="content"/>
<data android:scheme="file"/>
<data android:scheme="http"/>
<data android:scheme="https"/>

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<activity
android:name=".ui.notes.ChecklistNoteActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,10 @@ abstract class BaseNoteActivity(noteType: Int) : AppCompatActivity(), View.OnCli
loadActivity(false)
}

fun setTitle(title: String) {
etName.setText(title)
}

class ActionResult<O, E>(private val status: Boolean, val ok: O?, val err: E? = null) {
fun isOk(): Boolean {
return this.status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.Typeface
import android.media.MediaScannerConnection
import android.net.Uri
import android.os.Bundle
import android.text.Html
import android.text.Spannable
Expand All @@ -36,6 +37,7 @@ import org.secuso.privacyfriendlynotes.room.DbContract
import org.secuso.privacyfriendlynotes.room.model.Note
import java.io.File
import java.io.IOException
import java.io.InputStreamReader
import java.io.PrintWriter

/**
Expand Down Expand Up @@ -86,7 +88,18 @@ class TextNoteActivity : BaseNoteActivity(DbContract.NoteEntry.TYPE_TEXT) {
}

override fun onNewNote() {

if (intent != null) {
val uri: Uri? = listOf(intent.data, intent.getParcelableExtra(Intent.EXTRA_STREAM)).firstNotNullOfOrNull { it }
if (uri != null) {
val text = InputStreamReader(contentResolver.openInputStream(uri)).readLines();
super.setTitle(text[0])
etContent.setText(Html.fromHtml(text.subList(1,text.size).joinToString(System.lineSeparator())))
}
val text = intent.getStringExtra(Intent.EXTRA_TEXT)
if (text != null) {
etContent.setText(Html.fromHtml(text))
}
}
}

override fun onLoadActivity() {
Expand Down

0 comments on commit 39bbe1f

Please sign in to comment.