Added functionality to enable OsMo service from dashboard when it's disabled

This commit is contained in:
Bars107 2015-03-24 17:58:38 +02:00
parent dafddbf041
commit d491e0ac0e

View file

@ -75,21 +75,26 @@ public class DashOsMoFragment extends DashLocationFragment implements OsMoGroups
private void setupOsMoView() {
View mainView = getView();
boolean show = plugin != null;
if (show) {
show = plugin.getService().isEnabled();
}
if (!show) {
if (plugin == null) {
mainView.setVisibility(View.GONE);
return;
} else {
mainView.setVisibility(View.VISIBLE);
}
updateStatus();
}
private void setupHader(final View header) {
CompoundButton trackr = (CompoundButton) header.findViewById(R.id.check_item);
CompoundButton enableService = (CompoundButton)header.findViewById(R.id.header_layout).findViewById(R.id.check_item);
CompoundButton trackr = (CompoundButton) header.findViewById(R.id.card_content).findViewById(R.id.check_item);
enableService.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
plugin.getService().connect(true);
}
});
final OsmandApplication app = getMyApplication();
trackr.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@ -132,6 +137,19 @@ public class DashOsMoFragment extends DashLocationFragment implements OsMoGroups
if (getView() == null) {
return;
}
View cardContent = header.findViewById(R.id.card_content);
View enableOsmo = header.findViewById(R.id.header_layout).findViewById(R.id.check_item);
if (plugin.getService().isEnabled()) {
cardContent.setVisibility(View.VISIBLE);
enableOsmo.setVisibility(View.GONE);
} else {
cardContent.setVisibility(View.GONE);
enableOsmo.setVisibility(View.VISIBLE);
getClearContentList(header);
return;
}
CompoundButton trackr = (CompoundButton) header.findViewById(R.id.check_item);
if (plugin != null && plugin.getTracker() != null) {
trackr.setChecked(plugin.getTracker().isEnabledTracker());
@ -151,8 +169,7 @@ public class DashOsMoFragment extends DashLocationFragment implements OsMoGroups
break;
}
}
LinearLayout contentList = (LinearLayout) mainView.findViewById(R.id.items);
contentList.removeAllViews();
LinearLayout contentList = getClearContentList(mainView);
if (mainGroup == null) {
return;
}
@ -170,6 +187,12 @@ public class DashOsMoFragment extends DashLocationFragment implements OsMoGroups
}
}
private LinearLayout getClearContentList(View mainView) {
LinearLayout contentList = (LinearLayout) mainView.findViewById(R.id.items);
contentList.removeAllViews();
return contentList;
}
private void setupGroupsViews(int toAddCount, ArrayList<OsMoGroupsStorage.OsMoGroup> groups, LinearLayout contentList) {
int counter = 1;
LayoutInflater inflater = getActivity().getLayoutInflater();
@ -293,7 +316,7 @@ public class DashOsMoFragment extends DashLocationFragment implements OsMoGroups
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
updateConnectedDevices(getView());
updateStatus();
}
});
}