Yang Zhang avatar Yang Zhang committed 31c0a38

label & search works,
remove download update stuff, rethink solution

Comments (0)

Files changed (8)

android/res/values/styles.xml

-<resources>
-
-    <style name="AppTheme" parent="Theme.megamh" />
-
-</resources>

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

 		Intent intent = getIntent();
 		action =intent.getStringExtra("action");
 		word =intent.getStringExtra("word");
+		ListView listView = new ListView(this);
+		Helper.setListViewDivid(listView);
+		adapter = new BookArrayAdapter(this, bookList);
+		// Assign adapter to ListView
+		listView.setAdapter(adapter);
+		
 		if (!jsonPaser.isRunning()) {
 			if(action.equals("search")){
 				jsonPaser.execute(GlobalVariable.SEARCH_URL + word);
 			}else{
 				jsonPaser.execute(GlobalVariable.LABEL_URL + word);
+				listView.setOnScrollListener(new OnScrollListener() {
+
+					@Override
+					public void onScrollStateChanged(AbsListView view, int scrollState) {
+					}
+
+					@Override
+					public void onScroll(AbsListView view, int firstVisibleItem,
+							int visibleItemCount, int totalItemCount) {
+						if (!jsonPaser.isRunning()
+								&& totalItemCount != 0
+								&& (totalItemCount - visibleItemCount) <= (firstVisibleItem + 5)) {
+							currentBooklist++;
+							jsonPaser = new JSONParser(BooklistActivity.this,
+									BooklistActivity.this);
+							jsonPaser.execute(GlobalVariable.LABEL_URL+ word+"?page="
+									+ currentBooklist);
+						}
+					}
+				});
+				
 			}
 		}
-		
-		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() {
 				showChapterView(bookList.get(position));
 			}
 		});
+		
+		
 		setContentView(listView);
 	}
 

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

 import android.app.Activity;
 import android.app.Dialog;
 import android.content.Intent;
+import android.graphics.Color;
 import android.os.Bundle;
 import android.support.v4.app.DialogFragment;
+import android.view.Gravity;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View.OnClickListener;
 			}
 		});
 		Button downloadButton = (Button) findViewById(R.id.download);
-		downloadButton.getBackground().setColorFilter(GlobalVariable.BUTTON_COLOR);
+		downloadButton.getBackground().setColorFilter(
+				GlobalVariable.BUTTON_COLOR);
 		downloadButton.setOnClickListener(new OnClickListener() {
-			
+
 			@Override
 			public void onClick(View v) {
 				showDownloadBox();
 			}
 		});
-		
 
 		TextView lastChView = (TextView) findViewById(R.id.lastCh);
 		lastChView.setText(book.getLastChapter());
 		jsonPaser = new JSONParser(this, this);
 		jsonPaser.execute(GlobalVariable.CHAPTER_URL + book.getId());
 	}
-	
-	private void showDownloadBox(){
+
+	private void showDownloadBox() {
 		final Dialog dialog = new Dialog(ChapterListActivity.this);
-		View viewToLoad = LayoutInflater.from(ChapterListActivity.this).inflate(R.layout.download_chooser, null);
-		GridView downloadGd =  (GridView) viewToLoad.findViewById(R.id.downloadGradview);
-		Button downloadButton = (Button) viewToLoad.findViewById(R.id.downloadSureButton);
-		downloadButton.getBackground().setColorFilter(GlobalVariable.BUTTON_COLOR);
-		Button selectAllButton = (Button) viewToLoad.findViewById(R.id.select_all);
-		selectAllButton.getBackground().setColorFilter(GlobalVariable.BUTTON_COLOR);
-		final DownloadChapterAdapter dcha = new DownloadChapterAdapter(this, book);
+		View viewToLoad = LayoutInflater.from(ChapterListActivity.this)
+				.inflate(R.layout.download_chooser, null);
+		GridView downloadGd = (GridView) viewToLoad
+				.findViewById(R.id.downloadGradview);
+		Button downloadButton = (Button) viewToLoad
+				.findViewById(R.id.downloadSureButton);
+		downloadButton.getBackground().setColorFilter(
+				GlobalVariable.BUTTON_COLOR);
+		Button selectAllButton = (Button) viewToLoad
+				.findViewById(R.id.select_all);
+		selectAllButton.getBackground().setColorFilter(
+				GlobalVariable.BUTTON_COLOR);
+		final DownloadChapterAdapter dcha = new DownloadChapterAdapter(this,
+				book);
 		downloadGd.setAdapter(dcha);
-		setSelectAllButton(selectAllButton,dcha );
-		
-		
-		
+		setSelectAllButton(selectAllButton, dcha);
+
 		downloadButton.setOnClickListener(new OnClickListener() {
-			
+
 			@Override
 			public void onClick(View v) {
 				LinkedList<Chapter> tempList = dcha.getSelectChapter();
-				if(!tempList.isEmpty()){
-					GlobalVariable.downloader.setDs(new DownloadSource(ChapterListActivity.this));
-					GlobalVariable.downloader.addChapterList(tempList,book.getName() );
+				if (!tempList.isEmpty()) {
+					GlobalVariable.downloader.setDs(new DownloadSource(
+							ChapterListActivity.this));
+					GlobalVariable.downloader.addChapterList(tempList,
+							book.getName());
 					if (!GlobalVariable.downloader.isRunning()) {
 						new Thread(GlobalVariable.downloader).start();
 					}
-					Toast.makeText(ChapterListActivity.this, "���ؿ�ʼ...", Toast.LENGTH_SHORT).show();
+					Toast.makeText(ChapterListActivity.this, "aaaaaa", Toast.LENGTH_LONG).show();
+					
 				}
 				dialog.dismiss();
-				
+
 			}
 		});
-		
+
 		dialog.setTitle("ѡ��Ҫ���ص��½�");
 		dialog.setContentView(viewToLoad);
 		dialog.show();
 	}
-	
-	private void setSelectAllButton(final Button selectAllButton, final DownloadChapterAdapter dcha){
+
+	private void setSelectAllButton(final Button selectAllButton,
+			final DownloadChapterAdapter dcha) {
 		selectAllButton.setOnClickListener(new OnClickListener() {
 			@Override
 			public void onClick(View v) {
 				dcha.selectALl();
-				setUnSelect(selectAllButton,dcha);
-				
+				setUnSelect(selectAllButton, dcha);
+
 			}
 		});
 	}
-	
-	private void setUnSelect(final Button selectAllButton, final DownloadChapterAdapter dcha){
+
+	private void setUnSelect(final Button selectAllButton,
+			final DownloadChapterAdapter dcha) {
 		selectAllButton.setOnClickListener(new OnClickListener() {
 			@Override
 			public void onClick(View v) {
 				dcha.unSelectAll();
-				setSelectAllButton(selectAllButton,dcha);
+				setSelectAllButton(selectAllButton, dcha);
 			}
 		});
 	}
-	
-	
 
 	@Override
 	public void parseJSON(JSONObject jObj) throws JSONException {

android/src/me/yangblog/manmanpa/adapter/DownloadAdapter.java

 import android.widget.TextView;
 import android.graphics.LightingColorFilter;
 import android.graphics.PorterDuff;
+
 public class DownloadAdapter extends BaseExpandableListAdapter {
 
 	private Context context;
 	private LinkedList<Book> bookList;
+
 	public DownloadAdapter(Context context, LinkedList<Book> bookList) {
 		this.context = context;
 		this.bookList = bookList;
 		LayoutInflater inflater = (LayoutInflater) context
 				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 		convertView = inflater.inflate(R.layout.download_shower, parent, false);
-		Chapter ch = bookList.get(groupPosition).getChapterList()
+		final Chapter ch = bookList.get(groupPosition).getChapterList()
 				.get(childPosition);
 		TextView tvName = (TextView) convertView.findViewById(R.id.chapterName);
 		tvName.setText(ch.getName());
 				.findViewById(R.id.downloadProgressBar);
 		pb.setMax(ch.getLength());
 		pb.setProgress(ch.getDownloadedNumber());
+		/*
 		if (ch.equals(GlobalVariable.downloader.getCurrentDownloadingChapter())) {
-			final Chapter downloaCh = GlobalVariable.downloader.getCurrentDownloadingChapter();
 			final Handler handler = new Handler();
 			new Thread(new Runnable() {
 				public void run() {
-					while (!downloaCh.isDownloaded()) {
+					while (ch.isDownloaded()) {
 						try {
-							Thread.sleep(400);
+							Thread.sleep(800);
 						} catch (InterruptedException e) {
 							e.printStackTrace();
 						}
 						handler.post(new Runnable() {
 							@Override
 							public void run() {
-								tvNumberShower.setText(downloaCh.getDownloadedNumber()
-										+ "/" + downloaCh.getLength());
-								pb.setProgress(downloaCh.getDownloadedNumber());
+								tvNumberShower.setText(ch.getDownloadedNumber()
+										+ "/" + ch.getLength());
+								pb.setProgress(ch.getDownloadedNumber());
+								// DownloadAdapter.this.notifyDataSetChanged();
 							}
 						});
-						
 
 					}
-					handler.post(new Runnable() {
-						@Override
-						public void run() {
-							TextView stateText = (TextView) parent
-									.findViewById(R.id.downloadState);
-							Button stopOrResumeButton = (Button) parent
-									.findViewById(R.id.stopOrResume);
-							stateText.setText("�����");
-							stopOrResumeButton.setText("���");
-							stopOrResumeButton.setEnabled(false);
-							DownloadAdapter.this.notifyDataSetChanged();
-						}
-					});
+
+					if (GlobalVariable.downloader
+							.isBookWaitForDownload(bookList.get(groupPosition))) {
+
+						handler.post(new Runnable() {
+							@Override
+							public void run() {
+								TextView stateText = (TextView) parent
+										.findViewById(R.id.downloadState);
+								Button stopOrResumeButton = (Button) parent
+										.findViewById(R.id.stopOrResume);
+								stateText.setText("�����");
+								stopOrResumeButton.setText("���");
+								stopOrResumeButton.setEnabled(false);
+								DownloadAdapter.this.notifyDataSetChanged();
+							}
+						});
+					} else {
+
+						handler.post(new Runnable() {
+							@Override
+							public void run() {
+								DownloadAdapter.this.notifyDataSetChanged();
+							}
+						});
+
+					}
 
 				}
 			}).start();
 
 		}
-		
+*/
 		Button readButton = (Button) convertView.findViewById(R.id.read);
 		readButton.getBackground().setColorFilter(GlobalVariable.BUTTON_COLOR);
 		readButton.setOnClickListener(new OnClickListener() {
-			
+
 			@Override
 			public void onClick(View v) {
-//				context.getHs().saveHistoryorUpdate(book, chapterList.get(position));
+				// context.getHs().saveHistoryorUpdate(book,
+				// chapterList.get(position));
 				DownloadAdapter.this.notifyDataSetChanged();
 				Intent intent = new Intent(context, ComicReaderActivity.class);
 				Book book = bookList.get(groupPosition);
 				intent.putExtra("bookname", book.getName());
 				new HistorySource(context).saveHistoryorUpdate(book, ch);
 				ch.saveToIntent(intent);
-				context.startActivity(intent);					
-				
+				context.startActivity(intent);
+
 			}
 		});
 		return convertView;
 		ImageView image = (ImageView) row.findViewById(R.id.imgIcon);
 		TextView titleText = (TextView) row.findViewById(R.id.txtTitle);
 		TextView stateText = (TextView) row.findViewById(R.id.downloadState);
-		
+
 		Button stopOrResumeButton = (Button) row
 				.findViewById(R.id.stopOrResume);
-		Button deleteButton = (Button) row
-		.findViewById(R.id.delete);
-		deleteButton.getBackground().setColorFilter(GlobalVariable.BUTTON_COLOR);
-		stopOrResumeButton.getBackground().setColorFilter(GlobalVariable.BUTTON_COLOR);
+		Button deleteButton = (Button) row.findViewById(R.id.delete);
+		deleteButton.getBackground()
+				.setColorFilter(GlobalVariable.BUTTON_COLOR);
+		stopOrResumeButton.getBackground().setColorFilter(
+				GlobalVariable.BUTTON_COLOR);
 		Book book = bookList.get(groupPosition);
 		titleText.setText(book.getName());
 		if (book.isDownloading() && GlobalVariable.downloader.isRunning()) {

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

 		ExpandableListView expLV = (ExpandableListView) view.findViewById(R.id.downloadBookList);
 		Helper.setListViewDivid(expLV);
 		expLV.setAdapter(adaptor);
+		
 		expLV.setOnGroupExpandListener(new OnGroupExpandListener() {
 			
 			@Override
 				notifyDataChange();
 			}
 		});
+		
 		return view;
 	}
 	

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

 import me.yangblog.manmanpa.sql.HistorySource;
 import me.yangblog.manmanpa.util.GlobalVariable;
 import me.yangblog.manmanpa.util.Helper;
+import android.app.Activity;
 import android.app.AlertDialog;
+import android.app.Dialog;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.graphics.drawable.GradientDrawable;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.Window;
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemClickListener;
 import android.widget.AdapterView.OnItemLongClickListener;
 import android.widget.ListView;
+import android.widget.TextView;
 import android.widget.Toast;
 
 public class MyComicFragment extends Fragment {
 						if (which == 0) {
 							showtheReader(bookList.get(position));
 						} else if (which == 1) {
-
+							//showToast();
 						} else if (which == 2) {
 							showDeleteComfirm(position);
 						}
 					}
 				});
 		builder.show();
+		
 	}
 
+
+	
+	
+	/*
+	private void showToast() {
+		Dialog dg = new Dialog(activity);
+		dg.requestWindowFeature(Window.FEATURE_NO_TITLE);
+		TextView textView = new TextView(activity);
+		textView.setText("aaaaaaaa");
+		dg.setContentView(textView);
+		dg.show();
+
+	}
+*/
 	public void showDeleteComfirm(final int position) {
 		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
 		builder.setTitle("ɾ����ʾ?").setMessage("ȷ��ɾ���Ķ���ʷ?")
 						hs.deleteByBookid(bookList.get(position).getId());
 						bookList.remove(position);
 						adapter.notifyDataSetChanged();
-						
+
 					}
 
 				})
 				.setNegativeButton("��", new DialogInterface.OnClickListener() {
 					@Override
 					public void onClick(DialogInterface dialog, int which) {
-						
-						
+
 					}
 
 				}).show();

android/src/me/yangblog/manmanpa/util/Downloader.java

 
 		return false;
 	}
+	
+	public boolean isChapterWaitForDownload(Chapter ch){
+		for (List<ChapterDownloader> chdList : taskQueueMap.values()) {
+			for(ChapterDownloader chd: chdList){
+				if (chd.getChapter().equals(ch)&& !chd.getChapter().isDownloaded()) {
+					return true;
+				}
+			}
+		}
+
+		return false;
+	}
+	
 
 	public boolean isBookListDownloadFinish(List<Book> bookList) {
 		for (Book book : bookList) {
-2. ��ǩ + ����
-    * bind search event
-    * new activity to show list
 * delete files
 
 
 
-
+- ����, ������ҳ
 - dialog color----diffcult
 
 
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.