mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-18 03:26:15 +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
|
||||
for (Group group : GroupAdapter.this.serverStatus.getGroups()) {
|
||||
// add(group);
|
||||
int visibleCount = 0;
|
||||
if (group.getClients().isEmpty())
|
||||
continue;
|
||||
|
||||
int onlineCount = 0;
|
||||
int count = 0;
|
||||
for (Client client : group.getClients()) {
|
||||
if ((client != null) && client.isConnected() && !client.isDeleted())// && client.getConfig().getStream().equals(GroupListFragment.this.stream.getId()))
|
||||
visibleCount++;
|
||||
if (client == null || client.isDeleted())
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -494,14 +494,17 @@ public class MainActivity extends AppCompatActivity implements GroupItem.GroupIt
|
|||
|
||||
@Override
|
||||
public void onStreamUpdate(RemoteControl remoteControl, RemoteControl.RpcEvent rpcEvent, Stream stream) {
|
||||
// TODO
|
||||
serverStatus.updateStream(stream);
|
||||
// TODO: group sectionsPagerAdapter.updateServer(serverStatus);
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGroupUpdate(RemoteControl remoteControl, RemoteControl.RpcEvent rpcEvent, Group group) {
|
||||
// TODO
|
||||
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) {
|
||||
final Client client = clientItem.getClient();
|
||||
client.setDeleted(true);
|
||||
/* TODO: group
|
||||
|
||||
serverStatus.updateClient(client);
|
||||
sectionsPagerAdapter.updateServer(serverStatus);
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
Snackbar mySnackbar = Snackbar.make(findViewById(R.id.myCoordinatorLayout),
|
||||
getString(R.string.client_deleted, client.getVisibleName()),
|
||||
Snackbar.LENGTH_SHORT);
|
||||
|
@ -581,7 +584,7 @@ public class MainActivity extends AppCompatActivity implements GroupItem.GroupIt
|
|||
public void onClick(View v) {
|
||||
client.setDeleted(false);
|
||||
serverStatus.updateClient(client);
|
||||
sectionsPagerAdapter.updateServer(serverStatus);
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
}
|
||||
});
|
||||
mySnackbar.setCallback(new Snackbar.Callback() {
|
||||
|
@ -595,7 +598,7 @@ public class MainActivity extends AppCompatActivity implements GroupItem.GroupIt
|
|||
}
|
||||
});
|
||||
mySnackbar.show();
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
package de.badaix.snapcast.control.json;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
@ -109,6 +111,55 @@ public class Group implements JsonSerialisable, Comparable<Group> {
|
|||
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() {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
for (Client client : clients)
|
||||
|
|
|
@ -87,33 +87,27 @@ public class ServerStatus implements JsonSerialisable {
|
|||
streams.clear();
|
||||
}
|
||||
|
||||
/*
|
||||
public boolean removeClient(Client client) {
|
||||
for (int i = 0; i < clients.size(); ++i) {
|
||||
if (clients.get(i).getId().equals(client.getId())) {
|
||||
clients.remove(i);
|
||||
if (client == null)
|
||||
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) {
|
||||
if (client == null)
|
||||
return false;
|
||||
|
||||
for (Group group : groups) {
|
||||
for (int i = 0; i < group.getClients().size(); ++i) {
|
||||
Client c = group.getClients().get(i);
|
||||
if (c == null)
|
||||
continue;
|
||||
|
||||
if (client.getId().equals(c.getId())) {
|
||||
if (client.equals(c))
|
||||
if (group.getClient(client.getId()) != null) {
|
||||
group.updateClient(client);
|
||||
return true;
|
||||
group.getClients().set(i, client);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -343,7 +343,14 @@ void StreamServer::onMessageReceived(StreamSession* connection, const msg::BaseM
|
|||
|
||||
logD << "request kServerSettings: " << connection->clientId << "\n";
|
||||
// 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);
|
||||
|
||||
logD << "request kServerSettings\n";
|
||||
|
@ -382,9 +389,18 @@ void StreamServer::onMessageReceived(StreamSession* connection, const msg::BaseM
|
|||
auto headerChunk = stream->getHeader();
|
||||
connection->sendAsync(headerChunk);
|
||||
|
||||
if (newGroup)
|
||||
{
|
||||
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 << group->toJson().dump(4) << "\n";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue