Skip to content

WeatherNotFound provide everything you need to access the latest status of weather all over the world. also, it will provide you with cache functionalities for a better experience in your application.

Notifications You must be signed in to change notification settings

AbolfaZlRezaEe/WeatherNotFound

Repository files navigation

WeatherNotFound Banner

What is WeatherNotFound?

Did you ever think about having an Android application that shows Weather information to users? or Do you have any Android application with the subject of Weather status? I think you would love to check this library out =)))

WeatherNotFound provides everything you need to access the latest status of weather all over the world. also, it will provide you with cache functionalities for a better experience in your application.

Using WeatherNotFound in your project

To use WeatherNotFound library, you should follow the steps below:

  1. In setting.gradle file of your project, you should add jitpack repository like the following snippet:
pluginManagement {
    repositories {
        ...
        maven("https://jitpack.io")
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        ...
        maven("https://jitpack.io")
    }
}
  1. In build.gradle file of your project, you must add the following dependency like the below:
dependencies {
    implementation("com.github.AbolfaZlRezaEe:WeatherNotFound:{latest_version}")
}
  1. After you followed the two steps above, you should sync the project and wait for Gradle to download all dependencies it needs. when syncing is finished, you have two options for initializing the library:
  • You can initialize the library within the Manifest file. The only thing you need is your OpenWeatherMap ApiKey which you recieved from the website. After that in your Manifest file, you must add these two metadatas like bellow:
<application>

        <meta-data
            android:name="weather_not_found.auto_init_enabled"
            android:value="true"/>

        <meta-data
            android:name="weather_not_found.open_weather_api_key"
            android:value="Your Open Weather ApiKey"/>

</application>
  • Or maybe you want to initialize the library with a lot more configurations. For that, first make sure you disabled auto init mechanism in Manifest file like bellow:
<application>

        <meta-data
            android:name="weather_not_found.auto_init_enabled"
            android:value="false"/>

</application>

And then, initialize the library using init function like bellow:

class BaseApplication : Application() {

    override fun onCreate() {
        super.onCreate()

        WeatherNotFound.getInstance().init(
            context = this,
            openWeatherApiKey = /* Your value */,
            openWeatherResponseLanguage = /* Your value */,
            openWeatherResponseUnit = /* Your value */,
            httpLoggingLevel = HttpLoggingInterceptor.Level.BODY,
            cacheMechanismEnabled = true,
            readTimeoutInSeconds = /* Your value */,
            connectTimeoutInSeconds =  /* Your value */
        )
    }
}
  1. Finally this is the time you can use the library! in your activity, you can use OpenWeatherMap services like this:

NOTE: For now, we just have CurrentWeather Api and 5 Day 3 Hour Forecast! Other APIs will be added as soon as possible.

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        WeatherNotFound.getInstance().getCurrentWeatherInformation(
            latitude = latitude,
            longitude = longitude,
            weatherNotFoundCallback = object :
                WeatherNotFoundCallback<WeatherNotFoundResponse<CurrentWeatherModel>, WeatherNotFoundError> {
                override fun onSuccess(response: WeatherNotFoundResponse<CurrentWeatherModel>) {
                    // Do whatever you want...
                }

                override fun onError(error: WeatherNotFoundError) {
                    error.exception?.printStackTrace()
                }
            }
        )
    }
}

For more information you can see Sample Application!

WeatherNotFound Errors

In some situations, WeatherNotFound will log several errors which tells you what the problem is. for better understanding, we described the reason for each error in following section:

  • Please ensure you have INTERNET permission in your application!: This run-time exception will occur when you don't have Internet permission on your application. make sure you added this permission in the AndroidManifest.xml file.

  • You didn't call init() function of WeatherNotFound!: This run-time exception will occur when you don't call the init() function of WeatherNotFound library in your Application class. make sure you call it!

  • Validation failed! Your Api key is not working...: This is a log that you might see in your logcat section of Android Studio. if you are running Sample Application and saw this, you should check README.md file of Sample Application module and follow the steps correctly. If you are using the library in your own application, please make sure you followed these instructions correctly!

  • You are not allowed to call init() function if auto-init mechanism enabled!: This run-time exception will occur when you don't disable auto-init mechanism and also call init function of library in code! Please either disable the auto-init with meta-data tag in Manifest file, or remove init function from the code!

Don't forget that if you just created your Apikey, it takes some time to enabling it from OpenWeatherMap. So wait some minutes and then try again.

Contribution

Make me happy by contributing to this project! You can help me fix bugs, add features and resolve issues so WeatherNotFound can grow. To start your contribution, submit new issues and create pull requests. You can also check out the list of problems in the Issues Section.

About

WeatherNotFound provide everything you need to access the latest status of weather all over the world. also, it will provide you with cache functionalities for a better experience in your application.

Topics

Resources

Stars

Watchers

Forks

Languages