Преглед изворни кода

app/chatview: android fix clicking URLs and unselecting when single tapping during text selection mode

darkfi пре 1 недеља
родитељ
комит
e16d3ae864
3 измењених фајлова са 42 додато и 11 уклоњено
  1. 8 0
      bin/app/README.md
  2. 17 10
      bin/app/src/ui/chatview/mod.rs
  3. 17 1
      bin/app/src/ui/chatview/page.rs

+ 8 - 0
bin/app/README.md

@@ -34,6 +34,14 @@ Users who prefer to build locally can follow the commands in the `Dockerfile`.
 Note that the `build.rs` hardcodes the SDK/NDK paths so either you follow it
 Note that the `build.rs` hardcodes the SDK/NDK paths so either you follow it
 exactly (recommended) or modify `build.rs`.
 exactly (recommended) or modify `build.rs`.
 
 
+## GrapheneOS
+
+```
+$ adb shell pm list users
+    UserInfo{10:Work:30}
+$ adb install --user 10 darkfi-app.apk
+```
+
 # ADB Over Wifi
 # ADB Over Wifi
 
 
 Useful for reading the logs without having to be plugged in.
 Useful for reading the logs without having to be plugged in.

+ 17 - 10
bin/app/src/ui/chatview/mod.rs

@@ -1596,20 +1596,27 @@ impl UIObject for ChatView {
 
 
                 // If the timer never fired and movement was minimal, it is a tap.
                 // If the timer never fired and movement was minimal, it is a tap.
                 if is_select_mode.is_none() && (touch_y - start_y).abs() < BIG_EPSILON {
                 if is_select_mode.is_none() && (touch_y - start_y).abs() < BIG_EPSILON {
-                    if self.select_active.load(Ordering::Relaxed) {
-                        // Selection mode is active: a tap adds the line under the finger.
-                        self.select_line(atom.batch_id, touch_y).await;
-                    } else {
-                        // Forward the tap to the message (e.g. open a URL).
-                        let mut msgbuf = self.msgbuf.lock().await;
-                        let msgbuf_pos = self.to_msgbuf_pos(touch_pos);
-                        if let Some((msg, msg_top)) = msgbuf.get_line(msgbuf_pos.y).await {
-                            msg.handle_touch(
+                    // A tap forwards to the message first (opens a URL / downloads a file).
+                    let mut msgbuf = self.msgbuf.lock().await;
+                    let msgbuf_pos = self.to_msgbuf_pos(touch_pos);
+                    let mut is_handled = false;
+                    if let Some((msg, msg_top)) = msgbuf.get_line(msgbuf_pos.y).await {
+                        is_handled = msg
+                            .handle_touch(
                                 TouchPhase::Ended,
                                 TouchPhase::Ended,
                                 0,
                                 0,
                                 Point::new(msgbuf_pos.x, msg_top - msgbuf_pos.y),
                                 Point::new(msgbuf_pos.x, msg_top - msgbuf_pos.y),
                             )
                             )
-                            .await;
+                            .await
+                    }
+                    drop(msgbuf);
+
+                    // Not a URL/file tap and selection mode is active: toggle the line.
+                    if !is_handled && self.select_active.load(Ordering::Relaxed) {
+                        if self.is_line_selected(touch_y).await {
+                            self.deselect_line(atom.batch_id, touch_y).await;
+                        } else {
+                            self.select_line(atom.batch_id, touch_y).await;
                         }
                         }
                     }
                     }
                 }
                 }

+ 17 - 1
bin/app/src/ui/chatview/page.rs

@@ -389,6 +389,22 @@ impl PrivMessage {
 
 
         true
         true
     }
     }
+
+    async fn handle_touch(&self, phase: TouchPhase, touch_pos: Point) -> bool {
+        if phase != TouchPhase::Ended {
+            return false
+        }
+        let Some(url) = self.url_at_local(touch_pos) else { return false };
+        info!(target: "ui::chatview", "URL tapped: {url}");
+
+        #[cfg(target_os = "android")]
+        crate::android::open_url(url);
+
+        #[cfg(not(target_os = "android"))]
+        let _ = open::that(url);
+
+        true
+    }
 }
 }
 
 
 impl std::fmt::Debug for PrivMessage {
 impl std::fmt::Debug for PrivMessage {
@@ -1026,7 +1042,7 @@ impl UIObject for Message {
     }
     }
     async fn handle_touch(&self, phase: TouchPhase, id: u64, touch_pos: Point) -> bool {
     async fn handle_touch(&self, phase: TouchPhase, id: u64, touch_pos: Point) -> bool {
         match self {
         match self {
-            Self::Priv(_) => false,
+            Self::Priv(m) => m.handle_touch(phase, touch_pos).await,
             Self::Date(_) => false,
             Self::Date(_) => false,
             Self::File(m) => m.handle_touch(phase, id, touch_pos).await,
             Self::File(m) => m.handle_touch(phase, id, touch_pos).await,
         }
         }