还是用异步吧
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;
|
final UpgradeModule that = this;
|
||||||
AlertDialog dialog = new AlertDialog.Builder(reactContext.getCurrentActivity())
|
AlertDialog dialog = new AlertDialog.Builder(reactContext.getCurrentActivity())
|
||||||
.setTitle(TITLE)
|
.setTitle(TITLE)
|
||||||
.setMessage(CONTENT)
|
.setMessage(CONTENT)
|
||||||
.setNeutralButton("取消",
|
.setNeutralButton("取消",
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
.setNegativeButton("更新",
|
.setNegativeButton("更新",
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
that._startDownload();
|
that._startDownload();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
@ -124,25 +124,50 @@ public class UpgradeModule extends ReactContextBaseJavaModule {
|
|||||||
.method("GET", null)
|
.method("GET", null)
|
||||||
.build();
|
.build();
|
||||||
Call call = okHttpClient.newCall(request);
|
Call call = okHttpClient.newCall(request);
|
||||||
try {
|
final Handler handler = new ShowUpgradeAlertHandler(this);
|
||||||
Response response = call.execute();
|
call.enqueue(new Callback() {
|
||||||
if(response.isSuccessful()){
|
@Override
|
||||||
if(response.body() == null) return;
|
public void onFailure(Call call, IOException e) {
|
||||||
String jsonText = response.body().string();
|
Log.e("VERSION CHECK", call.toString(), e);
|
||||||
Log.d("VERSION CHECK", jsonText);
|
}
|
||||||
JSONObject json = new JSONObject(jsonText);
|
|
||||||
int status = json.getInt("status");
|
@Override
|
||||||
if(status > 0){
|
public void onResponse(Call call, Response response) {
|
||||||
CONTENT = json.getString("message");
|
if(response.isSuccessful()){
|
||||||
JSONObject jsonData = json.getJSONObject("data");
|
if(response.body() == null) return;
|
||||||
DOWNLOAD_URL = jsonData.getString("url");
|
try {
|
||||||
this._alertDialog();
|
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