修复空头像异常

0515
ZHD 5 years ago
parent 67728a2315
commit c5b58c41e1
  1. 5
      app/src/main/AndroidManifest.xml
  2. 3
      app/src/main/java/com/community/pocket/data/main/info/InfoRequest.java
  3. 104
      app/src/main/java/com/community/pocket/util/HttpUtil.java
  4. 2
      app/src/main/res/values-zh-rCN/strings.xml
  5. 4
      app/src/main/res/xml/network_security_config.xml

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.community.pocket">
<!-- 添加网络访问权限-->
<uses-permission android:name="android.permission.INTERNET" />
@ -14,7 +15,9 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:largeHeap="true">
android:largeHeap="true"
android:networkSecurityConfig="@xml/network_security_config"
tools:targetApi="n">
<activity
android:name=".ui.main.ui.forum.data.ForumDataActivity"
android:windowSoftInputMode="adjustPan" />

@ -63,6 +63,9 @@ public class InfoRequest {
//获取头像
public void getImg(MutableLiveData<Bitmap> liveData, String url) {
if(url==null){
return;
}
HttpUtil.getRequest(new HttpFileResponse(liveData), url);
}
}

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Looper;
import android.util.Log;
import android.util.Patterns;
import android.util.TypedValue;
import android.view.View;
@ -129,56 +130,61 @@ public class HttpUtil {
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
bool.postValue(false);
if (BuildConfig.DEBUG) {
Looper.prepare();
AlertDialog.Builder builder = getBuilder(context);
ConstraintLayout constraintLayout = (ConstraintLayout) View.inflate(context, R.layout.debug, null);
TextView buildType = constraintLayout.findViewById(R.id.build_type);
buildType.setText(context.getString(R.string.build_type, BuildConfig.BUILD_TYPE));
TextView url = constraintLayout.findViewById(R.id.url);
url.setText(context.getString(R.string.server_host, BuildConfig.API_HOST));
TextView detailError = constraintLayout.findViewById(R.id.detailError);
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
e.printStackTrace(printWriter);
detailError.setText(stringWriter.toString());
Button openUrl = constraintLayout.findViewById(R.id.open_url);
TextView error = constraintLayout.findViewById(R.id.error);
LinearLayout linearLayout = constraintLayout.findViewById(R.id.my_layout);
int index = linearLayout.indexOfChild(error);
TextView testPort = new TextView(context);
TextView mode = constraintLayout.findViewById(R.id.mode);
switch (BuildType.valueOf(BuildConfig.BUILD_TYPE)) {
case rap2debug:
testPort.setText(R.string.rap2_error);
mode.setText(context.getString(R.string.debug_mode, BuildType.rap2debug.getName()));
break;
case serverdebug:
testPort.setText(R.string.server_error);
mode.setText(context.getString(R.string.debug_mode, BuildType.serverdebug.getName()));
break;
default:
Log.e(HttpUtil.class.getName(),e.toString());
try {
if (BuildConfig.DEBUG) {
Looper.prepare();
AlertDialog.Builder builder = getBuilder(context);
ConstraintLayout constraintLayout = (ConstraintLayout) View.inflate(context, R.layout.debug, null);
TextView buildType = constraintLayout.findViewById(R.id.build_type);
buildType.setText(context.getString(R.string.build_type, BuildConfig.BUILD_TYPE));
TextView url = constraintLayout.findViewById(R.id.url);
url.setText(context.getString(R.string.server_host, BuildConfig.API_HOST));
TextView detailError = constraintLayout.findViewById(R.id.detailError);
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
e.printStackTrace(printWriter);
detailError.setText(stringWriter.toString());
Button openUrl = constraintLayout.findViewById(R.id.open_url);
TextView error = constraintLayout.findViewById(R.id.error);
LinearLayout linearLayout = constraintLayout.findViewById(R.id.my_layout);
int index = linearLayout.indexOfChild(error);
TextView testPort = new TextView(context);
TextView mode = constraintLayout.findViewById(R.id.mode);
switch (BuildType.valueOf(BuildConfig.BUILD_TYPE)) {
case rap2debug:
testPort.setText(R.string.rap2_error);
mode.setText(context.getString(R.string.debug_mode, BuildType.rap2debug.getName()));
break;
case serverdebug:
testPort.setText(R.string.server_error);
mode.setText(context.getString(R.string.debug_mode, BuildType.serverdebug.getName()));
break;
default:
}
testPort.setSingleLine(false);
testPort.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
testPort.setGravity(error.getGravity());
linearLayout.addView(testPort, index + 1);
openUrl.setOnClickListener(v -> {
//从其他浏览器打开
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri contentUrl = Uri.parse(BuildConfig.API_HOST);
intent.setData(contentUrl);
Activity activity = (Activity) context;
activity.startActivity(Intent.createChooser(intent, context.getString(R.string.choose_browser)));
});
builder.setView(constraintLayout);
builder.show();
Looper.loop();
}
testPort.setSingleLine(false);
testPort.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
testPort.setGravity(error.getGravity());
linearLayout.addView(testPort, index + 1);
openUrl.setOnClickListener(v -> {
//从其他浏览器打开
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri contentUrl = Uri.parse(BuildConfig.API_HOST);
intent.setData(contentUrl);
Activity activity = (Activity) context;
activity.startActivity(Intent.createChooser(intent, context.getString(R.string.choose_browser)));
});
builder.setView(constraintLayout);
builder.show();
Looper.loop();
} catch (Exception ex) {
Log.e(HttpUtil.class.getName(),ex.toString());
}
}

@ -207,7 +207,7 @@
<string name="open_url">尝试使用浏览器打开服务端</string>
<string name="choose_browser">请选择浏览器</string>
<string name="rap2_error">请按照以下步骤检查:\n1.rap2服务端ip地址是否正确\n2.rap2服务是否已启动\n3.浏览器是否能访问rap2的web服务(默认:3000端口)</string>
<string name="server_error">请按照以下步骤检查:\n1.springboot服务端ip地址是否正确\n2.mongo数据库服务是否已启动\n3.springboot服务端是否已启动</string>
<string name="server_error">请按照以下步骤检查:\n1.springboot服务端ip地址是否正确\n2.mongo数据库服务是否已启动\n3.springboot服务端是否已启动\n4.如果是真机调试,请确认手机IP和服务端IP处于同一个网段</string>
<string name="debug_mode">%1s联调模式</string>
<string name="exit_app">是否退出应用?</string>
<string name="YES"></string>

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config xmlns:android="http://schemas.android.com/apk/res/android">
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
Loading…
Cancel
Save