Incoming share

This commit is contained in:
Benoit Marty 2024-06-05 18:02:48 +02:00 committed by Benoit Marty
parent b3190590b9
commit c403dcd5da
21 changed files with 771 additions and 6 deletions

View file

@ -16,9 +16,32 @@
package io.element.android.libraries.androidutils.compat
import android.content.Intent
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.os.Build
import android.os.Parcelable
inline fun <reified T> Intent.getParcelableExtraCompat(key: String): T? = when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getParcelableExtra(key, T::class.java)
else -> @Suppress("DEPRECATION") getParcelableExtra(key) as? T?
}
inline fun <reified T : Parcelable> Intent.getParcelableArrayListExtraCompat(key: String): ArrayList<T>? = when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getParcelableArrayListExtra(key, T::class.java)
else -> @Suppress("DEPRECATION") getParcelableArrayListExtra<T>(key)
}
fun PackageManager.queryIntentActivitiesCompat(data: Intent, flags: Int): List<ResolveInfo> {
return when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> queryIntentActivities(
data,
PackageManager.ResolveInfoFlags.of(flags.toLong())
)
else -> @Suppress("DEPRECATION") queryIntentActivities(data, flags)
}
}
fun PackageManager.getApplicationInfoCompat(packageName: String, flags: Int): ApplicationInfo {
return when {

View file

@ -18,4 +18,5 @@ package io.element.android.libraries.roomselect.api
enum class RoomSelectMode {
Forward,
Share,
}

View file

@ -31,29 +31,33 @@ open class RoomSelectStateProvider : PreviewParameterProvider<RoomSelectState> {
get() = sequenceOf(
aRoomSelectState(),
aRoomSelectState(query = "Test", isSearchActive = true),
aRoomSelectState(resultState = SearchBarResultState.Results(aForwardMessagesRoomList())),
aRoomSelectState(resultState = SearchBarResultState.Results(aRoomSelectRoomList())),
aRoomSelectState(
resultState = SearchBarResultState.Results(aForwardMessagesRoomList()),
resultState = SearchBarResultState.Results(aRoomSelectRoomList()),
query = "Test",
isSearchActive = true,
),
aRoomSelectState(
resultState = SearchBarResultState.Results(aForwardMessagesRoomList()),
resultState = SearchBarResultState.Results(aRoomSelectRoomList()),
query = "Test",
isSearchActive = true,
selectedRooms = persistentListOf(aRoomSummaryDetails(roomId = RoomId("!room2:domain")))
),
// Add other states here
aRoomSelectState(
mode = RoomSelectMode.Share,
resultState = SearchBarResultState.Results(aRoomSelectRoomList()),
),
)
}
private fun aRoomSelectState(
mode: RoomSelectMode = RoomSelectMode.Forward,
resultState: SearchBarResultState<ImmutableList<RoomSummaryDetails>> = SearchBarResultState.Initial(),
query: String = "",
isSearchActive: Boolean = false,
selectedRooms: ImmutableList<RoomSummaryDetails> = persistentListOf(),
) = RoomSelectState(
mode = RoomSelectMode.Forward,
mode = mode,
resultState = resultState,
query = query,
isSearchActive = isSearchActive,
@ -61,7 +65,7 @@ private fun aRoomSelectState(
eventSink = {}
)
private fun aForwardMessagesRoomList() = persistentListOf(
private fun aRoomSelectRoomList() = persistentListOf(
aRoomSummaryDetails(),
aRoomSummaryDetails(
roomId = RoomId("!room2:domain"),

View file

@ -105,6 +105,7 @@ fun RoomSelectView(
Text(
text = when (state.mode) {
RoomSelectMode.Forward -> stringResource(CommonStrings.common_forward_message)
RoomSelectMode.Share -> stringResource(CommonStrings.common_send_to)
},
style = ElementTheme.typography.aliasScreenTitle
)

View file

@ -197,6 +197,7 @@
<string name="common_search_results">"Search results"</string>
<string name="common_security">"Security"</string>
<string name="common_seen_by">"Seen by"</string>
<string name="common_send_to">"Send to"</string>
<string name="common_sending">"Sending…"</string>
<string name="common_sending_failed">"Sending failed"</string>
<string name="common_sent">"Sent"</string>