content
stringlengths
0
3.9M
path
stringlengths
4
242
contentHash
stringlengths
1
10
package com.example.animemoi_app.common.comic_reading 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.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowBack import androidx.compose.material3.Icon import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.navigation.NavHostController @Composable fun TitleDetailComic(title: String, navController: NavHostController) { Row( Modifier .background( Brush.verticalGradient( colors = listOf( Color.Gray, Color.Black.copy(0.6f), ) ) ) .padding(8.dp) .fillMaxWidth(), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(0.dp) ) { Icon(imageVector = Icons.Default.ArrowBack, contentDescription = null, tint = Color.White, modifier = Modifier.clickable { navController.popBackStack() }) Column( modifier = Modifier.padding(start = 8.dp) ) { Text( text = title, color = Color.White, fontSize = 16.sp, fontWeight = FontWeight.Bold, ) Text( text = "Chương 1124: Chiến đấu với thái thản cự nhân", color = Color.White, fontSize = 12.sp, maxLines = 1, overflow = TextOverflow.Clip ) } } }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/common/comic_reading/TitleReading.kt
3647425766
package com.example.animemoi_app.screen import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController import com.example.animemoi_app.R import com.example.animemoi_app.common.ComeBack import com.example.animemoi_app.data.User import com.example.animemoi_app.model.UserData import com.example.animemoi_app.screen.setting.LoginRegisterFrame import com.example.animemoi_app.screen.setting.PersonalInformation import com.example.animemoi_app.screen.setting.SettingAppFrame import com.example.animemoi_app.screen.setting.SettingSourceFrame @Composable fun SettingScreen(navController: NavHostController) { var loggedIn by remember{ mutableStateOf(false)} Column( modifier = Modifier.background(Color.Black) ) { ComeBack(title = "Cài đặt", navController) Column( modifier = Modifier.verticalScroll(rememberScrollState()) ) { if(loggedIn) PersonalInformation( user = User().loadUser()[1] ) else LoginRegisterFrame(navController) SettingSourceFrame(navController) SettingAppFrame() } } } @Preview(showBackground = true) @Composable fun SettingScreenPreview() { SettingScreen(navController = rememberNavController()) }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/SettingScreen.kt
2928300067
package com.example.animemoi_app.screen import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.navigation.NavHostController import com.example.animemoi_app.common.comic_reading.ImagesComicList import com.example.animemoi_app.common.comic_reading.NavDetailComic import com.example.animemoi_app.common.comic_reading.TitleDetailComic @Composable fun ReadingScreen(navController: NavHostController, title: String) { Column ( modifier = Modifier .fillMaxSize() .background(Color.Black) ){ Box ( modifier = Modifier .fillMaxHeight(0.9f) ){ ImagesComicList(navController= navController, title= title) TitleDetailComic(title, navController) } NavDetailComic() } }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/ReadingScreen.kt
1495307066
package com.example.animemoi_app.screen import androidx.compose.foundation.background 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.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import androidx.navigation.NavHostController import com.example.animemoi_app.common.Bar import com.example.animemoi_app.common.history.GridHistoryCard @Composable fun HistoryScreen( navController: NavHostController, selectedComic: (Int) -> Unit ) { Column( modifier = Modifier .fillMaxSize() .background(Color.Black) ) { Bar(navController = navController) Row( modifier = Modifier .padding(top = 15.dp) .fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, ) { Button( onClick = { /*TODO*/ }, colors = ButtonDefaults.buttonColors(Color.Transparent) ) { Text(text = "Hôm nay") } Button( onClick = { }, colors = ButtonDefaults.buttonColors(Color.Transparent) ) { Text(text = "Xoá tất cả", color = Color(0xFFFF6666)) } } GridHistoryCard(showStatus = true, showLastTimeUpdate = false, selectedComic = selectedComic) } }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/HistoryScreen.kt
571657474
package com.example.animemoi_app.screen import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add import androidx.compose.material3.Icon import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController import com.example.animemoi_app.R import com.example.animemoi_app.common.ComeBack import com.example.animemoi_app.data.SourceData import com.example.animemoi_app.model.SourceComic @Composable fun SourceComicScreen(navController: NavHostController) { val items = SourceData().loadSourceData() Box(modifier = Modifier.fillMaxSize().background(Color.Black)){ ComeBack(title = stringResource(id = R.string.select_source), navController = navController) LazyColumn( modifier = Modifier .padding(start = 12.dp, top = 60.dp, end = 12.dp), contentPadding = PaddingValues(16.dp) ) { items(items) { item -> Row( modifier = Modifier .fillMaxWidth() .padding(bottom = 8.dp), verticalAlignment = Alignment.CenterVertically, ) { Image( painterResource(id = item.icon), contentDescription = null, modifier = Modifier.size(50.dp) ) Spacer(modifier = Modifier.width(8.dp)) Text( text = item.name, modifier = Modifier.align(Alignment.CenterVertically), color = Color.White ) Box( modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.CenterEnd ) { Icon( Icons.Default.Add, contentDescription = null, tint = Color(0xFFFF6666) ) } } } } } } @Preview @Composable fun SourceComicScreenPreview() { SourceComicScreen(rememberNavController()) }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/SourceComicScreen.kt
3830604311
package com.example.animemoi_app.screen import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.tooling.preview.Preview import androidx.navigation.NavController import androidx.navigation.compose.rememberNavController import com.example.animemoi_app.common.ComeBack import com.example.animemoi_app.common.comic.ComicGrid @Composable fun MoreComicScreen( title: String, navController: NavController, selectedComic: (Int) -> Unit ) { Column( modifier = Modifier .fillMaxSize() .background(Color.Black) ) { ComeBack(title, navController) ComicGrid(selectedComic) } }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/MoreComicScreen.kt
1086810119
package com.example.animemoi_app.screen import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.material3.Icon import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController import com.example.animemoi_app.R import com.example.animemoi_app.common.ComeBack import com.example.animemoi_app.common.history.GridHistoryCard @Composable fun NotificationScreen( navController: NavHostController, selectedComic: (Int) -> Unit ) { val isLogin = true val systemNotification = true val systemNotificationContent = "Hệ thống thông báo dừng hệ thống để nâng cấp vào lúc 22:00 ngày 21/1/2024. Mong quý khách có một trải nghiệm thú vị với phiên bản mới" val systemNotificationTimeUpdate = "22:00 21/1/2024" if (!isLogin) { Column( modifier = Modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center, ) { ComeBack(title = "Thông báo", navController) Icon( painter = painterResource(id = R.drawable.bell), contentDescription = null, Modifier.size(60.dp) ) Spacer(modifier = Modifier.height(12.dp)) Text( "Bạn cần đăng nhập để nhận thông báo", fontSize = 18.0.sp, color = Color.White, ) } } else { Column ( modifier = Modifier .fillMaxSize() .background(Color.Black) ){ ComeBack(title = "Thông báo", navController) if (systemNotification) { Column(Modifier .padding(start = 12.dp, top = 48.dp, end = 0.dp, bottom = 0.dp) ) { Text( systemNotificationContent, color = Color.White, ) Text( systemNotificationTimeUpdate, fontStyle = FontStyle.Italic, fontWeight = FontWeight.Light, color = Color.White, ) } } Spacer(modifier = Modifier.height(8.dp)) GridHistoryCard(showStatus = false, showLastTimeUpdate = true, selectedComic = selectedComic) } } } @Preview @Composable fun NotificationScreenPreview() { val navController: NavHostController = rememberNavController() NotificationScreen(navController, selectedComic = {}) }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/NotificationScreen.kt
2393407006
package com.example.animemoi_app.screen import androidx.compose.foundation.Image 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.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.layout.size import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Comment import androidx.compose.material.icons.filled.MoreVert import androidx.compose.material.icons.filled.Send import androidx.compose.material.icons.filled.ThumbUp import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Text import androidx.compose.material3.TextFieldDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController import com.example.animemoi_app.R import com.example.animemoi_app.common.ComeBack @OptIn(ExperimentalMaterial3Api::class) @Composable fun CommentScreen(title: String, navController: NavHostController, modifier: Modifier = Modifier) { var commentValue by remember { mutableStateOf("") } Column( modifier = modifier .background(Color.Black) .fillMaxSize() ) { ComeBack(title = title, navController = navController) Card( modifier = Modifier .padding(12.dp) .fillMaxWidth() .fillMaxHeight(0.85f), colors = CardDefaults.cardColors(Color(0xFF444242)) ) { //titleRow Row ( modifier = Modifier .fillMaxWidth() .padding(10.dp, 10.dp, 10.dp, 0.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween ){ Text( text = "Bình luận nổi bật", color = Color.White, fontSize = 18.sp ) Text( text = "Tổng 100 bình luận", color = Color.White ) } //listComment LazyColumn{ items(10){ CommentItem() } } } //Comment TextBox Row( modifier = Modifier .fillMaxWidth() .padding(horizontal = 15.dp, vertical = 20.dp), verticalAlignment = Alignment.CenterVertically ) { Image( painter = painterResource(id = R.drawable.deba), contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier .size(40.dp) .clip(CircleShape) .background(Color.Red) ) OutlinedTextField( value = commentValue, onValueChange = { commentValue = it }, label = null, placeholder = { Text(text = "Viết gì đó", fontSize = 10.sp) }, colors = TextFieldDefaults.outlinedTextFieldColors( containerColor = Color.Black, focusedTextColor = Color.White, unfocusedTextColor = Color.White ), modifier = Modifier .padding(horizontal = 5.dp) .fillMaxWidth(0.9f) .height(45.dp), shape = RoundedCornerShape(30.dp), maxLines = 1, textStyle = TextStyle(fontSize = 10.sp) ) Icon( imageVector = Icons.Default.Send, contentDescription = null, tint = Color.White, modifier = Modifier.clickable { } ) } } } @Composable fun CommentItem() { Card( modifier = Modifier .padding(15.dp), colors = CardDefaults.cardColors(Color.Transparent) ) { Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(15.dp) ) { Image( painter = painterResource(id = R.drawable.deba), contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier .size(40.dp) .clip(CircleShape) .background(Color.Red) ) Column( verticalArrangement = Arrangement.spacedBy(5.dp) ) { Text( text = "Lê Tuấn Kha", color = Color.White, fontWeight = FontWeight.Bold ) Text( text = "Tập này hay quáaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", color = Color.White, fontWeight = FontWeight.Light, ) Row( modifier = Modifier .fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically ) { Text( text = "22 giờ trước", color = Color.White, fontWeight = FontWeight.Light ) Row( horizontalArrangement = Arrangement.spacedBy(10.dp), ) { Icon( imageVector = Icons.Default.MoreVert, contentDescription = null, tint = Color(0xFFC2C2C2) ) Icon( imageVector = Icons.Default.Comment, contentDescription = null, tint = Color(0xFFC2C2C2), modifier = Modifier.padding(end = 5.dp) ) Icon( imageVector = Icons.Default.ThumbUp, contentDescription = null, tint = Color(0xFFC2C2C2) ) } } } } } } @Preview(showSystemUi = true) @Composable fun CommentScreenPreview() { CommentScreen(title = "Chap 1: Cùng nhau nở hoa", navController = rememberNavController()) } @Preview @Composable fun CommentItemPreview() { CommentItem() }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/CommentScreen.kt
3668907693
package com.example.animemoi_app.screen import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.Image 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.fillMaxHeight import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.rounded.Clear import androidx.compose.material.icons.rounded.Visibility import androidx.compose.material.icons.rounded.VisibilityOff import androidx.compose.material3.Icon import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.material3.TextField import androidx.compose.material3.TextFieldDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.text.input.VisualTransformation import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController import com.example.animemoi_app.R import com.example.animemoi_app.common.ButtonCommon import com.example.animemoi_app.common.ComeBack import com.example.animemoi_app.data.User import com.example.animemoi_app.screen.setting.MessageDialog @Composable fun LoginScreen(navController: NavHostController) { var email by remember { mutableStateOf("") } var password by remember { mutableStateOf("") } var showMessage by remember { mutableStateOf(false) } val users = User().loadUser() Column( modifier = Modifier .background(Color.Black) ) { ComeBack(title = "AnimeMoi", navController) Column( verticalArrangement = Arrangement.Center, modifier = Modifier .padding(16.dp) .fillMaxHeight(0.8f) ) { TextFieldInput( "Email", Icons.Rounded.Clear, false, value = email ) { enterEmail -> email = enterEmail } TextFieldInput( "Mật khẩu", Icons.Rounded.VisibilityOff, true, value = password ) { enter -> password = enter } ButtonCommon( text = "Đăng nhập", onClick = { var isValid = false for (user in users) { if (user.email == email && user.password == password) { isValid = true navController.popBackStack() } } if (!isValid) { showMessage = true } }, modifier = Modifier .fillMaxWidth() .padding(0.dp, 8.dp) ) TextAction() Text( text = "Hoặc", color = Color.White, textAlign = TextAlign.Center, modifier = Modifier.fillMaxWidth() ) LoginChoose() } Column( modifier = Modifier.fillMaxHeight(), verticalArrangement = Arrangement.Bottom ) { Text( text = "Tiếp tục đồng nghĩa với việc bạn đã đọc và đồng ý với Điều khoản sử dụng và Thỏa thuận dịch vụ người dùng", color = Color(0xFFFF6666), textAlign = TextAlign.Center, fontSize = 12.sp, modifier = Modifier .padding(16.dp, 16.dp) ) Text( text = "Chức năng đăng nhập nhanh qua Google, Facebook, Github do Google, Facebook, Github cung cấp và bảo mật an toàn cho tài khoản của bạn", color = Color.White, fontSize = 8.sp, textAlign = TextAlign.Center, modifier = Modifier .padding(16.dp, 16.dp) ) } } if(showMessage) MessageDialog(message = "Sai email hoặc mật khẩu", onExitClick = {showMessage = false}) } @Composable fun LoginChoose() { Row( modifier = Modifier .padding(0.dp, 16.dp, 0.dp, 0.dp) ) { Image( painterResource(id = R.drawable.google), contentDescription = "Google", modifier = Modifier .fillMaxWidth(0.3f) .clickable { } ) Image( painterResource(id = R.drawable.facebook), contentDescription = "Facebook", modifier = Modifier .fillMaxWidth(0.6f) .clickable { } ) Image( painterResource(id = R.drawable.github), contentDescription = "Github", modifier = Modifier .fillMaxWidth() .clickable { } ) } } @Composable fun TextAction() { Row( modifier = Modifier .padding(0.dp, 16.dp) ) { Text( text = "Quên mật khẩu", color = Color(0xFFFF6666), textDecoration = TextDecoration.Underline, textAlign = TextAlign.Center, modifier = Modifier.fillMaxWidth(0.5f) ) Text( text = "Đăng kí tài khoản", color = Color(0xFFFF6666), textDecoration = TextDecoration.Underline, textAlign = TextAlign.Center, modifier = Modifier.fillMaxWidth() ) } } @Composable fun TextFieldInput( label: String, trailingIcon: ImageVector, password: Boolean, value: String, onValueChange: (String) -> Unit ) { var userInput by remember { mutableStateOf(value) } var pass by remember { mutableStateOf(password) } Surface( border = BorderStroke(1.dp, Color.Gray), shape = CircleShape, color = Color.Transparent, modifier = Modifier.padding(0.dp, 8.dp) ) { TextField( modifier = Modifier .fillMaxWidth(), value = userInput, onValueChange = { userInput = it onValueChange(it) }, placeholder = { Text( text = label, ) }, visualTransformation = if (pass) PasswordVisualTransformation() else VisualTransformation.None, shape = CircleShape, colors = TextFieldDefaults.colors( unfocusedTextColor = Color.White, focusedTextColor = Color.White, unfocusedContainerColor = Color.Transparent, focusedContainerColor = Color.Transparent, unfocusedIndicatorColor = Color.Transparent, focusedIndicatorColor = Color.Transparent, cursorColor = Color(0xFFFF6666) ), singleLine = true, trailingIcon = { if (userInput != "") { Icon( imageVector = if (password) { if (pass) Icons.Rounded.VisibilityOff else Icons.Rounded.Visibility } else trailingIcon, contentDescription = "", tint = Color(0xFFFF6666), modifier = Modifier .clickable { if (password) pass = !pass else userInput = "" } ) } } ) } } @Preview @Composable fun LoginPreview() { LoginScreen(navController = rememberNavController()) }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/LoginScreen.kt
1953716107
package com.example.animemoi_app.screen import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.navigation.NavHostController import com.example.animemoi_app.common.Bar import com.example.animemoi_app.common.ListSourceComic import com.example.animemoi_app.common.comic.ComicRow import com.example.animemoi_app.common.comic.ComicRowWithTitle @Composable fun HomeScreen( navController: NavHostController, selectedComic: (Int) -> Unit, ) { val sources = listOf("NetTruyen", "BaoTangTruyen", "Yurineko") Column( modifier = Modifier .background(Color.Black) ) { Bar(navController) ListSourceComic(sources) Column(Modifier.verticalScroll(rememberScrollState())) { ComicRow(selectedComic) ComicRowWithTitle(title = "Truyện mới đăng", navController = navController, selectedComic = selectedComic) ComicRowWithTitle(title = "Truyện hay", navController = navController, selectedComic = selectedComic) ComicRowWithTitle(title = "Truyện mới cập nhật", navController = navController, selectedComic = selectedComic) ComicRowWithTitle(title = "Truyện đầy đủ", navController = navController, selectedComic = selectedComic) } } }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/HomeScreen.kt
1559023339
package com.example.animemoi_app.screen import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.navigation.NavHostController import com.example.animemoi_app.common.comic_detail.ChapterListDetail import com.example.animemoi_app.common.comic_detail.InformationComicDetail import com.example.animemoi_app.common.comic_detail.NavComicDetail import com.example.animemoi_app.common.comic_detail.TitleDetail import com.example.animemoi_app.common.comic_detail.VoteComicDetail import com.example.animemoi_app.data.ComicRepo.getComic import com.example.animemoi_app.model.ComicTest @Composable fun DetailScreen( comicId: Int, navigateUp: () -> Unit, navController: NavHostController ) { val context = LocalContext.current val comic: ComicTest = remember(comicId) { getComic(comicId, context) } val titleComic = stringResource(id = comic.stringResourceId) Column( modifier = Modifier .fillMaxSize() .background(Color.Black) ) { TitleDetail(comic.imageResourceId, comic.stringResourceId, navigateUp) VoteComicDetail() NavComicDetail(titleComic, navController) Column( modifier = Modifier .fillMaxSize() .verticalScroll(rememberScrollState()) ) { InformationComicDetail() ChapterListDetail() } } }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/DetailComicScreen.kt
2464726179
package com.example.animemoi_app.screen import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.height import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import androidx.navigation.NavHostController import com.example.animemoi_app.common.ComeBack import com.example.animemoi_app.common.comic.ComicGrid @Composable fun SearchResultScreen( navController: NavHostController, selectedComic: (Int) -> Unit) { ComeBack(title = "Kết quả", navController) Spacer(modifier = Modifier.height(16.dp)) ComicGrid(selectedComic) }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/SearchResultScreen.kt
1967847935
package com.example.animemoi_app.screen 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.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.items import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Close import androidx.compose.material3.Divider import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.material3.TextField import androidx.compose.material3.TextFieldDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController import com.example.animemoi_app.common.* @OptIn(ExperimentalMaterial3Api::class) @Composable fun SearchScreen(navController: NavHostController) { var historyItems = remember { mutableStateListOf("Toàn chức pháp sư", "Tu tiên truyện", "Xuyên không về thời cổ đại") } Column( modifier = Modifier .fillMaxSize() .background(Color.Black) ) { Bar(navController = navController) Spacer(modifier = Modifier.padding(8.dp)) SearchBar() TextAndClear(onClearClick = {historyItems.clear()}) ListPreviousSearch(historyItems) ListSourceComic( listOf( "Nettruyen", "Bao Tang Truyen", "Tu Tiên Truyện", "Truyện xuyên Việt" ) ) CategorySearch( listOf( "Thể loại", "Thể loại", "Thể loại", "Thể loại", "Thể loại", "Thể loại", "Thể loại", "Thể loại", "Thể loại", "Thể loại", "Thể loại", "Thể loại" ) ) AuthorSearch() StatusComic(listOf("Tạm dừng", "Đang cập nhật", "Đã hoàn thành")) Row ( modifier = Modifier.fillMaxSize(), verticalAlignment = Alignment.Bottom ) { ButtonCommon( text = "Tìm kiếm", onClick = { /*TODO*/ }, modifier = Modifier .fillMaxWidth() .padding(16.dp) ) } } } @Composable fun StatusComic(listStatus: List<String>) { Row( verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(16.dp) ) { Text( text = "Tình trạng:", color = Color.White, fontSize = 14.sp, fontWeight = FontWeight.Medium ) LazyRow( horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.padding(8.dp, 0.dp) ) { items(listStatus) { status -> Status(status) } } } } @Composable fun Status(status: String) { var clickChoose by remember { mutableStateOf(false) } Surface( modifier = Modifier.clickable { clickChoose = !clickChoose }, shape = CircleShape, content = { Box( modifier = Modifier .background( if (clickChoose) Color(0xFFFF6666) else Color(0xFF999999) ) ) { Text( text = status, fontWeight = FontWeight.Normal, color = if (clickChoose) Color.White else Color.Black, fontSize = 12.sp, textAlign = TextAlign.Center, modifier = Modifier .padding(8.dp, 4.dp) ) } } ) } @Composable fun AuthorSearch() { var authorQuery by remember { mutableStateOf("") } Row( verticalAlignment = Alignment.CenterVertically, modifier = Modifier .padding(16.dp) ) { Text( text = "Tác giả: ", fontSize = 14.sp, color = Color.White, fontWeight = FontWeight.Medium, ) TextField( shape = CircleShape, value = authorQuery, onValueChange = { query -> authorQuery = query }, modifier = Modifier .fillMaxWidth(), colors = TextFieldDefaults.colors( cursorColor = Color.White, unfocusedContainerColor = Color.Black, focusedContainerColor = Color.Black, focusedTextColor = Color.White, unfocusedTextColor = Color.White, focusedIndicatorColor = Color(0xFFFF6666), ), trailingIcon = { if (authorQuery != "") { Icon( Icons.Default.Close, contentDescription = "Clear", tint = Color(0xFFFF6666), modifier = Modifier.clickable { authorQuery = "" }) } }, ) } } @Composable fun CategorySearch(categories: List<String>) { Text( text = "Tìm kiếm thể loại", fontSize = 14.sp, color = Color.White, fontWeight = FontWeight.Medium, modifier = Modifier .padding(16.dp, 16.dp, 16.dp, 0.dp) ) Box( modifier = Modifier .padding(16.dp, 8.dp) ) { Divider(color = Color(0xFF808080)) LazyVerticalGrid( GridCells.Adaptive(60.dp), verticalArrangement = Arrangement.spacedBy(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.padding(0.dp, 16.dp) ) { items(categories) { category -> // Your category item composable Category(category) } } } } @Composable fun Category(category: String) { var clickCount by remember { mutableIntStateOf(0) } Surface( shape = CircleShape, content = { Text( text = category, fontWeight = FontWeight.Normal, fontSize = 12.sp, color = when (clickCount) { 1, 2 -> Color.White else -> Color.Black }, textAlign = TextAlign.Center, modifier = Modifier .background( when (clickCount) { 1 -> Color(0xFF33CC66) 2 -> Color(0xFFFF6666) else -> Color(0xFF999999) } ) .clickable { clickCount++ if (clickCount == 3) clickCount = 0 } ) } ) } @Composable fun ListPreviousSearch(searchs: List<String>) { LazyRow( Modifier .padding(16.dp, 0.dp, 16.dp, 16.dp) .fillMaxWidth() .height(30.dp) ) { items(searchs.take(10)) { item -> PreviousSearch(search = item) } } } @Composable fun PreviousSearch(search: String) { Surface( onClick = {}, color = Color.Transparent, modifier = Modifier .padding(8.dp, 0.dp, 8.dp, 0.dp) .clickable { }, ) { Text( text = search, fontSize = 12.sp, color = Color(0xFF808080), fontWeight = FontWeight.Normal, ) } } @Composable fun TextAndClear(onClearClick: () -> Unit) { Box( modifier = Modifier .fillMaxWidth() .padding(16.dp) // Optional: Add padding for better spacing ) { Text( text = "Tìm kiếm trước đây", fontWeight = FontWeight.Medium, color = Color.White, fontSize = 14.sp, modifier = Modifier .align(Alignment.CenterStart) ) Text( text = "Xóa tất cả", fontWeight = FontWeight.Medium, color = Color(0xFFFF6666), textDecoration = TextDecoration.Underline, fontSize = 14.sp, modifier = Modifier .align(Alignment.CenterEnd) .clickable { onClearClick() } ) } } @Preview(showBackground = true) @Composable fun SearchScreenPreview() { SearchScreen(navController = rememberNavController()) }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/SearchScreen.kt
1160935630
package com.example.animemoi_app.screen.setting import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.KeyboardArrowUp import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.example.animemoi_app.R import com.example.animemoi_app.common.setting.Input import com.example.animemoi_app.common.setting.InputIcon import com.example.animemoi_app.common.setting.InputListChoose import com.example.animemoi_app.screen.setting.setting_app_frame.AmountComicFrame import com.example.animemoi_app.screen.setting.setting_app_frame.AnimemoiInforFrame import com.example.animemoi_app.screen.setting.setting_app_frame.PrivacyFrame import com.example.animemoi_app.screen.setting.setting_app_frame.ReadingModeFrame import com.example.animemoi_app.screen.setting.setting_app_frame.StorageManagermentFrame @Composable fun SettingAppFrame() { Box { Column( modifier = Modifier .padding(16.dp, 0.dp, 16.dp, 16.dp) .fillMaxWidth() .background(Color(0xFF4D4D4D), RoundedCornerShape(10.dp)) ) { Column( modifier = Modifier .padding(8.dp) .fillMaxWidth() ) { Text( text = "Cài đặt ứng dụng", fontSize = 16.sp, fontWeight = FontWeight.Medium, color = Color.White, modifier = Modifier.padding(0.dp, 0.dp, 8.dp, 0.dp) ) InputIcon(text = "Chọn màu nền", icon = painterResource(id = R.drawable.color)) InputListChoose( title = "Chọn ngôn ngữ", listChoose = "Tiếng việt", icon = Icons.Default.KeyboardArrowUp, background = true ) Input(text = "Ẩn lịch sử", true) Input(text = "Đồng bộ tiến trình", true) Input(text = "Khóa xoay", true) AmountComicFrame() ReadingModeFrame() StorageManagermentFrame() PrivacyFrame() AnimemoiInforFrame() } } } } @Preview(showBackground = true) @Composable fun Preview() { SettingAppFrame() }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/setting/SettingAppFrame.kt
2321897371
package com.example.animemoi_app.screen.setting import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.items import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.KeyboardArrowUp import androidx.compose.material.icons.filled.Menu import androidx.compose.material3.Divider import androidx.compose.material3.Icon import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.navigation.NavHostController import com.example.animemoi_app.R import com.example.animemoi_app.common.navigation.Screens import com.example.animemoi_app.common.setting.Input import com.example.animemoi_app.common.setting.TitleWithIcon import com.example.animemoi_app.model.SourceData @Composable fun ListSource() { val listSource = listOf( SourceData(painterResource(id = R.drawable.deba), "Nettruyen"), SourceData(painterResource(id = R.drawable.thegioihoanmy), "Tachiyomi"), SourceData(painterResource(id = R.drawable.requytroicho480197), "Tu tiên truyện") ) LazyVerticalGrid( GridCells.Fixed(1), contentPadding = PaddingValues(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.height(150.dp) ) { items(listSource) { source -> Source(source = source) } } } @Composable fun Source(source: SourceData) { Row( verticalAlignment = Alignment.CenterVertically ) { Image( painter = source.image, contentDescription = "Image", Modifier.size(40.dp) ) Text( text = source.name, color = Color.White, modifier = Modifier .padding(16.dp, 0.dp) .fillMaxWidth(0.9f) ) Icon( imageVector = Icons.Default.Menu, contentDescription = "Icon", tint = Color.White ) } } @Composable fun SettingSourceFrame(navController: NavHostController) { Box { Column( modifier = Modifier .padding(16.dp, 0.dp, 16.dp, 16.dp) .fillMaxWidth() .background( Color(0xFF4D4D4D), RoundedCornerShape(10.dp) ) ) { Column( modifier = Modifier .padding(8.dp) .fillMaxWidth() ) { Text( text = "Cài đặt nguồn truyện", fontSize = 16.sp, fontWeight = FontWeight.Medium, color = Color.White, modifier = Modifier.padding(end = 8.dp) ) Input(text = "NSFW", true) Column( modifier = Modifier .fillMaxWidth() .background(Color(0f, 0f, 0f, 0.5f), RoundedCornerShape(10.dp)) ) { TitleWithIcon( title = "Nguồn truyện của bạn", icon = Icons.Default.KeyboardArrowUp ) Box { Divider(color = Color(0xFF808080), modifier = Modifier.padding(8.dp)) } TitleWithIcon(title = "Thêm nguồn mới", icon = Icons.Default.Add, modifier = Modifier.clickable { navController.navigate(Screens.SourceComicScreen.name) }) ListSource() } } } } }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/setting/SettingSourceFrame.kt
37049402
package com.example.animemoi_app.screen.setting import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.VisibilityOff import androidx.compose.material3.AlertDialog import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.Icon import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.material3.TextField import androidx.compose.material3.TextFieldDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.text.input.VisualTransformation import androidx.compose.ui.text.style.TextAlign @Composable fun MessageDialog(message: String, onExitClick: () -> Unit) { AlertDialog( containerColor = Color(0xFFCCCCCC), text = { Text(text = message) }, onDismissRequest = { }, confirmButton = { TextButton( onClick = { onExitClick() }, colors = ButtonDefaults.buttonColors(Color(0xFFFF6666)) ) { Text("Đồng ý") } }, ) } @Composable fun EditDialog( initialUserName: String, onConfirmClick: (String, String, String) -> Unit, onExitClick: () -> Unit ) { var userName by remember { mutableStateOf(initialUserName) } var newPassword by remember { mutableStateOf("") } var newPassword2 by remember { mutableStateOf("") } var showPass1 by remember { mutableStateOf(false) } var showPass2 by remember { mutableStateOf(false) } AlertDialog( containerColor = Color(0xFFCCCCCC), onDismissRequest = { }, title = { Text( "Cập nhật thông tin", modifier = Modifier.fillMaxWidth(), textAlign = TextAlign.Center ) }, text = { Column { TextField( value = userName, onValueChange = { name -> userName = name }, label = { Text("Biệt danh") }, colors = TextFieldDefaults.colors( unfocusedContainerColor = Color(0xFFd9d9d9), focusedContainerColor = Color(0xFFd9d9d9), focusedIndicatorColor = Color(0xFFFF9999) ) ) TextField( value = newPassword, onValueChange = { password -> newPassword = password }, label = { Text("Mật khẩu mới") }, visualTransformation = if (showPass1) VisualTransformation.None else PasswordVisualTransformation(), colors = TextFieldDefaults.colors( unfocusedContainerColor = Color(0xFFd9d9d9), focusedContainerColor = Color(0xFFd9d9d9), focusedIndicatorColor = Color(0xFFFF9999) ), trailingIcon = { if (newPassword != "") Icon( Icons.Outlined.VisibilityOff, contentDescription = "", modifier = Modifier.clickable { showPass1 = !showPass1 } ) } ) TextField( value = newPassword2, onValueChange = { password -> newPassword2 = password }, label = { Text("Nhập lại mật khẩu mới") }, visualTransformation = if (showPass2) VisualTransformation.None else PasswordVisualTransformation(), colors = TextFieldDefaults.colors( unfocusedContainerColor = Color(0xFFd9d9d9), focusedContainerColor = Color(0xFFd9d9d9), focusedIndicatorColor = Color(0xFFFF9999) ), trailingIcon = { if (newPassword2 != "") Icon( Icons.Outlined.VisibilityOff, contentDescription = "", modifier = Modifier.clickable { showPass2 = !showPass2 } ) } ) } }, confirmButton = { Button( onClick = { onConfirmClick(userName, newPassword, newPassword2) }, colors = ButtonDefaults.buttonColors(Color(0xFFFF6666)) ) { Text("Đồng ý") } }, dismissButton = { Button( onClick = { onExitClick() }, colors = ButtonDefaults.buttonColors(Color(0xFFFF6666)) ) { Text("Thoát") } } ) }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/setting/Dialog.kt
3089669957
package com.example.animemoi_app.screen.setting.setting_app_frame 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.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.KeyboardArrowDown import androidx.compose.material.icons.filled.KeyboardArrowLeft import androidx.compose.material.icons.filled.KeyboardArrowRight import androidx.compose.material3.Divider import androidx.compose.material3.Icon import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.example.animemoi_app.common.setting.TitleWithIcon @Composable fun AmountComicFrame() { Column( modifier = Modifier .fillMaxWidth() .background(Color(0xFF4D4D4D), RoundedCornerShape(10.dp)) ) { Column( modifier = Modifier .fillMaxWidth() .background(Color(0f, 0f, 0f, 0.5f), RoundedCornerShape(10.dp)) ) { TitleWithIcon( title = "Số lượng truyện hiển thị", icon = Icons.Default.KeyboardArrowDown ) Box { Divider(color = Color(0xFF808080), modifier = Modifier.padding(8.dp)) } LayoutVerticalHorizontal("Chiều dọc", 2) LayoutVerticalHorizontal("Chiều ngang", 6) } } } @Composable fun LayoutVerticalHorizontal(title: String, amountDefault: Int){ var amount by remember { mutableIntStateOf(amountDefault) } amount = amount.coerceIn(1, 10) Row ( modifier = Modifier.padding(8.dp, 8.dp), verticalAlignment = Alignment.CenterVertically ) { Text( text = title, fontSize = 12.sp, color = Color.White, modifier = Modifier.fillMaxWidth(0.8f) ) Row ( horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth() ) { Icon( Icons.Default.KeyboardArrowLeft, contentDescription = "Icon", tint = Color.White, modifier = Modifier.clickable { amount-- } ) Text( text = amount.toString(), color = Color.White ) Icon( Icons.Default.KeyboardArrowRight, contentDescription = "Icon", tint = Color.White, modifier = Modifier.clickable { amount++ } ) } } }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/setting/setting_app_frame/AmountComicFrame.kt
3560473593
package com.example.animemoi_app.screen.setting.setting_app_frame import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.KeyboardArrowDown import androidx.compose.material3.Divider import androidx.compose.material3.Text import androidx.compose.material3.TextField import androidx.compose.material3.TextFieldDefaults import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.example.animemoi_app.common.setting.Input import com.example.animemoi_app.common.setting.TitleWithIcon @Composable fun PrivacyFrame() { Column( modifier = Modifier .padding(0.dp, 8.dp, 0.dp, 0.dp) .fillMaxWidth() .background(Color(0xFF4D4D4D), RoundedCornerShape(10.dp)) ) { Column( modifier = Modifier .fillMaxWidth() .background(Color(0f, 0f, 0f, 0.5f), RoundedCornerShape(10.dp)) ) { TitleWithIcon( title = "Bảo mật riêng tư", icon = Icons.Default.KeyboardArrowDown ) Box { Divider(color = Color(0xFF808080), modifier = Modifier.padding(8.dp)) } Input(text = "Bật/ Tắt", false) PasswordPrivacy() Clear() } } } @Composable fun Clear(){ Row ( modifier = Modifier .padding(8.dp, 8.dp), verticalAlignment = Alignment.Bottom ) { Text( text = "Xóa khóa bảo mật", color = Color(0xFFFF6666), fontSize = 12.sp, textDecoration = TextDecoration.Underline, modifier = Modifier.clickable { } ) Text( text = "Lưu ý sau khi xóa, dữ liệu thư viện sẽ mất toàn bộ", fontSize = 10.sp, color = Color.Gray, textAlign = TextAlign.Right, modifier = Modifier .fillMaxWidth() ) } } @Composable fun PasswordPrivacy() { val password = "password" Row ( modifier = Modifier .padding(8.dp, 0.dp), verticalAlignment = Alignment.CenterVertically ) { Text( text = "Mật khẩu bảo mật", color = Color.White, fontSize = 12.sp, ) TextField( value = password, onValueChange = {}, enabled = false, singleLine = true, visualTransformation = PasswordVisualTransformation(), colors = TextFieldDefaults.colors( disabledContainerColor = Color.Transparent, disabledIndicatorColor = Color.White, disabledTextColor = Color.White ) ) } }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/setting/setting_app_frame/PrivacyFrame.kt
3619033412
package com.example.animemoi_app.screen.setting.setting_app_frame import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.KeyboardArrowDown import androidx.compose.material.icons.filled.KeyboardArrowUp import androidx.compose.material3.Divider import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.example.animemoi_app.common.setting.InputListChoose import com.example.animemoi_app.common.setting.TitleWithIcon @Composable fun StorageManagermentFrame() { Column( modifier = Modifier .padding(0.dp, 8.dp, 0.dp, 0.dp) .fillMaxWidth() .background(Color(0xFF4D4D4D), RoundedCornerShape(10.dp)) ) { Column( modifier = Modifier .fillMaxWidth() .background(Color(0f, 0f, 0f, 0.5f), RoundedCornerShape(10.dp)) ) { TitleWithIcon( title = "Quản lí bộ nhớ", icon = Icons.Default.KeyboardArrowDown ) Box { Divider(color = Color(0xFF808080), modifier = Modifier.padding(8.dp)) } CleanStorage("Dung lượng truyện tải về", "1gb") InputListChoose( title = "Số lượng cache mong muốn", listChoose = "500mb", icon = Icons.Default.KeyboardArrowUp, false ) CleanStorage("Cache", "100mb") } } } @Composable fun CleanStorage(title: String, capacity: String) { Row ( modifier = Modifier .padding(8.dp, 8.dp) .fillMaxWidth(), ) { Text( text = title, color = Color.White, fontSize = 12.sp, modifier = Modifier.fillMaxWidth(0.5f) ) Text( text = capacity, color = Color.White, fontSize = 12.sp, modifier = Modifier.fillMaxWidth(0.5f) ) Text( text = "Làm sạch", textAlign = TextAlign.Right, textDecoration = TextDecoration.Underline, color = Color(0xFFFF6666), fontSize = 12.sp, modifier = Modifier .fillMaxWidth() .clickable { } ) } }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/setting/setting_app_frame/StorageManagementFrame.kt
2173770114
package com.example.animemoi_app.screen.setting.setting_app_frame 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.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.KeyboardArrowDown import androidx.compose.material.icons.filled.KeyboardArrowUp import androidx.compose.material3.Divider import androidx.compose.material3.RadioButton import androidx.compose.material3.RadioButtonDefaults import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.example.animemoi_app.common.setting.InputListChoose import com.example.animemoi_app.common.setting.TitleWithIcon @Composable fun ReadingModeFrame() { Column( modifier = Modifier .padding(0.dp, 8.dp, 0.dp, 0.dp) .fillMaxWidth() .background(Color(0xFF4D4D4D), RoundedCornerShape(10.dp)) ) { Column( modifier = Modifier .fillMaxWidth() .background(Color(0f, 0f, 0f, 0.5f), RoundedCornerShape(10.dp)) ) { TitleWithIcon( title = "Chế độ đọc", icon = Icons.Default.KeyboardArrowDown ) Box { Divider(color = Color(0xFF808080), modifier = Modifier.padding(8.dp)) } Mode("Chọn chiều đọc", "Chiều dọc", "Chiều ngang") InputListChoose( title = "Tự động lướt theo thời gian", listChoose = "Không bao giờ", icon = Icons.Default.KeyboardArrowUp, false ) Mode("Chọn chế dộ tải ảnh", "Toàn bộ", "Từng trang") } } } @Composable fun Mode(title: String, mode1: String, mode2: String) { var selectedMode by remember { mutableStateOf(mode1) } Row( modifier = Modifier.padding(8.dp, 0.dp), verticalAlignment = Alignment.CenterVertically ) { Text( text = title, fontSize = 12.sp, color = Color.White, modifier = Modifier.fillMaxWidth(0.4f) ) Row( verticalAlignment = Alignment.CenterVertically, modifier = Modifier .fillMaxWidth() ) { RadioOption( text = mode1, isSelected = selectedMode == mode1, onSelected = { selectedMode = mode1 } ) RadioOption( text = mode2, isSelected = selectedMode == mode2, onSelected = { selectedMode = mode2 } ) } } } @Composable fun RadioOption( text: String, isSelected: Boolean, onSelected: () -> Unit ) { Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Start, ) { RadioButton( selected = isSelected, onClick = onSelected, colors = RadioButtonDefaults.colors( selectedColor = Color(0xFFFF6666) ), modifier = Modifier .clickable { onSelected() } ) Text( text = text, fontSize = 10.sp, color = Color.White, ) } }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/setting/setting_app_frame/ReadingModeFrame.kt
2679189745
package com.example.animemoi_app.screen.setting.setting_app_frame import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.KeyboardArrowDown import androidx.compose.material3.Divider import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.example.animemoi_app.common.setting.TitleWithIcon @Composable fun AnimemoiInforFrame() { Column( modifier = Modifier .padding(0.dp, 8.dp, 0.dp, 0.dp) .fillMaxWidth() .background(Color(0xFF4D4D4D), RoundedCornerShape(10.dp)) ) { Column( modifier = Modifier .fillMaxWidth() .background(Color(0f, 0f, 0f, 0.5f), RoundedCornerShape(10.dp)) ) { TitleWithIcon( title = "Thông tin AnimeMoi", icon = Icons.Default.KeyboardArrowDown ) Box { Divider(color = Color(0xFF808080), modifier = Modifier.padding(8.dp)) } Column( modifier = Modifier .padding(8.dp) ) { Text( text = "Thông tin nhà phát triển", color = Color.White, fontSize = 12.sp ) Text( text = "Nguyễn Văn Hoàng - Nhà phát triển chính - [email protected]", color = Color.Gray, fontSize = 8.sp ) Text( text = "Lê Đức Tuấn Vũ - Nhà phát triển chính - [email protected]", color = Color.Gray, fontSize = 8.sp ) Text( text = "Lê Tuấn Kha - Nhà phát triển chính - [email protected]", color = Color.Gray, fontSize = 8.sp ) } Column( modifier = Modifier .padding(8.dp) ) { Text( text = "Bản quyền và giấy phép", color = Color.White, fontSize = 12.sp ) Text( text = "© 2024 AnimeMoi. Bảo lưu mọi quyền.", color = Color.Gray, fontSize = 8.sp ) } Column( modifier = Modifier .padding(8.dp) ) { Text( text = "Liên kết", color = Color.White, fontSize = 12.sp ) Text( text = "Trang chính thức: https://animemoireact.vercel.app/", color = Color.Gray, fontSize = 8.sp ) Text( text = "Repository Github: https://github.com/AnimeMoi", color = Color.Gray, fontSize = 8.sp ) } Text( text = "Xin chân thành cảm ơn tất cả những người đã đóng góp vào sự phát triển của ứng dụng!", color = Color.Gray, fontSize = 8.sp, modifier = Modifier.padding(8.dp) ) } } }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/setting/setting_app_frame/AnimemoiInforFrame.kt
3643056158
package com.example.animemoi_app.screen.setting import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.navigation.NavHostController import com.example.animemoi_app.R import com.example.animemoi_app.common.ButtonCommon @Composable fun LoginRegisterFrame(navController: NavHostController) { Box { Column( modifier = Modifier .padding(16.dp, 0.dp, 16.dp, 16.dp) .fillMaxWidth() .background(Color(0xFF4D4D4D), RoundedCornerShape(10.dp)) ) { Column( modifier = Modifier .padding(16.dp) .fillMaxWidth() ) { Text( text = "Bạn cần đăng nhập để quản lí thông tin cũng như sử dụng những tính nằng đặc biệt của ứng dụng", textAlign = TextAlign.Center, color = Color.White, modifier = Modifier.fillMaxWidth() ) Row( modifier = Modifier .fillMaxWidth() .padding(0.dp, 16.dp, 0.dp, 0.dp) ) { Column( modifier = Modifier.fillMaxWidth(0.5f), horizontalAlignment = Alignment.CenterHorizontally ) { ButtonCommon( text = "Đăng nhập", onClick = { navController.navigate("LoginScreen") }, modifier = Modifier ) } Column( modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally ) { ButtonCommon( text = "Đăng kí", onClick = { navController.navigate("RegisterScreen") }, ) } } Text( text = "Hoặc đăng nhập bằng", textAlign = TextAlign.Center, color = Color.White, modifier = Modifier .padding(0.dp, 16.dp, 0.dp, 0.dp) .fillMaxWidth() ) Row( modifier = Modifier.padding(0.dp, 16.dp, 0.dp, 0.dp) ) { Image(painterResource(id = R.drawable.google), contentDescription = "Google", modifier = Modifier .fillMaxWidth(0.3f) .clickable { }) Image(painterResource(id = R.drawable.facebook), contentDescription = "Facebook", modifier = Modifier .fillMaxWidth(0.6f) .clickable { }) Image(painterResource(id = R.drawable.github), contentDescription = "Github", modifier = Modifier .fillMaxWidth() .clickable { }) } } } } }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/setting/LoginRegisterFrame.kt
1167178419
package com.example.animemoi_app.screen.setting import androidx.compose.foundation.Image 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.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Edit import androidx.compose.material.icons.filled.Logout import androidx.compose.material.icons.outlined.Visibility import androidx.compose.material.icons.outlined.VisibilityOff import androidx.compose.material3.Icon import androidx.compose.material3.Text import androidx.compose.material3.TextField import androidx.compose.material3.TextFieldDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.RectangleShape import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.text.input.VisualTransformation import androidx.compose.ui.unit.dp import com.example.animemoi_app.common.ButtonCommon import com.example.animemoi_app.model.UserData @Composable fun PersonalInformation(user: UserData) { var showPassword by remember { mutableStateOf(false) } var isEditing by remember { mutableStateOf(false) } var messageVisible by remember { mutableStateOf(false) } var message by remember { mutableStateOf("") } Box { Column( modifier = Modifier .padding(16.dp) .fillMaxWidth() .background(Color(0xFF4D4D4D), RoundedCornerShape(10.dp)) ) { Icon( Icons.Default.Edit, contentDescription = "", modifier = Modifier .padding(0.dp, 16.dp, 16.dp, 0.dp) .size(20.dp) .align(Alignment.End) .border(1.dp, Color(0xffff6666), RoundedCornerShape(5.dp)) .clickable { isEditing = !isEditing }, tint = Color(0xFFFF6666) ) Row( modifier = Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically, ) { Column( modifier = Modifier.fillMaxWidth(0.3f), horizontalAlignment = Alignment.CenterHorizontally ) { Image( painter = user.image, contentDescription = "", contentScale = ContentScale.Crop, modifier = Modifier .clip(CircleShape) .height(72.dp) ) } Column( modifier = Modifier .padding(8.dp, 0.dp, 16.dp, 0.dp) .fillMaxWidth() ) { Row { Column { Text( text = "Biệt danh: ", color = Color.White ) Text( text = "Mật khẩu: ", color = Color.White, modifier = Modifier.padding(0.dp, 16.dp, 0.dp, 0.dp) ) } Column( modifier = Modifier.fillMaxWidth(0.9f), ) { Text( text = user.name, color = Color.White, modifier = Modifier.padding(16.dp, 0.dp, 0.dp, 0.dp) ) TextField( shape = RectangleShape, value = user.password, onValueChange = {}, readOnly = true, enabled = false, colors = TextFieldDefaults.colors( disabledContainerColor = Color(0xFF4D4D4D), disabledTextColor = Color.White, disabledIndicatorColor = Color.Transparent ), visualTransformation = if (showPassword) VisualTransformation.None else PasswordVisualTransformation(), ) } Column( verticalArrangement = Arrangement.Center ) { Text(text = "") Text(text = "") Icon( if (showPassword) Icons.Outlined.Visibility else Icons.Outlined.VisibilityOff, contentDescription = "", modifier = Modifier.clickable { showPassword = !showPassword }, tint = Color(0xFFFF6666) ) } } } } Row( modifier = Modifier .fillMaxWidth() .padding(8.dp, 16.dp, 8.dp, 8.dp) ) { Column( modifier = Modifier.fillMaxWidth(0.5f), horizontalAlignment = Alignment.Start ) { ButtonCommon( text = "Xóa tài khoản", onClick = { /*TODO*/ }, modifier = Modifier ) } Column( modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.End ) { ButtonCommon( text = "Đăng xuất", onClick = { /*TODO*/ }, iconButton = Icons.Default.Logout ) } } } if (isEditing) { EditDialog(initialUserName = user.name, onConfirmClick = { updateName, updatePassword, updatePassword2 -> when { updateName != "" && updateName != user.name && updatePassword != "" && updatePassword == updatePassword2 && updatePassword != user.password -> { user.name = updateName user.password = updatePassword messageVisible = true message = "Cập nhật thành công" } updateName != "" && updateName != user.name -> { user.name = updateName messageVisible = true message = "Đã cập nhật biệt danh" } updatePassword != "" && updatePassword == updatePassword2 && updatePassword != user.password -> { user.password = updatePassword messageVisible = true message = "Đã cập nhật mật khẩu mới" } else -> { messageVisible = true message = "Cập nhật thất bại" } } isEditing = false }, onExitClick = { isEditing = false }) } if (messageVisible) { MessageDialog(message = message, onExitClick = { messageVisible = false }) } } }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/setting/PersonalIformationFrame.kt
3711283303
package com.example.animemoi_app.screen import androidx.compose.foundation.background 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.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.MoreHoriz import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import androidx.navigation.NavHostController import com.example.animemoi_app.common.* import com.example.animemoi_app.common.category_card.GridComic @OptIn(ExperimentalMaterial3Api::class) @Composable fun CategoryScreen( navController: NavHostController, selectedComic: (Int) -> Unit ){ Column( modifier = Modifier .fillMaxSize() .background(Color.Black) ) { val sources = listOf("Thiếu nhi", "Truyện tranh", "Trinh thám") Bar(navController) Box(modifier = Modifier.padding(top = 10.dp)) { SearchBar() } Row( modifier = Modifier .fillMaxWidth() .padding(top = 10.dp), horizontalArrangement = Arrangement.SpaceBetween, ) { ButtonCommon( modifier = Modifier.padding(start = 16.dp), backgroundColor = Color(0xFF33CC00), iconButton = Icons.Default.Add, onClick = {}, text = "Bộ sưu tập" ) Button( onClick = { /*TODO*/ }, colors = ButtonDefaults.buttonColors(Color.Transparent) ) { Icon( imageVector = Icons.Default.MoreHoriz, contentDescription = "Xem thêm" ) } } Box( modifier = Modifier .padding(top = 5.dp, bottom = 25.dp) ) { ListSourceComic(sources = sources) } Box { GridComic( modifier = Modifier, selectedComic = selectedComic ) } } }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/CategoryScreen.kt
3530850125
package com.example.animemoi_app.screen import androidx.compose.foundation.background 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.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material.icons.Icons import androidx.compose.material.icons.rounded.Clear import androidx.compose.material.icons.rounded.VisibilityOff import androidx.compose.material3.Checkbox import androidx.compose.material3.CheckboxDefaults import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController import com.example.animemoi_app.common.ButtonCommon import com.example.animemoi_app.common.ComeBack @Composable fun RegisterScreen(navController: NavHostController) { var name by remember { mutableStateOf("") } var email by remember { mutableStateOf("") } var password by remember { mutableStateOf("") } var confirmPassword by remember { mutableStateOf("") } Column( modifier = Modifier .background(Color.Black) ) { ComeBack(title = "AnimeMoi", navController) Column( verticalArrangement = Arrangement.Center, modifier = Modifier .padding(16.dp) .fillMaxHeight(0.9f) ) { TextFieldInput( "Biệt danh", Icons.Rounded.Clear, false, value = name ) { enter -> name = enter } TextFieldInput( "Email", Icons.Rounded.Clear, false, value = email ) { enter -> email = enter } TextFieldInput( "Mật khẩu", Icons.Rounded.VisibilityOff, true, value = password ) { enter -> password = enter } TextFieldInput( "Nhập lại mật khẩu", Icons.Rounded.VisibilityOff, true, value = confirmPassword ) { enter -> confirmPassword = enter } ButtonCommon( text = "Đăng kí", onClick = { /*TODO*/ }, modifier = Modifier .fillMaxWidth() .padding(0.dp, 8.dp) ) CheckAccept() Text( text = "Hoặc đăng nhập", color = Color.White, textAlign = TextAlign.Center, modifier = Modifier.fillMaxWidth() ) LoginChoose() } Column( modifier = Modifier.fillMaxHeight(), verticalArrangement = Arrangement.Bottom ) { Text( text = "Chức năng đăng nhập nhanh qua Google, Facebook, Github do Google, Facebook, Github cung cấp và bảo mật an toàn cho tài khoản của bạn", color = Color.White, fontSize = 8.sp, textAlign = TextAlign.Center, modifier = Modifier .padding(16.dp, 16.dp) ) } } } @Composable fun CheckAccept() { var checked by remember { mutableStateOf(false)} Row( modifier = Modifier .padding(16.dp) .fillMaxWidth(), horizontalArrangement = Arrangement.Center ) { Checkbox( checked = checked , onCheckedChange = {checked = !checked}, colors = CheckboxDefaults.colors( checkedColor = Color(0xFFFF6666), ) ) Text( text = "Điều khoản sử dụng", color = Color(0xFFFF6666), fontSize = 12.sp, textAlign = TextAlign.Center, modifier = Modifier .padding(16.dp, 16.dp) ) } } @Preview @Composable fun RegisterPreview(){ RegisterScreen(navController = rememberNavController()) }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/screen/RegisterScreen.kt
4228649647
package com.example.animemoi_app.model import androidx.compose.ui.graphics.painter.Painter data class UserData(val userId: Int, val email:String, var name: String, var password: String, val image: Painter )
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/model/UserData.kt
3807386483
package com.example.animemoi_app.model import androidx.annotation.DrawableRes import androidx.annotation.StringRes data class ComicTest( val comicId : Int, @StringRes val stringResourceId: Int, @DrawableRes val imageResourceId: Int, @StringRes val categoryResourceId: Int, @StringRes val status: Int, val lastChapter: String, val timeUpdate: String? )
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/model/ComicTest.kt
3489685528
package com.example.animemoi_app.model import androidx.annotation.DrawableRes import androidx.annotation.StringRes data class Comic( val comicId : Int, @StringRes val stringResourceId: Int, @DrawableRes val imageResourceId: Int, @StringRes val categoryResourceId: Int, @StringRes val status: Int, val lastChapter: String, val timeUpdate: String? )
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/model/Comic.kt
8056554
package com.example.animemoi_app.model import androidx.compose.ui.graphics.painter.Painter data class SourceData(val image: Painter, var name: String)
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/model/SourceData.kt
2013342919
package com.example.animemoi_app.model import androidx.annotation.StringRes data class Category( @StringRes val stringResourceId: Int, )
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/model/Category.kt
2662596542
package com.example.animemoi_app.model import androidx.annotation.DrawableRes import androidx.annotation.StringRes data class ComicDetail( @DrawableRes val imageResourceId: Int, )
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/model/ComicDetail.kt
870742962
package com.example.animemoi_app.model data class UserResponse(val user: String){ }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/model/UserResponse.kt
241747095
package com.example.animemoi_app.model enum class ModeReader { Vertical, Horizontal }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/model/ModeReader.kt
1365838581
package com.example.animemoi_app.model import androidx.annotation.DrawableRes import com.example.animemoi_app.R data class SourceComic( @DrawableRes val icon: Int = R.drawable.hentaivn, val name: String, val label: String, val nsfw: Boolean )
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/model/SourceComic.kt
36269111
package com.example.animemoi_app.model data class MoreComicScreenArgs(val title: String)
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/model/MoreComicScreenArgs.kt
897137159
package com.example.animemoi_app.fetchapi class CallComic { }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/fetchapi/CallComic.kt
1472237011
package com.example.animemoi_app.data import com.example.animemoi_app.R import com.example.animemoi_app.model.SourceComic class SourceData { fun loadSourceData(): List<SourceComic> { return listOf( SourceComic( icon = R.drawable.nettruyen, name = "NetTruyen", label = "nettruyen", nsfw = false ), SourceComic( name = "Bảo Tàng Truyện", label = "BaoTangTruyen", nsfw = false ), SourceComic( icon = R.drawable.hentaivn, name = "HentaiVn", label = "HentaiVn", nsfw = true ), SourceComic( name = "Lxmanga", label = "Lxmanga", nsfw = true ), SourceComic( icon = R.drawable.sayhentai, name = "SayHentai", label = "SayHentai", nsfw = true ), SourceComic( name = "YuriNeko", label = "YuriNeko", nsfw = false ) ) } }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/data/SourceData.kt
433556246
package com.example.animemoi_app.data import com.example.animemoi_app.R import com.example.animemoi_app.model.Category import com.example.animemoi_app.model.ComicDetail class ComicDetailData { fun loadComicDetail() : List<ComicDetail>{ return listOf<ComicDetail>( ComicDetail(R.drawable.img002), ComicDetail(R.drawable.img003), ComicDetail(R.drawable.img004), ComicDetail(R.drawable.img005), ComicDetail(R.drawable.img006), ComicDetail(R.drawable.img007), ) } }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/data/ComicDetailData.kt
2233806256
package com.example.animemoi_app.data import com.example.animemoi_app.R import com.example.animemoi_app.model.Comic class ComicData { fun loadComicCard(): List<Comic> { return listOf( Comic( 1, R.string.cm01, R.drawable.huongdanchamsoctieuzombie, R.string.trtr, R.string.st01, "234", "22:00 12/1/2024" ), Comic( 2, R.string.cm02, R.drawable.thancaodanton606028, R.string.tth, R.string.st01, "214", "22:00 12/1/2024" ), Comic( 3, R.string.cm03, R.drawable.linhvuthienha, R.string.thieunhi, R.string.st02, "2123", "22:00 12/1/2024" ), Comic( 4, R.string.cm04, R.drawable.truyendauphathuongkhung, R.string.trtr, R.string.st02, "234", "22:00 12/1/2024" ), Comic( 5, R.string.cm05, R.drawable.mevokhongloive982891, R.string.thieunhi, R.string.st02, "234", "22:00 12/1/2024" ), Comic( 6, R.string.cm06, R.drawable.thegioihoanmy, R.string.trtr, R.string.st01, "234", "22:00 12/1/2024" ), Comic( 7, R.string.cm07, R.drawable.phamnhantutien, R.string.thieunhi, R.string.st01, "234", "22:00 12/1/2024" ), Comic( 8, R.string.cm08, R.drawable.tiennghich, R.string.trtr, R.string.st01, "234", "22:00 12/1/2024" ), Comic( 9, R.string.cm09, R.drawable.deba, R.string.thieunhi, R.string.st03, "234", "22:00 12/1/2024" ), Comic( 10, R.string.cm10, R.drawable.tiennghich, R.string.thieunhi, R.string.st03, "234", "22:00 12/1/2024" ), Comic( 11, R.string.cm11, R.drawable.requytroicho480197, R.string.trtr, R.string.st03, "234", "22:00 12/1/2024" ), ) } }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/data/ComicData.kt
701579348
package com.example.animemoi_app.data import androidx.compose.runtime.Composable import androidx.compose.ui.res.painterResource import com.example.animemoi_app.R import com.example.animemoi_app.model.UserData class User { @Composable fun loadUser(): List<UserData> { return listOf( UserData( 1, "[email protected]", "Tuấn Kha", "TuanKha", painterResource(id = R.drawable.deba) ), UserData( 2, "[email protected]", "Wibu", "VanHoang", painterResource(id = R.drawable.deba) ), UserData( 3, "[email protected]", "Tuấn Vũ", "TuanVu", painterResource(id = R.drawable.deba) ) ) } }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/data/User.kt
3248345999
package com.example.animemoi_app.data import android.content.Context import com.example.animemoi_app.R import com.example.animemoi_app.model.ComicTest object ComicRepo { fun getComic( comicId:Int, context: Context ): ComicTest = getComicsList(context).find{ it.comicId == comicId }!! fun getComicsList(context: Context) = listOf( ComicTest( 1, R.string.cm01, R.drawable.huongdanchamsoctieuzombie, R.string.trtr, R.string.st01, "234", "22:00 12/1/2024" ), ComicTest( 2, R.string.cm02, R.drawable.thancaodanton606028, R.string.tth, R.string.st01, "214", "22:00 12/1/2024" ), ComicTest( 3, R.string.cm03, R.drawable.linhvuthienha, R.string.thieunhi, R.string.st02, "2123", "22:00 12/1/2024" ), ComicTest( 4, R.string.cm04, R.drawable.truyendauphathuongkhung, R.string.trtr, R.string.st02, "234", "22:00 12/1/2024" ), ComicTest( 5, R.string.cm05, R.drawable.mevokhongloive982891, R.string.thieunhi, R.string.st02, "234", "22:00 12/1/2024" ), ComicTest( 6, R.string.cm06, R.drawable.thegioihoanmy, R.string.trtr, R.string.st01, "234", "22:00 12/1/2024" ), ComicTest( 7, R.string.cm07, R.drawable.phamnhantutien, R.string.thieunhi, R.string.st01, "234", "22:00 12/1/2024" ), ComicTest( 8, R.string.cm08, R.drawable.tiennghich, R.string.trtr, R.string.st01, "234", "22:00 12/1/2024" ), ComicTest( 9, R.string.cm09, R.drawable.deba, R.string.thieunhi, R.string.st03, "234", "22:00 12/1/2024" ), ComicTest( 10, R.string.cm10, R.drawable.tiennghich, R.string.thieunhi, R.string.st03, "234", "22:00 12/1/2024" ), ComicTest( 11, R.string.cm11, R.drawable.requytroicho480197, R.string.trtr, R.string.st03, "234", "22:00 12/1/2024" ), ) }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/data/ComicRepo.kt
1412115720
package com.example.animemoi_app.data import com.example.animemoi_app.R import com.example.animemoi_app.model.Category import com.example.animemoi_app.model.Comic class CategoryData { fun loadCategory() : List<Category>{ return listOf<Category>( Category(R.string.thieunhi), Category(R.string.anime), Category(R.string.trtr), Category(R.string.tth), ) } }
AnimeMoiApp/app/src/main/java/com/example/animemoi_app/data/CategoryData.kt
2868223679
package org.d3if3011.aplikasipelajaran import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 import org.junit.Test import org.junit.runner.RunWith import org.junit.Assert.* /** * Instrumented test, which will execute on an Android device. * * See [testing documentation](http://d.android.com/tools/testing). */ @RunWith(AndroidJUnit4::class) class ExampleInstrumentedTest { @Test fun useAppContext() { // Context of the app under test. val appContext = InstrumentationRegistry.getInstrumentation().targetContext assertEquals("org.d3if3011.aplikasipelajaran", appContext.packageName) } }
AplikasiPelajaran/app/src/androidTest/java/org/d3if3011/aplikasipelajaran/ExampleInstrumentedTest.kt
2816163253
package org.d3if3011.aplikasipelajaran import org.junit.Test import org.junit.Assert.* /** * Example local unit test, which will execute on the development machine (host). * * See [testing documentation](http://d.android.com/tools/testing). */ class ExampleUnitTest { @Test fun addition_isCorrect() { assertEquals(4, 2 + 2) } }
AplikasiPelajaran/app/src/test/java/org/d3if3011/aplikasipelajaran/ExampleUnitTest.kt
3823747772
package org.d3if3011.aplikasipelajaran.ui.theme import androidx.compose.ui.graphics.Color val Purple80 = Color(0xFFD0BCFF) val PurpleGrey80 = Color(0xFFCCC2DC) val Pink80 = Color(0xFFEFB8C8) val Purple40 = Color(0xFF6650a4) val PurpleGrey40 = Color(0xFF625b71) val Pink40 = Color(0xFF7D5260)
AplikasiPelajaran/app/src/main/java/org/d3if3011/aplikasipelajaran/ui/theme/Color.kt
711501477
package org.d3if3011.aplikasipelajaran.ui.theme import android.app.Activity import android.os.Build import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material3.MaterialTheme import androidx.compose.material3.darkColorScheme import androidx.compose.material3.dynamicDarkColorScheme import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable import androidx.compose.runtime.SideEffect import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalView import androidx.core.view.WindowCompat private val DarkColorScheme = darkColorScheme( primary = Purple80, secondary = PurpleGrey80, tertiary = Pink80 ) private val LightColorScheme = lightColorScheme( primary = Purple40, secondary = PurpleGrey40, tertiary = Pink40 /* Other default colors to override background = Color(0xFFFFFBFE), surface = Color(0xFFFFFBFE), onPrimary = Color.White, onSecondary = Color.White, onTertiary = Color.White, onBackground = Color(0xFF1C1B1F), onSurface = Color(0xFF1C1B1F), */ ) @Composable fun AplikasiPelajaranTheme( darkTheme: Boolean = isSystemInDarkTheme(), // Dynamic color is available on Android 12+ dynamicColor: Boolean = true, content: @Composable () -> Unit ) { val colorScheme = when { dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { val context = LocalContext.current if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) } darkTheme -> DarkColorScheme else -> LightColorScheme } val view = LocalView.current if (!view.isInEditMode) { SideEffect { val window = (view.context as Activity).window window.statusBarColor = colorScheme.primary.toArgb() WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme } } MaterialTheme( colorScheme = colorScheme, typography = Typography, content = content ) }
AplikasiPelajaran/app/src/main/java/org/d3if3011/aplikasipelajaran/ui/theme/Theme.kt
3045116639
package org.d3if3011.aplikasipelajaran.ui.theme import androidx.compose.material3.Typography import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.sp // Set of Material typography styles to start with val Typography = Typography( bodyLarge = TextStyle( fontFamily = FontFamily.Default, fontWeight = FontWeight.Normal, fontSize = 16.sp, lineHeight = 24.sp, letterSpacing = 0.5.sp ) /* Other default text styles to override titleLarge = TextStyle( fontFamily = FontFamily.Default, fontWeight = FontWeight.Normal, fontSize = 22.sp, lineHeight = 28.sp, letterSpacing = 0.sp ), labelSmall = TextStyle( fontFamily = FontFamily.Default, fontWeight = FontWeight.Medium, fontSize = 11.sp, lineHeight = 16.sp, letterSpacing = 0.5.sp ) */ )
AplikasiPelajaran/app/src/main/java/org/d3if3011/aplikasipelajaran/ui/theme/Type.kt
4273051805
package org.d3if3011.aplikasipelajaran.ui.screen import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.animation.core.MutableTransitionState import androidx.compose.animation.core.Spring.DampingRatioLowBouncy import androidx.compose.animation.core.Spring.StiffnessVeryLow import androidx.compose.animation.core.spring import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut import androidx.compose.animation.slideInVertically import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.sizeIn import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.Person import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults import androidx.compose.material3.CenterAlignedTopAppBar import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.navigation.NavHostController import org.d3if3011.aplikasipelajaran.R import org.d3if3011.aplikasipelajaran.model.Pelajaran import org.d3if3011.aplikasipelajaran.model.PelajaranRepository import org.d3if3011.aplikasipelajaran.navigation.Screen import org.d3if3011.aplikasipelajaran.ui.theme.AplikasiPelajaranTheme @Composable fun DashboardScreen(username: String?, navHostController: NavHostController) { Scaffold ( modifier = Modifier.fillMaxSize(), topBar = { TopAppBar(username, navHostController) } ) {paddingValues -> PelajaranList(listPelajaran = PelajaranRepository.pelajaran, modifier = Modifier.padding(paddingValues)) } } @OptIn(ExperimentalMaterial3Api::class) @Composable fun TopAppBar(username: String?, navHostController: NavHostController ,modifier: Modifier = Modifier) { CenterAlignedTopAppBar( title = { Text( text = "Halo, $username", style = MaterialTheme.typography.headlineSmall ) }, actions = { IconButton( onClick = { navHostController.navigate(Screen.Profile.route + "/$username") } ) { Icon( imageVector = Icons.Outlined.Person, contentDescription = stringResource(R.string.profile), tint = MaterialTheme.colorScheme.primary ) } } ) } @OptIn(ExperimentalAnimationApi::class) @Composable fun PelajaranList( listPelajaran: List<Pelajaran>, modifier: Modifier = Modifier, contentPadding: PaddingValues = PaddingValues(0.dp) ) { val visibleState = remember { MutableTransitionState(false).apply { targetState = true } } AnimatedVisibility( visibleState = visibleState, enter = fadeIn( animationSpec = spring(dampingRatio = DampingRatioLowBouncy) ), exit = fadeOut(), modifier = modifier ) { LazyColumn(contentPadding = contentPadding) { itemsIndexed(listPelajaran) { index, pelajaran -> PelajaranListItem( pelajaran = pelajaran, modifier = Modifier .padding(horizontal = 10.dp, vertical = 8.dp) .animateEnterExit( enter = slideInVertically( animationSpec = spring( stiffness = StiffnessVeryLow, dampingRatio = DampingRatioLowBouncy ), initialOffsetY = { it * (index + 1) } ) ) ) } } } } @Composable fun PelajaranListItem( pelajaran: Pelajaran, modifier: Modifier = Modifier ) { Card ( elevation = CardDefaults.cardElevation(defaultElevation = 2.dp), modifier = modifier ) { Row ( modifier = Modifier .fillMaxWidth() .padding(16.dp) .sizeIn(minHeight = 72.dp) ){ Column (modifier = Modifier.weight(1f)) { Text( text = stringResource(id = pelajaran.namaPelajaranRes), style = MaterialTheme.typography.titleLarge, maxLines = 1, overflow = TextOverflow.Ellipsis ) Text( text = stringResource(id = pelajaran.namaDosenRes), style = MaterialTheme.typography.bodyMedium, maxLines = 1, overflow = TextOverflow.Ellipsis ) Text( text = stringResource(id = pelajaran.kelasRes), style = MaterialTheme.typography.bodySmall, ) } Spacer(modifier = Modifier.width(16.dp)) Box( modifier = Modifier .size(72.dp) .clip(RoundedCornerShape(8.dp)) ) { Image( painter = painterResource(pelajaran.imageRes), contentDescription = null, alignment = Alignment.TopCenter, contentScale = ContentScale.FillWidth ) } } } } @Preview @Composable fun PelajaranListItemPreview() { val pelajaran = Pelajaran( R.string.nama_pelajaran1, R.string.nama_dosen1, R.string.kelas, R.drawable.profile_img1 ) AplikasiPelajaranTheme { PelajaranListItem(pelajaran = pelajaran) } } @Preview @Composable fun PelajaranListPreview() { AplikasiPelajaranTheme { Surface { PelajaranList(listPelajaran = PelajaranRepository.pelajaran) } } }
AplikasiPelajaran/app/src/main/java/org/d3if3011/aplikasipelajaran/ui/screen/DashboardScreen.kt
1092832655
package org.d3if3011.aplikasipelajaran.ui.screen import android.widget.Toast import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Warning import androidx.compose.material3.Button import androidx.compose.material3.Checkbox import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.navigation.NavController import androidx.navigation.compose.rememberNavController import org.d3if3011.aplikasipelajaran.R import org.d3if3011.aplikasipelajaran.navigation.Screen import org.d3if3011.aplikasipelajaran.ui.theme.AplikasiPelajaranTheme @OptIn(ExperimentalMaterial3Api::class) @Composable fun MainScreen(navController: NavController) { Scaffold ( modifier = Modifier.fillMaxSize() ) { paddingValues -> ScreenContent(navController, modifier = Modifier.padding(paddingValues)) } } @Composable fun ScreenContent(navController: NavController, modifier: Modifier = Modifier) { var username by rememberSaveable { mutableStateOf("") } var password by rememberSaveable { mutableStateOf("") } var usernameFalse by rememberSaveable { mutableStateOf(false) } var passwordFalse by rememberSaveable { mutableStateOf(false) } val isChecked = remember { mutableStateOf(false) } val context = LocalContext.current Column ( modifier = modifier .fillMaxSize() .verticalScroll(rememberScrollState()) .padding(16.dp), verticalArrangement = Arrangement.spacedBy(12.dp), horizontalAlignment = Alignment.CenterHorizontally ) { Text( text = stringResource(R.string.login), style = MaterialTheme.typography.bodyLarge, modifier = Modifier .fillMaxWidth() .padding(top = 120.dp), fontSize = 48.sp ) OutlinedTextField( value = username, onValueChange = { username=it }, label = { Text(text = stringResource(R.string.username)) }, isError = usernameFalse, trailingIcon = { IconPicker(usernameFalse, "") }, supportingText = { ErrorHintUsername(isError = usernameFalse) }, singleLine = true, keyboardOptions = KeyboardOptions( keyboardType = KeyboardType.Text, imeAction = ImeAction.Next ), modifier = Modifier.fillMaxWidth() ) OutlinedTextField( value = password, onValueChange = { password=it }, label = { Text(text = stringResource(R.string.password)) }, isError = passwordFalse, trailingIcon = { IconPicker(passwordFalse, "") }, supportingText = { ErrorHintPassword(isError = passwordFalse) }, singleLine = true, keyboardOptions = KeyboardOptions( keyboardType = KeyboardType.Text, imeAction = ImeAction.Next ), modifier = Modifier.fillMaxWidth() ) Row ( verticalAlignment = Alignment.CenterVertically ) { Checkbox( checked = isChecked.value, onCheckedChange = { isChecked.value = it } ) Text( text = stringResource( R.string.kalimat_checkbox, if (isChecked.value) stringResource(R.string.checked) else stringResource(R.string.unchecked) ) ) } Button( onClick = { usernameFalse = (username == "") passwordFalse = (password == "") if (usernameFalse||passwordFalse) return@Button navController.navigate(Screen.Dashboard.route + "/$username") Toast.makeText(context, R.string.login_berhasil, Toast.LENGTH_SHORT).show() }, modifier = Modifier.padding(8.dp), contentPadding = PaddingValues(horizontal = 32.dp, vertical = 16.dp) ) { Text(text = stringResource(id = R.string.login)) } } } @Composable fun IconPicker(isError: Boolean, unit: String) { if (isError) { Icon(imageVector = Icons.Filled.Warning, contentDescription = null) } else { Text(text = unit) } } @Composable fun ErrorHintUsername(isError: Boolean) { if (isError) { Text(text = stringResource(id = R.string.username_wrong)) } } @Composable fun ErrorHintPassword(isError: Boolean) { if (isError) { Text(text = stringResource(id = R.string.password_wrong)) } } @Preview @Composable fun ScreenPreview() { AplikasiPelajaranTheme { MainScreen(rememberNavController()) } }
AplikasiPelajaran/app/src/main/java/org/d3if3011/aplikasipelajaran/ui/screen/MainScreen.kt
2604570708
package org.d3if3011.aplikasipelajaran.ui.screen import android.content.Context import android.content.Intent import android.graphics.Bitmap import android.graphics.ImageDecoder import android.net.Uri import android.os.Build import android.provider.MediaStore import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowBack import androidx.compose.material3.Button import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController import org.d3if3011.aplikasipelajaran.R import org.d3if3011.aplikasipelajaran.ui.theme.AplikasiPelajaranTheme @OptIn(ExperimentalMaterial3Api::class) @Composable fun ProfileScreen(username: String?, navController: NavHostController) { Scaffold ( topBar = { TopAppBar( title = { Text(text = stringResource(id = R.string.app_name)) }, colors = TopAppBarDefaults.mediumTopAppBarColors( containerColor = MaterialTheme.colorScheme.primaryContainer, titleContentColor = MaterialTheme.colorScheme.primary ), navigationIcon = { IconButton(onClick = { navController.popBackStack() }) { Icon( imageVector = Icons.Filled.ArrowBack, contentDescription = stringResource( id = R.string.back ) ) } } ) } ) {paddingValues -> ProfileScreenContent(username,modifier = Modifier.padding(paddingValues)) } } @Composable fun ProfileScreenContent(username: String?, modifier: Modifier = Modifier) { val context = LocalContext.current Column ( modifier = Modifier .fillMaxSize() .verticalScroll(rememberScrollState()), verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally ) { Text(text = "Halo, $username") // PickImageFromGallery() Button( onClick = { shareData( context = context, message = context.getString( R.string.text_untuk_dibagikan ) ) }, modifier = Modifier.padding(top = 8.dp), contentPadding = PaddingValues(horizontal = 32.dp, vertical = 16.dp) ) { Text(text = stringResource(id = R.string.share)) } } } private fun shareData(context: Context, message: String) { val shareIntent = Intent(Intent.ACTION_SEND).apply { type = "text/plain" putExtra(Intent.EXTRA_TEXT, message) } if (shareIntent.resolveActivity(context.packageManager) != null) { context.startActivity(shareIntent) } } // tidak digunakan karena belum bisa menyimpan gambar saat perpindahan halaman @Composable fun PickImageFromGallery() { var imageUri by rememberSaveable { mutableStateOf<Uri?>(null) } val bitmap = rememberSaveable { mutableStateOf<Bitmap?>(null) } val context = LocalContext.current val launcher = rememberLauncherForActivityResult( contract = ActivityResultContracts.GetContent(), onResult = {uri: Uri? -> imageUri = uri } ) Column ( horizontalAlignment = Alignment.CenterHorizontally ) { imageUri?.let { if (Build.VERSION.SDK_INT < 28) { bitmap.value = MediaStore.Images .Media.getBitmap(context.contentResolver, it) } else { val source = ImageDecoder.createSource(context.contentResolver, it) bitmap.value = ImageDecoder.decodeBitmap(source) } bitmap.value?.let { btm -> Image( bitmap = btm.asImageBitmap(), contentDescription = null, modifier = Modifier .size(400.dp) .padding(20.dp) ) } } Spacer(modifier = Modifier.height(12.dp)) Button(onClick = { launcher.launch("image/*") }) { Text(text = "Pick Image") } } } @Preview @Composable fun ProfileScreenPreview() { AplikasiPelajaranTheme { ProfileScreen("test", rememberNavController()) } }
AplikasiPelajaran/app/src/main/java/org/d3if3011/aplikasipelajaran/ui/screen/ProfileScreen.kt
2280018908
package org.d3if3011.aplikasipelajaran import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import org.d3if3011.aplikasipelajaran.navigation.SetupNavGraph import org.d3if3011.aplikasipelajaran.ui.screen.MainScreen import org.d3if3011.aplikasipelajaran.ui.theme.AplikasiPelajaranTheme class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { AplikasiPelajaranTheme { // A surface container using the 'background' color from the theme Surface( modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background ) { SetupNavGraph() } } } } }
AplikasiPelajaran/app/src/main/java/org/d3if3011/aplikasipelajaran/MainActivity.kt
1215685929
package org.d3if3011.aplikasipelajaran.navigation import androidx.compose.runtime.Composable import androidx.navigation.NavHostController import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController import org.d3if3011.aplikasipelajaran.ui.screen.DashboardScreen import org.d3if3011.aplikasipelajaran.ui.screen.MainScreen import org.d3if3011.aplikasipelajaran.ui.screen.ProfileScreen @Composable fun SetupNavGraph(navController: NavHostController = rememberNavController()) { NavHost( navController = navController, startDestination = Screen.Home.route, builder = { composable(route = Screen.Home.route) { MainScreen(navController) } composable(route = Screen.Dashboard.route + "/{id}") { navBackStack -> val username = navBackStack.arguments?.getString("id") DashboardScreen(username, navController) } composable(route = Screen.Profile.route + "/{id}") { navBackStack -> val username = navBackStack.arguments?.getString("id") ProfileScreen(username, navController) } } ) }
AplikasiPelajaran/app/src/main/java/org/d3if3011/aplikasipelajaran/navigation/NavGraph.kt
2476293886
package org.d3if3011.aplikasipelajaran.navigation sealed class Screen(val route: String) { data object Home: Screen("mainScreen") data object Profile: Screen("profile") data object Dashboard: Screen("dashboard") }
AplikasiPelajaran/app/src/main/java/org/d3if3011/aplikasipelajaran/navigation/Screen.kt
1817572633
package org.d3if3011.aplikasipelajaran.model import org.d3if3011.aplikasipelajaran.R object PelajaranRepository { val pelajaran = listOf( Pelajaran( namaPelajaranRes = R.string.nama_pelajaran1, namaDosenRes = R.string.nama_dosen1, kelasRes = R.string.kelas, imageRes = R.drawable.profile_img1 ), Pelajaran( namaPelajaranRes = R.string.nama_pelajaran2, namaDosenRes = R.string.nama_dosen2, kelasRes = R.string.kelas, imageRes = R.drawable.profile_img2 ), Pelajaran( namaPelajaranRes = R.string.nama_pelajaran3, namaDosenRes = R.string.nama_dosen3, kelasRes = R.string.kelas, imageRes = R.drawable.profile_img3 ), Pelajaran( namaPelajaranRes = R.string.nama_pelajaran4, namaDosenRes = R.string.nama_dosen4, kelasRes = R.string.kelas, imageRes = R.drawable.profile_img4 ), Pelajaran( namaPelajaranRes = R.string.nama_pelajaran5, namaDosenRes = R.string.nama_dosen5, kelasRes = R.string.kelas, imageRes = R.drawable.profile_img5 ), Pelajaran( namaPelajaranRes = R.string.nama_pelajaran6, namaDosenRes = R.string.nama_dosen6, kelasRes = R.string.kelas, imageRes = R.drawable.profile_img6 ), ) }
AplikasiPelajaran/app/src/main/java/org/d3if3011/aplikasipelajaran/model/PelajaranDataSource.kt
1509100073
package org.d3if3011.aplikasipelajaran.model import androidx.annotation.DrawableRes import androidx.annotation.StringRes data class Pelajaran ( @StringRes val namaPelajaranRes: Int, @StringRes val namaDosenRes: Int, @StringRes val kelasRes: Int, @DrawableRes val imageRes: Int )
AplikasiPelajaran/app/src/main/java/org/d3if3011/aplikasipelajaran/model/Pelajaran.kt
2550162154
package com.example.edinaldo import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 import org.junit.Test import org.junit.runner.RunWith import org.junit.Assert.* /** * Instrumented test, which will execute on an Android device. * * See [testing documentation](http://d.android.com/tools/testing). */ @RunWith(AndroidJUnit4::class) class ExampleInstrumentedTest { @Test fun useAppContext() { // Context of the app under test. val appContext = InstrumentationRegistry.getInstrumentation().targetContext assertEquals("com.example.edinaldo", appContext.packageName) } }
par-impar-kt/app/src/androidTest/java/com/example/edinaldo/ExampleInstrumentedTest.kt
2463407195
package com.example.edinaldo import org.junit.Test import org.junit.Assert.* /** * Example local unit test, which will execute on the development machine (host). * * See [testing documentation](http://d.android.com/tools/testing). */ class ExampleUnitTest { @Test fun addition_isCorrect() { assertEquals(4, 2 + 2) } }
par-impar-kt/app/src/test/java/com/example/bruno/ExampleUnitTest.kt
584399481
package com.example.edinaldo import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View import android.widget.Button import android.widget.TextView import kotlin.random.Random import android.util.Log class MainActivity : AppCompatActivity() { var score: Int = 0 lateinit var txtScore: TextView lateinit var txtRes: TextView lateinit var btnNewGame: Button lateinit var btnPar: Button lateinit var btnImpar: Button override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) txtRes = findViewById(R.id.txtRes) btnNewGame = findViewById(R.id.btnNewGame) btnPar = findViewById(R.id.btnPar) btnImpar = findViewById(R.id.btnImpar) txtScore = findViewById(R.id.txtScore) btnPar.visibility = View.INVISIBLE btnImpar.visibility = View.INVISIBLE txtScore.visibility = View.INVISIBLE btnNewGame.setOnClickListener { newGame() } } fun newGame(){ txtRes.text = Random.nextInt(0,100).toString() btnNewGame.visibility = View.INVISIBLE btnPar.visibility = View.VISIBLE btnImpar.visibility = View.VISIBLE txtScore.visibility = View.VISIBLE score = 0 txtScore.text = score.toString() btnPar.setOnClickListener { Par(txtRes.text.toString().toInt()) } btnImpar.setOnClickListener { Impar(txtRes.text.toString().toInt()) } } fun Par(numero: Int){ if(numero % 2 == 0){ score++ txtScore.text = score.toString() Log.d("score", "par") txtRes.text = Random.nextInt(0,100).toString() btnNewGame.visibility = View.VISIBLE } } fun Impar(numero: Int){ if(numero % 2 != 0){ score++ txtScore.text = score.toString() Log.d("score", "impar") txtRes.text = Random.nextInt(0,100).toString() btnNewGame.visibility = View.VISIBLE } } }
par-impar-kt/app/src/main/java/com/example/edinaldo/MainActivity.kt
4269438912
package com.example.designpattersexm import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 import org.junit.Test import org.junit.runner.RunWith import org.junit.Assert.* /** * Instrumented test, which will execute on an Android device. * * See [testing documentation](http://d.android.com/tools/testing). */ @RunWith(AndroidJUnit4::class) class ExampleInstrumentedTest { @Test fun useAppContext() { // Context of the app under test. val appContext = InstrumentationRegistry.getInstrumentation().targetContext assertEquals("com.example.designpattersexm", appContext.packageName) } }
DesignPattersExm/app/src/androidTest/java/com/example/designpattersexm/ExampleInstrumentedTest.kt
4232541035
package com.example.designpattersexm import org.junit.Test import org.junit.Assert.* /** * Example local unit test, which will execute on the development machine (host). * * See [testing documentation](http://d.android.com/tools/testing). */ class ExampleUnitTest { @Test fun addition_isCorrect() { assertEquals(4, 2 + 2) } }
DesignPattersExm/app/src/test/java/com/example/designpattersexm/ExampleUnitTest.kt
806197049
package com.example.designpattersexm import android.os.Build import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.util.Log import androidx.annotation.RequiresApi import com.example.designpattersexm.designPattern.builder.MyComponent import com.example.designpattersexm.designPattern.builder.MyComponent2 import com.example.designpattersexm.designPattern.builder.MyComponent3 import com.example.designpattersexm.designPattern.factoryPattern.FactoryMethod import com.example.designpattersexm.designPattern.singleton.MySingleton import java.lang.Exception class MainActivity : AppCompatActivity() { private lateinit var taskCreator: FactoryMethod.TaskCreator private fun initialize(){ val config= readApplicationConfigFile() taskCreator= when(config.task){ "Upload"-> FactoryMethod.UploadTaskCreator() "Download" -> FactoryMethod.DownloadTaskCreator() else -> throw Exception("Error! Unknown task.") } } @RequiresApi(Build.VERSION_CODES.P) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) //---------------FactoryDesignPattern------------------------------- initialize() taskCreator.taskManager() //-----------------Singleton Design Pattern--------------------------- val firstInitial= MySingleton.getInstance() val secondInitial= MySingleton.getInstance() val isSame = firstInitial == secondInitial Log.d("Singleton Test", isSame.toString()) //----------------Builder Design Pattern------------------------------ val component1 = MyComponent.Builder() .setName("MyComponent v1.0") .setId(10) .setVisibility(true) .build() println(component1.name) val cmptNew= MyComponent.Builder() .setName("NoName") .build() println(cmptNew.name) val component2 = MyComponent2.Builder().apply { name = "Component Name" id = 1 isVisible = true }.build() val component3= MyComponent3("MyName",10,true) val component4= MyComponent3("MySecondName",20,false,1.0f) } private fun readApplicationConfigFile(): Config { // Implement this method to read and return application configuration // You can replace it with your actual implementation. return Config("Upload") // Default configuration for the sake of the example. } data class Config(val task: String) }
DesignPattersExm/app/src/main/java/com/example/designpattersexm/MainActivity.kt
1916882442
package com.example.designpattersexm.designPattern.factoryPattern import android.util.Log class FactoryMethod { // Product interface interface Task { fun execute() } // Concrete Products class DownloadTask : Task { override fun execute() { println("Executing Download Task...") // Download logic } } class DelayTask: Task { override fun execute() { println("Execute ") } } class UploadTask : Task { override fun execute() { println("Executing Upload Task...") Log.d("MainAc", "Executing Upload Task...") // Upload logic } } // Creator abstract Class abstract class TaskCreator { abstract fun createTask(): Task fun taskManager(){ val testTask= createTask() testTask.execute() } } // Concrete Creators class DownloadTaskCreator : TaskCreator() { override fun createTask(): Task { return DownloadTask() } } class UploadTaskCreator : TaskCreator() { override fun createTask(): Task { return UploadTask() } } }
DesignPattersExm/app/src/main/java/com/example/designpattersexm/designPattern/factoryPattern/FactoryMethod.kt
2293156533
package com.example.designpattersexm.designPattern.singleton class MySingleton private constructor() { // instance companion object { @Volatile// ensures that the instance variable is always read from and written to the main memory, // preventing possible threading issues during the instance creation. private var instance: MySingleton? = null fun getInstance(): MySingleton { return instance ?: synchronized(this) // block ensures that only one instance of the singleton is created, // even in a multithreaded environment. { instance ?: MySingleton().also { instance = it } } } } // Other methods of singleton class fun doSomething() { println("Singleton is doing something") } } // Pros and Cons // P- gain a global access point to that instance, object is initialized only when it’s requested for the first time. // C- Violates the Single Responsibility Principle, It may be difficult to unit test the client code, // requires special treatment in a multithreaded environment
DesignPattersExm/app/src/main/java/com/example/designpattersexm/designPattern/singleton/MySingleton.kt
3922437585
package com.example.designpattersexm.designPattern.builder class MyComponent private constructor(builder: Builder) { var name: String? = null var id: Int? = null var isVisible: Boolean? = null class Builder { var name: String? = null var id: Int? = null var isVisible: Boolean? = null fun setName(name: String) = apply { this.name = name } fun setId(id: Int) = apply { this.id = id } fun setVisibility(visible: Boolean) = apply { this.isVisible = visible } fun build() = MyComponent(this) fun getName() = name fun getId() = id fun getIsVisible() = isVisible } init { name = builder.getName() id = builder.getId() isVisible = builder.getIsVisible() } } data class MyComponent2( var name: String? = null, var id: Int? = null, var isVisible: Boolean? = null ) { class Builder { var name: String? = null var id: Int? = null var isVisible: Boolean? = null fun build() = MyComponent2(name, id, isVisible) } } //Too long; didn't read (TLDR) //For most use cases you don't need a Builder pattern in Kotlin and are fine just using a constructor // with named arguments and default parameters. //In case you have a complex object and/or have a stateful configuration that // you want to pass around until you have build the complete object, a Builder is useful. //For even complex use cases you can use a type-safe builder to create a custom DSL to ease builder usage data class MyComponent3( val name: String, val id: Int, val isVisible: Boolean, val height: Float?= null, val weight: Float? =null )
DesignPattersExm/app/src/main/java/com/example/designpattersexm/designPattern/builder/MyComponent.kt
2380577227
package ng.com.netpos.app import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 import org.junit.Test import org.junit.runner.RunWith import org.junit.Assert.* /** * Instrumented test, which will execute on an Android device. * * See [testing documentation](http://d.android.com/tools/testing). */ @RunWith(AndroidJUnit4::class) class ExampleInstrumentedTest { @Test fun useAppContext() { // Context of the app under test. val appContext = InstrumentationRegistry.getInstrumentation().targetContext assertEquals("ng.com.netpos.app", appContext.packageName) } }
NetposLibrarySampleProject/app/src/androidTest/java/ng/com/netpos/app/ExampleInstrumentedTest.kt
1511743234
package ng.com.netpos.app import org.junit.Test import org.junit.Assert.* /** * Example local unit test, which will execute on the development machine (host). * * See [testing documentation](http://d.android.com/tools/testing). */ class ExampleUnitTest { @Test fun addition_isCorrect() { assertEquals(4, 2 + 2) } }
NetposLibrarySampleProject/app/src/test/java/ng/com/netpos/app/ExampleUnitTest.kt
549138780
package ng.com.netpos.app import android.os.Bundle import android.widget.Button import android.widget.TextView import androidx.activity.ComponentActivity import com.netpluspay.netpossdk.NetPosSdk import com.netpluspay.netpossdk.emv.CardReadResult import com.netpluspay.netpossdk.utils.DeviceConfig import io.reactivex.disposables.CompositeDisposable class MainActivity : ComponentActivity() { private var cardResult: CardReadResult? = null private lateinit var btn: Button private val compositeDisposable = CompositeDisposable() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) btn = findViewById(R.id.test_card_reading) NetPosSdk.writeTpkKey(DeviceConfig.TPKIndex, "6943DD4434E0B3C0D808D0FE2A590CD9", this) btn.setOnClickListener { showCardDialog(this, 1, 1, compositeDisposable) { result -> findViewById<TextView>(R.id.scan_result).text = result.toString() } } } }
NetposLibrarySampleProject/app/src/main/java/ng/com/netpos/app/MainActivity.kt
375400271
package ng.com.netpos.app import android.app.Application import com.netpluspay.netpossdk.NetPosSdk import com.netpluspay.netpossdk.utils.TerminalParameters import timber.log.Timber class NetPosApp : Application() { override fun onCreate() { super.onCreate() Timber.plant(Timber.DebugTree()) NetPosSdk.init() NetPosSdk.loadEmvParams( TerminalParameters().apply { terminalCapability = "E068C8" } ) } }
NetposLibrarySampleProject/app/src/main/java/ng/com/netpos/app/NetPosApp.kt
3179360405
@file:Suppress("DEPRECATION") package ng.com.netpos.app import android.app.Activity import android.app.ProgressDialog import android.content.* // ktlint-disable no-wildcard-imports import android.widget.Toast import com.netpluspay.netpossdk.emv.CardReadResult import com.netpluspay.netpossdk.emv.CardReaderEvent import com.netpluspay.netpossdk.emv.CardReaderService import com.pos.sdk.emvcore.POIEmvCoreManager.* // ktlint-disable no-wildcard-imports import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.Disposable import io.reactivex.schedulers.Schedulers import timber.log.Timber typealias ReaderListener = (result: CardReadResult) -> Unit fun showCardDialog( context: Activity, amount: Long, cashBackAmount: Long, compositeDisposable: CompositeDisposable, readerListener: ReaderListener ) { val dialog = ProgressDialog(context) .apply { setMessage("Waiting for card") setCancelable(false) } val cardService = CardReaderService(context, listOf(DEV_ICC, DEV_PICC)) val c = cardService.initiateICCCardPayment( amount, cashBackAmount ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe({ when (it) { is CardReaderEvent.CardRead -> { Timber.d("READ_CARD_DATA=>%s", it.data.toString()) readerListener.invoke(it.data) } is CardReaderEvent.CardDetected -> { val mode = when (it.mode) { DEV_ICC -> "EMV" DEV_PICC -> "EMV Contactless" else -> "MAGNETIC STRIPE" } dialog.setMessage("Reading Card with $mode Please Wait") Timber.d("DETECTED_CARD_MODE=>%s", mode) } } }, { it?.let { it.printStackTrace() Toast.makeText(context, it.localizedMessage, Toast.LENGTH_SHORT).show() dialog.dismiss() Timber.e(it.localizedMessage ?: "Fatal Error") Timber.e(it) } }, { dialog.dismiss() }) dialog.setButton(DialogInterface.BUTTON_POSITIVE, "Stop") { d, _ -> cardService.transEnd(message = "Stopped") d.dismiss() } dialog.show() compositeDisposable.let { c.disposeWith(it) } } fun Disposable.disposeWith(compositeDisposable: CompositeDisposable) = compositeDisposable.add(this)
NetposLibrarySampleProject/app/src/main/java/ng/com/netpos/app/CardExt.kt
296239988
package com.batch.job.batchtest import org.junit.jupiter.api.Test import org.springframework.boot.test.context.SpringBootTest @SpringBootTest class BatchTestApplicationTests { @Test fun contextLoads() { } }
batch-test/src/test/kotlin/com/batch/job/batchtest/BatchTestApplicationTests.kt
1352774056
package com.batch.job.batchtest import org.springframework.boot.CommandLineRunner import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication import java.io.BufferedReader import java.io.BufferedWriter import java.io.FileReader import java.io.FileWriter @SpringBootApplication open class BatchTestApplication : CommandLineRunner { override fun run(vararg args: String?) { println("Executing Task1") println("Executing Task2") println("Executing Task3") val fileName = "opt/a.txt" val value = "Hello, world!" writeToFile(fileName,value) println("Written to file : $fileName") val readFromFile = readFromFile(fileName) println("Content read from file: $readFromFile") } private fun readFromFile(fileName : String) :String { val reader = BufferedReader(FileReader(fileName)) val currentLine = reader.readLine() reader.close() return currentLine } private fun writeToFile(fileName : String, str : String) { val writer = BufferedWriter(FileWriter(fileName, true)) writer.append(' ') writer.append(str) writer.close() } } fun main(args: Array<String>) { runApplication<BatchTestApplication>(*args) }
batch-test/src/main/kotlin/com/batch/job/batchtest/BatchTestApplication.kt
1200536304
package com.example.moviex import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 import org.junit.Test import org.junit.runner.RunWith import org.junit.Assert.* /** * Instrumented test, which will execute on an Android device. * * See [testing documentation](http://d.android.com/tools/testing). */ @RunWith(AndroidJUnit4::class) class ExampleInstrumentedTest { @Test fun useAppContext() { // Context of the app under test. val appContext = InstrumentationRegistry.getInstrumentation().targetContext assertEquals("com.example.moviex", appContext.packageName) } }
MovieX/app/src/androidTest/java/com/example/moviex/ExampleInstrumentedTest.kt
1371601105
package com.example.moviex import org.junit.Test import org.junit.Assert.* /** * Example local unit test, which will execute on the development machine (host). * * See [testing documentation](http://d.android.com/tools/testing). */ class ExampleUnitTest { @Test fun addition_isCorrect() { assertEquals(4, 2 + 2) } }
MovieX/app/src/test/java/com/example/moviex/ExampleUnitTest.kt
134378371
package com.example.moviex.ui.theme import androidx.compose.ui.graphics.Color val Purple80 = Color(0xFFD0BCFF) val PurpleGrey80 = Color(0xFFCCC2DC) val Pink80 = Color(0xFFEFB8C8) val Purple40 = Color(0xFF6650a4) val PurpleGrey40 = Color(0xFF625b71) val Pink40 = Color(0xFF7D5260)
MovieX/app/src/main/java/com/example/moviex/ui/theme/Color.kt
1091425235
package com.example.moviex.ui.theme import android.app.Activity import android.os.Build import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material3.MaterialTheme import androidx.compose.material3.darkColorScheme import androidx.compose.material3.dynamicDarkColorScheme import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable import androidx.compose.runtime.SideEffect import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalView import androidx.core.view.WindowCompat private val DarkColorScheme = darkColorScheme( primary = Purple80, secondary = PurpleGrey80, tertiary = Pink80 ) private val LightColorScheme = lightColorScheme( primary = Purple40, secondary = PurpleGrey40, tertiary = Pink40 /* Other default colors to override background = Color(0xFFFFFBFE), surface = Color(0xFFFFFBFE), onPrimary = Color.White, onSecondary = Color.White, onTertiary = Color.White, onBackground = Color(0xFF1C1B1F), onSurface = Color(0xFF1C1B1F), */ ) @Composable fun MovieXTheme( darkTheme: Boolean = isSystemInDarkTheme(), // Dynamic color is available on Android 12+ dynamicColor: Boolean = true, content: @Composable () -> Unit ) { val colorScheme = when { dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { val context = LocalContext.current if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) } darkTheme -> DarkColorScheme else -> LightColorScheme } val view = LocalView.current if (!view.isInEditMode) { SideEffect { val window = (view.context as Activity).window window.statusBarColor = colorScheme.primary.toArgb() WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme } } MaterialTheme( colorScheme = colorScheme, typography = Typography, content = content ) }
MovieX/app/src/main/java/com/example/moviex/ui/theme/Theme.kt
1744918349
package com.example.moviex.ui.theme import androidx.compose.material3.Typography import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.sp // Set of Material typography styles to start with val Typography = Typography( bodyLarge = TextStyle( fontFamily = FontFamily.Default, fontWeight = FontWeight.Normal, fontSize = 16.sp, lineHeight = 24.sp, letterSpacing = 0.5.sp ) /* Other default text styles to override titleLarge = TextStyle( fontFamily = FontFamily.Default, fontWeight = FontWeight.Normal, fontSize = 22.sp, lineHeight = 28.sp, letterSpacing = 0.sp ), labelSmall = TextStyle( fontFamily = FontFamily.Default, fontWeight = FontWeight.Medium, fontSize = 11.sp, lineHeight = 16.sp, letterSpacing = 0.5.sp ) */ )
MovieX/app/src/main/java/com/example/moviex/ui/theme/Type.kt
3807756457
@file:OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3Api::class) package com.example.moviex import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.runtime.Composable import androidx.compose.ui.tooling.preview.Preview import com.example.moviex.navigation.MovieNavigation import com.example.moviex.ui.theme.MovieXTheme class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { MyApp { MovieNavigation() } } } } @Composable fun MyApp(content: @Composable () -> Unit) { MovieXTheme { content() } } @Preview(showBackground = true) @Composable fun GreetingPreview() { MovieXTheme { MyApp { MovieNavigation() } } }
MovieX/app/src/main/java/com/example/moviex/MainActivity.kt
421315473
package com.example.moviex.navigation enum class MovieScreens { HomeScreen, DetailScreen; companion object { fun fromRoute(route:String?):MovieScreens = when(route?.substringBefore("/")){ HomeScreen.name -> HomeScreen DetailScreen.name -> DetailScreen null -> HomeScreen else -> throw IllegalAccessException("Route $route is not recognized") } } }
MovieX/app/src/main/java/com/example/moviex/navigation/MovieScreens.kt
1292899370
package com.example.moviex.navigation import androidx.compose.runtime.Composable import androidx.navigation.NavType import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController import androidx.navigation.navArgument import com.example.moviex.screens.details.DetailsScreen import com.example.moviex.screens.home.HomeScreen @Composable fun MovieNavigation(){ val navController = rememberNavController() NavHost( navController = navController, startDestination =MovieScreens.HomeScreen.name ){ composable( MovieScreens.HomeScreen.name ){ HomeScreen(navController = navController) } //example: Passing arguments www.google.com/detail-screen/id=34 composable( MovieScreens.DetailScreen.name +"/{movie}", arguments = listOf(navArgument(name = "movie"){type = NavType.StringType}) ){ backStackEntry -> DetailsScreen(navController = navController,backStackEntry.arguments?.getString("movie")) } } }
MovieX/app/src/main/java/com/example/moviex/navigation/MovieNavigation.kt
2002289467
package com.example.moviex.models data class MovieData( val id: String, val title: String, val year: String, val genre: String, val director: String, val actors: String, val plot: String, val poster: String, val images: List<String>, val rating: String ) fun getMovies(): List<MovieData> { return listOf( MovieData( id = "tt0499549", title = "Avatar", year = "2009", genre = "Action, Adventure, Fantasy", director = "James Cameron", actors = "Sam Worthington, Zoe Saldana, Sigourney Weaver, Stephen Lang", plot = "A paraplegic marine dispatched to the moon Pandora on a unique mission becomes torn between following his orders and protecting the world he feels is his home.", poster = "http://ia.media-imdb.com/images/M/MV5BMTYwOTEwNjAzMl5BMl5BanBnXkFtZTcwODc5MTUwMw@@._V1_SX300.jpg", images = listOf( "https://images-na.ssl-images-amazon.com/images/M/MV5BMjEyOTYyMzUxNl5BMl5BanBnXkFtZTcwNTg0MTUzNA@@._V1_SX1500_CR0,0,1500,999_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BNzM2MDk3MTcyMV5BMl5BanBnXkFtZTcwNjg0MTUzNA@@._V1_SX1777_CR0,0,1777,999_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMTY2ODQ3NjMyMl5BMl5BanBnXkFtZTcwODg0MTUzNA@@._V1_SX1777_CR0,0,1777,999_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMTMxOTEwNDcxN15BMl5BanBnXkFtZTcwOTg0MTUzNA@@._V1_SX1777_CR0,0,1777,999_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMTYxMDg1Nzk1MV5BMl5BanBnXkFtZTcwMDk0MTUzNA@@._V1_SX1500_CR0,0,1500,999_AL_.jpg" ), rating = "7.9" ), MovieData( id = "tt0416449", title = "300", year = "2006", genre = "Action, Drama, Fantasy", director = "Zack Snyder", actors = "Gerard Butler, Lena Headey, Dominic West, David Wenham", plot = "King Leonidas of Sparta and a force of 300 men fight the Persians at Thermopylae in 480 B.C.", poster = "http://ia.media-imdb.com/images/M/MV5BMjAzNTkzNjcxNl5BMl5BanBnXkFtZTYwNDA4NjE3._V1_SX300.jpg", images = listOf( "https://images-na.ssl-images-amazon.com/images/M/MV5BMTMwNTg5MzMwMV5BMl5BanBnXkFtZTcwMzA2NTIyMw@@._V1_SX1777_CR0,0,1777,937_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMTQwNTgyNTMzNF5BMl5BanBnXkFtZTcwNDA2NTIyMw@@._V1_SX1777_CR0,0,1777,935_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMTc0MjQzOTEwMV5BMl5BanBnXkFtZTcwMzE2NTIyMw@@._V1_SX1777_CR0,0,1777,947_AL_.jpg" ), rating = "7.7" ), MovieData( id = "tt0848228", title = "The Avengers", year = "2012", genre = "Action, Sci-Fi, Thriller", director = "Joss Whedon", actors = "Robert Downey Jr., Chris Evans, Mark Ruffalo, Chris Hemsworth", plot = "Earth's mightiest heroes must come together and learn to fight as a team if they are to stop the mischievous Loki and his alien army from enslaving humanity.", poster = "http://ia.media-imdb.com/images/M/MV5BMTk2NTI1MTU4N15BMl5BanBnXkFtZTcwODg0OTY0Nw@@._V1_SX300.jpg", images = listOf( "https://images-na.ssl-images-amazon.com/images/M/MV5BMTA0NjY0NzE4OTReQTJeQWpwZ15BbWU3MDczODg2Nzc@._V1_SX1777_CR0,0,1777,999_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMjE1MzEzMjcyM15BMl5BanBnXkFtZTcwNDM4ODY3Nw@@._V1_SX1777_CR0,0,1777,999_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMjMwMzM2MTg1M15BMl5BanBnXkFtZTcwNjM4ODY3Nw@@._V1_SX1777_CR0,0,1777,999_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMTQ4NzM2Mjc5MV5BMl5BanBnXkFtZTcwMTkwOTY3Nw@@._V1_SX1777_CR0,0,1777,999_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMTc3MzQ3NjA5N15BMl5BanBnXkFtZTcwMzY5OTY3Nw@@._V1_SX1777_CR0,0,1777,999_AL_.jpg" ), rating = "8.1" ), MovieData( id = "tt0993846", title = "The Wolf of Wall Street", year = "2013", genre = "Biography, Comedy, Crime", director = "Martin Scorsese", actors = "Leonardo DiCaprio, Jonah Hill, Margot Robbie, Matthew McConaughey", plot = "Based on the true story of Jordan Belfort, from his rise to a wealthy stock-broker living the high life to his fall involving crime, corruption and the federal government.", poster = "http://ia.media-imdb.com/images/M/MV5BMjIxMjgxNTk0MF5BMl5BanBnXkFtZTgwNjIyOTg2MDE@._V1_SX300.jpg", images = listOf( "https://images-na.ssl-images-amazon.com/images/M/MV5BNDIwMDIxNzk3Ml5BMl5BanBnXkFtZTgwMTg0MzQ4MDE@._V1_SX1500_CR0,0,1500,999_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMTc0NzAxODAyMl5BMl5BanBnXkFtZTgwMDg0MzQ4MDE@._V1_SX1500_CR0,0,1500,999_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMTExMDk1MDE4NzVeQTJeQWpwZ15BbWU4MDM4NDM0ODAx._V1_SX1500_CR0,0,1500,999_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMTg3MTY4NDk4Nl5BMl5BanBnXkFtZTgwNjc0MzQ4MDE@._V1_SX1500_CR0,0,1500,999_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMTgzMTg4MDI0Ml5BMl5BanBnXkFtZTgwOTY0MzQ4MDE@._V1_SY1000_CR0,0,1553,1000_AL_.jpg" ), rating = "8.2" ), MovieData( id = "tt0816692", title = "Interstellar", year = "2014", genre = "Adventure, Drama, Sci-Fi", director = "Christopher Nolan", actors = "Ellen Burstyn, Matthew McConaughey, Mackenzie Foy, John Lithgow", plot = "A team of explorers travel through a wormhole in space in an attempt to ensure humanity's survival.", poster = "http://ia.media-imdb.com/images/M/MV5BMjIxNTU4MzY4MF5BMl5BanBnXkFtZTgwMzM4ODI3MjE@._V1_SX300.jpg", images = listOf( "https://images-na.ssl-images-amazon.com/images/M/MV5BMjA3NTEwOTMxMV5BMl5BanBnXkFtZTgwMjMyODgxMzE@._V1_SX1500_CR0,0,1500,999_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMzQ5ODE2MzEwM15BMl5BanBnXkFtZTgwMTMyODgxMzE@._V1_SX1500_CR0,0,1500,999_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMTg4Njk4MzY0Nl5BMl5BanBnXkFtZTgwMzIyODgxMzE@._V1_SX1500_CR0,0,1500,999_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMzE3MTM0MTc3Ml5BMl5BanBnXkFtZTgwMDIyODgxMzE@._V1_SX1500_CR0,0,1500,999_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BNjYzNjE2NDk3N15BMl5BanBnXkFtZTgwNzEyODgxMzE@._V1_SX1500_CR0,0,1500,999_AL_.jpg" ), rating = "8.6" ), MovieData( id = "tt0944947", title = "Game of Thrones", year = "2011 - 2018", genre = "Adventure, Drama, Fantasy", director = "N/A", actors = "Peter Dinklage, Lena Headey, Emilia Clarke, Kit Harington", plot = "While a civil war brews between several noble families in Westeros, the children of the former rulers of the land attempt to rise up to power. Meanwhile a forgotten race, bent on destruction, plans to return after thousands of years in the North.", poster = "http://ia.media-imdb.com/images/M/MV5BMjM5OTQ1MTY5Nl5BMl5BanBnXkFtZTgwMjM3NzMxODE@._V1_SX300.jpg", images = listOf( "https://images-na.ssl-images-amazon.com/images/M/MV5BNDc1MGUyNzItNWRkOC00MjM1LWJjNjMtZTZlYWIxMGRmYzVlXkEyXkFqcGdeQXVyMzU3MDEyNjk@._V1_SX1777_CR0,0,1777,999_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BZjZkN2M5ODgtMjQ2OC00ZjAxLWE1MjMtZDE0OTNmNGM0NWEwXkEyXkFqcGdeQXVyNjUxNzgwNTE@._V1_SX1777_CR0,0,1777,999_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMDk4Y2Y1MDAtNGVmMC00ZTlhLTlmMmQtYjcyN2VkNzUzZjg2XkEyXkFqcGdeQXVyNjUxNzgwNTE@._V1_SX1777_CR0,0,1777,999_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BNjZjNWIzMzQtZWZjYy00ZTkwLWJiMTYtOWRkZDBhNWJhY2JmXkEyXkFqcGdeQXVyMjk3NTUyOTc@._V1_SX1777_CR0,0,1777,999_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BNTMyMTRjZWEtM2UxMS00ZjU5LWIxMTYtZDA5YmJhZmRjYTc4XkEyXkFqcGdeQXVyMjk3NTUyOTc@._V1_SX1777_CR0,0,1777,999_AL_.jpg" ), rating = "9.5" ), MovieData( id = "tt2306299", title = "Vikings", year = "2013–2020", genre = "Action, Drama, History", director = "N/A", actors = "Travis Fimmel, Clive Standen, Gustaf Skarsgård, Katheryn Winnick", plot = "The world of the Vikings is brought to life through the journey of Ragnar Lothbrok, the first Viking to emerge from Norse legend and onto the pages of history - a man on the edge of myth.", poster = "http://ia.media-imdb.com/images/M/MV5BOTEzNzI3MDc0N15BMl5BanBnXkFtZTgwMzk1MzA5NzE@._V1_SX300.jpg", images = listOf( "https://images-na.ssl-images-amazon.com/images/M/MV5BMjM5MTM1ODUxNV5BMl5BanBnXkFtZTgwNTAzOTI2ODE@._V1_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BNzU2NDcxODMyOF5BMl5BanBnXkFtZTgwNDAzOTI2ODE@._V1_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMjMzMzIzOTU2M15BMl5BanBnXkFtZTgwODMzMTkyODE@._V1_SY1000_SX1500_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMTQ2NTQ2MDA3NF5BMl5BanBnXkFtZTgwODkxMDUxODE@._V1_SY1000_SX1500_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMTcxOTQ3NTA5N15BMl5BanBnXkFtZTgwMzExMDUxODE@._V1_SY1000_SX1500_AL_.jpg" ), rating = "9.5" ), MovieData( id = "tt0903747", title = "Breaking Bad", year = "2008–2013", genre = "Crime, Drama, Thriller", director = "N/A", actors = "Bryan Cranston, Anna Gunn, Aaron Paul, Dean Norris", plot = "A high school chemistry teacher diagnosed with inoperable lung cancer turns to manufacturing and selling methamphetamine in order to secure his family's financial future.", poster = "http://ia.media-imdb.com/images/M/MV5BMTQ0ODYzODc0OV5BMl5BanBnXkFtZTgwMDk3OTcyMDE@._V1_SX300.jpg", images = listOf( "https://images-na.ssl-images-amazon.com/images/M/MV5BMTgyMzI5NDc5Nl5BMl5BanBnXkFtZTgwMjM0MTI2MDE@._V1_SY1000_CR0,0,1498,1000_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMTQ2NDkwNDk5NV5BMl5BanBnXkFtZTgwNDM0MTI2MDE@._V1_SY1000_CR0,0,1495,1000_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMTM4NDcyNDMzMF5BMl5BanBnXkFtZTgwOTI0MTI2MDE@._V1_SY1000_CR0,0,1495,1000_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMTAzMTczMjM3NjFeQTJeQWpwZ15BbWU4MDc1MTI1MzAx._V1_SY1000_CR0,0,1495,1000_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMjA5MTE3MTgwMF5BMl5BanBnXkFtZTgwOTQxMjUzMDE@._V1_SX1500_CR0,0,1500,999_AL_.jpg" ), rating = "9.5" ), MovieData( id = "tt2707408", title = "Narcos", year = "2015-", genre = "Biography, Crime, Drama", director = "N/A", actors = "Wagner Moura, Boyd Holbrook, Pedro Pascal, Joanna Christie", plot = "A chronicled look at the criminal exploits of Colombian drug lord Pablo Escobar.", poster = "http://ia.media-imdb.com/images/M/MV5BMTU0ODQ4NDg2OF5BMl5BanBnXkFtZTgwNzczNTE4OTE@._V1_SX300.jpg", images = listOf( "https://images-na.ssl-images-amazon.com/images/M/MV5BMTk2MDMzMTc0MF5BMl5BanBnXkFtZTgwMTAyMzA1OTE@._V1_SX1500_CR0,0,1500,999_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMjIxMDkyOTEyNV5BMl5BanBnXkFtZTgwNjY3Mjc3OTE@._V1_SY1000_SX1500_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMjA2NDUwMTU2NV5BMl5BanBnXkFtZTgwNTI1Mzc3OTE@._V1_SY1000_CR0,0,1499,1000_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BODA1NjAyMTQ3Ml5BMl5BanBnXkFtZTgwNjI1Mzc3OTE@._V1_SY1000_CR0,0,1499,1000_AL_.jpg", "https://images-na.ssl-images-amazon.com/images/M/MV5BMTU0NzQ0OTAwNl5BMl5BanBnXkFtZTgwMDAyMzA1OTE@._V1_SX1500_CR0,0,1500,999_AL_.jpg" ), rating = "9.5" ), ) }
MovieX/app/src/main/java/com/example/moviex/models/MovieModel.kt
1567798328
package com.example.moviex.screens.home import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.navigation.NavController import com.example.moviex.models.MovieData import com.example.moviex.models.getMovies import com.example.moviex.navigation.MovieNavigation import com.example.moviex.navigation.MovieScreens import com.example.moviex.widgets.MovieRow val movies: List<MovieData> = getMovies() @OptIn(ExperimentalMaterial3Api::class) @Composable fun HomeScreen(navController: NavController){ // A surface container using the 'background' color from the theme Scaffold( topBar = { TopAppBar( colors = TopAppBarDefaults.topAppBarColors( containerColor = MaterialTheme.colorScheme.primary, titleContentColor = MaterialTheme.colorScheme.primary, ), title = { Text( text = "Movies", style = MaterialTheme.typography.titleMedium.copy( color = Color.White ) ) }) } ) { Box(modifier = Modifier.padding(it)) { Column { LazyColumn { items(movies.size) { MovieRow(movie = movies[it]) {movie-> navController.navigate(route = MovieScreens.DetailScreen.name + "/$movie") } } } } } } }
MovieX/app/src/main/java/com/example/moviex/screens/home/HomeScreen.kt
4266258633
@file:OptIn(ExperimentalMaterial3Api::class) package com.example.moviex.screens.details 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.Spacer import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyRow import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.ArrowBack import androidx.compose.material3.BottomAppBar import androidx.compose.material3.CenterAlignedTopAppBar import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.FloatingActionButton import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBarDefaults.topAppBarColors import androidx.compose.runtime.Composable 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.style.TextAlign import androidx.compose.ui.text.toLowerCase import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.navigation.NavController import coil.compose.AsyncImage import coil.request.ImageRequest import coil.transform.CircleCropTransformation import com.example.moviex.models.getMovies import com.example.moviex.widgets.MovieRow @OptIn(ExperimentalMaterial3Api::class) @Composable fun DetailsScreen(navController: NavController, movieData: String?) { val movieInfo = getMovies().first { it.id == movieData } Surface( modifier = Modifier .fillMaxHeight() .fillMaxWidth() ) { Scaffold( topBar = { CenterAlignedTopAppBar( navigationIcon = { Icon(imageVector = Icons.Default.ArrowBack, contentDescription = "Arrow Back", modifier = Modifier.clickable { navController.popBackStack() } ) }, colors = topAppBarColors( containerColor = MaterialTheme.colorScheme.primaryContainer, titleContentColor = MaterialTheme.colorScheme.primary, ), title = { Column(horizontalAlignment = Alignment.CenterHorizontally) { Text( movieInfo.title, ) } } ) }, ) { innerPadding -> Column( modifier = Modifier .padding(innerPadding), verticalArrangement = Arrangement.spacedBy(16.dp), ) { MovieRow( movie = movieInfo ) Spacer(modifier = Modifier.height(5.dp)) Text( text = "Movie Images", modifier = Modifier.padding(10.dp) ) Spacer(modifier = Modifier.height(5.dp)) Box(modifier = Modifier.padding(10.dp)) { LazyRow { items(movieInfo.images.size) { AsyncImage( model = ImageRequest.Builder(LocalContext.current) .data(movieInfo.images[it]) .crossfade(true) .build(), modifier = Modifier .height(100.dp) .padding(5.dp), contentDescription = "Image poster", onState = { }, ) } } } } } } }
MovieX/app/src/main/java/com/example/moviex/screens/details/DetailsScreen.kt
3846243532
package com.example.moviex.widgets import androidx.compose.animation.AnimatedVisibility import androidx.compose.foundation.Image 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.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.AccountBox import androidx.compose.material.icons.filled.ArrowDropDown import androidx.compose.material.icons.filled.KeyboardArrowDown import androidx.compose.material.icons.filled.KeyboardArrowUp import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable 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.SpanStyle import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.font.FontVariation.width import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.withStyle import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import coil.compose.AsyncImage import coil.compose.rememberAsyncImagePainter import coil.request.ImageRequest import coil.transform.CircleCropTransformation import com.example.moviex.models.MovieData import com.example.moviex.models.getMovies @Preview @Composable fun MovieRow( movie: MovieData = getMovies()[0], onClick: (String) -> Unit = {} ) { val expended = remember { mutableStateOf(false) } Card( modifier = Modifier .fillMaxWidth() // .height(200.dp) .padding(20.dp) .clickable { onClick(movie.id) }, colors = CardDefaults.cardColors( containerColor = MaterialTheme.colorScheme.surface, ), elevation = CardDefaults.cardElevation( defaultElevation = 3.dp ), ) { Row( horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically ) { Surface( modifier = Modifier .padding(5.dp) .size(120.dp) ) { AsyncImage( model = ImageRequest.Builder(LocalContext.current) .data(movie.images[0]).transformations( CircleCropTransformation() ) .crossfade(true) .build(), contentDescription = "Image poster", onState = { }, ) } Spacer(modifier = Modifier.size(width = 8.dp, height = 1.dp)) Column( modifier = Modifier.padding(4.dp) ) { Spacer(modifier = Modifier.height(3.dp)) Text( text = movie.title, style = MaterialTheme.typography.bodyMedium ) Spacer(modifier = Modifier.height(3.dp)) Text( text = "Director: ${movie.director}", style = MaterialTheme.typography.labelSmall ) Spacer(modifier = Modifier.height(3.dp)) Text( text = "Released: ${movie.year}", style = MaterialTheme.typography.labelSmall ) //icon to expand Spacer(modifier = Modifier.height(4.dp)) Row( modifier = Modifier.clickable { expended.value = !expended.value } ) { Text( text =if(!expended.value) "View more" else "View less", style = MaterialTheme.typography.labelSmall ) Spacer(modifier = Modifier.width(0.2.dp)) Icon( imageVector = if(!expended.value) Icons.Default.KeyboardArrowDown else Icons.Default.KeyboardArrowUp, tint = Color.DarkGray, contentDescription = "Drop down arrow", ) } AnimatedVisibility(visible = expended.value) { Column { Text(text = buildAnnotatedString { withStyle( style = SpanStyle( fontSize = 11.sp, color = Color.DarkGray ) ) { append("Plot") } withStyle( style = SpanStyle( fontSize = 11.sp, fontWeight = FontWeight.Bold ) ) { append(" ${movie.plot}") } }) } } } } } }
MovieX/app/src/main/java/com/example/moviex/widgets/MovieCard.kt
1015785766
package com.slicedwork.turtlepace import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 import org.junit.Test import org.junit.runner.RunWith import org.junit.Assert.* /** * Instrumented test, which will execute on an Android device. * * See [testing documentation](http://d.android.com/tools/testing). */ @RunWith(AndroidJUnit4::class) class ExampleInstrumentedTest { @Test fun useAppContext() { // Context of the app under test. val appContext = InstrumentationRegistry.getInstrumentation().targetContext assertEquals("com.slicedwork.turtlepace", appContext.packageName) } }
TurtlePace/app/src/androidTest/java/com/slicedwork/turtlepace/ExampleInstrumentedTest.kt
4154882916
package com.slicedwork.turtlepace import org.junit.Test import org.junit.Assert.* /** * Example local unit test, which will execute on the development machine (host). * * See [testing documentation](http://d.android.com/tools/testing). */ class ExampleUnitTest { @Test fun addition_isCorrect() { assertEquals(4, 2 + 2) } }
TurtlePace/app/src/test/java/com/slicedwork/turtlepace/ExampleUnitTest.kt
4007657693
package com.slicedwork.turtlepace.ui.theme import androidx.compose.ui.graphics.Color val Purple80 = Color(0xFFD0BCFF) val PurpleGrey80 = Color(0xFFCCC2DC) val Pink80 = Color(0xFFEFB8C8) val Purple40 = Color(0xFF6650a4) val PurpleGrey40 = Color(0xFF625b71) val Pink40 = Color(0xFF7D5260)
TurtlePace/app/src/main/java/com/slicedwork/turtlepace/ui/theme/Color.kt
11488945
package com.slicedwork.turtlepace.ui.theme import android.app.Activity import android.os.Build import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material3.MaterialTheme import androidx.compose.material3.darkColorScheme import androidx.compose.material3.dynamicDarkColorScheme import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable import androidx.compose.runtime.SideEffect import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalView import androidx.core.view.WindowCompat private val DarkColorScheme = darkColorScheme( primary = Purple80, secondary = PurpleGrey80, tertiary = Pink80 ) private val LightColorScheme = lightColorScheme( primary = Purple40, secondary = PurpleGrey40, tertiary = Pink40 /* Other default colors to override background = Color(0xFFFFFBFE), surface = Color(0xFFFFFBFE), onPrimary = Color.White, onSecondary = Color.White, onTertiary = Color.White, onBackground = Color(0xFF1C1B1F), onSurface = Color(0xFF1C1B1F), */ ) @Composable fun TurtlePaceTheme( darkTheme: Boolean = isSystemInDarkTheme(), // Dynamic color is available on Android 12+ dynamicColor: Boolean = true, content: @Composable () -> Unit ) { val colorScheme = when { dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { val context = LocalContext.current if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) } darkTheme -> DarkColorScheme else -> LightColorScheme } val view = LocalView.current if (!view.isInEditMode) { SideEffect { val window = (view.context as Activity).window window.statusBarColor = colorScheme.primary.toArgb() WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme } } MaterialTheme( colorScheme = colorScheme, typography = Typography, content = content ) }
TurtlePace/app/src/main/java/com/slicedwork/turtlepace/ui/theme/Theme.kt
1049822002
package com.slicedwork.turtlepace.ui.theme import androidx.compose.material3.Typography import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.sp // Set of Material typography styles to start with val Typography = Typography( bodyLarge = TextStyle( fontFamily = FontFamily.Default, fontWeight = FontWeight.Normal, fontSize = 16.sp, lineHeight = 24.sp, letterSpacing = 0.5.sp ) /* Other default text styles to override titleLarge = TextStyle( fontFamily = FontFamily.Default, fontWeight = FontWeight.Normal, fontSize = 22.sp, lineHeight = 28.sp, letterSpacing = 0.sp ), labelSmall = TextStyle( fontFamily = FontFamily.Default, fontWeight = FontWeight.Medium, fontSize = 11.sp, lineHeight = 16.sp, letterSpacing = 0.5.sp ) */ )
TurtlePace/app/src/main/java/com/slicedwork/turtlepace/ui/theme/Type.kt
1991952894
package com.slicedwork.turtlepace import android.graphics.drawable.shapes.Shape import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.Button import androidx.compose.material3.FloatingActionButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Shapes import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import com.slicedwork.turtlepace.ui.theme.TurtlePaceTheme class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { TurtlePaceTheme { // A surface container using the 'background' color from the theme Surface( modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background, ) { Greeting("Android") } } } } } @Composable fun Greeting(name: String, modifier: Modifier = Modifier) { Column { Text( text = "Hello $name!", modifier = modifier, ) } } @Preview(showBackground = true) @Composable fun GreetingPreview() { TurtlePaceTheme { Greeting("Android") } }
TurtlePace/app/src/main/java/com/slicedwork/turtlepace/MainActivity.kt
2676136357
package com.github.urbanbyte.formatplugin import com.intellij.ide.highlighter.XmlFileType import com.intellij.openapi.components.service import com.intellij.psi.xml.XmlFile import com.intellij.testFramework.TestDataPath import com.intellij.testFramework.fixtures.BasePlatformTestCase import com.intellij.util.PsiErrorElementUtil import com.github.urbanbyte.formatplugin.services.MyProjectService @TestDataPath("\$CONTENT_ROOT/src/test/testData") class MyPluginTest : BasePlatformTestCase() { fun testXMLFile() { val psiFile = myFixture.configureByText(XmlFileType.INSTANCE, "<foo>bar</foo>") val xmlFile = assertInstanceOf(psiFile, XmlFile::class.java) assertFalse(PsiErrorElementUtil.hasErrors(project, xmlFile.virtualFile)) assertNotNull(xmlFile.rootTag) xmlFile.rootTag?.let { assertEquals("foo", it.name) assertEquals("bar", it.value.text) } } fun testRename() { myFixture.testRename("foo.xml", "foo_after.xml", "a2") } fun testProjectService() { val projectService = project.service<MyProjectService>() assertNotSame(projectService.getRandomNumber(), projectService.getRandomNumber()) } override fun getTestDataPath() = "src/test/testData/rename" }
Format_plugin/src/test/kotlin/com/github/urbanbyte/formatplugin/MyPluginTest.kt
2926282987
package com.github.urbanbyte.formatplugin.toolWindow import com.intellij.openapi.components.service import com.intellij.openapi.diagnostic.thisLogger import com.intellij.openapi.project.Project import com.intellij.openapi.wm.ToolWindow import com.intellij.openapi.wm.ToolWindowFactory import com.intellij.ui.components.JBLabel import com.intellij.ui.components.JBPanel import com.intellij.ui.content.ContentFactory import com.github.urbanbyte.formatplugin.MyBundle import com.github.urbanbyte.formatplugin.services.MyProjectService import javax.swing.JButton class MyToolWindowFactory : ToolWindowFactory { init { thisLogger().warn("Don't forget to remove all non-needed sample code files with their corresponding registration entries in `plugin.xml`.") } override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) { val myToolWindow = MyToolWindow(toolWindow) val content = ContentFactory.getInstance().createContent(myToolWindow.getContent(), null, false) toolWindow.contentManager.addContent(content) } override fun shouldBeAvailable(project: Project) = true class MyToolWindow(toolWindow: ToolWindow) { private val service = toolWindow.project.service<MyProjectService>() fun getContent() = JBPanel<JBPanel<*>>().apply { val label = JBLabel(MyBundle.message("randomLabel", "?")) add(label) add(JButton(MyBundle.message("shuffle")).apply { addActionListener { label.text = MyBundle.message("randomLabel", service.getRandomNumber()) } }) } } }
Format_plugin/src/main/kotlin/com/github/urbanbyte/formatplugin/toolWindow/MyToolWindowFactory.kt
2241548586
package com.github.urbanbyte.formatplugin import com.intellij.DynamicBundle import org.jetbrains.annotations.NonNls import org.jetbrains.annotations.PropertyKey @NonNls private const val BUNDLE = "messages.MyBundle" object MyBundle : DynamicBundle(BUNDLE) { @JvmStatic fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) = getMessage(key, *params) @Suppress("unused") @JvmStatic fun messagePointer(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) = getLazyMessage(key, *params) }
Format_plugin/src/main/kotlin/com/github/urbanbyte/formatplugin/MyBundle.kt
2038491385
package com.github.urbanbyte.formatplugin.listeners import com.intellij.openapi.application.ApplicationActivationListener import com.intellij.openapi.diagnostic.thisLogger import com.intellij.openapi.wm.IdeFrame internal class MyApplicationActivationListener : ApplicationActivationListener { override fun applicationActivated(ideFrame: IdeFrame) { thisLogger().warn("Don't forget to remove all non-needed sample code files with their corresponding registration entries in `plugin.xml`.") } }
Format_plugin/src/main/kotlin/com/github/urbanbyte/formatplugin/listeners/MyApplicationActivationListener.kt
1959971242
package com.github.urbanbyte.formatplugin.services import com.intellij.openapi.components.Service import com.intellij.openapi.diagnostic.thisLogger import com.intellij.openapi.project.Project import com.github.urbanbyte.formatplugin.MyBundle @Service(Service.Level.PROJECT) class MyProjectService(project: Project) { init { thisLogger().info(MyBundle.message("projectService", project.name)) thisLogger().warn("Don't forget to remove all non-needed sample code files with their corresponding registration entries in `plugin.xml`.") } fun getRandomNumber() = (1..100).random() }
Format_plugin/src/main/kotlin/com/github/urbanbyte/formatplugin/services/MyProjectService.kt
2527375815
package com.mlp.simpleaction import com.mlp.sdk.MlpException import com.mlp.sdk.MlpExecutionContext import com.mlp.sdk.MlpPredictServiceBase import com.mlp.sdk.MlpServiceSDK data class SimpleTestActionRequest( val action: String, val name: String ) class SimpleTestAction( override val context: MlpExecutionContext ) : MlpPredictServiceBase<SimpleTestActionRequest, String>(REQUEST_EXAMPLE, RESPONSE_EXAMPLE) { override fun predict(req: SimpleTestActionRequest): String { return when (req.action) { "hello" -> "Hello ${req.name}!" "envs" -> "Envs: ${context.environment.envsOverride}" else -> throw MlpException("actionUnknownException") } } companion object { val REQUEST_EXAMPLE = SimpleTestActionRequest("hello", "World") val RESPONSE_EXAMPLE = "Hello World!" } } fun main() { val actionSDK = MlpServiceSDK({ SimpleTestAction(MlpExecutionContext.systemContext) }) actionSDK.start() actionSDK.blockUntilShutdown() }
mlp-java-service-template/src/main/kotlin/com/mlp/simpleaction/Main.kt
2207916835
import com.github.ajalt.clikt.core.CliktCommand import com.github.ajalt.clikt.parameters.options.default import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.options.transformAll import com.github.ajalt.clikt.parameters.options.varargValues import com.github.ajalt.clikt.parameters.types.int import com.github.ajalt.clikt.parameters.types.path import io.ktor.network.sockets.InetSocketAddress import java.nio.file.Path import kotlin.io.path.Path import kotlin.io.path.div public class Args : CliktCommand() { public val port: Int by option().int().default(6379) public val replicaof: InetSocketAddress? by option().varargValues(min = 2, max = 2) .transformAll { argPairs -> if (argPairs.isEmpty()) return@transformAll null val (it) = argPairs InetSocketAddress(it[0], it[1].toInt()) } public val dir: Path? by option().path() public val dbfilename: String? by option() public val dbFile: Path? get() { val filename = dbfilename ?: return null val dir = dir ?: Path(".") return dir / filename } override fun toString(): String = "Args(port=$port, dir=$dir, dbfilename=$dbfilename, replicaof=$replicaof)" @Suppress("EmptyFunctionBlock") override fun run() {} }
codecrafters-redis-kotlin/src/main/kotlin/Args.kt
3808557194
@file:Suppress("FunctionNaming") package redis.response import redis.protocol.resp2.Resp2 public sealed class Response public data object None : Response() public data object Upgrade : Response() public data class Resp2Response(val body: Resp2) : Response() public fun SimpleResponse(body: String): Response = Resp2Response(Resp2.String(body)) public fun NumberResponse(value: Int): Response = Resp2Response(Resp2.Number(value)) public val NullResponse: Response = Resp2Response(Resp2.Nil) public fun ArrayResponse(body: List<String>): Response = Resp2Response( Resp2.List(body), ) public fun ErrorResponse(message: String): Response = Resp2Response(Resp2.Error(message))
codecrafters-redis-kotlin/src/main/kotlin/redis/response/Response.kt
1626927097
package redis.connection import io.ktor.utils.io.writeFully import io.ktor.utils.io.writeStringUtf8 import redis.protocol.resp2.Resp2 public class ReplicaConnection(former: Connection) : Connection(former) { internal val bytesWritten get() = write.totalBytesWritten - handshakeSize private var handshakeSize: Long = 0L public suspend fun sendRdb(payload: ByteArray) { write.writeStringUtf8("\$${payload.size}\r\n") write.writeFully(payload) handshakeSize = write.totalBytesWritten } public suspend fun sendSimple(request: String) { send(Resp2.String(request)) } public val id: String = "replica#$remoteAddress" public companion object }
codecrafters-redis-kotlin/src/main/kotlin/redis/connection/ReplicaConnection.kt
2872451839
package redis.connection import io.ktor.network.sockets.Socket import io.ktor.network.sockets.SocketAddress import io.ktor.network.sockets.openReadChannel import io.ktor.network.sockets.openWriteChannel import io.ktor.utils.io.ByteReadChannel import io.ktor.utils.io.ByteWriteChannel import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.channels.ClosedReceiveChannelException import kotlinx.coroutines.channels.ReceiveChannel import kotlinx.coroutines.flow.buffer import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.produceIn import redis.protocol.resp2.Resp2 import redis.protocol.resp2.decode import redis.protocol.resp2.encode import redis.response.None import redis.response.Resp2Response import redis.response.Response import redis.response.Upgrade import kotlin.coroutines.CoroutineContext public abstract class Connection( private val raw: Socket, protected val read: ByteReadChannel = raw.openReadChannel(), protected val write: ByteWriteChannel = raw.openWriteChannel(autoFlush = true), ) { protected constructor(other: Connection) : this(other.raw, other.read, other.write) public val remoteAddress: SocketAddress get() = raw.remoteAddress @Suppress("UncheckedCast") internal suspend inline fun <reified T : Resp2> receive(): T = Resp2.decode(source = read) as T internal suspend fun<T : Resp2> send(value: T) { value.encode(write) } public fun commands(context: CoroutineContext): ReceiveChannel<List<String>> = flow { try { while (true) { val command = receiveCommand() emit(command) } } catch (_: ClosedReceiveChannelException) { return@flow } } .buffer(0) .produceIn(CoroutineScope(context + Dispatchers.Default)) public suspend fun sendCommand(commands: List<String>) { Resp2.List(commands).encode(write) } } public suspend fun Connection.receiveCommand(): List<String> = receive<Resp2.List>() .values .map { val string = it as? Resp2.String ?: error("Expected ro receive list of strings") string.value } internal suspend fun Response.writeTo(output: ByteWriteChannel) { when (this) { Upgrade, None -> {} is Resp2Response -> body.encode(sink = output) } }
codecrafters-redis-kotlin/src/main/kotlin/redis/connection/Connection.kt
953541279
package redis.connection import io.ktor.network.sockets.SocketAddress public class ClientConnectionState( public val address: SocketAddress, public var listeningPort: Int? = null, public val capabilities: MutableList<String> = mutableListOf(), )
codecrafters-redis-kotlin/src/main/kotlin/redis/connection/ClientConnectionState.kt
425387302