Skip to content

Commit

Permalink
update loading UI
Browse files Browse the repository at this point in the history
  • Loading branch information
iMeiji committed Aug 10, 2017
1 parent b1312ef commit b0961c2
Show file tree
Hide file tree
Showing 19 changed files with 417 additions and 291 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
android:name=".module.photo.content.PhotoContentActivity"
android:configChanges="orientation|screenSize|uiMode"
android:label="@string/title_photo_content"
android:theme="@style/AppTheme.NoActionBar"/>
android:theme="@style/AppTheme.NoActionBar.Slidable"/>

<activity
android:name=".module.news.channel.NewsChannelActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.meiji.toutiao.ErrorAction;
Expand Down Expand Up @@ -36,10 +38,14 @@ protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull final Wenda
String tv_answer_count = item.getNormal_ans_count() + item.getNice_ans_count() + " 回答";
String tv_follow_count = item.getFollow_count() + " 关注";
holder.tv_title.setText(tv_title);
holder.tv_abstract.setText(tv_abstract);
if (!TextUtils.isEmpty(tv_abstract)) {
holder.tv_abstract.setText(tv_abstract);
} else {
holder.tv_abstract.setVisibility(View.GONE);
}
holder.tv_answer_count.setText(tv_answer_count);
holder.tv_follow_count.setText(tv_follow_count);
holder.itemView.setBackgroundColor(SettingUtil.getInstance().getColor());
holder.title_view.setBackgroundColor(SettingUtil.getInstance().getColor());
} catch (Exception e) {
ErrorAction.print(e);
}
Expand All @@ -51,13 +57,15 @@ public class ViewHolder extends RecyclerView.ViewHolder {
private TextView tv_abstract;
private TextView tv_answer_count;
private TextView tv_follow_count;
private LinearLayout title_view;

public ViewHolder(View itemView) {
super(itemView);
this.tv_title = itemView.findViewById(R.id.tv_title);
this.tv_abstract = itemView.findViewById(R.id.tv_abstract);
this.tv_answer_count = itemView.findViewById(R.id.tv_answer_count);
this.tv_follow_count = itemView.findViewById(R.id.tv_follow_count);
this.title_view = itemView.findViewById(R.id.title_view);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@

import android.content.Intent;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.ContentLoadingProgressBar;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.ProgressBar;

import com.meiji.toutiao.ErrorAction;
import com.meiji.toutiao.InitApp;
Expand Down Expand Up @@ -48,7 +44,7 @@ public class MediaHomeActivity extends BaseActivity {
private Toolbar toolbar;
private TabLayout tabLayout;
private ViewPager viewPager;
private ProgressBar progressBar;
private ContentLoadingProgressBar progressBar;

public static void launch(String MediaId) {
InitApp.AppContext.startActivity(new Intent(InitApp.AppContext, MediaHomeActivity.class)
Expand All @@ -67,22 +63,18 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
private void initView() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setBackgroundColor(SettingUtil.getInstance().getColor());

tabLayout = (TabLayout) findViewById(R.id.tab_layout);
viewPager = (ViewPager) findViewById(R.id.view_pager);
tabLayout.setBackgroundColor(SettingUtil.getInstance().getColor());
tabLayout.setupWithViewPager(viewPager);
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);

progressBar = (ProgressBar) findViewById(R.id.pb_progress);
progressBar = (ContentLoadingProgressBar) findViewById(R.id.pb_progress);
int color = SettingUtil.getInstance().getColor();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Drawable wrapDrawable = DrawableCompat.wrap(progressBar.getIndeterminateDrawable());
DrawableCompat.setTint(wrapDrawable, color);
this.progressBar.setIndeterminateDrawable(DrawableCompat.unwrap(wrapDrawable));
} else {
this.progressBar.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
progressBar.setVisibility(View.VISIBLE);
progressBar.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
progressBar.show();

viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Expand Down Expand Up @@ -164,11 +156,11 @@ private void initTabLayout(MediaProfileBean.DataBean dataBean) {
BasePagerAdapter pagerAdapter = new BasePagerAdapter(getSupportFragmentManager(), fragmentList, titleList);
viewPager.setAdapter(pagerAdapter);
viewPager.setOffscreenPageLimit(topTab.size());
progressBar.setVisibility(View.GONE);
progressBar.hide();
}

private void onError() {
progressBar.setVisibility(View.GONE);
progressBar.hide();
Snackbar.make(progressBar, getString(R.string.error), Snackbar.LENGTH_INDEFINITE).show();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.meiji.toutiao.module.news.content;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;

import com.meiji.toutiao.bean.news.MultiNewsArticleDataBean;
import com.meiji.toutiao.module.base.IBasePresenter;
import com.meiji.toutiao.module.base.IBaseView;
Expand All @@ -27,10 +24,5 @@ interface Presenter extends IBasePresenter {
* 请求数据
*/
void doLoadData(MultiNewsArticleDataBean dataBean);

/**
* 查看评论
*/
void doShowComment(FragmentActivity context, Fragment fragment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.Snackbar;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v4.widget.ContentLoadingProgressBar;
import android.support.v4.widget.NestedScrollView;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
Expand All @@ -27,14 +26,14 @@
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.ProgressBar;

import com.meiji.toutiao.ErrorAction;
import com.meiji.toutiao.IntentAction;
import com.meiji.toutiao.R;
import com.meiji.toutiao.bean.news.MultiNewsArticleDataBean;
import com.meiji.toutiao.module.base.BaseFragment;
import com.meiji.toutiao.module.media.home.MediaHomeActivity;
import com.meiji.toutiao.module.news.comment.NewsCommentActivity;
import com.meiji.toutiao.util.ImageLoader;
import com.meiji.toutiao.util.SettingUtil;
import com.meiji.toutiao.widget.helper.AppBarStateChangeListener;
Expand All @@ -55,15 +54,17 @@ public class NewsContentFragment extends BaseFragment<INewsContent.Presenter> im
private String mediaName;
private String imgUrl;
private boolean isHasImage;
private MultiNewsArticleDataBean bean;

private Toolbar toolbar;
private WebView webView;
private NestedScrollView scrollView;
private INewsContent.Presenter presenter;
private ProgressBar progressBar;
private ContentLoadingProgressBar progressBar;
private AppBarLayout appBarLayout;
private CollapsingToolbarLayout collapsingToolbarLayout;
private ImageView imageView;
private SwipeRefreshLayout swipeRefreshLayout;

public static NewsContentFragment newInstance(Parcelable dataBean, String imgUrl) {
NewsContentFragment instance = new NewsContentFragment();
Expand All @@ -85,8 +86,8 @@ protected int attachLayoutId() {
protected void initData() {
Bundle bundle = getArguments();
try {
MultiNewsArticleDataBean bean = bundle.getParcelable(TAG);
Log.d(TAG, "initData: " + bean.toString());
bean = bundle.getParcelable(TAG);
// Log.d(TAG, "initData: " + bean.toString());
presenter.doLoadData(bean);
shareUrl = bean.getShare_url();
shareTitle = bean.getTitle();
Expand Down Expand Up @@ -140,38 +141,50 @@ public void onPause() {
protected void initView(View view) {
toolbar = view.findViewById(R.id.toolbar);
initToolBar(toolbar, true, "");
toolbar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
scrollView.smoothScrollTo(0, 0);
}
});

webView = view.findViewById(R.id.webview_content);
initWebClient();

scrollView = view.findViewById(R.id.scrollView);
scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
progressBar.setVisibility(View.GONE);
onHideLoading();
}
});
toolbar.setOnClickListener(new View.OnClickListener() {

progressBar = view.findViewById(R.id.pb_progress);
int color = SettingUtil.getInstance().getColor();
progressBar.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
progressBar.show();

swipeRefreshLayout = view.findViewById(R.id.refresh_layout);
swipeRefreshLayout.setColorSchemeColors(SettingUtil.getInstance().getColor());
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onClick(View view) {
scrollView.smoothScrollTo(0, 0);
public void onRefresh() {
swipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
swipeRefreshLayout.setRefreshing(true);
}
});
presenter.doLoadData(bean);
}
});
progressBar = view.findViewById(R.id.pb_progress);
int color = SettingUtil.getInstance().getColor();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Drawable wrapDrawable = DrawableCompat.wrap(progressBar.getIndeterminateDrawable());
DrawableCompat.setTint(wrapDrawable, color);
this.progressBar.setIndeterminateDrawable(DrawableCompat.unwrap(wrapDrawable));
} else {
this.progressBar.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
progressBar.setVisibility(View.VISIBLE);
setHasOptionsMenu(true);
initWebClient();

if (isHasImage) {
appBarLayout = view.findViewById(R.id.app_bar_layout);
collapsingToolbarLayout = view.findViewById(R.id.collapsing_toolbar);
imageView = view.findViewById(R.id.iv_image);
}
setHasOptionsMenu(true);
}

@SuppressLint("SetJavaScriptEnabled")
Expand Down Expand Up @@ -239,12 +252,18 @@ public void setPresenter(INewsContent.Presenter presenter) {

@Override
public void onShowLoading() {
progressBar.setVisibility(View.VISIBLE);
progressBar.show();
}

@Override
public void onHideLoading() {
progressBar.setVisibility(View.GONE);
progressBar.hide();
swipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
swipeRefreshLayout.setRefreshing(false);
}
});
}

@Override
Expand All @@ -258,7 +277,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.action_open_comment:
presenter.doShowComment(getActivity(), this);
NewsCommentActivity.launch(bean.getGroup_id() + "", bean.getItem_id() + "");
break;

case R.id.action_share:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.meiji.toutiao.module.news.content;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;

import com.meiji.toutiao.ErrorAction;
import com.meiji.toutiao.RetrofitFactory;
import com.meiji.toutiao.api.INewsApi;
import com.meiji.toutiao.bean.news.MultiNewsArticleDataBean;
import com.meiji.toutiao.bean.news.NewsContentBean;
import com.meiji.toutiao.module.news.comment.NewsCommentActivity;
import com.meiji.toutiao.util.SettingUtil;

import io.reactivex.Observable;
Expand Down Expand Up @@ -89,7 +86,7 @@ public String apply(@NonNull NewsContentBean bean) throws Exception {
.subscribe(new Observer<String>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
view.onShowLoading();

}

@Override
Expand Down Expand Up @@ -143,11 +140,6 @@ private String getHTML(NewsContentBean bean) {
}
}

@Override
public void doShowComment(FragmentActivity context, Fragment fragment) {
NewsCommentActivity.launch(groupId, itemId);
}

@Override
public void doRefresh() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.meiji.toutiao.R;
import com.meiji.toutiao.bean.photo.PhotoArticleBean;
import com.meiji.toutiao.module.base.BaseActivity;
import com.r0adkll.slidr.model.SlidrInterface;

/**
* Created by Meiji on 2017/3/1.
Expand All @@ -32,11 +33,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
.commit();
}

/**
* 禁用滑动返回
*/
@Override
protected void initSlidable() {

public SlidrInterface getSlidrInterface() {
return slidrInterface;
}
}
Loading

0 comments on commit b0961c2

Please sign in to comment.