Skip to content

Commit fe250a0

Browse files
committed
version 0.4.0 out
1 parent 544dfbf commit fe250a0

File tree

6 files changed

+77
-26
lines changed

6 files changed

+77
-26
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 0.4.0 (July, 9, 2020)
2+
3+
- changed loading screen
4+
- now user errors are handled correctly
5+
- added sliding server domain name in the result page
6+
- fixed network connectivity check
7+
18
## 0.3.0 (July, 8, 2020)
29

310
- radio buttons to uspport http and https

app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ android {
1111
minSdkVersion 25
1212
targetSdkVersion 29
1313
versionCode 2
14-
versionName "0.1.1"
14+
versionName "0.4.0"
1515

1616
}
1717

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

+13-11
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ package com.example.ncmonitor
2323
import android.content.Context
2424
import android.content.Intent
2525
import android.content.pm.PackageManager
26-
import android.net.ConnectivityManager
27-
import android.net.NetworkInfo
2826
import android.os.Build
2927
import android.os.Bundle
3028
import android.support.wearable.activity.WearableActivity
@@ -48,6 +46,7 @@ const val SERVERINFO_API = "ocs/v2.php/apps/serverinfo/api/v1/info?format=json"
4846
const val PERMISSION_REQUEST = 10
4947
const val PREF_KEY = "profile"
5048
const val PREF_NAME = "USER"
49+
const val OK_200 = 200
5150

5251

5352
class LoginActivity : WearableActivity()
@@ -77,6 +76,7 @@ class LoginActivity : WearableActivity()
7776
userJson.get("serverURL").toString(),
7877
userJson.get("username").toString(),
7978
userJson.get("password").toString(),
79+
userJson.get("domain").toString(),
8080
this
8181
)
8282
}
@@ -110,7 +110,7 @@ class LoginActivity : WearableActivity()
110110
{
111111
runOnUiThread {
112112
login_scrollview_layout.visibility = View.GONE
113-
progressBar.visibility = View.VISIBLE
113+
loading_layout.visibility = View.VISIBLE
114114
}
115115
}
116116

@@ -121,25 +121,26 @@ class LoginActivity : WearableActivity()
121121
{
122122
runOnUiThread {
123123
login_scrollview_layout.visibility = View.VISIBLE
124-
progressBar.visibility = View.GONE
124+
loading_layout.visibility = View.GONE
125125
}
126126
}
127127

128128
/* This method is used to navigate to the result activity
129129
* when the response comes from your NC server
130130
*/
131-
private fun navigateToResults(responseData: String)
131+
private fun navigateToResults(responseData: String, domain :String = "ServerDomain")
132132
{
133133
val intent = Intent(this, MainActivity::class.java)
134134
intent.putExtra("response", responseData)
135+
intent.putExtra("serverURL", domain)
135136
startActivity(intent)
136137
}
137138

138139
/* This method is used to request the server status to your
139-
* NC instance. Then, if the result code is 200_OK, results
140+
* NC instance. Then, if the result code is OK_200, results
140141
* are passed to the next activity.
141142
*/
142-
private fun requestNcStatus(serverURL: String, username: String, password: String, context: Context)
143+
private fun requestNcStatus(serverURL: String, username: String, password: String, domain: String, context: Context)
143144
{
144145
showProgressBar()
145146
val credentials = basic(username, password)
@@ -154,11 +155,12 @@ class LoginActivity : WearableActivity()
154155
val metaObject = responseObject.getJSONObject("meta")
155156
val statusCode = metaObject.getInt("statuscode")
156157

157-
if (statusCode == 200) {
158+
if (statusCode == OK_200) {
158159
val userInfo = JSONObject()
159160
userInfo.put("serverURL", serverURL)
160161
userInfo.put("username", username)
161162
userInfo.put("password", password)
163+
userInfo.put("domain", domain)
162164

163165
val sharedPref =
164166
getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
@@ -168,7 +170,7 @@ class LoginActivity : WearableActivity()
168170
}
169171

170172
// navigate to the next activity
171-
navigateToResults(responseData)
173+
navigateToResults(responseData, domain)
172174
// now destroying the current activity
173175
finish()
174176
} else {
@@ -190,13 +192,12 @@ class LoginActivity : WearableActivity()
190192
}
191193

192194
override fun onFailure(call: Call?, e: IOException?) {
193-
//todo: handle it showing info to the user
194195
showLoginFields()
195196
if (e != null) {
196197
runOnUiThread {
197198
Toast.makeText(
198199
context,
199-
e.message + "\nCheck your internet connectivity", Toast.LENGTH_SHORT
200+
"Error during the host resolution, check the URL or your internet connectivity", Toast.LENGTH_SHORT
200201
).show()
201202
}
202203
}
@@ -227,6 +228,7 @@ class LoginActivity : WearableActivity()
227228
requestNcStatus(serverURL,
228229
nc_username_input.text.toString(),
229230
nc_password_input.text.toString(),
231+
nc_server_input.text.toString(),
230232
this)
231233
} else {
232234
Toast.makeText(this,

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ class MainActivity : WearableActivity()
4747
setAmbientEnabled()
4848
val extras = intent.extras
4949
if (extras != null)
50-
showResults(extras.getString("response")!!)
50+
showResults(extras.getString("response")!!, extras.getString("serverURL")!!)
5151
}
5252

5353
/* This method shows the results retrieved from
5454
* the server. View are populated correctly.
5555
* In case of error a message is displayed
5656
*/
57-
private fun showResults(response: String)
57+
private fun showResults(response: String, serverURL: String)
5858
{
5959
try {
6060
val json = JSONObject(response)
@@ -71,6 +71,8 @@ class MainActivity : WearableActivity()
7171
if (statusCode == 200) {
7272
status_code_response_layout.visibility = View.GONE
7373
status_message_response_layout.visibility = View.GONE
74+
server_name_url.visibility = View.VISIBLE
75+
server_name_url.text = serverURL
7476

7577
val dataObject = responseObject.getJSONObject("data")
7678
val nextcloudObject = dataObject.getJSONObject("nextcloud")

app/src/main/res/layout/activity_login.xml

+27-10
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,34 @@
77
tools:context=".LoginActivity"
88
android:background="@color/black">
99

10-
<ProgressBar
11-
android:id="@+id/progressBar"
12-
style="?android:attr/progressBarStyleLarge"
13-
android:layout_width="wrap_content"
14-
android:layout_height="wrap_content"
10+
<androidx.constraintlayout.widget.ConstraintLayout
11+
android:id="@+id/loading_layout"
12+
android:layout_width="match_parent"
13+
android:layout_height="match_parent"
14+
android:padding="15dp"
1515
android:visibility="gone"
16-
android:indeterminate="true"
17-
app:layout_constraintBottom_toBottomOf="parent"
18-
app:layout_constraintEnd_toEndOf="parent"
19-
app:layout_constraintStart_toStartOf="parent"
20-
app:layout_constraintTop_toTopOf="parent" />
16+
>
17+
18+
<ImageView
19+
android:id="@+id/logo_loading"
20+
android:layout_width="wrap_content"
21+
android:layout_height="wrap_content"
22+
android:src="@mipmap/ic_launcher"
23+
app:layout_constraintEnd_toEndOf="parent"
24+
app:layout_constraintStart_toStartOf="parent"
25+
app:layout_constraintTop_toTopOf="parent" />
26+
27+
<ProgressBar
28+
android:id="@+id/progressBar"
29+
style="?android:attr/progressBarStyleLarge"
30+
android:layout_width="wrap_content"
31+
android:layout_height="wrap_content"
32+
android:indeterminate="true"
33+
app:layout_constraintBottom_toBottomOf="parent"
34+
app:layout_constraintEnd_toEndOf="parent"
35+
app:layout_constraintStart_toStartOf="parent"
36+
app:layout_constraintTop_toBottomOf="@+id/logo_loading"/>
37+
</androidx.constraintlayout.widget.ConstraintLayout>
2138

2239
<ScrollView
2340
android:id="@+id/login_scrollview_layout"

app/src/main/res/layout/activity_main.xml

+25-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<androidx.constraintlayout.widget.ConstraintLayout
2121
android:layout_width="match_parent"
2222
android:layout_height="wrap_content"
23-
android:padding="16dp">
23+
android:padding="15dp">
2424

2525
<FrameLayout
2626
android:id="@+id/status_layout"
@@ -62,14 +62,37 @@
6262
app:layout_constraintStart_toStartOf="parent"
6363
app:layout_constraintTop_toBottomOf="@+id/status_layout">
6464

65+
<TextView
66+
android:id="@+id/server_name_url"
67+
android:layout_width="0dp"
68+
android:layout_height="wrap_content"
69+
android:paddingBottom="2dp"
70+
android:paddingTop="5dp"
71+
app:layout_constraintStart_toStartOf="parent"
72+
app:layout_constraintEnd_toEndOf="parent"
73+
app:layout_constraintTop_toTopOf="parent"
74+
app:layout_constraintBottom_toTopOf="@+id/cpu_layout"
75+
android:textAppearance="@android:style/TextAppearance.Material.Medium"
76+
android:textStyle="bold"
77+
android:textColor="#3b7eca"
78+
android:gravity="center"
79+
android:visibility="gone"
80+
android:singleLine="true"
81+
android:ellipsize="marquee"
82+
android:marqueeRepeatLimit ="marquee_forever"
83+
android:focusable="true"
84+
android:focusableInTouchMode="true"
85+
android:scrollHorizontally="true"
86+
android:text="ServerURL"/>
87+
6588
<LinearLayout
6689
android:id="@+id/cpu_layout"
6790
android:layout_width="wrap_content"
6891
android:layout_height="wrap_content"
6992
android:orientation="horizontal"
7093
android:paddingTop="8dp"
7194
app:layout_constraintStart_toStartOf="parent"
72-
app:layout_constraintTop_toTopOf="parent">
95+
app:layout_constraintTop_toBottomOf="@+id/server_name_url">
7396

7497
<TextView
7598
android:id="@+id/cpu_text_view"

0 commit comments

Comments
 (0)