Skip to content

Commit

Permalink
Add kotlin linter plugin to and update all the code
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenzopalazzo authored Jun 10, 2021
2 parents baff387 + 421c29d commit 41e8e73
Show file tree
Hide file tree
Showing 48 changed files with 426 additions and 311 deletions.
25 changes: 25 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Note that in this case 'import-ordering' rule will be active and 'indent' will be disabled
[api/*.{kt,kts}]
root = true
disabled_rules=indent

# Comma-separated list of rules to disable (Since 0.34.0)
# Note that rules in any ruleset other than the standard ruleset will need to be prefixed
# by the ruleset identifier.
disabled_rules=no-wildcard-imports,experimental:annotation,my-custom-ruleset

# Defines the imports layout. The layout can be composed by the following symbols:
# "*" - wildcard. There must be at least one entry of a single wildcard to match all other imports. Matches anything after a specified symbol/import as well.
# "|" - blank line. Supports only single blank lines between imports. No blank line is allowed in the beginning or end of the layout.
# "^" - alias import, e.g. "^android.*" will match all android alias imports, "^" will match all other alias imports.
# import paths - these can be full paths, e.g. "java.util.List.*" as well as wildcard paths, e.g. "kotlin.**"
# Examples (we use ij_kotlin_imports_layout to set an imports layout for both ktlint and IDEA via a single property):
# ij_kotlin_imports_layout=* # alphabetical with capital letters before lower case letters (e.g. Z before a), no blank lines
# ij_kotlin_imports_layout=*,java.**,javax.**,kotlin.**,^ # default IntelliJ IDEA style, same as alphabetical, but with "java", "javax", "kotlin" and alias imports in the end of the imports list
# ij_kotlin_imports_layout=android.**,|,^org.junit.**,kotlin.io.Closeable.*,|,*,^ # custom imports layout

# According to https://kotlinlang.org/docs/reference/coding-conventions.html#names-for-test-methods it is acceptable to write method names
# in natural language. When using natural language, the description tends to be longer. Allow lines containing an identifier between
# backticks to be longer than the maximum line length. (Since 0.41.0)
[**/test/**.kt]
ktlint_ignore_back_ticked_identifier=true
2 changes: 2 additions & 0 deletions .github/workflows/android-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Check koltin formatting
run: bash ./gradlew lintKotlin
- name: Build debug APK
run: bash ./gradlew assembleDebug --stacktrace
- name: Upload APK
Expand Down
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@

[![build](https://github.com/clightning4j/lamp/workflows/android-master/badge.svg)](https://github.com/clightning4j/lamp/actions)
[![release](https://github.com/clightning4j/lamp/workflows/release/badge.svg)](https://github.com/clightning4j/lamp/actions)

[![MIT license](https://img.shields.io/github/license/clightning4j/lamp)](https://github.com/clightning4j/lamp/blob/master/LICENSE)


> This is an experimenting lightning wallet. Use it on testnet or only with amounts you can afford to lose on mainnet.
Touch the lamp to download and run c-lightning from cross-compiled binaries for Android are available [here](https://github.com/clightning4j/lightning_ndk/releases).

![screenshot1](doc/img/Screen2.png)
![screenshot2](doc/img/Screen1.png)
![screenshot3](doc/img/Screen3.png)

<span>
<img src="doc/img/Screen1.png" width="230" height="350" />
<img src="doc/img/Screen2.png" width="230" height="350" />
<img src="doc/img/Screen3.png" width="230" height="350" />
</span>

## Bitcoin Setup

Expand Down Expand Up @@ -56,6 +56,23 @@ Read the following instructions at [Tor on clightning](https://lightning.readthe
## Building

* [in Linux using cmdline tools](doc/cmdline-tools-setup.md)

## Store Supported
[<img src="https://gitlab.com/IzzyOnDroid/repo/-/raw/master/assets/IzzyOnDroid.png" width="200" height="80" />](https://apt.izzysoft.de/fdroid/index/apk/com.lvaccaro.lamp)



## Code Style
[![ktlint](https://img.shields.io/badge/code%20style-%E2%9D%A4-FF4081.svg)](https://ktlint.github.io/)

> We live in a world where robots can drive a car, so we shouldn't just write code, we should write elegant code.
This repository use [ktlint](https://github.com/pinterest/ktlint) to maintains the code of the repository elegant, so
before submit the code check the Kotlin format with the following command on the root of the directory

```bash
./gradlew formatKotlin
```

## References

Expand Down
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: "org.jmailen.kotlinter"

android {
compileSdkVersion 28
Expand All @@ -9,8 +10,8 @@ android {
applicationId "com.lvaccaro.lamp"
minSdkVersion 24
targetSdkVersion 28
versionCode 34
versionName "3.4"
versionCode 35
versionName "3.5"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package com.lvaccaro.lamp

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.runner.AndroidJUnit4

import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/java/com/lvaccaro/lamp/LightningCli.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ class LightningCli {
String.format("%s/cli/%s", binaryDir.canonicalPath, command),
String.format("--network=%s", network),
String.format("--lightning-dir=%s", lightningDir.path),
String.format("--%s", if (json == true) "json" else "raw" ))
String.format("--%s", if (json == true) "json" else "raw")
)

val pb = ProcessBuilder((args + options).asList())
pb.directory(binaryDir)
//pb.redirectErrorStream(true)
// pb.redirectErrorStream(true)

val process = pb.start()
val code = process.waitFor()
Expand All @@ -38,15 +39,15 @@ class LightningCli {
val input = process.inputStream.toText()
log.info(error)
log.info(input)
throw Exception(if(!error.isEmpty()) error else input)
throw Exception(if (!error.isEmpty()) error else input)
}
return process.inputStream
}
}

// extension to convert inputStream in text
fun InputStream.toText(): String {
val reader = bufferedReader()
val reader = bufferedReader()
val builder = StringBuilder()
var line = reader.readLine()
while (line != null) {
Expand All @@ -71,4 +72,4 @@ fun Context.rootDir(): File {
return noBackupFilesDir
}
return filesDir
}
}
67 changes: 46 additions & 21 deletions app/src/main/java/com/lvaccaro/lamp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import android.Manifest
import android.app.Activity
import android.app.ActivityManager
import android.app.DownloadManager
import android.content.*
import android.content.BroadcastReceiver
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
Expand All @@ -25,28 +29,48 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.lvaccaro.lamp.activities.*
import com.lvaccaro.lamp.activities.BuildInvoiceActivity
import com.lvaccaro.lamp.activities.ChannelsActivity
import com.lvaccaro.lamp.activities.ConsoleActivity
import com.lvaccaro.lamp.activities.LogActivity
import com.lvaccaro.lamp.activities.ScanActivity
import com.lvaccaro.lamp.activities.SendActivity
import com.lvaccaro.lamp.activities.SettingsActivity
import com.lvaccaro.lamp.activities.UriResultActivity
import com.lvaccaro.lamp.adapters.Balance
import com.lvaccaro.lamp.adapters.BalanceAdapter
import com.lvaccaro.lamp.fragments.PeerInfoFragment
import com.lvaccaro.lamp.fragments.WithdrawFragment
import com.lvaccaro.lamp.handlers.*
import com.lvaccaro.lamp.handlers.BrokenStatus
import com.lvaccaro.lamp.handlers.NewBlockHandler
import com.lvaccaro.lamp.handlers.NewChannelPayment
import com.lvaccaro.lamp.handlers.NewTransaction
import com.lvaccaro.lamp.handlers.NodeUpHandler
import com.lvaccaro.lamp.handlers.PaidInvoice
import com.lvaccaro.lamp.handlers.ShutdownNode
import com.lvaccaro.lamp.services.LightningService
import com.lvaccaro.lamp.services.TorService
import com.lvaccaro.lamp.utils.Archive
import com.lvaccaro.lamp.utils.SimulatorPlugin
import com.lvaccaro.lamp.utils.UI
import com.lvaccaro.lamp.views.HistoryBottomSheet
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.content_main_off.*
import kotlinx.android.synthetic.main.content_main_on.*
import kotlinx.android.synthetic.main.fragment_history.*
import kotlinx.android.synthetic.main.activity_main.contentMainOff
import kotlinx.android.synthetic.main.activity_main.contentMainOn
import kotlinx.android.synthetic.main.content_main_off.powerImageView
import kotlinx.android.synthetic.main.content_main_off.statusText
import kotlinx.android.synthetic.main.content_main_off.versionText
import kotlinx.android.synthetic.main.content_main_on.balanceText
import kotlinx.android.synthetic.main.content_main_on.floatingActionButton
import kotlinx.android.synthetic.main.content_main_on.receiveButton
import kotlinx.android.synthetic.main.content_main_on.recyclerView
import kotlinx.android.synthetic.main.content_main_on.sendButton
import kotlinx.android.synthetic.main.content_main_on.syncText
import kotlinx.android.synthetic.main.fragment_history.bottomSheet
import org.jetbrains.anko.doAsync
import org.json.JSONArray
import java.io.File
import java.util.logging.Logger


class MainActivity : UriResultActivity() {

private val REQUEST_SCAN = 102
Expand Down Expand Up @@ -178,7 +202,8 @@ class MainActivity : UriResultActivity() {

override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<String>, grantResults: IntArray
permissions: Array<String>,
grantResults: IntArray
) {
when (requestCode) {
WRITE_REQUEST_CODE -> {
Expand Down Expand Up @@ -280,13 +305,14 @@ class MainActivity : UriResultActivity() {
val peers: JSONArray = listPeers["peers"] as JSONArray

runOnUiThread {
balanceText.text = "${(SimulatorPlugin.funds(listPeers).toDouble()/1000)} sat"
balanceText.text = "${(SimulatorPlugin.funds(listPeers).toDouble() / 1000)} sat"
recyclerView.adapter = BalanceAdapter(
arrayListOf(
Balance("Spendable in channels", "${peers.length()} Peers", "${SimulatorPlugin.funds(listPeers).toDouble()/1000} sat"),
Balance("Locked in channels", "${channels.length()} Channels", "${SimulatorPlugin.offchain(listFunds).toDouble()/1000} sat"),
Balance("Spendable in channels", "${peers.length()} Peers", "${SimulatorPlugin.funds(listPeers).toDouble() / 1000} sat"),
Balance("Locked in channels", "${channels.length()} Channels", "${SimulatorPlugin.offchain(listFunds).toDouble() / 1000} sat"),
Balance("Bitcoin on chain", "${outputs.length()} Transactions", "${SimulatorPlugin.onchain(listFunds)} sat")
), null
),
null
)
}
}
Expand Down Expand Up @@ -335,17 +361,16 @@ class MainActivity : UriResultActivity() {
doAsync {
try {
Archive.uncompressXZ(tarFile, rootDir())
} catch(ex: Exception) {
} catch (ex: Exception) {
Log.e(TAG, "Error during uncompressXZ operation %s".format(ex.localizedMessage))
runOnUiThread {
UI.snackBar(this@MainActivity, "Error During download lightning node")
}
}finally {
} finally {
runOnUiThread {
powerOff()
}
}

}
} else {
statusText.text =
Expand All @@ -358,7 +383,7 @@ class MainActivity : UriResultActivity() {
private fun powerOff() {
contentMainOn.visibility = View.GONE
contentMainOff.visibility = View.VISIBLE
//val release = getPreferences(Context.MODE_PRIVATE).getString("RELEASE", "")
// val release = getPreferences(Context.MODE_PRIVATE).getString("RELEASE", "")
versionText.text = "Version: ${BuildConfig.VERSION_NAME} - ${Archive.RELEASE}"
statusText.text = "Offline. Rub the lamp to turn on."
powerImageView.off()
Expand Down Expand Up @@ -388,7 +413,7 @@ class MainActivity : UriResultActivity() {
title = alias
powerImageView.on()
val delta = blockcount - blockheight
syncText.text = if (delta > 0) "Syncing blocks -${delta}" else ""
syncText.text = if (delta > 0) "Syncing blocks -$delta" else ""
}
} catch (e: Exception) {
log.info("---" + e.localizedMessage + "---")
Expand Down Expand Up @@ -636,7 +661,7 @@ class MainActivity : UriResultActivity() {

private val notificationReceiver = object : BroadcastReceiver() {
// I can create a mediator that I can use to call all method inside the
//lightning-cli and return a json if the answer i ok or I throw an execeptions
// lightning-cli and return a json if the answer i ok or I throw an execeptions

override fun onReceive(context: Context?, intent: Intent?) {
Log.d(TAG, "onReceive action ${intent?.action}")
Expand All @@ -650,7 +675,7 @@ class MainActivity : UriResultActivity() {
NewBlockHandler.NOTIFICATION -> runOnUiThread {
val blockheight = intent.getIntExtra("height", 0)
val delta = blockcount - blockheight
statusText.text = if (delta > 0) "Syncing blocks -${delta}" else ""
statusText.text = if (delta > 0) "Syncing blocks -$delta" else ""
}
BrokenStatus.NOTIFICATION -> runOnUiThread {
val message = intent.getStringExtra("message")
Expand All @@ -662,7 +687,7 @@ class MainActivity : UriResultActivity() {
NewTransaction.NOTIFICATION, NewChannelPayment.NOTIFICATION, PaidInvoice.NOTIFICATION -> doAsync {
updateBalanceView(context)
}
NodeUpHandler.NOTIFICATION -> {
NodeUpHandler.NOTIFICATION -> {
isRunning = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,24 @@ import com.lvaccaro.lamp.LightningCli
import com.lvaccaro.lamp.R
import com.lvaccaro.lamp.toJSONObject
import com.lvaccaro.lamp.utils.UI
import kotlinx.android.synthetic.main.activity_build_invoice.*
import kotlinx.android.synthetic.main.list_balance.view.*
import kotlinx.android.synthetic.main.list_tx.*
import kotlinx.android.synthetic.main.activity_build_invoice.balanceText
import kotlinx.android.synthetic.main.activity_build_invoice.btcButton
import kotlinx.android.synthetic.main.activity_build_invoice.btclnLayout
import kotlinx.android.synthetic.main.activity_build_invoice.copyButton
import kotlinx.android.synthetic.main.activity_build_invoice.copyShareLayout
import kotlinx.android.synthetic.main.activity_build_invoice.descriptionText
import kotlinx.android.synthetic.main.activity_build_invoice.expiredText
import kotlinx.android.synthetic.main.activity_build_invoice.expiredTitle
import kotlinx.android.synthetic.main.activity_build_invoice.labelText
import kotlinx.android.synthetic.main.activity_build_invoice.lightningButton
import kotlinx.android.synthetic.main.activity_build_invoice.qrImage
import kotlinx.android.synthetic.main.activity_build_invoice.shareButton
import org.jetbrains.anko.contentView
import org.jetbrains.anko.doAsync
import org.json.JSONObject
import java.lang.Exception
import java.text.SimpleDateFormat
import java.util.*

import java.util.Date

class BuildInvoiceActivity : AppCompatActivity() {

Expand Down Expand Up @@ -59,13 +67,15 @@ class BuildInvoiceActivity : AppCompatActivity() {

fun invoice(amount: String, label: String, description: String) {
try {
val res = cli.exec(this,
val res = cli.exec(
this,
arrayOf(
"invoice",
amount,
label,
description
), true
),
true
).toJSONObject()
runOnUiThread { showInvoice(res["bolt11"] as String) }
} catch (e: Exception) {
Expand Down
Loading

0 comments on commit 41e8e73

Please sign in to comment.