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