WeatherInformation: just update remote values when geocoding data changed.
authorgu.martinm@gmail.com <gu.martinm@gmail.com>
Tue, 6 May 2014 06:42:01 +0000 (08:42 +0200)
committergu.martinm@gmail.com <gu.martinm@gmail.com>
Tue, 6 May 2014 06:42:01 +0000 (08:42 +0200)
AndroidManifest.xml
project.properties
src/de/example/exampletdd/WeatherInformationApplication.java [new file with mode: 0644]
src/de/example/exampletdd/WeatherTabsActivity.java

index 1fb26ff..d07af2d 100644 (file)
@@ -32,7 +32,8 @@
         android:icon="@drawable/ic_launcher"
         android:label="@string/app_name"
         android:logo="@drawable/ic_launcher"
-        android:theme="@style/AppTheme" >
+        android:theme="@style/AppTheme"
+        android:name="de.example.exampletdd.WeatherInformationApplication" >
         <!--
         <activity
             android:name="de.example.exampletdd.WeatherInformationActivity"
@@ -48,7 +49,8 @@
         <activity
             android:name="de.example.exampletdd.WeatherTabsActivity"
             android:hardwareAccelerated="false"
-            android:uiOptions="splitActionBarWhenNarrow" >
+            android:uiOptions="splitActionBarWhenNarrow"
+            android:launchMode="singleTop" >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
 
index 770d261..7612c3e 100644 (file)
@@ -12,5 +12,5 @@
 
 # Project target.
 target=android-18
-android.library.reference.1=../../../../../ALLGEMEINS/ALLGEMEIN/Android/android-sdk-linux/extras/google/google_play_services/libproject/google-play-services_lib
+android.library.reference.1=../../../../android/android-sdk-linux/extras/google/google_play_services/libproject/google-play-services_lib
 android.library=false
diff --git a/src/de/example/exampletdd/WeatherInformationApplication.java b/src/de/example/exampletdd/WeatherInformationApplication.java
new file mode 100644 (file)
index 0000000..e9fe4a4
--- /dev/null
@@ -0,0 +1,16 @@
+package de.example.exampletdd;
+
+import android.app.Application;
+import de.example.exampletdd.model.GeocodingData;
+
+public class WeatherInformationApplication extends Application {
+    private GeocodingData mGeocodingData;
+
+    protected void setGeocodingData(final GeocodingData geocodingData) {
+        this.mGeocodingData = geocodingData;
+    }
+
+    protected GeocodingData getGeocodingData() {
+        return this.mGeocodingData;
+    }
+}
index d8abcbb..0cf2431 100644 (file)
@@ -21,11 +21,9 @@ import de.example.exampletdd.model.GeocodingData;
 import de.example.exampletdd.service.WeatherServicePersistenceFile;
 
 public class WeatherTabsActivity extends FragmentActivity {
-    private static final String TAG = "WeatherTabsActivity";
     private static final int NUM_ITEMS = 2;
     private MyAdapter mAdapter;
     private ViewPager mPager;
-    private GeocodingData mGeocodingData;
     private WeatherServicePersistenceFile mWeatherServicePersistenceFile;
 
     @Override
@@ -33,6 +31,7 @@ public class WeatherTabsActivity extends FragmentActivity {
         super.onCreate(savedInstanceState);
         this.setContentView(R.layout.fragment_pager);
 
+        this.mWeatherServicePersistenceFile = new WeatherServicePersistenceFile(this);
         this.mAdapter = new MyAdapter(this.getSupportFragmentManager());
 
         this.mPager = (ViewPager)this.findViewById(R.id.pager);
@@ -150,8 +149,10 @@ public class WeatherTabsActivity extends FragmentActivity {
     @Override
     protected void onRestoreInstanceState(final Bundle savedInstanceState) {
         if (savedInstanceState != null) {
-            this.mGeocodingData = (GeocodingData) savedInstanceState
-                    .getSerializable("GEOCODINGDATA");
+            final WeatherInformationApplication application = (WeatherInformationApplication) this
+                    .getApplication();
+            application.setGeocodingData((GeocodingData) savedInstanceState
+                    .getSerializable("GEOCODINGDATA"));
         }
 
         super.onRestoreInstanceState(savedInstanceState);
@@ -190,8 +191,24 @@ public class WeatherTabsActivity extends FragmentActivity {
         }
         actionBar.getTabAt(1).setText(humanValue);
 
-        final Intent intent = new Intent(this, WeatherInformationBatch.class);
-        this.startService(intent);
+        final WeatherInformationApplication application = (WeatherInformationApplication) this
+                .getApplication();
+        if (application.getGeocodingData() != null) {
+            // If there is previous value.
+            final GeocodingData geocodingDataFile = this.mWeatherServicePersistenceFile
+                    .getGeocodingData();
+            if (!application.getGeocodingData().equals(geocodingDataFile)) {
+                // Just update when value changed.
+                application.setGeocodingData(geocodingDataFile);
+                final Intent intent = new Intent(this, WeatherInformationBatch.class);
+                this.startService(intent);
+            }
+        } else {
+            // There is no previous value.
+            application.setGeocodingData(this.mWeatherServicePersistenceFile.getGeocodingData());
+            final Intent intent = new Intent(this, WeatherInformationBatch.class);
+            this.startService(intent);
+        }
 
         //        if (geocodingData != null) {
         //            if ((this.mGeocodingData == null) || (!this.mGeocodingData.equals(geocodingData))) {
@@ -221,7 +238,9 @@ public class WeatherTabsActivity extends FragmentActivity {
 
     @Override
     public void onSaveInstanceState(final Bundle savedInstanceState) {
-        savedInstanceState.putSerializable("GEOCODINGDATA", this.mGeocodingData);
+        final WeatherInformationApplication application = (WeatherInformationApplication) this
+                .getApplication();
+        savedInstanceState.putSerializable("GEOCODINGDATA", application.getGeocodingData());
 
         super.onSaveInstanceState(savedInstanceState);
     }