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
38a4fb19
Commit
38a4fb19
authored
Jul 20, 2020
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
9f80a6ed
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
15 deletions
+34
-15
build.gradle
app/build.gradle
+2
-1
APIServices.java
app/src/main/java/com/virjar/echo/adr/repo/APIServices.java
+1
-1
UserApi.java
app/src/main/java/com/virjar/echo/adr/repo/UserApi.java
+3
-1
LoginActivity.java
app/src/main/java/com/virjar/echo/adr/ui/LoginActivity.java
+28
-12
No files found.
app/build.gradle
View file @
38a4fb19
...
...
@@ -52,7 +52,8 @@ dependencies {
implementation
'com.squareup.retrofit2:retrofit:2.0.2'
implementation
'com.squareup.retrofit2:converter-gson:2.0.2'
implementation
'com.google.code.gson:gson:2.8.5'
implementation
'com.squareup.retrofit2:adapter-rxjava:2.0.2'
//引入netty之后,class直接就爆炸了。考虑实现API精简
implementation
'com.android.support:multidex:1.0.3'
...
...
app/src/main/java/com/virjar/echo/adr/repo/APIServices.java
View file @
38a4fb19
...
...
@@ -16,7 +16,7 @@ public class APIServices {
private
static
Retrofit
retrofit
=
new
Retrofit
.
Builder
()
.
baseUrl
(
EchoConfig
.
getApiURL
())
.
callFactory
(
createInterceptedOkHttp
())
.
addConverterFactory
(
GsonConverterFactory
.
create
())
//
.addConverterFactory(GsonConverterFactory.create())
.
addCallAdapterFactory
(
RxJavaCallAdapterFactory
.
create
())
.
build
();
...
...
app/src/main/java/com/virjar/echo/adr/repo/UserApi.java
View file @
38a4fb19
package
com
.
virjar
.
echo
.
adr
.
repo
;
import
com.google.gson.JsonObject
;
import
retrofit2.Call
;
import
retrofit2.http.GET
;
public
interface
UserApi
{
@GET
(
"api/user/userInfo"
)
Call
<
?
>
loginWithToken
();
Call
<
JsonObject
>
loginWithToken
();
}
app/src/main/java/com/virjar/echo/adr/ui/LoginActivity.java
View file @
38a4fb19
...
...
@@ -2,6 +2,7 @@ package com.virjar.echo.adr.ui;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.text.TextUtils
;
import
android.view.View
;
import
android.view.Window
;
import
android.view.WindowManager
;
...
...
@@ -11,7 +12,14 @@ import android.widget.TextView;
import
androidx.appcompat.app.AppCompatActivity
;
import
com.google.gson.JsonObject
;
import
com.virjar.echo.adr.R
;
import
com.virjar.echo.adr.repo.APIServices
;
import
com.virjar.echo.adr.repo.EchoConfig
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
public
class
LoginActivity
extends
AppCompatActivity
{
...
...
@@ -42,18 +50,26 @@ public class LoginActivity extends AppCompatActivity {
}
private
void
autoLoginWithToken
()
{
// String token = EchoConfig.getToken();
// if (TextUtils.isEmpty(token)) {
// autoLoginWithUserName();
// return;
// }
// return new Request.Builder()
// .get()
// .url(url)
// .addHeader("Connection","close")
// .build();
//
// HttpClient.getClient().newCall()
String
token
=
EchoConfig
.
getToken
();
if
(
TextUtils
.
isEmpty
(
token
))
{
autoLoginWithUserName
();
return
;
}
Call
<
JsonObject
>
loginResponse
=
APIServices
.
userApi
.
loginWithToken
();
loginResponse
.
enqueue
(
new
Callback
<
JsonObject
>()
{
@Override
public
void
onResponse
(
Call
<
JsonObject
>
call
,
Response
<
JsonObject
>
response
)
{
JsonObject
body
=
response
.
body
();
if
(!
body
.
get
(
"ok"
).
getAsBoolean
())
{
autoLoginWithUserName
();
}
}
@Override
public
void
onFailure
(
Call
<
JsonObject
>
call
,
Throwable
t
)
{
autoLoginWithUserName
();
}
});
}
private
void
autoLoginWithUserName
()
{
...
...
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