2929import com .brian .csdnblog .R ;
3030import com .brian .csdnblog .datacenter .preference .SettingPreference ;
3131import com .brian .csdnblog .manager .BlogManager ;
32+ import com .brian .csdnblog .manager .BlogerManager ;
3233import com .brian .csdnblog .manager .DataFetcher ;
3334import com .brian .csdnblog .manager .DataFetcher .OnFetchDataListener ;
3435import com .brian .csdnblog .manager .DataFetcher .Result ;
@@ -62,14 +63,16 @@ public class BlogContentActivity extends BaseActivity implements OnFetchDataList
6263
6364 @ BindView (R .id .title_bar ) TitleBar mTitleBar ;
6465 @ BindView (R .id .article_content ) WebView mWebView ;
65- @ BindView (R .id .btn_favo ) ImageView mBtnFavo ;
6666 @ BindView (R .id .blogContentPro ) ProgressBar mProgressBar ; // 进度条
6767 @ BindView (R .id .reLoadImage ) ImageView mReLoadImageView ; // 重新加载的图片
6868 @ BindView (R .id .ad_group ) FrameLayout mAdLayout ; // 广告
69+ private PopupMenu mPopupMenu ;
6970
7071 private IQhInterstitialAd mAd ;
7172
7273 private IBlogHtmlParser mBlogParser = null ;
74+
75+ private boolean mHasFavoed ;
7376
7477 /**
7578 * 存放已打开过的链接
@@ -113,7 +116,6 @@ protected void onCreate(Bundle savedInstanceState) {
113116 ButterKnife .bind (this );
114117
115118 initUI ();// 初始化界面
116- initPopupMenu ();
117119 initListener ();
118120 initAd ();
119121
@@ -123,6 +125,8 @@ protected void onCreate(Bundle savedInstanceState) {
123125 finish ();
124126 return ;
125127 }
128+ initPopupMenu ();
129+
126130 mTitleBar .setTitle (mBlogInfo .title );
127131 mCurrentTitle = mBlogInfo .title ;
128132
@@ -181,7 +185,7 @@ private void toggleAdShow(boolean isShow) {
181185
182186
183187 private void initUI () {
184- mTitleBar .setRightImageResource (R .drawable .ic_share );
188+ mTitleBar .setRightImageResource (R .drawable .ic_menu );
185189 // 点击图片重新加载
186190 mWebView .setWebViewClient (new MyWebViewClient ());
187191 mWebView .setLayerType (View .LAYER_TYPE_SOFTWARE , null );
@@ -218,30 +222,40 @@ private void initUI() {
218222// webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);//适应屏幕,内容将自动缩放
219223 }
220224
221- PopupMenu popupMenu ;
222225 private void initPopupMenu () {
223- popupMenu = new PopupMenu (this , mTitleBar .getRightButton ());
224- Menu menu = popupMenu .getMenu ();
226+ mPopupMenu = new PopupMenu (this , mTitleBar .getRightButton ());
225227 // 通过代码添加菜单项
228+ Menu menu = mPopupMenu .getMenu ();
226229 menu .add (Menu .NONE , Menu .FIRST , 0 , "分享" );
227230 menu .add (Menu .NONE , Menu .FIRST + 1 , 1 , "收藏" );
228231 menu .add (Menu .NONE , Menu .FIRST + 2 , 2 , "博主列表" );
229232
233+ if (mBlogInfo .blogerID .equalsIgnoreCase (BlogerManager .getsInstance ().getCurrBloger ().blogerID )) {
234+ mPopupMenu .getMenu ().getItem (2 ).setVisible (false );
235+ }
236+
230237 // 监听事件
231- popupMenu .setOnMenuItemClickListener (new PopupMenu .OnMenuItemClickListener () {
238+ mPopupMenu .setOnMenuItemClickListener (new PopupMenu .OnMenuItemClickListener () {
232239
233240 @ Override
234241 public boolean onMenuItemClick (MenuItem item ) {
235242 switch (item .getItemId ()) {
236- case Menu .FIRST + 0 :
243+ case Menu .FIRST :
244+ UsageStatsManager .sendUsageData (UsageStatsManager .MENU_CONTENT_LIST , "分享" );
237245 onClickShare ();
238246 break ;
239247 case Menu .FIRST + 1 :
240- boolean hasFavoed = mBtnFavo .isSelected ();
241- BlogManager .getInstance ().doFavo (mBlogInfo , !hasFavoed );
242- mBtnFavo .setSelected (!hasFavoed );
248+ UsageStatsManager .sendUsageData (UsageStatsManager .MENU_CONTENT_LIST , "收藏" );
249+ mHasFavoed = !mHasFavoed ;
250+ BlogManager .getInstance ().doFavo (mBlogInfo , mHasFavoed );
251+ if (mHasFavoed ) {
252+ mPopupMenu .getMenu ().getItem (1 ).setTitle ("取消收藏" );
253+ } else {
254+ mPopupMenu .getMenu ().getItem (1 ).setTitle ("收藏" );
255+ }
243256 break ;
244257 case Menu .FIRST + 2 :
258+ UsageStatsManager .sendUsageData (UsageStatsManager .MENU_CONTENT_LIST , "博主" );
245259 if (!TextUtils .isEmpty (mBlogInfo .blogerID )) {
246260 LogUtil .log (mBlogInfo .blogerJson );
247261 Bloger bloger = Bloger .fromJson (mBlogInfo .blogerJson );
@@ -270,8 +284,7 @@ public void onClick(View v) {
270284
271285 @ Override
272286 public void onClick (View v ) {
273- // onClickShare();
274- popupMenu .show ();
287+ mPopupMenu .show ();
275288 }
276289 });
277290 mReLoadImageView .setOnClickListener (new OnClickListener () {
@@ -284,15 +297,6 @@ public void onClick(View v) {
284297 DataFetcher .getInstance ().fetchString (mCurrentUrl , BlogContentActivity .this );
285298 }
286299 });
287- mBtnFavo .setOnClickListener (new OnClickListener () {
288-
289- @ Override
290- public void onClick (View v ) {
291- boolean hasFavoed = mBtnFavo .isSelected ();
292- BlogManager .getInstance ().doFavo (mBlogInfo , !hasFavoed );
293- mBtnFavo .setSelected (!hasFavoed );
294- }
295- });
296300 }
297301
298302 @ Override
@@ -400,7 +404,6 @@ private void showErrorPage() {
400404 UsageStatsManager .sendUsageData (UsageStatsManager .EXP_EMPTY_BLOG , TypeManager .getBlogName (mBlogInfo .type ));
401405
402406 mWebView .setVisibility (View .INVISIBLE );
403- mBtnFavo .setVisibility (View .INVISIBLE );
404407 mProgressBar .setVisibility (View .INVISIBLE );
405408 mReLoadImageView .setVisibility (View .VISIBLE );
406409 }
@@ -412,11 +415,16 @@ private void showErrorPage() {
412415 public boolean handleMessage (Message msg ) {
413416 switch (msg .what ) {
414417 case MSG_UPDATE :
418+ toggleAdShow (false );// 隐藏广告
415419 mReLoadImageView .setVisibility (View .GONE );
416420 mProgressBar .setVisibility (View .GONE );
417-
418- mBtnFavo .setVisibility (View .VISIBLE );
419- mBtnFavo .setSelected (BlogManager .getInstance ().isFavo (mBlogInfo ));
421+
422+ mHasFavoed = BlogManager .getInstance ().isFavo (mBlogInfo );
423+ if (mHasFavoed ) {
424+ mPopupMenu .getMenu ().getItem (1 ).setTitle ("取消收藏" );
425+ } else {
426+ mPopupMenu .getMenu ().getItem (1 ).setTitle ("收藏" );
427+ }
420428 mWebView .setVisibility (View .VISIBLE );
421429 String content = (String ) msg .obj ;
422430 mWebView .loadDataWithBaseURL (mBlogParser .getBlogBaseUrl (), content ,
@@ -435,7 +443,6 @@ public boolean handleMessage(Message msg) {
435443
436444 @ Override
437445 public void onFetchFinished (final Result <String > response ) {
438- toggleAdShow (false );// 隐藏广告
439446 LogUtil .i ("response=" + response .data );
440447 if (TextUtils .isEmpty (response .data )) {
441448 showErrorPage ();
0 commit comments