Skip to content

Commit

Permalink
v1.2.3 发布
Browse files Browse the repository at this point in the history
  • Loading branch information
iMeiji committed May 11, 2017
1 parent e149282 commit 7590383
Show file tree
Hide file tree
Showing 60 changed files with 702 additions and 1,779 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## 头条
一款第三方今日头条客户端, 不断完善中
一款第三方今日头条客户端, 不断完善中, MVP + RxJava + Retrofit

其中API来自 [今日头条Api分析](https://github.com/iMeiji/Toutiao/wiki/%E4%BB%8A%E6%97%A5%E5%A4%B4%E6%9D%A1Api%E5%88%86%E6%9E%90)

Expand All @@ -18,6 +18,10 @@

## 更新日志
```
2017-5-11
修复无法下拉刷新 bug
重构项目
2017-5-9
更新部分 UI
图片浏览器若获取数据失败 则采用 WebView 加载
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ android {
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.2.2"
versionName "1.2.3"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
}
Expand Down
22 changes: 1 addition & 21 deletions app/src/main/java/com/meiji/toutiao/InitApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@
import android.content.Context;
import android.support.v7.app.AppCompatDelegate;

import com.facebook.stetho.Stetho;
import com.franmontiel.persistentcookiejar.ClearableCookieJar;
import com.franmontiel.persistentcookiejar.PersistentCookieJar;
import com.franmontiel.persistentcookiejar.cache.SetCookieCache;
import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor;
import com.meiji.toutiao.utils.SettingsUtil;

import okhttp3.OkHttpClient;

/**
* Created by Meiji on 2016/12/12.
*/
Expand All @@ -21,19 +14,6 @@ public class InitApp extends Application {

public static Context AppContext;

public static OkHttpClient okHttpClient = null;

public static OkHttpClient getOkHttpClient() {
if (okHttpClient == null) {
ClearableCookieJar cookieJar =
new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(AppContext));
okHttpClient = new OkHttpClient.Builder()
.cookieJar(cookieJar)
.build();
}
return okHttpClient;
}

@Override
public void onCreate() {
super.onCreate();
Expand All @@ -44,7 +24,7 @@ public void onCreate() {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
if (BuildConfig.DEBUG) {
Stetho.initializeWithDefaults(this);
SdkManager.initStetho(AppContext);
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/meiji/toutiao/api/IVideoApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface IVideoApi {
@GET("api/article/recent/?source=2&as=A105177907376A5&cp=5797C7865AD54E1&count=30")
Observable<VideoArticleBean> getVideoArticle(
@Query("category") String category,
@Query("_") int max_behot_time);
@Query("_") int time);

/**
* 获取视频信息
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ public MediaChannelDao() {
this.db = DatabaseHelper.getDatabase();
}

public void initData() {
add("4377795668", "新华网", "http://p2.pstatp.com/large/3658/7378365093", "news",
"", "传播中国,报道世界;权威声音,亲切表达。", "http://toutiao.com/m4377795668/");
add("52445544609", "互联网的这点事", "http://p3.pstatp.com/large/ef300164e786ff295da", "news",
"", "每天为你速递最新、最鲜、最有料的互联网科技资讯!", "http://toutiao.com/m52445544609/");
}

public boolean add(String id,
String name,
String avatar,
Expand Down
37 changes: 22 additions & 15 deletions app/src/main/java/com/meiji/toutiao/module/base/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@
import android.annotation.TargetApi;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

import com.meiji.toutiao.InitApp;
import com.meiji.toutiao.R;

import okhttp3.Call;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;

/**
* Created by Meiji on 2016/12/12.
*/

public class BaseActivity extends AppCompatActivity {
public abstract class BaseActivity extends RxAppCompatActivity {

/**
* 初始化 Toolbar
*/
protected void initToolBar(Toolbar toolbar, boolean homeAsUpEnabled, String title) {
toolbar.setTitle(title);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(homeAsUpEnabled);
}

@TargetApi(Build.VERSION_CODES.M)
@Override
Expand All @@ -38,16 +45,16 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

@Override
protected void onDestroy() {
for (Call call : InitApp.getOkHttpClient().dispatcher().queuedCalls()) {
call.cancel();
}
for (Call call : InitApp.getOkHttpClient().dispatcher().runningCalls()) {
call.cancel();
}
super.onDestroy();
}
// @Override
// protected void onDestroy() {
// for (Call call : InitApp.getOkHttpClient().dispatcher().queuedCalls()) {
// call.cancel();
// }
// for (Call call : InitApp.getOkHttpClient().dispatcher().runningCalls()) {
// call.cancel();
// }
// super.onDestroy();
// }

@Override
public void onBackPressed() {
Expand Down
67 changes: 67 additions & 0 deletions app/src/main/java/com/meiji/toutiao/module/base/BaseFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.meiji.toutiao.module.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.trello.rxlifecycle2.LifecycleTransformer;
import com.trello.rxlifecycle2.components.support.RxFragment;

/**
* Created by Meiji on 2017/5/11.
*/

public abstract class BaseFragment<T extends IBasePresenter> extends RxFragment implements IBaseView<T> {

protected T presenter;

/**
* 绑定布局文件
*
* @return 布局文件ID
*/
protected abstract int attachLayoutId();

/**
* 初始化视图控件
*/
protected abstract void initViews(View view);

/**
* 初始化数据
*/
protected abstract void initData();

/**
* 初始化 Toolbar
*/
protected void initToolBar(Toolbar toolbar, boolean homeAsUpEnabled, String title) {
((BaseActivity) getActivity()).initToolBar(toolbar, homeAsUpEnabled, title);
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setPresenter(presenter);
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(attachLayoutId(), container, false);
initViews(view);
initData();
return view;
}

/**
* 绑定生命周期
*/
@Override
public <T> LifecycleTransformer<T> bindToLife() {
return this.bindToLifecycle();
}
}
14 changes: 13 additions & 1 deletion app/src/main/java/com/meiji/toutiao/module/base/IBaseView.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.meiji.toutiao.module.base;

import com.trello.rxlifecycle2.LifecycleTransformer;

/**
* Created by Meiji on 2017/5/7.
*/

public interface IBaseView {
public interface IBaseView<T> {

/**
* 显示加载动画
Expand All @@ -20,4 +22,14 @@ public interface IBaseView {
* 显示网络错误
*/
void onShowNetError();

/**
* 设置 presenter
*/
void setPresenter(T presenter);

/**
* 绑定生命周期
*/
<T> LifecycleTransformer<T> bindToLife();
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.meiji.toutiao.module.base;

import android.os.Bundle;
import android.support.v4.app.Fragment;

/**
* Created by Meiji on 2016/12/27.
*/

public abstract class LazyLoadFragment extends Fragment {
public abstract class LazyLoadFragment<T extends IBasePresenter> extends BaseFragment<T> {

protected boolean isViewInitiated;
protected boolean isVisibleToUser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public boolean handleMessage(Message msg) {
}
});

public static void startActivity(String url, String type) {
public static void launch(String url, String type) {
InitApp.AppContext.startActivity(new Intent(InitApp.AppContext, MediaAddActivity.class).
putExtra(URLEXTRA, url)
.putExtra(TYPEEXTRA, type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public interface IMediaArticle {

interface View extends IBaseView {
interface View extends IBaseView<Presenter> {

/**
* 请求数据
Expand Down Expand Up @@ -56,21 +56,6 @@ interface Presenter extends IBasePresenter {
/**
* 点击事件跳转
*/
void doOnClickItem(MediaArticleBean.DataBean bean, MediaChannelBean mediaChannelBean);
}

@Deprecated
interface Model {
long getItemId();

long getGroupId();

boolean requestData(String url);

List<MediaArticleBean.DataBean> getDataList();

int getMaxBehotTime();

void getCommentRequestData(String articleUrl);
void doOnClickItem(int position, MediaChannelBean mediaChannelBean);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class MediaArticleActivity extends BaseActivity {

public static void startActivity(MediaChannelBean bean) {
InitApp.AppContext.startActivity(new Intent(InitApp.AppContext, MediaArticleActivity.class)
.putExtra(MediaArticleActivity.TAG, bean)
.putExtra(TAG, bean)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}

Expand Down
Loading

0 comments on commit 7590383

Please sign in to comment.