Skip to content
This repository has been archived by the owner on Jun 20, 2021. It is now read-only.

Commit

Permalink
These dialogs are keeping crash...
Browse files Browse the repository at this point in the history
  • Loading branch information
fengberd committed Sep 10, 2017
1 parent e421293 commit 2b9a1de
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 56 deletions.
104 changes: 73 additions & 31 deletions app/src/main/java/moe/berd/pocket_server/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,7 @@ public void run()
{
public void run()
{
if(processing_dialog.isShowing())
{
processing_dialog.dismiss();
}
tryDismissDialog(processing_dialog);
fragment_main.refreshElements();
toast(R.string.message_install_success);
}
Expand All @@ -150,10 +147,7 @@ public void run()
{
public void run()
{
if(processing_dialog.isShowing())
{
processing_dialog.dismiss();
}
tryDismissDialog(processing_dialog);
toast(getString(R.string.message_install_fail) + ex);
}
});
Expand Down Expand Up @@ -187,10 +181,7 @@ public void run()
{
public void run()
{
if(processing_dialog.isShowing())
{
processing_dialog.dismiss();
}
tryDismissDialog(processing_dialog);
}
});
}
Expand Down Expand Up @@ -253,12 +244,19 @@ public boolean handleMessage(Message msg)
@Override
public void run()
{
new AlertDialog.Builder(MainActivity.this).setTitle(R.string.dialog_start_failed_title)
.setCancelable(false)
.setMessage(getString(R.string.dialog_start_failed_message))
.setPositiveButton(R.string.button_ok,null)
.create()
.show();
try
{
new AlertDialog.Builder(MainActivity.this).setTitle(R.string.dialog_start_failed_title)
.setCancelable(false)
.setMessage(getString(R.string.dialog_start_failed_message))
.setPositiveButton(R.string.button_ok,null)
.create()
.show();
}
catch(Exception ignored)
{

}
}
});
break;
Expand Down Expand Up @@ -557,7 +555,8 @@ public void downloadServer(String jenkins,File saveTo,final ProgressDialog dialo
{
json=artifacts.getJSONObject(0);
}
downloadFile(jenkins + "lastSuccessfulBuild/artifact/" + json.getString("relativePath")+"?time="+System.currentTimeMillis(),saveTo,dialog);
downloadFile(jenkins + "lastSuccessfulBuild/artifact/" + json.getString("relativePath") + "?time=" + System
.currentTimeMillis(),saveTo,dialog);
}
catch(Exception e)
{
Expand Down Expand Up @@ -599,21 +598,64 @@ public void alertABIWarning(final String name,final DialogInterface.OnClickListe
@Override
public void run()
{
new AlertDialog.Builder(MainActivity.this).setTitle(R.string.dialog_abi_title)
.setCancelable(false)
.setMessage(getString(R.string.dialog_abi_message).replace("%binary",name))
.setNegativeButton(R.string.dialog_abi_exit,new DialogInterface.OnClickListener()
try
{
new AlertDialog.Builder(MainActivity.this).setTitle(R.string.dialog_abi_title)
.setCancelable(false)
.setMessage(getString(R.string.dialog_abi_message).replace("%binary",name))
.setNegativeButton(R.string.dialog_abi_exit,new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog,int which)
{
finish();
}
})
.setPositiveButton(R.string.dialog_abi_ignore,onclick)
.create()
.show();
}
catch(Exception ignored)
{

}
}
});
}

public static void tryDismissDialog(Dialog dialog)
{
try
{
if(dialog!=null && dialog.isShowing())
{
Context context=((ContextWrapper)dialog.getContext()).getBaseContext();
if(context instanceof Activity)
{
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN_MR1)
{
if(!((Activity)context).isFinishing() && !((Activity)context).isDestroyed())
{
dialog.dismiss();
}
}
else
{
@Override
public void onClick(DialogInterface dialog,int which)
if(!((Activity)context).isFinishing())
{
finish();
dialog.dismiss();
}
})
.setPositiveButton(R.string.dialog_abi_ignore,onclick)
.create()
.show();
}
}
else
{
dialog.dismiss();
}
}
});
}
catch(Exception ignored)
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,7 @@ public void run()
{
public void run()
{
if(processing_dialog.isShowing())
{
processing_dialog.dismiss();
}
tryDismissDialog(processing_dialog);
}
});
}
Expand Down Expand Up @@ -181,10 +178,7 @@ public void run()
{
public void run()
{
if(processing_dialog.isShowing())
{
processing_dialog.dismiss();
}
tryDismissDialog(processing_dialog);
main.startService(serverIntent);
ServerUtils.runServer();
refreshElements();
Expand All @@ -197,10 +191,7 @@ public void run()
{
public void run()
{
if(processing_dialog.isShowing())
{
processing_dialog.dismiss();
}
tryDismissDialog(processing_dialog);
main.toast(e.toString());
}
});
Expand Down Expand Up @@ -235,10 +226,7 @@ public void run()
{
public void run()
{
if(processing_dialog.isShowing())
{
processing_dialog.dismiss();
}
tryDismissDialog(processing_dialog);
refreshElements();
main.toast(R.string.message_done);
}
Expand All @@ -250,10 +238,7 @@ public void run()
{
public void run()
{
if(processing_dialog.isShowing())
{
processing_dialog.dismiss();
}
tryDismissDialog(processing_dialog);
main.toast(e.toString());
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void run()
{
public void run()
{
processing_dialog.dismiss();
MainActivity.tryDismissDialog(processing_dialog);
}
});
}
Expand Down Expand Up @@ -140,10 +140,7 @@ public void run()
{
public void run()
{
if(processing_dialog.isShowing())
{
processing_dialog.dismiss();
}
MainActivity.tryDismissDialog(processing_dialog);
}
});
}
Expand Down

0 comments on commit 2b9a1de

Please sign in to comment.