Skip to content

Commit

Permalink
add diable news function
Browse files Browse the repository at this point in the history
  • Loading branch information
zjywill committed Jun 18, 2014
1 parent fcf6a54 commit 9133326
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 7 deletions.
7 changes: 7 additions & 0 deletions res/menu/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,12 @@
android:showAsAction="never"
android:checkable="true"
android:title="@string/no_image_mode"/>

<item
android:id="@+id/action_no_news"
android:orderInCategory="100"
android:showAsAction="never"
android:checkable="true"
android:title="@string/no_news_mode"/>

</menu>
2 changes: 1 addition & 1 deletion res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
<string name="save_to_evernote">保存到印象笔记&#8230;</string>
<string name="note_saved">保存到印象笔记成功</string>
<string name="note_save_fail">保存到印象笔记失败</string>

<string name="no_news_mode">不显示新闻</string>
</resources>
1 change: 1 addition & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
<string name="save_to_evernote">Save to Evernote&#8230;</string>
<string name="note_saved">Note saved to Evernote</string>
<string name="note_save_fail">Fail to save to Evernote</string>
<string name="no_news_mode">Not show News</string>

</resources>
30 changes: 28 additions & 2 deletions src/com/comic/chhreader/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class MainActivity extends Activity implements OnItemClickListener, Loade

private boolean updating = false;
private boolean mNoImage = true;
private boolean mNoNews = false;

private List<RssNews> mENews = new ArrayList<RssNews>();

Expand Down Expand Up @@ -94,6 +95,8 @@ protected void onCreate(Bundle savedInstanceState) {
mNoImage = false;
}

mNoNews = SharedPreferencesUtils.getNoNewsMode(mContext);

mGirdAdapter.setNoImage(mNoImage);

mGrid.setAdapter(mGirdAdapter);
Expand All @@ -109,7 +112,14 @@ public void onAnimationEnd(Animator animation) {
mScrollView.setVisibility(View.VISIBLE);
}
});
new FetchNewsTaskLocal().execute();

mGalleryRootView.setNoImage(mNoImage);
if (mNoNews) {
mGalleryRootView.setVisibility(View.GONE);
} else {
new FetchNewsTaskLocal().execute();
}

getLoaderManager().initLoader(LOADER_ID_LOACL, null, this);

if (Utils.isWifiAvailable(mContext) && !updating) {
Expand Down Expand Up @@ -143,6 +153,8 @@ public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
MenuItem no_image = menu.findItem(R.id.action_no_image);
no_image.setChecked(SharedPreferencesUtils.getNoImageMode(mContext));
MenuItem no_news = menu.findItem(R.id.action_no_news);
no_news.setChecked(SharedPreferencesUtils.getNoNewsMode(mContext));
return true;
}

Expand All @@ -151,7 +163,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_do_refresh: {
Loge.i("Options Selected = do_refresh");
if (!updating){
if (!updating) {
new FetchDataTaskNet().execute();
new FetchNewsTaskNet().execute();
}
Expand All @@ -165,6 +177,19 @@ public boolean onOptionsItemSelected(MenuItem item) {
SharedPreferencesUtils.saveNoImageMode(mContext, !state);
}
break;
case R.id.action_no_news: {
boolean state = SharedPreferencesUtils.getNoNewsMode(mContext);
item.setChecked(!state);
SharedPreferencesUtils.saveNoNewsMode(mContext, !state);
mNoNews = !state;
if (mNoNews) {
mGalleryRootView.setVisibility(View.GONE);
} else {
mGalleryRootView.setVisibility(View.VISIBLE);
new FetchNewsTaskLocal().execute();
}
}
break;
default:
break;
}
Expand Down Expand Up @@ -192,6 +217,7 @@ protected void onResume() {
} else {
mNoImage = false;
}
mGalleryRootView.setNoImage(mNoImage);
if (mGirdAdapter != null) {
mGirdAdapter.setNoImage(mNoImage);
new Handler().postDelayed(new Runnable() {
Expand Down
15 changes: 11 additions & 4 deletions src/com/comic/chhreader/gallery/CenterCorssFadeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,27 @@ public class CenterCorssFadeView extends FrameLayout {

private Drawable mLogoDrawable;

public CenterCorssFadeView(Context context, GalleryRootView rootView,
int pagecount) {
private boolean mNoImage = true;

public CenterCorssFadeView(Context context, GalleryRootView rootView, int pagecount) {
super(context);
mPageCount = pagecount;
mRootView = rootView;
initView();
}

public void setNoImage(boolean noImage) {
mNoImage = noImage;
}

private void initView() {
mLogoDrawable = getContext().getResources().getDrawable(R.drawable.feedlogo);
if (mCenterLayoutList == null) {
mCenterLayoutList = new ArrayList<PhotoView>(mPageCount);
}

FrameLayout.LayoutParams centerParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
FrameLayout.LayoutParams centerParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);

for (int i = 0; i < 5; i++) {
PhotoView view = new PhotoView(getContext());
Expand Down Expand Up @@ -84,7 +90,8 @@ public void invalidate() {
String imageUrl = mRootView.mENews.get(i).imageurl;
Loge.d("CenterCorssFadeView invalidate: " + imageUrl);
try {
mCenterLayoutList.get(i).setImageURL(new URL(imageUrl), true, true, true, mLogoDrawable);
mCenterLayoutList.get(i).setImageURL(new URL(imageUrl), true, true, !mNoImage,
mLogoDrawable);
} catch (MalformedURLException e) {
e.printStackTrace();
}
Expand Down
8 changes: 8 additions & 0 deletions src/com/comic/chhreader/gallery/GalleryRootView.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ public void setNews(List<RssNews> eNews) {
mCenterCorssFadeView.invalidate();
}
}

public void setNoImage(boolean noImage){
if (mCenterCorssFadeView != null) {
mCenterCorssFadeView.setNoImage(noImage);
mCenterCorssFadeView.invalidate();
}
}

@Override
public boolean onTouchEvent(MotionEvent event) {
Expand Down Expand Up @@ -274,4 +281,5 @@ public boolean onSingleTapUp(MotionEvent e) {
}

}

}
12 changes: 12 additions & 0 deletions src/com/comic/chhreader/utils/SharedPreferencesUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,17 @@ public static boolean getNoImageMode(Context context) {
SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
return pref.getBoolean("noimagemode", true);
}

public static void saveNoNewsMode(Context context, boolean check) {
SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
Editor editor = pref.edit();
editor.putBoolean("nonewsmode", check);
editor.commit();
}

public static boolean getNoNewsMode(Context context) {
SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
return pref.getBoolean("nonewsmode", false);
}

}

0 comments on commit 9133326

Please sign in to comment.