Skip to content
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
22 changes: 13 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ apply plugin: 'android-apt'
apply plugin: 'realm-android'

android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
compileSdkVersion 25
buildToolsVersion '25.0.1'

defaultConfig {
applicationId "com.codeest.geeknews"
minSdkVersion 21
targetSdkVersion 24
targetSdkVersion 25
versionCode 2
versionName "1.0.1"
}
Expand All @@ -28,24 +28,28 @@ android {
}
}

ext {
appCompat = "25.0.1"
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/tbs_sdk_thirdapp_v2.2.0.1096_36549_sharewithdownload_withoutGame_obfs_20160830_211645.jar')
testCompile 'junit:junit:4.12'

//ui
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.android.support:recyclerview-v7:24.1.1'
compile 'com.android.support:cardview-v7:24.1.1'
compile "com.android.support:recyclerview-v7:${appCompat}"
compile "com.android.support:appcompat-v7:${appCompat}"
compile "com.android.support:cardview-v7:${appCompat}"
compile "com.android.support:design:${appCompat}"

//rx
compile 'io.reactivex:rxjava:1.1.0'
compile 'io.reactivex:rxandroid:1.1.0'
compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'

//network
compile 'com.google.code.gson:gson:2.4'
compile 'com.google.code.gson:gson:2.7'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
Expand All @@ -69,7 +73,7 @@ dependencies {
//widget
compile 'com.victor:lib:1.0.4'
compile 'com.prolificinteractive:material-calendarview:1.4.0'
compile 'net.opacapp:multiline-collapsingtoolbar:1.2.2'
compile 'net.opacapp:multiline-collapsingtoolbar:1.3.1'
compile 'com.github.chrisbanes:PhotoView:1.3.0'
compile 'com.miguelcatalan:materialsearchview:1.4.0'

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/codeest/geeknews/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatDelegate;
import android.util.DisplayMetrics;
import android.view.Display;
Expand Down Expand Up @@ -93,7 +94,7 @@ public void exitApp() {
if (allActivities != null) {
synchronized (allActivities) {
for (Activity act : allActivities) {
act.finish();
ActivityCompat.finishAfterTransition(act);
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/codeest/geeknews/base/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.Toolbar;
import android.view.View;
Expand Down Expand Up @@ -100,6 +101,15 @@ public void useNightMode(boolean isNight) {
recreate();
}

@Override
public void onBackPressedSupport() {
if (getSupportFragmentManager().getBackStackEntryCount() > 1) {
pop();
} else {
ActivityCompat.finishAfterTransition(this);
}
}

protected abstract void initInject();
protected abstract int getLayout();
protected abstract void initEventAndData();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.codeest.geeknews.ui.zhihu.activity;

import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v7.widget.Toolbar;

import com.codeest.geeknews.R;
Expand Down Expand Up @@ -54,6 +55,6 @@ public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull Calend
@OnClick(R.id.tv_calender_enter)
void chooseDate() {
RxBus.getDefault().post(mDate);
finish();
ActivityCompat.finishAfterTransition(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.codeest.geeknews.ui.zhihu.activity;

import android.app.ActivityOptions;
import android.content.Intent;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
Expand Down Expand Up @@ -43,6 +45,8 @@ public class SectionActivity extends BaseActivity<SectionChildPresenter> impleme
int id;
String title;

private int position = -1;

@Override
protected void initInject() {
getActivityComponent().inject(this);
Expand Down Expand Up @@ -74,21 +78,37 @@ public void onRefresh() {
public void OnItemClick(int position, View shareView) {
mPresenter.insertReadToDB(mList.get(position).getId());
mAdapter.setReadState(position, true);
mAdapter.notifyItemChanged(position);
SectionActivity.this.position = position;
Intent intent = new Intent();
intent.setClass(mContext, ZhihuDetailActivity.class);
intent.putExtra("id", mList.get(position).getId());
String transitionSharedItemName = ViewCompat.getTransitionName(shareView);
intent.putExtra("shared-item-name", transitionSharedItemName);
if (shareView != null) {
mContext.startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(mContext, shareView, "shareView").toBundle());
ActivityCompat.startActivity(SectionActivity.this, intent, ActivityOptionsCompat.makeSceneTransitionAnimation(mContext, shareView, transitionSharedItemName).toBundle());
} else {
startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(mContext).toBundle());
ActivityCompat.startActivity(SectionActivity.this, intent, ActivityOptionsCompat.makeBasic().toBundle());
}
}
});
mPresenter.getThemeChildData(id);
viewLoading.start();
}

@Override
protected void onResume() {
super.onResume();
if (mAdapter != null && position > 0) {
mAdapter.notifyItemChanged(position);
}
}

@Override
protected void onDestroy() {
super.onDestroy();
position = -1;
}

@Override
public void showContent(SectionChildListBean sectionChildListBean) {
if(swipeRefresh.isRefreshing()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.codeest.geeknews.ui.zhihu.activity;

import android.app.ActivityOptions;
import android.content.Intent;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
Expand Down Expand Up @@ -42,6 +44,8 @@ public class ThemeActivity extends BaseActivity<ThemeChildPresenter> implements

int id;

private int position = -1;

@Override
protected void initInject() {
getActivityComponent().inject(this);
Expand All @@ -67,14 +71,16 @@ protected void initEventAndData() {
public void onItemClick(int position, View shareView) {
mPresenter.insertReadToDB(mList.get(position).getId());
mAdapter.setReadState(position, true);
mAdapter.notifyItemChanged(position);
ThemeActivity.this.position = position;
Intent intent = new Intent();
intent.setClass(mContext, ZhihuDetailActivity.class);
intent.putExtra("id", mList.get(position).getId());
if (shareView != null) {
mContext.startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(mContext, shareView, "shareView").toBundle());
String transitionSharedItemName = ViewCompat.getTransitionName(shareView);
intent.putExtra("shared-item-name", transitionSharedItemName);
ActivityCompat.startActivity(ThemeActivity.this,intent, ActivityOptionsCompat.makeSceneTransitionAnimation(mContext, shareView, transitionSharedItemName).toBundle());
} else {
startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(mContext).toBundle());
ActivityCompat.startActivity(ThemeActivity.this, intent, ActivityOptionsCompat.makeBasic().toBundle());
}
}
});
Expand All @@ -97,6 +103,20 @@ public void onRefresh() {
});
}

@Override
protected void onResume() {
super.onResume();
if (mAdapter != null && position > 0) {
mAdapter.notifyItemChanged(position);
}
}

@Override
protected void onDestroy() {
super.onDestroy();
position = -1;
}

@Override
public void showError(String msg) {
if(swipeRefresh.isRefreshing()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.codeest.geeknews.ui.zhihu.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ActivityCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.Toolbar;
import android.transition.Transition;
Expand Down Expand Up @@ -62,6 +66,8 @@ public class ZhihuDetailActivity extends BaseActivity<ZhihuDetailPresenter> impl
FrameLayout llDetailBottom;
@BindView(R.id.fab_like)
FloatingActionButton fabLike;
@BindView(R.id.app_bar)
AppBarLayout appBar;

int id = 0;
int allNum = 0;
Expand All @@ -83,10 +89,12 @@ protected int getLayout() {
return R.layout.activity_zhihu_detail;
}

@SuppressLint("SetJavaScriptEnabled")
@Override
protected void initEventAndData() {
setToolBar(viewToolbar,"");
Intent intent = getIntent();
setToolBar(viewToolbar,"");
ViewCompat.setTransitionName(appBar, intent.getExtras().getString("shared-item-name"));
id = intent.getExtras().getInt("id");
mPresenter.queryLikeData(id);
mPresenter.getDetailData(id);
Expand Down Expand Up @@ -233,7 +241,7 @@ public void onBackPressedSupport() {
if (getSupportFragmentManager().getBackStackEntryCount() > 1) {
pop();
} else {
finishAfterTransition();
ActivityCompat.finishAfterTransition(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
Expand All @@ -12,6 +13,7 @@
import android.widget.TextView;

import com.codeest.geeknews.R;
import com.codeest.geeknews.app.App;
import com.codeest.geeknews.component.ImageLoader;
import com.codeest.geeknews.model.bean.DailyBeforeListBean;
import com.codeest.geeknews.model.bean.DailyListBean;
Expand Down Expand Up @@ -87,26 +89,31 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType
}

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
public void onBindViewHolder( RecyclerView.ViewHolder holder, int position) {
if (holder instanceof ContentViewHolder) {
final int contentPosition;
if(isBefore) {
contentPosition = position - 1;
} else {
contentPosition = position - 2;
}
((ContentViewHolder)holder).title.setText(mList.get(contentPosition).getTitle());
if (mList.get(contentPosition).getReadState()) {
final DailyListBean.StoriesBean listItem = mList.get(contentPosition);
((ContentViewHolder)holder).title.setText(listItem
.getTitle());
if (listItem
.getReadState()) {
((ContentViewHolder)holder).title.setTextColor(ContextCompat.getColor(mContext,R.color.news_read));
} else {
((ContentViewHolder)holder).title.setTextColor(ContextCompat.getColor(mContext,R.color.news_unread));
}
ImageLoader.load(mContext,mList.get(contentPosition).getImages().get(0),((ContentViewHolder)holder).image);
final String url = listItem.getImages().get(0);
ImageLoader.load(mContext,url, ((ContentViewHolder)holder).image);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(onItemClickListener != null) {
ImageView iv = (ImageView) view.findViewById(R.id.iv_daily_item_image);
ViewCompat.setTransitionName(iv, App.getInstance().getString(R.string.transition_share_item_name) + "-" + url);
onItemClickListener.onItemClick(contentPosition,iv);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -10,6 +11,7 @@
import android.widget.TextView;

import com.codeest.geeknews.R;
import com.codeest.geeknews.app.App;
import com.codeest.geeknews.component.ImageLoader;
import com.codeest.geeknews.model.bean.HotListBean;
import com.codeest.geeknews.widget.SquareImageView;
Expand Down Expand Up @@ -48,18 +50,24 @@ public int getItemCount() {

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
holder.title.setText(mList.get(position).getTitle());
if (mList.get(position).getReadState()) {
final HotListBean.RecentBean listItem = mList.get(position);
holder.title.setText(listItem
.getTitle());
if (listItem
.getReadState()) {
holder.title.setTextColor(ContextCompat.getColor(mContext,R.color.news_read));
} else {
holder.title.setTextColor(ContextCompat.getColor(mContext,R.color.news_unread));
}
ImageLoader.load(mContext,mList.get(position).getThumbnail(),holder.image);
final String url = listItem
.getThumbnail();
ImageLoader.load(mContext, url, holder.image);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(onItemClickListener != null) {
ImageView iv = (ImageView) view.findViewById(R.id.iv_daily_item_image);
ViewCompat.setTransitionName(iv, App.getInstance().getString(R.string.transition_share_item_name) + "-" + url);
onItemClickListener.onItemClick(holder.getAdapterPosition(),iv);
}
}
Expand Down
Loading