Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

master #57

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="@style/Look.Home"
>
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class MainActivity extends BaseActivity implements IMain {
private int nevigationId;
private int mainColor;

private SimpleArrayMap<Integer, String> mTitleArryMap = new SimpleArrayMap<>();
private SimpleArrayMap<Integer, String> mTitleArrayMap = new SimpleArrayMap<>();

private long exitTime = 0;
private SwitchCompat mThemeSwitch;
Expand All @@ -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;
}
Expand All @@ -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();
Expand All @@ -102,22 +104,35 @@ protected void onCreate(Bundle savedInstanceState) {
if (nevigationId != -1) {
currentMenuItem = navView.getMenu().findItem(nevigationId);
}

if (currentMenuItem == null) {
currentMenuItem = navView.getMenu().findItem(R.id.zhihuitem);
}
if (currentMenuItem != null) {
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);
}
Expand All @@ -131,21 +146,24 @@ 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);
return true;
}


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;
Expand Down Expand Up @@ -251,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
Expand All @@ -271,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();
Expand All @@ -291,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -115,7 +116,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {

}

private void initlistenr() {
private void initListener() {
zhihuReturnHomeListener =
new AnimUtils.TransitionListenerAdapter() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@
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;
import android.support.design.widget.Snackbar;
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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
}
}
};

Expand Down Expand Up @@ -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")) {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/layout/main_layout.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer"
Expand All @@ -12,6 +13,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<!--位于屏幕最顶端,显示手机信号强度、电池电量等的状态栏的背景色-->
<View
android:id="@+id/status_bar_background"
android:layout_width="match_parent"
Expand All @@ -29,7 +31,7 @@
android:layout_width="match_parent"
android:layout_height="?android:actionBarSize"
android:outlineProvider="none"
android:background="#bc000000"
android:background="#bcff0000"
android:elevation="1dp"
style="@style/Widget.Look.HomeToolbar"
app:title="@string/app_name"/>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/meizi_fragment_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


<ProgressBar
android:id="@+id/prograss"
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/topnews_fragment_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
android:elevation="1dp" />

<ProgressBar
android:id="@+id/prograss"
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/zhihu_fragment_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
android:id="@+id/recycle_zhihu"
android:id="@+id/recyclerview_zhihu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
Expand All @@ -13,7 +13,7 @@
android:elevation="1dp" />

<ProgressBar
android:id="@+id/prograss"
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
Expand Down
Loading