simplify android receive
This commit is contained in:
parent
f6280c4e23
commit
6693a70c72
147
gui/android.py
147
gui/android.py
|
@ -69,15 +69,9 @@ def modal_question(q, msg, pos_text = 'OK', neg_text = 'Cancel'):
|
||||||
return result.get('which') == 'positive'
|
return result.get('which') == 'positive'
|
||||||
|
|
||||||
def edit_label(addr):
|
def edit_label(addr):
|
||||||
v = modal_input('Edit label',None,wallet.labels.get(addr))
|
v = modal_input('Edit label', None, wallet.labels.get(addr))
|
||||||
if v is not None:
|
if v is not None:
|
||||||
if v:
|
wallet.set_label(addr, v)
|
||||||
wallet.labels[addr] = v
|
|
||||||
else:
|
|
||||||
if addr in wallet.labels.keys():
|
|
||||||
wallet.labels.pop(addr)
|
|
||||||
wallet.update_tx_history()
|
|
||||||
wallet.save()
|
|
||||||
droid.fullSetProperty("labelTextView", "text", v)
|
droid.fullSetProperty("labelTextView", "text", v)
|
||||||
|
|
||||||
def select_from_contacts():
|
def select_from_contacts():
|
||||||
|
@ -103,23 +97,6 @@ def select_from_contacts():
|
||||||
return addr
|
return addr
|
||||||
|
|
||||||
|
|
||||||
def select_from_addresses():
|
|
||||||
droid.dialogCreateAlert("Addresses:")
|
|
||||||
l = []
|
|
||||||
addresses = wallet.addresses()
|
|
||||||
for i in range(len(addresses)):
|
|
||||||
addr = addresses[i]
|
|
||||||
label = wallet.labels.get(addr,addr)
|
|
||||||
l.append( label )
|
|
||||||
droid.dialogSetItems(l)
|
|
||||||
droid.dialogShow()
|
|
||||||
response = droid.dialogGetResponse()
|
|
||||||
result = response.result.get('item')
|
|
||||||
droid.dialogDismiss()
|
|
||||||
if result is not None:
|
|
||||||
addr = addresses[result]
|
|
||||||
return addr
|
|
||||||
|
|
||||||
|
|
||||||
def protocol_name(p):
|
def protocol_name(p):
|
||||||
if p == 't': return 'TCP'
|
if p == 't': return 'TCP'
|
||||||
|
@ -234,34 +211,50 @@ def main_layout():
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def qr_layout(addr):
|
def qr_layout(addr, amount, message):
|
||||||
return make_layout("""
|
addr_view= """
|
||||||
|
<TextView android:id="@+id/addrTextView"
|
||||||
<TextView android:id="@+id/addrTextView"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="match_parent"
|
android:layout_height="50"
|
||||||
android:layout_height="50"
|
android:text="%s"
|
||||||
android:text="%s"
|
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
android:gravity="center_vertical|center_horizontal|center">
|
||||||
android:gravity="center_vertical|center_horizontal|center">
|
</TextView>"""%addr
|
||||||
</TextView>
|
if amount:
|
||||||
|
amount_view = """
|
||||||
<ImageView
|
<TextView android:id="@+id/amountTextView"
|
||||||
android:id="@+id/qrView"
|
|
||||||
android:gravity="center"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="350"
|
android:layout_height="50"
|
||||||
android:antialias="false"
|
android:text="Amount: %s"
|
||||||
android:src="file:///sdcard/sl4a/qrcode.bmp" />
|
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||||
|
android:gravity="center_vertical|center_horizontal|center">
|
||||||
|
</TextView>"""%format_satoshis(amount)
|
||||||
|
else:
|
||||||
|
amount_view = ""
|
||||||
|
if message:
|
||||||
|
message_view = """
|
||||||
|
<TextView android:id="@+id/messageTextView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="50"
|
||||||
|
android:text="Message: %s"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||||
|
android:gravity="center_vertical|center_horizontal|center">
|
||||||
|
</TextView>"""%message
|
||||||
|
else:
|
||||||
|
message_view = ""
|
||||||
|
|
||||||
<TextView android:id="@+id/labelTextView"
|
return make_layout("""
|
||||||
android:layout_width="match_parent"
|
%s
|
||||||
android:layout_height="50"
|
%s
|
||||||
android:text="%s"
|
%s
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
<ImageView
|
||||||
android:gravity="center_vertical|center_horizontal|center">
|
android:id="@+id/qrView"
|
||||||
</TextView>
|
android:gravity="center"
|
||||||
|
android:layout_width="match_parent"
|
||||||
"""%(addr,wallet.labels.get(addr,'')), True)
|
android:layout_height="350"
|
||||||
|
android:antialias="false"
|
||||||
|
android:src="file:///sdcard/sl4a/qrcode.bmp" />
|
||||||
|
"""%(addr_view, amount_view, message_view), True)
|
||||||
|
|
||||||
payto_layout = make_layout("""
|
payto_layout = make_layout("""
|
||||||
|
|
||||||
|
@ -557,16 +550,14 @@ def main_loop():
|
||||||
|
|
||||||
elif out == "receive":
|
elif out == "receive":
|
||||||
global receive_addr
|
global receive_addr
|
||||||
receive_addr = select_from_addresses()
|
domain = wallet.addresses(include_change = False)
|
||||||
if receive_addr:
|
for addr in domain:
|
||||||
amount = modal_input('Amount', 'Amount you want receive. ', '', "numberDecimal")
|
if not wallet.history.get(addr):
|
||||||
if amount:
|
receive_addr = addr
|
||||||
receive_addr = 'bitcoin:%s?amount=%s'%(receive_addr, amount)
|
break
|
||||||
|
else:
|
||||||
if not receive_addr:
|
|
||||||
out = None
|
out = None
|
||||||
|
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
@ -645,24 +636,43 @@ def payto_loop():
|
||||||
|
|
||||||
|
|
||||||
receive_addr = ''
|
receive_addr = ''
|
||||||
|
receive_amount = None
|
||||||
|
receive_message = None
|
||||||
|
|
||||||
contact_addr = ''
|
contact_addr = ''
|
||||||
recipient = ''
|
recipient = ''
|
||||||
|
|
||||||
def receive_loop():
|
def receive_loop():
|
||||||
|
global receive_addr, receive_amount, receive_message
|
||||||
|
print "receive loop"
|
||||||
|
receive_URI = util.create_URI(receive_addr, receive_amount, receive_message)
|
||||||
|
make_bitmap(receive_URI)
|
||||||
|
droid.fullShow(qr_layout(receive_addr, receive_amount, receive_message))
|
||||||
out = None
|
out = None
|
||||||
while out is None:
|
while out is None:
|
||||||
event = droid.eventWait().result
|
event = droid.eventWait().result
|
||||||
print "got event", event
|
if not event:
|
||||||
if event["name"]=="key":
|
continue
|
||||||
|
|
||||||
|
elif event["name"]=="key":
|
||||||
if event["data"]["key"] == '4':
|
if event["data"]["key"] == '4':
|
||||||
out = 'main'
|
out = 'main'
|
||||||
|
|
||||||
elif event["name"]=="clipboard":
|
elif event["name"]=="clipboard":
|
||||||
droid.setClipboard(receive_addr)
|
droid.setClipboard(receive_URI)
|
||||||
modal_dialog('Address copied to clipboard',receive_addr)
|
modal_dialog('URI copied to clipboard', receive_URI)
|
||||||
|
|
||||||
elif event["name"]=="edit":
|
elif event["name"]=="amount":
|
||||||
edit_label(receive_addr)
|
amount = modal_input('Amount', 'Amount you want receive (in BTC). ', format_satoshis(receive_amount) if receive_amount else None, "numberDecimal")
|
||||||
|
if amount is not None:
|
||||||
|
receive_amount = 100000000 * Decimal(amount) if amount else None
|
||||||
|
out = 'receive'
|
||||||
|
|
||||||
|
elif event["name"]=="message":
|
||||||
|
message = modal_input('Message', 'Message in your request', receive_message)
|
||||||
|
if message is not None:
|
||||||
|
receive_message = str(message)
|
||||||
|
out = 'receive'
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
@ -857,7 +867,8 @@ def add_menu(s):
|
||||||
droid.addOptionsMenuItem("Settings","settings",None,"")
|
droid.addOptionsMenuItem("Settings","settings",None,"")
|
||||||
elif s == 'receive':
|
elif s == 'receive':
|
||||||
droid.addOptionsMenuItem("Copy","clipboard",None,"")
|
droid.addOptionsMenuItem("Copy","clipboard",None,"")
|
||||||
droid.addOptionsMenuItem("Label","edit",None,"")
|
droid.addOptionsMenuItem("Amount","amount",None,"")
|
||||||
|
droid.addOptionsMenuItem("Message","message",None,"")
|
||||||
elif s == 'contacts':
|
elif s == 'contacts':
|
||||||
droid.addOptionsMenuItem("Copy","clipboard",None,"")
|
droid.addOptionsMenuItem("Copy","clipboard",None,"")
|
||||||
droid.addOptionsMenuItem("Label","edit",None,"")
|
droid.addOptionsMenuItem("Label","edit",None,"")
|
||||||
|
@ -943,13 +954,11 @@ class ElectrumGui:
|
||||||
s = payto_loop()
|
s = payto_loop()
|
||||||
|
|
||||||
elif s == 'receive':
|
elif s == 'receive':
|
||||||
make_bitmap(receive_addr)
|
|
||||||
droid.fullShow(qr_layout(receive_addr))
|
|
||||||
s = receive_loop()
|
s = receive_loop()
|
||||||
|
|
||||||
elif s == 'contacts':
|
elif s == 'contacts':
|
||||||
make_bitmap(contact_addr)
|
make_bitmap(contact_addr)
|
||||||
droid.fullShow(qr_layout(contact_addr))
|
droid.fullShow(qr_layout(contact_addr, None, None))
|
||||||
s = contacts_loop()
|
s = contacts_loop()
|
||||||
|
|
||||||
elif s == 'settings':
|
elif s == 'settings':
|
||||||
|
|
Loading…
Reference in New Issue