Commits

mugulion committed 8f42aad

修复BookmarkManageActivity 和 NoteReadActivity

Comments (0)

Files changed (2)

Project/src/com/noodle/note/activity/BookmarkManageActivity.java

 	private Button buttonComplete;
 	private Button buttonCancle;
 	private Session session;
-	/** 书签条目浏览的List*/
+	/** 书签条目浏览的List */
 	private ListView listView;
-	/** 书签条目浏览中每个List的HashMap*/
-	private ArrayList <HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
+	/** 书签条目浏览中每个List的HashMap */
+	private ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
 
 	@Override
 	public void onCreate(Bundle savedInstanceState) {
 		buttonCancle.setOnClickListener(cancle);
 		bundle = this.getIntent().getExtras();
 		session = Session.getInstance(this);
-		/**ListView的内容显示*/
+		bundle = this.getIntent().getExtras();
+		line = bundle.getInt("line");
+		column = bundle.getInt("column");
+		noteId = bundle.getInt("noteId");
+		/** ListView的内容显示 */
 		initViews();
-		/**设置监听器*/
+		/** 设置监听器 */
 		setListeners();
 	}
 
 
 		@Override
 		public void onClick(View v) {
-			line  = bundle.getInt("line");
+			line = bundle.getInt("line");
 			column = bundle.getInt("column");
 			noteId = bundle.getInt("noteId");
 			String bookmarkName = bookmarkEditText.getText().toString();
 			Note note = Registry.getInstance().getEntity(Note.class, noteId);
 			Bookmark bookmark = new Bookmark(note, line, column);
 			bookmark.setName(bookmarkName);
-			BookmarkGateway bookmarkGateway = (BookmarkGateway) session.query(Bookmark.class);
+			BookmarkGateway bookmarkGateway = (BookmarkGateway) session
+					.query(Bookmark.class);
 			bookmarkGateway.create(bookmark);
 			Intent intent = new Intent();
-			int id = bundle.getInt("noteId");
 			Bundle bundle = new Bundle();
-			bundle.putInt("id", id);
+			bundle.putInt("id", noteId);
 			intent.putExtras(bundle);
 			intent.setClass(BookmarkManageActivity.this, NoteReadActivity.class);
 			startActivity(intent);
 			startActivity(intent);
 		}
 	};
-	
-	/**listView项的长按菜单*/
+
+	/** listView项的长按菜单 */
 	OnCreateContextMenuListener longPressMenu = new OnCreateContextMenuListener() {
-		
+
 		@Override
 		public void onCreateContextMenu(ContextMenu menu, View v,
 				ContextMenuInfo menuInfo) {
 			String deleteItem = "删除";
-			/**第二个参数为操作ID */
-			menu.add(0, 0, 0, deleteItem);}	};
+			/** 第二个参数为操作ID */
+			menu.add(0, 0, 0, deleteItem);
+		}
+	};
 
-	/**listView项的接口设置以及监听器设置*/
-	public void setListeners(){
-		listItemAdapter = new SimpleAdapter(this,listItem,R.layout.bookmark_manage_listview,new String[]{"bookmarkname","bookmarkpos"},new int[]{R.id.bookmarkName,R.id.bookmarkPos});
+	/** listView项的接口设置以及监听器设置 */
+	public void setListeners() {
+		listItemAdapter = new SimpleAdapter(this, listItem,
+				R.layout.bookmark_manage_listview, new String[] {
+						"bookmarkname", "bookmarkpos" }, new int[] {
+						R.id.bookmarkName, R.id.bookmarkPos });
 		listView.setAdapter(listItemAdapter);
 		listView.setOnItemClickListener(oicl);
 		listView.setOnCreateContextMenuListener(longPressMenu);
 	}
 
-	
-	/**长按菜单操作设置*/
+	/** 长按菜单操作设置 */
 	@Override
-	public boolean onContextItemSelected(MenuItem item){
-		AdapterView.AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
-		int listItemId = (Integer) listItem.get(info.position).get("bookmarkid");
-		BookmarkGateway bookmarkGateway = (BookmarkGateway) Session.getInstance(this).query(Bookmark.class);
+	public boolean onContextItemSelected(MenuItem item) {
+		AdapterView.AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
+				.getMenuInfo();
+		int listItemId = (Integer) listItem.get(info.position)
+				.get("bookmarkid");
+		BookmarkGateway bookmarkGateway = (BookmarkGateway) Session
+				.getInstance(this).query(Bookmark.class);
 		Bookmark bookmark = bookmarkGateway.findById(listItemId);
-		switch (item.getItemId()){
-		/**长按各项菜单操作*/
+		switch (item.getItemId()) {
+		/** 长按各项菜单操作 */
 		case 0:
 			bookmarkGateway.delete(bookmark);
-			/**变相刷新界面*/
-//			Bundle bundle = new Bundle();
-//			bundle.putInt("line", line);
-//			bundle.putInt("column", column);
-//			bundle.putInt("noteId", noteId);
-			
+			/** 变相刷新界面 */
+			// Bundle bundle = new Bundle();
+			// bundle.putInt("line", line);
+			// bundle.putInt("column", column);
+			// bundle.putInt("noteId", noteId);
+
 			Intent selfintent = new Intent();
 			selfintent.putExtras(bundle);
-			selfintent.setClass(BookmarkManageActivity.this, BookmarkManageActivity.class);
+			selfintent.setClass(BookmarkManageActivity.this,
+					BookmarkManageActivity.class);
 			startActivity(selfintent);
 			BookmarkManageActivity.this.finish();
 			break;
 		}
 		return super.onContextItemSelected(item);
 	}
-	
 
-	
-	/**listView的项短按操作*/
+	/** listView的项短按操作 */
 	OnItemClickListener oicl = new OnItemClickListener() {
-		public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
-			int bookmarkId = (Integer) listItem.get(position).get("id");
-			shortpress(bookmarkId);	}	};
+		public void onItemClick(AdapterView<?> adapter, View v, int position,
+				long id) {
+			int startLine = (Integer) listItem.get(position).get("bookmarkpos");
+			shortpress(noteId, startLine);
+		}
+	};
 
-	/**listview短按链接设置*/
-	private void shortpress(int bookmarkId) {
+	/** listview短按链接设置 */
+	private void shortpress(int id, int startLine) {
 		Intent intent = new Intent();
 		Bundle bundle = new Bundle();
-		bundle.putInt("id", bookmarkId);
+		bundle.putInt("startLine", startLine);
+		bundle.putInt("id", id);
 		intent.setClass(this, NoteReadActivity.class);
 		intent.putExtras(bundle);
-		startActivity(intent);}
-	
-	/**listView的内容创建*/
-	private void initViews(){
-		BookmarkGateway bookmarkGateway = (BookmarkGateway) Session.getInstance(BookmarkManageActivity.this).query(Bookmark.class);
+		startActivity(intent);
+	}
+
+	/** listView的内容创建 */
+	private void initViews() {
+		BookmarkGateway bookmarkGateway = (BookmarkGateway) Session
+				.getInstance(BookmarkManageActivity.this).query(Bookmark.class);
 		listView = (ListView) findViewById(R.id.bookmarkManageList);
-		ArrayList<Bookmark> list = new ArrayList<Bookmark>();
-		list = (ArrayList<Bookmark>) bookmarkGateway.findAll();
-		
-		if(!list.isEmpty()){
-			for(Bookmark bm : list){
+		ArrayList<Bookmark> bookmarkList = new ArrayList<Bookmark>();
+		// TODO 错误
+		HashMap<String, Integer> conditions = new HashMap<String, Integer>();
+		conditions.put("note_id", (Integer) noteId);
+		bookmarkList = (ArrayList<Bookmark>) bookmarkGateway.findBy(conditions);
+
+		if (!bookmarkList.isEmpty()) {
+			for (Bookmark bm : bookmarkList) {
 				HashMap<String, Object> contentMap = new HashMap<String, Object>();
 				contentMap.put("bookmarkname", bm.getName());
 				contentMap.put("bookmarkpos", bm.getLineNumber());
 				contentMap.put("bookmarkid", bm.getId());
-				listItem.add(contentMap);}	}
-		else{
+				listItem.add(contentMap);
+			}
+		} else {
 			HashMap<String, Object> noContentMap = new HashMap<String, Object>();
 			noContentMap.put("bookmarkname", "没有书签");
 			noContentMap.put("bookmarkpos", "空");
-			listItem.add(noContentMap);}	}
+			listItem.add(noContentMap);
+		}
+	}
 }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

Project/src/com/noodle/note/activity/NoteReadActivity.java

 		intent.putExtras(bundle);
 		intent.setClass(this, BookmarkManageActivity.class);
 		this.startActivity(intent);
-		NoteReadActivity.this.finish();
+		//NoteReadActivity.this.finish();
 	}
 
 	private void displayContent() {
 		NoteGateway gateway = (NoteGateway) Session.getInstance(this).query(Note.class);
 		Note note = gateway.findById(pk);
 		String content = note.getArticle();
+		startLine = this.getIntent().getExtras().getInt("startLine");
 		noteContentView.setText(content);
 		noteContentView.scrollBy(0, startLine);
 		
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.