Skip to content

HarrisDas/WeatherSDKApp

Repository files navigation

WeatherSDK

WeatherSDK is a simple yet powerful SDK designed to provide weather-related functionalities for Android applications. With this SDK, you can easily create weather fragments, observe weather events, and manage API keys for authenticating requests to a weather service.

Features

  • Create Weather Fragments: Easily create a fragment to display weather information for any city.
  • Observe Weather Events: Monitor weather-related events and handle them within your application.
  • Singleton Pattern: The SDK manager is implemented as a singleton, ensuring that only one instance is used throughout your app.
  • Easy Initialization: Initialize the SDK with your API key to start making weather-related requests.

Installation

To use WeatherSDK in your project, add the following dependency to your build.gradle file:

dependencies {
    implementation 'com.example:weathersdk:1.0.0'
}

Usage

1. Initialize the SDK

Before using the SDK, you need to initialize it with your API key. This should typically be done in your application's onCreate method.

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        WeatherSDKManager.initializeSDK("YOUR_API_KEY")
    }
}

2. Create a Weather Fragment

You can create a WeatherFragment to display weather information for a specific city by calling the createWeatherFragment method.

val fragment = WeatherSDKManager.getInstance().createWeatherFragment("San Francisco")
supportFragmentManager.beginTransaction()
    .replace(R.id.fragment_container, fragment)
    .commit()

3. Observe Weather Events

To monitor weather-related events, use the observeWeatherSdkEvents method, which returns a Flow of WeatherSDKEvent. You can collect these events to handle them appropriately.

lifecycleScope.launch {
    WeatherSDKManager.getInstance().observeWeatherSdkEvents().collect { event ->
        when (event) {
            is WeatherSDKEvent.OnFinished -> {
                // Handle successful event
            }
            is WeatherSDKEvent.OnFinishedWithError -> {
                // Handle error event
                Log.e("WeatherSDK", "Error: ${event.error}")
            }
        }
    }
}

4. Handling SDK Events

The WeatherSDKEvent sealed class defines the events emitted by the SDK:

  • OnFinished: Indicates that an operation has successfully completed.
  • OnFinishedWithError: Indicates that an operation has completed with an error, providing a Throwable with details.

Assumptions & Understanding

The WeatherSDKEvent indicates internal event happened in weather sdk i.e if fragment is closed or closed due to error by SDK then events will be triggered respectively

Improvements

Their are some verticals that can be improved further, which are not implemented in first cut

  1. Persisting apiKey can be secure by implementing EncryptedSharePref. Well that could be debatable that securing apiKey should be a responsibility of App or SDK. For now apiKey is being save in runtime memory in sdk.

Documentation

Documentation can be generated by running Dokka plugin

Author

WeatherSDK is developed and maintained by Harris Das.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages