-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to AndroidX, flex box demo: #26 [ci skip]
- Loading branch information
Showing
32 changed files
with
344 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
app/src/main/java/com/github/nukc/sample/AnotherActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
app/src/main/java/com/github/nukc/sample/FlexboxActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package com.github.nukc.sample; | ||
|
||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import com.github.nukc.LoadMoreWrapper.LoadMoreWrapper; | ||
import com.google.android.flexbox.FlexDirection; | ||
import com.google.android.flexbox.FlexboxLayoutManager; | ||
import com.google.android.flexbox.JustifyContent; | ||
|
||
public class FlexboxActivity extends AppCompatActivity { | ||
|
||
private boolean mShowLoadFailedEnabled = true; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_flexbox); | ||
|
||
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view); | ||
FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(this); | ||
layoutManager.setFlexDirection(FlexDirection.ROW); | ||
layoutManager.setJustifyContent(JustifyContent.FLEX_END); | ||
recyclerView.setLayoutManager(layoutManager); | ||
|
||
FlexAdapter flexAdapter = new FlexAdapter(20); | ||
// recyclerView.setAdapter(flexAdapter); | ||
LoadMoreWrapper.with(flexAdapter) | ||
// .setFooterView(R.layout.view_flex_loading) | ||
// .setNoMoreView(R.layout.view_flex_no_more) | ||
// .setLoadFailedView(R.layout.view_flex_retry) | ||
.setShowNoMoreEnabled(true) | ||
.setListener(enabled -> { | ||
int itemCount = flexAdapter.getItemCount(); | ||
if (itemCount > 20 && mShowLoadFailedEnabled) { | ||
mShowLoadFailedEnabled = false; | ||
recyclerView.postDelayed(() -> enabled.setLoadFailed(true), 800); | ||
} else { | ||
//not enable load more | ||
if (itemCount >= 80) { | ||
enabled.setLoadMoreEnabled(false); | ||
} | ||
|
||
recyclerView.postDelayed(flexAdapter::addItem, 1200); | ||
} | ||
}) | ||
.into(recyclerView); | ||
} | ||
|
||
private static class FlexAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { | ||
|
||
private int mCount; | ||
|
||
public FlexAdapter(int count) { | ||
mCount = count; | ||
} | ||
|
||
@Override | ||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_flex, parent, false); | ||
return new SampleHolder(view); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { | ||
((SampleHolder) holder).mTextView.setText(position + ""); | ||
ViewGroup.LayoutParams lp = ((SampleHolder) holder).itemView.getLayoutParams(); | ||
if (lp instanceof com.google.android.flexbox.FlexboxLayoutManager.LayoutParams) { | ||
((FlexboxLayoutManager.LayoutParams) lp).setFlexGrow(1); | ||
} | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return mCount; | ||
} | ||
|
||
public void addItem() { | ||
final int positionStart = mCount; | ||
mCount+= 5; | ||
notifyItemRangeInserted(positionStart, 5); | ||
} | ||
|
||
static class SampleHolder extends RecyclerView.ViewHolder { | ||
TextView mTextView; | ||
|
||
public SampleHolder(View itemView) { | ||
super(itemView); | ||
mTextView = (TextView) itemView.findViewById(R.id.text); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
app/src/main/java/com/github/nukc/sample/NotShowFooterWhenNotCoveredScreenActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 8 additions & 6 deletions
14
app/src/main/java/com/github/nukc/sample/SampleActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 7 additions & 6 deletions
13
app/src/main/java/com/github/nukc/sample/ScrollingActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" | ||
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/recycler_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".FlexboxActivity"> | ||
|
||
<androidx.recyclerview.widget.RecyclerView | ||
android:id="@+id/recycler_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/swipe_refresh_layout" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<android.support.v7.widget.RecyclerView | ||
<androidx.recyclerview.widget.RecyclerView | ||
android:id="@+id/recycler_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" /> | ||
</android.support.v4.widget.SwipeRefreshLayout> | ||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.