Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions soup/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ android {
applicationId "com.thunsaker.soup"
minSdkVersion 9
targetSdkVersion 19
versionCode 25
versionName "2.6.2"
versionCode 26
versionName "2.6.3"
resConfigs "en", "es", "fr", "pt", "ru"
}

Expand Down Expand Up @@ -98,4 +98,5 @@ dependencies {
compile 'com.squareup:android-times-square:1.2.1@aar'

compile 'com.tundem.aboutlibraries:library:3.0.0@aar'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.thunsaker.soup.data;

import android.test.InstrumentationTestCase;

public class CategoriesDataSourceTest extends InstrumentationTestCase {

}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.thunsaker.soup.data;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import java.sql.SQLException;

public class CategoriesDataSource {
private SQLiteDatabase db;
private CategoriesDb dbHelper;
private String[] catColumns = { CategoriesDb.COLUMN_ID, CategoriesDb.COLUMN_FOURSQUARE_ID, CategoriesDb.COLUMN_NAME, CategoriesDb.COLUMN_PARENT };

public CategoriesDataSource (Context context) {
dbHelper = new CategoriesDb(context);
}

public void open() throws SQLException {
db = dbHelper.getWritableDatabase();
}

public void close() {
dbHelper.close();
}

public CategoryInfo createCategoryInfo(String categoryId, String name) {
return this.createCategoryInfo(categoryId, name, "");
}

public CategoryInfo createCategoryInfo(String categoryId, String name, String parentId) {
ContentValues vals = new ContentValues();
vals.put(CategoriesDb.COLUMN_FOURSQUARE_ID, categoryId);
vals.put(CategoriesDb.COLUMN_NAME, name);
vals.put(CategoriesDb.COLUMN_PARENT, parentId);
long insertId = db.insert(CategoriesDb.TABLE_CATEGORIES, null, vals);
Cursor cursor = db.query(CategoriesDb.TABLE_CATEGORIES, catColumns, CategoriesDb.COLUMN_ID + " = " + insertId, null, null, null, null);
cursor.moveToFirst();
CategoryInfo newCatInfo = cursorToCategory(cursor);
cursor.close();
return newCatInfo;
}

public void deleteCategoryInfo(String foursquareCategoryId) throws SQLException {
db.delete(CategoriesDb.TABLE_CATEGORIES, CategoriesDb.COLUMN_FOURSQUARE_ID + " = " + foursquareCategoryId, null);
}

private CategoryInfo cursorToCategory(Cursor cursor) {
CategoryInfo catInfo = new CategoryInfo();
catInfo.id = cursor.getLong(0);
catInfo.categoryId = cursor.getString(1);
catInfo.name = cursor.getString(2);
// TODO: This may be empty, if no parent is given
catInfo.parentId = cursor.getString(3);
return catInfo;
}
}
25 changes: 25 additions & 0 deletions soup/src/main/java/com/thunsaker/soup/data/CategoriesDb.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.thunsaker.soup.data;

import android.content.Context;

import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;

public class CategoriesDb extends SQLiteAssetHelper {
private static final String DATABASE_NAME = "categories.db";
private static final int DATABASE_VERSION = 1;

public static final String TABLE_CATEGORIES = "categories";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_FOURSQUARE_ID = "foursquareId";
public static final String COLUMN_NAME = "name";
public static final String COLUMN_PARENT = "parentId";
// Consider adding the category color here.

private static final String DATABASE_CREATE =
String.format("create table %s (%s integer primary key autoincrement, %s text not null, %s text not null, %s);",
TABLE_CATEGORIES, COLUMN_ID, COLUMN_FOURSQUARE_ID, COLUMN_NAME, COLUMN_PARENT);

public CategoriesDb(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
}
8 changes: 8 additions & 0 deletions soup/src/main/java/com/thunsaker/soup/data/CategoryInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.thunsaker.soup.data;

public class CategoryInfo {
public long id;
public String categoryId;
public String name;
public String parentId;
}
4 changes: 2 additions & 2 deletions soup/src/main/res/values/donottranslate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<string name="app_name" translatable="false">Soup</string>
<string name="app_name_pro" translatable="false">Soup Pro</string>
<string name="app_name_dev" translatable="false">Soup Dev</string>
<string name="app_version" translatable="false">2.6.2</string>
<string name="app_version_long" translatable="false">Soup v.2.6.2</string>
<string name="app_version" translatable="false">2.6.3</string>
<string name="app_version_long" translatable="false">Soup v.2.6.3</string>

<string name="prefs_foursquare_connected" translatable="false">soup_foursquare_connected</string>
<string name="prefs_foursquare_token" translatable="false">soup_foursquare_token</string>
Expand Down