Skip to content

Commit

Permalink
Update UI from the UI thread. Fixes: #54 #55 #58 #59
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Freimuth authored and Kamuno committed May 14, 2020
1 parent 6763977 commit fd1c35e
Showing 1 changed file with 33 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.secuso.privacyfriendlyfoodtracker.helpers.FirstLaunchManager;
import org.secuso.privacyfriendlyfoodtracker.helpers.KeyGenHelper;

import java.util.concurrent.Executors;

/**
* Generate key activity. Manages the key creation and shows the current state.
*
Expand Down Expand Up @@ -85,40 +87,41 @@ protected void onResume() {
public void onAttachedToWindow() {
super.onAttachedToWindow();

Thread task = new Thread() {
Executors.newSingleThreadExecutor().execute(new Runnable() {
@Override
public void run() {
if (!KeyGenHelper.isKeyGenerated()) {
try {
KeyGenHelper.generateKey(getApplicationContext());
mCheckBox1.setChecked(true);
KeyGenHelper.generatePassphrase(getApplicationContext());
mCheckBox2.setChecked(true);
ApplicationDatabase.getInstance(getApplicationContext());
mCheckBox3.setChecked(true);
mProgressBar.setVisibility(View.INVISIBLE);
} catch (Exception e) {
Log.e("GenerateKeyActivity", e.getMessage());
}
} else {
mCheckBox1.setChecked(true);
mCheckBox2.setChecked(true);
mCheckBox3.setChecked(true);
mProgressBar.setVisibility(View.INVISIBLE);
try {
KeyGenHelper.generateKey(getApplicationContext());
runOnUiThread(new Runnable() {
@Override
public void run() {
mCheckBox1.setChecked(true);
}
});


KeyGenHelper.generatePassphrase(getApplicationContext());
runOnUiThread(new Runnable() {
@Override
public void run() {
mCheckBox2.setChecked(true);
}
});

ApplicationDatabase.getInstance(getApplicationContext());
runOnUiThread(new Runnable() {
@Override
public void run() {
mCheckBox3.setChecked(true);
mProgressBar.setVisibility(View.INVISIBLE);
showFAB();
}
});
} catch (Exception e) {
Log.e("GenerateKeyActivity", e.getMessage());
}
runOnUiThread(new Runnable() {

@Override
public void run() {
// update gui
showFAB();
}
});
}
};

task.start();

});
}

boolean fabShouldBeShown;
Expand Down

0 comments on commit fd1c35e

Please sign in to comment.