Skip to content

Commit

Permalink
Maybe save layout w/ groups?
Browse files Browse the repository at this point in the history
Untested, but I like the look of it so far!
  • Loading branch information
theonlytechnohead committed Jul 13, 2022
1 parent 9ad494c commit 6221f32
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,34 @@ public HashMap<Integer, Integer> getChannelMap() {
return channelMap;
}

public HashMap<Integer, Object> getLayout() {
HashMap<Integer, Object> layout = new HashMap<>();
for (int i = 0; i < channels.size(); i++) {
ChannelStrip channel = channels.get(i);
if (!channel.group) {
layout.put(i, channel.index);
}
if (channel.group && channel.groupIndex == 0) {
Group group = new Group();
group.index = channel.index;
group.name = channel.name;
group.colourIndex = channel.colourIndex;
// add subchannels
ArrayList<ChannelStrip> subchannels = groupedChannels.get(-channel.index);
if (subchannels != null) {
for (int j = 0; j < subchannels.size(); j++) {
ChannelStrip subchannel = subchannels.get(j);
group.channels.put(j, subchannel.index);
}
}
}
}
for (Map.Entry<Integer, ChannelStrip> entry : hiddenChannels.entrySet()) {
layout.put(entry.getKey(), entry.getValue().index);
}
return layout;
}

void setValuesChangeListener(FaderValueChangedListener listener) {
faderValueChangedListener = listener;
}
Expand Down
30 changes: 30 additions & 0 deletions app/src/main/java/net/ddns/anderserver/touchfadersapp/Group.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.ddns.anderserver.touchfadersapp;

import androidx.annotation.Nullable;

import java.util.HashMap;
import java.util.Objects;

public class Group {

public int index;

public String name;
public int colourIndex;
public int groupIndex = -1;

public HashMap<Integer, Integer> channels = new HashMap<>();

@Override
public boolean equals(@Nullable Object obj) {
if (obj instanceof Group) {
return ((Group) obj).index == index;
}
return false;
}

@Override
public int hashCode() {
return Objects.hash(index);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ protected void onPause() {
runUDP = false;
channelLayer = adapter.getChannelMap();
saveMap(channelLayer);
saveLayout(adapter.getLayout());
}

@Override
Expand Down Expand Up @@ -528,6 +529,47 @@ private void saveMap(HashMap<Integer, Integer> inputMap) {
}
}

private void saveLayout(HashMap<Integer, Object> inputLayout) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
if (preferences != null) {
JSONObject json = new JSONObject();
for (Map.Entry<Integer, Object> inputEntry : inputLayout.entrySet()) {
try {
json.put(inputEntry.getKey().toString(), inputEntry.getValue());
} catch (JSONException e) {
e.printStackTrace();
}
}
String jsonString = json.toString();
preferences.edit()
.remove("channel_layout")
.putString("channel_layout", jsonString)
.apply();
}
}

private HashMap<Integer, Object> loadLayout() {
HashMap<Integer, Object> outputMap = new HashMap<>();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
try {
if (preferences != null) {
String jsonString = preferences.getString("channel_layout", (new JSONObject()).toString());
if (jsonString != null) {
JSONObject json = new JSONObject(jsonString);
Iterator<String> keys = json.keys();
while (keys.hasNext()) {
String key = keys.next();
Object value = json.get(key);
outputMap.put(Integer.valueOf(key), value);
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
return outputMap;
}

private HashMap<Integer, Integer> loadMap() {
HashMap<Integer, Integer> outputMap = new HashMap<>();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Expand Down

0 comments on commit 6221f32

Please sign in to comment.