Skip to content

Commit

Permalink
update RxDemo.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamsiree committed Mar 12, 2020
1 parent 6d3d0ba commit 0963630
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.GridLayoutManager;
Expand Down Expand Up @@ -71,10 +72,12 @@
public class FragmentDemo extends FragmentLazy implements SwipeRefreshLayout.OnRefreshListener {

List<ModelDemo> mDemoList = new ArrayList<>();
@BindView(R.id.recyclerview)
@BindView(R.id.recyclerViewDemo)
RecyclerView mRecyclerview;
@BindView(R.id.swipeLayout)
@BindView(R.id.swipeLayoutDemo)
SwipeRefreshLayout mSwipeLayout;
@BindView(R.id.tvHint)
TextView mTvHint;

private AdapterRecyclerViewMain mAdapter;

Expand Down Expand Up @@ -108,6 +111,7 @@ protected void initData() {

private void init() {
initRecyclerView();
mTvHint.setVisibility(View.VISIBLE);
}

private void initRecyclerView() {
Expand Down
8 changes: 5 additions & 3 deletions RxDemo/src/main/res/layout/fragment_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:orientation="vertical">

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeLayout"
android:id="@+id/swipeLayoutDemo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
Expand All @@ -24,14 +24,15 @@
android:orientation="vertical">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview"
android:id="@+id/recyclerViewDemo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_10"
android:layout_marginRight="@dimen/dp_10"
android:padding="@dimen/dp_10" />

<TextView
android:id="@+id/tvHint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/dp_20"
Expand All @@ -40,7 +41,8 @@
android:padding="@dimen/dp_20"
android:text="仅列出了部分 [工具类] 和 [UI效果] 的Demo展示效果,因为有些功能或者效果无法单独展示,需要特定的生产环境或者需要依赖其他条件才能完全展示,因此可以自己查阅源码,说不定能找到惊喜"
android:textColor="@color/wheat"
android:textSize="@dimen/sp_10" />
android:textSize="@dimen/sp_10"
android:visibility="gone" />

</LinearLayout>

Expand Down
13 changes: 10 additions & 3 deletions RxUI/src/main/java/com/tamsiree/rxui/fragment/FragmentLazy.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

Expand Down Expand Up @@ -42,8 +43,10 @@ public abstract class FragmentLazy extends Fragment {

public FragmentActivity mContext;

private View rootView;

@Override
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle savedInstanceState) {
// 若 viewpager 不设置 setOffscreenPageLimit 或设置数量不够
// 销毁的Fragment onCreateView 每次都会执行(但实体类没有从内存销毁)
// 导致initData反复执行,所以这里注释掉
Expand All @@ -55,10 +58,10 @@ public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bun
mContext = getActivity();

isFirstLoad = true;
View view = initViews(layoutInflater, viewGroup, savedInstanceState);
rootView = initViews(layoutInflater, viewGroup, savedInstanceState);
isPrepared = true;
lazyLoad();
return view;
return rootView;
}

/**
Expand Down Expand Up @@ -120,4 +123,8 @@ protected void lazyLoad() {

protected abstract void initData();


public View getRootView() {
return rootView;
}
}

0 comments on commit 0963630

Please sign in to comment.