blob: 3c8541f4ce2a174ad57b248b4e345784f4780d33 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
package ml.docilealligator.infinityforreddit.asynctasks;
import android.os.Handler;
import java.util.concurrent.Executor;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.user.UserData;
public class InsertUserData {
public static void insertUserData(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase,
UserData userData, InsertUserDataListener insertUserDataListener) {
executor.execute(() -> {
if (redditDataRoomDatabase.userDao().getNUsers() > 10000) {
redditDataRoomDatabase.userDao().deleteAllUsers();
}
redditDataRoomDatabase.userDao().insert(userData);
if (insertUserDataListener != null) {
handler.post(insertUserDataListener::insertSuccess);
}
});
}
public interface InsertUserDataListener {
void insertSuccess();
}
}
|