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
Show file tree
Hide file tree
Changes from 1 commit
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,31 @@ 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")

// Append a checkmark based on the "isDone" value
bhoomigadhiya marked this conversation as resolved.
Show resolved Hide resolved
val checkmark = if (isDone) "✔" else "✘"

stringBuilder.append("$checkmark $title")

// Add a newline separator if it's not the last item
if (i < jsonArray.length() - 1) {
stringBuilder.append("\n")
}
}

return stringBuilder.toString()
}

@SuppressLint("NewApi")
private fun createShortcut() {
val manager = getSystemService(ShortcutManager::class.java)
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
android.enableJetifier=true
android.useAndroidX=true
android.nonTransitiveRClass=true
org.gradle.jvmargs=-Xmx1024m
bhoomigadhiya marked this conversation as resolved.
Show resolved Hide resolved