Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
E
echo-adr-Deprecated
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
echo
echo-adr-Deprecated
Commits
074261f1
Commit
074261f1
authored
Jul 31, 2020
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
链接新服务器
parent
9c7db5a6
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
55 additions
and
53 deletions
+55
-53
CommonRes.java
app/src/main/java/com/virjar/echo/adr/bean/CommonRes.java
+21
-0
Result.java
app/src/main/java/com/virjar/echo/adr/bean/Result.java
+0
-21
APIServices.java
app/src/main/java/com/virjar/echo/adr/repo/APIServices.java
+2
-0
EchoConfig.java
app/src/main/java/com/virjar/echo/adr/repo/EchoConfig.java
+1
-1
UserApi.java
app/src/main/java/com/virjar/echo/adr/repo/UserApi.java
+8
-8
LogFragment.java
app/src/main/java/com/virjar/echo/adr/ui/LogFragment.java
+7
-7
LoginActivity.java
app/src/main/java/com/virjar/echo/adr/ui/LoginActivity.java
+15
-15
strings.xml
app/src/main/res/values/strings.xml
+1
-1
No files found.
app/src/main/java/com/virjar/echo/adr/bean/CommonRes.java
0 → 100644
View file @
074261f1
package
com
.
virjar
.
echo
.
adr
.
bean
;
import
lombok.Data
;
@Data
public
class
CommonRes
<
T
>
{
private
int
status
=
statusOK
;
private
String
message
;
private
T
data
;
private
String
token
;
public
static
final
int
statusOK
=
0
;
public
static
final
int
statusError
=
-
1
;
public
static
final
int
statusNeedLogin
=
-
2
;
public
static
final
int
statusLoginExpire
=
-
3
;
public
boolean
isOk
()
{
return
status
==
statusOK
;
}
}
app/src/main/java/com/virjar/echo/adr/bean/Result.java
deleted
100644 → 0
View file @
9c7db5a6
package
com
.
virjar
.
echo
.
adr
.
bean
;
import
lombok.Data
;
@Data
public
class
Result
<
O
>
{
public
static
final
int
OK
=
200
;
public
static
final
int
SERVER_ERROR
=
500
;
public
static
final
int
CLIENT_ERROR
=
400
;
public
static
final
int
NOT_FOUND
=
404
;
public
static
final
int
AUTH_FAIL
=
403
;
private
O
data
;
private
int
code
;
private
String
errorMessage
;
public
boolean
isOk
()
{
return
code
==
OK
;
}
}
app/src/main/java/com/virjar/echo/adr/repo/APIServices.java
View file @
074261f1
...
...
@@ -24,6 +24,8 @@ public class APIServices {
private
static
OkHttpClient
createInterceptedOkHttp
()
{
OkHttpClient
.
Builder
builder
=
new
OkHttpClient
.
Builder
();
// builder.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.168.0.2", 8888)));
builder
.
addInterceptor
(
new
Interceptor
()
{
@Override
public
Response
intercept
(
Chain
chain
)
throws
IOException
{
...
...
app/src/main/java/com/virjar/echo/adr/repo/EchoConfig.java
View file @
074261f1
...
...
@@ -17,7 +17,7 @@ public class EchoConfig {
private
static
String
defaultServerHost
;
private
static
int
defaultServerPort
;
private
static
final
String
defaultApiURL
=
"http://echo.virjar.com/"
;
private
static
final
String
defaultApiURL
=
"http://echo
new
.virjar.com/"
;
private
static
final
String
loginTokenKey
=
"loginToken"
;
private
static
final
String
userNameKey
=
"userName"
;
private
static
final
String
userPasswordKey
=
"password"
;
...
...
app/src/main/java/com/virjar/echo/adr/repo/UserApi.java
View file @
074261f1
package
com
.
virjar
.
echo
.
adr
.
repo
;
import
com.virjar.echo.adr.bean.
Result
;
import
com.virjar.echo.adr.bean.
CommonRes
;
import
com.virjar.echo.adr.bean.UserInfo
;
import
retrofit2.Call
;
...
...
@@ -11,16 +11,16 @@ import retrofit2.http.POST;
import
retrofit2.http.Query
;
public
interface
UserApi
{
@GET
(
"api/user
/userInfo
"
)
Call
<
Result
<
UserInfo
>>
loginWithToken
();
@GET
(
"api/user
-info/userMode
"
)
Call
<
CommonRes
<
UserInfo
>>
loginWithToken
();
@FormUrlEncoded
@POST
(
"api/user/login"
)
Call
<
Result
<
UserInfo
>>
loginWithUsername
(
@Field
(
"userName"
)
String
userName
,
@Field
(
"password"
)
String
password
);
@POST
(
"api/user
-info
/login"
)
Call
<
CommonRes
<
UserInfo
>>
loginWithUsername
(
@Field
(
"userName"
)
String
userName
,
@Field
(
"password"
)
String
password
);
@GET
(
"api/user/queryClientMapping"
)
Call
<
Result
<
Integer
>>
getClientMappingPort
(
@Query
(
"clientId"
)
String
clientId
);
@GET
(
"api/user
-info
/queryClientMapping"
)
Call
<
CommonRes
<
Integer
>>
getClientMappingPort
(
@Query
(
"clientId"
)
String
clientId
);
}
app/src/main/java/com/virjar/echo/adr/ui/LogFragment.java
View file @
074261f1
...
...
@@ -13,7 +13,7 @@ import androidx.annotation.Nullable;
import
androidx.fragment.app.Fragment
;
import
com.virjar.echo.adr.R
;
import
com.virjar.echo.adr.bean.
Result
;
import
com.virjar.echo.adr.bean.
CommonRes
;
import
com.virjar.echo.adr.component.LogServices
;
import
com.virjar.echo.adr.repo.APIServices
;
import
com.virjar.echo.adr.repo.EchoConfig
;
...
...
@@ -52,11 +52,11 @@ public class LogFragment extends Fragment {
private
void
updateClientId
()
{
APIServices
.
userApi
.
getClientMappingPort
(
EchoConfig
.
getClientId
()
).
enqueue
(
new
Callback
<
Result
<
Integer
>>()
{
).
enqueue
(
new
Callback
<
CommonRes
<
Integer
>>()
{
@Override
public
void
onResponse
(
Call
<
Result
<
Integer
>>
call
,
Response
<
Result
<
Integer
>>
response
)
{
final
Result
<
Integer
>
result
=
response
.
body
();
if
(!
result
.
isOk
())
{
public
void
onResponse
(
Call
<
CommonRes
<
Integer
>>
call
,
Response
<
CommonRes
<
Integer
>>
response
)
{
final
CommonRes
<
Integer
>
commonRes
=
response
.
body
();
if
(!
commonRes
.
isOk
())
{
new
Handler
(
Looper
.
getMainLooper
())
.
postDelayed
(
new
Runnable
()
{
@Override
...
...
@@ -71,13 +71,13 @@ public class LogFragment extends Fragment {
new
Handler
(
Looper
.
getMainLooper
()).
post
(
new
Runnable
()
{
@Override
public
void
run
()
{
mappingView
.
setText
(
EchoConfig
.
getEchoServer
()
+
":"
+
result
.
getData
());
mappingView
.
setText
(
EchoConfig
.
getEchoServer
()
+
":"
+
commonRes
.
getData
());
}
});
}
@Override
public
void
onFailure
(
Call
<
Result
<
Integer
>>
call
,
Throwable
t
)
{
public
void
onFailure
(
Call
<
CommonRes
<
Integer
>>
call
,
Throwable
t
)
{
EchoLogger
.
getLogger
().
error
(
"can not get mapping info"
,
t
);
new
Handler
(
Looper
.
getMainLooper
())
.
postDelayed
(
new
Runnable
()
{
...
...
app/src/main/java/com/virjar/echo/adr/ui/LoginActivity.java
View file @
074261f1
...
...
@@ -14,7 +14,7 @@ import android.widget.Toast;
import
androidx.appcompat.app.AppCompatActivity
;
import
com.virjar.echo.adr.R
;
import
com.virjar.echo.adr.bean.
Result
;
import
com.virjar.echo.adr.bean.
CommonRes
;
import
com.virjar.echo.adr.bean.UserInfo
;
import
com.virjar.echo.adr.repo.APIServices
;
import
com.virjar.echo.adr.repo.EchoConfig
;
...
...
@@ -83,13 +83,13 @@ public class LoginActivity extends AppCompatActivity {
autoLoginWithUserName
();
return
;
}
Call
<
Result
<
UserInfo
>>
loginResponse
=
APIServices
.
userApi
.
loginWithToken
();
loginResponse
.
enqueue
(
new
Callback
<
Result
<
UserInfo
>>()
{
Call
<
CommonRes
<
UserInfo
>>
loginResponse
=
APIServices
.
userApi
.
loginWithToken
();
loginResponse
.
enqueue
(
new
Callback
<
CommonRes
<
UserInfo
>>()
{
@Override
public
void
onResponse
(
Call
<
Result
<
UserInfo
>>
call
,
Response
<
Result
<
UserInfo
>>
response
)
{
Result
<
UserInfo
>
body
=
response
.
body
();
public
void
onResponse
(
Call
<
CommonRes
<
UserInfo
>>
call
,
Response
<
CommonRes
<
UserInfo
>>
response
)
{
CommonRes
<
UserInfo
>
body
=
response
.
body
();
if
(!
body
.
isOk
())
{
EchoLogger
.
getLogger
().
info
(
"auto login with token failed: "
+
body
.
get
Error
Message
());
EchoLogger
.
getLogger
().
info
(
"auto login with token failed: "
+
body
.
getMessage
());
autoLoginWithUserName
();
}
else
{
EchoLogger
.
getLogger
().
info
(
"auto login with token success"
);
...
...
@@ -98,7 +98,7 @@ public class LoginActivity extends AppCompatActivity {
}
@Override
public
void
onFailure
(
Call
<
Result
<
UserInfo
>>
call
,
Throwable
t
)
{
public
void
onFailure
(
Call
<
CommonRes
<
UserInfo
>>
call
,
Throwable
t
)
{
EchoLogger
.
getLogger
().
error
(
"auto login with token failed"
,
t
);
autoLoginWithUserName
();
}
...
...
@@ -120,26 +120,26 @@ public class LoginActivity extends AppCompatActivity {
buttonLogin
.
setClickable
(
false
);
APIServices
.
userApi
.
loginWithUsername
(
username
,
password
)
.
enqueue
(
new
Callback
<
Result
<
UserInfo
>>()
{
.
enqueue
(
new
Callback
<
CommonRes
<
UserInfo
>>()
{
@Override
public
void
onResponse
(
Call
<
Result
<
UserInfo
>>
call
,
Response
<
Result
<
UserInfo
>>
response
)
{
public
void
onResponse
(
Call
<
CommonRes
<
UserInfo
>>
call
,
Response
<
CommonRes
<
UserInfo
>>
response
)
{
buttonLogin
.
setClickable
(
true
);
final
Result
<
UserInfo
>
result
=
response
.
body
();
if
(!
result
.
isOk
())
{
EchoLogger
.
getLogger
().
error
(
"login failed:"
+
result
.
getError
Message
());
final
CommonRes
<
UserInfo
>
commonRes
=
response
.
body
();
if
(!
commonRes
.
isOk
())
{
EchoLogger
.
getLogger
().
error
(
"login failed:"
+
commonRes
.
get
Message
());
LoginActivity
.
this
.
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
Toast
.
makeText
(
LoginActivity
.
this
,
result
.
getError
Message
(),
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
LoginActivity
.
this
,
commonRes
.
get
Message
(),
Toast
.
LENGTH_SHORT
).
show
();
}
});
return
;
}
onLoginSuccess
(
result
.
getData
());
onLoginSuccess
(
commonRes
.
getData
());
}
@Override
public
void
onFailure
(
Call
<
Result
<
UserInfo
>>
call
,
Throwable
t
)
{
public
void
onFailure
(
Call
<
CommonRes
<
UserInfo
>>
call
,
Throwable
t
)
{
buttonLogin
.
setClickable
(
true
);
EchoLogger
.
getLogger
().
error
(
"auto login with username failed"
,
t
);
}
...
...
app/src/main/res/values/strings.xml
View file @
074261f1
...
...
@@ -8,7 +8,7 @@
<!-- Messages Preferences -->
<string
name=
"server_host_title"
>
ServerHost
</string>
<string
name=
"default_server_host"
>
echo.virjar.com
</string>
<string
name=
"default_server_host"
>
echo
new
.virjar.com
</string>
<string
name=
"server_port_title"
>
ServerPort
</string>
<string
name=
"default_server_port"
>
5698
</string>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment