Skip to content

Commit

Permalink
Migrate to AndroidX, flex box demo: #26 [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
nukc committed Jun 15, 2021
1 parent 323b329 commit 9d84205
Show file tree
Hide file tree
Showing 32 changed files with 344 additions and 124 deletions.
23 changes: 12 additions & 11 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
compileSdkVersion 30
buildToolsVersion '30.0.3'

defaultConfig {
applicationId "com.github.nukc.loadmorewrapper.sample"
minSdkVersion 14
targetSdkVersion 28
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -26,12 +26,13 @@ ext {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.android.support:appcompat-v7:${supportLibVersion}"
implementation "com.android.support:design:${supportLibVersion}"
implementation "com.android.support:recyclerview-v7:${supportLibVersion}"
implementation "com.android.support:support-v4:${supportLibVersion}"
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'com.google.android.flexbox:flexbox:3.0.0'
implementation project(':loadmorewrapper')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".FlexboxActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/com/github/nukc/sample/AnotherActivity.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.github.nukc.sample;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
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.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.github.nukc.LoadMoreWrapper.LoadMoreAdapter;
import com.github.nukc.LoadMoreWrapper.LoadMoreWrapper;

Expand Down
99 changes: 99 additions & 0 deletions app/src/main/java/com/github/nukc/sample/FlexboxActivity.java
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);
}
}
}
}
9 changes: 5 additions & 4 deletions app/src/main/java/com/github/nukc/sample/Issue9Activity.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.github.nukc.sample;

import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
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.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.github.nukc.LoadMoreWrapper.LoadMoreAdapter;
import com.github.nukc.LoadMoreWrapper.LoadMoreWrapper;

Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/com/github/nukc/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

@Override
Expand All @@ -15,6 +16,7 @@ protected void onCreate(Bundle savedInstanceState) {
findViewById(R.id.btn_another).setOnClickListener(mOnClickListener);
findViewById(R.id.btn_issues).setOnClickListener(mOnClickListener);
findViewById(R.id.btn_not_show_footer_when_not_covered_screen).setOnClickListener(mOnClickListener);
findViewById(R.id.btn_flex_box).setOnClickListener(mOnClickListener);
}

private View.OnClickListener mOnClickListener = new View.OnClickListener() {
Expand All @@ -34,6 +36,9 @@ public void onClick(View v) {
case R.id.btn_not_show_footer_when_not_covered_screen:
cls = NotShowFooterWhenNotCoveredScreenActivity.class;
break;
case R.id.btn_flex_box:
cls = FlexboxActivity.class;
break;
}
startActivity(new Intent(MainActivity.this, cls));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.github.nukc.sample;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
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.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.github.nukc.LoadMoreWrapper.LoadMoreAdapter;
import com.github.nukc.LoadMoreWrapper.LoadMoreWrapper;

Expand Down
14 changes: 8 additions & 6 deletions app/src/main/java/com/github/nukc/sample/SampleActivity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.github.nukc.sample;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;

public class SampleActivity extends AppCompatActivity {

@Override
Expand Down
15 changes: 8 additions & 7 deletions app/src/main/java/com/github/nukc/sample/SampleFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@


import android.os.Bundle;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.github.nukc.LoadMoreWrapper.LoadMoreAdapter;
import com.github.nukc.LoadMoreWrapper.LoadMoreWrapper;

Expand Down
13 changes: 7 additions & 6 deletions app/src/main/java/com/github/nukc/sample/ScrollingActivity.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.github.nukc.sample;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.github.nukc.LoadMoreWrapper.LoadMoreAdapter;
import com.github.nukc.LoadMoreWrapper.LoadMoreWrapper;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

public class ScrollingActivity extends AppCompatActivity {

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_another.xml
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" />
14 changes: 14 additions & 0 deletions app/src/main/res/layout/activity_flexbox.xml
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>
6 changes: 3 additions & 3 deletions app/src/main/res/layout/activity_issue9.xml
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>
8 changes: 8 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@
android:text="@string/not_show_footer_when_not_covered_screen"
app:textAllCaps="false" />

<Button
android:id="@+id/btn_flex_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/flex_box_layout_manager"
app:textAllCaps="false" />

</LinearLayout>
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_sample.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
android:orientation="vertical"
tools:context="com.github.nukc.sample.SampleActivity">

<android.support.design.widget.TabLayout
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:tabSelectedTextColor="@color/colorPrimary"
app:tabTextColor="#333333" />

<android.support.v4.view.ViewPager
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Expand Down
Loading

0 comments on commit 9d84205

Please sign in to comment.