Coder Social home page Coder Social logo

olehkhol / weathercomparator Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 51.6 MB

An Android app Weather Averages

Home Page: https://play.google.com/store/apps/details?id=ua.in.khol.oleh.touristweathercomparer

License: Apache License 2.0

Java 100.00%

weathercomparator's Introduction

The source code of an application Weather Averages

Contents

Build

You are free to use this code in any manner you see fit, but please refrain from creating direct clones of my application on Google Play Store or other platforms.

Let's respect each other's creative work and innovation.

This is a fully functional codebase of the application.

The only thing you need to do is to fill the API keys file

and the resources file with your own values:

app/src/main/java/ua/in/khol/oleh/touristweathercomparer/Secrets.java
package ua.in.khol.oleh.touristweathercomparer;

public interface Secrets {

    String OPEN_WEATHER_API_KEY = "YOUR_OPEN_WEATHER_API_KEY";
    String GEOCODING_API_KEY = "YOUR_GEOCODING_API_KEY";
    String PLACES_API_KEY = "YOUR_PLACES_API_KEY";
}
app/src/main/res/values/api_keys.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="maps_sdk_for_android_api_key" translatable="false">YOUR_MAPS_SDK_FOR_ANDROID_API_KEY</string>
</resources>

Architecture

   MVVM + DI + RX

In the Weather Averages application, ViewModel retrieval is handled uniquely in Activity and Fragment components. This process is critical to the MVVM architecture, ensuring that ViewModels are appropriately instantiated and tied to their respective lifecycle owners.

ActivityView.getViewModelClass()

This method is used in the ActivityView class to dynamically determine the ViewModel class type associated with a specific activity. It employs Java generics and reflection to achieve this:

package ua.in.khol.oleh.touristweathercomparer.ui;

public abstract class ActivityView<VM extends ActivityViewModel>
        extends AppCompatActivity
        implements ViewModelStoreOwner {
    
    private Class<VM> getViewModelClass() {
        Class<? extends ActivityView> aClass = getClass();
        Class superclass = aClass.getSuperclass();
        Type genericSuperclass = superclass.getGenericSuperclass();
        ParameterizedType parameterizedType = (ParameterizedType) genericSuperclass;
        Type actualTypeArgument = parameterizedType.getActualTypeArguments()[0];
        
        return (Class<VM>) actualTypeArgument;
    }
}

FragmentView.getViewModelClass()

In FragmentView, the getViewModelClass method operates slightly differently, tailored for fragments:

package ua.in.khol.oleh.touristweathercomparer.ui;

public abstract class FragmentView<VM extends FragmentViewModel>
        extends Fragment {

    private Class<VM> getViewModelClass() {
        Class<? extends FragmentView> aClass = getClass();
        Type genericSuperclass = aClass.getGenericSuperclass();
        ParameterizedType parameterizedType = (ParameterizedType) genericSuperclass;
        Type actualTypeArgument = parameterizedType.getActualTypeArguments()[0];
        
        return (Class<VM>) actualTypeArgument;
    }
}

Services

Location API

Weather API

Dependencies

Android Architecture Components

AndroidX

ReactiveX

Square Open Source

Google

License

Copyright 2020-2024 Oleh Kholiavchuk

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.

weathercomparator's People

Contributors

olehkhol 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.