mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-10 23:56:43 +02:00
deletion of clients is working
This commit is contained in:
parent
dce6e7f6ba
commit
310aefac6e
5 changed files with 105 additions and 33 deletions
|
@ -175,12 +175,20 @@ public class GroupListFragment extends Fragment {
|
||||||
// TODO: group
|
// TODO: group
|
||||||
for (Group group : GroupAdapter.this.serverStatus.getGroups()) {
|
for (Group group : GroupAdapter.this.serverStatus.getGroups()) {
|
||||||
// add(group);
|
// add(group);
|
||||||
int visibleCount = 0;
|
if (group.getClients().isEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int onlineCount = 0;
|
||||||
|
int count = 0;
|
||||||
for (Client client : group.getClients()) {
|
for (Client client : group.getClients()) {
|
||||||
if ((client != null) && client.isConnected() && !client.isDeleted())// && client.getConfig().getStream().equals(GroupListFragment.this.stream.getId()))
|
if (client == null || client.isDeleted())
|
||||||
visibleCount++;
|
continue;
|
||||||
|
if (client.isConnected())// && client.getConfig().getStream().equals(GroupListFragment.this.stream.getId()))
|
||||||
|
onlineCount++;
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
if ((visibleCount > 0) || !hideOffline)
|
|
||||||
|
if ((onlineCount > 0) || (!hideOffline && (count > 0)))
|
||||||
add(group);
|
add(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -494,14 +494,17 @@ public class MainActivity extends AppCompatActivity implements GroupItem.GroupIt
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStreamUpdate(RemoteControl remoteControl, RemoteControl.RpcEvent rpcEvent, Stream stream) {
|
public void onStreamUpdate(RemoteControl remoteControl, RemoteControl.RpcEvent rpcEvent, Stream stream) {
|
||||||
|
// TODO
|
||||||
serverStatus.updateStream(stream);
|
serverStatus.updateStream(stream);
|
||||||
// TODO: group sectionsPagerAdapter.updateServer(serverStatus);
|
groupListFragment.updateServer(serverStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGroupUpdate(RemoteControl remoteControl, RemoteControl.RpcEvent rpcEvent, Group group) {
|
public void onGroupUpdate(RemoteControl remoteControl, RemoteControl.RpcEvent rpcEvent, Group group) {
|
||||||
// TODO
|
// TODO
|
||||||
Log.d(TAG, "onGroupUpdate: " + group.toString());
|
Log.d(TAG, "onGroupUpdate: " + group.toString());
|
||||||
|
serverStatus.updateGroup(group);
|
||||||
|
groupListFragment.updateServer(serverStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -570,9 +573,9 @@ public class MainActivity extends AppCompatActivity implements GroupItem.GroupIt
|
||||||
public void onDeleteClicked(GroupItem groupItem, final ClientItem clientItem) {
|
public void onDeleteClicked(GroupItem groupItem, final ClientItem clientItem) {
|
||||||
final Client client = clientItem.getClient();
|
final Client client = clientItem.getClient();
|
||||||
client.setDeleted(true);
|
client.setDeleted(true);
|
||||||
/* TODO: group
|
|
||||||
serverStatus.updateClient(client);
|
serverStatus.updateClient(client);
|
||||||
sectionsPagerAdapter.updateServer(serverStatus);
|
groupListFragment.updateServer(serverStatus);
|
||||||
Snackbar mySnackbar = Snackbar.make(findViewById(R.id.myCoordinatorLayout),
|
Snackbar mySnackbar = Snackbar.make(findViewById(R.id.myCoordinatorLayout),
|
||||||
getString(R.string.client_deleted, client.getVisibleName()),
|
getString(R.string.client_deleted, client.getVisibleName()),
|
||||||
Snackbar.LENGTH_SHORT);
|
Snackbar.LENGTH_SHORT);
|
||||||
|
@ -581,7 +584,7 @@ public class MainActivity extends AppCompatActivity implements GroupItem.GroupIt
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
client.setDeleted(false);
|
client.setDeleted(false);
|
||||||
serverStatus.updateClient(client);
|
serverStatus.updateClient(client);
|
||||||
sectionsPagerAdapter.updateServer(serverStatus);
|
groupListFragment.updateServer(serverStatus);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mySnackbar.setCallback(new Snackbar.Callback() {
|
mySnackbar.setCallback(new Snackbar.Callback() {
|
||||||
|
@ -595,7 +598,7 @@ public class MainActivity extends AppCompatActivity implements GroupItem.GroupIt
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mySnackbar.show();
|
mySnackbar.show();
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
package de.badaix.snapcast.control.json;
|
package de.badaix.snapcast.control.json;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
@ -109,6 +111,55 @@ public class Group implements JsonSerialisable, Comparable<Group> {
|
||||||
return clients;
|
return clients;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean removeClient(String id) {
|
||||||
|
if (TextUtils.isEmpty(id))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (int i = 0; i < clients.size(); ++i) {
|
||||||
|
if (clients.get(i).getId().equals(id)) {
|
||||||
|
clients.remove(i);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
boolean updateClient(Client client) {
|
||||||
|
if (client == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (int i = 0; i < clients.size(); ++i) {
|
||||||
|
Client c = clients.get(i);
|
||||||
|
if (c == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (client.getId().equals(c.getId())) {
|
||||||
|
if (client.equals(c))
|
||||||
|
return true;
|
||||||
|
clients.set(i, client);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Client getClient(String id) {
|
||||||
|
if (TextUtils.isEmpty(id))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
for (Client c: clients) {
|
||||||
|
if (c == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (id.equals(c.getId()))
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public JSONArray getJsonClients() {
|
public JSONArray getJsonClients() {
|
||||||
JSONArray jsonArray = new JSONArray();
|
JSONArray jsonArray = new JSONArray();
|
||||||
for (Client client : clients)
|
for (Client client : clients)
|
||||||
|
|
|
@ -87,33 +87,27 @@ public class ServerStatus implements JsonSerialisable {
|
||||||
streams.clear();
|
streams.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
public boolean removeClient(Client client) {
|
||||||
public boolean removeClient(Client client) {
|
if (client == null)
|
||||||
for (int i = 0; i < clients.size(); ++i) {
|
|
||||||
if (clients.get(i).getId().equals(client.getId())) {
|
|
||||||
clients.remove(i);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
for (Group group : groups) {
|
||||||
|
if (group.getClient(client.getId()) != null) {
|
||||||
|
group.removeClient(client.getId());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean updateClient(Client client) {
|
public boolean updateClient(Client client) {
|
||||||
if (client == null)
|
if (client == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (Group group : groups) {
|
for (Group group : groups) {
|
||||||
for (int i = 0; i < group.getClients().size(); ++i) {
|
if (group.getClient(client.getId()) != null) {
|
||||||
Client c = group.getClients().get(i);
|
group.updateClient(client);
|
||||||
if (c == null)
|
return true;
|
||||||
continue;
|
|
||||||
|
|
||||||
if (client.getId().equals(c.getId())) {
|
|
||||||
if (client.equals(c))
|
|
||||||
return true;
|
|
||||||
group.getClients().set(i, client);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -343,7 +343,14 @@ void StreamServer::onMessageReceived(StreamSession* connection, const msg::BaseM
|
||||||
|
|
||||||
logD << "request kServerSettings: " << connection->clientId << "\n";
|
logD << "request kServerSettings: " << connection->clientId << "\n";
|
||||||
// std::lock_guard<std::mutex> mlock(mutex_);
|
// std::lock_guard<std::mutex> mlock(mutex_);
|
||||||
GroupPtr group = Config::instance().addClientInfo(connection->clientId);
|
bool newGroup(false);
|
||||||
|
GroupPtr group = Config::instance().getGroupFromClient(connection->clientId);
|
||||||
|
if (group == nullptr)
|
||||||
|
{
|
||||||
|
group = Config::instance().addClientInfo(connection->clientId);
|
||||||
|
newGroup = true;
|
||||||
|
}
|
||||||
|
|
||||||
ClientInfoPtr client = group->getClient(connection->clientId);
|
ClientInfoPtr client = group->getClient(connection->clientId);
|
||||||
|
|
||||||
logD << "request kServerSettings\n";
|
logD << "request kServerSettings\n";
|
||||||
|
@ -382,9 +389,18 @@ void StreamServer::onMessageReceived(StreamSession* connection, const msg::BaseM
|
||||||
auto headerChunk = stream->getHeader();
|
auto headerChunk = stream->getHeader();
|
||||||
connection->sendAsync(headerChunk);
|
connection->sendAsync(headerChunk);
|
||||||
|
|
||||||
json notification = JsonNotification::getJson("Client.OnConnect", client->toJson());
|
if (newGroup)
|
||||||
// logO << notification.dump(4) << "\n";
|
{
|
||||||
controlServer_->send(notification.dump());
|
json serverJson = Config::instance().getServerStatus(streamManager_->toJson());
|
||||||
|
json notification = JsonNotification::getJson("Server.OnUpdate", serverJson);
|
||||||
|
controlServer_->send(notification.dump());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
json notification = JsonNotification::getJson("Client.OnConnect", client->toJson());
|
||||||
|
//logO << notification.dump(4) << "\n";
|
||||||
|
controlServer_->send(notification.dump());
|
||||||
|
}
|
||||||
// cout << Config::instance().getServerStatus(streamManager_->toJson()).dump(4) << "\n";
|
// cout << Config::instance().getServerStatus(streamManager_->toJson()).dump(4) << "\n";
|
||||||
// cout << group->toJson().dump(4) << "\n";
|
// cout << group->toJson().dump(4) << "\n";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue