Skip to content

Commit

Permalink
Merge pull request #10 from HamidrezaAmz/developer
Browse files Browse the repository at this point in the history
Developer
  • Loading branch information
HamidrezaAmz authored Mar 14, 2019
2 parents 7fbe8ea + 6b3ab61 commit 2328e1e
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 139 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'

// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 17
versionName "1.1.7"
versionCode 18
versionName "1.1.8"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
22 changes: 1 addition & 21 deletions library/src/main/java/com/vasl/recyclerlibrary/MyCustomView.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@

import com.tuyenmonkey.mkloader.MKLoader;
import com.vasl.recyclerlibrary.globalEnums.ListStatus;
import com.vasl.recyclerlibrary.globalEnums.ScrollDirection;
import com.vasl.recyclerlibrary.globalInterfaces.MyCustomViewCallBack;
import com.vasl.recyclerlibrary.globalInterfaces.MyCustomViewScrollCallBack;
import com.vasl.recyclerlibrary.utils.PublicFunction;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.OnScrollListener;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

public class MyCustomView extends RelativeLayout implements View.OnClickListener, SwipeRefreshLayout.OnRefreshListener {
Expand Down Expand Up @@ -90,6 +87,7 @@ private void init(AttributeSet attrs) {

View view = LayoutInflater.from(context).inflate(R.layout.layout_my_custom_view, this, false);

// retry-view
buttonRetry = view.findViewById(R.id.button_retry);
buttonRetry.setOnClickListener(this);

Expand All @@ -104,24 +102,6 @@ private void init(AttributeSet attrs) {

// recycler-view
recyclerView = view.findViewById(R.id.recyclerView);
recyclerView.addOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}

@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy > 0) {
if (myCustomViewScrollCallBack != null)
myCustomViewScrollCallBack.onScrollChange(ScrollDirection.UP);
} else {
if (myCustomViewScrollCallBack != null)
myCustomViewScrollCallBack.onScrollChange(ScrollDirection.DOWN);
}
}
});

// swipe-view
swipeRefreshLayout = view.findViewById(R.id.swipeHolder);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package com.vasl.recyclerlibrary.baseClasses;

import android.graphics.Canvas;

import com.vasl.recyclerlibrary.globalInterfaces.MyCustomAdapterCallBack;
import com.vasl.recyclerlibrary.utils.LogHelper;
import com.vasl.recyclerlibrary.utils.PublicValue;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;

public abstract class BaseRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
Expand All @@ -36,8 +32,7 @@ protected int checkScrollChanged(int adapterSize, int position) {
return lastPosition;
}
lastPosition = position;
float percentage = ((position + 1) * 100 / adapterSize);
if (percentage > PublicValue.percentVerticalNotify) {
if (lastPosition == adapterSize - 1) { // adapterSize - 1 for zero base array
if (myCustomAdapterCallBack != null) {
myCustomAdapterCallBack.richToEnd();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.vasl.recyclerlibrary.globalInterfaces.MyCustomAdapterCallBack;
import com.vasl.recyclerlibrary.utils.LogHelper;
import com.vasl.recyclerlibrary.utils.PublicValue;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.vasl.recyclerlibrary.globalInterfaces;

import com.vasl.recyclerlibrary.globalEnums.ScrollDirection;

public interface MyCustomViewScrollCallBack {

void onScrollChange(ScrollDirection scrollDirection);
void endOfList();

}
10 changes: 6 additions & 4 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">

<activity android:name=".MainActivity">
<activity
android:name="com.vasl.Library.Android.MainActivity">

</activity>

<activity android:name=".FragmentTestActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<!--<activity android:name=".MainActivity"></activity>-->

</application>

</manifest>
96 changes: 47 additions & 49 deletions sample/src/main/java/com/vasl/Library/Android/BlankFragment.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package com.vasl.Library.Android;


import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.vasl.recyclerlibrary.MyCustomView;
import com.vasl.recyclerlibrary.globalEnums.ListStatus;
import com.vasl.recyclerlibrary.globalEnums.ScrollDirection;
import com.vasl.recyclerlibrary.globalInterfaces.MyCustomAdapterCallBack;
import com.vasl.recyclerlibrary.globalInterfaces.MyCustomViewCallBack;
import com.vasl.recyclerlibrary.globalInterfaces.MyCustomViewScrollCallBack;
import com.vasl.recyclerlibrary.globalObjects.RowModel;

import java.util.ArrayList;
Expand All @@ -21,14 +19,19 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


/**
* A simple {@link Fragment} subclass.
*/
public class BlankFragment extends Fragment implements MyCustomViewCallBack, MyCustomAdapterCallBack, MyCustomViewScrollCallBack {
public class BlankFragment extends Fragment implements MyCustomViewCallBack, MyCustomAdapterCallBack {

private int index = 1;

private int start_page = 1;

private int curr_page = 1;

private TextView textView;

private MyCustomView myCustomView;

private RecyclerVerticalAdapter adapter;
Expand All @@ -40,84 +43,79 @@ public BlankFragment() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View inflate = inflater.inflate(R.layout.fragment_blank, container, false);

myCustomView = inflate.findViewById(R.id.myCustomView);

textView = inflate.findViewById(R.id.index);

RecyclerView recyclerView = myCustomView.getRecyclerView();

myCustomView.setMyCustomViewCallBack(this);

myCustomView.setStatus(ListStatus.LOADING);

adapter = new RecyclerVerticalAdapter(getContext(), rowModels);

recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false));
adapter = new RecyclerVerticalAdapter(getActivity(), rowModels);

adapter.setMyCustomAdapterCallBack(this);

myCustomView.setMyCustomViewScrollCallBack(this);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), RecyclerView.VERTICAL, false));


recyclerView.setAdapter(adapter);

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
myList();
}
}, 2000);
getList(start_page);

return inflate;
}

private void myList() {

rowModels.add(new RowModel("https://dkstatics-public.digikala.com/digikala-products/4308693.jpg?x-oss-process=image/resize,m_lfit,h_600,w_600/quality,q_80", "" + index++));
rowModels.add(new RowModel("https://dkstatics-public.digikala.com/digikala-products/4308693.jpg?x-oss-process=image/resize,m_lfit,h_600,w_600/quality,q_80", "" + index++));
rowModels.add(new RowModel("https://dkstatics-public.digikala.com/digikala-products/4308693.jpg?x-oss-process=image/resize,m_lfit,h_600,w_600/quality,q_80", "" + index++));
rowModels.add(new RowModel("https://dkstatics-public.digikala.com/digikala-products/4308693.jpg?x-oss-process=image/resize,m_lfit,h_600,w_600/quality,q_80", "" + index++));
rowModels.add(new RowModel("https://dkstatics-public.digikala.com/digikala-products/4308693.jpg?x-oss-process=image/resize,m_lfit,h_600,w_600/quality,q_80", "" + index++));
rowModels.add(new RowModel("https://dkstatics-public.digikala.com/digikala-products/4308693.jpg?x-oss-process=image/resize,m_lfit,h_600,w_600/quality,q_80", "" + index++));
rowModels.add(new RowModel("https://dkstatics-public.digikala.com/digikala-products/4308693.jpg?x-oss-process=image/resize,m_lfit,h_600,w_600/quality,q_80", "" + index++));
rowModels.add(new RowModel("https://dkstatics-public.digikala.com/digikala-products/4308693.jpg?x-oss-process=image/resize,m_lfit,h_600,w_600/quality,q_80", "" + index++));
rowModels.add(new RowModel("https://dkstatics-public.digikala.com/digikala-products/4308693.jpg?x-oss-process=image/resize,m_lfit,h_600,w_600/quality,q_80", "" + index++));
rowModels.add(new RowModel("https://dkstatics-public.digikala.com/digikala-products/4308693.jpg?x-oss-process=image/resize,m_lfit,h_600,w_600/quality,q_80", "" + index++));

adapter.notifyDataSetChanged();
myCustomView.setStatus(ListStatus.SUCCESS);
myCustomView.setSwipeRefreshStatus(false);
}
private void getList(int page) {

@Override
public void onRetryClicked() {
myList();
}
textView.setText("PAGE : " + page);

@Override
public void onRefresh(int page) {
myList();
}
if (page == 1)
myCustomView.setStatus(ListStatus.LOADING);
else
myCustomView.setStatus(ListStatus.LOADING_BOTTOM);

@Override
public void richToEnd() {
myCustomView.setStatus(ListStatus.LOADING_BOTTOM);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
myList();

rowModels.add(new RowModel("https://dkstatics-public.digikala.com/digikala-products/4308693.jpg?x-oss-process=image/resize,m_lfit,h_600,w_600/quality,q_80", "" + index++));
rowModels.add(new RowModel("https://dkstatics-public.digikala.com/digikala-products/4308693.jpg?x-oss-process=image/resize,m_lfit,h_600,w_600/quality,q_80", "" + index++));
rowModels.add(new RowModel("https://dkstatics-public.digikala.com/digikala-products/4308693.jpg?x-oss-process=image/resize,m_lfit,h_600,w_600/quality,q_80", "" + index++));
rowModels.add(new RowModel("https://dkstatics-public.digikala.com/digikala-products/4308693.jpg?x-oss-process=image/resize,m_lfit,h_600,w_600/quality,q_80", "" + index++));
rowModels.add(new RowModel("https://dkstatics-public.digikala.com/digikala-products/4308693.jpg?x-oss-process=image/resize,m_lfit,h_600,w_600/quality,q_80", "" + index++));
rowModels.add(new RowModel("https://dkstatics-public.digikala.com/digikala-products/4308693.jpg?x-oss-process=image/resize,m_lfit,h_600,w_600/quality,q_80", "" + index++));
rowModels.add(new RowModel("https://dkstatics-public.digikala.com/digikala-products/4308693.jpg?x-oss-process=image/resize,m_lfit,h_600,w_600/quality,q_80", "" + index++));
rowModels.add(new RowModel("https://dkstatics-public.digikala.com/digikala-products/4308693.jpg?x-oss-process=image/resize,m_lfit,h_600,w_600/quality,q_80", "" + index++));
rowModels.add(new RowModel("https://dkstatics-public.digikala.com/digikala-products/4308693.jpg?x-oss-process=image/resize,m_lfit,h_600,w_600/quality,q_80", "" + index++));
rowModels.add(new RowModel("https://dkstatics-public.digikala.com/digikala-products/4308693.jpg?x-oss-process=image/resize,m_lfit,h_600,w_600/quality,q_80", "" + index++));

adapter.notifyDataSetChanged();
myCustomView.setStatus(ListStatus.SUCCESS);
myCustomView.setSwipeRefreshStatus(false);
}
}, 2000);
}, 1000);
}

@Override
public void onRetryClicked() {
getList(start_page);
}

@Override
public void onScrollChange(ScrollDirection scrollDirection) {
public void onRefresh(int page) {
getList(start_page);
}

@Override
public void richToEnd() {
curr_page = curr_page + 1;
getList(curr_page);
}
}
Loading

0 comments on commit 2328e1e

Please sign in to comment.