2018-10-30 00:44:29 +01:00
|
|
|
package de.vanitasvitae.omemoqrgenerator;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import com.jfoenix.controls.JFXListCell;
|
|
|
|
import com.jfoenix.controls.JFXToggleButton;
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
import javafx.fxml.FXMLLoader;
|
|
|
|
import javafx.scene.control.Label;
|
|
|
|
import javafx.scene.layout.HBox;
|
|
|
|
|
|
|
|
public class ListViewCell extends JFXListCell<OmemoIdentity> {
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
private HBox hBox;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
private Label id;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
private Label fingerprint;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
private JFXToggleButton toggle;
|
|
|
|
|
|
|
|
public ListViewCell() {
|
|
|
|
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/item.fxml"));
|
|
|
|
fxmlLoader.setController(this);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
fxmlLoader.load();
|
|
|
|
}
|
|
|
|
catch (IOException e)
|
|
|
|
{
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateItem(OmemoIdentity identity, boolean empty) {
|
2018-11-03 17:49:06 +01:00
|
|
|
Repository repository = Repository.getInstance();
|
2018-10-30 00:44:29 +01:00
|
|
|
if (empty) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-03 17:49:06 +01:00
|
|
|
id.setText(Integer.toString(identity.getDevice().getDeviceId()));
|
|
|
|
fingerprint.setText(Util.twoLinesFingerprint(identity.getFingerprint()));
|
|
|
|
toggle.setSelected(identity.getEnabled());
|
|
|
|
setGraphic(hBox);
|
|
|
|
|
|
|
|
toggle.setOnAction(actionEvent -> {
|
|
|
|
identity.setEnabled(toggle.isSelected());
|
|
|
|
repository.getIdentities().add(repository.getIdentities().remove(repository.getIdentities().size() -1));
|
|
|
|
});
|
2018-10-30 00:44:29 +01:00
|
|
|
}
|
|
|
|
}
|