Skip to content

Commit

Permalink
Update Gradle version to 3.5.3, Kotlin version & Update readme file
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedeltaher committed Dec 5, 2019
1 parent 8cf8f38 commit 4c20413
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
54 changes: 36 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,21 @@
![MVVM3](https://user-images.githubusercontent.com/1812129/68319232-446cf900-00be-11ea-92cf-cad817b2af2c.png)

Model-View-ViewModel (ie MVVM) is a template of a client application architecture, proposed by John Gossman as an alternative to MVC and MVP patterns when using Data Binding technology. Its concept is to separate data presentation logic from business logic by moving it into particular class for a clear distinction.
You can also check [**MVP**](https://github.com/ahmedeltaher/Android-MVP-Architecture)
You can also check [**MVP**](https://github.com/ahmedeltaher/Android-MVP-Architecture)

**Why Promoting MVVM VS MVP:**
- ViewModel has Built in LifeCycleOwerness, on the other hand Presenter not, and you have to take this responsiblty in your side.
- ViewModle doesn't have a refrence for View, on the other hade Presenter still hold a refrnce for view, even if you made it as weakrefrence.
- ViewModel survive configuration changes, while it is your own responsiblities to servive the configuration changes in case of Presenter. (Saving and restoring the UI state)

**MVVM Best Pratice:**
- Avoid references to Views in ViewModels.
- Instead of pushing data to the UI, let the UI observe changes to it.
- Distribute responsibilities, add a domain layer if needed.
- Add a data repository as the single-point entry to your data.
- Expose information about the state of your data using a wrapper or another LiveData.
- Consider edge cases, leaks and how long-running operations can affect the instances in your architecture.
- Don’t put logic in the ViewModel that is critical to saving clean state or related to data. Any call you make from a ViewModel can be the last one.


**What is Coroutines ?**
Expand Down Expand Up @@ -69,8 +83,11 @@ They're different tools with different strengths. Like a tank and a cannon, they

- Make Retrofit Calls.

> @GET("topstories/v2/home.json")
> fun fetchNews(): Call<NewsModel>

```kotlin
@GET("topstories/v2/home.json")
fun fetchNews(): Call<NewsModel>
```


- With ```async``` we create new coroutine and returns its future result as an implementation of [Deferred].
Expand All @@ -83,21 +100,22 @@ They're different tools with different strengths. Like a tank and a cannon, they



> launch {
> try {
> val serviceResponse: Data? = withContext(Dispatchers.IO) { dataRepository.requestNews()
> }
> if (serviceResponse?.code == Error.SUCCESS_CODE) {
> val data = serviceResponse.data
> callback.onSuccess(data as NewsModel)
> } else {
> callback.onFail(serviceResponse?.error)
> }
> } catch (e: Exception) {
> callback.onFail(Error(e))
> }
> }
```kotlin
launch {
try {
val serviceResponse: Data? = withContext(Dispatchers.IO) { dataRepository.requestNews()
}
if (serviceResponse?.code == Error.SUCCESS_CODE) {
val data = serviceResponse.data
callback.onSuccess(data as NewsModel)
} else {
callback.onFail(serviceResponse?.error)
}
} catch (e: Exception) {
callback.onFail(Error(e))
}
}
```



Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')

//kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.60"
implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.60"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61"
implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.61"

/**-------------------testing libs------------------------------------------**/
//UI Testing , AndroidJUnitRunner and JUnit Rules &Espresso dependencies
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ buildscript {
maven { url "https://maven.google.com" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.60"
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.3.3'
Expand Down

0 comments on commit 4c20413

Please sign in to comment.