forked from j62/ctbrec
Add online / offline selector on MFC Friends tab
This commit is contained in:
parent
617954928e
commit
f553ca3db5
|
@ -4,7 +4,6 @@ package ctbrec.sites.mfc;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
@ -21,6 +20,12 @@ public class FriendsUpdateService extends PaginatedScheduledService {
|
|||
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(FriendsUpdateService.class);
|
||||
private MyFreeCams myFreeCams;
|
||||
private Mode mode = Mode.ONLINE;
|
||||
|
||||
public static enum Mode {
|
||||
ONLINE,
|
||||
OFFLINE
|
||||
}
|
||||
|
||||
public FriendsUpdateService(MyFreeCams myFreeCams) {
|
||||
this.myFreeCams = myFreeCams;
|
||||
|
@ -31,7 +36,7 @@ public class FriendsUpdateService extends PaginatedScheduledService {
|
|||
return new Task<List<Model>>() {
|
||||
@Override
|
||||
public List<Model> call() throws IOException {
|
||||
List<Model> models = new ArrayList<>();
|
||||
List<MyFreeCamsModel> models = new ArrayList<>();
|
||||
String url = myFreeCams.getBaseUrl() + "/php/manage_lists2.php?passcode=&list_type=friends&data_mode=online&get_user_list=1";
|
||||
Request req = new Request.Builder()
|
||||
.url(url)
|
||||
|
@ -69,25 +74,16 @@ public class FriendsUpdateService extends PaginatedScheduledService {
|
|||
LOG.error("Couldn't load friends list {} {}", resp.code(), resp.message());
|
||||
resp.close();
|
||||
}
|
||||
boolean filterOnline = mode == Mode.ONLINE;
|
||||
return models.stream()
|
||||
.sorted((a, b) -> {
|
||||
.filter(m -> {
|
||||
try {
|
||||
if(a.isOnline() && b.isOnline() || !a.isOnline() && !b.isOnline()) {
|
||||
return a.getName().compareTo(b.getName());
|
||||
} else {
|
||||
if(a.isOnline()) {
|
||||
return -1;
|
||||
}
|
||||
if(b.isOnline()) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
} catch (IOException | ExecutionException | InterruptedException e) {
|
||||
LOG.warn("Couldn't sort friends list", e);
|
||||
return 0;
|
||||
return m.isOnline() == filterOnline;
|
||||
} catch(Exception e) {
|
||||
return false;
|
||||
}
|
||||
return 0;
|
||||
})
|
||||
.sorted((m1,m2) -> (int)(m2.getCamScore() - m1.getCamScore()))
|
||||
.skip((page-1) * 50)
|
||||
.limit(50)
|
||||
.collect(Collectors.toList());
|
||||
|
@ -95,4 +91,7 @@ public class FriendsUpdateService extends PaginatedScheduledService {
|
|||
};
|
||||
}
|
||||
|
||||
public void setMode(Mode mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package ctbrec.sites.mfc;
|
||||
import static ctbrec.sites.mfc.FriendsUpdateService.Mode.*;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import ctbrec.ui.ThumbOverviewTab;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.RadioButton;
|
||||
import javafx.scene.control.ToggleGroup;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.util.Duration;
|
||||
|
||||
public class MyFreeCamsFriendsTab extends ThumbOverviewTab {
|
||||
public MyFreeCamsFriendsTab(MyFreeCams mfc) {
|
||||
super("Friends", new FriendsUpdateService(mfc), mfc);
|
||||
updateService.setPeriod(new Duration(TimeUnit.SECONDS.toMillis(10)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createGui() {
|
||||
super.createGui();
|
||||
addOnlineOfflineSelector();
|
||||
}
|
||||
|
||||
private void addOnlineOfflineSelector() {
|
||||
ToggleGroup group = new ToggleGroup();
|
||||
RadioButton online = new RadioButton("online");
|
||||
online.setToggleGroup(group);
|
||||
RadioButton offline = new RadioButton("offline");
|
||||
offline.setToggleGroup(group);
|
||||
pagination.getChildren().add(online);
|
||||
pagination.getChildren().add(offline);
|
||||
HBox.setMargin(online, new Insets(5,5,5,40));
|
||||
HBox.setMargin(offline, new Insets(5,5,5,5));
|
||||
online.setSelected(true);
|
||||
group.selectedToggleProperty().addListener((e) -> {
|
||||
if(online.isSelected()) {
|
||||
((FriendsUpdateService)updateService).setMode(ONLINE);
|
||||
} else {
|
||||
((FriendsUpdateService)updateService).setMode(OFFLINE);
|
||||
}
|
||||
queue.clear();
|
||||
updateService.restart();
|
||||
});
|
||||
}
|
||||
|
||||
public void setScene(Scene scene) {
|
||||
scene.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
|
||||
if(this.isSelected()) {
|
||||
if(event.getCode() == KeyCode.DELETE) {
|
||||
follow(selectedThumbCells, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -31,10 +31,8 @@ public class MyFreeCamsTabProvider extends TabProvider {
|
|||
updateService.setPeriod(new Duration(TimeUnit.SECONDS.toMillis(10)));
|
||||
tabs.add(online);
|
||||
|
||||
updateService = new FriendsUpdateService(myFreeCams);
|
||||
ThumbOverviewTab friends = new ThumbOverviewTab("Friends", updateService, myFreeCams);
|
||||
ThumbOverviewTab friends = new MyFreeCamsFriendsTab(myFreeCams);
|
||||
friends.setRecorder(recorder);
|
||||
updateService.setPeriod(new Duration(TimeUnit.SECONDS.toMillis(10)));
|
||||
tabs.add(friends);
|
||||
|
||||
updateService = new HDCamsUpdateService();
|
||||
|
|
|
@ -30,6 +30,7 @@ import ctbrec.Config;
|
|||
import ctbrec.Model;
|
||||
import ctbrec.recorder.Recorder;
|
||||
import ctbrec.sites.Site;
|
||||
import ctbrec.sites.chaturbate.ChaturbateFollowedTab;
|
||||
import ctbrec.sites.mfc.MyFreeCamsClient;
|
||||
import ctbrec.sites.mfc.MyFreeCamsModel;
|
||||
import javafx.collections.ObservableList;
|
||||
|
@ -61,20 +62,21 @@ import javafx.util.Duration;
|
|||
public class ThumbOverviewTab extends Tab implements TabSelectionListener {
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(ThumbOverviewTab.class);
|
||||
|
||||
static Set<Model> resolutionProcessing = Collections.synchronizedSet(new HashSet<>());
|
||||
static BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();
|
||||
protected static BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();
|
||||
static ExecutorService threadPool = new ThreadPoolExecutor(2, 2, 10, TimeUnit.MINUTES, queue);
|
||||
static Set<Model> resolutionProcessing = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
protected FlowPane grid = new FlowPane();
|
||||
protected PaginatedScheduledService updateService;
|
||||
Recorder recorder;
|
||||
protected HBox pagination;
|
||||
protected List<ThumbCell> selectedThumbCells = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
List<ThumbCell> filteredThumbCells = Collections.synchronizedList(new ArrayList<>());
|
||||
List<ThumbCell> selectedThumbCells = Collections.synchronizedList(new ArrayList<>());
|
||||
Recorder recorder;
|
||||
String filter;
|
||||
FlowPane grid = new FlowPane();
|
||||
ReentrantLock gridLock = new ReentrantLock();
|
||||
ScrollPane scrollPane = new ScrollPane();
|
||||
boolean loginRequired;
|
||||
HBox pagination;
|
||||
TextField pageInput = new TextField(Integer.toString(1));
|
||||
Button pagePrev = new Button("◀");
|
||||
Button pageNext = new Button("▶");
|
||||
|
@ -93,7 +95,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
|
|||
initializeUpdateService();
|
||||
}
|
||||
|
||||
void createGui() {
|
||||
protected void createGui() {
|
||||
grid.setPadding(new Insets(5));
|
||||
grid.setHgap(5);
|
||||
grid.setVgap(5);
|
||||
|
@ -389,7 +391,8 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
|
|||
contextMenu.setAutoHide(true);
|
||||
contextMenu.setHideOnEscape(true);
|
||||
contextMenu.setAutoFix(true);
|
||||
MenuItem followOrUnFollow = this instanceof FollowedTab ? unfollow : follow;
|
||||
// TODO get rid of direct reference to Chaturbate
|
||||
MenuItem followOrUnFollow = this instanceof ChaturbateFollowedTab ? unfollow : follow;
|
||||
contextMenu.getItems().addAll(openInPlayer, startStop);
|
||||
if(site.supportsFollow()) {
|
||||
contextMenu.getItems().add(followOrUnFollow);
|
||||
|
@ -398,7 +401,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
|
|||
contextMenu.getItems().add(sendTip);
|
||||
}
|
||||
contextMenu.getItems().addAll(copyUrl);
|
||||
if(cell.getModel() instanceof MyFreeCamsModel && !Objects.equals(System.getenv("CTBREC_DEV"), "1")) {
|
||||
if(cell.getModel() instanceof MyFreeCamsModel && Objects.equals(System.getenv("CTBREC_DEV"), "1")) {
|
||||
MenuItem debug = new MenuItem("debug");
|
||||
debug.setOnAction((e) -> {
|
||||
MyFreeCamsClient.getInstance().getSessionState(cell.getModel());
|
||||
|
@ -416,7 +419,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
|
|||
}
|
||||
}
|
||||
|
||||
void follow(List<ThumbCell> selection, boolean follow) {
|
||||
protected void follow(List<ThumbCell> selection, boolean follow) {
|
||||
for (ThumbCell thumbCell : selection) {
|
||||
thumbCell.follow(follow);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue