From c57a2946f5353a2b1ce21d31d200f0520cea007d Mon Sep 17 00:00:00 2001 From: shrunzy Date: Wed, 11 Mar 2026 00:40:37 -0700 Subject: [PATCH] =?UTF-8?q?1=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=81=D0=BE=D0=BB=D1=8C=D0=BD=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D0=BF=D1=80=D0=B8=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B7=D0=B0=D0=BC=D0=B5=D1=82=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/caches/deviceStreaming.xml | 1450 +++++++++++++++++++++++++++++ .idea/deviceManager.xml | 13 + .idea/markdown.xml | 8 + .idea/misc.xml | 3 +- Kotlin-Module-Project.iml | 1 + src/main/kotlin/Archive.kt | 4 + src/main/kotlin/ArchiveMenu.kt | 50 + src/main/kotlin/Main.kt | 25 +- src/main/kotlin/MenuScreen.kt | 46 + src/main/kotlin/Note.kt | 5 + src/main/kotlin/NoteListScreen.kt | 47 + src/main/kotlin/NoteViewScreen.kt | 11 + 12 files changed, 1658 insertions(+), 5 deletions(-) create mode 100644 .idea/caches/deviceStreaming.xml create mode 100644 .idea/deviceManager.xml create mode 100644 .idea/markdown.xml create mode 100644 src/main/kotlin/Archive.kt create mode 100644 src/main/kotlin/ArchiveMenu.kt create mode 100644 src/main/kotlin/MenuScreen.kt create mode 100644 src/main/kotlin/Note.kt create mode 100644 src/main/kotlin/NoteListScreen.kt create mode 100644 src/main/kotlin/NoteViewScreen.kt diff --git a/.idea/caches/deviceStreaming.xml b/.idea/caches/deviceStreaming.xml new file mode 100644 index 000000000..d966f1b52 --- /dev/null +++ b/.idea/caches/deviceStreaming.xml @@ -0,0 +1,1450 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deviceManager.xml b/.idea/deviceManager.xml new file mode 100644 index 000000000..91f95584d --- /dev/null +++ b/.idea/deviceManager.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/.idea/markdown.xml b/.idea/markdown.xml new file mode 100644 index 000000000..c61ea3346 --- /dev/null +++ b/.idea/markdown.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 9c8e74009..cf9058214 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,5 @@ - - + \ No newline at end of file diff --git a/Kotlin-Module-Project.iml b/Kotlin-Module-Project.iml index 4eba30bca..2b2598950 100644 --- a/Kotlin-Module-Project.iml +++ b/Kotlin-Module-Project.iml @@ -7,6 +7,7 @@ + diff --git a/src/main/kotlin/Archive.kt b/src/main/kotlin/Archive.kt new file mode 100644 index 000000000..26b6a0b9f --- /dev/null +++ b/src/main/kotlin/Archive.kt @@ -0,0 +1,4 @@ +data class Archive( + val name: String, + val notes: MutableList = mutableListOf() +) diff --git a/src/main/kotlin/ArchiveMenu.kt b/src/main/kotlin/ArchiveMenu.kt new file mode 100644 index 000000000..ac572f8ad --- /dev/null +++ b/src/main/kotlin/ArchiveMenu.kt @@ -0,0 +1,50 @@ +class ArchiveMenu( + private val archives: MutableList + +) { + fun start() { + + while (true) { + //var needRefresh = false + val menuItems = mutableListOf() + + // 0 — создание архива + menuItems.add(MenuScreen.MenuItem("Создать архив") { + createArchive() + // needRefresh = true + }) + + // Существующие архивы + archives.forEachIndexed { index, archive -> + menuItems.add(MenuScreen.MenuItem(archive.name) { + NoteListScreen(archive).start() + }) + } + + // Последним всегда выход + menuItems.add(MenuScreen.exitItem { + println("\nДо свидания!") + kotlin.system.exitProcess(0) + }) + + val screen = MenuScreen( + title = "Список архивов:", + items = menuItems + ) + + screen.show() + + } + } + + private fun createArchive() { + println("Начало создания архива") + println("\nВведите название архива:") + val name = readNotEmptyString("Название архива не может быть пустым") + println("Имя получено: '$name'") + archives.add(Archive(name)) + println("Архив $name успешно создан.") + println("Архив добавлен, теперь размер списка = ${archives.size}") + + } +} \ No newline at end of file diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index aade54c57..0d7897fb0 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,3 +1,22 @@ -fun main(args: Array) { - println("Hello World!") -} \ No newline at end of file +//fun main(args: Array) { +fun main() { + val archives = mutableListOf() + + ArchiveMenu(archives).start() + //println("Hello World!") + + +} + +fun readNotEmptyString(errorMessage: String): String { + val scanner = java.util.Scanner(System.`in`) + while (true) { + val input = scanner.nextLine().trim() + if (input.isNotBlank()) { + return input + } + println() + println(errorMessage) + print("Попробуйте снова: ") + } +} diff --git a/src/main/kotlin/MenuScreen.kt b/src/main/kotlin/MenuScreen.kt new file mode 100644 index 000000000..4ce3285fa --- /dev/null +++ b/src/main/kotlin/MenuScreen.kt @@ -0,0 +1,46 @@ +class MenuScreen( + private val title: String, // Заголовок - "Список архивов:" + private val items: List, // список к выбору + //private val onExit: () -> Unit = {} // действие при выходе +) { + data class MenuItem( + val text: String, // элементы меню + val action: () -> Unit // действие при выборе элемента меню + ) + + private val scanner = java.util.Scanner(System.`in`) + fun show() { + while (true) { + println("$title") + items.forEachIndexed { index, item -> + println("$index. ${item.text}") + } + print("Выберите пункт меню: ") + + val input = scanner.nextLine().trim() + + val selectedIndex = input.toIntOrNull() + + when { + selectedIndex == null -> { + println("Ошибка: нужно ввести число.") + } + + selectedIndex < 0 || selectedIndex >= items.size -> { + println("Ошибка: такого пункта нет. Выберите число от 0 до ${items.size - 1}") + } + + else -> { + val selectedItem = items[selectedIndex] + selectedItem.action() // выполняем действие пункта меню + return + } + } + } + + } + + companion object { + fun exitItem(onExit: () -> Unit) = MenuItem("Выход") { onExit() } + } +} \ No newline at end of file diff --git a/src/main/kotlin/Note.kt b/src/main/kotlin/Note.kt new file mode 100644 index 000000000..03e67add3 --- /dev/null +++ b/src/main/kotlin/Note.kt @@ -0,0 +1,5 @@ +data class Note( + val title: String, + val text: String + +) diff --git a/src/main/kotlin/NoteListScreen.kt b/src/main/kotlin/NoteListScreen.kt new file mode 100644 index 000000000..2a2f9c5d9 --- /dev/null +++ b/src/main/kotlin/NoteListScreen.kt @@ -0,0 +1,47 @@ +class NoteListScreen( + private val archive: Archive +) { + fun start() { + while (true) { + var exitRequested = false + val menuItems = mutableListOf() + + menuItems.add(MenuScreen.MenuItem("Создать заметку") { + createNote() + }) + + archive.notes.forEachIndexed { index, note -> + menuItems.add(MenuScreen.MenuItem(note.title) { + NoteViewScreen(note).show() + }) + + } + + + menuItems.add(MenuScreen.MenuItem("Назад") { + exitRequested = true + }) + + val screen = MenuScreen( + title = "Архив: ${archive.name}\nЗаметки:", + items = menuItems + ) + + screen.show() + if (exitRequested) { + return // выход из функции start() и возврат в меню архивов + } + } + } + + private fun createNote() { + println("\nВведите заголовок заметки:") + val title = readNotEmptyString("Заголовок не может быть пустым") + + println("Введите текст заметки:") + val text = readNotEmptyString("Текст заметки не может быть пустым") + + archive.notes.add(Note(title, text)) + println("Заметка «$title» сохранена.") + } +} \ No newline at end of file diff --git a/src/main/kotlin/NoteViewScreen.kt b/src/main/kotlin/NoteViewScreen.kt new file mode 100644 index 000000000..acdb1ffd3 --- /dev/null +++ b/src/main/kotlin/NoteViewScreen.kt @@ -0,0 +1,11 @@ +class NoteViewScreen( + private val note: Note +) { + fun show() { + println("Заметка: ${note.title}") + println(note.text) + println("Нажмите Enter для возврата...") + readln() + // После нажатия Enter возврат в предыдущее меню + } +} \ No newline at end of file