changeset 413:c466678c57b2

chat: control send button visibility in core.platform_, and show it when there are attachments
author Goffi <goffi@goffi.org>
date Sun, 23 Feb 2020 15:39:06 +0100
parents 7c6149c249c1
children 72a6b06728ab
files cagou/core/platform_/android.py cagou/core/platform_/base.py cagou/plugins/plugin_wid_chat.kv cagou/plugins/plugin_wid_chat.py
diffstat 4 files changed, 13 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/cagou/core/platform_/android.py	Sun Feb 23 15:39:03 2020 +0100
+++ b/cagou/core/platform_/android.py	Sun Feb 23 15:39:06 2020 +0100
@@ -71,6 +71,7 @@
 
 
 class Platform(BasePlatform):
+    send_button_visible = True
 
     def __init__(self):
         super().__init__()
--- a/cagou/core/platform_/base.py	Sun Feb 23 15:39:03 2020 +0100
+++ b/cagou/core/platform_/base.py	Sun Feb 23 15:39:06 2020 +0100
@@ -34,6 +34,8 @@
 
 class Platform:
     """Base class to handle platform specific behaviours"""
+    # set to True to always show the send button in chat
+    send_button_visible = False
 
     def init_platform(self):
         # we don't want multi-touch emulation with mouse
--- a/cagou/plugins/plugin_wid_chat.kv	Sun Feb 23 15:39:03 2020 +0100
+++ b/cagou/plugins/plugin_wid_chat.kv	Sun Feb 23 15:39:06 2020 +0100
@@ -171,6 +171,7 @@
     message_input: message_input
     messages_widget: messages_widget
     history_scroll: history_scroll
+    send_button_visible: G.local_platform.send_button_visible or bool(attachments_to_send.attachments.children)
     ScrollView:
         id: history_scroll
         scroll_y: 0
@@ -201,15 +202,15 @@
             multiline: True
             hint_text: _(u"Enter your message here")
             on_text_validate: root.onSend(args[0])
-
+        SymbolButton:
+            # "send" button, permanent visibility depends on platform
+            symbol: "forward"
+            size_hint: None, 1
+            width: dp(30) if root.send_button_visible else 0
+            opacity: 1 if root.send_button_visible else 0
+            font_size: dp(25)
+            on_release: self.parent.send_text()
 
-<SendButton>:
-    # SendButton is only shown on touch devices
-    symbol: "forward"
-    size_hint: None, 1
-    width: dp(30)
-    font_size: dp(25)
-    on_release: self.message_input_box.send_text()
 
 # Buttons added in header
 
--- a/cagou/plugins/plugin_wid_chat.py	Sun Feb 23 15:39:03 2020 +0100
+++ b/cagou/plugins/plugin_wid_chat.py	Sun Feb 23 15:39:06 2020 +0100
@@ -210,21 +210,9 @@
             layout.add_widget(item)
 
 
-class SendButton(SymbolButton):
-    message_input_box = properties.ObjectProperty()
-
-
 class MessageInputBox(BoxLayout):
     message_input = properties.ObjectProperty()
 
-    def __init__(self, *args, **kwargs):
-        super(MessageInputBox, self).__init__(*args, **kwargs)
-        Clock.schedule_once(self.post_init, 0)
-
-    def post_init(self, *args):
-        if sys.platform == 'android':
-            self.add_widget(SendButton(message_input_box=self), 0)
-
     def send_text(self):
         self.message_input.send_text()
 
@@ -459,6 +447,7 @@
     messages_widget = properties.ObjectProperty()
     history_scroll = properties.ObjectProperty()
     attachments_to_send = properties.ObjectProperty()
+    send_button_visible = properties.BooleanProperty()
     use_header_input = True
     global_screen_manager = True
     collection_carousel = True