1
0
mirror of https://github.com/nerzhul/ownCloud-SMS-App.git synced 2026-08-20 21:03:08 +00:00

Fix wrong Thread created Toast

This fixes #153
This commit is contained in:
Loic Blot
2017-09-12 08:03:06 +02:00
parent b47a36dd99
commit 47abfac7c3
3 changed files with 16 additions and 5 deletions
@@ -205,7 +205,7 @@ public class MainActivity extends AppCompatActivity
return;
}
new SyncTask(getApplicationContext()).execute();
new SyncTask(this).execute();
Log.v(MainActivity.TAG, "Finish syncAllMessages()");
}
@@ -19,6 +19,7 @@ package fr.unix_experience.owncloud_sms.engine;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
@@ -33,12 +34,14 @@ import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs;
public interface ASyncSMSSync {
class SyncTask extends AsyncTask<Void, Void, Void> {
public SyncTask(Context context) {
public SyncTask(Activity context) {
_activity = context;
_context = context;
_smsBuffer = null;
}
public SyncTask(Context context, SmsBuffer buffer) {
_activity = null;
_context = context;
_smsBuffer = buffer;
}
@@ -70,7 +73,14 @@ public interface ASyncSMSSync {
SmsBuffer smsBuffer = new SmsBuffer();
fetcher.bufferMessagesSinceDate(smsBuffer, syncStartupDate);
if (smsBuffer.empty()) {
Toast.makeText(_context, _context.getString(R.string.nothing_to_sync), Toast.LENGTH_SHORT).show();
if (_activity != null) {
_activity.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(_context, _context.getString(R.string.nothing_to_sync), Toast.LENGTH_SHORT).show();
}
});
}
Log.i(ASyncSMSSync.TAG, "Finish syncAllMessages(): no more sms");
smsBuffer.clear();
shouldSync = false;
@@ -113,6 +123,7 @@ public interface ASyncSMSSync {
private final SmsBuffer _smsBuffer;
private final Context _context;
private final Activity _activity;
}
String TAG = ASyncSMSSync.class.getSimpleName();