Added auto sort for all the things

This commit is contained in:
2021-02-10 15:48:08 -06:00
parent 2adfeb74bf
commit 3b7f78c618
8 changed files with 59 additions and 0 deletions

View File

@@ -322,6 +322,52 @@ public class Backend {
writeToFile(TAC.SETTINGS_PATH, gsonForSettings().toJson(settings));
}
public void sortGroups() {
Collections.sort(config.getGroups(), new Comparator<Group>() {
@Override
public int compare(Group a, Group b) {
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
}
});
}
public void sortActions(Group group) {
Collections.sort(group.getActions(), new Comparator<Action>() {
@Override
public int compare(Action a, Action b) {
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
}
});
}
public void sortVariables(Action action) {
Collections.sort(action.getVariables(), new Comparator<Variable>() {
@Override
public int compare(Variable a, Variable b) {
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
}
});
}
public void sortGroupPresets() {
Collections.sort(config.getPresets().getGroups(), new Comparator<Group>() {
@Override
public int compare(Group a, Group b) {
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
}
});
}
public void sortActionsPresets() {
Collections.sort(config.getPresets().getActions(), new Comparator<Action>() {
@Override
public int compare(Action a, Action b) {
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
}
});
}
public void writeDefaultSettings() {
settings = new Settings(TACNET.DEFAULT_HOSTNAME, TACNET.DEFAULT_PORT, "", false, false, false);
saveSettings();

View File

@@ -108,6 +108,7 @@ public class ActionDialog extends TimeCraftersDialog {
group.getActions().add(action);
}
Backend.instance().sortActions(group);
Backend.instance().configChanged();
ActionsFragment fragment = (ActionsFragment) getFragmentManager().getPrimaryNavigationFragment();
if (fragment != null) {

View File

@@ -108,6 +108,7 @@ public class CloneDialog extends TimeCraftersDialog {
group.getActions().add(actionClone);
Backend.instance().sortActions(group);
Backend.instance().configChanged();
ActionsFragment fragment = (ActionsFragment) getFragmentManager().getPrimaryNavigationFragment();
if (fragment != null) {
@@ -121,6 +122,7 @@ public class CloneDialog extends TimeCraftersDialog {
Backend.instance().getConfig().getGroups().add(groupClone);
Backend.instance().sortGroups();
Backend.instance().configChanged();
GroupsFragment fragment = (GroupsFragment) getFragmentManager().getPrimaryNavigationFragment();
if (fragment != null) {

View File

@@ -94,6 +94,7 @@ public class GroupDialog extends TimeCraftersDialog {
Backend.instance().getConfig().getGroups().add(group);
}
Backend.instance().sortGroups();
Backend.instance().configChanged();
GroupsFragment fragment = (GroupsFragment) getFragmentManager().getPrimaryNavigationFragment();
if (fragment != null) {

View File

@@ -188,12 +188,14 @@ public class PresetDialog extends TimeCraftersDialog {
if (isNewPreset) {
Backend.instance().getConfig().getPresets().getGroups().add(groupClone);
Backend.instance().sortGroupPresets();
GroupsFragment fragment = (GroupsFragment) getFragmentManager().getPrimaryNavigationFragment();
Snackbar.make(fragment.getActivity().findViewById(R.id.snackbar_host), "Saved group preset: " + presetName, Snackbar.LENGTH_LONG).show();
} else { // Don't repopulate presets when it is not possible
PresetsFragment fragment = (PresetsFragment) getFragmentManager().getPrimaryNavigationFragment();
if (fragment != null) {
Backend.instance().sortGroupPresets();
fragment.populatePresets();
}
}
@@ -220,12 +222,15 @@ public class PresetDialog extends TimeCraftersDialog {
if (isNewPreset) {
Backend.instance().getConfig().getPresets().getActions().add(actionClone);
Backend.instance().sortActionsPresets();
ActionsFragment fragment = (ActionsFragment) getFragmentManager().getPrimaryNavigationFragment();
Snackbar.make(fragment.getActivity().findViewById(R.id.snackbar_host), "Saved action preset: " + presetName, Snackbar.LENGTH_LONG).show();
} else { // Don't repopulate presets when it is not possible
PresetsFragment fragment = (PresetsFragment) getFragmentManager().getPrimaryNavigationFragment();
if (fragment != null) {
Backend.instance().sortActionsPresets();
fragment.populatePresets();
}
}

View File

@@ -162,6 +162,7 @@ public class VariableDialog extends TimeCraftersDialog {
action.getVariables().add(variable);
}
Backend.instance().sortVariables(action);
Backend.instance().configChanged();
VariablesFragment fragment = (VariablesFragment) getFragmentManager().getPrimaryNavigationFragment();
if (fragment != null) {

View File

@@ -158,6 +158,7 @@ public class GroupsFragment extends TimeCraftersFragment {
@Override
public void run(TimeCraftersDialog dialog) {
Backend.instance().getConfig().getGroups().remove(group);
Backend.instance().sortGroups();
Backend.instance().configChanged();
Backend.getStorage().remove(deleteActionKey);

View File

@@ -105,6 +105,7 @@ public class PresetsFragment extends TimeCraftersFragment {
if (Backend.instance().getConfig().getPresets().getGroups().get(group_index) != null) {
Backend.instance().getConfig().getPresets().getGroups().remove(group_index);
Backend.instance().sortGroupPresets();
Backend.instance().configChanged();
}
@@ -182,6 +183,7 @@ public class PresetsFragment extends TimeCraftersFragment {
if (Backend.instance().getConfig().getPresets().getActions().get(action_index) != null) {
Backend.instance().getConfig().getPresets().getActions().remove(action_index);
Backend.instance().sortActionsPresets();
Backend.instance().configChanged();
}