• 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

25.0
opensrp-child/src/main/java/org/smartregister/child/toolbar/LocationSwitcherToolbar.java
1
package org.smartregister.child.toolbar;
2

3
import android.content.Context;
4
import android.util.AttributeSet;
5
import android.view.MenuItem;
6
import android.view.View;
7

8
import androidx.annotation.Nullable;
9
import androidx.core.content.res.ResourcesCompat;
10

11
import org.smartregister.AllConstants;
12
import org.smartregister.child.R;
13
import org.smartregister.child.activity.BaseActivity;
14
import org.smartregister.child.view.LocationActionView;
15
import org.smartregister.util.Utils;
16
import org.smartregister.view.customcontrols.CustomFontTextView;
17

18
/**
19
 * To use this toolbar in your activity, include the following line as the first child in your activity's main
20
 * <p/>
21
 * <include layout="@layout/toolbar_location_switcher" />
22
 * <p/>
23
 * Created by Jason Rogena - jrogena@ona.io on 17/02/2017.
24
 */
25

26
public class LocationSwitcherToolbar extends BaseToolbar {
27
    public static final int TOOLBAR_ID = R.id.location_switching_toolbar;
1✔
28
    private BaseActivity baseActivity;
29
    private OnLocationChangeListener onLocationChangeListener;
30
    private String title;
31
    private int separatorResourceId;
32

33
    public LocationSwitcherToolbar(Context context) {
34
        super(context);
×
35
    }
×
36

37
    public LocationSwitcherToolbar(Context context, @Nullable AttributeSet attrs) {
38
        super(context, attrs);
1✔
39
    }
1✔
40

41
    public LocationSwitcherToolbar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
42
        super(context, attrs, defStyleAttr);
×
43
    }
×
44

45
    public void init(BaseActivity baseActivity) {
46
        this.baseActivity = baseActivity;
1✔
47
    }
1✔
48

49
    public String getCurrentLocation() {
50
        if (baseActivity != null && baseActivity.getMenu() != null) {
×
51
            return ((LocationActionView) baseActivity.getMenu().findItem(R.id.location_switcher).getActionView())
×
52
                    .getSelectedItem();
×
53
        }
54

55
        return null;
×
56
    }
57

58
    public void setTitle(String title) {
59
        this.title = title;
1✔
60
    }
1✔
61

62

63
    public void setOnLocationChangeListener(OnLocationChangeListener onLocationChangeListener) {
64
        this.onLocationChangeListener = onLocationChangeListener;
1✔
65
    }
1✔
66

67
    @Override
68
    public int getSupportedMenu() {
69
        return R.menu.menu_location_switcher;
×
70
    }
71

72
    @Override
73
    public void prepareMenu() {
74
        if (baseActivity != null) {
×
75
            CustomFontTextView titleTV = baseActivity.findViewById(R.id.title);
×
76
            titleTV.setText(title);
×
77

78

79
            if (!Utils.getBooleanProperty(AllConstants.PROPERTY.DISABLE_LOCATION_PICKER_VIEW)) {
×
80
                LocationActionView locationActionView = new LocationActionView(baseActivity);
×
81
                locationActionView.getLocationPickerView()
×
82
                        .setOnLocationChangeListener(newLocation -> {
×
83
                            if (onLocationChangeListener != null) {
×
84
                                onLocationChangeListener.onLocationChanged(newLocation);
×
85
                            }
86
                        });
×
87
                View separatorV = baseActivity.findViewById(R.id.separator_v);
×
88
                separatorV.setVisibility(VISIBLE);
×
89
                baseActivity.getMenu().findItem(R.id.location_switcher).setActionView(locationActionView);
×
90
                separatorV.setBackground(ResourcesCompat.getDrawable(getResources(), separatorResourceId, null));
×
91
            }
92
        }
93
    }
×
94

95
    @Override
96
    public MenuItem onMenuItemSelected(MenuItem menuItem) {
97
        return menuItem;
×
98
    }
99

100
    public void updateSeparatorView(int newView) {
101
        separatorResourceId = newView;
×
102
    }
×
103

104
    public interface OnLocationChangeListener {
105
        void onLocationChanged(String newLocation);
106
    }
107
}
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