From 130c63f226b6f9f0ab0cefab142a3b07126b8977 Mon Sep 17 00:00:00 2001 From: navjot Date: Tue, 21 Apr 2020 23:03:38 +0530 Subject: [PATCH] impleneted chatroom UI --- src/bitmessagekivy/kv/chat_list.kv | 52 +++++++++++++++++++++ src/bitmessagekivy/kv/chat_room.kv | 40 ++++++++++++++++ src/bitmessagekivy/main.kv | 11 +++++ src/bitmessagekivy/mpybit.py | 74 +++++++++++++++++++++++++++++- 4 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 src/bitmessagekivy/kv/chat_list.kv create mode 100644 src/bitmessagekivy/kv/chat_room.kv diff --git a/src/bitmessagekivy/kv/chat_list.kv b/src/bitmessagekivy/kv/chat_list.kv new file mode 100644 index 00000000..b982b2e4 --- /dev/null +++ b/src/bitmessagekivy/kv/chat_list.kv @@ -0,0 +1,52 @@ +: + name: 'chlist' + MDTabs: + id: chat_panel + tab_display_mode:'text' + + Tab: + text: "Chats" + BoxLayout: + id: chat_box + orientation: 'vertical' + ScrollView: + id: scroll_y + do_scroll_x: False + MDList: + id: ml + MDLabel: + font_style: 'Caption' + theme_text_color: 'Primary' + text: 'No Chat' + halign: 'center' + size_hint_y: None + bold: True + valign: 'top' + # OneLineAvatarListItem: + # text: "Single-line item with avatar" + # divider: None + # _no_ripple_effect: True + # ImageLeftWidget: + # source: './images/text_images/A.png' + # OneLineAvatarListItem: + # text: "Single-line item with avatar" + # divider: None + # _no_ripple_effect: True + # ImageLeftWidget: + # source: './images/text_images/B.png' + # OneLineAvatarListItem: + # text: "Single-line item with avatar" + # divider: None + # _no_ripple_effect: True + # ImageLeftWidget: + # source: './images/text_images/A.png' + Tab: + text: "Contacts" + BoxLayout: + id: contact_box + orientation: 'vertical' + ScrollView: + id: scroll_y + do_scroll_x: False + MDList: + id: ml diff --git a/src/bitmessagekivy/kv/chat_room.kv b/src/bitmessagekivy/kv/chat_room.kv new file mode 100644 index 00000000..a1413ae8 --- /dev/null +++ b/src/bitmessagekivy/kv/chat_room.kv @@ -0,0 +1,40 @@ +#:import C kivy.utils.get_color_from_hex + +: + name: 'chroom' + BoxLayout: + orientation: 'vertical' + + ScrollView: + Label: + id: chat_logs + text: '' + color: C('#101010') + text_size: (self.width, None) + halign: 'left' + valign: 'top' + padding: (0, 0) # fixed in Kivy 1.8.1 + size_hint: (1, None) + height: self.texture_size[1] + markup: True + font_size: sp(20) + BoxLayout: + height: 50 + orientation: 'horizontal' + padding: 0 + size_hint: (1, None) + + TextInput: + id: message + size_hint: (1, 1) + multiline: False + font_size: sp(20) + on_text_validate: root.send_msg() + + MDRaisedButton: + text: "Send" + elevation_normal: 2 + opposite_colors: True + size_hint: (0.3, 1) + pos_hint: {"center_x": .5} + on_press: root.send_msg() diff --git a/src/bitmessagekivy/main.kv b/src/bitmessagekivy/main.kv index 029516fd..9d113ba2 100644 --- a/src/bitmessagekivy/main.kv +++ b/src/bitmessagekivy/main.kv @@ -155,6 +155,13 @@ on_release: app.root.ids.scr_mngr.current = 'allmails' on_release: root.parent.set_state() on_press: app.load_screen(self) + NavigationItem: + id: chat_rm + text: 'Chat Room' + icon: 'wechat' + divider: None + on_release: app.root.ids.scr_mngr.current = 'chlist' + on_release: root.parent.set_state() NavigationDrawerDivider: NavigationDrawerSubheader: text: "All labels" @@ -260,6 +267,10 @@ NavigationLayout: id:sc19 Archieve: id:sc20 + ChatRoom: + id:sc21 + ChatList: + id:sc22 MDNavigationDrawer: id: nav_drawer diff --git a/src/bitmessagekivy/mpybit.py b/src/bitmessagekivy/mpybit.py index b462f85d..8cc6876e 100644 --- a/src/bitmessagekivy/mpybit.py +++ b/src/bitmessagekivy/mpybit.py @@ -73,7 +73,8 @@ KVFILES = [ 'settings', 'popup', 'allmails', 'draft', 'maildetail', 'common_widgets', 'addressbook', 'myaddress', 'composer', 'payment', 'sent', - 'network', 'login', 'credits', 'trash', 'inbox' + 'network', 'login', 'credits', 'trash', 'inbox', + 'chat_room', 'chat_list' ] @@ -3018,3 +3019,74 @@ class ToAddrBoxlayout(BoxLayout): class RandomBoxlayout(BoxLayout): """class for BoxLayout behaviour""" pass + + +def esc_markup(msg): + return (msg.replace('&', '&') + .replace('[', '&bl;') + .replace(']', '&br;')) + + +class ChatRoom(Screen): + """class for chatroom screen""" + def send_msg(self): + """This method is for sending message""" + msg = self.ids.message.text + if msg: + self.ids.chat_logs.text += ( + '[b][color=2980b9]{}:[/color][/b] {}\n' + .format('Me', esc_markup(msg))) + # obj = MDChip(label=msg, radius=7) + # obj.icon = '' + # self.ids.ml.add_widget(obj) + self.ids.message.text = '' + + +class ChatList(Screen): + """class for showing chat list""" + queryreturn = ListProperty() + has_refreshed = True + + def __init__(self, *args, **kwargs): + """Getting ChatList Details""" + super(ChatList, self).__init__(*args, **kwargs) + Clock.schedule_once(self.init_ui, 0) + + def init_ui(self, dt=0): + """Clock Schdule for method ChatList""" + self.loadAddresslist(None, 'All', '') + print(dt) + + def loadAddresslist(self, account="", where="", what=""): + """Clock Schdule for method ChatList""" + self.queryreturn = kivy_helper_search.search_sql( + '', account, "addressbook", where, what, False) + self.queryreturn = [obj for obj in reversed(self.queryreturn)] + if self.queryreturn: + self.set_mdList() + else: + content = MDLabel( + font_style='Caption', + theme_text_color='Primary', + text="No contact found!", + halign='center', + size_hint_y=None, + valign='top') + self.ids.ml.add_widget(content) + + def set_mdList(self): + """Creating the mdList""" + for item in self.queryreturn: + meny = TwoLineAvatarIconListItem( + text=item[0], secondary_text=item[1], theme_text_color='Custom', + text_color=NavigateApp().theme_cls.primary_color) + meny.add_widget(AvatarSampleWidget( + source='./images/text_images/{}.png'.format( + avatarImageFirstLetter(item[0].strip())))) + # meny.bind(on_press=self.redirect_on_chat()) + meny.bind(on_press=partial( + self.redirect_on_chat,)) + self.ids.ml.add_widget(meny) + + def redirect_on_chat(self, *args): + self.manager.current = 'chroom'