-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avatar Overhaul #191
base: develop
Are you sure you want to change the base?
Avatar Overhaul #191
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.faforever.moderatorclient.ui.data_cells; | ||
|
||
import com.faforever.moderatorclient.ui.caches.AvatarCache; | ||
import com.faforever.moderatorclient.ui.domain.AvatarAssignmentFX; | ||
import com.faforever.moderatorclient.ui.domain.AvatarFX; | ||
import javafx.scene.control.TableCell; | ||
import javafx.scene.image.Image; | ||
import javafx.scene.image.ImageView; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.util.Objects; | ||
|
||
public class UrlImageViewTableCellSync<T> extends TableCell<T, String> { | ||
private ImageView imageView = new ImageView(); | ||
private String currentUrl; | ||
|
||
@Override | ||
protected void updateItem(String item, boolean empty) { | ||
super.updateItem(item, empty); | ||
|
||
if (item != null) { | ||
if (!Objects.equals(currentUrl, item)) { | ||
currentUrl = item; | ||
Image img; | ||
if (getTableRow() != null && getTableRow().getItem() != null) { | ||
String cacheKey = cacheKeyFrom(item, getTableRow().getItem()); | ||
if (AvatarCache.getInstance().containsKey(cacheKey)) { | ||
img = AvatarCache.getInstance().get(cacheKey); | ||
} else { | ||
img = new Image(item, true); | ||
AvatarCache.getInstance().put(cacheKey, img); | ||
} | ||
} else { | ||
img = new Image(item); | ||
} | ||
imageView.setImage(img); | ||
} | ||
|
||
setGraphic(imageView); | ||
|
||
|
||
} else { | ||
setGraphic(null); | ||
} | ||
|
||
} | ||
|
||
private String cacheKeyFrom(String item, Object rawData) { | ||
OffsetDateTime updateTime = null; | ||
if (rawData instanceof AvatarFX) { | ||
updateTime = ((AvatarFX)rawData).getUpdateTime(); | ||
} else if (rawData instanceof AvatarAssignmentFX) { | ||
updateTime = ((AvatarAssignmentFX)rawData).getUpdateTime(); | ||
} | ||
return updateTime != null ? item+updateTime.toString() : item; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this only be added if onRemove != null?