Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/AndroidProjectSystem.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
id("kotlin-kapt")
}

android {
Expand All @@ -17,6 +18,14 @@ android {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildFeatures {
dataBinding = true
}

kapt {
correctErrorTypes = true
}

buildTypes {
release {
isMinifyEnabled = false
Expand All @@ -36,12 +45,18 @@ android {
}

dependencies {

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
implementation(libs.androidx.activity)
implementation(libs.androidx.constraintlayout)
implementation(libs.androidx.lifecycle.viewmodel.ktx)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.androidx.room.runtime)
implementation("com.github.bumptech.glide:glide:4.16.0")
kapt ("com.github.bumptech.glide:compiler:4.16.0")
implementation(libs.androidx.room.ktx)
kapt(libs.androidx.room.compiler)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -12,6 +15,9 @@
android:supportsRtl="true"
android:theme="@style/Theme.BCSD_Android_20251"
tools:targetApi="31">
<activity
android:name=".AddEditActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
Expand Down
14 changes: 0 additions & 14 deletions app/src/main/java/com/example/bcsd_android_2025_1/MainActivity.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.example.bcsd_android_2025_1

import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import com.bumptech.glide.Glide
import com.example.bcsd_android_2025_1.databinding.ActivityAddEditBinding

class AddEditActivity : AppCompatActivity() {
private lateinit var binding: ActivityAddEditBinding
private val viewModel: WordViewModel by viewModels()

private var imageUri: String? = null
private var wordId: Int? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityAddEditBinding.inflate(layoutInflater)
setContentView(binding.root)

val editWordText = intent.getStringExtra(MainActivity.wordTextKey)
val editMeaning = intent.getStringExtra(MainActivity.wordMeaningKey)
wordId = intent.getIntExtra(MainActivity.wordIdKey, -1).takeIf { it != -1 }

val image = intent.getStringExtra(MainActivity.wordImageKey)
imageUri = image

if (!imageUri.isNullOrEmpty()) {
Glide.with(this).load(imageUri).into(binding.addImageImageview)
} else {
binding.addImageImageview.setImageDrawable(null)
}

binding.wordEdittext.setText(editWordText)
binding.meaningEdittext.setText(editMeaning)

binding.addImageButton.setOnClickListener {
imagePickerLauncher.launch("image/*")
}

binding.addButton.setOnClickListener {
val wordText = binding.wordEdittext.text.toString()
val meaning = binding.meaningEdittext.text.toString()
if (wordText.isNotBlank() && meaning.isNotBlank()) {
val word = WordListData(wordId ?: 0, wordText, meaning, imageUri)
if (wordId != null) {
viewModel.update(word)
binding.wordEdittext.setText("")
binding.meaningEdittext.setText("")
binding.addImageImageview.setImageDrawable(null)
imageUri = null
val resultIntent = Intent().apply {
putExtra(MainActivity.editedWordKey, word.word)
putExtra(MainActivity.editedMeaningKey, word.meaning)
putExtra(MainActivity.editedImageKey, word.imageUri)
}
setResult(Activity.RESULT_OK, resultIntent)
finish()

} else {
viewModel.insert(word)
}
finish()
}
}
}

private val imagePickerLauncher =
registerForActivityResult(ActivityResultContracts.GetContent()) { uri: Uri? ->
if (uri != null) {
imageUri = uri.toString()
Glide.with(this).load(uri).into(binding.addImageImageview)
} else {
imageUri = null
binding.addImageImageview.setImageDrawable(null)
}
}
}
Loading