diff --git a/settings.gradle.kts b/settings.gradle.kts index 58cfac6..d863d97 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -14,5 +14,4 @@ dependencyResolutionManagement { } rootProject.name = "Andoid" -include(":app") include(":testapp") diff --git a/testapp/libs.versions.toml b/testapp/libs.versions.toml new file mode 100644 index 0000000..121b5fc --- /dev/null +++ b/testapp/libs.versions.toml @@ -0,0 +1,48 @@ +[versions] +coreVersion = "1.9.0" +ktxVersion = "2.8.3" +composeVersion = "1.9.0" +appcompatVersion = "1.7.0" +junitVersion = "4.13.2" +testExtJunitVersion = "1.2.1" +espressoCoreVersion = "3.6.1" +composeBomVersion = "2023.03.00" + +[libraries] +androidx-core = {group = "androidx.core", name = "core-ktx",version.ref = "coreVersion"} +androidx-lifecycle = {group = "androidx.lifecycle", name = "lifecycle-runtime-ktx" , version.ref = "ktxVersion"} +androidx-activity = {group = "androidx.activity", name = "activity-compose" , version.ref = "composeVersion"} +androidx-appcompat = {group = "androidx.appcompat", name = "appcompat" , version.ref = "appcompatVersion"} +junit = {group = "junit", name = "junit" , version.ref = "junitVersion"} +androidx-test-ext = {group = "androidx.test.ext", name = "junit" , version.ref = "testExtJunitVersion"} +androidx-test-espresso = {group = "androidx.test.espresso", name = "espresso-core" , version.ref = "espressoCoreVersion"} +androidx-compose = {group = "androidx.compose", name = "compose-bom" , version.ref = "composeBomVersion"} + + +#implementation(libs.android.core) +#implementation(libs.androidx.lifecycle) +#implementation(libs.androidx.activity) +# +#implementation(platform(libs.androidx.compose)) +#implementation("androidx.compose.ui:ui") +#implementation("androidx.compose.ui:ui-graphics") +#implementation("androidx.compose.ui:ui-tooling-preview") +#implementation("androidx.compose.material3:material3") +# +#implementation(libs.androidx.appcompat) +#testImplementation(libs.junit) +#androidTestImplementation(libs.androidx.test.ext) +#androidTestImplementation(libs.androidx.test.espresso) +# +#androidTestImplementation(platform(libs.androidx.compose)) +#androidTestImplementation("androidx.compose.ui:ui-test-junit4") +#debugImplementation("androidx.compose.ui:ui-tooling") +#debugImplementation("androidx.compose.ui:ui-test-manifest") + + +[plugins] +kotlin-gradlePlugin = {id = "org.jetbrains.kotlin.android", version.ref ="kotlin"} +android-application = {id = "com.android.application", version.ref ="androidGradlePlugin"} + +#alias(libs.plugins.kotlin.gradlePlugin) +#alias(libs.plugins.android.application) \ No newline at end of file diff --git a/testapp/src/main/java/com/example/testapp/MainActivity.kt b/testapp/src/main/java/com/example/testapp/MainActivity.kt index 9ae90b9..e9514a8 100644 --- a/testapp/src/main/java/com/example/testapp/MainActivity.kt +++ b/testapp/src/main/java/com/example/testapp/MainActivity.kt @@ -10,11 +10,13 @@ import android.view.ViewGroup import android.widget.Button import android.widget.EditText import android.widget.LinearLayout +import android.widget.Toast import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.allViews class MainActivity : AppCompatActivity() { - private lateinit var itemsList: MutableList + private val textOnScreen = arrayListOf() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -27,29 +29,100 @@ class MainActivity : AppCompatActivity() { return true } - override fun onOptionsItemSelected(item: MenuItem): Boolean { - val id = item.getItemId() - val mainScreen = findViewById(R.id.scroll_main_layout) as LinearLayout - if (id == R.id.action_add_button) { - Log.d("myLogs","button created") - val v: View = LayoutInflater.from(this).inflate( - /* resource = */ R.layout.button, - /* root = */ mainScreen, - /* attachToRoot = */ false - ) - val str: String = v.resources.getString(R.string.button_text) - val btn = v as Button - btn.text = str - mainScreen.addView(btn) + private fun showToast(message: String) { + Toast.makeText(this, message, Toast.LENGTH_SHORT).show() + } + + private fun getTextById(stringId: Int): String { + return resources.getString(stringId) + } + + private fun sendLogEvent(message: String) { + Log.d("Log",message) + } + + private fun click() { + var countButton = 0 + var countEditText = 0 + val mainScreen = findViewById(R.id.scroll_main_layout) + mainScreen + .allViews + .filter { view -> view is EditText } + .map { view -> view as EditText } + .forEach { editText: EditText -> + textOnScreen.add(editText.text.toString()) + } + val textEditText = getTextById(R.string.text) + val textEditButton = getTextById(R.string.button) + val textLog = getTextById(R.string.log) + val mistake = getTextById(R.string.mistake) + val zeroText = getTextById(R.string.zerotext) + if (textOnScreen.isEmpty()) { + showToast(zeroText) + } else { + for (element in textOnScreen) { + when (element) { + textEditText -> { + createEditView() + countEditText += 1 + break + } + textEditButton -> { + createButton() + countButton +=1 + break + } + else -> showToast(mistake) + } + } + sendLogEvent("$countEditText $textEditText $countButton $textEditButton $textLog") } - if (id == R.id.action_add_text) { - Log.d("myLogs","text created") - val addText = EditText(this) - addText.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT) - mainScreen.addView(addText) + mainScreen + .allViews + .filter { view -> view is EditText } + .map { view -> view as EditText } + .forEach { editText: EditText -> + editText.text.clear() + } + textOnScreen.clear() + } + + private fun createButton() { + val mainScreen = findViewById(R.id.scroll_main_layout) + val buttonCreated = getTextById(R.string.button_created) + sendLogEvent(buttonCreated) + val v: View = LayoutInflater.from(this).inflate( + /* resource = */ R.layout.button, + /* root = */ mainScreen, + /* attachToRoot = */ false + ) + val str: String = v.resources.getString(R.string.button_text) + val btn = v as Button + btn.text = str + mainScreen.addView(btn) + btn.setOnClickListener { + click() } - if (id == R.id.action_clear) { - mainScreen.removeAllViews() + } + + private fun createEditView() { + val mainScreen = findViewById(R.id.scroll_main_layout) + val textCreated = getTextById(R.string.text_created) + sendLogEvent(textCreated) + val addText = EditText(this) + addText.layoutParams = LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT) + mainScreen.addView(addText) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + val id = item.itemId + val mainScreen = findViewById(R.id.scroll_main_layout) + when (id) { + R.id.action_add_button -> createButton() + R.id.action_add_text -> createEditView() + R.id.action_clear -> mainScreen.removeAllViews() } return super.onOptionsItemSelected(item) } diff --git a/testapp/src/main/res/layout-land/button.xml b/testapp/src/main/res/layout-land/button.xml index d76158b..852e22a 100644 --- a/testapp/src/main/res/layout-land/button.xml +++ b/testapp/src/main/res/layout-land/button.xml @@ -1,10 +1,10 @@ \ No newline at end of file diff --git a/testapp/src/main/res/layout/activity_main.xml b/testapp/src/main/res/layout/activity_main.xml index 98a1cc3..6f0389c 100644 --- a/testapp/src/main/res/layout/activity_main.xml +++ b/testapp/src/main/res/layout/activity_main.xml @@ -1,9 +1,9 @@ + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"> + android:layout_width="match_parent" + android:layout_height="wrap_content" /> diff --git a/testapp/src/main/res/layout/button.xml b/testapp/src/main/res/layout/button.xml index 4987db3..7fd735b 100644 --- a/testapp/src/main/res/layout/button.xml +++ b/testapp/src/main/res/layout/button.xml @@ -1,11 +1,10 @@ \ No newline at end of file diff --git a/testapp/src/main/res/menu/menu_main.xml b/testapp/src/main/res/menu/menu_main.xml index d7ca599..a9a9db0 100644 --- a/testapp/src/main/res/menu/menu_main.xml +++ b/testapp/src/main/res/menu/menu_main.xml @@ -4,14 +4,14 @@ + android:title="@string/button_text" /> + android:title="@string/create_text" /> + android:title="@string/clear" /> \ No newline at end of file diff --git a/testapp/src/main/res/values-en/strings.xml b/testapp/src/main/res/values-en/strings.xml index 144ccba..5df86d7 100644 --- a/testapp/src/main/res/values-en/strings.xml +++ b/testapp/src/main/res/values-en/strings.xml @@ -2,4 +2,13 @@ testApp Create elements + Create text + Clear + button created + text created + text + button + were created + mistake + need 1 text \ No newline at end of file diff --git a/testapp/src/main/res/values/strings.xml b/testapp/src/main/res/values/strings.xml index 78f580a..070ba0b 100644 --- a/testapp/src/main/res/values/strings.xml +++ b/testapp/src/main/res/values/strings.xml @@ -2,4 +2,13 @@ Тестовое приложение Создать кнопку + Создать поле + Очистить + кнопка создана + текстовое поле создано + текст + кнопка + было создано + ошибка + нужно хотя бы 1 тексовое поле \ No newline at end of file