@@ -4,7 +4,11 @@ import android.Manifest
4
4
import android.app.Activity
5
5
import android.app.ActivityManager
6
6
import android.app.DownloadManager
7
- import android.content.*
7
+ import android.content.BroadcastReceiver
8
+ import android.content.ClipboardManager
9
+ import android.content.Context
10
+ import android.content.Intent
11
+ import android.content.IntentFilter
8
12
import android.content.pm.PackageManager
9
13
import android.net.Uri
10
14
import android.os.Build
@@ -25,28 +29,48 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager
25
29
import androidx.preference.PreferenceManager
26
30
import androidx.recyclerview.widget.DividerItemDecoration
27
31
import androidx.recyclerview.widget.LinearLayoutManager
28
- import com.lvaccaro.lamp.activities.*
32
+ import com.lvaccaro.lamp.activities.BuildInvoiceActivity
33
+ import com.lvaccaro.lamp.activities.ChannelsActivity
34
+ import com.lvaccaro.lamp.activities.ConsoleActivity
35
+ import com.lvaccaro.lamp.activities.LogActivity
36
+ import com.lvaccaro.lamp.activities.ScanActivity
37
+ import com.lvaccaro.lamp.activities.SendActivity
38
+ import com.lvaccaro.lamp.activities.SettingsActivity
39
+ import com.lvaccaro.lamp.activities.UriResultActivity
29
40
import com.lvaccaro.lamp.adapters.Balance
30
41
import com.lvaccaro.lamp.adapters.BalanceAdapter
31
42
import com.lvaccaro.lamp.fragments.PeerInfoFragment
32
43
import com.lvaccaro.lamp.fragments.WithdrawFragment
33
- import com.lvaccaro.lamp.handlers.*
44
+ import com.lvaccaro.lamp.handlers.BrokenStatus
45
+ import com.lvaccaro.lamp.handlers.NewBlockHandler
46
+ import com.lvaccaro.lamp.handlers.NewChannelPayment
47
+ import com.lvaccaro.lamp.handlers.NewTransaction
48
+ import com.lvaccaro.lamp.handlers.NodeUpHandler
49
+ import com.lvaccaro.lamp.handlers.PaidInvoice
50
+ import com.lvaccaro.lamp.handlers.ShutdownNode
34
51
import com.lvaccaro.lamp.services.LightningService
35
52
import com.lvaccaro.lamp.services.TorService
36
53
import com.lvaccaro.lamp.utils.Archive
37
54
import com.lvaccaro.lamp.utils.SimulatorPlugin
38
55
import com.lvaccaro.lamp.utils.UI
39
56
import com.lvaccaro.lamp.views.HistoryBottomSheet
40
- import kotlinx.android.synthetic.main.activity_main.*
41
- import kotlinx.android.synthetic.main.content_main_off.*
42
- import kotlinx.android.synthetic.main.content_main_on.*
43
- import kotlinx.android.synthetic.main.fragment_history.*
57
+ import kotlinx.android.synthetic.main.activity_main.contentMainOff
58
+ import kotlinx.android.synthetic.main.activity_main.contentMainOn
59
+ import kotlinx.android.synthetic.main.content_main_off.powerImageView
60
+ import kotlinx.android.synthetic.main.content_main_off.statusText
61
+ import kotlinx.android.synthetic.main.content_main_off.versionText
62
+ import kotlinx.android.synthetic.main.content_main_on.balanceText
63
+ import kotlinx.android.synthetic.main.content_main_on.floatingActionButton
64
+ import kotlinx.android.synthetic.main.content_main_on.receiveButton
65
+ import kotlinx.android.synthetic.main.content_main_on.recyclerView
66
+ import kotlinx.android.synthetic.main.content_main_on.sendButton
67
+ import kotlinx.android.synthetic.main.content_main_on.syncText
68
+ import kotlinx.android.synthetic.main.fragment_history.bottomSheet
44
69
import org.jetbrains.anko.doAsync
45
70
import org.json.JSONArray
46
71
import java.io.File
47
72
import java.util.logging.Logger
48
73
49
-
50
74
class MainActivity : UriResultActivity () {
51
75
52
76
private val REQUEST_SCAN = 102
@@ -178,7 +202,8 @@ class MainActivity : UriResultActivity() {
178
202
179
203
override fun onRequestPermissionsResult (
180
204
requestCode : Int ,
181
- permissions : Array <String >, grantResults : IntArray
205
+ permissions : Array <String >,
206
+ grantResults : IntArray
182
207
) {
183
208
when (requestCode) {
184
209
WRITE_REQUEST_CODE -> {
@@ -280,13 +305,14 @@ class MainActivity : UriResultActivity() {
280
305
val peers: JSONArray = listPeers[" peers" ] as JSONArray
281
306
282
307
runOnUiThread {
283
- balanceText.text = " ${(SimulatorPlugin .funds(listPeers).toDouble()/ 1000 )} sat"
308
+ balanceText.text = " ${(SimulatorPlugin .funds(listPeers).toDouble() / 1000 )} sat"
284
309
recyclerView.adapter = BalanceAdapter (
285
310
arrayListOf (
286
- Balance (" Spendable in channels" , " ${peers.length()} Peers" , " ${SimulatorPlugin .funds(listPeers).toDouble()/ 1000 } sat" ),
287
- Balance (" Locked in channels" , " ${channels.length()} Channels" , " ${SimulatorPlugin .offchain(listFunds).toDouble()/ 1000 } sat" ),
311
+ Balance (" Spendable in channels" , " ${peers.length()} Peers" , " ${SimulatorPlugin .funds(listPeers).toDouble() / 1000 } sat" ),
312
+ Balance (" Locked in channels" , " ${channels.length()} Channels" , " ${SimulatorPlugin .offchain(listFunds).toDouble() / 1000 } sat" ),
288
313
Balance (" Bitcoin on chain" , " ${outputs.length()} Transactions" , " ${SimulatorPlugin .onchain(listFunds)} sat" )
289
- ), null
314
+ ),
315
+ null
290
316
)
291
317
}
292
318
}
@@ -335,17 +361,16 @@ class MainActivity : UriResultActivity() {
335
361
doAsync {
336
362
try {
337
363
Archive .uncompressXZ(tarFile, rootDir())
338
- } catch (ex: Exception ) {
364
+ } catch (ex: Exception ) {
339
365
Log .e(TAG , " Error during uncompressXZ operation %s" .format(ex.localizedMessage))
340
366
runOnUiThread {
341
367
UI .snackBar(this @MainActivity, " Error During download lightning node" )
342
368
}
343
- }finally {
369
+ } finally {
344
370
runOnUiThread {
345
371
powerOff()
346
372
}
347
373
}
348
-
349
374
}
350
375
} else {
351
376
statusText.text =
@@ -358,7 +383,7 @@ class MainActivity : UriResultActivity() {
358
383
private fun powerOff () {
359
384
contentMainOn.visibility = View .GONE
360
385
contentMainOff.visibility = View .VISIBLE
361
- // val release = getPreferences(Context.MODE_PRIVATE).getString("RELEASE", "")
386
+ // val release = getPreferences(Context.MODE_PRIVATE).getString("RELEASE", "")
362
387
versionText.text = " Version: ${BuildConfig .VERSION_NAME } - ${Archive .RELEASE } "
363
388
statusText.text = " Offline. Rub the lamp to turn on."
364
389
powerImageView.off()
@@ -388,7 +413,7 @@ class MainActivity : UriResultActivity() {
388
413
title = alias
389
414
powerImageView.on()
390
415
val delta = blockcount - blockheight
391
- syncText.text = if (delta > 0 ) " Syncing blocks -${ delta} " else " "
416
+ syncText.text = if (delta > 0 ) " Syncing blocks -$delta " else " "
392
417
}
393
418
} catch (e: Exception ) {
394
419
log.info(" ---" + e.localizedMessage + " ---" )
@@ -636,7 +661,7 @@ class MainActivity : UriResultActivity() {
636
661
637
662
private val notificationReceiver = object : BroadcastReceiver () {
638
663
// I can create a mediator that I can use to call all method inside the
639
- // lightning-cli and return a json if the answer i ok or I throw an execeptions
664
+ // lightning-cli and return a json if the answer i ok or I throw an execeptions
640
665
641
666
override fun onReceive (context : Context ? , intent : Intent ? ) {
642
667
Log .d(TAG , " onReceive action ${intent?.action} " )
@@ -650,7 +675,7 @@ class MainActivity : UriResultActivity() {
650
675
NewBlockHandler .NOTIFICATION -> runOnUiThread {
651
676
val blockheight = intent.getIntExtra(" height" , 0 )
652
677
val delta = blockcount - blockheight
653
- statusText.text = if (delta > 0 ) " Syncing blocks -${ delta} " else " "
678
+ statusText.text = if (delta > 0 ) " Syncing blocks -$delta " else " "
654
679
}
655
680
BrokenStatus .NOTIFICATION -> runOnUiThread {
656
681
val message = intent.getStringExtra(" message" )
@@ -662,7 +687,7 @@ class MainActivity : UriResultActivity() {
662
687
NewTransaction .NOTIFICATION , NewChannelPayment .NOTIFICATION , PaidInvoice .NOTIFICATION -> doAsync {
663
688
updateBalanceView(context)
664
689
}
665
- NodeUpHandler .NOTIFICATION -> {
690
+ NodeUpHandler .NOTIFICATION -> {
666
691
isRunning = true
667
692
}
668
693
}
0 commit comments