Retain content of compose view on orientation change
This commit is contained in:
parent
e3c7c4d557
commit
fb72356467
@ -43,6 +43,7 @@ class ComposeMessageActivity : AppCompatActivity() {
|
|||||||
setHomeButtonEnabled(false)
|
setHomeButtonEnabled(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (supportFragmentManager.findFragmentById(R.id.content) == null) {
|
||||||
// Display the fragment as the main content.
|
// Display the fragment as the main content.
|
||||||
val fragment = ComposeMessageFragment()
|
val fragment = ComposeMessageFragment()
|
||||||
fragment.arguments = intent.extras
|
fragment.arguments = intent.extras
|
||||||
@ -51,6 +52,7 @@ class ComposeMessageActivity : AppCompatActivity() {
|
|||||||
.replace(R.id.content, fragment)
|
.replace(R.id.content, fragment)
|
||||||
.commit()
|
.commit()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val EXTRA_DRAFT = "ch.dissem.abit.Message.DRAFT"
|
const val EXTRA_DRAFT = "ch.dissem.abit.Message.DRAFT"
|
||||||
@ -63,10 +65,13 @@ class ComposeMessageActivity : AppCompatActivity() {
|
|||||||
const val EXTRA_PARENT = "ch.dissem.abit.Message.PARENT"
|
const val EXTRA_PARENT = "ch.dissem.abit.Message.PARENT"
|
||||||
|
|
||||||
fun launchReplyTo(fragment: Fragment, item: Plaintext) =
|
fun launchReplyTo(fragment: Fragment, item: Plaintext) =
|
||||||
fragment.startActivity(getReplyIntent(
|
fragment.startActivity(
|
||||||
ctx = fragment.activity ?: throw IllegalStateException("Fragment not attached to an activity"),
|
getReplyIntent(
|
||||||
|
ctx = fragment.activity
|
||||||
|
?: throw IllegalStateException("Fragment not attached to an activity"),
|
||||||
item = item
|
item = item
|
||||||
))
|
)
|
||||||
|
)
|
||||||
|
|
||||||
fun launchReplyTo(activity: Activity, item: Plaintext) =
|
fun launchReplyTo(activity: Activity, item: Plaintext) =
|
||||||
activity.startActivity(getReplyIntent(activity, item))
|
activity.startActivity(getReplyIntent(activity, item))
|
||||||
@ -90,15 +95,20 @@ class ComposeMessageActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
replyIntent.putExtra(EXTRA_PARENT, item)
|
replyIntent.putExtra(EXTRA_PARENT, item)
|
||||||
item.subject?.let { subject ->
|
item.subject?.let { subject ->
|
||||||
val prefix: String = if (subject.length >= 3 && subject.substring(0, 3).equals("RE:", ignoreCase = true)) {
|
val prefix: String = if (subject.length >= 3 && subject.substring(0, 3).equals(
|
||||||
|
"RE:",
|
||||||
|
ignoreCase = true
|
||||||
|
)) {
|
||||||
""
|
""
|
||||||
} else {
|
} else {
|
||||||
"RE: "
|
"RE: "
|
||||||
}
|
}
|
||||||
replyIntent.putExtra(EXTRA_SUBJECT, prefix + subject)
|
replyIntent.putExtra(EXTRA_SUBJECT, prefix + subject)
|
||||||
}
|
}
|
||||||
replyIntent.putExtra(EXTRA_CONTENT,
|
replyIntent.putExtra(
|
||||||
"\n\n------------------------------------------------------\n" + item.text!!)
|
EXTRA_CONTENT,
|
||||||
|
"\n\n------------------------------------------------------\n" + item.text!!
|
||||||
|
)
|
||||||
return replyIntent
|
return replyIntent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,7 @@ class ComposeMessageFragment : Fragment() {
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
retainInstance = true
|
||||||
arguments?.apply {
|
arguments?.apply {
|
||||||
val draft = getSerializable(EXTRA_DRAFT) as Plaintext?
|
val draft = getSerializable(EXTRA_DRAFT) as Plaintext?
|
||||||
if (draft != null) {
|
if (draft != null) {
|
||||||
@ -266,6 +267,14 @@ class ComposeMessageFragment : Fragment() {
|
|||||||
super.onPause()
|
super.onPause()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDestroyView() {
|
||||||
|
identity = sender_input.selectedItem as BitmessageAddress
|
||||||
|
// recipient is set when one is selected
|
||||||
|
subject = subject_input.text?.toString() ?: ""
|
||||||
|
content = body_input.text?.toString() ?: ""
|
||||||
|
super.onDestroyView()
|
||||||
|
}
|
||||||
|
|
||||||
private fun send() {
|
private fun send() {
|
||||||
val ctx = activity ?: throw IllegalStateException("Fragment is not attached to an activity")
|
val ctx = activity ?: throw IllegalStateException("Fragment is not attached to an activity")
|
||||||
if (recipient == null) {
|
if (recipient == null) {
|
||||||
|
@ -114,6 +114,13 @@ class ContactAdapter(
|
|||||||
}.invoke()
|
}.invoke()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newValues.isEmpty()) {
|
||||||
|
try {
|
||||||
|
newValues.add(BitmessageAddress(prefix.toString()))
|
||||||
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
results.values = newValues
|
results.values = newValues
|
||||||
results.count = newValues.size
|
results.count = newValues.size
|
||||||
} else {
|
} else {
|
||||||
@ -134,4 +141,6 @@ class ContactAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun indexOf(element: BitmessageAddress) = originalData.indexOf(element)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user