@@ -23,8 +23,6 @@ package com.example.ncmonitor
23
23
import android.content.Context
24
24
import android.content.Intent
25
25
import android.content.pm.PackageManager
26
- import android.net.ConnectivityManager
27
- import android.net.NetworkInfo
28
26
import android.os.Build
29
27
import android.os.Bundle
30
28
import android.support.wearable.activity.WearableActivity
@@ -48,6 +46,7 @@ const val SERVERINFO_API = "ocs/v2.php/apps/serverinfo/api/v1/info?format=json"
48
46
const val PERMISSION_REQUEST = 10
49
47
const val PREF_KEY = " profile"
50
48
const val PREF_NAME = " USER"
49
+ const val OK_200 = 200
51
50
52
51
53
52
class LoginActivity : WearableActivity ()
@@ -77,6 +76,7 @@ class LoginActivity : WearableActivity()
77
76
userJson.get(" serverURL" ).toString(),
78
77
userJson.get(" username" ).toString(),
79
78
userJson.get(" password" ).toString(),
79
+ userJson.get(" domain" ).toString(),
80
80
this
81
81
)
82
82
}
@@ -110,7 +110,7 @@ class LoginActivity : WearableActivity()
110
110
{
111
111
runOnUiThread {
112
112
login_scrollview_layout.visibility = View .GONE
113
- progressBar .visibility = View .VISIBLE
113
+ loading_layout .visibility = View .VISIBLE
114
114
}
115
115
}
116
116
@@ -121,25 +121,26 @@ class LoginActivity : WearableActivity()
121
121
{
122
122
runOnUiThread {
123
123
login_scrollview_layout.visibility = View .VISIBLE
124
- progressBar .visibility = View .GONE
124
+ loading_layout .visibility = View .GONE
125
125
}
126
126
}
127
127
128
128
/* This method is used to navigate to the result activity
129
129
* when the response comes from your NC server
130
130
*/
131
- private fun navigateToResults (responseData : String )
131
+ private fun navigateToResults (responseData : String , domain : String = " ServerDomain " )
132
132
{
133
133
val intent = Intent (this , MainActivity ::class .java)
134
134
intent.putExtra(" response" , responseData)
135
+ intent.putExtra(" serverURL" , domain)
135
136
startActivity(intent)
136
137
}
137
138
138
139
/* 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
140
141
* are passed to the next activity.
141
142
*/
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 )
143
144
{
144
145
showProgressBar()
145
146
val credentials = basic(username, password)
@@ -154,11 +155,12 @@ class LoginActivity : WearableActivity()
154
155
val metaObject = responseObject.getJSONObject(" meta" )
155
156
val statusCode = metaObject.getInt(" statuscode" )
156
157
157
- if (statusCode == 200 ) {
158
+ if (statusCode == OK_200 ) {
158
159
val userInfo = JSONObject ()
159
160
userInfo.put(" serverURL" , serverURL)
160
161
userInfo.put(" username" , username)
161
162
userInfo.put(" password" , password)
163
+ userInfo.put(" domain" , domain)
162
164
163
165
val sharedPref =
164
166
getSharedPreferences(PREF_NAME , Context .MODE_PRIVATE )
@@ -168,7 +170,7 @@ class LoginActivity : WearableActivity()
168
170
}
169
171
170
172
// navigate to the next activity
171
- navigateToResults(responseData)
173
+ navigateToResults(responseData, domain )
172
174
// now destroying the current activity
173
175
finish()
174
176
} else {
@@ -190,13 +192,12 @@ class LoginActivity : WearableActivity()
190
192
}
191
193
192
194
override fun onFailure (call : Call ? , e : IOException ? ) {
193
- // todo: handle it showing info to the user
194
195
showLoginFields()
195
196
if (e != null ) {
196
197
runOnUiThread {
197
198
Toast .makeText(
198
199
context,
199
- e.message + " \n Check your internet connectivity" , Toast .LENGTH_SHORT
200
+ " Error during the host resolution, check the URL or your internet connectivity" , Toast .LENGTH_SHORT
200
201
).show()
201
202
}
202
203
}
@@ -227,6 +228,7 @@ class LoginActivity : WearableActivity()
227
228
requestNcStatus(serverURL,
228
229
nc_username_input.text.toString(),
229
230
nc_password_input.text.toString(),
231
+ nc_server_input.text.toString(),
230
232
this )
231
233
} else {
232
234
Toast .makeText(this ,
0 commit comments