Commit 0ae48289 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Row now changes layout when a server is stopped/started

parent 7c7534ac
......@@ -43,12 +43,28 @@ public class ServersAdapter extends RecyclerView.Adapter<ServersAdapter.ViewHold
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
DNSServerSetting setting = dnsServerSettings.get(position);
setting.clearServerStateListeners();
((TextView)holder.itemView.findViewById(R.id.server_name)).setText(setting.getName());
((TextView)holder.itemView.findViewById(R.id.server_port)).setText(portText.replace("[x]", "" + setting.getPort()));
final ImageButton startStopButton = holder.itemView.findViewById(R.id.server_start_stop);
final View indicatorView = holder.itemView.findViewById(R.id.server_status_indicator);
if(!setting.isServerRunning()){
holder.itemView.findViewById(R.id.server_status_indicator).setBackgroundColor(serverNotRunningColor);
((ImageButton)holder.itemView.findViewById(R.id.server_start_stop)).setImageResource(R.drawable.ic_play);
indicatorView.setBackgroundColor(serverNotRunningColor);
startStopButton.setImageResource(R.drawable.ic_play);
}
setting.addServerStateListener(new DNSServerSetting.ServerStateListener() {
@Override
public void serverStarted() {
indicatorView.setBackgroundColor(Color.parseColor("#00FF00"));
startStopButton.setImageResource(R.drawable.ic_stop);
}
@Override
public void serverStopped() {
indicatorView.setBackgroundColor(serverNotRunningColor);
startStopButton.setImageResource(R.drawable.ic_play);
}
});
}
@Override
......
......@@ -12,8 +12,11 @@ import com.frostnerd.utils.database.orm.annotations.NotNull;
import com.frostnerd.utils.database.orm.annotations.RowID;
import com.frostnerd.utils.database.orm.annotations.Serialized;
import com.frostnerd.utils.database.orm.annotations.Table;
import com.frostnerd.utils.database.orm.annotations.Unique;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* Copyright Daniel Wolf 2017
......@@ -29,6 +32,7 @@ public class DNSServerSetting extends SingletonEntity implements Serializable{
@RowID
private int rowID;
@Named(name = "Name")
@Unique
@NotNull
private String name;
@Named(name = "Port")
......@@ -55,6 +59,12 @@ public class DNSServerSetting extends SingletonEntity implements Serializable{
@Ignore
private boolean serverRunning;
@Ignore
private DNSServer.ErrorListener errorListener;
@Ignore
private DNSServer.QueryListener queryListener;
@Ignore
private List<ServerStateListener> serverStateListeners = new ArrayList<>();
public DNSServerSetting(){
......@@ -78,13 +88,10 @@ public class DNSServerSetting extends SingletonEntity implements Serializable{
public void setServerRunning(boolean serverRunning) {
this.serverRunning = serverRunning;
if(serverRunning)for(ServerStateListener listener: serverStateListeners)listener.serverStarted();
else for(ServerStateListener listener: serverStateListeners)listener.serverStopped();
}
@Ignore
private DNSServer.ErrorListener errorListener;
@Ignore
private DNSServer.QueryListener queryListener;
public String getName() {
return name;
}
......@@ -136,4 +143,21 @@ public class DNSServerSetting extends SingletonEntity implements Serializable{
public boolean shouldResolveLocal(){
return resolveLocal;
}
public void addServerStateListener(ServerStateListener listener){
serverStateListeners.add(listener);
}
public void removeServerStateListener(ServerStateListener listener){
serverStateListeners.remove(listener);
}
public void clearServerStateListeners(){
serverStateListeners.clear();
}
public interface ServerStateListener{
public void serverStarted();
public void serverStopped();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment