Skip to content

Commit

Permalink
未及时刷新bug 修复
Browse files Browse the repository at this point in the history
  • Loading branch information
liudao01 committed Jun 19, 2020
1 parent babd587 commit 2a85fc0
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 17 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand Down
31 changes: 26 additions & 5 deletions app/src/main/java/demo/libtestapp/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ public class MainActivity extends Activity {
private TextView tvIpList;
private Button btStart;
private Button btCrash;
private Button btStartOne;
int count = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = this;
// TestLibUtil.getInstance().startUtil(getApplication());
// TestLibUtil.getInstance().startUtil(getApplication());

setContentView(R.layout.activity_main);

Expand All @@ -60,7 +62,7 @@ public void onClick(View v) {
btCrash.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int x = 1/0;
int x = 1 / 0;
}
});

Expand All @@ -86,11 +88,24 @@ public void onClick(View v) {
" ]\n" +
"}";


btStartOne = findViewById(R.id.bt_start_one);

HttpTransaction httpTransaction = new HttpTransaction();
httpTransaction.setUrl(url);
httpTransaction.setResponseBody(json);
TestLibUtil.getInstance().sendmessage(httpTransaction);

btStartOne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
HttpTransaction httpTransaction = new HttpTransaction();
httpTransaction.setUrl("www.google.com__" + (count++));
httpTransaction.setResponseBody(json);

TestLibUtil.getInstance().sendmessage(httpTransaction);
}
});
// tvIpList.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
Expand All @@ -103,7 +118,7 @@ public void onClick(View v) {
List<IpConfigBeen> ipList = TestLibUtil.getInstance().getIpList();
String list = "";
for (IpConfigBeen ipConfigBeen : ipList) {
list = list + ipConfigBeen.toString()+"\n";
list = list + ipConfigBeen.toString() + "\n";
}
tvIpList.setText(list);

Expand Down Expand Up @@ -137,8 +152,14 @@ private OkHttpClient getClient(Context context) {
private void doHttpActivity() {
SampleApiService.HttpbinApi api = SampleApiService.getInstance(getClient(this));
Callback<Void> cb = new Callback<Void>() {
@Override public void onResponse(Call call, Response response) {}
@Override public void onFailure(Call call, Throwable t) { t.printStackTrace(); }
@Override
public void onResponse(Call call, Response response) {
}

@Override
public void onFailure(Call call, Throwable t) {
t.printStackTrace();
}
};
api.get().enqueue(cb);
api.post(new SampleApiService.Data("posted_____sssssssssssssssss_post请求")).enqueue(cb);
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
android:text="开始发送数据"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/bt_start_one"
android:text="开始发送数据_一次"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Button
android:id="@+id/bt_crash"
Expand Down
6 changes: 5 additions & 1 deletion myLib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ android {
lintOptions {
abortOnError false
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}

}
//configurations.embed.transitive = true
Expand All @@ -34,7 +38,7 @@ dependencies {
// api 'io.mattcarroll.hover:hover:0.9.8'//悬浮窗
// api('com.github.liudao01:hover:918fbbb806')

implementation ('de.greenrobot:eventbus:2.4.0')
implementation('de.greenrobot:eventbus:2.4.0')
implementation 'com.squareup.okhttp3:logging-interceptor:4.7.2'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.squareup.okhttp3:okhttp:4.7.2'
Expand Down
32 changes: 27 additions & 5 deletions myLib/src/main/java/lib/net/HttpNavigatorContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import androidx.annotation.NonNull;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
Expand All @@ -30,6 +30,9 @@
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -95,7 +98,6 @@ public class HttpNavigatorContent extends FrameLayout implements Content, Adapte
private Button btCopy;



static Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
Expand Down Expand Up @@ -244,18 +246,22 @@ public boolean isFullscreen() {

@Override
public void onShown() {
Log.d(TAG, "onShown: ");

}



public static void setList() {

if (TestLibUtil.httpMoudleList != null) {
if (listHttpAdapter != null) {
List<HttpTransaction> httpMoudleList = TestLibUtil.httpMoudleList;

if (httpMoudleList != null && httpMoudleList.size() > 0) {
Collections.reverse(httpMoudleList);//倒序刚发的在最前面


// Collections.reverse(httpMoudleList);//倒序刚发的在最前面
// Collections.sort(httpMoudleList);
}
Message message = Message.obtain();
message.obj = httpMoudleList;
Expand All @@ -267,10 +273,11 @@ public static void setList() {

@Override
public void onHidden() {

Log.d(TAG, "onHidden: ");
}

public void onEventMainThread(@NonNull HoverTheme newTheme) {
Log.d(TAG, "onEventMainThread: ");
//点击导航按钮的时候调用这个
// if (TestLibUtil.httpMoudleList != null) {
// if (myAdapter == null) {
Expand All @@ -280,6 +287,21 @@ public void onEventMainThread(@NonNull HoverTheme newTheme) {
//
// }
// }
if (TestLibUtil.httpMoudleList != null) {
if (listHttpAdapter != null) {

List<HttpTransaction> httpMoudleList = new ArrayList<>();
httpMoudleList.addAll(TestLibUtil.httpMoudleList);
if (httpMoudleList != null && httpMoudleList.size() > 0) {
Collections.reverse(httpMoudleList);//倒序刚发的在最前面
}

Message message = Message.obtain();
message.obj = httpMoudleList;
handler.sendMessage(message);

}
}
}

@Override
Expand Down
9 changes: 3 additions & 6 deletions myLib/src/main/java/lib/util/TestLibUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;

import androidx.core.content.ContextCompat;

import android.provider.Settings;
import android.text.TextUtils;

import com.orhanobut.logger.Logger;

import java.util.ArrayList;
Expand Down Expand Up @@ -118,8 +115,8 @@ public void sendmessage(HttpTransaction httpBeen) {
//最大条数 0条避免数量过多溢出
if (httpMoudleList != null) {

if (httpMoudleList.size() > 30) {
httpMoudleList.remove(30);
if (httpMoudleList.size() > 20) {
httpMoudleList.remove(20);
httpMoudleList.add(httpBeen);
} else {
httpMoudleList.add(httpBeen);
Expand Down
3 changes: 3 additions & 0 deletions mylibrary-no-op/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
}

}

Expand Down

0 comments on commit 2a85fc0

Please sign in to comment.