Commit fb723c78 authored by Administrator's avatar Administrator

update

parent 0536b861
......@@ -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'
......
......@@ -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();
}
}
......@@ -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);
......
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());
......
......@@ -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();
});
}
......
......@@ -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"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment