content
stringlengths 0
13M
| path
stringlengths 4
263
| contentHash
stringlengths 1
10
|
---|---|---|
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/OperationKalkulator.kt | 3626460131 |
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
)
}
} | kalkulator_kotlin/app/src/main/java/com/example/challenge_rekamin_satu/ButtonKalkulator.kt | 2259160422 |
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/androidTest/java/com/example/android_team4_project/ExampleInstrumentedTest.kt | 1560122834 |
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/test/java/com/example/android_team4_project/ExampleUnitTest.kt | 3132026911 |
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/PopupActivitywed.kt | 821953153 |
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/MyActivity.kt | 335701514 |
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/StopActivity3.kt | 380985920 |
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/MyApplication.kt | 741804922 |
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/MainActivity.kt | 609781131 |
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/DetailActivitythu.kt | 2088746993 |
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/PopupActivityfri.kt | 3489493460 |
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/StopActivity2.kt | 3007358413 |
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/PopupActivitysat.kt | 2033505829 |
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/DetailActivitytue.kt | 1775559125 |
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/XmlParser.kt | 2097972070 |
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/RoutineData.kt | 134460480 |
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/PopupActivitymon.kt | 3823262506 |
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/DetailActivitysun.kt | 489716229 |
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/CountDownActivity.kt | 454382540 |
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/DetailActivitywed.kt | 3401914704 |
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/PopupActivitythu.kt | 3789211977 |
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/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 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/DetailActivitysat.kt | 3043087764 |
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/StopActivity1.kt | 1925380375 |
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/StorageManager.kt | 445392439 |
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/StopActivity5.kt | 43801426 |
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/LoginActivity.kt | 171898651 |
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/PopupActivitytue.kt | 68498841 |
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/StopActivity4.kt | 3051420169 |
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/SplashActivity.kt | 3916379667 |
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/DetailActivitymon.kt | 329312811 |
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()
}
}
} | Android_team_Project/android_team4_project/app/src/main/java/com/example/android_team4_project/PopupActivitysun.kt | 3250191407 |
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/TipeData.kt | 3087652618 |
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/Variable.kt | 2350819743 |
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/OperasiMatematika.kt | 2259889313 |
fun main() {
var nullable: String? = "Hello"
nullable = null
println(nullable)
} | Kotlin_Dasar/src/main/kotlin/Nullabe.kt | 2591481121 |
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/OperatorPerbandingan.kt | 600369701 |
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/String.kt | 979494330 |
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/Constant.kt | 449855294 |
fun main(){
println("Hello World")
} | Kotlin_Dasar/src/main/kotlin/HelloWorld.kt | 2386544438 |
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/Array.kt | 1234159183 |
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/List.kt | 2306709338 |
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/OperasiBoolena.kt | 600369701 |
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/IfElse.kt | 351795807 |
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/When.kt | 1278325347 |
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/For Loop.kt | 2523375934 |
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/WhileLoop.kt | 2525085784 |
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/Operator.kt | 1418900425 |
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/IFElse.kt | 4039268455 |
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/Jump Expression.kt | 2985414219 |
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/ControlFlow/Range.kt | 2450067974 |
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/Conversion.kt | 2199285021 |
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/Function.kt | 272393489 |
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/Lambda.kt | 1891410413 |
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)
}
| Kotlin_Dasar/src/main/kotlin/FunctionParameter/LambdaHighFunction.kt | 2132655082 |
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)
}
} | jiwonminsu/app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.kt | 1188990709 |
package com.example.myapplication
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)
}
} | jiwonminsu/app/src/test/java/com/example/myapplication/ExampleUnitTest.kt | 2019423820 |
package com.example.myapplication.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) | jiwonminsu/app/src/main/java/com/example/myapplication/ui/theme/Color.kt | 2513741509 |
package com.example.myapplication.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 MyApplicationTheme(
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
)
} | jiwonminsu/app/src/main/java/com/example/myapplication/ui/theme/Theme.kt | 196007232 |
package com.example.myapplication.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
)
*/
) | jiwonminsu/app/src/main/java/com/example/myapplication/ui/theme/Type.kt | 3481532690 |
package com.example.myapplication
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.example.myapplication.ui.theme.MyApplicationTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyApplicationTheme {
// A surface container using the 'background' color from the theme
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
Greeting("Android")
}
}
}
}
}
// git test
@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}
@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
MyApplicationTheme {
Greeting("Android")
}
} | jiwonminsu/app/src/main/java/com/example/myapplication/MainActivity.kt | 3231288311 |
package com.angrypenguin.mikesinventorysystem
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.angrypenguin.mikesinventorysystem", appContext.packageName)
}
} | MikesInventoryList/app/src/androidTest/java/com/angrypenguin/mikesinventorysystem/ExampleInstrumentedTest.kt | 4147614012 |
package com.angrypenguin.mikesinventorysystem.contacts
import android.database.sqlite.SQLiteDatabase
import com.angrypenguin.mikesinventorysystem.contracts.InventoryTable
import com.angrypenguin.mikesinventorysystem.data.InventoryItem
import io.mockk.mockk
import io.mockk.verify
import org.junit.Assert.assertTrue
import org.junit.Test
//class InventoryTableTest {
//
// private val db = mockk<SQLiteDatabase>(relaxed = true)
// private val table = InventoryTable()
//
// @Test
// fun `creates table if it doesn't exist`() {
// table.createTable(db)
//
// verify(db).execSQL(contains("CREATE TABLE IF NOT EXISTS"))
// }
//
// @Test
// fun `table exist check works`() {
// table.createTable(db)
//
// val exists = table.doesTableExist(db)
//
// assertTrue(exists)
// }
//
// @Test
// fun `can search inventory by partial match`() {
// // Populate some test data
//
// val results = table.searchInventory(db, "office")
//
// assertTrue(results.isNotEmpty())
// assertTrue(results[0].location.contains("office"))
// }
//
// @Test
// fun `can insert new item`() {
// val guid = "test_guid"
// val item = InventoryItem(guid = guid, ...)
//
// table.insertItem(db, item)
//
// verify(db).insert(TABLE_NAME, null, hasValue(guid))
// }
//
// @Test
// fun `can update existing item`() {
// // Insert
// val item = InventoryItem(...)
// table.insertItem(db, item)
//
// // Update
// item.qty = 15
// table.updateItem(db, item)
//
// verify(db).update(eq(TABLE_NAME), hasValue(15), any(), any())
// }
//} | MikesInventoryList/app/src/test/java/com/angrypenguin/mikesinventorysystem/contacts/InventoryClassTests.kt | 1812740749 |
package com.angrypenguin.mikesinventorysystem.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) | MikesInventoryList/app/src/main/java/com/angrypenguin/mikesinventorysystem/ui/theme/Color.kt | 738418412 |
package com.angrypenguin.mikesinventorysystem.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 MikesInventorySystemTheme(
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
)
} | MikesInventoryList/app/src/main/java/com/angrypenguin/mikesinventorysystem/ui/theme/Theme.kt | 2830503979 |
package com.angrypenguin.mikesinventorysystem.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
)
*/
) | MikesInventoryList/app/src/main/java/com/angrypenguin/mikesinventorysystem/ui/theme/Type.kt | 4192849162 |
package com.angrypenguin.mikesinventorysystem
import android.content.Intent
import android.database.sqlite.SQLiteDatabase
import android.net.Uri
import android.os.Bundle
import android.os.Environment
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import com.angrypenguin.mikesinventorysystem.components.screens.HomeScreen
import com.angrypenguin.mikesinventorysystem.contracts.DBHelper
import com.angrypenguin.mikesinventorysystem.contracts.InventoryTable
import com.angrypenguin.mikesinventorysystem.data.InventoryItem
import com.angrypenguin.mikesinventorysystem.ui.theme.MikesInventorySystemTheme
import java.io.File
import java.io.PrintWriter
class MainActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (!InventoryTable.doesTableExist(db!!)) {
InventoryTable.createTable(db!!)
}
setContent {
MikesInventorySystemTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
HomeScreen(this, ::exportFile);
}
}
}
}
private fun exportFile() {
var items = InventoryTable.getInventory(db!!)
// Get downloads path
val downloadsPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
// Create file in downloads folder
val file = File(downloadsPath, "mikeInventorySystem.txt")
// Write text to file
val writer = PrintWriter(file)
for (item in items) {
writer.println(item.toCSVRecord())
}
writer.close()
}
private val getContent = registerForActivityResult(ActivityResultContracts.GetContent()) { uri: Uri? ->
// Handle the returned uri
if (uri != null) {
val path = uri.path // file path
// Do something with the file
}
}
} | MikesInventoryList/app/src/main/java/com/angrypenguin/mikesinventorysystem/MainActivity.kt | 509938589 |
package com.angrypenguin.mikesinventorysystem
import android.database.sqlite.SQLiteDatabase
import android.os.Bundle
import androidx.activity.ComponentActivity
import com.angrypenguin.mikesinventorysystem.contracts.DBHelper
open class BaseActivity : ComponentActivity() {
var db: SQLiteDatabase? = null;
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val dbHelper = DBHelper(this)
db = dbHelper!!.writableDatabase
}
override fun onDestroy() {
super.onDestroy()
db?.close()
}
} | MikesInventoryList/app/src/main/java/com/angrypenguin/mikesinventorysystem/BaseActivity.kt | 493832665 |
package com.angrypenguin.mikesinventorysystem.contracts
import android.content.ContentValues
import android.database.Cursor
import android.database.sqlite.SQLiteDatabase
import com.angrypenguin.mikesinventorysystem.data.InventoryItem
import java.util.Date
class InventoryTable {
companion object {
const val TABLE_NAME = "INVENTORY"
const val COLUMN_NAME_GUID = "GUID"
const val COLUMN_NAME_BARCODE = "BARCODE"
const val COLUMN_NAME_NAME = "NAME"
const val COLUMN_NAME_QTY = "QTY"
const val COLUMN_NAME_LOCATION = "LOCATION"
const val COLUMN_NAME_DATE = "DATE"
fun createTable(db: SQLiteDatabase) {
val createTableSql = """
CREATE TABLE IF NOT EXISTS $TABLE_NAME (
$COLUMN_NAME_GUID TEXT PRIMARY KEY,
$COLUMN_NAME_BARCODE TEXT,
$COLUMN_NAME_NAME TEXT,
$COLUMN_NAME_QTY INTEGER,
$COLUMN_NAME_LOCATION TEXT,
$COLUMN_NAME_DATE DATETIME
)
""".trimIndent()
db.execSQL(createTableSql)
}
fun doesTableExist(db: SQLiteDatabase): Boolean {
val cursor = db.rawQuery(
"SELECT name FROM sqlite_master WHERE type='table' AND name='$TABLE_NAME'",
null
)
val exists = cursor.count > 0
cursor.close()
return exists
}
fun getItem(db: SQLiteDatabase, guid: String): InventoryItem? {
lateinit var item: InventoryItem
val cursor = db.query(
TABLE_NAME,
null,
"${COLUMN_NAME_GUID} = ?",
arrayOf(guid),
null,
null,
null
)
if (cursor.moveToFirst()) {
item = get_item_from_cursor(cursor)
} else {
return null;
}
cursor.close();
return item;
}
fun searchInventory(db: SQLiteDatabase, query: String): List<InventoryItem> {
val selection = """
$COLUMN_NAME_BARCODE LIKE ?
OR $COLUMN_NAME_NAME LIKE ?
OR $COLUMN_NAME_LOCATION LIKE ?
"""
val selectionArgs = arrayOf(
"%$query%",
"%$query%",
"%$query%"
)
var cursor = db.query(
TABLE_NAME,
null,
selection,
selectionArgs,
null,
null,
null
)
val items = mutableListOf<InventoryItem>()
while (cursor.moveToNext()) {
val item = get_item_from_cursor(cursor)
items.add(item)
}
cursor.close()
return items
}
fun getInventory(db: SQLiteDatabase): List<InventoryItem> {
var cursor = db.query(
TABLE_NAME,
null,
null,
null,
null,
null,
null
)
val items = mutableListOf<InventoryItem>()
while (cursor.moveToNext()) {
val item = get_item_from_cursor(cursor)
items.add(item)
}
cursor.close()
return items
}
fun insertItem(db: SQLiteDatabase, item: InventoryItem) {
val values = ContentValues().apply {
put(COLUMN_NAME_GUID, item.guid)
put(COLUMN_NAME_BARCODE, item.barcode)
put(COLUMN_NAME_NAME, item.name)
put(COLUMN_NAME_QTY, item.qty)
put(COLUMN_NAME_LOCATION, item.location)
put(COLUMN_NAME_DATE, item.date.time)
}
db.insert(TABLE_NAME, null, values)
}
fun updateItem(db: SQLiteDatabase, item: InventoryItem) {
val values = ContentValues().apply {
put(COLUMN_NAME_BARCODE, item.barcode)
put(COLUMN_NAME_NAME, item.name)
put(COLUMN_NAME_QTY, item.qty)
put(COLUMN_NAME_LOCATION, item.location)
put(COLUMN_NAME_DATE, item.date.time)
}
db.update(TABLE_NAME, values, "$COLUMN_NAME_GUID = ?", arrayOf(item.guid))
}
fun deleteItem(db: SQLiteDatabase, item: InventoryItem) {
db.delete(TABLE_NAME, "$COLUMN_NAME_GUID = ?", arrayOf(item.guid))
}
private fun get_item_from_cursor(cursor: Cursor) : InventoryItem {
return InventoryItem(
cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_NAME_GUID)),
cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_NAME_BARCODE)),
cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_NAME_NAME)),
cursor.getInt(cursor.getColumnIndexOrThrow(COLUMN_NAME_QTY)),
cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_NAME_LOCATION)),
Date(cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_NAME_DATE)))
)
}
}
} | MikesInventoryList/app/src/main/java/com/angrypenguin/mikesinventorysystem/contracts/IntentoryContract.kt | 3465622113 |
package com.angrypenguin.mikesinventorysystem.contracts
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
const val DB_NAME = "MikesInventorySystem"
const val DB_VERSION = 1
class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) {
override fun onCreate(db: SQLiteDatabase) {}
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {}
} | MikesInventoryList/app/src/main/java/com/angrypenguin/mikesinventorysystem/contracts/MyDBHelper.kt | 1448238636 |
package com.angrypenguin.mikesinventorysystem
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import com.angrypenguin.mikesinventorysystem.components.screens.AddNewItem
import com.angrypenguin.mikesinventorysystem.contracts.InventoryTable
import com.angrypenguin.mikesinventorysystem.models.InventoryItemModel
import com.angrypenguin.mikesinventorysystem.ui.theme.MikesInventorySystemTheme
class AddNewItemActivity : BaseActivity() {
private val viewModel: InventoryItemModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
var guid = intent.getStringExtra("guid")
var from_search = intent.getBooleanExtra("from_search", false)
if (guid != null) {
viewModel.setGuid(guid)
var item = InventoryTable.getItem(db!!, guid!!)
if (item != null) {
viewModel.barcode.value = item.barcode
viewModel.name.value = item.name
viewModel.location.value = item.location
viewModel.date.value = item.date
viewModel.qty.value = item.qty
}
}
setContent {
MikesInventorySystemTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
AddNewItem(this, guid, from_search, viewModel)
}
}
}
}
} | MikesInventoryList/app/src/main/java/com/angrypenguin/mikesinventorysystem/AddNewItemActivity.kt | 303237493 |
package com.angrypenguin.mikesinventorysystem.models
import android.database.sqlite.SQLiteDatabase
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.angrypenguin.mikesinventorysystem.contracts.InventoryTable
import com.angrypenguin.mikesinventorysystem.data.InventoryItem
class InventoryListModel : ViewModel() {
var list = MutableLiveData<MutableList<InventoryItem>>(mutableListOf())
var input = "";
fun updateList(db: SQLiteDatabase, input: String) {
this.input = input
list.value = InventoryTable.searchInventory(db, input).toMutableList()
}
fun updateList(db:SQLiteDatabase) {
list.value = InventoryTable.searchInventory(db, input).toMutableList()
}
fun deleteItem(db: SQLiteDatabase, item: InventoryItem) {
InventoryTable.deleteItem(db, item)
updateList(db)
}
} | MikesInventoryList/app/src/main/java/com/angrypenguin/mikesinventorysystem/models/InventoryListModel.kt | 2295577974 |
package com.angrypenguin.mikesinventorysystem.models
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.angrypenguin.mikesinventorysystem.data.InventoryItem
import java.util.Date
class InventoryItemModel : ViewModel() {
private var guid: String? = null;
var barcode = MutableLiveData("")
var name = MutableLiveData("")
var qty = MutableLiveData(1)
var location = MutableLiveData("")
var date = MutableLiveData(Date())
fun setGuid(guid: String) {
this.guid = guid;
}
fun getInventoryItem(): InventoryItem {
if (guid != null) {
return InventoryItem(
guid!!,
barcode.value!!,
name.value!!,
qty.value!!,
location.value!!,
date.value!!
)
}
return InventoryItem(
barcode.value!!,
name.value!!,
qty.value!!,
location.value!!,
date.value!!
)
}
} | MikesInventoryList/app/src/main/java/com/angrypenguin/mikesinventorysystem/models/InventoryItemModel.kt | 1236621065 |
package com.angrypenguin.mikesinventorysystem
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import androidx.lifecycle.viewmodel.compose.viewModel
import com.angrypenguin.mikesinventorysystem.components.screens.SearchScreen
import com.angrypenguin.mikesinventorysystem.data.InventoryItem
import com.angrypenguin.mikesinventorysystem.models.InventoryItemModel
import com.angrypenguin.mikesinventorysystem.models.InventoryListModel
import com.angrypenguin.mikesinventorysystem.ui.theme.MikesInventorySystemTheme
class SearchActivity : BaseActivity() {
private val viewModel: InventoryListModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
var searchBar = intent.getBooleanExtra("SEARCH_BAR", true)
setContent {
MikesInventorySystemTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
SearchScreen(db!!, viewModel, ::deleteItem, searchBar)
}
}
}
}
override fun onResume() {
super.onResume()
viewModel.updateList(db!!)
}
private fun deleteItem(item: InventoryItem) {
viewModel.deleteItem(db!!, item)
}
} | MikesInventoryList/app/src/main/java/com/angrypenguin/mikesinventorysystem/SearchActivity.kt | 2784392400 |
package com.angrypenguin.mikesinventorysystem.components.screens
import android.content.Context
import android.content.Intent
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.angrypenguin.mikesinventorysystem.AddNewItemActivity
import com.angrypenguin.mikesinventorysystem.SearchActivity
@Composable
fun HomeScreen(context: Context, exportFile: () -> Unit) {
Column(
modifier = Modifier
.fillMaxWidth(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Button(
onClick = {
val intent = Intent(context, AddNewItemActivity::class.java)
context.startActivity(intent)
},
content = {
Text (text = "Add New Items")
},
modifier = Modifier
.fillMaxWidth(1F)
.align(Alignment.CenterHorizontally)
.padding(8.dp)
)
Button(
onClick = {
val intent = Intent(context, SearchActivity::class.java)
context.startActivity(intent)
},
content = {
Text (text = "Search")
},
modifier = Modifier
.fillMaxWidth(1F)
.align(Alignment.CenterHorizontally)
.padding(8.dp)
)
Button(
onClick = {
val intent = Intent(context, SearchActivity::class.java)
intent.putExtra("SEARCH_BAR", false)
context.startActivity(intent)
},
content = {
Text (text = "View All")
},
modifier = Modifier
.fillMaxWidth(1F)
.align(Alignment.CenterHorizontally)
.padding(8.dp)
)
Button(
onClick = {
exportFile()
},
content = {
Text (text = "Export")
},
modifier = Modifier
.fillMaxWidth(1F)
.align(Alignment.CenterHorizontally)
.padding(8.dp)
)
}
} | MikesInventoryList/app/src/main/java/com/angrypenguin/mikesinventorysystem/components/screens/HomeScreen.kt | 2398942848 |
package com.angrypenguin.mikesinventorysystem.components.screens
import android.content.Intent
import android.database.sqlite.SQLiteDatabase
import android.graphics.drawable.Icon
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
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.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import com.angrypenguin.mikesinventorysystem.AddNewItemActivity
import com.angrypenguin.mikesinventorysystem.contracts.InventoryTable
import com.angrypenguin.mikesinventorysystem.data.InventoryItem
import com.angrypenguin.mikesinventorysystem.models.InventoryListModel
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SearchScreen(db: SQLiteDatabase,
viewModel: InventoryListModel,
deleteItem: (item: InventoryItem) -> Unit,
searchBar: Boolean) {
var context = LocalContext.current
var input by remember { mutableStateOf("") }
val items by viewModel.list.observeAsState()
Column(
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally
) {
if (searchBar) {
Row() {
OutlinedTextField(
label = {
Text(
text = "Search"
)
},
value = input,
onValueChange = {
input = it
viewModel.updateList(db, input)
}
)
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.padding(15.dp)
.clickable {
val intent = Intent(context, AddNewItemActivity::class.java)
intent.putExtra("from_search", true)
context.startActivity(intent)
}
) {
Icon(
Icons.Default.Add,
contentDescription = "Add New Item",
modifier = Modifier
.background(Color.LightGray, RoundedCornerShape(8.dp))
.padding(10.dp)
)
}
}
}
ListInventoryScreen(items = items!!, deleteItem)
}
} | MikesInventoryList/app/src/main/java/com/angrypenguin/mikesinventorysystem/components/screens/SearchScreen.kt | 790400947 |
package com.angrypenguin.mikesinventorysystem.components.screens
import android.content.Context
import android.content.Intent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import com.angrypenguin.mikesinventorysystem.AddNewItemActivity
import com.angrypenguin.mikesinventorysystem.BaseActivity
import com.angrypenguin.mikesinventorysystem.contracts.InventoryTable
import com.angrypenguin.mikesinventorysystem.models.InventoryItemModel
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AddNewItem(context: Context, guid: String?, from_search: Boolean, viewModel: InventoryItemModel) {
var activity = LocalContext.current as BaseActivity
val barcode by viewModel.barcode.observeAsState("")
val name by viewModel.name.observeAsState("")
var qtyString by remember { mutableStateOf("")}
val location by viewModel.location.observeAsState("")
val date by viewModel.date.observeAsState(initial = Date())
val formatter = SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH)
var dateString by remember { mutableStateOf(formatter.format(date)) }
Column(
horizontalAlignment = Alignment.CenterHorizontally
) {
OutlinedTextField(
label = {
Text (
text = "Barcode"
)
},
value = barcode,
onValueChange = {
viewModel.barcode.value = it
}
)
OutlinedTextField(
label = {
Text (
text = "Name"
)
},
value = name,
onValueChange = {
viewModel.name.value = it
}
)
OutlinedTextField(
label = {
Text (
text = "Quantity"
)
},
value = qtyString,
onValueChange = {
qtyString = it
try {
viewModel.qty.value = it.toInt()
} catch (e: Exception){
//do nothing
}
},
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number)
)
OutlinedTextField(
label = {
Text (
text = "Location"
)
},
value = location,
onValueChange = {
viewModel.location.value = it
}
)
OutlinedTextField(
value = dateString,
label = {
Text (
text = "Date"
)
},
onValueChange = {
try {
dateString = it
viewModel.date.value = formatter.parse(dateString)
} catch (e: Exception) {
}
}
)
Button(
onClick = {
activity?.db?.let {
var item = viewModel.getInventoryItem()
if (guid == null) {
InventoryTable.insertItem(it,item)
if (!from_search) {
val intent = Intent(context, AddNewItemActivity::class.java)
context.startActivity(intent)
}
} else {
InventoryTable.updateItem(it, item)
}
}
activity?.finish();
},
content = {
Text (text = "Save")
},
modifier = Modifier
.fillMaxWidth(1F)
.align(Alignment.CenterHorizontally)
.padding(8.dp)
)
}
} | MikesInventoryList/app/src/main/java/com/angrypenguin/mikesinventorysystem/components/screens/AddNewItem.kt | 176532236 |
package com.angrypenguin.mikesinventorysystem.components.screens
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.angrypenguin.mikesinventorysystem.components.listitems.InventoryListItem
import com.angrypenguin.mikesinventorysystem.data.InventoryItem
@Composable
fun ListInventoryScreen(items: List<InventoryItem>, deleteItem: (item: InventoryItem) -> Unit) {
Column(
modifier = Modifier.padding(10.dp)
) {
Text(
text = "Inventory List:",
style = TextStyle(
fontSize = 18.sp
)
)
LazyColumn() {
items(items = items) { item ->
InventoryListItem(item = item, deleteItem)
}
}
}
} | MikesInventoryList/app/src/main/java/com/angrypenguin/mikesinventorysystem/components/screens/ListInventoryScreen.kt | 264058255 |
package com.angrypenguin.mikesinventorysystem.components.listitems
import android.content.Intent
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import com.angrypenguin.mikesinventorysystem.AddNewItemActivity
import com.angrypenguin.mikesinventorysystem.data.InventoryItem
import java.text.SimpleDateFormat
import java.util.Locale
@Composable
fun InventoryListItem(item: InventoryItem, deleteItem: (item: InventoryItem) -> Unit) {
val context = LocalContext.current
Column(
modifier = Modifier
.fillMaxWidth()
.padding(4.dp)
.border(BorderStroke(1.5.dp, Color.Black), RoundedCornerShape(10.dp))
.padding(10.dp)
.clickable {
val intent = Intent(context, AddNewItemActivity::class.java)
intent.putExtra("guid", item.guid);
context.startActivity(intent)
},
) {
Row() {
Text(
text = item.name,
modifier = Modifier.weight(1f)
)
Text(
text = "Qty: ${item.qty}"
)
}
Row() {
Box(
Modifier.weight(1f)
) {
Text(
text = item.location
)
}
Text(
text = item.barcode
)
}
Row() {
Box(
Modifier.weight(1f)
) {
val formatter = SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH)
Text(
text = formatter.format(item.date)
)
}
Box(
Modifier.weight(1f)
) {
Icon(
Icons.Default.Delete,
contentDescription = "Delete Item",
modifier = Modifier
.background(Color.LightGray, RoundedCornerShape(8.dp))
.padding(10.dp)
.clickable{
deleteItem(item)
}
)
}
}
}
} | MikesInventoryList/app/src/main/java/com/angrypenguin/mikesinventorysystem/components/listitems/InventoryListItem.kt | 4248096691 |
package com.angrypenguin.mikesinventorysystem.data
enum class State {
HomeScreen,
AddNewItem,
} | MikesInventoryList/app/src/main/java/com/angrypenguin/mikesinventorysystem/data/State.kt | 2479503127 |
package com.angrypenguin.mikesinventorysystem.data
import java.util.Date
import java.util.UUID
class InventoryItem {
var guid: String = UUID.randomUUID().toString()
var barcode: String = ""
var name: String = ""
var qty: Int = 1
var location: String = ""
var date: Date = Date()
constructor()
constructor(
barcode: String,
name: String,
qty: Int = 1,
location: String = "",
date: Date = Date()
) {
this.barcode = barcode
this.name = name
this.qty = qty
this.location = location
this.date = date
}
constructor(
guid: String,
barcode: String,
name: String,
qty: Int = 1,
location: String = "",
date: Date = Date()
) {
this.guid = guid
this.barcode = barcode
this.name = name
this.qty = qty
this.location = location
this.date = date
}
fun toCSVRecord() : String {
return "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\""
.format(
guid,
barcode,
name,
qty,
location,
date
)
}
} | MikesInventoryList/app/src/main/java/com/angrypenguin/mikesinventorysystem/data/InventoryItem.kt | 4130651348 |
package com.example.firebasegroupapp1
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.firebasegroupapp1", appContext.packageName)
}
} | e-commerce-android-app-with-Kotlin/app/src/androidTest/java/com/example/firebasegroupapp1/ExampleInstrumentedTest.kt | 27666528 |
package com.example.firebasegroupapp1
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)
}
} | e-commerce-android-app-with-Kotlin/app/src/test/java/com/example/firebasegroupapp1/ExampleUnitTest.kt | 3789899055 |
package com.example.firebasegroupapp1
data class Product (
var name: String = "",
var price: Double = 0.0,
var image: String = "",
var description: String = ""
) | e-commerce-android-app-with-Kotlin/app/src/main/java/com/example/firebasegroupapp1/Product.kt | 499895552 |
package com.example.firebasegroupapp1
import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.widget.ImageView
import android.content.res.Configuration
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.firebase.ui.database.FirebaseRecyclerOptions
import com.google.android.material.appbar.MaterialToolbar
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.database.FirebaseDatabase
class ProductActivity : AppCompatActivity() {
private lateinit var adapter: ProductAdapter
private lateinit var auth: FirebaseAuth
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_product)
val topAppBar: MaterialToolbar = findViewById(R.id.top_app_bar)
setSupportActionBar(topAppBar)
supportActionBar?.title = "Products"
auth = FirebaseAuth.getInstance()
val query = FirebaseDatabase.getInstance().reference.child("Products")
val options = FirebaseRecyclerOptions.Builder<Product>().setQuery(query, Product::class.java).build()
adapter = ProductAdapter(options)
val productsRecyclerView: RecyclerView = findViewById(R.id.productsRecyclerView)
productsRecyclerView.adapter = adapter
val layoutManager = if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
GridLayoutManager(this, 3)
} else {
GridLayoutManager(this, 2)
}
productsRecyclerView.layoutManager = layoutManager
val logoutButton: ImageView = findViewById(R.id.logoutButton)
logoutButton.setOnClickListener {
FirebaseAuth.getInstance().signOut()
startActivity(Intent(this, MainActivity::class.java))
finish()
}
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu_main, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.action_products -> {
true
}
R.id.action_orders -> {
startActivity(Intent(this, OrderActivity::class.java))
true
}
else -> super.onOptionsItemSelected(item)
}
}
override fun onStart() {
super.onStart()
adapter.startListening()
}
} | e-commerce-android-app-with-Kotlin/app/src/main/java/com/example/firebasegroupapp1/ProductActivity.kt | 2684098120 |
package com.example.firebasegroupapp1
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.firebase.ui.database.FirebaseRecyclerAdapter
import com.firebase.ui.database.FirebaseRecyclerOptions
import com.google.firebase.storage.FirebaseStorage
class OrderAdapter(options: FirebaseRecyclerOptions<Order>)
: FirebaseRecyclerAdapter<Order, OrderAdapter.OrderViewHolder>(options) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): OrderViewHolder {
val inflater = LayoutInflater.from(parent.context)
return OrderViewHolder(inflater, parent)
}
override fun onBindViewHolder(holder: OrderViewHolder, position: Int, model: Order) {
holder.fullNameTextView.text = model.fullName
holder.productNameTextView.text = model.productName
holder.quantityTextView.text = model.quantity.toString()
holder.totalPriceTextView.text = "$" + model.totalPrice.toString()
holder.addressTextView.text = model.address
val theImage: String = model.productImage
if (theImage.indexOf("gs://") >-1) {
val storageReference = FirebaseStorage.getInstance().getReferenceFromUrl(theImage)
Glide.with(holder.productImageView.context)
.load(storageReference)
.into(holder.productImageView)
} else {
Glide.with(holder.productImageView.context)
.load(theImage)
.into(holder.productImageView)
}
}
class OrderViewHolder(inflater: LayoutInflater, parent: ViewGroup) :
RecyclerView.ViewHolder(inflater.inflate(R.layout.order_item, parent, false)) {
val fullNameTextView: TextView = itemView.findViewById(R.id.fullNameTextView)
val productNameTextView: TextView = itemView.findViewById(R.id.productNameTextView)
val quantityTextView: TextView = itemView.findViewById(R.id.quantityTextView)
val totalPriceTextView: TextView = itemView.findViewById(R.id.totalPriceTextView)
val addressTextView: TextView = itemView.findViewById(R.id.addressTextView)
val productImageView: ImageView = itemView.findViewById(R.id.productImageView)
}
} | e-commerce-android-app-with-Kotlin/app/src/main/java/com/example/firebasegroupapp1/OrderAdapter.kt | 299996320 |
package com.example.firebasegroupapp1
import android.content.Intent
import android.os.Bundle
import com.google.android.material.snackbar.Snackbar
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController
import android.view.Menu
import android.view.MenuItem
import android.widget.Button
import com.example.firebasegroupapp1.databinding.ActivityMainBinding
import com.google.firebase.auth.FirebaseAuth
import com.firebase.ui.auth.AuthUI
import com.firebase.ui.auth.FirebaseUiUserCollisionException
import com.firebase.ui.auth.FirebaseAuthUIActivityResultContract
import com.firebase.ui.auth.data.model.FirebaseAuthUIAuthenticationResult
import com.google.firebase.auth.FirebaseUser
import android.widget.TextView
class MainActivity : AppCompatActivity() {
private lateinit var auth: FirebaseAuth
private lateinit var appBarConfiguration: AppBarConfiguration
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
auth = FirebaseAuth.getInstance()
val currentUser = auth.currentUser
if (currentUser == null) {
createSignInIntent()
} else {
loadUIDesign(currentUser)
}
}
private fun createSignInIntent() {
val providers = arrayListOf(AuthUI.IdpConfig.EmailBuilder().build())
val signInIntent = AuthUI.getInstance()
.createSignInIntentBuilder()
.setIsSmartLockEnabled(false)
.setAvailableProviders(providers)
.build()
signInLauncher.launch(signInIntent)
}
private val signInLauncher = registerForActivityResult(FirebaseAuthUIActivityResultContract()) { result ->
this.onSignInResult(result)
}
private fun onSignInResult(result: FirebaseAuthUIAuthenticationResult) {
if (result.resultCode == RESULT_OK) {
val user = FirebaseAuth.getInstance().currentUser
user?.let { loadUIDesign(it) }
} else {
createSignInIntent()
}
}
private fun loadUIDesign(user: FirebaseUser) {
setContentView(R.layout.activity_main)
val fullName = user.displayName
val fullNameTextView = findViewById<TextView>(R.id.fullNameTextView)
fullNameTextView.text = fullName
val shopButton: Button = findViewById(R.id.shop_button)
shopButton.setOnClickListener {
startActivity(Intent(this, ProductActivity::class.java))
}
}
} | e-commerce-android-app-with-Kotlin/app/src/main/java/com/example/firebasegroupapp1/MainActivity.kt | 3222537099 |
package com.example.firebasegroupapp1
import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import com.bumptech.glide.Glide
import android.view.MenuItem
import com.google.firebase.storage.FirebaseStorage
import com.google.firebase.auth.FirebaseAuth
class ProductDetailActivity : AppCompatActivity() {
private var quantity: Int = 1
private lateinit var txtQuantity: TextView
private lateinit var topAppBar: Toolbar
var productImage : String? = ""
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_product_detail)
topAppBar = findViewById(R.id.top_app_bar)
setSupportActionBar(topAppBar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.title = "Product Detail"
val productName = intent.getStringExtra("productName")
val productPrice = intent.getDoubleExtra("productPrice", 0.0)
productImage = intent.getStringExtra("productImage")
val productDescription = intent.getStringExtra("productDescription")
val txtProductName: TextView = findViewById(R.id.txtProductName)
val txtProductPrice: TextView = findViewById(R.id.txtProductPrice)
val txtProductDescription: TextView = findViewById(R.id.txtProductDescription)
val productImageView: ImageView = findViewById(R.id.productImageView)
var totalPrice = roundToTwoDecimalPlaces(productPrice)
txtProductName.text = " $productName"
txtProductPrice.text = "Price: $$totalPrice"
txtProductDescription.text = "$productDescription"
txtQuantity = findViewById(R.id.txtQuantity)
txtQuantity.text = quantity.toString()
val theImage: String = productImage ?: ""
if (theImage.indexOf("gs://") > -1) {
val storageReference = FirebaseStorage.getInstance().getReferenceFromUrl(theImage)
Glide.with(this)
.load(storageReference)
.into(productImageView)
} else {
Glide.with(this)
.load(theImage)
.into(productImageView)
}
val btnPlus: Button = findViewById(R.id.btnPlus)
val btnMinus: Button = findViewById(R.id.btnMinus)
btnPlus.setOnClickListener {
incrementQuantity()
}
btnMinus.setOnClickListener {
decrementQuantity()
}
val btnCheckout: Button = findViewById(R.id.btnCheckout)
btnCheckout.setOnClickListener {
checkout(productName, quantity, productPrice, productImage)
}
}
fun roundToTwoDecimalPlaces(number: Double): Double {
return "%.2f".format(number).toDouble()
}
private fun incrementQuantity() {
if (quantity < 10) {
quantity++
updateQuantityTextView()
} else {
showToast("Maximum quantity reached")
}
}
private fun decrementQuantity() {
if (quantity > 1) {
quantity--
updateQuantityTextView()
} else {
showToast("Minimum quantity reached")
}
}
private fun showToast(message: String) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
}
private fun updateQuantityTextView() {
txtQuantity.text = quantity.toString()
}
private fun checkout(productName: String?, quantity: Int, productPrice: Double, productImage: String?) {
val totalPrice = roundToTwoDecimalPlaces(quantity * productPrice)
val intent = Intent(this, CheckoutActivity::class.java).apply {
putExtra("productName", productName)
putExtra("quantity", quantity)
putExtra("totalPrice", totalPrice)
putExtra("productImage", productImage)
putExtra("fullName", FirebaseAuth.getInstance().currentUser?.displayName)
}
startActivity(intent)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
android.R.id.home -> {
super.onBackPressed()
true
}
else -> super.onOptionsItemSelected(item)
}
}
} | e-commerce-android-app-with-Kotlin/app/src/main/java/com/example/firebasegroupapp1/ProductDetailActivity.kt | 2420022923 |
package com.example.firebasegroupapp1
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.view.Menu
import android.widget.Toast
import android.widget.ImageView
import android.widget.TextView
import android.view.MenuItem
import android.content.res.Configuration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.GridLayoutManager
import com.google.android.material.appbar.MaterialToolbar
import com.google.firebase.database.FirebaseDatabase
import com.firebase.ui.database.FirebaseRecyclerOptions
import com.google.firebase.auth.FirebaseAuth
class OrderActivity : AppCompatActivity() {
private lateinit var adapter: OrderAdapter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_order)
val topAppBar: MaterialToolbar = findViewById(R.id.top_app_bar)
setSupportActionBar(topAppBar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.title = "Orders"
val currentUser = FirebaseAuth.getInstance().currentUser
val uid = currentUser?.uid ?: ""
val query = FirebaseDatabase.getInstance().reference.child("Orders").child(uid)
val options = FirebaseRecyclerOptions.Builder<Order>().setQuery(query, Order::class.java).build()
adapter = OrderAdapter(options)
val ordersRecyclerView: RecyclerView = findViewById(R.id.ordersRecyclerView)
val layoutManager = if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
GridLayoutManager(this, 2)
} else {
LinearLayoutManager(this)
}
ordersRecyclerView.layoutManager = layoutManager
ordersRecyclerView.adapter = adapter
val removeAllButton: Button = findViewById(R.id.removeAllButton)
removeAllButton.setOnClickListener {
removeOrdersFromDatabase(uid)
}
}
private fun removeOrdersFromDatabase(uid: String) {
val ordersRef = FirebaseDatabase.getInstance().reference.child("Orders").child(uid)
ordersRef.removeValue().addOnCompleteListener { task ->
if (task.isSuccessful) {
adapter.notifyDataSetChanged()
Toast.makeText(this, "All orders removed successfully", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this, "Failed to remove orders", Toast.LENGTH_SHORT).show()
}
}
}
override fun onStart() {
super.onStart()
adapter.startListening()
}
override fun onStop() {
super.onStop()
adapter.stopListening()
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu_main, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.action_products -> {
startActivity(Intent(this, ProductActivity::class.java))
true
}
android.R.id.home -> {
onBackPressed()
true
}
else -> super.onOptionsItemSelected(item)
}
}
} | e-commerce-android-app-with-Kotlin/app/src/main/java/com/example/firebasegroupapp1/OrderActivity.kt | 2484427034 |
package com.example.firebasegroupapp1
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.widget.Toolbar
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.database.FirebaseDatabase
class CheckoutActivity : AppCompatActivity() {
private lateinit var topAppBar: Toolbar
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_checkout)
topAppBar = findViewById(R.id.topAppBar)
setSupportActionBar(topAppBar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.title = "Checkout"
val productName = intent.getStringExtra("productName")
val quantity = intent.getIntExtra("quantity", 0)
val totalPrice = intent.getDoubleExtra("totalPrice", 0.0)
val totalPriceFormatted = roundToTwoDecimalPlaces(totalPrice)
val txtProductName: TextView = findViewById(R.id.txtProductName)
val txtQuantity: TextView = findViewById(R.id.txtQuantity)
val txtTotalPrice: TextView = findViewById(R.id.txtTotalPrice)
txtProductName.text = "Product Name: $productName"
txtQuantity.text = "Quantity: $quantity"
txtTotalPrice.text = "Total Price: $$totalPriceFormatted"
val currentUser = FirebaseAuth.getInstance().currentUser
val fullName = currentUser?.displayName
val email = currentUser?.email
val etFullName: EditText = findViewById(R.id.etFullName)
etFullName.setText(fullName)
val btnPlaceOrder: Button = findViewById(R.id.btnPlaceOrder)
val etPhoneNumber: EditText = findViewById(R.id.etPhoneNumber)
val etAddress: EditText = findViewById(R.id.etAddress)
val etCity: EditText = findViewById(R.id.etCity)
val etProvince: EditText = findViewById(R.id.etProvince)
val etPostalCode: EditText = findViewById(R.id.etPostalCode)
val etCardHolderName: EditText = findViewById(R.id.etCardHolderName)
val etCardNumber: EditText = findViewById(R.id.etCardNumber)
val etSecurityCode: EditText = findViewById(R.id.etSecurityCode)
val etValidUntil: EditText = findViewById(R.id.etValidUntil)
btnPlaceOrder.setOnClickListener {
val phoneNumber = etPhoneNumber.text.toString()
val address = etAddress.text.toString()
val city = etCity.text.toString()
val province = etProvince.text.toString()
val postalCode = etPostalCode.text.toString()
val cardHolderName = etCardHolderName.text.toString()
val cardNumber = etCardNumber.text.toString()
val securityCode = etSecurityCode.text.toString()
val validUntil = etValidUntil.text.toString()
val validationErrors = mutableListOf<Pair<EditText, String>>()
val nameRegex = Regex("^[a-zA-Z ]+\$")
val phoneRegex = Regex("^[0-9]{10}\$")
val cityRegex = Regex("^[a-zA-Z.,\\- ]+\$")
val provinceRegex = Regex("^[a-zA-Z]+\$")
val postalCodeRegex = Regex("^[a-zA-Z0-9]{6}\$")
val cardNumberRegex = Regex("^[0-9]{16}\$")
val securityCodeRegex = Regex("^[0-9]{3}\$")
val validUntilRegex = Regex("^[0-9]{4}\$")
if (!phoneNumber.matches(phoneRegex)) {
validationErrors.add(Pair(etPhoneNumber, "Invalid phone number"))
}
if (address.isBlank()) {
validationErrors.add(Pair(etAddress, "Address cannot be empty"))
}
if (!city.matches(cityRegex)) {
validationErrors.add(Pair(etCity, "Invalid city"))
}
if (!province.matches(provinceRegex)) {
validationErrors.add(Pair(etProvince, "Invalid province"))
}
if (!postalCode.matches(postalCodeRegex)) {
validationErrors.add(Pair(etPostalCode, "Invalid postal code"))
}
if (!cardHolderName.matches(nameRegex)) {
validationErrors.add(Pair(etCardHolderName, "Invalid card holder name"))
}
if (!cardNumber.matches(cardNumberRegex)) {
validationErrors.add(Pair(etCardNumber, "Invalid card number"))
}
if (!securityCode.matches(securityCodeRegex)) {
validationErrors.add(Pair(etSecurityCode, "Invalid security code"))
}
if (!validUntil.matches(validUntilRegex)) {
validationErrors.add(Pair(etValidUntil, "Invalid valid until"))
}
validationErrors.forEach { (editText, errorMessage) ->
editText.error = errorMessage
}
if (validationErrors.isNotEmpty()) {
return@setOnClickListener
}
val order = Order(
fullName = fullName,
email = email,
quantity = quantity,
productName = productName,
phoneNumber = phoneNumber,
totalPrice = totalPrice,
address = address,
city = city,
province = province,
postalCode = postalCode,
cardHolderName = cardHolderName,
cardNumber = cardNumber,
securityCode = securityCode,
validUntil = validUntil,
productImage = intent.getStringExtra("productImage") ?: ""
)
saveOrder(order)
}
}
private fun saveOrder(order: Order) {
val currentUser = FirebaseAuth.getInstance().currentUser
val uid = currentUser?.uid
if (uid != null) {
val roundedTotalPrice = roundToTwoDecimalPlaces(order.totalPrice)
order.totalPrice = roundedTotalPrice
FirebaseDatabase.getInstance().reference.child("Orders/$uid").push().setValue(order).addOnSuccessListener {
Toast.makeText(this, "Order placed successfully!", Toast.LENGTH_SHORT).show()
startActivity(Intent(this, OrderActivity::class.java))
finish()
}
.addOnFailureListener {
Toast.makeText(this, "Failed to place order: ${it.message}", Toast.LENGTH_SHORT).show()
}
} else {
Toast.makeText(this, "User not authenticated", Toast.LENGTH_SHORT).show()
}
}
fun roundToTwoDecimalPlaces(number: Double): Double {
return "%.2f".format(number).toDouble()
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
android.R.id.home -> {
super.onBackPressed()
true
}
else -> super.onOptionsItemSelected(item)
}
}
} | e-commerce-android-app-with-Kotlin/app/src/main/java/com/example/firebasegroupapp1/CheckoutActivity.kt | 3912609961 |
package com.example.firebasegroupapp1
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.firebase.ui.database.FirebaseRecyclerAdapter
import com.firebase.ui.database.FirebaseRecyclerOptions
import com.google.firebase.storage.FirebaseStorage
import com.google.firebase.storage.StorageReference
class ProductAdapter(options: FirebaseRecyclerOptions<Product>)
: FirebaseRecyclerAdapter<Product, ProductAdapter.ProductViewHolder>(options) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProductViewHolder {
val inflater = LayoutInflater.from(parent.context)
return ProductViewHolder(inflater, parent)
}
override fun onBindViewHolder(holder: ProductViewHolder, position: Int, model: Product) {
holder.productNameTextView.text = model.name
holder.productPriceTextView.text = "$" + model.price.toString()
val theImage: String = model.image
if (theImage.indexOf("gs://") >-1) {
val storageReference = FirebaseStorage.getInstance().getReferenceFromUrl(theImage)
Glide.with(holder.productImageView.context)
.load(storageReference)
.into(holder.productImageView)
} else {
Glide.with(holder.productImageView.context)
.load(theImage)
.into(holder.productImageView)
}
holder.itemView.setOnClickListener {
val intent = Intent(holder.itemView.context, ProductDetailActivity::class.java).apply {
putExtra("productName", model.name)
putExtra("productPrice", model.price)
putExtra("productImage", model.image)
putExtra("productDescription", model.description)
}
holder.itemView.context.startActivity(intent)
}
}
class ProductViewHolder(inflater: LayoutInflater, parent: ViewGroup) :
RecyclerView.ViewHolder(inflater.inflate(R.layout.item_product, parent, false)) {
val productNameTextView: TextView = itemView.findViewById(R.id.productNameTextView)
val productPriceTextView: TextView = itemView.findViewById(R.id.productPriceTextView)
val productImageView: ImageView = itemView.findViewById(R.id.productImageView)
}
} | e-commerce-android-app-with-Kotlin/app/src/main/java/com/example/firebasegroupapp1/ProductAdapter.kt | 4048909337 |
package com.example.firebasegroupapp1
import android.content.Context
import com.bumptech.glide.Glide
import com.bumptech.glide.Registry
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.module.AppGlideModule
import com.firebase.ui.storage.images.FirebaseImageLoader
import com.google.firebase.storage.StorageReference
import java.io.InputStream
@GlideModule
class MyAppGlideModule: AppGlideModule() {
override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
//super.registerComponents(context, glide, registry)
registry.append(
StorageReference::class.java,
InputStream::class.java,
FirebaseImageLoader.Factory()
)
}
} | e-commerce-android-app-with-Kotlin/app/src/main/java/com/example/firebasegroupapp1/MyAppGlideModule.kt | 2646647544 |
package com.example.firebasegroupapp1
data class Order(
var fullName: String? = null,
var email: String? = null,
var productName: String? = null,
var quantity: Int = 0,
var totalPrice: Double = 0.0,
var address: String = "",
var city: String = "",
var province: String = "",
var postalCode: String = "",
var cardHolderName: String = "",
var cardNumber: String = "",
var securityCode: String = "",
var validUntil: String = "",
var phoneNumber: String = "",
var productImage: String = ""
) | e-commerce-android-app-with-Kotlin/app/src/main/java/com/example/firebasegroupapp1/Order.kt | 4279151207 |
package com.example.nastartapplication
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.nastartapplication", appContext.packageName)
}
} | nastart_android_app/app/src/androidTest/java/com/example/nastartapplication/ExampleInstrumentedTest.kt | 2899044486 |
package com.example.nastartapplication
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)
}
} | nastart_android_app/app/src/test/java/com/example/nastartapplication/ExampleUnitTest.kt | 2344948806 |
package com.example.nastartapplication.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) | nastart_android_app/app/src/main/java/com/example/nastartapplication/ui/theme/Color.kt | 2694527405 |
package com.example.nastartapplication.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 NastartApplicationTheme(
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
)
} | nastart_android_app/app/src/main/java/com/example/nastartapplication/ui/theme/Theme.kt | 2892000704 |
package com.example.nastartapplication.ui.theme
import androidx.compose.material3.Typography
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
import com.example.nastartapplication.R
val themeFontFamily = FontFamily(
Font(R.font.inter, FontWeight.Light),
Font(R.font.inter, FontWeight.Normal),
Font(R.font.inter, FontWeight.Bold)
)
// Set of Material typography styles to start with
val Typography = Typography(
bodyLarge = TextStyle(
fontFamily = themeFontFamily,
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
)
*/
) | nastart_android_app/app/src/main/java/com/example/nastartapplication/ui/theme/Type.kt | 4059735394 |
package com.example.nastartapplication
import Order
import io.ktor.client.HttpClient
import io.ktor.client.plugins.websocket.WebSockets
import io.ktor.client.plugins.websocket.webSocket
import io.ktor.http.HttpMethod
import io.ktor.websocket.Frame
import io.ktor.websocket.readText
import kotlinx.coroutines.channels.consumeEach
import kotlinx.coroutines.delay
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
class WebSocketClient(private val onOrderReceived: (Order) -> Unit) {
private val client = HttpClient {
install(WebSockets)
}
suspend fun connect() {
while (true) {
try {
client.webSocket(method = HttpMethod.Get, host = "c501-171-33-254-209.ngrok-free.app", path = "/ws?client=abcde") {
incoming.consumeEach { frame ->
if (frame is Frame.Text) {
val orders: List<Order> = Json.decodeFromString(frame.readText())
orders.forEach { onOrderReceived(it) }
}
}
}
break
} catch (e: Exception) {
delay(100)
}
}
}
} | nastart_android_app/app/src/main/java/com/example/nastartapplication/WebSocketClient.kt | 74493499 |
package com.example.nastartapplication
import Order
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
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.RowScope
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.lazy.LazyColumn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import com.example.nastartapplication.ui.theme.NastartApplicationTheme
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import okhttp3.OkHttpClient
import okhttp3.Request
private val Context.dataStore by preferencesDataStore("settings")
@Serializable
data class AuthResponse(
@SerialName("isAuth")
val isAuth: Boolean
)
class MainActivity : ComponentActivity() {
private val client = OkHttpClient()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
startService(Intent(this, WebSocketService::class.java))
val authKey = stringPreferencesKey("auth")
setContent {
val authFlow: Flow<String?> = dataStore.data.map { preferences ->
preferences[authKey]
}
val coroutineScope = rememberCoroutineScope()
val authState by authFlow.collectAsState(initial = false)
NastartApplicationTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
val isAuthorized = remember { mutableStateOf(false) }
Column {
Header(isAuthorized)
if (!isAuthorized.value) {
LoginForm(onLoginClick = { token ->
coroutineScope.launch {
checkAuthToken(token, onResult = { isValid ->
if (isValid) {
coroutineScope.launch {
storeAuthKey(token)
}
}
}, isAuthorized = isAuthorized)
}
}, isAuthorized = isAuthorized)
} else {
MainScreen()
}
}
}
}
}
}
private suspend fun storeAuthKey(token: String) {
dataStore.edit { preferences ->
preferences[stringPreferencesKey("auth")] = token
}
}
private suspend fun checkAuthToken(token: String, onResult: (Boolean) -> Unit, isAuthorized: MutableState<Boolean>) {
withContext(Dispatchers.IO) {
val request = Request.Builder()
.url("https://c501-171-33-254-209.ngrok-free.app/auth?token=$token")
.build()
client.newCall(request).execute().use { response ->
val body = response.body?.string()
val authResponse = body?.let { Json.decodeFromString<AuthResponse>(it) }
withContext(Dispatchers.Main) {
val isValid = authResponse?.isAuth ?: false
onResult(isValid)
if (isValid) {
isAuthorized.value = true
}
}
}
}
}
}
@Composable
fun MainScreen() {
var currentOrder by remember { mutableStateOf<Order?>(null) }
var isMainViewActive by remember { mutableStateOf(true) }
val orders = remember { mutableStateListOf<Order>() }
LaunchedEffect(Unit) {
val webSocketClient = WebSocketClient { order: Order ->
orders.add(order)
}
webSocketClient.connect()
}
ActiveCompletedSwitcher { isMainViewActive = !isMainViewActive; currentOrder = null }
if (currentOrder == null) {
MainView(orders, onOrderClick = { order ->
currentOrder = order
isMainViewActive = false
})
} else {
OrderView(currentOrder!!) {
currentOrder = null
isMainViewActive = true
}
}
}
@Composable
fun MainView(orders: MutableList<Order>, onOrderClick: (Order) -> Unit) {
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.SpaceEvenly,
horizontalAlignment = Alignment.CenterHorizontally
) {
for (order in orders) {
BuildOrderButton(order, onOrderClick)
}
}
}
@Composable
fun OrderView(order: Order, onBackClick: () -> Unit) {
Column(
modifier = Modifier
.fillMaxSize()
.padding(top = 12.dp),
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally
) {
Box(
modifier = Modifier
.width(360.dp)
.height(480.dp)
.clip(RoundedCornerShape(topStart = 15.dp, topEnd = 15.dp))
.border(
2.dp,
Color.Black.copy(alpha = 0.3f),
RoundedCornerShape(topStart = 15.dp, topEnd = 15.dp)
)
) {
Text(
text = order.invoice.createdTime,
fontSize = 18.sp,
modifier = Modifier
.align(Alignment.TopCenter)
.padding(top = 4.dp)
)
val nameColumn = .60f // 60%
val quantityColumn = .15f // 15%
val priceColumn = .25f // 25%
LazyColumn(
modifier = Modifier
.fillMaxSize()
.padding(
top = 34.dp,
start = 12.dp,
end = 12.dp
),
userScrollEnabled = true) {
item {
Row(
Modifier
.background(colorResource(id = R.color.secondary))) {
TableCell(text = "ะะฐะธะผะตะฝะพะฒะฐะฝะธะต", weight = nameColumn)
TableCell(text = "x", weight = quantityColumn)
TableCell(text = "ะกัะผะผะฐ", weight = priceColumn)
}
}
for (product in order.invoice.products) {
item {
Row {
Row(Modifier.fillMaxWidth()) {
TableCell(text = product.title, weight = nameColumn)
TableCell(text = product.quantity.toString(), weight = quantityColumn)
TableCell(text = (product.price * product.quantity).toString(), weight = priceColumn)
}
}
}
}
item {
Row(
Modifier
.background(colorResource(id = R.color.secondary))) {
TableCell(text = "ะัะพะณะพ", weight = 0.6f)
TableCell(text = order.invoice.price.toString() + " ััะฑ.", weight = 0.4f)
}
Row(Modifier.padding(bottom = 34.dp)) {}
}
}
val context = LocalContext.current
val webView = remember {
WebView(context).apply {
webViewClient = WebViewClient()
settings.javaScriptEnabled = true
loadDataWithBaseURL(
null,
"""
<!DOCTYPE html>
<html>
<head>
<title>ะัััััะน ััะฐัั. ะ ะฐะทะผะตัะตะฝะธะต ะธะฝัะตัะฐะบัะธะฒะฝะพะน ะบะฐััั ะฝะฐ ัััะฐะฝะธัะต</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="https://api-maps.yandex.ru/2.1/?apikey=bb3bf806-ea2f-4b74-87a7-d81b10882d76&lang=ru_RU"></script>
<script>
ymaps.ready(init);
function init() {
var myMap = new ymaps.Map("map", {
center: ${order.delivery.coords},
zoom: 14
});
var myPlacemark = new ymaps.Placemark(${order.delivery.coords}, {}, {
iconLayout: 'default#image',
iconImageHref: 'https://cdn4.iconfinder.com/data/icons/small-n-flat/24/map-marker-512.png',
iconImageSize: [30, 42],
iconImageOffset: [-3, -42]
});
myMap.geoObjects.add(myPlacemark);
}
</script>
</head>
<body>
<div id="map" style="width: 500px; height: 250px"></div>
</body>
</html>
""",
"text/html",
"UTF-8",
null
)
}
}
AndroidView({ webView },
modifier = Modifier
.fillMaxWidth()
.height(200.dp)
.padding(top = 10.dp)
.align(Alignment.BottomCenter)) { webView ->
// Update WebView in here if necessary
}
}
Button(
onClick = {},
modifier = Modifier
.width(360.dp)
.height(80.dp)
.shadow(
elevation = 4.dp,
spotColor = Color.Black,
shape = RoundedCornerShape(bottomStart = 15.dp, bottomEnd = 15.dp)
),
colors = ButtonDefaults.buttonColors(
containerColor = colorResource(id = R.color.primary),
contentColor = colorResource(id = R.color.main_black)
),
shape = RoundedCornerShape(bottomStart = 15.dp, bottomEnd = 15.dp),
) {
Text(
text = "ะัะฟัะฐะฒะธัั ะฒ ะดะพััะฐะฒะบั"
)
}
}
}
@Composable
fun RowScope.TableCell(
text: String,
weight: Float
) {
Text(
text = text,
Modifier
.border(1.dp, Color.Black.copy(alpha = 0.1f))
.weight(weight)
.padding(4.dp)
)
}
@Composable
fun BuildOrderButton(order: Order, onOrderClick: (Order) -> Unit) {
Button(
onClick = { onOrderClick(order) },
modifier = Modifier
.padding(
top = 12.dp,
bottom = 12.dp
)
.width(360.dp)
.height(160.dp)
.border(1.dp, Color.Black.copy(alpha = 0.1f), RoundedCornerShape(15.dp))
.shadow(
elevation = 8.dp,
spotColor = Color.Black,
shape = RoundedCornerShape(15.dp)
),
shape = RoundedCornerShape(15.dp),
colors = ButtonDefaults.buttonColors(
containerColor = Color.White,
contentColor = colorResource(id = R.color.main_black)
)
) {
Box(
modifier = Modifier.fillMaxSize()
) {
Text(
text = order.invoice.createdTime,
fontSize = 18.sp,
modifier = Modifier.align(Alignment.TopCenter)
)
Row {
Column {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.padding(top = 25.dp)
) {
Image(
painter = painterResource(id = R.drawable.avataaars),
contentDescription = "Client avatar",
modifier = Modifier
.width(70.dp)
.align(Alignment.CenterVertically)
)
}
Row(
modifier = Modifier
.align(Alignment.CenterHorizontally)
) {
Text(
text = order.customer.name,
fontSize = 20.sp,
)
}
}
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center
) {
for (product in order.invoice.products) {
Row(
modifier = Modifier
.align(Alignment.CenterHorizontally)
) {
Text(text = product.title + " x " + product.quantity)
}
}
}
}
Text(
text = "ะัะพะณ: " + order.invoice.price + " ััะฑ.",
modifier = Modifier
.align(Alignment.BottomCenter))
}
}
}
@Composable
fun Header(isAuthorized: MutableState<Boolean>) {
var showDialog by remember { mutableStateOf(false) }
val context = LocalContext.current
val dataStore = context.dataStore
val authKeyPreferencesKey = stringPreferencesKey("auth")
val authFlow: Flow<String?> = dataStore.data.map { preferences ->
preferences[authKeyPreferencesKey]
}
val authKey by authFlow.collectAsState(initial = false)
if (showDialog) {
AlertDialog(
onDismissRequest = { showDialog = false },
title = { Text(text = "ะะฐั ัะพะบะตะฝ:\n$authKey") },
confirmButton = {
Button(onClick = {
CoroutineScope(Dispatchers.IO).launch {
dataStore.edit { preferences ->
preferences.remove(authKeyPreferencesKey)
}
}
showDialog = false
isAuthorized.value = false // ะะพะฑะฐะฒััะต ััั ัััะพะบั
}) {
Text("ะัะนัะธ")
}
},
dismissButton = {
Button(onClick = { showDialog = false }) {
Text("ะัะผะตะฝะฐ")
}
}
)
}
Column(
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally
) {
Image(
painter = painterResource(id = R.drawable.nastart_logo),
contentDescription = "App logo",
modifier = Modifier
.width(340.dp)
.padding(start = 50.dp, end = 50.dp, top = 10.dp),
contentScale = ContentScale.FillWidth
)
Button(onClick = { showDialog = true }) {
Text("โ๏ธ") // ะัะพััะพะน ัะธะผะฒะพะป ะดะปั ะบะฝะพะฟะบะธ
}
}
}
@Composable
fun ActiveCompletedSwitcher(onSwitch: () -> Unit) {
var activeWindowToggled by remember { mutableStateOf(true) }
Column(
modifier = Modifier
.fillMaxWidth()
.padding(top = 10.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Row {
Button(
onClick = { if (!activeWindowToggled) { activeWindowToggled = true}; onSwitch() },
modifier = Modifier.width(180.dp),
shape = RoundedCornerShape(topStart = 15.dp, bottomStart = 15.dp),
colors = ButtonDefaults.buttonColors(
containerColor = if (activeWindowToggled) colorResource(id = R.color.primary) else colorResource(id = R.color.secondary),
contentColor = colorResource(id = R.color.main_black)
)
) {
Text(
text = stringResource(id = R.string.active_window_label),
fontSize = 18.sp
)
}
Button(
onClick = { if (activeWindowToggled) { activeWindowToggled = false}; onSwitch() },
modifier = Modifier.width(180.dp),
shape = RoundedCornerShape(topEnd = 15.dp, bottomEnd = 15.dp),
colors = ButtonDefaults.buttonColors(
containerColor = if (!activeWindowToggled) colorResource(id = R.color.primary) else colorResource(id = R.color.secondary),
contentColor = colorResource(id = R.color.main_black)
)
) {
Text(
text = stringResource(id = R.string.completed_window_label),
fontSize = 18.sp
)
}
}
}
}
@Composable
fun LoginForm(onLoginClick: (String) -> Unit, isAuthorized: MutableState<Boolean>) {
var text by remember { mutableStateOf("") }
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = stringResource(id = R.string.welcome_message),
modifier = Modifier.padding(bottom = 50.dp),
fontSize = 30.sp,
)
OutlinedTextField(
value = text,
onValueChange = { text = it },
label = {
Text(
text = stringResource(id = R.string.token_field_label)
)
}
)
FilledTonalButton(
onClick = {
onLoginClick(text)
},
modifier = Modifier.padding(top = 50.dp),
) {
Text(
text = stringResource(id = R.string.login_button_text),
fontSize = 20.sp
)
}
}
}
| nastart_android_app/app/src/main/java/com/example/nastartapplication/MainActivity.kt | 3397506441 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.