还是用异步吧
This commit is contained in:
parent
63c0c22419
commit
8f6ba4a99a
@ -68,26 +68,26 @@ public class UpgradeModule extends ReactContextBaseJavaModule {
|
||||
}
|
||||
}
|
||||
|
||||
private void _alertDialog(){
|
||||
void _alertDialog(){
|
||||
final UpgradeModule that = this;
|
||||
AlertDialog dialog = new AlertDialog.Builder(reactContext.getCurrentActivity())
|
||||
.setTitle(TITLE)
|
||||
.setMessage(CONTENT)
|
||||
.setNeutralButton("取消",
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
)
|
||||
.setNegativeButton("更新",
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
that._startDownload();
|
||||
}
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
that._startDownload();
|
||||
}
|
||||
}
|
||||
)
|
||||
.show();
|
||||
}
|
||||
@ -124,25 +124,50 @@ public class UpgradeModule extends ReactContextBaseJavaModule {
|
||||
.method("GET", null)
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
try {
|
||||
Response response = call.execute();
|
||||
if(response.isSuccessful()){
|
||||
if(response.body() == null) return;
|
||||
String jsonText = response.body().string();
|
||||
Log.d("VERSION CHECK", jsonText);
|
||||
JSONObject json = new JSONObject(jsonText);
|
||||
int status = json.getInt("status");
|
||||
if(status > 0){
|
||||
CONTENT = json.getString("message");
|
||||
JSONObject jsonData = json.getJSONObject("data");
|
||||
DOWNLOAD_URL = jsonData.getString("url");
|
||||
this._alertDialog();
|
||||
final Handler handler = new ShowUpgradeAlertHandler(this);
|
||||
call.enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
Log.e("VERSION CHECK", call.toString(), e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) {
|
||||
if(response.isSuccessful()){
|
||||
if(response.body() == null) return;
|
||||
try {
|
||||
String jsonText = response.body().string();
|
||||
Log.d("VERSION CHECK", jsonText);
|
||||
JSONObject json = new JSONObject(jsonText);
|
||||
int status = json.getInt("status");
|
||||
if(status > 0){
|
||||
CONTENT = json.getString("message");
|
||||
// String version = json.getString("version");
|
||||
JSONObject jsonData = json.getJSONObject("data");
|
||||
DOWNLOAD_URL = jsonData.getString("url");
|
||||
handler.sendEmptyMessage(0);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e("REQUEST FAILED", "AAA", e);
|
||||
} catch (JSONException e) {
|
||||
Log.e("JSON FAILED", "BBB", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
Log.e("JSON FAILED", "BBB", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
final class ShowUpgradeAlertHandler extends Handler
|
||||
{
|
||||
private UpgradeModule module;
|
||||
|
||||
ShowUpgradeAlertHandler(UpgradeModule module)
|
||||
{
|
||||
this.module = module;
|
||||
}
|
||||
@Override
|
||||
public void handleMessage(Message message){
|
||||
module._alertDialog();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user