Пример #1
0
class ClientItem:
    def __init__(self, client, context, callback=None):
        self.client = client
        self.callback = callback
        self.context = context
        self.layout = LinearLayout(self.context)

        self.text_view = TextView(self.context)
        self.text_view.setText(self.client)
        self.text_view.setTextSize(22)
        self.layout.addView(self.text_view)

        self.add_button = Button(self.context)
        self.add_button.setOnClickListener(ButtonClick(self.view_sales))
        self.add_button.getBackground().setColorFilter(
            0xff9e9e9e, PorterDuff.Mode.MULTIPLY)
        self.add_button.setText('+')
        relative = RelativeLayout(self.context)
        relative.addView(self.add_button, _create_layout_params('right'))
        self.layout.addView(relative)

    def view_sales(self):
        self.callback(event='sales_client', value=self.client, back='clients')

    def getView(self):
        return self.layout
Пример #2
0
class ProductItem:
    def __init__(self, product, context, callback=None):
        self.product = product
        self.context = context
        self.callback = callback

        self.layout = LinearLayout(self.context)
        self.text_view = TextView(self.context)
        self.text_view.setTextSize(20)
        self.text_view.setText('%s | %d | R$%.2f' %
                               (self.product['name'], self.product['quantity'],
                                self.product['value']))
        self.layout.addView(self.text_view)

        hbuttons = LinearLayout(self.context)
        hbuttons.setOrientation(LinearLayout.HORIZONTAL)

        self.add_button = Button(self.context)
        self.add_button.setOnClickListener(ButtonClick(self.add))
        self.add_button.getBackground().setColorFilter(
            0xff8bc34a, PorterDuff.Mode.MULTIPLY)
        self.add_button.setText('+')
        hbuttons.addView(self.add_button)

        self.remove_button = Button(self.context)
        self.remove_button.setOnClickListener(ButtonClick(self.remove))
        self.remove_button.getBackground().setColorFilter(
            0xffff0000, PorterDuff.Mode.MULTIPLY)
        self.remove_button.setText('-')
        hbuttons.addView(self.remove_button)

        relative = RelativeLayout(self.context)
        relative.addView(hbuttons, _create_layout_params('right'))

        self.layout.addView(relative)

    def add(self):
        self.product['quantity'] += 1
        self.text_view.setText('%s | %d | R$%.2f' %
                               (self.product['name'], self.product['quantity'],
                                self.product['value']))
        self.callback(event='update_product', value=self.product)

    def remove(self):
        self.product['quantity'] -= 1
        self.text_view.setText('%s | %d | R$%.2f' %
                               (self.product['name'], self.product['quantity'],
                                self.product['value']))
        self.callback(event='update_product', value=self.product)

    def getView(self):
        return self.layout
Пример #3
0
class TodoItem:
    def __init__(self, value, context, layout=None, callback=None):
        self.callback = callback
        self.context = context
        self.value = value
        if layout:
            self.layout = layout
            self.checkbox = layout.getChildAt(0)
            self.text_view = layout.getChildAt(1)
        else:
            self.layout = LinearLayout(self.context)
            self.checkbox = CheckBox(self.context)
            self.checkbox.setOnClickListener(OnClick(self.update))
            self.layout.addView(self.checkbox)

            print(value)
            self.text_view = StrikeableTextView(self.context,
                                                striked=value['finished'])
            self.text_view.setTextSize(25)
            self.layout.addView(self.text_view)

            self.button_delete = Button(self.context)
            self.button_delete.setOnClickListener(OnClick(self.delete))
            self.button_delete.getBackground().setColorFilter(
                0xffff4444, PorterDuff.Mode.MULTIPLY)
            self.button_delete.setText('X')
            relative1 = RelativeLayout(
                self.context)  # relative inside horizontal layout
            relative1.addView(self.button_delete, _create_layout_params())
            self.layout.addView(relative1)

        self.text_view.setText(value['title'])
        self.checkbox.setChecked(value['finished'])

    def update(self):
        self.value['finished'] = self.checkbox.isChecked()
        self.text_view.setStriked(self.value['finished'])
        self.callback('update', self.value)

    def delete(self):
        self.callback('delete', self.value)

    def getView(self):
        return self.layout
Пример #4
0
class SaleItem:
    def __init__(self, sale, context, callback=None, back=None):
        self.sale = sale
        self.back = back
        self.context = context
        self.callback = callback
        self.layout = LinearLayout(self.context)

        self.button_details = Button(self.context)
        self.button_details.setOnClickListener(ButtonClick(self.details))
        self.button_details.setText('+')
        self.button_details.getBackground().setColorFilter(
            0xff9e9e9e, PorterDuff.Mode.MULTIPLY)
        self.layout.addView(self.button_details)

        self.text_view = StrikeableTextView(self.context, striked=sale['paid'])
        self.text_view.setText(self.sale['person'])
        self.text_view.setTextSize(22)
        self.layout.addView(self.text_view)

        self.button_pay = Button(self.context)
        self.button_pay.setOnClickListener(ButtonClick(self.pay))
        self.button_pay.setText('V')
        self.button_pay.getBackground().setColorFilter(
            0xff8bc34a, PorterDuff.Mode.MULTIPLY)

        relative1 = RelativeLayout(self.context)
        relative1.addView(self.button_pay, _create_layout_params('right'))

        self.layout.addView(relative1)

    def details(self):
        self.callback(event='details_sale', value=self.sale, back=self.back)

    def pay(self):
        self.sale['paid'] = True
        self.text_view.setStriked(self.sale['paid'])
        self.callback(event='update_sale', value=self.sale)

    def getView(self):
        return self.layout