修复空头像异常

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

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

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Looper; import android.os.Looper;
import android.util.Log;
import android.util.Patterns; import android.util.Patterns;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.View; import android.view.View;
@ -129,56 +130,61 @@ public class HttpUtil {
@Override @Override
public void onFailure(@NotNull Call call, @NotNull IOException e) { public void onFailure(@NotNull Call call, @NotNull IOException e) {
bool.postValue(false); bool.postValue(false);
if (BuildConfig.DEBUG) { Log.e(HttpUtil.class.getName(),e.toString());
Looper.prepare(); try {
AlertDialog.Builder builder = getBuilder(context); if (BuildConfig.DEBUG) {
ConstraintLayout constraintLayout = (ConstraintLayout) View.inflate(context, R.layout.debug, null); Looper.prepare();
TextView buildType = constraintLayout.findViewById(R.id.build_type); AlertDialog.Builder builder = getBuilder(context);
buildType.setText(context.getString(R.string.build_type, BuildConfig.BUILD_TYPE)); ConstraintLayout constraintLayout = (ConstraintLayout) View.inflate(context, R.layout.debug, null);
TextView url = constraintLayout.findViewById(R.id.url); TextView buildType = constraintLayout.findViewById(R.id.build_type);
url.setText(context.getString(R.string.server_host, BuildConfig.API_HOST)); buildType.setText(context.getString(R.string.build_type, BuildConfig.BUILD_TYPE));
TextView detailError = constraintLayout.findViewById(R.id.detailError); TextView url = constraintLayout.findViewById(R.id.url);
StringWriter stringWriter = new StringWriter(); url.setText(context.getString(R.string.server_host, BuildConfig.API_HOST));
PrintWriter printWriter = new PrintWriter(stringWriter); TextView detailError = constraintLayout.findViewById(R.id.detailError);
e.printStackTrace(printWriter); StringWriter stringWriter = new StringWriter();
detailError.setText(stringWriter.toString()); PrintWriter printWriter = new PrintWriter(stringWriter);
Button openUrl = constraintLayout.findViewById(R.id.open_url); e.printStackTrace(printWriter);
TextView error = constraintLayout.findViewById(R.id.error); detailError.setText(stringWriter.toString());
LinearLayout linearLayout = constraintLayout.findViewById(R.id.my_layout); Button openUrl = constraintLayout.findViewById(R.id.open_url);
int index = linearLayout.indexOfChild(error); TextView error = constraintLayout.findViewById(R.id.error);
LinearLayout linearLayout = constraintLayout.findViewById(R.id.my_layout);
TextView testPort = new TextView(context); int index = linearLayout.indexOfChild(error);
TextView mode = constraintLayout.findViewById(R.id.mode);
switch (BuildType.valueOf(BuildConfig.BUILD_TYPE)) { TextView testPort = new TextView(context);
case rap2debug: TextView mode = constraintLayout.findViewById(R.id.mode);
testPort.setText(R.string.rap2_error); switch (BuildType.valueOf(BuildConfig.BUILD_TYPE)) {
mode.setText(context.getString(R.string.debug_mode, BuildType.rap2debug.getName())); case rap2debug:
break; testPort.setText(R.string.rap2_error);
case serverdebug: mode.setText(context.getString(R.string.debug_mode, BuildType.rap2debug.getName()));
testPort.setText(R.string.server_error); break;
mode.setText(context.getString(R.string.debug_mode, BuildType.serverdebug.getName())); case serverdebug:
break; testPort.setText(R.string.server_error);
default: 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); } catch (Exception ex) {
testPort.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); Log.e(HttpUtil.class.getName(),ex.toString());
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();
} }
} }

@ -207,7 +207,7 @@
<string name="open_url">尝试使用浏览器打开服务端</string> <string name="open_url">尝试使用浏览器打开服务端</string>
<string name="choose_browser">请选择浏览器</string> <string name="choose_browser">请选择浏览器</string>
<string name="rap2_error">请按照以下步骤检查:\n1.rap2服务端ip地址是否正确\n2.rap2服务是否已启动\n3.浏览器是否能访问rap2的web服务(默认:3000端口)</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="debug_mode">%1s联调模式</string>
<string name="exit_app">是否退出应用?</string> <string name="exit_app">是否退出应用?</string>
<string name="YES"></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