GithubHelp home page GithubHelp logo

matthieucoisne / yelpexplorer Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 1.0 1.63 MB

Android application that demonstrates the differences between using a REST API versus a GraphQL API while following the best practices using Kotlin, Jetpack Compose, Coroutines, Clean Architecture, MVVM, Dependency Injection, Tests...

License: Apache License 2.0

Kotlin 100.00%
android kotlin coroutines clean-architecture mvvm tests jetpack-compose

yelpexplorer's Introduction

YelpExplorer

build Kotlin Version API

Project Description

YelpExplorer is a multiplatform project that shows a list of businesses, their details and latest reviews using Yelp's API.

I originally created this project to learn about GraphQL but since Yelp is also serving its data with a REST API, I thought it would be a great opportunity to showcase the power of Clean Architecture when it comes to being able to swap one data layer for another without having to modify the domain and presentation layers.

I then thought it would be a great experience to port this Android project to Flutter and ReactNative to learn more about all the different technologies that exist to build multiplatform applications.

This project is available in:
Compose/Kotlin
Flutter/Dart
ReactNative/TypeScript

Screenshots

Business List Business Details
YelpExplorer - Business List YelpExplorer - Business Details

Project Characteristics

  • 100% Kotlin
  • Modern architecture (Clean Architecture, Model-View-ViewModel, Dependency Injection)
  • Declarative UI framework using Jetpack Compose
  • Testing
  • Material design
  • Continuous Integration with GitHub Actions
  • Project management with GitHub Project Board

Tech Stack

Development Setup

Yelp API Key

If you want to run this project on an device or an emulator, you need to obtain your own API key from Yelp and provide it to the app.

  1. Request your API key: https://www.yelp.com/developers/documentation/v3/authentication
  2. Update Const.kt with your key

REST vs GraphQL

This project allows you to either use the GraphQL API or the REST API to retrieve data.
To switch between one or the other, you can change the value of DATASOURCE in Const.kt.

Author

Follow me

License

Copyright 2019-Present Matthieu Coisne

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

yelpexplorer's People

Contributors

matthieucoisne avatar

Stargazers

Dinesh K avatar  avatar Abdul Aziz avatar Edmond Ó Floinn avatar Raphaël Bussa avatar Andrea Cappelli avatar Etienne Caron avatar Yohann Jouanneau avatar

Watchers

James Cloos avatar  avatar

yelpexplorer's Issues

Add a REST implementation to compare with GraphQL

I wanted to see how much work it would take and how many layers would be affected from moving from GraphQL to REST. I thought that with a clean architecture, there would only be modifications in the data package, but it turns out that with REST, I have to combine several API calls to reproduce what I have with GraphQL, so use cases should also be updated.

To better demonstrate this, use 2 versions to better separate the 2 implementations.

Remove `closeOnDestroy` for the viewmodel subscopes

KTP.openScopes(ApplicationScope::class)
    .openSubScope(BusinessDetailsViewModel::class) { scope: Scope ->
        scope.installViewModelBinding<BusinessDetailsViewModel>(this)
            .closeOnViewModelCleared(this)
    }
    .closeOnDestroy(this)
    .inject(this)

.closeOnDestroy(this) should not be executed because on rotation, the scope will be closed.
We only want this scope to be closed when the viewmodel gets cleared

Fix memory leaks in Fragments

LeakCanary found a leak with our implementation of ViewBindings.

Problem:
Fragments actually have 2 lifecycles, one for the fragment itself, and one for its view.

In the official documentation:
https://developer.android.com/topic/libraries/view-binding#fragments
"Fragments outlive their views. Make sure you clean up any references to the binding class instance in the fragment's onDestroyView() method."

 

Possible fixes:

1- From the official documentation

override fun onDestroyView() {
    binding = null
    super.onDestroyView()
}

2- AutoClearedValue
https://github.com/android/architecture-components-samples/blob/master/GithubBrowserSample/app/src/main/java/com/android/example/github/util/AutoClearedValue.kt

Usage: var xxx by autoCleared<xxxType>()
But that would require to copy/paste AutoClearedValue.kt in each project... not ideal

3- Wait for a fix from Google
https://stackoverflow.com/questions/59503689/could-navigation-arch-component-create-a-false-positive-memory-leak/59504797#59504797
https://www.youtube.com/watch?v=RS1IACnZLy4&feature=youtu.be&t=957

While 3 would be the best, let's fix this with 1 for now.

 

Also, some other improvements can be made:

  • Don't keep a reference to the adapter in the BusinessListFragment. The adapter could be accessed via the binding.rvBusinessList and casted to a BusinessListAdapter
  • Don't keep a reference to a List<TextView> in BusinessDetailsFragment.

Crash when clicking multiple times on a business in the business list

Steps to repro:

  1. Launch the app and wait for the business list to be loaded
  2. Click multiple times with multiple fingers on a business in the list
    -> The app will crash

Stacktrace:

2020-02-15 15:10:01.642 14060-14060/com.yelpexplorer E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.yelpexplorer, PID: 14060
    java.lang.IllegalArgumentException: navigation destination com.yelpexplorer:id/action_businessListFragment_to_businessDetailsFragment is unknown to this NavController
        at androidx.navigation.NavController.navigate(NavController.java:892)
        at androidx.navigation.NavController.navigate(NavController.java:833)
        at androidx.navigation.NavController.navigate(NavController.java:819)
        at com.yelpexplorer.features.business.presentation.businesslist.BusinessListFragment.navigateToDetails(BusinessListFragment.kt:103)
        at com.yelpexplorer.features.business.presentation.businesslist.BusinessListFragment.access$navigateToDetails(BusinessListFragment.kt:28)

fix lint and test commands

Can't execute this command: ./gradlew lintDebug
But this one succeeds: ./gradlew lintGraphqlDebug lintRestDebug

Same for ./gradlew testDebug

> ./gradlew lintDebug

> Configure project :app
WARNING: DSL element 'useProguard' is obsolete.
It will be removed in a future version of the Android Gradle plugin.
Use 'android.enableR8' in gradle.properties to switch between R8 and Proguard.
WARNING: DSL element 'android.viewBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.viewBinding'.
It will be removed in version 5.0 of the Android Gradle plugin.

> Configure project :features:business
WARNING: DSL element 'android.viewBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.viewBinding'.
It will be removed in version 5.0 of the Android Gradle plugin.

> Configure project :features:settings
WARNING: DSL element 'android.viewBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.viewBinding'.
It will be removed in version 5.0 of the Android Gradle plugin.

> Configure project :libraries:core
WARNING: DSL element 'android.viewBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.viewBinding'.
It will be removed in version 5.0 of the Android Gradle plugin.

FAILURE: Build failed with an exception.

* What went wrong:
Task 'lintDebug' not found in root project 'YelpExplorer'.

* Try:
Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

Gradlle not syncing

Hi
i downloaded the repo to see the code and try it on my machine but i got the below error while building the gradle. Any thing i am missing?
Thanks

A problem occurred configuring root project 'YelpExplorer'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not resolve org.jetbrains.kotlin:kotlin-android-extensions:1.4.0.
     Required by:
         project : > org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.0
      > No cached version of org.jetbrains.kotlin:kotlin-android-extensions:1.4.0 available for offline mode.
      > No cached version of org.jetbrains.kotlin:kotlin-android-extensions:1.4.0 available for offline mode.
      > No cached version of org.jetbrains.kotlin:kotlin-android-extensions:1.4.0 available for offline mode.
      > No cached version of org.jetbrains.kotlin:kotlin-android-extensions:1.4.0 available for offline mode.
      > No cached version of org.jetbrains.kotlin:kotlin-android-extensions:1.4.0 available for offline mode.
   > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.4.0.
     Required by:
         project : > org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.0
      > No cached version of org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.4.0 available for offline mode.
      > No cached version of org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.4.0 available for offline mode.
      > No cached version of org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.4.0 available for offline mode.
      > No cached version of org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.4.0 available for offline mode.
      > No cached version of org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.4.0 available for offline mode.
   > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin-model:1.4.0.
     Required by:
         project : > org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.0
      > No cached version of org.jetbrains.kotlin:kotlin-gradle-plugin-model:1.4.0 available for offline mode.
      > No cached version of org.jetbrains.kotlin:kotlin-gradle-plugin-model:1.4.0 available for offline mode.
      > No cached version of org.jetbrains.kotlin:kotlin-gradle-plugin-model:1.4.0 available for offline mode.
      > No cached version of org.jetbrains.kotlin:kotlin-gradle-plugin-model:1.4.0 available for offline mode.
      > No cached version of org.jetbrains.kotlin:kotlin-gradle-plugin-model:1.4.0 available for offline mode.

Possible solution:
 - Disable offline mode and rerun the build


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.