This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <Intent : Any> LazyListScope.genericList( | |
items: List<GenericLazyItem<Intent>>, | |
processIntent: (Intent) -> Unit | |
) { | |
items.forEachIndexed { index, genericLazyItem -> | |
/* | |
Draw Header if the section is different than the previous one. | |
*/ | |
if (index == 0 || genericLazyItem.sectionMatcher() != items[index - 1].sectionMatcher()) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class TextImageLeft( | |
private val imageUrl: String, | |
private val title: String, | |
private val description: String, | |
private val groupTitle: String | |
) : GenericLazyItem<ItemIntent>() { | |
override fun sectionMatcher() = groupTitle.hashCode() | |
@Composable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class GenericLazyItem<Intent : Any> { | |
open fun itemKey(): Int = hashCode() | |
open fun sectionMatcher(): Int? = null | |
@Composable | |
open fun BuildHeaderItem( | |
processIntent: (Intent) -> Unit | |
) { | |
//by default no header. | |
} | |
@Composable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LazyColumn { | |
genericList(state.lazyItems) { | |
//list item intent interactions | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LazyColumn { | |
items(contentList) { content -> | |
when(content){ | |
is ImageOnly -> MessageRow(content) | |
is ImageTextRight -> ImageTextRight(content) | |
is ImageTextLeft -> ImageTextLeft(content) | |
is ImageTextTop -> ImageTextTop(content) | |
//... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LazyColumn { | |
items(contentList) { content -> | |
ImageOnly(content) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { | |
when (resultCode) { | |
Constants.LOGIN_SUCCESS -> { | |
if (requestCode == Constants.REQUEST_CODE_MY_ACCOUNT) { | |
onLoginSuccess() | |
} | |
} | |
Constants.LOGOUT_SUCCESS -> { | |
if (requestCode == Constants.REQUEST_CODE_MY_ACCOUNT) { | |
onLogoutSuccess() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val messageLauncher = | |
registerForActivityResult(MessageContract()) { | |
Toast.makeText(this, it, Toast.LENGTH_SHORT).show() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MessageContract : ActivityResultContract<Unit, String>() { | |
companion object { | |
const val MESSAGE = "MESSAGE_CONTRACT" | |
} | |
override fun createIntent(context: Context, input: Unit?) = | |
Intent(context, MessageActivity::class.java) | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MessageActivity : AppCompatActivity() { | |
....... | |
/** | |
* launched via onClick in the XML | |
* sets this finishing activity's result to the text string | |
* entered by the user | |
*/ | |
fun onSubmitMessage(view: View) { | |
val result = Intent().putExtra(MessageContract.MESSAGE, |
NewerOlder