path
stringlengths
4
297
contentHash
stringlengths
1
10
content
stringlengths
0
13M
AndroidLearning/compose-training-lunch-tray/app/src/main/java/com/example/lunchtray/model/MenuItem.kt
2124744105
/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.lunchtray.model import java.text.NumberFormat sealed class MenuItem( open val name: String, open val description: String, open val price: Double ) { /** * Getter method for price. * Includes formatting. */ data class EntreeItem( override val name: String, override val description: String, override val price: Double ) : MenuItem(name, description, price) data class SideDishItem( override val name: String, override val description: String, override val price: Double ) : MenuItem(name, description, price) data class AccompanimentItem( override val name: String, override val description: String, override val price: Double ) : MenuItem(name, description, price) /** * Getter method for price. * Includes formatting. */ fun getFormattedPrice(): String = NumberFormat.getCurrencyInstance().format(price) }
AndroidLearning/compose-training-lunch-tray/app/src/main/java/com/example/lunchtray/model/OrderUiState.kt
3341595473
/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.lunchtray.model data class OrderUiState( // Entree Selection val entree: MenuItem.EntreeItem? = null, val sideDish: MenuItem.SideDishItem? = null, val accompaniment: MenuItem.AccompanimentItem? = null, val itemTotalPrice: Double = 0.0, val orderTax: Double = 0.0, val orderTotalPrice: Double = 0.0 )
AndroidLearning/compose-training-cupcake/app/src/androidTest/java/com/example/cupcake/test/ComposeRuleExtensions.kt
3917163553
package com.example.cupcake.test import androidx.activity.ComponentActivity import androidx.annotation.StringRes import androidx.compose.ui.test.SemanticsNodeInteraction import androidx.compose.ui.test.junit4.AndroidComposeTestRule import androidx.compose.ui.test.onNodeWithText import androidx.test.ext.junit.rules.ActivityScenarioRule fun <A : ComponentActivity> AndroidComposeTestRule<ActivityScenarioRule<A>, A>.onNodeWithStringId(@StringRes id: Int): SemanticsNodeInteraction = onNodeWithText(activity.getString(id))
AndroidLearning/compose-training-cupcake/app/src/androidTest/java/com/example/cupcake/test/ScreenAssertions.kt
378215826
package com.example.cupcake.test import androidx.navigation.NavController import org.junit.Assert.assertEquals fun NavController.assertCurrentRouteName(expectedRouteName: String) { assertEquals(expectedRouteName, currentBackStackEntry?.destination?.route) }
AndroidLearning/compose-training-cupcake/app/src/androidTest/java/com/example/cupcake/test/CupcakeScreenNavigationTest.kt
3527858392
package com.example.cupcake.test import androidx.activity.ComponentActivity import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import androidx.navigation.compose.ComposeNavigator import androidx.navigation.testing.TestNavHostController import com.example.cupcake.CupcakeApp import com.example.cupcake.CupcakeScreen import com.example.cupcake.R import org.junit.Before import org.junit.Rule import org.junit.Test import java.text.SimpleDateFormat import java.util.Calendar import java.util.Locale class CupcakeScreenNavigationTest { @get:Rule val composeTestRule = createAndroidComposeRule<ComponentActivity>() private lateinit var navController: TestNavHostController @Before fun setupCupcakeNavHost() { composeTestRule.setContent { navController = TestNavHostController(LocalContext.current).apply { navigatorProvider.addNavigator(ComposeNavigator()) } CupcakeApp(navController = navController) } } @Test fun cupcakeNavHost_verifyStartDestination() { navController.assertCurrentRouteName(CupcakeScreen.Start.name) } @Test fun cupcakeNavHost_verifyBackNavigationNotShownOnStartOrderScreen() { val backText = composeTestRule.activity.getString(R.string.back_button) composeTestRule.onNodeWithContentDescription(backText).assertDoesNotExist() } @Test fun cupcakeNavHost_clickOneCupcake_navigatesToSelectFlavorScreen() { composeTestRule.onNodeWithStringId(R.string.one_cupcake) .performClick() navController.assertCurrentRouteName(CupcakeScreen.Flavor.name) } @Test fun cupcakeNavHost_clickNextOnFlavorScreen_navigatesToPickupScreen() { navigateToFlavorScreen() composeTestRule.onNodeWithStringId(R.string.next) .performClick() navController.assertCurrentRouteName(CupcakeScreen.Pickup.name) } @Test fun cupcakeNavHost_clickBackOnFlavorScreen_navigatesToStartOrderScreen() { navigateToFlavorScreen() performNavigateUp() navController.assertCurrentRouteName(CupcakeScreen.Start.name) } @Test fun cupcakeNavHost_clickCancelOnFlavorScreen_navigatesToStartOrderScreen() { navigateToFlavorScreen() composeTestRule.onNodeWithStringId(R.string.cancel) .performClick() navController.assertCurrentRouteName(CupcakeScreen.Start.name) } @Test fun cupcakeNavHost_clickNextOnPickupScreen_navigatesToSummaryScreen() { navigateToPickupScreen() composeTestRule.onNodeWithText(getFormattedDate()) .performClick() composeTestRule.onNodeWithStringId(R.string.next) .performClick() navController.assertCurrentRouteName(CupcakeScreen.Summary.name) } @Test fun cupcakeNavHost_clickBackOnPickupScreen_navigatesToFlavorScreen() { navigateToPickupScreen() performNavigateUp() navController.assertCurrentRouteName(CupcakeScreen.Flavor.name) } @Test fun cupcakeNavHost_clickCancelOnPickupScreen_navigatesToStartOrderScreen() { navigateToPickupScreen() composeTestRule.onNodeWithStringId(R.string.cancel) .performClick() navController.assertCurrentRouteName(CupcakeScreen.Start.name) } @Test fun cupcakeNavHost_clickCancelOnSummaryScreen_navigatesToStartOrderScreen() { navigateToSummaryScreen() composeTestRule.onNodeWithStringId(R.string.cancel) .performClick() navController.assertCurrentRouteName(CupcakeScreen.Start.name) } private fun navigateToFlavorScreen() { composeTestRule.onNodeWithStringId(R.string.one_cupcake) .performClick() composeTestRule.onNodeWithStringId(R.string.chocolate) .performClick() } private fun navigateToPickupScreen() { navigateToFlavorScreen() composeTestRule.onNodeWithStringId(R.string.next) .performClick() } private fun navigateToSummaryScreen() { navigateToPickupScreen() composeTestRule.onNodeWithText(getFormattedDate()) .performClick() composeTestRule.onNodeWithStringId(R.string.next) .performClick() } private fun performNavigateUp() { val backText = composeTestRule.activity.getString(R.string.back_button) composeTestRule.onNodeWithContentDescription(backText).performClick() } private fun getFormattedDate(): String { val calendar = Calendar.getInstance() calendar.add(java.util.Calendar.DATE, 1) val formatter = SimpleDateFormat("E MMM d", Locale.getDefault()) return formatter.format(calendar.time) } }
AndroidLearning/compose-training-cupcake/app/src/androidTest/java/com/example/cupcake/test/CupcakeOrderScreenTest.kt
2485442232
package com.example.cupcake.test import androidx.activity.ComponentActivity import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.assertIsEnabled import androidx.compose.ui.test.assertIsNotEnabled import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import com.example.cupcake.R import com.example.cupcake.ui.SelectOptionScreen import org.junit.Rule import org.junit.Test class CupcakeOrderScreenTest { @get:Rule val composeTestRule = createAndroidComposeRule<ComponentActivity>() @Test fun selectOptionScreen_verifyContent() { val flavors = listOf("Vanilla", "Chocolate", "Hazelnut", "Cookie", "Mango") val subtotal = "$100" composeTestRule.setContent { SelectOptionScreen( subtotal = subtotal, options = flavors ) } flavors.forEach { composeTestRule.onNodeWithText(it).assertIsDisplayed() } composeTestRule.onNodeWithText( composeTestRule.activity.getString( R.string.subtotal_price, subtotal ) ).assertIsDisplayed() composeTestRule.onNodeWithStringId(R.string.next).assertIsNotEnabled() composeTestRule.onNodeWithText(flavors[0]).performClick() composeTestRule.onNodeWithStringId(R.string.next).assertIsEnabled() } }
AndroidLearning/compose-training-cupcake/app/src/main/java/com/example/cupcake/ui/OrderViewModel.kt
97958473
/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.cupcake.ui import androidx.lifecycle.ViewModel import com.example.cupcake.data.OrderUiState import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.update import java.text.NumberFormat import java.text.SimpleDateFormat import java.util.Calendar import java.util.Locale /** Price for a single cupcake */ private const val PRICE_PER_CUPCAKE = 2.00 /** Additional cost for same day pickup of an order */ private const val PRICE_FOR_SAME_DAY_PICKUP = 3.00 /** * [OrderViewModel] holds information about a cupcake order in terms of quantity, flavor, and * pickup date. It also knows how to calculate the total price based on these order details. */ class OrderViewModel : ViewModel() { /** * Cupcake state for this order */ private val _uiState = MutableStateFlow(OrderUiState(pickupOptions = pickupOptions())) val uiState: StateFlow<OrderUiState> = _uiState.asStateFlow() /** * Set the quantity [numberCupcakes] of cupcakes for this order's state and update the price */ fun setQuantity(numberCupcakes: Int) { _uiState.update { currentState -> currentState.copy( quantity = numberCupcakes, price = calculatePrice(quantity = numberCupcakes) ) } } /** * Set the [desiredFlavor] of cupcakes for this order's state. * Only 1 flavor can be selected for the whole order. */ fun setFlavor(desiredFlavor: String) { _uiState.update { currentState -> currentState.copy(flavor = desiredFlavor) } } /** * Set the [pickupDate] for this order's state and update the price */ fun setDate(pickupDate: String) { _uiState.update { currentState -> currentState.copy( date = pickupDate, price = calculatePrice(pickupDate = pickupDate) ) } } /** * Reset the order state */ fun resetOrder() { _uiState.value = OrderUiState(pickupOptions = pickupOptions()) } /** * Returns the calculated price based on the order details. */ private fun calculatePrice( quantity: Int = _uiState.value.quantity, pickupDate: String = _uiState.value.date ): String { var calculatedPrice = quantity * PRICE_PER_CUPCAKE // If the user selected the first option (today) for pickup, add the surcharge if (pickupOptions()[0] == pickupDate) { calculatedPrice += PRICE_FOR_SAME_DAY_PICKUP } val formattedPrice = NumberFormat.getCurrencyInstance().format(calculatedPrice) return formattedPrice } /** * Returns a list of date options starting with the current date and the following 3 dates. */ private fun pickupOptions(): List<String> { val dateOptions = mutableListOf<String>() val formatter = SimpleDateFormat("E MMM d", Locale.getDefault()) val calendar = Calendar.getInstance() // add current date and the following 3 dates. repeat(4) { dateOptions.add(formatter.format(calendar.time)) calendar.add(Calendar.DATE, 1) } return dateOptions } }
AndroidLearning/compose-training-cupcake/app/src/main/java/com/example/cupcake/ui/SelectOptionScreen.kt
294905089
/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.cupcake.ui 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.selection.selectable import androidx.compose.material3.Button import androidx.compose.material3.Divider import androidx.compose.material3.OutlinedButton import androidx.compose.material3.RadioButton import androidx.compose.material3.Text 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.res.dimensionResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import com.example.cupcake.R import com.example.cupcake.ui.components.FormattedPriceLabel import com.example.cupcake.ui.theme.CupcakeTheme /** * Composable that displays the list of items as [RadioButton] options, * [onSelectionChanged] lambda that notifies the parent composable when a new value is selected, * [onCancelButtonClicked] lambda that cancels the order when user clicks cancel and * [onNextButtonClicked] lambda that triggers the navigation to next screen */ @Composable fun SelectOptionScreen( subtotal: String, options: List<String>, onSelectionChanged: (String) -> Unit = {}, onCancelButtonClicked: () -> Unit = {}, onNextButtonClicked: () -> Unit = {}, modifier: Modifier = Modifier ) { var selectedValue by rememberSaveable { mutableStateOf("") } Column( modifier = modifier, verticalArrangement = Arrangement.SpaceBetween ) { Column(modifier = Modifier.padding(dimensionResource(R.dimen.padding_medium))) { options.forEach { item -> Row( modifier = Modifier.selectable( selected = selectedValue == item, onClick = { selectedValue = item onSelectionChanged(item) } ), verticalAlignment = Alignment.CenterVertically ) { RadioButton( selected = selectedValue == item, onClick = { selectedValue = item onSelectionChanged(item) } ) Text(item) } } Divider( thickness = dimensionResource(R.dimen.thickness_divider), modifier = Modifier.padding(bottom = dimensionResource(R.dimen.padding_medium)) ) FormattedPriceLabel( subtotal = subtotal, modifier = Modifier .align(Alignment.End) .padding( top = dimensionResource(R.dimen.padding_medium), bottom = dimensionResource(R.dimen.padding_medium) ) ) } Row( modifier = Modifier .fillMaxWidth() .padding(dimensionResource(R.dimen.padding_medium)), horizontalArrangement = Arrangement.spacedBy(dimensionResource(R.dimen.padding_medium)), verticalAlignment = Alignment.Bottom ) { OutlinedButton( modifier = Modifier.weight(1f), onClick = { onCancelButtonClicked() } ) { Text(stringResource(R.string.cancel)) } Button( modifier = Modifier.weight(1f), // the button is enabled when the user makes a selection enabled = selectedValue.isNotEmpty(), onClick = { onNextButtonClicked() } ) { Text(stringResource(R.string.next)) } } } } @Preview @Composable fun SelectOptionPreview() { CupcakeTheme { SelectOptionScreen( subtotal = "299.99", options = listOf("Option 1", "Option 2", "Option 3", "Option 4"), modifier = Modifier.fillMaxHeight() ) } }
AndroidLearning/compose-training-cupcake/app/src/main/java/com/example/cupcake/ui/SummaryScreen.kt
1274787079
/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.cupcake.ui import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.material3.Button import androidx.compose.material3.Divider import androidx.compose.material3.OutlinedButton import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview import com.example.cupcake.R import com.example.cupcake.data.OrderUiState import com.example.cupcake.ui.components.FormattedPriceLabel import com.example.cupcake.ui.theme.CupcakeTheme /** * This composable expects [orderUiState] that represents the order state, [onCancelButtonClicked] * lambda that triggers canceling the order and passes the final order to [onSendButtonClicked] * lambda */ @Composable fun OrderSummaryScreen( orderUiState: OrderUiState, onCancelButtonClicked: () -> Unit, onSentButtonClicked: (String, String) -> Unit, modifier: Modifier = Modifier ) { val resources = LocalContext.current.resources val numberOfCupcakes = resources.getQuantityString( R.plurals.cupcakes, orderUiState.quantity, orderUiState.quantity ) //Load and format a string resource with the parameters. val orderSummary = stringResource( R.string.order_details, numberOfCupcakes, orderUiState.flavor, orderUiState.date, orderUiState.quantity ) val newOrder = stringResource(R.string.new_cupcake_order) //Create a list of order summary to display val items = listOf( // Summary line 1: display selected quantity Pair(stringResource(R.string.quantity), numberOfCupcakes), // Summary line 2: display selected flavor Pair(stringResource(R.string.flavor), orderUiState.flavor), // Summary line 3: display selected pickup date Pair(stringResource(R.string.pickup_date), orderUiState.date) ) Column( modifier = modifier, verticalArrangement = Arrangement.SpaceBetween ) { Column( modifier = Modifier.padding(dimensionResource(R.dimen.padding_medium)), verticalArrangement = Arrangement.spacedBy(dimensionResource(R.dimen.padding_small)) ) { items.forEach { item -> Text(item.first.uppercase()) Text(text = item.second, fontWeight = FontWeight.Bold) Divider(thickness = dimensionResource(R.dimen.thickness_divider)) } Spacer(modifier = Modifier.height(dimensionResource(R.dimen.padding_small))) FormattedPriceLabel( subtotal = orderUiState.price, modifier = Modifier.align(Alignment.End) ) } Row( modifier = Modifier.padding(dimensionResource(R.dimen.padding_medium)) ) { Column( verticalArrangement = Arrangement.spacedBy(dimensionResource(R.dimen.padding_small)) ) { Button( modifier = Modifier.fillMaxWidth(), onClick = { onSentButtonClicked(newOrder, orderSummary) } ) { Text(stringResource(R.string.send)) } OutlinedButton( modifier = Modifier.fillMaxWidth(), onClick = { onCancelButtonClicked() } ) { Text(stringResource(R.string.cancel)) } } } } } @Preview @Composable fun OrderSummaryPreview() { CupcakeTheme { OrderSummaryScreen( orderUiState = OrderUiState(0, "Test", "Test", "$300.00"), {}, { a, b -> }, modifier = Modifier.fillMaxHeight() ) } }
AndroidLearning/compose-training-cupcake/app/src/main/java/com/example/cupcake/ui/StartOrderScreen.kt
1249653009
/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.cupcake.ui import androidx.annotation.StringRes import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column 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.layout.width import androidx.compose.foundation.layout.widthIn import androidx.compose.material3.Button import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.dimensionResource 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 com.example.cupcake.R import com.example.cupcake.data.DataSource import com.example.cupcake.ui.theme.CupcakeTheme /** * Composable that allows the user to select the desired cupcake quantity and expects * [onNextButtonClicked] lambda that expects the selected quantity and triggers the navigation to * next screen */ @Composable fun StartOrderScreen( quantityOptions: List<Pair<Int, Int>>, onNextButtonClicked: (Int) -> Unit, modifier: Modifier = Modifier ) { Column( modifier = modifier, verticalArrangement = Arrangement.SpaceBetween ) { Column( modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(dimensionResource(R.dimen.padding_small)) ) { Spacer(modifier = Modifier.height(dimensionResource(R.dimen.padding_medium))) Image( painter = painterResource(R.drawable.cupcake), contentDescription = null, modifier = Modifier.width(300.dp) ) Spacer(modifier = Modifier.height(dimensionResource(R.dimen.padding_medium))) Text( text = stringResource(R.string.order_cupcakes), style = MaterialTheme.typography.headlineSmall ) Spacer(modifier = Modifier.height(dimensionResource(R.dimen.padding_small))) } Column( modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy( dimensionResource(id = R.dimen.padding_medium) ) ) { quantityOptions.forEach { item -> SelectQuantityButton( labelResourceId = item.first, onClick = {onNextButtonClicked(item.second)} ) } } } } /** * Customizable button composable that displays the [labelResourceId] * and triggers [onClick] lambda when this composable is clicked */ @Composable fun SelectQuantityButton( @StringRes labelResourceId: Int, onClick: () -> Unit, modifier: Modifier = Modifier ) { Button( onClick = onClick, modifier = modifier.widthIn(min = 250.dp) ) { Text(stringResource(labelResourceId)) } } @Preview @Composable fun StartOrderPreview() { CupcakeTheme { StartOrderScreen( quantityOptions = DataSource.quantityOptions, onNextButtonClicked = {}, modifier = Modifier .fillMaxSize() .padding(dimensionResource(R.dimen.padding_medium)) ) } }
AndroidLearning/compose-training-cupcake/app/src/main/java/com/example/cupcake/ui/components/CommonUi.kt
3238236991
/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.cupcake.ui.components import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import com.example.cupcake.R /** * Composable that displays formatted [price] that will be formatted and displayed on screen */ @Composable fun FormattedPriceLabel(subtotal: String, modifier: Modifier = Modifier) { Text( text = stringResource(R.string.subtotal_price, subtotal), modifier = modifier, style = MaterialTheme.typography.headlineSmall ) }
AndroidLearning/compose-training-cupcake/app/src/main/java/com/example/cupcake/ui/theme/Color.kt
3674021801
/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.cupcake.ui.theme import androidx.compose.ui.graphics.Color val md_theme_light_primary = Color(0xFF984062) val md_theme_light_onPrimary = Color(0xFFFFFFFF) val md_theme_light_primaryContainer = Color(0xFFFFD9E2) val md_theme_light_onPrimaryContainer = Color(0xFF3E001E) val md_theme_light_secondary = Color(0xFF74565F) val md_theme_light_onSecondary = Color(0xFFFFFFFF) val md_theme_light_secondaryContainer = Color(0xFFFFD9E2) val md_theme_light_onSecondaryContainer = Color(0xFF2B151C) val md_theme_light_tertiary = Color(0xFF7C5635) val md_theme_light_onTertiary = Color(0xFFFFFFFF) val md_theme_light_tertiaryContainer = Color(0xFFFFDCC2) val md_theme_light_onTertiaryContainer = Color(0xFF2E1500) val md_theme_light_error = Color(0xFFBA1A1A) val md_theme_light_errorContainer = Color(0xFFFFDAD6) val md_theme_light_onError = Color(0xFFFFFFFF) val md_theme_light_onErrorContainer = Color(0xFF410002) val md_theme_light_background = Color(0xFFFFFBFF) val md_theme_light_onBackground = Color(0xFF201A1B) val md_theme_light_surface = Color(0xFFFFFBFF) val md_theme_light_onSurface = Color(0xFF201A1B) val md_theme_light_surfaceVariant = Color(0xFFF2DDE2) val md_theme_light_onSurfaceVariant = Color(0xFF514347) val md_theme_light_outline = Color(0xFF837377) val md_theme_light_inverseOnSurface = Color(0xFFFAEEEF) val md_theme_light_inverseSurface = Color(0xFF352F30) val md_theme_light_inversePrimary = Color(0xFFFFB0C9) val md_theme_light_surfaceTint = Color(0xFF984062) val md_theme_light_outlineVariant = Color(0xFFD5C2C6) val md_theme_light_scrim = Color(0xFF000000) val md_theme_dark_primary = Color(0xFFFFB0C9) val md_theme_dark_onPrimary = Color(0xFF5E1133) val md_theme_dark_primaryContainer = Color(0xFF7B294A) val md_theme_dark_onPrimaryContainer = Color(0xFFFFD9E2) val md_theme_dark_secondary = Color(0xFFE2BDC7) val md_theme_dark_onSecondary = Color(0xFF422931) val md_theme_dark_secondaryContainer = Color(0xFF5A3F47) val md_theme_dark_onSecondaryContainer = Color(0xFFFFD9E2) val md_theme_dark_tertiary = Color(0xFFEFBD94) val md_theme_dark_onTertiary = Color(0xFF48290C) val md_theme_dark_tertiaryContainer = Color(0xFF623F20) val md_theme_dark_onTertiaryContainer = Color(0xFFFFDCC2) val md_theme_dark_error = Color(0xFFFFB4AB) val md_theme_dark_errorContainer = Color(0xFF93000A) val md_theme_dark_onError = Color(0xFF690005) val md_theme_dark_onErrorContainer = Color(0xFFFFDAD6) val md_theme_dark_background = Color(0xFF201A1B) val md_theme_dark_onBackground = Color(0xFFEBE0E1) val md_theme_dark_surface = Color(0xFF201A1B) val md_theme_dark_onSurface = Color(0xFFEBE0E1) val md_theme_dark_surfaceVariant = Color(0xFF514347) val md_theme_dark_onSurfaceVariant = Color(0xFFD5C2C6) val md_theme_dark_outline = Color(0xFF9E8C90) val md_theme_dark_inverseOnSurface = Color(0xFF201A1B) val md_theme_dark_inverseSurface = Color(0xFFEBE0E1) val md_theme_dark_inversePrimary = Color(0xFF984062) val md_theme_dark_surfaceTint = Color(0xFFFFB0C9) val md_theme_dark_outlineVariant = Color(0xFF514347) val md_theme_dark_scrim = Color(0xFF000000)
AndroidLearning/compose-training-cupcake/app/src/main/java/com/example/cupcake/ui/theme/Theme.kt
4049201284
/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.cupcake.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 LightColors = lightColorScheme( primary = md_theme_light_primary, onPrimary = md_theme_light_onPrimary, primaryContainer = md_theme_light_primaryContainer, onPrimaryContainer = md_theme_light_onPrimaryContainer, secondary = md_theme_light_secondary, onSecondary = md_theme_light_onSecondary, secondaryContainer = md_theme_light_secondaryContainer, onSecondaryContainer = md_theme_light_onSecondaryContainer, tertiary = md_theme_light_tertiary, onTertiary = md_theme_light_onTertiary, tertiaryContainer = md_theme_light_tertiaryContainer, onTertiaryContainer = md_theme_light_onTertiaryContainer, error = md_theme_light_error, errorContainer = md_theme_light_errorContainer, onError = md_theme_light_onError, onErrorContainer = md_theme_light_onErrorContainer, background = md_theme_light_background, onBackground = md_theme_light_onBackground, surface = md_theme_light_surface, onSurface = md_theme_light_onSurface, surfaceVariant = md_theme_light_surfaceVariant, onSurfaceVariant = md_theme_light_onSurfaceVariant, outline = md_theme_light_outline, inverseOnSurface = md_theme_light_inverseOnSurface, inverseSurface = md_theme_light_inverseSurface, inversePrimary = md_theme_light_inversePrimary, surfaceTint = md_theme_light_surfaceTint, outlineVariant = md_theme_light_outlineVariant, scrim = md_theme_light_scrim, ) private val DarkColors = darkColorScheme( primary = md_theme_dark_primary, onPrimary = md_theme_dark_onPrimary, primaryContainer = md_theme_dark_primaryContainer, onPrimaryContainer = md_theme_dark_onPrimaryContainer, secondary = md_theme_dark_secondary, onSecondary = md_theme_dark_onSecondary, secondaryContainer = md_theme_dark_secondaryContainer, onSecondaryContainer = md_theme_dark_onSecondaryContainer, tertiary = md_theme_dark_tertiary, onTertiary = md_theme_dark_onTertiary, tertiaryContainer = md_theme_dark_tertiaryContainer, onTertiaryContainer = md_theme_dark_onTertiaryContainer, error = md_theme_dark_error, errorContainer = md_theme_dark_errorContainer, onError = md_theme_dark_onError, onErrorContainer = md_theme_dark_onErrorContainer, background = md_theme_dark_background, onBackground = md_theme_dark_onBackground, surface = md_theme_dark_surface, onSurface = md_theme_dark_onSurface, surfaceVariant = md_theme_dark_surfaceVariant, onSurfaceVariant = md_theme_dark_onSurfaceVariant, outline = md_theme_dark_outline, inverseOnSurface = md_theme_dark_inverseOnSurface, inverseSurface = md_theme_dark_inverseSurface, inversePrimary = md_theme_dark_inversePrimary, surfaceTint = md_theme_dark_surfaceTint, outlineVariant = md_theme_dark_outlineVariant, scrim = md_theme_dark_scrim, ) @Composable fun CupcakeTheme( darkTheme: Boolean = isSystemInDarkTheme(), // Dynamic color is available on Android 12+ but turned off for training purposes dynamicColor: Boolean = false, 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 -> DarkColors else -> LightColors } 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 ) }
AndroidLearning/compose-training-cupcake/app/src/main/java/com/example/cupcake/ui/theme/Type.kt
925331214
/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.cupcake.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 ) )
AndroidLearning/compose-training-cupcake/app/src/main/java/com/example/cupcake/MainActivity.kt
3033576811
/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.cupcake import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import com.example.cupcake.ui.theme.CupcakeTheme class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { enableEdgeToEdge() super.onCreate(savedInstanceState) setContent { CupcakeTheme { CupcakeApp() } } } }
AndroidLearning/compose-training-cupcake/app/src/main/java/com/example/cupcake/CupcakeScreen.kt
998002077
/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.cupcake import android.content.Context import android.content.Intent import androidx.annotation.StringRes import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize 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.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.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.stringResource import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavHostController import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController import com.example.cupcake.data.DataSource import com.example.cupcake.ui.OrderSummaryScreen import com.example.cupcake.ui.OrderViewModel import com.example.cupcake.ui.SelectOptionScreen import com.example.cupcake.ui.StartOrderScreen enum class CupcakeScreen(@StringRes val title: Int) { Start(R.string.app_name), Flavor(R.string.choose_flavor), Pickup(R.string.choose_pickup_date), Summary(R.string.order_summary) } private fun shareOrder(context: Context, subject: String, summary: String) { val intent = Intent(Intent.ACTION_SEND).apply { type = "text/plain" putExtra(Intent.EXTRA_SUBJECT, subject) putExtra(Intent.EXTRA_TEXT, summary) } context.startActivity( Intent.createChooser( intent, context.getString(R.string.new_cupcake_order) ) ) } /** * Composable that displays the topBar and displays back button if back navigation is possible. */ @Composable fun CupcakeAppBar( currentScreen: CupcakeScreen, canNavigateBack: Boolean, navigateUp: () -> Unit, modifier: Modifier = Modifier ) { TopAppBar( title = { Text(stringResource(id = currentScreen.title)) }, colors = TopAppBarDefaults.mediumTopAppBarColors( containerColor = MaterialTheme.colorScheme.primaryContainer ), modifier = modifier, navigationIcon = { if (canNavigateBack) { IconButton(onClick = navigateUp) { Icon( imageVector = Icons.Filled.ArrowBack, contentDescription = stringResource(R.string.back_button) ) } } } ) } @Composable fun CupcakeApp( viewModel: OrderViewModel = viewModel(), navController: NavHostController = rememberNavController() ) { val backStackEntry by navController.currentBackStackEntryAsState() val currentScreen = CupcakeScreen.valueOf( backStackEntry?.destination?.route ?: CupcakeScreen.Start.name ) Scaffold( topBar = { CupcakeAppBar( currentScreen = currentScreen, canNavigateBack = navController.previousBackStackEntry != null, navigateUp = { navController.navigateUp() } ) } ) { innerPadding -> val uiState by viewModel.uiState.collectAsState() NavHost( navController = navController, startDestination = CupcakeScreen.Start.name, modifier = Modifier.padding(innerPadding) ) { composable(route = CupcakeScreen.Start.name) { StartOrderScreen( quantityOptions = DataSource.quantityOptions, onNextButtonClicked = { viewModel.setQuantity(it) navController.navigate(CupcakeScreen.Flavor.name) }, modifier = Modifier .fillMaxSize() .padding(dimensionResource(id = R.dimen.padding_medium)) ) } composable( route = CupcakeScreen.Flavor.name, ) { val context = LocalContext.current SelectOptionScreen( subtotal = uiState.price, options = DataSource.flavors.map { id -> context.resources.getString(id) }, onSelectionChanged = { viewModel.setFlavor(it) }, onCancelButtonClicked = { cancelOrderAndNavigateToStart( viewModel, navController ) }, onNextButtonClicked = { navController.navigate(CupcakeScreen.Pickup.name) }, modifier = Modifier.fillMaxHeight() ) } composable( route = CupcakeScreen.Pickup.name ) { SelectOptionScreen( subtotal = uiState.price, options = uiState.pickupOptions, onNextButtonClicked = { navController.navigate(CupcakeScreen.Summary.name) }, onCancelButtonClicked = { cancelOrderAndNavigateToStart( viewModel, navController ) }, onSelectionChanged = { viewModel.setDate(it) }, modifier = Modifier.fillMaxHeight() ) } composable( route = CupcakeScreen.Summary.name ) { val context = LocalContext.current OrderSummaryScreen( orderUiState = uiState, onSentButtonClicked = { sub, summ -> shareOrder(context, sub, summ) }, onCancelButtonClicked = { cancelOrderAndNavigateToStart( viewModel, navController ) }, modifier = Modifier.fillMaxHeight() ) } } } } private fun cancelOrderAndNavigateToStart( viewModel: OrderViewModel, navController: NavHostController ) { viewModel.resetOrder() navController.popBackStack(CupcakeScreen.Start.name, false) }
AndroidLearning/compose-training-cupcake/app/src/main/java/com/example/cupcake/data/DataSource.kt
4143548309
/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.cupcake.data import com.example.cupcake.R object DataSource { val flavors = listOf( R.string.vanilla, R.string.chocolate, R.string.red_velvet, R.string.salted_caramel, R.string.coffee ) val quantityOptions = listOf( Pair(R.string.one_cupcake, 1), Pair(R.string.six_cupcakes, 6), Pair(R.string.twelve_cupcakes, 12) ) }
AndroidLearning/compose-training-cupcake/app/src/main/java/com/example/cupcake/data/OrderUiState.kt
582577361
/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.cupcake.data /** * Data class that represents the current UI state in terms of [quantity], [flavor], * [dateOptions], selected pickup [date] and [price] */ data class OrderUiState( /** Selected cupcake quantity (1, 6, 12) */ val quantity: Int = 0, /** Flavor of the cupcakes in the order (such as "Chocolate", "Vanilla", etc..) */ val flavor: String = "", /** Selected date for pickup (such as "Jan 1") */ val date: String = "", /** Total price for the order */ val price: String = "", /** Available pickup dates for the order*/ val pickupOptions: List<String> = listOf() )
Nali-Rescue/app/src/androidTest/java/com/sti/nalirescue/ExampleInstrumentedTest.kt
722288897
package com.sti.nalirescue 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.sti.nalirescue", appContext.packageName) } }
Nali-Rescue/app/src/test/java/com/sti/nalirescue/ExampleUnitTest.kt
2567849556
package com.sti.nalirescue 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) } }
Nali-Rescue/app/src/main/java/com/sti/nalirescue/Settings.kt
2680993463
package com.sti.nalirescue import android.app.AlertDialog import android.content.DialogInterface import android.content.Intent import android.os.Bundle import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Toast import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.sti.nalirescue.R class Settings : Fragment() { private lateinit var recyclerView: RecyclerView private lateinit var adapter: SettingsAdapter override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { val view = inflater.inflate(R.layout.fragment_settings, container, false) recyclerView = view.findViewById(R.id.recyclerViewSetting) val settingsList = listOf(SettingsItem("Logout")) // Add other items as needed val sessionManager = SessionManager(requireContext()) // assuming SessionManager takes a context parameter adapter = SettingsAdapter(settingsList) { item -> // Handle click action for each item if (item.title == "Logout") { showLogoutConfirmationDialog() } } recyclerView.adapter = adapter recyclerView.layoutManager = LinearLayoutManager(activity) return view } private fun showLogoutConfirmationDialog() { val builder = AlertDialog.Builder(requireContext()) builder.setTitle("Logout") builder.setMessage("Are you sure you want to log out?") builder.setPositiveButton("Yes") { _: DialogInterface, _: Int -> // User clicked Yes, perform logout val sessionManager = SessionManager(requireContext()) sessionManager.logoutUser() val intent = Intent(requireContext(), LoginActivity::class.java) startActivity(intent) requireActivity().finish() } builder.setNegativeButton("No") { dialog: DialogInterface, _: Int -> // User clicked No, dismiss the dialog dialog.dismiss() } val dialog = builder.create() dialog.show() } }
Nali-Rescue/app/src/main/java/com/sti/nalirescue/MainActivity.kt
389204779
package com.sti.nalirescue import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import androidx.fragment.app.Fragment import com.sti.nalirescue.databinding.ActivityMainBinding class MainActivity : AppCompatActivity() { private lateinit var binding : ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) replaceFragment(Home()) binding.bottomNavigationView.setOnItemSelectedListener { when(it.itemId){ R.id.home -> replaceFragment(Home()) R.id.profile -> replaceFragment(Profile()) R.id.settings -> replaceFragment(Settings()) else ->{ } } true } } private fun replaceFragment(fragment : Fragment){ val fragmentManager = supportFragmentManager val fragmentTransaction = fragmentManager.beginTransaction() fragmentTransaction.replace(R.id.frame_layout,fragment) fragmentTransaction.commit() } }
Nali-Rescue/app/src/main/java/com/sti/nalirescue/ApiInterface.kt
1098941433
package com.sti.nalirescue import retrofit2.Call import retrofit2.http.Field import retrofit2.http.FormUrlEncoded import retrofit2.http.GET import retrofit2.http.POST import retrofit2.http.Query interface ApiInterface { @FormUrlEncoded @POST("login") // Replace with your actual login endpoint fun login( @Field("email") email: String, @Field("password") password: String ): Call<ApiResponse> @FormUrlEncoded @POST("register") // Replace with your actual registration endpoint fun register( @Field("name") name: String, @Field("email") email: String, @Field("password") password: String, @Field("roleId") roleId: Int, // Make sure to add this field if needed @Field("mobile") mobile: String, @Field("isAdmin") isAdmin: Int, // Make sure to add this field if needed @Field("createdBy") createdBy: Int, // Make sure to add this field if needed @Field("createdDtm") createdDtm: String // Add the createdDtm field as a String ): Call<ApiResponse> @FormUrlEncoded @POST("registerdevice") // Replace with your actual registration endpoint fun device( @Field("device_id") device_id: String, @Field("user_id") user_id: String, ): Call<ApiResponse> @FormUrlEncoded @POST("information") // Replace with your actual registration endpoint fun information( @Field("user_id") user_id: String, @Field("emer_contact") emer_contact: String, @Field("contact_address") contact_address: String, @Field("city_muni") city_muni: String, @Field("blood_type") blood_type: String, @Field("contact_person") contact_person: String, // Make sure to add this field if needed @Field("medical_history") medical_history: String, @Field("verified") verified: Int, // Make sure to add this field if needed @Field("date_added") date_added: String // Add the createdDtm field as a String ): Call<ApiResponse> @FormUrlEncoded @POST("updatetask") // Replace with your actual registration endpoint fun updatetask( @Field("taskId") user_id: String, @Field("description")description:String, @Field("rescue_status") status: String ): Call<ApiResponse> // Add a new method for checking user information // @FormUrlEncoded @GET("listtask") fun check(@Query("rescue") rescue: String, @Query("city_muni") cityMuni: String): Call<ApiResponse> @POST("checkdevice") fun checkerdevice(@Query("user_id") userId: String): Call<ApiResponse> }
Nali-Rescue/app/src/main/java/com/sti/nalirescue/SettingsItem.kt
1996517398
package com.sti.nalirescue class SettingsItem(val title: String)
Nali-Rescue/app/src/main/java/com/sti/nalirescue/CustomDialog.kt
3658015873
package com.sti.nalirescue import android.app.Dialog import android.content.Context import android.content.Intent import android.net.Uri import android.os.Bundle import android.view.Window import android.view.WindowManager import android.widget.Button import android.widget.TextView class CustomDialog(context: Context, private val link: String) : Dialog(context) { private lateinit var titleTextView: TextView private lateinit var closeButton: Button private lateinit var openLinkButton: Button override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) requestWindowFeature(Window.FEATURE_NO_TITLE) setContentView(R.layout.custom_dialog) // Set the window size val window = window window?.setLayout( WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT ) titleTextView = findViewById(R.id.dialogTitle) closeButton = findViewById(R.id.dialogButton) openLinkButton = findViewById(R.id.openLinkButton) titleTextView.text = "Custom Dialog Title" closeButton.setOnClickListener { dismiss() } openLinkButton.setOnClickListener { // Open the link here (e.g., using Intent to open a web page) openLink(link) } } private fun openLink(link: String) { // You need to implement the logic to open the link here // For example, you can use an Intent to open a web page val intent = Intent(Intent.ACTION_VIEW, Uri.parse(link)) context.startActivity(intent) } // You can add more methods or modify the behavior as needed fun setDialogTitle(title: String) { titleTextView.text = title } fun setDialogDetails(details: String) { val detailsTextView: TextView = findViewById(R.id.dialogDetails) detailsTextView.text = details } fun setDialogLocation(location: String) { val locationTextView: TextView = findViewById(R.id.dialogLocation) locationTextView.text = location } fun setDialogMessage(message: String) { val messageTextView: TextView = findViewById(R.id.dialogMessage) messageTextView.text = message } fun setDialogDate(nalidate: String) { val dateTextView: TextView = findViewById(R.id.dialogDate) dateTextView.text = nalidate } fun setOnCloseButtonClickListener(listener: () -> Unit) { closeButton.setOnClickListener { listener.invoke() dismiss() } } }
Nali-Rescue/app/src/main/java/com/sti/nalirescue/TaskAdapter.kt
4110621646
package com.sti.nalirescue import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.recyclerview.widget.RecyclerView class TaskAdapter(private val onItemClick: (Task) -> Unit) : RecyclerView.Adapter<TaskAdapter.TaskViewHolder>() { private var tasks: List<Task> = emptyList() fun setTasks(tasks: List<Task>) { this.tasks = tasks notifyDataSetChanged() } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TaskViewHolder { val view = LayoutInflater.from(parent.context).inflate(R.layout.task_item_layout, parent, false) return TaskViewHolder(view) } override fun onBindViewHolder(holder: TaskViewHolder, position: Int) { val task = tasks[position] holder.bind(task) holder.itemView.setOnClickListener { onItemClick(task) } } override fun getItemCount(): Int { return tasks.size } fun getTasks(): List<Task> { return tasks } class TaskViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { val titleTextView: TextView = itemView.findViewById(R.id.titleTextView) val descriptionTextView: TextView = itemView.findViewById(R.id.descriptionTextView) val dateTextView: TextView = itemView.findViewById(R.id.dateTextView) val naliTextView: TextView = itemView.findViewById(R.id.naliTextView) fun bind(task: Task) { titleTextView.text = task.taskTitle descriptionTextView.text = task.message dateTextView.text = task.createdDtm.toString() naliTextView.text = task.device_id.toUpperCase() } } }
Nali-Rescue/app/src/main/java/com/sti/nalirescue/Home.kt
3017622039
package com.sti.nalirescue import android.app.NotificationChannel import android.app.NotificationManager import android.app.PendingIntent import android.content.Context import android.content.Intent import android.os.Build import android.os.Bundle import android.os.Handler import android.os.Looper import android.util.Log import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Toast import androidx.core.app.NotificationCompat import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.sti.nalirescue.R import okhttp3.OkHttpClient import com.sti.nalirescue.CustomDialog import okhttp3.Request import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Call import retrofit2.Callback import retrofit2.Response import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory class Home : Fragment() { private val BASE_URL = "https://naliproject.xyz/api/" private lateinit var adapter: TaskAdapter private val CHANNEL_ID = "MyChannel" private val NOTIFICATION_ID = 1 var googleMapsNavigationLink ="" private val handler = Handler(Looper.getMainLooper()) private val fetchRunnable = object : Runnable { override fun run() { // Call the function to fetch data fetchData() // Schedule the next data fetch after a delay (e.g., 10 seconds) handler.postDelayed(this, 10 * 1000) // 10 seconds in milliseconds } } // Declare customOkHttpClient as a class-level property private val customOkHttpClient: OkHttpClient by lazy { val loggingInterceptor = HttpLoggingInterceptor(object : HttpLoggingInterceptor.Logger { override fun log(message: String) { Log.d("API Request", message) } }).apply { level = HttpLoggingInterceptor.Level.BODY } OkHttpClient.Builder() .addInterceptor(loggingInterceptor) .build() } override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { val view = inflater.inflate(R.layout.fragment_home, container, false) startPeriodicDataFetch() val recyclerView: RecyclerView = view.findViewById(R.id.recyclerView) recyclerView.layoutManager = LinearLayoutManager(requireContext()) // Inside your onCreateView method where you set up the OkHttpClient val loggingInterceptor = HttpLoggingInterceptor(object : HttpLoggingInterceptor.Logger { override fun log(message: String) { // Log the message as desired, e.g., to Android Logcat // You can also write it to a file or use any other logging mechanism Log.d("API Request", message) } }).apply { level = HttpLoggingInterceptor.Level.BODY // Set the desired logging level } val okHttpClient = OkHttpClient.Builder() .addInterceptor(loggingInterceptor) .build() // Create an instance of your Retrofit service interface with the custom OkHttpClient val apiInterface = Retrofit.Builder() .baseUrl("https://naliproject.xyz/api/") // Replace with your CodeIgniter API base URL .addConverterFactory(GsonConverterFactory.create()) .client(okHttpClient) // Set the OkHttpClient with the custom logging interceptor .build() .create(ApiInterface::class.java) val sessionManager = SessionManager(view.context) val role = sessionManager.getRoleID() adapter = TaskAdapter { task -> onTaskItemClick(task) } recyclerView.adapter = adapter return view } private fun startPeriodicDataFetch() { // Start the initial data fetch fetchData() // Schedule the next data fetch after a delay (e.g., 10 seconds) handler.postDelayed(fetchRunnable, 10 * 1000) // 10 seconds in milliseconds } private fun fetchData() { Log.d("FetchData", "Fetching data.") val loggingInterceptor = HttpLoggingInterceptor(object : HttpLoggingInterceptor.Logger { override fun log(message: String) { Log.d("API Request", message) } }).apply { level = HttpLoggingInterceptor.Level.BODY } val okHttpClient = OkHttpClient.Builder() .addInterceptor(loggingInterceptor) .build() // Create an instance of your Retrofit service interface with the custom OkHttpClient val apiInterface = Retrofit.Builder() .baseUrl("https://naliproject.xyz/api/") // Replace with your CodeIgniter API base URL .addConverterFactory(GsonConverterFactory.create()) .client(okHttpClient) // Set the OkHttpClient with the custom logging interceptor .build() .create(ApiInterface::class.java) val sessionManager = SessionManager(requireContext()) val role = sessionManager.getRoleID() val assign = sessionManager.getAssignValue() showToast(assign.toString()) var emer_type = "" if (role == 13) { emer_type = "PNP" } else if (role == 14) { emer_type = "MEDICAL" }else if (role == 16){ emer_type = "RELATIVE" } val call = apiInterface.check(emer_type,assign) call.enqueue(object : Callback<ApiResponse> { override fun onResponse(call: Call<ApiResponse>, response: Response<ApiResponse>) { if (response.isSuccessful) { val apiResponse = response.body() Log.e("USERINFO", apiResponse.toString()) if (apiResponse != null) { if (apiResponse.status == true) { val apiTasks = apiResponse.tasks val tasks = apiTasks.map { Task( it.taskId.toInt(), it.taskTitle, it.device_id, it.emergency_type, it.location, it.link, it.message, it.description, it.type, it.status, it.createdDtm ) } val existingTasks = adapter.getTasks() // Check if there are new tasks val newTasks = tasks.filterNot { existingTasks.contains(it) } // Update the adapter with the new tasks adapter.setTasks(tasks) val firstDeviceId: String? = tasks.firstOrNull()?.device_id val firstTaskTItle: String? = tasks.firstOrNull()?.taskTitle val firstMessage: String? = tasks.firstOrNull()?.message val location_area : String? = tasks.firstOrNull()?.location val firstLocation: String? = tasks.firstOrNull()?.link // Check if firstLocation is not null and starts with the specified prefix if (!firstLocation.isNullOrBlank() && firstLocation.startsWith("https://www.google.com/maps?q=")) { // Trim the prefix val coordinates = firstLocation.removePrefix("https://www.google.com/maps?q=") googleMapsNavigationLink = "https://www.google.com/maps/dir/?api=1&destination=$coordinates" Log.e("GPS",googleMapsNavigationLink) } else { // Handle the case where the URL format is not as expected println("Invalid URL format or location is null/blank.") } val firstDate: String? = tasks.firstOrNull()?.createdDtm // Check if new tasks are added if (newTasks.isNotEmpty()) { Log.d("Notification", "New tasks added: ${newTasks.size}") // Notify user about new tasks // Replace with your actual link val customDialog = CustomDialog(requireContext(), googleMapsNavigationLink) customDialog.show() customDialog.setDialogTitle(firstDeviceId.toString().toUpperCase()) customDialog.setDialogDetails(firstTaskTItle.toString()) customDialog.setDialogLocation(location_area.toString()) customDialog.setDialogMessage(firstMessage.toString()) customDialog.setDialogDate(firstDate.toString()) } } else { showToast("API response indicates failure: ${apiResponse.message}") } } else { showToast("API response is null") } } else { showToast("Waiting for new Data") } } override fun onFailure(call: Call<ApiResponse>, t: Throwable) { // Handle failure here showToast("Failed to fetch data from the API") } }) } private fun showToast(message: String) { Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show() } private fun showNotification(nali : String) { Log.d("Notification", "Notification is being shown.") val notificationManager = requireContext().getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager // Create a Notification Channel (for Android Oreo and higher) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val channel = NotificationChannel( CHANNEL_ID, "My Channel", NotificationManager.IMPORTANCE_DEFAULT ) notificationManager.createNotificationChannel(channel) } // Create an Intent to launch the app when the notification is clicked val intent = Intent(requireContext(), MainActivity::class.java) intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP val pendingIntent = PendingIntent.getActivity( requireContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE // or FLAG_MUTABLE ) // Create a Notification val notification = NotificationCompat.Builder(requireContext(), CHANNEL_ID) .setSmallIcon(R.drawable.nali) .setContentTitle(nali) .setContentText("You have new tasks to review.") .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setContentIntent(pendingIntent) // Set the PendingIntent for the notification .setAutoCancel(true) // Automatically removes the notification when clicked .build() // Show the Notification notificationManager.notify(NOTIFICATION_ID, notification) } // Add the onDestroyView method to remove the callback when the fragment is destroyed override fun onDestroyView() { super.onDestroyView() // Remove the callback to prevent memory leaks handler.removeCallbacks(fetchRunnable) } private fun onTaskItemClick(task: Task) { // Open TaskDetailsActivity and pass task details val intent = Intent(requireContext(), TaskDetailsActivity::class.java) intent.putExtra("TASK_ID", task.taskId) intent.putExtra("TASK_TITLE", task.taskTitle) intent.putExtra("TASK_DESCRIPTION", task.message) intent.putExtra("TASK_LOCATION", task.location) intent.putExtra("TASK_DIRECTION",googleMapsNavigationLink) intent.putExtra("TASK_LINK",task.link) startActivity(intent) } }
Nali-Rescue/app/src/main/java/com/sti/nalirescue/SessionManager.kt
2925645024
package com.sti.nalirescue import android.content.Context import android.content.SharedPreferences class SessionManager(context: Context) { private val PREF_NAME = "Rescuer" private val KEY_USERNAME = "username" private val KEY_PASSWORD = "password" private val KEY_USER_ID = "userid" private val KEY_ROLE_ID = "role_id" private val KEY_USER_NAME = "user_name" private val KEY_IS_LOGGED_IN = "isLoggedIn" private val KEY_ASSIGN = "assign" private val sharedPreferences: SharedPreferences = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE) fun createLoginSession( username: String, password: String, userid: Int, role_id: Int, user_name:String,assign:String) { val editor = sharedPreferences.edit() editor.putString(KEY_USERNAME, username) editor.putString(KEY_PASSWORD, password) editor.putInt(KEY_USER_ID, userid) editor.putInt(KEY_ROLE_ID, role_id) editor.putString(KEY_USER_NAME,user_name)// Store as an integer editor.putString(KEY_ASSIGN,assign)// Store as an integer editor.putBoolean(KEY_IS_LOGGED_IN, true) editor.apply() } fun checkLogin(): Boolean { return sharedPreferences.getBoolean(KEY_IS_LOGGED_IN, false) } fun getUserDetails(): HashMap<String, Any> { // Change the return type to Any val user = HashMap<String, Any>() // Change the value type to Any user[KEY_USERNAME] = sharedPreferences.getString(KEY_USERNAME, "") ?: "" user[KEY_PASSWORD] = sharedPreferences.getString(KEY_PASSWORD, "") ?: "" user[KEY_USER_NAME] = sharedPreferences.getString(KEY_USER_NAME,"")?:"" user[KEY_ASSIGN] = sharedPreferences.getString(KEY_ASSIGN,"")?:"" user[KEY_USER_ID] = sharedPreferences.getInt(KEY_USER_ID, 0) // Retrieve as an integer user[KEY_ROLE_ID] = sharedPreferences.getInt(KEY_ROLE_ID, 0) // Retrieve as an integer return user } fun logoutUser() { val editor = sharedPreferences.edit() editor.clear() editor.apply() } // Getter method for KEY_USERNAME fun getUsernameKey(): String { return KEY_USERNAME } fun getAssignValue(): String { return sharedPreferences.getString(KEY_ASSIGN, "") ?: "" } // Getter method for KEY_USERNAME fun getUser_nameKey(): String { return KEY_USER_NAME } // Getter method for KEY_USERNAME fun getUserID(): Int { return sharedPreferences.getInt(KEY_USER_ID, 0) } // Getter method for KEY_ROLE_ID fun getRoleID(): Int { return sharedPreferences.getInt(KEY_ROLE_ID, 0) } }
Nali-Rescue/app/src/main/java/com/sti/nalirescue/ApiReponse.kt
766535907
package com.sti.nalirescue import java.math.BigInteger import java.util.Date data class User( val userId: String, val roleId: Int, val name :String, val assign :String // Add other user properties here ) data class ApiResponse( val status: Boolean, val message: String, val device_data: List<DeviceData>, val tasks:List<TaskData>, val login: Boolean, val result: Boolean, val user: User // Define it as an object, not a string ) data class DeviceData( val user_id: String, val device_id: String ) data class TaskData( val taskId: BigInteger, val taskTitle: String, val device_id: String, val emergency_type: String, val location:String, val link:String, val message: String, val description: String, val type:String, val status:String, val city_muni:String, val date:Date, val createdDtm:String )
Nali-Rescue/app/src/main/java/com/sti/nalirescue/Task.kt
3747612099
package com.sti.nalirescue import java.math.BigInteger import java.util.Date data class Task( val taskId: Int, val taskTitle: String, val device_id: String, val emergency_type: String, val location: String, val link: String, val message: String, val description: String?, val type: String?, val status: String?, val createdDtm: String? )
Nali-Rescue/app/src/main/java/com/sti/nalirescue/TaskDetailsActivity.kt
1545788166
// TaskDetailsActivity.kt package com.sti.nalirescue import android.content.Intent import android.net.Uri import android.os.Bundle import android.util.Log import android.widget.ArrayAdapter import android.widget.Button import android.widget.EditText import android.widget.Spinner import androidx.appcompat.app.AppCompatActivity import android.widget.TextView import android.widget.Toast import androidx.appcompat.widget.Toolbar import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Call import retrofit2.Callback import retrofit2.Response import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory import java.math.BigInteger class TaskDetailsActivity : AppCompatActivity() { private lateinit var rescueDetails: EditText override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_task_details) val toolbar: Toolbar = findViewById(R.id.toolbar) setSupportActionBar(toolbar) // Enable the back button in the toolbar supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) val taskId = intent.getIntExtra("TASK_ID", -1) val taskTitle = intent.getStringExtra("TASK_TITLE") val taskDescription = intent.getStringExtra("TASK_DESCRIPTION") val tasklocation_ = intent.getStringExtra("TASK_LOCATION") val taskDirection = intent.getStringExtra("TASK_DIRECTION") // Use these details to populate your TaskDetailsActivity UI val titleTextView: TextView = findViewById(R.id.titleTextView) val descriptionTextView: TextView = findViewById(R.id.descriptionTextView) val locationTextView: TextView = findViewById(R.id.locationTextView) val townTextView: TextView = findViewById(R.id.townTextView) val buttonDirection: Button = findViewById(R.id.respondButton) rescueDetails = findViewById(R.id.editRescueText) val sessionManager = SessionManager(this) val role = sessionManager.getRoleID() val device = sessionManager.getUserID() showToast(role.toString()) val buttonApply: Button = findViewById(R.id.applyButton) // Inside your onCreateView method where you set up the OkHttpClient val loggingInterceptor = HttpLoggingInterceptor(object : HttpLoggingInterceptor.Logger { override fun log(message: String) { // Log the message as desired, e.g., to Android Logcat // You can also write it to a file or use any other logging mechanism Log.d("API Request", message) } }).apply { level = HttpLoggingInterceptor.Level.BODY // Set the desired logging level } // Inside onCreateView method val okHttpClient = OkHttpClient.Builder() .addInterceptor(loggingInterceptor) .build() // Create an instance of your Retrofit service interface with the custom OkHttpClient val apiInterface = Retrofit.Builder() .baseUrl("https://naliproject.xyz/api/") // Replace with your CodeIgniter API base URL .addConverterFactory(GsonConverterFactory.create()) .client(okHttpClient) // Set the OkHttpClient with the custom logging interceptor .build() .create(ApiInterface::class.java) titleTextView.text = taskTitle descriptionTextView.text = taskDescription locationTextView.text = tasklocation_ buttonDirection.setOnClickListener { // Replace "https://www.example.com" with the actual URL you want to open val url = taskDirection Log.e("URL",url.toString()) // // // Create an Intent with ACTION_VIEW and the URI of the webpage val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) // Start the activity with the intent startActivity(intent) } val spinner: Spinner = findViewById(R.id.itemSpinner) // Define an array of items val items = arrayOf("RESPONDING", "CANCLED", "DONE") // Create an ArrayAdapter using the string array and a default spinner layout val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, items) // Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) // Apply the adapter to the spinner spinner.adapter = adapter buttonApply.setOnClickListener { // Validate descriptionRescue val rescueDets = rescueDetails.text.toString() val selectedResp:String = spinner.selectedItem.toString() showToast(rescueDets) val call = apiInterface.updatetask( taskId.toString(), rescueDets, selectedResp, ) Log.d("DEVICE", "Request URL: ${call.request().url}") // Enqueue the call to run asynchronously call.enqueue(object : Callback<ApiResponse> { override fun onResponse(call: Call<ApiResponse>, response: Response<ApiResponse>) { Log.e("API-UPDATE", response.toString()) if (response.code() == 201) { // 201 Created is typically returned for successful registration val apiResponse = response.body() if (apiResponse != null && apiResponse.status == true) { Log.e("API-UPDATE", apiResponse.toString()) // Registration was successful Toast.makeText(applicationContext, "${apiResponse.message}", Toast.LENGTH_SHORT).show() // Registration was successful, navigate to LoginActivity finish() } else { Log.e("API", apiResponse.toString()) } } else { // Registration request failed Toast.makeText(applicationContext, "Registration request 1 failed", Toast.LENGTH_SHORT).show() } } override fun onFailure(call: Call<ApiResponse>, t: Throwable) { // Registration request failed Toast.makeText(applicationContext, "Registration request failed.", Toast.LENGTH_SHORT).show() t.printStackTrace() } }) } } private fun showToast(message:String){ Toast.makeText(this, message ,Toast.LENGTH_SHORT).show() } // Handle the back button press override fun onSupportNavigateUp(): Boolean { onBackPressed() return true } }
Nali-Rescue/app/src/main/java/com/sti/nalirescue/LoginActivity.kt
2811086233
package com.sti.nalirescue import android.content.Intent import android.os.Bundle import android.util.Log import android.view.View import androidx.appcompat.app.AppCompatActivity import android.widget.Button import android.widget.EditText import android.widget.Toast import com.sti.nalirescue.MainActivity import com.sti.nalirescue.R import retrofit2.Call import retrofit2.Callback import retrofit2.Response import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory class LoginActivity : AppCompatActivity() { private val BASE_URL = "https://naliproject.xyz/api/" // Replace with your API base URL private lateinit var usernameEditText: EditText private lateinit var passwordEditText: EditText override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_login) // Initialize UI elements usernameEditText = findViewById(R.id.usernameEditText) passwordEditText = findViewById(R.id.passwordEditText) val loginButton = findViewById<Button>(R.id.loginButton) // Set up Retrofit val retrofit = Retrofit.Builder() .baseUrl(BASE_URL) .addConverterFactory(GsonConverterFactory.create()) .build() val apiInterface = retrofit.create(ApiInterface::class.java) // Check if the user is already logged in val sessionManager = SessionManager(this) if (sessionManager.checkLogin()) { val roleIdCheck = sessionManager.getRoleID() // User is logged in, redirect to the HomeActivity or desired activity val intent = Intent(this@LoginActivity,MainActivity::class.java) startActivity(intent) finish() } //Handle register button click // Handle login button click loginButton.setOnClickListener { val username = usernameEditText.text.toString() val password = passwordEditText.text.toString() // Call the login API using Retrofit apiInterface.login(username, password).enqueue(object : Callback<ApiResponse> { override fun onResponse(call: Call<ApiResponse>, response: Response<ApiResponse>) { if (response.isSuccessful) { val apiResponse = response.body() Log.e("LOGIN",apiResponse.toString()) // Check if login is true if (apiResponse?.login == true) { val user = apiResponse?.user val iduser = user?.userId val iduserInt = iduser?.toIntOrNull() ?: 0 val assign = user?.assign val roleId = user?.roleId val user_name = user?.name // real username val roleIdInt = roleId ?: 0 val username = usernameEditText.text.toString() // email val password = passwordEditText.text.toString() if(roleIdInt == 13) { // Save user credentials and login status val sessionManager = SessionManager(this@LoginActivity) if (assign != null) { sessionManager.createLoginSession(username, password, iduserInt,roleIdInt,user_name.toString(),assign) } // User is logged in, redirect to the HomeActivity or desired activity val intent = Intent(this@LoginActivity, MainActivity::class.java) startActivity(intent) finish() }else if (roleIdInt == 14){ if (assign != null) { sessionManager.createLoginSession(username, password, iduserInt,roleIdInt,user_name.toString(),assign) } // User is logged in, redirect to the HomeActivity or desired activity val intent = Intent(this@LoginActivity, MainActivity::class.java) startActivity(intent) finish() }else if (roleIdInt == 16){ if (assign != null) { sessionManager.createLoginSession(username, password, iduserInt,roleIdInt,user_name.toString(),assign) } // User is logged in, redirect to the HomeActivity or desired activity val intent = Intent(this@LoginActivity, MainActivity::class.java) startActivity(intent) finish() } } else { // Handle the case where login is false val errorMessage = "Login failed. Email and password are required." showToast(errorMessage) } } else { // Handle API error and display the status code val statusCode = response.code() val errorMessage = "API Error. Status Code: $statusCode" showToast(errorMessage) } } override fun onFailure(call: Call<ApiResponse>, t: Throwable) { // Log the error message Log.e("NetworkError", "Error: ${t.message}", t) // Show an error message to the user showToast("Network error. Please try again.") } }) } } private fun showToast(message: String) { Toast.makeText(this, message, Toast.LENGTH_SHORT).show() } }
Nali-Rescue/app/src/main/java/com/sti/nalirescue/SettingsAdapter.kt
1558450007
package com.sti.nalirescue import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.recyclerview.widget.RecyclerView class SettingsAdapter(private val settingsList: List<SettingsItem>, private val onItemClick: (SettingsItem) -> Unit) : RecyclerView.Adapter<SettingsAdapter.ViewHolder>() { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { val view = LayoutInflater.from(parent.context).inflate(R.layout.settings_item_layout, parent, false) return ViewHolder(view) } override fun onBindViewHolder(holder: ViewHolder, position: Int) { val item = settingsList[position] holder.bind(item) } override fun getItemCount(): Int { return settingsList.size } inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { private val textViewTitle: TextView = itemView.findViewById(R.id.textViewTitle) init { itemView.setOnClickListener { onItemClick.invoke(settingsList[adapterPosition]) } } fun bind(item: SettingsItem) { textViewTitle.text = item.title } } }
Nali-Rescue/app/src/main/java/com/sti/nalirescue/Profile.kt
3932059393
package com.sti.nalirescue import android.os.Bundle import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import com.sti.nalirescue.R // TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER private const val ARG_PARAM1 = "param1" private const val ARG_PARAM2 = "param2" /** * A simple [Fragment] subclass. * Use the [Profile.newInstance] factory method to * create an instance of this fragment. */ class Profile : Fragment() { // TODO: Rename and change types of parameters private var param1: String? = null private var param2: String? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) arguments?.let { param1 = it.getString(ARG_PARAM1) param2 = it.getString(ARG_PARAM2) } } override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_profile, container, false) } companion object { /** * Use this factory method to create a new instance of * this fragment using the provided parameters. * * @param param1 Parameter 1. * @param param2 Parameter 2. * @return A new instance of fragment Profile. */ // TODO: Rename and change types and number of parameters @JvmStatic fun newInstance(param1: String, param2: String) = Profile().apply { arguments = Bundle().apply { putString(ARG_PARAM1, param1) putString(ARG_PARAM2, param2) } } } }
kalkulator_kotlin/app/src/androidTest/java/com/example/challenge_rekamin_satu/ExampleInstrumentedTest.kt
2305704444
package com.example.challenge_rekamin_satu 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.challenge_rekamin_satu", appContext.packageName) } }
kalkulator_kotlin/app/src/test/java/com/example/challenge_rekamin_satu/ExampleUnitTest.kt
2868113574
package com.example.challenge_rekamin_satu 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) } }
kalkulator_kotlin/app/src/main/java/com/example/challenge_rekamin_satu/Kalkulator.kt
446071388
package com.example.challenge_rekamin_satu 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.aspectRatio import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width 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.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.example.challenge_rekamin_satu.ui.theme.Orange @Composable fun Kalkulator( state: StateKalkulator, buttonSpacing: Dp= 8.dp, modifier: Modifier = Modifier, onAction: (ActionKalkulator) -> Unit ) { Box(modifier = modifier){ Column ( modifier = Modifier .fillMaxWidth() .align(Alignment.BottomCenter), verticalArrangement = Arrangement.spacedBy(buttonSpacing) ) { Text( text = state.number1 + (state.operation?.symbol?: "") + state.number2, textAlign = TextAlign.End, modifier = Modifier .fillMaxWidth() .padding(vertical = 32.dp), fontWeight = FontWeight.Light, fontSize = 80.sp, color = Color.White, maxLines = 2 ) Row ( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(buttonSpacing) ) { ButtonKalkulator ( symbol = "AC", modifier = Modifier .background(Color.LightGray) .aspectRatio(2f) .weight(2f), onClick = { onAction(ActionKalkulator.Clear) } ) ButtonKalkulator ( symbol = "Del", modifier = Modifier .background(Color.LightGray) .aspectRatio(1f) .weight(1f), onClick = { onAction(ActionKalkulator.Delete) } ) ButtonKalkulator ( symbol = "/", modifier = Modifier .background(Color.LightGray) .aspectRatio(1f) .weight(1f), onClick = { onAction(ActionKalkulator.Operation(OperationKalkulator.Divide)) } ) } Row ( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(buttonSpacing) ) { ButtonKalkulator ( symbol = "7", modifier = Modifier .background(Color.DarkGray) .aspectRatio(1f) .weight(1f), onClick = { onAction(ActionKalkulator.Number(7)) } ) ButtonKalkulator ( symbol = "8", modifier = Modifier .background(Color.DarkGray) .aspectRatio(1f) .weight(1f), onClick = { onAction(ActionKalkulator.Number(8)) } ) ButtonKalkulator ( symbol = "9", modifier = Modifier .background(Color.DarkGray) .aspectRatio(1f) .weight(1f), onClick = { onAction(ActionKalkulator.Number(9)) } ) ButtonKalkulator ( symbol = "x", modifier = Modifier .background(Orange) .aspectRatio(1f) .weight(1f), onClick = { onAction(ActionKalkulator.Operation(OperationKalkulator.Multiply)) } ) } Row ( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(buttonSpacing) ) { ButtonKalkulator ( symbol = "4", modifier = Modifier .background(Color.DarkGray) .aspectRatio(1f) .weight(1f), onClick = { onAction(ActionKalkulator.Number(4)) } ) ButtonKalkulator ( symbol = "5", modifier = Modifier .background(Color.DarkGray) .aspectRatio(1f) .weight(1f), onClick = { onAction(ActionKalkulator.Number(5)) } ) ButtonKalkulator ( symbol = "6", modifier = Modifier .background(Color.DarkGray) .aspectRatio(1f) .weight(1f), onClick = { onAction(ActionKalkulator.Number(6)) } ) ButtonKalkulator ( symbol = "-", modifier = Modifier .background(Orange) .aspectRatio(1f) .weight(1f), onClick = { onAction(ActionKalkulator.Operation(OperationKalkulator.Subtract)) } ) } Row ( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(buttonSpacing) ) { ButtonKalkulator ( symbol = "1", modifier = Modifier .background(Color.DarkGray) .aspectRatio(1f) .weight(1f), onClick = { onAction(ActionKalkulator.Number(1)) } ) ButtonKalkulator ( symbol = "2", modifier = Modifier .background(Color.DarkGray) .aspectRatio(1f) .weight(1f), onClick = { onAction(ActionKalkulator.Number(2)) } ) ButtonKalkulator ( symbol = "3", modifier = Modifier .background(Color.DarkGray) .aspectRatio(1f) .weight(1f), onClick = { onAction(ActionKalkulator.Number(3)) } ) ButtonKalkulator ( symbol = "+", modifier = Modifier .background(Orange) .aspectRatio(1f) .weight(1f), onClick = { onAction(ActionKalkulator.Operation(OperationKalkulator.Add)) } ) } Row ( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(buttonSpacing) ) { ButtonKalkulator ( symbol = "0", modifier = Modifier .background(Color.DarkGray) .aspectRatio(2f) .weight(2f), onClick = { onAction(ActionKalkulator.Number(0)) } ) ButtonKalkulator ( symbol = ".", modifier = Modifier .background(Color.DarkGray) .aspectRatio(1f) .weight(1f), onClick = { onAction(ActionKalkulator.Desimal) } ) ButtonKalkulator ( symbol = "=", modifier = Modifier .background(Orange) .aspectRatio(1f) .weight(1f), onClick = { onAction(ActionKalkulator.Kalkulator) } ) } } } }
kalkulator_kotlin/app/src/main/java/com/example/challenge_rekamin_satu/ui/theme/Color.kt
1843673336
package com.example.challenge_rekamin_satu.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) val MediumGray = Color(0xFF2E2E2E) val lightGray = Color(0xFF818181) val Orange = Color(0xFFFF9800)
kalkulator_kotlin/app/src/main/java/com/example/challenge_rekamin_satu/ui/theme/Theme.kt
1835132469
package com.example.challenge_rekamin_satu.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 Challenge_rekamin_satuTheme( 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 ) }
kalkulator_kotlin/app/src/main/java/com/example/challenge_rekamin_satu/ui/theme/Type.kt
2994460186
package com.example.challenge_rekamin_satu.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 ) */ )
kalkulator_kotlin/app/src/main/java/com/example/challenge_rekamin_satu/StateKalkulator.kt
1285208825
package com.example.challenge_rekamin_satu data class StateKalkulator( val number1: String="", val number2: String="", val operation: OperationKalkulator? = null )
kalkulator_kotlin/app/src/main/java/com/example/challenge_rekamin_satu/MainActivity.kt
445024437
package com.example.challenge_rekamin_satu import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.background import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel import com.example.challenge_rekamin_satu.ui.theme.Challenge_rekamin_satuTheme import com.example.challenge_rekamin_satu.ui.theme.MediumGray class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { Challenge_rekamin_satuTheme { val viewModel = viewModel<ViewModelKalkulator>() val state = viewModel.state val buttonSpacing = 8.dp Kalkulator( state = state, onAction = viewModel::onAction, buttonSpacing = buttonSpacing, modifier = Modifier .fillMaxSize() .background(MediumGray) .padding(16.dp) ) } } } }
kalkulator_kotlin/app/src/main/java/com/example/challenge_rekamin_satu/ViewModelKalkulator.kt
1334158847
package com.example.challenge_rekamin_satu import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel class ViewModelKalkulator: ViewModel() { var state by mutableStateOf(StateKalkulator()) private set fun onAction(action: ActionKalkulator){ when(action){ is ActionKalkulator.Number -> enterNumber(action.number) is ActionKalkulator.Desimal -> enterDecimal() is ActionKalkulator.Clear -> state = StateKalkulator() is ActionKalkulator.Operation -> enterOperation (action.operation) is ActionKalkulator.Kalkulator -> performKalkulation() is ActionKalkulator.Delete -> performDeletion() } } private fun performDeletion() { when { state.number2.isBlank() -> state = state.copy( number2 = state.number2.dropLast(1) ) state.operation != null -> state = state.copy( operation = null ) state.number1.isNotBlank() -> state = state.copy( number1 = state.number1.dropLast(1) ) } } private fun performKalkulation() { val number1 = state.number1.toDoubleOrNull() val number2 = state.number2.toDoubleOrNull() if (number1 != null && number2 != null){ val result = when(state.operation){ is OperationKalkulator.Add -> number1 + number2 is OperationKalkulator.Subtract -> number1 - number2 is OperationKalkulator.Multiply -> number1 * number2 is OperationKalkulator.Divide -> number1 / number2 null -> return } state =state.copy( number1 = result.toString().take(15), number2 = "", operation = null ) } } private fun enterOperation(operation: OperationKalkulator) { if(state.number1.isBlank()) { state = state.copy(operation = operation) } } private fun enterDecimal() { if (state.operation == null && !state.number1.contains(".") && state.number1.isNotBlank() ) { state = state.copy( number1 = state.number1 + "." ) return } if (!state.number2.contains(".") && state.number2.isNotBlank() ) { state = state.copy( number1 = state.number2 + "." ) } } private fun enterNumber(number: Int) { if (state.operation == null){ if (state.number1.length >= MAX_NUM_LENGTH){ return } state = state.copy( number1 = state.number1 + number ) return } if (state.number2.length >= MAX_NUM_LENGTH){ return } state = state.copy( number2 = state.number2 + number ) } companion object{ private const val MAX_NUM_LENGTH = 8 } }
kalkulator_kotlin/app/src/main/java/com/example/challenge_rekamin_satu/ActionKalkulator.kt
983271589
package com.example.challenge_rekamin_satu sealed class ActionKalkulator { data class Number(val number : Int): ActionKalkulator() object Clear: ActionKalkulator() object Delete: ActionKalkulator() object Desimal: ActionKalkulator() object Kalkulator : ActionKalkulator() data class Operation(val operation: OperationKalkulator): ActionKalkulator() }
kalkulator_kotlin/app/src/main/java/com/example/challenge_rekamin_satu/OperationKalkulator.kt
3626460131
package com.example.challenge_rekamin_satu sealed class OperationKalkulator(val symbol:String) { object Add: OperationKalkulator("+") object Subtract: OperationKalkulator("-") object Multiply: OperationKalkulator("x") object Divide: OperationKalkulator("/") }
kalkulator_kotlin/app/src/main/java/com/example/challenge_rekamin_satu/ButtonKalkulator.kt
2259160422
package com.example.challenge_rekamin_satu import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.shape.CircleShape import androidx.compose.material3.Text import androidx.compose.runtime.Composable 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.unit.sp @Composable fun ButtonKalkulator( symbol: String, modifier: Modifier, onClick: () -> Unit ) { Box( contentAlignment = Alignment.Center, modifier = modifier .clip(CircleShape) .clickable { onClick() } .then(modifier) ){ Text( text = symbol, fontSize = 34.sp, color = Color.White ) } }
Android_team_Project/android_team4_project/app/src/androidTest/java/com/example/android_team4_project/ExampleInstrumentedTest.kt
1560122834
package com.example.android_team4_project 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.android_team4_project", appContext.packageName) } }
Android_team_Project/android_team4_project/app/src/test/java/com/example/android_team4_project/ExampleUnitTest.kt
3132026911
package com.example.android_team4_project 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) } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/PopupActivitywed.kt
821953153
package com.example.android_team4_project import android.app.Dialog import android.content.Context import android.content.Intent import android.content.SharedPreferences import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.text.Editable import android.text.TextWatcher import android.widget.ArrayAdapter import android.widget.EditText import android.widget.ListView import android.widget.Spinner import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.example.android_team4_project.databinding.ActivityPopupBinding import com.google.firebase.auth.FirebaseAuth class PopupActivitywed : AppCompatActivity() { private lateinit var binding: ActivityPopupBinding private lateinit var userEmail: String private lateinit var arrayList: ArrayList<String> private lateinit var dialog: Dialog private lateinit var spinner: Spinner private lateinit var selectedSpinnerValue: String private lateinit var auth: FirebaseAuth override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityPopupBinding.inflate(layoutInflater) setContentView(binding.root) auth = FirebaseAuth.getInstance() val user = auth.currentUser userEmail = user?.uid ?: "" dialog = Dialog(this) val sharedPrefTitlewed = getSharedPreferences("Routine_Wed$userEmail", Context.MODE_PRIVATE) val routine = RoutineData( title = sharedPrefTitlewed.getString("title", "") ?: "", selectedSpinnerItem = sharedPrefTitlewed.getString("selectedSpinnerItem", "") ?: "", con1 = sharedPrefTitlewed.getString("con1", "") ?: "", con2 = sharedPrefTitlewed.getString("con2", "") ?: "", con3 = sharedPrefTitlewed.getString("con3", "") ?: "", con4 = sharedPrefTitlewed.getString("con4", "") ?: "", con5 = sharedPrefTitlewed.getString("con5", "") ?: "", edm1 = sharedPrefTitlewed.getString("edm1", "") ?: "", edm2 = sharedPrefTitlewed.getString("edm2", "") ?: "", edm3 = sharedPrefTitlewed.getString("edm3", "") ?: "", edm4 = sharedPrefTitlewed.getString("edm4", "") ?: "", edm5 = sharedPrefTitlewed.getString("edm5", "") ?: "", eds1 = sharedPrefTitlewed.getString("eds1", "") ?: "", eds2 = sharedPrefTitlewed.getString("eds2", "") ?: "", eds3 = sharedPrefTitlewed.getString("eds3", "") ?: "", eds4 = sharedPrefTitlewed.getString("eds4", "") ?: "", eds5 = sharedPrefTitlewed.getString("eds5", "") ?: "" ) initializeEditText(binding.edTitle, routine.title) routine.con1?.let { initializeEditText(binding.edContent1, it) } routine.con2?.let { initializeEditText(binding.edContent2, it) } routine.con3?.let { initializeEditText(binding.edContent3, it) } routine.con4?.let { initializeEditText(binding.edContent4, it) } routine.con5?.let { initializeEditText(binding.edContent5, it) } initializeEditText(binding.edm1, routine.edm1.toString()) initializeEditText(binding.edm2, routine.edm2.toString()) initializeEditText(binding.edm3, routine.edm3.toString()) initializeEditText(binding.edm4, routine.edm4.toString()) initializeEditText(binding.edm5, routine.edm5.toString()) initializeEditText(binding.eds1, routine.eds1.toString()) initializeEditText(binding.eds2, routine.eds2.toString()) initializeEditText(binding.eds3, routine.eds3.toString()) initializeEditText(binding.eds4, routine.eds4.toString()) initializeEditText(binding.eds5, routine.eds5.toString()) binding.spinner.setSelection(getSelectedSpinnerPosition(sharedPrefTitlewed, routine.selectedSpinnerItem)) binding.btnSaveAll.setOnClickListener { //Toast Toast.makeText(this,"์ˆ˜์š”์ผ ๋ฃจํ‹ด์ด ์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.", Toast.LENGTH_SHORT).show() val edTitle = binding.edTitle.text.toString() val edCon1 = binding.edContent1.text.toString() val edCon2 = binding.edContent2.text.toString() val edCon3 = binding.edContent3.text.toString() val edCon4 = binding.edContent4.text.toString() val edCon5 = binding.edContent5.text.toString() val edm1 = binding.edm1.text.toString().toIntOrNull() ?: 0 val edm2 = binding.edm2.text.toString().toIntOrNull() ?: 0 val edm3 = binding.edm3.text.toString().toIntOrNull() ?: 0 val edm4 = binding.edm4.text.toString().toIntOrNull() ?: 0 val edm5 = binding.edm5.text.toString().toIntOrNull() ?: 0 val eds1 = binding.eds1.text.toString().toIntOrNull() ?: 0 val eds2 = binding.eds2.text.toString().toIntOrNull() ?: 0 val eds3 = binding.eds3.text.toString().toIntOrNull() ?: 0 val eds4 = binding.eds4.text.toString().toIntOrNull() ?: 0 val eds5 = binding.eds5.text.toString().toIntOrNull() ?: 0 // ์Šคํ”ผ๋„ˆ์—์„œ ์„ ํƒ๋œ ํ•ญ๋ชฉ์˜ ๊ฐ’์„ ๊ฐ€์ ธ์˜ค๊ธฐ val selectedSpinnerItem = binding.spinner.selectedItem.toString() // RoutineData ๊ฐ์ฒด ์—…๋ฐ์ดํŠธ val routine = RoutineData( title = edTitle, selectedSpinnerItem = selectedSpinnerItem, con1 = edCon1, con2 = edCon2, con3 = edCon3, con4 = edCon4, con5 = edCon5, edm1 = edm1.toString(), edm2 = edm2.toString(), edm3 = edm3.toString(), edm4 = edm4.toString(), edm5 = edm5.toString(), eds1 = eds1.toString(), eds2 = eds2.toString(), eds3 = eds3.toString(), eds4 = eds4.toString(), eds5 = eds5.toString() ) // RoutineData ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ๋ฐ์ดํ„ฐ ์ƒ์„ฑ val xmlData = generateXmlData(routine,"Wed") // userEmail์„ ์ด์šฉํ•˜์—ฌ StorageManager๋ฅผ ์ดˆ๊ธฐํ™” val storageManager = StorageManager(this) // StorageManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ํŒŒ์ผ ์—…๋กœ๋“œ storageManager.uploadXmlFile(xmlData,"Wed") // SharedPreferences๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ์ €์žฅ val userUid = FirebaseAuth.getInstance().uid val sharedPrefTitlewed = getSharedPreferences("Routine_Wed$userUid", Context.MODE_PRIVATE) val editor = sharedPrefTitlewed.edit() editor.putString("title", routine.title) editor.putString("selectedSpinnerItem", routine.selectedSpinnerItem) editor.putString("con1", routine.con1) editor.putString("con2", routine.con2) editor.putString("con3", routine.con3) editor.putString("con4", routine.con4) editor.putString("con5", routine.con5) editor.putString("edm1", routine.edm1) editor.putString("edm2", routine.edm2) editor.putString("edm3", routine.edm3) editor.putString("edm4", routine.edm4) editor.putString("edm5", routine.edm5) editor.putString("eds1", routine.eds1) editor.putString("eds2", routine.eds2) editor.putString("eds3", routine.eds3) editor.putString("eds4", routine.eds4) editor.putString("eds5", routine.eds5) editor.apply() // ์ €์žฅ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ด๋ฃจ์–ด์ง€๋ฉด ์•กํ‹ฐ๋น„ํ‹ฐ ์ด๋™ val intent = Intent(this, MyActivity::class.java) startActivity(intent) finish() // ํ˜„์žฌ ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ์ข…๋ฃŒ } binding.btnCancel.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MyActivity::class.java) startActivity(intent) } // ๋ฒ„ํŠผํด๋ฆญ์‹œ ๋งˆ์ด๋ฃจํ‹ด์œผ๋กœ ์ด๋™ binding.btnMypage.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MainActivity::class.java) startActivity(intent) } // ์Šคํ”ผ๋„ˆ ๊ฐ์ฒด ์ƒ์„ฑ spinner = binding.spinner // // ์Šคํ”ผ๋„ˆ ํด๋ฆญ ์‹œ ๋‹ค์ด์–ผ๋กœ๊ทธ ๋„์šฐ๊ธฐ // spinner.setOnTouchListener { _, _ -> // showSearchableSpinnerDialog() // false // } // ์Šคํ”ผ๋„ˆ ํด๋ฆญ ์‹œ ๋‹ค์ด์–ผ๋กœ๊ทธ ๋„์šฐ๊ธฐ spinner.setOnTouchListener { _, _ -> if (dialog == null) { // ๋‹ค์ด์–ผ๋กœ๊ทธ๊ฐ€ ์ดˆ๊ธฐํ™”๋˜์ง€ ์•Š์•˜๋‹ค๋ฉด ์ดˆ๊ธฐํ™” ํ›„ ๋ณด์—ฌ์ฃผ๊ธฐ showSearchableSpinnerDialog() } else if (!dialog!!.isShowing) { // ๋‹ค์ด์–ผ๋กœ๊ทธ๊ฐ€ ์ดˆ๊ธฐํ™”๋˜์–ด ์žˆ๊ณ  ๋ณด์—ฌ์ง€์ง€ ์•Š๋Š” ์ƒํƒœ๋ผ๋ฉด ๋ณด์—ฌ์ฃผ๊ธฐ showSearchableSpinnerDialog() } true } // ์ดˆ๊ธฐํ™” arrayList = arrayListOf( "์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ" ) // ๋“œ๋กญ๋‹ค์šด ๋ฉ”๋‰ด์— ํ‘œ์‹œํ•  ํ•ญ๋ชฉ๋“ค val items = arrayOf("์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ") // ArrayAdapter๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋“œ๋กญ๋‹ค์šด ๋ฉ”๋‰ด์— ํ•ญ๋ชฉ๋“ค์„ ์—ฐ๊ฒฐ val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, items) adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spinner.adapter = adapter val items2 = arrayOf("์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ") // ์ €์žฅ๋œ ๊ฐ’์„ ๋ถˆ๋Ÿฌ์™€์„œ ์Šคํ”ผ๋„ˆ์— ๋Œ€์ž… val savedSpinnerItem = sharedPrefTitlewed.getString("selectedSpinnerItem", "") if (items2.contains(savedSpinnerItem)) { val positionInAdapter = items2.indexOf(savedSpinnerItem) binding.spinner.setSelection(positionInAdapter) } } // ์—…๋กœ๋“œํ•  ํŒŒ์ผ์— ์ €์žฅ๋  ๊ฐ’ ์„ค์ • private fun generateXmlData(routine: RoutineData, dayOfWeek:String): String { val xmlStringBuilder = StringBuilder() xmlStringBuilder.append("<routine>") xmlStringBuilder.append("<title>${routine.title}</title>") xmlStringBuilder.append("<con1>${routine.con1}</con1>") xmlStringBuilder.append("<con2>${routine.con2}</con2>") xmlStringBuilder.append("<con3>${routine.con3}</con3>") xmlStringBuilder.append("<con4>${routine.con4}</con4>") xmlStringBuilder.append("<con5>${routine.con5}</con5>") xmlStringBuilder.append("<edm1>${routine.edm1}</edm1>") xmlStringBuilder.append("<edm2>${routine.edm2}</edm2>") xmlStringBuilder.append("<edm3>${routine.edm3}</edm3>") xmlStringBuilder.append("<edm4>${routine.edm4}</edm4>") xmlStringBuilder.append("<edm5>${routine.edm5}</edm5>") xmlStringBuilder.append("<eds1>${routine.eds1}</eds1>") xmlStringBuilder.append("<eds2>${routine.eds2}</eds2>") xmlStringBuilder.append("<eds3>${routine.eds3}</eds3>") xmlStringBuilder.append("<eds4>${routine.eds4}</eds4>") xmlStringBuilder.append("<eds5>${routine.eds5}</eds5>") xmlStringBuilder.append("<selectedSpinnerItem>${routine.selectedSpinnerItem}</selectedSpinnerItem>") xmlStringBuilder.append("</routine>") return xmlStringBuilder.toString() } private fun initializeEditText(editText: EditText, value: String) { editText.setText(value) } private fun getSelectedSpinnerPosition(sharedPrefs: SharedPreferences, savedValue: String): Int { val items = arrayOf("์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ") return items.indexOf(savedValue).coerceAtLeast(0) } private fun showSearchableSpinnerDialog() { // dialog ์ดˆ๊ธฐํ™” dialog = Dialog(this) // dialog set dialog!!.setContentView(R.layout.dialog_searchable_spinner) dialog!!.window?.setLayout(650, 800) dialog!!.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog!!.show() val editText: EditText = dialog!!.findViewById(R.id.edit_text) val listView: ListView = dialog!!.findViewById(R.id.list_view) val dialogAdapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, arrayList) // ์–ด๋Œ‘ํ„ฐ ์„ค์ • listView.adapter = dialogAdapter editText.addTextChangedListener(object : TextWatcher { override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { dialogAdapter.filter.filter(s) } override fun afterTextChanged(s: Editable?) {} }) listView.setOnItemClickListener { _, _, position, _ -> // ์„ ํƒํ•œ ๊ฐ’์„ ํ”„๋กœํผํ‹ฐ์— ์„ค์ • selectedSpinnerValue = dialogAdapter.getItem(position).toString() val positionInAdapter = arrayList.indexOf(selectedSpinnerValue) // ์Šคํ”ผ๋„ˆ์— ์„ ํƒ๋œ ํ•ญ๋ชฉ ๋Œ€์ž… // val positionInAdapter = dialogAdapter.getPosition(selectedSpinnerValue) if (positionInAdapter != -1) { spinner.setSelection(positionInAdapter) } // ์‚ฌ์šฉ์ž๊ฐ€ ํ•ญ๋ชฉ ์„ ํƒํ•˜๋ฉด ๋‹ค์ด์–ผ๋กœ๊ทธ ๋‹ซ์Œ dialog!!.dismiss() } } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/MyActivity.kt
335701514
package com.example.android_team4_project import android.Manifest import android.content.Context import android.content.Intent import android.content.pm.PackageManager import android.graphics.BitmapFactory import android.net.Uri import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.provider.MediaStore import android.util.Log import android.view.View import android.view.View.GONE import android.widget.TextView import android.widget.Toast import androidx.activity.result.contract.ActivityResultContracts import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import com.bumptech.glide.Glide import com.example.android_team4_project.databinding.ActivityLoginBinding import com.example.android_team4_project.databinding.ActivityMyBinding import com.google.android.gms.auth.api.signin.GoogleSignIn import com.google.android.gms.auth.api.signin.GoogleSignInAccount import com.google.android.gms.auth.api.signin.GoogleSignInClient import com.google.android.gms.auth.api.signin.GoogleSignInOptions import com.google.firebase.FirebaseApp import com.google.firebase.auth.FirebaseAuth import com.google.firebase.auth.GoogleAuthProvider import com.google.firebase.firestore.FirebaseFirestore import java.io.InputStream private val STORAGE_PERMISSION_CODE = 123 class MyActivity : AppCompatActivity() { private lateinit var mGoogleSignInClient: GoogleSignInClient private lateinit var mAuth: FirebaseAuth override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val binding = ActivityMyBinding.inflate(layoutInflater) setContentView(binding.root) // ๋กœ๊ทธ์•„์›ƒ์„ ์œ„ํ•œ ์ฃผ์†Œ ๋ถˆ๋Ÿฌ์˜ค๋Š” ํ•จ์ˆ˜ mAuth = FirebaseAuth.getInstance() val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(getString(R.string.default_web_client_id)) .requestEmail() .build() mGoogleSignInClient = GoogleSignIn.getClient(this, gso) // ๋กœ๊ทธ์•„์›ƒ ๋ฆฌ์Šค๋„ˆ binding.btnSignOut.setOnClickListener { signOut() } val xmlData = intent.getStringExtra("xmlData") val Name = binding.Name FirebaseApp.initializeApp(this) val sharedPrefimg = getSharedPreferences("myPreferences", Context.MODE_PRIVATE) val sharedPreferences = getSharedPreferences("myPreferences", Context.MODE_PRIVATE) val dataToUpload = sharedPreferences.getString("userKey", "") // val db = FirebaseFirestore.getInstance() // val userUid = FirebaseAuth.getInstance().currentUser?.uid val savedImageUriString = sharedPrefimg.getString("profileImageUri", "") val savedImageUri = Uri.parse(savedImageUriString) Glide.with(this) .load(savedImageUri) .into(binding.mainprofile) // ๊ฐค๋Ÿฌ๋ฆฌ ์š”์ฒญ val reqGallery = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> try { if (result.resultCode == RESULT_OK) { result.data?.data?.let { selectedImageUri -> // ์…ˆํ”Œ ์‚ฌ์ด์ฆˆ ๋น„์œจ๊ณ„์‚ฐ ์ง€์ • val calRatio = calculateInSampleSize( selectedImageUri, resources.getDimensionPixelSize(R.dimen.imgSize), resources.getDimensionPixelSize(R.dimen.imgSize) ) val option = BitmapFactory.Options() option.inSampleSize = calRatio // ์ด๋ฏธ์ง€ ๋กœ๋”ฉ var inputStream: InputStream? = contentResolver.openInputStream(selectedImageUri) val bitmap = BitmapFactory.decodeStream(inputStream, null, option) inputStream?.close() inputStream = null bitmap?.let { binding.mainprofile.setImageBitmap(bitmap) // ์ €์žฅ๋œ ์ด๋ฏธ์ง€ URI ์—…๋ฐ์ดํŠธ saveImageUriToSharedPreferences(selectedImageUri) } ?: run { Log.d("ksj", "bitmap null") } } } } catch (e: Exception) { e.printStackTrace() } } // ์ด๋ฏธ์ง€๋ทฐ ํด๋ฆญ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋ง binding.mainprofile.setOnClickListener { val intent = Intent(Intent.ACTION_OPEN_DOCUMENT, MediaStore.Images.Media.EXTERNAL_CONTENT_URI) intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) intent.type = "image/*" reqGallery.launch(intent) } // ๋ฒ„ํŠผํด๋ฆญ์‹œ ๋งˆ์ด๋ฃจํ‹ด์œผ๋กœ ์ด๋™ binding.btnMypage.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MainActivity::class.java) startActivity(intent) } // ์ˆ˜์ • ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ binding.EditBtn.setOnClickListener { // ํ…์ŠคํŠธ๋ทฐ์™€ ์ˆ˜์ •๋ฒ„ํŠผ๊ณผ ๊ฐ€๋กœ์„ ์„ ์ˆจ๊ธฐ๊ณ  EditText์™€ ์ฒดํฌ๋ฒ„ํŠผ ํ‘œ์‹œ binding.Name.visibility = View.GONE binding.Hr.visibility = View.GONE binding.EditBtn.visibility = View.GONE //์ฒดํฌ๋ฒ„ํŠผ ๋น„์ง€๋ธ” binding.EditName.visibility = View.VISIBLE binding.Checkbtn.visibility = View.VISIBLE // EditText์— ํ…์ŠคํŠธ๋ทฐ์˜ ํ…์ŠคํŠธ ์„ค์ • binding.EditName.setText(binding.Name.text) } // EditText์—์„œ ์ฒดํฌ๋ฒ„ํŠผ ํด๋ฆญ์‹œ binding.Checkbtn.setOnClickListener { // EditText์˜ ํ…์ŠคํŠธ๋ฅผ ๊ฐ€์ ธ์˜ค๊ธฐ val editedName = binding.EditName.text.toString() // SharedPreferences๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ์ €์žฅ val sharedPref = getSharedPreferences("myPreferences", Context.MODE_PRIVATE) val editor = sharedPref.edit() editor.putString("userName", editedName) editor.apply() //ํ…์ŠคํŠธ๋ทฐ์— ์ˆ˜์ •๋œ ์ด๋ฆ„ ์„ค์ • binding.Name.text = editedName // ํ…์ŠคํŠธ๋ทฐ์™€ ์ˆ˜์ •๋ฒ„ํŠผ๊ณผ ๊ฐ€๋กœ์„ ์„ ํ‘œ์‹œํ•˜๊ณ  EditText์™€ ์ฒดํฌ๋ฒ„ํŠผ ํ‘œ์‹œ์ˆจ๊น€ binding.Name.visibility = View.VISIBLE binding.Hr.visibility = View.VISIBLE binding.EditBtn.visibility = View.VISIBLE //์ฒดํฌ๋ฒ„ํŠผ ๋น„์ง€๋ธ” binding.EditName.visibility = View.GONE binding.Checkbtn.visibility = View.GONE } // ์•ฑ์„ ์‹œ์ž‘ํ•  ๋•Œ SharedPreferences์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPref = getSharedPreferences("myPreferences", Context.MODE_PRIVATE) val savedName = sharedPref.getString("userName", "์‚ฌ์šฉ์ž") // ํ…์ŠคํŠธ๋ทฐ์— ์ €์žฅ๋œ ์ด๋ฆ„ ์„ค์ • binding.Name.text = savedName //์ถ”๊ฐ€๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํŒ์—…์—‘ํ‹ฐ๋น„ํ‹ฐ๋กœ ์ด๋™ binding.addBtnmon.setOnClickListener { val intent = Intent(this, PopupActivitymon::class.java) intent.putExtra("xmlData", xmlData) startActivity(intent) } //์ถ”๊ฐ€๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํŒ์—…์—‘ํ‹ฐ๋น„ํ‹ฐ๋กœ ์ด๋™ binding.addBtntue.setOnClickListener { val intent = Intent(this, PopupActivitytue::class.java) intent.putExtra("xmlData", xmlData) startActivity(intent) } //์ถ”๊ฐ€๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํŒ์—…์—‘ํ‹ฐ๋น„ํ‹ฐ๋กœ ์ด๋™ binding.addBtnwed.setOnClickListener { val intent = Intent(this, PopupActivitywed::class.java) intent.putExtra("xmlData", xmlData) startActivity(intent) } //์ถ”๊ฐ€๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํŒ์—…์—‘ํ‹ฐ๋น„ํ‹ฐ๋กœ ์ด๋™ binding.addBtnthu.setOnClickListener { val intent = Intent(this, PopupActivitythu::class.java) intent.putExtra("xmlData", xmlData) startActivity(intent) } //์ถ”๊ฐ€๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํŒ์—…์—‘ํ‹ฐ๋น„ํ‹ฐ๋กœ ์ด๋™ binding.addBtnfri.setOnClickListener { val intent = Intent(this, PopupActivityfri::class.java) intent.putExtra("xmlData", xmlData) startActivity(intent) } //์ถ”๊ฐ€๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํŒ์—…์—‘ํ‹ฐ๋น„ํ‹ฐ๋กœ ์ด๋™ binding.addBtnsat.setOnClickListener { val intent = Intent(this, PopupActivitysat::class.java) intent.putExtra("xmlData", xmlData) startActivity(intent) } //์ถ”๊ฐ€๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํŒ์—…์—‘ํ‹ฐ๋น„ํ‹ฐ๋กœ ์ด๋™ binding.addBtnsun.setOnClickListener { val intent = Intent(this, PopupActivitysun::class.java) intent.putExtra("xmlData", xmlData) startActivity(intent) } //์ˆ˜์ •๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํŒ์—…์—‘ํ‹ฐ๋น„ํ‹ฐ๋กœ ์ด๋™ binding.rewriteBtnmon.setOnClickListener { val intent = Intent(this, PopupActivitymon::class.java) startActivity(intent) } //์ˆ˜์ •๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํŒ์—…์—‘ํ‹ฐ๋น„ํ‹ฐ๋กœ ์ด๋™ binding.rewriteBtntue.setOnClickListener { val intent = Intent(this, PopupActivitytue::class.java) startActivity(intent) } //์ˆ˜์ •๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํŒ์—…์—‘ํ‹ฐ๋น„ํ‹ฐ๋กœ ์ด๋™ binding.rewriteBtnwed.setOnClickListener { val intent = Intent(this, PopupActivitywed::class.java) startActivity(intent) } //์ˆ˜์ •๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํŒ์—…์—‘ํ‹ฐ๋น„ํ‹ฐ๋กœ ์ด๋™ binding.rewriteBtnthu.setOnClickListener { val intent = Intent(this, PopupActivitythu::class.java) startActivity(intent) } //์ˆ˜์ •๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํŒ์—…์—‘ํ‹ฐ๋น„ํ‹ฐ๋กœ ์ด๋™ binding.rewriteBtnfri.setOnClickListener { val intent = Intent(this, PopupActivityfri::class.java) startActivity(intent) } //์ˆ˜์ •๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํŒ์—…์—‘ํ‹ฐ๋น„ํ‹ฐ๋กœ ์ด๋™ binding.rewriteBtnsat.setOnClickListener { val intent = Intent(this, PopupActivitysat::class.java) startActivity(intent) } //์ˆ˜์ •๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํŒ์—…์—‘ํ‹ฐ๋น„ํ‹ฐ๋กœ ์ด๋™ binding.rewriteBtnsun.setOnClickListener { val intent = Intent(this, PopupActivitysun::class.java) startActivity(intent) } binding.mon.setOnClickListener { val intent = Intent(this, DetailActivitymon::class.java) startActivity(intent) } binding.tue.setOnClickListener { val intent = Intent(this, DetailActivitytue::class.java) startActivity(intent) } binding.wed.setOnClickListener { val intent = Intent(this, DetailActivitywed::class.java) startActivity(intent) } binding.thu.setOnClickListener { val intent = Intent(this, DetailActivitythu::class.java) startActivity(intent) } binding.fri.setOnClickListener { val intent = Intent(this, DetailActivityfri::class.java) startActivity(intent) } binding.sat.setOnClickListener { val intent = Intent(this, DetailActivitysat::class.java) startActivity(intent) } binding.sun.setOnClickListener { val intent = Intent(this, DetailActivitysun::class.java) startActivity(intent) } // ํ•ด๋‹น ๋ถ€๋ถ„ Uid๊ฐ’ ๋ฐ›์•„์™€์„œ ์ถœ๋ ฅํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์ˆ˜์ • val userUid = FirebaseAuth.getInstance().currentUser?.uid val sharedPrefTitlemon = userUid?.let { getSharedPreferences("Routine_Mon$it", Context.MODE_PRIVATE) } ?: getSharedPreferences("Routine_MonDefault", Context.MODE_PRIVATE) val sharedPrefTitletue = userUid?.let { getSharedPreferences("Routine_Tue$it", Context.MODE_PRIVATE) } ?: getSharedPreferences("Routine_TueDefault", Context.MODE_PRIVATE) val sharedPrefTitlewed = userUid?.let { getSharedPreferences("Routine_Wed$it", Context.MODE_PRIVATE) } ?: getSharedPreferences("Routine_WedDefault", Context.MODE_PRIVATE) val sharedPrefTitlethu = userUid?.let { getSharedPreferences("Routine_Thu$it", Context.MODE_PRIVATE) } ?: getSharedPreferences("Routine_ThuDefault", Context.MODE_PRIVATE) val sharedPrefTitlefri = userUid?.let { getSharedPreferences("Routine_Fri$it", Context.MODE_PRIVATE) } ?: getSharedPreferences("Routine_FriDefault", Context.MODE_PRIVATE) val sharedPrefTitlesat = userUid?.let { getSharedPreferences("Routine_Sat$it", Context.MODE_PRIVATE) } ?: getSharedPreferences("Routine_SatDefault", Context.MODE_PRIVATE) val sharedPrefTitlesun = userUid?.let { getSharedPreferences("Routine_Sun$it", Context.MODE_PRIVATE) } ?: getSharedPreferences("Routine_SunDefault", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitlemon = sharedPrefTitlemon.getString("title", "") val savedSpinnermon = sharedPrefTitlemon.getString("selectedSpinnerItem", "") val savedTitletue = sharedPrefTitletue.getString("title", "") val savedSpinnertue = sharedPrefTitletue.getString("selectedSpinnerItem", "") val savedTitlewed = sharedPrefTitlewed.getString("title", "") val savedSpinnerwed = sharedPrefTitlewed.getString("selectedSpinnerItem", "") val savedTitlethu = sharedPrefTitlethu.getString("title", "") val savedSpinnerthu = sharedPrefTitlethu.getString("selectedSpinnerItem", "") val savedTitlefri = sharedPrefTitlefri.getString("title", "") val savedSpinnerfri = sharedPrefTitlefri.getString("selectedSpinnerItem", "") val savedTitlesat = sharedPrefTitlesat.getString("title", "") val savedSpinnersat = sharedPrefTitlesat.getString("selectedSpinnerItem", "") val savedTitlesun = sharedPrefTitlesun.getString("title", "") val savedSpinnersun = sharedPrefTitlesun.getString("selectedSpinnerItem", "") // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • binding.titlemon.text = savedTitlemon binding.spinnermon.text = savedSpinnermon binding.titletue.text = savedTitletue binding.spinnertue.text = savedSpinnertue binding.titlewed.text = savedTitlewed binding.spinnerwed.text = savedSpinnerwed binding.titlethu.text = savedTitlethu binding.spinnerthu.text = savedSpinnerthu binding.titlefri.text = savedTitlefri binding.spinnerfri.text = savedSpinnerfri binding.titlesat.text = savedTitlesat binding.spinnersat.text = savedSpinnersat binding.titlesun.text = savedTitlesun binding.spinnersun.text = savedSpinnersun if (!savedTitlemon.isNullOrBlank() && savedSpinnermon != "์„ ํƒํ•˜๊ธฐ") { binding.addBtnmon.visibility = View.GONE binding.rewriteBtnmon.visibility = View.VISIBLE binding.rewriteBtnmon.setOnClickListener { val intent = Intent(this, PopupActivitymon::class.java) startActivity(intent) } } else { binding.addBtnmon.visibility = View.VISIBLE binding.rewriteBtnmon.visibility = View.GONE } if (!savedTitletue.isNullOrBlank() && savedSpinnertue != "์„ ํƒํ•˜๊ธฐ") { binding.addBtntue.visibility = View.GONE binding.rewriteBtntue.visibility = View.VISIBLE binding.rewriteBtntue.setOnClickListener { val intent = Intent(this, PopupActivitytue::class.java) startActivity(intent) } } else { binding.addBtntue.visibility = View.VISIBLE binding.rewriteBtntue.visibility = View.GONE } if (!savedTitlewed.isNullOrBlank() && savedSpinnerwed != "์„ ํƒํ•˜๊ธฐ") { binding.addBtnwed.visibility = View.GONE binding.rewriteBtnwed.visibility = View.VISIBLE binding.rewriteBtnwed.setOnClickListener { val intent = Intent(this, PopupActivitywed::class.java) startActivity(intent) } } else { binding.addBtnwed.visibility = View.VISIBLE binding.rewriteBtnwed.visibility = View.GONE } if (!savedTitlethu.isNullOrBlank() && savedSpinnerthu != "์„ ํƒํ•˜๊ธฐ") { binding.addBtnthu.visibility = View.GONE binding.rewriteBtnthu.visibility = View.VISIBLE binding.rewriteBtnthu.setOnClickListener { val intent = Intent(this, PopupActivitythu::class.java) startActivity(intent) } } else { binding.addBtnthu.visibility = View.VISIBLE binding.rewriteBtnthu.visibility = View.GONE } if (!savedTitlefri.isNullOrBlank() && savedSpinnerfri != "์„ ํƒํ•˜๊ธฐ") { binding.addBtnfri.visibility = View.GONE binding.rewriteBtnfri.visibility = View.VISIBLE binding.rewriteBtnfri.setOnClickListener { val intent = Intent(this, PopupActivityfri::class.java) startActivity(intent) } } else { binding.addBtnfri.visibility = View.VISIBLE binding.rewriteBtnfri.visibility = View.GONE } if (!savedTitlesat.isNullOrBlank() && savedSpinnersat != "์„ ํƒํ•˜๊ธฐ") { binding.addBtnsat.visibility = View.GONE binding.rewriteBtnsat.visibility = View.VISIBLE binding.rewriteBtnsat.setOnClickListener { val intent = Intent(this, PopupActivitysat::class.java) startActivity(intent) } } else { binding.addBtnsat.visibility = View.VISIBLE binding.rewriteBtnsat.visibility = View.GONE } if (!savedTitlesun.isNullOrBlank() && savedSpinnersun != "์„ ํƒํ•˜๊ธฐ") { binding.addBtnsun.visibility = View.GONE binding.rewriteBtnsun.visibility = View.VISIBLE binding.rewriteBtnsun.setOnClickListener { val intent = Intent(this, PopupActivitysun::class.java) startActivity(intent) } } else { binding.addBtnsun.visibility = View.VISIBLE binding.rewriteBtnsun.visibility = View.GONE } // "users" ์ปฌ๋ ‰์…˜์— ์‚ฌ์šฉ์ž UID๋ฅผ ๋ฌธ์„œ๋กœ ๊ฐ–๋Š” ๋ฐ์ดํ„ฐ ์ €์žฅ // db.collection("users").document(userUid!!) // .set(mapOf("data" to dataToUpload)) // .addOnSuccessListener { // // ์—…๋กœ๋“œ ์„ฑ๊ณต ์‹œ ์ฒ˜๋ฆฌ // } // .addOnFailureListener { // // ์—…๋กœ๋“œ ์‹คํŒจ ์‹œ ์ฒ˜๋ฆฌ // } // FirebaseAuth์—์„œ ํ˜„์žฌ ์‚ฌ์šฉ์ž ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ val currentUser = FirebaseAuth.getInstance().currentUser if (currentUser != null && currentUser.providerData.any { it.providerId == GoogleAuthProvider.PROVIDER_ID }) { // ์‚ฌ์šฉ์ž๊ฐ€ Google ๊ณ„์ •์œผ๋กœ ๋กœ๊ทธ์ธํ•œ ๊ฒฝ์šฐ // Google ๊ณ„์ •์—์„œ ์‚ฌ์šฉ์ž ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ val googleSignInAccount = GoogleSignIn.getLastSignedInAccount(this) // ์‚ฌ์šฉ์ž ๋‹‰๋„ค์ž„์„ TextView์— ์„ค์ • Name.text = googleSignInAccount?.displayName } else { // ์‚ฌ์šฉ์ž๊ฐ€ ๋กœ๊ทธ์ธ๋˜์–ด ์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ, ๋กœ๊ทธ์ธ ํ™”๋ฉด์œผ๋กœ ์ด๋™ val intent = Intent(this, LoginActivity::class.java) startActivity(intent) finish() // ํ˜„์žฌ ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ์ข…๋ฃŒํ•˜์—ฌ ๋’ค๋กœ ๊ฐ€๊ธฐ ๋ฒ„ํŠผ์œผ๋กœ ๋กœ๊ทธ์ธ ํ™”๋ฉด์— ๋Œ์•„๊ฐ€์ง€ ์•Š๋„๋ก ํ•จ } } // ๋กœ๊ทธ์•„์›ƒ ์‹คํ–‰๋ถ€๋ถ„ ํ•จ์ˆ˜ใ„ดใ…‡ private fun signOut() { mAuth.signOut() mGoogleSignInClient.signOut().addOnCompleteListener(this) { Toast.makeText(this, "Sign out successful", Toast.LENGTH_SHORT).show() } val intent = Intent(this@MyActivity, LoginActivity::class.java) startActivity(intent) } // ์ด๋ฏธ์ง€ ์ €์žฅ private fun saveImageUriToSharedPreferences(imageUri: Uri) { val sharedPref = getSharedPreferences("myPreferences", Context.MODE_PRIVATE) val editor = sharedPref.edit() editor.putString("profileImageUri", imageUri.toString()) editor.apply() } private fun checkStoragePermission() { if (ContextCompat.checkSelfPermission( this, Manifest.permission.READ_EXTERNAL_STORAGE ) != PackageManager.PERMISSION_GRANTED ) { // ๊ถŒํ•œ์ด ์—†๋Š” ๊ฒฝ์šฐ, ๊ถŒํ•œ์„ ์š”์ฒญ ActivityCompat.requestPermissions( this, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), STORAGE_PERMISSION_CODE ) } else { // ์ด๋ฏธ ๊ถŒํ•œ์ด ๋ถ€์—ฌ๋œ ๊ฒฝ์šฐ์— ๋Œ€ํ•œ ๋กœ์ง } } private fun calculateInSampleSize(fileUri: Uri, reqWidth: Int, reqHeight: Int): Int { val options = BitmapFactory.Options() options.inJustDecodeBounds = true try { var inputStream = contentResolver.openInputStream(fileUri) BitmapFactory.decodeStream(inputStream, null, options) inputStream!!.close() inputStream = null } catch (e: Exception) { e.printStackTrace() } val (height: Int, width: Int) = options.run { outHeight to outWidth } var inSampleSize = 1 if (height > reqHeight || width > reqWidth) { val halfHeight: Int = height / 2 val halfWidth: Int = width / 2 while (halfHeight / inSampleSize >= reqHeight && halfWidth / inSampleSize >= reqWidth) { inSampleSize *= 2 } } return inSampleSize } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/StopActivity3.kt
380985920
package com.example.android_team4_project import android.app.NotificationChannel import android.app.NotificationManager import android.content.Context import android.content.Intent import android.graphics.Color import android.os.Build import android.os.Bundle import android.os.SystemClock import android.util.Log import android.view.KeyEvent import android.view.View import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.core.app.NotificationCompat import com.example.android_team4_project.databinding.ActivityStop3Binding class StopActivity3 : AppCompatActivity() { var initTime = 0L var pauseTime = 0L override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val binding = ActivityStop3Binding.inflate(layoutInflater) setContentView(binding.root) binding.btnStart3.setOnClickListener { binding.chronometer3.base = SystemClock.elapsedRealtime() + pauseTime binding.chronometer3.start() binding.btnStop3.isEnabled = true binding.btnReset3.isEnabled = true binding.btnStart3.isEnabled = false binding.btnSave3.visibility = View.INVISIBLE } // binding.btnStop.text = "Stop" binding.btnStop3.setOnClickListener { pauseTime = binding.chronometer3.base - SystemClock.elapsedRealtime() binding.chronometer3.stop() binding.btnStart3.isEnabled = true binding.btnStop3.isEnabled = false binding.btnReset3.isEnabled = true binding.btnSave3.isEnabled = true binding.btnSave3.visibility = View.VISIBLE } binding.btnReset3.setOnClickListener { // binding.btnReset.text = "Reset" pauseTime = 0L binding.chronometer3.base = SystemClock.elapsedRealtime() binding.chronometer3.stop() binding.btnStart3.isEnabled = true binding.btnStop3.isEnabled = false binding.btnReset3.isEnabled = false binding.btnSave3.visibility = View.INVISIBLE } //getTime1์™€ chronometer๊ฐ’์ด ๊ฐ™์•„์ง€๋ฉด notification๋œจ๊ฒŒํ•˜๊ธฐ binding.chronometer3.setOnChronometerTickListener{ // Mainactivity์—์„œ stopActivity1 ์—ด๋•Œ ๋ณด๋ƒˆ๋˜ ์‚ฌ์šฉ์ž๊ฐ€ ์ง€์ •ํ•œ ๋ฃจํ‹ด ์‹œ๊ฐ„ ๊ฐ’ ๋ฐ›์•„์˜ค๊ธฐ val isGetTime3 = intent.getStringExtra("isGetTime3") // ์ •๊ทœ์‹์„ ์‚ฌ์šฉํ•˜์—ฌ "๋ถ„"๊ณผ "์ดˆ"๋ฅผ ์—†์• ๊ณ , ":"๋กœ ๋ถ„๊ณผ ์ดˆ๋ฅผ ๊ตฌ๋ถ„ํ•˜์—ฌ ํ•ฉ์น˜๊ธฐ val modifiedText = isGetTime3.toString().replace(Regex("[^0-9]"), "").chunked(2).joinToString(":") { it } val elapsedMillis = SystemClock.elapsedRealtime() - binding.chronometer3.base val elapsedSeconds = elapsedMillis / 1000 // TextView ์—…๋ฐ์ดํŠธ ๋˜๋Š” ํŠน์ • ์‹œ๊ฐ„์— ๋„๋‹ฌํ•˜๋ฉด ์•Œ๋ฆผ ๋“ฑ // ๊ฒฝ๊ณผ๋œ ์‹œ๊ฐ„์„ ๋ถ„๊ณผ ์ดˆ๋กœ ๋ณ€ํ™˜ val elapsedMinutes = elapsedSeconds / 60 val remainingSeconds = elapsedSeconds % 60 val currentTime = String.format("%02d:%02d", elapsedMinutes, remainingSeconds) if(modifiedText == currentTime){ notiAlarm() // Toast.makeText(this,"good" , Toast.LENGTH_SHORT).show() } } binding.btnSave3.setOnClickListener { pauseTime = binding.chronometer3.base - SystemClock.elapsedRealtime() binding.chronometer3.stop() val intent = Intent(this, MainActivity::class.java) // intent.putExtra("times3", binding.chronometer3.text.toString()) startActivity(intent) val sharePref3 = getSharedPreferences("stop3", Context.MODE_PRIVATE) val editor3 = sharePref3.edit() editor3.putString("times3", binding.chronometer3.text.toString()) editor3.apply() } } private fun notiAlarm() { // getSystemService(์„œ๋น„์Šค) : ์•ˆ๋“œ๋กœ์ด๋“œ ์‹œ์Šคํ…œ์—์„œ ๋™์ž‘ํ•˜๊ณ  ์žˆ๋Š” ์„œ๋น„์Šค ์ค‘ ์ง€์ •ํ•œ ์„œ๋น„์Šค๋ฅผ ๊ฐ€์ ธ์˜ด // getSystemService() ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ NotificationManager ํƒ€์ž…์˜ ๊ฐ์ฒด ๊ฐ€์ ธ์˜ค๊ธฐ val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager // NotificationCompat ํƒ€์ž…์˜ ๊ฐ์ฒด๋ฅผ ์ €์žฅํ•  ๋ณ€์ˆ˜ ์„ ์–ธ val builder: NotificationCompat.Builder // API 26๋ถ€ํ„ฐ ์ฑ„๋„์ด ์ถ”๊ฐ€ ๋˜์–ด ๋ฒ„์ „์— ๋”ฐ๋ผ ์‚ฌ์šฉ ๋ฐฉ์‹์„ ๋ณ€๊ฒฝ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val channelId = "one-channel" val channelName = "My Channel One" // ์ฑ„๋„ ๊ฐ์ฒด ์ƒ์„ฑ val channel = NotificationChannel( channelId, channelName, // ์•Œ๋ฆผ ๋“ฑ๊ธ‰ ์„ค์ • NotificationManager.IMPORTANCE_DEFAULT ) channel.description = "My Channel One description" channel.setShowBadge(true) // ์•Œ๋ฆผ ์‹œ ๋ผ์ดํŠธ ์‚ฌ์šฉ channel.enableLights(true) channel.lightColor = Color.RED // ์ง€์ •ํ•œ ์ฑ„๋„ ์ •๋ณด๋ฅผ ํ†ตํ•ด์„œ ์ฑ„๋„ ์ƒ์„ฑ manager.createNotificationChannel(channel) // NotificationCompat ํƒ€์ž…์˜ ๊ฐ์ฒด ์ƒ์„ฑ builder = NotificationCompat.Builder(this, channelId) } else { builder = NotificationCompat.Builder(this) } // ์Šคํ…Œ์ด์Šคํ„ฐ์ฐฝ ์•Œ๋ฆผ ํ™”๋ฉด ์„ค์ • builder.setSmallIcon(android.R.drawable.ic_notification_overlay) builder.setWhen(System.currentTimeMillis()) builder.setContentTitle("์•Œ๋ฆผ") builder.setContentText("๋ฃจํ‹ด ์„ฑ๊ณต!") // NotificationManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์Šคํ…Œ์ดํ„ฐ์Šค์ฐฝ์— ์•Œ๋ฆผ์ฐฝ ์ถœ๋ ฅ manager.notify(11, builder.build()) } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/MyApplication.kt
741804922
package com.example.android_team4_project import android.content.Intent import android.widget.Toast import androidx.lifecycle.MutableLiveData import androidx.multidex.MultiDexApplication import com.google.android.gms.auth.api.signin.GoogleSignIn import com.google.android.gms.auth.api.signin.GoogleSignInAccount import com.google.android.gms.auth.api.signin.GoogleSignInClient import com.google.android.gms.auth.api.signin.GoogleSignInOptions import com.google.android.gms.common.api.ApiException import com.google.android.gms.tasks.Task import com.google.firebase.auth.FirebaseAuth import com.google.firebase.auth.GoogleAuthProvider import com.google.firebase.auth.ktx.auth import com.google.firebase.ktx.Firebase class MyApplication:MultiDexApplication() { companion object { private lateinit var instance: MyApplication lateinit var auth: FirebaseAuth private var mGoogleSignInClient: GoogleSignInClient? = null private val signInCallback = MutableLiveData<GoogleSignInAccount?>() fun getSignInCallback(): MutableLiveData<GoogleSignInAccount?> { return signInCallback } fun getInstance(): MyApplication { return instance } private fun getGoogleSignInOptions(): GoogleSignInOptions { return GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(instance.getString(R.string.default_web_client_id)) .requestEmail() .build() } private fun initializeGoogleSignInClient() { mGoogleSignInClient = GoogleSignIn.getClient(instance, getGoogleSignInOptions()) } fun signInWithGoogle() { initializeGoogleSignInClient() val signInIntent = mGoogleSignInClient?.signInIntent instance.startActivity(signInIntent) } fun handleGoogleSignInResult(completedTask: Task<GoogleSignInAccount>) { try { val account = completedTask.getResult(ApiException::class.java) signInCallback.value = account } catch (e: ApiException) { // Google Sign-In ์‹คํŒจ ์ฒ˜๋ฆฌ signInCallback.value = null } } var email: String? = null fun checkAuth(): Boolean { val currentUser = auth.currentUser return currentUser?.let { email = currentUser.email if (currentUser.isEmailVerified) { true } else { false } } ?: let { false } } } fun firebaseAuthWithGoogle(account: GoogleSignInAccount?) { val credential = GoogleAuthProvider.getCredential(account?.idToken, null) auth.signInWithCredential(credential) .addOnCompleteListener { task -> if (task.isSuccessful) { // Firebase ์ธ์ฆ ์„ฑ๊ณต ์‹œ ์ฒ˜๋ฆฌ val intent = Intent(instance, MyActivity::class.java) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK instance.startActivity(intent) } else { // Firebase ์ธ์ฆ ์‹คํŒจ ์‹œ ์ฒ˜๋ฆฌ Toast.makeText(instance, "Authentication Failed.", Toast.LENGTH_SHORT).show() } } } override fun onCreate() { super.onCreate() auth = Firebase.auth instance = this } fun checkGoogleSignInAndNavigate() { val gsa = GoogleSignIn.getLastSignedInAccount(instance) if (gsa != null) { // Google ๊ณ„์ •์œผ๋กœ ๋กœ๊ทธ์ธ๋œ ์ƒํƒœ Toast.makeText(instance, R.string.status_login, Toast.LENGTH_SHORT).show() navigateToMyPage() } else { // Google ๊ณ„์ •์œผ๋กœ ๋กœ๊ทธ์ธ๋˜์ง€ ์•Š์€ ์ƒํƒœ Toast.makeText(instance, R.string.status_not_login, Toast.LENGTH_SHORT).show() navigateToLoginPage() } } private fun navigateToMyPage() { val intent = Intent(this, MyActivity::class.java) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK startActivity(intent) } private fun navigateToLoginPage() { val intent = Intent(this, LoginActivity::class.java) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK startActivity(intent) } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/MainActivity.kt
609781131
package com.example.android_team4_project import android.app.DatePickerDialog import android.app.NotificationManager import android.content.Context import android.content.Intent import android.icu.util.Calendar import android.os.Bundle import android.view.View import android.widget.FrameLayout import androidx.appcompat.app.AppCompatActivity import com.example.android_team4_project.databinding.ActivityMainBinding import com.google.android.material.bottomnavigation.BottomNavigationView import android.content.DialogInterface import android.widget.RelativeLayout import android.widget.TextView import android.widget.Toast import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.text.Editable import android.widget.Button import android.widget.CalendarView import androidx.appcompat.app.AlertDialog import androidx.core.content.ContextCompat import com.google.firebase.auth.FirebaseAuth import java.text.DateFormat import java.text.SimpleDateFormat import java.util.Date import java.util.Locale class MainActivity : AppCompatActivity() { private lateinit var mAuth: FirebaseAuth //ํƒ€์ด๋จธ ์„ฑ๊ณต์‹คํŒจ ํŒ๋‹จ์šฉ ์ „์—ญ๋ณ€์ˆ˜ private var timesuccess1 = 0 private var timesuccess2 = 0 private var timesuccess3 = 0 private var timesuccess4 = 0 private var timesuccess5 = 0 private lateinit var binding: ActivityMainBinding // View Binding ์ถ”๊ฐ€ // private lateinit var intent: Intent // ํ•˜๋‹จ ๋ฉ”๋‰ด๋ฐ”๋กœ frameLayout ๋™์  ์ œ์–ด private lateinit var frameLayout1: FrameLayout private lateinit var frameLayout2: FrameLayout private lateinit var frameLayout3: FrameLayout private lateinit var bottomNavigationView: BottomNavigationView private var savedPref1: String? = null private var savedPref2: String? = null private var savedPref3: String? = null private var savedPref4: String? = null private var savedPref5: String? = null private fun showFrameLayout(frameLayout: FrameLayout) { frameLayout1.visibility = if (frameLayout == frameLayout1) View.VISIBLE else View.INVISIBLE frameLayout2.visibility = if (frameLayout == frameLayout2) View.VISIBLE else View.INVISIBLE frameLayout3.visibility = if (frameLayout == frameLayout3) View.VISIBLE else View.INVISIBLE } // ์ „์—ฐํ•จ์ˆ˜ : ์˜ค๋Š˜๋‚ ์งœ์— ํ•ด๋‹นํ•˜๋Š” ์š”์ผ๊ฐ€์ ธ์˜ค๊ณ  ํ•œ๊ธ€๋กœ ๋ณ€ํ™˜ private fun getDayOfWeek(): String { val calendar = Calendar.getInstance() val dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) // ์š”์ผ์„ ํ•œ๊ธ€๋กœ ๋ณ€ํ™˜ return when (dayOfWeek) { Calendar.SUNDAY -> "์ผ" Calendar.MONDAY -> "์›”" Calendar.TUESDAY -> "ํ™”" Calendar.WEDNESDAY -> "์ˆ˜" Calendar.THURSDAY -> "๋ชฉ" Calendar.FRIDAY -> "๊ธˆ" Calendar.SATURDAY -> "ํ† " else -> "" } } private val nowDay: Int by lazy { Calendar.getInstance().get(Calendar.DAY_OF_WEEK) } // ์š”์ผ๋ณ„๋กœ ๋ฐ์ดํ„ฐ ์‚ฝ์ž… private fun init(todayDayOfWeek: String) { val userUid = FirebaseAuth.getInstance().currentUser?.uid when (todayDayOfWeek) { "์ผ" -> { // sharedPref์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPrefTitlesun = getSharedPreferences("Routine_Sun$userUid", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitlesun = sharedPrefTitlesun.getString("title", "") val savedSpinnersun = sharedPrefTitlesun.getString("selectedSpinnerItem", "") val savedContentsun1 = sharedPrefTitlesun.getString("con1", "") val savedContentsun2 = sharedPrefTitlesun.getString("con2", "") val savedContentsun3 = sharedPrefTitlesun.getString("con3", "") val savedContentsun4 = sharedPrefTitlesun.getString("con4", "") val savedContentsun5 = sharedPrefTitlesun.getString("con5", "") val savededm1 = sharedPrefTitlesun.getString("edm1", "") val savededm2 = sharedPrefTitlesun.getString("edm2", "") val savededm3 = sharedPrefTitlesun.getString("edm3", "") val savededm4 = sharedPrefTitlesun.getString("edm4", "") val savededm5 = sharedPrefTitlesun.getString("edm5", "") val savededs1 = sharedPrefTitlesun.getString("eds1", "") val savededs2 = sharedPrefTitlesun.getString("eds2", "") val savededs3 = sharedPrefTitlesun.getString("eds3", "") val savededs4 = sharedPrefTitlesun.getString("eds4", "") val savededs5 = sharedPrefTitlesun.getString("eds5", "") // null๊ฐ’ ํ—ˆ์šฉ val intSavededm1 = savededm1?.toIntOrNull() ?: 0 val intSavededs1 = savededs1?.toIntOrNull() ?: 0 // 00๋ถ„ 00์ดˆ ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ val formattedSavededm1 = "%02d".format(intSavededm1) val formattedSavededs1 = "%02d".format(intSavededs1) val timeText1 = "${formattedSavededm1}๋ถ„ ${formattedSavededs1}์ดˆ" val intSavededm2 = savededm2?.toIntOrNull() ?: 0 val intSavededs2 = savededs2?.toIntOrNull() ?: 0 val formattedSavededm2 = "%02d".format(intSavededm2) val formattedSavededs2 = "%02d".format(intSavededs2) val timeText2 = "${formattedSavededm2}๋ถ„ ${formattedSavededs2}์ดˆ" val intSavededm3 = savededm3?.toIntOrNull() ?: 0 val intSavededs3 = savededs3?.toIntOrNull() ?: 0 val formattedSavededm3 = "%02d".format(intSavededm3) val formattedSavededs3 = "%02d".format(intSavededs3) val timeText3 = "${formattedSavededm3}๋ถ„ ${formattedSavededs3}์ดˆ" val intSavededm4 = savededm4?.toIntOrNull() ?: 0 val intSavededs4 = savededs4?.toIntOrNull() ?: 0 val formattedSavededm4 = "%02d".format(intSavededm4) val formattedSavededs4 = "%02d".format(intSavededs4) val timeText4 = "${formattedSavededm4}๋ถ„ ${formattedSavededs4}์ดˆ" val intSavededm5 = savededm5?.toIntOrNull() ?: 0 val intSavededs5 = savededs5?.toIntOrNull() ?: 0 val formattedSavededm5 = "%02d".format(intSavededm5) val formattedSavededs5 = "%02d".format(intSavededs5) val timeText5 = "${formattedSavededm5}๋ถ„ ${formattedSavededs5}์ดˆ" // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • binding.getTitle.text = savedTitlesun binding.getSpinner.text = savedSpinnersun binding.getRoutine1.text = savedContentsun1 binding.getRoutine2.text = savedContentsun2 binding.getRoutine3.text = savedContentsun3 binding.getRoutine4.text = savedContentsun4 binding.getRoutine5.text = savedContentsun5 binding.getTime1.text = timeText1 binding.getTime2.text = timeText2 binding.getTime3.text = timeText3 binding.getTime4.text = timeText4 binding.getTime5.text = timeText5 binding.getHomeSpinner.text = savedSpinnersun binding.getHomeTitle.text = savedTitlesun } "์›”" -> { // sharedPref์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPrefTitlemon = getSharedPreferences("Routine_Mon$userUid", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitlemon = sharedPrefTitlemon.getString("title", "") val savedSpinnermon = sharedPrefTitlemon.getString("selectedSpinnerItem", "") val savedContentmon1 = sharedPrefTitlemon.getString("con1", "") val savedContentmon2 = sharedPrefTitlemon.getString("con2", "") val savedContentmon3 = sharedPrefTitlemon.getString("con3", "") val savedContentmon4 = sharedPrefTitlemon.getString("con4", "") val savedContentmon5 = sharedPrefTitlemon.getString("con5", "") val savededm1 = sharedPrefTitlemon.getString("edm1", "") val savededm2 = sharedPrefTitlemon.getString("edm2", "") val savededm3 = sharedPrefTitlemon.getString("edm3", "") val savededm4 = sharedPrefTitlemon.getString("edm4", "") val savededm5 = sharedPrefTitlemon.getString("edm5", "") val savededs1 = sharedPrefTitlemon.getString("eds1", "") val savededs2 = sharedPrefTitlemon.getString("eds2", "") val savededs3 = sharedPrefTitlemon.getString("eds3", "") val savededs4 = sharedPrefTitlemon.getString("eds4", "") val savededs5 = sharedPrefTitlemon.getString("eds5", "") // null๊ฐ’ ํ—ˆ์šฉ val intSavededm1 = savededm1?.toIntOrNull() ?: 0 val intSavededs1 = savededs1?.toIntOrNull() ?: 0 // 00๋ถ„ 00์ดˆ ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ val formattedSavededm1 = "%02d".format(intSavededm1) val formattedSavededs1 = "%02d".format(intSavededs1) val timeText1 = "${formattedSavededm1}๋ถ„ ${formattedSavededs1}์ดˆ" val intSavededm2 = savededm2?.toIntOrNull() ?: 0 val intSavededs2 = savededs2?.toIntOrNull() ?: 0 val formattedSavededm2 = "%02d".format(intSavededm2) val formattedSavededs2 = "%02d".format(intSavededs2) val timeText2 = "${formattedSavededm2}๋ถ„ ${formattedSavededs2}์ดˆ" val intSavededm3 = savededm3?.toIntOrNull() ?: 0 val intSavededs3 = savededs3?.toIntOrNull() ?: 0 val formattedSavededm3 = "%02d".format(intSavededm3) val formattedSavededs3 = "%02d".format(intSavededs3) val timeText3 = "${formattedSavededm3}๋ถ„ ${formattedSavededs3}์ดˆ" val intSavededm4 = savededm4?.toIntOrNull() ?: 0 val intSavededs4 = savededs4?.toIntOrNull() ?: 0 val formattedSavededm4 = "%02d".format(intSavededm4) val formattedSavededs4 = "%02d".format(intSavededs4) val timeText4 = "${formattedSavededm4}๋ถ„ ${formattedSavededs4}์ดˆ" val intSavededm5 = savededm5?.toIntOrNull() ?: 0 val intSavededs5 = savededs5?.toIntOrNull() ?: 0 val formattedSavededm5 = "%02d".format(intSavededm5) val formattedSavededs5 = "%02d".format(intSavededs5) val timeText5 = "${formattedSavededm5}๋ถ„ ${formattedSavededs5}์ดˆ" // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • binding.getTitle.text = savedTitlemon binding.getSpinner.text = savedSpinnermon binding.getRoutine1.text = savedContentmon1 binding.getRoutine2.text = savedContentmon2 binding.getRoutine3.text = savedContentmon3 binding.getRoutine4.text = savedContentmon4 binding.getRoutine5.text = savedContentmon5 binding.getTime1.text = timeText1 binding.getTime2.text = timeText2 binding.getTime3.text = timeText3 binding.getTime4.text = timeText4 binding.getTime5.text = timeText5 binding.getHomeSpinner.text = savedSpinnermon binding.getHomeTitle.text = savedTitlemon } "ํ™”" -> { // sharedPref์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPrefTitletue = getSharedPreferences("Routine_Tue$userUid", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitletue = sharedPrefTitletue.getString("title", "") val savedSpinnertue = sharedPrefTitletue.getString("selectedSpinnerItem", "") val savedContenttue1 = sharedPrefTitletue.getString("con1", "") val savedContenttue2 = sharedPrefTitletue.getString("con2", "") val savedContenttue3 = sharedPrefTitletue.getString("con3", "") val savedContenttue4 = sharedPrefTitletue.getString("con4", "") val savedContenttue5 = sharedPrefTitletue.getString("con5", "") val savededm1 = sharedPrefTitletue.getString("edm1", "") val savededm2 = sharedPrefTitletue.getString("edm2", "") val savededm3 = sharedPrefTitletue.getString("edm3", "") val savededm4 = sharedPrefTitletue.getString("edm4", "") val savededm5 = sharedPrefTitletue.getString("edm5", "") val savededs1 = sharedPrefTitletue.getString("eds1", "") val savededs2 = sharedPrefTitletue.getString("eds2", "") val savededs3 = sharedPrefTitletue.getString("eds3", "") val savededs4 = sharedPrefTitletue.getString("eds4", "") val savededs5 = sharedPrefTitletue.getString("eds5", "") // null๊ฐ’ ํ—ˆ์šฉ val intSavededm1 = savededm1?.toIntOrNull() ?: 0 val intSavededs1 = savededs1?.toIntOrNull() ?: 0 // 00๋ถ„ 00์ดˆ ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ val formattedSavededm1 = "%02d".format(intSavededm1) val formattedSavededs1 = "%02d".format(intSavededs1) val timeText1 = "${formattedSavededm1}๋ถ„ ${formattedSavededs1}์ดˆ" val intSavededm2 = savededm2?.toIntOrNull() ?: 0 val intSavededs2 = savededs2?.toIntOrNull() ?: 0 val formattedSavededm2 = "%02d".format(intSavededm2) val formattedSavededs2 = "%02d".format(intSavededs2) val timeText2 = "${formattedSavededm2}๋ถ„ ${formattedSavededs2}์ดˆ" val intSavededm3 = savededm3?.toIntOrNull() ?: 0 val intSavededs3 = savededs3?.toIntOrNull() ?: 0 val formattedSavededm3 = "%02d".format(intSavededm3) val formattedSavededs3 = "%02d".format(intSavededs3) val timeText3 = "${formattedSavededm3}๋ถ„ ${formattedSavededs3}์ดˆ" val intSavededm4 = savededm4?.toIntOrNull() ?: 0 val intSavededs4 = savededs4?.toIntOrNull() ?: 0 val formattedSavededm4 = "%02d".format(intSavededm4) val formattedSavededs4 = "%02d".format(intSavededs4) val timeText4 = "${formattedSavededm4}๋ถ„ ${formattedSavededs4}์ดˆ" val intSavededm5 = savededm5?.toIntOrNull() ?: 0 val intSavededs5 = savededs5?.toIntOrNull() ?: 0 val formattedSavededm5 = "%02d".format(intSavededm5) val formattedSavededs5 = "%02d".format(intSavededs5) val timeText5 = "${formattedSavededm5}๋ถ„ ${formattedSavededs5}์ดˆ" // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • binding.getTitle.text = savedTitletue binding.getSpinner.text = savedSpinnertue binding.getRoutine1.text = savedContenttue1 binding.getRoutine2.text = savedContenttue2 binding.getRoutine3.text = savedContenttue3 binding.getRoutine4.text = savedContenttue4 binding.getRoutine5.text = savedContenttue5 binding.getTime1.text = timeText1 binding.getTime2.text = timeText2 binding.getTime3.text = timeText3 binding.getTime4.text = timeText4 binding.getTime5.text = timeText5 binding.getHomeSpinner.text = savedSpinnertue binding.getHomeTitle.text = savedTitletue } "์ˆ˜" -> { // sharedPref์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPrefTitlewed = getSharedPreferences("Routine_Wed$userUid", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitlewed = sharedPrefTitlewed.getString("title", "") val savedSpinnerwed = sharedPrefTitlewed.getString("selectedSpinnerItem", "") val savedContentwed1 = sharedPrefTitlewed.getString("con1", "") val savedContentwed2 = sharedPrefTitlewed.getString("con2", "") val savedContentwed3 = sharedPrefTitlewed.getString("con3", "") val savedContentwed4 = sharedPrefTitlewed.getString("con4", "") val savedContentwed5 = sharedPrefTitlewed.getString("con5", "") val savededm1 = sharedPrefTitlewed.getString("edm1", "") val savededm2 = sharedPrefTitlewed.getString("edm2", "") val savededm3 = sharedPrefTitlewed.getString("edm3", "") val savededm4 = sharedPrefTitlewed.getString("edm4", "") val savededm5 = sharedPrefTitlewed.getString("edm5", "") val savededs1 = sharedPrefTitlewed.getString("eds1", "") val savededs2 = sharedPrefTitlewed.getString("eds2", "") val savededs3 = sharedPrefTitlewed.getString("eds3", "") val savededs4 = sharedPrefTitlewed.getString("eds4", "") val savededs5 = sharedPrefTitlewed.getString("eds5", "") // null๊ฐ’ ํ—ˆ์šฉ val intSavededm1 = savededm1?.toIntOrNull() ?: 0 val intSavededs1 = savededs1?.toIntOrNull() ?: 0 // 00๋ถ„ 00์ดˆ ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ val formattedSavededm1 = "%02d".format(intSavededm1) val formattedSavededs1 = "%02d".format(intSavededs1) val timeText1 = "${formattedSavededm1}๋ถ„ ${formattedSavededs1}์ดˆ" val intSavededm2 = savededm2?.toIntOrNull() ?: 0 val intSavededs2 = savededs2?.toIntOrNull() ?: 0 val formattedSavededm2 = "%02d".format(intSavededm2) val formattedSavededs2 = "%02d".format(intSavededs2) val timeText2 = "${formattedSavededm2}๋ถ„ ${formattedSavededs2}์ดˆ" val intSavededm3 = savededm3?.toIntOrNull() ?: 0 val intSavededs3 = savededs3?.toIntOrNull() ?: 0 val formattedSavededm3 = "%02d".format(intSavededm3) val formattedSavededs3 = "%02d".format(intSavededs3) val timeText3 = "${formattedSavededm3}๋ถ„ ${formattedSavededs3}์ดˆ" val intSavededm4 = savededm4?.toIntOrNull() ?: 0 val intSavededs4 = savededs4?.toIntOrNull() ?: 0 val formattedSavededm4 = "%02d".format(intSavededm4) val formattedSavededs4 = "%02d".format(intSavededs4) val timeText4 = "${formattedSavededm4}๋ถ„ ${formattedSavededs4}์ดˆ" val intSavededm5 = savededm5?.toIntOrNull() ?: 0 val intSavededs5 = savededs5?.toIntOrNull() ?: 0 val formattedSavededm5 = "%02d".format(intSavededm5) val formattedSavededs5 = "%02d".format(intSavededs5) val timeText5 = "${formattedSavededm5}๋ถ„ ${formattedSavededs5}์ดˆ" // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • binding.getTitle.text = savedTitlewed binding.getSpinner.text = savedSpinnerwed binding.getRoutine1.text = savedContentwed1 binding.getRoutine2.text = savedContentwed2 binding.getRoutine3.text = savedContentwed3 binding.getRoutine4.text = savedContentwed4 binding.getRoutine5.text = savedContentwed5 binding.getTime1.text = timeText1 binding.getTime2.text = timeText2 binding.getTime3.text = timeText3 binding.getTime4.text = timeText4 binding.getTime5.text = timeText5 binding.getHomeSpinner.text = savedSpinnerwed binding.getHomeTitle.text = savedTitlewed } "๋ชฉ" -> { // sharedPref์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPrefTitlethu = getSharedPreferences("Routine_Thu$userUid", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitlethu = sharedPrefTitlethu.getString("title", "") val savedSpinnerthu = sharedPrefTitlethu.getString("selectedSpinnerItem", "") val savedContentthu1 = sharedPrefTitlethu.getString("con1", "") val savedContentthu2 = sharedPrefTitlethu.getString("con2", "") val savedContentthu3 = sharedPrefTitlethu.getString("con3", "") val savedContentthu4 = sharedPrefTitlethu.getString("con4", "") val savedContentthu5 = sharedPrefTitlethu.getString("con5", "") val savededm1 = sharedPrefTitlethu.getString("edm1", "") val savededm2 = sharedPrefTitlethu.getString("edm2", "") val savededm3 = sharedPrefTitlethu.getString("edm3", "") val savededm4 = sharedPrefTitlethu.getString("edm4", "") val savededm5 = sharedPrefTitlethu.getString("edm5", "") val savededs1 = sharedPrefTitlethu.getString("eds1", "") val savededs2 = sharedPrefTitlethu.getString("eds2", "") val savededs3 = sharedPrefTitlethu.getString("eds3", "") val savededs4 = sharedPrefTitlethu.getString("eds4", "") val savededs5 = sharedPrefTitlethu.getString("eds5", "") // null๊ฐ’ ํ—ˆ์šฉ val intSavededm1 = savededm1?.toIntOrNull() ?: 0 val intSavededs1 = savededs1?.toIntOrNull() ?: 0 // 00๋ถ„ 00์ดˆ ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ val formattedSavededm1 = "%02d".format(intSavededm1) val formattedSavededs1 = "%02d".format(intSavededs1) val timeText1 = "${formattedSavededm1}๋ถ„ ${formattedSavededs1}์ดˆ" val intSavededm2 = savededm2?.toIntOrNull() ?: 0 val intSavededs2 = savededs2?.toIntOrNull() ?: 0 val formattedSavededm2 = "%02d".format(intSavededm2) val formattedSavededs2 = "%02d".format(intSavededs2) val timeText2 = "${formattedSavededm2}๋ถ„ ${formattedSavededs2}์ดˆ" val intSavededm3 = savededm3?.toIntOrNull() ?: 0 val intSavededs3 = savededs3?.toIntOrNull() ?: 0 val formattedSavededm3 = "%02d".format(intSavededm3) val formattedSavededs3 = "%02d".format(intSavededs3) val timeText3 = "${formattedSavededm3}๋ถ„ ${formattedSavededs3}์ดˆ" val intSavededm4 = savededm4?.toIntOrNull() ?: 0 val intSavededs4 = savededs4?.toIntOrNull() ?: 0 val formattedSavededm4 = "%02d".format(intSavededm4) val formattedSavededs4 = "%02d".format(intSavededs4) val timeText4 = "${formattedSavededm4}๋ถ„ ${formattedSavededs4}์ดˆ" val intSavededm5 = savededm5?.toIntOrNull() ?: 0 val intSavededs5 = savededs5?.toIntOrNull() ?: 0 val formattedSavededm5 = "%02d".format(intSavededm5) val formattedSavededs5 = "%02d".format(intSavededs5) val timeText5 = "${formattedSavededm5}๋ถ„ ${formattedSavededs5}์ดˆ" // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • binding.getTitle.text = savedTitlethu binding.getSpinner.text = savedSpinnerthu binding.getRoutine1.text = savedContentthu1 binding.getRoutine2.text = savedContentthu2 binding.getRoutine3.text = savedContentthu3 binding.getRoutine4.text = savedContentthu4 binding.getRoutine5.text = savedContentthu5 binding.getTime1.text = timeText1 binding.getTime2.text = timeText2 binding.getTime3.text = timeText3 binding.getTime4.text = timeText4 binding.getTime5.text = timeText5 binding.getHomeSpinner.text = savedSpinnerthu binding.getHomeTitle.text = savedTitlethu } "๊ธˆ" -> { // sharedPref์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPrefTitlefri = getSharedPreferences("Routine_Fri$userUid", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitlefri = sharedPrefTitlefri.getString("title", "") val savedSpinnerfri = sharedPrefTitlefri.getString("selectedSpinnerItem", "") val savedContentfri1 = sharedPrefTitlefri.getString("con1", "") val savedContentfri2 = sharedPrefTitlefri.getString("con2", "") val savedContentfri3 = sharedPrefTitlefri.getString("con3", "") val savedContentfri4 = sharedPrefTitlefri.getString("con4", "") val savedContentfri5 = sharedPrefTitlefri.getString("con5", "") val savededm1 = sharedPrefTitlefri.getString("edm1", "") val savededm2 = sharedPrefTitlefri.getString("edm2", "") val savededm3 = sharedPrefTitlefri.getString("edm3", "") val savededm4 = sharedPrefTitlefri.getString("edm4", "") val savededm5 = sharedPrefTitlefri.getString("edm5", "") val savededs1 = sharedPrefTitlefri.getString("eds1", "") val savededs2 = sharedPrefTitlefri.getString("eds2", "") val savededs3 = sharedPrefTitlefri.getString("eds3", "") val savededs4 = sharedPrefTitlefri.getString("eds4", "") val savededs5 = sharedPrefTitlefri.getString("eds5", "") // null๊ฐ’ ํ—ˆ์šฉ val intSavededm1 = savededm1?.toIntOrNull() ?: 0 val intSavededs1 = savededs1?.toIntOrNull() ?: 0 // 00๋ถ„ 00์ดˆ ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ val formattedSavededm1 = "%02d".format(intSavededm1) val formattedSavededs1 = "%02d".format(intSavededs1) val timeText1 = "${formattedSavededm1}๋ถ„ ${formattedSavededs1}์ดˆ" val intSavededm2 = savededm2?.toIntOrNull() ?: 0 val intSavededs2 = savededs2?.toIntOrNull() ?: 0 val formattedSavededm2 = "%02d".format(intSavededm2) val formattedSavededs2 = "%02d".format(intSavededs2) val timeText2 = "${formattedSavededm2}๋ถ„ ${formattedSavededs2}์ดˆ" val intSavededm3 = savededm3?.toIntOrNull() ?: 0 val intSavededs3 = savededs3?.toIntOrNull() ?: 0 val formattedSavededm3 = "%02d".format(intSavededm3) val formattedSavededs3 = "%02d".format(intSavededs3) val timeText3 = "${formattedSavededm3}๋ถ„ ${formattedSavededs3}์ดˆ" val intSavededm4 = savededm4?.toIntOrNull() ?: 0 val intSavededs4 = savededs4?.toIntOrNull() ?: 0 val formattedSavededm4 = "%02d".format(intSavededm4) val formattedSavededs4 = "%02d".format(intSavededs4) val timeText4 = "${formattedSavededm4}๋ถ„ ${formattedSavededs4}์ดˆ" val intSavededm5 = savededm5?.toIntOrNull() ?: 0 val intSavededs5 = savededs5?.toIntOrNull() ?: 0 val formattedSavededm5 = "%02d".format(intSavededm5) val formattedSavededs5 = "%02d".format(intSavededs5) val timeText5 = "${formattedSavededm5}๋ถ„ ${formattedSavededs5}์ดˆ" // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • binding.getTitle.text = savedTitlefri binding.getSpinner.text = savedSpinnerfri binding.getRoutine1.text = savedContentfri1 binding.getRoutine2.text = savedContentfri2 binding.getRoutine3.text = savedContentfri3 binding.getRoutine4.text = savedContentfri4 binding.getRoutine5.text = savedContentfri5 binding.getTime1.text = timeText1 binding.getTime2.text = timeText2 binding.getTime3.text = timeText3 binding.getTime4.text = timeText4 binding.getTime5.text = timeText5 binding.getHomeSpinner.text = savedSpinnerfri binding.getHomeTitle.text = savedTitlefri } "ํ† " -> { // sharedPref์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPrefTitlesat = getSharedPreferences("Routine_Sat$userUid", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitlesat = sharedPrefTitlesat.getString("title", "") val savedSpinnersat = sharedPrefTitlesat.getString("selectedSpinnerItem", "") val savedContentsat1 = sharedPrefTitlesat.getString("con1", "") val savedContentsat2 = sharedPrefTitlesat.getString("con2", "") val savedContentsat3 = sharedPrefTitlesat.getString("con3", "") val savedContentsat4 = sharedPrefTitlesat.getString("con4", "") val savedContentsat5 = sharedPrefTitlesat.getString("con5", "") val savededm1 = sharedPrefTitlesat.getString("edm1", "") val savededm2 = sharedPrefTitlesat.getString("edm2", "") val savededm3 = sharedPrefTitlesat.getString("edm3", "") val savededm4 = sharedPrefTitlesat.getString("edm4", "") val savededm5 = sharedPrefTitlesat.getString("edm5", "") val savededs1 = sharedPrefTitlesat.getString("eds1", "") val savededs2 = sharedPrefTitlesat.getString("eds2", "") val savededs3 = sharedPrefTitlesat.getString("eds3", "") val savededs4 = sharedPrefTitlesat.getString("eds4", "") val savededs5 = sharedPrefTitlesat.getString("eds5", "") // null๊ฐ’ ํ—ˆ์šฉ val intSavededm1 = savededm1?.toIntOrNull() ?: 0 val intSavededs1 = savededs1?.toIntOrNull() ?: 0 // 00๋ถ„ 00์ดˆ ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ val formattedSavededm1 = "%02d".format(intSavededm1) val formattedSavededs1 = "%02d".format(intSavededs1) val timeText1 = "${formattedSavededm1}๋ถ„ ${formattedSavededs1}์ดˆ" val intSavededm2 = savededm2?.toIntOrNull() ?: 0 val intSavededs2 = savededs2?.toIntOrNull() ?: 0 val formattedSavededm2 = "%02d".format(intSavededm2) val formattedSavededs2 = "%02d".format(intSavededs2) val timeText2 = "${formattedSavededm2}๋ถ„ ${formattedSavededs2}์ดˆ" val intSavededm3 = savededm3?.toIntOrNull() ?: 0 val intSavededs3 = savededs3?.toIntOrNull() ?: 0 val formattedSavededm3 = "%02d".format(intSavededm3) val formattedSavededs3 = "%02d".format(intSavededs3) val timeText3 = "${formattedSavededm3}๋ถ„ ${formattedSavededs3}์ดˆ" val intSavededm4 = savededm4?.toIntOrNull() ?: 0 val intSavededs4 = savededs4?.toIntOrNull() ?: 0 val formattedSavededm4 = "%02d".format(intSavededm4) val formattedSavededs4 = "%02d".format(intSavededs4) val timeText4 = "${formattedSavededm4}๋ถ„ ${formattedSavededs4}์ดˆ" val intSavededm5 = savededm5?.toIntOrNull() ?: 0 val intSavededs5 = savededs5?.toIntOrNull() ?: 0 val formattedSavededm5 = "%02d".format(intSavededm5) val formattedSavededs5 = "%02d".format(intSavededs5) val timeText5 = "${formattedSavededm5}๋ถ„ ${formattedSavededs5}์ดˆ" // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • binding.getTitle.text = savedTitlesat binding.getSpinner.text = savedSpinnersat binding.getRoutine1.text = savedContentsat1 binding.getRoutine2.text = savedContentsat2 binding.getRoutine3.text = savedContentsat3 binding.getRoutine4.text = savedContentsat4 binding.getRoutine5.text = savedContentsat5 binding.getTime1.text = timeText1 binding.getTime2.text = timeText2 binding.getTime3.text = timeText3 binding.getTime4.text = timeText4 binding.getTime5.text = timeText5 binding.getHomeSpinner.text = savedSpinnersat binding.getHomeTitle.text = savedTitlesat } else -> { // ๊ทธ ์™ธ์˜ ๊ฒฝ์šฐ } } } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) // View Binding ์ดˆ๊ธฐํ™” setContentView(binding.root) // ๋ฃจํ‹ด ์Šคํƒ‘์›Œ์น˜ ์ €์žฅ ํ›„ ๋ฃจํ‹ด์„ฑ๊ณต ์•Œ๋žŒ cancelNotification() // ํ•˜๋‹จํƒญ๋ฐ” ์ž‘๋™์‹œํ‚ค๊ธฐ frameLayout1 = findViewById(R.id.Home1) frameLayout2 = findViewById(R.id.Home2) frameLayout3 = findViewById(R.id.Home3) bottomNavigationView = findViewById(R.id.bottomNavigationView) // ์ดˆ๊ธฐ ํƒญ ์„ค์ • showFrameLayout(frameLayout1) val userUid = FirebaseAuth.getInstance().currentUser?.uid bottomNavigationView.setOnItemSelectedListener { menuItem -> when (menuItem.itemId) { R.id.Home1 -> showFrameLayout(frameLayout1) R.id.Home2 -> showFrameLayout(frameLayout2) R.id.Home3 -> showFrameLayout(frameLayout3) } true } // ํ˜„์žฌ ๋‚ ์งœ์˜ ์š”์ผ์„ ๊ฐ€์ ธ์˜ค๊ธฐ val todayDayOfWeek = getDayOfWeek() // ํ˜„์žฌ ์š”์ผ์— ๋”ฐ๋ผ ๋ถ„๊ธฐ init(todayDayOfWeek) // ๋‹ฌ๋ ฅ์ƒ์„ฑ ๋ฐ ๋‚ ์งœ๋ฅผ ๋‘๋ฒˆ์งธ, ์„ธ๋ฒˆ์งธ ํŽ˜์ด์ง€์— ์ถœ๋ ฅ val dayText2: TextView = findViewById(R.id.day_text2) val dayText3: TextView = findViewById(R.id.day_text3) val calendarView: CalendarView = findViewById(R.id.calendarView) // ๋‹์งœ ํ˜•ํƒœ val dateFormat: DateFormat = SimpleDateFormat("yyyy๋…„ MM์›” dd์ผ") // ์˜ค๋Š˜ ๋‚ ์งœ val date: Date = Date(calendarView.date) // ๋‚ ์งœ ํ…์ŠคํŠธ๋ทฐ์— ๋‹ด๊ธฐ dayText2.text = dateFormat.format(date) // ๋‘๋ฒˆ์งธ ํŽ˜์ด์ง€๋Š” ์˜ค๋Š˜ ๋‚ ์งœ๋งŒ ๋ฐ›์•„์˜ด dayText3.text = dateFormat.format(date) // ์บ˜๋ฆฐ๋” ๋‚ ์งœ ๋ณ€ํ™˜ ์ด๋ฒคํŠธ calendarView.setOnDateChangeListener { calendarView, year, month, dayOfMonth -> val calendar = Calendar.getInstance() calendar.set(year, month, dayOfMonth) // ์š”์ผ์„ ์–ป๊ธฐ ์œ„ํ•ด Calendar ํด๋ž˜์Šค์˜ get ๋ฉ”์„œ๋“œ์™€ Calendar.DAY_OF_WEEK ์ƒ์ˆ˜ ์‚ฌ์šฉ val dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) val currentDate = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(calendar.time) val sharedPref = getSharedPreferences("Write_$currentDate", Context.MODE_PRIVATE) val memo = sharedPref.getString("memo", "") binding.getHomeMemo.text = memo // dayOfWeek ๊ฐ’์— ๋”ฐ๋ผ ์š”์ผ๋ณ„ ๋™์ž‘ ์ •์˜ when (dayOfWeek) { Calendar.SUNDAY -> { // sharedPref์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPrefTitlesun = getSharedPreferences("Routine_Sun$userUid", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitlesun = sharedPrefTitlesun.getString("title", "") val savedSpinnersun = sharedPrefTitlesun.getString("selectedSpinnerItem", "") // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • // homeํŽ˜์ด์ง€ binding.getHomeSpinner.text = savedSpinnersun binding.getHomeTitle.text = savedTitlesun } Calendar.MONDAY -> { // sharedPref์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPrefTitlemon = getSharedPreferences("Routine_Mon$userUid", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitlemon = sharedPrefTitlemon.getString("title", "") val savedSpinnermon = sharedPrefTitlemon.getString("selectedSpinnerItem", "") // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • // homeํŽ˜์ด์ง€ binding.getHomeSpinner.text = savedSpinnermon binding.getHomeTitle.text = savedTitlemon } Calendar.TUESDAY -> { // sharedPref์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPrefTitletue = getSharedPreferences("Routine_Tue$userUid", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitletue = sharedPrefTitletue.getString("title", "") val savedSpinnertue = sharedPrefTitletue.getString("selectedSpinnerItem", "") // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • // homeํŽ˜์ด์ง€ binding.getHomeSpinner.text = savedSpinnertue binding.getHomeTitle.text = savedTitletue } Calendar.WEDNESDAY -> { // sharedPref์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPrefTitlewed = getSharedPreferences("Routine_Wen$userUid", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitlewed = sharedPrefTitlewed.getString("title", "") val savedSpinnerwed = sharedPrefTitlewed.getString("selectedSpinnerItem", "") // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • // homeํŽ˜์ด์ง€ binding.getHomeSpinner.text = savedSpinnerwed binding.getHomeTitle.text = savedTitlewed } Calendar.THURSDAY -> { // sharedPref์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPrefTitlethu = getSharedPreferences("Routine_Thu$userUid", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitlethu = sharedPrefTitlethu.getString("title", "") val savedSpinnerthu = sharedPrefTitlethu.getString("selectedSpinnerItem", "") // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • // homeํŽ˜์ด์ง€ binding.getHomeSpinner.text = savedSpinnerthu binding.getHomeTitle.text = savedTitlethu } Calendar.FRIDAY -> { // sharedPref์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPrefTitlefri = getSharedPreferences("Routine_Fri$userUid", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitlefri = sharedPrefTitlefri.getString("title", "") val savedSpinnerfri = sharedPrefTitlefri.getString("selectedSpinnerItem", "") // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • // homeํŽ˜์ด์ง€ binding.getHomeSpinner.text = savedSpinnerfri binding.getHomeTitle.text = savedTitlefri } Calendar.SATURDAY -> { // sharedPref์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPrefTitlesat = getSharedPreferences("Routine_Sat$userUid", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitlesat = sharedPrefTitlesat.getString("title", "") val savedSpinnersat = sharedPrefTitlesat.getString("selectedSpinnerItem", "") // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • // homeํŽ˜์ด์ง€ binding.getHomeSpinner.text = savedSpinnersat binding.getHomeTitle.text = savedTitlesat } else -> { "์ผ์ •์ด ์—†์Šต๋‹ˆ๋‹ค" } } // ๋‚ ์งœ ๋ณ€์ˆ˜์— ๋‹ด๊ธฐ var day: String = "${year}๋…„ ${month + 1}์›” ${dayOfMonth}์ผ" // ๋ณ€์ˆ˜๋ฅผ textView์— ๋‹ด๊ธฐ // dayText3.text = day } // ์ƒ๋‹จ ํ”„๋กœํ•„ ์ด๋™ ๋ฆฌ์Šค๋„ˆ binding.profile1.setOnClickListener { mAuth = FirebaseAuth.getInstance() val user = mAuth.currentUser if (user != null) { // ์‚ฌ์šฉ์ž๊ฐ€ ๋กœ๊ทธ์ธํ•œ ๊ฒฝ์šฐ val intent = Intent(this, MyActivity::class.java) startActivity(intent) finish() } else { intent = Intent(this, LoginActivity::class.java) startActivity(intent) } } binding.profile2.setOnClickListener { mAuth = FirebaseAuth.getInstance() val user = mAuth.currentUser if (user != null) { // ์‚ฌ์šฉ์ž๊ฐ€ ๋กœ๊ทธ์ธํ•œ ๊ฒฝ์šฐ val intent = Intent(this, MyActivity::class.java) startActivity(intent) finish() } else { intent = Intent(this, LoginActivity::class.java) startActivity(intent) } } binding.profile3.setOnClickListener { mAuth = FirebaseAuth.getInstance() val user = mAuth.currentUser if (user != null) { // ์‚ฌ์šฉ์ž๊ฐ€ ๋กœ๊ทธ์ธํ•œ ๊ฒฝ์šฐ val intent = Intent(this, MyActivity::class.java) startActivity(intent) finish() } else { intent = Intent(this, LoginActivity::class.java) startActivity(intent) } } // ์ฒซ๋ฒˆ์งธ ํŽ˜์ด์ง€ // ๋‘๋ฒˆ์งธ ํ™”๋ฉด //1. ์•ฑ์‹คํ–‰์‹œ ๋ฆฌ์ŠคํŠธํŽ˜์ด์ง€์— ์˜ค๋Š˜๋‚ ์งœ ๊ธฐ์ค€ ๋ฐ์ดํ„ฐ ๋ฟŒ๋ ค์ฃผ๊ธฐ val currentDate = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(Date()) val sharedPref = getSharedPreferences("Write_$currentDate", Context.MODE_PRIVATE) // ํŒŒ์ผ์—์„œ ๋ฐ์ดํ„ฐ ์ฝ๊ธฐ val title = sharedPref.getString("title", "") val spinner = sharedPref.getString("spinner", "") val routin1 = sharedPref.getString("con1", "") val routin2 = sharedPref.getString("con2", "") val routin3 = sharedPref.getString("con3", "") val routin4 = sharedPref.getString("con4", "") val routin5 = sharedPref.getString("con5", "") val time1 = sharedPref.getString("time1", "") val time2 = sharedPref.getString("time2", "") val time3 = sharedPref.getString("time3", "") val time4 = sharedPref.getString("time4", "") val time5 = sharedPref.getString("time5", "") val tvTimerTotal = sharedPref.getString("tvTimerTotal", "") val memo = sharedPref.getString("memo", "") val realTime1 = sharedPref.getString("realTime1", "") val realTime2 = sharedPref.getString("realTime2", "") val realTime3 = sharedPref.getString("realTime3", "") val realTime4 = sharedPref.getString("realTime4", "") val realTime5 = sharedPref.getString("realTime5", "") var timesuccess11 = sharedPref.getInt("timedetect1", 0) var timesuccess21 = sharedPref.getInt("timedetect2", 0) var timesuccess31 = sharedPref.getInt("timedetect3", 0) var timesuccess41 = sharedPref.getInt("timedetect4", 0) var timesuccess51 = sharedPref.getInt("timedetect5", 0) // UI์— ๋ฐ์ดํ„ฐ ์—ฐ๋™ binding.showTitle.text = title binding.showSpinner.text = spinner binding.showRoutine1.text = routin1 binding.showRoutine2.text = routin2 binding.showRoutine3.text = routin3 binding.showRoutine4.text = routin4 binding.showRoutine5.text = routin5 binding.showTime1.text = time1 binding.showTime2.text = time2 binding.showTime3.text = time3 binding.showTime4.text = time4 binding.showTime5.text = time5 binding.tvShowTimerTotal.text = tvTimerTotal binding.showMemo.text = memo binding.showRealTime1.text = realTime1 binding.showRealTime2.text = realTime2 binding.showRealTime3.text = realTime3 binding.showRealTime4.text = realTime4 binding.showRealTime5.text = realTime5 binding.getHomeMemo.text = memo if (timesuccess11 == 1) { binding.form1.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_green_light ) ) } else if (timesuccess11 == 2) { binding.form1.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_red_light ) ) } else { binding.form1.setBackgroundColor( ContextCompat.getColor( this, android.R.color.transparent ) ) } if (timesuccess21 == 1) { binding.form2.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_green_light ) ) } else if (timesuccess21 == 2) { binding.form2.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_red_light ) ) } else { binding.form2.setBackgroundColor( ContextCompat.getColor( this, android.R.color.transparent ) ) } if (timesuccess31 == 1) { binding.form3.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_green_light ) ) } else if (timesuccess31 == 2) { binding.form3.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_red_light ) ) } else { binding.form3.setBackgroundColor( ContextCompat.getColor( this, android.R.color.transparent ) ) } if (timesuccess41 == 1) { binding.form4.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_green_light ) ) } else if (timesuccess41 == 2) { binding.form4.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_red_light ) ) } else { binding.form4.setBackgroundColor( ContextCompat.getColor( this, android.R.color.transparent ) ) } if (timesuccess51 == 1) { binding.form5.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_green_light ) ) } else if (timesuccess51 == 2) { binding.form5.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_red_light ) ) } else { binding.form5.setBackgroundColor( ContextCompat.getColor( this, android.R.color.transparent ) ) } // 2. ์ €์žฅํ•˜๊ธฐ ๋ฒ„ํŠผ ํด๋ฆญ์‹œ ๋ถˆ๋Ÿฌ์˜จ ํ…์ŠคํŠธ๋ทฐ๊ฐ’ ๊ทธ๋Œ€๋กœ ์ €์žฅ(๋‹จ, ์ผ์ž๋ณ„๋กœ ์ €์žฅ) binding.btnSaveAll.setOnClickListener { //Toast Toast.makeText(this,"๋ฐ์ดํ„ฐ๊ฐ€ ์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.",Toast.LENGTH_SHORT).show() // ํ…์ŠคํŠธ๊ฐ’ ๊ฐ€์ ธ์˜ค๊ธฐ val Spinner = binding.getSpinner.text.toString() val Title = binding.getTitle.text.toString() val routin1 = binding.getRoutine1.text.toString() val routin2 = binding.getRoutine2.text.toString() val routin3 = binding.getRoutine3.text.toString() val routin4 = binding.getRoutine4.text.toString() val routin5 = binding.getRoutine5.text.toString() val time1 = binding.getTime1.text.toString() val time2 = binding.getTime2.text.toString() val time3 = binding.getTime3.text.toString() val time4 = binding.getTime4.text.toString() val time5 = binding.getTime5.text.toString() val tvTimerTotal = binding.tvTimerTotal.text.toString() val memo = binding.memo.text.toString() val realTime1 = binding.tvTimer.text.toString() val realTime2 = binding.tvTimer2.text.toString() val realTime3 = binding.tvTimer3.text.toString() val realTime4 = binding.tvTimer4.text.toString() val realTime5 = binding.tvTimer5.text.toString() // SharedPreferences๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ๋‚ ์งœ๋ณ„๋กœ ์ €์žฅ val currentDate = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(Date()) val sharedPref = getSharedPreferences("Write_$currentDate", Context.MODE_PRIVATE) val editor = sharedPref.edit() // ํŒŒ์ผ์— ์ €์žฅ editor.putString("title", Title) editor.putString("spinner", Spinner) editor.putString("con1", routin1) editor.putString("con2", routin2) editor.putString("con3", routin3) editor.putString("con4", routin4) editor.putString("con5", routin5) editor.putString("time1", time1) editor.putString("time2", time2) editor.putString("time3", time3) editor.putString("time4", time4) editor.putString("time5", time5) editor.putString("tvTimerTotal", tvTimerTotal) editor.putString("memo", memo) editor.putInt("timedetect1", timesuccess1) editor.putInt("timedetect2", timesuccess2) editor.putInt("timedetect3", timesuccess3) editor.putInt("timedetect4", timesuccess4) editor.putInt("timedetect5", timesuccess5) editor.putString("realTime1", realTime1) editor.putString("realTime2", realTime2) editor.putString("realTime3", realTime3) editor.putString("realTime4", realTime4) editor.putString("realTime5", realTime5) editor.apply() //์ €์žฅ ์„ฑ๊ณตํ›„ ๋™์ž‘์ •์˜ // ํŒŒ์ผ์—์„œ ๋ฐ์ดํ„ฐ ์ฝ๊ธฐ val title1 = sharedPref.getString("title", "") val spinner1 = sharedPref.getString("spinner", "") val routin11 = sharedPref.getString("con1", "") val routin21 = sharedPref.getString("con2", "") val routin31 = sharedPref.getString("con3", "") val routin41 = sharedPref.getString("con4", "") val routin51 = sharedPref.getString("con5", "") val time11 = sharedPref.getString("time1", "") val time21 = sharedPref.getString("time2", "") val time31 = sharedPref.getString("time3", "") val time41 = sharedPref.getString("time4", "") val time51 = sharedPref.getString("time5", "") val tvTimerTotal1 = sharedPref.getString("tvTimerTotal", "") val memo1 = sharedPref.getString("memo", "") var timesuccess11 = sharedPref.getInt("timedetect1", 0) var timesuccess21 = sharedPref.getInt("timedetect2", 0) var timesuccess31 = sharedPref.getInt("timedetect3", 0) var timesuccess41 = sharedPref.getInt("timedetect4", 0) var timesuccess51 = sharedPref.getInt("timedetect5", 0) val realTime11 = sharedPref.getString("realTime1", "") val realTime21 = sharedPref.getString("realTime2", "") val realTime31 = sharedPref.getString("realTime3", "") val realTime41 = sharedPref.getString("realTime4", "") val realTime51 = sharedPref.getString("realTime5", "") // UI์— ๋ฐ์ดํ„ฐ ์—ฐ๋™ binding.showTitle.text = title1 binding.showSpinner.text = spinner1 binding.showRoutine1.text = routin11 binding.showRoutine2.text = routin21 binding.showRoutine3.text = routin31 binding.showRoutine4.text = routin41 binding.showRoutine5.text = routin51 binding.showTime1.text = time11 binding.showTime2.text = time21 binding.showTime3.text = time31 binding.showTime4.text = time41 binding.showTime5.text = time51 binding.tvShowTimerTotal.text = tvTimerTotal1 binding.showMemo.text = memo1 binding.getHomeMemo.text = memo1 val editableMemo = Editable.Factory.getInstance().newEditable(memo1) binding.memo.text = editableMemo binding.showRealTime1.text = realTime11 binding.showRealTime2.text = realTime21 binding.showRealTime3.text = realTime31 binding.showRealTime4.text = realTime41 binding.showRealTime5.text = realTime51 if (timesuccess11 == 1) { binding.form1.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_green_light ) ) } else if (timesuccess11 == 2) { binding.form1.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_red_light ) ) } else { binding.form1.setBackgroundColor( ContextCompat.getColor( this, android.R.color.transparent ) ) } if (timesuccess21 == 1) { binding.form2.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_green_light ) ) } else if (timesuccess21 == 2) { binding.form2.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_red_light ) ) } else { binding.form2.setBackgroundColor( ContextCompat.getColor( this, android.R.color.transparent ) ) } if (timesuccess31 == 1) { binding.form3.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_green_light ) ) } else if (timesuccess31 == 2) { binding.form3.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_red_light ) ) } else { binding.form3.setBackgroundColor( ContextCompat.getColor( this, android.R.color.transparent ) ) } if (timesuccess41 == 1) { binding.form4.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_green_light ) ) } else if (timesuccess41 == 2) { binding.form4.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_red_light ) ) } else { binding.form4.setBackgroundColor( ContextCompat.getColor( this, android.R.color.transparent ) ) } if (timesuccess51 == 1) { binding.form5.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_green_light ) ) } else if (timesuccess51 == 2) { binding.form5.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_red_light ) ) } else { binding.form5.setBackgroundColor( ContextCompat.getColor( this, android.R.color.transparent ) ) } } // ์ฒซ๋ฒˆ์งธ ๋ฃจํ‹ด ํƒ€์ด๋จธ // ํƒ€์ด๋จธํ™”๋ฉด์œผ๋กœ ์ด๋™ binding.btnPlay1.setOnClickListener { intent = Intent(this, StopActivity1::class.java) intent.putExtra("isGetTime1", binding.getTime1.text.toString()) startActivity(intent) } // ํƒ€์ด๋จธ ๊ฐ’ ๋ฐ›์•„์˜ค๊ธฐ // val value1 = intent.getStringExtra("times1") val sharedPref1 = getSharedPreferences("stop1", Context.MODE_PRIVATE) savedPref1 = sharedPref1.getString("times1", "") val routinePackage1 = findViewById<RelativeLayout>(R.id.routinePackage1) val getTime1 = findViewById<TextView>(R.id.getTime1) // ์‚ฌ์šฉ if (savedPref1.isNullOrEmpty() || savedPref1!!.length < 5) { // ์ดˆ๊ธฐํ™”๋˜์ง€ ์•Š์•˜๊ฑฐ๋‚˜ ์œ ํšจํ•œ ๊ฐ’์ด ์—†๋Š” ๊ฒฝ์šฐ routinePackage1.setBackgroundColor(Color.TRANSPARENT) } else { val laterText1 = getTime1.text.toString() if (savedPref1!!.startsWith(laterText1.substring(0, 5))) { routinePackage1.setBackgroundColor(ContextCompat.getColor(this, R.color.green)) } else { routinePackage1.setBackgroundColor(Color.TRANSPARENT) } val savedValue11 = savedPref1.toString() binding.tvTimer.text = "${savedValue11.substring(0, 2)}๋ถ„ ${savedValue11.substring(3, 5)}์ดˆ" if (getTime1.text.toString().compareTo(binding.tvTimer.text.toString()) <= 0) { timesuccess1 = 1 routinePackage1.setBackgroundColor(ContextCompat.getColor(this, R.color.green)) } else { timesuccess1 = 2 routinePackage1.setBackgroundColor(ContextCompat.getColor(this, R.color.red)) } // ๊ฐ’ ๋ฐ›์•„์˜ค๋ฉด remove๋ฒ„ํŠผ ์†Œํ™˜ binding.btnPlay1.visibility = View.GONE binding.btnRemove1.visibility = View.VISIBLE showFrameLayout(frameLayout2) } // remove1๋ฒ„ํŠผ ๋™์ž‘ - ์ƒ‰๊น” , ์ €์žฅ๋œ ์Šคํƒ‘์›Œ์น˜ ๊ฐ’ ๋ฆฌ์…‹ binding.btnRemove1.setOnClickListener { binding.tvTimer.setText("") timesuccess1 = 0 // SharedPreferences์—์„œ Editor ์ƒ์„ฑ val editor = sharedPref1.edit() // times1 ํ‚ค์— ํ•ด๋‹นํ•˜๋Š” ๋ฐ์ดํ„ฐ ์ œ๊ฑฐ editor.remove("times1") // ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ์ ์šฉ editor.commit() // UI ์—…๋ฐ์ดํŠธ ๋“ฑ ํ•„์š”ํ•œ ์ž‘์—… ์ˆ˜ํ–‰ routinePackage1.setBackgroundColor(Color.TRANSPARENT) binding.btnPlay1.visibility = View.VISIBLE binding.btnRemove1.visibility = View.GONE //times1์‚ญ์ œ๋˜์—ˆ์œผ๋‚˜ savedPref1์€ ํ•ด๋‹น ๊ฐ’์ด ์‚ญ์ œ๋˜๊ธฐ ์ „์˜ ๊ฐ’์„ ๊ทธ๋Œ€๋กœ ์œ ์ง€ํ•จ ๊ทธ๋ž˜์„œ ์ดˆ๊ธฐํ™”ํ•ด์ฃผ๊ธฐ savedPref1 = null // calculateAndSetTotalTime ํ•จ์ˆ˜ ํ˜ธ์ถœ val savedPrefs = arrayOf(savedPref1, savedPref2, savedPref3, savedPref4, savedPref5) calculateAndSetTotalTime(savedPrefs, binding.tvTimerTotal) } // ๋‘๋ฒˆ์งธ ๋ฃจํ‹ด ํƒ€์ด๋จธ binding.btnPlay2.setOnClickListener { intent = Intent(this, StopActivity2::class.java) intent.putExtra("isGetTime2", binding.getTime2.text.toString()) startActivity(intent) } // val value2 = intent.getStringExtra("times2") val sharedPref2 = getSharedPreferences("stop2", Context.MODE_PRIVATE) savedPref2 = sharedPref2.getString("times2", "") val routinePackage2 = findViewById<RelativeLayout>(R.id.routinePackage2) val getTime2 = findViewById<TextView>(R.id.getTime2) // ์‚ฌ์šฉ if (savedPref2.isNullOrEmpty() || savedPref2!!.length < 5) { // ์ดˆ๊ธฐํ™”๋˜์ง€ ์•Š์•˜๊ฑฐ๋‚˜ ์œ ํšจํ•œ ๊ฐ’์ด ์—†๋Š” ๊ฒฝ์šฐ routinePackage2.setBackgroundColor(Color.TRANSPARENT) } else { val laterText2 = getTime2.text.toString() if (savedPref2!!.startsWith(laterText2.substring(0, 5))) { routinePackage2.setBackgroundColor(ContextCompat.getColor(this, R.color.green)) } else { routinePackage2.setBackgroundColor(Color.TRANSPARENT) } val savedValue22 = savedPref2.toString() binding.tvTimer2.text = "${savedValue22.substring(0, 2)}๋ถ„ ${savedValue22.substring(3, 5)}์ดˆ" if (getTime2.text.toString().compareTo(binding.tvTimer2.text.toString()) <= 0) { timesuccess2 = 1 routinePackage2.setBackgroundColor(ContextCompat.getColor(this, R.color.green)) } else { timesuccess2 = 2 routinePackage2.setBackgroundColor(ContextCompat.getColor(this, R.color.red)) } // ๊ฐ’ ๋ฐ›์•„์˜ค๋ฉด remove๋ฒ„ํŠผ ์†Œํ™˜ binding.btnPlay2.visibility = View.GONE binding.btnRemove2.visibility = View.VISIBLE showFrameLayout(frameLayout2) } // remove2๋ฒ„ํŠผ ๋™์ž‘ - ์ƒ‰๊น” , ์ €์žฅ๋œ ์Šคํƒ‘์›Œ์น˜ ๊ฐ’ ๋ฆฌ์…‹ binding.btnRemove2.setOnClickListener { binding.tvTimer2.setText("") timesuccess2 = 0 // SharedPreferences์—์„œ Editor ์ƒ์„ฑ val editor = sharedPref2.edit() // times2 ํ‚ค์— ํ•ด๋‹นํ•˜๋Š” ๋ฐ์ดํ„ฐ ์ œ๊ฑฐ editor.remove("times2") // ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ์ ์šฉ editor.commit() // UI ์—…๋ฐ์ดํŠธ ๋“ฑ ํ•„์š”ํ•œ ์ž‘์—… ์ˆ˜ํ–‰ routinePackage2.setBackgroundColor(Color.TRANSPARENT) binding.btnPlay2.visibility = View.VISIBLE binding.btnRemove2.visibility = View.GONE savedPref2 = null // calculateAndSetTotalTime ํ•จ์ˆ˜ ํ˜ธ์ถœ val savedPrefs = arrayOf(savedPref1, savedPref2, savedPref3, savedPref4, savedPref5) calculateAndSetTotalTime(savedPrefs, binding.tvTimerTotal) } // binding.btnPlay2.setOnClickListener { // intent = Intent(this, StopActivity2::class.java) // startActivity(intent) // } // val value2 = intent.getStringExtra("times2") // // val routinePackage2 = findViewById<RelativeLayout>(R.id.routinePackage2) // // val getTime2 = findViewById<TextView>(R.id.getTime2) // // val laterText2 = getTime2.text.toString() // // if (value2 != null && value2.startsWith(laterText2.substring(0, 5))) { // routinePackage2.setBackgroundColor(ContextCompat.getColor(this, R.color.green)) // // } else { // routinePackage2.setBackgroundColor(Color.TRANSPARENT) // ์ดˆ๋ก์ƒ‰์ด ์•„๋‹Œ ๊ฒฝ์šฐ ํˆฌ๋ช… ๋ฐฐ๊ฒฝ์œผ๋กœ ์ดˆ๊ธฐํ™” // } // // // if (value2 == null) { // binding.tvTimer2.text = "์†Œ์š”์‹œ๊ฐ„" // } else { // val value22 = value2.toString() // binding.tvTimer2.text = value22.substring(0, 2) + "๋ถ„ " + value22.substring(3, 5) + "์ดˆ" // // if (getTime2.text.toString().compareTo(binding.tvTimer2.text.toString()) <= 0) { // routinePackage2.setBackgroundColor(ContextCompat.getColor(this, R.color.green)) // } else { // routinePackage2.setBackgroundColor(ContextCompat.getColor(this, R.color.red)) // } // } // ์„ธ๋ฒˆ์งธ ๋ฃจํ‹ด ํƒ€์ด๋จธ binding.btnPlay3.setOnClickListener { intent = Intent(this, StopActivity3::class.java) intent.putExtra("isGetTime3", binding.getTime3.text.toString()) startActivity(intent) } // val value3 = intent.getStringExtra("times3") // ์ดˆ๊ธฐํ™” val sharedPref3 = getSharedPreferences("stop3", Context.MODE_PRIVATE) savedPref3 = sharedPref3.getString("times3", "") val routinePackage3 = findViewById<RelativeLayout>(R.id.routinePackage3) val getTime3 = findViewById<TextView>(R.id.getTime3) // ์‚ฌ์šฉ if (savedPref3.isNullOrEmpty() || savedPref3!!.length < 5) { // ์ดˆ๊ธฐํ™”๋˜์ง€ ์•Š์•˜๊ฑฐ๋‚˜ ์œ ํšจํ•œ ๊ฐ’์ด ์—†๋Š” ๊ฒฝ์šฐ routinePackage3.setBackgroundColor(Color.TRANSPARENT) } else { val laterText3 = getTime3.text.toString() if (savedPref3!!.startsWith(laterText3.substring(0, 5))) { routinePackage3.setBackgroundColor(ContextCompat.getColor(this, R.color.green)) } else { routinePackage3.setBackgroundColor(Color.TRANSPARENT) } val savedValue33 = savedPref3.toString() binding.tvTimer3.text = "${savedValue33.substring(0, 2)}๋ถ„ ${savedValue33.substring(3, 5)}์ดˆ" if (getTime3.text.toString().compareTo(binding.tvTimer3.text.toString()) <= 0) { timesuccess3 = 1 routinePackage3.setBackgroundColor(ContextCompat.getColor(this, R.color.green)) } else { timesuccess3 = 2 routinePackage3.setBackgroundColor(ContextCompat.getColor(this, R.color.red)) } // ๊ฐ’ ๋ฐ›์•„์˜ค๋ฉด remove๋ฒ„ํŠผ ์†Œํ™˜ binding.btnPlay3.visibility = View.GONE binding.btnRemove3.visibility = View.VISIBLE showFrameLayout(frameLayout2) } // remove3๋ฒ„ํŠผ ๋™์ž‘ - ์ƒ‰๊น” , ์ €์žฅ๋œ ์Šคํƒ‘์›Œ์น˜ ๊ฐ’ ๋ฆฌ์…‹ binding.btnRemove3.setOnClickListener { binding.tvTimer3.setText("") timesuccess3 = 0 // SharedPreferences์—์„œ Editor ์ƒ์„ฑ val editor = sharedPref3.edit() // times3 ํ‚ค์— ํ•ด๋‹นํ•˜๋Š” ๋ฐ์ดํ„ฐ ์ œ๊ฑฐ editor.remove("times3") // ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ์ ์šฉ editor.commit() // UI ์—…๋ฐ์ดํŠธ ๋“ฑ ํ•„์š”ํ•œ ์ž‘์—… ์ˆ˜ํ–‰ routinePackage3.setBackgroundColor(Color.TRANSPARENT) binding.btnPlay3.visibility = View.VISIBLE binding.btnRemove3.visibility = View.GONE savedPref3 = null // calculateAndSetTotalTime ํ•จ์ˆ˜ ํ˜ธ์ถœ val savedPrefs = arrayOf(savedPref1, savedPref2, savedPref3, savedPref4, savedPref5) calculateAndSetTotalTime(savedPrefs, binding.tvTimerTotal) } // binding.btnPlay3.setOnClickListener { // intent = Intent(this, StopActivity3::class.java) // startActivity(intent) // } // val value3 = intent.getStringExtra("times3") // // val routinePackage3 = findViewById<RelativeLayout>(R.id.routinePackage3) // // val getTime3 = findViewById<TextView>(R.id.getTime3) // // val laterText3 = getTime3.text.toString() // // if (value3 != null && value3.startsWith(laterText3.substring(0, 5))) { // routinePackage3.setBackgroundColor(ContextCompat.getColor(this, R.color.green)) // } else { // routinePackage3.setBackgroundColor(Color.TRANSPARENT) // ์ดˆ๋ก์ƒ‰์ด ์•„๋‹Œ ๊ฒฝ์šฐ ํˆฌ๋ช… ๋ฐฐ๊ฒฝ์œผ๋กœ ์ดˆ๊ธฐํ™” // } // // // if (value3 == null) { // binding.tvTimer3.text = "์†Œ์š”์‹œ๊ฐ„" // } else { // val value33 = value3.toString() // binding.tvTimer3.text = value33.substring(0, 2) + "๋ถ„ " + value33.substring(3, 5) + "์ดˆ" // // if (getTime3.text.toString().compareTo(binding.tvTimer3.text.toString()) <= 0) { // routinePackage3.setBackgroundColor(ContextCompat.getColor(this, R.color.green)) // } else { // routinePackage3.setBackgroundColor(ContextCompat.getColor(this, R.color.red)) // } // } // ๋„ค๋ฒˆ์งธ ๋ฃจํ‹ด ํƒ€์ด๋จธ binding.btnPlay4.setOnClickListener { intent = Intent(this, StopActivity4::class.java) intent.putExtra("isGetTime4", binding.getTime4.text.toString()) startActivity(intent) } // ์ดˆ๊ธฐํ™” val sharedPref4 = getSharedPreferences("stop4", Context.MODE_PRIVATE) savedPref4 = sharedPref4.getString("times4", "") val routinePackage4 = findViewById<RelativeLayout>(R.id.routinePackage4) val getTime4 = findViewById<TextView>(R.id.getTime4) // ์‚ฌ์šฉ if (savedPref4.isNullOrEmpty() || savedPref4!!.length < 5) { // ์ดˆ๊ธฐํ™”๋˜์ง€ ์•Š์•˜๊ฑฐ๋‚˜ ์œ ํšจํ•œ ๊ฐ’์ด ์—†๋Š” ๊ฒฝ์šฐ routinePackage4.setBackgroundColor(Color.TRANSPARENT) } else { val laterText4 = getTime4.text.toString() if (savedPref4!!.startsWith(laterText4.substring(0, 5))) { routinePackage4.setBackgroundColor(ContextCompat.getColor(this, R.color.green)) } else { routinePackage4.setBackgroundColor(Color.TRANSPARENT) } val savedValue44 = savedPref4.toString() binding.tvTimer4.text = "${savedValue44.substring(0, 2)}๋ถ„ ${savedValue44.substring(3, 5)}์ดˆ" if (getTime4.text.toString().compareTo(binding.tvTimer4.text.toString()) <= 0) { timesuccess4 = 1 routinePackage4.setBackgroundColor(ContextCompat.getColor(this, R.color.green)) } else { timesuccess4 = 2 routinePackage4.setBackgroundColor(ContextCompat.getColor(this, R.color.red)) } // ๊ฐ’ ๋ฐ›์•„์˜ค๋ฉด remove๋ฒ„ํŠผ ์†Œํ™˜ binding.btnPlay4.visibility = View.GONE binding.btnRemove4.visibility = View.VISIBLE showFrameLayout(frameLayout2) } // remove4๋ฒ„ํŠผ ๋™์ž‘ - ์ƒ‰๊น” , ์ €์žฅ๋œ ์Šคํƒ‘์›Œ์น˜ ๊ฐ’ ๋ฆฌ์…‹ binding.btnRemove4.setOnClickListener { binding.tvTimer4.setText("") timesuccess4 = 0 // SharedPreferences์—์„œ Editor ์ƒ์„ฑ val editor = sharedPref4.edit() // times4 ํ‚ค์— ํ•ด๋‹นํ•˜๋Š” ๋ฐ์ดํ„ฐ ์ œ๊ฑฐ editor.remove("times4") // ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ์ ์šฉ editor.commit() // UI ์—…๋ฐ์ดํŠธ ๋“ฑ ํ•„์š”ํ•œ ์ž‘์—… ์ˆ˜ํ–‰ routinePackage4.setBackgroundColor(Color.TRANSPARENT) binding.btnPlay4.visibility = View.VISIBLE binding.btnRemove4.visibility = View.GONE savedPref4 = null // calculateAndSetTotalTime ํ•จ์ˆ˜ ํ˜ธ์ถœ val savedPrefs = arrayOf(savedPref1, savedPref2, savedPref3, savedPref4, savedPref5) calculateAndSetTotalTime(savedPrefs, binding.tvTimerTotal) } // binding.btnPlay4.setOnClickListener { // intent = Intent(this, StopActivity4::class.java) // startActivity(intent) // } // val value4 = intent.getStringExtra("times4") // // val routinePackage4 = findViewById<RelativeLayout>(R.id.routinePackage4) // // val getTime4 = findViewById<TextView>(R.id.getTime4) // // val laterText4 = getTime3.text.toString() // // if (value4 != null && value4.startsWith(laterText4.substring(0, 5))) { // routinePackage3.setBackgroundColor(ContextCompat.getColor(this, R.color.green)) // } else { // routinePackage3.setBackgroundColor(Color.TRANSPARENT) // ์ดˆ๋ก์ƒ‰์ด ์•„๋‹Œ ๊ฒฝ์šฐ ํˆฌ๋ช… ๋ฐฐ๊ฒฝ์œผ๋กœ ์ดˆ๊ธฐํ™” // } // // // if (value4 == null) { // binding.tvTimer4.text = "์†Œ์š”์‹œ๊ฐ„" // } else { // val value44 = value4.toString() // binding.tvTimer4.text = value44.substring(0, 2) + "๋ถ„ " + value44.substring(3, 5) + "์ดˆ" // // if (getTime4.text.toString().compareTo(binding.tvTimer4.text.toString()) <= 0) { // routinePackage4.setBackgroundColor(ContextCompat.getColor(this, R.color.green)) // } else { // routinePackage4.setBackgroundColor(ContextCompat.getColor(this, R.color.red)) // } // } // ๋‹ค์„ฏ๋ฒˆ์งธ ๋ฃจํ‹ด ํƒ€์ด๋จธ binding.btnPlay5.setOnClickListener { intent = Intent(this, StopActivity5::class.java) intent.putExtra("isGetTime5", binding.getTime5.text.toString()) startActivity(intent) } // ์ดˆ๊ธฐํ™” val sharedPref5 = getSharedPreferences("stop5", Context.MODE_PRIVATE) savedPref5 = sharedPref5.getString("times5", "") val routinePackage5 = findViewById<RelativeLayout>(R.id.routinePackage5) val getTime5 = findViewById<TextView>(R.id.getTime5) // ์‚ฌ์šฉ if (savedPref5.isNullOrEmpty() || savedPref5!!.length < 5) { // ์ดˆ๊ธฐํ™”๋˜์ง€ ์•Š์•˜๊ฑฐ๋‚˜ ์œ ํšจํ•œ ๊ฐ’์ด ์—†๋Š” ๊ฒฝ์šฐ routinePackage5.setBackgroundColor(Color.TRANSPARENT) } else { val laterText5 = getTime5.text.toString() if (savedPref5!!.startsWith(laterText5.substring(0, 5))) { routinePackage5.setBackgroundColor(ContextCompat.getColor(this, R.color.green)) } else { routinePackage5.setBackgroundColor(Color.TRANSPARENT) } val savedValue55 = savedPref5.toString() binding.tvTimer5.text = "${savedValue55.substring(0, 2)}๋ถ„ ${savedValue55.substring(3, 5)}์ดˆ" if (getTime5.text.toString().compareTo(binding.tvTimer5.text.toString()) <= 0) { timesuccess5 = 1 routinePackage5.setBackgroundColor(ContextCompat.getColor(this, R.color.green)) } else { timesuccess5 = 2 routinePackage5.setBackgroundColor(ContextCompat.getColor(this, R.color.red)) } // ๊ฐ’ ๋ฐ›์•„์˜ค๋ฉด remove๋ฒ„ํŠผ ์†Œํ™˜ binding.btnPlay5.visibility = View.GONE binding.btnRemove5.visibility = View.VISIBLE showFrameLayout(frameLayout2) } // remove5๋ฒ„ํŠผ ๋™์ž‘ - ์ƒ‰๊น” , ์ €์žฅ๋œ ์Šคํƒ‘์›Œ์น˜ ๊ฐ’ ๋ฆฌ์…‹ binding.btnRemove5.setOnClickListener { binding.tvTimer5.setText("") timesuccess5 = 0 // SharedPreferences์—์„œ Editor ์ƒ์„ฑ val editor = sharedPref5.edit() // times5 ํ‚ค์— ํ•ด๋‹นํ•˜๋Š” ๋ฐ์ดํ„ฐ ์ œ๊ฑฐ editor.remove("times5") // ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ์ ์šฉ editor.commit() // UI ์—…๋ฐ์ดํŠธ ๋“ฑ ํ•„์š”ํ•œ ์ž‘์—… ์ˆ˜ํ–‰ routinePackage5.setBackgroundColor(Color.TRANSPARENT) binding.btnPlay5.visibility = View.VISIBLE binding.btnRemove5.visibility = View.GONE savedPref5 = null // calculateAndSetTotalTime ํ•จ์ˆ˜ ํ˜ธ์ถœ val savedPrefs = arrayOf(savedPref1, savedPref2, savedPref3, savedPref4, savedPref5) calculateAndSetTotalTime(savedPrefs, binding.tvTimerTotal) } // binding.btnPlay5.setOnClickListener { // intent = Intent(this, StopActivity5::class.java) // startActivity(intent) // } // val value5 = intent.getStringExtra("times5") // // val routinePackage5 = findViewById<RelativeLayout>(R.id.routinePackage5) // // val getTime5 = findViewById<TextView>(R.id.getTime5) // // val laterText5 = getTime5.text.toString() // // if (value5 != null && value5.startsWith(laterText5.substring(0, 5))) { // routinePackage5.setBackgroundColor(ContextCompat.getColor(this, R.color.green)) // } else { // routinePackage5.setBackgroundColor(Color.TRANSPARENT) // ์ดˆ๋ก์ƒ‰์ด ์•„๋‹Œ ๊ฒฝ์šฐ ํˆฌ๋ช… ๋ฐฐ๊ฒฝ์œผ๋กœ ์ดˆ๊ธฐํ™” // } // // // if (value5 == null) { // binding.tvTimer5.text = "์†Œ์š”์‹œ๊ฐ„" // } else { // val value55 = value5.toString() // binding.tvTimer5.text = value55.substring(0, 2) + "๋ถ„ " + value5.substring(3, 5) + "์ดˆ" // // if (getTime5.text.toString().compareTo(binding.tvTimer5.text.toString()) <= 0) { // routinePackage5.setBackgroundColor(ContextCompat.getColor(this, R.color.green)) // } else { // routinePackage5.setBackgroundColor(ContextCompat.getColor(this, R.color.red)) // } // } //์ด ์šด๋™์‹œ๊ฐ„ ์ž๋™ ๊ณ„์‚ฐ val savedPrefs = arrayOf(savedPref1, savedPref2, savedPref3, savedPref4, savedPref5) calculateAndSetTotalTime(savedPrefs, binding.tvTimerTotal) // ์นด์šดํŠธ๋‹ค์šด ํŽ˜์ด์ง€ ์ด๋™ binding.btnTimer.setOnClickListener { intent = Intent(this, CountDownActivity::class.java) startActivity(intent) } // ์„ธ๋ฒˆ์งธ ํ™”๋ฉด // ์šด๋™ ๊ด€๋ฆฌ ํŽ˜์ด์ง€ ํŽธ์ง‘ ๋ฒ„ํŠผ var selectedDate:String = "" binding.btnEdit.setOnClickListener { Toast.makeText(this, "์˜ค๋Š˜๋‚ ์งœ๋งŒ ํŽธ์ง‘๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค", Toast.LENGTH_SHORT).show() binding.Home3.visibility = View.INVISIBLE binding.Home2.visibility = View.VISIBLE } // ์šด๋™ ๊ด€๋ฆฌ ํŽ˜์ด์ง€ ์‚ญ์ œ ๋ฒ„ํŠผ binding.btnDel.setOnClickListener { val view = View.inflate(this, R.layout.dialog_view, null) val builder = AlertDialog.Builder(this) builder.setView(view) val dialog = builder.create() dialog.setCanceledOnTouchOutside(false) dialog.show() val btnConfirm = view.findViewById<Button>(R.id.btn_confirm) val btnCancel = view.findViewById<Button>(R.id.btn_cancel) btnConfirm.setOnClickListener { deleteData("Write_$selectedDate") dialog.dismiss() } btnCancel.setOnClickListener { dialog.dismiss() } dialog.window?.setBackgroundDrawable(ColorDrawable(Color.WHITE)) } // binding.btnDel.setOnClickListener { // //// ์‚ญ์ œํ•  ๋ฐ์ดํ„ฐ์˜ ํฌ๊ธฐ๋ฅผ ๋ฐ›์•„์˜ค๊ธฐ์œ„ํ•œ ์‚ญ์ œํ•  ๋ฐ์ดํ„ฐ ๋ณ€์ˆ˜์„ค์ • // val textValue = binding.showMemo.text.toString() // // // ํ…์ŠคํŠธ๊ฐ€ ๋น„์–ด์žˆ์„ ๋•Œ // if (textValue.isBlank()) { // Toast.makeText(this@MainActivity, "์‚ญ์ œํ•  ๋ฐ์ดํ„ฐ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค", Toast.LENGTH_SHORT).show() // } else { // // ์‚ญ์ œ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ // val eventHandler = object : DialogInterface.OnClickListener { // override fun onClick(p0: DialogInterface?, p1: Int) { // // // Positive Button ํด๋ฆญ ์‹œ // if (p1 == DialogInterface.BUTTON_POSITIVE) { // // // ์‚ญ์ œ ๋กœ์ง // binding.showMemo.setText("") // Toast.makeText(this@MainActivity, "์‚ญ์ œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค", Toast.LENGTH_SHORT).show() // // // Negative Button ํด๋ฆญ ์‹œ // } else if (p1 == DialogInterface.BUTTON_NEGATIVE) { // Toast.makeText(this@MainActivity, "์ทจ์†Œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค", Toast.LENGTH_SHORT).show() // } // } // } // ์‚ญ์ œ ๋ฒ„ํŠผ AlertDialog // AlertDialog.Builder(this).run { // setTitle("์‚ญ์ œ ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?") // setMessage("์‚ญ์ œ๋œ ๋ฐ์ดํ„ฐ๋Š” ๋ณต๊ตฌํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค") // setPositiveButton("ใ…‡ใ…‡์‚ญ์ œํ•จ", eventHandler) // setNegativeButton("ใ„ดใ„ด์‚ญ์ œ์•ˆํ•จ", eventHandler) // show() // } // } // } // ์šด๋™ ๊ด€๋ฆฌ ํŽ˜์ด์ง€ ๋‹ฌ๋ ฅ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ ๋ฒ„ํŠผ binding.iconCalendar.setOnClickListener { // DatePickerDialog๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‚ ์งœ ์„ ํƒ val calendar = Calendar.getInstance() val year = calendar.get(Calendar.YEAR) val month = calendar.get(Calendar.MONTH) val day = calendar.get(Calendar.DAY_OF_MONTH) val datePickerDialog = DatePickerDialog(this, { _, selectedYear, selectedMonth, selectedDay -> selectedDate = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).run { calendar.set(selectedYear, selectedMonth, selectedDay) format(calendar.time) } //์ƒ‰๊น” ์ดˆ๊ธฐํ™” binding.form1.setBackgroundColor( ContextCompat.getColor( this, android.R.color.transparent ) ) binding.form2.setBackgroundColor( ContextCompat.getColor( this, android.R.color.transparent ) ) binding.form3.setBackgroundColor( ContextCompat.getColor( this, android.R.color.transparent ) ) binding.form4.setBackgroundColor( ContextCompat.getColor( this, android.R.color.transparent ) ) binding.form5.setBackgroundColor( ContextCompat.getColor( this, android.R.color.transparent ) ) // ์„ ํƒ๋œ ๋‚ ์งœ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํŒŒ์ผ๋ช… ์ƒ์„ฑ val fileName = "Write_$selectedDate" // binding.dayText3.text = selectedDate val selecteDate2 = SimpleDateFormat("yyyy๋…„MM์›”dd์ผ", Locale.getDefault()).run { calendar.set(selectedYear, selectedMonth, selectedDay) format(calendar.time) } // ์„ ํƒ๋œ ๋‚ ์งœ๋ฅผ TextView์— ๋ฐ”์ธ๋”ฉ // binding.dayText3.text = selectedDate binding.dayText3.text = selecteDate2 // ํ•ด๋‹น ํŒŒ์ผ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ์–ด์™€ UI์— ํ‘œ์‹œ loadDataAndDisplayUI(fileName) }, year, month, day) datePickerDialog.show() } binding.btnDone.setOnClickListener { binding.Home3.visibility = View.VISIBLE binding.Home1.visibility = View.INVISIBLE binding.title1.visibility = View.VISIBLE binding.homeLine.visibility = View.VISIBLE binding.tvToday.visibility = View.VISIBLE binding.Schedule.visibility = View.VISIBLE binding.btnDone.visibility = View.INVISIBLE Toast.makeText(this, "๋‚ ์งœ๊ฐ€ ๋ณ€๊ฒฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค", Toast.LENGTH_SHORT).show() } } fun calculateAndSetTotalTime(savedPrefs: Array<String?>, textView: TextView) { // ์ด ์šด๋™ ์‹œ๊ฐ„ ๊ณ„์‚ฐ var totalHours = 0 var totalMinutes = 0 for (savedPref in savedPrefs) { if (!savedPref.isNullOrEmpty()) { totalHours += savedPref.substring(0, 2).toInt() totalMinutes += savedPref.substring(3, 5).toInt() } } val totalSeconds = totalHours * 60 + totalMinutes val formattedTime = String.format("%02d๋ถ„ %02d์ดˆ", totalSeconds / 60, totalSeconds % 60) // ํฌ๋งทํŒ…๋œ ์‹œ๊ฐ„์„ TextView์— ์„ค์ • binding.tvTimerTotal.text = formattedTime } private fun deleteData(fileName: String) { val sharedPref = getSharedPreferences(fileName, Context.MODE_PRIVATE) val editor = sharedPref.edit() // ์‚ญ์ œํ•  ๋ฐ์ดํ„ฐ์˜ ํ‚ค ๊ฐ’์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ ์‚ญ์ œ editor.remove("tvTimerTotal") editor.remove("memo") editor.remove("timedetect1") editor.remove("timedetect2") editor.remove("timedetect3") editor.remove("timedetect4") editor.remove("timedetect5") editor.remove("realtime1") editor.remove("realtime2") editor.remove("realtime3") editor.remove("realtime4") editor.remove("realtime5") binding.showMemo.setText("") binding.showRealTime1.setText("") binding.showRealTime2.setText("") binding.showRealTime3.setText("") binding.showRealTime4.setText("") binding.showRealTime5.setText("") binding.tvShowTimerTotal.setText("") binding.form1.setBackgroundColor(Color.TRANSPARENT) binding.form2.setBackgroundColor(Color.TRANSPARENT) binding.form3.setBackgroundColor(Color.TRANSPARENT) binding.form4.setBackgroundColor(Color.TRANSPARENT) binding.form5.setBackgroundColor(Color.TRANSPARENT) // ๋ณ€๊ฒฝ ์‚ฌํ•ญ ์ €์žฅ editor.apply() } private fun cancelNotification() { // NotificationManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์•Œ๋ฆผ์„ ์‚ญ์ œ val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager manager.cancel(11) // ์•Œ๋ฆผ ID๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์•Œ๋ฆผ ์ทจ์†Œ } // ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ์–ด์™€ UI์— ํ‘œ์‹œํ•˜๋Š” ํ•จ์ˆ˜ private fun loadDataAndDisplayUI(fileName: String) { val sharedPref = getSharedPreferences(fileName, Context.MODE_PRIVATE) // ํŒŒ์ผ์—์„œ ๋ฐ์ดํ„ฐ ์ฝ๊ธฐ val title = sharedPref.getString("title", "") val spinner = sharedPref.getString("spinner", "") val routin1 = sharedPref.getString("con1", "") val routin2 = sharedPref.getString("con2", "") val routin3 = sharedPref.getString("con3", "") val routin4 = sharedPref.getString("con4", "") val routin5 = sharedPref.getString("con5", "") val time1 = sharedPref.getString("time1", "") val time2 = sharedPref.getString("time2", "") val time3 = sharedPref.getString("time3", "") val time4 = sharedPref.getString("time4", "") val time5 = sharedPref.getString("time5", "") val tvTimerTotal = sharedPref.getString("tvTimerTotal", "") val memo = sharedPref.getString("memo", "") var timesuccess11 = sharedPref.getInt("timedetect1", 0) var timesuccess21 = sharedPref.getInt("timedetect2", 0) var timesuccess31 = sharedPref.getInt("timedetect3", 0) var timesuccess41 = sharedPref.getInt("timedetect4", 0) var timesuccess51 = sharedPref.getInt("timedetect5", 0) val realTime1 = sharedPref.getString("realtime1", "") val realTime2 = sharedPref.getString("realtime2", "") val realTime3 = sharedPref.getString("realtime3", "") val realTime4 = sharedPref.getString("realtime4", "") val realTime5 = sharedPref.getString("realtime5", "") // UI์— ๋ฐ์ดํ„ฐ ์—ฐ๋™ binding.showTitle.text = title binding.showSpinner.text = spinner binding.showRoutine1.text = routin1 binding.showRoutine2.text = routin2 binding.showRoutine3.text = routin3 binding.showRoutine4.text = routin4 binding.showRoutine5.text = routin5 binding.showTime1.text = time1 binding.showTime2.text = time2 binding.showTime3.text = time3 binding.showTime4.text = time4 binding.showTime5.text = time5 binding.tvShowTimerTotal.text = tvTimerTotal binding.showMemo.text = memo binding.getHomeMemo.text = memo binding.showRealTime1.text = realTime1 binding.showRealTime2.text = realTime2 binding.showRealTime3.text = realTime3 binding.showRealTime4.text = realTime4 binding.showRealTime5.text = realTime5 if (timesuccess11 == 1) { binding.form1.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_green_light ) ) } else if (timesuccess11 == 2) { binding.form1.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_red_light ) ) } else { binding.form1.setBackgroundColor( ContextCompat.getColor( this, android.R.color.transparent ) ) } if (timesuccess21 == 1) { binding.form2.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_green_light ) ) } else if (timesuccess21 == 2) { binding.form2.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_red_light ) ) } else { binding.form2.setBackgroundColor( ContextCompat.getColor( this, android.R.color.transparent ) ) } if (timesuccess31 == 1) { binding.form3.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_green_light ) ) } else if (timesuccess31 == 2) { binding.form3.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_red_light ) ) } else { binding.form3.setBackgroundColor( ContextCompat.getColor( this, android.R.color.transparent ) ) } if (timesuccess41 == 1) { binding.form4.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_green_light ) ) } else if (timesuccess41 == 2) { binding.form4.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_red_light ) ) } else { binding.form4.setBackgroundColor( ContextCompat.getColor( this, android.R.color.transparent ) ) } if (timesuccess51 == 1) { binding.form5.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_green_light ) ) } else if (timesuccess51 == 2) { binding.form5.setBackgroundColor( ContextCompat.getColor( this, android.R.color.holo_red_light ) ) } else { binding.form5.setBackgroundColor( ContextCompat.getColor( this, android.R.color.transparent ) ) } // binding.iconCalendar.setOnClickListener { // binding.Home3.visibility = View.INVISIBLE // binding.Home1.visibility = View.VISIBLE // binding.title1.visibility = View.INVISIBLE // binding.homeLine.visibility = View.INVISIBLE // binding.tvToday.visibility = View.INVISIBLE // binding.Schedule.visibility = View.INVISIBLE // binding.btnDone.visibility = View.VISIBLE // } // // binding.btnDone.setOnClickListener { // binding.Home3.visibility = View.VISIBLE // binding.Home1.visibility = View.INVISIBLE // binding.title1.visibility = View.VISIBLE // binding.homeLine.visibility = View.VISIBLE // binding.tvToday.visibility = View.VISIBLE // binding.Schedule.visibility = View.VISIBLE // binding.btnDone.visibility = View.INVISIBLE // Toast.makeText(this, "๋‚ ์งœ๊ฐ€ ๋ณ€๊ฒฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค", Toast.LENGTH_SHORT).show() // } } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/DetailActivitythu.kt
2088746993
package com.example.android_team4_project import android.app.AlertDialog import android.app.Dialog import android.content.Context import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.view.View import android.widget.Button import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.example.android_team4_project.databinding.ActivityDetailBinding import com.google.firebase.auth.FirebaseAuth private lateinit var auth: FirebaseAuth private lateinit var userEmail: String class DetailActivitythu: AppCompatActivity() { private lateinit var binding: ActivityDetailBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityDetailBinding.inflate(layoutInflater) setContentView(binding.root) auth = FirebaseAuth.getInstance() val user = auth.currentUser userEmail = user?.uid ?: "" // ๋ฒ„ํŠผํด๋ฆญ์‹œ ๋งˆ์ด๋ฃจํ‹ด์œผ๋กœ ์ด๋™ binding.btnMypage.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MainActivity::class.java) startActivity(intent) } // ์ˆ˜์ •๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํ•ด๋‹น์š”์ผ ํŒ์—…์—‘ํ‹ฐ๋น„ํ‹ฐ binding.btnSaveAll.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, PopupActivitythu::class.java) startActivity(intent) } // ์‚ญ์ œ๋ฒ„ํŠผ ํด๋ฆญ์‹œ ์ €์žฅ๋‚ด์šฉ ์‚ญ์ œ // binding.btnCancel.setOnClickListener { // showDeleteConfirmationDialog() // } binding.btnCancel.setOnClickListener { val view = View.inflate(this, R.layout.dialog_view, null) val builder = androidx.appcompat.app.AlertDialog.Builder(this) builder.setView(view) val dialog = builder.create() dialog.setCanceledOnTouchOutside(false) dialog.show() val btnConfirm = view.findViewById<Button>(R.id.btn_confirm) val btnCancel = view.findViewById<Button>(R.id.btn_cancel) btnConfirm.setOnClickListener { showDeleteConfirmationDialog() Toast.makeText(this@DetailActivitythu, "์‚ญ์ œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค", Toast.LENGTH_SHORT).show() dialog.dismiss() } btnCancel.setOnClickListener { dialog.dismiss() } dialog.window?.setBackgroundDrawable(ColorDrawable(Color.WHITE)) } // SharedPreferences์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPrefTitlethu = getSharedPreferences("Routine_Thu$userEmail", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitlethu = sharedPrefTitlethu.getString("title", "") val savedSpinnerthu = sharedPrefTitlethu.getString("selectedSpinnerItem", "") val savedcon1thu = sharedPrefTitlethu.getString("con1", "") val savedcon2thu = sharedPrefTitlethu.getString("con2", "") val savedcon3thu = sharedPrefTitlethu.getString("con3", "") val savedcon4thu = sharedPrefTitlethu.getString("con4", "") val savedcon5thu = sharedPrefTitlethu.getString("con5", "") val savededm1thu = sharedPrefTitlethu.getString("edm1", "") val savededm2thu = sharedPrefTitlethu.getString("edm2", "") val savededm3thu = sharedPrefTitlethu.getString("edm3", "") val savededm4thu = sharedPrefTitlethu.getString("edm4", "") val savededm5thu = sharedPrefTitlethu.getString("edm5", "") val savededs1thu = sharedPrefTitlethu.getString("eds1", "") val savededs2thu = sharedPrefTitlethu.getString("eds2", "") val savededs3thu = sharedPrefTitlethu.getString("eds3", "") val savededs4thu = sharedPrefTitlethu.getString("eds4", "") val savededs5thu = sharedPrefTitlethu.getString("eds5", "") // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • binding.edTitle.text = savedTitlethu binding.spinner.text = savedSpinnerthu binding.edContent1.text = savedcon1thu binding.edContent2.text = savedcon2thu binding.edContent3.text = savedcon3thu binding.edContent4.text = savedcon4thu binding.edContent5.text = savedcon5thu binding.edm1.text = savededm1thu binding.edm2.text = savededm2thu binding.edm3.text = savededm3thu binding.edm4.text = savededm4thu binding.edm5.text = savededm5thu binding.eds1.text = savededs1thu binding.eds2.text = savededs2thu binding.eds3.text = savededs3thu binding.eds4.text = savededs4thu binding.eds5.text = savededs5thu } private fun showDeleteConfirmationDialog() { val builder = AlertDialog.Builder(this) builder.setTitle("์ฃผ์˜") builder.setMessage("์‚ญ์ œํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?") builder.setPositiveButton("์‚ญ์ œ") { _, _ -> // ์‚ฌ์šฉ์ž๊ฐ€ ์‚ญ์ œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ–ˆ์„ ๋•Œ auth = FirebaseAuth.getInstance() val user = auth.currentUser userEmail = user?.uid ?: "" // RoutineData ๊ฐ์ฒด ์—…๋ฐ์ดํŠธ val routine = RoutineData( title = "", selectedSpinnerItem = "", con1 = "", con2 = "", con3 = "", con4 = "", con5 = "", edm1 = "", edm2 = "", edm3 = "", edm4 = "", edm5 = "", eds1 = "", eds2 = "", eds3 = "", eds4 = "", eds5 = "" ) // RoutineData ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ๋ฐ์ดํ„ฐ ์ƒ์„ฑ val xmlData = generateXmlData(routine, "Thu") // userEmail์„ ์ด์šฉํ•˜์—ฌ StorageManager๋ฅผ ์ดˆ๊ธฐํ™” val storageManager = StorageManager(this) // StorageManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ํŒŒ์ผ ์—…๋กœ๋“œ storageManager.uploadXmlFile(xmlData, "Thu") // SharedPreferences๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ์ €์žฅ val userUid = FirebaseAuth.getInstance().uid val sharedPrefTitlethu = getSharedPreferences("Routine_Thu$userUid", Context.MODE_PRIVATE) val editor = sharedPrefTitlethu.edit() editor.putString("title", routine.title) editor.putString("selectedSpinnerItem", routine.selectedSpinnerItem) editor.putString("con1", routine.con1) editor.putString("con2", routine.con2) editor.putString("con3", routine.con3) editor.putString("con4", routine.con4) editor.putString("con5", routine.con5) editor.putString("edm1", routine.edm1) editor.putString("edm2", routine.edm2) editor.putString("edm3", routine.edm3) editor.putString("edm4", routine.edm4) editor.putString("edm5", routine.edm5) editor.putString("eds1", routine.eds1) editor.putString("eds2", routine.eds2) editor.putString("eds3", routine.eds3) editor.putString("eds4", routine.eds4) editor.putString("eds5", routine.eds5) editor.apply() // ์ €์žฅ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ด๋ฃจ์–ด์ง€๋ฉด ์•กํ‹ฐ๋น„ํ‹ฐ ์ด๋™ val intent = Intent(this, MyActivity::class.java) startActivity(intent) finish() // ํ˜„์žฌ ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ์ข…๋ฃŒ } builder.setNegativeButton("์ทจ์†Œ") { dialog, _ -> // ์‚ฌ์šฉ์ž๊ฐ€ ์ทจ์†Œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ–ˆ์„ ๋•Œ dialog.dismiss() } val dialog: AlertDialog = builder.create() dialog.show() } private fun generateXmlData(routine: RoutineData, dayOfWeek:String): String { val xmlStringBuilder = StringBuilder() xmlStringBuilder.append("<routine>") xmlStringBuilder.append("<title>${routine.title}</title>") xmlStringBuilder.append("<con1>${routine.con1}</con1>") xmlStringBuilder.append("<con2>${routine.con2}</con2>") xmlStringBuilder.append("<con3>${routine.con3}</con3>") xmlStringBuilder.append("<con4>${routine.con4}</con4>") xmlStringBuilder.append("<con5>${routine.con5}</con5>") xmlStringBuilder.append("<edm1>${routine.edm1}</edm1>") xmlStringBuilder.append("<edm2>${routine.edm2}</edm2>") xmlStringBuilder.append("<edm3>${routine.edm3}</edm3>") xmlStringBuilder.append("<edm4>${routine.edm4}</edm4>") xmlStringBuilder.append("<edm5>${routine.edm5}</edm5>") xmlStringBuilder.append("<eds1>${routine.eds1}</eds1>") xmlStringBuilder.append("<eds2>${routine.eds2}</eds2>") xmlStringBuilder.append("<eds3>${routine.eds3}</eds3>") xmlStringBuilder.append("<eds4>${routine.eds4}</eds4>") xmlStringBuilder.append("<eds5>${routine.eds5}</eds5>") xmlStringBuilder.append("<selectedSpinnerItem>${routine.selectedSpinnerItem}</selectedSpinnerItem>") xmlStringBuilder.append("</routine>") return xmlStringBuilder.toString() } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/PopupActivityfri.kt
3489493460
package com.example.android_team4_project import android.app.Dialog import android.content.Context import android.content.Intent import android.content.SharedPreferences import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.text.Editable import android.text.TextWatcher import android.widget.ArrayAdapter import android.widget.EditText import android.widget.ListView import android.widget.Spinner import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.example.android_team4_project.databinding.ActivityPopupBinding import com.google.firebase.auth.FirebaseAuth class PopupActivityfri : AppCompatActivity() { private lateinit var binding: ActivityPopupBinding private lateinit var userEmail: String private lateinit var arrayList: ArrayList<String> private lateinit var dialog: Dialog private lateinit var spinner: Spinner private lateinit var selectedSpinnerValue: String private lateinit var auth: FirebaseAuth override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityPopupBinding.inflate(layoutInflater) setContentView(binding.root) auth = FirebaseAuth.getInstance() val user = auth.currentUser userEmail = user?.uid ?: "" dialog = Dialog(this) val sharedPrefTitlefri = getSharedPreferences("Routine_Fri$userEmail", Context.MODE_PRIVATE) val routine = RoutineData( title = sharedPrefTitlefri.getString("title", "") ?: "", selectedSpinnerItem = sharedPrefTitlefri.getString("selectedSpinnerItem", "") ?: "", con1 = sharedPrefTitlefri.getString("con1", "") ?: "", con2 = sharedPrefTitlefri.getString("con2", "") ?: "", con3 = sharedPrefTitlefri.getString("con3", "") ?: "", con4 = sharedPrefTitlefri.getString("con4", "") ?: "", con5 = sharedPrefTitlefri.getString("con5", "") ?: "", edm1 = sharedPrefTitlefri.getString("edm1", "") ?: "", edm2 = sharedPrefTitlefri.getString("edm2", "") ?: "", edm3 = sharedPrefTitlefri.getString("edm3", "") ?: "", edm4 = sharedPrefTitlefri.getString("edm4", "") ?: "", edm5 = sharedPrefTitlefri.getString("edm5", "") ?: "", eds1 = sharedPrefTitlefri.getString("eds1", "") ?: "", eds2 = sharedPrefTitlefri.getString("eds2", "") ?: "", eds3 = sharedPrefTitlefri.getString("eds3", "") ?: "", eds4 = sharedPrefTitlefri.getString("eds4", "") ?: "", eds5 = sharedPrefTitlefri.getString("eds5", "") ?: "" ) initializeEditText(binding.edTitle, routine.title) routine.con1?.let { initializeEditText(binding.edContent1, it) } routine.con2?.let { initializeEditText(binding.edContent2, it) } routine.con3?.let { initializeEditText(binding.edContent3, it) } routine.con4?.let { initializeEditText(binding.edContent4, it) } routine.con5?.let { initializeEditText(binding.edContent5, it) } initializeEditText(binding.edm1, routine.edm1.toString()) initializeEditText(binding.edm2, routine.edm2.toString()) initializeEditText(binding.edm3, routine.edm3.toString()) initializeEditText(binding.edm4, routine.edm4.toString()) initializeEditText(binding.edm5, routine.edm5.toString()) initializeEditText(binding.eds1, routine.eds1.toString()) initializeEditText(binding.eds2, routine.eds2.toString()) initializeEditText(binding.eds3, routine.eds3.toString()) initializeEditText(binding.eds4, routine.eds4.toString()) initializeEditText(binding.eds5, routine.eds5.toString()) binding.spinner.setSelection(getSelectedSpinnerPosition(sharedPrefTitlefri, routine.selectedSpinnerItem)) binding.btnSaveAll.setOnClickListener { //Toast Toast.makeText(this,"๊ธˆ์š”์ผ ๋ฃจํ‹ด์ด ์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.", Toast.LENGTH_SHORT).show() val edTitle = binding.edTitle.text.toString() val edCon1 = binding.edContent1.text.toString() val edCon2 = binding.edContent2.text.toString() val edCon3 = binding.edContent3.text.toString() val edCon4 = binding.edContent4.text.toString() val edCon5 = binding.edContent5.text.toString() val edm1 = binding.edm1.text.toString().toIntOrNull() ?: 0 val edm2 = binding.edm2.text.toString().toIntOrNull() ?: 0 val edm3 = binding.edm3.text.toString().toIntOrNull() ?: 0 val edm4 = binding.edm4.text.toString().toIntOrNull() ?: 0 val edm5 = binding.edm5.text.toString().toIntOrNull() ?: 0 val eds1 = binding.eds1.text.toString().toIntOrNull() ?: 0 val eds2 = binding.eds2.text.toString().toIntOrNull() ?: 0 val eds3 = binding.eds3.text.toString().toIntOrNull() ?: 0 val eds4 = binding.eds4.text.toString().toIntOrNull() ?: 0 val eds5 = binding.eds5.text.toString().toIntOrNull() ?: 0 // ์Šคํ”ผ๋„ˆ์—์„œ ์„ ํƒ๋œ ํ•ญ๋ชฉ์˜ ๊ฐ’์„ ๊ฐ€์ ธ์˜ค๊ธฐ val selectedSpinnerItem = binding.spinner.selectedItem.toString() // RoutineData ๊ฐ์ฒด ์—…๋ฐ์ดํŠธ val routine = RoutineData( title = edTitle, selectedSpinnerItem = selectedSpinnerItem, con1 = edCon1, con2 = edCon2, con3 = edCon3, con4 = edCon4, con5 = edCon5, edm1 = edm1.toString(), edm2 = edm2.toString(), edm3 = edm3.toString(), edm4 = edm4.toString(), edm5 = edm5.toString(), eds1 = eds1.toString(), eds2 = eds2.toString(), eds3 = eds3.toString(), eds4 = eds4.toString(), eds5 = eds5.toString() ) // RoutineData ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ๋ฐ์ดํ„ฐ ์ƒ์„ฑ val xmlData = generateXmlData(routine,"Fri") // userEmail์„ ์ด์šฉํ•˜์—ฌ StorageManager๋ฅผ ์ดˆ๊ธฐํ™” val storageManager = StorageManager(this) // StorageManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ํŒŒ์ผ ์—…๋กœ๋“œ storageManager.uploadXmlFile(xmlData,"Fri") // SharedPreferences๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ์ €์žฅ val userUid = FirebaseAuth.getInstance().uid val sharedPrefTitlefri = getSharedPreferences("Routine_Fri$userUid", Context.MODE_PRIVATE) val editor = sharedPrefTitlefri.edit() editor.putString("title", routine.title) editor.putString("selectedSpinnerItem", routine.selectedSpinnerItem) editor.putString("con1", routine.con1) editor.putString("con2", routine.con2) editor.putString("con3", routine.con3) editor.putString("con4", routine.con4) editor.putString("con5", routine.con5) editor.putString("edm1", routine.edm1) editor.putString("edm2", routine.edm2) editor.putString("edm3", routine.edm3) editor.putString("edm4", routine.edm4) editor.putString("edm5", routine.edm5) editor.putString("eds1", routine.eds1) editor.putString("eds2", routine.eds2) editor.putString("eds3", routine.eds3) editor.putString("eds4", routine.eds4) editor.putString("eds5", routine.eds5) editor.apply() // ์ €์žฅ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ด๋ฃจ์–ด์ง€๋ฉด ์•กํ‹ฐ๋น„ํ‹ฐ ์ด๋™ val intent = Intent(this, MyActivity::class.java) startActivity(intent) finish() // ํ˜„์žฌ ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ์ข…๋ฃŒ } binding.btnCancel.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MyActivity::class.java) startActivity(intent) } // ๋ฒ„ํŠผํด๋ฆญ์‹œ ๋งˆ์ด๋ฃจํ‹ด์œผ๋กœ ์ด๋™ binding.btnMypage.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MainActivity::class.java) startActivity(intent) } // ์Šคํ”ผ๋„ˆ ๊ฐ์ฒด ์ƒ์„ฑ spinner = binding.spinner // // ์Šคํ”ผ๋„ˆ ํด๋ฆญ ์‹œ ๋‹ค์ด์–ผ๋กœ๊ทธ ๋„์šฐ๊ธฐ // spinner.setOnTouchListener { _, _ -> // showSearchableSpinnerDialog() // false // } // ์Šคํ”ผ๋„ˆ ํด๋ฆญ ์‹œ ๋‹ค์ด์–ผ๋กœ๊ทธ ๋„์šฐ๊ธฐ spinner.setOnTouchListener { _, _ -> if (dialog == null) { // ๋‹ค์ด์–ผ๋กœ๊ทธ๊ฐ€ ์ดˆ๊ธฐํ™”๋˜์ง€ ์•Š์•˜๋‹ค๋ฉด ์ดˆ๊ธฐํ™” ํ›„ ๋ณด์—ฌ์ฃผ๊ธฐ showSearchableSpinnerDialog() } else if (!dialog!!.isShowing) { // ๋‹ค์ด์–ผ๋กœ๊ทธ๊ฐ€ ์ดˆ๊ธฐํ™”๋˜์–ด ์žˆ๊ณ  ๋ณด์—ฌ์ง€์ง€ ์•Š๋Š” ์ƒํƒœ๋ผ๋ฉด ๋ณด์—ฌ์ฃผ๊ธฐ showSearchableSpinnerDialog() } true } // ์ดˆ๊ธฐํ™” arrayList = arrayListOf( "์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ" ) // ๋“œ๋กญ๋‹ค์šด ๋ฉ”๋‰ด์— ํ‘œ์‹œํ•  ํ•ญ๋ชฉ๋“ค val items = arrayOf("์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ") // ArrayAdapter๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋“œ๋กญ๋‹ค์šด ๋ฉ”๋‰ด์— ํ•ญ๋ชฉ๋“ค์„ ์—ฐ๊ฒฐ val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, items) adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spinner.adapter = adapter val items2 = arrayOf("์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ") // ์ €์žฅ๋œ ๊ฐ’์„ ๋ถˆ๋Ÿฌ์™€์„œ ์Šคํ”ผ๋„ˆ์— ๋Œ€์ž… val savedSpinnerItem = sharedPrefTitlefri.getString("selectedSpinnerItem", "") if (items2.contains(savedSpinnerItem)) { val positionInAdapter = items2.indexOf(savedSpinnerItem) binding.spinner.setSelection(positionInAdapter) } } // ์—…๋กœ๋“œํ•  ํŒŒ์ผ์— ์ €์žฅ๋  ๊ฐ’ ์„ค์ • private fun generateXmlData(routine: RoutineData, dayOfWeek:String): String { val xmlStringBuilder = StringBuilder() xmlStringBuilder.append("<routine>") xmlStringBuilder.append("<title>${routine.title}</title>") xmlStringBuilder.append("<con1>${routine.con1}</con1>") xmlStringBuilder.append("<con2>${routine.con2}</con2>") xmlStringBuilder.append("<con3>${routine.con3}</con3>") xmlStringBuilder.append("<con4>${routine.con4}</con4>") xmlStringBuilder.append("<con5>${routine.con5}</con5>") xmlStringBuilder.append("<edm1>${routine.edm1}</edm1>") xmlStringBuilder.append("<edm2>${routine.edm2}</edm2>") xmlStringBuilder.append("<edm3>${routine.edm3}</edm3>") xmlStringBuilder.append("<edm4>${routine.edm4}</edm4>") xmlStringBuilder.append("<edm5>${routine.edm5}</edm5>") xmlStringBuilder.append("<eds1>${routine.eds1}</eds1>") xmlStringBuilder.append("<eds2>${routine.eds2}</eds2>") xmlStringBuilder.append("<eds3>${routine.eds3}</eds3>") xmlStringBuilder.append("<eds4>${routine.eds4}</eds4>") xmlStringBuilder.append("<eds5>${routine.eds5}</eds5>") xmlStringBuilder.append("<selectedSpinnerItem>${routine.selectedSpinnerItem}</selectedSpinnerItem>") xmlStringBuilder.append("</routine>") return xmlStringBuilder.toString() } private fun initializeEditText(editText: EditText, value: String) { editText.setText(value) } private fun getSelectedSpinnerPosition(sharedPrefs: SharedPreferences, savedValue: String): Int { val items = arrayOf("์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ") return items.indexOf(savedValue).coerceAtLeast(0) } private fun showSearchableSpinnerDialog() { // dialog ์ดˆ๊ธฐํ™” dialog = Dialog(this) // dialog set dialog!!.setContentView(R.layout.dialog_searchable_spinner) dialog!!.window?.setLayout(650, 800) dialog!!.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog!!.show() val editText: EditText = dialog!!.findViewById(R.id.edit_text) val listView: ListView = dialog!!.findViewById(R.id.list_view) val dialogAdapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, arrayList) // ์–ด๋Œ‘ํ„ฐ ์„ค์ • listView.adapter = dialogAdapter editText.addTextChangedListener(object : TextWatcher { override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { dialogAdapter.filter.filter(s) } override fun afterTextChanged(s: Editable?) {} }) listView.setOnItemClickListener { _, _, position, _ -> // ์„ ํƒํ•œ ๊ฐ’์„ ํ”„๋กœํผํ‹ฐ์— ์„ค์ • selectedSpinnerValue = dialogAdapter.getItem(position).toString() val positionInAdapter = arrayList.indexOf(selectedSpinnerValue) // ์Šคํ”ผ๋„ˆ์— ์„ ํƒ๋œ ํ•ญ๋ชฉ ๋Œ€์ž… // val positionInAdapter = dialogAdapter.getPosition(selectedSpinnerValue) if (positionInAdapter != -1) { spinner.setSelection(positionInAdapter) } // ์‚ฌ์šฉ์ž๊ฐ€ ํ•ญ๋ชฉ ์„ ํƒํ•˜๋ฉด ๋‹ค์ด์–ผ๋กœ๊ทธ ๋‹ซ์Œ dialog!!.dismiss() } } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/StopActivity2.kt
3007358413
package com.example.android_team4_project import android.app.NotificationChannel import android.app.NotificationManager import android.content.Context import android.content.Intent import android.graphics.Color import android.os.Build import android.os.Bundle import android.os.SystemClock import android.util.Log import android.view.KeyEvent import android.view.View import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.core.app.NotificationCompat import com.example.android_team4_project.databinding.ActivityStop2Binding class StopActivity2 : AppCompatActivity() { var initTime = 0L var pauseTime = 0L override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val binding = ActivityStop2Binding.inflate(layoutInflater) setContentView(binding.root) binding.btnStart2.setOnClickListener { binding.chronometer2.base = SystemClock.elapsedRealtime() + pauseTime binding.chronometer2.start() binding.btnStop2.isEnabled = true binding.btnReset2.isEnabled = true binding.btnStart2.isEnabled = false binding.btnSave2.visibility = View.INVISIBLE } // binding.btnStop.text = "Stop" binding.btnStop2.setOnClickListener { pauseTime = binding.chronometer2.base - SystemClock.elapsedRealtime() binding.chronometer2.stop() binding.btnStart2.isEnabled = true binding.btnStop2.isEnabled = false binding.btnReset2.isEnabled = true binding.btnSave2.isEnabled = true binding.btnSave2.visibility = View.VISIBLE } binding.btnReset2.setOnClickListener { // binding.btnReset.text = "Reset" pauseTime = 0L binding.chronometer2.base = SystemClock.elapsedRealtime() binding.chronometer2.stop() binding.btnStart2.isEnabled = true binding.btnStop2.isEnabled = false binding.btnReset2.isEnabled = false binding.btnSave2.visibility = View.INVISIBLE } //getTime1์™€ chronometer๊ฐ’์ด ๊ฐ™์•„์ง€๋ฉด notification๋œจ๊ฒŒํ•˜๊ธฐ binding.chronometer2.setOnChronometerTickListener{ // Mainactivity์—์„œ stopActivity1 ์—ด๋•Œ ๋ณด๋ƒˆ๋˜ ์‚ฌ์šฉ์ž๊ฐ€ ์ง€์ •ํ•œ ๋ฃจํ‹ด ์‹œ๊ฐ„ ๊ฐ’ ๋ฐ›์•„์˜ค๊ธฐ val isGetTime2 = intent.getStringExtra("isGetTime2") // ์ •๊ทœ์‹์„ ์‚ฌ์šฉํ•˜์—ฌ "๋ถ„"๊ณผ "์ดˆ"๋ฅผ ์—†์• ๊ณ , ":"๋กœ ๋ถ„๊ณผ ์ดˆ๋ฅผ ๊ตฌ๋ถ„ํ•˜์—ฌ ํ•ฉ์น˜๊ธฐ val modifiedText = isGetTime2.toString().replace(Regex("[^0-9]"), "").chunked(2).joinToString(":") { it } val elapsedMillis = SystemClock.elapsedRealtime() - binding.chronometer2.base val elapsedSeconds = elapsedMillis / 1000 // TextView ์—…๋ฐ์ดํŠธ ๋˜๋Š” ํŠน์ • ์‹œ๊ฐ„์— ๋„๋‹ฌํ•˜๋ฉด ์•Œ๋ฆผ ๋“ฑ // ๊ฒฝ๊ณผ๋œ ์‹œ๊ฐ„์„ ๋ถ„๊ณผ ์ดˆ๋กœ ๋ณ€ํ™˜ val elapsedMinutes = elapsedSeconds / 60 val remainingSeconds = elapsedSeconds % 60 val currentTime = String.format("%02d:%02d", elapsedMinutes, remainingSeconds) if(modifiedText == currentTime){ notiAlarm() // Toast.makeText(this,"good" , Toast.LENGTH_SHORT).show() } } binding.btnSave2.setOnClickListener { pauseTime = binding.chronometer2.base - SystemClock.elapsedRealtime() binding.chronometer2.stop() val intent = Intent(this, MainActivity::class.java) // intent.putExtra("times2", binding.chronometer2.text.toString()) startActivity(intent) val sharePref2 = getSharedPreferences("stop2", Context.MODE_PRIVATE) val editor2 = sharePref2.edit() editor2.putString("times2", binding.chronometer2.text.toString()) editor2.apply() } } private fun notiAlarm() { // getSystemService(์„œ๋น„์Šค) : ์•ˆ๋“œ๋กœ์ด๋“œ ์‹œ์Šคํ…œ์—์„œ ๋™์ž‘ํ•˜๊ณ  ์žˆ๋Š” ์„œ๋น„์Šค ์ค‘ ์ง€์ •ํ•œ ์„œ๋น„์Šค๋ฅผ ๊ฐ€์ ธ์˜ด // getSystemService() ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ NotificationManager ํƒ€์ž…์˜ ๊ฐ์ฒด ๊ฐ€์ ธ์˜ค๊ธฐ val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager // NotificationCompat ํƒ€์ž…์˜ ๊ฐ์ฒด๋ฅผ ์ €์žฅํ•  ๋ณ€์ˆ˜ ์„ ์–ธ val builder: NotificationCompat.Builder // API 26๋ถ€ํ„ฐ ์ฑ„๋„์ด ์ถ”๊ฐ€ ๋˜์–ด ๋ฒ„์ „์— ๋”ฐ๋ผ ์‚ฌ์šฉ ๋ฐฉ์‹์„ ๋ณ€๊ฒฝ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val channelId = "one-channel" val channelName = "My Channel One" // ์ฑ„๋„ ๊ฐ์ฒด ์ƒ์„ฑ val channel = NotificationChannel( channelId, channelName, // ์•Œ๋ฆผ ๋“ฑ๊ธ‰ ์„ค์ • NotificationManager.IMPORTANCE_DEFAULT ) channel.description = "My Channel One description" channel.setShowBadge(true) // ์•Œ๋ฆผ ์‹œ ๋ผ์ดํŠธ ์‚ฌ์šฉ channel.enableLights(true) channel.lightColor = Color.RED // ์ง€์ •ํ•œ ์ฑ„๋„ ์ •๋ณด๋ฅผ ํ†ตํ•ด์„œ ์ฑ„๋„ ์ƒ์„ฑ manager.createNotificationChannel(channel) // NotificationCompat ํƒ€์ž…์˜ ๊ฐ์ฒด ์ƒ์„ฑ builder = NotificationCompat.Builder(this, channelId) } else { builder = NotificationCompat.Builder(this) } // ์Šคํ…Œ์ด์Šคํ„ฐ์ฐฝ ์•Œ๋ฆผ ํ™”๋ฉด ์„ค์ • builder.setSmallIcon(android.R.drawable.ic_notification_overlay) builder.setWhen(System.currentTimeMillis()) builder.setContentTitle("์•Œ๋ฆผ") builder.setContentText("๋ฃจํ‹ด ์„ฑ๊ณต!") // NotificationManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์Šคํ…Œ์ดํ„ฐ์Šค์ฐฝ์— ์•Œ๋ฆผ์ฐฝ ์ถœ๋ ฅ manager.notify(11, builder.build()) } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/PopupActivitysat.kt
2033505829
package com.example.android_team4_project import android.app.Dialog import android.content.Context import android.content.Intent import android.content.SharedPreferences import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.text.Editable import android.text.TextWatcher import android.widget.ArrayAdapter import android.widget.EditText import android.widget.ListView import android.widget.Spinner import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.example.android_team4_project.databinding.ActivityPopupBinding import com.google.firebase.auth.FirebaseAuth class PopupActivitysat : AppCompatActivity() { private lateinit var binding: ActivityPopupBinding private lateinit var userEmail: String private lateinit var arrayList: ArrayList<String> private lateinit var dialog: Dialog private lateinit var spinner: Spinner private lateinit var selectedSpinnerValue: String private lateinit var auth: FirebaseAuth override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityPopupBinding.inflate(layoutInflater) setContentView(binding.root) auth = FirebaseAuth.getInstance() val user = auth.currentUser userEmail = user?.uid ?: "" dialog = Dialog(this) val sharedPrefTitlesat = getSharedPreferences("Routine_Sat$userEmail", Context.MODE_PRIVATE) val routine = RoutineData( title = sharedPrefTitlesat.getString("title", "") ?: "", selectedSpinnerItem = sharedPrefTitlesat.getString("selectedSpinnerItem", "") ?: "", con1 = sharedPrefTitlesat.getString("con1", "") ?: "", con2 = sharedPrefTitlesat.getString("con2", "") ?: "", con3 = sharedPrefTitlesat.getString("con3", "") ?: "", con4 = sharedPrefTitlesat.getString("con4", "") ?: "", con5 = sharedPrefTitlesat.getString("con5", "") ?: "", edm1 = sharedPrefTitlesat.getString("edm1", "") ?: "", edm2 = sharedPrefTitlesat.getString("edm2", "") ?: "", edm3 = sharedPrefTitlesat.getString("edm3", "") ?: "", edm4 = sharedPrefTitlesat.getString("edm4", "") ?: "", edm5 = sharedPrefTitlesat.getString("edm5", "") ?: "", eds1 = sharedPrefTitlesat.getString("eds1", "") ?: "", eds2 = sharedPrefTitlesat.getString("eds2", "") ?: "", eds3 = sharedPrefTitlesat.getString("eds3", "") ?: "", eds4 = sharedPrefTitlesat.getString("eds4", "") ?: "", eds5 = sharedPrefTitlesat.getString("eds5", "") ?: "" ) initializeEditText(binding.edTitle, routine.title) routine.con1?.let { initializeEditText(binding.edContent1, it) } routine.con2?.let { initializeEditText(binding.edContent2, it) } routine.con3?.let { initializeEditText(binding.edContent3, it) } routine.con4?.let { initializeEditText(binding.edContent4, it) } routine.con5?.let { initializeEditText(binding.edContent5, it) } initializeEditText(binding.edm1, routine.edm1.toString()) initializeEditText(binding.edm2, routine.edm2.toString()) initializeEditText(binding.edm3, routine.edm3.toString()) initializeEditText(binding.edm4, routine.edm4.toString()) initializeEditText(binding.edm5, routine.edm5.toString()) initializeEditText(binding.eds1, routine.eds1.toString()) initializeEditText(binding.eds2, routine.eds2.toString()) initializeEditText(binding.eds3, routine.eds3.toString()) initializeEditText(binding.eds4, routine.eds4.toString()) initializeEditText(binding.eds5, routine.eds5.toString()) binding.spinner.setSelection(getSelectedSpinnerPosition(sharedPrefTitlesat, routine.selectedSpinnerItem)) binding.btnSaveAll.setOnClickListener { //Toast Toast.makeText(this,"ํ† ์š”์ผ ๋ฃจํ‹ด์ด ์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.",Toast.LENGTH_SHORT).show() val edTitle = binding.edTitle.text.toString() val edCon1 = binding.edContent1.text.toString() val edCon2 = binding.edContent2.text.toString() val edCon3 = binding.edContent3.text.toString() val edCon4 = binding.edContent4.text.toString() val edCon5 = binding.edContent5.text.toString() val edm1 = binding.edm1.text.toString().toIntOrNull() ?: 0 val edm2 = binding.edm2.text.toString().toIntOrNull() ?: 0 val edm3 = binding.edm3.text.toString().toIntOrNull() ?: 0 val edm4 = binding.edm4.text.toString().toIntOrNull() ?: 0 val edm5 = binding.edm5.text.toString().toIntOrNull() ?: 0 val eds1 = binding.eds1.text.toString().toIntOrNull() ?: 0 val eds2 = binding.eds2.text.toString().toIntOrNull() ?: 0 val eds3 = binding.eds3.text.toString().toIntOrNull() ?: 0 val eds4 = binding.eds4.text.toString().toIntOrNull() ?: 0 val eds5 = binding.eds5.text.toString().toIntOrNull() ?: 0 // ์Šคํ”ผ๋„ˆ์—์„œ ์„ ํƒ๋œ ํ•ญ๋ชฉ์˜ ๊ฐ’์„ ๊ฐ€์ ธ์˜ค๊ธฐ val selectedSpinnerItem = binding.spinner.selectedItem.toString() // RoutineData ๊ฐ์ฒด ์—…๋ฐ์ดํŠธ val routine = RoutineData( title = edTitle, selectedSpinnerItem = selectedSpinnerItem, con1 = edCon1, con2 = edCon2, con3 = edCon3, con4 = edCon4, con5 = edCon5, edm1 = edm1.toString(), edm2 = edm2.toString(), edm3 = edm3.toString(), edm4 = edm4.toString(), edm5 = edm5.toString(), eds1 = eds1.toString(), eds2 = eds2.toString(), eds3 = eds3.toString(), eds4 = eds4.toString(), eds5 = eds5.toString() ) // RoutineData ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ๋ฐ์ดํ„ฐ ์ƒ์„ฑ val xmlData = generateXmlData(routine,"Sat") // userEmail์„ ์ด์šฉํ•˜์—ฌ StorageManager๋ฅผ ์ดˆ๊ธฐํ™” val storageManager = StorageManager(this) // StorageManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ํŒŒ์ผ ์—…๋กœ๋“œ storageManager.uploadXmlFile(xmlData,"Sat") // SharedPreferences๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ์ €์žฅ val userUid = FirebaseAuth.getInstance().uid val sharedPrefTitlesat = getSharedPreferences("Routine_Sat$userUid", Context.MODE_PRIVATE) val editor = sharedPrefTitlesat.edit() editor.putString("title", routine.title) editor.putString("selectedSpinnerItem", routine.selectedSpinnerItem) editor.putString("con1", routine.con1) editor.putString("con2", routine.con2) editor.putString("con3", routine.con3) editor.putString("con4", routine.con4) editor.putString("con5", routine.con5) editor.putString("edm1", routine.edm1) editor.putString("edm2", routine.edm2) editor.putString("edm3", routine.edm3) editor.putString("edm4", routine.edm4) editor.putString("edm5", routine.edm5) editor.putString("eds1", routine.eds1) editor.putString("eds2", routine.eds2) editor.putString("eds3", routine.eds3) editor.putString("eds4", routine.eds4) editor.putString("eds5", routine.eds5) editor.apply() // ์ €์žฅ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ด๋ฃจ์–ด์ง€๋ฉด ์•กํ‹ฐ๋น„ํ‹ฐ ์ด๋™ val intent = Intent(this, MyActivity::class.java) startActivity(intent) finish() // ํ˜„์žฌ ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ์ข…๋ฃŒ } binding.btnCancel.setOnClickListener { finish() // ํ˜„์žฌ ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ์ข…๋ฃŒ // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MyActivity::class.java) startActivity(intent) } // ๋ฒ„ํŠผํด๋ฆญ์‹œ ๋งˆ์ด๋ฃจํ‹ด์œผ๋กœ ์ด๋™ binding.btnMypage.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MainActivity::class.java) startActivity(intent) } // ์Šคํ”ผ๋„ˆ ๊ฐ์ฒด ์ƒ์„ฑ spinner = binding.spinner // // ์Šคํ”ผ๋„ˆ ํด๋ฆญ ์‹œ ๋‹ค์ด์–ผ๋กœ๊ทธ ๋„์šฐ๊ธฐ // spinner.setOnTouchListener { _, _ -> // showSearchableSpinnerDialog() // false // } // ์Šคํ”ผ๋„ˆ ํด๋ฆญ ์‹œ ๋‹ค์ด์–ผ๋กœ๊ทธ ๋„์šฐ๊ธฐ spinner.setOnTouchListener { _, _ -> if (dialog == null) { // ๋‹ค์ด์–ผ๋กœ๊ทธ๊ฐ€ ์ดˆ๊ธฐํ™”๋˜์ง€ ์•Š์•˜๋‹ค๋ฉด ์ดˆ๊ธฐํ™” ํ›„ ๋ณด์—ฌ์ฃผ๊ธฐ showSearchableSpinnerDialog() } else if (!dialog!!.isShowing) { // ๋‹ค์ด์–ผ๋กœ๊ทธ๊ฐ€ ์ดˆ๊ธฐํ™”๋˜์–ด ์žˆ๊ณ  ๋ณด์—ฌ์ง€์ง€ ์•Š๋Š” ์ƒํƒœ๋ผ๋ฉด ๋ณด์—ฌ์ฃผ๊ธฐ showSearchableSpinnerDialog() } true } // ์ดˆ๊ธฐํ™” arrayList = arrayListOf( "์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ" ) // ๋“œ๋กญ๋‹ค์šด ๋ฉ”๋‰ด์— ํ‘œ์‹œํ•  ํ•ญ๋ชฉ๋“ค val items = arrayOf("์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ") // ArrayAdapter๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋“œ๋กญ๋‹ค์šด ๋ฉ”๋‰ด์— ํ•ญ๋ชฉ๋“ค์„ ์—ฐ๊ฒฐ val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, items) adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spinner.adapter = adapter val items2 = arrayOf("์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ") // ์ €์žฅ๋œ ๊ฐ’์„ ๋ถˆ๋Ÿฌ์™€์„œ ์Šคํ”ผ๋„ˆ์— ๋Œ€์ž… val savedSpinnerItem = sharedPrefTitlesat.getString("selectedSpinnerItem", "") if (items2.contains(savedSpinnerItem)) { val positionInAdapter = items2.indexOf(savedSpinnerItem) binding.spinner.setSelection(positionInAdapter) } } // ์—…๋กœ๋“œํ•  ํŒŒ์ผ์— ์ €์žฅ๋  ๊ฐ’ ์„ค์ • private fun generateXmlData(routine: RoutineData, dayOfWeek:String): String { val xmlStringBuilder = StringBuilder() xmlStringBuilder.append("<routine>") xmlStringBuilder.append("<title>${routine.title}</title>") xmlStringBuilder.append("<con1>${routine.con1}</con1>") xmlStringBuilder.append("<con2>${routine.con2}</con2>") xmlStringBuilder.append("<con3>${routine.con3}</con3>") xmlStringBuilder.append("<con4>${routine.con4}</con4>") xmlStringBuilder.append("<con5>${routine.con5}</con5>") xmlStringBuilder.append("<edm1>${routine.edm1}</edm1>") xmlStringBuilder.append("<edm2>${routine.edm2}</edm2>") xmlStringBuilder.append("<edm3>${routine.edm3}</edm3>") xmlStringBuilder.append("<edm4>${routine.edm4}</edm4>") xmlStringBuilder.append("<edm5>${routine.edm5}</edm5>") xmlStringBuilder.append("<eds1>${routine.eds1}</eds1>") xmlStringBuilder.append("<eds2>${routine.eds2}</eds2>") xmlStringBuilder.append("<eds3>${routine.eds3}</eds3>") xmlStringBuilder.append("<eds4>${routine.eds4}</eds4>") xmlStringBuilder.append("<eds5>${routine.eds5}</eds5>") xmlStringBuilder.append("<selectedSpinnerItem>${routine.selectedSpinnerItem}</selectedSpinnerItem>") xmlStringBuilder.append("</routine>") return xmlStringBuilder.toString() } private fun initializeEditText(editText: EditText, value: String) { editText.setText(value) } private fun getSelectedSpinnerPosition(sharedPrefs: SharedPreferences, savedValue: String): Int { val items = arrayOf("์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ") return items.indexOf(savedValue).coerceAtLeast(0) } private fun showSearchableSpinnerDialog() { // dialog ์ดˆ๊ธฐํ™” dialog = Dialog(this) // dialog set dialog!!.setContentView(R.layout.dialog_searchable_spinner) dialog!!.window?.setLayout(650, 800) dialog!!.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog!!.show() val editText: EditText = dialog!!.findViewById(R.id.edit_text) val listView: ListView = dialog!!.findViewById(R.id.list_view) val dialogAdapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, arrayList) // ์–ด๋Œ‘ํ„ฐ ์„ค์ • listView.adapter = dialogAdapter editText.addTextChangedListener(object : TextWatcher { override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { dialogAdapter.filter.filter(s) } override fun afterTextChanged(s: Editable?) {} }) listView.setOnItemClickListener { _, _, position, _ -> // ์„ ํƒํ•œ ๊ฐ’์„ ํ”„๋กœํผํ‹ฐ์— ์„ค์ • selectedSpinnerValue = dialogAdapter.getItem(position).toString() val positionInAdapter = arrayList.indexOf(selectedSpinnerValue) // ์Šคํ”ผ๋„ˆ์— ์„ ํƒ๋œ ํ•ญ๋ชฉ ๋Œ€์ž… // val positionInAdapter = dialogAdapter.getPosition(selectedSpinnerValue) if (positionInAdapter != -1) { spinner.setSelection(positionInAdapter) } // ์‚ฌ์šฉ์ž๊ฐ€ ํ•ญ๋ชฉ ์„ ํƒํ•˜๋ฉด ๋‹ค์ด์–ผ๋กœ๊ทธ ๋‹ซ์Œ dialog!!.dismiss() } } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/DetailActivitytue.kt
1775559125
package com.example.android_team4_project import android.app.AlertDialog import android.app.Dialog import android.content.Context import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.view.View import android.widget.Button import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.example.android_team4_project.databinding.ActivityDetailBinding import com.google.firebase.auth.FirebaseAuth private lateinit var auth: FirebaseAuth private lateinit var userEmail: String class DetailActivitytue: AppCompatActivity() { private lateinit var binding: ActivityDetailBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityDetailBinding.inflate(layoutInflater) setContentView(binding.root) auth = FirebaseAuth.getInstance() val user = auth.currentUser userEmail = user?.uid ?: "" // ๋ฒ„ํŠผํด๋ฆญ์‹œ ๋งˆ์ด๋ฃจํ‹ด์œผ๋กœ ์ด๋™ binding.btnMypage.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MainActivity::class.java) startActivity(intent) } // ์ˆ˜์ •๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํ•ด๋‹น์š”์ผ ํŒ์—…์—‘ํ‹ฐ๋น„ํ‹ฐ binding.btnSaveAll.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, PopupActivitytue::class.java) startActivity(intent) } // ์‚ญ์ œ๋ฒ„ํŠผ ํด๋ฆญ์‹œ ์ €์žฅ๋‚ด์šฉ ์‚ญ์ œ // binding.btnCancel.setOnClickListener { // showDeleteConfirmationDialog() // } binding.btnCancel.setOnClickListener { val view = View.inflate(this, R.layout.dialog_view, null) val builder = androidx.appcompat.app.AlertDialog.Builder(this) builder.setView(view) val dialog = builder.create() dialog.setCanceledOnTouchOutside(false) dialog.show() val btnConfirm = view.findViewById<Button>(R.id.btn_confirm) val btnCancel = view.findViewById<Button>(R.id.btn_cancel) btnConfirm.setOnClickListener { showDeleteConfirmationDialog() Toast.makeText(this@DetailActivitytue, "์‚ญ์ œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค", Toast.LENGTH_SHORT).show() dialog.dismiss() } btnCancel.setOnClickListener { dialog.dismiss() } dialog.window?.setBackgroundDrawable(ColorDrawable(Color.WHITE)) } // SharedPreferences์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPrefTitletue = getSharedPreferences("Routine_Tue$userEmail", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitletue = sharedPrefTitletue.getString("title", "") val savedSpinnertue = sharedPrefTitletue.getString("selectedSpinnerItem", "") val savedcon1tue = sharedPrefTitletue.getString("con1", "") val savedcon2tue = sharedPrefTitletue.getString("con2", "") val savedcon3tue = sharedPrefTitletue.getString("con3", "") val savedcon4tue = sharedPrefTitletue.getString("con4", "") val savedcon5tue = sharedPrefTitletue.getString("con5", "") val savededm1tue = sharedPrefTitletue.getString("edm1", "") val savededm2tue = sharedPrefTitletue.getString("edm2", "") val savededm3tue = sharedPrefTitletue.getString("edm3", "") val savededm4tue = sharedPrefTitletue.getString("edm4", "") val savededm5tue = sharedPrefTitletue.getString("edm5", "") val savededs1tue = sharedPrefTitletue.getString("eds1", "") val savededs2tue = sharedPrefTitletue.getString("eds2", "") val savededs3tue = sharedPrefTitletue.getString("eds3", "") val savededs4tue = sharedPrefTitletue.getString("eds4", "") val savededs5tue = sharedPrefTitletue.getString("eds5", "") // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • binding.edTitle.text = savedTitletue binding.spinner.text = savedSpinnertue binding.edContent1.text = savedcon1tue binding.edContent2.text = savedcon2tue binding.edContent3.text = savedcon3tue binding.edContent4.text = savedcon4tue binding.edContent5.text = savedcon5tue binding.edm1.text = savededm1tue binding.edm2.text = savededm2tue binding.edm3.text = savededm3tue binding.edm4.text = savededm4tue binding.edm5.text = savededm5tue binding.eds1.text = savededs1tue binding.eds2.text = savededs2tue binding.eds3.text = savededs3tue binding.eds4.text = savededs4tue binding.eds5.text = savededs5tue } private fun showDeleteConfirmationDialog() { val builder = AlertDialog.Builder(this) builder.setTitle("์ฃผ์˜") builder.setMessage("์‚ญ์ œํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?") builder.setPositiveButton("์‚ญ์ œ") { _, _ -> // ์‚ฌ์šฉ์ž๊ฐ€ ์‚ญ์ œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ–ˆ์„ ๋•Œ auth = FirebaseAuth.getInstance() val user = auth.currentUser userEmail = user?.uid ?: "" // RoutineData ๊ฐ์ฒด ์—…๋ฐ์ดํŠธ val routine = RoutineData( title = "", selectedSpinnerItem = "", con1 = "", con2 = "", con3 = "", con4 = "", con5 = "", edm1 = "", edm2 = "", edm3 = "", edm4 = "", edm5 = "", eds1 = "", eds2 = "", eds3 = "", eds4 = "", eds5 = "" ) // RoutineData ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ๋ฐ์ดํ„ฐ ์ƒ์„ฑ val xmlData = generateXmlData(routine, "Tue") // userEmail์„ ์ด์šฉํ•˜์—ฌ StorageManager๋ฅผ ์ดˆ๊ธฐํ™” val storageManager = StorageManager(this) // StorageManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ํŒŒ์ผ ์—…๋กœ๋“œ storageManager.uploadXmlFile(xmlData, "Tue") // SharedPreferences๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ์ €์žฅ val userUid = FirebaseAuth.getInstance().uid val sharedPrefTitletue = getSharedPreferences("Routine_Tue$userUid", Context.MODE_PRIVATE) val editor = sharedPrefTitletue.edit() editor.putString("title", routine.title) editor.putString("selectedSpinnerItem", routine.selectedSpinnerItem) editor.putString("con1", routine.con1) editor.putString("con2", routine.con2) editor.putString("con3", routine.con3) editor.putString("con4", routine.con4) editor.putString("con5", routine.con5) editor.putString("edm1", routine.edm1) editor.putString("edm2", routine.edm2) editor.putString("edm3", routine.edm3) editor.putString("edm4", routine.edm4) editor.putString("edm5", routine.edm5) editor.putString("eds1", routine.eds1) editor.putString("eds2", routine.eds2) editor.putString("eds3", routine.eds3) editor.putString("eds4", routine.eds4) editor.putString("eds5", routine.eds5) editor.apply() // ์ €์žฅ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ด๋ฃจ์–ด์ง€๋ฉด ์•กํ‹ฐ๋น„ํ‹ฐ ์ด๋™ val intent = Intent(this, MyActivity::class.java) startActivity(intent) finish() // ํ˜„์žฌ ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ์ข…๋ฃŒ } builder.setNegativeButton("์ทจ์†Œ") { dialog, _ -> // ์‚ฌ์šฉ์ž๊ฐ€ ์ทจ์†Œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ–ˆ์„ ๋•Œ dialog.dismiss() } val dialog: AlertDialog = builder.create() dialog.show() } private fun generateXmlData(routine: RoutineData, dayOfWeek:String): String { val xmlStringBuilder = StringBuilder() xmlStringBuilder.append("<routine>") xmlStringBuilder.append("<title>${routine.title}</title>") xmlStringBuilder.append("<con1>${routine.con1}</con1>") xmlStringBuilder.append("<con2>${routine.con2}</con2>") xmlStringBuilder.append("<con3>${routine.con3}</con3>") xmlStringBuilder.append("<con4>${routine.con4}</con4>") xmlStringBuilder.append("<con5>${routine.con5}</con5>") xmlStringBuilder.append("<edm1>${routine.edm1}</edm1>") xmlStringBuilder.append("<edm2>${routine.edm2}</edm2>") xmlStringBuilder.append("<edm3>${routine.edm3}</edm3>") xmlStringBuilder.append("<edm4>${routine.edm4}</edm4>") xmlStringBuilder.append("<edm5>${routine.edm5}</edm5>") xmlStringBuilder.append("<eds1>${routine.eds1}</eds1>") xmlStringBuilder.append("<eds2>${routine.eds2}</eds2>") xmlStringBuilder.append("<eds3>${routine.eds3}</eds3>") xmlStringBuilder.append("<eds4>${routine.eds4}</eds4>") xmlStringBuilder.append("<eds5>${routine.eds5}</eds5>") xmlStringBuilder.append("<selectedSpinnerItem>${routine.selectedSpinnerItem}</selectedSpinnerItem>") xmlStringBuilder.append("</routine>") return xmlStringBuilder.toString() } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/XmlParser.kt
2097972070
package com.example.android_team4_project import org.w3c.dom.Document import java.io.ByteArrayInputStream import javax.xml.parsers.DocumentBuilderFactory class XmlParser { fun parseXml(xmlData: String): RoutineData { // XML ํŒŒ์‹ฑ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋กœ์ง val builderFactory = DocumentBuilderFactory.newInstance() val builder = builderFactory.newDocumentBuilder() val input = ByteArrayInputStream(xmlData.toByteArray()) val document: Document = builder.parse(input) // ์—ฌ๊ธฐ์—์„œ Document ๊ฐ์ฒด๋ฅผ ์ด์šฉํ•˜์—ฌ XML ๋ฐ์ดํ„ฐ๋ฅผ ํŒŒ์‹ฑํ•˜๊ณ  ํ•„์š”ํ•œ ์ •๋ณด๋ฅผ ์ถ”์ถœ val title = getNodeContent(document, "title") val selectedSpinnerItem = getNodeContent(document, "selectedSpinnerItem") val con1 = getNodeContent(document, "con1") val con2 = getNodeContent(document, "con2") val con3 = getNodeContent(document, "con3") val con4 = getNodeContent(document, "con4") val con5 = getNodeContent(document, "con5") val edm1 = getNodeContent(document, "edm1") val edm2 = getNodeContent(document, "edm2") val edm3 = getNodeContent(document, "edm3") val edm4 = getNodeContent(document, "edm4") val edm5 = getNodeContent(document, "edm5") val eds1 = getNodeContent(document, "eds1") val eds2 = getNodeContent(document, "eds2") val eds3 = getNodeContent(document, "eds3") val eds4 = getNodeContent(document, "eds4") val eds5 = getNodeContent(document, "eds5") return RoutineData(title, selectedSpinnerItem, con1, con2, con3, con4, con5, edm1, edm2, edm3, edm4, edm5, eds1, eds2, eds3, eds4, eds5) } private fun getNodeContent(document: Document, tagName: String): String { val nodeList = document.getElementsByTagName(tagName) return if (nodeList.length > 0) { nodeList.item(0).textContent } else { "" } } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/RoutineData.kt
134460480
package com.example.android_team4_project import java.io.Serializable data class RoutineData( val title: String, val selectedSpinnerItem: String, val con1: String?, val con2: String?, val con3: String?, val con4: String?, val con5: String?, val edm1: String?, val edm2: String?, val edm3: String?, val edm4: String?, val edm5: String?, val eds1: String?, val eds2: String?, val eds3: String?, val eds4: String?, val eds5: String? ) : Serializable
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/PopupActivitymon.kt
3823262506
package com.example.android_team4_project import android.app.Dialog import android.content.Context import android.content.Intent import android.content.SharedPreferences import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.text.Editable import android.text.TextWatcher import android.widget.ArrayAdapter import android.widget.EditText import android.widget.ListView import android.widget.Spinner import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.example.android_team4_project.databinding.ActivityPopupBinding import com.google.firebase.auth.FirebaseAuth class PopupActivitymon : AppCompatActivity() { private lateinit var binding: ActivityPopupBinding private lateinit var userEmail: String private lateinit var arrayList: ArrayList<String> private lateinit var dialog: Dialog private lateinit var spinner: Spinner private lateinit var selectedSpinnerValue: String private lateinit var auth: FirebaseAuth override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityPopupBinding.inflate(layoutInflater) setContentView(binding.root) auth = FirebaseAuth.getInstance() val user = auth.currentUser userEmail = user?.uid ?: "" dialog = Dialog(this) val sharedPrefTitlemon = getSharedPreferences("Routine_Mon$userEmail", Context.MODE_PRIVATE) val routine = RoutineData( title = sharedPrefTitlemon.getString("title", "") ?: "", selectedSpinnerItem = sharedPrefTitlemon.getString("selectedSpinnerItem", "") ?: "", con1 = sharedPrefTitlemon.getString("con1", "") ?: "", con2 = sharedPrefTitlemon.getString("con2", "") ?: "", con3 = sharedPrefTitlemon.getString("con3", "") ?: "", con4 = sharedPrefTitlemon.getString("con4", "") ?: "", con5 = sharedPrefTitlemon.getString("con5", "") ?: "", edm1 = sharedPrefTitlemon.getString("edm1", "") ?: "", edm2 = sharedPrefTitlemon.getString("edm2", "") ?: "", edm3 = sharedPrefTitlemon.getString("edm3", "") ?: "", edm4 = sharedPrefTitlemon.getString("edm4", "") ?: "", edm5 = sharedPrefTitlemon.getString("edm5", "") ?: "", eds1 = sharedPrefTitlemon.getString("eds1", "") ?: "", eds2 = sharedPrefTitlemon.getString("eds2", "") ?: "", eds3 = sharedPrefTitlemon.getString("eds3", "") ?: "", eds4 = sharedPrefTitlemon.getString("eds4", "") ?: "", eds5 = sharedPrefTitlemon.getString("eds5", "") ?: "" ) initializeEditText(binding.edTitle, routine.title) routine.con1?.let { initializeEditText(binding.edContent1, it) } routine.con2?.let { initializeEditText(binding.edContent2, it) } routine.con3?.let { initializeEditText(binding.edContent3, it) } routine.con4?.let { initializeEditText(binding.edContent4, it) } routine.con5?.let { initializeEditText(binding.edContent5, it) } initializeEditText(binding.edm1, routine.edm1.toString()) initializeEditText(binding.edm2, routine.edm2.toString()) initializeEditText(binding.edm3, routine.edm3.toString()) initializeEditText(binding.edm4, routine.edm4.toString()) initializeEditText(binding.edm5, routine.edm5.toString()) initializeEditText(binding.eds1, routine.eds1.toString()) initializeEditText(binding.eds2, routine.eds2.toString()) initializeEditText(binding.eds3, routine.eds3.toString()) initializeEditText(binding.eds4, routine.eds4.toString()) initializeEditText(binding.eds5, routine.eds5.toString()) binding.spinner.setSelection(getSelectedSpinnerPosition(sharedPrefTitlemon, routine.selectedSpinnerItem)) binding.btnSaveAll.setOnClickListener { //Toast Toast.makeText(this,"์›”์š”์ผ ๋ฃจํ‹ด์ด ์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.",Toast.LENGTH_SHORT).show() val edTitle = binding.edTitle.text.toString() val edCon1 = binding.edContent1.text.toString() val edCon2 = binding.edContent2.text.toString() val edCon3 = binding.edContent3.text.toString() val edCon4 = binding.edContent4.text.toString() val edCon5 = binding.edContent5.text.toString() val edm1 = binding.edm1.text.toString().toIntOrNull() ?: 0 val edm2 = binding.edm2.text.toString().toIntOrNull() ?: 0 val edm3 = binding.edm3.text.toString().toIntOrNull() ?: 0 val edm4 = binding.edm4.text.toString().toIntOrNull() ?: 0 val edm5 = binding.edm5.text.toString().toIntOrNull() ?: 0 val eds1 = binding.eds1.text.toString().toIntOrNull() ?: 0 val eds2 = binding.eds2.text.toString().toIntOrNull() ?: 0 val eds3 = binding.eds3.text.toString().toIntOrNull() ?: 0 val eds4 = binding.eds4.text.toString().toIntOrNull() ?: 0 val eds5 = binding.eds5.text.toString().toIntOrNull() ?: 0 // ์Šคํ”ผ๋„ˆ์—์„œ ์„ ํƒ๋œ ํ•ญ๋ชฉ์˜ ๊ฐ’์„ ๊ฐ€์ ธ์˜ค๊ธฐ val selectedSpinnerItem = binding.spinner.selectedItem.toString() // RoutineData ๊ฐ์ฒด ์—…๋ฐ์ดํŠธ val routine = RoutineData( title = edTitle, selectedSpinnerItem = selectedSpinnerItem, con1 = edCon1, con2 = edCon2, con3 = edCon3, con4 = edCon4, con5 = edCon5, edm1 = edm1.toString(), edm2 = edm2.toString(), edm3 = edm3.toString(), edm4 = edm4.toString(), edm5 = edm5.toString(), eds1 = eds1.toString(), eds2 = eds2.toString(), eds3 = eds3.toString(), eds4 = eds4.toString(), eds5 = eds5.toString() ) // RoutineData ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ๋ฐ์ดํ„ฐ ์ƒ์„ฑ val xmlData = generateXmlData(routine,"Mon") // userEmail์„ ์ด์šฉํ•˜์—ฌ StorageManager๋ฅผ ์ดˆ๊ธฐํ™” val storageManager = StorageManager(this) // StorageManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ํŒŒ์ผ ์—…๋กœ๋“œ storageManager.uploadXmlFile(xmlData,"Mon") // SharedPreferences๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ์ €์žฅ val userUid = FirebaseAuth.getInstance().uid val sharedPrefTitlemon = getSharedPreferences("Routine_Mon$userUid", Context.MODE_PRIVATE) val editor = sharedPrefTitlemon.edit() editor.putString("title", routine.title) editor.putString("selectedSpinnerItem", routine.selectedSpinnerItem) editor.putString("con1", routine.con1) editor.putString("con2", routine.con2) editor.putString("con3", routine.con3) editor.putString("con4", routine.con4) editor.putString("con5", routine.con5) editor.putString("edm1", routine.edm1) editor.putString("edm2", routine.edm2) editor.putString("edm3", routine.edm3) editor.putString("edm4", routine.edm4) editor.putString("edm5", routine.edm5) editor.putString("eds1", routine.eds1) editor.putString("eds2", routine.eds2) editor.putString("eds3", routine.eds3) editor.putString("eds4", routine.eds4) editor.putString("eds5", routine.eds5) editor.apply() // ์ €์žฅ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ด๋ฃจ์–ด์ง€๋ฉด ์•กํ‹ฐ๋น„ํ‹ฐ ์ด๋™ val intent = Intent(this, MyActivity::class.java) startActivity(intent) finish() // ํ˜„์žฌ ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ์ข…๋ฃŒ } binding.btnCancel.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MyActivity::class.java) startActivity(intent) } // ๋ฒ„ํŠผํด๋ฆญ์‹œ ๋งˆ์ด๋ฃจํ‹ด์œผ๋กœ ์ด๋™ binding.btnMypage.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MainActivity::class.java) startActivity(intent) } // ์Šคํ”ผ๋„ˆ ๊ฐ์ฒด ์ƒ์„ฑ spinner = binding.spinner // // ์Šคํ”ผ๋„ˆ ํด๋ฆญ ์‹œ ๋‹ค์ด์–ผ๋กœ๊ทธ ๋„์šฐ๊ธฐ // spinner.setOnTouchListener { _, _ -> // showSearchableSpinnerDialog() // false // } // ์Šคํ”ผ๋„ˆ ํด๋ฆญ ์‹œ ๋‹ค์ด์–ผ๋กœ๊ทธ ๋„์šฐ๊ธฐ spinner.setOnTouchListener { _, _ -> if (dialog == null) { // ๋‹ค์ด์–ผ๋กœ๊ทธ๊ฐ€ ์ดˆ๊ธฐํ™”๋˜์ง€ ์•Š์•˜๋‹ค๋ฉด ์ดˆ๊ธฐํ™” ํ›„ ๋ณด์—ฌ์ฃผ๊ธฐ showSearchableSpinnerDialog() } else if (!dialog!!.isShowing) { // ๋‹ค์ด์–ผ๋กœ๊ทธ๊ฐ€ ์ดˆ๊ธฐํ™”๋˜์–ด ์žˆ๊ณ  ๋ณด์—ฌ์ง€์ง€ ์•Š๋Š” ์ƒํƒœ๋ผ๋ฉด ๋ณด์—ฌ์ฃผ๊ธฐ showSearchableSpinnerDialog() } true } // ์ดˆ๊ธฐํ™” arrayList = arrayListOf( "์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ" ) // ๋“œ๋กญ๋‹ค์šด ๋ฉ”๋‰ด์— ํ‘œ์‹œํ•  ํ•ญ๋ชฉ๋“ค val items = arrayOf("์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ") // ArrayAdapter๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋“œ๋กญ๋‹ค์šด ๋ฉ”๋‰ด์— ํ•ญ๋ชฉ๋“ค์„ ์—ฐ๊ฒฐ val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, items) adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spinner.adapter = adapter val items2 = arrayOf("์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ") // ์ €์žฅ๋œ ๊ฐ’์„ ๋ถˆ๋Ÿฌ์™€์„œ ์Šคํ”ผ๋„ˆ์— ๋Œ€์ž… val savedSpinnerItem = sharedPrefTitlemon.getString("selectedSpinnerItem", "") if (items2.contains(savedSpinnerItem)) { val positionInAdapter = items2.indexOf(savedSpinnerItem) binding.spinner.setSelection(positionInAdapter) } } // ์—…๋กœ๋“œํ•  ํŒŒ์ผ์— ์ €์žฅ๋  ๊ฐ’ ์„ค์ • private fun generateXmlData(routine: RoutineData, dayOfWeek:String): String { val xmlStringBuilder = StringBuilder() xmlStringBuilder.append("<routine>") xmlStringBuilder.append("<title>${routine.title}</title>") xmlStringBuilder.append("<con1>${routine.con1}</con1>") xmlStringBuilder.append("<con2>${routine.con2}</con2>") xmlStringBuilder.append("<con3>${routine.con3}</con3>") xmlStringBuilder.append("<con4>${routine.con4}</con4>") xmlStringBuilder.append("<con5>${routine.con5}</con5>") xmlStringBuilder.append("<edm1>${routine.edm1}</edm1>") xmlStringBuilder.append("<edm2>${routine.edm2}</edm2>") xmlStringBuilder.append("<edm3>${routine.edm3}</edm3>") xmlStringBuilder.append("<edm4>${routine.edm4}</edm4>") xmlStringBuilder.append("<edm5>${routine.edm5}</edm5>") xmlStringBuilder.append("<eds1>${routine.eds1}</eds1>") xmlStringBuilder.append("<eds2>${routine.eds2}</eds2>") xmlStringBuilder.append("<eds3>${routine.eds3}</eds3>") xmlStringBuilder.append("<eds4>${routine.eds4}</eds4>") xmlStringBuilder.append("<eds5>${routine.eds5}</eds5>") xmlStringBuilder.append("<selectedSpinnerItem>${routine.selectedSpinnerItem}</selectedSpinnerItem>") xmlStringBuilder.append("</routine>") return xmlStringBuilder.toString() } private fun initializeEditText(editText: EditText, value: String) { editText.setText(value) } private fun getSelectedSpinnerPosition(sharedPrefs: SharedPreferences, savedValue: String): Int { val items = arrayOf("์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ") return items.indexOf(savedValue).coerceAtLeast(0) } private fun showSearchableSpinnerDialog() { // dialog ์ดˆ๊ธฐํ™” dialog = Dialog(this) // dialog set dialog!!.setContentView(R.layout.dialog_searchable_spinner) dialog!!.window?.setLayout(650, 800) dialog!!.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog!!.show() val editText: EditText = dialog!!.findViewById(R.id.edit_text) val listView: ListView = dialog!!.findViewById(R.id.list_view) val dialogAdapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, arrayList) // ์–ด๋Œ‘ํ„ฐ ์„ค์ • listView.adapter = dialogAdapter editText.addTextChangedListener(object : TextWatcher { override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { dialogAdapter.filter.filter(s) } override fun afterTextChanged(s: Editable?) {} }) listView.setOnItemClickListener { _, _, position, _ -> // ์„ ํƒํ•œ ๊ฐ’์„ ํ”„๋กœํผํ‹ฐ์— ์„ค์ • selectedSpinnerValue = dialogAdapter.getItem(position).toString() val positionInAdapter = arrayList.indexOf(selectedSpinnerValue) // ์Šคํ”ผ๋„ˆ์— ์„ ํƒ๋œ ํ•ญ๋ชฉ ๋Œ€์ž… // val positionInAdapter = dialogAdapter.getPosition(selectedSpinnerValue) if (positionInAdapter != -1) { spinner.setSelection(positionInAdapter) } // ์‚ฌ์šฉ์ž๊ฐ€ ํ•ญ๋ชฉ ์„ ํƒํ•˜๋ฉด ๋‹ค์ด์–ผ๋กœ๊ทธ ๋‹ซ์Œ dialog!!.dismiss() } } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/DetailActivitysun.kt
489716229
package com.example.android_team4_project import android.app.AlertDialog import android.app.Dialog import android.content.Context import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.view.View import android.widget.Button import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.example.android_team4_project.databinding.ActivityDetailBinding import com.google.firebase.auth.FirebaseAuth private lateinit var auth: FirebaseAuth private lateinit var userEmail: String class DetailActivitysun: AppCompatActivity() { private lateinit var binding: ActivityDetailBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityDetailBinding.inflate(layoutInflater) setContentView(binding.root) auth = FirebaseAuth.getInstance() val user = auth.currentUser userEmail = user?.uid ?: "" // ๋ฒ„ํŠผํด๋ฆญ์‹œ ๋งˆ์ด๋ฃจํ‹ด์œผ๋กœ ์ด๋™ binding.btnMypage.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MainActivity::class.java) startActivity(intent) } // ์ˆ˜์ •๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํ•ด๋‹น์š”์ผ ํŒ์—…์—‘ํ‹ฐ๋น„ํ‹ฐ binding.btnSaveAll.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, PopupActivitysun::class.java) startActivity(intent) } // ์‚ญ์ œ๋ฒ„ํŠผ ํด๋ฆญ์‹œ ์ €์žฅ๋‚ด์šฉ ์‚ญ์ œ // binding.btnCancel.setOnClickListener { // showDeleteConfirmationDialog() // } binding.btnCancel.setOnClickListener { val view = View.inflate(this, R.layout.dialog_view, null) val builder = androidx.appcompat.app.AlertDialog.Builder(this) builder.setView(view) val dialog = builder.create() dialog.setCanceledOnTouchOutside(false) dialog.show() val btnConfirm = view.findViewById<Button>(R.id.btn_confirm) val btnCancel = view.findViewById<Button>(R.id.btn_cancel) btnConfirm.setOnClickListener { showDeleteConfirmationDialog() Toast.makeText(this@DetailActivitysun, "์‚ญ์ œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค", Toast.LENGTH_SHORT).show() dialog.dismiss() } btnCancel.setOnClickListener { dialog.dismiss() } dialog.window?.setBackgroundDrawable(ColorDrawable(Color.WHITE)) } // SharedPreferences์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPrefTitlesun = getSharedPreferences("Routine_Sun$userEmail", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitlesun = sharedPrefTitlesun.getString("title", "") val savedSpinnersun = sharedPrefTitlesun.getString("selectedSpinnerItem", "") val savedcon1sun = sharedPrefTitlesun.getString("con1", "") val savedcon2sun = sharedPrefTitlesun.getString("con2", "") val savedcon3sun = sharedPrefTitlesun.getString("con3", "") val savedcon4sun = sharedPrefTitlesun.getString("con4", "") val savedcon5sun = sharedPrefTitlesun.getString("con5", "") val savededm1sun = sharedPrefTitlesun.getString("edm1", "") val savededm2sun = sharedPrefTitlesun.getString("edm2", "") val savededm3sun = sharedPrefTitlesun.getString("edm3", "") val savededm4sun = sharedPrefTitlesun.getString("edm4", "") val savededm5sun = sharedPrefTitlesun.getString("edm5", "") val savededs1sun = sharedPrefTitlesun.getString("eds1", "") val savededs2sun = sharedPrefTitlesun.getString("eds2", "") val savededs3sun = sharedPrefTitlesun.getString("eds3", "") val savededs4sun = sharedPrefTitlesun.getString("eds4", "") val savededs5sun = sharedPrefTitlesun.getString("eds5", "") // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • binding.edTitle.text = savedTitlesun binding.spinner.text = savedSpinnersun binding.edContent1.text = savedcon1sun binding.edContent2.text = savedcon2sun binding.edContent3.text = savedcon3sun binding.edContent4.text = savedcon4sun binding.edContent5.text = savedcon5sun binding.edm1.text = savededm1sun binding.edm2.text = savededm2sun binding.edm3.text = savededm3sun binding.edm4.text = savededm4sun binding.edm5.text = savededm5sun binding.eds1.text = savededs1sun binding.eds2.text = savededs2sun binding.eds3.text = savededs3sun binding.eds4.text = savededs4sun binding.eds5.text = savededs5sun } private fun showDeleteConfirmationDialog() { val builder = AlertDialog.Builder(this) builder.setTitle("์ฃผ์˜") builder.setMessage("์‚ญ์ œํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?") builder.setPositiveButton("์‚ญ์ œ") { _, _ -> // ์‚ฌ์šฉ์ž๊ฐ€ ์‚ญ์ œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ–ˆ์„ ๋•Œ auth = FirebaseAuth.getInstance() val user = auth.currentUser userEmail = user?.uid ?: "" // RoutineData ๊ฐ์ฒด ์—…๋ฐ์ดํŠธ val routine = RoutineData( title = "", selectedSpinnerItem = "", con1 = "", con2 = "", con3 = "", con4 = "", con5 = "", edm1 = "", edm2 = "", edm3 = "", edm4 = "", edm5 = "", eds1 = "", eds2 = "", eds3 = "", eds4 = "", eds5 = "" ) // RoutineData ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ๋ฐ์ดํ„ฐ ์ƒ์„ฑ val xmlData = generateXmlData(routine, "Sun") // userEmail์„ ์ด์šฉํ•˜์—ฌ StorageManager๋ฅผ ์ดˆ๊ธฐํ™” val storageManager = StorageManager(this) // StorageManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ํŒŒ์ผ ์—…๋กœ๋“œ storageManager.uploadXmlFile(xmlData, "Sun") // SharedPreferences๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ์ €์žฅ val userUid = FirebaseAuth.getInstance().uid val sharedPrefTitlesun = getSharedPreferences("Routine_Sun$userUid", Context.MODE_PRIVATE) val editor = sharedPrefTitlesun.edit() editor.putString("title", routine.title) editor.putString("selectedSpinnerItem", routine.selectedSpinnerItem) editor.putString("con1", routine.con1) editor.putString("con2", routine.con2) editor.putString("con3", routine.con3) editor.putString("con4", routine.con4) editor.putString("con5", routine.con5) editor.putString("edm1", routine.edm1) editor.putString("edm2", routine.edm2) editor.putString("edm3", routine.edm3) editor.putString("edm4", routine.edm4) editor.putString("edm5", routine.edm5) editor.putString("eds1", routine.eds1) editor.putString("eds2", routine.eds2) editor.putString("eds3", routine.eds3) editor.putString("eds4", routine.eds4) editor.putString("eds5", routine.eds5) editor.apply() // ์ €์žฅ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ด๋ฃจ์–ด์ง€๋ฉด ์•กํ‹ฐ๋น„ํ‹ฐ ์ด๋™ val intent = Intent(this, MyActivity::class.java) startActivity(intent) finish() // ํ˜„์žฌ ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ์ข…๋ฃŒ } builder.setNegativeButton("์ทจ์†Œ") { dialog, _ -> // ์‚ฌ์šฉ์ž๊ฐ€ ์ทจ์†Œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ–ˆ์„ ๋•Œ dialog.dismiss() } val dialog: AlertDialog = builder.create() dialog.show() } private fun generateXmlData(routine: RoutineData, dayOfWeek:String): String { val xmlStringBuilder = StringBuilder() xmlStringBuilder.append("<routine>") xmlStringBuilder.append("<title>${routine.title}</title>") xmlStringBuilder.append("<con1>${routine.con1}</con1>") xmlStringBuilder.append("<con2>${routine.con2}</con2>") xmlStringBuilder.append("<con3>${routine.con3}</con3>") xmlStringBuilder.append("<con4>${routine.con4}</con4>") xmlStringBuilder.append("<con5>${routine.con5}</con5>") xmlStringBuilder.append("<edm1>${routine.edm1}</edm1>") xmlStringBuilder.append("<edm2>${routine.edm2}</edm2>") xmlStringBuilder.append("<edm3>${routine.edm3}</edm3>") xmlStringBuilder.append("<edm4>${routine.edm4}</edm4>") xmlStringBuilder.append("<edm5>${routine.edm5}</edm5>") xmlStringBuilder.append("<eds1>${routine.eds1}</eds1>") xmlStringBuilder.append("<eds2>${routine.eds2}</eds2>") xmlStringBuilder.append("<eds3>${routine.eds3}</eds3>") xmlStringBuilder.append("<eds4>${routine.eds4}</eds4>") xmlStringBuilder.append("<eds5>${routine.eds5}</eds5>") xmlStringBuilder.append("<selectedSpinnerItem>${routine.selectedSpinnerItem}</selectedSpinnerItem>") xmlStringBuilder.append("</routine>") return xmlStringBuilder.toString() } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/CountDownActivity.kt
454382540
package com.example.android_team4_project import android.app.NotificationChannel import android.app.NotificationManager import android.app.PendingIntent import android.content.Context import android.content.Intent import android.graphics.Color import android.media.AudioAttributes import android.media.RingtoneManager import android.net.Uri import android.os.Build import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.os.CountDownTimer import android.view.View import android.view.inputmethod.InputMethodManager import android.widget.EditText import androidx.core.app.NotificationCompat import com.example.android_team4_project.databinding.ActivityCountDownBinding class CountDownActivity : AppCompatActivity() { lateinit var countDownTimer: CountDownTimer lateinit var binding: ActivityCountDownBinding var timeRunning = false //ํƒ€์ด๋จธ ์‹คํ–‰ ์ƒํƒœ var firstState = false //ํƒ€์ด๋จธ ์‹คํ–‰ ์ฒ˜์Œ์ธ์ง€ ์•„๋‹Œ์ง€ var time = 0L //ํƒ€์ด๋จธ ์‹œ๊ฐ„ var tempTime = 0L //ํƒ€์ด๋จธ ์ž„์‹œ ์‹œ๊ฐ„ override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityCountDownBinding.inflate(layoutInflater) setContentView(binding.root) //์‹œ์ž‘๋ฒ„ํŠผ binding.btnStartCount.setOnClickListener { viewMode("start") startStop() } //์ •์ง€๋ฒ„ํŠผ binding.btnStopCount.setOnClickListener { startStop() } //์ทจ์†Œ๋ฒ„ํŠผ binding.btnCancelCount.setOnClickListener { viewMode("cancel") startStop() } //์•Œ๋žŒ ์‚ญ์ œ cancelNotification() } private fun viewMode(mode: String) { // ์ƒํƒœ : ์ฒ˜์Œ firstState = true if (mode == "start") { //ํƒ€์ด๋จธ ๋ชจ๋“œ binding.settingLayout.visibility = View.GONE //์‚ฌ๋ผ์ง binding.timerLayout.visibility = View.VISIBLE //๋ณด์—ฌ์ง } else {//์„ค์ •๋ชจ๋“œ binding.settingLayout.visibility = View.VISIBLE //์‚ฌ๋ผ์ง binding.timerLayout.visibility = View.GONE //๋ณด์—ฌ์ง } } //ํƒ€์ด๋จธ ์‹คํ–‰ ์ƒํƒœ์— ๋”ฐ๋ฅธ ์‹œ์ž‘ & ์ •์ง€ private fun startStop() { if (timeRunning) { //์‹คํ–‰ ์ค‘์ด๋ฉด ์ •์ง€ stopTimer() } else { //์ •์ง€๋ฉด ์‹คํ–‰ startTimer() } } // ํƒ€์ด๋จธ ์‹คํ–‰ private fun startTimer() { // ์ฒ˜์Œ ์‹คํ–‰์ด๋ฉด ์ž…๋ ฅ๊ฐ’์„ ํƒ€์ด๋จธ ์„ค์ •๊ฐ’์œผ๋กœ ์‚ฌ์šฉ if (firstState) { val sHour = binding.hourEdit.text.toString() val sMin = binding.minEdit.text.toString() val sSec = binding.secEdit.text.toString() time = (sHour.toLong()) * 3600000 + (sMin.toLong() * 60000) + (sSec.toLong() * 1000) + 1000 } else { // ์ •์ง€ ํ›„ ์ด์–ด์„œ ์‹œ์ž‘์ด๋ฉด ๊ธฐ์กด ๊ฐ’ ์‚ฌ์šฉํ•˜๊ธฐ time = tempTime } // ํƒ€์ด๋จธ ์‹คํ–‰ countDownTimer = object : CountDownTimer(time, 1000) { override fun onTick(millisUntilFinished: Long) { tempTime = millisUntilFinished //ํƒ€์ด๋จธ ์—…๋ฐ์ดํŠธ updateTime() } override fun onFinish() { notiAlarm() // //๋๋‚˜๋ฉด ์†Œ๋ฆฌ์•Œ๋ฆผ // val notification: Uri = // RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) // val ringtone = RingtoneManager.getRingtone(this@CountDownActivity, notification) // ringtone.play() } }.start() //์ •์ง€ ๋ฒ„ํŠผ ํ…์ŠคํŠธ binding.btnStopCount.text = "์ผ์‹œ ์ •์ง€" //ํƒ€์ด๋จธ ์ƒํƒœ : ์‹คํ–‰ timeRunning = true //์ฒ˜์Œ์•„๋‹˜ firstState = false } private fun notiAlarm() { // getSystemService(์„œ๋น„์Šค) : ์•ˆ๋“œ๋กœ์ด๋“œ ์‹œ์Šคํ…œ์—์„œ ๋™์ž‘ํ•˜๊ณ  ์žˆ๋Š” ์„œ๋น„์Šค ์ค‘ ์ง€์ •ํ•œ ์„œ๋น„์Šค๋ฅผ ๊ฐ€์ ธ์˜ด // getSystemService() ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ NotificationManager ํƒ€์ž…์˜ ๊ฐ์ฒด ๊ฐ€์ ธ์˜ค๊ธฐ val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager // NotificationCompat ํƒ€์ž…์˜ ๊ฐ์ฒด๋ฅผ ์ €์žฅํ•  ๋ณ€์ˆ˜ ์„ ์–ธ val builder: NotificationCompat.Builder // API 26๋ถ€ํ„ฐ ์ฑ„๋„์ด ์ถ”๊ฐ€ ๋˜์–ด ๋ฒ„์ „์— ๋”ฐ๋ผ ์‚ฌ์šฉ ๋ฐฉ์‹์„ ๋ณ€๊ฒฝ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val channelId = "one-channel" val channelName = "My Channel One" // ์ฑ„๋„ ๊ฐ์ฒด ์ƒ์„ฑ val channel = NotificationChannel( channelId, channelName, // ์•Œ๋ฆผ ๋“ฑ๊ธ‰ ์„ค์ • NotificationManager.IMPORTANCE_DEFAULT ) channel.description = "My Channel One description" channel.setShowBadge(true) // ์•Œ๋ฆผ ๋™์ž‘ ์‹œ ์‚ฌ์šฉํ•  ์Œ์› ์ง€์ • // ์•ˆ๋“œ๋กœ์ด๋“œ ๊ธฐ๋ณธ ์•Œ๋ฆผ ์Œ์› ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ val uri: Uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) val audioAttributes = AudioAttributes.Builder() .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .setUsage(AudioAttributes.USAGE_ALARM) .build() // ์•Œ๋ฆผ ์ฑ„๋„์— ์‚ฌ์šฉํ•  ์Œ์› ์„ค์ • channel.setSound(uri, audioAttributes) // ์•Œ๋ฆผ ์‹œ ๋ผ์ดํŠธ ์‚ฌ์šฉ channel.enableLights(true) channel.lightColor = Color.RED // ์•Œ๋ฆผ ์‹œ ์ง„๋™ ์‚ฌ์šฉ channel.enableVibration(true) channel.vibrationPattern = longArrayOf(100, 200, 100, 200) // ์ง€์ •ํ•œ ์ฑ„๋„ ์ •๋ณด๋ฅผ ํ†ตํ•ด์„œ ์ฑ„๋„ ์ƒ์„ฑ manager.createNotificationChannel(channel) // NotificationCompat ํƒ€์ž…์˜ ๊ฐ์ฒด ์ƒ์„ฑ builder = NotificationCompat.Builder(this, channelId) } else { builder = NotificationCompat.Builder(this) } // ์Šคํ…Œ์ด์Šคํ„ฐ์ฐฝ ์•Œ๋ฆผ ํ™”๋ฉด ์„ค์ • builder.setSmallIcon(android.R.drawable.ic_notification_overlay) builder.setWhen(System.currentTimeMillis()) builder.setContentTitle("์•Œ๋ฆผ") builder.setContentText("ํƒ€์ด๋จธ ์ข…๋ฃŒ") // ํ™”๋ฉด ์ „ํ™˜์„ ์œ„ํ•œ Intent๋ฅผ ์ €์žฅํ•  ๋ฆฌ์ŠคํŠธ ๋ณ€์ˆ˜ ์ƒ์„ฑ val mainIntent = Intent(this, CountDownActivity::class.java) // PendingIntent๋ฅผ ํ†ตํ•ด์„œ ์•ˆ๋“œ๋กœ์ด๋“œ ์‹œ์Šคํ…œ์— ์ด๋ฒคํŠธ ์š”์ฒญ ์ฒ˜๋ฆฌ ๋“ฑ๋ก // getActivity()๋ฅผ ํ†ตํ•ด์„œ ์ง€์ •ํ•œ ์•ฑ์˜ ํ™”๋ฉด์œผ๋กœ ์ „ํ™˜ ์š”์ฒญ var eventPendingIntent = PendingIntent.getActivity(this, 30, mainIntent, PendingIntent.FLAG_MUTABLE) // ์•Œ๋ฆผ์˜ setContentIntent()๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ PendingIntent ์ถ”๊ฐ€ํ•˜๊ณ  ์ง€์ •ํ•œ ์ด๋ฒคํŠธ๊ฐ€ ๋™์ž‘ํ•˜๋„๋ก ํ•จ // builder.setContentIntent(eventPendingIntent) // ์•Œ๋ฆผ์—๋Š” ์•ก์…˜ ๋ฒ„ํŠผ์„ 3๊ฐœ๊นŒ์ง€ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Œ // ์•Œ๋ฆผ์— ์•ก์…˜์„ ์ถ”๊ฐ€ builder.addAction( // ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ์•„์ด์ฝ˜, ์•ก์…˜๋ฒ„ํŠผ ์ œ๋ชฉ, PendingIntent ๊ฐ์ฒด ์ˆœ์„œ NotificationCompat.Action.Builder( android.R.drawable.stat_notify_more, "ํ™•์ธ", eventPendingIntent ).build() ) // NotificationManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์Šคํ…Œ์ดํ„ฐ์Šค์ฐฝ์— ์•Œ๋ฆผ์ฐฝ ์ถœ๋ ฅ manager.notify(11, builder.build()) } // Notification ์‚ญ์ œ private fun cancelNotification() { // NotificationManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์•Œ๋ฆผ์„ ์‚ญ์ œ val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager manager.cancel(11) // ์•Œ๋ฆผ ID๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์•Œ๋ฆผ ์ทจ์†Œ } // ํƒ€์ด๋จธ ์ •์ง€ private fun stopTimer() { //ํƒ€์ด๋จธ ์ทจ์†Œ countDownTimer.cancel() //ํƒ€์ด๋จธ ์ƒํƒœ : ์ •์ง€ timeRunning = false //์ •์ง€๋ฒ„ํŠผ ํ…์ŠคํŠธ binding.btnStopCount.text = "๊ณ„์†" } // ํƒ€์ด๋จธ ์—…๋ฐ์ดํŠธ private fun updateTime() { val hour = tempTime / 3600000 val min = tempTime % 3600000 / 60000 val sec = tempTime % 3600000 % 60000 / 1000 //์‹œ๊ฐ„ ์ถ”๊ฐ€ var timeLeftText = "$hour : " //๋ถ„์ด 10๋ณด๋‹ค ์ž‘์œผ๋ฉด 0๋ถ™์ด๊ธฐ if (min < 10) timeLeftText += "0" //๋ถ„ ์ถ”๊ฐ€ timeLeftText += "$min : " //์ดˆ๊ฐ€ 10๋ณด๋‹ค ์ž‘์œผ๋ฉด 0๋ถ™์ž„ if (sec < 10) timeLeftText += "0" //์ดˆ ์ถ”๊ฐ€ timeLeftText += "$sec" //ํƒ€์ด๋จธ ํ…์ŠคํŠธ ๋ณด์—ฌ์ฃผ๊ธฐ binding.timerText.text = timeLeftText } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/DetailActivitywed.kt
3401914704
package com.example.android_team4_project import android.app.AlertDialog import android.app.Dialog import android.content.Context import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.view.View import android.widget.Button import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.example.android_team4_project.databinding.ActivityDetailBinding import com.google.firebase.auth.FirebaseAuth private lateinit var auth: FirebaseAuth private lateinit var userEmail: String class DetailActivitywed: AppCompatActivity() { private lateinit var binding: ActivityDetailBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityDetailBinding.inflate(layoutInflater) setContentView(binding.root) auth = FirebaseAuth.getInstance() val user = auth.currentUser userEmail = user?.uid ?: "" // ๋ฒ„ํŠผํด๋ฆญ์‹œ ๋งˆ์ด๋ฃจํ‹ด์œผ๋กœ ์ด๋™ binding.btnMypage.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MainActivity::class.java) startActivity(intent) } // ์ˆ˜์ •๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํ•ด๋‹น์š”์ผ ํŒ์—…์—‘ํ‹ฐ๋น„ํ‹ฐ binding.btnSaveAll.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, PopupActivitywed::class.java) startActivity(intent) } // ์‚ญ์ œ๋ฒ„ํŠผ ํด๋ฆญ์‹œ ์ €์žฅ๋‚ด์šฉ ์‚ญ์ œ // binding.btnCancel.setOnClickListener { // showDeleteConfirmationDialog() // } binding.btnCancel.setOnClickListener { val view = View.inflate(this, R.layout.dialog_view, null) val builder = androidx.appcompat.app.AlertDialog.Builder(this) builder.setView(view) val dialog = builder.create() dialog.setCanceledOnTouchOutside(false) dialog.show() val btnConfirm = view.findViewById<Button>(R.id.btn_confirm) val btnCancel = view.findViewById<Button>(R.id.btn_cancel) btnConfirm.setOnClickListener { showDeleteConfirmationDialog() Toast.makeText(this@DetailActivitywed, "์‚ญ์ œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค", Toast.LENGTH_SHORT).show() dialog.dismiss() } btnCancel.setOnClickListener { dialog.dismiss() } dialog.window?.setBackgroundDrawable(ColorDrawable(Color.WHITE)) } // SharedPreferences์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPrefTitlewed = getSharedPreferences("Routine_Wed$userEmail", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitlewed = sharedPrefTitlewed.getString("title", "") val savedSpinnerwed = sharedPrefTitlewed.getString("selectedSpinnerItem", "") val savedcon1wed = sharedPrefTitlewed.getString("con1", "") val savedcon2wed = sharedPrefTitlewed.getString("con2", "") val savedcon3wed = sharedPrefTitlewed.getString("con3", "") val savedcon4wed = sharedPrefTitlewed.getString("con4", "") val savedcon5wed = sharedPrefTitlewed.getString("con5", "") val savededm1wed = sharedPrefTitlewed.getString("edm1", "") val savededm2wed = sharedPrefTitlewed.getString("edm2", "") val savededm3wed = sharedPrefTitlewed.getString("edm3", "") val savededm4wed = sharedPrefTitlewed.getString("edm4", "") val savededm5wed = sharedPrefTitlewed.getString("edm5", "") val savededs1wed = sharedPrefTitlewed.getString("eds1", "") val savededs2wed = sharedPrefTitlewed.getString("eds2", "") val savededs3wed = sharedPrefTitlewed.getString("eds3", "") val savededs4wed = sharedPrefTitlewed.getString("eds4", "") val savededs5wed = sharedPrefTitlewed.getString("eds5", "") // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • binding.edTitle.text = savedTitlewed binding.spinner.text = savedSpinnerwed binding.edContent1.text = savedcon1wed binding.edContent2.text = savedcon2wed binding.edContent3.text = savedcon3wed binding.edContent4.text = savedcon4wed binding.edContent5.text = savedcon5wed binding.edm1.text = savededm1wed binding.edm2.text = savededm2wed binding.edm3.text = savededm3wed binding.edm4.text = savededm4wed binding.edm5.text = savededm5wed binding.eds1.text = savededs1wed binding.eds2.text = savededs2wed binding.eds3.text = savededs3wed binding.eds4.text = savededs4wed binding.eds5.text = savededs5wed } private fun showDeleteConfirmationDialog() { val builder = AlertDialog.Builder(this) builder.setTitle("์ฃผ์˜") builder.setMessage("์‚ญ์ œํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?") builder.setPositiveButton("์‚ญ์ œ") { _, _ -> // ์‚ฌ์šฉ์ž๊ฐ€ ์‚ญ์ œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ–ˆ์„ ๋•Œ auth = FirebaseAuth.getInstance() val user = auth.currentUser userEmail = user?.uid ?: "" // RoutineData ๊ฐ์ฒด ์—…๋ฐ์ดํŠธ val routine = RoutineData( title = "", selectedSpinnerItem = "", con1 = "", con2 = "", con3 = "", con4 = "", con5 = "", edm1 = "", edm2 = "", edm3 = "", edm4 = "", edm5 = "", eds1 = "", eds2 = "", eds3 = "", eds4 = "", eds5 = "" ) // RoutineData ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ๋ฐ์ดํ„ฐ ์ƒ์„ฑ val xmlData = generateXmlData(routine, "Wed") // userEmail์„ ์ด์šฉํ•˜์—ฌ StorageManager๋ฅผ ์ดˆ๊ธฐํ™” val storageManager = StorageManager(this) // StorageManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ํŒŒ์ผ ์—…๋กœ๋“œ storageManager.uploadXmlFile(xmlData, "Wed") // SharedPreferences๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ์ €์žฅ val userUid = FirebaseAuth.getInstance().uid val sharedPrefTitlewed = getSharedPreferences("Routine_Wed$userUid", Context.MODE_PRIVATE) val editor = sharedPrefTitlewed.edit() editor.putString("title", routine.title) editor.putString("selectedSpinnerItem", routine.selectedSpinnerItem) editor.putString("con1", routine.con1) editor.putString("con2", routine.con2) editor.putString("con3", routine.con3) editor.putString("con4", routine.con4) editor.putString("con5", routine.con5) editor.putString("edm1", routine.edm1) editor.putString("edm2", routine.edm2) editor.putString("edm3", routine.edm3) editor.putString("edm4", routine.edm4) editor.putString("edm5", routine.edm5) editor.putString("eds1", routine.eds1) editor.putString("eds2", routine.eds2) editor.putString("eds3", routine.eds3) editor.putString("eds4", routine.eds4) editor.putString("eds5", routine.eds5) editor.apply() // ์ €์žฅ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ด๋ฃจ์–ด์ง€๋ฉด ์•กํ‹ฐ๋น„ํ‹ฐ ์ด๋™ val intent = Intent(this, MyActivity::class.java) startActivity(intent) finish() // ํ˜„์žฌ ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ์ข…๋ฃŒ } builder.setNegativeButton("์ทจ์†Œ") { dialog, _ -> // ์‚ฌ์šฉ์ž๊ฐ€ ์ทจ์†Œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ–ˆ์„ ๋•Œ dialog.dismiss() } val dialog: AlertDialog = builder.create() dialog.show() } private fun generateXmlData(routine: RoutineData, dayOfWeek:String): String { val xmlStringBuilder = StringBuilder() xmlStringBuilder.append("<routine>") xmlStringBuilder.append("<title>${routine.title}</title>") xmlStringBuilder.append("<con1>${routine.con1}</con1>") xmlStringBuilder.append("<con2>${routine.con2}</con2>") xmlStringBuilder.append("<con3>${routine.con3}</con3>") xmlStringBuilder.append("<con4>${routine.con4}</con4>") xmlStringBuilder.append("<con5>${routine.con5}</con5>") xmlStringBuilder.append("<edm1>${routine.edm1}</edm1>") xmlStringBuilder.append("<edm2>${routine.edm2}</edm2>") xmlStringBuilder.append("<edm3>${routine.edm3}</edm3>") xmlStringBuilder.append("<edm4>${routine.edm4}</edm4>") xmlStringBuilder.append("<edm5>${routine.edm5}</edm5>") xmlStringBuilder.append("<eds1>${routine.eds1}</eds1>") xmlStringBuilder.append("<eds2>${routine.eds2}</eds2>") xmlStringBuilder.append("<eds3>${routine.eds3}</eds3>") xmlStringBuilder.append("<eds4>${routine.eds4}</eds4>") xmlStringBuilder.append("<eds5>${routine.eds5}</eds5>") xmlStringBuilder.append("<selectedSpinnerItem>${routine.selectedSpinnerItem}</selectedSpinnerItem>") xmlStringBuilder.append("</routine>") return xmlStringBuilder.toString() } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/PopupActivitythu.kt
3789211977
package com.example.android_team4_project import android.app.Dialog import android.content.Context import android.content.Intent import android.content.SharedPreferences import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.text.Editable import android.text.TextWatcher import android.widget.ArrayAdapter import android.widget.EditText import android.widget.ListView import android.widget.Spinner import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.example.android_team4_project.databinding.ActivityPopupBinding import com.google.firebase.auth.FirebaseAuth class PopupActivitythu : AppCompatActivity() { private lateinit var binding: ActivityPopupBinding private lateinit var userEmail: String private lateinit var arrayList: ArrayList<String> private lateinit var dialog: Dialog private lateinit var spinner: Spinner private lateinit var selectedSpinnerValue: String private lateinit var auth: FirebaseAuth override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityPopupBinding.inflate(layoutInflater) setContentView(binding.root) auth = FirebaseAuth.getInstance() val user = auth.currentUser userEmail = user?.uid ?: "" dialog = Dialog(this) val sharedPrefTitlethu = getSharedPreferences("Routine_Thu$userEmail", Context.MODE_PRIVATE) val routine = RoutineData( title = sharedPrefTitlethu.getString("title", "") ?: "", selectedSpinnerItem = sharedPrefTitlethu.getString("selectedSpinnerItem", "") ?: "", con1 = sharedPrefTitlethu.getString("con1", "") ?: "", con2 = sharedPrefTitlethu.getString("con2", "") ?: "", con3 = sharedPrefTitlethu.getString("con3", "") ?: "", con4 = sharedPrefTitlethu.getString("con4", "") ?: "", con5 = sharedPrefTitlethu.getString("con5", "") ?: "", edm1 = sharedPrefTitlethu.getString("edm1", "") ?: "", edm2 = sharedPrefTitlethu.getString("edm2", "") ?: "", edm3 = sharedPrefTitlethu.getString("edm3", "") ?: "", edm4 = sharedPrefTitlethu.getString("edm4", "") ?: "", edm5 = sharedPrefTitlethu.getString("edm5", "") ?: "", eds1 = sharedPrefTitlethu.getString("eds1", "") ?: "", eds2 = sharedPrefTitlethu.getString("eds2", "") ?: "", eds3 = sharedPrefTitlethu.getString("eds3", "") ?: "", eds4 = sharedPrefTitlethu.getString("eds4", "") ?: "", eds5 = sharedPrefTitlethu.getString("eds5", "") ?: "" ) initializeEditText(binding.edTitle, routine.title) routine.con1?.let { initializeEditText(binding.edContent1, it) } routine.con2?.let { initializeEditText(binding.edContent2, it) } routine.con3?.let { initializeEditText(binding.edContent3, it) } routine.con4?.let { initializeEditText(binding.edContent4, it) } routine.con5?.let { initializeEditText(binding.edContent5, it) } initializeEditText(binding.edm1, routine.edm1.toString()) initializeEditText(binding.edm2, routine.edm2.toString()) initializeEditText(binding.edm3, routine.edm3.toString()) initializeEditText(binding.edm4, routine.edm4.toString()) initializeEditText(binding.edm5, routine.edm5.toString()) initializeEditText(binding.eds1, routine.eds1.toString()) initializeEditText(binding.eds2, routine.eds2.toString()) initializeEditText(binding.eds3, routine.eds3.toString()) initializeEditText(binding.eds4, routine.eds4.toString()) initializeEditText(binding.eds5, routine.eds5.toString()) binding.spinner.setSelection(getSelectedSpinnerPosition(sharedPrefTitlethu, routine.selectedSpinnerItem)) binding.btnSaveAll.setOnClickListener { //Toast Toast.makeText(this,"๋ชฉ์š”์ผ ๋ฃจํ‹ด์ด ์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.",Toast.LENGTH_SHORT).show() val edTitle = binding.edTitle.text.toString() val edCon1 = binding.edContent1.text.toString() val edCon2 = binding.edContent2.text.toString() val edCon3 = binding.edContent3.text.toString() val edCon4 = binding.edContent4.text.toString() val edCon5 = binding.edContent5.text.toString() val edm1 = binding.edm1.text.toString().toIntOrNull() ?: 0 val edm2 = binding.edm2.text.toString().toIntOrNull() ?: 0 val edm3 = binding.edm3.text.toString().toIntOrNull() ?: 0 val edm4 = binding.edm4.text.toString().toIntOrNull() ?: 0 val edm5 = binding.edm5.text.toString().toIntOrNull() ?: 0 val eds1 = binding.eds1.text.toString().toIntOrNull() ?: 0 val eds2 = binding.eds2.text.toString().toIntOrNull() ?: 0 val eds3 = binding.eds3.text.toString().toIntOrNull() ?: 0 val eds4 = binding.eds4.text.toString().toIntOrNull() ?: 0 val eds5 = binding.eds5.text.toString().toIntOrNull() ?: 0 // ์Šคํ”ผ๋„ˆ์—์„œ ์„ ํƒ๋œ ํ•ญ๋ชฉ์˜ ๊ฐ’์„ ๊ฐ€์ ธ์˜ค๊ธฐ val selectedSpinnerItem = binding.spinner.selectedItem.toString() // RoutineData ๊ฐ์ฒด ์—…๋ฐ์ดํŠธ val routine = RoutineData( title = edTitle, selectedSpinnerItem = selectedSpinnerItem, con1 = edCon1, con2 = edCon2, con3 = edCon3, con4 = edCon4, con5 = edCon5, edm1 = edm1.toString(), edm2 = edm2.toString(), edm3 = edm3.toString(), edm4 = edm4.toString(), edm5 = edm5.toString(), eds1 = eds1.toString(), eds2 = eds2.toString(), eds3 = eds3.toString(), eds4 = eds4.toString(), eds5 = eds5.toString() ) // RoutineData ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ๋ฐ์ดํ„ฐ ์ƒ์„ฑ val xmlData = generateXmlData(routine,"Thu") // userEmail์„ ์ด์šฉํ•˜์—ฌ StorageManager๋ฅผ ์ดˆ๊ธฐํ™” val storageManager = StorageManager(this) // StorageManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ํŒŒ์ผ ์—…๋กœ๋“œ storageManager.uploadXmlFile(xmlData,"Thu") // SharedPreferences๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ์ €์žฅ val userUid = FirebaseAuth.getInstance().uid val sharedPrefTitlethu = getSharedPreferences("Routine_Thu$userUid", Context.MODE_PRIVATE) val editor = sharedPrefTitlethu.edit() editor.putString("title", routine.title) editor.putString("selectedSpinnerItem", routine.selectedSpinnerItem) editor.putString("con1", routine.con1) editor.putString("con2", routine.con2) editor.putString("con3", routine.con3) editor.putString("con4", routine.con4) editor.putString("con5", routine.con5) editor.putString("edm1", routine.edm1) editor.putString("edm2", routine.edm2) editor.putString("edm3", routine.edm3) editor.putString("edm4", routine.edm4) editor.putString("edm5", routine.edm5) editor.putString("eds1", routine.eds1) editor.putString("eds2", routine.eds2) editor.putString("eds3", routine.eds3) editor.putString("eds4", routine.eds4) editor.putString("eds5", routine.eds5) editor.apply() // ์ €์žฅ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ด๋ฃจ์–ด์ง€๋ฉด ์•กํ‹ฐ๋น„ํ‹ฐ ์ด๋™ val intent = Intent(this, MyActivity::class.java) startActivity(intent) finish() // ํ˜„์žฌ ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ์ข…๋ฃŒ } binding.btnCancel.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MyActivity::class.java) startActivity(intent) } // ๋ฒ„ํŠผํด๋ฆญ์‹œ ๋งˆ์ด๋ฃจํ‹ด์œผ๋กœ ์ด๋™ binding.btnMypage.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MainActivity::class.java) startActivity(intent) } // ์Šคํ”ผ๋„ˆ ๊ฐ์ฒด ์ƒ์„ฑ spinner = binding.spinner // // ์Šคํ”ผ๋„ˆ ํด๋ฆญ ์‹œ ๋‹ค์ด์–ผ๋กœ๊ทธ ๋„์šฐ๊ธฐ // spinner.setOnTouchListener { _, _ -> // showSearchableSpinnerDialog() // false // } // ์Šคํ”ผ๋„ˆ ํด๋ฆญ ์‹œ ๋‹ค์ด์–ผ๋กœ๊ทธ ๋„์šฐ๊ธฐ spinner.setOnTouchListener { _, _ -> if (dialog == null) { // ๋‹ค์ด์–ผ๋กœ๊ทธ๊ฐ€ ์ดˆ๊ธฐํ™”๋˜์ง€ ์•Š์•˜๋‹ค๋ฉด ์ดˆ๊ธฐํ™” ํ›„ ๋ณด์—ฌ์ฃผ๊ธฐ showSearchableSpinnerDialog() } else if (!dialog!!.isShowing) { // ๋‹ค์ด์–ผ๋กœ๊ทธ๊ฐ€ ์ดˆ๊ธฐํ™”๋˜์–ด ์žˆ๊ณ  ๋ณด์—ฌ์ง€์ง€ ์•Š๋Š” ์ƒํƒœ๋ผ๋ฉด ๋ณด์—ฌ์ฃผ๊ธฐ showSearchableSpinnerDialog() } true } // ์ดˆ๊ธฐํ™” arrayList = arrayListOf( "์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ" ) // ๋“œ๋กญ๋‹ค์šด ๋ฉ”๋‰ด์— ํ‘œ์‹œํ•  ํ•ญ๋ชฉ๋“ค val items = arrayOf("์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ") // ArrayAdapter๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋“œ๋กญ๋‹ค์šด ๋ฉ”๋‰ด์— ํ•ญ๋ชฉ๋“ค์„ ์—ฐ๊ฒฐ val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, items) adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spinner.adapter = adapter val items2 = arrayOf("์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ") // ์ €์žฅ๋œ ๊ฐ’์„ ๋ถˆ๋Ÿฌ์™€์„œ ์Šคํ”ผ๋„ˆ์— ๋Œ€์ž… val savedSpinnerItem = sharedPrefTitlethu.getString("selectedSpinnerItem", "") if (items2.contains(savedSpinnerItem)) { val positionInAdapter = items2.indexOf(savedSpinnerItem) binding.spinner.setSelection(positionInAdapter) } } // ์—…๋กœ๋“œํ•  ํŒŒ์ผ์— ์ €์žฅ๋  ๊ฐ’ ์„ค์ • private fun generateXmlData(routine: RoutineData, dayOfWeek:String): String { val xmlStringBuilder = StringBuilder() xmlStringBuilder.append("<routine>") xmlStringBuilder.append("<title>${routine.title}</title>") xmlStringBuilder.append("<con1>${routine.con1}</con1>") xmlStringBuilder.append("<con2>${routine.con2}</con2>") xmlStringBuilder.append("<con3>${routine.con3}</con3>") xmlStringBuilder.append("<con4>${routine.con4}</con4>") xmlStringBuilder.append("<con5>${routine.con5}</con5>") xmlStringBuilder.append("<edm1>${routine.edm1}</edm1>") xmlStringBuilder.append("<edm2>${routine.edm2}</edm2>") xmlStringBuilder.append("<edm3>${routine.edm3}</edm3>") xmlStringBuilder.append("<edm4>${routine.edm4}</edm4>") xmlStringBuilder.append("<edm5>${routine.edm5}</edm5>") xmlStringBuilder.append("<eds1>${routine.eds1}</eds1>") xmlStringBuilder.append("<eds2>${routine.eds2}</eds2>") xmlStringBuilder.append("<eds3>${routine.eds3}</eds3>") xmlStringBuilder.append("<eds4>${routine.eds4}</eds4>") xmlStringBuilder.append("<eds5>${routine.eds5}</eds5>") xmlStringBuilder.append("<selectedSpinnerItem>${routine.selectedSpinnerItem}</selectedSpinnerItem>") xmlStringBuilder.append("</routine>") return xmlStringBuilder.toString() } private fun initializeEditText(editText: EditText, value: String) { editText.setText(value) } private fun getSelectedSpinnerPosition(sharedPrefs: SharedPreferences, savedValue: String): Int { val items = arrayOf("์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ") return items.indexOf(savedValue).coerceAtLeast(0) } private fun showSearchableSpinnerDialog() { // dialog ์ดˆ๊ธฐํ™” dialog = Dialog(this) // dialog set dialog!!.setContentView(R.layout.dialog_searchable_spinner) dialog!!.window?.setLayout(650, 800) dialog!!.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog!!.show() val editText: EditText = dialog!!.findViewById(R.id.edit_text) val listView: ListView = dialog!!.findViewById(R.id.list_view) val dialogAdapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, arrayList) // ์–ด๋Œ‘ํ„ฐ ์„ค์ • listView.adapter = dialogAdapter editText.addTextChangedListener(object : TextWatcher { override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { dialogAdapter.filter.filter(s) } override fun afterTextChanged(s: Editable?) {} }) listView.setOnItemClickListener { _, _, position, _ -> // ์„ ํƒํ•œ ๊ฐ’์„ ํ”„๋กœํผํ‹ฐ์— ์„ค์ • selectedSpinnerValue = dialogAdapter.getItem(position).toString() val positionInAdapter = arrayList.indexOf(selectedSpinnerValue) // ์Šคํ”ผ๋„ˆ์— ์„ ํƒ๋œ ํ•ญ๋ชฉ ๋Œ€์ž… // val positionInAdapter = dialogAdapter.getPosition(selectedSpinnerValue) if (positionInAdapter != -1) { spinner.setSelection(positionInAdapter) } // ์‚ฌ์šฉ์ž๊ฐ€ ํ•ญ๋ชฉ ์„ ํƒํ•˜๋ฉด ๋‹ค์ด์–ผ๋กœ๊ทธ ๋‹ซ์Œ dialog!!.dismiss() } } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/DetailActivityfri.kt
2360092493
package com.example.android_team4_project import android.app.AlertDialog import android.app.Dialog import android.content.Context import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.view.View import android.widget.Button import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.example.android_team4_project.databinding.ActivityDetailBinding import com.google.firebase.auth.FirebaseAuth private lateinit var auth: FirebaseAuth private lateinit var userEmail: String class DetailActivityfri: AppCompatActivity() { private lateinit var binding: ActivityDetailBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityDetailBinding.inflate(layoutInflater) setContentView(binding.root) auth = FirebaseAuth.getInstance() val user = auth.currentUser userEmail = user?.uid ?: "" // ๋ฒ„ํŠผํด๋ฆญ์‹œ ๋งˆ์ด๋ฃจํ‹ด์œผ๋กœ ์ด๋™ binding.btnMypage.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MainActivity::class.java) startActivity(intent) } // ์ˆ˜์ •๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํ•ด๋‹น์š”์ผ ํŒ์—…์—‘ํ‹ฐ๋น„ํ‹ฐ binding.btnSaveAll.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, PopupActivityfri::class.java) startActivity(intent) } // // ์‚ญ์ œ๋ฒ„ํŠผ ํด๋ฆญ์‹œ ์ €์žฅ๋‚ด์šฉ ์‚ญ์ œ // binding.btnCancel.setOnClickListener { // showDeleteConfirmationDialog() // } binding.btnCancel.setOnClickListener { val view = View.inflate(this, R.layout.dialog_view, null) val builder = androidx.appcompat.app.AlertDialog.Builder(this) builder.setView(view) val dialog = builder.create() dialog.setCanceledOnTouchOutside(false) dialog.show() val btnConfirm = view.findViewById<Button>(R.id.btn_confirm) val btnCancel = view.findViewById<Button>(R.id.btn_cancel) btnConfirm.setOnClickListener { showDeleteConfirmationDialog() Toast.makeText(this@DetailActivityfri, "์‚ญ์ œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค", Toast.LENGTH_SHORT).show() dialog.dismiss() } btnCancel.setOnClickListener { dialog.dismiss() } dialog.window?.setBackgroundDrawable(ColorDrawable(Color.WHITE)) } // SharedPreferences์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPrefTitlefri = getSharedPreferences("Routine_Fri$userEmail", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitlefri = sharedPrefTitlefri.getString("title", "") val savedSpinnerfri = sharedPrefTitlefri.getString("selectedSpinnerItem", "") val savedcon1fri = sharedPrefTitlefri.getString("con1", "") val savedcon2fri = sharedPrefTitlefri.getString("con2", "") val savedcon3fri = sharedPrefTitlefri.getString("con3", "") val savedcon4fri = sharedPrefTitlefri.getString("con4", "") val savedcon5fri = sharedPrefTitlefri.getString("con5", "") val savededm1fri = sharedPrefTitlefri.getString("edm1", "") val savededm2fri = sharedPrefTitlefri.getString("edm2", "") val savededm3fri = sharedPrefTitlefri.getString("edm3", "") val savededm4fri = sharedPrefTitlefri.getString("edm4", "") val savededm5fri = sharedPrefTitlefri.getString("edm5", "") val savededs1fri = sharedPrefTitlefri.getString("eds1", "") val savededs2fri = sharedPrefTitlefri.getString("eds2", "") val savededs3fri = sharedPrefTitlefri.getString("eds3", "") val savededs4fri = sharedPrefTitlefri.getString("eds4", "") val savededs5fri = sharedPrefTitlefri.getString("eds5", "") // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • binding.edTitle.text = savedTitlefri binding.spinner.text = savedSpinnerfri binding.edContent1.text = savedcon1fri binding.edContent2.text = savedcon2fri binding.edContent3.text = savedcon3fri binding.edContent4.text = savedcon4fri binding.edContent5.text = savedcon5fri binding.edm1.text = savededm1fri binding.edm2.text = savededm2fri binding.edm3.text = savededm3fri binding.edm4.text = savededm4fri binding.edm5.text = savededm5fri binding.eds1.text = savededs1fri binding.eds2.text = savededs2fri binding.eds3.text = savededs3fri binding.eds4.text = savededs4fri binding.eds5.text = savededs5fri } private fun showDeleteConfirmationDialog() { val builder = AlertDialog.Builder(this) builder.setTitle("์ฃผ์˜") builder.setMessage("์‚ญ์ œํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?") builder.setPositiveButton("์‚ญ์ œ") { _, _ -> // ์‚ฌ์šฉ์ž๊ฐ€ ์‚ญ์ œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ–ˆ์„ ๋•Œ auth = FirebaseAuth.getInstance() val user = auth.currentUser userEmail = user?.uid ?: "" // RoutineData ๊ฐ์ฒด ์—…๋ฐ์ดํŠธ val routine = RoutineData( title = "", selectedSpinnerItem = "", con1 = "", con2 = "", con3 = "", con4 = "", con5 = "", edm1 = "", edm2 = "", edm3 = "", edm4 = "", edm5 = "", eds1 = "", eds2 = "", eds3 = "", eds4 = "", eds5 = "" ) // RoutineData ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ๋ฐ์ดํ„ฐ ์ƒ์„ฑ val xmlData = generateXmlData(routine, "Fri") // userEmail์„ ์ด์šฉํ•˜์—ฌ StorageManager๋ฅผ ์ดˆ๊ธฐํ™” val storageManager = StorageManager(this) // StorageManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ํŒŒ์ผ ์—…๋กœ๋“œ storageManager.uploadXmlFile(xmlData, "Fri") // SharedPreferences๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ์ €์žฅ val userUid = FirebaseAuth.getInstance().uid val sharedPrefTitlefri = getSharedPreferences("Routine_Fri$userUid", Context.MODE_PRIVATE) val editor = sharedPrefTitlefri.edit() editor.putString("title", routine.title) editor.putString("selectedSpinnerItem", routine.selectedSpinnerItem) editor.putString("con1", routine.con1) editor.putString("con2", routine.con2) editor.putString("con3", routine.con3) editor.putString("con4", routine.con4) editor.putString("con5", routine.con5) editor.putString("edm1", routine.edm1) editor.putString("edm2", routine.edm2) editor.putString("edm3", routine.edm3) editor.putString("edm4", routine.edm4) editor.putString("edm5", routine.edm5) editor.putString("eds1", routine.eds1) editor.putString("eds2", routine.eds2) editor.putString("eds3", routine.eds3) editor.putString("eds4", routine.eds4) editor.putString("eds5", routine.eds5) editor.apply() // ์ €์žฅ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ด๋ฃจ์–ด์ง€๋ฉด ์•กํ‹ฐ๋น„ํ‹ฐ ์ด๋™ val intent = Intent(this, MyActivity::class.java) startActivity(intent) finish() // ํ˜„์žฌ ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ์ข…๋ฃŒ } builder.setNegativeButton("์ทจ์†Œ") { dialog, _ -> // ์‚ฌ์šฉ์ž๊ฐ€ ์ทจ์†Œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ–ˆ์„ ๋•Œ dialog.dismiss() } val dialog: AlertDialog = builder.create() dialog.show() } private fun generateXmlData(routine: RoutineData, dayOfWeek:String): String { val xmlStringBuilder = StringBuilder() xmlStringBuilder.append("<routine>") xmlStringBuilder.append("<title>${routine.title}</title>") xmlStringBuilder.append("<con1>${routine.con1}</con1>") xmlStringBuilder.append("<con2>${routine.con2}</con2>") xmlStringBuilder.append("<con3>${routine.con3}</con3>") xmlStringBuilder.append("<con4>${routine.con4}</con4>") xmlStringBuilder.append("<con5>${routine.con5}</con5>") xmlStringBuilder.append("<edm1>${routine.edm1}</edm1>") xmlStringBuilder.append("<edm2>${routine.edm2}</edm2>") xmlStringBuilder.append("<edm3>${routine.edm3}</edm3>") xmlStringBuilder.append("<edm4>${routine.edm4}</edm4>") xmlStringBuilder.append("<edm5>${routine.edm5}</edm5>") xmlStringBuilder.append("<eds1>${routine.eds1}</eds1>") xmlStringBuilder.append("<eds2>${routine.eds2}</eds2>") xmlStringBuilder.append("<eds3>${routine.eds3}</eds3>") xmlStringBuilder.append("<eds4>${routine.eds4}</eds4>") xmlStringBuilder.append("<eds5>${routine.eds5}</eds5>") xmlStringBuilder.append("<selectedSpinnerItem>${routine.selectedSpinnerItem}</selectedSpinnerItem>") xmlStringBuilder.append("</routine>") return xmlStringBuilder.toString() } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/DetailActivitysat.kt
3043087764
package com.example.android_team4_project import android.app.AlertDialog import android.app.Dialog import android.content.Context import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.view.View import android.widget.Button import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.example.android_team4_project.databinding.ActivityDetailBinding import com.google.firebase.auth.FirebaseAuth private lateinit var auth: FirebaseAuth private lateinit var userEmail: String class DetailActivitysat: AppCompatActivity() { private lateinit var binding: ActivityDetailBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityDetailBinding.inflate(layoutInflater) setContentView(binding.root) auth = FirebaseAuth.getInstance() val user = auth.currentUser userEmail = user?.uid ?: "" // ๋ฒ„ํŠผํด๋ฆญ์‹œ ๋งˆ์ด๋ฃจํ‹ด์œผ๋กœ ์ด๋™ binding.btnMypage.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MainActivity::class.java) startActivity(intent) } // ์ˆ˜์ •๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํ•ด๋‹น์š”์ผ ํŒ์—…์—‘ํ‹ฐ๋น„ํ‹ฐ binding.btnSaveAll.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, PopupActivitysat::class.java) startActivity(intent) } // ์‚ญ์ œ๋ฒ„ํŠผ ํด๋ฆญ์‹œ ์ €์žฅ๋‚ด์šฉ ์‚ญ์ œ // binding.btnCancel.setOnClickListener { // showDeleteConfirmationDialog() // } binding.btnCancel.setOnClickListener { val view = View.inflate(this, R.layout.dialog_view, null) val builder = androidx.appcompat.app.AlertDialog.Builder(this) builder.setView(view) val dialog = builder.create() dialog.setCanceledOnTouchOutside(false) dialog.show() val btnConfirm = view.findViewById<Button>(R.id.btn_confirm) val btnCancel = view.findViewById<Button>(R.id.btn_cancel) btnConfirm.setOnClickListener { showDeleteConfirmationDialog() Toast.makeText(this@DetailActivitysat, "์‚ญ์ œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค", Toast.LENGTH_SHORT).show() dialog.dismiss() } btnCancel.setOnClickListener { dialog.dismiss() } dialog.window?.setBackgroundDrawable(ColorDrawable(Color.WHITE)) } // SharedPreferences์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPrefTitlesat = getSharedPreferences("Routine_Sat$userEmail", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitlesat = sharedPrefTitlesat.getString("title", "") val savedSpinnersat = sharedPrefTitlesat.getString("selectedSpinnerItem", "") val savedcon1sat = sharedPrefTitlesat.getString("con1", "") val savedcon2sat = sharedPrefTitlesat.getString("con2", "") val savedcon3sat = sharedPrefTitlesat.getString("con3", "") val savedcon4sat = sharedPrefTitlesat.getString("con4", "") val savedcon5sat = sharedPrefTitlesat.getString("con5", "") val savededm1sat = sharedPrefTitlesat.getString("edm1", "") val savededm2sat = sharedPrefTitlesat.getString("edm2", "") val savededm3sat = sharedPrefTitlesat.getString("edm3", "") val savededm4sat = sharedPrefTitlesat.getString("edm4", "") val savededm5sat = sharedPrefTitlesat.getString("edm5", "") val savededs1sat = sharedPrefTitlesat.getString("eds1", "") val savededs2sat = sharedPrefTitlesat.getString("eds2", "") val savededs3sat = sharedPrefTitlesat.getString("eds3", "") val savededs4sat = sharedPrefTitlesat.getString("eds4", "") val savededs5sat = sharedPrefTitlesat.getString("eds5", "") // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • binding.edTitle.text = savedTitlesat binding.spinner.text = savedSpinnersat binding.edContent1.text = savedcon1sat binding.edContent2.text = savedcon2sat binding.edContent3.text = savedcon3sat binding.edContent4.text = savedcon4sat binding.edContent5.text = savedcon5sat binding.edm1.text = savededm1sat binding.edm2.text = savededm2sat binding.edm3.text = savededm3sat binding.edm4.text = savededm4sat binding.edm5.text = savededm5sat binding.eds1.text = savededs1sat binding.eds2.text = savededs2sat binding.eds3.text = savededs3sat binding.eds4.text = savededs4sat binding.eds5.text = savededs5sat } private fun showDeleteConfirmationDialog() { val builder = AlertDialog.Builder(this) builder.setTitle("์ฃผ์˜") builder.setMessage("์‚ญ์ œํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?") builder.setPositiveButton("์‚ญ์ œ") { _, _ -> // ์‚ฌ์šฉ์ž๊ฐ€ ์‚ญ์ œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ–ˆ์„ ๋•Œ auth = FirebaseAuth.getInstance() val user = auth.currentUser userEmail = user?.uid ?: "" // RoutineData ๊ฐ์ฒด ์—…๋ฐ์ดํŠธ val routine = RoutineData( title = "", selectedSpinnerItem = "", con1 = "", con2 = "", con3 = "", con4 = "", con5 = "", edm1 = "", edm2 = "", edm3 = "", edm4 = "", edm5 = "", eds1 = "", eds2 = "", eds3 = "", eds4 = "", eds5 = "" ) // RoutineData ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ๋ฐ์ดํ„ฐ ์ƒ์„ฑ val xmlData = generateXmlData(routine, "Sat") // userEmail์„ ์ด์šฉํ•˜์—ฌ StorageManager๋ฅผ ์ดˆ๊ธฐํ™” val storageManager = StorageManager(this) // StorageManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ํŒŒ์ผ ์—…๋กœ๋“œ storageManager.uploadXmlFile(xmlData, "Sat") // SharedPreferences๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ์ €์žฅ val userUid = FirebaseAuth.getInstance().uid val sharedPrefTitlesat = getSharedPreferences("Routine_Sat$userUid", Context.MODE_PRIVATE) val editor = sharedPrefTitlesat.edit() editor.putString("title", routine.title) editor.putString("selectedSpinnerItem", routine.selectedSpinnerItem) editor.putString("con1", routine.con1) editor.putString("con2", routine.con2) editor.putString("con3", routine.con3) editor.putString("con4", routine.con4) editor.putString("con5", routine.con5) editor.putString("edm1", routine.edm1) editor.putString("edm2", routine.edm2) editor.putString("edm3", routine.edm3) editor.putString("edm4", routine.edm4) editor.putString("edm5", routine.edm5) editor.putString("eds1", routine.eds1) editor.putString("eds2", routine.eds2) editor.putString("eds3", routine.eds3) editor.putString("eds4", routine.eds4) editor.putString("eds5", routine.eds5) editor.apply() // ์ €์žฅ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ด๋ฃจ์–ด์ง€๋ฉด ์•กํ‹ฐ๋น„ํ‹ฐ ์ด๋™ val intent = Intent(this, MyActivity::class.java) startActivity(intent) finish() // ํ˜„์žฌ ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ์ข…๋ฃŒ } builder.setNegativeButton("์ทจ์†Œ") { dialog, _ -> // ์‚ฌ์šฉ์ž๊ฐ€ ์ทจ์†Œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ–ˆ์„ ๋•Œ dialog.dismiss() } val dialog: AlertDialog = builder.create() dialog.show() } private fun generateXmlData(routine: RoutineData, dayOfWeek:String): String { val xmlStringBuilder = StringBuilder() xmlStringBuilder.append("<routine>") xmlStringBuilder.append("<title>${routine.title}</title>") xmlStringBuilder.append("<con1>${routine.con1}</con1>") xmlStringBuilder.append("<con2>${routine.con2}</con2>") xmlStringBuilder.append("<con3>${routine.con3}</con3>") xmlStringBuilder.append("<con4>${routine.con4}</con4>") xmlStringBuilder.append("<con5>${routine.con5}</con5>") xmlStringBuilder.append("<edm1>${routine.edm1}</edm1>") xmlStringBuilder.append("<edm2>${routine.edm2}</edm2>") xmlStringBuilder.append("<edm3>${routine.edm3}</edm3>") xmlStringBuilder.append("<edm4>${routine.edm4}</edm4>") xmlStringBuilder.append("<edm5>${routine.edm5}</edm5>") xmlStringBuilder.append("<eds1>${routine.eds1}</eds1>") xmlStringBuilder.append("<eds2>${routine.eds2}</eds2>") xmlStringBuilder.append("<eds3>${routine.eds3}</eds3>") xmlStringBuilder.append("<eds4>${routine.eds4}</eds4>") xmlStringBuilder.append("<eds5>${routine.eds5}</eds5>") xmlStringBuilder.append("<selectedSpinnerItem>${routine.selectedSpinnerItem}</selectedSpinnerItem>") xmlStringBuilder.append("</routine>") return xmlStringBuilder.toString() } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/StopActivity1.kt
1925380375
package com.example.android_team4_project import android.app.NotificationChannel import android.app.NotificationManager import android.content.Context import android.content.Intent import android.graphics.Color import android.os.Build import android.os.Bundle import android.os.SystemClock import android.view.View import androidx.appcompat.app.AppCompatActivity import androidx.core.app.NotificationCompat import com.example.android_team4_project.databinding.ActivityStop1Binding class StopActivity1 : AppCompatActivity() { var initTime = 0L var pauseTime = 0L override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val binding = ActivityStop1Binding.inflate(layoutInflater) setContentView(binding.root) binding.btnStart.setOnClickListener { binding.chronometer.base = SystemClock.elapsedRealtime() + pauseTime binding.chronometer.start() binding.btnStop.isEnabled = true binding.btnReset.isEnabled = true binding.btnStart.isEnabled = false binding.btnSave.visibility = View.INVISIBLE } //getTime1์™€ chronometer๊ฐ’์ด ๊ฐ™์•„์ง€๋ฉด notification๋œจ๊ฒŒํ•˜๊ธฐ binding.chronometer.setOnChronometerTickListener{ // Mainactivity์—์„œ stopActivity1 ์—ด๋•Œ ๋ณด๋ƒˆ๋˜ ์‚ฌ์šฉ์ž๊ฐ€ ์ง€์ •ํ•œ ๋ฃจํ‹ด ์‹œ๊ฐ„ ๊ฐ’ ๋ฐ›์•„์˜ค๊ธฐ val isGetTime1 = intent.getStringExtra("isGetTime1") // ์ •๊ทœ์‹์„ ์‚ฌ์šฉํ•˜์—ฌ "๋ถ„"๊ณผ "์ดˆ"๋ฅผ ์—†์• ๊ณ , ":"๋กœ ๋ถ„๊ณผ ์ดˆ๋ฅผ ๊ตฌ๋ถ„ํ•˜์—ฌ ํ•ฉ์น˜๊ธฐ val modifiedText = isGetTime1.toString().replace(Regex("[^0-9]"), "").chunked(2).joinToString(":") { it } val elapsedMillis = SystemClock.elapsedRealtime() - binding.chronometer.base val elapsedSeconds = elapsedMillis / 1000 // TextView ์—…๋ฐ์ดํŠธ ๋˜๋Š” ํŠน์ • ์‹œ๊ฐ„์— ๋„๋‹ฌํ•˜๋ฉด ์•Œ๋ฆผ ๋“ฑ // ๊ฒฝ๊ณผ๋œ ์‹œ๊ฐ„์„ ๋ถ„๊ณผ ์ดˆ๋กœ ๋ณ€ํ™˜ val elapsedMinutes = elapsedSeconds / 60 val remainingSeconds = elapsedSeconds % 60 val currentTime = String.format("%02d:%02d", elapsedMinutes, remainingSeconds) if(modifiedText == currentTime){ notiAlarm() // Toast.makeText(this,"good" , Toast.LENGTH_SHORT).show() } } // binding.btnStop.text = "Stop" binding.btnStop.setOnClickListener { pauseTime = binding.chronometer.base - SystemClock.elapsedRealtime() binding.chronometer.stop() binding.btnStart.isEnabled = true binding.btnStop.isEnabled = false binding.btnReset.isEnabled = true binding.btnSave.isEnabled = true binding.btnSave.visibility = View.VISIBLE } binding.btnReset.setOnClickListener { // binding.btnReset.text = "Reset" pauseTime = 0L binding.chronometer.base = SystemClock.elapsedRealtime() binding.chronometer.stop() binding.btnStart.isEnabled = true binding.btnStop.isEnabled = false binding.btnReset.isEnabled = false binding.btnSave.visibility = View.INVISIBLE } binding.btnSave.setOnClickListener { pauseTime = binding.chronometer.base - SystemClock.elapsedRealtime() binding.chronometer.stop() val intent = Intent(this, MainActivity::class.java) // intent.putExtra("times1", binding.chronometer.text.toString()) startActivity(intent) val sharePref1 = getSharedPreferences("stop1", Context.MODE_PRIVATE) val editor1 = sharePref1.edit() editor1.putString("times1", binding.chronometer.text.toString()) editor1.apply() } } private fun notiAlarm() { // getSystemService(์„œ๋น„์Šค) : ์•ˆ๋“œ๋กœ์ด๋“œ ์‹œ์Šคํ…œ์—์„œ ๋™์ž‘ํ•˜๊ณ  ์žˆ๋Š” ์„œ๋น„์Šค ์ค‘ ์ง€์ •ํ•œ ์„œ๋น„์Šค๋ฅผ ๊ฐ€์ ธ์˜ด // getSystemService() ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ NotificationManager ํƒ€์ž…์˜ ๊ฐ์ฒด ๊ฐ€์ ธ์˜ค๊ธฐ val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager // NotificationCompat ํƒ€์ž…์˜ ๊ฐ์ฒด๋ฅผ ์ €์žฅํ•  ๋ณ€์ˆ˜ ์„ ์–ธ val builder: NotificationCompat.Builder // API 26๋ถ€ํ„ฐ ์ฑ„๋„์ด ์ถ”๊ฐ€ ๋˜์–ด ๋ฒ„์ „์— ๋”ฐ๋ผ ์‚ฌ์šฉ ๋ฐฉ์‹์„ ๋ณ€๊ฒฝ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val channelId = "one-channel" val channelName = "My Channel One" // ์ฑ„๋„ ๊ฐ์ฒด ์ƒ์„ฑ val channel = NotificationChannel( channelId, channelName, // ์•Œ๋ฆผ ๋“ฑ๊ธ‰ ์„ค์ • NotificationManager.IMPORTANCE_DEFAULT ) channel.description = "My Channel One description" channel.setShowBadge(true) // ์•Œ๋ฆผ ์‹œ ๋ผ์ดํŠธ ์‚ฌ์šฉ channel.enableLights(true) channel.lightColor = Color.RED // ์ง€์ •ํ•œ ์ฑ„๋„ ์ •๋ณด๋ฅผ ํ†ตํ•ด์„œ ์ฑ„๋„ ์ƒ์„ฑ manager.createNotificationChannel(channel) // NotificationCompat ํƒ€์ž…์˜ ๊ฐ์ฒด ์ƒ์„ฑ builder = NotificationCompat.Builder(this, channelId) } else { builder = NotificationCompat.Builder(this) } // ์Šคํ…Œ์ด์Šคํ„ฐ์ฐฝ ์•Œ๋ฆผ ํ™”๋ฉด ์„ค์ • builder.setSmallIcon(android.R.drawable.ic_notification_overlay) builder.setWhen(System.currentTimeMillis()) builder.setContentTitle("์•Œ๋ฆผ") builder.setContentText("๋ฃจํ‹ด ์„ฑ๊ณต!") // NotificationManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์Šคํ…Œ์ดํ„ฐ์Šค์ฐฝ์— ์•Œ๋ฆผ์ฐฝ ์ถœ๋ ฅ manager.notify(11, builder.build()) } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/StorageManager.kt
445392439
package com.example.android_team4_project import android.content.Context import android.util.Log import android.widget.Toast import com.google.firebase.auth.FirebaseAuth import com.google.firebase.storage.FirebaseStorage import com.google.firebase.storage.StorageReference class StorageManager(context: Context) { private val storage = FirebaseStorage.getInstance() private val storageRef = storage.reference private val applicationContext = context.applicationContext private lateinit var mAuth: FirebaseAuth fun uploadXmlFile(xmlData: String,dayOfWeek:String) { mAuth = FirebaseAuth.getInstance() val user = mAuth.currentUser val userEmail: String = user?.uid ?: "" val filePath = "Routine_${dayOfWeek}$userEmail.xml" val routineRef: StorageReference = storageRef.child(filePath) val data: ByteArray = xmlData.toByteArray() val uploadTask = routineRef.putBytes(data) uploadTask.addOnSuccessListener { // ์—…๋กœ๋“œ ์„ฑ๊ณต ์‹œ // Toast.makeText(applicationContext, "XML ํŒŒ์ผ ์—…๋กœ๋“œ ์„ฑ๊ณต", Toast.LENGTH_SHORT).show() // ์—ฌ๊ธฐ์—์„œ ์ถ”๊ฐ€์ ์ธ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. }.addOnFailureListener { exception -> // ์—…๋กœ๋“œ ์‹คํŒจ ์‹œ // Toast.makeText(applicationContext, "XML ํŒŒ์ผ ์—…๋กœ๋“œ ์‹คํŒจ", Toast.LENGTH_SHORT).show() // ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅํ•˜๊ฑฐ๋‚˜ ์ถ”๊ฐ€์ ์ธ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. }.addOnProgressListener { taskSnapshot -> // ์—…๋กœ๋“œ ์ง„ํ–‰ ์ƒํ™ฉ์„ ํ‘œ์‹œํ•˜๊ฑฐ๋‚˜ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. val progress = (100.0 * taskSnapshot.bytesTransferred / taskSnapshot.totalByteCount).toInt() // ์—…๋กœ๋“œ ์ง„ํ–‰๋ฅ ์„ ์‚ฌ์šฉํ•˜์—ฌ ํ”„๋กœ๊ทธ๋ ˆ์Šค ๋ฐ” ์—…๋ฐ์ดํŠธ ๋“ฑ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. } } fun downloadXmlFile(listener: DownloadFileListener, day: String) { mAuth = FirebaseAuth.getInstance() val user = mAuth.currentUser val userEmail: String = user?.uid ?: "" val filePath = "Routine_$day$userEmail.xml" val routineRef: StorageReference = storageRef.child(filePath) val ONE_MEGABYTE: Long = 1024 * 1024 routineRef.getBytes(ONE_MEGABYTE) .addOnSuccessListener { data -> // ๋‹ค์šด๋กœ๋“œ ์„ฑ๊ณต ์‹œ val xmlData = String(data) listener.onDownloadSuccess(xmlData) // ์—ฌ๊ธฐ์—์„œ ์ถ”๊ฐ€์ ์ธ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. }.addOnFailureListener { exception -> // ๋‹ค์šด๋กœ๋“œ ์‹คํŒจ ์‹œ listener.onDownloadFailure() // ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅํ•˜๊ฑฐ๋‚˜ ์ถ”๊ฐ€์ ์ธ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Log.d("StorageManager", "ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค: $filePath") } } interface DownloadFileListener { fun onDownloadSuccess(xmlData: String) fun onDownloadFailure() } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/StopActivity5.kt
43801426
package com.example.android_team4_project import android.app.NotificationChannel import android.app.NotificationManager import android.content.Context import android.content.Intent import android.graphics.Color import android.os.Build import android.os.Bundle import android.os.SystemClock import android.view.View import androidx.appcompat.app.AppCompatActivity import androidx.core.app.NotificationCompat import com.example.android_team4_project.databinding.ActivityStop5Binding class StopActivity5 : AppCompatActivity() { var initTime = 0L var pauseTime = 0L override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val binding = ActivityStop5Binding.inflate(layoutInflater) setContentView(binding.root) binding.btnStart5.setOnClickListener { binding.chronometer5.base = SystemClock.elapsedRealtime() + pauseTime binding.chronometer5.start() binding.btnStop5.isEnabled = true binding.btnReset5.isEnabled = true binding.btnStart5.isEnabled = false binding.btnSave5.visibility = View.INVISIBLE } // binding.btnStop.text = "Stop" binding.btnStop5.setOnClickListener { pauseTime = binding.chronometer5.base - SystemClock.elapsedRealtime() binding.chronometer5.stop() binding.btnStart5.isEnabled = true binding.btnStop5.isEnabled = false binding.btnReset5.isEnabled = true binding.btnSave5.isEnabled = true binding.btnSave5.visibility = View.VISIBLE } binding.btnReset5.setOnClickListener { // binding.btnReset.text = "Reset" pauseTime = 0L binding.chronometer5.base = SystemClock.elapsedRealtime() binding.chronometer5.stop() binding.btnStart5.isEnabled = true binding.btnStop5.isEnabled = false binding.btnReset5.isEnabled = false binding.btnSave5.visibility = View.INVISIBLE } //getTime1์™€ chronometer๊ฐ’์ด ๊ฐ™์•„์ง€๋ฉด notification๋œจ๊ฒŒํ•˜๊ธฐ binding.chronometer5.setOnChronometerTickListener{ // Mainactivity์—์„œ stopActivity1 ์—ด๋•Œ ๋ณด๋ƒˆ๋˜ ์‚ฌ์šฉ์ž๊ฐ€ ์ง€์ •ํ•œ ๋ฃจํ‹ด ์‹œ๊ฐ„ ๊ฐ’ ๋ฐ›์•„์˜ค๊ธฐ val isGetTime5 = intent.getStringExtra("isGetTime5") // ์ •๊ทœ์‹์„ ์‚ฌ์šฉํ•˜์—ฌ "๋ถ„"๊ณผ "์ดˆ"๋ฅผ ์—†์• ๊ณ , ":"๋กœ ๋ถ„๊ณผ ์ดˆ๋ฅผ ๊ตฌ๋ถ„ํ•˜์—ฌ ํ•ฉ์น˜๊ธฐ val modifiedText = isGetTime5.toString().replace(Regex("[^0-9]"), "").chunked(2).joinToString(":") { it } val elapsedMillis = SystemClock.elapsedRealtime() - binding.chronometer5.base val elapsedSeconds = elapsedMillis / 1000 // TextView ์—…๋ฐ์ดํŠธ ๋˜๋Š” ํŠน์ • ์‹œ๊ฐ„์— ๋„๋‹ฌํ•˜๋ฉด ์•Œ๋ฆผ ๋“ฑ // ๊ฒฝ๊ณผ๋œ ์‹œ๊ฐ„์„ ๋ถ„๊ณผ ์ดˆ๋กœ ๋ณ€ํ™˜ val elapsedMinutes = elapsedSeconds / 60 val remainingSeconds = elapsedSeconds % 60 val currentTime = String.format("%02d:%02d", elapsedMinutes, remainingSeconds) if(modifiedText == currentTime){ notiAlarm() // Toast.makeText(this,"good" , Toast.LENGTH_SHORT).show() } } binding.btnSave5.setOnClickListener { pauseTime = binding.chronometer5.base - SystemClock.elapsedRealtime() binding.chronometer5.stop() val intent = Intent(this, MainActivity::class.java) // intent.putExtra("times5", binding.chronometer5.text.toString()) startActivity(intent) val sharePref5 = getSharedPreferences("stop5", Context.MODE_PRIVATE) val editor5 = sharePref5.edit() editor5.putString("times5", binding.chronometer5.text.toString()) editor5.apply() } } private fun notiAlarm() { // getSystemService(์„œ๋น„์Šค) : ์•ˆ๋“œ๋กœ์ด๋“œ ์‹œ์Šคํ…œ์—์„œ ๋™์ž‘ํ•˜๊ณ  ์žˆ๋Š” ์„œ๋น„์Šค ์ค‘ ์ง€์ •ํ•œ ์„œ๋น„์Šค๋ฅผ ๊ฐ€์ ธ์˜ด // getSystemService() ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ NotificationManager ํƒ€์ž…์˜ ๊ฐ์ฒด ๊ฐ€์ ธ์˜ค๊ธฐ val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager // NotificationCompat ํƒ€์ž…์˜ ๊ฐ์ฒด๋ฅผ ์ €์žฅํ•  ๋ณ€์ˆ˜ ์„ ์–ธ val builder: NotificationCompat.Builder // API 26๋ถ€ํ„ฐ ์ฑ„๋„์ด ์ถ”๊ฐ€ ๋˜์–ด ๋ฒ„์ „์— ๋”ฐ๋ผ ์‚ฌ์šฉ ๋ฐฉ์‹์„ ๋ณ€๊ฒฝ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val channelId = "one-channel" val channelName = "My Channel One" // ์ฑ„๋„ ๊ฐ์ฒด ์ƒ์„ฑ val channel = NotificationChannel( channelId, channelName, // ์•Œ๋ฆผ ๋“ฑ๊ธ‰ ์„ค์ • NotificationManager.IMPORTANCE_DEFAULT ) channel.description = "My Channel One description" channel.setShowBadge(true) // ์•Œ๋ฆผ ์‹œ ๋ผ์ดํŠธ ์‚ฌ์šฉ channel.enableLights(true) channel.lightColor = Color.RED // ์ง€์ •ํ•œ ์ฑ„๋„ ์ •๋ณด๋ฅผ ํ†ตํ•ด์„œ ์ฑ„๋„ ์ƒ์„ฑ manager.createNotificationChannel(channel) // NotificationCompat ํƒ€์ž…์˜ ๊ฐ์ฒด ์ƒ์„ฑ builder = NotificationCompat.Builder(this, channelId) } else { builder = NotificationCompat.Builder(this) } // ์Šคํ…Œ์ด์Šคํ„ฐ์ฐฝ ์•Œ๋ฆผ ํ™”๋ฉด ์„ค์ • builder.setSmallIcon(android.R.drawable.ic_notification_overlay) builder.setWhen(System.currentTimeMillis()) builder.setContentTitle("์•Œ๋ฆผ") builder.setContentText("๋ฃจํ‹ด ์„ฑ๊ณต!") // NotificationManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์Šคํ…Œ์ดํ„ฐ์Šค์ฐฝ์— ์•Œ๋ฆผ์ฐฝ ์ถœ๋ ฅ manager.notify(11, builder.build()) } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/LoginActivity.kt
171898651
package com.example.android_team4_project import android.content.Context import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.util.Log import android.view.View import android.widget.Toast import com.example.android_team4_project.databinding.ActivityLoginBinding import com.google.android.gms.auth.api.signin.GoogleSignIn import com.google.android.gms.auth.api.signin.GoogleSignInAccount import com.google.android.gms.auth.api.signin.GoogleSignInClient import com.google.android.gms.auth.api.signin.GoogleSignInOptions import com.google.android.gms.common.SignInButton import com.google.android.gms.common.api.ApiException import com.google.android.gms.tasks.Task import com.google.firebase.auth.FirebaseAuth import com.google.firebase.auth.FirebaseUser import com.google.firebase.auth.GoogleAuthProvider class LoginActivity : AppCompatActivity() { private lateinit var mGoogleSignInClient: GoogleSignInClient private lateinit var mAuth: FirebaseAuth private lateinit var binding: ActivityLoginBinding // View Binding ์ถ”๊ฐ€ override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityLoginBinding.inflate(layoutInflater) // View Binding ์ดˆ๊ธฐํ™” setContentView(binding.root) mAuth = FirebaseAuth.getInstance() val signInButton = findViewById<SignInButton>(R.id.btnSignIn) signInButton.setSize(SignInButton.SIZE_WIDE) signInButton.setColorScheme(SignInButton.COLOR_DARK) val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(getString(R.string.default_web_client_id)) .requestEmail() .build() mGoogleSignInClient = GoogleSignIn.getClient(this, gso) binding.btnSignIn.setOnClickListener { signInWithGoogle() } // binding.btnSignOut.setOnClickListener { // signOut() // } } private fun signInWithGoogle() { val signInIntent = mGoogleSignInClient.signInIntent startActivityForResult(signInIntent, RC_SIGN_IN) } // Google ๋กœ๊ทธ์ธ ๊ฒฐ๊ณผ ์ฒ˜๋ฆฌ override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == RC_SIGN_IN) { val task = GoogleSignIn.getSignedInAccountFromIntent(data) handleSignInResult(task) } } private fun handleSignInResult(completedTask: Task<GoogleSignInAccount>) { try { val account = completedTask.getResult(ApiException::class.java) // Firebase์— Google ๋กœ๊ทธ์ธ ์ •๋ณด ๋“ฑ๋ก if (account != null) { firebaseAuthWithGoogle(account) } } catch (e: ApiException) { Toast.makeText(this, "Google Sign In Failed", Toast.LENGTH_SHORT).show() } } private fun firebaseAuthWithGoogle(account: GoogleSignInAccount) { val credential = GoogleAuthProvider.getCredential(account.idToken, null) mAuth.signInWithCredential(credential) .addOnCompleteListener(this) { task -> if (task.isSuccessful) { val user = mAuth.currentUser user?.let { firebaseUser -> val uid = user.uid // Firebase ์‚ฌ์šฉ์ž UID ๊ฐ€์ ธ์˜ค๊ธฐ // ๋‹ค์šด๋กœ๋“œ ๋ฉ”์„œ๋“œ ํ˜ธ์ถœ downloadRoutineData(uid, object : StorageManager.DownloadFileListener { override fun onDownloadSuccess(xmlData: String) { // ๋‹ค์šด๋กœ๋“œ ์„ฑ๊ณตํ•œ ๊ฒฝ์šฐ์— ์ดํ›„ ์ฒ˜๋ฆฌ๋ฅผ ์ˆ˜ํ–‰ // xmlData๋ฅผ ํŒŒ์‹ฑํ•˜์—ฌ ํ•„์š”ํ•œ ๋‚ด์šฉ์„ ๊ฐ€์ ธ์™€ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Œ Log.d("KSC","๋‹ค์šด๋กœ๋“œ ์„ฑ๊ณต") moveToActivity() } override fun onDownloadFailure() { // ๋‹ค์šด๋กœ๋“œ ์‹คํŒจํ•œ ๊ฒฝ์šฐ์— ์ฒ˜๋ฆฌ Log.d("KSC","๋‹ค์šด๋กœ๋“œ ์‹คํŒจ") moveToActivity() } }) } } else { Toast.makeText(this, "Authentication Failed.", Toast.LENGTH_SHORT).show() } } } private fun downloadRoutineData(uid: String, listener: StorageManager.DownloadFileListener) { val storageManager = StorageManager(this) val daysOfWeek = listOf("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun") var downloadCount = 0 for (day in daysOfWeek) { val fileName = "Routine_$day$uid.xml" storageManager.downloadXmlFile(object : StorageManager.DownloadFileListener { override fun onDownloadSuccess(xmlData: String) { val routineData = XmlParser().parseXml(xmlData) // ํŒŒ์ผ์— ๋ฃจํ‹ด ๋ฐ์ดํ„ฐ ์ €์žฅ saveRoutineDataToShare(routineData, day, uid) // ๋‹ค์šด๋กœ๋“œ ์™„๋ฃŒ ํ›„ ํŽ˜์ด์ง€ ์ด๋™ downloadCount++ if (downloadCount == daysOfWeek.size) { listener.onDownloadSuccess("") } } override fun onDownloadFailure() { // ๋‹ค์šด๋กœ๋“œ ์‹คํŒจํ•œ ๊ฒฝ์šฐ์— ์ฒ˜๋ฆฌ Log.d("KSC","๋‹ค์šด๋กœ๋“œ ์‹คํŒจ") downloadCount++ if (downloadCount == daysOfWeek.size) { // ๋ชจ๋“  ๋ฐ์ดํ„ฐ ๋‹ค์šด๋กœ๋“œ๊ฐ€ ์™„๋ฃŒ๋œ ๊ฒฝ์šฐ์—๋งŒ ์ด๋™ listener.onDownloadFailure() } } }, day) // day๋ฅผ ํ•œ ๋ฒˆ๋งŒ ์ „๋‹ฌํ•˜๋„๋ก ์ˆ˜์ • } } private fun saveRoutineDataToShare(routineData: RoutineData, day: String, uid: String) { val sharedPrefTitle = getSharedPreferences("Routine_$day$uid", Context.MODE_PRIVATE) val editor = sharedPrefTitle.edit() editor.putString("title", routineData.title) editor.putString("selectedSpinnerItem", routineData.selectedSpinnerItem) editor.putString("con1", routineData.con1) editor.putString("con2", routineData.con2) editor.putString("con3", routineData.con3) editor.putString("con4", routineData.con4) editor.putString("con5", routineData.con5) editor.putString("edm1", routineData.edm1) editor.putString("edm2", routineData.edm2) editor.putString("edm3", routineData.edm3) editor.putString("edm4", routineData.edm4) editor.putString("edm5", routineData.edm5) editor.putString("eds1", routineData.eds1) editor.putString("eds2", routineData.eds2) editor.putString("eds3", routineData.eds3) editor.putString("eds4", routineData.eds4) editor.putString("eds5", routineData.eds5) editor.apply() } // private fun signOut() { // mAuth.signOut() // mGoogleSignInClient.signOut().addOnCompleteListener(this) { // Toast.makeText(this, "Sign out successful", Toast.LENGTH_SHORT).show() // } // } // ํ•ด๋‹น๋ถ€๋ถ„์„ ์ด์ œ ์ฒ˜์Œ ์‹œ์ž‘ํ–ˆ์„ ๋•Œ ๋กœ๊ทธ์ธ ํŽ˜์ด์ง€์—์„œ ๋ฉ”์ธ์•กํ‹ฐ๋น„ํ‹ฐ๋กœ ์ด๋™ํ•˜๋„๋ก ์ˆ˜์ •๋งŒ ํ•˜๋ฉด๋จ private fun moveToActivity() { val intent = Intent(this@LoginActivity, MainActivity::class.java) startActivity(intent) finish() } companion object { private const val RC_SIGN_IN = 9001 private const val TAG = "GoogleSignIn" } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/PopupActivitytue.kt
68498841
package com.example.android_team4_project import android.app.Dialog import android.content.Context import android.content.Intent import android.content.SharedPreferences import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.text.Editable import android.text.TextWatcher import android.widget.ArrayAdapter import android.widget.EditText import android.widget.ListView import android.widget.Spinner import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.example.android_team4_project.databinding.ActivityPopupBinding import com.google.firebase.auth.FirebaseAuth class PopupActivitytue : AppCompatActivity() { private lateinit var binding: ActivityPopupBinding private lateinit var userEmail: String private lateinit var arrayList: ArrayList<String> private lateinit var dialog: Dialog private lateinit var spinner: Spinner private lateinit var selectedSpinnerValue: String private lateinit var auth: FirebaseAuth override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityPopupBinding.inflate(layoutInflater) setContentView(binding.root) auth = FirebaseAuth.getInstance() val user = auth.currentUser userEmail = user?.uid ?: "" dialog = Dialog(this) val sharedPrefTitletue = getSharedPreferences("Routine_Tue$userEmail", Context.MODE_PRIVATE) val routine = RoutineData( title = sharedPrefTitletue.getString("title", "") ?: "", selectedSpinnerItem = sharedPrefTitletue.getString("selectedSpinnerItem", "") ?: "", con1 = sharedPrefTitletue.getString("con1", "") ?: "", con2 = sharedPrefTitletue.getString("con2", "") ?: "", con3 = sharedPrefTitletue.getString("con3", "") ?: "", con4 = sharedPrefTitletue.getString("con4", "") ?: "", con5 = sharedPrefTitletue.getString("con5", "") ?: "", edm1 = sharedPrefTitletue.getString("edm1", "") ?: "", edm2 = sharedPrefTitletue.getString("edm2", "") ?: "", edm3 = sharedPrefTitletue.getString("edm3", "") ?: "", edm4 = sharedPrefTitletue.getString("edm4", "") ?: "", edm5 = sharedPrefTitletue.getString("edm5", "") ?: "", eds1 = sharedPrefTitletue.getString("eds1", "") ?: "", eds2 = sharedPrefTitletue.getString("eds2", "") ?: "", eds3 = sharedPrefTitletue.getString("eds3", "") ?: "", eds4 = sharedPrefTitletue.getString("eds4", "") ?: "", eds5 = sharedPrefTitletue.getString("eds5", "") ?: "" ) initializeEditText(binding.edTitle, routine.title) routine.con1?.let { initializeEditText(binding.edContent1, it) } routine.con2?.let { initializeEditText(binding.edContent2, it) } routine.con3?.let { initializeEditText(binding.edContent3, it) } routine.con4?.let { initializeEditText(binding.edContent4, it) } routine.con5?.let { initializeEditText(binding.edContent5, it) } initializeEditText(binding.edm1, routine.edm1.toString()) initializeEditText(binding.edm2, routine.edm2.toString()) initializeEditText(binding.edm3, routine.edm3.toString()) initializeEditText(binding.edm4, routine.edm4.toString()) initializeEditText(binding.edm5, routine.edm5.toString()) initializeEditText(binding.eds1, routine.eds1.toString()) initializeEditText(binding.eds2, routine.eds2.toString()) initializeEditText(binding.eds3, routine.eds3.toString()) initializeEditText(binding.eds4, routine.eds4.toString()) initializeEditText(binding.eds5, routine.eds5.toString()) binding.spinner.setSelection(getSelectedSpinnerPosition(sharedPrefTitletue, routine.selectedSpinnerItem)) binding.btnSaveAll.setOnClickListener { //Toast Toast.makeText(this,"ํ™”์š”์ผ ๋ฃจํ‹ด์ด ์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.", Toast.LENGTH_SHORT).show() val edTitle = binding.edTitle.text.toString() val edCon1 = binding.edContent1.text.toString() val edCon2 = binding.edContent2.text.toString() val edCon3 = binding.edContent3.text.toString() val edCon4 = binding.edContent4.text.toString() val edCon5 = binding.edContent5.text.toString() val edm1 = binding.edm1.text.toString().toIntOrNull() ?: 0 val edm2 = binding.edm2.text.toString().toIntOrNull() ?: 0 val edm3 = binding.edm3.text.toString().toIntOrNull() ?: 0 val edm4 = binding.edm4.text.toString().toIntOrNull() ?: 0 val edm5 = binding.edm5.text.toString().toIntOrNull() ?: 0 val eds1 = binding.eds1.text.toString().toIntOrNull() ?: 0 val eds2 = binding.eds2.text.toString().toIntOrNull() ?: 0 val eds3 = binding.eds3.text.toString().toIntOrNull() ?: 0 val eds4 = binding.eds4.text.toString().toIntOrNull() ?: 0 val eds5 = binding.eds5.text.toString().toIntOrNull() ?: 0 // ์Šคํ”ผ๋„ˆ์—์„œ ์„ ํƒ๋œ ํ•ญ๋ชฉ์˜ ๊ฐ’์„ ๊ฐ€์ ธ์˜ค๊ธฐ val selectedSpinnerItem = binding.spinner.selectedItem.toString() // RoutineData ๊ฐ์ฒด ์—…๋ฐ์ดํŠธ val routine = RoutineData( title = edTitle, selectedSpinnerItem = selectedSpinnerItem, con1 = edCon1, con2 = edCon2, con3 = edCon3, con4 = edCon4, con5 = edCon5, edm1 = edm1.toString(), edm2 = edm2.toString(), edm3 = edm3.toString(), edm4 = edm4.toString(), edm5 = edm5.toString(), eds1 = eds1.toString(), eds2 = eds2.toString(), eds3 = eds3.toString(), eds4 = eds4.toString(), eds5 = eds5.toString() ) // RoutineData ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ๋ฐ์ดํ„ฐ ์ƒ์„ฑ val xmlData = generateXmlData(routine,"Tue") // userEmail์„ ์ด์šฉํ•˜์—ฌ StorageManager๋ฅผ ์ดˆ๊ธฐํ™” val storageManager = StorageManager(this) // StorageManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ํŒŒ์ผ ์—…๋กœ๋“œ storageManager.uploadXmlFile(xmlData,"Tue") // SharedPreferences๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ์ €์žฅ val userUid = FirebaseAuth.getInstance().uid val sharedPrefTitletue = getSharedPreferences("Routine_Tue$userUid", Context.MODE_PRIVATE) val editor = sharedPrefTitletue.edit() editor.putString("title", routine.title) editor.putString("selectedSpinnerItem", routine.selectedSpinnerItem) editor.putString("con1", routine.con1) editor.putString("con2", routine.con2) editor.putString("con3", routine.con3) editor.putString("con4", routine.con4) editor.putString("con5", routine.con5) editor.putString("edm1", routine.edm1) editor.putString("edm2", routine.edm2) editor.putString("edm3", routine.edm3) editor.putString("edm4", routine.edm4) editor.putString("edm5", routine.edm5) editor.putString("eds1", routine.eds1) editor.putString("eds2", routine.eds2) editor.putString("eds3", routine.eds3) editor.putString("eds4", routine.eds4) editor.putString("eds5", routine.eds5) editor.apply() // ์ €์žฅ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ด๋ฃจ์–ด์ง€๋ฉด ์•กํ‹ฐ๋น„ํ‹ฐ ์ด๋™ val intent = Intent(this, MyActivity::class.java) startActivity(intent) finish() // ํ˜„์žฌ ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ์ข…๋ฃŒ } binding.btnCancel.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MyActivity::class.java) startActivity(intent) } // ๋ฒ„ํŠผํด๋ฆญ์‹œ ๋งˆ์ด๋ฃจํ‹ด์œผ๋กœ ์ด๋™ binding.btnMypage.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MainActivity::class.java) startActivity(intent) } // ์Šคํ”ผ๋„ˆ ๊ฐ์ฒด ์ƒ์„ฑ spinner = binding.spinner // // ์Šคํ”ผ๋„ˆ ํด๋ฆญ ์‹œ ๋‹ค์ด์–ผ๋กœ๊ทธ ๋„์šฐ๊ธฐ // spinner.setOnTouchListener { _, _ -> // showSearchableSpinnerDialog() // false // } // ์Šคํ”ผ๋„ˆ ํด๋ฆญ ์‹œ ๋‹ค์ด์–ผ๋กœ๊ทธ ๋„์šฐ๊ธฐ spinner.setOnTouchListener { _, _ -> if (dialog == null) { // ๋‹ค์ด์–ผ๋กœ๊ทธ๊ฐ€ ์ดˆ๊ธฐํ™”๋˜์ง€ ์•Š์•˜๋‹ค๋ฉด ์ดˆ๊ธฐํ™” ํ›„ ๋ณด์—ฌ์ฃผ๊ธฐ showSearchableSpinnerDialog() } else if (!dialog!!.isShowing) { // ๋‹ค์ด์–ผ๋กœ๊ทธ๊ฐ€ ์ดˆ๊ธฐํ™”๋˜์–ด ์žˆ๊ณ  ๋ณด์—ฌ์ง€์ง€ ์•Š๋Š” ์ƒํƒœ๋ผ๋ฉด ๋ณด์—ฌ์ฃผ๊ธฐ showSearchableSpinnerDialog() } true } // ์ดˆ๊ธฐํ™” arrayList = arrayListOf( "์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ" ) // ๋“œ๋กญ๋‹ค์šด ๋ฉ”๋‰ด์— ํ‘œ์‹œํ•  ํ•ญ๋ชฉ๋“ค val items = arrayOf("์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ") // ArrayAdapter๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋“œ๋กญ๋‹ค์šด ๋ฉ”๋‰ด์— ํ•ญ๋ชฉ๋“ค์„ ์—ฐ๊ฒฐ val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, items) adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spinner.adapter = adapter val items2 = arrayOf("์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ") // ์ €์žฅ๋œ ๊ฐ’์„ ๋ถˆ๋Ÿฌ์™€์„œ ์Šคํ”ผ๋„ˆ์— ๋Œ€์ž… val savedSpinnerItem = sharedPrefTitletue.getString("selectedSpinnerItem", "") if (items2.contains(savedSpinnerItem)) { val positionInAdapter = items2.indexOf(savedSpinnerItem) binding.spinner.setSelection(positionInAdapter) } } // ์—…๋กœ๋“œํ•  ํŒŒ์ผ์— ์ €์žฅ๋  ๊ฐ’ ์„ค์ • private fun generateXmlData(routine: RoutineData, dayOfWeek:String): String { val xmlStringBuilder = StringBuilder() xmlStringBuilder.append("<routine>") xmlStringBuilder.append("<title>${routine.title}</title>") xmlStringBuilder.append("<con1>${routine.con1}</con1>") xmlStringBuilder.append("<con2>${routine.con2}</con2>") xmlStringBuilder.append("<con3>${routine.con3}</con3>") xmlStringBuilder.append("<con4>${routine.con4}</con4>") xmlStringBuilder.append("<con5>${routine.con5}</con5>") xmlStringBuilder.append("<edm1>${routine.edm1}</edm1>") xmlStringBuilder.append("<edm2>${routine.edm2}</edm2>") xmlStringBuilder.append("<edm3>${routine.edm3}</edm3>") xmlStringBuilder.append("<edm4>${routine.edm4}</edm4>") xmlStringBuilder.append("<edm5>${routine.edm5}</edm5>") xmlStringBuilder.append("<eds1>${routine.eds1}</eds1>") xmlStringBuilder.append("<eds2>${routine.eds2}</eds2>") xmlStringBuilder.append("<eds3>${routine.eds3}</eds3>") xmlStringBuilder.append("<eds4>${routine.eds4}</eds4>") xmlStringBuilder.append("<eds5>${routine.eds5}</eds5>") xmlStringBuilder.append("<selectedSpinnerItem>${routine.selectedSpinnerItem}</selectedSpinnerItem>") xmlStringBuilder.append("</routine>") return xmlStringBuilder.toString() } private fun initializeEditText(editText: EditText, value: String) { editText.setText(value) } private fun getSelectedSpinnerPosition(sharedPrefs: SharedPreferences, savedValue: String): Int { val items = arrayOf("์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ") return items.indexOf(savedValue).coerceAtLeast(0) } private fun showSearchableSpinnerDialog() { // dialog ์ดˆ๊ธฐํ™” dialog = Dialog(this) // dialog set dialog!!.setContentView(R.layout.dialog_searchable_spinner) dialog!!.window?.setLayout(650, 800) dialog!!.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog!!.show() val editText: EditText = dialog!!.findViewById(R.id.edit_text) val listView: ListView = dialog!!.findViewById(R.id.list_view) val dialogAdapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, arrayList) // ์–ด๋Œ‘ํ„ฐ ์„ค์ • listView.adapter = dialogAdapter editText.addTextChangedListener(object : TextWatcher { override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { dialogAdapter.filter.filter(s) } override fun afterTextChanged(s: Editable?) {} }) listView.setOnItemClickListener { _, _, position, _ -> // ์„ ํƒํ•œ ๊ฐ’์„ ํ”„๋กœํผํ‹ฐ์— ์„ค์ • selectedSpinnerValue = dialogAdapter.getItem(position).toString() val positionInAdapter = arrayList.indexOf(selectedSpinnerValue) // ์Šคํ”ผ๋„ˆ์— ์„ ํƒ๋œ ํ•ญ๋ชฉ ๋Œ€์ž… // val positionInAdapter = dialogAdapter.getPosition(selectedSpinnerValue) if (positionInAdapter != -1) { spinner.setSelection(positionInAdapter) } // ์‚ฌ์šฉ์ž๊ฐ€ ํ•ญ๋ชฉ ์„ ํƒํ•˜๋ฉด ๋‹ค์ด์–ผ๋กœ๊ทธ ๋‹ซ์Œ dialog!!.dismiss() } } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/StopActivity4.kt
3051420169
package com.example.android_team4_project import android.app.NotificationChannel import android.app.NotificationManager import android.content.Context import android.content.Intent import android.graphics.Color import android.os.Build import android.os.Bundle import android.os.SystemClock import android.util.Log import android.view.KeyEvent import android.view.View import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.core.app.NotificationCompat import com.example.android_team4_project.databinding.ActivityStop4Binding class StopActivity4 : AppCompatActivity() { var initTime = 0L var pauseTime = 0L override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val binding = ActivityStop4Binding.inflate(layoutInflater) setContentView(binding.root) binding.btnStart4.setOnClickListener { binding.chronometer4.base = SystemClock.elapsedRealtime() + pauseTime binding.chronometer4.start() binding.btnStop4.isEnabled = true binding.btnReset4.isEnabled = true binding.btnStart4.isEnabled = false binding.btnSave4.visibility = View.INVISIBLE } // binding.btnStop.text = "Stop" binding.btnStop4.setOnClickListener { pauseTime = binding.chronometer4.base - SystemClock.elapsedRealtime() binding.chronometer4.stop() binding.btnStart4.isEnabled = true binding.btnStop4.isEnabled = false binding.btnReset4.isEnabled = true binding.btnSave4.isEnabled = true binding.btnSave4.visibility = View.VISIBLE } binding.btnReset4.setOnClickListener { // binding.btnReset.text = "Reset" pauseTime = 0L binding.chronometer4.base = SystemClock.elapsedRealtime() binding.chronometer4.stop() binding.btnStart4.isEnabled = true binding.btnStop4.isEnabled = false binding.btnReset4.isEnabled = false binding.btnSave4.visibility = View.INVISIBLE } //getTime1์™€ chronometer๊ฐ’์ด ๊ฐ™์•„์ง€๋ฉด notification๋œจ๊ฒŒํ•˜๊ธฐ binding.chronometer4.setOnChronometerTickListener{ // Mainactivity์—์„œ stopActivity1 ์—ด๋•Œ ๋ณด๋ƒˆ๋˜ ์‚ฌ์šฉ์ž๊ฐ€ ์ง€์ •ํ•œ ๋ฃจํ‹ด ์‹œ๊ฐ„ ๊ฐ’ ๋ฐ›์•„์˜ค๊ธฐ val isGetTime4 = intent.getStringExtra("isGetTime4") // ์ •๊ทœ์‹์„ ์‚ฌ์šฉํ•˜์—ฌ "๋ถ„"๊ณผ "์ดˆ"๋ฅผ ์—†์• ๊ณ , ":"๋กœ ๋ถ„๊ณผ ์ดˆ๋ฅผ ๊ตฌ๋ถ„ํ•˜์—ฌ ํ•ฉ์น˜๊ธฐ val modifiedText = isGetTime4.toString().replace(Regex("[^0-9]"), "").chunked(2).joinToString(":") { it } val elapsedMillis = SystemClock.elapsedRealtime() - binding.chronometer4.base val elapsedSeconds = elapsedMillis / 1000 // TextView ์—…๋ฐ์ดํŠธ ๋˜๋Š” ํŠน์ • ์‹œ๊ฐ„์— ๋„๋‹ฌํ•˜๋ฉด ์•Œ๋ฆผ ๋“ฑ // ๊ฒฝ๊ณผ๋œ ์‹œ๊ฐ„์„ ๋ถ„๊ณผ ์ดˆ๋กœ ๋ณ€ํ™˜ val elapsedMinutes = elapsedSeconds / 60 val remainingSeconds = elapsedSeconds % 60 val currentTime = String.format("%02d:%02d", elapsedMinutes, remainingSeconds) if(modifiedText == currentTime){ notiAlarm() // Toast.makeText(this,"good" , Toast.LENGTH_SHORT).show() } } binding.btnSave4.setOnClickListener { pauseTime = binding.chronometer4.base - SystemClock.elapsedRealtime() binding.chronometer4.stop() val intent = Intent(this, MainActivity::class.java) // intent.putExtra("times4", binding.chronometer4.text.toString()) startActivity(intent) val sharePref4 = getSharedPreferences("stop4", Context.MODE_PRIVATE) val editor4 = sharePref4.edit() editor4.putString("times4", binding.chronometer4.text.toString()) editor4.apply() } } private fun notiAlarm() { // getSystemService(์„œ๋น„์Šค) : ์•ˆ๋“œ๋กœ์ด๋“œ ์‹œ์Šคํ…œ์—์„œ ๋™์ž‘ํ•˜๊ณ  ์žˆ๋Š” ์„œ๋น„์Šค ์ค‘ ์ง€์ •ํ•œ ์„œ๋น„์Šค๋ฅผ ๊ฐ€์ ธ์˜ด // getSystemService() ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ NotificationManager ํƒ€์ž…์˜ ๊ฐ์ฒด ๊ฐ€์ ธ์˜ค๊ธฐ val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager // NotificationCompat ํƒ€์ž…์˜ ๊ฐ์ฒด๋ฅผ ์ €์žฅํ•  ๋ณ€์ˆ˜ ์„ ์–ธ val builder: NotificationCompat.Builder // API 26๋ถ€ํ„ฐ ์ฑ„๋„์ด ์ถ”๊ฐ€ ๋˜์–ด ๋ฒ„์ „์— ๋”ฐ๋ผ ์‚ฌ์šฉ ๋ฐฉ์‹์„ ๋ณ€๊ฒฝ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val channelId = "one-channel" val channelName = "My Channel One" // ์ฑ„๋„ ๊ฐ์ฒด ์ƒ์„ฑ val channel = NotificationChannel( channelId, channelName, // ์•Œ๋ฆผ ๋“ฑ๊ธ‰ ์„ค์ • NotificationManager.IMPORTANCE_DEFAULT ) channel.description = "My Channel One description" channel.setShowBadge(true) // ์•Œ๋ฆผ ์‹œ ๋ผ์ดํŠธ ์‚ฌ์šฉ channel.enableLights(true) channel.lightColor = Color.RED // ์ง€์ •ํ•œ ์ฑ„๋„ ์ •๋ณด๋ฅผ ํ†ตํ•ด์„œ ์ฑ„๋„ ์ƒ์„ฑ manager.createNotificationChannel(channel) // NotificationCompat ํƒ€์ž…์˜ ๊ฐ์ฒด ์ƒ์„ฑ builder = NotificationCompat.Builder(this, channelId) } else { builder = NotificationCompat.Builder(this) } // ์Šคํ…Œ์ด์Šคํ„ฐ์ฐฝ ์•Œ๋ฆผ ํ™”๋ฉด ์„ค์ • builder.setSmallIcon(android.R.drawable.ic_notification_overlay) builder.setWhen(System.currentTimeMillis()) builder.setContentTitle("์•Œ๋ฆผ") builder.setContentText("๋ฃจํ‹ด ์„ฑ๊ณต!") // NotificationManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์Šคํ…Œ์ดํ„ฐ์Šค์ฐฝ์— ์•Œ๋ฆผ์ฐฝ ์ถœ๋ ฅ manager.notify(11, builder.build()) } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/SplashActivity.kt
3916379667
package com.example.android_team4_project import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.os.Handler import android.os.Looper import com.example.android_team4_project.databinding.ActivitySplashBinding class SplashActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val binding = ActivitySplashBinding.inflate(layoutInflater) setContentView(binding.root) Handler(Looper.getMainLooper()).postDelayed({ val intent = Intent(this@SplashActivity,MainActivity::class.java) startActivity(intent) finish() }, 3000) } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/DetailActivitymon.kt
329312811
package com.example.android_team4_project import android.app.AlertDialog import android.app.Dialog import android.content.Context import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.view.View import android.widget.Button import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.example.android_team4_project.databinding.ActivityDetailBinding import com.google.firebase.auth.FirebaseAuth private lateinit var auth: FirebaseAuth private lateinit var userEmail: String class DetailActivitymon: AppCompatActivity() { private lateinit var binding: ActivityDetailBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityDetailBinding.inflate(layoutInflater) setContentView(binding.root) auth = FirebaseAuth.getInstance() val user = auth.currentUser userEmail = user?.uid ?: "" // ๋ฒ„ํŠผํด๋ฆญ์‹œ ๋งˆ์ด๋ฃจํ‹ด์œผ๋กœ ์ด๋™ binding.btnMypage.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MainActivity::class.java) startActivity(intent) } // ์ˆ˜์ •๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํ•ด๋‹น์š”์ผ ํŒ์—…์—‘ํ‹ฐ๋น„ํ‹ฐ binding.btnSaveAll.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, PopupActivitymon::class.java) startActivity(intent) } // ์‚ญ์ œ๋ฒ„ํŠผ ํด๋ฆญ์‹œ ์ €์žฅ๋‚ด์šฉ ์‚ญ์ œ // binding.btnCancel.setOnClickListener { // showDeleteConfirmationDialog() // } binding.btnCancel.setOnClickListener { val view = View.inflate(this, R.layout.dialog_view, null) val builder = androidx.appcompat.app.AlertDialog.Builder(this) builder.setView(view) val dialog = builder.create() dialog.setCanceledOnTouchOutside(false) dialog.show() val btnConfirm = view.findViewById<Button>(R.id.btn_confirm) val btnCancel = view.findViewById<Button>(R.id.btn_cancel) btnConfirm.setOnClickListener { showDeleteConfirmationDialog() Toast.makeText(this@DetailActivitymon, "์‚ญ์ œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค", Toast.LENGTH_SHORT).show() dialog.dismiss() } btnCancel.setOnClickListener { dialog.dismiss() } dialog.window?.setBackgroundDrawable(ColorDrawable(Color.WHITE)) } // SharedPreferences์—์„œ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ val sharedPrefTitlemon = getSharedPreferences("Routine_Mon$userEmail", Context.MODE_PRIVATE) // ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ val savedTitlemon = sharedPrefTitlemon.getString("title", "") val savedSpinnermon = sharedPrefTitlemon.getString("selectedSpinnerItem", "") val savedcon1mon = sharedPrefTitlemon.getString("con1", "") val savedcon2mon = sharedPrefTitlemon.getString("con2", "") val savedcon3mon = sharedPrefTitlemon.getString("con3", "") val savedcon4mon = sharedPrefTitlemon.getString("con4", "") val savedcon5mon = sharedPrefTitlemon.getString("con5", "") val savededm1mon = sharedPrefTitlemon.getString("edm1", "") val savededm2mon = sharedPrefTitlemon.getString("edm2", "") val savededm3mon = sharedPrefTitlemon.getString("edm3", "") val savededm4mon = sharedPrefTitlemon.getString("edm4", "") val savededm5mon = sharedPrefTitlemon.getString("edm5", "") val savededs1mon = sharedPrefTitlemon.getString("eds1", "") val savededs2mon = sharedPrefTitlemon.getString("eds2", "") val savededs3mon = sharedPrefTitlemon.getString("eds3", "") val savededs4mon = sharedPrefTitlemon.getString("eds4", "") val savededs5mon = sharedPrefTitlemon.getString("eds5", "") // ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํ…์ŠคํŠธ๋ทฐ์— ์„ค์ • binding.edTitle.text = savedTitlemon binding.spinner.text = savedSpinnermon binding.edContent1.text = savedcon1mon binding.edContent2.text = savedcon2mon binding.edContent3.text = savedcon3mon binding.edContent4.text = savedcon4mon binding.edContent5.text = savedcon5mon binding.edm1.text = savededm1mon binding.edm2.text = savededm2mon binding.edm3.text = savededm3mon binding.edm4.text = savededm4mon binding.edm5.text = savededm5mon binding.eds1.text = savededs1mon binding.eds2.text = savededs2mon binding.eds3.text = savededs3mon binding.eds4.text = savededs4mon binding.eds5.text = savededs5mon } private fun showDeleteConfirmationDialog() { val builder = AlertDialog.Builder(this) builder.setTitle("์ฃผ์˜") builder.setMessage("์‚ญ์ œํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?") builder.setPositiveButton("์‚ญ์ œ") { _, _ -> // ์‚ฌ์šฉ์ž๊ฐ€ ์‚ญ์ œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ–ˆ์„ ๋•Œ auth = FirebaseAuth.getInstance() val user = auth.currentUser userEmail = user?.uid ?: "" // RoutineData ๊ฐ์ฒด ์—…๋ฐ์ดํŠธ val routine = RoutineData( title = "", selectedSpinnerItem = "", con1 = "", con2 = "", con3 = "", con4 = "", con5 = "", edm1 = "", edm2 = "", edm3 = "", edm4 = "", edm5 = "", eds1 = "", eds2 = "", eds3 = "", eds4 = "", eds5 = "" ) // RoutineData ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ๋ฐ์ดํ„ฐ ์ƒ์„ฑ val xmlData = generateXmlData(routine, "Mon") // userEmail์„ ์ด์šฉํ•˜์—ฌ StorageManager๋ฅผ ์ดˆ๊ธฐํ™” val storageManager = StorageManager(this) // StorageManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ํŒŒ์ผ ์—…๋กœ๋“œ storageManager.uploadXmlFile(xmlData, "Mon") // SharedPreferences๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ์ €์žฅ val userUid = FirebaseAuth.getInstance().uid val sharedPrefTitlemon = getSharedPreferences("Routine_Mon$userUid", Context.MODE_PRIVATE) val editor = sharedPrefTitlemon.edit() editor.putString("title", routine.title) editor.putString("selectedSpinnerItem", routine.selectedSpinnerItem) editor.putString("con1", routine.con1) editor.putString("con2", routine.con2) editor.putString("con3", routine.con3) editor.putString("con4", routine.con4) editor.putString("con5", routine.con5) editor.putString("edm1", routine.edm1) editor.putString("edm2", routine.edm2) editor.putString("edm3", routine.edm3) editor.putString("edm4", routine.edm4) editor.putString("edm5", routine.edm5) editor.putString("eds1", routine.eds1) editor.putString("eds2", routine.eds2) editor.putString("eds3", routine.eds3) editor.putString("eds4", routine.eds4) editor.putString("eds5", routine.eds5) editor.apply() // ์ €์žฅ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ด๋ฃจ์–ด์ง€๋ฉด ์•กํ‹ฐ๋น„ํ‹ฐ ์ด๋™ val intent = Intent(this, MyActivity::class.java) startActivity(intent) finish() // ํ˜„์žฌ ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ์ข…๋ฃŒ } builder.setNegativeButton("์ทจ์†Œ") { dialog, _ -> // ์‚ฌ์šฉ์ž๊ฐ€ ์ทจ์†Œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ–ˆ์„ ๋•Œ dialog.dismiss() } val dialog: AlertDialog = builder.create() dialog.show() } private fun generateXmlData(routine: RoutineData, dayOfWeek:String): String { val xmlStringBuilder = StringBuilder() xmlStringBuilder.append("<routine>") xmlStringBuilder.append("<title>${routine.title}</title>") xmlStringBuilder.append("<con1>${routine.con1}</con1>") xmlStringBuilder.append("<con2>${routine.con2}</con2>") xmlStringBuilder.append("<con3>${routine.con3}</con3>") xmlStringBuilder.append("<con4>${routine.con4}</con4>") xmlStringBuilder.append("<con5>${routine.con5}</con5>") xmlStringBuilder.append("<edm1>${routine.edm1}</edm1>") xmlStringBuilder.append("<edm2>${routine.edm2}</edm2>") xmlStringBuilder.append("<edm3>${routine.edm3}</edm3>") xmlStringBuilder.append("<edm4>${routine.edm4}</edm4>") xmlStringBuilder.append("<edm5>${routine.edm5}</edm5>") xmlStringBuilder.append("<eds1>${routine.eds1}</eds1>") xmlStringBuilder.append("<eds2>${routine.eds2}</eds2>") xmlStringBuilder.append("<eds3>${routine.eds3}</eds3>") xmlStringBuilder.append("<eds4>${routine.eds4}</eds4>") xmlStringBuilder.append("<eds5>${routine.eds5}</eds5>") xmlStringBuilder.append("<selectedSpinnerItem>${routine.selectedSpinnerItem}</selectedSpinnerItem>") xmlStringBuilder.append("</routine>") return xmlStringBuilder.toString() } }
Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/PopupActivitysun.kt
3250191407
package com.example.android_team4_project import android.app.Dialog import android.content.Context import android.content.Intent import android.content.SharedPreferences import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.text.Editable import android.text.TextWatcher import android.widget.ArrayAdapter import android.widget.EditText import android.widget.ListView import android.widget.Spinner import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.example.android_team4_project.databinding.ActivityPopupBinding import com.google.firebase.auth.FirebaseAuth class PopupActivitysun : AppCompatActivity() { private lateinit var binding: ActivityPopupBinding private lateinit var userEmail: String private lateinit var arrayList: ArrayList<String> private lateinit var dialog: Dialog private lateinit var spinner: Spinner private lateinit var selectedSpinnerValue: String private lateinit var auth: FirebaseAuth override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityPopupBinding.inflate(layoutInflater) setContentView(binding.root) auth = FirebaseAuth.getInstance() val user = auth.currentUser userEmail = user?.uid ?: "" dialog = Dialog(this) val sharedPrefTitlesun = getSharedPreferences("Routine_Sun$userEmail", Context.MODE_PRIVATE) val routine = RoutineData( title = sharedPrefTitlesun.getString("title", "") ?: "", selectedSpinnerItem = sharedPrefTitlesun.getString("selectedSpinnerItem", "") ?: "", con1 = sharedPrefTitlesun.getString("con1", "") ?: "", con2 = sharedPrefTitlesun.getString("con2", "") ?: "", con3 = sharedPrefTitlesun.getString("con3", "") ?: "", con4 = sharedPrefTitlesun.getString("con4", "") ?: "", con5 = sharedPrefTitlesun.getString("con5", "") ?: "", edm1 = sharedPrefTitlesun.getString("edm1", "") ?: "", edm2 = sharedPrefTitlesun.getString("edm2", "") ?: "", edm3 = sharedPrefTitlesun.getString("edm3", "") ?: "", edm4 = sharedPrefTitlesun.getString("edm4", "") ?: "", edm5 = sharedPrefTitlesun.getString("edm5", "") ?: "", eds1 = sharedPrefTitlesun.getString("eds1", "") ?: "", eds2 = sharedPrefTitlesun.getString("eds2", "") ?: "", eds3 = sharedPrefTitlesun.getString("eds3", "") ?: "", eds4 = sharedPrefTitlesun.getString("eds4", "") ?: "", eds5 = sharedPrefTitlesun.getString("eds5", "") ?: "" ) initializeEditText(binding.edTitle, routine.title) routine.con1?.let { initializeEditText(binding.edContent1, it) } routine.con2?.let { initializeEditText(binding.edContent2, it) } routine.con3?.let { initializeEditText(binding.edContent3, it) } routine.con4?.let { initializeEditText(binding.edContent4, it) } routine.con5?.let { initializeEditText(binding.edContent5, it) } initializeEditText(binding.edm1, routine.edm1.toString()) initializeEditText(binding.edm2, routine.edm2.toString()) initializeEditText(binding.edm3, routine.edm3.toString()) initializeEditText(binding.edm4, routine.edm4.toString()) initializeEditText(binding.edm5, routine.edm5.toString()) initializeEditText(binding.eds1, routine.eds1.toString()) initializeEditText(binding.eds2, routine.eds2.toString()) initializeEditText(binding.eds3, routine.eds3.toString()) initializeEditText(binding.eds4, routine.eds4.toString()) initializeEditText(binding.eds5, routine.eds5.toString()) binding.spinner.setSelection(getSelectedSpinnerPosition(sharedPrefTitlesun, routine.selectedSpinnerItem)) binding.btnSaveAll.setOnClickListener { //Toast Toast.makeText(this,"์ผ์š”์ผ ๋ฃจํ‹ด์ด ์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.",Toast.LENGTH_SHORT).show() val edTitle = binding.edTitle.text.toString() val edCon1 = binding.edContent1.text.toString() val edCon2 = binding.edContent2.text.toString() val edCon3 = binding.edContent3.text.toString() val edCon4 = binding.edContent4.text.toString() val edCon5 = binding.edContent5.text.toString() val edm1 = binding.edm1.text.toString().toIntOrNull() ?: 0 val edm2 = binding.edm2.text.toString().toIntOrNull() ?: 0 val edm3 = binding.edm3.text.toString().toIntOrNull() ?: 0 val edm4 = binding.edm4.text.toString().toIntOrNull() ?: 0 val edm5 = binding.edm5.text.toString().toIntOrNull() ?: 0 val eds1 = binding.eds1.text.toString().toIntOrNull() ?: 0 val eds2 = binding.eds2.text.toString().toIntOrNull() ?: 0 val eds3 = binding.eds3.text.toString().toIntOrNull() ?: 0 val eds4 = binding.eds4.text.toString().toIntOrNull() ?: 0 val eds5 = binding.eds5.text.toString().toIntOrNull() ?: 0 // ์Šคํ”ผ๋„ˆ์—์„œ ์„ ํƒ๋œ ํ•ญ๋ชฉ์˜ ๊ฐ’์„ ๊ฐ€์ ธ์˜ค๊ธฐ val selectedSpinnerItem = binding.spinner.selectedItem.toString() // RoutineData ๊ฐ์ฒด ์—…๋ฐ์ดํŠธ val routine = RoutineData( title = edTitle, selectedSpinnerItem = selectedSpinnerItem, con1 = edCon1, con2 = edCon2, con3 = edCon3, con4 = edCon4, con5 = edCon5, edm1 = edm1.toString(), edm2 = edm2.toString(), edm3 = edm3.toString(), edm4 = edm4.toString(), edm5 = edm5.toString(), eds1 = eds1.toString(), eds2 = eds2.toString(), eds3 = eds3.toString(), eds4 = eds4.toString(), eds5 = eds5.toString() ) // RoutineData ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ๋ฐ์ดํ„ฐ ์ƒ์„ฑ val xmlData = generateXmlData(routine,"Sun") // userEmail์„ ์ด์šฉํ•˜์—ฌ StorageManager๋ฅผ ์ดˆ๊ธฐํ™” val storageManager = StorageManager(this) // StorageManager๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ XML ํŒŒ์ผ ์—…๋กœ๋“œ storageManager.uploadXmlFile(xmlData,"Sun") // SharedPreferences๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ์ €์žฅ val userUid = FirebaseAuth.getInstance().uid val sharedPrefTitlesun = getSharedPreferences("Routine_Sun$userUid", Context.MODE_PRIVATE) val editor = sharedPrefTitlesun.edit() editor.putString("title", routine.title) editor.putString("selectedSpinnerItem", routine.selectedSpinnerItem) editor.putString("con1", routine.con1) editor.putString("con2", routine.con2) editor.putString("con3", routine.con3) editor.putString("con4", routine.con4) editor.putString("con5", routine.con5) editor.putString("edm1", routine.edm1) editor.putString("edm2", routine.edm2) editor.putString("edm3", routine.edm3) editor.putString("edm4", routine.edm4) editor.putString("edm5", routine.edm5) editor.putString("eds1", routine.eds1) editor.putString("eds2", routine.eds2) editor.putString("eds3", routine.eds3) editor.putString("eds4", routine.eds4) editor.putString("eds5", routine.eds5) editor.apply() // ์ €์žฅ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ด๋ฃจ์–ด์ง€๋ฉด ์•กํ‹ฐ๋น„ํ‹ฐ ์ด๋™ val intent = Intent(this, MyActivity::class.java) startActivity(intent) finish() // ํ˜„์žฌ ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ์ข…๋ฃŒ } binding.btnCancel.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MyActivity::class.java) startActivity(intent) } // ๋ฒ„ํŠผํด๋ฆญ์‹œ ๋งˆ์ด๋ฃจํ‹ด์œผ๋กœ ์ด๋™ binding.btnMypage.setOnClickListener { // ์ด๋™ํ•  ์•กํ‹ฐ๋น„ํ‹ฐ์ฝ”๋“œ val intent = Intent(this, MainActivity::class.java) startActivity(intent) } // ์Šคํ”ผ๋„ˆ ๊ฐ์ฒด ์ƒ์„ฑ spinner = binding.spinner // // ์Šคํ”ผ๋„ˆ ํด๋ฆญ ์‹œ ๋‹ค์ด์–ผ๋กœ๊ทธ ๋„์šฐ๊ธฐ // spinner.setOnTouchListener { _, _ -> // showSearchableSpinnerDialog() // false // } // ์Šคํ”ผ๋„ˆ ํด๋ฆญ ์‹œ ๋‹ค์ด์–ผ๋กœ๊ทธ ๋„์šฐ๊ธฐ spinner.setOnTouchListener { _, _ -> if (dialog == null) { // ๋‹ค์ด์–ผ๋กœ๊ทธ๊ฐ€ ์ดˆ๊ธฐํ™”๋˜์ง€ ์•Š์•˜๋‹ค๋ฉด ์ดˆ๊ธฐํ™” ํ›„ ๋ณด์—ฌ์ฃผ๊ธฐ showSearchableSpinnerDialog() } else if (!dialog!!.isShowing) { // ๋‹ค์ด์–ผ๋กœ๊ทธ๊ฐ€ ์ดˆ๊ธฐํ™”๋˜์–ด ์žˆ๊ณ  ๋ณด์—ฌ์ง€์ง€ ์•Š๋Š” ์ƒํƒœ๋ผ๋ฉด ๋ณด์—ฌ์ฃผ๊ธฐ showSearchableSpinnerDialog() } true } // ์ดˆ๊ธฐํ™” arrayList = arrayListOf( "์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ" ) // ๋“œ๋กญ๋‹ค์šด ๋ฉ”๋‰ด์— ํ‘œ์‹œํ•  ํ•ญ๋ชฉ๋“ค val items = arrayOf("์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ") // ArrayAdapter๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋“œ๋กญ๋‹ค์šด ๋ฉ”๋‰ด์— ํ•ญ๋ชฉ๋“ค์„ ์—ฐ๊ฒฐ val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, items) adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spinner.adapter = adapter val items2 = arrayOf("์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ") // ์ €์žฅ๋œ ๊ฐ’์„ ๋ถˆ๋Ÿฌ์™€์„œ ์Šคํ”ผ๋„ˆ์— ๋Œ€์ž… val savedSpinnerItem = sharedPrefTitlesun.getString("selectedSpinnerItem", "") if (items2.contains(savedSpinnerItem)) { val positionInAdapter = items2.indexOf(savedSpinnerItem) binding.spinner.setSelection(positionInAdapter) } } // ์—…๋กœ๋“œํ•  ํŒŒ์ผ์— ์ €์žฅ๋  ๊ฐ’ ์„ค์ • private fun generateXmlData(routine: RoutineData, dayOfWeek:String): String { val xmlStringBuilder = StringBuilder() xmlStringBuilder.append("<routine>") xmlStringBuilder.append("<title>${routine.title}</title>") xmlStringBuilder.append("<con1>${routine.con1}</con1>") xmlStringBuilder.append("<con2>${routine.con2}</con2>") xmlStringBuilder.append("<con3>${routine.con3}</con3>") xmlStringBuilder.append("<con4>${routine.con4}</con4>") xmlStringBuilder.append("<con5>${routine.con5}</con5>") xmlStringBuilder.append("<edm1>${routine.edm1}</edm1>") xmlStringBuilder.append("<edm2>${routine.edm2}</edm2>") xmlStringBuilder.append("<edm3>${routine.edm3}</edm3>") xmlStringBuilder.append("<edm4>${routine.edm4}</edm4>") xmlStringBuilder.append("<edm5>${routine.edm5}</edm5>") xmlStringBuilder.append("<eds1>${routine.eds1}</eds1>") xmlStringBuilder.append("<eds2>${routine.eds2}</eds2>") xmlStringBuilder.append("<eds3>${routine.eds3}</eds3>") xmlStringBuilder.append("<eds4>${routine.eds4}</eds4>") xmlStringBuilder.append("<eds5>${routine.eds5}</eds5>") xmlStringBuilder.append("<selectedSpinnerItem>${routine.selectedSpinnerItem}</selectedSpinnerItem>") xmlStringBuilder.append("</routine>") return xmlStringBuilder.toString() } private fun initializeEditText(editText: EditText, value: String) { editText.setText(value) } private fun getSelectedSpinnerPosition(sharedPrefs: SharedPreferences, savedValue: String): Int { val items = arrayOf("์„ ํƒํ•˜๊ธฐ", "ํ•„๋ผํ…Œ์Šค", "๋งจ๋ชธ์šด๋™", "์š”๊ฐ€", "๋Ÿฌ๋‹", "๋กœ์ž‰์šด๋™", "์‚ฌ์ดํด๋ง", "์Šคํƒญํผ์šด๋™", "ํ•˜์ดํ‚น", "์›จ์ดํŠธ") return items.indexOf(savedValue).coerceAtLeast(0) } private fun showSearchableSpinnerDialog() { // dialog ์ดˆ๊ธฐํ™” dialog = Dialog(this) // dialog set dialog!!.setContentView(R.layout.dialog_searchable_spinner) dialog!!.window?.setLayout(650, 800) dialog!!.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog!!.show() val editText: EditText = dialog!!.findViewById(R.id.edit_text) val listView: ListView = dialog!!.findViewById(R.id.list_view) val dialogAdapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, arrayList) // ์–ด๋Œ‘ํ„ฐ ์„ค์ • listView.adapter = dialogAdapter editText.addTextChangedListener(object : TextWatcher { override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { dialogAdapter.filter.filter(s) } override fun afterTextChanged(s: Editable?) {} }) listView.setOnItemClickListener { _, _, position, _ -> // ์„ ํƒํ•œ ๊ฐ’์„ ํ”„๋กœํผํ‹ฐ์— ์„ค์ • selectedSpinnerValue = dialogAdapter.getItem(position).toString() val positionInAdapter = arrayList.indexOf(selectedSpinnerValue) // ์Šคํ”ผ๋„ˆ์— ์„ ํƒ๋œ ํ•ญ๋ชฉ ๋Œ€์ž… // val positionInAdapter = dialogAdapter.getPosition(selectedSpinnerValue) if (positionInAdapter != -1) { spinner.setSelection(positionInAdapter) } // ์‚ฌ์šฉ์ž๊ฐ€ ํ•ญ๋ชฉ ์„ ํƒํ•˜๋ฉด ๋‹ค์ด์–ผ๋กœ๊ทธ ๋‹ซ์Œ dialog!!.dismiss() } } }
Kotlin_Dasar/src/main/kotlin/TipeData.kt
3087652618
fun main(){ val byte:Byte = 1 val short:Short = 2 val int:Int = 3 val long:Long = 4 val float:Float = 5.0f val double:Double = 6.0 print("$byte $short $int $long $float $double \n") val string: String = "Kelvin" val char:Char = '7' val boolean:Boolean = true print("$string $char $boolean") }
Kotlin_Dasar/src/main/kotlin/Variable.kt
2350819743
fun main(){ val name = "Kelvin" var age = 20 age = 21 println("Hello $name you are ${age} years old") println(name) }
Kotlin_Dasar/src/main/kotlin/OperasiMatematika.kt
2259889313
fun main() { val a = 10 val b = 5 println("a + b = ${a + b}") println("a - b = ${a - b}") println("a * b = ${a * b}") println("a / b = ${a / b}") println("a % b = ${a % b}") }
Kotlin_Dasar/src/main/kotlin/Nullabe.kt
2591481121
fun main() { var nullable: String? = "Hello" nullable = null println(nullable) }
Kotlin_Dasar/src/main/kotlin/OperatorPerbandingan.kt
600369701
fun main() { val a = 10 val b = 20 println(a < b) println(a > b) println(a <= b) println(a >= b) println(a == b) println(a != b) }
Kotlin_Dasar/src/main/kotlin/String.kt
979494330
fun main(){ val escapeString:String = "\"Kelvin\" \n" println(escapeString) val rawString:String = """ Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups. """.trimIndent() println(rawString) val name:String = "Kelvin" val age:Int = 20 println("My name is $name" + " and I am $age years old \n") println("My Name And My Age is ${name + age}") var firstname:String = "AbuLahab" firstname = "Abu" println(firstname) }
Kotlin_Dasar/src/main/kotlin/Constant.kt
449855294
fun main() { println("Hello ${APP} ${APP_VERSION}") } const val APP = "App" const val APP_VERSION = "1.0.0" const val App
Kotlin_Dasar/src/main/kotlin/HelloWorld.kt
2386544438
fun main(){ println("Hello World") }
Kotlin_Dasar/src/main/kotlin/Array.kt
1234159183
fun main(){ val array: Array<Int> = arrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) var arrayString: Array<String> = arrayOf("Kiriyama","Souya","Buhab") val arrayList : Array<String> = arrayOf("Asu","Kuro","Shiho") println(array[0]) println(arrayList[1]) println(arrayList.set(1,"haram")) // for (i in array){ // println(i) // } // // for (i in arrayString){ // println(i) // } // // for (i in arrayList){ // println(i) // } }
Kotlin_Dasar/src/main/kotlin/List.kt
2306709338
fun main(){ val list: List<Int> = listOf(1, 2, 3) // Imurable hanya bisa Di baca Tidak bIsa Menambah, menghapus Data val listString:List<String> = listOf("satu", "dua", "tiga") for (i in listString){ println(i) } for (i in list){ println(i) } println(list.get(0)) // Memanggil data() val mutableList: MutableList<Int> = mutableListOf(1, 2, 3) // Mutable list bisa menambah data mutableList.add(4) println(mutableList[1]) // mutableList.removeAll(true) // Menghapus semua data yang bernilai true mutableList.removeAt(1) // Menghapus data pada index for (i in mutableList){ println(i) } println(mutableList.size) }
Kotlin_Dasar/src/main/kotlin/OperasiBoolena.kt
600369701
fun main() { val a = 10 val b = 20 println(a < b) println(a > b) println(a <= b) println(a >= b) println(a == b) println(a != b) }
Kotlin_Dasar/src/main/kotlin/IfElse.kt
351795807
fun main() { val a = 1 val b = 2 if (a > b) { println("a > b") } else if (a < b) { println("a < b") } else { println("a == b") } }
Kotlin_Dasar/src/main/kotlin/ControlFlow/When.kt
1278325347
fun main(){ val number :Int = 4 val hasil = when (number) { 1 -> "satu" 2 -> "dua" 3 -> "tiga" 4 -> "Bener" else -> "Salah" } println(hasil) // cek tyipe data var tipeData: Any = 20 when(tipeData){ is Int -> println("Int") is String -> println("String") is Boolean -> println("Boolean") else -> println("tidak diketahui") } }
Kotlin_Dasar/src/main/kotlin/ControlFlow/For Loop.kt
2523375934
package ControlFlow fun main(){ for (i in 1..10){ println("Range :$i ") } val arrayList:Array<Int> = arrayOf(1,2,3,4,5,6,7,8) for (i in arrayList){ println(i) } arrayList.forEach { println("it berisi data : $it") } var nilai = 1 while (nilai <= 10){ println("Nilai : $nilai") nilai++ } do { println("Nilai : $nilai") nilai++ } while (nilai <= 5) }
Kotlin_Dasar/src/main/kotlin/ControlFlow/WhileLoop.kt
2525085784
package ControlFlow fun main() { var i = 0 while (i < 10) { i++ println(i) } // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 var doWhile = 0 do { println(doWhile) doWhile++ } while (doWhile < 10) }
Kotlin_Dasar/src/main/kotlin/ControlFlow/Operator.kt
1418900425
package ControlFlow fun main(){ val hasilTambah = tambah(1,2) println(hasilTambah) } fun tambah(a: Int, b: Int): Int { return a + b } fun kurang(a: Int, b: Int): Int { return a - b } fun bagi(a: Int, b: Int): Int { return a / b } fun kali(a: Int, b: Int): Int { return a * b }
Kotlin_Dasar/src/main/kotlin/ControlFlow/IFElse.kt
4039268455
package ControlFlow fun main(){ val name:String = "" if (name === ""){ println("MuhKelvin") } else if (name === null){ println("Asu") } else{ println("Hasil Salah") } val nilai = 85 if (nilai >= 80){ println("Nilai A") } else if (nilai === 80){ println("Nilai B") } else { println("Noob") } }
Kotlin_Dasar/src/main/kotlin/ControlFlow/Jump Expression.kt
2985414219
package ControlFlow fun main(){ var nilai = 0 while (nilai < 10){ println("Nilai : $nilai") nilai++ if (nilai >= 5){ break } } var nilai2 = 0 while (nilai2 < 7){ if (nilai2 == 3){ continue } println(nilai2) nilai2++ } }
Kotlin_Dasar/src/main/kotlin/ControlFlow/Range.kt
2450067974
package ControlFlow fun main(){ val range = 1..10 val steps = 0..10 step 2 for(i in range){ println(i) // 1 2 3 4 5 6 7 8 9 10() } for (i in steps){ println("Lewati 2 angka : $i") } val rangeTo = 0.rangeTo(10) step 2 for (i in rangeTo){ println("Lewati 2 angka : $i") } val downTo = 10.downTo(0) step 2 for (i in downTo){ println("turun dan lewati 2 angka $i") } val nilai = 71 when (nilai){ in 0..50 -> println("Nilai anda $nilai") in 51..100 -> println("Nilai anda $nilai") else -> println("Nilai anda $nilai") } }
Kotlin_Dasar/src/main/kotlin/Conversion.kt
2199285021
fun main() { var number:Int = 20 var number2:Long = number.toLong() var duble:Double = number.toDouble() var float:Float = number.toFloat() var char:Char = number.toChar() var string:String = number.toString() }
Kotlin_Dasar/src/main/kotlin/FunctionParameter/Function.kt
272393489
package FunctionParameter fun main(){ sayHello() name("Daffa") identitity("Daffa", 20) println(sum(10, 20)) gega(1) singleExpression(2) val extension = "Daffa".hello() println(extension) println(returnIf("Daffa")) } fun sayHello(){ // function Tanpa parameter println("Hello Function") } fun name(name: String){ // function dengan parameter println("Hello $name") } fun identitity(name: String, age: Int){ // function dengan multiple parameter println("Hello $name, $age") } fun sum(a: Int, b: Int): Int{ // function dengan return value return a + b } fun singleExpression(a:Int):Int = a + 2 // single expression fun String.hello(){ println("Hello $this") // extension } fun gega(angka: Int){ if (angka % 2 == 0){ println("Angka $angka Genap") } else if (angka % 2 != 0){ println("Angka $angka Ganjil") } } fun returnIf(name:String = ""):String{ return if (name == "") "Guest" else name }
Kotlin_Dasar/src/main/kotlin/FunctionParameter/Lambda.kt
1891410413
package FunctionParameter fun main() { val lambdaName:(String) -> String = { it.toUpperCase() } val lamdaNumber:(Int) -> Int = {value -> value + 1 } val name = lambdaName("hello") println(name) val number = lamdaNumber(1) println(number) }
Kotlin_Dasar/src/main/kotlin/FunctionParameter/LambdaHighFunction.kt
2132655082
package FunctionParameter fun main(){ val sum = lambdaFuntion(1, 2) val sum2 = lambdaFuntion2(1, 2) println(sum2) println(sum) } val lambdaFuntion = { a: Int, b: Int -> a + b } val lambdaFuntion2: (Int, Int) -> Int = { a, b -> a + b } fun highOrderFunction(a: Int, b: Int, function: (Int, Int) -> Int): Int { return function(a, b) }
jiwonminsu/app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.kt
1188990709
package com.example.myapplication 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.myapplication", appContext.packageName) } }