Skip to content

Commit afa677f

Browse files
committed
More fixes to UI thread
1 parent bd6d1fc commit afa677f

File tree

1 file changed

+43
-27
lines changed

1 file changed

+43
-27
lines changed

app/src/main/java/com/javiersantos/whatsappbetaupdater/activities/MainActivity.java

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -170,42 +170,58 @@ public boolean onOptionsItemSelected(MenuItem item) {
170170
}
171171

172172
@Override
173-
public void onFinished(Update update, boolean isUpdateAvailable) {
173+
public void onFinished(final Update update, final boolean isUpdateAvailable) {
174174
this.mUpdate = update;
175-
progressWheel.setVisibility(View.GONE);
176-
whatsapp_latest_version.setVisibility(View.VISIBLE);
177-
whatsapp_latest_version.setText(update.getLatestVersion());
178-
179-
boolean isWhatsAppInstalled = UtilsWhatsApp.isWhatsAppInstalled(MainActivity.this);
180-
if (isWhatsAppInstalled && isUpdateAvailable) {
181-
UtilsUI.showFAB(fab, true);
182-
toolbar_subtitle.setText(String.format(getResources().getString(R.string.update_available), update.getLatestVersion()));
183-
if (appPreferences.getAutoDownload()) {
184-
new UtilsAsync.DownloadFile(MainActivity.this, UtilsEnum.DownloadType.WHATSAPP_APK, update).execute();
175+
final boolean isWhatsAppInstalled = UtilsWhatsApp.isWhatsAppInstalled(MainActivity.this);
176+
177+
runOnUiThread(new Runnable() {
178+
@Override
179+
public void run() {
180+
progressWheel.setVisibility(View.GONE);
181+
whatsapp_latest_version.setVisibility(View.VISIBLE);
182+
whatsapp_latest_version.setText(update.getLatestVersion());
183+
184+
if (isWhatsAppInstalled && isUpdateAvailable) {
185+
UtilsUI.showFAB(fab, true);
186+
toolbar_subtitle.setText(String.format(getResources().getString(R.string.update_available), update.getLatestVersion()));
187+
if (appPreferences.getAutoDownload()) {
188+
new UtilsAsync.DownloadFile(MainActivity.this, UtilsEnum.DownloadType.WHATSAPP_APK, update).execute();
189+
}
190+
} else if (!isWhatsAppInstalled) {
191+
UtilsUI.showFAB(fab, true);
192+
toolbar_subtitle.setText(String.format(getResources().getString(R.string.update_not_installed), update.getLatestVersion()));
193+
} else {
194+
UtilsUI.showFAB(fab, false);
195+
toolbar_subtitle.setText(getResources().getString(R.string.update_not_available));
196+
}
185197
}
186-
} else if (!isWhatsAppInstalled) {
187-
UtilsUI.showFAB(fab, true);
188-
toolbar_subtitle.setText(String.format(getResources().getString(R.string.update_not_installed), update.getLatestVersion()));
189-
} else {
190-
UtilsUI.showFAB(fab, false);
191-
toolbar_subtitle.setText(getResources().getString(R.string.update_not_available));
192-
}
198+
});
193199
}
194200

195201
@Override
196202
public void onLoading() {
197-
checkInstalledWhatsAppVersion();
198-
whatsapp_latest_version.setVisibility(View.GONE);
199-
progressWheel.setVisibility(View.VISIBLE);
203+
runOnUiThread(new Runnable() {
204+
@Override
205+
public void run() {
206+
checkInstalledWhatsAppVersion();
207+
whatsapp_latest_version.setVisibility(View.GONE);
208+
progressWheel.setVisibility(View.VISIBLE);
209+
}
210+
});
200211
}
201212

202213
@Override
203-
public void onError(UpdaterError error) {
204-
if (error == UpdaterError.NO_INTERNET_CONNECTION)
205-
toolbar_subtitle.setText(getResources().getString(R.string.update_not_connection));
206-
progressWheel.setVisibility(View.GONE);
207-
whatsapp_latest_version.setVisibility(View.VISIBLE);
208-
whatsapp_latest_version.setText(getString(R.string.whatsapp_not_available));
214+
public void onError(final UpdaterError error) {
215+
runOnUiThread(new Runnable() {
216+
@Override
217+
public void run() {
218+
if (error == UpdaterError.NO_INTERNET_CONNECTION)
219+
toolbar_subtitle.setText(getResources().getString(R.string.update_not_connection));
220+
progressWheel.setVisibility(View.GONE);
221+
whatsapp_latest_version.setVisibility(View.VISIBLE);
222+
whatsapp_latest_version.setText(getString(R.string.whatsapp_not_available));
223+
}
224+
});
209225
}
210226

211227
}

0 commit comments

Comments
 (0)