From b0961c2a255fd9006dc7a947b062f52cb49fd4a2 Mon Sep 17 00:00:00 2001 From: iMeiji <361183736@qq.com> Date: Fri, 11 Aug 2017 02:11:04 +0800 Subject: [PATCH] update loading UI --- app/src/main/AndroidManifest.xml | 2 +- .../wenda/WendaContentHeaderViewBinder.java | 12 +- .../module/media/home/MediaHomeActivity.java | 26 ++-- .../module/news/content/INewsContent.java | 8 -- .../news/content/NewsContentFragment.java | 71 ++++++---- .../news/content/NewsContentPresenter.java | 10 +- .../photo/content/PhotoContentActivity.java | 9 +- .../photo/content/PhotoContentFragment.java | 95 +++++++++---- .../photo/content/PhotoContentPresenter.java | 4 +- .../video/content/VideoContentActivity.java | 50 ++++--- .../wenda/detail/WendaDetailFragment.java | 92 +++++++------ .../main/res/layout/activity_media_home.xml | 3 +- .../main/res/layout/fragment_news_content.xml | 28 ++-- .../res/layout/fragment_news_content_img.xml | 32 +++-- .../res/layout/fragment_photo_content.xml | 29 ++-- .../res/layout/fragment_video_content_new.xml | 15 ++- .../main/res/layout/fragment_wenda_detail.xml | 126 ++++++++++-------- .../main/res/layout/item_media_channel.xml | 6 +- .../res/layout/item_wenda_content_header.xml | 90 ++++++++----- 19 files changed, 417 insertions(+), 291 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index fdde1f3..83b6d69 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -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"/> 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(); @@ -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(); @@ -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") @@ -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 @@ -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: diff --git a/app/src/main/java/com/meiji/toutiao/module/news/content/NewsContentPresenter.java b/app/src/main/java/com/meiji/toutiao/module/news/content/NewsContentPresenter.java index 5fdee14..1af9ea8 100644 --- a/app/src/main/java/com/meiji/toutiao/module/news/content/NewsContentPresenter.java +++ b/app/src/main/java/com/meiji/toutiao/module/news/content/NewsContentPresenter.java @@ -1,7 +1,5 @@ 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; @@ -9,7 +7,6 @@ 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; @@ -89,7 +86,7 @@ public String apply(@NonNull NewsContentBean bean) throws Exception { .subscribe(new Observer() { @Override public void onSubscribe(@NonNull Disposable d) { - view.onShowLoading(); + } @Override @@ -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() { diff --git a/app/src/main/java/com/meiji/toutiao/module/photo/content/PhotoContentActivity.java b/app/src/main/java/com/meiji/toutiao/module/photo/content/PhotoContentActivity.java index 41290d4..78e36bd 100644 --- a/app/src/main/java/com/meiji/toutiao/module/photo/content/PhotoContentActivity.java +++ b/app/src/main/java/com/meiji/toutiao/module/photo/content/PhotoContentActivity.java @@ -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. @@ -32,11 +33,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { .commit(); } - /** - * 禁用滑动返回 - */ - @Override - protected void initSlidable() { - + public SlidrInterface getSlidrInterface() { + return slidrInterface; } } diff --git a/app/src/main/java/com/meiji/toutiao/module/photo/content/PhotoContentFragment.java b/app/src/main/java/com/meiji/toutiao/module/photo/content/PhotoContentFragment.java index 3759e86..ad76964 100644 --- a/app/src/main/java/com/meiji/toutiao/module/photo/content/PhotoContentFragment.java +++ b/app/src/main/java/com/meiji/toutiao/module/photo/content/PhotoContentFragment.java @@ -5,16 +5,15 @@ import android.content.DialogInterface; import android.content.Intent; 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.annotation.NonNull; import android.support.design.widget.Snackbar; -import android.support.v4.graphics.drawable.DrawableCompat; import android.support.v4.view.ViewPager; +import android.support.v4.widget.ContentLoadingProgressBar; import android.support.v4.widget.NestedScrollView; +import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; @@ -26,10 +25,10 @@ import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; -import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.TextView; +import com.meiji.toutiao.ErrorAction; import com.meiji.toutiao.IntentAction; import com.meiji.toutiao.R; import com.meiji.toutiao.adapter.photo.PhotoContentAdapter; @@ -39,6 +38,7 @@ import com.meiji.toutiao.module.news.comment.NewsCommentActivity; import com.meiji.toutiao.util.SettingUtil; import com.meiji.toutiao.widget.ViewPagerFixed; +import com.r0adkll.slidr.model.SlidrInterface; import permissions.dispatcher.NeedsPermission; import permissions.dispatcher.OnNeverAskAgain; @@ -60,7 +60,7 @@ public class PhotoContentFragment extends BaseFragment private RelativeLayout photoView; private WebView webView; private NestedScrollView scrollView; - private ProgressBar progressBar; + private ContentLoadingProgressBar progressBar; private String shareUrl; private String shareTitle; private String groupId; @@ -68,6 +68,7 @@ public class PhotoContentFragment extends BaseFragment private PhotoContentAdapter adapter; private String mediaUrl; private String mediaId; + private SwipeRefreshLayout swipeRefreshLayout; public static PhotoContentFragment newInstance(Parcelable dataBean) { PhotoContentFragment instance = new PhotoContentFragment(); @@ -85,16 +86,20 @@ protected int attachLayoutId() { @Override protected void initData() { Bundle bundle = getArguments(); - PhotoArticleBean.DataBean dataBean = bundle.getParcelable(TAG); - shareUrl = dataBean.getSource_url(); - shareTitle = dataBean.getTitle(); - ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(shareTitle); - groupId = dataBean.getGroup_id() + ""; - itemId = dataBean.getGroup_id() + ""; - mediaUrl = dataBean.getMedia_url(); - presenter.doLoadData(shareUrl); - if (!shareUrl.contains("toutiao")) { - shareUrl = "http://toutiao.com" + shareUrl; + try { + PhotoArticleBean.DataBean dataBean = bundle.getParcelable(TAG); + shareUrl = dataBean.getSource_url(); + shareTitle = dataBean.getTitle(); + ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(shareTitle); + groupId = dataBean.getGroup_id() + ""; + itemId = dataBean.getGroup_id() + ""; + mediaUrl = dataBean.getMedia_url(); + presenter.doLoadData(shareUrl); + if (!shareUrl.contains("toutiao")) { + shareUrl = "http://toutiao.com" + shareUrl; + } + } catch (Exception e) { + ErrorAction.print(e); } } @@ -102,28 +107,42 @@ protected void initData() { protected void initView(View view) { Toolbar toolbar = view.findViewById(R.id.toolbar); initToolBar(toolbar, true, ""); + toolbar.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + scrollView.smoothScrollTo(0, 0); + } + }); + tv_hint = view.findViewById(R.id.tv_hint); tv_save = view.findViewById(R.id.tv_save); tv_save.setOnClickListener(this); + viewPager = view.findViewById(R.id.viewPager); photoView = view.findViewById(R.id.photoView); webView = view.findViewById(R.id.webview_content); scrollView = view.findViewById(R.id.scrollView); + 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); - } - toolbar.setOnClickListener(new View.OnClickListener() { + 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 v) { - scrollView.smoothScrollTo(0, 0); + public void onRefresh() { + swipeRefreshLayout.post(new Runnable() { + @Override + public void run() { + swipeRefreshLayout.setRefreshing(true); + } + }); + presenter.doLoadData(shareUrl); } }); + setHasOptionsMenu(true); } @@ -142,7 +161,7 @@ public void onSetImageBrowser(PhotoGalleryBean bean, int position) { public void onSetWebView(String url, boolean flag) { initWebClient(); photoView.setVisibility(View.GONE); - scrollView.setVisibility(View.VISIBLE); + swipeRefreshLayout.setVisibility(View.VISIBLE); // 是否为头条的网站 if (flag) { @@ -150,16 +169,27 @@ public void onSetWebView(String url, boolean flag) { } else { webView.loadUrl(shareUrl); } + + SlidrInterface slidrInterface = ((PhotoContentActivity) getActivity()).getSlidrInterface(); + if (slidrInterface != null) { + slidrInterface.unlock(); + } } @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 @@ -183,6 +213,15 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse public void onPageSelected(int position) { presenter.doSetPosition(position); tv_hint.setText(position + 1 + "/" + presenter.doGetImageCount()); + + SlidrInterface slidrInterface = ((PhotoContentActivity) getActivity()).getSlidrInterface(); + if (slidrInterface != null) { + if (position == 0) { + slidrInterface.unlock(); + } else { + slidrInterface.lock(); + } + } } @Override diff --git a/app/src/main/java/com/meiji/toutiao/module/photo/content/PhotoContentPresenter.java b/app/src/main/java/com/meiji/toutiao/module/photo/content/PhotoContentPresenter.java index 52d7c19..1df6ce1 100644 --- a/app/src/main/java/com/meiji/toutiao/module/photo/content/PhotoContentPresenter.java +++ b/app/src/main/java/com/meiji/toutiao/module/photo/content/PhotoContentPresenter.java @@ -116,7 +116,7 @@ public Boolean apply(@NonNull String s) throws Exception { .subscribe(new Observer() { @Override public void onSubscribe(@NonNull Disposable d) { - view.onShowLoading(); + } @Override @@ -189,7 +189,7 @@ public String apply(@NonNull NewsContentBean bean) throws Exception { .subscribe(new Observer() { @Override public void onSubscribe(@NonNull Disposable d) { - view.onShowLoading(); + } @Override diff --git a/app/src/main/java/com/meiji/toutiao/module/video/content/VideoContentActivity.java b/app/src/main/java/com/meiji/toutiao/module/video/content/VideoContentActivity.java index 747f8d9..9b8d9a9 100644 --- a/app/src/main/java/com/meiji/toutiao/module/video/content/VideoContentActivity.java +++ b/app/src/main/java/com/meiji/toutiao/module/video/content/VideoContentActivity.java @@ -4,20 +4,19 @@ import android.content.pm.ActivityInfo; import android.content.res.ColorStateList; 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.FloatingActionButton; import android.support.design.widget.Snackbar; -import android.support.v4.graphics.drawable.DrawableCompat; +import android.support.v4.widget.ContentLoadingProgressBar; +import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.text.TextUtils; import android.view.MotionEvent; import android.view.View; import android.view.WindowManager; -import android.widget.ProgressBar; import com.meiji.toutiao.ErrorAction; import com.meiji.toutiao.InitApp; @@ -64,11 +63,12 @@ public class VideoContentActivity extends BaseActivity implements IVideoContent. private Items oldItems = new Items(); private RecyclerView recyclerView; - private ProgressBar progressBar; + private ContentLoadingProgressBar progressBar; private FloatingActionButton fab; private MyJCVideoPlayerStandard jcVideo; private IVideoContent.Presenter presenter; private int currentAction; + private SwipeRefreshLayout swipeRefreshLayout; public static void launch(MultiNewsArticleDataBean bean) { InitApp.AppContext.startActivity(new Intent(InitApp.AppContext, VideoContentActivity.class) @@ -131,8 +131,6 @@ public void onLoadMore() { } }); - jcVideo = (MyJCVideoPlayerStandard) findViewById(R.id.jc_video); - MyJCVideoPlayerStandard.setOnClickFullScreenListener(new MyJCVideoPlayerStandard.onClickFullScreenListener() { @Override public void onClickFullScreen() { @@ -142,25 +140,36 @@ public void onClickFullScreen() { } }); - 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.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.MULTIPLY); + progressBar.show(); + + swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh_layout); + swipeRefreshLayout.setColorSchemeColors(SettingUtil.getInstance().getColor()); + swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + swipeRefreshLayout.post(new Runnable() { + @Override + public void run() { + swipeRefreshLayout.setRefreshing(true); + } + }); + onLoadData(); + } + }); fab = (FloatingActionButton) findViewById(R.id.fab); fab.setBackgroundTintList(ColorStateList.valueOf(SettingUtil.getInstance().getColor())); - fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { IntentAction.send(VideoContentActivity.this, videoTitle + "\n" + shareUrl); } }); + + jcVideo = (MyJCVideoPlayerStandard) findViewById(R.id.jc_video); jcVideo.thumbImageView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { @@ -172,7 +181,6 @@ public boolean onTouch(View view, MotionEvent motionEvent) { @Override public void onLoadData() { - onShowLoading(); presenter.doLoadData(groupId, itemId); presenter.doLoadVideoData(videoId); } @@ -191,12 +199,18 @@ public void onSetAdapter(final List list) { @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 diff --git a/app/src/main/java/com/meiji/toutiao/module/wenda/detail/WendaDetailFragment.java b/app/src/main/java/com/meiji/toutiao/module/wenda/detail/WendaDetailFragment.java index c53930c..1ba47ad 100644 --- a/app/src/main/java/com/meiji/toutiao/module/wenda/detail/WendaDetailFragment.java +++ b/app/src/main/java/com/meiji/toutiao/module/wenda/detail/WendaDetailFragment.java @@ -2,14 +2,12 @@ import android.annotation.SuppressLint; import android.graphics.PorterDuff; -import android.graphics.drawable.Drawable; -import android.os.Build; import android.os.Bundle; import android.os.Parcelable; 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.v7.widget.LinearLayoutManager; +import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.KeyEvent; @@ -22,7 +20,6 @@ import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.LinearLayout; -import android.widget.ProgressBar; import android.widget.TextView; import com.meiji.toutiao.IntentAction; @@ -57,15 +54,17 @@ public class WendaDetailFragment extends BaseFragment im private WebView webView; private NestedScrollView scrollView; - private ProgressBar progressBar; + private ContentLoadingProgressBar progressBar; private TextView tv_title; private CircleImageView iv_user_avatar; private TextView tv_user_name; private RecyclerView recyclerView; + private LinearLayout header_layout; + private SwipeRefreshLayout swipeRefreshLayout; + private MultiTypeAdapter adapter; private boolean canLoadMore; private Items oldItems = new Items(); - private LinearLayout header_layout; public static WendaDetailFragment newInstance(Parcelable bean) { Bundle args = new Bundle(); @@ -77,19 +76,18 @@ public static WendaDetailFragment newInstance(Parcelable bean) { @Override protected void initData() { - this.bean = getArguments().getParcelable(TAG); + bean = getArguments().getParcelable(TAG); if (null == this.bean) { onShowNetError(); return; } - this.url = bean.getShare_data().getShare_url(); - - ImageLoader.loadCenterCrop(getActivity(), bean.getUser().getAvatar_url(), iv_user_avatar, R.color.viewBackground); - this.tv_title.setText(bean.getTitle()); - this.tv_user_name.setText(bean.getUser().getUname()); - this.shareTitle = bean.getShare_data().getTitle(); + url = bean.getShare_data().getShare_url(); onLoadData(); + ImageLoader.loadCenterCrop(getActivity(), bean.getUser().getAvatar_url(), iv_user_avatar, R.color.viewBackground); + tv_title.setText(bean.getTitle()); + tv_user_name.setText(bean.getUser().getUname()); + shareTitle = bean.getShare_data().getTitle(); header_layout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -129,15 +127,6 @@ protected int attachLayoutId() { @Override protected void initView(View view) { Toolbar toolbar = view.findViewById(R.id.toolbar); - webView = view.findViewById(R.id.webview_content); - scrollView = view.findViewById(R.id.scrollView); - progressBar = view.findViewById(R.id.pb_progress); - header_layout = view.findViewById(R.id.header_layout); - tv_title = view.findViewById(R.id.tv_title); - iv_user_avatar = view.findViewById(R.id.iv_user_avatar); - tv_user_name = view.findViewById(R.id.tv_user_name); - recyclerView = view.findViewById(R.id.recycler_view); - initToolBar(toolbar, true, getString(R.string.title_wenda_detail)); toolbar.setOnClickListener(new View.OnClickListener() { @Override @@ -146,23 +135,28 @@ public void onClick(View view) { } }); + webView = view.findViewById(R.id.webview_content); + initWebClient(); + + header_layout = view.findViewById(R.id.header_layout); header_layout.setBackgroundColor(SettingUtil.getInstance().getColor()); + tv_title = view.findViewById(R.id.tv_title); + iv_user_avatar = view.findViewById(R.id.iv_user_avatar); + tv_user_name = view.findViewById(R.id.tv_user_name); + + 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(); } }); - scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { @Override public void onScrollChanged() { View view = scrollView.getChildAt(scrollView.getChildCount() - 1); - - int diff = (view.getBottom() - (scrollView.getHeight() + scrollView - .getScrollY())); - + int diff = (view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY())); if (diff == 0) { canLoadMore = false; presenter.doLoadMoreComment(); @@ -170,27 +164,35 @@ public void onScrollChanged() { } }); + swipeRefreshLayout = view.findViewById(R.id.refresh_layout); + swipeRefreshLayout.setColorSchemeColors(SettingUtil.getInstance().getColor()); + swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + swipeRefreshLayout.post(new Runnable() { + @Override + public void run() { + swipeRefreshLayout.setRefreshing(true); + } + }); + presenter.doLoadData(url); + } + }); + + 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); + progressBar.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.MULTIPLY); + progressBar.show(); + recyclerView = view.findViewById(R.id.recycler_view); recyclerView.setHasFixedSize(true); - recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); // 禁止嵌套滚动 recyclerView.setNestedScrollingEnabled(false); - adapter = new MultiTypeAdapter(oldItems); Register.registerNewsCommentItem(adapter); recyclerView.setAdapter(adapter); setHasOptionsMenu(true); - initWebClient(); } @Override @@ -282,12 +284,18 @@ public void run() { @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 diff --git a/app/src/main/res/layout/activity_media_home.xml b/app/src/main/res/layout/activity_media_home.xml index 7ddd38e..49b6860 100644 --- a/app/src/main/res/layout/activity_media_home.xml +++ b/app/src/main/res/layout/activity_media_home.xml @@ -33,8 +33,9 @@ tools:layout="@layout/fragment_list"> - diff --git a/app/src/main/res/layout/fragment_news_content.xml b/app/src/main/res/layout/fragment_news_content.xml index 98e25c9..b708983 100644 --- a/app/src/main/res/layout/fragment_news_content.xml +++ b/app/src/main/res/layout/fragment_news_content.xml @@ -18,25 +18,29 @@ android:scrollbars="vertical" app:layout_behavior="@string/appbar_scrolling_view_behavior"> - - + android:layout_height="match_parent"> - + - + + + + diff --git a/app/src/main/res/layout/fragment_news_content_img.xml b/app/src/main/res/layout/fragment_news_content_img.xml index 0bd00d3..cd37aa3 100644 --- a/app/src/main/res/layout/fragment_news_content_img.xml +++ b/app/src/main/res/layout/fragment_news_content_img.xml @@ -55,25 +55,33 @@ android:scrollbars="vertical" app:layout_behavior="@string/appbar_scrolling_view_behavior"> - - + android:layout_height="match_parent"> + + + + - + - diff --git a/app/src/main/res/layout/fragment_photo_content.xml b/app/src/main/res/layout/fragment_photo_content.xml index a258405..7743f8f 100644 --- a/app/src/main/res/layout/fragment_photo_content.xml +++ b/app/src/main/res/layout/fragment_photo_content.xml @@ -45,30 +45,39 @@ android:layout_marginBottom="48dp" android:layout_marginTop="?attr/actionBarSize"/> - - - + android:fadeScrollbars="true" + android:scrollbarFadeDuration="1" + android:scrollbars="vertical" + app:layout_behavior="@string/appbar_scrolling_view_behavior"> - + + + + + diff --git a/app/src/main/res/layout/fragment_video_content_new.xml b/app/src/main/res/layout/fragment_video_content_new.xml index 2757cea..ea31760 100644 --- a/app/src/main/res/layout/fragment_video_content_new.xml +++ b/app/src/main/res/layout/fragment_video_content_new.xml @@ -13,14 +13,21 @@ android:layout_height="220dp" android:fitsSystemWindows="true"/> - + android:layout_marginTop="196dp"> - + + + diff --git a/app/src/main/res/layout/fragment_wenda_detail.xml b/app/src/main/res/layout/fragment_wenda_detail.xml index 2e9ad36..6fa1145 100644 --- a/app/src/main/res/layout/fragment_wenda_detail.xml +++ b/app/src/main/res/layout/fragment_wenda_detail.xml @@ -18,86 +18,96 @@ android:scrollbars="vertical" app:layout_behavior="@string/appbar_scrolling_view_behavior"> - - + android:layout_height="match_parent"> - - - - - - - - + android:layout_height="wrap_content" + android:background="?attr/selectableItemBackground" + android:foreground="?attr/selectableItemBackground" + android:orientation="vertical"> + android:maxLines="2" + android:padding="16dp" + android:text="都说床头不能朝西,有什么说法吗?" + android:textAppearance="@style/TextAppearance.AppCompat.Title" + android:textColor="@color/White"/> + - + + + + + + + + + + + + - + + - - + - + - diff --git a/app/src/main/res/layout/item_media_channel.xml b/app/src/main/res/layout/item_media_channel.xml index 2a88803..166fccb 100644 --- a/app/src/main/res/layout/item_media_channel.xml +++ b/app/src/main/res/layout/item_media_channel.xml @@ -3,7 +3,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" - android:layout_height="72dp" + android:layout_height="wrap_content" android:layout_marginBottom="4dp" android:layout_marginTop="4dp" android:background="@color/viewBackground" @@ -29,6 +29,7 @@ android:layout_height="match_parent" android:layout_marginLeft="8dp" android:layout_marginStart="8dp" + android:gravity="center_vertical" android:orientation="vertical"> diff --git a/app/src/main/res/layout/item_wenda_content_header.xml b/app/src/main/res/layout/item_wenda_content_header.xml index 3351b5b..8efb246 100644 --- a/app/src/main/res/layout/item_wenda_content_header.xml +++ b/app/src/main/res/layout/item_wenda_content_header.xml @@ -1,51 +1,75 @@ + android:orientation="vertical"> - + android:paddingBottom="8dp" + android:paddingLeft="16dp" + android:paddingRight="16dp" + android:paddingTop="0dp"> - + + - + android:layout_marginBottom="1dp" + android:background="@color/viewBackground" + app:cardElevation="1dp"> - + android:orientation="vertical" + android:paddingBottom="8dp" + android:paddingLeft="16dp" + android:paddingRight="16dp" + android:paddingTop="8dp"> - + - + + + + + + + + +