forked from spesmilo/electrum
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
215 additions
and
27 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
android/app/src/main/java/org/electroncash/electroncash3/ColdLoad.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.electroncash.electroncash3 | ||
|
||
import android.content.ClipboardManager | ||
import android.content.Intent | ||
import android.text.Editable | ||
import android.text.TextWatcher | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AlertDialog | ||
import androidx.fragment.app.viewModels | ||
import androidx.lifecycle.ViewModel | ||
import com.google.zxing.integration.android.IntentIntegrator | ||
import kotlinx.android.synthetic.main.load.* | ||
|
||
|
||
val libTransaction by lazy { libMod("transaction") } | ||
|
||
|
||
// This provides a dialog to allow users to input a string, which is then broadcast | ||
// on the bitcoin cash network. Strings are not validated, | ||
// but broadcast_transaction should throw error which is toasted. | ||
// Valid transaction quickly show up in transactions. | ||
|
||
class ColdLoadDialog : AlertDialogFragment() { | ||
|
||
class Model : ViewModel() {} | ||
|
||
val model: Model by viewModels() | ||
|
||
override fun onBuildDialog(builder: AlertDialog.Builder) { | ||
builder.setTitle(R.string.load_transaction) | ||
.setView(R.layout.load) | ||
.setNegativeButton(android.R.string.cancel, null) | ||
.setNeutralButton(R.string.qr_code, null) | ||
.setPositiveButton(R.string.send, null) | ||
} | ||
|
||
override fun onShowDialog() { | ||
super.onShowDialog() | ||
etTransaction.addTextChangedListener(object : TextWatcher { | ||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} | ||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {} | ||
override fun afterTextChanged(s: Editable?) { updateUI() } | ||
}) | ||
updateUI() | ||
|
||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { onOK() } | ||
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener { scanQR(this) } | ||
btnPaste.setOnClickListener { | ||
val clipdata = getSystemService(ClipboardManager::class).primaryClip | ||
if (clipdata != null && clipdata.getItemCount() > 0) { | ||
val cliptext = clipdata.getItemAt(0) | ||
etTransaction.setText(cliptext.text) | ||
} | ||
} | ||
} | ||
|
||
private fun updateUI() { | ||
val currenttext = etTransaction.text | ||
//checks if text is blank. further validations can be added here | ||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = currenttext.isNotBlank() | ||
} | ||
|
||
// Receives the result of a QR scan. | ||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | ||
val result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data) | ||
if (result != null && result.contents != null) { | ||
etTransaction.setText(result.contents) | ||
} else { | ||
super.onActivityResult(requestCode, resultCode, data) | ||
} | ||
} | ||
|
||
fun onOK() { | ||
val tx = libTransaction.callAttr("Transaction", etTransaction.text.toString()) | ||
if (!daemonModel.isConnected()) { | ||
throw ToastException(R.string.not_connected) | ||
} | ||
val result = daemonModel.network.callAttr("broadcast_transaction", tx) | ||
try { | ||
checkBroadcastResult(result) | ||
toast(R.string.the_string, Toast.LENGTH_LONG) | ||
dismiss() | ||
} catch (e: ToastException) { e.show() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M19,2h-4.18C14.4,0.84 13.3,0 12,0c-1.3,0 -2.4,0.84 -2.82,2L5,2c-1.1,0 -2,0.9 -2,2v16c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,4c0,-1.1 -0.9,-2 -2,-2zM12,2c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM19,20L5,20L5,4h2v3h10L17,4h2v16z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<ScrollView | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<TextView | ||
android:id="@+id/textView4" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_marginEnd="24dp" | ||
android:layout_marginLeft="24dp" | ||
android:layout_marginRight="24dp" | ||
android:layout_marginStart="24dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/type_paste" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent"/> | ||
|
||
<EditText | ||
android:id="@+id/etTransaction" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_marginEnd="4dp" | ||
android:layout_marginRight="4dp" | ||
android:inputType="textNoSuggestions" | ||
android:minLines="3" | ||
app:layout_constraintEnd_toStartOf="@+id/btnPaste" | ||
app:layout_constraintStart_toStartOf="@+id/textView4" | ||
app:layout_constraintTop_toBottomOf="@+id/textView4" | ||
tools:text="@string/test_address"> | ||
<requestFocus/> | ||
</EditText> | ||
|
||
<!-- Bottom constraint keeps button aligned with text box before API 21 (see dimens.xml). --> | ||
<com.google.android.material.floatingactionbutton.FloatingActionButton | ||
android:id="@+id/btnPaste" | ||
style="@style/FAB.Dialog" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
app:layout_constraintBottom_toBottomOf="@+id/etTransaction" | ||
app:layout_constraintEnd_toEndOf="@+id/textView4" | ||
app:layout_constraintTop_toTopOf="@+id/etTransaction" | ||
app:srcCompat="@drawable/ic_paste_24dp"/> | ||
|
||
|
||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
|
||
</ScrollView> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters