diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/images/1047883_1711005940.png b/images/1047883_1711005940.png
new file mode 100644
index 0000000..6d9ee00
Binary files /dev/null and b/images/1047883_1711005940.png differ
diff --git a/images/1047883_1711005940.webp b/images/1047883_1711005940.webp
new file mode 100644
index 0000000..43dca6b
Binary files /dev/null and b/images/1047883_1711005940.webp differ
diff --git a/images/104992_1711005934.png b/images/104992_1711005934.png
new file mode 100644
index 0000000..688c4f8
Binary files /dev/null and b/images/104992_1711005934.png differ
diff --git a/images/104992_1711005934.webp b/images/104992_1711005934.webp
new file mode 100644
index 0000000..c0c5667
Binary files /dev/null and b/images/104992_1711005934.webp differ
diff --git a/images/1219149_1711005919.png b/images/1219149_1711005919.png
new file mode 100644
index 0000000..e9fcbd2
Binary files /dev/null and b/images/1219149_1711005919.png differ
diff --git a/images/1219149_1711005919.webp b/images/1219149_1711005919.webp
new file mode 100644
index 0000000..7cad0ae
Binary files /dev/null and b/images/1219149_1711005919.webp differ
diff --git a/images/1311078_1711005805.png b/images/1311078_1711005805.png
new file mode 100644
index 0000000..99d8c10
Binary files /dev/null and b/images/1311078_1711005805.png differ
diff --git a/images/1311078_1711005805.webp b/images/1311078_1711005805.webp
new file mode 100644
index 0000000..c9cd5c0
Binary files /dev/null and b/images/1311078_1711005805.webp differ
diff --git a/images/1338480_1711005954.png b/images/1338480_1711005954.png
new file mode 100644
index 0000000..4c6a42e
Binary files /dev/null and b/images/1338480_1711005954.png differ
diff --git a/images/1338480_1711005954.webp b/images/1338480_1711005954.webp
new file mode 100644
index 0000000..178b63a
Binary files /dev/null and b/images/1338480_1711005954.webp differ
diff --git a/images/1396687_1711005696.png b/images/1396687_1711005696.png
new file mode 100644
index 0000000..def56d3
Binary files /dev/null and b/images/1396687_1711005696.png differ
diff --git a/images/1396687_1711005696.webp b/images/1396687_1711005696.webp
new file mode 100644
index 0000000..b025e84
Binary files /dev/null and b/images/1396687_1711005696.webp differ
diff --git a/images/1405959_1711005703.png b/images/1405959_1711005703.png
new file mode 100644
index 0000000..976d251
Binary files /dev/null and b/images/1405959_1711005703.png differ
diff --git a/images/1405959_1711005703.webp b/images/1405959_1711005703.webp
new file mode 100644
index 0000000..1a0021b
Binary files /dev/null and b/images/1405959_1711005703.webp differ
diff --git a/images/1435343_1711005913.png b/images/1435343_1711005913.png
new file mode 100644
index 0000000..3a761a8
Binary files /dev/null and b/images/1435343_1711005913.png differ
diff --git a/images/1435343_1711005913.webp b/images/1435343_1711005913.webp
new file mode 100644
index 0000000..cd227c4
Binary files /dev/null and b/images/1435343_1711005913.webp differ
diff --git a/images/1711005829_bez-nazvanija.png b/images/1711005829_bez-nazvanija.png
new file mode 100644
index 0000000..9966570
Binary files /dev/null and b/images/1711005829_bez-nazvanija.png differ
diff --git a/images/1711005829_bez-nazvanija.webp b/images/1711005829_bez-nazvanija.webp
new file mode 100644
index 0000000..75e5cb7
Binary files /dev/null and b/images/1711005829_bez-nazvanija.webp differ
diff --git a/images/1711005866_180266.png b/images/1711005866_180266.png
new file mode 100644
index 0000000..6431cf2
Binary files /dev/null and b/images/1711005866_180266.png differ
diff --git a/images/1711005866_180266.webp b/images/1711005866_180266.webp
new file mode 100644
index 0000000..4084303
Binary files /dev/null and b/images/1711005866_180266.webp differ
diff --git a/images/1993_1711005947.png b/images/1993_1711005947.png
new file mode 100644
index 0000000..09b96dd
Binary files /dev/null and b/images/1993_1711005947.png differ
diff --git a/images/1993_1711005947.webp b/images/1993_1711005947.webp
new file mode 100644
index 0000000..8cf752f
Binary files /dev/null and b/images/1993_1711005947.webp differ
diff --git a/images/2213_1711005981.png b/images/2213_1711005981.png
new file mode 100644
index 0000000..d5c741c
Binary files /dev/null and b/images/2213_1711005981.png differ
diff --git a/images/2213_1711005981.webp b/images/2213_1711005981.webp
new file mode 100644
index 0000000..4656038
Binary files /dev/null and b/images/2213_1711005981.webp differ
diff --git a/images/403_1711005928.png b/images/403_1711005928.png
new file mode 100644
index 0000000..fdca047
Binary files /dev/null and b/images/403_1711005928.png differ
diff --git a/images/403_1711005928.webp b/images/403_1711005928.webp
new file mode 100644
index 0000000..8df3d55
Binary files /dev/null and b/images/403_1711005928.webp differ
diff --git a/images/4482093_1711005725.png b/images/4482093_1711005725.png
new file mode 100644
index 0000000..5212c15
Binary files /dev/null and b/images/4482093_1711005725.png differ
diff --git a/images/4482093_1711005725.webp b/images/4482093_1711005725.webp
new file mode 100644
index 0000000..5611468
Binary files /dev/null and b/images/4482093_1711005725.webp differ
diff --git a/images/4511631_1711005878.png b/images/4511631_1711005878.png
new file mode 100644
index 0000000..99f3bb1
Binary files /dev/null and b/images/4511631_1711005878.png differ
diff --git a/images/4511631_1711005878.webp b/images/4511631_1711005878.webp
new file mode 100644
index 0000000..3c7357b
Binary files /dev/null and b/images/4511631_1711005878.webp differ
diff --git a/images/4540126_1711005740.png b/images/4540126_1711005740.png
new file mode 100644
index 0000000..ad38a32
Binary files /dev/null and b/images/4540126_1711005740.png differ
diff --git a/images/4540126_1711005740.webp b/images/4540126_1711005740.webp
new file mode 100644
index 0000000..44992f5
Binary files /dev/null and b/images/4540126_1711005740.webp differ
diff --git a/images/4878248_1711005974.png b/images/4878248_1711005974.png
new file mode 100644
index 0000000..22ae07a
Binary files /dev/null and b/images/4878248_1711005974.png differ
diff --git a/images/4878248_1711005974.webp b/images/4878248_1711005974.webp
new file mode 100644
index 0000000..8e7da8e
Binary files /dev/null and b/images/4878248_1711005974.webp differ
diff --git a/images/5024491_1711005884.png b/images/5024491_1711005884.png
new file mode 100644
index 0000000..a8bcc9f
Binary files /dev/null and b/images/5024491_1711005884.png differ
diff --git a/images/5024491_1711005884.webp b/images/5024491_1711005884.webp
new file mode 100644
index 0000000..ab234e7
Binary files /dev/null and b/images/5024491_1711005884.webp differ
diff --git a/images/5120138_1711005811.png b/images/5120138_1711005811.png
new file mode 100644
index 0000000..5ede1d0
Binary files /dev/null and b/images/5120138_1711005811.png differ
diff --git a/images/5120138_1711005811.webp b/images/5120138_1711005811.webp
new file mode 100644
index 0000000..50ccf2a
Binary files /dev/null and b/images/5120138_1711005811.webp differ
diff --git a/images/5144406_1711005839.png b/images/5144406_1711005839.png
new file mode 100644
index 0000000..1a362d5
Binary files /dev/null and b/images/5144406_1711005839.png differ
diff --git a/images/5144406_1711005839.webp b/images/5144406_1711005839.webp
new file mode 100644
index 0000000..16e7a59
Binary files /dev/null and b/images/5144406_1711005839.webp differ
diff --git a/images/5364708_1711005849.png b/images/5364708_1711005849.png
new file mode 100644
index 0000000..b34e1d8
Binary files /dev/null and b/images/5364708_1711005849.png differ
diff --git a/images/5364708_1711005849.webp b/images/5364708_1711005849.webp
new file mode 100644
index 0000000..643d785
Binary files /dev/null and b/images/5364708_1711005849.webp differ
diff --git a/images/5437562_1711005900.png b/images/5437562_1711005900.png
new file mode 100644
index 0000000..7966301
Binary files /dev/null and b/images/5437562_1711005900.png differ
diff --git a/images/5437562_1711005900.webp b/images/5437562_1711005900.webp
new file mode 100644
index 0000000..cce4f45
Binary files /dev/null and b/images/5437562_1711005900.webp differ
diff --git a/images/804476_1711005789.png b/images/804476_1711005789.png
new file mode 100644
index 0000000..b0873b5
Binary files /dev/null and b/images/804476_1711005789.png differ
diff --git a/images/804476_1711005789.webp b/images/804476_1711005789.webp
new file mode 100644
index 0000000..0a1d88a
Binary files /dev/null and b/images/804476_1711005789.webp differ
diff --git a/images/817324_1711005962.png b/images/817324_1711005962.png
new file mode 100644
index 0000000..6ded301
Binary files /dev/null and b/images/817324_1711005962.png differ
diff --git a/images/817324_1711005962.webp b/images/817324_1711005962.webp
new file mode 100644
index 0000000..ea8384d
Binary files /dev/null and b/images/817324_1711005962.webp differ
diff --git a/images/891578_1711005797.png b/images/891578_1711005797.png
new file mode 100644
index 0000000..c810d83
Binary files /dev/null and b/images/891578_1711005797.png differ
diff --git a/images/891578_1711005797.webp b/images/891578_1711005797.webp
new file mode 100644
index 0000000..91fcb69
Binary files /dev/null and b/images/891578_1711005797.webp differ
diff --git a/images/913425_1711005908.png b/images/913425_1711005908.png
new file mode 100644
index 0000000..ba970bb
Binary files /dev/null and b/images/913425_1711005908.png differ
diff --git a/images/913425_1711005908.webp b/images/913425_1711005908.webp
new file mode 100644
index 0000000..4ca3266
Binary files /dev/null and b/images/913425_1711005908.webp differ
diff --git a/pom.xml b/pom.xml
index e16f1b5..da64c91 100644
--- a/pom.xml
+++ b/pom.xml
@@ -15,6 +15,26 @@
+
+
+ org.jsoup
+ jsoup
+ 1.17.2
+
+
+
+ org.xerial
+ sqlite-jdbc
+ 3.36.0.3
+
+
+
+
+ org.sejda.imageio
+ webp-imageio
+ 0.1.6
+
+
org.openjfx
javafx-controls
diff --git a/src/main/java/com/mdkefir/filmlibrary/Database.java b/src/main/java/com/mdkefir/filmlibrary/Database.java
new file mode 100644
index 0000000..3bf4f34
--- /dev/null
+++ b/src/main/java/com/mdkefir/filmlibrary/Database.java
@@ -0,0 +1,59 @@
+package com.mdkefir.filmlibrary;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.Statement;
+
+public class Database {
+ public static Connection connect() {
+ String url = "jdbc:sqlite:src/main/java/com/mdkefir/filmlibrary/filmlibrary.db"; // Укажите путь к вашей базе данных
+ Connection conn = null;
+ try {
+ conn = DriverManager.getConnection(url);
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ }
+ return conn;
+ }
+
+ public static void createNewDatabase() {
+ try (Connection conn = connect()) {
+ if (conn != null) {
+ Statement stmt = conn.createStatement();
+ // Создание таблицы пользователей
+ /*stmt.execute("DROP TABLE users");*/
+ stmt.execute("CREATE TABLE IF NOT EXISTS users (" +
+ "id INTEGER PRIMARY KEY AUTOINCREMENT," +
+ "username TEXT NOT NULL UNIQUE," +
+ "password TEXT NOT NULL," +
+ "secret_code TEXT);");
+
+ /*stmt.execute("DROP TABLE favorites");*/
+ // Создание таблицы избранных фильмов
+ stmt.execute("CREATE TABLE IF NOT EXISTS favorites (" +
+ "user_id INTEGER," +
+ "title TEXT," +
+ "year TEXT," +
+ "rating TEXT," +
+ "image_path TEXT," +
+ "FOREIGN KEY(user_id) REFERENCES users(id));");
+
+ // Создание таблицы друзей
+ stmt.execute("CREATE TABLE IF NOT EXISTS friends (" +
+ "user_id INTEGER," +
+ "friend_id INTEGER," +
+ "FOREIGN KEY(user_id) REFERENCES users(id)," +
+ "FOREIGN KEY(friend_id) REFERENCES users(id));");
+
+ System.out.println("Таблицы созданы");
+ }
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ }
+ }
+
+ public static void main(String[] args) {
+ createNewDatabase(); // Создание базы данных и таблиц при запуске
+ }
+}
+
diff --git a/src/main/java/com/mdkefir/filmlibrary/Main.java b/src/main/java/com/mdkefir/filmlibrary/Main.java
index 763004c..7b25269 100644
--- a/src/main/java/com/mdkefir/filmlibrary/Main.java
+++ b/src/main/java/com/mdkefir/filmlibrary/Main.java
@@ -8,7 +8,6 @@
import javafx.scene.paint.Color;
import javafx.stage.Stage;
-
public class Main extends Application {
public static void main(String[] args) {
launch(args);
@@ -17,7 +16,7 @@ public static void main(String[] args) {
@Override
public void start(Stage primaryStage) {
try {
- primaryStage.setMinWidth(920);
+ primaryStage.setMinWidth(925);
primaryStage.setMinHeight(620);
Button closeButton = new Button("Закрыть");
closeButton.setOnAction(e -> primaryStage.close());
diff --git a/src/main/java/com/mdkefir/filmlibrary/controllers/AuthController.java b/src/main/java/com/mdkefir/filmlibrary/controllers/AuthController.java
new file mode 100644
index 0000000..f677458
--- /dev/null
+++ b/src/main/java/com/mdkefir/filmlibrary/controllers/AuthController.java
@@ -0,0 +1,106 @@
+package com.mdkefir.filmlibrary.controllers;
+
+import com.mdkefir.filmlibrary.Database;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class AuthController {
+ private Database db;
+
+ public AuthController() {
+ db = new Database(); // Предполагается, что у вас есть класс Database для работы с базой данных
+ }
+
+ public boolean registerUser(String username, String password) {
+ String sql = "INSERT INTO users (username, password) VALUES (?, ?)";
+ try (Connection conn = db.connect();
+ PreparedStatement pstmt = conn.prepareStatement(sql)) {
+ pstmt.setString(1, username);
+ pstmt.setString(2, password); // В реальном приложении пароль следует хранить в зашифрованном виде
+ pstmt.executeUpdate();
+ return true;
+ } catch (SQLException e) {
+ System.out.println(e.getMessage());
+ return false;
+ }
+ }
+
+ public boolean loginUser(String username, String password) {
+ String sql = "SELECT * FROM users WHERE username = ? AND password = ?";
+ try (Connection conn = db.connect();
+ PreparedStatement pstmt = conn.prepareStatement(sql)) {
+ pstmt.setString(1, username);
+ pstmt.setString(2, password);
+ ResultSet rs = pstmt.executeQuery();
+ return rs.next(); // Возвращает true, если пользователь найден
+ } catch (SQLException e) {
+ System.out.println(e.getMessage());
+ return false;
+ }
+ }
+
+ public int getUserId(String username) {
+ String sql = "SELECT id FROM users WHERE username = ?";
+ try (Connection conn = db.connect();
+ PreparedStatement pstmt = conn.prepareStatement(sql)) {
+ pstmt.setString(1, username);
+ ResultSet rs = pstmt.executeQuery();
+ if (rs.next()) {
+ return rs.getInt("id");
+ }
+ } catch (SQLException e) {
+ System.out.println("Ошибка получения ID пользователя: " + e.getMessage());
+ }
+ return -1; // Возвращаем -1, если пользователь не найден
+ }
+
+ public boolean addFriend(int userId, String friendName, String secretCode) {
+ String sql = "INSERT INTO friends (user_id, friend_id) VALUES (?, ?)";
+ try (Connection conn = db.connect();
+ PreparedStatement pstmt = conn.prepareStatement(sql)) {
+ pstmt.setInt(1, userId);
+ pstmt.setString(2, friendName);
+ pstmt.executeUpdate();
+ return true;
+ } catch (SQLException e) {
+ System.out.println("Ошибка добавления друга: " + e.getMessage());
+ return false;
+ }
+ }
+
+ public boolean deleteFriend(int userId, String friendName) {
+ String sql = "DELETE FROM friends WHERE user_id = ? AND friend_name = ?";
+ try (Connection conn = db.connect();
+ PreparedStatement pstmt = conn.prepareStatement(sql)) {
+ pstmt.setInt(1, userId);
+ pstmt.setString(2, friendName);
+ pstmt.executeUpdate();
+ return true;
+ } catch (SQLException e) {
+ System.out.println("Ошибка удаления друга: " + e.getMessage());
+ return false;
+ }
+ }
+
+ public List getFriends(int userId) {
+ List friends = new ArrayList<>();
+ String sql = "SELECT friend_id FROM friends WHERE user_id = ?";
+ try (Connection conn = db.connect();
+ PreparedStatement pstmt = conn.prepareStatement(sql)) {
+ pstmt.setInt(1, userId);
+ ResultSet rs = pstmt.executeQuery();
+ while (rs.next()) {
+ friends.add(rs.getString("friend_name"));
+ }
+ } catch (SQLException e) {
+ System.out.println("Ошибка получения списка друзей: " + e.getMessage());
+ }
+ return friends;
+ }
+
+}
diff --git a/src/main/java/com/mdkefir/filmlibrary/controllers/MainController.java b/src/main/java/com/mdkefir/filmlibrary/controllers/MainController.java
index b27cbd5..ac35856 100644
--- a/src/main/java/com/mdkefir/filmlibrary/controllers/MainController.java
+++ b/src/main/java/com/mdkefir/filmlibrary/controllers/MainController.java
@@ -1,30 +1,71 @@
package com.mdkefir.filmlibrary.controllers;
+import com.mdkefir.filmlibrary.Database;
import com.mdkefir.filmlibrary.models.Movie;
-import com.mdkefir.filmlibrary.models.Series;
-import com.mdkefir.filmlibrary.models.SportEvent;
+import com.mdkefir.filmlibrary.models.User;
+import javafx.application.Platform;
+import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
-import javafx.geometry.Insets;
+import javafx.fxml.FXMLLoader;
import javafx.geometry.Pos;
import javafx.scene.Node;
+import javafx.scene.Parent;
+import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
-import javafx.scene.layout.AnchorPane;
-import javafx.scene.layout.Region;
-import javafx.scene.layout.TilePane;
-import javafx.scene.layout.VBox;
+import javafx.scene.layout.*;
import javafx.scene.paint.Color;
-
-import java.io.InputStream;
+import java.awt.image.BufferedImage;
+import java.io.*;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
+import javafx.scene.shape.Rectangle;
+import javafx.stage.*;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
+
+import javax.imageio.ImageIO;
+
public class MainController {
@FXML private TextField searchField;
+ private AuthController authController;
+ private String currentCategory;
+ private Stage loadingStage;
+
+ // Добавляем поля класса для использования в POPUP
+ private TextField emailField = new TextField();
+ private PasswordField passwordField = new PasswordField();
+ private Label statusLabel = new Label(""); // Для сообщений о состоянии
+
+ private Database db;
+
+ @FXML
+ private HBox searchHBox;
+
+
+ @FXML
+ private AnchorPane authPane; // Панель авторизации/регистрации
+
@FXML
private Label filmLabel;
@@ -45,6 +86,8 @@ private void handleSeriesMenu() {
private void handleSearch() {
// Обработка поиска
}
+ @FXML
+ private ScrollPane scrollPaneMovie; // Добавьте ScrollPane в FXML и свяжите его здесь
@FXML
private ToggleButton moviesButton;
@@ -53,94 +96,254 @@ private void handleSearch() {
private ToggleButton seriesButton;
@FXML
- private ToggleButton sportsButton;
+ private ToggleButton cartoonsButton;
+
+ @FXML ToggleButton myAccountButton;
+
+ @FXML
+ private ToggleButton favoritesButton;
@FXML
private ToggleGroup categoryToggleGroup = new ToggleGroup();
+
@FXML
- private List getMovies() {
- return List.of(
- new Movie("Терминатор 2: СД", "/com/mdkefir/filmlibrary/images/movies/1.png"),
- new Movie("1+1", "/com/mdkefir/filmlibrary/images/movies/2.png"),
- new Movie("Ходячий замок", "/com/mdkefir/filmlibrary/images/movies/3.png"),
- new Movie("Список Шиндлера", "/com/mdkefir/filmlibrary/images/movies/4.png"),
- new Movie("Властелин колец", "/com/mdkefir/filmlibrary/images/movies/5.png"),
- new Movie("Бойцовский клуб", "/com/mdkefir/filmlibrary/images/movies/6.png"),
- new Movie("Интерстеллар", "/com/mdkefir/filmlibrary/images/movies/7.png"),
- new Movie("Форрест Гамп", "/com/mdkefir/filmlibrary/images/movies/8.png"),
- new Movie("Зеленая миля", "/com/mdkefir/filmlibrary/images/movies/9.png"),
- new Movie("Властелин колец 2", "/com/mdkefir/filmlibrary/images/movies/10.png")
- // Добавьте больше фильмов
- );
- }
- @FXML
- private List getSeries() {
- return List.of(
- new Series("Во все тяжкие", "/com/mdkefir/filmlibrary/images/series/1.png"),
- new Series("Игра престолов", "/com/mdkefir/filmlibrary/images/series/2.png"),
- new Series("Клан Сопрано", "/com/mdkefir/filmlibrary/images/series/3.png"),
- new Series("Офис", "/com/mdkefir/filmlibrary/images/series/4.png"),
- new Series("Друзья", "/com/mdkefir/filmlibrary/images/series/5.png"),
- new Series("Гравити Фолз", "/com/mdkefir/filmlibrary/images/series/6.png"),
- new Series("Тед Лассо", "/com/mdkefir/filmlibrary/images/series/7.png"),
- new Series("Атака Титанов", "/com/mdkefir/filmlibrary/images/series/8.png"),
- new Series("Шерлок", "/com/mdkefir/filmlibrary/images/series/9.png"),
- new Series("Чернобыль", "/com/mdkefir/filmlibrary/images/series/10.png"),
- new Series("Голяк", "/com/mdkefir/filmlibrary/images/series/11.png"),
- new Series("Крепость Бадабер", "/com/mdkefir/filmlibrary/images/series/12.png")
- // Добавьте больше сериалов
- );
- }
- @FXML
- private List getSportEvents() {
- return List.of(
- new SportEvent("World Cup 2022", "/com/mdkefir/filmlibrary/images/sportevent/1.png"),
- new SportEvent("Олимпийские игры 2014", "/com/mdkefir/filmlibrary/images/sportevent/2.png")
- // Добавьте больше спортивных событий
- );
- }
- private Node getContentForMovies() {
- return createContentTilePane(getMovies());
- }
-
- private Node getContentForSeries() {
- return createContentTilePane(getSeries());
- }
-
- private Node getContentForSports() {
- return createContentTilePane(getSportEvents());
- }
- @FXML
- private VBox createVBoxForContent(String title, String imagePath) {
- VBox vbox = new VBox(5);
- InputStream is = getClass().getResourceAsStream(imagePath);
- if (is == null) {
- throw new IllegalArgumentException("ПОСОСИПОСОСИПОСОСИПОСОСИ " + imagePath);
- }
- Image image = new Image(is);
- ImageView imageView = new ImageView(image);
- imageView.setFitHeight(225);
- imageView.setFitWidth(150);
- Label label = new Label(title);
- vbox.getChildren().addAll(imageView, label);
- vbox.getStyleClass().add("filmListTile"); // Добавьте класс стилей, как в вашем FXML
- return vbox;
+ private AnchorPane friendsPane;
+
+ @FXML
+ private AnchorPane filtersPane;
+
+ @FXML
+ private CheckBox showAccessCheckBox;
+
+ @FXML
+ private ComboBox favoriteFriendComboBox;
+
+ @FXML
+ private Button acceptFavoriteFriendButton;
+
+ @FXML
+ private Label favoriteText1;
+
+ @FXML
+ private Label favoriteText2;
+
+ @FXML
+ private ToggleButton friendsButton;
+
+ @FXML
+ private Rectangle friendRectangle;
+
+ @FXML
+ private Label friendStatusLabel;
+
+ @FXML
+ private TextField nameFriend;
+ @FXML
+ private TextField secretCodeFriend;
+ @FXML
+ private ComboBox friendChoose;
+ @FXML
+ private TextField fieldSecretWord;
+
+ @FXML
+ private Button friendAdd;
+ @FXML
+ private Button friendDelete;
+ @FXML
+ private Button applySecretWordButton;
+
+ private int currentUserId;
+
+ public void setCurrentUserId(int userId) {
+ this.currentUserId = userId;
+ loadFriends();
}
+
+ private AtomicInteger currentPage = new AtomicInteger(1);
+ private volatile boolean isLoading = false;
+ private final int totalPages = 30;
+
+ public String downloadImage(String imageUrl, String s) throws IOException {
+ // Create a URL object from the image URL string
+ URL url = new URL(imageUrl);
+ // Extract the file name from the URL
+ String fileName = Paths.get(url.getPath()).getFileName().toString();
+ // Define the path where the image will be saved
+ Path targetPath = Paths.get(System.getProperty("user.dir")).resolve("images").resolve(fileName);
+
+ // Open a stream to the image URL
+ try (InputStream in = url.openStream()) {
+ // Copy the image to the target path, replacing any existing file
+ Files.copy(in, targetPath, StandardCopyOption.REPLACE_EXISTING);
+ }
+
+ // Return the file path as a string
+ return targetPath.toString();
+ }
+
+ public String downloadAndConvertImage(String imageUrl, String destinationFolder) throws IOException, URISyntaxException {
+ // Скачивание изображения
+ String imageExtension = imageUrl.substring(imageUrl.lastIndexOf(".") + 1);
+ String localImagePath = downloadImage(imageUrl, destinationFolder);
+
+ // Конвертация в формат PNG, если это необходимо
+ if (!"png".equals(imageExtension) && !"jpg".equals(imageExtension)) {
+ String outputImagePath = localImagePath.substring(0, localImagePath.lastIndexOf(".")) + ".png";
+ convertToPng(localImagePath, outputImagePath);
+ return outputImagePath; // Вернуть новый путь к изображению
+ }
+
+ return localImagePath; // Вернуть исходный путь к изображению
+ }
+
+ public static void convertToPng(String inputImagePath, String outputImagePath) throws IOException {
+ BufferedImage bufferedImage = ImageIO.read(new File(inputImagePath));
+ ImageIO.write(bufferedImage, "png", new File(outputImagePath));
+ }
+
+ public List parseMedia(String baseUrl, int page) {
+ List mediaList = new ArrayList<>();
+ try {
+ Document doc = Jsoup.connect(baseUrl + "page/" + (page + 1) + "/").get();
+ Elements mediaElements = doc.select(".sect-cont.sect-items.clearfix .th-item");
+
+ for (Element mediaElement : mediaElements) {
+ String title = mediaElement.select(".th-title").text();
+ String year = mediaElement.select(".th-year").text();
+ String rating = mediaElement.select(".th-rates .th-rate.th-rate-imdb").text();
+ String imageUrl = mediaElement.select("img").first().absUrl("src");
+
+ if (!imageUrl.isEmpty()) {
+ String localImagePath = downloadAndConvertImage(imageUrl, "images/");
+ mediaList.add(new Movie (title, year, rating, localImagePath));
+ }
+ }
+ } catch (IOException | URISyntaxException e) {
+ e.printStackTrace();
+ }
+ return mediaList;
+ }
+
+ /*
+ public List parseFilms() {
+ List movies = new ArrayList<>();
+ String baseUrl = "https://lordfilm.ai/filmy/page/";
+
+ try {
+ for (int i = 1; i <= 5; i++) { // Loop through pages 1 to 5
+ Document doc = Jsoup.connect(baseUrl + i + "/").get();
+ Elements movieElements = doc.select(".sect-cont.sect-items.clearfix .th-item");
+
+ for (Element movieElement : movieElements) {
+ String title = movieElement.select(".th-title").text();
+ String imageUrl = movieElement.select("img").first().absUrl("src");
+
+ if (!imageUrl.isEmpty()) {
+ movies.add(new Movie(title, imageUrl));
+ }
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ return movies;
+}*/
+
+
+
@FXML
public void initialize() {
+ authController = new AuthController();
// Назначаем все кнопки одной группе
- moviesButton.setToggleGroup(categoryToggleGroup);
- seriesButton.setToggleGroup(categoryToggleGroup);
- sportsButton.setToggleGroup(categoryToggleGroup);
+ hideAllExtraPanes();
+
+ friendsButton.setOnAction(event -> {
+ if (friendsButton.isSelected()) {
+ hideAllExtraPanes();
+ showFriendsPane();
+ } else {
+ hideAllExtraPanes();
+ }
+ });
+
+ favoritesButton.setOnAction(event -> {
+ if (favoritesButton.isSelected()) {
+ showFavoritePane();
+ loadFavorites();
+ } else {
+ hideAllExtraPanes();
+ }
+ });
+
+ moviesButton.setOnAction(event -> {
+
+ /*scrollPaneMovie.setVisible(false);
+ scrollPaneMovie.setManaged(false);
+ filtersPane.setVisible(false);
+ filtersPane.setManaged(false);
+ searchHBox.setVisible(false);*/
+ showLoadingScreen();
+ currentPage.set(1); // Устанавливаем номер текущей страницы на 1
+ clearContent(); // Очищаем содержимое перед загрузкой нового
+ loadMovies();
+ hideAllExtraPanes();
+ });
+
+ seriesButton.setOnAction(event -> {
+
+ showLoadingScreen();
+ currentPage.set(1); // Устанавливаем номер текущей страницы на 1
+ clearContent(); // Очищаем содержимое перед загрузкой нового
+ loadSeries();
+ hideAllExtraPanes();
+ });
+
+ cartoonsButton.setOnAction(event -> {
+
+ showLoadingScreen();
+ currentPage.set(1); // Устанавливаем номер текущей страницы на 1
+ clearContent(); // Очищаем содержимое перед загрузкой нового
+ loadCartoons();
+ hideAllExtraPanes();
+ });
+
+ myAccountButton.setOnAction(event -> {
+
+ });
+
+ friendAdd.setOnAction(event -> {
+ handleAddFriend();
+ });
+
+ friendDelete.setOnAction(event -> {
+ handleDeleteFriend();
+ });
+ applySecretWordButton.setOnAction(event -> {
+ handleApplySecretWord();
+ });
+
+ scrollPaneMovie.vvalueProperty().addListener((obs, oldValue, newValue) -> {
+ if (newValue.doubleValue() >= scrollPaneMovie.getVmax() - 0.5) { // Threshold can be adjusted
+ if (!isLoading && currentPage.get() <= totalPages) {
+ switch (currentCategory) {
+ case "movies":
+ loadMovies();
+ break;
+ case "series":
+ loadSeries();
+ break;
+ case "cartoons":
+ loadCartoons();
+ break;
+ }
+ }
+ }
+ });
- // настройка категорий для отображения
- moviesButton.setOnAction(event -> updateTilePaneContent(getContentForMovies()));
- seriesButton.setOnAction(event -> updateTilePaneContent(getContentForSeries()));
- sportsButton.setOnAction(event -> updateTilePaneContent(getContentForSports()));
+ loadMovies();
- // По умолчанию показываем контент для фильмов
- updateTilePaneContent(getContentForMovies());
// Найти все VBox'ы с классом "film-box"
List filmBoxes = moviesTilePane.getChildren().stream()
@@ -157,7 +360,24 @@ public void initialize() {
// По умолчанию выбираем "Фильмы"
moviesButton.setSelected(true);
+ createLoginPopup();
+ }
+ private void hideAllExtraPanes() {
+ friendsPane.setVisible(false);
+ friendsPane.setManaged(false);
+ filtersPane.setVisible(false);
+ filtersPane.setManaged(false);
+ }
+
+ private void showFriendsPane() {
+ friendsPane.setVisible(true);
+ friendsPane.setManaged(true);
+ }
+
+ private void showFavoritePane() {
+ filtersPane.setVisible(true);
+ filtersPane.setManaged(true);
}
@@ -173,70 +393,433 @@ private void setLabelStyle(VBox vbox, Color color) {
});
}
+ private void createLoginPopup() {
+ Popup popup = new Popup();
+ VBox popupContent = new VBox(10);
+ popupContent.setStyle("-fx-background-color: #283035; -fx-padding: 10;");
+
+ Label titleLabel = new Label("Авторизация / Регистрация");
+ titleLabel.setStyle("-fx-text-fill: white;");
+
+ // Используйте поля класса
+ emailField.setPromptText("Эл. почта");
+ passwordField.setPromptText("Пароль");
+
+ // Создание HBox для кнопок
+ HBox buttonBar = new HBox(10); // Расстояние между кнопками
+ Button loginButton = new Button("Войти");
+ Button registerButton = new Button("Регистрация");
+ buttonBar.getChildren().addAll(loginButton, registerButton);
+ buttonBar.setAlignment(Pos.CENTER); // Центрирование кнопок в HBox
+
+ // Настройка statusLabel
+ statusLabel.setStyle("-fx-text-fill: WHITE; -fx-font-size: 14px;");
+ statusLabel.setMaxWidth(Double.MAX_VALUE);
+ statusLabel.setAlignment(Pos.CENTER); // Центрирование текста внутри Label
+
+ // Настройка statusLabel
+ friendStatusLabel.setStyle("-fx-text-fill: WHITE; -fx-font-size: 14px;");
+ friendStatusLabel.setMaxWidth(Double.MAX_VALUE);
+ friendStatusLabel.setAlignment(Pos.CENTER); // Центрирование текста внутри Label
+
+ // Установка обработчиков
+ loginButton.setOnAction(e -> handleLogin());
+ registerButton.setOnAction(e -> handleRegistration());
+
+ popupContent.getChildren().addAll(titleLabel, emailField, passwordField, buttonBar, statusLabel);
+ popup.getContent().add(popupContent);
+
+ myAccountButton.setOnAction(event -> {
+ if (!popup.isShowing()) {
+ Node source = (Node) event.getSource();
+ Window theStage = source.getScene().getWindow();
+ double x = 6 + theStage.getX() + source.localToScene(source.getBoundsInLocal()).getMinX();
+ double y = theStage.getY() + source.localToScene(source.getBoundsInLocal()).getMinY();
+ popup.show(theStage, x, y + source.getBoundsInLocal().getHeight() + 40);
+ } else {
+ popup.hide();
+ }
+ });
+ }
+ // Этот метод теперь принимает List и обновляет moviesTilePane
+ public void updateTilePaneContent(List movies) throws FileNotFoundException, URISyntaxException {
+ for (Movie movie : movies) {
+ Node movieNode = createMovieNode(movie);
+ moviesTilePane.getChildren().add(movieNode);
+ }
+ }
- /* ChoiceBox ФИЛЬТРЫ*/
- @FXML
- private void onGenreSelected(ActionEvent event) {
- // Логика обработки выбора жанра
+ private Node createMovieNode(Movie movie) throws FileNotFoundException {
+ VBox vbox = new VBox();
+ vbox.setAlignment(Pos.CENTER);
+ vbox.setStyle("-fx-background-color: #151A1EFF;");
+
+ File file = new File(movie.getImagePath());
+ Image image = new Image(file.toURI().toString());
+ ImageView imageView = new ImageView(image);
+ imageView.setFitHeight(225);
+ imageView.setFitWidth(150);
+
+ Label titleLabel = new Label(movie.getTitle());
+ titleLabel.setMaxWidth(150);
+ titleLabel.setWrapText(true);
+ titleLabel.setStyle("-fx-font-weight: bold;");
+ titleLabel.setAlignment(Pos.CENTER);
+
+ HBox hBox = new HBox();
+ hBox.setAlignment(Pos.CENTER);
+
+ Label yearLabel = new Label(movie.getYear() + ", ");
+ yearLabel.setAlignment(Pos.CENTER);
+
+ Label ratingLabel = new Label("✫" + movie.getRating());
+ ratingLabel.setStyle("-fx-text-fill: yellow;"); // Желтый цвет только для рейтинга
+ ratingLabel.setAlignment(Pos.CENTER);
+
+ CheckBox favoriteCheckBox = new CheckBox("В избранное");
+ favoriteCheckBox.setSelected(currentUser != null && isFavorite(movie.getTitle()));
+ favoriteCheckBox.setOnAction(event -> {
+ if (currentUser == null) {
+ System.out.println("Вы не авторизированы");
+ favoriteCheckBox.setSelected(false);
+ return;
+ }
+ toggleFavorite(movie);
+ });
+
+ hBox.getChildren().addAll(yearLabel, ratingLabel);
+ vbox.getChildren().addAll(imageView, titleLabel, hBox, favoriteCheckBox);
+
+ return vbox;
}
- @FXML
- private void onYearSelected(ActionEvent event) {
- // Логика обработки выбора года
+ public void toggleFavorite(Movie movie) {
+ if (isFavorite(movie.getTitle())) {
+ removeFavorite(movie.getTitle());
+ } else {
+ addFavorite(movie);
+ }
}
- @FXML
- private void onCountrySelected(ActionEvent event) {
- // Логика обработки выбора страны
+
+ public void addFavorite(Movie movie) {
+ if (currentUser == null) {
+ System.out.println("Вы не авторизированы");
+ return;
+ }
+ String sql = "INSERT INTO favorites (user_id, title, year, rating, image_path) VALUES (?, ?, ?, ?, ?)";
+ try (Connection conn = db.connect();
+ PreparedStatement pstmt = conn.prepareStatement(sql)) {
+ pstmt.setInt(1, currentUser.getId());
+ pstmt.setString(2, movie.getTitle());
+ pstmt.setString(3, movie.getYear());
+ pstmt.setString(4, movie.getRating());
+ pstmt.setString(5, movie.getImagePath());
+ pstmt.executeUpdate();
+ System.out.println("Фильм добавлен в избранное");
+ } catch (SQLException e) {
+ System.out.println(e.getMessage());
+ }
}
- @FXML
- private void onRatingSelected(ActionEvent event) {
- // Логика обработки выбора рейтинга
+
+ public void removeFavorite(String movieTitle) {
+ if (currentUser == null) {
+ System.out.println("Вы не авторизированы");
+ return;
+ }
+ String sql = "DELETE FROM favorites WHERE user_id = ? AND title = ?";
+ try (Connection conn = db.connect();
+ PreparedStatement pstmt = conn.prepareStatement(sql)) {
+ pstmt.setInt(1, currentUser.getId());
+ pstmt.setString(2, movieTitle);
+ pstmt.executeUpdate();
+ System.out.println("Фильм удален из избранного");
+ } catch (SQLException e) {
+ System.out.println(e.getMessage());
+ }
}
- @FXML
- private void updateTilePaneContent(Node content) {
- if (content instanceof ScrollPane) {
- ScrollPane scrollPane = (ScrollPane) content;
- if (scrollPane.getContent() instanceof TilePane) {
- TilePane newTilePane = (TilePane) scrollPane.getContent();
- moviesTilePane.getChildren().clear(); // Очистка текущего содержимого TilePane
- moviesTilePane.getChildren().addAll(newTilePane.getChildren()); // Добавление нового содержимого
+ public void loadFavorites() {
+ if (currentUser == null) {
+ System.out.println("Вы не авторизированы");
+ return;
+ }
+ String sql = "SELECT title, year, rating, image_path FROM favorites WHERE user_id = ?";
+ try (Connection conn = db.connect();
+ PreparedStatement pstmt = conn.prepareStatement(sql)) {
+ pstmt.setInt(1, currentUser.getId());
+ ResultSet rs = pstmt.executeQuery();
+ List favoriteMovies = new ArrayList<>();
+ while (rs.next()) {
+ String title = rs.getString("title");
+ String year = rs.getString("year");
+ String rating = rs.getString("rating");
+ String imagePath = rs.getString("image_path");
+ favoriteMovies.add(new Movie(title, year, rating, imagePath));
}
+ Platform.runLater(() -> {
+ try {
+ clearContent(); // Очистить предыдущий контент
+ updateTilePaneContent(favoriteMovies); // Отобразить избранные фильмы
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ });
+ } catch (SQLException e) {
+ System.out.println(e.getMessage());
}
}
- private Node createContentTilePane(List> contents) {
- TilePane tilePane = new TilePane();
- for (Object content : contents) {
- if (content instanceof Movie) {
- Movie movie = (Movie) content;
- VBox vbox = createVBoxForContent(movie.getTitle(), movie.getImagePath());
- tilePane.getChildren().add(vbox);
- } else if (content instanceof Series) {
- Series series = (Series) content;
- VBox vbox = createVBoxForContent(series.getTitle(), series.getImagePath());
- tilePane.getChildren().add(vbox);
- } else if (content instanceof SportEvent) {
- SportEvent sportEvent = (SportEvent) content;
- VBox vbox = createVBoxForContent(sportEvent.getTitle(), sportEvent.getImagePath());
- tilePane.getChildren().add(vbox);
+
+ private User currentUser;
+ public void removeFavorite(int movieId) {
+ String sql = "DELETE FROM favorites WHERE user_id = ? AND movie_id = ?";
+ try (Connection conn = db.connect();
+ PreparedStatement pstmt = conn.prepareStatement(sql)) {
+ pstmt.setInt(1, currentUser.getId());
+ pstmt.setInt(2, movieId);
+ pstmt.executeUpdate();
+ } catch (SQLException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+
+ public boolean isFavorite(String movieTitle) {
+ if (currentUser == null) {
+ System.out.println("Вы не авторизированы");
+ return false;
+ }
+ String sql = "SELECT 1 FROM favorites WHERE user_id = ? AND title = ?";
+ try (Connection conn = db.connect();
+ PreparedStatement pstmt = conn.prepareStatement(sql)) {
+ pstmt.setInt(1, currentUser.getId());
+ pstmt.setString(2, movieTitle);
+ ResultSet rs = pstmt.executeQuery();
+ return rs.next(); // Возвращает true, если запись найдена
+ } catch (SQLException e) {
+ System.out.println(e.getMessage());
+ return false;
+ }
+ }
+
+
+
+
+ // Метод для установки текущего пользователя после успешной авторизации
+ public void setCurrentUser(int id, String username) {
+ this.currentUser = new User(id, username);
+ }
+
+
+ public void clearContent() {
+ if (!moviesTilePane.getChildren().isEmpty()) {
+ moviesTilePane.getChildren().clear();
+ }
+ }
+
+ // Отдельные методы для парсинга фильмов, сериалов и мультфильмов
+ public void loadMovies() {
+ currentCategory = "movies";
+ if (isLoading || currentPage.get() > totalPages) return; // Проверка, идет ли загрузка и есть ли еще страницы
+ isLoading = true;
+ int pageToLoad = currentPage.getAndIncrement(); // Получаем текущую страницу для загрузки и увеличиваем счетчик
+
+ new Thread(() -> {
+ List movies = parseMedia("https://lordfilm.ai/filmy/", pageToLoad);
+ System.out.println("Страница фильма : " + pageToLoad);
+ Platform.runLater(() -> {
+ try {
+ updateTilePaneContent(movies);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ isLoading = false; // Сбрасываем состояние загрузки
+ closeLoadingScreen();
+ }
+ });
+ }).start();
+ }
+
+ public void loadSeries() {
+ currentCategory = "series";
+ if (isLoading || currentPage.get() > totalPages) return; // Проверка, идет ли загрузка и есть ли еще страницы
+ isLoading = true;
+ int pageToLoad = currentPage.getAndIncrement();
+
+ new Thread(() -> {
+ List series = parseMedia("https://lordfilm.ai/serialy/", pageToLoad);
+ System.out.println("Страница сериала : " + pageToLoad);
+ Platform.runLater(() -> {
+ try {
+ updateTilePaneContent(series);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ isLoading = false;
+ closeLoadingScreen();
+ }
+ });
+ }).start();
+ }
+
+ public void loadCartoons() {
+ currentCategory = "cartoons";
+ if (isLoading || currentPage.get() > 3) return; // Проверка, идет ли загрузка и есть ли еще страницы
+ isLoading = true;
+ int pageToLoad = currentPage.getAndIncrement();
+
+ new Thread(() -> {
+ List cartoons = parseMedia("https://lordfilm.ai/multserialy/", pageToLoad);
+ System.out.println("Страница мультика : " + pageToLoad);
+ Platform.runLater(() -> {
+ try {
+ updateTilePaneContent(cartoons);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ isLoading = false;
+ closeLoadingScreen();
+ }
+ });
+ }).start();
+ }
+
+ private void showLoadingScreen(){
+ try{
+ FXMLLoader loader = new FXMLLoader(getClass().getResource("/com/mdkefir/filmlibrary/fxml/main_download.fxml"));
+ Parent root = loader.load();
+
+ //Создание новой формы
+ loadingStage = new Stage();
+ loadingStage.initStyle(StageStyle.UNDECORATED);
+ loadingStage.setScene(new Scene(root));
+ loadingStage.initModality(Modality.APPLICATION_MODAL); // делаем окно модальным
+ loadingStage.setTitle("Загрузка");
+ loadingStage.show();
+ }catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void closeLoadingScreen(){
+ if (loadingStage != null){
+ loadingStage.close();
+ }
+ }
+
+
+ // Пример метода, который вызывается при нажатии кнопки "Регистрация"
+
+ private void handleRegistration() {
+ String username = emailField.getText(); // Используйте email в качестве логина
+ String password = passwordField.getText();
+ if (authController.registerUser(username, password)) {
+ statusLabel.setText("Регистрация успешна");
+ } else {
+ statusLabel.setText("Ошибка регистрации");
+ }
+ }
+
+
+ @FXML
+ private void handleLogin() {
+ String username = emailField.getText();
+ String password = passwordField.getText();
+ if (authController.loginUser(username, password)) {
+ int userId = authController.getUserId(username);
+ currentUser = new User(userId, username); // Создание текущего пользователя
+ statusLabel.setText("Авторизация успешна");
+ } else {
+ statusLabel.setText("Ошибка авторизации");
+ }
+ }
+
+
+
+ @FXML
+ private void handleAddFriend() {
+ String friendName = nameFriend.getText();
+ String secretCode = secretCodeFriend.getText();
+ if (currentUser != null && friendName != null && !friendName.isEmpty() && secretCode != null && !secretCode.isEmpty()) {
+ if (authController.addFriend(currentUser.getId(), friendName, secretCode)) {
+ friendStatusLabel.setText("Друг добавлен");
+ updateFriendList();
+ } else {
+ friendStatusLabel.setText("Ошибка добавления друга");
}
+ } else {
+ friendStatusLabel.setText("Необходимо заполнить все поля");
+ }
+ }
+
+ @FXML
+ private void handleDeleteFriend() {
+ String selectedFriend = friendChoose.getValue();
+ if (currentUser != null && selectedFriend != null) {
+ if (authController.deleteFriend(currentUser.getId(), selectedFriend)) {
+ friendStatusLabel.setText("Друг удален");
+ updateFriendList();
+ } else {
+ friendStatusLabel.setText("Ошибка удаления друга");
+ }
+ } else {
+ friendStatusLabel.setText("Выберите друга для удаления");
+ }
+ }
+
+ private void updateFriendList() {
+ if (currentUser != null) {
+ List friends = authController.getFriends(currentUser.getId());
+ friendChoose.getItems().setAll(friends);
}
+ }
- // Create ScrollPane and bind TilePane's preferred width/height to ScrollPane's viewport dimensions
- ScrollPane scrollPane = new ScrollPane(tilePane);
- scrollPane.setFitToHeight(true);
- scrollPane.setFitToWidth(true);
- scrollPane.setStyle("-fx-background-color: #1e252b;"); // Set the background color if not using CSS
+ @FXML
+ private void handleApplySecretWord() {
+ String secretWord = fieldSecretWord.getText();
+
+ if (secretWord.isEmpty()) {
+ friendStatusLabel.setText("Введите секретное слово");
+ return;
+ }
- return scrollPane;
+ try (Connection conn = Database.connect()) {
+ // Обновить секретное слово текущего пользователя
+ String updateSecretWordSQL = "UPDATE users SET secret_code = ? WHERE id = ?";
+ PreparedStatement pstmt = conn.prepareStatement(updateSecretWordSQL);
+ pstmt.setString(1, secretWord);
+ pstmt.setInt(2, currentUser.getId());
+ pstmt.executeUpdate();
+
+ friendStatusLabel.setText("Секретное слово обновлено");
+ } catch (SQLException e) {
+ e.printStackTrace();
+ friendStatusLabel.setText("Ошибка обновления секретного слова");
+ }
}
+ private void loadFriends() {
+ friendChoose.getItems().clear();
+
+ try (Connection conn = Database.connect()) {
+ // Получить список друзей текущего пользователя
+ String loadFriendsSQL = "SELECT u.username FROM friends f JOIN users u ON f.friend_id = u.id WHERE f.user_id = ?";
+ PreparedStatement pstmt = conn.prepareStatement(loadFriendsSQL);
+ pstmt.setInt(1, currentUserId);
+ ResultSet rs = pstmt.executeQuery();
+
+ while (rs.next()) {
+ friendChoose.getItems().add(rs.getString("username"));
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ friendStatusLabel.setText("Ошибка загрузки друзей");
+ }
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/mdkefir/filmlibrary/models/SportEvent.java b/src/main/java/com/mdkefir/filmlibrary/models/Cartoon.java
similarity index 78%
rename from src/main/java/com/mdkefir/filmlibrary/models/SportEvent.java
rename to src/main/java/com/mdkefir/filmlibrary/models/Cartoon.java
index f53f657..9665faa 100644
--- a/src/main/java/com/mdkefir/filmlibrary/models/SportEvent.java
+++ b/src/main/java/com/mdkefir/filmlibrary/models/Cartoon.java
@@ -1,10 +1,10 @@
package com.mdkefir.filmlibrary.models;
-public class SportEvent {
+public class Cartoon {
public String title;
public String imagePath;
- public SportEvent(String title, String imagePath) {
+ public Cartoon(String title, String imagePath) {
this.title = title;
this.imagePath = imagePath;
}
diff --git a/src/main/java/com/mdkefir/filmlibrary/models/Movie.java b/src/main/java/com/mdkefir/filmlibrary/models/Movie.java
index 9c7e9a7..3833645 100644
--- a/src/main/java/com/mdkefir/filmlibrary/models/Movie.java
+++ b/src/main/java/com/mdkefir/filmlibrary/models/Movie.java
@@ -2,10 +2,14 @@
public class Movie {
private String title;
+ private String year;
+ private String rating;
private String imagePath;
- public Movie(String title, String imagePath) {
+ public Movie(String title, String year, String rating, String imagePath) {
this.title = title;
+ this.year = year;
+ this.rating = rating;
this.imagePath = imagePath;
}
@@ -13,6 +17,14 @@ public String getTitle() {
return title;
}
+ public String getYear() {
+ return year;
+ }
+
+ public String getRating() {
+ return rating;
+ }
+
public String getImagePath() {
return imagePath;
}
diff --git a/src/main/java/com/mdkefir/filmlibrary/models/User.java b/src/main/java/com/mdkefir/filmlibrary/models/User.java
new file mode 100644
index 0000000..25b8f5d
--- /dev/null
+++ b/src/main/java/com/mdkefir/filmlibrary/models/User.java
@@ -0,0 +1,33 @@
+package com.mdkefir.filmlibrary.models;
+
+public class User {
+ private int id; // идентификатор пользователя
+ private String username; // имя пользователя
+ private String password; // пароль пользователя
+
+ // Конструктор
+ public User(int id, String username, String password) {
+ this.id = id;
+ this.username = username;
+ this.password = password;
+ }
+
+ public User(int id, String username) {
+ this.id = id;
+ this.username = username;
+ }
+
+ // Геттер для идентификатора пользователя
+ public int getId() {
+ return id;
+ }
+
+ // Геттеры для других полей
+ public String getUsername() {
+ return username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+}
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
index 0146e9c..361a2bd 100644
--- a/src/main/java/module-info.java
+++ b/src/main/java/module-info.java
@@ -6,6 +6,9 @@
requires com.dlsc.formsfx;
requires org.kordamp.ikonli.javafx;
requires org.kordamp.bootstrapfx.core;
+ requires org.jsoup;
+ requires java.desktop;
+ requires java.sql;
opens com.mdkefir.filmlibrary.controllers to javafx.fxml;
exports com.mdkefir.filmlibrary;
diff --git a/src/main/resources/com/mdkefir/filmlibrary/fxml/main.fxml b/src/main/resources/com/mdkefir/filmlibrary/fxml/main.fxml
index b12939b..82fe1fb 100644
--- a/src/main/resources/com/mdkefir/filmlibrary/fxml/main.fxml
+++ b/src/main/resources/com/mdkefir/filmlibrary/fxml/main.fxml
@@ -1,48 +1,11 @@
-
-
-
-
-
+
+
-
-
-
-
@@ -51,68 +14,31 @@
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
+
+
+
+
@@ -122,7 +48,7 @@
-
+
@@ -134,97 +60,101 @@
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
\ No newline at end of file