Giter VIP home page Giter VIP logo

stars_war_demo_sdk's Introduction

StarWars SDK

StarWars SDK integrates can be used to get Planet, People, & Films list of Star Wars.

Installation

Project Root Level Gradle

allprojects {
	repositories {
		maven { url 'https://jitpack.io' }
	}
}

OR

settings.gradle Level Gradle

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
    }
}

App Level Gradle

dependencies {
	 implementation 'com.github.debojyoti452:stars_war_demo_sdk:${version}'
}

APIs

  • Response has three Types
       -> Response.Success // will return success model. Typed Request Model will be returned.
       -> Response.Error   // will return if any error found. String message will be returned.
       -> Response.Loading // will return Loading State. Show any progress dialog.
  • People & Planet Model
       -> getEyeColors() // is prebuilt function available in People Model which will return an List<eyecolor: String?>? of first 5 people.
       -> getFiveClimateAndPopulation() // is prebuilt function available in Planet Model which will return an List<Pair<climate: String?, population: String?>>? of first 5 planets.

Integrations

  • Initiate StarWars SDK
       private val initiateStarWars: StarWars by lazy {
           StarWars.Builder()
               .setContext(requireContext())
               .create()
       }
  • To get All People

       initiateStarWars.getPeople(peopleOnResponseListener)
  • People OnResponseListener

       private val peopleOnResponseListener = object : ResponseOnListener<Response<People>> {
       	override fun onResult(result: Response<People>) {
           		when (result) {
   			is Response.Success -> {
   			    _loading.postValue(false)
   			    _peopleEyeData.postValue(result.data.getEyeColors())
   			}

   			is Response.Error -> {
   			    _loading.postValue(false)
   			    _errorMessage.postValue(Pair(true, result.exception.toString()))
   			}

   			is Response.Loading -> {
   			    _loading.postValue(true)
   			}
           	}
       }
   }
  • To get All Planet

       initiateStarWars.getPlanets(planetOnResponseListener)
  • Planet OnResponseListener

       private val planetOnResponseListener = object : ResponseOnListener<Response<Planet>> {
       	override fun onResult(result: Response<Planet>) {
   	    when (result) {
   		is Response.Success -> {
   		    _loading.postValue(false)
   		    _populationData.postValue(result.data.getFiveClimateAndPopulation())
   		}

   		is Response.Error -> {
   		    _loading.postValue(false)
   		    _errorMessage.postValue(Pair(true, result.exception.toString()))
   		}

   		is Response.Loading -> {
   		    _loading.postValue(true)
   		}
   	}
       }
   }
  • To get All Films

       initiateStarWars.getFilm(filmOnResponseListener)
  • Film OnResponseListener

   private val filmOnResponseListener = object : ResponseOnListener<Response<Film>> {
       override fun onResult(result: Response<Film>) {
           when (result) {
               is Response.Success -> {
                   _filmData.postValue(result.data.dataList)
                   _loading.postValue(false)
               }

               is Response.Error -> {
                   _loading.postValue(false)
                   _errorMessage.postValue(Pair(true, result.exception.toString()))
               }

               is Response.Loading -> {
                   _loading.postValue(true)
               }
           }
       }
   }

IMPORTANT NOTES

  • If you're using MVC or MVP architecture or Java without Viewmodel then you need to use it like this:

        starWars.getPlanets(planetResponse -> {
                requireActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Log.d("TEST:: ", planetResponse.toString());
                    }
                });
        });
  • If you're using MVVM make sure to use postValue() instead setValue():

        is Response.Success -> {
            _loading.postValue(false)
            _populationData.postValue(result.data.getFiveClimateAndPopulation())
        }
        
        is Response.Error -> {
            _loading.postValue(false)
            _errorMessage.postValue(Pair(true, result.exception.toString()))
        }
        
        is Response.Loading -> {
            _loading.postValue(true)
        }

ScreenShots

Open Source Plugins used

Library README
Retrofit [https://square.github.io/retrofit/]
Kotlin Coroutines [https://kotlinlang.org/docs/coroutines-overview.html]
GSON Serializer [https://github.com/google/gson]
Mockk [https://mockk.io/]
Android STD Libs [https://developer.android.com/kotlin/first]

stars_war_demo_sdk's People

Contributors

debojyoti452 avatar

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.