Skip to content

Init ci/application #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 10, 2025
Merged
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
31 changes: 31 additions & 0 deletions .github/workflows/android_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Android Build

on:
push:
branches: [ master ]
pull_request:
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest
timeout-minutes: 15

steps:

- name: Checkout branch
uses: actions/checkout@v4

- name: set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
cache: gradle

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build
14 changes: 13 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
/.idea
/.idea
/build
/.gradle
*.iml
.gradle
.idea
.kotlin
/local.properties
.DS_Store
/captures
.externalNativeBuild
.cxx
local.properties
2 changes: 2 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
/release
38 changes: 38 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
plugins {
alias(libs.plugins.application)
alias(libs.plugins.kotlin)
}

android {
compileSdk = libs.versions.compileSdk.get().toInt()

defaultConfig {
applicationId = "com.stslex.compiler_app"
minSdk = libs.versions.minSdk.get().toInt()
targetSdk = libs.versions.targetSdk.get().toInt()
versionCode = libs.versions.versionCode.get().toInt()
versionName = libs.versions.versionName.get()
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
isCoreLibraryDesugaringEnabled = true
}

kotlinOptions {
jvmTarget = "21"
}

namespace = "com.stslex.compiler_app.app"
}

dependencies {
coreLibraryDesugaring(libs.android.desugarJdkLibs)

implementation(libs.androidx.activity)
implementation(libs.androidx.lifecycle.viewModel)
implementation(libs.androidx.lifecycle.runtime)
implementation(libs.androidx.lifecycle.common)
implementation(libs.androidx.constraintlayout)
}
19 changes: 19 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="TestAppForCompilerPlugin"
android:roundIcon="@mipmap/ic_launcher_round">
<activity
android:name="com.stslex.compiler_app.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
60 changes: 60 additions & 0 deletions app/src/main/kotlin/com/stslex/compiler_app/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.stslex.compiler_app

import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.viewModels
import androidx.lifecycle.lifecycleScope
import com.stslex.compiler_app.app.R
import com.stslex.compiler_app.model.UserModel
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import java.util.logging.Level
import java.util.logging.Logger
import kotlin.random.Random

class MainActivity : ComponentActivity() {

private val viewModel: MainActivityViewModel by viewModels { MainActivityViewModelFactory() }

private val logger = Logger.getLogger("KotlinCompilerLogger")

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

viewModel.userInfo
.onEach(::setUI)
.launchIn(lifecycleScope)

setClickListeners()
}

private fun setClickListeners() {
findViewById<Button>(R.id.usernameChangeButton).setOnClickListener {
logger.log(Level.INFO, "usernameChangeButton clicked")
val randomInt = Random.nextInt()
viewModel.setName("John $randomInt")
}
}

private fun setUI(user: UserModel) {
logger.log(Level.INFO, "Setting UI with user: $user")
sendToastOfUserChanges(user)
findViewById<TextView>(R.id.usernameFieldTextView).text = user.name
}

private fun sendToastOfUserChanges(userModel: UserModel) {
val textMsg = userModel.getChangesValue(user)
Toast.makeText(this, textMsg, Toast.LENGTH_SHORT).show()
user = userModel
}

companion object {

private var user: UserModel? = null
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.stslex.compiler_app

import androidx.lifecycle.ViewModel
import com.stslex.compiler_app.model.UserModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow

class MainActivityViewModel : ViewModel() {

private val _userInfo = MutableStateFlow(UserModel.defaultMock)

val userInfo: StateFlow<UserModel>
get() = _userInfo.asStateFlow()

fun setIsLiked(isLiked: Boolean) {
_userInfo.value = _userInfo.value.copy(isLiked = isLiked)
}

fun setLikes(likes: Int) {
_userInfo.value = _userInfo.value.copy(likes = likes)
}

fun setSubscriptions(subscriptions: Int) {
_userInfo.value = _userInfo.value.copy(subscriptions = subscriptions)
}

fun setIsSubscribed(isSubscribed: Boolean) {
_userInfo.value = _userInfo.value.copy(isSubscribed = isSubscribed)
}

fun setName(name: String) {
_userInfo.value = _userInfo.value.copy(name = name)
}

fun setAvatarUrl(avatarUrl: String) {
_userInfo.value = _userInfo.value.copy(avatarUrl = avatarUrl)
}

fun setEmail(email: String) {
_userInfo.value = _userInfo.value.copy(email = email)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.stslex.compiler_app

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider

@Suppress("UNCHECKED_CAST")
class MainActivityViewModelFactory : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
if (modelClass.isAssignableFrom(MainActivityViewModel::class.java)) {
return MainActivityViewModel() as T
}
throw IllegalArgumentException("Unknown ViewModel class")
}
}
47 changes: 47 additions & 0 deletions app/src/main/kotlin/com/stslex/compiler_app/model/UserModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.stslex.compiler_app.model

data class UserModel(
val uuid: String,
val name: String,
val avatarUrl: String,
val email: String,
val isLiked: Boolean,
val likes: Int,
val isSubscribed: Boolean,
val subscriptions: Int,
) {

fun getChangesValue(
user: UserModel?
): String = if (user == null) {
"User full change"
} else {
val changes = mutableListOf<String>()
if (user.name != name) changes.add("name")
if (user.avatarUrl != avatarUrl) changes.add("avatarUrl")
if (user.email != email) changes.add("email")
if (user.isLiked != isLiked) changes.add("isLiked")
if (user.likes != likes) changes.add("likes")
if (user.isSubscribed != isSubscribed) changes.add("isSubscribed")
if (user.subscriptions != subscriptions) changes.add("subscriptions")
when {
changes.isEmpty() -> "No changes"
changes.size == 7 -> "User full change"
else -> changes.joinToString(", ") + " changed"
}
}

companion object {

val defaultMock = UserModel(
uuid = "uuid",
name = "Test User",
avatarUrl = "https://images.unsplash.com/photo-1488161628813-04466f872be2?q=80&w=3376&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
email = "email",
isLiked = false,
likes = 0,
isSubscribed = false,
subscriptions = 0,
)
}
}
74 changes: 74 additions & 0 deletions app/src/main/res/drawable/ic_launcher_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
android:height="108dp"
android:width="108dp"
android:viewportHeight="108"
android:viewportWidth="108"
xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z"/>
<path android:fillColor="#00000000" android:pathData="M9,0L9,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,0L19,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M29,0L29,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M39,0L39,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M49,0L49,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M59,0L59,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M69,0L69,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M79,0L79,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M89,0L89,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M99,0L99,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,9L108,9"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,19L108,19"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,29L108,29"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,39L108,39"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,49L108,49"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,59L108,59"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,69L108,69"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,79L108,79"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,89L108,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,99L108,99"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,29L89,29"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,39L89,39"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,49L89,49"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,59L89,59"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,69L89,69"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,79L89,79"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M29,19L29,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M39,19L39,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M49,19L49,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M59,19L59,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M69,19L69,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M79,19L79,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
</vector>
31 changes: 31 additions & 0 deletions app/src/main/res/drawable/ic_launcher_foreground.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:startY="49.59793"
android:startX="42.9492"
android:endY="92.4963"
android:endX="85.84757"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:strokeWidth="1"
android:strokeColor="#00000000"/>
</vector>
Loading