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.
- 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.
To use WeatherSDK in your project, add the following dependency to your build.gradle file:
dependencies {
implementation 'com.example:weathersdk:1.0.0'
}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")
}
}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()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}")
}
}
}
}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 aThrowablewith details.
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
Their are some verticals that can be improved further, which are not implemented in first cut
- 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 can be generated by running Dokka plugin
WeatherSDK is developed and maintained by Harris Das.