Commit fb723c78 authored by Administrator's avatar Administrator

update

parent 0536b861
...@@ -33,6 +33,11 @@ android { ...@@ -33,6 +33,11 @@ android {
signingConfig signingConfigs.release signingConfig signingConfigs.release
} }
} }
compileOptions {
//base-lib-ratel-api 使用了1.8特性
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions { packagingOptions {
exclude 'META-INF/INDEX.LIST' exclude 'META-INF/INDEX.LIST'
......
...@@ -90,4 +90,12 @@ public class EchoConfig { ...@@ -90,4 +90,12 @@ public class EchoConfig {
public static String getPassword() { public static String getPassword() {
return sharedPreferences.getString(userPasswordKey, ""); 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 { ...@@ -22,6 +22,10 @@ public interface UserApi {
Call<CommonRes<UserInfo>> loginWithUsername(@Field("userName") String userName, Call<CommonRes<UserInfo>> loginWithUsername(@Field("userName") String userName,
@Field("password") String password); @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") @GET("api/user-info/queryClientMapping")
Call<CommonRes<Integer>> getClientMappingPort(@Query("clientId") String clientId); Call<CommonRes<Integer>> getClientMappingPort(@Query("clientId") String clientId);
......
package com.virjar.echo.adr.ui; package com.virjar.echo.adr.ui;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.View;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.Button; import android.widget.Button;
...@@ -13,11 +14,13 @@ import android.widget.Toast; ...@@ -13,11 +14,13 @@ import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import com.virjar.echo.adr.EchoApplication;
import com.virjar.echo.adr.R; import com.virjar.echo.adr.R;
import com.virjar.echo.adr.bean.CommonRes; import com.virjar.echo.adr.bean.CommonRes;
import com.virjar.echo.adr.bean.UserInfo; import com.virjar.echo.adr.bean.UserInfo;
import com.virjar.echo.adr.repo.APIServices; import com.virjar.echo.adr.repo.APIServices;
import com.virjar.echo.adr.repo.EchoConfig; import com.virjar.echo.adr.repo.EchoConfig;
import com.virjar.echo.adr.util.MainThreadRunning;
import com.virjar.echo.nat.log.EchoLogger; import com.virjar.echo.nat.log.EchoLogger;
import retrofit2.Call; import retrofit2.Call;
...@@ -31,6 +34,10 @@ public class LoginActivity extends AppCompatActivity { ...@@ -31,6 +34,10 @@ public class LoginActivity extends AppCompatActivity {
int count = 0; int count = 0;
private Button buttonLogin; private Button buttonLogin;
public static void go(Context context) {
context.startActivity(new Intent(context, LoginActivity.class));
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -44,12 +51,7 @@ public class LoginActivity extends AppCompatActivity { ...@@ -44,12 +51,7 @@ public class LoginActivity extends AppCompatActivity {
setupAnimation(); setupAnimation();
Button btnSetting = findViewById(R.id.btn_setting); Button btnSetting = findViewById(R.id.btn_setting);
btnSetting.setOnClickListener(new View.OnClickListener() { btnSetting.setOnClickListener(v -> SettingsActivity.go(LoginActivity.this));
@Override
public void onClick(View v) {
SettingsActivity.go(LoginActivity.this);
}
});
autoLoginWithToken(); autoLoginWithToken();
...@@ -57,23 +59,55 @@ public class LoginActivity extends AppCompatActivity { ...@@ -57,23 +59,55 @@ public class LoginActivity extends AppCompatActivity {
final EditText editTextUsername = findViewById(R.id.edt_username); final EditText editTextUsername = findViewById(R.id.edt_username);
final EditText editTextPassword = findViewById(R.id.edt_password); final EditText editTextPassword = findViewById(R.id.edt_password);
buttonLogin = findViewById(R.id.btn_sign_in); buttonLogin = findViewById(R.id.btn_sign_in);
buttonLogin.setOnClickListener(new View.OnClickListener() { buttonLogin.setOnClickListener(v -> {
@Override String userName = editTextUsername.getText().toString();
public void onClick(View v) { if (userName.isEmpty()) {
String userName = editTextUsername.getText().toString(); Toast.makeText(LoginActivity.this, "please input username", Toast.LENGTH_SHORT).show();
if (userName.isEmpty()) { return;
Toast.makeText(LoginActivity.this, "please input username", Toast.LENGTH_SHORT).show(); }
return; String password = editTextPassword.getText().toString();
} if (password.isEmpty()) {
String password = editTextPassword.getText().toString(); Toast.makeText(LoginActivity.this, "please input password", Toast.LENGTH_SHORT).show();
if (password.isEmpty()) { return;
Toast.makeText(LoginActivity.this, "please input password", Toast.LENGTH_SHORT).show();
return;
}
loginWithUserName(userName, password);
} }
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 { ...@@ -127,12 +161,7 @@ public class LoginActivity extends AppCompatActivity {
final CommonRes<UserInfo> commonRes = response.body(); final CommonRes<UserInfo> commonRes = response.body();
if (!commonRes.isOk()) { if (!commonRes.isOk()) {
EchoLogger.getLogger().error("login failed:" + commonRes.getMessage()); EchoLogger.getLogger().error("login failed:" + commonRes.getMessage());
LoginActivity.this.runOnUiThread(new Runnable() { LoginActivity.this.runOnUiThread(() -> Toast.makeText(LoginActivity.this, commonRes.getMessage(), Toast.LENGTH_SHORT).show());
@Override
public void run() {
Toast.makeText(LoginActivity.this, commonRes.getMessage(), Toast.LENGTH_SHORT).show();
}
});
return; return;
} }
onLoginSuccess(commonRes.getData()); onLoginSuccess(commonRes.getData());
......
...@@ -4,12 +4,14 @@ import android.os.Bundle; ...@@ -4,12 +4,14 @@ import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.DefaultItemAnimator; import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager; import androidx.recyclerview.widget.StaggeredGridLayoutManager;
...@@ -18,6 +20,7 @@ import com.virjar.echo.adr.EchoApplication; ...@@ -18,6 +20,7 @@ import com.virjar.echo.adr.EchoApplication;
import com.virjar.echo.adr.R; import com.virjar.echo.adr.R;
import com.virjar.echo.adr.bean.CommonRes; import com.virjar.echo.adr.bean.CommonRes;
import com.virjar.echo.adr.repo.APIServices; 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.adr.util.MainThreadRunning;
import java.util.Collections; import java.util.Collections;
...@@ -36,6 +39,17 @@ public class MineFragment extends Fragment { ...@@ -36,6 +39,17 @@ public class MineFragment extends Fragment {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_mine, container, false); 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 recyclerView = view.findViewById(R.id.rc_port_list_view);
RecyclerView.LayoutManager layoutManager = new StaggeredGridLayoutManager(5, StaggeredGridLayoutManager.VERTICAL); RecyclerView.LayoutManager layoutManager = new StaggeredGridLayoutManager(5, StaggeredGridLayoutManager.VERTICAL);
...@@ -93,24 +107,21 @@ public class MineFragment extends Fragment { ...@@ -93,24 +107,21 @@ public class MineFragment extends Fragment {
.myProxies().enqueue(new Callback<CommonRes<List<Integer>>>() { .myProxies().enqueue(new Callback<CommonRes<List<Integer>>>() {
@Override @Override
public void onResponse(Call<CommonRes<List<Integer>>> call, final Response<CommonRes<List<Integer>>> response) { public void onResponse(Call<CommonRes<List<Integer>>> call, final Response<CommonRes<List<Integer>>> response) {
MainThreadRunning.runOnMainThread(new Runnable() { MainThreadRunning.runOnMainThread(() -> {
@Override CommonRes<List<Integer>> body = response.body();
public void run() { if (body == null) {
CommonRes<List<Integer>> body = response.body(); Toast.makeText(EchoApplication.echoApplication,
if (body == null) { "代理列表加载失败,数据解析异常", Toast.LENGTH_LONG).show();
Toast.makeText(EchoApplication.echoApplication, return;
"代理列表加载失败,数据解析异常", Toast.LENGTH_LONG).show(); }
return; if (!body.isOk()) {
} Toast.makeText(EchoApplication.echoApplication,
if (!body.isOk()) { body.getMessage(), Toast.LENGTH_LONG).show();
Toast.makeText(EchoApplication.echoApplication, return;
body.getMessage(), Toast.LENGTH_LONG).show();
return;
}
List<Integer> data = body.getData();
myAdapter.resIds = data;
myAdapter.notifyDataSetChanged();
} }
List<Integer> data = body.getData();
myAdapter.resIds = data;
myAdapter.notifyDataSetChanged();
}); });
} }
......
...@@ -144,7 +144,18 @@ ...@@ -144,7 +144,18 @@
android:textStyle="bold" android:textStyle="bold"
android:textColor="#96ffffff" android:textColor="#96ffffff"
android:textSize="16dp" /> 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 <Button
android:id="@+id/btn_setting" android:id="@+id/btn_setting"
android:layout_width="wrap_content" 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