Android UI State.


Лицензия

Лицензия

Группа

Группа

com.github.sophoun
Идентификатор

Идентификатор

android-ui-state
Последняя версия

Последняя версия

0.0.4
Дата

Дата

Тип

Тип

aar
Описание

Описание

Android UI State.
Android UI State.
Ссылка на сайт

Ссылка на сайт

https://github.com/Sophoun/android-ui-state.git
Система контроля версий

Система контроля версий

https://github.com/Sophoun/android-ui-state

Скачать android-ui-state

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.github.sophoun/android-ui-state/ -->
<dependency>
    <groupId>com.github.sophoun</groupId>
    <artifactId>android-ui-state</artifactId>
    <version>0.0.4</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.sophoun/android-ui-state/
implementation 'com.github.sophoun:android-ui-state:0.0.4'
// https://jarcasting.com/artifacts/com.github.sophoun/android-ui-state/
implementation ("com.github.sophoun:android-ui-state:0.0.4")
'com.github.sophoun:android-ui-state:aar:0.0.4'
<dependency org="com.github.sophoun" name="android-ui-state" rev="0.0.4">
  <artifact name="android-ui-state" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.github.sophoun', module='android-ui-state', version='0.0.4')
)
libraryDependencies += "com.github.sophoun" % "android-ui-state" % "0.0.4"
[com.github.sophoun/android-ui-state "0.0.4"]

Зависимости

compile (5)

Идентификатор библиотеки Тип Версия
org.jetbrains.kotlin : kotlin-android-extensions-runtime jar 1.3.72
androidx.core » core-ktx jar 1.3.2
androidx.fragment » fragment-ktx jar 1.2.5
org.jetbrains.kotlinx : kotlinx-coroutines-core jar 1.3.7
com.github.sophoun : android-utils jar 0.0.2

Модули Проекта

Данный проект не имеет модулей.

Android UI State

We create this library to easy update Activity or Fragment ui state. And also easy to send message between service and Activity or Fragment.

How to use

Import dependency

We host this library on jcenter. Make sure you have added jcenter() repository to your build.gradle root project.

allprojects {
    repositories {
        jcenter()
    }
}

Then import library dependency inside your app module:

implementation 'com.github.sophoun:android-ui-state:0.0.1'

Sample

In our library we force user to extend Activity, Fragment, ViewModel or Service class from our class that provided.

If you add Activity, Fragment or ViewModel you need to extend from class BaseActivity, BaseFragment or BaseViewModel and then set it up with ViewModel that also extended from BaseViewModel.

Example for Activity, Fragment and ViewModel

Activity:

class MyActivity : BaseActivity() {

    private val sampleViewModel by lazy { (application as MyApplication).viewModelFactory.create(SampleViewModel::class.java) }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setupWithViewModel(sampleViewModel)
        
        myBtn.setOnClickListener {
            sampleViewModel.getString()
        }
    }
    
    override fun onStateChanged(state: UiState) {
        super.onStateChanged(state)
        // Here is the place where you
        // handle the state changed
        // of [MyActivityState] class
    }
}

Fragment:

class MyFragment : BaseFragment() {

    private val sampleViewModel by lazy { (activity?.application as MyApplication).viewModelFactory?.create(SampleViewModel::class.java)!! }
    override fun layout(): Int = R.layout.fragment_first

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        setupWithViewModel(sampleViewModel)

        btn_open_second.setOnClickListener {
            sampleViewModel.getStringForFragment()
        }
    }

    override fun onStateChanged(state: UiState) {
        super.onStateChanged(state)
        // Here is the place where you
        // handle the state changed
        // of [MyFragmentState] class
    }
}

Inside your ViewModel class, you just extend from BaseViewModel and then call setState(uiState) from wherever you want.

class SampleViewModel : BaseViewModel() {

    fun getString() {
        setState(MyActivityState("Hello world!"))
    }
    
    fun getStringForFragment() {
        setState(MyFragmentState("Hello Fragment!"))
    }
}

Inside onStateChanged it will be call based on ViewModel lifecycle and the state class type that you cast to.

Example for Service

TODO()

Documentation

Document references

Версии библиотеки

Версия
0.0.4
0.0.1