Skip to content

Commit

Permalink
fix #27: add the step graphic in Parent Category Spinner under Add Ne…
Browse files Browse the repository at this point in the history
…w Category
  • Loading branch information
maxme committed Sep 19, 2013
1 parent 422e535 commit ce4ff3e
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 23 deletions.
24 changes: 24 additions & 0 deletions res/layout/categories_row_parent.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/category_row_height"
android:orientation="horizontal"
android:id="@+id/categoryRow" android:clickable="false">
<ImageView android:layout_width="@dimen/category_row_height"
android:layout_height="@dimen/category_row_height"
android:src="@drawable/ic_level_indicator"
android:id="@+id/categoryRowLevelIndicator" android:scaleType="fitEnd"/>
<TextView
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:textColor="#464646"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:id="@+id/categoryRowText"/>
</LinearLayout>
30 changes: 7 additions & 23 deletions src/org/wordpress/android/ui/posts/AddCategoryActivity.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
package org.wordpress.android.ui.posts;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

import org.wordpress.android.R;
import org.wordpress.android.WordPress;
import org.wordpress.android.models.CategoryNode;

import java.util.ArrayList;

public class AddCategoryActivity extends Activity {
private int id;
@Override
Expand Down Expand Up @@ -51,7 +47,7 @@ public void onClick(View v) {
Spinner sCategories = (Spinner) findViewById(R.id.parent_category);
String parent_category = "";
if (sCategories.getSelectedItem() != null)
parent_category = sCategories.getSelectedItem().toString().trim();
parent_category = ((CategoryNode)sCategories.getSelectedItem()).getName().trim();
int parent_id = 0;
if (sCategories.getSelectedItemPosition() != 0){
parent_id = WordPress.wpDB.getCategoryId(id, parent_category);
Expand Down Expand Up @@ -105,25 +101,14 @@ public void onClick(View v) {
}

private void loadCategories() {
ArrayList<CharSequence> loadTextArray = new ArrayList<CharSequence>();
CategoryNode rootCategory = CategoryNode.createCategoryTreeFromDB(id);
ArrayList<CategoryNode> categoryLevels = CategoryNode.getSortedListOfCategoriesFromRoot(rootCategory);
categoryLevels.add(0, new CategoryNode(0, 0, getString(R.string.none)));
if (categoryLevels.size() > 0) {
loadTextArray.add(getResources().getText(R.string.none));
for (int i = 0; i < categoryLevels.size(); i++) {
CategoryNode currentCategory = categoryLevels.get(i);
String name = "";
for (int j = 1; j < currentCategory.getLevel(); j++) {
name += " ";
}
name += Html.fromHtml(currentCategory.getName());
loadTextArray.add(name);
}
ArrayAdapter<CharSequence> categories = new ArrayAdapter<CharSequence>(this,
android.R.layout.simple_dropdown_item_1line, loadTextArray);
categories.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
ParentCategorySpinnerAdapter categoryAdapter = new ParentCategorySpinnerAdapter(this,
R.layout.categories_row_parent, categoryLevels);
Spinner sCategories = (Spinner) findViewById(R.id.parent_category);
sCategories.setAdapter(categories);
sCategories.setAdapter(categoryAdapter);
}
}

Expand All @@ -132,5 +117,4 @@ public void onConfigurationChanged(Configuration newConfig) {
//ignore orientation change
super.onConfigurationChanged(newConfig);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.wordpress.android.ui.posts;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.SpinnerAdapter;
import android.widget.TextView;
import org.wordpress.android.R;
import org.wordpress.android.models.CategoryNode;

import java.util.List;


public class ParentCategorySpinnerAdapter extends BaseAdapter implements SpinnerAdapter {
int mResourceId;
List<CategoryNode> mObjects;
Context mContext;

public int getCount() {
return mObjects.size();
}

public CategoryNode getItem(int position) {
return mObjects.get(position);
}

public long getItemId(int position) {
return position;
}

public ParentCategorySpinnerAdapter(Context context, int resource, List<CategoryNode> objects) {
super();
mContext = context;
mObjects = objects;
mResourceId = resource;
}

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(mResourceId, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.categoryRowText);
ImageView levelIndicatorView = (ImageView) rowView.findViewById(R.id.categoryRowLevelIndicator);
textView.setText(Html.fromHtml(getItem(position).getName()));
int level = getItem(position).getLevel();
if (level == 1) { // hide ImageView
levelIndicatorView.setVisibility(View.GONE);
} else {
ViewGroup.LayoutParams params = levelIndicatorView.getLayoutParams();
params.width = (params.width / 2) * level;
levelIndicatorView.setLayoutParams(params);
}
return rowView;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(mResourceId, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.categoryRowText);
ImageView levelIndicatorView = (ImageView) rowView.findViewById(R.id.categoryRowLevelIndicator);
textView.setText(Html.fromHtml(getItem(position).getName()));
levelIndicatorView.setVisibility(View.GONE);
return rowView;
}
}

0 comments on commit ce4ff3e

Please sign in to comment.