from kivy.uix.screenmanager import Screen
from kivy.uix.gridlayout import GridLayout
from kivy.factory import Factory
from kivy.lang import Builder
from functools import partial


class ScreenCommunity(Screen):
    Builder.load_string('''
<ScreenCommunity>
    name: 'ScreenCommunity'
    ScrollView
        ScrollGrid
            id: container
            AsyncImage
                source: "atlas://data/default/community"
                size_hint_y: None
                allow_stretch: True
                height: dp(120)
            BackLabel
                id: bcklbl

        ''')

    def on_enter(self, onsuccess=False):
        from network import get_data
        community = get_data('community', onsuccess=onsuccess)

        if not community:
            return

        community = community.get('0.0.1')[0]

        self.ids.bcklbl.text = community['about']

        social_comm = community['social']
        social_len = len(social_comm)

        gl = GridLayout(cols=social_len,
                    size_hint_y=None,
                    padding='2dp',
                    spacing='2dp')
        import webbrowser
        for social_acc, social_link in social_comm.items():
            imbt = Factory.ImBut()
            imbt.source = 'atlas://data/default/' + social_acc.lower()
            imbt.on_released = partial(webbrowser.open, social_link)
            gl.add_widget(imbt)

        self.ids.container.add_widget(gl)
@@ -316,34 +316,8 @@
 rid%0A
-            id: container%0A
     
@@ -355,48 +355,16 @@
     
-source: %22atlas://data/default/community%22
+id: aimg
 %0A   
@@ -511,17 +511,212 @@
  bcklbl%0A
+            GridLayout%0A                id: container%0A                row: 2%0A                cols: 4%0A                size_hint_y: None%0A                padding: '9dp'%0A                spacing: '9dp'
 %0A
-
         
@@ -1005,16 +1005,66 @@
 'about'%5D
+%0A        self.ids.aimg.source = community%5B'photo'%5D
 %0A%0A      
@@ -1155,142 +1155,52 @@
 l = 
-GridLayout(cols=social_len,%0A                    size_hint_y=None,%0A                    padding='2dp',%0A                    spacing='2dp'
+self.ids.container%0A        gl.clear_widgets(
 )%0A  
@@ -1458,16 +1458,16 @@
 l_link)%0A
+
         
@@ -1493,47 +1493,4 @@
 mbt)
-%0A%0A        self.ids.container.add_widget(gl)

Fix issue #38