• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OpenSRP / opensrp-client-child / #798

pending completion
#798

Pull #302

github-actions

web-flow
Merge 67ae6b5c4 into c099d4f8b
Pull Request #302: Migrate core to 6 - Memory Leak Fixes

4929 of 9038 relevant lines covered (54.54%)

0.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

54.55
opensrp-child/src/main/java/org/smartregister/child/ChildLibrary.java
1
package org.smartregister.child;
2

3
import android.os.Handler;
4

5
import org.greenrobot.eventbus.EventBus;
6
import org.smartregister.Context;
7
import org.smartregister.CoreLibrary;
8
import org.smartregister.child.domain.ChildMetadata;
9
import org.smartregister.repository.EventClientRepository;
10
import org.smartregister.repository.LocationRepository;
11
import org.smartregister.repository.Repository;
12
import org.smartregister.repository.UniqueIdRepository;
13
import org.smartregister.sync.ClientProcessorForJava;
14
import org.smartregister.sync.helper.ECSyncHelper;
15
import org.smartregister.util.AppProperties;
16
import org.smartregister.view.LocationPickerView;
17
import org.smartregister.view.activity.DrishtiApplication;
18

19
import id.zelory.compressor.Compressor;
20
import timber.log.Timber;
21

22
/**
23
 * Created by ndegwamartin on 25/02/2019.
24
 */
25
public class ChildLibrary {
26

27
    private static ChildLibrary instance;
28
    private final Context context;
29
    private final Repository repository;
30
    private final ChildMetadata metadata;
31
    private final int applicationVersion;
32
    private final int databaseVersion;
33
    private String applicationVersionName;
34
    private UniqueIdRepository uniqueIdRepository;
35
    private EventClientRepository eventClientRepository;
36
    private ECSyncHelper syncHelper;
37
    private ClientProcessorForJava clientProcessorForJava;
38
    private Compressor compressor;
39
    private LocationPickerView locationPickerView;
40
    private EventBus eventBus;
41

42
    private ChildLibrary(Context contextArg, Repository repositoryArg, ChildMetadata metadataArg, int applicationVersion, String applicationVersionName, int databaseVersion) {
1✔
43
        this.context = contextArg;
1✔
44
        this.repository = repositoryArg;
1✔
45
        this.metadata = metadataArg;
1✔
46
        this.applicationVersion = applicationVersion;
1✔
47
        this.applicationVersionName = applicationVersionName;
1✔
48
        this.databaseVersion = databaseVersion;
1✔
49
    }
1✔
50

51
    public static void init(Context context, Repository repository, ChildMetadata metadataArg, int applicationVersion, String applicationVersionName, int databaseVersion) {
52
        if (instance == null) {
1✔
53
            instance = new ChildLibrary(context, repository, metadataArg, applicationVersion, applicationVersionName, databaseVersion);
1✔
54
        }
55
    }
1✔
56

57
    /**
58
     * This init method is deprecated, use {@link #init(Context context, Repository repository, ChildMetadata metadataArg, int applicationVersion, String applicationVersionName, int databaseVersion)} instead which adds application version name.
59
     */
60
    @Deprecated
61
    public static void init(Context context, Repository repository, ChildMetadata metadataArg, int applicationVersion, int databaseVersion) {
62
        init(context, repository, metadataArg, applicationVersion, null, databaseVersion);
1✔
63

64
    }
1✔
65

66
    public static ChildLibrary getInstance() {
67
        if (instance == null) {
1✔
68
            throw new IllegalStateException(" Instance does not exist!!! Call " + ChildLibrary.class.getName() +
1✔
69
                    ".init method in the onCreate method of " + "your Application class ");
70
        }
71
        return instance;
1✔
72
    }
73

74
    public static void destroyInstance() {
75
        instance = null;
1✔
76
    }
1✔
77

78
    public ChildMetadata metadata() {
79
        return metadata;
1✔
80
    }
81

82
    public int getApplicationVersion() {
83
        return applicationVersion;
1✔
84
    }
85

86
    public int getDatabaseVersion() {
87
        return databaseVersion;
1✔
88
    }
89

90
    public UniqueIdRepository getUniqueIdRepository() {
91
        if (uniqueIdRepository == null) {
×
92
            uniqueIdRepository = new UniqueIdRepository();
×
93
        }
94
        return uniqueIdRepository;
×
95
    }
96

97
    public Repository getRepository() {
98
        return repository;
1✔
99
    }
100

101
    public EventClientRepository eventClientRepository() {
102
        if (eventClientRepository == null) {
1✔
103
            eventClientRepository = new EventClientRepository();
1✔
104
        }
105
        return eventClientRepository;
1✔
106
    }
107

108
    public ECSyncHelper getEcSyncHelper() {
109
        if (syncHelper == null) {
×
110
            syncHelper = ECSyncHelper.getInstance(context().applicationContext());
×
111
        }
112
        return syncHelper;
×
113
    }
114

115
    public Context context() {
116
        return context;
1✔
117
    }
118

119
    public ClientProcessorForJava getClientProcessorForJava() {
120
        if (clientProcessorForJava == null) {
×
121
            clientProcessorForJava = DrishtiApplication.getInstance().getClientProcessor();
×
122
        }
123
        return clientProcessorForJava;
×
124
    }
125

126
    public void setClientProcessorForJava(ClientProcessorForJava clientProcessorForJava) {
127
        this.clientProcessorForJava = clientProcessorForJava;
×
128
    }
×
129

130
    public Compressor getCompressor() {
131
        if (compressor == null) {
1✔
132
            compressor = new Compressor(this.context().applicationContext());
1✔
133
        }
134
        return compressor;
1✔
135
    }
136

137
    public LocationPickerView getLocationPickerView(android.content.Context context) {
138
        if (locationPickerView == null) {
×
139
            locationPickerView = new LocationPickerView(context);
×
140
            new Handler(context.getMainLooper()).post(() -> locationPickerView.init());
×
141

142
        }
143
        return locationPickerView;
×
144
    }
145

146
    public AppProperties getProperties() {
147
        return CoreLibrary.getInstance().context().getAppProperties();
1✔
148
    }
149

150
    public EventBus getEventBus() {
151

152
        if (eventBus == null) {
×
153
            Timber.e(" Event Bus instance does not exist!!! Pass the Implementing Application's Eventbus by invoking the " +
×
154
                    ChildLibrary.class.getCanonicalName() + ".setEventBus method from the onCreate method of " + "your Application class ");
×
155
        }
156

157
        return eventBus;
×
158
    }
159

160
    public void setEventBus(EventBus eventBus) {
161
        this.eventBus = eventBus;
×
162
    }
×
163

164
    public String getApplicationVersionName() {
165
        return applicationVersionName;
×
166
    }
167

168
    public void setApplicationVersionName(String applicationVersionName) {
169
        this.applicationVersionName = applicationVersionName;
×
170
    }
×
171

172
    public LocationRepository getLocationRepository() {
173
        return CoreLibrary.getInstance().context().getLocationRepository();
×
174
    }
175
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc