Yang Zhang avatar Yang Zhang committed ad43811

finish category fragment

Comments (0)

Files changed (6)

android/AndroidManifest.xml

         <!-- ChapterListActivity -->
         <activity android:name=".ChapterListActivity" 
         	android:label="@string/title_activity_main" />
-        
+         <!--BooklistActivity.java -->
+         <activity android:name=".BooklistActivity" 
+        	android:label="@string/title_activity_main" />
         
     </application>
 	<uses-permission android:name="android.permission.INTERNET" /> 

android/res/layout/download_fragment.xml

             android:layout_width="match_parent"
             android:layout_height="wrap_content" >
         </LinearLayout>
-
+
         <ExpandableListView
             android:id="@+id/downloadBookList"
+            style="@style/ListViewAppTheme"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:layout_weight="1"

android/src/me/yangblog/manmanpa/BooklistActivity.java

+package me.yangblog.manmanpa;
+
+import java.util.LinkedList;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import me.yangblog.manmanpa.adapter.BookArrayAdapter;
+import me.yangblog.manmanpa.fragment.RankFragment;
+import me.yangblog.manmanpa.model.Book;
+import me.yangblog.manmanpa.util.GlobalVariable;
+import me.yangblog.manmanpa.util.Helper;
+import me.yangblog.manmanpa.util.JSONNeedParser;
+import me.yangblog.manmanpa.util.JSONParser;
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.AbsListView;
+import android.widget.AdapterView;
+import android.widget.ListView;
+import android.widget.AbsListView.OnScrollListener;
+import android.widget.AdapterView.OnItemClickListener;
+
+public class BooklistActivity extends Activity implements JSONNeedParser{
+	private LinkedList<Book> bookList = new LinkedList<Book>();
+	private BookArrayAdapter adapter;
+	private JSONParser jsonPaser;
+	private int currentBooklist = 1;
+	String action = null;
+	String word = null;
+	
+	
+	
+	@Override
+	public void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		jsonPaser = new JSONParser(this, this);
+		Intent intent = getIntent();
+		action =intent.getStringExtra("action");
+		word =intent.getStringExtra("word");
+		if (!jsonPaser.isRunning()) {
+			if(action.equals("search")){
+				jsonPaser.execute(GlobalVariable.SEARCH_URL + word);
+			}else{
+				jsonPaser.execute(GlobalVariable.LABEL_URL + word);
+			}
+		}
+		
+		ListView listView = new ListView(this);
+		Helper.setListViewDivid(listView);
+		adapter = new BookArrayAdapter(this, bookList);
+
+		// Assign adapter to ListView
+
+		listView.setAdapter(adapter);
+
+		adapter.notifyDataSetChanged();
+		listView.setOnItemClickListener(new OnItemClickListener() {
+			@Override
+			public void onItemClick(AdapterView<?> parent, View view,
+					int position, long id) {
+				showChapterView(bookList.get(position));
+			}
+		});
+		setContentView(listView);
+	}
+
+	
+	private void showChapterView(Book book) {
+		Intent intent = new Intent(this,
+				ChapterListActivity.class);
+		book.saveToIntent(intent);
+		startActivity(intent);
+	}
+	
+
+	
+	
+	@Override
+	public void parseJSON(JSONObject jObj) throws JSONException {
+		JSONArray booksJson = jObj.getJSONArray("content");
+
+		// this.bookList.clear();
+		// looping through All Contacts
+		for (int i = 0; i < booksJson.length(); i++) {
+			JSONObject c = booksJson.getJSONObject(i);
+			Book book = Book.createBookByJSONObject(c);
+			book.initBookCover();
+			this.adapter.addBook(book);
+		}
+
+	}
+
+	@Override
+	public void notifyDataChange() {
+		this.adapter.update();
+		this.adapter.notifyDataSetChanged();
+		
+	}
+
+}

android/src/me/yangblog/manmanpa/fragment/CategoryFragment.java

 import org.json.JSONException;
 import org.json.JSONObject;
 
+import me.yangblog.manmanpa.BooklistActivity;
 import me.yangblog.manmanpa.MainActivity;
 import me.yangblog.manmanpa.R;
 import me.yangblog.manmanpa.adapter.BookArrayAdapter;
+import me.yangblog.manmanpa.adapter.ChapterAdapter;
 import me.yangblog.manmanpa.model.Book;
+import me.yangblog.manmanpa.reader.ComicReaderActivity;
 import me.yangblog.manmanpa.util.GlobalVariable;
 import me.yangblog.manmanpa.util.JSONNeedParser;
 import me.yangblog.manmanpa.util.JSONParser;
+import android.content.Intent;
 import android.graphics.Color;
 import android.graphics.drawable.ColorDrawable;
 import android.os.Bundle;
 import android.widget.Button;
 import android.widget.GridLayout;
 import android.widget.SearchView;
+import android.widget.SearchView.OnQueryTextListener;
 
-public class CategoryFragment extends Fragment implements JSONNeedParser{
+public class CategoryFragment extends Fragment{
 	private MainActivity activity;
-
+	private String action = null;
+	private String word = null;
 	
 	public CategoryFragment(MainActivity activity) {
 		this.activity = activity;
 		View view = inflater.inflate(R.layout.category_search, container, false);
 		SearchView sv =(SearchView) view.findViewById(R.id.search);
 		//sv.setBackground(new ColorDrawable(Color.RED));
-		
+		sv. setOnQueryTextListener(new OnQueryTextListener() {
+			
+			@Override
+			public boolean onQueryTextSubmit(String query) {
+				word = query;
+				action = "search";
+				startBookListActivity();
+				return true;
+			}
+			
+			@Override
+			public boolean onQueryTextChange(String newText) {
+
+				return true;
+			}
+		});
 		GridLayout gl = (GridLayout) view.findViewById(R.id.hot_labels);
 		gl.addView(makeLabelButton("�������"));
 		gl.addView(makeLabelButton("���"));
 	}
 
 	private Button makeLabelButton(String string) {
-		Button button = new Button(activity);
+		final Button button = new Button(activity);
 		button.setMinimumWidth(100);
 		button.setText(string);
 		button.getBackground().setColorFilter(GlobalVariable.BUTTON_COLOR);
 		button.setOnClickListener(new OnClickListener() {
-			
 			@Override
 			public void onClick(View v) {
-				
+				word = (String) button.getText();
+				action = "label";
+				startBookListActivity();
 			}
 		});
 		return button;
 	}
-
-	@Override
-	public void parseJSON(JSONObject jObj) throws JSONException {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void notifyDataChange() {
-		// TODO Auto-generated method stub
-		
+	
+	private void startBookListActivity(){
+		Intent intent = new Intent(activity, BooklistActivity.class);
+		intent.putExtra("action", action);
+		intent.putExtra("word", word);
+		activity.startActivity(intent);					
 	}
 	
 	

android/src/me/yangblog/manmanpa/fragment/DownloadFragment.java

 import android.view.ViewGroup;
 import android.widget.Button;
 import android.widget.ExpandableListView;
+import android.widget.ExpandableListView.OnGroupCollapseListener;
 import android.widget.ExpandableListView.OnGroupExpandListener;
 import android.widget.Toast;
 
 				notifyDataChange();
 			}
 		});
+		expLV.setOnGroupCollapseListener(new OnGroupCollapseListener() {
+			
+			@Override
+			public void onGroupCollapse(int groupPosition) {
+				notifyDataChange();
+			}
+		});
 		return view;
 	}
 	

android/src/me/yangblog/manmanpa/fragment/RankFragment.java

 	private BookArrayAdapter adapter;
 	private JSONParser jsonPaser;
 	private int currentBooklist = 1;
-	JSONObject json = null;
 
 	public RankFragment() {
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.