blob: 4c5da96a955dd463150fdda6f1037d0d2d45e06e (
plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
package it.niedermann.nextcloud.deck.api;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.annotation.NonNull;
import java.time.Instant;
import it.niedermann.nextcloud.deck.R;
public class LastSyncUtil {
private static final String LAST_SYNC_KEY = "lS_";
private static LastSyncUtil INSTANCE;
private final SharedPreferences lastSyncPref;
private LastSyncUtil(@NonNull Context applicationContext) {
lastSyncPref = applicationContext.getSharedPreferences(
applicationContext.getString(R.string.shared_preference_last_sync),
Context.MODE_PRIVATE
);
}
public static long getLastSync(long accountId) {
return INSTANCE.lastSyncPref.getLong(getSyncKeyForAccount(accountId), 0L);
}
public static Instant getLastSyncDate(long accountId) {
return Instant.ofEpochMilli(getLastSync(accountId));
}
public static void setLastSyncDate(long accountId, Instant value) {
INSTANCE.lastSyncPref.edit().putLong(getSyncKeyForAccount(accountId), value.toEpochMilli()).apply();
}
public static void resetLastSyncDate(long accountId) {
INSTANCE.lastSyncPref.edit().remove(getSyncKeyForAccount(accountId)).apply();
}
public static void init(Context applicationContext) {
INSTANCE = new LastSyncUtil(applicationContext);
}
private static String getSyncKeyForAccount(long accountId) {
return LAST_SYNC_KEY + accountId;
}
public static void resetAll() {
INSTANCE.lastSyncPref.edit().clear().apply();
}
}
|