package net.ktnx.mobileledger.dao;
import android.os.AsyncTask;
-import android.os.Handler;
-import android.os.Looper;
import androidx.annotation.NonNull;
+import net.ktnx.mobileledger.utils.Misc;
+
public abstract class BaseDAO<T> {
abstract long insertSync(T item);
public void insert(T item) {
public void insert(T item, @NonNull OnInsertedReceiver receiver) {
AsyncTask.execute(() -> {
long id = insertSync(item);
- new Handler(Looper.getMainLooper()).post(() -> receiver.onInsert(id));
+ Misc.onMainThread(() -> receiver.onInsert(id));
});
}
public void update(T item, @NonNull Runnable onDone) {
AsyncTask.execute(() -> {
updateSync(item);
- new Handler(Looper.getMainLooper()).post(onDone);
+ Misc.onMainThread(onDone);
});
}
abstract void deleteSync(T item);
public void delete(T item, @NonNull Runnable onDone) {
AsyncTask.execute(() -> {
deleteSync(item);
- new Handler(Looper.getMainLooper()).post(onDone);
+ Misc.onMainThread(onDone);
});
}
interface OnInsertedReceiver {
package net.ktnx.mobileledger.dao;
import android.os.AsyncTask;
-import android.os.Handler;
-import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import net.ktnx.mobileledger.db.TemplateAccount;
import net.ktnx.mobileledger.db.TemplateHeader;
import net.ktnx.mobileledger.db.TemplateWithAccounts;
+import net.ktnx.mobileledger.utils.Misc;
import java.util.List;
public void insertAsync(@NonNull TemplateHeader item, @Nullable Runnable callback) {
AsyncTask.execute(() -> {
insertSync(item);
- if (callback != null) {
- new Handler(Looper.getMainLooper()).post(callback);
- }
+ if (callback != null)
+ Misc.onMainThread(callback);
});
}
public void deleteAsync(@NonNull TemplateHeader item, @NonNull Runnable callback) {
AsyncTask.execute(() -> {
deleteSync(item);
- new Handler(Looper.getMainLooper()).post(callback);
+ Misc.onMainThread(callback);
});
}
public void insertAsync(@NonNull TemplateWithAccounts item, @Nullable Runnable callback) {
AsyncTask.execute(() -> {
insertSync(item);
- if (callback != null) {
- new Handler(Looper.getMainLooper()).post(callback);
- }
+ if (callback != null)
+ Misc.onMainThread(callback);
});
}
public void duplicateTemplateWitAccounts(@NonNull Long id, @Nullable
dupAcc.setId(accDao.insertSync(dupAcc));
}
if (callback != null)
- new Handler(Looper.getMainLooper()).post(() -> callback.onResult(dup));
+ Misc.onMainThread(() -> callback.onResult(dup));
});
}
import android.content.res.Resources;
import android.os.AsyncTask;
-import android.os.Handler;
-import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
return (position == 0) ? ITEM_TYPE_HEADER : ITEM_TYPE_ACCOUNT;
}
public void setAccounts(List<AccountListItem> newList) {
- new Handler(Looper.getMainLooper()).post(() -> listDiffer.submitList(newList));
+ Misc.onMainThread(() -> listDiffer.submitList(newList));
}
static class Change {
static final int NAME = 1;
package net.ktnx.mobileledger.ui.new_transaction;
import android.annotation.SuppressLint;
-import android.os.Handler;
-import android.os.Looper;
import android.text.TextUtils;
import androidx.annotation.NonNull;
newItems.add(accRow);
}
- new Handler(Looper.getMainLooper()).post(() -> replaceItems(newItems));
+ Misc.onMainThread(() -> replaceItems(newItems));
});
}
private int extractIntFromMatches(MatchResult m, Integer group, Integer literal) {
moveItemLast(newList, singlePositiveIndex);
}
- new Handler(Looper.getMainLooper()).post(() -> {
+ Misc.onMainThread(() -> {
setItems(newList);
noteFocusChanged(1, FocusedElement.Amount);
});
import android.app.Activity;
import android.content.res.Configuration;
+import android.os.Handler;
+import android.os.Looper;
import android.text.Editable;
import android.view.WindowManager;
return a.equals(b);
}
+ public static void onMainThread(Runnable r) {
+ new Handler(Looper.getMainLooper()).post(r);
+ }
}