summaryrefslogtreecommitdiff
path: root/src/de/podfetcher
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/podfetcher')
-rw-r--r--src/de/podfetcher/storage/PodDBAdapter.java80
-rw-r--r--src/de/podfetcher/util/Converter.java98
-rw-r--r--src/de/podfetcher/util/NumberGenerator.java18
-rw-r--r--src/de/podfetcher/util/URLChecker.java56
4 files changed, 136 insertions, 116 deletions
diff --git a/src/de/podfetcher/storage/PodDBAdapter.java b/src/de/podfetcher/storage/PodDBAdapter.java
index 6884965f8..d5cb506a1 100644
--- a/src/de/podfetcher/storage/PodDBAdapter.java
+++ b/src/de/podfetcher/storage/PodDBAdapter.java
@@ -174,7 +174,7 @@ public class PodDBAdapter {
if(image.getId() == 0) {
image.setId(db.insert(TABLE_NAME_FEED_IMAGES, null, values));
} else {
- db.update(TABLE_NAME_FEED_IMAGES, values, KEY_ID+"=?", new String[]{String.valueOf(image.getId())});
+ db.update(TABLE_NAME_FEED_IMAGES, values, KEY_ID + "=?", new String[]{String.valueOf(image.getId())});
}
close();
return image.getId();
@@ -198,7 +198,7 @@ public class PodDBAdapter {
if(media.getId() == 0) {
media.setId(db.insert(TABLE_NAME_FEED_MEDIA, null, values));
} else {
- db.update(TABLE_NAME_FEED_MEDIA, values, KEY_ID+"=?", new String[]{String.valueOf(media.getId())});
+ db.update(TABLE_NAME_FEED_MEDIA, values, KEY_ID + "=?", new String[]{String.valueOf(media.getId())});
}
close();
return media.getId();
@@ -214,70 +214,95 @@ public class PodDBAdapter {
values.put(KEY_LINK, item.getLink());
values.put(KEY_DESCRIPTION, item.getDescription());
values.put(KEY_PUBDATE, item.getPubDate());
- if(item.getMedia() != null) {
+ if (item.getMedia() != null) {
if(item.getMedia().getId() == 0) {
setMedia(item.getMedia());
}
values.put(KEY_MEDIA, item.getMedia().getId());
}
- if(item.getFeed().getId() == 0) {
+ if (item.getFeed().getId() == 0) {
setFeed(item.getFeed());
}
values.put(KEY_FEED, item.getFeed().getId());
values.put(KEY_READ, (item.isRead()) ? 1 : 0);
-
+
open();
- if(item.getId() == 0) {
+ if (item.getId() == 0) {
item.setId(db.insert(TABLE_NAME_FEED_ITEMS, null, values));
} else {
- db.update(TABLE_NAME_FEED_ITEMS, values, KEY_ID+"=?", new String[]{String.valueOf(item.getId())});
+ db.update(TABLE_NAME_FEED_ITEMS, values, KEY_ID + "=?",
+ new String[]{String.valueOf(item.getId())});
}
close();
return item.getId();
}
-
- public Cursor getAllCategoriesCursor() {
+
+ /** Get all Categories from the Categories Table.
+ * @return The cursor of the query
+ * */
+ public final Cursor getAllCategoriesCursor() {
open();
Cursor c = db.query(TABLE_NAME_FEED_CATEGORIES, null, null, null, null, null, null);
return c;
}
-
- public Cursor getAllFeedsCursor() {
+
+ /** Get all Feeds from the Feed Table.
+ * @return The cursor of the query
+ * */
+ public final Cursor getAllFeedsCursor() {
open();
Cursor c = db.query(TABLE_NAME_FEEDS, null, null, null, null, null, null);
return c;
}
-
- public Cursor getAllItemsOfFeedCursor(Feed feed) {
+
+ /** Returns a cursor with all FeedItems of a Feed.
+ * @param feed The feed you want to get the FeedItems from.
+ * @return The cursor of the query
+ * */
+ public final Cursor getAllItemsOfFeedCursor(final Feed feed) {
open();
Cursor c = db.query(TABLE_NAME_FEED_ITEMS, null, KEY_FEED + "=?",
new String[]{String.valueOf(feed.getId())}, null, null, null);
return c;
}
-
- public Cursor getFeedMediaOfItemCursor(FeedItem item) {
+
+ /** Returns a cursor for a DB query in the FeedMedia table for a given ID.
+ * @param item The item you want to get the FeedMedia from
+ * @return The cursor of the query
+ * */
+ public final Cursor getFeedMediaOfItemCursor(final FeedItem item) {
open();
Cursor c = db.query(TABLE_NAME_FEED_MEDIA, null, KEY_ID + "=?",
- new String[]{String.valueOf(item.getMedia().getId())}, null, null, null);
+ new String[]{String.valueOf(item.getMedia().getId())},
+ null, null, null);
return c;
}
-
- public Cursor getImageOfFeedCursor(long id) {
+
+ /** Returns a cursor for a DB query in the FeedImages table for a given ID.
+ * @param id ID of the FeedImage
+ * @return The cursor of the query
+ * */
+ public final Cursor getImageOfFeedCursor(final long id) {
open();
Cursor c = db.query(TABLE_NAME_FEED_IMAGES, null, KEY_ID + "=?",
new String[]{String.valueOf(id)}, null, null, null);
return c;
}
-
- public FeedMedia getFeedMedia(long row_index, FeedItem owner) throws SQLException{
+
+ /** Get a FeedMedia object from the Database.
+ * @param rowIndex DB Index of Media object
+ * @param owner FeedItem the Media object belongs to
+ * @return A newly created FeedMedia object
+ * */
+ public final FeedMedia getFeedMedia(final long rowIndex, final FeedItem owner)
+ throws SQLException {
open();
Cursor cursor = db.query(TABLE_NAME_FEED_MEDIA, null, KEY_ID + "=?",
- new String[]{String.valueOf(row_index)}, null, null, null);
-
+ new String[]{String.valueOf(rowIndex)}, null, null, null);
if ((cursor.getCount() == 0) || !cursor.moveToFirst()) {
- throw new SQLException("No FeedMedia found at index: " + row_index);
+ throw new SQLException("No FeedMedia found at index: " + rowIndex);
}
- FeedMedia media = new FeedMedia(row_index,
+ FeedMedia media = new FeedMedia(rowIndex,
owner,
cursor.getLong(cursor.getColumnIndex(KEY_LENGTH)),
cursor.getLong(cursor.getColumnIndex(KEY_POSITION)),
@@ -287,14 +312,13 @@ public class PodDBAdapter {
cursor.getString(cursor.getColumnIndex(KEY_DOWNLOAD_URL)));
close();
return media;
-
}
/** Searches the DB for a FeedImage of the given id.
* @param id The id of the object
* @return The found object
* */
- public FeedImage getFeedImage(final long id) throws SQLException {
+ public final FeedImage getFeedImage(final long id) throws SQLException {
open();
Cursor cursor = this.getImageOfFeedCursor(id);
if ((cursor.getCount() == 0) || !cursor.moveToFirst()) {
@@ -319,7 +343,6 @@ public class PodDBAdapter {
* @param name Name of the database
* @param factory to use for creating cursor objects
* @param version number of the database
- *
* */
public PodDBHelper(final Context context,
final String name, final CursorFactory factory,
@@ -334,7 +357,6 @@ public class PodDBAdapter {
db.execSQL(CREATE_TABLE_FEED_CATEGORIES);
db.execSQL(CREATE_TABLE_FEED_IMAGES);
db.execSQL(CREATE_TABLE_FEED_MEDIA);
-
}
@Override
@@ -344,8 +366,6 @@ public class PodDBAdapter {
+ oldVersion + " to "
+ newVersion + ".");
// TODO delete Database
-
}
-
}
}
diff --git a/src/de/podfetcher/util/Converter.java b/src/de/podfetcher/util/Converter.java
index 262debe51..eb91be286 100644
--- a/src/de/podfetcher/util/Converter.java
+++ b/src/de/podfetcher/util/Converter.java
@@ -4,53 +4,53 @@ import android.util.Log;
/** Provides methods for converting various units. */
public final class Converter {
- /** Class shall not be instantiated. */
- private Converter() {
- }
-
- /** Logging tag. */
- private static final String TAG = "Converter";
-
-
- /** Indicates that the value is in the Byte range.*/
- private static final int B_RANGE = 0;
- /** Indicates that the value is in the Kilobyte range.*/
- private static final int KB_RANGE = 1;
- /** Indicates that the value is in the Megabyte range.*/
- private static final int MB_RANGE = 2;
- /** Indicates that the value is in the Gigabyte range.*/
- private static final int GB_RANGE = 3;
- /** Determines the length of the number for best readability.*/
- private static final int NUM_LENGTH = 1000;
-
- /** Takes a byte-value and converts it into a more readable
- * String.
- * @param input The value to convert
- * @return The converted String with a unit
- * */
- public static String byteToString(final long input) {
- int i = 0;
- int result = 0;
-
- for (i = 0; i < GB_RANGE + 1; i++) {
- result = (int) (input / Math.pow(1024, i));
- if (result < NUM_LENGTH) {
- break;
- }
- }
-
- switch (i) {
- case B_RANGE:
- return result + " B";
- case KB_RANGE:
- return result + " KB";
- case MB_RANGE:
- return result + " MB";
- case GB_RANGE:
- return result + " GB";
- default:
- Log.e(TAG, "Error happened in byteToString");
- return "ERROR";
- }
- }
+ /** Class shall not be instantiated. */
+ private Converter() {
+ }
+
+ /** Logging tag. */
+ private static final String TAG = "Converter";
+
+
+ /** Indicates that the value is in the Byte range.*/
+ private static final int B_RANGE = 0;
+ /** Indicates that the value is in the Kilobyte range.*/
+ private static final int KB_RANGE = 1;
+ /** Indicates that the value is in the Megabyte range.*/
+ private static final int MB_RANGE = 2;
+ /** Indicates that the value is in the Gigabyte range.*/
+ private static final int GB_RANGE = 3;
+ /** Determines the length of the number for best readability.*/
+ private static final int NUM_LENGTH = 1000;
+
+ /** Takes a byte-value and converts it into a more readable
+ * String.
+ * @param input The value to convert
+ * @return The converted String with a unit
+ * */
+ public static String byteToString(final long input) {
+ int i = 0;
+ int result = 0;
+
+ for (i = 0; i < GB_RANGE + 1; i++) {
+ result = (int) (input / Math.pow(1024, i));
+ if (result < NUM_LENGTH) {
+ break;
+ }
+ }
+
+ switch (i) {
+ case B_RANGE:
+ return result + " B";
+ case KB_RANGE:
+ return result + " KB";
+ case MB_RANGE:
+ return result + " MB";
+ case GB_RANGE:
+ return result + " GB";
+ default:
+ Log.e(TAG, "Error happened in byteToString");
+ return "ERROR";
+ }
+ }
}
diff --git a/src/de/podfetcher/util/NumberGenerator.java b/src/de/podfetcher/util/NumberGenerator.java
index 2ffefbbaa..172b87a39 100644
--- a/src/de/podfetcher/util/NumberGenerator.java
+++ b/src/de/podfetcher/util/NumberGenerator.java
@@ -5,18 +5,18 @@ import android.util.Log;
/**Utility class for creating large random numbers.*/
public final class NumberGenerator {
- /** Class shall not be instantiated.*/
- private NumberGenerator() {
- }
+ /** Class shall not be instantiated.*/
+ private NumberGenerator() {
+ }
- /**Logging tag.*/
+ /**Logging tag.*/
private static final String TAG = "NumberGenerator";
- /** Takes a string and generates a random value out of
- * the hash-value of that string.
- * @param strSeed The string to take for the return value
- * @return The generated random value
- * */
+ /** Takes a string and generates a random value out of
+ * the hash-value of that string.
+ * @param strSeed The string to take for the return value
+ * @return The generated random value
+ * */
public static long generateLong(final String strSeed) {
long seed = (long) strSeed.hashCode();
Log.d(TAG, "Taking " + seed + " as seed.");
diff --git a/src/de/podfetcher/util/URLChecker.java b/src/de/podfetcher/util/URLChecker.java
index f862b03a9..7a5d65180 100644
--- a/src/de/podfetcher/util/URLChecker.java
+++ b/src/de/podfetcher/util/URLChecker.java
@@ -1,39 +1,39 @@
-package de.podfetcher.util;
+package de.podfetcher.util;
import android.util.Log;
/** Provides methods for checking and editing a URL.*/
public final class URLChecker {
- /**Class shall not be instantiated.*/
- private URLChecker() {
- }
+ /**Class shall not be instantiated.*/
+ private URLChecker() {
+ }
- /**Logging tag.*/
- private static final String TAG = "URLChecker";
- /**Indicator for URLs made by Feedburner.*/
- private static final String FEEDBURNER_URL = "feeds.feedburner.com";
- /**Prefix that is appended to URLs by Feedburner.*/
- private static final String FEEDBURNER_PREFIX = "?format=xml";
+ /**Logging tag.*/
+ private static final String TAG = "URLChecker";
+ /**Indicator for URLs made by Feedburner.*/
+ private static final String FEEDBURNER_URL = "feeds.feedburner.com";
+ /**Prefix that is appended to URLs by Feedburner.*/
+ private static final String FEEDBURNER_PREFIX = "?format=xml";
- /** Checks if URL is valid and modifies it if necessary.
- * @param url The url which is going to be prepared
- * @return The prepared url
- * */
- public static String prepareURL(final String url) {
- StringBuilder builder = new StringBuilder();
+ /** Checks if URL is valid and modifies it if necessary.
+ * @param url The url which is going to be prepared
+ * @return The prepared url
+ * */
+ public static String prepareURL(final String url) {
+ StringBuilder builder = new StringBuilder();
- if (!url.startsWith("http")) {
- builder.append("http://");
- Log.d(TAG, "Missing http; appending");
- }
- builder.append(url);
+ if (!url.startsWith("http")) {
+ builder.append("http://");
+ Log.d(TAG, "Missing http; appending");
+ }
+ builder.append(url);
- if (url.contains(FEEDBURNER_URL)) {
- Log.d(TAG,
- "URL seems to be Feedburner URL; appending prefix");
- builder.append(FEEDBURNER_PREFIX);
- }
- return builder.toString();
- }
+ if (url.contains(FEEDBURNER_URL)) {
+ Log.d(TAG,
+ "URL seems to be Feedburner URL; appending prefix");
+ builder.append(FEEDBURNER_PREFIX);
+ }
+ return builder.toString();
+ }
}