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
9f80a6ed
Commit
9f80a6ed
authored
Jul 20, 2020
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
8e95a880
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
227 additions
and
1 deletion
+227
-1
build.gradle
app/build.gradle
+4
-1
APIServices.java
app/src/main/java/com/virjar/echo/adr/repo/APIServices.java
+44
-0
EchoConfig.java
app/src/main/java/com/virjar/echo/adr/repo/EchoConfig.java
+44
-0
UserApi.java
app/src/main/java/com/virjar/echo/adr/repo/UserApi.java
+10
-0
LoginActivity.java
app/src/main/java/com/virjar/echo/adr/ui/LoginActivity.java
+20
-0
Constants.java
app/src/main/java/com/virjar/echo/adr/util/Constants.java
+5
-0
Lists.java
app/src/main/java/com/virjar/echo/adr/util/Lists.java
+92
-0
strings.xml
app/src/main/res/values/strings.xml
+2
-0
root_preferences.xml
app/src/main/res/xml/root_preferences.xml
+6
-0
No files found.
app/build.gradle
View file @
9f80a6ed
...
...
@@ -49,7 +49,10 @@ dependencies {
//compile 'com.android.support:support-v4:24.2.0'
api
project
(
':echo-lib'
)
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
0 → 100644
View file @
9f80a6ed
package
com
.
virjar
.
echo
.
adr
.
repo
;
import
android.text.TextUtils
;
import
java.io.IOException
;
import
okhttp3.Interceptor
;
import
okhttp3.OkHttpClient
;
import
okhttp3.Request
;
import
okhttp3.Response
;
import
retrofit2.Retrofit
;
import
retrofit2.adapter.rxjava.RxJavaCallAdapterFactory
;
import
retrofit2.converter.gson.GsonConverterFactory
;
public
class
APIServices
{
private
static
Retrofit
retrofit
=
new
Retrofit
.
Builder
()
.
baseUrl
(
EchoConfig
.
getApiURL
())
.
callFactory
(
createInterceptedOkHttp
())
.
addConverterFactory
(
GsonConverterFactory
.
create
())
.
addCallAdapterFactory
(
RxJavaCallAdapterFactory
.
create
())
.
build
();
public
static
UserApi
userApi
=
retrofit
.
create
(
UserApi
.
class
);
private
static
OkHttpClient
createInterceptedOkHttp
()
{
OkHttpClient
.
Builder
builder
=
new
OkHttpClient
.
Builder
();
builder
.
addInterceptor
(
new
Interceptor
()
{
@Override
public
Response
intercept
(
Chain
chain
)
throws
IOException
{
String
token
=
EchoConfig
.
getToken
();
if
(
TextUtils
.
isEmpty
(
token
))
{
Request
originalRequest
=
chain
.
request
();
return
chain
.
proceed
(
originalRequest
);
}
//自动增加登录token
Request
originalRequest
=
chain
.
request
();
Request
updateRequest
=
originalRequest
.
newBuilder
().
header
(
"Token"
,
token
).
build
();
return
chain
.
proceed
(
updateRequest
);
}
});
return
builder
.
build
();
}
}
app/src/main/java/com/virjar/echo/adr/repo/EchoConfig.java
View file @
9f80a6ed
...
...
@@ -16,6 +16,11 @@ public class EchoConfig {
private
static
String
defaultServerHost
;
private
static
int
defaultServerPort
;
private
static
final
String
defaultApiURL
=
"http://echo.virjar.com/"
;
private
static
final
String
loginTokenKey
=
"loginToken"
;
private
static
final
String
userNameKey
=
"userName"
;
private
static
final
String
userPasswordKey
=
"password"
;
public
static
void
init
(
Context
context
)
{
sharedPreferences
=
context
.
getSharedPreferences
(
configFile
,
Context
.
MODE_PRIVATE
);
...
...
@@ -23,6 +28,7 @@ public class EchoConfig {
defaultServerPort
=
Integer
.
parseInt
(
context
.
getString
(
R
.
string
.
default_server_port
));
getClientId
();
getApiURL
();
}
public
static
String
getEchoServer
()
{
...
...
@@ -43,4 +49,42 @@ public class EchoConfig {
}
return
getClientId
();
}
public
static
String
getApiURL
()
{
String
serverApiUrl
=
sharedPreferences
.
getString
(
"server_api_url"
,
""
);
if
(
TextUtils
.
isEmpty
(
serverApiUrl
))
{
serverApiUrl
=
defaultApiURL
;
sharedPreferences
.
edit
().
putString
(
"server_api_url"
,
serverApiUrl
).
apply
();
}
return
serverApiUrl
;
}
public
static
void
updateLoginToken
(
String
token
)
{
if
(
TextUtils
.
isEmpty
(
token
))
{
return
;
}
sharedPreferences
.
edit
().
putString
(
loginTokenKey
,
token
).
apply
();
}
public
static
String
getToken
()
{
return
sharedPreferences
.
getString
(
loginTokenKey
,
""
);
}
public
static
void
saveUsernameAndPassword
(
String
userName
,
String
password
)
{
SharedPreferences
.
Editor
edit
=
sharedPreferences
.
edit
();
edit
.
putString
(
userNameKey
,
userName
);
edit
.
putString
(
userPasswordKey
,
password
);
edit
.
apply
();
}
public
static
String
getUsername
()
{
return
sharedPreferences
.
getString
(
userNameKey
,
""
);
}
public
static
String
getPassword
()
{
return
sharedPreferences
.
getString
(
userPasswordKey
,
""
);
}
}
app/src/main/java/com/virjar/echo/adr/repo/UserApi.java
0 → 100644
View file @
9f80a6ed
package
com
.
virjar
.
echo
.
adr
.
repo
;
import
retrofit2.Call
;
import
retrofit2.http.GET
;
public
interface
UserApi
{
@GET
(
"api/user/userInfo"
)
Call
<?>
loginWithToken
();
}
app/src/main/java/com/virjar/echo/adr/ui/LoginActivity.java
View file @
9f80a6ed
...
...
@@ -41,6 +41,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()
}
private
void
autoLoginWithUserName
()
{
}
private
void
setupAnimation
()
{
imageView
.
setOnTouchListener
(
new
OnSwipeTouchListener
(
getApplicationContext
())
{
public
void
onSwipeTop
()
{
...
...
app/src/main/java/com/virjar/echo/adr/util/Constants.java
0 → 100644
View file @
9f80a6ed
package
com
.
virjar
.
echo
.
adr
.
util
;
public
class
Constants
{
public
static
final
String
url
=
""
;
}
app/src/main/java/com/virjar/echo/adr/util/Lists.java
0 → 100644
View file @
9f80a6ed
package
com
.
virjar
.
echo
.
adr
.
util
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.concurrent.CopyOnWriteArrayList
;
/**
* some utils migrated from guava
*/
public
class
Lists
{
public
static
<
E
>
ArrayList
<
E
>
newArrayList
(
E
...
elements
)
{
// Avoid integer overflow when a large array is passed in
int
capacity
=
computeArrayListCapacity
(
elements
.
length
);
ArrayList
<
E
>
list
=
new
ArrayList
<
E
>(
capacity
);
Collections
.
addAll
(
list
,
elements
);
return
list
;
}
static
int
computeArrayListCapacity
(
int
arraySize
)
{
return
saturatedCast
(
5L
+
arraySize
+
(
arraySize
/
10
));
}
/**
* Returns the {@code int} nearest in value to {@code value}.
*
* @param value any {@code long} value
* @return the same value cast to {@code int} if it is in the range of the
* {@code int} type, {@link Integer#MAX_VALUE} if it is too large,
* or {@link Integer#MIN_VALUE} if it is too small
*/
public
static
int
saturatedCast
(
long
value
)
{
if
(
value
>
Integer
.
MAX_VALUE
)
{
return
Integer
.
MAX_VALUE
;
}
if
(
value
<
Integer
.
MIN_VALUE
)
{
return
Integer
.
MIN_VALUE
;
}
return
(
int
)
value
;
}
public
static
<
E
>
LinkedList
<
E
>
newLinkedList
()
{
return
new
LinkedList
<
E
>();
}
static
<
T
>
Collection
<
T
>
cast
(
Iterable
<
T
>
iterable
)
{
return
(
Collection
<
T
>)
iterable
;
}
public
static
<
E
>
CopyOnWriteArrayList
<
E
>
newCopyOnWriteArrayList
(
Iterable
<?
extends
E
>
elements
)
{
// We copy elements to an ArrayList first, rather than incurring the
// quadratic cost of adding them to the COWAL directly.
Collection
<?
extends
E
>
elementsCollection
=
(
elements
instanceof
Collection
)
?
cast
(
elements
)
:
newArrayList
(
elements
);
return
new
CopyOnWriteArrayList
<
E
>(
elementsCollection
);
}
public
static
<
E
>
ArrayList
<
E
>
newArrayList
(
Iterable
<?
extends
E
>
elements
)
{
// Let ArrayList's sizing logic work, if possible
return
(
elements
instanceof
Collection
)
?
new
ArrayList
<
E
>(
cast
(
elements
))
:
newArrayList
(
elements
.
iterator
());
}
public
static
<
E
>
ArrayList
<
E
>
newArrayList
(
Iterator
<?
extends
E
>
elements
)
{
ArrayList
<
E
>
list
=
newArrayList
();
addAll
(
list
,
elements
);
return
list
;
}
public
static
<
T
>
boolean
addAll
(
Collection
<
T
>
addTo
,
Iterator
<?
extends
T
>
iterator
)
{
boolean
wasModified
=
false
;
while
(
iterator
.
hasNext
())
{
wasModified
|=
addTo
.
add
(
iterator
.
next
());
}
return
wasModified
;
}
public
static
<
T
>
List
<
T
>
newArrayListWithCapacity
(
int
length
)
{
return
new
ArrayList
<>(
length
);
}
}
app/src/main/res/values/strings.xml
View file @
9f80a6ed
...
...
@@ -13,6 +13,8 @@
<string
name=
"server_port_title"
>
ServerPort
</string>
<string
name=
"default_server_port"
>
5698
</string>
<string
name=
"server_api_url"
>
API Url
</string>
<string
name=
"client_id_title"
>
ClientId
</string>
<string
name=
"reply_title"
>
Default reply action
</string>
...
...
app/src/main/res/xml/root_preferences.xml
View file @
9f80a6ed
...
...
@@ -14,6 +14,12 @@
app:title=
"@string/server_port_title"
app:useSimpleSummaryProvider=
"true"
/>
<EditTextPreference
app:key=
"server_api_url"
app:title=
"@string/server_api_url"
app:useSimpleSummaryProvider=
"true"
/>
</PreferenceCategory>
<PreferenceCategory
app:title=
"@string/client_header"
>
...
...
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