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
be933c56
Commit
be933c56
authored
Jul 31, 2020
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
074261f1
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
194 additions
and
5 deletions
+194
-5
EchoApplication.java
app/src/main/java/com/virjar/echo/adr/EchoApplication.java
+3
-0
APIServices.java
app/src/main/java/com/virjar/echo/adr/repo/APIServices.java
+1
-1
EchoConfig.java
app/src/main/java/com/virjar/echo/adr/repo/EchoConfig.java
+2
-0
UserApi.java
app/src/main/java/com/virjar/echo/adr/repo/UserApi.java
+6
-0
GridSpacingItemDecoration.java
...ava/com/virjar/echo/adr/ui/GridSpacingItemDecoration.java
+44
-0
LogFragment.java
app/src/main/java/com/virjar/echo/adr/ui/LogFragment.java
+1
-0
MineFragment.java
app/src/main/java/com/virjar/echo/adr/ui/MineFragment.java
+109
-0
MainThreadRunning.java
...main/java/com/virjar/echo/adr/util/MainThreadRunning.java
+10
-0
fragment_log.xml
app/src/main/res/layout/fragment_log.xml
+3
-0
fragment_mine.xml
app/src/main/res/layout/fragment_mine.xml
+5
-4
recycler_view_item_port.xml
app/src/main/res/layout/recycler_view_item_port.xml
+10
-0
No files found.
app/src/main/java/com/virjar/echo/adr/EchoApplication.java
View file @
be933c56
...
...
@@ -7,10 +7,13 @@ import com.virjar.echo.adr.repo.EchoConfig;
public
class
EchoApplication
extends
Application
{
public
static
EchoApplication
echoApplication
;
@Override
public
void
onCreate
()
{
super
.
onCreate
();
LogServices
.
init
();
EchoConfig
.
init
(
this
);
echoApplication
=
this
;
}
}
app/src/main/java/com/virjar/echo/adr/repo/APIServices.java
View file @
be933c56
...
...
@@ -36,7 +36,7 @@ public class APIServices {
}
//自动增加登录token
Request
originalRequest
=
chain
.
request
();
Request
updateRequest
=
originalRequest
.
newBuilder
().
header
(
"Token"
,
token
).
build
();
Request
updateRequest
=
originalRequest
.
newBuilder
().
header
(
"
operator
Token"
,
token
).
build
();
return
chain
.
proceed
(
updateRequest
);
}
});
...
...
app/src/main/java/com/virjar/echo/adr/repo/EchoConfig.java
View file @
be933c56
...
...
@@ -5,6 +5,7 @@ import android.content.SharedPreferences;
import
android.text.TextUtils
;
import
com.virjar.echo.adr.R
;
import
com.virjar.echo.nat.log.EchoLogger
;
import
java.util.Objects
;
import
java.util.UUID
;
...
...
@@ -46,6 +47,7 @@ public class EchoConfig {
echoClientId
=
System
.
currentTimeMillis
()
+
"_"
+
UUID
.
randomUUID
().
toString
();
sharedPreferences
.
edit
().
putString
(
"echo_clientId"
,
echoClientId
).
apply
();
}
else
{
EchoLogger
.
getLogger
().
info
(
"clientId:"
+
echoClientId
);
return
echoClientId
;
}
return
getClientId
();
...
...
app/src/main/java/com/virjar/echo/adr/repo/UserApi.java
View file @
be933c56
...
...
@@ -3,6 +3,8 @@ package com.virjar.echo.adr.repo;
import
com.virjar.echo.adr.bean.CommonRes
;
import
com.virjar.echo.adr.bean.UserInfo
;
import
java.util.List
;
import
retrofit2.Call
;
import
retrofit2.http.Field
;
import
retrofit2.http.FormUrlEncoded
;
...
...
@@ -23,4 +25,8 @@ public interface UserApi {
@GET
(
"api/user-info/queryClientMapping"
)
Call
<
CommonRes
<
Integer
>>
getClientMappingPort
(
@Query
(
"clientId"
)
String
clientId
);
@GET
(
"api/user-info/myProxies"
)
Call
<
CommonRes
<
List
<
Integer
>>>
myProxies
();
}
app/src/main/java/com/virjar/echo/adr/ui/GridSpacingItemDecoration.java
0 → 100644
View file @
be933c56
package
com
.
virjar
.
echo
.
adr
.
ui
;
import
android.graphics.Rect
;
import
android.view.View
;
import
androidx.recyclerview.widget.RecyclerView
;
/**
* 代码来自 http://stackoverflow.com/a/30701422
*/
public
class
GridSpacingItemDecoration
extends
RecyclerView
.
ItemDecoration
{
private
int
spanCount
;
private
int
spacing
;
private
boolean
includeEdge
;
public
GridSpacingItemDecoration
(
int
spanCount
,
int
spacing
,
boolean
includeEdge
)
{
this
.
spanCount
=
spanCount
;
this
.
spacing
=
spacing
;
this
.
includeEdge
=
includeEdge
;
}
@Override
public
void
getItemOffsets
(
Rect
outRect
,
View
view
,
RecyclerView
parent
,
RecyclerView
.
State
state
)
{
int
position
=
parent
.
getChildAdapterPosition
(
view
);
// item position
int
column
=
position
%
spanCount
;
// item column
if
(
includeEdge
)
{
outRect
.
left
=
spacing
-
column
*
spacing
/
spanCount
;
// spacing - column * ((1f / spanCount) * spacing)
outRect
.
right
=
(
column
+
1
)
*
spacing
/
spanCount
;
// (column + 1) * ((1f / spanCount) * spacing)
if
(
position
<
spanCount
)
{
// top edge
outRect
.
top
=
spacing
;
}
outRect
.
bottom
=
spacing
;
// item bottom
}
else
{
outRect
.
left
=
column
*
spacing
/
spanCount
;
// column * ((1f / spanCount) * spacing)
outRect
.
right
=
spacing
-
(
column
+
1
)
*
spacing
/
spanCount
;
// spacing - (column + 1) * ((1f / spanCount) * spacing)
if
(
position
>=
spanCount
)
{
outRect
.
top
=
spacing
;
// item top
}
}
}
}
\ No newline at end of file
app/src/main/java/com/virjar/echo/adr/ui/LogFragment.java
View file @
be933c56
...
...
@@ -110,6 +110,7 @@ public class LogFragment extends Fragment {
if
(!
running
)
{
return
;
}
//updateClientId();
new
Handler
(
Looper
.
getMainLooper
()).
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
...
...
app/src/main/java/com/virjar/echo/adr/ui/MineFragment.java
View file @
be933c56
...
...
@@ -4,20 +4,129 @@ import android.os.Bundle;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.fragment.app.Fragment
;
import
androidx.recyclerview.widget.DefaultItemAnimator
;
import
androidx.recyclerview.widget.RecyclerView
;
import
androidx.recyclerview.widget.StaggeredGridLayoutManager
;
import
com.virjar.echo.adr.EchoApplication
;
import
com.virjar.echo.adr.R
;
import
com.virjar.echo.adr.bean.CommonRes
;
import
com.virjar.echo.adr.repo.APIServices
;
import
com.virjar.echo.adr.util.MainThreadRunning
;
import
java.util.Collections
;
import
java.util.List
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
public
class
MineFragment
extends
Fragment
{
private
MyAdapter
myAdapter
;
@Nullable
@Override
public
View
onCreateView
(
@NonNull
LayoutInflater
inflater
,
@Nullable
ViewGroup
container
,
@Nullable
Bundle
savedInstanceState
)
{
View
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_mine
,
container
,
false
);
RecyclerView
recyclerView
=
view
.
findViewById
(
R
.
id
.
rc_port_list_view
);
RecyclerView
.
LayoutManager
layoutManager
=
new
StaggeredGridLayoutManager
(
5
,
StaggeredGridLayoutManager
.
VERTICAL
);
recyclerView
.
setLayoutManager
(
layoutManager
);
myAdapter
=
new
MyAdapter
();
recyclerView
.
setAdapter
(
myAdapter
);
recyclerView
.
addItemDecoration
(
new
GridSpacingItemDecoration
(
2
,
10
,
true
));
recyclerView
.
setItemAnimator
(
new
DefaultItemAnimator
());
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
recyclerView
.
setHasFixedSize
(
true
);
return
view
;
}
public
class
MyViewHolder
extends
RecyclerView
.
ViewHolder
{
TextView
imageView
;
public
MyViewHolder
(
View
itemView
)
{
super
(
itemView
);
imageView
=
itemView
.
findViewById
(
R
.
id
.
tv_port
);
}
}
public
class
MyAdapter
extends
RecyclerView
.
Adapter
<
MyViewHolder
>
{
private
List
<
Integer
>
resIds
=
Collections
.
emptyList
();
@Override
public
MyViewHolder
onCreateViewHolder
(
ViewGroup
parent
,
int
viewType
)
{
View
item
=
LayoutInflater
.
from
(
parent
.
getContext
()).
inflate
(
R
.
layout
.
recycler_view_item_port
,
parent
,
false
);
return
new
MyViewHolder
(
item
);
}
@Override
public
void
onBindViewHolder
(
final
MyViewHolder
holder
,
final
int
position
)
{
holder
.
imageView
.
setText
(
String
.
valueOf
(
resIds
.
get
(
position
)));
}
@Override
public
int
getItemCount
()
{
return
resIds
.
size
();
}
}
@Override
public
void
onResume
()
{
super
.
onResume
();
reloadProxies
();
}
private
void
reloadProxies
()
{
APIServices
.
userApi
.
myProxies
().
enqueue
(
new
Callback
<
CommonRes
<
List
<
Integer
>>>()
{
@Override
public
void
onResponse
(
Call
<
CommonRes
<
List
<
Integer
>>>
call
,
final
Response
<
CommonRes
<
List
<
Integer
>>>
response
)
{
MainThreadRunning
.
runOnMainThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
CommonRes
<
List
<
Integer
>>
body
=
response
.
body
();
if
(
body
==
null
)
{
Toast
.
makeText
(
EchoApplication
.
echoApplication
,
"代理列表加载失败,数据解析异常"
,
Toast
.
LENGTH_LONG
).
show
();
return
;
}
if
(!
body
.
isOk
())
{
Toast
.
makeText
(
EchoApplication
.
echoApplication
,
body
.
getMessage
(),
Toast
.
LENGTH_LONG
).
show
();
return
;
}
List
<
Integer
>
data
=
body
.
getData
();
myAdapter
.
resIds
=
data
;
myAdapter
.
notifyDataSetChanged
();
}
});
}
@Override
public
void
onFailure
(
Call
<
CommonRes
<
List
<
Integer
>>>
call
,
Throwable
t
)
{
MainThreadRunning
.
runOnMainThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
Toast
.
makeText
(
EchoApplication
.
echoApplication
,
"代理列表加载失败"
,
Toast
.
LENGTH_LONG
).
show
();
}
});
}
});
}
}
app/src/main/java/com/virjar/echo/adr/util/MainThreadRunning.java
0 → 100644
View file @
be933c56
package
com
.
virjar
.
echo
.
adr
.
util
;
import
android.os.Handler
;
import
android.os.Looper
;
public
class
MainThreadRunning
{
public
static
void
runOnMainThread
(
Runnable
runnable
)
{
new
Handler
(
Looper
.
getMainLooper
()).
post
(
runnable
);
}
}
app/src/main/res/layout/fragment_log.xml
View file @
be933c56
...
...
@@ -16,17 +16,20 @@
android:orientation=
"horizontal"
>
<TextView
android:textSize=
"28sp"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"当前出口:"
/>
<TextView
android:textSize=
"26sp"
android:id=
"@+id/tv_mapping_proxy"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
</LinearLayout>
<TextView
android:layout_marginTop=
"20sp"
android:id=
"@+id/tv_log"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
...
...
app/src/main/res/layout/fragment_mine.xml
View file @
be933c56
...
...
@@ -49,12 +49,13 @@
<TextView
android:text=
"我的在线设备"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
></TextView>
<ListView
android:layout_height=
"wrap_content"
/>
<androidx.recyclerview.widget.RecyclerView
android:id=
"@+id/rc_port_list_view"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
></ListView>
android:layout_height=
"match_parent"
android:scrollbars=
"vertical"
/>
</LinearLayout>
...
...
app/src/main/res/layout/recycler_view_item_port.xml
0 → 100644
View file @
be933c56
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<TextView
android:id=
"@+id/tv_port"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
</LinearLayout>
\ No newline at end of file
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