Пример #1
0
 def _toggle_notify(self, *largs):
     self.notify = not self.notify
     from modules.core.android_utils import Toast
     if self.notify:
         Toast('notifications enabled')
     else:
         Toast('notifications disabled')
Пример #2
0
 def _toggle_favorite(self):
     from modules.core.android_utils import Toast
     if self.favorite:
         remove_post_from_favs(self.item_key)
         remove_post_from_fav_data(self.item_key)
         Toast('removed from favorites')
     else:
         add_post_to_favs(self.item_key)
         Toast('added to favorites')
Пример #3
0
    def on_start(self):
        # on ios we have to change the status bar color right when we are up.
        if platform == 'ios':
            from pyobjus import autoclass, objc_str
            ObjcClass = autoclass('ObjcClassINSD')
            o_instance = ObjcClass.alloc().init()
            o_instance.lightStatusBar()
        print('App started')
        from modules.core.android_utils import RemoveTutorialScreen
        RemoveTutorialScreen()
        from modules.core.android_utils import Toast
        Toast('logging in...', True)
        from utilities.notification import stopNotificationService, getLastNotificationMessage
        stopNotificationService()
        # make sure that if we started from a notification we act accordingly.
        keys = getLastNotificationMessage()
        if keys:
            from kivy.clock import Clock

            def switchscreens(*largs):
                from api.streams.posts import Manager as PostsManager
                if not PostsManager.logged_in:
                    Clock.schedule_once(switchscreens, 0.125)
                    return
                if len(keys) == 1:
                    s = self.root.manager.get_screen('favs')
                    s.fake_click_for_item = keys[0]
                self.root.manager.current = 'favs'

            Clock.schedule_once(switchscreens, 0.125)
Пример #4
0
 def on_submit(self):
     text = self.textinput.text.strip()
     if text:
         from modules.core.android_utils import Toast
         Toast('feedback sent')
         post_feedback(content=text)
     self.dispatch('on_close')
Пример #5
0
 def button_clicked(self, item):
     super(OptionsMenu, self).button_clicked(item)
     action = item.action
     LogTestFairy('Post option menu pressed %s' % action)
     if action == 'share':
         self.dispatch('on_share', self.item)
     elif action == 'favorite':
         self._toggle_favorite()
     elif action == 'remove':
         from modules.core.android_utils import Toast
         Toast('post removed')
         if self.item_key:
             self.dispatch('on_removed', self.item_key)
     elif action == 'flag':
         from modules.core.android_utils import Toast
         Toast('post flagged')
         if self.item_key:
             post_flag(self.item_key)
             self.dispatch('on_removed', self.item_key)
Пример #6
0
def _on_error_reconnect(failure, reconnect_func):
    from twisted.python.failure import Failure
    if isinstance(failure, Failure):

        def reconnect(dt):
            reconnect_func()

        Toast('network error')
        Clock.schedule_once(reconnect, network_reconnect_timeout)
        return True
Пример #7
0
 def on_error(failure, code=None):
     print 'print _do_register %s ' % str(failure)
     if not _on_error_reconnect(failure,
                                reconnect_func=partial(_do_register,
                                                       pub_key=pub_key,
                                                       on_login=on_login)):
         if code == 400:
             # duplicate keys, clear them and try again
             print '_do_register force keys regeneration'
             clear_keys()
             _register(on_login=on_login)
         else:
             Toast('registration failed')
Пример #8
0
def _gen_RSA_and_register(on_login):
    from modules.core.android_utils import Toast
    Toast('creating new anonymous profile')

    def _continue_login(pair, dt):
        update_keys(pair)
        _do_register(pair[1], on_login=on_login)

    def _done_pair(pair):
        from kivy.clock import Clock
        from functools import partial
        Clock.schedule_once(partial(_continue_login, pair), 0.025)

    # notice we are crating the thread here, but the callback will be run from UI context
    start_new_thread(_generate_RSA, (_done_pair, ))
Пример #9
0
def _login(uid, on_login=None, toast=False):
    def on_token(new_token):
        print('register: received token %s' % new_token)

    def on_error(failure, code=None):
        if not _on_error_reconnect(
                failure,
                reconnect_func=partial(
                    _login, uid=uid, on_login=on_login, toast=True)):
            # duplicate keys, clear them and try again
            print '_login force uid regeneration'
            clear_uid()
            _register(on_login=on_login)
            # Toast('login unauthorized')

    if toast:
        Toast('logging in...')

    api.auth.login(user_id=uid,
                   on_token=(on_login or on_token),
                   on_error=on_error)
Пример #10
0
    def on_post(self):
        from modules.core.android_utils import Toast
        Toast('posting...')
        LogTestFairy('Post published')
        self.posted = True

        text = self.post_textinput.text.strip()
        if not text:
            return

        # so we don't double post
        self.post_textinput.text = ''

        if not PostsManager.streams:
            Logger.info('on_post: no channel to post to!')
            return
        chan_key = PostsManager.streams[0].key
        if self.post_color:
            background = 'color:%s' % self.post_color
        else:
            background = self.post_image_key

        def dispatch_created(key, **kwargs):
            Toast('posted successfully')
            self.dispatch('on_post_created', key)

        def dispatch_error(reason, *largs):
            Toast('posting failed')
            self.dispatch('on_post_failed', reason)

        post(content=text[:comment_length_limit],
             role="none",
             role_text="",
             theme=self.current_theme,
             background=background,
             channels=[chan_key],
             on_created=dispatch_created,
             on_error=dispatch_error)
Пример #11
0
 def on_network_error(*largs):
     print 'Network Error %s' % str(*largs)
     Logger.info('item_vote: failed voting (network error)')
     Toast('Voting failed (no network access)')
Пример #12
0
 def dispatch_created(key, **kwargs):
     Toast('posted successfully')
     self.dispatch('on_post_created', key)
Пример #13
0
 def dispatch_error(reason, *largs):
     Toast('posting failed')
     self.dispatch('on_post_failed', reason)
Пример #14
0
 def _on_no_favorites(self, *args):
     self.status = 'empty'
     from modules.core.android_utils import Toast
     Toast('favorites timeout')
Пример #15
0
 def updated(*largs):
     from modules.core.android_utils import Toast
     Toast('Linkedin profile updated')
Пример #16
0
 def feed_network_error_message(*args):
     from modules.core.android_utils import Toast
     Toast('no network access')
Пример #17
0
 def _on_error(self, linkedin, reason=None):
     from modules.core.android_utils import Toast
     Toast('Linkedin login failed')
     self.allow_dismiss = True
     self.dispatch('on_close', False)
Пример #18
0
 def _on_complete(self, linkedin):
     from modules.core.android_utils import Toast
     Toast('Successfull Linkedin login')
     self.allow_dismiss = True
     self.dispatch('on_close', True)