|
|
|
@ -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()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|