Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
ccjeng committed Oct 8, 2016
1 parent dbfb966 commit f7ca261
Show file tree
Hide file tree
Showing 17 changed files with 122 additions and 19 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Weather+
[![Release](https://img.shields.io/github/release/ccjeng/US-Stocks.svg)](https://github.com/ccjeng/Weather/releases)
[![Twitter](https://img.shields.io/badge/[email protected]?style=flat)](http://twitter.com/ccjeng)

Weather+ is a lightware weather app that focuses on summarizing the current, the next 48 hours and the next week weather data

Libraries
* [Retrofit] (http://square.github.io/retrofit/)
* [RxAndroid] (https://github.com/ReactiveX/RxAndroid)
* [MPAndroidChart] (https://github.com/PhilJay/MPAndroidChart)
* [ButterKnife] (http://jakewharton.github.io/butterknife/)
* [Calligraphy] (https://github.com/chrisjenx/Calligraphy)

<a href="https://play.google.com/store/apps/details?id=com.ccjeng.weather&utm_source=global_co&utm_medium=prtnr&utm_content=Mar2515&utm_campaign=PartBadge&pcampaignid=MKT-Other-global-all-co-prtnr-py-PartBadge-Mar2515-1"><img alt="Get it on Google Play" src="https://play.google.com/intl/en_us/badges/images/generic/en-play-badge.png" width="150"/></a>
10 changes: 8 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ android {
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
versionName "1.0.0.100916W"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
buildTypes.each {
it.buildConfigField 'String', 'DARK_SKY_KEY', DARK_SKY_KEY
}
}
}

Expand All @@ -31,6 +34,8 @@ dependencies {
compile 'com.android.support:gridlayout-v7:24.2.1'
compile 'com.google.android.gms:play-services-location:9.6.1'
compile 'com.google.android.gms:play-services-places:9.6.1'
compile 'com.google.firebase:firebase-core:9.6.1'
releaseCompile 'com.google.firebase:firebase-crash:9.6.1'
compile 'com.jakewharton:butterknife:8.4.0'
apt 'com.jakewharton:butterknife-compiler:8.4.0'
compile 'io.reactivex:rxjava:1.1.10'
Expand All @@ -41,8 +46,9 @@ dependencies {
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
compile 'com.mikepenz:iconics-core:2.8.1@aar'
compile 'com.mikepenz:weather-icons-typeface:2.0.10.2@aar'
//compile 'com.github.PhilJay:MPAndroidChart:v2.2.5'
compile 'com.github.PhilJay:MPAndroidChart:v3.0.0-beta1'
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
compile 'joda-time:joda-time:2.9.4'
compile('com.mikepenz:aboutlibraries:5.8.1@aar') { transitive = true }
}
apply plugin: 'com.google.gms.google-services'
42 changes: 42 additions & 0 deletions app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"project_info": {
"project_number": "353941179510",
"firebase_url": "https://lithe-window-141808.firebaseio.com",
"project_id": "lithe-window-141808",
"storage_bucket": "lithe-window-141808.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:353941179510:android:ab7f7d48c6491f0b",
"android_client_info": {
"package_name": "com.ccjeng.weather"
}
},
"oauth_client": [
{
"client_id": "353941179510-hed3far83m0r223u359vt86tth7gb36a.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyD0dDq7RKoRRpYS7ZXbqyqVFCUXEHogMSE"
}
],
"services": {
"analytics_service": {
"status": 1
},
"appinvite_service": {
"status": 1,
"other_platform_oauth_client": []
},
"ads_service": {
"status": 2
}
}
}
],
"configuration_version": "1"
}
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

<!-- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
-->
<application
android:name=".view.base.BaseApplication"
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ public interface CitiesView {
void updateCity(City city);
void showTemperatureInCelsius();
void showTemperatureInFahrenheit();
void setSetColumns(int columns);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.View;
Expand All @@ -15,6 +17,7 @@
import com.ccjeng.weather.repository.impl.CacheRepository;
import com.ccjeng.weather.repository.impl.CityRepository;
import com.ccjeng.weather.repository.impl.Repository;
import com.ccjeng.weather.view.activity.SettingsActivity;
import com.ccjeng.weather.view.activity.WeatherActivity;
import com.ccjeng.weather.view.adapter.CitiesAdapter;
import com.ccjeng.weather.view.adapter.RecyclerItemClickListener;
Expand All @@ -32,7 +35,9 @@
* Created by andycheng on 2016/9/5.
*/
public class CitiesPresenter extends BasePresenter<CitiesView>
implements RecyclerItemClickListener.OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
implements RecyclerItemClickListener.OnItemClickListener
, SwipeRefreshLayout.OnRefreshListener
, SharedPreferences.OnSharedPreferenceChangeListener{

private final String TAG = this.getClass().getSimpleName();
private Context context;
Expand All @@ -49,6 +54,7 @@ public CitiesPresenter(CitiesView citiesView, Context context) {
cityRepository = new CityRepository();
repository = new Repository();
this.subscriptions = new CompositeSubscription();
PreferenceManager.getDefaultSharedPreferences(context).registerOnSharedPreferenceChangeListener(this);
}

public void onClickAddCity() {
Expand Down Expand Up @@ -135,6 +141,7 @@ public void onDestroy() {
if (subscriptions != null) {
subscriptions.unsubscribe();
}
PreferenceManager.getDefaultSharedPreferences(context).unregisterOnSharedPreferenceChangeListener(this);
}

@Override
Expand All @@ -154,4 +161,19 @@ public void onItemClick(View view, int position) {
}

}

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {

switch (key) {
case SettingsActivity.PREF_UNIT:
if (sharedPreferences.getString(key, "celsius").equals("celsius")) {
citiesView.showTemperatureInCelsius();
} else {
citiesView.showTemperatureInFahrenheit();
}
break;
}
}

}
5 changes: 3 additions & 2 deletions app/src/main/java/com/ccjeng/weather/utils/Constant.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.ccjeng.weather.utils;

import com.ccjeng.weather.BuildConfig;

/**
* Created by andycheng on 2016/9/9.
*/
public class Constant {

public static final String FORECASTIO_ENDPOINT = "https://api.darksky.net/";
public static final String FORECASTIO_APIKEY = "3021a64fa44fe78d95b05991be3fecc4";

public static final String FORECASTIO_APIKEY = BuildConfig.DARK_SKY_KEY;
}
14 changes: 14 additions & 0 deletions app/src/main/java/com/ccjeng/weather/utils/Utils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.ccjeng.weather.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import java.util.UUID;

/**
Expand All @@ -10,4 +14,14 @@ public class Utils {
public static String getUniqueID() {
return UUID.randomUUID().toString();
}

public static boolean isNetworkConnected(Context mContext) {
ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if (ni == null) {
// There are no active networks.
return false;
} else
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.ccjeng.weather.R;
import com.ccjeng.weather.model.City;
import com.ccjeng.weather.presenter.CitiesView;
import com.ccjeng.weather.presenter.impl.CitiesPresenter;
import com.ccjeng.weather.utils.Utils;
import com.ccjeng.weather.view.GoogleApiClientProvider;
import com.ccjeng.weather.view.adapter.CitiesAdapter;
import com.ccjeng.weather.view.adapter.RecyclerItemClickListener;
Expand Down Expand Up @@ -71,6 +73,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
}

private void initialize() {
getActivity().overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

adapter = new CitiesAdapter(getActivity());
StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
Expand Down Expand Up @@ -112,6 +115,10 @@ public void onClick(View view) {
android.R.color.holo_orange_light);
citiesRecyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), presenter));
presenter.reloadCities();

if (!Utils.isNetworkConnected(getActivity())) {
Toast.makeText(getActivity(), getActivity().getString(R.string.no_connection), Toast.LENGTH_LONG).show();
}
}

@Override
Expand Down Expand Up @@ -165,16 +172,12 @@ public void updateCity(City city) {

@Override
public void showTemperatureInCelsius() {

adapter.showTemperaturesInCelsius();
}

@Override
public void showTemperatureInFahrenheit() {

adapter.showTemperaturesInFahrenheit();
}

@Override
public void setSetColumns(int columns) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.places.Places;
import com.mikepenz.aboutlibraries.Libs;
import com.mikepenz.aboutlibraries.LibsBuilder;

import butterknife.BindView;
import butterknife.ButterKnife;
Expand Down Expand Up @@ -72,7 +74,6 @@ protected void onStop() {
super.onStop();
}


protected synchronized void buildGoogleApiClient() {
googleApiClient = new GoogleApiClient
.Builder(this)
Expand Down Expand Up @@ -130,14 +131,13 @@ public boolean onNavigationItemSelected(MenuItem menuItem) {
startActivity(new Intent(MainActivity.this, SettingsActivity.class));
break;
case R.id.navAbout:
/* new LibsBuilder()
//provide a style (optional) (LIGHT, DARK, LIGHT_DARK_TOOLBAR)
new LibsBuilder()
.withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR)
.withAboutIconShown(true)
.withAboutVersionShown(true)
.withAboutAppName(getString(R.string.app_name))
.withActivityTitle(getString(R.string.action_about))
.start(MainActivity.this);*/
.start(MainActivity.this);
break;

}
Expand Down
Binary file modified app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
<item>fahrenheit</item>
</string-array>

<string name="no_connection">No Internet Connection</string>

<string name="wind">Wind</string>
<string name="pressure">Pressure</string>
<string name="humidity">Humidity</string>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath "io.realm:realm-gradle-plugin:1.2.0"

classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down

0 comments on commit f7ca261

Please sign in to comment.