From 50f3d5bf555d3ea06265f2bce79d06e5cb695940 Mon Sep 17 00:00:00 2001 From: Amon Date: Wed, 27 Dec 2023 20:15:34 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9A=D1=83=D1=80=D1=81=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F:=20=D0=92=D1=80=D0=BE=D0=B4=D0=B5=20=D0=B3=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/example/dtf/AppModule.kt | 21 +- .../main/java/com/example/dtf/MainActivity.kt | 27 +- .../dtf/{ => data}/api/ServerService.kt | 43 +-- .../example/dtf/{ => data}/dao/CategoryDao.kt | 11 +- .../example/dtf/{ => data}/dao/CommentDao.kt | 11 +- .../com/example/dtf/{ => data}/dao/LikeDao.kt | 10 +- .../com/example/dtf/{ => data}/dao/PostDao.kt | 11 +- .../com/example/dtf/{ => data}/dao/UserDao.kt | 11 +- .../example/dtf/{ => data}/db/AppDatabase.kt | 28 +- .../example/dtf/{ => data}/db/Converter.kt | 2 +- .../example/dtf/{ => data}/dto/Credentials.kt | 2 +- .../example/dtf/{ => data}/dto/EditPostDto.kt | 2 +- .../com/example/dtf/{ => data}/dto/MeUser.kt | 2 +- .../dtf/{ => data}/dto/NewCommentDto.kt | 2 +- .../example/dtf/{ => data}/dto/NewPostDto.kt | 2 +- .../com/example/dtf/{ => data}/dto/Token.kt | 2 +- .../dto/remote/CategoriesResponse.kt | 4 +- .../{ => data}/dto/remote/CommentsResponse.kt | 4 +- .../{ => data}/dto/remote/PostsResponse.kt | 4 +- .../example/dtf/{ => data}/models/Category.kt | 6 +- .../example/dtf/{ => data}/models/Comment.kt | 6 +- .../com/example/dtf/{ => data}/models/Like.kt | 5 +- .../com/example/dtf/{ => data}/models/Post.kt | 6 +- .../com/example/dtf/{ => data}/models/User.kt | 6 +- .../repositories/ICategoryRepository.kt | 4 +- .../repositories/ICommentRepository.kt | 4 +- .../repositories/ILikeRepository.kt | 4 +- .../repositories/IPostRepository.kt | 7 +- .../repositories/IUserRepository.kt | 4 +- .../offline/OfflineCategoryRepository.kt | 8 +- .../offline/OfflineCommentRepository.kt | 11 +- .../offline/OfflineLikeRepository.kt | 8 +- .../offline/OfflinePostRepository.kt | 17 +- .../offline/OfflineUserRepository.kt | 7 +- .../online/RestCategoryRepository.kt | 10 +- .../online/RestCommentRepository.kt | 14 +- .../repositories/online/RestLikeRepository.kt | 10 +- .../repositories/online/RestPostRepository.kt | 32 +- .../repositories/online/RestUserRepository.kt | 10 +- .../online/mediator/CategoryMediator.kt | 8 +- .../online/mediator/CommentMediator.kt | 8 +- .../online/mediator/PostMediator.kt | 8 +- .../dtf/{ => ui}/screens/EditPostScreen.kt | 32 +- .../dtf/{ => ui}/screens/LoginScreen.kt | 33 ++- .../dtf/{ => ui}/screens/NewPostScreen.kt | 38 ++- .../dtf/{ => ui}/screens/PostScreen.kt | 45 ++- .../dtf/{ => ui}/screens/PostsScreen.kt | 46 ++- .../dtf/{ => ui}/screens/ProfileScreen.kt | 31 +- .../dtf/{ => ui}/screens/RegisterScreen.kt | 27 +- .../example/dtf/ui/screens/TopPostsScreen.kt | 279 ++++++++++++++++++ .../example/dtf/{ => ui}/utils/ScreenPaths.kt | 3 +- .../{ => ui}/viewmodels/EditPostViewModel.kt | 6 +- .../dtf/{ => ui}/viewmodels/LoginViewModel.kt | 7 +- .../{ => ui}/viewmodels/NewPostViewModel.kt | 8 +- .../dtf/{ => ui}/viewmodels/PostViewModel.kt | 16 +- .../dtf/{ => ui}/viewmodels/PostsViewModel.kt | 12 +- .../{ => ui}/viewmodels/ProfileViewModel.kt | 8 +- .../{ => ui}/viewmodels/RegisterViewModel.kt | 7 +- .../dtf/ui/viewmodels/TopPostsViewModel.kt | 63 ++++ .../dtf/{ => ui}/widgets/BottomNavBar.kt | 23 +- .../dtf/{ => ui}/widgets/MyTextField.kt | 2 +- 61 files changed, 795 insertions(+), 293 deletions(-) rename app/src/main/java/com/example/dtf/{ => data}/api/ServerService.kt (81%) rename app/src/main/java/com/example/dtf/{ => data}/dao/CategoryDao.kt (76%) rename app/src/main/java/com/example/dtf/{ => data}/dao/CommentDao.kt (78%) rename app/src/main/java/com/example/dtf/{ => data}/dao/LikeDao.kt (67%) rename app/src/main/java/com/example/dtf/{ => data}/dao/PostDao.kt (74%) rename app/src/main/java/com/example/dtf/{ => data}/dao/UserDao.kt (57%) rename app/src/main/java/com/example/dtf/{ => data}/db/AppDatabase.kt (50%) rename app/src/main/java/com/example/dtf/{ => data}/db/Converter.kt (89%) rename app/src/main/java/com/example/dtf/{ => data}/dto/Credentials.kt (81%) rename app/src/main/java/com/example/dtf/{ => data}/dto/EditPostDto.kt (79%) rename app/src/main/java/com/example/dtf/{ => data}/dto/MeUser.kt (82%) rename app/src/main/java/com/example/dtf/{ => data}/dto/NewCommentDto.kt (80%) rename app/src/main/java/com/example/dtf/{ => data}/dto/NewPostDto.kt (82%) rename app/src/main/java/com/example/dtf/{ => data}/dto/Token.kt (75%) rename app/src/main/java/com/example/dtf/{ => data}/dto/remote/CategoriesResponse.kt (63%) rename app/src/main/java/com/example/dtf/{ => data}/dto/remote/CommentsResponse.kt (63%) rename app/src/main/java/com/example/dtf/{ => data}/dto/remote/PostsResponse.kt (62%) rename app/src/main/java/com/example/dtf/{ => data}/models/Category.kt (79%) rename app/src/main/java/com/example/dtf/{ => data}/models/Comment.kt (84%) rename app/src/main/java/com/example/dtf/{ => data}/models/Like.kt (69%) rename app/src/main/java/com/example/dtf/{ => data}/models/Post.kt (97%) rename app/src/main/java/com/example/dtf/{ => data}/models/User.kt (79%) rename app/src/main/java/com/example/dtf/{ => data}/repositories/ICategoryRepository.kt (72%) rename app/src/main/java/com/example/dtf/{ => data}/repositories/ICommentRepository.kt (73%) rename app/src/main/java/com/example/dtf/{ => data}/repositories/ILikeRepository.kt (74%) rename app/src/main/java/com/example/dtf/{ => data}/repositories/IPostRepository.kt (57%) rename app/src/main/java/com/example/dtf/{ => data}/repositories/IUserRepository.kt (55%) rename app/src/main/java/com/example/dtf/{ => data}/repositories/offline/OfflineCategoryRepository.kt (76%) rename app/src/main/java/com/example/dtf/{ => data}/repositories/offline/OfflineCommentRepository.kt (65%) rename app/src/main/java/com/example/dtf/{ => data}/repositories/offline/OfflineLikeRepository.kt (70%) rename app/src/main/java/com/example/dtf/{ => data}/repositories/offline/OfflinePostRepository.kt (52%) rename app/src/main/java/com/example/dtf/{ => data}/repositories/offline/OfflineUserRepository.kt (52%) rename app/src/main/java/com/example/dtf/{ => data}/repositories/online/RestCategoryRepository.kt (78%) rename app/src/main/java/com/example/dtf/{ => data}/repositories/online/RestCommentRepository.kt (76%) rename app/src/main/java/com/example/dtf/{ => data}/repositories/online/RestLikeRepository.kt (75%) rename app/src/main/java/com/example/dtf/{ => data}/repositories/online/RestPostRepository.kt (58%) rename app/src/main/java/com/example/dtf/{ => data}/repositories/online/RestUserRepository.kt (60%) rename app/src/main/java/com/example/dtf/{ => data}/repositories/online/mediator/CategoryMediator.kt (91%) rename app/src/main/java/com/example/dtf/{ => data}/repositories/online/mediator/CommentMediator.kt (92%) rename app/src/main/java/com/example/dtf/{ => data}/repositories/online/mediator/PostMediator.kt (91%) rename app/src/main/java/com/example/dtf/{ => ui}/screens/EditPostScreen.kt (79%) rename app/src/main/java/com/example/dtf/{ => ui}/screens/LoginScreen.kt (80%) rename app/src/main/java/com/example/dtf/{ => ui}/screens/NewPostScreen.kt (82%) rename app/src/main/java/com/example/dtf/{ => ui}/screens/PostScreen.kt (82%) rename app/src/main/java/com/example/dtf/{ => ui}/screens/PostsScreen.kt (82%) rename app/src/main/java/com/example/dtf/{ => ui}/screens/ProfileScreen.kt (74%) rename app/src/main/java/com/example/dtf/{ => ui}/screens/RegisterScreen.kt (88%) create mode 100644 app/src/main/java/com/example/dtf/ui/screens/TopPostsScreen.kt rename app/src/main/java/com/example/dtf/{ => ui}/utils/ScreenPaths.kt (83%) rename app/src/main/java/com/example/dtf/{ => ui}/viewmodels/EditPostViewModel.kt (91%) rename app/src/main/java/com/example/dtf/{ => ui}/viewmodels/LoginViewModel.kt (89%) rename app/src/main/java/com/example/dtf/{ => ui}/viewmodels/NewPostViewModel.kt (89%) rename app/src/main/java/com/example/dtf/{ => ui}/viewmodels/PostViewModel.kt (86%) rename app/src/main/java/com/example/dtf/{ => ui}/viewmodels/PostsViewModel.kt (82%) rename app/src/main/java/com/example/dtf/{ => ui}/viewmodels/ProfileViewModel.kt (78%) rename app/src/main/java/com/example/dtf/{ => ui}/viewmodels/RegisterViewModel.kt (87%) create mode 100644 app/src/main/java/com/example/dtf/ui/viewmodels/TopPostsViewModel.kt rename app/src/main/java/com/example/dtf/{ => ui}/widgets/BottomNavBar.kt (78%) rename app/src/main/java/com/example/dtf/{ => ui}/widgets/MyTextField.kt (98%) diff --git a/app/src/main/java/com/example/dtf/AppModule.kt b/app/src/main/java/com/example/dtf/AppModule.kt index 3013cbf..a750229 100644 --- a/app/src/main/java/com/example/dtf/AppModule.kt +++ b/app/src/main/java/com/example/dtf/AppModule.kt @@ -2,11 +2,22 @@ package com.example.dtf import android.app.Application import androidx.room.* -import com.example.dtf.api.ServerService -import com.example.dtf.db.AppDatabase -import com.example.dtf.repositories.* -import com.example.dtf.repositories.offline.* -import com.example.dtf.repositories.online.* +import com.example.dtf.data.api.ServerService +import com.example.dtf.data.db.AppDatabase +import com.example.dtf.data.repositories.ICategoryRepository +import com.example.dtf.data.repositories.ICommentRepository +import com.example.dtf.data.repositories.ILikeRepository +import com.example.dtf.data.repositories.IPostRepository +import com.example.dtf.data.repositories.IUserRepository +import com.example.dtf.data.repositories.offline.OfflineCategoryRepository +import com.example.dtf.data.repositories.offline.OfflineCommentRepository +import com.example.dtf.data.repositories.offline.OfflineLikeRepository +import com.example.dtf.data.repositories.offline.OfflinePostRepository +import com.example.dtf.data.repositories.offline.OfflineUserRepository +import com.example.dtf.data.repositories.online.RestCommentRepository +import com.example.dtf.data.repositories.online.RestLikeRepository +import com.example.dtf.data.repositories.online.RestPostRepository +import com.example.dtf.data.repositories.online.RestUserRepository import com.example.dtf.repositories.online.mediator.RestCategoryRepository import dagger.Module import dagger.Provides diff --git a/app/src/main/java/com/example/dtf/MainActivity.kt b/app/src/main/java/com/example/dtf/MainActivity.kt index 97f4de9..5eb5a5b 100644 --- a/app/src/main/java/com/example/dtf/MainActivity.kt +++ b/app/src/main/java/com/example/dtf/MainActivity.kt @@ -1,15 +1,16 @@ package com.example.dtf import android.annotation.SuppressLint +import android.os.Build import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent +import androidx.annotation.RequiresApi import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height import androidx.compose.material.Icon import androidx.compose.material.IconButton import androidx.compose.material.Scaffold -import androidx.compose.material.Text import androidx.compose.material.TopAppBar import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowBack @@ -24,19 +25,21 @@ import androidx.navigation.compose.composable import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController import androidx.navigation.navigation -import com.example.dtf.screens.EditPostScreen -import com.example.dtf.screens.LoginScreen -import com.example.dtf.screens.NewPostScreen -import com.example.dtf.screens.PostScreen -import com.example.dtf.screens.PostsScreen -import com.example.dtf.screens.ProfileScreen -import com.example.dtf.screens.RegisterScreen -import com.example.dtf.utils.ScreenPaths -import com.example.dtf.widgets.BottomNavBar +import com.example.dtf.ui.screens.EditPostScreen +import com.example.dtf.ui.screens.LoginScreen +import com.example.dtf.ui.screens.NewPostScreen +import com.example.dtf.ui.screens.PostScreen +import com.example.dtf.ui.screens.PostsScreen +import com.example.dtf.ui.screens.ProfileScreen +import com.example.dtf.ui.screens.RegisterScreen +import com.example.dtf.ui.screens.TopPostsScreen +import com.example.dtf.ui.utils.ScreenPaths +import com.example.dtf.ui.widgets.BottomNavBar import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class MainActivity : ComponentActivity() { + @RequiresApi(Build.VERSION_CODES.O) @SuppressLint("UnusedMaterial3ScaffoldPaddingParameter", "UnusedMaterialScaffoldPaddingParameter" ) @@ -100,6 +103,10 @@ class MainActivity : ComponentActivity() { includeBackButton.value = false PostsScreen(navController) } + composable(ScreenPaths.TopPosts.route) { + includeBackButton.value = false + TopPostsScreen(navController) + } composable(ScreenPaths.NewPost.route) { includeBackButton.value = true NewPostScreen(navController) diff --git a/app/src/main/java/com/example/dtf/api/ServerService.kt b/app/src/main/java/com/example/dtf/data/api/ServerService.kt similarity index 81% rename from app/src/main/java/com/example/dtf/api/ServerService.kt rename to app/src/main/java/com/example/dtf/data/api/ServerService.kt index 2d01cd5..3bcdd60 100644 --- a/app/src/main/java/com/example/dtf/api/ServerService.kt +++ b/app/src/main/java/com/example/dtf/data/api/ServerService.kt @@ -1,30 +1,28 @@ -package com.example.dtf.api +package com.example.dtf.data.api -import com.example.dtf.dto.Credentials -import com.example.dtf.dto.EditPostDto -import com.example.dtf.dto.MeUser -import com.example.dtf.dto.NewCommentDto -import com.example.dtf.dto.NewPostDto -import com.example.dtf.dto.Token -import com.example.dtf.dto.remote.CategoriesResponse -import com.example.dtf.dto.remote.CommentsResponse -import com.example.dtf.dto.remote.PostsResponse -import com.example.dtf.models.Category -import com.example.dtf.models.Comment -import com.example.dtf.models.Post -import com.example.dtf.models.User +import com.example.dtf.data.dto.Credentials +import com.example.dtf.data.dto.EditPostDto +import com.example.dtf.data.dto.MeUser +import com.example.dtf.data.dto.NewCommentDto +import com.example.dtf.data.dto.NewPostDto +import com.example.dtf.data.dto.Token +import com.example.dtf.data.dto.remote.CategoriesResponse +import com.example.dtf.data.dto.remote.CommentsResponse +import com.example.dtf.data.dto.remote.PostsResponse +import com.example.dtf.data.models.Comment +import com.example.dtf.data.models.Post +import com.example.dtf.data.models.User import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory +import kotlinx.serialization.json.Json +import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor -import retrofit2.http.POST import retrofit2.Retrofit import retrofit2.http.Body import retrofit2.http.GET +import retrofit2.http.POST import retrofit2.http.Path import retrofit2.http.Query -import kotlinx.serialization.json.Json -import okhttp3.MediaType.Companion.toMediaType -import retrofit2.http.Header interface ServerService { @POST("auth/login") @@ -53,6 +51,13 @@ interface ServerService { @Query("limit") limit: Int? ): PostsResponse + @GET("post/top") + suspend fun getTopPosts( + @Query("category") categoryId: Int, + @Query("from_date") fromDate: String?, + @Query("to_date") toDate: String? + ): List + @GET("post/{postId}") suspend fun getPost( @Path("postId") postId: Int @@ -107,7 +112,7 @@ interface ServerService { ): User companion object { - private const val BASE_URL = "http://192.168.1.9:8000/" + private const val BASE_URL = "http://192.168.0.103:8000/" private var _token: String = "" diff --git a/app/src/main/java/com/example/dtf/dao/CategoryDao.kt b/app/src/main/java/com/example/dtf/data/dao/CategoryDao.kt similarity index 76% rename from app/src/main/java/com/example/dtf/dao/CategoryDao.kt rename to app/src/main/java/com/example/dtf/data/dao/CategoryDao.kt index 316969b..eb9f97b 100644 --- a/app/src/main/java/com/example/dtf/dao/CategoryDao.kt +++ b/app/src/main/java/com/example/dtf/data/dao/CategoryDao.kt @@ -1,8 +1,13 @@ -package com.example.dtf.dao +package com.example.dtf.data.dao import androidx.paging.PagingSource -import androidx.room.* -import com.example.dtf.models.* +import androidx.room.Dao +import androidx.room.Delete +import androidx.room.Insert +import androidx.room.OnConflictStrategy +import androidx.room.Query +import androidx.room.Update +import com.example.dtf.data.models.Category import kotlinx.coroutines.flow.Flow @Dao diff --git a/app/src/main/java/com/example/dtf/dao/CommentDao.kt b/app/src/main/java/com/example/dtf/data/dao/CommentDao.kt similarity index 78% rename from app/src/main/java/com/example/dtf/dao/CommentDao.kt rename to app/src/main/java/com/example/dtf/data/dao/CommentDao.kt index d411302..0e84c41 100644 --- a/app/src/main/java/com/example/dtf/dao/CommentDao.kt +++ b/app/src/main/java/com/example/dtf/data/dao/CommentDao.kt @@ -1,8 +1,13 @@ -package com.example.dtf.dao +package com.example.dtf.data.dao import androidx.paging.PagingSource -import androidx.room.* -import com.example.dtf.models.* +import androidx.room.Dao +import androidx.room.Delete +import androidx.room.Insert +import androidx.room.OnConflictStrategy +import androidx.room.Query +import androidx.room.Update +import com.example.dtf.data.models.Comment import kotlinx.coroutines.flow.Flow @Dao diff --git a/app/src/main/java/com/example/dtf/dao/LikeDao.kt b/app/src/main/java/com/example/dtf/data/dao/LikeDao.kt similarity index 67% rename from app/src/main/java/com/example/dtf/dao/LikeDao.kt rename to app/src/main/java/com/example/dtf/data/dao/LikeDao.kt index 183f731..1156752 100644 --- a/app/src/main/java/com/example/dtf/dao/LikeDao.kt +++ b/app/src/main/java/com/example/dtf/data/dao/LikeDao.kt @@ -1,7 +1,11 @@ -package com.example.dtf.dao +package com.example.dtf.data.dao -import androidx.room.* -import com.example.dtf.models.Like +import androidx.room.Dao +import androidx.room.Delete +import androidx.room.Insert +import androidx.room.OnConflictStrategy +import androidx.room.Query +import com.example.dtf.data.models.Like import kotlinx.coroutines.flow.Flow @Dao diff --git a/app/src/main/java/com/example/dtf/dao/PostDao.kt b/app/src/main/java/com/example/dtf/data/dao/PostDao.kt similarity index 74% rename from app/src/main/java/com/example/dtf/dao/PostDao.kt rename to app/src/main/java/com/example/dtf/data/dao/PostDao.kt index 7a8d690..9dc3df0 100644 --- a/app/src/main/java/com/example/dtf/dao/PostDao.kt +++ b/app/src/main/java/com/example/dtf/data/dao/PostDao.kt @@ -1,8 +1,13 @@ -package com.example.dtf.dao +package com.example.dtf.data.dao import androidx.paging.PagingSource -import androidx.room.* -import com.example.dtf.models.* +import androidx.room.Dao +import androidx.room.Delete +import androidx.room.Insert +import androidx.room.OnConflictStrategy +import androidx.room.Query +import androidx.room.Update +import com.example.dtf.data.models.Post import kotlinx.coroutines.flow.Flow @Dao diff --git a/app/src/main/java/com/example/dtf/dao/UserDao.kt b/app/src/main/java/com/example/dtf/data/dao/UserDao.kt similarity index 57% rename from app/src/main/java/com/example/dtf/dao/UserDao.kt rename to app/src/main/java/com/example/dtf/data/dao/UserDao.kt index de080c6..9fe3e7c 100644 --- a/app/src/main/java/com/example/dtf/dao/UserDao.kt +++ b/app/src/main/java/com/example/dtf/data/dao/UserDao.kt @@ -1,7 +1,12 @@ -package com.example.dtf.dao +package com.example.dtf.data.dao -import androidx.room.* -import com.example.dtf.models.User +import androidx.room.Dao +import androidx.room.Delete +import androidx.room.Insert +import androidx.room.OnConflictStrategy +import androidx.room.Query +import androidx.room.Update +import com.example.dtf.data.models.User import kotlinx.coroutines.flow.Flow @Dao diff --git a/app/src/main/java/com/example/dtf/db/AppDatabase.kt b/app/src/main/java/com/example/dtf/data/db/AppDatabase.kt similarity index 50% rename from app/src/main/java/com/example/dtf/db/AppDatabase.kt rename to app/src/main/java/com/example/dtf/data/db/AppDatabase.kt index b3cd4d5..43e4963 100644 --- a/app/src/main/java/com/example/dtf/db/AppDatabase.kt +++ b/app/src/main/java/com/example/dtf/data/db/AppDatabase.kt @@ -1,18 +1,18 @@ -package com.example.dtf.db +package com.example.dtf.data.db -import android.content.Context -import androidx.room.* -import com.example.dtf.models.Category -import com.example.dtf.models.Comment -import com.example.dtf.models.Post -import com.example.dtf.models.User -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import androidx.sqlite.db.SupportSQLiteDatabase -import com.example.dtf.dao.* -import com.example.dtf.models.Like -import java.util.Date +import androidx.room.Database +import androidx.room.RoomDatabase +import androidx.room.TypeConverters +import com.example.dtf.data.dao.CategoryDao +import com.example.dtf.data.dao.CommentDao +import com.example.dtf.data.dao.LikeDao +import com.example.dtf.data.dao.PostDao +import com.example.dtf.data.dao.UserDao +import com.example.dtf.data.models.Category +import com.example.dtf.data.models.Comment +import com.example.dtf.data.models.Like +import com.example.dtf.data.models.Post +import com.example.dtf.data.models.User @Database( entities = [ diff --git a/app/src/main/java/com/example/dtf/db/Converter.kt b/app/src/main/java/com/example/dtf/data/db/Converter.kt similarity index 89% rename from app/src/main/java/com/example/dtf/db/Converter.kt rename to app/src/main/java/com/example/dtf/data/db/Converter.kt index f6235ac..e3cfca3 100644 --- a/app/src/main/java/com/example/dtf/db/Converter.kt +++ b/app/src/main/java/com/example/dtf/data/db/Converter.kt @@ -1,4 +1,4 @@ -package com.example.dtf.db +package com.example.dtf.data.db import androidx.room.TypeConverter import java.util.Date diff --git a/app/src/main/java/com/example/dtf/dto/Credentials.kt b/app/src/main/java/com/example/dtf/data/dto/Credentials.kt similarity index 81% rename from app/src/main/java/com/example/dtf/dto/Credentials.kt rename to app/src/main/java/com/example/dtf/data/dto/Credentials.kt index e3a2c35..29d9528 100644 --- a/app/src/main/java/com/example/dtf/dto/Credentials.kt +++ b/app/src/main/java/com/example/dtf/data/dto/Credentials.kt @@ -1,4 +1,4 @@ -package com.example.dtf.dto +package com.example.dtf.data.dto import kotlinx.serialization.Serializable diff --git a/app/src/main/java/com/example/dtf/dto/EditPostDto.kt b/app/src/main/java/com/example/dtf/data/dto/EditPostDto.kt similarity index 79% rename from app/src/main/java/com/example/dtf/dto/EditPostDto.kt rename to app/src/main/java/com/example/dtf/data/dto/EditPostDto.kt index de4923d..faca33b 100644 --- a/app/src/main/java/com/example/dtf/dto/EditPostDto.kt +++ b/app/src/main/java/com/example/dtf/data/dto/EditPostDto.kt @@ -1,4 +1,4 @@ -package com.example.dtf.dto +package com.example.dtf.data.dto import kotlinx.serialization.Serializable diff --git a/app/src/main/java/com/example/dtf/dto/MeUser.kt b/app/src/main/java/com/example/dtf/data/dto/MeUser.kt similarity index 82% rename from app/src/main/java/com/example/dtf/dto/MeUser.kt rename to app/src/main/java/com/example/dtf/data/dto/MeUser.kt index 54eb68e..c9b6316 100644 --- a/app/src/main/java/com/example/dtf/dto/MeUser.kt +++ b/app/src/main/java/com/example/dtf/data/dto/MeUser.kt @@ -1,4 +1,4 @@ -package com.example.dtf.dto +package com.example.dtf.data.dto import kotlinx.serialization.Serializable diff --git a/app/src/main/java/com/example/dtf/dto/NewCommentDto.kt b/app/src/main/java/com/example/dtf/data/dto/NewCommentDto.kt similarity index 80% rename from app/src/main/java/com/example/dtf/dto/NewCommentDto.kt rename to app/src/main/java/com/example/dtf/data/dto/NewCommentDto.kt index d697e5b..d0c16e6 100644 --- a/app/src/main/java/com/example/dtf/dto/NewCommentDto.kt +++ b/app/src/main/java/com/example/dtf/data/dto/NewCommentDto.kt @@ -1,4 +1,4 @@ -package com.example.dtf.dto +package com.example.dtf.data.dto import kotlinx.serialization.Serializable diff --git a/app/src/main/java/com/example/dtf/dto/NewPostDto.kt b/app/src/main/java/com/example/dtf/data/dto/NewPostDto.kt similarity index 82% rename from app/src/main/java/com/example/dtf/dto/NewPostDto.kt rename to app/src/main/java/com/example/dtf/data/dto/NewPostDto.kt index 84bbe42..26847c8 100644 --- a/app/src/main/java/com/example/dtf/dto/NewPostDto.kt +++ b/app/src/main/java/com/example/dtf/data/dto/NewPostDto.kt @@ -1,4 +1,4 @@ -package com.example.dtf.dto +package com.example.dtf.data.dto import kotlinx.serialization.Serializable diff --git a/app/src/main/java/com/example/dtf/dto/Token.kt b/app/src/main/java/com/example/dtf/data/dto/Token.kt similarity index 75% rename from app/src/main/java/com/example/dtf/dto/Token.kt rename to app/src/main/java/com/example/dtf/data/dto/Token.kt index f200831..f6712fa 100644 --- a/app/src/main/java/com/example/dtf/dto/Token.kt +++ b/app/src/main/java/com/example/dtf/data/dto/Token.kt @@ -1,4 +1,4 @@ -package com.example.dtf.dto +package com.example.dtf.data.dto import kotlinx.serialization.Serializable diff --git a/app/src/main/java/com/example/dtf/dto/remote/CategoriesResponse.kt b/app/src/main/java/com/example/dtf/data/dto/remote/CategoriesResponse.kt similarity index 63% rename from app/src/main/java/com/example/dtf/dto/remote/CategoriesResponse.kt rename to app/src/main/java/com/example/dtf/data/dto/remote/CategoriesResponse.kt index 99c225f..5c32412 100644 --- a/app/src/main/java/com/example/dtf/dto/remote/CategoriesResponse.kt +++ b/app/src/main/java/com/example/dtf/data/dto/remote/CategoriesResponse.kt @@ -1,6 +1,6 @@ -package com.example.dtf.dto.remote +package com.example.dtf.data.dto.remote -import com.example.dtf.models.Category +import com.example.dtf.data.models.Category import kotlinx.serialization.Serializable @Serializable diff --git a/app/src/main/java/com/example/dtf/dto/remote/CommentsResponse.kt b/app/src/main/java/com/example/dtf/data/dto/remote/CommentsResponse.kt similarity index 63% rename from app/src/main/java/com/example/dtf/dto/remote/CommentsResponse.kt rename to app/src/main/java/com/example/dtf/data/dto/remote/CommentsResponse.kt index 03daa5a..a4fb6e3 100644 --- a/app/src/main/java/com/example/dtf/dto/remote/CommentsResponse.kt +++ b/app/src/main/java/com/example/dtf/data/dto/remote/CommentsResponse.kt @@ -1,6 +1,6 @@ -package com.example.dtf.dto.remote +package com.example.dtf.data.dto.remote -import com.example.dtf.models.Comment +import com.example.dtf.data.models.Comment import kotlinx.serialization.Serializable @Serializable diff --git a/app/src/main/java/com/example/dtf/dto/remote/PostsResponse.kt b/app/src/main/java/com/example/dtf/data/dto/remote/PostsResponse.kt similarity index 62% rename from app/src/main/java/com/example/dtf/dto/remote/PostsResponse.kt rename to app/src/main/java/com/example/dtf/data/dto/remote/PostsResponse.kt index 654df0e..938c401 100644 --- a/app/src/main/java/com/example/dtf/dto/remote/PostsResponse.kt +++ b/app/src/main/java/com/example/dtf/data/dto/remote/PostsResponse.kt @@ -1,6 +1,6 @@ -package com.example.dtf.dto.remote +package com.example.dtf.data.dto.remote -import com.example.dtf.models.Post +import com.example.dtf.data.models.Post import kotlinx.serialization.Serializable @Serializable diff --git a/app/src/main/java/com/example/dtf/models/Category.kt b/app/src/main/java/com/example/dtf/data/models/Category.kt similarity index 79% rename from app/src/main/java/com/example/dtf/models/Category.kt rename to app/src/main/java/com/example/dtf/data/models/Category.kt index 2df43fd..7f27bc0 100644 --- a/app/src/main/java/com/example/dtf/models/Category.kt +++ b/app/src/main/java/com/example/dtf/data/models/Category.kt @@ -1,6 +1,8 @@ -package com.example.dtf.models +package com.example.dtf.data.models -import androidx.room.* +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey import kotlinx.serialization.Serializable @Entity(tableName = "category") diff --git a/app/src/main/java/com/example/dtf/models/Comment.kt b/app/src/main/java/com/example/dtf/data/models/Comment.kt similarity index 84% rename from app/src/main/java/com/example/dtf/models/Comment.kt rename to app/src/main/java/com/example/dtf/data/models/Comment.kt index 203fb7f..0a99575 100644 --- a/app/src/main/java/com/example/dtf/models/Comment.kt +++ b/app/src/main/java/com/example/dtf/data/models/Comment.kt @@ -1,6 +1,8 @@ -package com.example.dtf.models +package com.example.dtf.data.models -import androidx.room.* +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey import kotlinx.serialization.Serializable @Entity(tableName = "comment") diff --git a/app/src/main/java/com/example/dtf/models/Like.kt b/app/src/main/java/com/example/dtf/data/models/Like.kt similarity index 69% rename from app/src/main/java/com/example/dtf/models/Like.kt rename to app/src/main/java/com/example/dtf/data/models/Like.kt index 3889518..d27b2f8 100644 --- a/app/src/main/java/com/example/dtf/models/Like.kt +++ b/app/src/main/java/com/example/dtf/data/models/Like.kt @@ -1,6 +1,7 @@ -package com.example.dtf.models +package com.example.dtf.data.models -import androidx.room.* +import androidx.room.ColumnInfo +import androidx.room.Entity @Entity(tableName = "likes", primaryKeys = ["user_id", "post_id"]) data class Like ( diff --git a/app/src/main/java/com/example/dtf/models/Post.kt b/app/src/main/java/com/example/dtf/data/models/Post.kt similarity index 97% rename from app/src/main/java/com/example/dtf/models/Post.kt rename to app/src/main/java/com/example/dtf/data/models/Post.kt index 5cd092f..a85f64e 100644 --- a/app/src/main/java/com/example/dtf/models/Post.kt +++ b/app/src/main/java/com/example/dtf/data/models/Post.kt @@ -1,6 +1,8 @@ -package com.example.dtf.models +package com.example.dtf.data.models -import androidx.room.* +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey import kotlinx.serialization.Serializable //private val posts = listOf( diff --git a/app/src/main/java/com/example/dtf/models/User.kt b/app/src/main/java/com/example/dtf/data/models/User.kt similarity index 79% rename from app/src/main/java/com/example/dtf/models/User.kt rename to app/src/main/java/com/example/dtf/data/models/User.kt index d563c49..910f635 100644 --- a/app/src/main/java/com/example/dtf/models/User.kt +++ b/app/src/main/java/com/example/dtf/data/models/User.kt @@ -1,6 +1,8 @@ -package com.example.dtf.models +package com.example.dtf.data.models -import androidx.room.* +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey import kotlinx.serialization.Serializable @Entity(tableName = "user") diff --git a/app/src/main/java/com/example/dtf/repositories/ICategoryRepository.kt b/app/src/main/java/com/example/dtf/data/repositories/ICategoryRepository.kt similarity index 72% rename from app/src/main/java/com/example/dtf/repositories/ICategoryRepository.kt rename to app/src/main/java/com/example/dtf/data/repositories/ICategoryRepository.kt index a80af87..bd24008 100644 --- a/app/src/main/java/com/example/dtf/repositories/ICategoryRepository.kt +++ b/app/src/main/java/com/example/dtf/data/repositories/ICategoryRepository.kt @@ -1,7 +1,7 @@ -package com.example.dtf.repositories +package com.example.dtf.data.repositories import androidx.paging.PagingData -import com.example.dtf.models.Category +import com.example.dtf.data.models.Category import kotlinx.coroutines.flow.Flow interface ICategoryRepository { diff --git a/app/src/main/java/com/example/dtf/repositories/ICommentRepository.kt b/app/src/main/java/com/example/dtf/data/repositories/ICommentRepository.kt similarity index 73% rename from app/src/main/java/com/example/dtf/repositories/ICommentRepository.kt rename to app/src/main/java/com/example/dtf/data/repositories/ICommentRepository.kt index fb4ad0a..d94a981 100644 --- a/app/src/main/java/com/example/dtf/repositories/ICommentRepository.kt +++ b/app/src/main/java/com/example/dtf/data/repositories/ICommentRepository.kt @@ -1,7 +1,7 @@ -package com.example.dtf.repositories +package com.example.dtf.data.repositories import androidx.paging.PagingData -import com.example.dtf.models.Comment +import com.example.dtf.data.models.Comment import kotlinx.coroutines.flow.Flow interface ICommentRepository { diff --git a/app/src/main/java/com/example/dtf/repositories/ILikeRepository.kt b/app/src/main/java/com/example/dtf/data/repositories/ILikeRepository.kt similarity index 74% rename from app/src/main/java/com/example/dtf/repositories/ILikeRepository.kt rename to app/src/main/java/com/example/dtf/data/repositories/ILikeRepository.kt index af3479d..5472663 100644 --- a/app/src/main/java/com/example/dtf/repositories/ILikeRepository.kt +++ b/app/src/main/java/com/example/dtf/data/repositories/ILikeRepository.kt @@ -1,6 +1,6 @@ -package com.example.dtf.repositories +package com.example.dtf.data.repositories -import com.example.dtf.models.Like +import com.example.dtf.data.models.Like import kotlinx.coroutines.flow.Flow interface ILikeRepository { diff --git a/app/src/main/java/com/example/dtf/repositories/IPostRepository.kt b/app/src/main/java/com/example/dtf/data/repositories/IPostRepository.kt similarity index 57% rename from app/src/main/java/com/example/dtf/repositories/IPostRepository.kt rename to app/src/main/java/com/example/dtf/data/repositories/IPostRepository.kt index ed06677..cedafc1 100644 --- a/app/src/main/java/com/example/dtf/repositories/IPostRepository.kt +++ b/app/src/main/java/com/example/dtf/data/repositories/IPostRepository.kt @@ -1,8 +1,9 @@ -package com.example.dtf.repositories +package com.example.dtf.data.repositories import androidx.paging.PagingData -import com.example.dtf.models.Post +import com.example.dtf.data.models.Post import kotlinx.coroutines.flow.Flow +import java.time.LocalDate interface IPostRepository { suspend fun insert(post: Post) @@ -10,4 +11,6 @@ interface IPostRepository { fun getById(id: Int): Flow fun getByCategory(categoryId: Int): Flow> + + fun getTopTen(categoryId: Int, fromDate: LocalDate, toDate: LocalDate): Flow> } \ No newline at end of file diff --git a/app/src/main/java/com/example/dtf/repositories/IUserRepository.kt b/app/src/main/java/com/example/dtf/data/repositories/IUserRepository.kt similarity index 55% rename from app/src/main/java/com/example/dtf/repositories/IUserRepository.kt rename to app/src/main/java/com/example/dtf/data/repositories/IUserRepository.kt index 655ded1..6cd6e5e 100644 --- a/app/src/main/java/com/example/dtf/repositories/IUserRepository.kt +++ b/app/src/main/java/com/example/dtf/data/repositories/IUserRepository.kt @@ -1,6 +1,6 @@ -package com.example.dtf.repositories +package com.example.dtf.data.repositories -import com.example.dtf.models.User +import com.example.dtf.data.models.User import kotlinx.coroutines.flow.Flow interface IUserRepository { diff --git a/app/src/main/java/com/example/dtf/repositories/offline/OfflineCategoryRepository.kt b/app/src/main/java/com/example/dtf/data/repositories/offline/OfflineCategoryRepository.kt similarity index 76% rename from app/src/main/java/com/example/dtf/repositories/offline/OfflineCategoryRepository.kt rename to app/src/main/java/com/example/dtf/data/repositories/offline/OfflineCategoryRepository.kt index 0e7dfca..d7b707d 100644 --- a/app/src/main/java/com/example/dtf/repositories/offline/OfflineCategoryRepository.kt +++ b/app/src/main/java/com/example/dtf/data/repositories/offline/OfflineCategoryRepository.kt @@ -1,10 +1,10 @@ -package com.example.dtf.repositories.offline +package com.example.dtf.data.repositories.offline import androidx.paging.Pager import androidx.paging.PagingConfig -import com.example.dtf.dao.CategoryDao -import com.example.dtf.models.Category -import com.example.dtf.repositories.ICategoryRepository +import com.example.dtf.data.dao.CategoryDao +import com.example.dtf.data.models.Category +import com.example.dtf.data.repositories.ICategoryRepository import kotlinx.coroutines.flow.Flow import javax.inject.Inject diff --git a/app/src/main/java/com/example/dtf/repositories/offline/OfflineCommentRepository.kt b/app/src/main/java/com/example/dtf/data/repositories/offline/OfflineCommentRepository.kt similarity index 65% rename from app/src/main/java/com/example/dtf/repositories/offline/OfflineCommentRepository.kt rename to app/src/main/java/com/example/dtf/data/repositories/offline/OfflineCommentRepository.kt index a448746..47884d2 100644 --- a/app/src/main/java/com/example/dtf/repositories/offline/OfflineCommentRepository.kt +++ b/app/src/main/java/com/example/dtf/data/repositories/offline/OfflineCommentRepository.kt @@ -1,9 +1,10 @@ -package com.example.dtf.repositories.offline +package com.example.dtf.data.repositories.offline -import androidx.paging.* -import com.example.dtf.dao.CommentDao -import com.example.dtf.models.Comment -import com.example.dtf.repositories.ICommentRepository +import androidx.paging.Pager +import androidx.paging.PagingConfig +import com.example.dtf.data.dao.CommentDao +import com.example.dtf.data.models.Comment +import com.example.dtf.data.repositories.ICommentRepository import javax.inject.Inject class OfflineCommentRepository @Inject constructor( diff --git a/app/src/main/java/com/example/dtf/repositories/offline/OfflineLikeRepository.kt b/app/src/main/java/com/example/dtf/data/repositories/offline/OfflineLikeRepository.kt similarity index 70% rename from app/src/main/java/com/example/dtf/repositories/offline/OfflineLikeRepository.kt rename to app/src/main/java/com/example/dtf/data/repositories/offline/OfflineLikeRepository.kt index e280123..e4a5cdb 100644 --- a/app/src/main/java/com/example/dtf/repositories/offline/OfflineLikeRepository.kt +++ b/app/src/main/java/com/example/dtf/data/repositories/offline/OfflineLikeRepository.kt @@ -1,8 +1,8 @@ -package com.example.dtf.repositories.offline +package com.example.dtf.data.repositories.offline -import com.example.dtf.dao.LikeDao -import com.example.dtf.models.Like -import com.example.dtf.repositories.ILikeRepository +import com.example.dtf.data.dao.LikeDao +import com.example.dtf.data.models.Like +import com.example.dtf.data.repositories.ILikeRepository import javax.inject.Inject class OfflineLikeRepository @Inject constructor( diff --git a/app/src/main/java/com/example/dtf/repositories/offline/OfflinePostRepository.kt b/app/src/main/java/com/example/dtf/data/repositories/offline/OfflinePostRepository.kt similarity index 52% rename from app/src/main/java/com/example/dtf/repositories/offline/OfflinePostRepository.kt rename to app/src/main/java/com/example/dtf/data/repositories/offline/OfflinePostRepository.kt index b4e1661..d86dec0 100644 --- a/app/src/main/java/com/example/dtf/repositories/offline/OfflinePostRepository.kt +++ b/app/src/main/java/com/example/dtf/data/repositories/offline/OfflinePostRepository.kt @@ -1,9 +1,12 @@ -package com.example.dtf.repositories.offline +package com.example.dtf.data.repositories.offline -import androidx.paging.* -import com.example.dtf.dao.PostDao -import com.example.dtf.models.Post -import com.example.dtf.repositories.IPostRepository +import androidx.paging.Pager +import androidx.paging.PagingConfig +import com.example.dtf.data.dao.PostDao +import com.example.dtf.data.models.Post +import com.example.dtf.data.repositories.IPostRepository +import kotlinx.coroutines.flow.Flow +import java.time.LocalDate import javax.inject.Inject class OfflinePostRepository @Inject constructor( @@ -22,4 +25,8 @@ class OfflinePostRepository @Inject constructor( ), pagingSourceFactory = { postDao.getByCategory(categoryId.toString()) } ).flow + + override fun getTopTen(categoryId: Int, fromDate: LocalDate, toDate: LocalDate): Flow> { + throw NotImplementedError("Cannot access top without internet connection") + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/dtf/repositories/offline/OfflineUserRepository.kt b/app/src/main/java/com/example/dtf/data/repositories/offline/OfflineUserRepository.kt similarity index 52% rename from app/src/main/java/com/example/dtf/repositories/offline/OfflineUserRepository.kt rename to app/src/main/java/com/example/dtf/data/repositories/offline/OfflineUserRepository.kt index 1712f9e..b2e9d6e 100644 --- a/app/src/main/java/com/example/dtf/repositories/offline/OfflineUserRepository.kt +++ b/app/src/main/java/com/example/dtf/data/repositories/offline/OfflineUserRepository.kt @@ -1,8 +1,7 @@ -package com.example.dtf.repositories.offline +package com.example.dtf.data.repositories.offline -import com.example.dtf.dao.UserDao -import com.example.dtf.models.User -import com.example.dtf.repositories.IUserRepository +import com.example.dtf.data.dao.UserDao +import com.example.dtf.data.repositories.IUserRepository import javax.inject.Inject class OfflineUserRepository @Inject constructor( diff --git a/app/src/main/java/com/example/dtf/repositories/online/RestCategoryRepository.kt b/app/src/main/java/com/example/dtf/data/repositories/online/RestCategoryRepository.kt similarity index 78% rename from app/src/main/java/com/example/dtf/repositories/online/RestCategoryRepository.kt rename to app/src/main/java/com/example/dtf/data/repositories/online/RestCategoryRepository.kt index 8f122a9..0c0c148 100644 --- a/app/src/main/java/com/example/dtf/repositories/online/RestCategoryRepository.kt +++ b/app/src/main/java/com/example/dtf/data/repositories/online/RestCategoryRepository.kt @@ -4,12 +4,12 @@ import androidx.paging.ExperimentalPagingApi import androidx.paging.Pager import androidx.paging.PagingConfig import androidx.paging.PagingData -import com.example.dtf.api.ServerService -import com.example.dtf.db.AppDatabase -import com.example.dtf.models.Category -import com.example.dtf.repositories.ICategoryRepository +import com.example.dtf.data.api.ServerService +import com.example.dtf.data.db.AppDatabase +import com.example.dtf.data.models.Category +import com.example.dtf.data.repositories.ICategoryRepository +import com.example.dtf.data.repositories.online.mediator.CategoryMediator import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.flow import javax.inject.Inject class RestCategoryRepository @Inject constructor( diff --git a/app/src/main/java/com/example/dtf/repositories/online/RestCommentRepository.kt b/app/src/main/java/com/example/dtf/data/repositories/online/RestCommentRepository.kt similarity index 76% rename from app/src/main/java/com/example/dtf/repositories/online/RestCommentRepository.kt rename to app/src/main/java/com/example/dtf/data/repositories/online/RestCommentRepository.kt index ae0549e..c871ec9 100644 --- a/app/src/main/java/com/example/dtf/repositories/online/RestCommentRepository.kt +++ b/app/src/main/java/com/example/dtf/data/repositories/online/RestCommentRepository.kt @@ -1,15 +1,15 @@ -package com.example.dtf.repositories.online +package com.example.dtf.data.repositories.online import androidx.paging.ExperimentalPagingApi import androidx.paging.Pager import androidx.paging.PagingConfig import androidx.paging.PagingData -import com.example.dtf.api.ServerService -import com.example.dtf.db.AppDatabase -import com.example.dtf.dto.NewCommentDto -import com.example.dtf.models.Comment -import com.example.dtf.repositories.ICommentRepository -import com.example.dtf.repositories.online.mediator.CommentMediator +import com.example.dtf.data.api.ServerService +import com.example.dtf.data.db.AppDatabase +import com.example.dtf.data.dto.NewCommentDto +import com.example.dtf.data.models.Comment +import com.example.dtf.data.repositories.ICommentRepository +import com.example.dtf.data.repositories.online.mediator.CommentMediator import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import javax.inject.Inject diff --git a/app/src/main/java/com/example/dtf/repositories/online/RestLikeRepository.kt b/app/src/main/java/com/example/dtf/data/repositories/online/RestLikeRepository.kt similarity index 75% rename from app/src/main/java/com/example/dtf/repositories/online/RestLikeRepository.kt rename to app/src/main/java/com/example/dtf/data/repositories/online/RestLikeRepository.kt index 3e66320..7dacb43 100644 --- a/app/src/main/java/com/example/dtf/repositories/online/RestLikeRepository.kt +++ b/app/src/main/java/com/example/dtf/data/repositories/online/RestLikeRepository.kt @@ -1,9 +1,9 @@ -package com.example.dtf.repositories.online +package com.example.dtf.data.repositories.online -import com.example.dtf.api.ServerService -import com.example.dtf.db.AppDatabase -import com.example.dtf.models.Like -import com.example.dtf.repositories.ILikeRepository +import com.example.dtf.data.api.ServerService +import com.example.dtf.data.db.AppDatabase +import com.example.dtf.data.models.Like +import com.example.dtf.data.repositories.ILikeRepository import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import javax.inject.Inject diff --git a/app/src/main/java/com/example/dtf/repositories/online/RestPostRepository.kt b/app/src/main/java/com/example/dtf/data/repositories/online/RestPostRepository.kt similarity index 58% rename from app/src/main/java/com/example/dtf/repositories/online/RestPostRepository.kt rename to app/src/main/java/com/example/dtf/data/repositories/online/RestPostRepository.kt index 87e21c1..670b9db 100644 --- a/app/src/main/java/com/example/dtf/repositories/online/RestPostRepository.kt +++ b/app/src/main/java/com/example/dtf/data/repositories/online/RestPostRepository.kt @@ -1,18 +1,21 @@ -package com.example.dtf.repositories.online +package com.example.dtf.data.repositories.online +import android.os.Build +import androidx.annotation.RequiresApi import androidx.paging.ExperimentalPagingApi import androidx.paging.Pager import androidx.paging.PagingConfig import androidx.paging.PagingData -import com.example.dtf.api.ServerService -import com.example.dtf.db.AppDatabase -import com.example.dtf.dto.EditPostDto -import com.example.dtf.dto.NewPostDto -import com.example.dtf.models.Post -import com.example.dtf.repositories.IPostRepository -import com.example.dtf.repositories.online.mediator.PostMediator +import com.example.dtf.data.api.ServerService +import com.example.dtf.data.db.AppDatabase +import com.example.dtf.data.dto.EditPostDto +import com.example.dtf.data.dto.NewPostDto +import com.example.dtf.data.models.Post +import com.example.dtf.data.repositories.IPostRepository +import com.example.dtf.data.repositories.online.mediator.PostMediator import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow +import java.time.LocalDate import javax.inject.Inject class RestPostRepository @Inject constructor( @@ -46,4 +49,17 @@ class RestPostRepository @Inject constructor( remoteMediator = PostMediator(appDatabase, serverService, categoryId.toString()), pagingSourceFactory = { appDatabase.postDao().getByCategory(categoryId.toString()) } ).flow + + @RequiresApi(Build.VERSION_CODES.O) + override fun getTopTen(categoryId: Int, fromDate: LocalDate, toDate: LocalDate): Flow> { + return flow { + emit( + serverService.getTopPosts( + categoryId, + "${fromDate.year}-${fromDate.monthValue}-${fromDate.dayOfMonth}", + "${toDate.year}-${toDate.monthValue}-${toDate.dayOfMonth}" + ) + ) + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/dtf/repositories/online/RestUserRepository.kt b/app/src/main/java/com/example/dtf/data/repositories/online/RestUserRepository.kt similarity index 60% rename from app/src/main/java/com/example/dtf/repositories/online/RestUserRepository.kt rename to app/src/main/java/com/example/dtf/data/repositories/online/RestUserRepository.kt index 4699adf..8ec8e5c 100644 --- a/app/src/main/java/com/example/dtf/repositories/online/RestUserRepository.kt +++ b/app/src/main/java/com/example/dtf/data/repositories/online/RestUserRepository.kt @@ -1,9 +1,9 @@ -package com.example.dtf.repositories.online +package com.example.dtf.data.repositories.online -import com.example.dtf.api.ServerService -import com.example.dtf.db.AppDatabase -import com.example.dtf.models.User -import com.example.dtf.repositories.IUserRepository +import com.example.dtf.data.api.ServerService +import com.example.dtf.data.db.AppDatabase +import com.example.dtf.data.models.User +import com.example.dtf.data.repositories.IUserRepository import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import javax.inject.Inject diff --git a/app/src/main/java/com/example/dtf/repositories/online/mediator/CategoryMediator.kt b/app/src/main/java/com/example/dtf/data/repositories/online/mediator/CategoryMediator.kt similarity index 91% rename from app/src/main/java/com/example/dtf/repositories/online/mediator/CategoryMediator.kt rename to app/src/main/java/com/example/dtf/data/repositories/online/mediator/CategoryMediator.kt index e0a053b..420e68f 100644 --- a/app/src/main/java/com/example/dtf/repositories/online/mediator/CategoryMediator.kt +++ b/app/src/main/java/com/example/dtf/data/repositories/online/mediator/CategoryMediator.kt @@ -1,13 +1,13 @@ -package com.example.dtf.repositories.online.mediator +package com.example.dtf.data.repositories.online.mediator import androidx.paging.ExperimentalPagingApi import androidx.paging.LoadType import androidx.paging.PagingState import androidx.paging.RemoteMediator import androidx.room.withTransaction -import com.example.dtf.api.ServerService -import com.example.dtf.db.AppDatabase -import com.example.dtf.models.Category +import com.example.dtf.data.api.ServerService +import com.example.dtf.data.db.AppDatabase +import com.example.dtf.data.models.Category import kotlinx.coroutines.flow.first import java.io.IOException diff --git a/app/src/main/java/com/example/dtf/repositories/online/mediator/CommentMediator.kt b/app/src/main/java/com/example/dtf/data/repositories/online/mediator/CommentMediator.kt similarity index 92% rename from app/src/main/java/com/example/dtf/repositories/online/mediator/CommentMediator.kt rename to app/src/main/java/com/example/dtf/data/repositories/online/mediator/CommentMediator.kt index 8b6b088..2e210da 100644 --- a/app/src/main/java/com/example/dtf/repositories/online/mediator/CommentMediator.kt +++ b/app/src/main/java/com/example/dtf/data/repositories/online/mediator/CommentMediator.kt @@ -1,13 +1,13 @@ -package com.example.dtf.repositories.online.mediator +package com.example.dtf.data.repositories.online.mediator import androidx.paging.ExperimentalPagingApi import androidx.paging.LoadType import androidx.paging.PagingState import androidx.paging.RemoteMediator import androidx.room.withTransaction -import com.example.dtf.api.ServerService -import com.example.dtf.db.AppDatabase -import com.example.dtf.models.Comment +import com.example.dtf.data.api.ServerService +import com.example.dtf.data.db.AppDatabase +import com.example.dtf.data.models.Comment import kotlinx.coroutines.flow.first import java.io.IOException diff --git a/app/src/main/java/com/example/dtf/repositories/online/mediator/PostMediator.kt b/app/src/main/java/com/example/dtf/data/repositories/online/mediator/PostMediator.kt similarity index 91% rename from app/src/main/java/com/example/dtf/repositories/online/mediator/PostMediator.kt rename to app/src/main/java/com/example/dtf/data/repositories/online/mediator/PostMediator.kt index 39a9e86..c5f77b0 100644 --- a/app/src/main/java/com/example/dtf/repositories/online/mediator/PostMediator.kt +++ b/app/src/main/java/com/example/dtf/data/repositories/online/mediator/PostMediator.kt @@ -1,13 +1,13 @@ -package com.example.dtf.repositories.online.mediator +package com.example.dtf.data.repositories.online.mediator import androidx.paging.ExperimentalPagingApi import androidx.paging.LoadType import androidx.paging.PagingState import androidx.paging.RemoteMediator import androidx.room.withTransaction -import com.example.dtf.api.ServerService -import com.example.dtf.db.AppDatabase -import com.example.dtf.models.Post +import com.example.dtf.data.api.ServerService +import com.example.dtf.data.db.AppDatabase +import com.example.dtf.data.models.Post import kotlinx.coroutines.flow.first import java.io.IOException diff --git a/app/src/main/java/com/example/dtf/screens/EditPostScreen.kt b/app/src/main/java/com/example/dtf/ui/screens/EditPostScreen.kt similarity index 79% rename from app/src/main/java/com/example/dtf/screens/EditPostScreen.kt rename to app/src/main/java/com/example/dtf/ui/screens/EditPostScreen.kt index 029e739..1670dcb 100644 --- a/app/src/main/java/com/example/dtf/screens/EditPostScreen.kt +++ b/app/src/main/java/com/example/dtf/ui/screens/EditPostScreen.kt @@ -1,26 +1,40 @@ -package com.example.dtf.screens +package com.example.dtf.ui.screens import androidx.compose.foundation.BorderStroke -import androidx.compose.foundation.layout.* +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll -import androidx.compose.material.* -import androidx.compose.runtime.* +import androidx.compose.material.AlertDialog +import androidx.compose.material.Button +import androidx.compose.material.ButtonDefaults +import androidx.compose.material.Text +import androidx.compose.material.TextButton +import androidx.compose.runtime.Composable import androidx.compose.runtime.livedata.observeAsState -import androidx.compose.ui.* +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.TextFieldValue -import androidx.compose.ui.unit.* +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavHostController import com.example.dtf.PreferencesManager -import com.example.dtf.utils.ScreenPaths -import com.example.dtf.viewmodels.EditPostViewModel -import com.example.dtf.widgets.MyTextField +import com.example.dtf.ui.utils.ScreenPaths +import com.example.dtf.ui.viewmodels.EditPostViewModel +import com.example.dtf.ui.widgets.MyTextField @Composable fun EditPostScreen(navController: NavHostController, postId: Int) { diff --git a/app/src/main/java/com/example/dtf/screens/LoginScreen.kt b/app/src/main/java/com/example/dtf/ui/screens/LoginScreen.kt similarity index 80% rename from app/src/main/java/com/example/dtf/screens/LoginScreen.kt rename to app/src/main/java/com/example/dtf/ui/screens/LoginScreen.kt index 65f6046..f932381 100644 --- a/app/src/main/java/com/example/dtf/screens/LoginScreen.kt +++ b/app/src/main/java/com/example/dtf/ui/screens/LoginScreen.kt @@ -1,25 +1,40 @@ -package com.example.dtf.screens +package com.example.dtf.ui.screens import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.* +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.* -import androidx.compose.runtime.* +import androidx.compose.material.AlertDialog +import androidx.compose.material.Button +import androidx.compose.material.ButtonDefaults +import androidx.compose.material.Text +import androidx.compose.material.TextButton +import androidx.compose.runtime.Composable import androidx.compose.runtime.livedata.observeAsState -import androidx.compose.ui.* +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.TextFieldValue -import androidx.compose.ui.unit.* +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavHostController import com.example.dtf.PreferencesManager -import com.example.dtf.utils.ScreenPaths -import com.example.dtf.viewmodels.LoginViewModel -import com.example.dtf.widgets.MyTextField +import com.example.dtf.ui.utils.ScreenPaths +import com.example.dtf.ui.viewmodels.LoginViewModel +import com.example.dtf.ui.widgets.MyTextField @Composable fun LoginScreen(navController: NavHostController) { diff --git a/app/src/main/java/com/example/dtf/screens/NewPostScreen.kt b/app/src/main/java/com/example/dtf/ui/screens/NewPostScreen.kt similarity index 82% rename from app/src/main/java/com/example/dtf/screens/NewPostScreen.kt rename to app/src/main/java/com/example/dtf/ui/screens/NewPostScreen.kt index f8c5bc7..21fc867 100644 --- a/app/src/main/java/com/example/dtf/screens/NewPostScreen.kt +++ b/app/src/main/java/com/example/dtf/ui/screens/NewPostScreen.kt @@ -1,29 +1,45 @@ -package com.example.dtf.screens +package com.example.dtf.ui.screens import androidx.compose.foundation.BorderStroke -import androidx.compose.foundation.layout.* +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll -import androidx.compose.material.* -import androidx.compose.runtime.* +import androidx.compose.material.AlertDialog +import androidx.compose.material.Button +import androidx.compose.material.ButtonDefaults +import androidx.compose.material.DropdownMenu +import androidx.compose.material.DropdownMenuItem +import androidx.compose.material.Text +import androidx.compose.material.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState import androidx.compose.runtime.livedata.observeAsState -import androidx.compose.ui.* +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.unit.* +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavHostController -import androidx.paging.compose.collectAsLazyPagingItems import com.example.dtf.PreferencesManager -import com.example.dtf.models.Category -import com.example.dtf.utils.ScreenPaths -import com.example.dtf.viewmodels.NewPostViewModel -import com.example.dtf.widgets.MyTextField +import com.example.dtf.data.models.Category +import com.example.dtf.ui.utils.ScreenPaths +import com.example.dtf.ui.viewmodels.NewPostViewModel +import com.example.dtf.ui.widgets.MyTextField @Composable fun NewPostScreen(navController: NavHostController) { diff --git a/app/src/main/java/com/example/dtf/screens/PostScreen.kt b/app/src/main/java/com/example/dtf/ui/screens/PostScreen.kt similarity index 82% rename from app/src/main/java/com/example/dtf/screens/PostScreen.kt rename to app/src/main/java/com/example/dtf/ui/screens/PostScreen.kt index 18b0e70..dd10941 100644 --- a/app/src/main/java/com/example/dtf/screens/PostScreen.kt +++ b/app/src/main/java/com/example/dtf/ui/screens/PostScreen.kt @@ -1,32 +1,51 @@ -package com.example.dtf.screens +package com.example.dtf.ui.screens -import androidx.compose.foundation.layout.* -import androidx.compose.foundation.* +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.* +import androidx.compose.material.Divider +import androidx.compose.material.Icon +import androidx.compose.material.IconButton +import androidx.compose.material.Text import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.AddCircle import androidx.compose.material.icons.filled.ThumbUp import androidx.compose.runtime.Composable -import androidx.compose.runtime.* +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.collectAsState import androidx.compose.runtime.livedata.observeAsState -import androidx.compose.ui.* -import androidx.compose.ui.draw.* -import androidx.compose.ui.graphics.* +import androidx.compose.runtime.mutableIntStateOf +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.scale +import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.unit.* +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavHostController import androidx.paging.compose.collectAsLazyPagingItems import androidx.paging.compose.itemKey import com.example.dtf.PreferencesManager -import com.example.dtf.models.Comment -import com.example.dtf.utils.ScreenPaths -import com.example.dtf.viewmodels.PostViewModel -import com.example.dtf.widgets.MyTextField +import com.example.dtf.data.models.Comment +import com.example.dtf.ui.utils.ScreenPaths +import com.example.dtf.ui.viewmodels.PostViewModel +import com.example.dtf.ui.widgets.MyTextField @Composable fun PostScreen(postId: Int, navController: NavHostController) { diff --git a/app/src/main/java/com/example/dtf/screens/PostsScreen.kt b/app/src/main/java/com/example/dtf/ui/screens/PostsScreen.kt similarity index 82% rename from app/src/main/java/com/example/dtf/screens/PostsScreen.kt rename to app/src/main/java/com/example/dtf/ui/screens/PostsScreen.kt index 05c8f26..29b71b2 100644 --- a/app/src/main/java/com/example/dtf/screens/PostsScreen.kt +++ b/app/src/main/java/com/example/dtf/ui/screens/PostsScreen.kt @@ -1,31 +1,49 @@ -package com.example.dtf.screens +package com.example.dtf.ui.screens -import androidx.compose.foundation.layout.* -import androidx.compose.foundation.* +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyRow -import androidx.compose.material.* +import androidx.compose.material.Icon +import androidx.compose.material.Text import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ThumbUp import androidx.compose.runtime.Composable -import androidx.compose.runtime.* -import androidx.compose.ui.* -import androidx.compose.ui.draw.* -import androidx.compose.ui.geometry.* -import androidx.compose.ui.graphics.* +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.MutableState +import androidx.compose.runtime.mutableIntStateOf +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.drawBehind +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.style.TextOverflow -import androidx.compose.ui.unit.* +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavHostController import androidx.paging.PagingData import androidx.paging.compose.collectAsLazyPagingItems import androidx.paging.compose.itemKey import com.example.dtf.PreferencesManager -import com.example.dtf.models.Category -import com.example.dtf.models.Post -import com.example.dtf.utils.ScreenPaths -import com.example.dtf.viewmodels.PostsViewModel +import com.example.dtf.data.models.Category +import com.example.dtf.data.models.Post +import com.example.dtf.ui.utils.ScreenPaths +import com.example.dtf.ui.viewmodels.PostsViewModel import kotlinx.coroutines.flow.Flow @Composable diff --git a/app/src/main/java/com/example/dtf/screens/ProfileScreen.kt b/app/src/main/java/com/example/dtf/ui/screens/ProfileScreen.kt similarity index 74% rename from app/src/main/java/com/example/dtf/screens/ProfileScreen.kt rename to app/src/main/java/com/example/dtf/ui/screens/ProfileScreen.kt index feb4aca..613ed50 100644 --- a/app/src/main/java/com/example/dtf/screens/ProfileScreen.kt +++ b/app/src/main/java/com/example/dtf/ui/screens/ProfileScreen.kt @@ -1,20 +1,33 @@ -package com.example.dtf.screens +package com.example.dtf.ui.screens -import androidx.compose.foundation.* -import androidx.compose.foundation.layout.* +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.* +import androidx.compose.material.Card +import androidx.compose.material.Divider +import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.livedata.observeAsState -import androidx.compose.ui.* -import androidx.compose.ui.graphics.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.unit.* +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavHostController import com.example.dtf.PreferencesManager -import com.example.dtf.utils.ScreenPaths -import com.example.dtf.viewmodels.ProfileViewModel +import com.example.dtf.ui.utils.ScreenPaths +import com.example.dtf.ui.viewmodels.ProfileViewModel @Composable fun ProfileScreen(navController: NavHostController) { diff --git a/app/src/main/java/com/example/dtf/screens/RegisterScreen.kt b/app/src/main/java/com/example/dtf/ui/screens/RegisterScreen.kt similarity index 88% rename from app/src/main/java/com/example/dtf/screens/RegisterScreen.kt rename to app/src/main/java/com/example/dtf/ui/screens/RegisterScreen.kt index 49dc1b6..1e5a077 100644 --- a/app/src/main/java/com/example/dtf/screens/RegisterScreen.kt +++ b/app/src/main/java/com/example/dtf/ui/screens/RegisterScreen.kt @@ -1,11 +1,15 @@ -package com.example.dtf.screens +package com.example.dtf.ui.screens -import android.graphics.drawable.shapes.Shape import androidx.compose.foundation.BorderStroke -import androidx.compose.foundation.background -import androidx.compose.foundation.border import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.* +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.AlertDialog import androidx.compose.material.Button @@ -16,22 +20,19 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember -import androidx.compose.ui.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.text.font.Font -import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.TextFieldValue -import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel -import androidx.navigation.NavController import androidx.navigation.NavHostController -import com.example.dtf.utils.ScreenPaths -import com.example.dtf.viewmodels.RegisterViewModel -import com.example.dtf.widgets.MyTextField +import com.example.dtf.ui.utils.ScreenPaths +import com.example.dtf.ui.viewmodels.RegisterViewModel +import com.example.dtf.ui.widgets.MyTextField @Composable fun RegisterScreen(navController: NavHostController) { diff --git a/app/src/main/java/com/example/dtf/ui/screens/TopPostsScreen.kt b/app/src/main/java/com/example/dtf/ui/screens/TopPostsScreen.kt new file mode 100644 index 0000000..64f973a --- /dev/null +++ b/app/src/main/java/com/example/dtf/ui/screens/TopPostsScreen.kt @@ -0,0 +1,279 @@ +package com.example.dtf.ui.screens + +import android.os.Build +import androidx.annotation.RequiresApi +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyRow +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll +import androidx.compose.material.Icon +import androidx.compose.material.Text +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.ThumbUp +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.MutableState +import androidx.compose.runtime.livedata.observeAsState +import androidx.compose.runtime.mutableIntStateOf +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.drawBehind +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.hilt.navigation.compose.hiltViewModel +import androidx.navigation.NavHostController +import androidx.paging.compose.LazyPagingItems +import androidx.paging.compose.collectAsLazyPagingItems +import androidx.paging.compose.itemKey +import com.example.dtf.PreferencesManager +import com.example.dtf.data.models.Category +import com.example.dtf.data.models.Post +import com.example.dtf.ui.utils.ScreenPaths +import com.example.dtf.ui.viewmodels.TopPostsViewModel +import java.time.LocalDate +import java.time.Period + + +@RequiresApi(Build.VERSION_CODES.O) +@Composable +fun TopPostsScreen(navController: NavHostController) { + val viewModel = hiltViewModel() + + val currentCategory = remember { mutableStateOf(null) } + val categories = viewModel.getCategoriesListUiState().collectAsLazyPagingItems() + val dateFrom = remember { mutableStateOf(LocalDate.now()) } + + Column( + modifier = Modifier + .fillMaxSize() + .verticalScroll(rememberScrollState()), + verticalArrangement = Arrangement.spacedBy(15.dp), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Spacer(modifier = Modifier.height(15.dp)) + Text( + text = "Топ 10 новостей", + fontSize = 36.sp + ) + DateSelect(viewModel, dateFrom, currentCategory) + Categories(viewModel, currentCategory, categories, dateFrom) + Posts(viewModel, navController) + Spacer(modifier = Modifier.height(60.dp)) + } +} + +@RequiresApi(Build.VERSION_CODES.O) +@Composable +fun DateSelect( + viewModel: TopPostsViewModel, + dateFrom: MutableState, + currentCategory: MutableState + ) { + val week = Pair(LocalDate.now() - Period.ofWeeks(1), "Неделя") + val month = Pair(LocalDate.now() - Period.ofMonths(1), "Месяц") + val year = Pair(LocalDate.now() - Period.ofYears(1), "Год") + + dateFrom.value = week.first + + Row( + modifier = Modifier + .fillMaxWidth() + .fillMaxHeight(0.1f) + .background(Color.White), + horizontalArrangement = Arrangement.spacedBy(25.dp), + verticalAlignment = Alignment.CenterVertically + ) { + Spacer(modifier = Modifier) + listOf(week, month, year).forEach { (date, name) -> + Text( + modifier = Modifier + .clickable { + dateFrom.value = date + if (currentCategory.value != null) { + viewModel.retrievePosts(currentCategory.value!!.id!!, dateFrom.value, LocalDate.now()) + } + } + .drawBehind { + if (dateFrom.value == date) { + val strokeWidthPx = 2.dp.toPx() + val verticalOffset = size.height + 2.sp.toPx() + drawLine( + color = Color(0xFF319CFF), + strokeWidth = strokeWidthPx, + start = Offset(0f, verticalOffset), + end = Offset(size.width, verticalOffset) + ) + } + }, + text = name, + fontSize = 22.sp + ) + } + } +} + +@RequiresApi(Build.VERSION_CODES.O) +@Composable +fun Categories( + viewModel: TopPostsViewModel, + currentCategory: MutableState, + categories: LazyPagingItems, + dateFrom: MutableState) { + LazyRow( + modifier = Modifier + .fillMaxWidth() + .fillMaxHeight(0.1f) + .background(Color.White), + horizontalArrangement = Arrangement.spacedBy(25.dp), + verticalAlignment = Alignment.CenterVertically + ) { + item { + Spacer(modifier = Modifier) + } + items( + count = categories.itemCount, + key = categories.itemKey() + ) { + if (currentCategory.value == null) { + currentCategory.value = categories[0] + viewModel.retrievePosts(currentCategory.value!!.id!!, dateFrom.value, LocalDate.now()) + } + Text( + modifier = Modifier + .clickable { + currentCategory.value = categories[it]!! + viewModel.retrievePosts( + currentCategory.value!!.id!!, + dateFrom.value, + LocalDate.now() + ) + } + .drawBehind { + if (categories[it]!!.name == currentCategory.value?.name) { + val strokeWidthPx = 2.dp.toPx() + val verticalOffset = size.height + 2.sp.toPx() + drawLine( + color = Color(0xFF319CFF), + strokeWidth = strokeWidthPx, + start = Offset(0f, verticalOffset), + end = Offset(size.width, verticalOffset) + ) + } + }, + text = categories[it]!!.name, + fontSize = 22.sp + ) + } + } +} + +@Composable +fun Posts(viewModel: TopPostsViewModel, navController: NavHostController) { + Column( + modifier = Modifier.fillMaxSize(), + verticalArrangement = Arrangement.spacedBy(10.dp) + ) { + for (post in viewModel.posts.observeAsState(listOf()).value) { + Post(viewModel, navController, post) + } + } +} + +@Composable +fun Post(viewModel: TopPostsViewModel, navController: NavHostController, post: Post) { + val sharedPref = PreferencesManager(LocalContext.current) + + val likes = remember { mutableIntStateOf(post.likes) } + val isLiked = remember { mutableStateOf(false) } + + LaunchedEffect(Unit) { + viewModel.isLiked(sharedPref, post.id!!).collect { + isLiked.value = it + } + } + + Column( + modifier = Modifier + .heightIn(min = 250.dp, max = 300.dp) + .fillMaxWidth() + .background(Color.White) + .clickable { + navController.navigate(ScreenPaths.Post.route.replace("{post}", post.id.toString())) + }, + verticalArrangement = Arrangement.spacedBy(5.dp), + horizontalAlignment = Alignment.Start + ) { + Text( + modifier = Modifier.padding(10.dp), + text = post.title, + fontSize = 26.sp + ) + Text( + modifier = Modifier + .fillMaxHeight(0.6f) + .padding(10.dp, 0.dp, 10.dp, 0.dp), + text = post.content, + fontSize = 20.sp, + overflow = TextOverflow.Ellipsis + ) + Row( + modifier = Modifier + .fillMaxWidth() + .padding(10.dp), + verticalAlignment = Alignment.Bottom, + horizontalArrangement = Arrangement.SpaceBetween + ) { + Text( + text = post.date, + fontSize = 14.sp, + color = Color(0xFFCECCCC) + ) + Row ( + modifier = Modifier + .fillMaxWidth(), + horizontalArrangement = Arrangement.End + ) { + Text( + text = likes.intValue.toString(), + fontSize = 16.sp, + color = Color.Green + ) + Icon( + modifier = Modifier + .padding(start = 8.dp) + .clickable { + if (isLiked.value) { + viewModel.unlikePost(sharedPref, post.id!!) + likes.intValue-- + } else { + viewModel.likePost(sharedPref, post.id!!) + likes.intValue++ + } + isLiked.value = !isLiked.value + }, + imageVector = Icons.Default.ThumbUp, + contentDescription = null, + tint = if (isLiked.value) { Color(40, 200, 40, 255) } else { + Color.Black} + ) + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/dtf/utils/ScreenPaths.kt b/app/src/main/java/com/example/dtf/ui/utils/ScreenPaths.kt similarity index 83% rename from app/src/main/java/com/example/dtf/utils/ScreenPaths.kt rename to app/src/main/java/com/example/dtf/ui/utils/ScreenPaths.kt index ea4c889..c8f67d3 100644 --- a/app/src/main/java/com/example/dtf/utils/ScreenPaths.kt +++ b/app/src/main/java/com/example/dtf/ui/utils/ScreenPaths.kt @@ -1,4 +1,4 @@ -package com.example.dtf.utils +package com.example.dtf.ui.utils sealed class ScreenPaths (val route: String){ object Auth: ScreenPaths("auth") @@ -6,6 +6,7 @@ sealed class ScreenPaths (val route: String){ object Register: ScreenPaths("auth/register") object Post: ScreenPaths("posts/{post}") object Posts: ScreenPaths("posts") + object TopPosts: ScreenPaths("posts/top") object NewPost: ScreenPaths("posts/new") object EditPost: ScreenPaths("posts/{post}/edit") object Profile: ScreenPaths("profile") diff --git a/app/src/main/java/com/example/dtf/viewmodels/EditPostViewModel.kt b/app/src/main/java/com/example/dtf/ui/viewmodels/EditPostViewModel.kt similarity index 91% rename from app/src/main/java/com/example/dtf/viewmodels/EditPostViewModel.kt rename to app/src/main/java/com/example/dtf/ui/viewmodels/EditPostViewModel.kt index 7b65e45..cd1f630 100644 --- a/app/src/main/java/com/example/dtf/viewmodels/EditPostViewModel.kt +++ b/app/src/main/java/com/example/dtf/ui/viewmodels/EditPostViewModel.kt @@ -1,12 +1,12 @@ -package com.example.dtf.viewmodels +package com.example.dtf.ui.viewmodels import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.example.dtf.PreferencesManager -import com.example.dtf.models.Post -import com.example.dtf.repositories.IPostRepository +import com.example.dtf.data.models.Post +import com.example.dtf.data.repositories.IPostRepository import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import javax.inject.Inject diff --git a/app/src/main/java/com/example/dtf/viewmodels/LoginViewModel.kt b/app/src/main/java/com/example/dtf/ui/viewmodels/LoginViewModel.kt similarity index 89% rename from app/src/main/java/com/example/dtf/viewmodels/LoginViewModel.kt rename to app/src/main/java/com/example/dtf/ui/viewmodels/LoginViewModel.kt index 9aeb8fa..1e18c2a 100644 --- a/app/src/main/java/com/example/dtf/viewmodels/LoginViewModel.kt +++ b/app/src/main/java/com/example/dtf/ui/viewmodels/LoginViewModel.kt @@ -1,13 +1,12 @@ -package com.example.dtf.viewmodels +package com.example.dtf.ui.viewmodels import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.example.dtf.PreferencesManager -import com.example.dtf.api.ServerService -import com.example.dtf.dto.Credentials -import com.example.dtf.repositories.IUserRepository +import com.example.dtf.data.api.ServerService +import com.example.dtf.data.dto.Credentials import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import javax.inject.Inject diff --git a/app/src/main/java/com/example/dtf/viewmodels/NewPostViewModel.kt b/app/src/main/java/com/example/dtf/ui/viewmodels/NewPostViewModel.kt similarity index 89% rename from app/src/main/java/com/example/dtf/viewmodels/NewPostViewModel.kt rename to app/src/main/java/com/example/dtf/ui/viewmodels/NewPostViewModel.kt index 1cb04a0..5ca168e 100644 --- a/app/src/main/java/com/example/dtf/viewmodels/NewPostViewModel.kt +++ b/app/src/main/java/com/example/dtf/ui/viewmodels/NewPostViewModel.kt @@ -1,13 +1,13 @@ -package com.example.dtf.viewmodels +package com.example.dtf.ui.viewmodels import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.example.dtf.PreferencesManager -import com.example.dtf.models.Post -import com.example.dtf.repositories.ICategoryRepository -import com.example.dtf.repositories.IPostRepository +import com.example.dtf.data.models.Post +import com.example.dtf.data.repositories.ICategoryRepository +import com.example.dtf.data.repositories.IPostRepository import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import java.util.Date diff --git a/app/src/main/java/com/example/dtf/viewmodels/PostViewModel.kt b/app/src/main/java/com/example/dtf/ui/viewmodels/PostViewModel.kt similarity index 86% rename from app/src/main/java/com/example/dtf/viewmodels/PostViewModel.kt rename to app/src/main/java/com/example/dtf/ui/viewmodels/PostViewModel.kt index 7dd0262..09ea5ec 100644 --- a/app/src/main/java/com/example/dtf/viewmodels/PostViewModel.kt +++ b/app/src/main/java/com/example/dtf/ui/viewmodels/PostViewModel.kt @@ -1,4 +1,4 @@ -package com.example.dtf.viewmodels +package com.example.dtf.ui.viewmodels import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData @@ -6,13 +6,13 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import androidx.paging.PagingData import com.example.dtf.PreferencesManager -import com.example.dtf.models.Comment -import com.example.dtf.models.Like -import com.example.dtf.models.Post -import com.example.dtf.repositories.ICommentRepository -import com.example.dtf.repositories.ILikeRepository -import com.example.dtf.repositories.IPostRepository -import com.example.dtf.repositories.IUserRepository +import com.example.dtf.data.models.Comment +import com.example.dtf.data.models.Like +import com.example.dtf.data.models.Post +import com.example.dtf.data.repositories.ICommentRepository +import com.example.dtf.data.repositories.ILikeRepository +import com.example.dtf.data.repositories.IPostRepository +import com.example.dtf.data.repositories.IUserRepository import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.launch diff --git a/app/src/main/java/com/example/dtf/viewmodels/PostsViewModel.kt b/app/src/main/java/com/example/dtf/ui/viewmodels/PostsViewModel.kt similarity index 82% rename from app/src/main/java/com/example/dtf/viewmodels/PostsViewModel.kt rename to app/src/main/java/com/example/dtf/ui/viewmodels/PostsViewModel.kt index 2839bf6..d312a72 100644 --- a/app/src/main/java/com/example/dtf/viewmodels/PostsViewModel.kt +++ b/app/src/main/java/com/example/dtf/ui/viewmodels/PostsViewModel.kt @@ -1,12 +1,12 @@ -package com.example.dtf.viewmodels +package com.example.dtf.ui.viewmodels import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.example.dtf.PreferencesManager -import com.example.dtf.models.Like -import com.example.dtf.repositories.ICategoryRepository -import com.example.dtf.repositories.ILikeRepository -import com.example.dtf.repositories.IPostRepository +import com.example.dtf.data.models.Like +import com.example.dtf.data.repositories.ICategoryRepository +import com.example.dtf.data.repositories.ILikeRepository +import com.example.dtf.data.repositories.IPostRepository import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import javax.inject.Inject @@ -47,7 +47,5 @@ class PostsViewModel @Inject constructor( fun getCategoriesListUiState() = categoryRepository.getAll() - fun getInitialCategory() = categoryRepository.getFirst() - fun getPostsListUiState(categoryId: Int) = postRepository.getByCategory(categoryId) } \ No newline at end of file diff --git a/app/src/main/java/com/example/dtf/viewmodels/ProfileViewModel.kt b/app/src/main/java/com/example/dtf/ui/viewmodels/ProfileViewModel.kt similarity index 78% rename from app/src/main/java/com/example/dtf/viewmodels/ProfileViewModel.kt rename to app/src/main/java/com/example/dtf/ui/viewmodels/ProfileViewModel.kt index 0b6b2bb..6bd5b74 100644 --- a/app/src/main/java/com/example/dtf/viewmodels/ProfileViewModel.kt +++ b/app/src/main/java/com/example/dtf/ui/viewmodels/ProfileViewModel.kt @@ -1,14 +1,12 @@ -package com.example.dtf.viewmodels +package com.example.dtf.ui.viewmodels import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope import com.example.dtf.PreferencesManager -import com.example.dtf.models.User -import com.example.dtf.repositories.offline.OfflineUserRepository +import com.example.dtf.data.models.User +import com.example.dtf.data.repositories.offline.OfflineUserRepository import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel diff --git a/app/src/main/java/com/example/dtf/viewmodels/RegisterViewModel.kt b/app/src/main/java/com/example/dtf/ui/viewmodels/RegisterViewModel.kt similarity index 87% rename from app/src/main/java/com/example/dtf/viewmodels/RegisterViewModel.kt rename to app/src/main/java/com/example/dtf/ui/viewmodels/RegisterViewModel.kt index 4cdfd7a..35d525e 100644 --- a/app/src/main/java/com/example/dtf/viewmodels/RegisterViewModel.kt +++ b/app/src/main/java/com/example/dtf/ui/viewmodels/RegisterViewModel.kt @@ -1,12 +1,11 @@ -package com.example.dtf.viewmodels +package com.example.dtf.ui.viewmodels import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.example.dtf.api.ServerService -import com.example.dtf.dto.Credentials -import com.example.dtf.repositories.offline.OfflineUserRepository +import com.example.dtf.data.api.ServerService +import com.example.dtf.data.dto.Credentials import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch import javax.inject.Inject diff --git a/app/src/main/java/com/example/dtf/ui/viewmodels/TopPostsViewModel.kt b/app/src/main/java/com/example/dtf/ui/viewmodels/TopPostsViewModel.kt new file mode 100644 index 0000000..af71488 --- /dev/null +++ b/app/src/main/java/com/example/dtf/ui/viewmodels/TopPostsViewModel.kt @@ -0,0 +1,63 @@ +package com.example.dtf.ui.viewmodels + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.example.dtf.PreferencesManager +import com.example.dtf.data.models.Like +import com.example.dtf.data.models.Post +import com.example.dtf.data.repositories.ICategoryRepository +import com.example.dtf.data.repositories.ILikeRepository +import com.example.dtf.data.repositories.IPostRepository +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.launch +import java.time.LocalDate +import javax.inject.Inject + +@HiltViewModel +class TopPostsViewModel @Inject constructor( + private val postRepository: IPostRepository, + private val categoryRepository: ICategoryRepository, + private val likeRepository: ILikeRepository +) : ViewModel() { + private val _posts = MutableLiveData>() + val posts: LiveData> + get() = _posts + + fun getCategoriesListUiState() = categoryRepository.getAll() + + fun retrievePosts(categoryId: Int, fromDate: LocalDate, toDate: LocalDate) { + viewModelScope.launch { + postRepository.getTopTen(categoryId, fromDate, toDate).collect { + _posts.value = it + } + } + } + + fun likePost(sharedPref: PreferencesManager, postId: Int) { + val userId = sharedPref.getData("userId", "-1").toInt() + + if (userId == -1) return + + viewModelScope.launch { + likeRepository.insert(Like(userId, postId)) + } + } + + fun unlikePost(sharedPref: PreferencesManager, postId: Int) { + val userId = sharedPref.getData("userId", "-1").toInt() + + if (userId == -1) return + + viewModelScope.launch { + likeRepository.delete(Like(userId, postId)) + } + } + + fun isLiked(sharedPref: PreferencesManager, postId: Int) + = likeRepository.isLikedByUser( + sharedPref.getData("userId", "-1").toInt(), + postId + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/example/dtf/widgets/BottomNavBar.kt b/app/src/main/java/com/example/dtf/ui/widgets/BottomNavBar.kt similarity index 78% rename from app/src/main/java/com/example/dtf/widgets/BottomNavBar.kt rename to app/src/main/java/com/example/dtf/ui/widgets/BottomNavBar.kt index 1735628..e5ece30 100644 --- a/app/src/main/java/com/example/dtf/widgets/BottomNavBar.kt +++ b/app/src/main/java/com/example/dtf/ui/widgets/BottomNavBar.kt @@ -1,9 +1,5 @@ -package com.example.dtf.widgets +package com.example.dtf.ui.widgets -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.size import androidx.compose.material.BottomNavigation @@ -14,27 +10,17 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Edit import androidx.compose.material.icons.filled.Home import androidx.compose.material.icons.filled.Person +import androidx.compose.material.icons.filled.Star import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.navigation.NavController import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp +import androidx.navigation.NavController import androidx.navigation.compose.currentBackStackEntryAsState import com.example.dtf.PreferencesManager -import com.example.dtf.db.AppDatabase -import com.example.dtf.models.User -import com.example.dtf.utils.ScreenPaths -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext +import com.example.dtf.ui.utils.ScreenPaths @Composable fun BottomNavBar(navController: NavController) { @@ -49,6 +35,7 @@ fun BottomNavBar(navController: NavController) { val currentRoute = navBackStackEntry?.destination?.route listOfNotNull( Triple(ScreenPaths.Posts.route, Icons.Default.Home, "Новости"), + Triple(ScreenPaths.TopPosts.route, Icons.Default.Star, "Топ"), if (sharedPref.getData("isModerator", "false").toBooleanStrict()) { Triple(ScreenPaths.NewPost.route, Icons.Default.Edit, "Создать") } else { null }, diff --git a/app/src/main/java/com/example/dtf/widgets/MyTextField.kt b/app/src/main/java/com/example/dtf/ui/widgets/MyTextField.kt similarity index 98% rename from app/src/main/java/com/example/dtf/widgets/MyTextField.kt rename to app/src/main/java/com/example/dtf/ui/widgets/MyTextField.kt index 1889b06..22cb3ea 100644 --- a/app/src/main/java/com/example/dtf/widgets/MyTextField.kt +++ b/app/src/main/java/com/example/dtf/ui/widgets/MyTextField.kt @@ -1,4 +1,4 @@ -package com.example.dtf.widgets +package com.example.dtf.ui.widgets import androidx.compose.foundation.background import androidx.compose.foundation.border