series = getSeries(2, false, null); // 2 = archive and current shows, false = don't filter networks, null = ignore networks filter
+ for (int i = 0; i < series.size(); i += 1) {
+ updateShowStats(series.get(i));
+ }
+ }
+
+ public void updateShowStats(String serieId) {
+ int seasonCount = getSeasonCount(serieId);
+ int unwatchedAired = getEPUnwatchedAired(serieId);
+ int unwatched = getEPUnwatched(serieId);
+ NextEpisode nextEpisode = getNextEpisode(serieId);
+ String nextEpisodeString = getNextEpisodeString(nextEpisode, DroidShows.showNextAiring && 0 < unwatchedAired && unwatchedAired < unwatched);
+ execQuery("UPDATE series SET seasonCount="+ seasonCount +", unwatchedAired="+ unwatchedAired +", unwatched="+ unwatched +", nextEpisode='"+ nextEpisodeString +"', nextAir='"+ nextEpisode.firstAired +"' WHERE id="+ serieId);
+ }
+
+ public void updateToday(String newToday) {
+ today = newToday;
+ }
+
+ private class EpisodeSeen {
+ public String episode;
+ public int seen;
+
+ public EpisodeSeen(String episode, int seen) {
+ this.episode = episode;
+ this.seen = seen;
+ }
+ }
+
+ public class EpisodeRow {
+ public String id;
+ public String name;
+ public String aired;
+ public Date airedDate;
+ public int seen;
+
+ public EpisodeRow(String id, String name, String aired, Date airedDate, int seen) {
+ this.id = id;
+ this.name = name;
+ this.aired = aired;
+ this.airedDate = airedDate;
+ this.seen = seen;
+ }
+ }
+
+ public class NextEpisode {
+ public String serieId;
+ public int season;
+ public int episode;
+ public String firstAired;
+ public Date firstAiredDate = null;
+
+ public NextEpisode(String serieId, int season, int episode, String firstAired) {
+ this.serieId = serieId;
+ this.season = season;
+ this.episode = episode;
+ this.firstAired = firstAired;
+ if (!firstAired.equals("") && !firstAired.equals("null")) {
+ try { this.firstAiredDate = new SimpleDateFormat("yyyy-MM-dd").parse(firstAired); // used by seasons AsyncTask, so shouldn't use dateFormat
+ } catch (ParseException e) { e.printStackTrace(); }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/droidshows_772_src/src/nl/asymmetrics/droidshows/utils/SwipeDetect.java b/droidshows_772_src/src/nl/asymmetrics/droidshows/utils/SwipeDetect.java
new file mode 100644
index 00000000..cbcc56ae
--- /dev/null
+++ b/droidshows_772_src/src/nl/asymmetrics/droidshows/utils/SwipeDetect.java
@@ -0,0 +1,43 @@
+package nl.asymmetrics.droidshows.utils;
+
+import android.app.Activity;
+import android.view.MotionEvent;
+import android.view.View;
+import nl.asymmetrics.droidshows.DroidShows;
+import nl.asymmetrics.droidshows.ui.ViewSerie;
+
+public class SwipeDetect implements View.OnTouchListener {
+ private int onDownX, onDownY;
+ public int value = 0;
+
+ public boolean onTouch(View v, MotionEvent event) {
+ switch (event.getAction()) {
+ case MotionEvent.ACTION_DOWN:
+ onDownX = (int) event.getX();
+ onDownY = (int) event.getY();
+ value = 0;
+ break;
+ case MotionEvent.ACTION_MOVE:
+ int deltaX = onDownX - (int) event.getX();
+ int deltaY = onDownY - (int) event.getY();
+ if (value > -1 && (((deltaX < 0) ? -deltaX : deltaX) / 4) > ((deltaY < 0) ? -deltaY : deltaY)) {
+ if (deltaX > v.getWidth() / 4) { // > 0 = RTL
+ if (v.getContext() instanceof DroidShows) {
+ value = 1; // mark next episode seen
+ return true;
+ } else if (DroidShows.switchSwipeDirection || v.getContext() instanceof ViewSerie) {
+ ((Activity)v.getContext()).onBackPressed();
+ value = -1;
+ return true;
+ }
+ value = -1; // Don't fire more than once
+ } else if (!DroidShows.switchSwipeDirection && -deltaX > v.getWidth() / 4) { // < 0 = LTR
+ ((Activity)v.getContext()).onBackPressed();
+ value = -1;
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/droidshows_772_src/src/nl/asymmetrics/droidshows/utils/Update.java b/droidshows_772_src/src/nl/asymmetrics/droidshows/utils/Update.java
new file mode 100644
index 00000000..56a780b1
--- /dev/null
+++ b/droidshows_772_src/src/nl/asymmetrics/droidshows/utils/Update.java
@@ -0,0 +1,91 @@
+package nl.asymmetrics.droidshows.utils;
+
+import android.database.Cursor;
+import android.database.sqlite.SQLiteException;
+import android.util.Log;
+
+public class Update
+{
+ private SQLiteStore db;
+
+ public Update(SQLiteStore db) {
+ this.db = db;
+ }
+
+ public boolean updateDroidShows() {
+ String version = getVersion();
+ boolean done = false;
+ if (version.equals("0.1.5-6") || version.equals("0")) {
+ done = u0156To0157();
+ version = getVersion();
+ }
+ if (version.equals("0.1.5-7")) {
+ done = u0157To0157G();
+ version = getVersion();
+ }
+ if (version.equals("0.1.5-7G")) {
+ done = u0157GTo0157G2();
+ }
+ return done;
+ }
+
+ private String getVersion() {
+ String version = "";
+ try {
+ Cursor c = db.Query("SELECT version FROM droidseries");
+ if (c != null && c.moveToFirst()) {
+ version = c.getString(0);
+ return version;
+ }
+ c.close();
+ } catch (SQLiteException e) {
+ Log.e(SQLiteStore.TAG, e.getMessage());
+ }
+ db.execQuery("INSERT INTO droidseries (version) VALUES ('0');");
+ Log.d(SQLiteStore.TAG, "DB version blank. All updates will be run; please ignore errors.");
+ return "0";
+ }
+
+ private boolean u0156To0157() {
+ Log.d(SQLiteStore.TAG, "UPDATING TO VERSION 0.1.5-7");
+ try {
+ db.execQuery("ALTER TABLE series ADD COLUMN passiveStatus INTEGER DEFAULT 0");
+ db.execQuery("UPDATE droidseries SET version='0.1.5-7'");
+ return true;
+ } catch (Exception e) {
+ Log.e(SQLiteStore.TAG, "Error updating database");
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ private boolean u0157To0157G() {
+ Log.d(SQLiteStore.TAG, "UPDATING TO VERSION 0.1.5-7G");
+ try {
+ db.execQuery("ALTER TABLE series ADD COLUMN seasonCount INTEGER DEFAULT -1");
+ db.execQuery("ALTER TABLE series ADD COLUMN unwatchedAired INTEGER DEFAULT -1");
+ db.execQuery("ALTER TABLE series ADD COLUMN unwatched INTEGER DEFAULT -1");
+ db.execQuery("ALTER TABLE series ADD COLUMN nextEpisode VARCHAR DEFAULT '-1'");
+ db.execQuery("ALTER TABLE series ADD COLUMN nextAir VARCHAR DEFAULT '-1'");
+ db.execQuery("UPDATE droidseries SET version='0.1.5-7G'");
+ return true;
+ } catch (Exception e) {
+ Log.e(SQLiteStore.TAG, "Error updating database");
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ private boolean u0157GTo0157G2() {
+ Log.d(SQLiteStore.TAG, "UPDATING TO VERSION 0.1.5-7G2");
+ try {
+ db.execQuery("ALTER TABLE series ADD COLUMN extResources VARCHAR NOT NULL DEFAULT ''");
+ db.execQuery("UPDATE droidseries SET version='0.1.5-7G2'");
+ return true;
+ } catch (Exception e) {
+ Log.e(SQLiteStore.TAG, "Error updating database");
+ e.printStackTrace();
+ return false;
+ }
+ }
+}
\ No newline at end of file
diff --git a/droidshows_772_src/src/nl/asymmetrics/droidshows/utils/Utils.java b/droidshows_772_src/src/nl/asymmetrics/droidshows/utils/Utils.java
new file mode 100644
index 00000000..3406c23b
--- /dev/null
+++ b/droidshows_772_src/src/nl/asymmetrics/droidshows/utils/Utils.java
@@ -0,0 +1,35 @@
+package nl.asymmetrics.droidshows.utils;
+
+import android.app.Activity;
+import android.content.Context;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+
+//import android.util.Log;
+public class Utils
+{
+ public boolean isNetworkAvailable(Activity mActivity) {
+ Context context = mActivity.getApplicationContext();
+ ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ if (connectivity == null) {
+ // Log.d(TAG," connectivity is null");
+ return false;
+ } else {
+ // Log.d(TAG," connectivity is not null");
+ NetworkInfo[] info = connectivity.getAllNetworkInfo();
+ if (info != null) {
+ // Log.d(TAG," info is not null");
+ for (int i = 0; i < info.length; i++) {
+ if (info[i].getState() == NetworkInfo.State.CONNECTED) {
+ return true;
+ } else {
+ // Log.d(TAG," info["+i+"] is not connected");
+ }
+ }
+ } else {
+ // Log.d(TAG," info is null");
+ }
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/droidshows_772_src/src/org/apache/commons/io/FileUtils.java b/droidshows_772_src/src/org/apache/commons/io/FileUtils.java
new file mode 100644
index 00000000..220851df
--- /dev/null
+++ b/droidshows_772_src/src/org/apache/commons/io/FileUtils.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.commons.io;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+public class FileUtils {
+ public static FileOutputStream openOutputStream(File file) throws IOException {
+ if (file.exists()) {
+ if (file.isDirectory()) {
+ throw new IOException("File '" + file + "' exists but is a directory");
+ }
+ if (file.canWrite() == false) {
+ throw new IOException("File '" + file + "' cannot be written to");
+ }
+ } else {
+ File parent = file.getParentFile();
+ if (parent != null && parent.exists() == false) {
+ if (parent.mkdirs() == false) {
+ throw new IOException("File '" + file + "' could not be created");
+ }
+ }
+ }
+ return new FileOutputStream(file);
+ }
+
+ public static void copyURLToFile(URL source, File destination) throws IOException {
+ InputStream input = source.openStream();
+ try {
+ FileOutputStream output = openOutputStream(destination);
+ try {
+ IOUtils.copy(input, output);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
+ } finally {
+ IOUtils.closeQuietly(input);
+ }
+ }
+}
\ No newline at end of file
diff --git a/droidshows_772_src/src/org/apache/commons/io/IOUtils.java b/droidshows_772_src/src/org/apache/commons/io/IOUtils.java
new file mode 100644
index 00000000..7a55e66a
--- /dev/null
+++ b/droidshows_772_src/src/org/apache/commons/io/IOUtils.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.commons.io;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public class IOUtils {
+ /**
+ * The default buffer size to use.
+ */
+ private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
+
+ public IOUtils() {
+ super();
+ }
+
+ /**
+ * Unconditionally close an InputStream
.
+ *
+ * Equivalent to {@link InputStream#close()}, except any exceptions will be ignored.
+ * This is typically used in finally blocks.
+ *
+ * @param input the InputStream to close, may be null or already closed
+ */
+ public static void closeQuietly(InputStream input) {
+ try {
+ if (input != null) {
+ input.close();
+ }
+ } catch (IOException ioe) {}
+ }
+
+ /**
+ * Unconditionally close an OutputStream
.
+ *
+ * Equivalent to {@link OutputStream#close()}, except any exceptions will be ignored.
+ * This is typically used in finally blocks.
+ *
+ * @param output the OutputStream to close, may be null or already closed
+ */
+ public static void closeQuietly(OutputStream output) {
+ try {
+ if (output != null) {
+ output.close();
+ }
+ } catch (IOException ioe) {
+ // ignore
+ }
+ }
+
+ // read toByteArray
+ //-----------------------------------------------------------------------
+ /**
+ * Get the contents of an InputStream
as a byte[]
.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream
.
+ *
+ * @param input the InputStream
to read from
+ * @return the requested byte array
+ * @throws NullPointerException if the input is null
+ * @throws IOException if an I/O error occurs
+ */
+ public static byte[] toByteArray(InputStream input) throws IOException {
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ copy(input, output);
+ return output.toByteArray();
+ }
+
+ // copy from InputStream
+ //-----------------------------------------------------------------------
+ /**
+ * Copy bytes from an InputStream
to an
+ * OutputStream
.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream
.
+ *
+ * Large streams (over 2GB) will return a bytes copied value of
+ * -1
after the copy has completed since the correct
+ * number of bytes cannot be returned as an int. For large streams
+ * use the copyLarge(InputStream, OutputStream)
method.
+ *
+ * @param input the InputStream
to read from
+ * @param output the OutputStream
to write to
+ * @return the number of bytes copied
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @throws ArithmeticException if the byte count is too large
+ * @since Commons IO 1.1
+ */
+ public static int copy(InputStream input, OutputStream output) throws IOException {
+ long count = copyLarge(input, output);
+ if (count > Integer.MAX_VALUE) {
+ return -1;
+ }
+ return (int) count;
+ }
+
+ /**
+ * Copy bytes from a large (over 2GB) InputStream
to an
+ * OutputStream
.
+ *
+ * This method buffers the input internally, so there is no need to use a
+ * BufferedInputStream
.
+ *
+ * @param input the InputStream
to read from
+ * @param output the OutputStream
to write to
+ * @return the number of bytes copied
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since Commons IO 1.3
+ */
+ public static long copyLarge(InputStream input, OutputStream output)
+ throws IOException {
+ byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
+ long count = 0;
+ int n = 0;
+ while (-1 != (n = input.read(buffer))) {
+ output.write(buffer, 0, n);
+ count += n;
+ }
+ return count;
+ }
+
+}