CB optional tabs

This commit is contained in:
jafea7 2025-04-10 21:43:09 +10:00
parent f58bbf8e74
commit 85e5a8bf57
2 changed files with 180 additions and 16 deletions

View File

@ -10,6 +10,8 @@ import javafx.scene.Parent;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import java.util.ArrayList;
import java.util.List;
public class ChaturbateConfigUi extends AbstractConfigUI {
private Chaturbate chaturbate;
@ -100,6 +102,98 @@ public class ChaturbateConfigUi extends AbstractConfigUI {
GridPane.setColumnSpan(requestThrottle, 2);
layout.add(requestThrottle, 1, row++);
Label tabsLabel = new Label("Tabs");
layout.add(tabsLabel, 0, row);
List<String> tabs = getEnabledTabs();
GridPane checkboxGrid = new GridPane();
checkboxGrid.setHgap(10);
checkboxGrid.setVgap(5);
checkboxGrid.setPadding(new Insets(0, 0, 0, 7));
CheckBox female = new CheckBox("Female");
female.setSelected(tabs.contains("f"));
female.setOnAction(e -> toggleTab("f", female.isSelected()));
checkboxGrid.add(female, 0, 0);
CheckBox newFemale = new CheckBox("New Female");
newFemale.setSelected(tabs.contains("nf"));
newFemale.setOnAction(e -> toggleTab("nf", newFemale.isSelected()));
checkboxGrid.add(newFemale, 1, 0);
CheckBox male = new CheckBox("Male");
male.setSelected(tabs.contains("m"));
male.setOnAction(e -> toggleTab("m", male.isSelected()));
checkboxGrid.add(male, 2, 0);
CheckBox newMale = new CheckBox("New Male");
newMale.setSelected(tabs.contains("nm"));
newMale.setOnAction(e -> toggleTab("nm", newMale.isSelected()));
checkboxGrid.add(newMale, 3, 0);
CheckBox couples = new CheckBox("Couples");
couples.setSelected(tabs.contains("c"));
couples.setOnAction(e -> toggleTab("c", couples.isSelected()));
checkboxGrid.add(couples, 0, 1);
CheckBox trans = new CheckBox("Trans");
trans.setSelected(tabs.contains("t"));
trans.setOnAction(e -> toggleTab("t", trans.isSelected()));
checkboxGrid.add(trans, 1, 1);
CheckBox pvt = new CheckBox("Private");
pvt.setSelected(tabs.contains("xp"));
pvt.setOnAction(e -> toggleTab("xp", pvt.isSelected()));
checkboxGrid.add(pvt, 2, 1);
CheckBox hidden = new CheckBox("Hidden");
hidden.setSelected(tabs.contains("xh"));
hidden.setOnAction(e -> toggleTab("xh", hidden.isSelected()));
checkboxGrid.add(hidden, 3, 1);
CheckBox gaming = new CheckBox("Gaming");
gaming.setSelected(tabs.contains("xg"));
gaming.setOnAction(e -> toggleTab("xg", gaming.isSelected()));
checkboxGrid.add(gaming, 0, 2);
CheckBox feat = new CheckBox("Featured");
feat.setSelected(tabs.contains("ft"));
feat.setOnAction(e -> toggleTab("ft", feat.isSelected()));
checkboxGrid.add(feat, 1, 2);
CheckBox top = new CheckBox("Top Rated");
top.setSelected(tabs.contains("ar"));
top.setOnAction(e -> toggleTab("ar", top.isSelected()));
checkboxGrid.add(top, 2, 2);
CheckBox trend = new CheckBox("Trending");
trend.setSelected(tabs.contains("at"));
trend.setOnAction(e -> toggleTab("at", trend.isSelected()));
checkboxGrid.add(trend, 3, 2);
CheckBox asiaOther = new CheckBox("Asia/Oth");
asiaOther.setSelected(tabs.contains("AS,O"));
asiaOther.setOnAction(e -> toggleTab("AS,O", asiaOther.isSelected()));
checkboxGrid.add(asiaOther, 0, 3);
CheckBox euRu = new CheckBox("Eu/Ru");
euRu.setSelected(tabs.contains("ER"));
euRu.setOnAction(e -> toggleTab("ER", euRu.isSelected()));
checkboxGrid.add(euRu, 1, 3);
CheckBox nthAm = new CheckBox("Nth Am");
nthAm.setSelected(tabs.contains("NA"));
nthAm.setOnAction(e -> toggleTab("NA", nthAm.isSelected()));
checkboxGrid.add(nthAm, 2, 3);
CheckBox sthAm = new CheckBox("Sth Am");
sthAm.setSelected(tabs.contains("SA"));
sthAm.setOnAction(e -> toggleTab("SA", sthAm.isSelected()));
checkboxGrid.add(sthAm, 3, 3);
layout.add(checkboxGrid, 1, row, 4, 4);
row += 4;
var createAccount = new Button("Create new Account");
createAccount.setOnAction(e -> DesktopIntegration.open(Chaturbate.REGISTRATION_LINK));
layout.add(createAccount, 1, row++);
@ -121,4 +215,17 @@ public class ChaturbateConfigUi extends AbstractConfigUI {
return layout;
}
private void toggleTab(String region, boolean selected) {
var settings = Config.getInstance().getSettings();
if (selected) {
settings.chaturbateTabs.add(region);
} else {
settings.chaturbateTabs.remove(region);
}
save();
}
private List<String> getEnabledTabs() {
return new ArrayList<>(Config.getInstance().getSettings().chaturbateTabs);
}
}

View File

@ -1,5 +1,6 @@
package ctbrec.ui.sites.chaturbate;
import ctbrec.Config;
import ctbrec.sites.chaturbate.Chaturbate;
import ctbrec.ui.sites.AbstractTabProvider;
import ctbrec.ui.tabs.PaginatedScheduledService;
@ -9,6 +10,7 @@ import javafx.scene.control.Tab;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class ChaturbateTabProvider extends AbstractTabProvider {
@ -24,24 +26,75 @@ public class ChaturbateTabProvider extends AbstractTabProvider {
@Override
protected List<Tab> getSiteTabs(Scene scene) {
List<Tab> tabs = new ArrayList<>();
tabs.add(createTab("Featured", apiUrl + "/roomlist/room-list/?enable_recommendations=false"));
tabs.add(createTab("Female", apiUrl + "/roomlist/room-list/?enable_recommendations=false&genders=f"));
tabs.add(createTab("New Female", apiUrl + "/roomlist/room-list/?enable_recommendations=false&genders=f&new_cams=true"));
tabs.add(createTab("Male", apiUrl + "/roomlist/room-list/?enable_recommendations=false&genders=m"));
tabs.add(createTab("New Male", apiUrl + "/roomlist/room-list/?enable_recommendations=false&genders=m&new_cams=true"));
tabs.add(createTab("Couples", apiUrl + "/roomlist/room-list/?enable_recommendations=false&genders=c"));
tabs.add(createTab("Trans", apiUrl + "/roomlist/room-list/?enable_recommendations=false&genders=t"));
tabs.add(createTab("Private", apiUrl + "/roomlist/room-list/?enable_recommendations=false&private=true"));
tabs.add(createTab("Hidden", apiUrl + "/roomlist/room-list/?enable_recommendations=false&hidden=true"));
tabs.add(createTab("Gaming", apiUrl + "/roomlist/room-list/?enable_recommendations=false&gaming=true"));
followedTab.setScene(scene);
followedTab.setRecorder(recorder);
followedTab.setImageAspectRatio(9.0 / 16.0);
tabs.add(followedTab);
tabs.add(createApiTab("Top Rated", apiUrl + "/discover/carousels/top-rated/"));
tabs.add(createApiTab("Trending", apiUrl + "/discover/carousels/trending/"));
for (String tab : getEnabledTabs()) {
switch (tab) {
case "ft":
tabs.add(createTab("Featured", apiUrl + "/roomlist/room-list/?enable_recommendations=false"));
break;
case "f":
case "m":
case "c":
case "t":
tabs.add(createTab("Female", apiUrl + "/roomlist/room-list/?enable_recommendations=false&genders=" + tab));
break;
case "nf":
addNewCamsTab(tabs, "New Female", "f");
break;
case "nm":
addNewCamsTab(tabs, "New Male", "m");
break;
case "xp":
tabs.add(createTab("Private", apiUrl + "/roomlist/room-list/?enable_recommendations=false&private=true"));
break;
case "xh":
tabs.add(createTab("Hidden", apiUrl + "/roomlist/room-list/?enable_recommendations=false&hidden=true"));
break;
case "xg":
tabs.add(createTab("Gaming", apiUrl + "/roomlist/room-list/?enable_recommendations=false&gaming=true"));
break;
case "ar":
tabs.add(createApiTab("Top Rated", apiUrl + "/discover/carousels/top-rated/"));
break;
case "at":
tabs.add(createApiTab("Trending", apiUrl + "/discover/carousels/trending/"));
break;
default:
if (Pattern.matches("^[A-Z].+", tab)) {
addRegionBasedTab(tabs, tab);
}
break;
}
}
return tabs;
}
private void addNewCamsTab(List<Tab> tabs, String title, String gender) {
tabs.add(createTab(title, apiUrl + "/roomlist/room-list/?enable_recommendations=false&genders=" + gender + "&new_cams=true"));
}
private void addRegionBasedTab(List<Tab> tabs, String regionCode) {
String regions = getRegionTitle(regionCode);
if (regions != null) {
tabs.add(createTab(regions, apiUrl + "/roomlist/room-list/?enable_recommendations=false&regions=" + regionCode));
}
}
private String getRegionTitle(String regionCode) {
switch (regionCode) {
case "AS,O":
return "Asia/Oth";
case "ER":
return "Eu/Ru";
case "NA":
return "Nth Amer";
case "SA":
return "Sth Amer";
default:
return null;
}
}
@Override
public Tab getFollowedTab() {
@ -64,4 +117,8 @@ public class ChaturbateTabProvider extends AbstractTabProvider {
var updateService = new ChaturbateApiUpdateService(apiUrl, (Chaturbate) site);
return createTab(title, updateService);
}
private List<String> getEnabledTabs() {
return new ArrayList<>(Config.getInstance().getSettings().chaturbateTabs);
}
}