Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat-share-checklist #695

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import com.simplemobiletools.notes.pro.fragments.TextFragment
import com.simplemobiletools.notes.pro.helpers.*
import com.simplemobiletools.notes.pro.models.Note
import com.simplemobiletools.notes.pro.models.NoteType
import org.json.JSONArray
import java.io.File
import java.nio.charset.Charset
import java.util.*
Expand Down Expand Up @@ -1165,7 +1166,11 @@ class MainActivity : SimpleActivity() {
}

private fun shareText() {
val text = if (mCurrentNote.type == NoteType.TYPE_TEXT) getCurrentNoteText() else mCurrentNote.value
val text = if (mCurrentNote.type == NoteType.TYPE_TEXT) {
getCurrentNoteText()
} else {
getTitlesFromCheckList(mCurrentNote.value)
}
if (text.isNullOrEmpty()) {
toast(R.string.cannot_share_empty_text)
return
Expand All @@ -1182,6 +1187,29 @@ class MainActivity : SimpleActivity() {
}
}

private fun getTitlesFromCheckList(jsonStr: String): String {

val jsonArray = JSONArray(jsonStr)

val stringBuilder = StringBuilder()

for (i in 0 until jsonArray.length()) {
val jsonObject = jsonArray.getJSONObject(i)
val title = jsonObject.getString("title")
val isDone = jsonObject.getBoolean("isDone")

val checkmark = if (isDone) "✔" else "✘"

stringBuilder.append("$checkmark $title")

if (i < jsonArray.length() - 1) {
stringBuilder.append("\n")
}
}

return stringBuilder.toString()
}

@SuppressLint("NewApi")
private fun createShortcut() {
val manager = getSystemService(ShortcutManager::class.java)
Expand Down