Skip to content

Commit

Permalink
renamed project
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and [email protected] committed Jun 14, 2020
1 parent d2fa907 commit b853a58
Show file tree
Hide file tree
Showing 43 changed files with 101 additions and 126 deletions.
6 changes: 3 additions & 3 deletions .idea/gradle.xml

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

32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
**C-logic is a framework that allows you to intuitively and quickly create UI** using the principle of reusable components. This principle is the most modern and effective in the field of UI development, and it underlies such frameworks as React and Flutter.
**UI-generator is a framework that allows you to intuitively and quickly create UI** using the principle of reusable components. This principle is the most modern and effective in the field of UI development, and it underlies such frameworks as React and Flutter.

---
**C-logic is similar in functionality to Jetpack Compose** and provides all its main features. But unlike the Jetpack Compose, C-logic is fully compatible with the components of the Android support library - Fragments and Views, so you do not have to rewrite all your code to implement this framework. C-logic works on annotation processing and generates code on top of Fragment and View classes.
**UI-generator is similar in functionality to [Jetpack Compose](https://developer.android.com/jetpack/compose)** and provides all its main features. But unlike the Jetpack Compose, UI-generator is fully compatible with the components of the Android support library - Fragments and Views, so you do not have to rewrite all your code to implement this framework. UI-generator works on annotation processing and generates code on top of Fragment and View classes.

## Installation

Expand Down Expand Up @@ -30,18 +30,18 @@ android {
}
}
dependencies {
implementation 'com.github.ArtemiyDmtrvch.c-logic:c-logic-base:0.9.+'
implementation 'com.github.ArtemiyDmtrvch.c-logic:c-logic-annotations:0.9.+'
kapt 'com.github.ArtemiyDmtrvch.c-logic:c-logic-processor:0.9.+'
implementation 'com.github.ArtemiyDmtrvch.ui-generator:ui-generator-base:0.9.+'
implementation 'com.github.ArtemiyDmtrvch.ui-generator:ui-generator-annotations:0.9.+'
kapt 'com.github.ArtemiyDmtrvch.ui-generator:ui-generator-processor:0.9.+'
}
```
## Why do you need C-logic:
## Why do you need UI-generator
- You will write ***at least 2 times less code*** than if you wrote using Android SDK and any architecture.
- The entry threshold into your project will be minimal, because there are very few rules, and they are simple and universal for all situations
- Your code will be a priori reusable, and you will never have a situation when you have a Fragment, but you need to display it in the RecyclerView
- The principles laid down in C-logic are the most promising for development for any platform, and soon they will become the standard for Android development
- The principles laid down in UI-generator are the most promising for development for any platform, and soon they will become the standard for Android development

## Now let's see how this is all achieved.
## Now let's see how this is all achieved

### 1. One rule for all components

Expand All @@ -57,7 +57,7 @@ class MyFragmentViewModel : ComponentViewModel() {
}
```
```xml
// MyFragmentBinding xml
// my_fragment.xml
<layout>
<data>
<variable
Expand All @@ -70,35 +70,35 @@ class MyFragmentViewModel : ComponentViewModel() {
android:text="@{viewModel.myText}" />
</layout>
```
The annotation processor will generate a class **MyFragmentComponent** inherited from the Fragment with the ViewModel and the field `myText`. When this field is changed, an argument will be added to the Fragment, which will then be passed to the ViewModel and bound to the TextView using Android data binding. As a result, **this class can be used like this:**
The annotation processor will generate a class **MyFragmentComponent** inherited from the Fragment with the ViewModel and the field `myText`. When this field is changed, an argument will be added to the Fragment, which will then be passed to the ViewModel and bound to the TextView using [Android data binding](https://developer.android.com/topic/libraries/data-binding). As a result, **this class can be used like this:**
```kotlin
showFragment(MyFragmentComponent().apply { myText = "Hello world!" })
```

Now let's imagine a similar example, but you will have a FrameLayout to which the text is bound, which is then displayed in the TextView. And here is how you do it:
```kotlin
@MakeComponent
class MyLayout : ComponentScheme<FrameLayout, MyLayoutViewModel>({ MyLayoutBinding::class }) // MyLayoutBinding xml is the same as MyFragmentBinding xml
class MyLayout : ComponentScheme<FrameLayout, MyLayoutViewModel>({ MyLayoutBinding::class }) // my_layout.xml is the same as my_fragment.xml

class MyLayoutViewModel : ComponentViewModel() {

@Prop
var myText by state<String?>(null)
}
```
The annotation processor will generate a class **MyLayoutComponent** inherited from the FrameLayout with the ViewModel and the BindingAdapter for `myText` attribute, which will pass the value to the ViewModel. As a result, **this class can be used like this:**
The annotation processor will generate a class **MyLayoutComponent** inherited from the FrameLayout with the ViewModel and the [binding adapter](https://developer.android.com/topic/libraries/data-binding/binding-adapters) for `myText` attribute, which will pass the value to the ViewModel. As a result, **this class can be used like this:**
```xml
<my.package.MyLayoutComponent
android:layout_width="wrap_content"
android:layout_height="wrap_content"
myText='@{"Hello world!"}' />
```

*As you can see, the codes for the Fragment and for the View are completely identical.*
As you can see, the codes for the Fragment and for the View are completely identical.

**The single rule is:** create a class inherited from `ComponentScheme`, specify the super component as the first type argument, ViewModel as the second and mark this class with `MakeComponent` annotation. Then mark with `Prop` annotation those properties that may come from the parent component (the properties must be vars). An argument will be generated for the Fragment, and a binding adapter for the View. Then build the project and use generated classes.

**Note:** you may need to build the project twice so that the binding appapters and component classes are generated correctly.
**Note:** you may need to build the project twice so that the binding adapters and component classes are generated correctly.

Also, in the case of a View, you can set `Prop.twoWay = true`, and then a two-way binding adapter will be generated for the View. It will send the value back when the annotated property changes.
```kotlin
Expand Down Expand Up @@ -162,4 +162,6 @@ class MyPlainViewModel : ComponentViewModel() {
```
A ViewModel with a shared property is marked with `SharedViewModel` annotation, and the shared property is declared by the `observable` or `state` delegate. Then, in the observing ViewModel, in the initial block, using `isMutableBy` method, it is indicated which property values will be duplicated to your property (your property must be a var).

Consider using the `observable` delegate wherever you need to observe changes of a variable, because it, unlike `kotlin.properties.Delegates.observable`, does not call `onChanged` if the new value is equal to the old.
Consider using the `observable` delegate wherever you need to observe changes of a variable, because it, unlike `kotlin.properties.Delegates.observable`, does not call `onChanged` if the new value is equal to the old.

***For detailed examples see module `app`.***
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
buildToolsVersion "29.0.2"

defaultConfig {
applicationId "ru.impression.c_logic_example"
applicationId "ru.impression.ui_generator_example"
minSdkVersion 17
targetSdkVersion 29
versionCode 1
Expand Down Expand Up @@ -41,10 +41,10 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(":c-logic-base")
implementation project(":c-logic-annotations")
implementation project(':ui-generator-base')
implementation project(':ui-generator-annotations')
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
kapt project(':c-logic-processor')
kapt project(':ui-generator-processor')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.3.0-alpha01'
implementation 'androidx.core:core-ktx:1.3.0'
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ru.impression.c_logic_example">
package="ru.impression.ui_generator_example">

<application
android:name=".MainApplication"
android:name="ru.impression.ui_generator_example.MainApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name="ru.impression.ui_generator_example.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.impression.c_logic_example
package ru.impression.ui_generator_example

import android.view.View
import android.view.animation.AlphaAnimation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ru.impression.c_logic_example
package ru.impression.ui_generator_example

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import ru.impression.c_logic_example.fragment.MainFragmentComponent
import ru.impression.ui_generator_example.fragment.MainFragmentComponent

class MainActivity : AppCompatActivity() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.impression.c_logic_example
package ru.impression.ui_generator_example

import android.app.Application
import android.content.Context
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package ru.impression.c_logic_example.fragment
package ru.impression.ui_generator_example.fragment

import android.view.View.INVISIBLE
import android.view.View.VISIBLE
import android.widget.Toast
import androidx.fragment.app.Fragment
import ru.impression.c_logic_annotations.MakeComponent
import ru.impression.c_logic_annotations.Prop
import ru.impression.c_logic_base.ComponentScheme
import ru.impression.c_logic_base.ComponentViewModel
import ru.impression.c_logic_example.context
import ru.impression.c_logic_example.databinding.MainFragmentBinding
import ru.impression.c_logic_example.view.AnimatedText
import ru.impression.c_logic_example.view.TextEditorViewModel
import ru.impression.ui_generator_annotations.MakeComponent
import ru.impression.ui_generator_annotations.Prop
import ru.impression.ui_generator_base.ComponentScheme
import ru.impression.ui_generator_base.ComponentViewModel
import ru.impression.ui_generator_example.context
import ru.impression.ui_generator_example.databinding.MainFragmentBinding
import ru.impression.ui_generator_example.view.AnimatedText
import ru.impression.ui_generator_example.view.TextEditorViewModel
import kotlin.random.Random
import kotlin.random.nextInt

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
@file:SuppressLint("RestrictedApi")

package ru.impression.c_logic_example.view
package ru.impression.ui_generator_example.view

import android.annotation.SuppressLint
import androidx.appcompat.widget.AppCompatTextView
import androidx.databinding.adapters.TextViewBindingAdapter
import ru.impression.c_logic_annotations.MakeComponent
import ru.impression.c_logic_annotations.Prop
import ru.impression.c_logic_base.ComponentScheme
import ru.impression.c_logic_base.ComponentViewModel
import ru.impression.c_logic_example.fadeIn
import ru.impression.c_logic_example.fadeOut
import ru.impression.c_logic_example.translateLeft
import ru.impression.c_logic_example.translateRight
import ru.impression.ui_generator_annotations.MakeComponent
import ru.impression.ui_generator_annotations.Prop
import ru.impression.ui_generator_base.ComponentScheme
import ru.impression.ui_generator_base.ComponentViewModel
import ru.impression.ui_generator_example.fadeIn
import ru.impression.ui_generator_example.fadeOut
import ru.impression.ui_generator_example.translateLeft
import ru.impression.ui_generator_example.translateRight

@MakeComponent
class AnimatedText : ComponentScheme<AppCompatTextView, AnimatedTextViewModel>({ viewModel ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package ru.impression.c_logic_example.view
package ru.impression.ui_generator_example.view

import android.widget.FrameLayout
import ru.impression.c_logic_annotations.MakeComponent
import ru.impression.c_logic_annotations.SharedViewModel
import ru.impression.c_logic_base.ComponentScheme
import ru.impression.c_logic_base.ComponentViewModel
import ru.impression.c_logic_example.databinding.TextEditorBinding
import ru.impression.ui_generator_annotations.MakeComponent
import ru.impression.ui_generator_annotations.SharedViewModel
import ru.impression.ui_generator_base.ComponentScheme
import ru.impression.ui_generator_base.ComponentViewModel
import ru.impression.ui_generator_example.databinding.TextEditorBinding

@MakeComponent
class TextEditor : ComponentScheme<FrameLayout, TextEditorViewModel>({ TextEditorBinding::class })
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/layout/main_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<variable
name="viewModel"
type="ru.impression.c_logic_example.fragment.MainFragmentViewModel" />
type="ru.impression.ui_generator_example.fragment.MainFragmentViewModel" />
</data>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
Expand All @@ -26,11 +26,11 @@
android:onClick="@{() -> viewModel.toggleVisibility()}"
android:text="Toggle visibility" />

<ru.impression.c_logic_example.view.TextEditorComponent
<ru.impression.ui_generator_example.view.TextEditorComponent
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<ru.impression.c_logic_example.view.AnimatedTextComponent
<ru.impression.ui_generator_example.view.AnimatedTextComponent
animation="@={viewModel.textAnimation}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/text_editor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<variable
name="viewModel"
type="ru.impression.c_logic_example.view.TextEditorViewModel" />
type="ru.impression.ui_generator_example.view.TextEditorViewModel" />
</data>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">C-logic</string>
<string name="app_name">UI-generator</string>
</resources>

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions c-logic-base/src/main/AndroidManifest.xml

This file was deleted.

8 changes: 4 additions & 4 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
rootProject.name='C-logic'
rootProject.name='UI-generator'
include ':app'
include ':c-logic-annotations'
include ':c-logic-processor'
include ':c-logic-base'
include ':ui-generator-annotations'
include ':ui-generator-processor'
include ':ui-generator-base'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package ru.impression.ui_generator_annotations

annotation class MakeComponent
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package ru.impression.c_logic_annotations
package ru.impression.ui_generator_annotations

annotation class Prop(val twoWay: Boolean = false)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package ru.impression.ui_generator_annotations

annotation class SharedViewModel
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ android {
}

dependencies {
implementation project(":c-logic-annotations")
implementation project(':ui-generator-annotations')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.3.0-alpha01'
implementation 'androidx.core:core-ktx:1.3.0'
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ru.impression.c_logic" />
package="ru.impression.ui_generator_base" />
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package ru.impression.c_logic_base
package ru.impression.ui_generator_base

import android.view.View
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import ru.impression.c_logic_annotations.SharedViewModel
import ru.impression.ui_generator_annotations.SharedViewModel
import kotlin.reflect.full.findAnnotation


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.impression.c_logic_base
package ru.impression.ui_generator_base

import androidx.databinding.ViewDataBinding
import kotlin.reflect.KClass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.impression.c_logic_base
package ru.impression.ui_generator_base

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.impression.c_logic_base
package ru.impression.ui_generator_base

import android.content.ContextWrapper
import android.os.Bundle
Expand All @@ -12,7 +12,7 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStoreOwner
import ru.impression.c_logic_annotations.SharedViewModel
import ru.impression.ui_generator_annotations.SharedViewModel
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.*
import kotlin.reflect.full.createInstance
Expand Down
Loading

0 comments on commit b853a58

Please sign in to comment.