Instantly share code, notes, and snippets.

@cruor99 cruor99/main.py
Created Aug 27, 2018

Embed
What would you like to do?
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty, BooleanProperty
from kivy.logger import Logger
from kivy.clock import Clock
from kivy.utils import platform
from kivy.logger import Logger
# KivyMD stuff
from kivymd.theming import ThemeManager
from kivymd.snackbar import Snackbar
# Services
from services.login import LoginProvider
# Components
from components.navdrawer import OrganizerNavdrawer
# iOS imports
if platform == "ios":
from pyobjus import autoclass, objc_dict
class OrganizerRoot(BoxLayout):
login_provider = ObjectProperty(LoginProvider())
logged_in = BooleanProperty(True)
onesignal_object = ObjectProperty()
Crashlytics = ObjectProperty()
Fabric = ObjectProperty()
def __init__(self, **kwargs):
super(OrganizerRoot, self).__init__(**kwargs)
# List of screens for back button
self.screen_list = []
Clock.schedule_once(self.finish_init)
if platform == "ios":
Clock.schedule_once(self.finish_ios_init)
elif platform == "android":
Clock.schedule_once(self.finish_android_init)
def finish_ios_init(self, *args):
self.Crashlytics = autoclass("Crashlytics")
self.Fabric = autoclass("Fabric").with_([self.Crashlytics])
self.onesignal_object = autoclass("OneSignal")
mock_launch_options = objc_dict({})
self.onesignal_object.initWithLaunchOptions_appId_(mock_launch_options, "onesignal-appid-goes-here")
def finish_android_init(self, *args):
pass
def finish_init(self, *args):
from screens.login_screen import LoginScreen
self.ids.main_screen_manager.add_widget(LoginScreen(name="login_screen", id="login_screen"))
from screens.dash_screen import DashScreen
self.ids.main_screen_manager.add_widget(DashScreen(name="dash_screen", id="dash_screen"))
def next_page(self, neoscreen):
current_screen = self.ids.main_screen_manager.current
if current_screen == neoscreen:
Logger.debug("Duplicate screen attempted: {}".format(current_screen))
else:
Logger.debug("New screen: {}".format(neoscreen))
self.screen_list.append(current_screen)
self.ids.main_screen_manager.current = neoscreen
def login_user(self, username, password):
self.login_provider.login(username=username, password=password, callbacks={
"success": self.login_success,
"failure": self.login_failed,
"error": self.login_failed,
})
def login_success(self, req, res):
Logger.info("Login Success: {}".format(res))
Snackbar(text="Login Successful").show()
self.onesignal_object.setEmail_(res["user"]["email"])
def login_failed(self, req, res):
Logger.info("Login failed: {}".format(res))
Logger.info("Login status: {}".format(req.resp_status))
Snackbar(text="Login feilet: {}:{}".format(req.resp_status, res)).show()
class OrganizerApp(App):
theme_cls = ThemeManager()
def build(self):
self.theme_cls.theme_style = "Light"
self.theme_cls.primary_palette = "Indigo"
self.theme_cls.primary_hue = "500"
return OrganizerRoot()
if __name__ == "__main__":
OrganizerApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment