Commit be933c56 authored by Administrator's avatar Administrator

update

parent 074261f1
......@@ -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;
}
}
......@@ -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("operatorToken", token).build();
return chain.proceed(updateRequest);
}
});
......
......@@ -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();
......
......@@ -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();
}
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
......@@ -110,6 +110,7 @@ public class LogFragment extends Fragment {
if (!running) {
return;
}
//updateClientId();
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
......
......@@ -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();
}
});
}
});
}
}
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);
}
}
......@@ -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" />
......
......@@ -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>
......
<?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
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