Skip to content

Commit f38274e

Browse files
committed
App starting state with no architecture components
Change-Id: I5e1685fed58e6cdc582a08661642120e3112055b
1 parent e8768e0 commit f38274e

File tree

99 files changed

+4789
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+4789
-0
lines changed

.gitignore

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.DS_Store
2+
3+
# built application files
4+
*.apk
5+
*.ap_
6+
7+
# files for the dex VM
8+
*.dex
9+
10+
# Java class files
11+
*.class
12+
13+
# generated files
14+
bin/
15+
out/
16+
gen/
17+
18+
19+
# Build stuff (auto-generated by android update project ...)
20+
build.xml
21+
ant.properties
22+
local.properties
23+
project.properties
24+
25+
# idea project files
26+
.idea/
27+
*.iml
28+
*.ipr
29+
*.iws
30+
31+
# Gradle-based build
32+
.gradle
33+
build/

CONTRIBUTING.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# How to become a contributor and submit your own code
2+
## Contributor License Agreements
3+
We'd love to accept your sample apps and patches! Before we can take them, we
4+
have to jump a couple of legal hurdles.
5+
Please fill out either the individual or corporate Contributor License Agreement (CLA).
6+
* If you are an individual writing original source code and you're sure you
7+
own the intellectual property, then you'll need to sign an [individual CLA]
8+
(https://developers.google.com/open-source/cla/individual).
9+
* If you work for a company that wants to allow you to contribute your work,
10+
then you'll need to sign a [corporate CLA]
11+
(https://developers.google.com/open-source/cla/corporate).
12+
Follow either of the two links above to access the appropriate CLA and
13+
instructions for how to sign and return it. Once we receive it, we'll be able to
14+
accept your pull requests.
15+
## Contributing A Patch
16+
1. Submit an issue describing your proposed change to the repo in question.
17+
1. The repo owner will respond to your issue promptly.
18+
1. If your proposed change is accepted, and you haven't already done so, sign a
19+
Contributor License Agreement (see details above).
20+
1. Fork the desired repo, develop and test your code changes.
21+
1. Ensure that your code adheres to the existing style in the sample to which
22+
you are contributing. Refer to the
23+
[Android Code Style Guide]
24+
(https://source.android.com/source/code-style.html) for the
25+
recommended coding standards for this organization.
26+
1. Ensure that your code has an appropriate set of unit tests which all pass.
27+
1. Submit a pull request.

LICENSE

+514
Large diffs are not rendered by default.

README.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Sunshine with Architecture Components
2+
================================
3+
## About
4+
This app is for the [Build an App with Architecture Components Codelab](https://codelabs.developers.google.com/codelabs/build-app-with-arch-components/index.html).
5+
6+
## Starting Classes
7+
8+
Below is a description of the different packages and classes in the starting app code.
9+
10+
### `data` package
11+
Contains all classes related to local and network app data.
12+
13+
##### `data.network` package
14+
All classes related to fetching data from the network.
15+
16+
* The network fetching and parsing functions are all written for you.
17+
* You will not modify the `NetworkUtils`, `OpenWeatherJsonParser` and `WeatherResponse` classes.
18+
* `WeatherNetworkDataSource` manages everything to do with the network. It's a [singleton](https://en.wikipedia.org/wiki/Singleton_pattern). It contains:
19+
* `scheduleRecurringFetchWeatherSync()` - Makes a repeating [`JobService`](https://developer.android.com/reference/android/app/job/JobService.html) using [`FirebaseJobDispatcher`](https://developer.android.com/topic/performance/scheduling.html#fjd). This repeating job will eventually sync weather information in the background.
20+
* `startFetchWeatherService()` - [`IntentService`](https://developer.android.com/reference/android/app/IntentService.html) for doing an immediate fetch of weather data.
21+
* `fetchWeather()` - Actually gets weather forecast data. This method uses the JSON parsing classes and network classes to make the fetch. It currently doesn't do anything with the fetched weather data.
22+
23+
##### `data.database` package
24+
All classes related to caching the data locally (it's pretty empty right now).
25+
* `WeatherEntry` - A simple Java object representing one day of weather.
26+
27+
28+
### `ui` package
29+
All activities and adapters - anything to do with display.
30+
31+
##### ui.detail package
32+
* `DetailActivity` - [`Activity`](https://developer.android.com/reference/android/app/Activity.html) for a single day of forecast.
33+
##### ui.list package
34+
* `MainActivty` - [`Activity`](https://developer.android.com/reference/android/app/Activity.html) for a list of `WeatherEntry` forecasts.
35+
* `ForecastAdapter` - [`RecyclerView.Adapter`](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter.html) for displaying the list of `WeatherEntry` forecasts.
36+
37+
### `utilities` package
38+
* You will not modify `SunshineDateUtils` or `SunshineWeatherUtils`.
39+
* `SunshineDateUtils` - Utility methods for normalizing dates across time zones; this helps us to "round" to the nearest date, so that when you store a date in the database, it always refers to that date at 12:00am, GMT.
40+
* `SunshineWeatherUtils` - Utility methods related to displaying the weather, such as picking the right image resource to show a cloudy sky or rain.
41+
42+
### AppExectuors class
43+
This class provides a global executor pool. You can learn more about thread pools [here](https://www.youtube.com/watch?v=uCmHoEY1iTM). In short, this class provides an easy and efficient way to run code off of the main thread.
44+
45+
## License
46+
All image and audio files (including *.png, *.jpg, *.svg, *.mp3, *.wav
47+
and *.ogg) are licensed under the CC-BY-NC license. All other files are
48+
licensed under the Apache 2 license. See the LICENSE file for details.
49+
Copyright 2017 Google Inc. All rights reserved.
50+
Licensed under the Apache License, Version 2.0 (the "License");
51+
you may not use this file except in compliance with the License.
52+
You may obtain a copy of the License at
53+
http://www.apache.org/licenses/LICENSE-2.0
54+
Unless required by applicable law or agreed to in writing, software
55+
distributed under the License is distributed on an "AS IS" BASIS,
56+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
57+
See the License for the specific language governing permissions and
58+
limitations under the License.

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 26
5+
buildToolsVersion '26.0.1'
6+
7+
defaultConfig {
8+
applicationId "com.example.android.sunshine"
9+
minSdkVersion 14
10+
targetSdkVersion 26
11+
versionCode 1
12+
versionName "1.0"
13+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14+
}
15+
buildTypes {
16+
release {
17+
minifyEnabled false
18+
}
19+
}
20+
21+
dataBinding.enabled = true
22+
23+
compileOptions {
24+
sourceCompatibility JavaVersion.VERSION_1_8
25+
targetCompatibility JavaVersion.VERSION_1_8
26+
}
27+
}
28+
29+
// Versions number variables are defined in the module build.gradle file
30+
dependencies {
31+
compile "com.android.support:appcompat-v7:$support_version"
32+
compile "com.android.support:recyclerview-v7:$support_version"
33+
compile "com.android.support:preference-v7:$support_version"
34+
compile "com.android.support.constraint:constraint-layout:$constraint_layout_version"
35+
compile "com.firebase:firebase-jobdispatcher:$firebase_jobdispatcher_version"
36+
37+
// Instrumentation dependencies use androidTestCompile"
38+
// (as opposed to testCompile for local unit tests run in the JVM"
39+
androidTestCompile "junit:junit:$junit_version"
40+
androidTestCompile "com.android.support:support-annotations:$support_version"
41+
androidTestCompile "com.android.support.test:runner:$support_test_version"
42+
androidTestCompile "com.android.support.test:rules:$support_test_version"
43+
}

app/src/main/AndroidManifest.xml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright (C) 2016 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<manifest
18+
xmlns:android="http://schemas.android.com/apk/res/android"
19+
package="com.example.android.sunshine">
20+
21+
<!-- This permission is necessary in order for Sunshine to perform network access. -->
22+
<uses-permission android:name="android.permission.INTERNET"/>
23+
24+
<application
25+
android:allowBackup="true"
26+
android:icon="@mipmap/ic_launcher"
27+
android:label="@string/app_name"
28+
android:supportsRtl="true"
29+
android:theme="@style/AppTheme">
30+
31+
<!--The manifest entry for our MainActivity. Each Activity requires a manifest entry-->
32+
<activity
33+
android:name=".ui.list.MainActivity"
34+
android:label="@string/app_name"
35+
android:launchMode="singleTop"
36+
android:theme="@style/AppTheme.Forecast">
37+
</activity>
38+
39+
<!--The manifest entry for our DetailActivity. Each Activity requires a manifest entry-->
40+
<activity
41+
android:name=".ui.detail.DetailActivity"
42+
android:label="@string/title_activity_detail"
43+
android:parentActivityName=".ui.list.MainActivity"
44+
android:theme="@style/AppTheme">
45+
<meta-data
46+
android:name="android.support.PARENT_ACTIVITY"
47+
android:value=".ui.list.MainActivity"/>
48+
<intent-filter>
49+
<action android:name="android.intent.action.MAIN"/>
50+
<category android:name="android.intent.category.LAUNCHER"/>
51+
</intent-filter>
52+
</activity>
53+
54+
55+
<!--This is required for immediate syncs -->
56+
<service
57+
android:name=".data.network.SunshineSyncIntentService"
58+
android:exported="false" />
59+
60+
<!-- This is the Service declaration used in conjunction with FirebaseJobDispatcher -->
61+
<service
62+
android:name=".data.network.SunshineFirebaseJobService"
63+
android:exported="false">
64+
<intent-filter>
65+
<action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE"/>
66+
</intent-filter>
67+
</service>
68+
69+
</application>
70+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (C) 2017 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.android.sunshine;
18+
19+
import android.os.Handler;
20+
import android.os.Looper;
21+
import android.support.annotation.NonNull;
22+
23+
import java.util.concurrent.Executor;
24+
import java.util.concurrent.Executors;
25+
26+
/**
27+
* Global executor pools for the whole application.
28+
* <p>
29+
* Grouping tasks like this avoids the effects of task starvation (e.g. disk reads don't wait behind
30+
* webservice requests).
31+
*/
32+
public class AppExecutors {
33+
34+
// For Singleton instantiation
35+
private static final Object LOCK = new Object();
36+
private static AppExecutors sInstance;
37+
private final Executor diskIO;
38+
private final Executor mainThread;
39+
private final Executor networkIO;
40+
41+
private AppExecutors(Executor diskIO, Executor networkIO, Executor mainThread) {
42+
this.diskIO = diskIO;
43+
this.networkIO = networkIO;
44+
this.mainThread = mainThread;
45+
}
46+
47+
public static AppExecutors getInstance() {
48+
if (sInstance == null) {
49+
synchronized (LOCK) {
50+
sInstance = new AppExecutors(Executors.newSingleThreadExecutor(),
51+
Executors.newFixedThreadPool(3),
52+
new MainThreadExecutor());
53+
}
54+
}
55+
return sInstance;
56+
}
57+
58+
public Executor diskIO() {
59+
return diskIO;
60+
}
61+
62+
public Executor mainThread() {
63+
return mainThread;
64+
}
65+
66+
public Executor networkIO() {
67+
return networkIO;
68+
}
69+
70+
private static class MainThreadExecutor implements Executor {
71+
private Handler mainThreadHandler = new Handler(Looper.getMainLooper());
72+
73+
@Override
74+
public void execute(@NonNull Runnable command) {
75+
mainThreadHandler.post(command);
76+
}
77+
}
78+
}

0 commit comments

Comments
 (0)