mirror of
https://github.com/TimeCrafters/TimeCraftersConfigurationTool.git
synced 2025-12-15 05:02:33 +00:00
Added auto sort for all the things
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user