[app] Fix toast on worker thread (#120)
This commit is contained in:
parent
d9362b921e
commit
83e6182252
|
|
@ -4,6 +4,8 @@ import android.annotation.SuppressLint;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
@ -24,6 +26,7 @@ public class App extends Application {
|
||||||
private static OkHttpClient okHttpClient;
|
private static OkHttpClient okHttpClient;
|
||||||
private static Cache okHttpCache;
|
private static Cache okHttpCache;
|
||||||
private SharedPreferences pref;
|
private SharedPreferences pref;
|
||||||
|
private final Handler handler = new Handler(Looper.getMainLooper());
|
||||||
|
|
||||||
public static App getInstance() {
|
public static App getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
|
|
@ -87,4 +90,8 @@ public class App extends Application {
|
||||||
}
|
}
|
||||||
return okHttpCache;
|
return okHttpCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void runOnUiThread(Runnable runnable) {
|
||||||
|
handler.post(runnable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ public class RepoLoader {
|
||||||
.build()).enqueue(new Callback() {
|
.build()).enqueue(new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
||||||
Toast.makeText(App.getInstance(), e.getMessage(), Toast.LENGTH_LONG).show();
|
App.getInstance().runOnUiThread(() -> Toast.makeText(App.getInstance(), e.getMessage(), Toast.LENGTH_LONG).show());
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue