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
fb723c78
Commit
fb723c78
authored
Aug 01, 2020
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
0536b861
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
113 additions
and
45 deletions
+113
-45
build.gradle
app/build.gradle
+5
-0
EchoConfig.java
app/src/main/java/com/virjar/echo/adr/repo/EchoConfig.java
+8
-0
UserApi.java
app/src/main/java/com/virjar/echo/adr/repo/UserApi.java
+4
-0
LoginActivity.java
app/src/main/java/com/virjar/echo/adr/ui/LoginActivity.java
+56
-27
MineFragment.java
app/src/main/java/com/virjar/echo/adr/ui/MineFragment.java
+28
-17
activity_login.xml
app/src/main/res/layout/activity_login.xml
+12
-1
No files found.
app/build.gradle
View file @
fb723c78
...
...
@@ -33,6 +33,11 @@ android {
signingConfig
signingConfigs
.
release
}
}
compileOptions
{
//base-lib-ratel-api 使用了1.8特性
sourceCompatibility
JavaVersion
.
VERSION_1_8
targetCompatibility
JavaVersion
.
VERSION_1_8
}
packagingOptions
{
exclude
'META-INF/INDEX.LIST'
...
...
app/src/main/java/com/virjar/echo/adr/repo/EchoConfig.java
View file @
fb723c78
...
...
@@ -90,4 +90,12 @@ public class EchoConfig {
public
static
String
getPassword
()
{
return
sharedPreferences
.
getString
(
userPasswordKey
,
""
);
}
public
static
void
logout
()
{
SharedPreferences
.
Editor
edit
=
sharedPreferences
.
edit
();
edit
.
remove
(
userNameKey
);
edit
.
remove
(
userPasswordKey
);
edit
.
remove
(
loginTokenKey
);
edit
.
apply
();
}
}
app/src/main/java/com/virjar/echo/adr/repo/UserApi.java
View file @
fb723c78
...
...
@@ -22,6 +22,10 @@ public interface UserApi {
Call
<
CommonRes
<
UserInfo
>>
loginWithUsername
(
@Field
(
"userName"
)
String
userName
,
@Field
(
"password"
)
String
password
);
@FormUrlEncoded
@POST
(
"api/user-info/register"
)
Call
<
CommonRes
<
String
>>
register
(
@Field
(
"userName"
)
String
userName
,
@Field
(
"password"
)
String
password
);
@GET
(
"api/user-info/queryClientMapping"
)
Call
<
CommonRes
<
Integer
>>
getClientMappingPort
(
@Query
(
"clientId"
)
String
clientId
);
...
...
app/src/main/java/com/virjar/echo/adr/ui/LoginActivity.java
View file @
fb723c78
package
com
.
virjar
.
echo
.
adr
.
ui
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.text.TextUtils
;
import
android.view.View
;
import
android.view.Window
;
import
android.view.WindowManager
;
import
android.widget.Button
;
...
...
@@ -13,11 +14,13 @@ import android.widget.Toast;
import
androidx.appcompat.app.AppCompatActivity
;
import
com.virjar.echo.adr.EchoApplication
;
import
com.virjar.echo.adr.R
;
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
;
import
com.virjar.echo.adr.util.MainThreadRunning
;
import
com.virjar.echo.nat.log.EchoLogger
;
import
retrofit2.Call
;
...
...
@@ -31,6 +34,10 @@ public class LoginActivity extends AppCompatActivity {
int
count
=
0
;
private
Button
buttonLogin
;
public
static
void
go
(
Context
context
)
{
context
.
startActivity
(
new
Intent
(
context
,
LoginActivity
.
class
));
}
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
...
...
@@ -44,12 +51,7 @@ public class LoginActivity extends AppCompatActivity {
setupAnimation
();
Button
btnSetting
=
findViewById
(
R
.
id
.
btn_setting
);
btnSetting
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
SettingsActivity
.
go
(
LoginActivity
.
this
);
}
});
btnSetting
.
setOnClickListener
(
v
->
SettingsActivity
.
go
(
LoginActivity
.
this
));
autoLoginWithToken
();
...
...
@@ -57,23 +59,55 @@ public class LoginActivity extends AppCompatActivity {
final
EditText
editTextUsername
=
findViewById
(
R
.
id
.
edt_username
);
final
EditText
editTextPassword
=
findViewById
(
R
.
id
.
edt_password
);
buttonLogin
=
findViewById
(
R
.
id
.
btn_sign_in
);
buttonLogin
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
String
userName
=
editTextUsername
.
getText
().
toString
();
if
(
userName
.
isEmpty
())
{
Toast
.
makeText
(
LoginActivity
.
this
,
"please input username"
,
Toast
.
LENGTH_SHORT
).
show
();
return
;
}
String
password
=
editTextPassword
.
getText
().
toString
();
if
(
password
.
isEmpty
())
{
Toast
.
makeText
(
LoginActivity
.
this
,
"please input password"
,
Toast
.
LENGTH_SHORT
).
show
();
return
;
}
loginWithUserName
(
userName
,
password
);
buttonLogin
.
setOnClickListener
(
v
->
{
String
userName
=
editTextUsername
.
getText
().
toString
();
if
(
userName
.
isEmpty
())
{
Toast
.
makeText
(
LoginActivity
.
this
,
"please input username"
,
Toast
.
LENGTH_SHORT
).
show
();
return
;
}
String
password
=
editTextPassword
.
getText
().
toString
();
if
(
password
.
isEmpty
())
{
Toast
.
makeText
(
LoginActivity
.
this
,
"please input password"
,
Toast
.
LENGTH_SHORT
).
show
();
return
;
}
loginWithUserName
(
userName
,
password
);
});
Button
registerBtn
=
findViewById
(
R
.
id
.
btn_sign_up
);
registerBtn
.
setOnClickListener
(
v
->
{
String
userName
=
editTextUsername
.
getText
().
toString
();
if
(
userName
.
isEmpty
())
{
Toast
.
makeText
(
LoginActivity
.
this
,
"please input username"
,
Toast
.
LENGTH_SHORT
).
show
();
return
;
}
String
password
=
editTextPassword
.
getText
().
toString
();
if
(
password
.
isEmpty
())
{
Toast
.
makeText
(
LoginActivity
.
this
,
"please input password"
,
Toast
.
LENGTH_SHORT
).
show
();
return
;
}
APIServices
.
userApi
.
register
(
userName
,
password
)
.
enqueue
(
new
Callback
<
CommonRes
<
String
>>()
{
@Override
public
void
onResponse
(
Call
<
CommonRes
<
String
>>
call
,
Response
<
CommonRes
<
String
>>
response
)
{
CommonRes
<
String
>
body
=
response
.
body
();
if
(
body
.
isOk
())
{
loginWithUserName
(
userName
,
password
);
}
else
{
MainThreadRunning
.
runOnMainThread
(()
->
Toast
.
makeText
(
EchoApplication
.
echoApplication
,
"error:"
+
body
.
getMessage
(),
Toast
.
LENGTH_SHORT
).
show
());
}
}
@Override
public
void
onFailure
(
Call
<
CommonRes
<
String
>>
call
,
Throwable
t
)
{
EchoLogger
.
getLogger
().
error
(
"error "
,
t
);
MainThreadRunning
.
runOnMainThread
(()
->
{
Toast
.
makeText
(
EchoApplication
.
echoApplication
,
"注册失败,错误"
,
Toast
.
LENGTH_SHORT
).
show
();
});
}
});
});
}
...
...
@@ -127,12 +161,7 @@ public class LoginActivity extends AppCompatActivity {
final
CommonRes
<
UserInfo
>
commonRes
=
response
.
body
();
if
(!
commonRes
.
isOk
())
{
EchoLogger
.
getLogger
().
error
(
"login failed:"
+
commonRes
.
getMessage
());
LoginActivity
.
this
.
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
Toast
.
makeText
(
LoginActivity
.
this
,
commonRes
.
getMessage
(),
Toast
.
LENGTH_SHORT
).
show
();
}
});
LoginActivity
.
this
.
runOnUiThread
(()
->
Toast
.
makeText
(
LoginActivity
.
this
,
commonRes
.
getMessage
(),
Toast
.
LENGTH_SHORT
).
show
());
return
;
}
onLoginSuccess
(
commonRes
.
getData
());
...
...
app/src/main/java/com/virjar/echo/adr/ui/MineFragment.java
View file @
fb723c78
...
...
@@ -4,12 +4,14 @@ import android.os.Bundle;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.Button
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.fragment.app.Fragment
;
import
androidx.fragment.app.FragmentActivity
;
import
androidx.recyclerview.widget.DefaultItemAnimator
;
import
androidx.recyclerview.widget.RecyclerView
;
import
androidx.recyclerview.widget.StaggeredGridLayoutManager
;
...
...
@@ -18,6 +20,7 @@ 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.repo.EchoConfig
;
import
com.virjar.echo.adr.util.MainThreadRunning
;
import
java.util.Collections
;
...
...
@@ -36,6 +39,17 @@ public class MineFragment extends Fragment {
public
View
onCreateView
(
@NonNull
LayoutInflater
inflater
,
@Nullable
ViewGroup
container
,
@Nullable
Bundle
savedInstanceState
)
{
View
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_mine
,
container
,
false
);
Button
btn_logout
=
view
.
findViewById
(
R
.
id
.
btn_login_out
);
btn_logout
.
setOnClickListener
((
v
)
->
{
EchoConfig
.
logout
();
LoginActivity
.
go
(
EchoApplication
.
echoApplication
);
FragmentActivity
activity
=
getActivity
();
if
(
activity
!=
null
)
{
activity
.
finish
();
}
});
RecyclerView
recyclerView
=
view
.
findViewById
(
R
.
id
.
rc_port_list_view
);
RecyclerView
.
LayoutManager
layoutManager
=
new
StaggeredGridLayoutManager
(
5
,
StaggeredGridLayoutManager
.
VERTICAL
);
...
...
@@ -93,24 +107,21 @@ public class MineFragment extends Fragment {
.
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
();
MainThreadRunning
.
runOnMainThread
(()
->
{
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
();
});
}
...
...
app/src/main/res/layout/activity_login.xml
View file @
fb723c78
...
...
@@ -144,7 +144,18 @@
android:textStyle=
"bold"
android:textColor=
"#96ffffff"
android:textSize=
"16dp"
/>
<Button
android:id=
"@+id/btn_sign_up"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginRight=
"16dp"
android:background=
"@drawable/buttonshapewhitebg"
android:fontFamily=
"@font/calibri"
android:text=
"Register"
android:textAllCaps=
"false"
android:textStyle=
"bold"
android:textColor=
"#96ffffff"
android:textSize=
"16dp"
/>
<Button
android:id=
"@+id/btn_setting"
android:layout_width=
"wrap_content"
...
...
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