This document discusses cleaning up Android architecture using Architecture Components. It begins with an overview of issues with previous approaches like callbacks between layers. It then covers how each component addresses these issues: ViewModel/LiveData for presentation, MediatorLiveData for merging repository calls in the domain layer, and Room/Paging Library for the data layer. Considerations are provided for each component regarding threading, lifecycles, and other best practices. Code examples demonstrate implementations across the layers following these guidelines.
20180518 QNAP Seminar - Introduction to React NativeEric Deng
What is React Native?
How does React Native work?
Writing React Native
Expo
Components, props, and states
Component lifecycle
Declarative and imperative
Event handling
User input
Style
Layout
Data access
Publishing your Project
20180518 QNAP Seminar - Introduction to React NativeEric Deng
What is React Native?
How does React Native work?
Writing React Native
Expo
Components, props, and states
Component lifecycle
Declarative and imperative
Event handling
User input
Style
Layout
Data access
Publishing your Project
Come see how easy it is to build fast, accurate, and responsive web UIs using the React library. Even if you’ve never written Javascript before, React’s straightforward syntax can get you started with your UI project quickly. In this session, you’ll learn about React’s declarative syntax and state representation, explore some of the basic components that are used to build sophisticated UIs, and leave with a foundational application you can continue to build on.
React (or React Js) is a declarative, component-based JS library to build SPA(single page applications) which was created by Jordan Walke, a software engineer at Facebook. It is flexible and can be used in a variety of projects.
React Js Basic Details and Descriptions
Frontend Javascript Library, to make decent SPA
The fastest way to build a segregated component based front end for software development.
React – Structure Container Component In MeteorDesignveloper
Over the past two months, I have been working on an interesting project at my company which is supposed to be a very big one. So at first, as a team leader and core maker, I spent quite a lot of time to find a good starting point, I meant stuff like how to structure the project, which frontend stack to use, how that stack connects to server, how to set up and bring all those things together, etc, to satisfy all the project’s requirements.....
In this presentation, Prashant Sharma of Valuebound has talked about ReactJS - a JavaScript library for building user interfaces. Check out the agendas to know what is there for you.
----------------------------------------------------------
Get Socialistic
Our website: http://valuebound.com/
LinkedIn: http://bit.ly/2eKgdux
Facebook: https://www.facebook.com/valuebound/
Twitter: http://bit.ly/2gFPTi8
Tutorial Videos: https://www.youtube.com/playlist?list=PLD8nQCAhR3tQ7KXnvIk_v_SLK-Fb2y_k_
Day 1 : Introduction to React, Babel and Webpack
Prerequisites of starting the workshop ( Basic understanding of Node & Express )
What is Virtual DOM?
What is React and why should we use it?
Install and set up React:
a-Using create-react-app
b-From scratch using Babel and Webpack. We will use Webpack Dev Server.
Day 2 : React Basic Concepts
Types of Components: Class-based and Functional based Components
Use of JSX
Parent, Child, and Nested Components
Difference between State and Props
Create and Handle Routes
Component Lifecycle Methods
Create a form and handling form inputs
Use of arrow functions and Spread Operator
Day 3: Advanced Concepts in React
Use of Refs
What are Higher Order Components( HOC )?
How to use HOC
Understanding Context in React
ReactJS is arguably the most popular Javascript framework around for web development today. With more and more teams exploring and adopting React, here is TechTalks presentation elaborating fundamentals of React, in a code along session
Getting started with the reactjs, basics of reactjs, introduction of reactjs, core concepts of reactjs and comparison with the other libraries/frameworks
In this presentation I will go through latest features being added in Spring 3.1/3.2 one more time and also will try to look behind the scene on what new features are comming in Spring 4 which should be released at the end of this year.
Building Modern Apps using Android Architecture ComponentsHassan Abid
Android architecture components are part of Android Jetpack. They are a collection of libraries that help you design robust, testable, and maintainable apps. In this talk, We will cover LiveData, ViewModel, Room and lifecycle components. We will go through practical code example to understand modern android app architecture especially MVVM architecture.
Come see how easy it is to build fast, accurate, and responsive web UIs using the React library. Even if you’ve never written Javascript before, React’s straightforward syntax can get you started with your UI project quickly. In this session, you’ll learn about React’s declarative syntax and state representation, explore some of the basic components that are used to build sophisticated UIs, and leave with a foundational application you can continue to build on.
React (or React Js) is a declarative, component-based JS library to build SPA(single page applications) which was created by Jordan Walke, a software engineer at Facebook. It is flexible and can be used in a variety of projects.
React Js Basic Details and Descriptions
Frontend Javascript Library, to make decent SPA
The fastest way to build a segregated component based front end for software development.
React – Structure Container Component In MeteorDesignveloper
Over the past two months, I have been working on an interesting project at my company which is supposed to be a very big one. So at first, as a team leader and core maker, I spent quite a lot of time to find a good starting point, I meant stuff like how to structure the project, which frontend stack to use, how that stack connects to server, how to set up and bring all those things together, etc, to satisfy all the project’s requirements.....
In this presentation, Prashant Sharma of Valuebound has talked about ReactJS - a JavaScript library for building user interfaces. Check out the agendas to know what is there for you.
----------------------------------------------------------
Get Socialistic
Our website: http://valuebound.com/
LinkedIn: http://bit.ly/2eKgdux
Facebook: https://www.facebook.com/valuebound/
Twitter: http://bit.ly/2gFPTi8
Tutorial Videos: https://www.youtube.com/playlist?list=PLD8nQCAhR3tQ7KXnvIk_v_SLK-Fb2y_k_
Day 1 : Introduction to React, Babel and Webpack
Prerequisites of starting the workshop ( Basic understanding of Node & Express )
What is Virtual DOM?
What is React and why should we use it?
Install and set up React:
a-Using create-react-app
b-From scratch using Babel and Webpack. We will use Webpack Dev Server.
Day 2 : React Basic Concepts
Types of Components: Class-based and Functional based Components
Use of JSX
Parent, Child, and Nested Components
Difference between State and Props
Create and Handle Routes
Component Lifecycle Methods
Create a form and handling form inputs
Use of arrow functions and Spread Operator
Day 3: Advanced Concepts in React
Use of Refs
What are Higher Order Components( HOC )?
How to use HOC
Understanding Context in React
ReactJS is arguably the most popular Javascript framework around for web development today. With more and more teams exploring and adopting React, here is TechTalks presentation elaborating fundamentals of React, in a code along session
Getting started with the reactjs, basics of reactjs, introduction of reactjs, core concepts of reactjs and comparison with the other libraries/frameworks
In this presentation I will go through latest features being added in Spring 3.1/3.2 one more time and also will try to look behind the scene on what new features are comming in Spring 4 which should be released at the end of this year.
Building Modern Apps using Android Architecture ComponentsHassan Abid
Android architecture components are part of Android Jetpack. They are a collection of libraries that help you design robust, testable, and maintainable apps. In this talk, We will cover LiveData, ViewModel, Room and lifecycle components. We will go through practical code example to understand modern android app architecture especially MVVM architecture.
Home Improvement: Architecture & KotlinJorge Ortiz
Two of the most relevant news from the recent Google IO were the Guide to App Architecture and the adoption of Kotlin as a first-class language. Both have a very positive impact in our applications.
In my talk I introduced and advanced architecture inspired in the Clean Architecture of Uncle Bob and I showed the impact of these two elements.
First I mentioned the components provided for integration with the lifecycle and how that saves a lot of effort to preserve view models or presenters. I briefly covered the methods that we had available until know focusing on the use of a fragment with no view that had the retained instance property set to true.
Then I covered some real scenarios explaining the improvements that Kotlin provide us with. Some examples:
- Conciseness of data classes (and limitations)
- Property observation
- Use of extensions in presentation logic
- Sealed classes for results (as an either-like type)
This is a "Code or it didn't happen" (TM) talk. ;-)
Presentation given at the Toulouse JUG in Dec 2019
GraalVM and its native-image component allow building native standalone executables from Java or any other language compiling to Java bytecode like Scala or Kotlin.
This talks goes through the practical steps leading to producing a native executable for a command-line tool, explaining the benefits and also the limits of GraalVM native-image.
Esta charla comprende las lecciones aprendidas convirtiendo la app de Android de Teambox (una app repleta de deuda técnica y con un alto nivel de acoplamiento entre clases), en la versión actual de Redbooth, que intenta cumplir la arquitectura Hexagonal y los principios SOLID. Durante la exposición explicaremos como fuimos desenredando el código paso a paso; como aplicamos por partes los conceptos de la arquitectura hexagonal; como dejamos de lado componentes del framework de Android que dificultaban el mantenimiento de la app; y que errores cometimos, como los solucionamos y como se podrían haber evitado.
Handling an SQLite database in Android implies challenges like a lot of boilerplate code, database operations on the main thread, queries checked at runtime and especially unmaintainable code. At Google I/O 2017, the Android team launched Room, an SQLite object mapper, that provides a set of components and features that will solve all these challenges and will help us, the developers, to have a better experience when using a database in our app.
The presentation will include examples about how to use the main components from Room (@Entity, @Dao, @Database), how to handle the relations between the entities, how to use the (observable) queries and not run database operations on the main thread. Also, we will discover more details about the migration support, compile time query verification and what’s happening behind the scenes.
Clojure is a new dialect of LISP that runs on the Java Virtual Machine (JVM). As a functional language, it offers great benefits in terms of programmer productivity; as a language that runs on the JVM, it also offers the opportunity to reuse existing Java libraries. Simon’s interest is in using Clojure to build desktop applications with the Java Swing GUI library. In this presentation Simon discusses how the power of Clojure can be applied to Swing, and whether it hits the sweet spot.
In this session, see Google Web Toolkit used in exotic and creative ways to solve interesting engineering problems, from authoring OpenSocial apps that run as both Web gadgets and native Android applications, to developing Adobe AIR applications using GWT, compiling CSS selectors to Javascript at compile time, running multithreaded code with GWT and Gears workers, or exporting GWT libraries for JavaScript users. Learn the secrets of writing "faster than possible" GWT code, how to use Generators and Linkers in harmony, and make seamless procedure calls from GWT code to other environments like Flash, Gears, or Android.
Comment développer une application mobile en 8 semaines - Meetup PAUG 24-01-2023Nicolas HAAN
À l'automne dernier, nous avons eu la chance de développer une nouvelle app pour un de nos clients en partant de zéro.
L'objectif ? Créer une application minimale à mettre entre les mains de dizaines de beta testeurs, en 8 semaines et avec 2 développeurs. Partant d'une feuille blanche, nous avons pu mettre en œuvre les dernières avancées de la stack Android sans être contraints par l'existant.
Développeurs débutants comme expérimentés, vous repartirez de ce talk avec nos apprentissages clés sur l'architecture ainsi que sur les bibliothèques et astuces pour faciliter la maintenance et la stabilité de l'application. En bonus, nous répondrons à la question : "Une app full-compose, est-ce que c'est cool ?"
2. Who am I?
Team & Technical Lead
myToys Group GmbH
https://github.com/dgomez-developer
dgomez.developer@gmail.com
@dgomezdebora
www.linkedin.com/in/deboragomezbertoli
7. It is impossible for this to happen
Trying to update an Activity / Fragment that is not there anymore …
#commitconf @dgomezdebora
if((view as? Activity)?.isFinishing == false){
view?.showQuestions(result.map { question ->
QuestionViewItem(question.id, question.question, question.contact) })
}
8. This is a callback nightmare
Callback in datasource, that calls a callback in the repository, that calls a callback in the
interactor, that calls a callback in the presenter, that calls the view.
#commitconf @dgomezdebora
getQuestionsUseCase.invoke(object : Callback<List<Question>, Throwable>
{..}
questionsRepository.getQuestions(object : Callback<List<Question>,
Throwable> {..}
override fun setView(view: QuestionsView?) {
this.view = view}
11. ViewModel as Presenter
Is designed to store and manage UI-related data in a lifecycle conscious way.
#commitconf @dgomezdebora
Is automatically retained during configuration changes.
Remains in memory until the Activity finishes or the Fragment is detached.
Includes support for Kotlin coroutines.
12. LiveData as callbacks
#commitconf @dgomezdebora
Is an observable data holder class.
Is lifecycle-aware, only updates observers that are in an active lifecycle state
(STARTED, RESUMED).
Observers are bound to lifecycle so they are clean up when their associated lifecycle is
destroyed.
13. Transformations as mapper
#commitconf @dgomezdebora
Transformations.map() - It observes the LiveData. Whenever a
new value is available it takes the value, applies the Function on in, and
sets the Function’s output as a value on the LiveData it returns.
Transformations.switchmap() - It observes the LiveData and
returns a new LiveData with the value mapped according to the Function
applied.
15. Implementation - ViewModel
#commitconf @dgomezdebora
class QuestionsListViewModel (private val getQuestionsUseCase: GetQuestionsUseCase) :
ViewModel() {
[...]
fun init() {
loaderLD.value = true
val listOfQuestionsLD = getQuestionsUseCase.invoke(Unit)
questionsLD.removeSource(listOfQuestionsLD)
questionsLD.addSource(listOfQuestionsLD) {
when (it) {
is Either.Success -> questionsLD.value =
it.value.map { question -> QuestionViewItem(question.id, question.question,
question.contact) }
is Either.Failure -> messageLD.value = R.string.error_getting_questions
}
loaderLD.value = false
}
}
}
16. Implementation - Activity
#commitconf @dgomezdebora
private val viewModel by viewModel<QuestionsListViewModel>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
list_of_questions.layoutManager = LinearLayoutManager(this)
list_of_questions.adapter = QuestionsListAdapter()
viewModel.showQuestions().observe(this, Observer {
adapter.questionsList = it
})
viewModel.showMessage().observe(this, Observer {
Snackbar.make(list_of_questions_container, it, Snackbar.LENGTH_LONG).show()
})
viewModel.init()
}
17. Considerations - ViewModel
ViewModel shouldn’t be referenced in any object that can outlive the Activity,
so the ViewModel can be garbage collected.
A ViewModel must never reference a view, Lifecycle, or any class that may hold a
reference to the Activity context.
ViewModel is not an eternal thing, they also get killed when the OS is low on
resources and kills our process.
.... don’t panic! Google is already working on a safe state module for
ViewModel. (still in alpha)
#commitconf @dgomezdebora
18. Considerations - LiveData
If the code is executed in a worker thread, use postValue(T).
setValue(T) should be called only from the main thread.
If you use this instead of viewLifeCycleOwner, LiveData won´t remove
observers every time the Fragment´s view is destroyed.
Views should not be able of updating LiveData, this is ViewModel’s
reponsibility. Do not expose mutable LiveData to the views.
When using observeForever(Observer), you should manually call
removeObserver(Observer)
#commitconf @dgomezdebora
19. Considerations - Transformations
Solution is to use Events to trigger a new request and update the
LiveData.
Transformations create a new LiveData when called (both map and switchmap).
It is very common to miss that the observer will only receive updates to the
LiveData assigned to the var in the moment of the subscription!!
#commitconf @dgomezdebora
22. MediatorLiveData as merger of
repository calls
Scenario: we have 2 instances of different LiveData (liveDataA, liveDataB), we
want to merge their emissions in one LiveData (liveDatasMerger).
Then, liveDataA and liveDataB will become sources of liveDatasMerger.
Each time onChanged is called for either of them, we will set a new value
in liveDatasMerger.
#commitconf @dgomezdebora
23. Implementation - Use Case
#commitconf @dgomezdebora
class GetQuestionsUseCase(
private val questionsRepository: QuestionsRepository,
threadExecutor: ThreadExecutor,
postExecutionThread: PostExecutionThread):
BaseBackgroundLiveDataInteractor<Unit, List<Question>>(
threadExecutor, postExecutionThread) {
override fun run(inputParams: Unit): LiveData<List<Question>> {
return questionsRepository.getQuestions()
}
}
24. Implementation - Interactor
#commitconf @dgomezdebora
abstract class BaseBackgroundLiveDataInteractor<I, O>(
private val backgroundThread: ThreadExecutor,
private val postExecutionThread: PostExecutionThread) {
internal abstract fun run(inputParams: I): LiveData<O>
operator fun invoke(inputParams: I): LiveData<Either<O, Throwable>> =
buildLiveData(inputParams)
25. Implementation - Interactor
#commitconf @dgomezdebora
private fun buildLiveData(inputParams: I): LiveData<Either<O, Throwable>> =
MediatorLiveData<Either<O, Throwable>>().also {
backgroundThread.execute(Runnable {
val result = execute(inputParams)
postExecutionThread.post(Runnable {
when (result) {
is Either.Success -> it.addSource(result.value) { t -> it.postValue(Either.Success(t)) }
is Either.Failure -> it.postValue(Either.Failure(result.error))
}
})
})
}
private fun execute(inputParams: I): Either<LiveData<O>, Throwable> = try {
Either.Success(run(inputParams))
} catch (throwable: Throwable) {
Either.Failure(throwable)
}
26. Considerations - MediatorLiveData
It does not combine data. In case we want to combine data, we will have to do it a
separate method that receives all the LiveDatas and merges their values.
If a method where an addSource is executing is called several times, we will leak all the
previous LiveData.
#commitconf @dgomezdebora
28. Room as persistence data source
Provides an abstraction layer over SQLite.
It is highly recommended by Google using Room instead of SQLite.
We can use LiveData with Room to observe changes in the database.
In Room the intensive use of annotations let us write less code.
Provides integration with RxJava out of the box.
There is no compile time verification of raw SQLite queries.
To convert SQLite queries into data objects, you need to write a lot of boilerplate
code.
#commitconf @dgomezdebora
34. Considerations - Room
Room does not support to be called on the MainThread unless you set
allowMainThreadQueries().
Room is NOT a relational database.
You could simulate a relational database using:
@ForeignKey to define one-to-many relationships.
@Embedded to create nested objects.
Intermediate class operating as Join query to define many-to-many relationships.
If your app runs in a single process, you should follow the singleton pattern when
instantiating an AppDatabase object.
Otherwise …. You will get crashes like SQLiteException when migrating different
instances of the AppDatabase object.
#commitconf @dgomezdebora
38. Paging Library
#commitconf @dgomezdebora
Helps loading displaying small chunks of data at a time.
The key component is the PagedList.
If any loaded data changes, a new instance of the PagedList is emitted to the
observable data holder from a LiveData.
39. Paging Library DataSource
#commitconf @dgomezdebora
class QuestionsPagedDataSource(
private val api: QuestionsApi,
private val requestParams: QuestionsRequestParams,
private val errorLD: MutableLiveData<Throwable>) :
PageKeyedDataSource<Int, Question>() {
46. This is a win!
No memory leaks.
Ensures our UI matches our data state.
No crashes due to stopped Activities.
No more manual lifecycle handling.
Proper configuration changes.
#commitconf @dgomezdebora
47. What about RxJava?
If you already use Rx for this, you can connect both using
LiveDataReactiveStreams.
LiveData was designed to allow the View observe the ViewModel.
If you want to use LiveData beyond presentation layer, you might find that
MediatorLiveData is not as powerful when combining and operating on streams
as RXJava.
However with some magic using Kotlin Extensions it might be more than
enough for your use case.
#commitconf @dgomezdebora