Don't call blocking functions from ui thread.

This commit is contained in:
Felix Ableitner 2014-07-23 00:36:27 +02:00
parent 387202d92d
commit 3ffecaa310
2 changed files with 30 additions and 10 deletions

View file

@ -42,9 +42,14 @@ public class CertificateAdapter extends ArrayAdapter<Certificate> {
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
new Thread(new Runnable() {
@Override
public void run() {
mCertificateManager.deleteCertificate(cert); mCertificateManager.deleteCertificate(cert);
mMovedCertificatesStorage.delete(cert); mMovedCertificatesStorage.delete(cert);
} }
}).start();
}
}); });
colorRes = R.color.background_system_certificate; colorRes = R.color.background_system_certificate;
} }
@ -53,9 +58,14 @@ public class CertificateAdapter extends ArrayAdapter<Certificate> {
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
new Thread(new Runnable() {
@Override
public void run() {
mCertificateManager.moveCertificateToSystem(cert); mCertificateManager.moveCertificateToSystem(cert);
mMovedCertificatesStorage.insert(cert); mMovedCertificatesStorage.insert(cert);
} }
}).start();
}
}); });
colorRes = R.color.background_user_certificate; colorRes = R.color.background_user_certificate;
} }

View file

@ -31,8 +31,13 @@ public class MainActivity extends ListActivity {
mCertificateAdapter = mCertificateAdapter =
new CertificateAdapter(this, mCertificateManager, mMovedCertificatesStorage); new CertificateAdapter(this, mCertificateManager, mMovedCertificatesStorage);
new Thread(new Runnable() {
@Override
public void run() {
mCertificateAdapter.addAll(mCertificateManager.getCertificates(false)); mCertificateAdapter.addAll(mCertificateManager.getCertificates(false));
mCertificateAdapter.addAll(mMovedCertificatesStorage.list()); mCertificateAdapter.addAll(mMovedCertificatesStorage.list());
}
}).start();
mListView.setAdapter(mCertificateAdapter); mListView.setAdapter(mCertificateAdapter);
} }
@ -50,11 +55,16 @@ public class MainActivity extends ListActivity {
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
new Thread(new Runnable() {
@Override
public void run() {
for (Certificate c : list) { for (Certificate c : list) {
c = mCertificateManager.moveCertificateToSystem(c); c = mCertificateManager.moveCertificateToSystem(c);
mMovedCertificatesStorage.insert(c); mMovedCertificatesStorage.insert(c);
} }
} }
}).start();
}
}) })
.setNegativeButton(android.R.string.no, null) .setNegativeButton(android.R.string.no, null)
.show(); .show();