[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SelectCategory and AddCategory activities refreshed #21

Merged
merged 13 commits into from
Jul 31, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
New database version (v18) atlering categories table to add parent_id
  • Loading branch information
maxme committed Jul 25, 2013
commit 0bc465cbcaf8792ec25bd7dd23c98dfe78a01fb3
43 changes: 39 additions & 4 deletions src/org/wordpress/android/WordPressDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

public class WordPressDB {

private static final int DATABASE_VERSION = 17;
private static final int DATABASE_VERSION = 18;

private static final String CREATE_TABLE_SETTINGS = "create table if not exists accounts (id integer primary key autoincrement, "
+ "url text, blogName text, username text, password text, imagePlacement text, centerThumbnail boolean, fullSizeImage boolean, maxImageWidth text, maxImageWidthId integer, lastCommentId integer, runService boolean);";
Expand Down Expand Up @@ -125,6 +125,9 @@ public class WordPressDB {

private static final String ADD_BLOG_OPTIONS = "alter table accounts add blog_options text default '';";

// add category parent id to keep track of category hierarchy
private static final String ADD_PARENTID_IN_CATEGORIES = "alter table cats add parent_id integer default 0;";

private SQLiteDatabase db;

protected static final String PASSWORD_SECRET = Config.DB_SECRET;
Expand Down Expand Up @@ -181,6 +184,7 @@ public WordPressDB(Context ctx) {
db.execSQL(ADD_FEATURED_IN_POST);
db.execSQL(ADD_HOME_URL);
db.execSQL(ADD_BLOG_OPTIONS);
db.execSQL(ADD_PARENTID_IN_CATEGORIES);
migratePasswords();
db.setVersion(DATABASE_VERSION); // set to latest revision
} else if (db.getVersion() == 1) { // v1.0 or v1.0.1
Expand Down Expand Up @@ -213,6 +217,7 @@ public WordPressDB(Context ctx) {
db.execSQL(ADD_FEATURED_IN_POST);
db.execSQL(ADD_HOME_URL);
db.execSQL(ADD_BLOG_OPTIONS);
db.execSQL(ADD_PARENTID_IN_CATEGORIES);
migratePasswords();
migratePreferences(ctx);
migrateWPComAccount();
Expand Down Expand Up @@ -245,6 +250,7 @@ public WordPressDB(Context ctx) {
db.execSQL(ADD_FEATURED_IN_POST);
db.execSQL(ADD_HOME_URL);
db.execSQL(ADD_BLOG_OPTIONS);
db.execSQL(ADD_PARENTID_IN_CATEGORIES);
migratePasswords();
migratePreferences(ctx);
migrateWPComAccount();
Expand Down Expand Up @@ -274,6 +280,7 @@ public WordPressDB(Context ctx) {
db.execSQL(ADD_FEATURED_IN_POST);
db.execSQL(ADD_HOME_URL);
db.execSQL(ADD_BLOG_OPTIONS);
db.execSQL(ADD_PARENTID_IN_CATEGORIES);
migratePasswords();
migratePreferences(ctx);
migrateWPComAccount();
Expand Down Expand Up @@ -303,6 +310,7 @@ public WordPressDB(Context ctx) {
db.execSQL(ADD_FEATURED_IN_POST);
db.execSQL(ADD_HOME_URL);
db.execSQL(ADD_BLOG_OPTIONS);
db.execSQL(ADD_PARENTID_IN_CATEGORIES);
migratePasswords();
migratePreferences(ctx);
migrateWPComAccount();
Expand Down Expand Up @@ -357,6 +365,7 @@ public WordPressDB(Context ctx) {
db.execSQL(ADD_FEATURED_IN_POST);
db.execSQL(ADD_HOME_URL);
db.execSQL(ADD_BLOG_OPTIONS);
db.execSQL(ADD_PARENTID_IN_CATEGORIES);
migratePasswords();
migratePreferences(ctx);
migrateWPComAccount();
Expand All @@ -375,6 +384,7 @@ public WordPressDB(Context ctx) {
db.execSQL(ADD_FEATURED_IN_POST);
db.execSQL(ADD_HOME_URL);
db.execSQL(ADD_BLOG_OPTIONS);
db.execSQL(ADD_PARENTID_IN_CATEGORIES);
migratePasswords();
migratePreferences(ctx);
migrateWPComAccount();
Expand All @@ -392,6 +402,7 @@ public WordPressDB(Context ctx) {
db.execSQL(ADD_FEATURED_IN_POST);
db.execSQL(ADD_HOME_URL);
db.execSQL(ADD_BLOG_OPTIONS);
db.execSQL(ADD_PARENTID_IN_CATEGORIES);
migratePasswords();
migratePreferences(ctx);
migrateWPComAccount();
Expand All @@ -409,6 +420,7 @@ public WordPressDB(Context ctx) {
db.execSQL(ADD_FEATURED_IN_POST);
db.execSQL(ADD_HOME_URL);
db.execSQL(ADD_BLOG_OPTIONS);
db.execSQL(ADD_PARENTID_IN_CATEGORIES);
migratePasswords();
migratePreferences(ctx);
migrateWPComAccount();
Expand Down Expand Up @@ -481,6 +493,7 @@ public WordPressDB(Context ctx) {
db.execSQL(ADD_FEATURED_IN_POST);
db.execSQL(ADD_HOME_URL);
db.execSQL(ADD_BLOG_OPTIONS);
db.execSQL(ADD_PARENTID_IN_CATEGORIES);
migratePreferences(ctx);
migrateWPComAccount();
db.setVersion(DATABASE_VERSION);
Expand All @@ -491,34 +504,43 @@ public WordPressDB(Context ctx) {
db.execSQL(ADD_FEATURED_IN_POST);
db.execSQL(ADD_HOME_URL);
db.execSQL(ADD_BLOG_OPTIONS);
db.execSQL(ADD_PARENTID_IN_CATEGORIES);
migratePreferences(ctx);
migrateWPComAccount();
db.setVersion(DATABASE_VERSION);
} else if (db.getVersion() == 12) {
db.execSQL(ADD_FEATURED_IN_POST);
db.execSQL(ADD_HOME_URL);
db.execSQL(ADD_BLOG_OPTIONS);
db.execSQL(ADD_PARENTID_IN_CATEGORIES);
migratePreferences(ctx);
migrateWPComAccount();
db.setVersion(DATABASE_VERSION);
} else if (db.getVersion() == 13) {
db.execSQL(ADD_HOME_URL);
db.execSQL(ADD_BLOG_OPTIONS);
db.execSQL(ADD_PARENTID_IN_CATEGORIES);
migratePreferences(ctx);
migrateWPComAccount();
db.setVersion(DATABASE_VERSION);
} else if (db.getVersion() == 14) {
db.execSQL(ADD_BLOG_OPTIONS);
db.execSQL(ADD_PARENTID_IN_CATEGORIES);
migratePreferences(ctx);
migrateWPComAccount();
db.setVersion(DATABASE_VERSION);
} else if (db.getVersion() == 15) {
db.execSQL(ADD_PARENTID_IN_CATEGORIES);
migratePreferences(ctx);
migrateWPComAccount();
db.setVersion(DATABASE_VERSION);
} else if (db.getVersion() == 16) {
db.execSQL(ADD_PARENTID_IN_CATEGORIES);
migrateWPComAccount();
db.setVersion(DATABASE_VERSION);
} else if (db.getVersion() == 17) {
db.execSQL(ADD_PARENTID_IN_CATEGORIES);
db.setVersion(DATABASE_VERSION);
}
} catch (SQLException e) {
e.printStackTrace();
Expand Down Expand Up @@ -1228,10 +1250,10 @@ public long savePost(Post post, int blogID) {
values.put("description", post.getDescription());
values.put("mt_text_more", post.getMt_text_more());

if (post.getCategories() != null) {
if (post.getJSONCategories() != null) {
JSONArray jsonArray = null;
try {
jsonArray = new JSONArray(post.getCategories().toString());
jsonArray = new JSONArray(post.getJSONCategories().toString());
values.put("categories", jsonArray.toString());
} catch (JSONException e) {
e.printStackTrace();
Expand Down Expand Up @@ -1553,12 +1575,13 @@ public long getStatsDate() {
}

// categories
public boolean insertCategory(int id, int wp_id, String category_name) {
public boolean insertCategory(int id, int wp_id, int parent_id, String category_name) {

ContentValues values = new ContentValues();
values.put("blog_id", id);
values.put("wp_id", wp_id);
values.put("category_name", category_name.toString());
values.put("parent_id", parent_id);
boolean returnValue = false;
synchronized (this) {
returnValue = db.insert(CATEGORIES_TABLE, null, values) > 0;
Expand Down Expand Up @@ -1600,6 +1623,18 @@ public int getCategoryId(int id, String category) {
return categoryID;
}

public int getCategoryParentId(int id, String category) {
Cursor c = db.query(CATEGORIES_TABLE, new String[] { "parent_id" },
"category_name=\"" + category + "\" AND blog_id=" + id, null,
null, null, null);
if (c.getCount() == 0)
return -1;
c.moveToFirst();
int categoryParentID = c.getInt(0);

return categoryParentID;
}

public void clearCategories(int id) {

// clear out the table since we are refreshing the whole enchilada
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public String addCategory(String category_name, String category_slug, String cat
// Convert "result" (= category_id) from type Object to int
int category_id = Integer.parseInt(result.toString());
// Insert the new category into database
WordPress.wpDB.insertCategory(id, category_id, category_name);
WordPress.wpDB.insertCategory(blog.getId(), category_id, parent_id, category_name);

returnString = "addCategory_success";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.content.Intent;
import android.content.res.Configuration;
import android.location.LocationManager;
import android.opengl.Visibility;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
Expand Down Expand Up @@ -81,7 +80,7 @@ public void onCreate(Bundle savedInstanceState) {

if (blog.isDotcomFlag()) {
// Hide credentials section
RelativeLayout credentialsRL = (RelativeLayout)findViewById(R.id.section1);
RelativeLayout credentialsRL = (RelativeLayout)findViewById(R.id.sectionContent);
credentialsRL.setVisibility(View.GONE);
}

Expand Down