From 89fccb546eaf20a1d4ebe1fa4c6978c3dcacba12 Mon Sep 17 00:00:00 2001 From: Kevin Boos Date: Tue, 8 Oct 2024 01:05:12 -0700 Subject: [PATCH 01/12] Initial implementation of fetching location and rendering a location preview Not yet working; can't fetch current location. --- Cargo.lock | 146 ++++++++++++++++++++++++++++--- Cargo.toml | 1 + resources/icons/location-poi.svg | 2 + src/home/room_screen.rs | 135 ++++++++++++++++++++++++---- src/lib.rs | 1 + src/location.rs | 123 ++++++++++++++++++++++++++ 6 files changed, 379 insertions(+), 29 deletions(-) create mode 100644 resources/icons/location-poi.svg create mode 100644 src/location.rs diff --git a/Cargo.lock b/Cargo.lock index 18306a9d..1509ba66 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -77,6 +77,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "android-build" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a133d38cebf328adaea4bc1891d9568e14a394b50e4f4ba5f63dc14e8beaaee9" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -328,9 +337,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" dependencies = [ "serde", ] @@ -391,6 +400,15 @@ dependencies = [ "objc2", ] +[[package]] +name = "block2" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c132eebf10f5cad5289222520a4a058514204aed6d791f1cf4fe8088b82d15f" +dependencies = [ + "objc2", +] + [[package]] name = "bs58" version = "0.5.0" @@ -1360,7 +1378,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fb69199826926eb864697bddd27f73d9fddcffc004f5733131e15b465e30642" dependencies = [ - "block2", + "block2 0.4.0", "objc2", ] @@ -1612,7 +1630,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "bitflags 2.4.1", + "bitflags 2.6.0", "libc", ] @@ -1959,7 +1977,7 @@ name = "makepad-zune-core" version = "0.2.14" source = "git+https://github.com/kevinaboos/makepad?branch=modal_sends_dismissed_action_to_inner_modal_content#dd319e6e74d9d70f8c90fef639109ae32caee863" dependencies = [ - "bitflags 2.4.1", + "bitflags 2.6.0", ] [[package]] @@ -2084,7 +2102,7 @@ source = "git+https://github.com/matrix-org/matrix-rust-sdk#dc055c632c106c6392ee dependencies = [ "as_variant", "async-trait", - "bitflags 2.4.1", + "bitflags 2.6.0", "eyeball", "eyeball-im", "futures-util", @@ -2341,7 +2359,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad5a3bbb2ae61f345b8c11776f2e79fc2bb71d1901af9a5f81f03c9238a05d86" dependencies = [ - "bitflags 2.4.1", + "bitflags 2.6.0", "ctor", "napi-sys-ohos", "once_cell", @@ -2413,12 +2431,47 @@ dependencies = [ "objc2-encode", ] +[[package]] +name = "objc2-contacts" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5ff520e9c33812fd374d8deecef01d4a840e7b41862d849513de77e44aa4889" +dependencies = [ + "block2 0.5.1", + "objc2", + "objc2-foundation", +] + +[[package]] +name = "objc2-core-location" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "000cfee34e683244f284252ee206a27953279d370e309649dc3ee317b37e5781" +dependencies = [ + "block2 0.5.1", + "objc2", + "objc2-contacts", + "objc2-foundation", +] + [[package]] name = "objc2-encode" version = "4.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7891e71393cd1f227313c9379a26a584ff3d7e6e7159e988851f0934c993f0f8" +[[package]] +name = "objc2-foundation" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ee638a5da3799329310ad4cfa62fbf045d5f56e3ef5ba4149e7452dcf89d5a8" +dependencies = [ + "bitflags 2.6.0", + "block2 0.5.1", + "libc", + "objc2", +] + [[package]] name = "object" version = "0.32.1" @@ -2747,7 +2800,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "666f0f59e259aea2d72e6012290c09877a780935cc3c18b1ceded41f3890d59c" dependencies = [ - "bitflags 2.4.1", + "bitflags 2.6.0", "memchr", "pulldown-cmark-escape", "unicase", @@ -3040,6 +3093,21 @@ dependencies = [ "robius-android-env", ] +[[package]] +name = "robius-location" +version = "0.1.0" +source = "git+https://github.com/project-robius/robius-location#544c57e3d4f4ee6257a5c290e3e76104acae6046" +dependencies = [ + "android-build", + "cfg-if", + "jni", + "objc2", + "objc2-core-location", + "objc2-foundation", + "robius-android-env", + "windows", +] + [[package]] name = "robius-open" version = "0.1.0" @@ -3084,6 +3152,7 @@ dependencies = [ "rand", "rangemap", "robius-directories", + "robius-location", "robius-open", "robius-use-makepad", "serde", @@ -3253,7 +3322,7 @@ version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b838eba278d213a8beaf485bd313fd580ca4505a00d5871caeb1457c55322cae" dependencies = [ - "bitflags 2.4.1", + "bitflags 2.6.0", "fallible-iterator", "fallible-streaming-iterator", "hashlink", @@ -3288,7 +3357,7 @@ version = "0.38.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3" dependencies = [ - "bitflags 2.4.1", + "bitflags 2.6.0", "errno", "libc", "linux-raw-sys", @@ -4361,6 +4430,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +dependencies = [ + "windows-core 0.57.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows-core" version = "0.51.1" @@ -4378,17 +4457,60 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result 0.1.2", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.75", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.75", +] + [[package]] name = "windows-registry" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" dependencies = [ - "windows-result", + "windows-result 0.2.0", "windows-strings", "windows-targets 0.52.6", ] +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-result" version = "0.2.0" @@ -4404,7 +4526,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" dependencies = [ - "windows-result", + "windows-result 0.2.0", "windows-targets 0.52.6", ] diff --git a/Cargo.toml b/Cargo.toml index 9deb4084..1168f8dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ robius-use-makepad = "0.1.0" robius-open = "0.1.0" ## A fork of the `directories` crate that adds support for Android by using our `robius-android-env` crate. robius-directories = { git = "https://github.com/project-robius/robius-directories", branch = "robius"} +robius-location = { git = "https://github.com/project-robius/robius-location" } anyhow = "1.0" chrono = "0.4" diff --git a/resources/icons/location-poi.svg b/resources/icons/location-poi.svg new file mode 100644 index 00000000..1c7515d5 --- /dev/null +++ b/resources/icons/location-poi.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/src/home/room_screen.rs b/src/home/room_screen.rs index 37aaa5fd..5aab0c61 100644 --- a/src/home/room_screen.rs +++ b/src/home/room_screen.rs @@ -24,7 +24,7 @@ use matrix_sdk_ui::timeline::{ }; use crate::{ - avatar_cache::{self, AvatarCacheEntry}, event_preview::{text_preview_of_member_profile_change, text_preview_of_other_state, text_preview_of_redacted_message, text_preview_of_room_membership_change, text_preview_of_timeline_item}, media_cache::{MediaCache, MediaCacheEntry}, profile::{ + avatar_cache::{self, AvatarCacheEntry}, event_preview::{text_preview_of_member_profile_change, text_preview_of_other_state, text_preview_of_redacted_message, text_preview_of_room_membership_change, text_preview_of_timeline_item}, location::{get_latest_location, init_location_subscriber, request_location_update, LocationRequest, LocationUpdate}, media_cache::{MediaCache, MediaCacheEntry}, profile::{ user_profile::{AvatarState, ShowUserProfileAction, UserProfile, UserProfileAndRoomId, UserProfilePaneInfo, UserProfileSlidingPaneRef, UserProfileSlidingPaneWidgetExt}, user_profile_cache, }, shared::{ @@ -32,8 +32,7 @@ use crate::{ html_or_plaintext::{HtmlOrPlaintextRef, HtmlOrPlaintextWidgetRefExt}, text_or_image::{TextOrImageRef, TextOrImageWidgetRefExt}, typing_animation::TypingAnimationWidgetExt, - }, - sliding_sync::{get_client, submit_async_request, take_timeline_update_receiver, MatrixRequest}, utils::{self, unix_time_millis_to_datetime, MediaFormatConst} + }, sliding_sync::{get_client, submit_async_request, take_timeline_update_receiver, MatrixRequest}, utils::{self, unix_time_millis_to_datetime, MediaFormatConst} }; use rangemap::RangeSet; @@ -60,6 +59,7 @@ live_design! { ICO_USER = dep("crate://self/resources/icon_user.svg") ICO_ADD = dep("crate://self/resources/icon_add.svg") ICO_CLOSE = dep("crate://self/resources/icons/close.svg") + ICO_LOCATION_POI = dep("crate://self/resources/icons/location_poi.svg") ICO_JUMP_TO_BOTTOM = dep("crate://self/resources/icon_jump_to_bottom.svg") TEXT_SUB = { @@ -728,9 +728,6 @@ live_design! { // First, display the timeline of all messages/events. timeline = {} - - - // Below that, display an optional preview of the message that the user // is currently drafting a replied to. replying_preview = { @@ -777,7 +774,7 @@ live_design! { reply_preview_content = { } } - // Below that, display user typing notice + // Below that, display a typing notice when other users in the room are typing. typing_notice = { visible: false width: Fill @@ -802,6 +799,70 @@ live_design! { typing_animation = {} } + // Below that, display a preview of the current location that a user is about to share. + location_preview = { + visible: false + width: Fill + height: Fit + flow: Down + padding: 0.0 + + show_bg: true, + draw_bg: { + color: #EEEEEE, + } + + { + width: Fill + height: Fit + flow: Right + padding: {left: 12.0, top: 8.0, bottom: 8.0, right: 10.0} + align: {y: 0.5} + +