예제 #1
0
 def build(self):
     self.ads = KivMob(APP_ID)
     self.ads.add_test_device(TEST_DEVICE_ID)
     self.ads.new_banner({"unitID": BANNER_ID})
     self.ads.new_interstitial(INTERSTITIAL_ID)
     self.ads.request_banner()
     self.ads.request_interstitial()
     self.toggled = False
     return KivMobDemoUI()
예제 #2
0
class ScatterTextWidget(BoxLayout):
    APPID = 'ca-app-pub-4594686446272625~3110544260'
    BANNERID = 'ca-app-pub-4594686446272625/3787177591'
    ads = KivMob(APPID)
    ads.new_banner(BANNERID)
    ads.request_banner()
    ads.show_banner()

    pass
예제 #3
0
 def build(self):
     self.ads = KivMob(TestIds.APP)
     self.ads.new_banner(TestIds.BANNER, False)
     self.ads.new_interstitial(TestIds.INTERSTITIAL)
     self.ads.request_banner()
     self.ads.request_interstitial()
     self.ads.set_rewarded_ad_listener(self.rewards)
     self.ads.load_rewarded_ad(TestIds.REWARDED_VIDEO)
     self.toggled = False
     return KivMobDemoUI()
예제 #4
0
 def __init__(self, **kwargs):
     super(MyApp, self).__init__(**kwargs)
     app_id = TestIds.APP
     self.ads = KivMob(app_id)
     banner_id = TestIds.BANNER
     interstitial_id = TestIds.INTERSTITIAL
     self.ads.new_banner(banner_id, top_pos=True)
     self.ads.new_interstitial(interstitial_id)
     self.show_ads()
     self.ads_created = True
     self.manga_text_color = (0, 0, 0, 1)
     self.start_up = True  # Use in theme_color
예제 #5
0
파일: main.py 프로젝트: will702/projek1
    def build(self):

        self.config = Config()

        self.ads = KivMob('ca-app-pub-1818238534900904~2025018602')
        self.ads.new_banner('ca-app-pub-1818238534900904/4048546717',
                            top_pos=False)
        self.ads.request_banner()
        self.ads.show_banner()

        self.screen = Builder.load_file(self.config.screen)

        return self.screen
예제 #6
0
class Screen2(MDScreen):
    ads = KivMob('ca-app-pub-1818238534900904~2025018602')# ADS ID 


    ads.new_interstitial('ca-app-pub-1818238534900904/8138357580')#ADS UNIT ID
    ads.add_test_device('7569F1B8DC0951A')#Test Device ID 
    ads.request_interstitial()


    def resume(self):
        self.ads.request_interstitial()

    def show_ads(self):
        self.ads.show_interstitial()
예제 #7
0
파일: main.py 프로젝트: rifa88/androidapp
class SimpleApp(MDApp):
    def __init__(self, **kwargs):
        self.theme_cls.theme_style = "Dark"
        super().__init__(**kwargs)
        self.rewards = Rewards_Handler(self)

    ads = KivMob(
        TestIds.APP)  # put your Admob Id in case you want to put your own ads.
    points = NumericProperty(0)

    def build(self):
        self.ads.new_banner(TestIds.BANNER, False)
        self.ads.request_banner()
        self.ads.show_banner()
        self.ads.new_interstitial(TestIds.INTERSTITIAL)
        self.ads.load_rewarded_ad(TestIds.REWARDED_VIDEO)
        self.ads.set_rewarded_ad_listener(self.rewards)

        return Screenmgr()

    def load_video(self):
        self.ads.load_rewarded_ad(TestIds.REWARDED_VIDEO)
예제 #8
0
    def build(self):
        self.theme_cls.theme_style = 'Dark'

        self.sm = Builder.load_file('main.kv')

        # ads
        self.ads = KivMob(os.environ.get('APP_ID'))
        self.ads.add_test_device('70356742')
        self.ads.new_banner(os.environ.get('BANNER_ID'), top_pos=False)
        self.ads.request_banner()
        self.ads.new_interstitial(os.environ.get('INTERSTITIAL_ID'))
        self.ads.request_interstitial()

        # dialog window to show when starting new game if active game exists
        self.dialog = Dialog(
            title='Створити нову гру?',
            text='Дані про поточну гру буде втрачено.',
            buttons=[
                TextButton(text="Назад",
                           on_release=lambda _: self.dialog.dismiss()),
                TextButton(
                    text="Так",
                    on_release=lambda _: self.drop_game_and_create_new())
            ],
        )

        Cache.append('images', 'round_background',
                     FitImage(source="assets/imgs/round.png"))

        # enable buttons only in 2 second after build to avoid bugs
        def show_menu_buttons():
            self.buttons_ready_to_use = True

        Clock.schedule_once(lambda _: show_menu_buttons(), 2)

        return self.sm
예제 #9
0
파일: main.py 프로젝트: aqulline/Yummy
class MainApp(MDApp):
    # APP
    storage_url = "https://farmzon-abdcb.appspot.com"
    database_url = "https://farmzon-abdcb.firebaseio.com/.json"
    data = {"uu": {"Joe Tilsed": "me"}}
    auth_key = "sBlt6fzvguYnrGl2FlXRK3k4vRxSfZJBV2P7yIRv"
    size_x = NumericProperty(0)
    size_y = NumericProperty(0)
    menu = ObjectProperty(None)
    count = NumericProperty(0)
    loggin_count = NumericProperty(0)
    count_update = NumericProperty(0)
    dialog = None
    dialog_phone = None
    dialog_last = None
    setter = None
    counter_image = NumericProperty(0)
    spin_active = BooleanProperty(False)
    menu_text = StringProperty("Your Location")
    loading = StringProperty("")

    # Business
    product_name = StringProperty("")
    phone_number = StringProperty("")
    location = StringProperty("")
    quantity = StringProperty("")
    total_amount = NumericProperty(0)
    order_number = StringProperty("0")
    category_tp = StringProperty("")

    # MATH
    calculator = StringProperty("0")
    calculator2 = StringProperty("0")

    # XXX-------ADMIN LOGIN VAR-------XXX
    admin_name = StringProperty("")
    admin_phone = StringProperty("")
    customer_phone = StringProperty("")
    admin_password = StringProperty("")
    admin_true = BooleanProperty(False)
    admin_product_description = StringProperty("")
    admin_product_image = StringProperty("images/picture.png")
    admin_product_name = StringProperty("")
    admin_product_price = StringProperty("")
    admin_product_id = StringProperty("")
    admin_product_url = StringProperty("")

    # ADS
    app_id = "ca-app-pub-9270156272717443~8633598837"
    interstitial = "ca-app-pub-9270156272717443/2248347409"

    # DATABASE

    def stream_handler(self, message):
        if True:
            print("hello")
            return notification.notify(title='New order', message='you have new order!')

    def notifi(self, phone):
        try:
            import firebase_admin
            firebase_admin._apps.clear()
            from firebase_admin import credentials, initialize_app, db
            id = datetime.datetime.now()
            cred = credentials.Certificate("credential/farmzon-abdcb-c4c57249e43b.json")
            initialize_app(cred, {'databaseURL': 'https://farmzon-abdcb.firebaseio.com/'})
            if phone != "0788204327":
                my_stream = db.reference("Yummy").child("Admin").child(phone).child("Orders").listen(
                    self.stream_handler)
            else:
                my_stream = db.reference("Yummy").child("Orders").listen(
                    self.stream_handler)
        except:
            print("poor me")

    def remember_me_admin(self, user, password, name):
        with open("credential/admin.txt", "w") as fl:
            fl.write(user + "\n")
            fl.write(password)
        with open("credential/admin_info.txt", "w") as ui:
            ui.write(name)
        fl.close()
        ui.close()

    def admin_memory(self):
        if self.loggin_count == 0:
            self.loggin_count = 1 + self.loggin_count
            self.admin_true = True
            file1 = open('credential/admin.txt', 'r')
            file2 = open("credential/admin_info.txt")
            Lines = file1.readlines()
            Lines2 = file2.readlines()

            # Strips the newline character
            self.admin_phone = Lines[0].strip()
            self.admin_password = Lines[1].strip()
            self.admin_name = Lines2[0]
            self.count += 1
            thread = threading.Thread(self.notifi(self.admin_phone))
            thread = threading.Thread(self.listen_db(self.admin_phone))
            thread.start()
        else:
            sm = self.root
            sm.current = "admin_main"
            self.spin_active = False

    def actively_reg(self):
        if self.spin_active:
            self.spin_active = False
            toast("Successfully Registered!")

    def permision_req(self):
        if utils.platform == 'android':
            from android.permissions import request_permissions, Permission  # todo
            request_permissions([Permission.WRITE_EXTERNAL_STORAGE, Permission.READ_EXTERNAL_STORAGE])

    def notifier(self):
        notification.notify(title="Welcome", message="you can also sell and buy!")

    def on_start(self):
        m = self.root
        m.current = "one"
        identity = self.root.ids.drop_item_one
        self.menu_fun(identity)
        self.keyboard_hooker()

    def menu_fun(self, identity):
        vimbweta = [
            "vimbweta vya uwanjani",
            "vimbweta vya stationary",
            "vimbweta vya girls hostel",
            "vimbweta vya boys hostel",
            "vimbweta nyuma ya ndege",
            "vimbweta vya block 16",
            "vimbweta vya adminstration",
            "class one",
            "class two",
            "class three",
            "Aviation classes"
        ]
        self.menu = MDDropdownMenu(
            caller=identity,
            width_mult=9,
            position="auto",
            callback=self.menu_callback
        )
        for i in range(vimbweta.__len__()):
            self.menu.items.append(
                {
                    "text": vimbweta[i]
                }
            )
        for i in range(22):
            if i == 0:
                pass
            else:
                self.menu.items.append(
                    {
                        "text": "Block " + "" + str(i)
                    }
                )
        self.menu.bind(
            on_release=self.menu_callback
        )

        self.setter = identity
        self.setter.set_item(self.menu_text)

    def show_alert_dialog(self):
        if not self.dialog:
            self.dialog = MDDialog(
                title="Do you real want to quit?",
                buttons=[
                    MDFlatButton(
                        text="CANCEL", text_color=self.theme_cls.primary_color, on_release=self.kill
                    ),
                    MDRaisedButton(
                        text="QUIT!", text_color=self.theme_cls.primary_color,
                        on_release=lambda x: toast("Please press the home button!", 5)
                    ),
                ],
            )
        self.dialog.open()

    def phone_number_dialog(self):
        if not self.dialog_phone:
            self.dialog_phone = phone_dialog(
                title="Enter Your phone number",
                auto_dismiss=False,
                buttons=[
                    MDFlatButton(
                        text="Cancel", text_color=self.theme_cls.primary_color, on_release=self.kill_phone
                    ),
                    MDRaisedButton(
                        text="Submit", text_color=self.theme_cls.primary_color,
                        on_release=lambda x: self.phone_number_check(self.phone_number)
                    ),
                ],
            )
        self.dialog_phone.open()

    def last_step_dialog(self):
        if not self.dialog_last:
            self.dialog_last = MDDialog(
                title="Confirm",
                type="custom",
                auto_dismiss=False,
                content_cls=last_dialog(),
                buttons=[
                    MDFlatButton(
                        text="Cancel",
                        text_color=self.theme_cls.primary_color,
                        on_release=lambda x: self.adver()
                    ),
                    MDRaisedButton(
                        text="Ok",
                        on_release=lambda x: self.adver(),
                        theme_text_color="Custom",
                        md_bg_color=[243 / 255, 189 / 255, 106 / 255, 1]
                    ),

                ],
            )
        self.dialog_last.md_bg_color = 245 / 255, 0 / 255, 72 / 255, 1
        self.dialog_last.open()

    def phone_number_check(self, phone):
        new_number = ""
        if phone != "":
            for i in range(phone.__len__()):
                if i == 0:
                    pass
                else:
                    new_number = new_number + phone[i]
            number = "+255" + new_number
            if not carrier._is_mobile(number_type(phonenumbers.parse(number))):
                toast("Please check your phone number!", 1)
                return False
            else:
                self.phone_number = phone
                thread = threading.Thread(target=self.Business(self.product_name, self.quantity, self.phone_number))
                thread.start()
                self.kill_phone()
                return True
        else:
            toast("check your number")

    def phone_number_check_admin(self, phone):
        new_number = ""
        if phone != "":
            for i in range(phone.__len__()):
                if i == 0:
                    pass
                else:
                    new_number = new_number + phone[i]
            number = "+255" + new_number
            if not carrier._is_mobile(number_type(phonenumbers.parse(number))):
                toast("Please check your phone number!", 1)
                return False
            else:
                return True
        else:
            toast("enter phone number!")

    def kill(self, *kwargs):
        self.dialog.dismiss()

    def kill_phone(self, *kwargs):
        self.ads.request_interstitial()
        self.dialog_phone.dismiss()
        self.ads.show_interstitial()

    def kill_adver(self):
        self.dialog_last.dismiss()

    def Business(self, product, quantity, phone):
        self.last_step_dialog()
        print("location:", self.location, '\n'
                                          "Product name:", product, '\n'
                                                                    "quantity:", quantity, '\n'
                                                                                           "Total amount:",
              self.total_amount, '\n'
                                 "Phone number:", phone)
        if self.category_tp != "admin":
            from helped import connection_status as CS
            if CS.Network.internet(CS.Network()):
                self.spin_active = True
                thread = threading.Thread(target=DB.upload_data,
                                          args=(
                                              DB(), self.customer_phone, phone, self.location, quantity,
                                              self.total_amount,
                                              product))
                thread.start()
                thread.join()
                toast("Ordered successfully!", 10)
                self.spin_active = False
            else:
                self.spin_active = False
                toast("Sorry try again!", 5)
        else:
            from helped import connection_status as CS
            if CS.Network.internet(CS.Network()):
                self.spin_active = True
                thread = threading.Thread(target=DB.upload_data_admin,
                                          args=(
                                              DB(), self.customer_phone, phone, self.location, quantity,
                                              self.total_amount,
                                              product))
                thread.start()
                thread.join()
                toast("Ordered successfully!", 10)
                self.spin_active = False
            else:
                self.spin_active = False
                toast("Sorry try again!", 5)

    def keyboard_hooker(self):
        EventLoop.window.bind(on_keyboard=self.hook_keyboard)

    def hook_keyboard(self, window, key, *largs):
        sm = self.root
        print(key, self.count)
        if key == 27 and self.count == 1 or self.count <= -1:
            sm.current = "one"
            print("change", self.count)
            self.count = self.count - 1
            print("current>>", self.count)
            return True
        elif key == 27 and self.count == 0:
            # Window.on_close()
            self.show_alert_dialog()
            return True

    def menu_callback(self, menu):
        self.menu_text = menu.text
        self.setter.set_item(menu.text)
        self.menu.dismiss()
        print(menu.text)
        self.location = menu.text

    def callculator_rim(self, mingapi, price):
        identity = self.root.ids.quantity
        self.calculator = mingapi + "0"
        if mingapi == "":
            pass
        elif mingapi == '.':
            identity.text = "1"
        else:
            self.total_amount = self.calculator = str(float(mingapi) * int(price))

    def callback(self, button):
        self.menu.caller = button
        self.menu.open()

    food_count = 0

    def order_spinner2(self):
        if self.front_shop_count == 0:
            self.spin_active = True
            try:
                toast("loading please wait...", 10)
                self.loading = "Loading..."
                # Clock.schedule_once(lambda x: self.front_shop(), 4)
                thread = threading.Thread(target=self.front_shop())
                thread.start()
            except:
                toast("no internet!")
                self.loading = ""
                self.spin_active = False

    def order_spinner3(self):
        if self.other_shops == 0:
            self.spin_active = True
            try:
                toast("loading please wait...", 10)
                Clock.schedule_once(lambda x: self.other_shop(), 4)
                # thread = threading.Thread(target=self.other_shop)
                # thread.start()
            except:
                toast("no internet!")
                self.spin_active = False

    def order_spinner1(self):
        sm = self.root
        file_size = os.path.getsize("credential/admin.txt")
        if file_size == 0:
            sm.current = "login"
        else:
            self.spin_active = True
            sm.current = "admin_main"
            thread = threading.Thread(target=self.admin_memory)
            thread.start()
            thread.join()
            self.spin_active = False

    def add_order(self):
        try:
            if self.food_count == 0:
                self.food_count = self.food_count + 1
                food = self.root.ids.food_cat
                import firebase_admin
                firebase_admin._apps.clear()
                from firebase_admin import credentials, initialize_app, db
                if not firebase_admin._apps:
                    cred = credentials.Certificate("credential/farmzon-abdcb-c4c57249e43b.json")
                    initialize_app(cred, {'databaseURL': 'https://farmzon-abdcb.firebaseio.com/'})

                    store = db.reference("Yummy").child("Orders")
                    stores = store.get()

                    count = 0
                    for y, x in stores.items():
                        food_categories = category()
                        del_btn = MDIconButton(icon="delete", on_release=self.remove_widgets,
                                               pos_hint={"center_x": .9, "center_y": .3}, theme_text_color="Custom",
                                               text_color={60 / 255, 66 / 255, 75 / 255}, user_font_size="26sp")
                        count += 1
                        # food_categories.md_bg_color = 245 / 255, 0 / 255, 72 / 255, 1
                        food_categories.id = y
                        del_btn.id = y
                        food_categories.md_bg_color = 121 / 255, 174 / 255, 141 / 255, 1
                        food_categories.add_widget(Labels(text="Admin-phone:" + " " + str(x['Admin phone'])))
                        food_categories.add_widget(Labels(text="Phone:" + " " + y))
                        food_categories.add_widget(MDSeparator(height="5dp"))
                        food_categories.add_widget(Labels(text="Amount:" + " " + " " + str(x['amount'])))
                        food_categories.add_widget(Labels(text="Location:" + " " + " " + str(x['location'])))
                        food_categories.add_widget(Labels(text="Product-Name:" + " " + " " + str(x['product name'])))
                        food_categories.add_widget(Labels(text="Quantity:" + " " + " " + str(x['quantity'])))
                        food_categories.add_widget(Labels(text="Time-Ordered:" + " " + " " + str(x['time'])))
                        food_categories.add_widget(del_btn)
                        food.add_widget(food_categories)
                    self.spin_active = False
                    self.order_number = str(count)

            else:
                pass
        except:
            toast("no internet")
            self.spin_active = False

    def resize_bottom_tabs(self):
        # bottom_nav
        bv = self.root.ids.bottom_nav
        bv.on_resize()

    def add_order_admin(self):
        try:
            if self.food_count == 0:
                print("num>", self.admin_phone)
                self.food_count = self.food_count + 1
                food = self.root.ids.food_cat
                import firebase_admin
                firebase_admin._apps.clear()
                from firebase_admin import credentials, initialize_app, db
                if not firebase_admin._apps:
                    cred = credentials.Certificate("credential/farmzon-abdcb-c4c57249e43b.json")
                    initialize_app(cred, {'databaseURL': 'https://farmzon-abdcb.firebaseio.com/'})

                    if self.admin_phone != "0788204327":
                        store = db.reference("Yummy").child("Admin").child(self.admin_phone).child("Orders")
                        stores = store.get()
                        print(stores)
                        count = 0
                        for y, x in stores.items():
                            print(x)
                            food_categories = category()
                            del_btn = MDIconButton(icon="delete", on_release=self.remove_widgets,
                                                   pos_hint={"center_x": .9, "center_y": .3}, theme_text_color="Custom",
                                                   text_color={60 / 255, 66 / 255, 75 / 255}, user_font_size="26sp")
                            count += 1
                            # food_categories.md_bg_color = 245 / 255, 0 / 255, 72 / 255, 1
                            food_categories.id = y
                            del_btn.id = y
                            food_categories.md_bg_color = 121 / 255, 174 / 255, 141 / 255, 1
                            food_categories.add_widget(Labels(text="Admin-phone:" + " " + str(x['Phone number'])))
                            food_categories.add_widget(Labels(text="Phone:" + " " + y))
                            food_categories.add_widget(MDSeparator(height="5dp"))
                            food_categories.add_widget(Labels(text="Amount:" + " " + " " + str(x['amount'])))
                            food_categories.add_widget(Labels(text="Location:" + " " + " " + str(x['location'])))
                            food_categories.add_widget(
                                Labels(text="Product-Name:" + " " + " " + str(x['product name'])))
                            food_categories.add_widget(Labels(text="Quantity:" + " " + " " + str(x['quantity'])))
                            food_categories.add_widget(Labels(text="Time-Ordered:" + " " + " " + str(x['time'])))
                            food_categories.add_widget(del_btn)
                            food.add_widget(food_categories)
                        self.spin_active = False
                        self.order_number = str(count)
                    else:
                        self.add_order()

            else:
                pass
        except:
            toast("no internet")
            self.spin_active = False

    all_products = {}
    front_products = {}
    front_shop_count = 0
    other_shops = 0

    def other_shop(self):
        if True:
            try:
                if self.other_shops == 0:
                    self.other_shops = self.other_shops + 1
                    import firebase_admin
                    firebase_admin._apps.clear()
                    from firebase_admin import credentials, initialize_app, db
                    if not firebase_admin._apps:
                        shop = self.root.ids.other_shop
                        cred = credentials.Certificate("credential/farmzon-abdcb-c4c57249e43b.json")
                        initialize_app(cred, {'databaseURL': 'https://farmzon-abdcb.firebaseio.com/'})
                        store = db.reference("Yummy").child("Products")
                        stores = store.get()
                        from retrive_data import Retrieve as RE
                        RE.other_shop(RE(), stores)
                        self.all_products = stores
                        for y, x in stores.items():
                            self.admin_product_name = x["product_name"]
                            self.customer_phone = x["admin_phone"]
                            self.admin_product_url = x["image_url"]
                            self.admin_product_price = x["product_price"]
                            self.admin_product_description = x["product_description"]

                            other_shops = Shops(on_release=self.selling_other)
                            other_shops.add_widget(Labels(text=self.admin_product_name))
                            other_shops.add_widget(Shop_image(source=self.admin_product_url))
                            other_shops.add_widget(Labels(text=self.admin_product_price))
                            other_shops.id = y
                            shop.add_widget(other_shops)
                            self.spin_active = False
            except:
                self.spin_active = False
                toast("no internet!")

    def other_shop_offline(self):
        filename = "helped/other.json"
        try:
            file_size = os.path.getsize(filename)
            if file_size > 0:
                shop = self.root.ids.front_shop
                with open(filename) as file:
                    line = json.load(file)
                    print(line)
                    for y, x in line.items():
                        self.admin_product_name = x["product_name"]
                        self.customer_phone = x["admin_phone"]
                        self.admin_product_url = x["image_url"]
                        self.admin_product_price = x["product_price"]
                        self.admin_product_description = x["product_description"]

                        other_shops = Shops(on_release=self.selling_other)
                        other_shops.add_widget(Labels(text=self.admin_product_name))
                        other_shops.add_widget(Shop_image(source=self.admin_product_url))
                        other_shops.add_widget(Labels(text=self.admin_product_price))
                        other_shops.id = y
                        shop.add_widget(other_shops)
                        self.spin_active = False
        except:
            self.spin_active = False
            self.order_spinner3()

    def other_shop_comparison(self):
        filename = "helped/other.json"
        try:
            file_size = os.path.getsize(filename)
            if file_size != 0:
                with open(filename) as file:
                    line = json.load(file)
                    local_len = len(line)
                    import firebase_admin
                    firebase_admin._apps.clear()
                    from firebase_admin import credentials, initialize_app, db
                    if not firebase_admin._apps:
                        cred = credentials.Certificate("credential/farmzon-abdcb-c4c57249e43b.json")
                        initialize_app(cred, {'databaseURL': 'https://farmzon-abdcb.firebaseio.com/'})
                        store = db.reference("Yummy").child("Products")
                        stores = store.get()
                        online_len = len(stores)
                        print(local_len, online_len)
                    if local_len == online_len:
                        print(local_len, online_len)
                    else:
                        self.refresh_other()
            else:
                self.refresh_other()
        except:
            toast("something is wrong!")

    def other_shop_faster(self):
        filename = "helped/other.json"
        try:
            if self.other_shops == 0:
                self.other_shops = self.other_shops + 1
                file_size = os.path.getsize(filename)
                thread = threading.Thread(target=self.other_shop_comparison)
                thread.start()
                if file_size != 0:
                    shop = self.root.ids.other_shop
                    with open(filename) as file:
                        line = json.load(file)
                        print(line)
                        self.all_products = line
                        for y, x in line.items():
                            self.admin_product_name = x["product_name"]
                            self.customer_phone = x["admin_phone"]
                            self.admin_product_url = x["image_url"]
                            self.admin_product_price = x["product_price"]
                            self.admin_product_description = x["product_description"]

                            other_shops = Shops(on_release=self.selling_other)
                            other_shops.add_widget(Labels(text=self.admin_product_name))
                            other_shops.add_widget(Shop_image(source=self.admin_product_url))
                            other_shops.add_widget(Labels(text=self.admin_product_price + "/Tsh"))
                            other_shops.id = y
                            shop.add_widget(other_shops)
                            self.spin_active = False
                else:
                    self.other_shops = 0
                    self.order_spinner3()
        except:
            self.other_shops = 0
            self.order_spinner3()

    def selling_other(self, instance):
        print(instance.id)
        # self.count = self.count + 1
        product = instance.id
        self.customer_phone = self.all_products[product]["admin_phone"]
        self.admin_product_url = self.all_products[product]["image_url"]
        self.admin_product_name = self.all_products[product]["product_name"]
        self.admin_product_price = self.all_products[product]["product_price"]
        self.admin_product_description = self.all_products[product]["product_description"]
        sm = self.root
        sm.current = "selling_other"

    def summon(self):
        sm = self.root
        sm.current = "other_shops"
        if self.other_shops == 0:
            self.spin_active = True

    def front_shop(self):
        if True:
            try:
                print("ok")
                if self.front_shop_count == 0:
                    self.front_shop_count = self.front_shop_count + 1
                    print("yess..")
                    import firebase_admin
                    firebase_admin._apps.clear()
                    from firebase_admin import credentials, initialize_app, db
                    if not firebase_admin._apps:
                        shop = self.root.ids.front_shop
                        cred = credentials.Certificate("credential/farmzon-abdcb-c4c57249e43b.json")
                        initialize_app(cred, {'databaseURL': 'https://farmzon-abdcb.firebaseio.com/'})
                        store = db.reference("Yummy").child("Products_admin")
                        print("nice")
                        stores = store.get()
                        from retrive_data import Retrieve as RE
                        thread = threading.Thread(target=RE.front_shop, args=(RE(), stores))
                        thread.start()
                        print("good")
                        self.front_products = stores
                        for y, x in stores.items():
                            self.admin_product_name = x["product_name"]
                            self.customer_phone = x["admin_phone"]
                            self.admin_product_url = x["image_url"]
                            self.admin_product_price = x["product_price"]

                            front_shops = Front_shop(on_release=self.selling_front)
                            layout = FloatLayout()
                            layout.add_widget(Labels(text=self.admin_product_name,
                                                     pos_hint={"center_x": .5, "center_y": .2},
                                                     halign="center"))
                            layout.add_widget(Cool(source=self.admin_product_url))
                            front_shops.add_widget(layout)
                            front_shops.id = y
                            shop.add_widget(front_shops)
                            time.sleep(2)
                            self.spin_active = False
                            self.loading = ""
                    else:
                        print("f**k!")


            except:
                toast("no internet!")
                self.front_shop_offline()

    def front_shop_offline(self):
        filename = "helped/admin.json"
        try:
            file_size = os.path.getsize(filename)
            if file_size > 0:
                shop = self.root.ids.front_shop
                with open(filename) as file:
                    line = json.load(file)
                    print(line)
                    for y, x in line.items():
                        self.admin_product_name = x["product_name"]
                        self.customer_phone = x["admin_phone"]
                        self.admin_product_url = x["image_url"]
                        self.admin_product_price = x["product_price"]

                        front_shops = Front_shop(on_release=self.selling_front)
                        layout = FloatLayout()
                        layout.add_widget(Labels(text=self.admin_product_name,
                                                 pos_hint={"center_x": .5, "center_y": .2},
                                                 halign="center"))
                        layout.add_widget(Cool(source=self.admin_product_url))
                        front_shops.add_widget(layout)
                        front_shops.id = y
                        shop.add_widget(front_shops)
                        time.sleep(2)
                        self.spin_active = False
                        self.loading = ""
        except:
            button = MDTextButton(text="Retry", pos_hint={"center_x": .5, "center_y": .5},
                                  on_release=lambda x: self.refresh_front())
            button.id = "you"
            button.custom_color = 40 / 255, 123 / 255, 222 / 255, 1
            shop = self.root.ids.front_shop
            shop.add_widget(button)
            self.loading = ""
            self.spin_active = False

    def front_shop_comparison(self):
        filename = "helped/admin.json"
        try:
            file_size = os.path.getsize(filename)
            if file_size != 0:
                with open(filename) as file:
                    line = json.load(file)
                    local_len = len(line)
                    import firebase_admin
                    firebase_admin._apps.clear()
                    from firebase_admin import credentials, initialize_app, db
                    if not firebase_admin._apps:
                        cred = credentials.Certificate("credential/farmzon-abdcb-c4c57249e43b.json")
                        initialize_app(cred, {'databaseURL': 'https://farmzon-abdcb.firebaseio.com/'})
                        store = db.reference("Yummy").child("Products_admin")
                        stores = store.get()
                        online_len = len(stores)
                    if local_len == online_len:
                        pass
                    else:
                        self.refresh_front()

            else:
                self.refresh_front()
        except:
            toast("something is wrong!")

    def front_shop_faster(self):
        filename = "helped/admin.json"
        try:
            if self.front_shop_count == 0:
                self.notifier()
                self.front_shop_count = self.front_shop_count + 1
                file_size = os.path.getsize(filename)
                thread = threading.Thread(target=self.front_shop_comparison)
                thread.start()
                if file_size != 0:
                    shop = self.root.ids.front_shop
                    with open(filename) as file:
                        line = json.load(file)
                        print(line)
                        self.front_products = line
                        for y, x in line.items():
                            self.admin_product_name = x["product_name"]
                            self.customer_phone = x["admin_phone"]
                            self.admin_product_url = x["image_url"]
                            self.admin_product_price = x["product_price"]

                            front_shops = Front_shop(on_release=self.selling_front)
                            layout = FloatLayout()
                            layout.add_widget(Labels(text=self.admin_product_name,
                                                     pos_hint={"center_x": .5, "center_y": .2},
                                                     halign="center"))
                            layout.add_widget(Cool(source=self.admin_product_url))
                            front_shops.add_widget(layout)
                            front_shops.id = y
                            shop.add_widget(front_shops)
                            self.spin_active = False
                            self.loading = ""
                else:
                    self.front_shop_count = 0
                    self.order_spinner2()
        except:
            self.front_shop_count = 0
            self.order_spinner2()

    def selling_front(self, instance):
        print(instance.id)
        self.count = self.count + 1
        self.category_tp = "admin"
        product = instance.id
        self.customer_phone = self.front_products[product]["admin_phone"]
        self.admin_product_url = self.front_products[product]["image_url"]
        self.admin_product_name = self.front_products[product]["product_name"]
        self.admin_product_price = self.front_products[product]["product_price"]
        sm = self.root
        sm.current = "selling"

    def success(self, *kwargs):
        self.refresh()

    def refresh(self):
        parent = self.root.ids.food_cat
        all_childs = parent.children
        identity = []
        self.food_count = 0
        for child in all_childs:
            identity.append(child.id)

        self.order_number = str(identity.__len__())

        for i in identity:
            self.remove_wide(i)

        if self.admin_phone == "0788204327":
            self.add_order()
        else:
            self.add_order_admin()

    def refresh_front(self):
        parent = self.root.ids.front_shop
        all_childs = parent.children
        identity = []
        self.front_shop_count = 0
        for child in all_childs:
            identity.append(child.id)

        for i in identity:
            print(i)
            self.remove_wide_front(i)

        self.spin_active = True
        self.order_spinner2()

    def refresh_other(self):
        parent = self.root.ids.other_shop
        all_childs = parent.children
        identity = []
        self.other_shops = 0
        for child in all_childs:
            identity.append(child.id)

        for i in identity:
            print(i)
            self.remove_wide_other(i)

        self.spin_active = True
        self.order_spinner3()

    def remove_wide_front(self, name):
        parent = self.root.ids.front_shop
        for child in parent.children:
            if name == child.id:
                parent.remove_widget(child)

    def remove_wide_other(self, name):
        parent = self.root.ids.other_shop
        for child in parent.children:
            if name == child.id:
                parent.remove_widget(child)

    def remove_wide(self, name):
        parent = self.root.ids.food_cat
        for child in parent.children:
            if name == child.id:
                parent.remove_widget(child)

    def remove_widgets(self, instance):
        name = instance.id
        parent = self.root.ids.food_cat
        for child in parent.children:
            if name == child.id:
                parent.remove_widget(child)
                self.del_entity(child.id)

    def del_entity(self, name):
        import firebase_admin
        firebase_admin._apps.clear()
        from firebase_admin import credentials, initialize_app, db
        if not firebase_admin._apps:
            cred = credentials.Certificate("credential/farmzon-abdcb-c4c57249e43b.json")
            initialize_app(cred, {'databaseURL': 'https://farmzon-abdcb.firebaseio.com/'})

            if self.admin_phone == "0788204327":
                db.reference("Yummy").child("Orders").child(name).delete()
            else:
                db.reference("Yummy").child("Admin").child(self.admin_phone).child("Orders").child(name).delete()

    def validate_user(self, phone, password):
        if phone == "" and phone.Isdigit():
            toast("please enter your phone number correctly")
        elif password == "":
            toast("please enter your password")
        else:
            self.spin_active = True
            thread = threading.Thread(target=self.Signing_in_admin_function, args=(phone, password))
            thread.start()

    def Signing_in_admin(self, phone, password):
        # thread = threading.Thread(target=self.Signing_in_admin_function, args=(phone, password))
        # thread.start()
        self.Signing_in_admin_function(phone, password)

    @mainthread
    def Signing_in_admin_function(self, phone, password):
        if DB.Signing_in_admin(DB(), phone, password):
            self.admin_name = DB.name_admin
            self.remember_me_admin(phone, password, self.admin_name)
            if not self.admin_true:
                self.listen_db(phone)
                sm = self.root
                sm.current = "admin_main"
        else:
            if self.admin_true:
                toast("no internet connection")
                self.spin_active = False
            else:
                self.spin_active = False
                toast("oops! phone number or password in correct or internet connection")

    # XXX---------CUSTOMER--------------XXX

    def id_generator(self):
        not_allowed = ".-:"
        date1 = datetime.datetime.now()
        date, time = id = str(date1).split(" ")
        self.admin_product_id = date + time
        product_id = ""
        for i in range(len(self.admin_product_id)):
            if self.admin_product_id[i] not in not_allowed:
                product_id = self.admin_product_id[i] + product_id
        id = self.admin_product_id = product_id
        print(id)
        return self.admin_product_id

    def get_info(self, phone, phone_other, name, price, product_name, image_path, password, category, description):
        if phone != "" and self.phone_number_check_admin(phone):
            if name != "" and name.isalpha() and price != "" and password != "":
                self.customer_phone = phone
                self.admin_password = password
                self.admin_name = name
                self.admin_product_image = image_path
                self.admin_product_price = price
                self.admin_product_name = product_name
                self.admin_product_id = self.id_generator()
                cate = category
                print(phone, name, price, product_name, image_path, password, self.admin_product_id)
                try:
                    thread = threading.Thread(target=self.transporter, args=(
                        phone, phone_other, name, price, product_name, image_path, password, self.admin_product_id,
                        cate, description))
                    thread.start()
                except:
                    toast("no internet")
            else:
                toast("check your info well")
                self.spin_active = False

        else:
            toast("check your mobile number")
            self.spin_active = False

    def transporter(self, phone, phone_other, name, price, product_name, image_path, password, id, cate, description):
        thread = threading.Thread(target=DB.upload_product_image, args=(
            DB(), cate, image_path, phone, phone_other, name, price, product_name, password, id, description))
        thread.start()

        thread.join()

        self.actively_reg()

    def listen_db(self, phone):
        try:
            import firebase_admin
            firebase_admin._apps.clear()
            from firebase_admin import credentials, initialize_app, db
            id = datetime.datetime.now()
            cred = credentials.Certificate("credential/farmzon-abdcb-c4c57249e43b.json")
            initialize_app(cred, {'databaseURL': 'https://farmzon-abdcb.firebaseio.com/'})
            self.admin_phone = phone
            if phone != "0788204327":
                print("i am listening......")
                my_stream = db.reference("Yummy").child("Admin").child(phone).child("Orders").listen(self.success)
            else:
                print("i am listening......")
                my_stream = db.reference("Yummy").child("Orders").listen(self.success)
        except:
            print("poor you")

    def Permission(self, android=None):
        if self.counter_image <= 0:
            if utils.platform == 'android':
                if self.count_update == 0:
                    from gallary import Gambler as GA
                    Clock.schedule_once(GA.user_select_image, 0)
                    self.admin_product_image = GA.path_of_picture
                    img = self.root.ids.product_image
                    img.source = GA.path_of_picture
                    self.count_update += self.count_update + 1
                else:
                    from gallary import Gambler as GA
                    self.count_update = self.count_update - 1
                    self.admin_product_image = GA.path_of_picture
                    img = self.root.ids.product_image
                    img.source = GA.path_of_picture

            else:
                self.counter_image = self.counter_image + 1
                for root, dirs, files in os.walk("/home/alpha9060/Downloads", topdown=False):
                    for file_ in files:
                        full_file_path = os.path.join(root, file_)
                        if full_file_path.endswith(('.png', '.jpg', '.jpeg')):
                            print(full_file_path)
                            image = full_file_path
                            cat_class = category_gal()
                            cat_class.add_widget(category_ga(source=image))
                            img = self.root.ids.images_added
                            img.add_widget(cat_class)
        else:
            pass

    ads = KivMob(TestIds.INTERSTITIAL)

    def adver(self):
        self.kill_adver()
        self.ads.show_interstitial()

    def build(self):

        self.ads.new_interstitial(TestIds.INTERSTITIAL)
        self.theme_cls.theme_style = "Light"
        self.theme_cls.primary_palette = "DeepOrange"
        self.theme_cls.accent = "Brown"
        # Window.size = (360, 640)
        self.size_x, self.size_y = Window.size
        self.title = "yummy"
예제 #10
0
class OneApp(MDApp):
    try:
        ads = KivMob('ca-app-pub-1818238534900904~2025018602')

        def __init__(self):
            try:
                super().__init__()
                #Declaring MDApp object
                self.theme_cls = ThemeManager()
                self.theme_cls.primary_palette = 'Orange'

                self.theme_cls.primary_style = 'Light'
                self.title = 'Type To Write'
                self.screen = Builder.load_file('main.kv')

                self.setup()

                # Put Banner Ads
            except:
                pass

        def animate_card(self, widget, text_field, spinn):
            anim = Animation(pos_hint={'center_y': 0.53})

            anim.start(widget)
            anim1 = Animation(pos_hint={'center_y': 0.75})
            anim1.start(text_field)
            anim2 = Animation(pos_hint={'center_y': 0.65})
            anim2.start(spinn)

        def picture_taken(self, obj, filename):

            try:
                self.picture = filename
                from google.cloud import storage
                """Uploads a file to the bucket."""
                bucket_name = 'online-server-test'
                destination_blob_name = "test-storage-blob.png"
                debug = True
                if not debug:
                    storage_client = storage.Client()
                else:
                    cred_file = 'key.json'
                    storage_client = storage.Client.from_service_account_json(
                        cred_file)

                bucket = storage_client.bucket(bucket_name)
                blob = bucket.blob(destination_blob_name)

                blob.upload_from_filename(self.picture)
                print("File {} uploaded to {}.".format(self.picture,
                                                       destination_blob_name))

                self.hit_cloud_function(destination_blob_name)
                self.screen.ids.firebaseloginscreen.display_loading_screen()

            except:
                pass

        @mainthread
        def hit_cloud_function(self, blob_name):

            try:
                from urllib.parse import urlencode
                msg_data = urlencode({'message': blob_name})
                headers = {
                    'Content-type': 'application/x-www-form-urlencoded',
                    'Accept': 'text/plain'
                }

                print("Sending trigger request")
                trigger_url = "https://us-central1-endless-theorem-297112.cloudfunctions.net/detect_handwriting"
                UrlRequest(trigger_url,
                           req_body=msg_data,
                           req_headers=headers,
                           ca_file=certifi.where(),
                           on_failure=self.error,
                           on_error=self.error,
                           on_success=self.success)
            except:
                pass

        def error(self, *args):
            try:
                print("Error", args)
            except:
                pass

        def success(self, request, response):

            print("Success!")
            try:
                self.screen.ids.typetowritescreen.change_values(response)
                self.hide_screen()
                self.screen.ids.typetowritescreen.change_screen('screen1')
            except:
                pass

        def setup(self):
            try:

                self.screen.ids.firebaseloginscreen.web_api_key = "AIzaSyBmrGpiwimYZ-HT_BSesv4gMjuPJcG3omM"
                self.screen.ids.firebaseloginscreen.debug = False
                self.screen.ids.firebaseloginscreen.remember_user = True
                self.screen.ids.firebaseloginscreen.require_email_verification = True
            except:
                pass

        def call(self, button):
            if button.icon == 'typewriter':

                try:
                    self.screen.ids.typetowritescreen.check_data_login()
                except:
                    pass

            if button.icon == 'notebook':
                try:
                    self.screen.ids.typetowritescreen.grammar_check()
                except:
                    pass
            if button.icon == 'google-photos':
                try:
                    self.screen.ids.typetowritescreen.see_recent_images()
                except:
                    pass

            if button.icon == 'camera':
                try:
                    self.screen.ids.typetowritescreen.ids.screen1.go_camera()
                except:
                    pass

            if button.icon == 'ship-wheel':
                try:
                    self.screen.ids.typetowritescreen.ids.screen1.go_addscreen(
                    )
                except:
                    pass

            if button.icon == 'content-save':
                try:
                    self.screen.ids.typetowritescreen.make_json()
                except:
                    pass

            if button.icon == 'view-list':
                try:
                    self.screen.ids.typetowritescreen.visualize_json()

                    self.screen.ids.typetowritescreen.ids.addscreen.go_friend()
                except:
                    pass

            if button.icon == 'exit-to-app':
                try:
                    self.screen.ids.typetowritescreen.ids.addscreen.go_back()
                except:
                    pass

            if button.icon == 'delete':
                try:
                    self.screen.ids.typetowritescreen.delete()
                except:
                    pass
            if button.icon == 'email-alert':
                try:
                    self.screen.ids.typetowritescreen.change_email()
                except:
                    pass
            if button.icon == 'chart-bar':
                try:
                    self.screen.ids.typetowritescreen.ids.screen1.go_pie_chart(
                    )
                except:
                    pass
            if button.icon == 'truck-delivery':
                try:
                    self.screen.ids.typetowritescreen.change_screen(
                        'ongkirscreen')
                except:
                    pass

        def show_dialog(self):
            try:
                #Make A PopUp Dialog to warn user
                self.dialog = MDDialog(
                    title='LOGOUT',
                    text='Are you sure to log out',
                    size_hint=(0.5, 1),
                    buttons=[
                        MDFlatButton(text='Close',
                                     on_release=self.close_dialog),
                        MDRaisedButton(text='Sign Out',
                                       on_release=self.sign_out)
                    ])
                #Show It On The Screen
                self.dialog.open()
            except:
                pass

        def making_banner(self):
            try:
                self.ads.new_banner('ca-app-pub-1818238534900904/4048546717',
                                    top_pos=False)
                # Requesting New Ads

                self.ads.request_banner()
                from plyer import uniqueid
                self.ads.add_test_device(uniqueid.id.decode('utf-8'))
                self.ads.show_banner()
            except:
                pass

        def close_dialog(self, *args):
            #Closing Dialog
            try:
                self.dialog.dismiss()
            except:
                pass

        def sign_out(self, obj):
            #Make Firebase To Be Logged Out
            try:

                self.screen.ids.firebaseloginscreen.log_out()
                self.screen.current = "firebaseloginscreen"
                self.dialog.dismiss()
            except:
                pass

        def loading_screen(self, *args):
            #Show The Loading Screen
            try:
                self.screen.ids.firebaseloginscreen.display_loading_screen()
            except:
                pass

        def hide_screen(self, *args):
            #Hide The Loading Screen
            try:
                self.screen.ids.firebaseloginscreen.hide_loading_screen()
            except:
                pass

        def on_resume(self):
            self.ads.request_banner()

        def build(self):
            try:
                self.making_banner()
                self.screen.ids.typetowritescreen.setup()

                self.screen.ids.typetowritescreen.ids.ongkirscreen.ids.search_provinsi.setup(
                )
                self.screen.ids.typetowritescreen.store_data_online()
            except:
                pass

            return self.screen
            # Showing Ads To The Screen

    except:
        pass