From 9f9fe47bbc372cccafb26c87c8a81a5f2e24276b Mon Sep 17 00:00:00 2001
From: yongjiexu <13255288587@163.com>
Date: Mon, 5 Jun 2017 20:14:08 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=82=B9=E5=87=BB?=
=?UTF-8?q?=E5=AF=BC=E8=88=AA=E6=A0=8F=E2=80=9C=E5=85=B3=E4=BA=8E=E2=80=9D?=
=?UTF-8?q?item=E5=90=8E=E4=BB=A3=E7=A0=81=E9=97=AA=E9=80=80=E7=9A=84bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/modules.xml | 2 ++
.../java/com/looklook/xinghongfei/looklook/MainActivity.java | 1 +
2 files changed, 3 insertions(+)
diff --git a/.idea/modules.xml b/.idea/modules.xml
index 1ea45e5..c1ff828 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -3,6 +3,8 @@
+
+
diff --git a/app/src/main/java/com/looklook/xinghongfei/looklook/MainActivity.java b/app/src/main/java/com/looklook/xinghongfei/looklook/MainActivity.java
index e2371d0..52e5c3b 100644
--- a/app/src/main/java/com/looklook/xinghongfei/looklook/MainActivity.java
+++ b/app/src/main/java/com/looklook/xinghongfei/looklook/MainActivity.java
@@ -134,6 +134,7 @@ public boolean onNavigationItemSelected(MenuItem item) {
if(currentMenuItem!=null&&item.getItemId()==R.id.menu_about)
{
Intent intent = new Intent(getApplication(), AboutActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(intent);
return true;
}
From f5694ef62abb4bb8bc09522cab8822b927e1dec5 Mon Sep 17 00:00:00 2001
From: yongjiexu <13255288587@163.com>
Date: Tue, 6 Jun 2017 17:23:56 +0800
Subject: [PATCH 2/2] =?UTF-8?q?=E5=81=9A=E5=87=BA=E4=B8=80=E4=BA=9B?=
=?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9Arename=E3=80=81=E8=B0=83=E6=95=B4?=
=?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F=E7=AD=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/encodings.xml | 2 +-
app/src/main/AndroidManifest.xml | 1 -
.../xinghongfei/looklook/MainActivity.java | 39 +++--
.../activity/ZhihuDescribeActivity.java | 5 +-
.../looklook/fragment/MeiziFragment.java | 2 +-
.../looklook/fragment/TopNewsFragment.java | 2 +-
.../looklook/fragment/ZhihuFragment.java | 49 +++---
.../implPresenter/ZhihuPresenterImpl.java | 2 +-
app/src/main/res/layout/main_layout.xml | 6 +-
.../main/res/layout/meizi_fragment_layout.xml | 2 +-
.../res/layout/topnews_fragment_layout.xml | 2 +-
.../main/res/layout/zhihu_fragment_layout.xml | 4 +-
app/src/main/res/layout/zhihudescribe.xml | 149 +++++++++---------
13 files changed, 146 insertions(+), 119 deletions(-)
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
index 97626ba..c2bae49 100644
--- a/.idea/encodings.xml
+++ b/.idea/encodings.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 7d3d9d0..63cadb7 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -22,7 +22,6 @@
diff --git a/app/src/main/java/com/looklook/xinghongfei/looklook/MainActivity.java b/app/src/main/java/com/looklook/xinghongfei/looklook/MainActivity.java
index 52e5c3b..3661b17 100644
--- a/app/src/main/java/com/looklook/xinghongfei/looklook/MainActivity.java
+++ b/app/src/main/java/com/looklook/xinghongfei/looklook/MainActivity.java
@@ -60,7 +60,7 @@ public class MainActivity extends BaseActivity implements IMain {
private int nevigationId;
private int mainColor;
- private SimpleArrayMap mTitleArryMap = new SimpleArrayMap<>();
+ private SimpleArrayMap mTitleArrayMap = new SimpleArrayMap<>();
private long exitTime = 0;
private SwitchCompat mThemeSwitch;
@@ -71,7 +71,7 @@ public class MainActivity extends BaseActivity implements IMain {
private Toolbar.OnMenuItemClickListener onMenuItemClick = new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
-
+ //设置侧边菜单的打开方向。
drawer.openDrawer(GravityCompat.END);
return true;
}
@@ -87,8 +87,10 @@ protected void onCreate(Bundle savedInstanceState) {
IMainPresenter = new MainPresenterImpl(this, this);
IMainPresenter.getBackground();
+ //设置使用菜单项打开侧边菜单的监听器
toolbar.setOnMenuItemClickListener(onMenuItemClick);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ //TODO ?
animateToolbar();
}
addfragmentsAndTitle();
@@ -102,6 +104,7 @@ protected void onCreate(Bundle savedInstanceState) {
if (nevigationId != -1) {
currentMenuItem = navView.getMenu().findItem(nevigationId);
}
+
if (currentMenuItem == null) {
currentMenuItem = navView.getMenu().findItem(R.id.zhihuitem);
}
@@ -109,15 +112,27 @@ protected void onCreate(Bundle savedInstanceState) {
currentMenuItem.setChecked(true);
// TODO: 16/8/17 add a fragment and set toolbar title
Fragment fragment = getFragmentById(currentMenuItem.getItemId());
- String title = mTitleArryMap.get((Integer) currentMenuItem.getItemId());
+ //TODO title在哪里显示出来?
+ String title = mTitleArrayMap.get((Integer) currentMenuItem.getItemId());
if (fragment != null) {
switchFragment(fragment, title);
}
}
} else {
+ //TODO 此处currentMenuItem不是必定为空的吗?
+ //发邮件问作者currentMenuItem不空的情况何时出现
+ /**question1: 为什么旋转屏幕后重建Activity时 onCreate不执行
+ * q2:旋转屏幕后,activity类对象是原来的,还是新的
+ */
+
+ /**
+ * 可能不空的情境:
+ * 屏幕旋转,MainActivity被销毁后重建,而MainActivity类实例没有被销毁。
+ * 此时currentMenuItem仍然存在
+ */
if (currentMenuItem != null) {
Fragment fragment = getFragmentById(currentMenuItem.getItemId());
- String title = mTitleArryMap.get((Integer) currentMenuItem.getItemId());
+ String title = mTitleArrayMap.get((Integer) currentMenuItem.getItemId());
if (fragment != null) {
switchFragment(fragment, title);
}
@@ -131,8 +146,9 @@ protected void onCreate(Bundle savedInstanceState) {
navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem item) {
- if(currentMenuItem!=null&&item.getItemId()==R.id.menu_about)
+ if(currentMenuItem != null && item.getItemId() == R.id.menu_about)
{
+ //TODO getApplication()作为参数的作用
Intent intent = new Intent(getApplication(), AboutActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(intent);
@@ -140,13 +156,14 @@ public boolean onNavigationItemSelected(MenuItem item) {
}
- if (currentMenuItem != item && currentMenuItem != null) {
+ if (currentMenuItem != null && currentMenuItem != item) {
currentMenuItem.setChecked(false);
int id = item.getItemId();
SharePreferenceUtil.putNevigationItem(MainActivity.this, id);
currentMenuItem = item;
currentMenuItem.setChecked(true);
- switchFragment(getFragmentById(currentMenuItem.getItemId()), mTitleArryMap.get(currentMenuItem.getItemId()));
+ switchFragment(getFragmentById(currentMenuItem.getItemId()),
+ mTitleArrayMap.get(currentMenuItem.getItemId()));
}
drawer.closeDrawer(GravityCompat.END, true);
return true;
@@ -252,9 +269,9 @@ private Fragment getFragmentById(int id) {
}
private void addfragmentsAndTitle() {
- mTitleArryMap.put(R.id.zhihuitem, getResources().getString(R.string.zhihu));
- mTitleArryMap.put(R.id.topnewsitem, getResources().getString(R.string.topnews));
- mTitleArryMap.put(R.id.meiziitem, getResources().getString(R.string.meizi));
+ mTitleArrayMap.put(R.id.zhihuitem, getResources().getString(R.string.zhihu));
+ mTitleArrayMap.put(R.id.topnewsitem, getResources().getString(R.string.topnews));
+ mTitleArrayMap.put(R.id.meiziitem, getResources().getString(R.string.meizi));
}
@Override
@@ -272,6 +289,7 @@ public void onBackPressed() {
if (drawer.isDrawerOpen(GravityCompat.END)) {
drawer.closeDrawer(GravityCompat.END);
} else {
+ //TODO 这句话的目的是什么?
if ((System.currentTimeMillis() - exitTime) > 2000) {
Toast.makeText(MainActivity.this, "再点一次,退出", Toast.LENGTH_SHORT).show();
exitTime = System.currentTimeMillis();
@@ -292,6 +310,7 @@ private void switchFragment(Fragment fragment, String title) {
}
}
+ //TODO 看关于动画部分的知识
private void animateToolbar() {
// this is gross but toolbar doesn't expose it's children to animate them :(
View t = toolbar.getChildAt(0);
diff --git a/app/src/main/java/com/looklook/xinghongfei/looklook/activity/ZhihuDescribeActivity.java b/app/src/main/java/com/looklook/xinghongfei/looklook/activity/ZhihuDescribeActivity.java
index 1c9e6e1..2d7f9ed 100644
--- a/app/src/main/java/com/looklook/xinghongfei/looklook/activity/ZhihuDescribeActivity.java
+++ b/app/src/main/java/com/looklook/xinghongfei/looklook/activity/ZhihuDescribeActivity.java
@@ -93,13 +93,14 @@ public class ZhihuDescribeActivity extends SwipeBackActivity implements IZhihuSt
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.zhihudescribe);
+
setDragEdge(SwipeBackLayout.DragEdge.LEFT);
ButterKnife.bind(this);
mDeviceInfo = DensityUtil.getDeviceInfo(this);
width = mDeviceInfo[0];
heigh = width * 3 / 4;
setSupportActionBar(mToolbar);
- initlistenr();
+ initListener();
initData();
initView();
getData();
@@ -115,7 +116,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
}
- private void initlistenr() {
+ private void initListener() {
zhihuReturnHomeListener =
new AnimUtils.TransitionListenerAdapter() {
@Override
diff --git a/app/src/main/java/com/looklook/xinghongfei/looklook/fragment/MeiziFragment.java b/app/src/main/java/com/looklook/xinghongfei/looklook/fragment/MeiziFragment.java
index dc841d1..f31f6ae 100644
--- a/app/src/main/java/com/looklook/xinghongfei/looklook/fragment/MeiziFragment.java
+++ b/app/src/main/java/com/looklook/xinghongfei/looklook/fragment/MeiziFragment.java
@@ -31,7 +31,7 @@ public class MeiziFragment extends BaseFragment implements IMeiziFragment {
@BindView(R.id.recycle_meizi)
RecyclerView mRecycleMeizi;
- @BindView(R.id.prograss)
+ @BindView(R.id.progress)
ProgressBar mPrograss;
private WrapContentLinearLayoutManager linearLayoutManager;
diff --git a/app/src/main/java/com/looklook/xinghongfei/looklook/fragment/TopNewsFragment.java b/app/src/main/java/com/looklook/xinghongfei/looklook/fragment/TopNewsFragment.java
index d1611e8..6b11abb 100644
--- a/app/src/main/java/com/looklook/xinghongfei/looklook/fragment/TopNewsFragment.java
+++ b/app/src/main/java/com/looklook/xinghongfei/looklook/fragment/TopNewsFragment.java
@@ -31,7 +31,7 @@ public class TopNewsFragment extends BaseFragment implements ITopNewsFragment {
private TopNewsPrensenterImpl mTopNewsPrensenter;
@BindView(R.id.recycle_topnews)
RecyclerView recycle;
- @BindView(R.id.prograss)
+ @BindView(R.id.progress)
ProgressBar progress;
private boolean isLoading;
diff --git a/app/src/main/java/com/looklook/xinghongfei/looklook/fragment/ZhihuFragment.java b/app/src/main/java/com/looklook/xinghongfei/looklook/fragment/ZhihuFragment.java
index e8e3119..48e098c 100644
--- a/app/src/main/java/com/looklook/xinghongfei/looklook/fragment/ZhihuFragment.java
+++ b/app/src/main/java/com/looklook/xinghongfei/looklook/fragment/ZhihuFragment.java
@@ -6,6 +6,7 @@
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkRequest;
+import android.nfc.Tag;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
@@ -13,12 +14,14 @@
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.widget.ProgressBar;
import android.widget.TextView;
+import android.widget.Toast;
import com.looklook.xinghongfei.looklook.R;
import com.looklook.xinghongfei.looklook.adapter.ZhihuAdapter;
@@ -47,10 +50,10 @@ public class ZhihuFragment extends BaseFragment implements IZhihuFragment {
View view = null;
ZhihuPresenterImpl zhihuPresenter;
- @BindView(R.id.recycle_zhihu)
- RecyclerView recycle;
- @BindView(R.id.prograss)
- ProgressBar progress;
+ @BindView(R.id.recyclerview_zhihu)
+ RecyclerView recyclerView_zhihu;
+ @BindView(R.id.progress)
+ ProgressBar progressBar;
private String currentLoadDate;
private ConnectivityManager.NetworkCallback connectivityCallback;
@@ -111,14 +114,14 @@ private void initialView() {
} else {
mLinearLayoutManager = new LinearLayoutManager(getContext());
}
- recycle.setLayoutManager(mLinearLayoutManager);
- recycle.setHasFixedSize(true);
- recycle.addItemDecoration(new GridItemDividerDecoration(getContext(), R.dimen.divider_height, R.color.divider));
+ recyclerView_zhihu.setLayoutManager(mLinearLayoutManager);
+ recyclerView_zhihu.setHasFixedSize(true);
+ recyclerView_zhihu.addItemDecoration(new GridItemDividerDecoration(getContext(), R.dimen.divider_height, R.color.divider));
// TODO: 16/8/13 add animation
- recycle.setItemAnimator(new DefaultItemAnimator());
- recycle.setAdapter(zhihuAdapter);
- recycle.addOnScrollListener(loadingMoreListener);
-// recycle.addOnScrollListener(tooldimissListener);
+ recyclerView_zhihu.setItemAnimator(new DefaultItemAnimator());
+ recyclerView_zhihu.setAdapter(zhihuAdapter);
+ recyclerView_zhihu.addOnScrollListener(loadingMoreListener);
+// recyclerView_zhihu.addOnScrollListener(tooldimissListener);
if (connected) {
loadDate();
}
@@ -163,6 +166,12 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
loadMoreDate();
}
}
+
+ if(dy < 0) //TODO 向上滚动, 即下拉。下拉的判断条件应该更严格 考虑增加下拉刷新功能
+ {
+ Log.i("ZhihuFragment", "下拉刷新");
+ Toast.makeText(getActivity(), "下拉刷新", Toast.LENGTH_SHORT);
+ }
}
};
@@ -201,30 +210,30 @@ public void updateList(ZhihuDaily zhihuDaily) {
currentLoadDate = zhihuDaily.getDate();
zhihuAdapter.addItems(zhihuDaily.getStories());
// if the new data is not full of the screen, need load more data
- if (!recycle.canScrollVertically(View.SCROLL_INDICATOR_BOTTOM)) {
+ if (!recyclerView_zhihu.canScrollVertically(View.SCROLL_INDICATOR_BOTTOM)) {
loadMoreDate();
}
}
@Override
public void showProgressDialog() {
- if (progress != null) {
- progress.setVisibility(View.VISIBLE);
+ if (progressBar != null) {
+ progressBar.setVisibility(View.VISIBLE);
}
}
@Override
public void hidProgressDialog() {
- if (progress != null) {
- progress.setVisibility(View.INVISIBLE);
+ if (progressBar != null) {
+ progressBar.setVisibility(View.INVISIBLE);
}
}
@Override
public void showError(String error) {
- if (recycle != null) {
- Snackbar.make(recycle, getString(R.string.snack_infor), Snackbar.LENGTH_SHORT).setAction("重试", new View.OnClickListener() {
+ if (recyclerView_zhihu != null) {
+ Snackbar.make(recyclerView_zhihu, getString(R.string.snack_infor), Snackbar.LENGTH_LONG).setAction("重试", new View.OnClickListener() {
@Override
public void onClick(View v) {
if (currentLoadDate.equals("0")) {
@@ -249,8 +258,8 @@ private void checkConnectivity(View view) {
= (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
final NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
connected = activeNetworkInfo != null && activeNetworkInfo.isConnected();
- if (!connected && progress != null) {//不判断容易抛出空指针异常
- progress.setVisibility(View.INVISIBLE);
+ if (!connected && progressBar != null) {//不判断容易抛出空指针异常
+ progressBar.setVisibility(View.INVISIBLE);
if (noConnectionText == null) {
ViewStub stub_text = (ViewStub) view.findViewById(R.id.stub_no_connection_text);
diff --git a/app/src/main/java/com/looklook/xinghongfei/looklook/presenter/implPresenter/ZhihuPresenterImpl.java b/app/src/main/java/com/looklook/xinghongfei/looklook/presenter/implPresenter/ZhihuPresenterImpl.java
index 3fc40a4..18448dd 100755
--- a/app/src/main/java/com/looklook/xinghongfei/looklook/presenter/implPresenter/ZhihuPresenterImpl.java
+++ b/app/src/main/java/com/looklook/xinghongfei/looklook/presenter/implPresenter/ZhihuPresenterImpl.java
@@ -26,7 +26,7 @@ public class ZhihuPresenterImpl extends BasePresenterImpl implements IZhihuPrese
private CacheUtil mCacheUtil;
private Gson gson = new Gson();
- public ZhihuPresenterImpl(Context context,IZhihuFragment zhihuFragment) {
+ public ZhihuPresenterImpl(Context context, IZhihuFragment zhihuFragment) {
mZhihuFragment = zhihuFragment;
mCacheUtil = CacheUtil.get(context);
diff --git a/app/src/main/res/layout/main_layout.xml b/app/src/main/res/layout/main_layout.xml
index 6856885..e9719b8 100644
--- a/app/src/main/res/layout/main_layout.xml
+++ b/app/src/main/res/layout/main_layout.xml
@@ -1,5 +1,6 @@
-
+
diff --git a/app/src/main/res/layout/meizi_fragment_layout.xml b/app/src/main/res/layout/meizi_fragment_layout.xml
index edab74a..62f6e7d 100644
--- a/app/src/main/res/layout/meizi_fragment_layout.xml
+++ b/app/src/main/res/layout/meizi_fragment_layout.xml
@@ -17,7 +17,7 @@
-
-
-
-
-
+ android:layout_height="match_parent"
+ android:background="@color/nev_item"
+ android:transitionGroup="false"
+ android:transitionName="@string/transition_shot_background">
-
-
-
-
-
-
+ android:layout_height="wrap_content">
-
-
-
-
+
+
+
+
+
+
+
+ android:layout_height="?android:actionBarSize"
+ android:background="#3b000000"
+ android:elevation="1dp"
+ android:outlineProvider="none"
+ app:title="@string/zhihu" />
+
+
-
-
-
-
-
-
-
+ android:layout_marginTop="260dp"
+ android:orientation="vertical">
+
+
+
+
+
+
+
+