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

Fix for crash on Samsung Clipboard ListView on Android 8.X #795

Merged
merged 3 commits into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
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
15 changes: 14 additions & 1 deletion aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import android.view.WindowManager
import android.view.inputmethod.BaseInputConnection
import android.widget.CheckBox
import android.widget.EditText
import android.widget.Toast
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -1384,6 +1385,8 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
max = Math.max(0, Math.max(selectionStart, selectionEnd))
}

var clipboardIdentifier = resources.getIdentifier("android:id/clipboard", "id", context.packageName)

when (id) {
android.R.id.paste -> paste(text, min, max)
android.R.id.pasteAsPlainText -> paste(text, min, max, true)
Expand All @@ -1400,7 +1403,17 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
deleteInlineStyleFromTheBeginning()
}
}
else -> return super.onTextContextMenuItem(id)
// Fix for crash when pasting text on Samsung Devices running Android 8.
// Ref: https://github.com/wordpress-mobile/WordPress-Android/issues/8827
clipboardIdentifier -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && Build.VERSION.SDK_INT < 28
&& Build.MANUFACTURER.toLowerCase().equals("samsung")) {
// Nope return true
Toast.makeText(context, R.string.samsung_disabled_custom_clipboard, Toast.LENGTH_LONG).show()
} else {
return super.onTextContextMenuItem(id)
}
} else -> return super.onTextContextMenuItem(id)
}

return true
Expand Down
1 change: 1 addition & 0 deletions aztec/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<!-- GENERAL -->
<string name="cursor_moved">Cursor moved</string>
<string name="samsung_disabled_custom_clipboard">Sorry, this feature is disabled on Android 8. Please use the Paste action instead.</string>

<!-- LINK DIALOG -->
<string name="link_dialog_title">Insert link</string>
Expand Down