Skip to content

Commit 2b83a1e

Browse files
committed
added header license
1 parent 00b7701 commit 2b83a1e

File tree

4 files changed

+127
-92
lines changed

4 files changed

+127
-92
lines changed

README.md

+48-48
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
1-
# NcMonitor - Nextcloud monitoring WearOS app :watch:
2-
NcMonitor is a native [WearOS](https://wearos.google.com/#hands-free-help) application written in [Kotlin](https://kotlinlang.org/) that can be used to check the state of your [Nextcloud](https://nextcloud.com/) server. It is simple, fast and light. You have just to look up at your wrist to know if your NC instance is working properly or not.
3-
4-
<br>
5-
<p align="center">
6-
<img src="./images/login.png"
7-
alt="NcMonitor login "
8-
height="330" />
9-
</p>
10-
11-
<p align="center">
12-
<img src="./images/status.png"
13-
alt="NcMonitor status "
14-
height="325" />
15-
</p>
16-
17-
## Displayed metrics
18-
Currently this application is still under development and the information that are displayed are:
19-
20-
- CPU usage (last-minute)
21-
- RAM usage
22-
- SWAP usage
23-
- Disk free space
24-
25-
The final goal is to provide to the user more information about the Nc instance. In the future more metrics will be added.
26-
27-
Data are retrived from [Nextcloud/serverinfo](https://github.com/nextcloud/serverinfo).
28-
29-
## How to use it
30-
To use the application you have to install the application (see Project status) and then you have to log-in in your Nc server using:
31-
32-
- select your HyperText Transfer Protocol (`http` or `https`)
33-
- server URL (e.g. myserver.com)
34-
- Nextcloud username
35-
- Nextcloud password
36-
37-
## Changelog
38-
Changelog information are reported [here](https://github.com/DavideAG/NcMonitor/blob/master/CHANGELOG.md).
39-
40-
## Project status
41-
This application is in `beta` phase and is working but it is not yet released in Google Play Store.
42-
If you want to use this application you can download the `apk` in the release section of this repository or you can manually build the project.
43-
44-
## License
45-
This application is licensed under the `AGPLv3`
46-
47-
## Contact
48-
Any comment or idea about the project is appreciated. You can ping me at [davide@giorgiodavide.it](mailto:davide@giorgiodavide.it?subject=[GitHub]%20NcMonitor)
1+
# NcMonitor - Nextcloud monitoring WearOS app :watch:
2+
NcMonitor is a native [WearOS](https://wearos.google.com/#hands-free-help) application written in [Kotlin](https://kotlinlang.org/) that can be used to check the state of your [Nextcloud](https://nextcloud.com/) server. It is simple, fast and light. You have just to look up at your wrist to know if your NC instance is working properly or not.
3+
4+
<br>
5+
<p align="center">
6+
<img src="./images/login.png"
7+
alt="NcMonitor login "
8+
height="330" />
9+
</p>
10+
11+
<p align="center">
12+
<img src="./images/status.png"
13+
alt="NcMonitor status "
14+
height="325" />
15+
</p>
16+
17+
## Displayed metrics
18+
Currently this application is still under development and the information that are displayed are:
19+
20+
- CPU usage (last-minute)
21+
- RAM usage
22+
- SWAP usage
23+
- Disk free space
24+
25+
The final goal is to provide to the user more information about the Nc instance. In the future more metrics will be added.
26+
27+
Data are retrived from [Nextcloud/serverinfo](https://github.com/nextcloud/serverinfo).
28+
29+
## How to use it
30+
To use the application you have to install the application (see Project status) and then you have to log-in in your Nc server using:
31+
32+
- select your HyperText Transfer Protocol (`http` or `https`)
33+
- server URL (e.g. myserver.com)
34+
- Nextcloud username
35+
- Nextcloud password
36+
37+
## Changelog
38+
Changelog information are reported [here](https://github.com/DavideAG/NcMonitor/blob/master/CHANGELOG.md).
39+
40+
## Project status
41+
This application is in `beta` phase and is working but it is not yet released in Google Play Store.
42+
If you want to use this application you can download the `apk` in the release section of this repository or you can manually build the project.
43+
44+
## License
45+
This application is licensed under the `AGPLv3`
46+
47+
## Contact
48+
Any comment or idea about the project is appreciated. You can ping me at [davide@giorgiodavide.it](mailto:davide@giorgiodavide.it?subject=[GitHub]%20NcMonitor)

app/src/main/java/com/example/ncmonitor/LoginActivity.kt

+27-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
/*
2+
* NcMonitor WearOS application
3+
*
4+
* @author Davide Antonino Giorgio
5+
* Copyright (C) 2020 Davide Antonino Giorgio
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
9+
* License as published by the Free Software Foundation; either
10+
* version 3 of the License, or any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public
18+
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
121
package com.example.ncmonitor
222

323
import android.content.Context
@@ -6,28 +26,24 @@ import android.content.pm.PackageManager
626
import android.os.Build
727
import android.os.Bundle
828
import android.support.wearable.activity.WearableActivity
9-
import android.text.InputType
1029
import android.text.method.PasswordTransformationMethod
1130
import android.util.Log
1231
import android.view.View
13-
import android.view.inputmethod.EditorInfo
1432
import android.webkit.URLUtil
15-
import android.widget.RadioButton
1633
import android.widget.Toast
1734
import kotlinx.android.synthetic.main.activity_login.*
18-
import kotlinx.android.synthetic.main.activity_main.*
1935
import okhttp3.Credentials.basic
2036
import org.json.JSONObject
2137
import okhttp3.*
2238
import org.json.JSONException
2339
import java.io.IOException
2440

25-
2641
const val SERVERINFO_API = "ocs/v2.php/apps/serverinfo/api/v1/info?format=json"
2742
const val PERMISSION_REQUEST = 10
2843
const val PREF_KEY = "profile"
2944
const val PREF_NAME = "USER"
3045

46+
3147
class LoginActivity : WearableActivity()
3248
{
3349
var client = OkHttpClient()
@@ -57,7 +73,6 @@ class LoginActivity : WearableActivity()
5773
userJson.get("password").toString()
5874
)
5975
}
60-
6176
checkAndRequestPermissions()
6277
btn_next.setOnClickListener { onNextClicked() }
6378
}
@@ -137,7 +152,8 @@ class LoginActivity : WearableActivity()
137152
userInfo.put("username", username)
138153
userInfo.put("password", password)
139154

140-
val sharedPref = getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
155+
val sharedPref =
156+
getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
141157
with(sharedPref.edit()) {
142158
putString(PREF_KEY, userInfo.toString())
143159
apply()
@@ -181,17 +197,16 @@ class LoginActivity : WearableActivity()
181197
Log.d("inputs","ServerURL: $serverURL \ninvalid url")
182198
return
183199
}
184-
185200
if (serverURL.last() != '/') {
186201
serverURL += '/'
187202
}
188-
189203
serverURL += SERVERINFO_API
190-
191204
requestNcStatus(serverURL,
192-
nc_username_input.text.toString(), nc_password_input.text.toString())
205+
nc_username_input.text.toString(),
206+
nc_password_input.text.toString())
193207
} else {
194-
Toast.makeText(this, "All fields are mandatory", Toast.LENGTH_SHORT).show()
208+
Toast.makeText(this,
209+
"All fields are mandatory", Toast.LENGTH_SHORT).show()
195210
}
196211
}
197212

app/src/main/java/com/example/ncmonitor/MainActivity.kt

+31-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
1-
package com.example.ncmonitor
2-
3-
/**
4-
* Created by Davide Antonino Giorgio on 02-07-2020.
1+
/*
2+
* NcMonitor WearOS application
3+
*
4+
* @author Davide Antonino Giorgio
5+
* Copyright (C) 2020 Davide Antonino Giorgio
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
9+
* License as published by the Free Software Foundation; either
10+
* version 3 of the License, or any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public
18+
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
519
*/
620

7-
import android.content.pm.PackageManager
8-
import android.os.Build
21+
package com.example.ncmonitor
22+
923
import android.os.Bundle
1024
import android.support.wearable.activity.WearableActivity
1125
import android.util.Log
1226
import android.view.View
1327
import kotlinx.android.synthetic.main.activity_main.*
14-
import okhttp3.*
15-
import okhttp3.Credentials.basic
1628
import org.json.JSONException
1729
import org.json.JSONObject
18-
import java.io.IOException
19-
import kotlin.math.round
2030

2131
const val GB = 1073741824
2232
const val Byte = 1024
@@ -25,23 +35,24 @@ const val Byte = 1024
2535
const val N_CORES = 4
2636

2737

28-
class MainActivity : WearableActivity() {
38+
class MainActivity : WearableActivity()
39+
{
2940

3041
override fun onCreate(savedInstanceState: Bundle?) {
3142
super.onCreate(savedInstanceState)
3243
setContentView(R.layout.activity_main)
3344

3445
// Enables Always-on
3546
setAmbientEnabled()
36-
3747
val extras = intent.extras
3848
if (extras != null)
3949
showResults(extras.getString("response")!!)
40-
41-
//requestNcStatus()
4250
}
4351

44-
52+
/* This method shows the results retrieved from
53+
* the server. View are populated correctly.
54+
* In case of error a message is displayed
55+
*/
4556
private fun showResults(response: String)
4657
{
4758
try {
@@ -78,7 +89,6 @@ class MainActivity : WearableActivity() {
7889
updateViews(cpuLoad, ramTotal-ramFree, ramTotal,
7990
swapTotal-swapFree, swapTotal, diskFree)
8091

81-
8292
} else {
8393
cpu_layout.visibility = View.GONE
8494
ram_layout.visibility = View.GONE
@@ -87,7 +97,6 @@ class MainActivity : WearableActivity() {
8797
status_code_response_used_placeholder.text = statusCode.toString()
8898
status_message_response_placeholder.text = metaObject.getString("message")
8999
}
90-
91100
} catch (e: JSONException) {
92101
Log.d("requestNcStatus","JsonException!!")
93102
warning_icon.visibility = View.GONE
@@ -96,8 +105,13 @@ class MainActivity : WearableActivity() {
96105
}
97106
}
98107

108+
/* This method is used to format the disk usage
109+
*/
99110
fun Double.format(digits: Int) = "%.${digits}f".format(this)
100111

112+
/* This method is used to populate the views
113+
* using the information coming from the server.
114+
*/
101115
private fun updateViews(cpuLoad :Double, ramBusy :Long, ramTotal :Long, swapBusy :Long, swapTotal :Long, diskFree :Double)
102116
{
103117

@@ -109,7 +123,6 @@ class MainActivity : WearableActivity() {
109123
ram_total_placeholder.text = (ramTotal / Byte).toString()
110124
swap_used_placeholder.text = (swapBusy /Byte).toString()
111125
swap_total_placeholder.text = (swapTotal / Byte).toString()
112-
113126
disk_used_placeholder.text = (diskFree / GB).format(2)
114127
}
115128
}

app/src/main/java/com/example/ncmonitor/OkHttpRequest.kt

+21-14
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
1-
package com.example.ncmonitor
2-
3-
import android.content.Context
4-
import org.json.JSONException
5-
import org.json.JSONObject
6-
import java.io.IOException
7-
import java.nio.charset.Charset
8-
import android.app.PendingIntent.getActivity
9-
import okhttp3.*
10-
11-
/**
12-
* Created by Davide Antonino Giorgio on 02-07-2020.
1+
/*
2+
* NcMonitor WearOS application
3+
*
4+
* @author Davide Antonino Giorgio
5+
* Copyright (C) 2020 Davide Antonino Giorgio
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
9+
* License as published by the Free Software Foundation; either
10+
* version 3 of the License, or any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public
18+
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
1319
*/
1420

21+
package com.example.ncmonitor
1522

16-
import java.util.HashMap
17-
23+
import okhttp3.*
24+
import java.util.*
1825
import java.util.Map
1926

2027

0 commit comments

Comments
 (0)