Giter Site home page Giter Site logo

nglauber / mvp-sample Goto Github PK

View Code? Open in Web Editor NEW
35.0 6.0 6.0 156 KB

Demonstrates how to implement MVP (Model View Presenter) pattern using Kotlin, RXJava, Retrofit, Dagger and DataBinding

Kotlin 92.96% PHP 7.04%
kotlin rxjava retrofit2 databinding mvp architecture dagger2 firebase-auth google-places mockito

mvp-sample's Introduction

mvp-sample

Demonstrates how to implement MVP (Model View Presenter) pattern using Kotlin, RXJava, Retrofit, Dagger and DataBinding

Setup

I just cloned this project... how do I run this? Read on!

Client

Right after importing the project you will notice that it fails to compile due to a missing google-services.json file error. This project uses Firebase authentication and that file is required.

Why isn't google-services.json in github?

Quoting Sam here:

The general answer is yes, the google-services.json is safe to check in to your repo and is something that should be shared among engineers on your team. The JSON file does not contain any super-sensitive information (like a server API key). It does contain some information like your database URL, Android API key, and storage bucket. These are not secrets, but if your security rules are not set up correctly an attacker could use them against you. However since these values are also compiled into your APK as resources, the theoretical attacker would not need your JSON file to get these values anyway.

For a library or open-source sample we do not include the JSON file because the intention is that users insert their own to point the code to their own backend. That's why you won't see JSON files in most of our firebase repos on github.

So how do I get a google-services.json file to use with this project?

You need to create your own firebase project, which is luckily very easy to do:

  1. Create a new Firebase project in your Firebase console https://console.firebase.google.com/
  2. Choose a name for your project like MVPSample
  3. Then choose "Add Firebase to your Android app"
  4. And complete with the following:
    • Android package name: br.com.nglauber.exemplolivro
    • App nickname (optional): MVPSample
    • Debug signing certificate SHA-1: The SHA-1 in your debug.keystore (see here if you don't know how to get this exactly)
  5. Lastly click in the Authentication section SIGN-IN METHOD tab and make sure you at least enable Google as a Sign-in provider. You can also enable Facebook but that requires a little bit more setup so feel free to skip initially.

Server

The client app can either store data in a local database or it can post it to a local server. A basic PHP server is provided under folder server that you can use to run this sample.

Pre-requisites to launch the server

  • PHP Installed
  • MySql Installed

Under mvp-sample/server run:

$ php -S {your_local_ip}:{your_port} 

Do not use "localhost" for {your_local_ip}

Example:

php -S 192.168.1.104:8000

Make sure you can reach your server by opening this URL in your browser:

http://{your_local_ip}:{your_port}/webservice.php

Example:

http://192.168.1.104:8000/webservice.php

You should get a blank page with just a pair of square brackets: []

In the app's build.gradle file you can specify the SERVER_PATH you chose, like this:

buildConfigField "String", "SERVER_PATH", "\"http://192.168.1.104:8000/\""

Tests

Before running the tests you should grant READ_EXTERNAL_STORAGE permissions to the app with adb from the command line:

$ adb shell pm grant br.com.nglauber.exemplolivro android.permission.READ_EXTERNAL_STORAGE

DataSource

You can switch the DataSource from PostWeb to PostDb in PostsModule.kt

    @Provides
    fun providesDataSource(user : User?) : PostDataSource {
        //return PostWeb(user?.uuid, application)
        return PostDb()
    }

mvp-sample's People

Contributors

nglauber avatar pablonajt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mvp-sample's Issues

Mysql error when hitting the server `mysqli::mysqli(): (HY000/2002): No such file or directory`

There seems to be a problem in some configurations where the PHP server is returning this error:

05-03 13:42:39.852 11388-18458/br.com.nglauber.exemplolivro D/OkHttp: <b>Warning</b>:  mysqli::mysqli(): (HY000/2002): No such file or directory in <b>mvp-sample/server/webservice.php</b> on line <b>5</b><br />

It seems to get fixed by replacing:

<?php
$servername = "localhost";

with

<?php
$servername = "127.0.0.1";

in webservice.php

Submitting a PR.

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.