Comments (7)
Here is the whole activity code, and i would really appreciate some help here:
`public class HomeActivity extends AppCompatActivity implements OnLikeListener {
private List<Post> mPosts = new ArrayList<>();
private SimpleFacebook mSimpleFacebook;
private VerticalInfiniteCycleViewPager infiniteCycleViewPager;
private Permission[] mPermissions = new Permission[]{
Permission.USER_PHOTOS,
Permission.PUBLISH_ACTION,
Permission.USER_LIKES,
};
private DialogLoadingScreen progressDialog;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Making notification bar transparent
if (Build.VERSION.SDK_INT >= 21) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
setContentView(R.layout.activity_home);
progressDialog = DialogLoadingScreen.newInstance();
mSimpleFacebook = SimpleFacebook.getInstance(this);
initViews();
initLikeButton();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
showProgressDialog();
}
}, 1000);
mSimpleFacebook.requestNewPermissions(mPermissions, onNewPermissionListener);
Util.changeStatusBarColor(this);
}
private void configureInfinitiveCycleViewPager() {
infiniteCycleViewPager =
(VerticalInfiniteCycleViewPager) findViewById(R.id.view_pager);
VerticalPagerAdapter adapter = new VerticalPagerAdapter(getSupportFragmentManager(), mPosts);
infiniteCycleViewPager.setAdapter(adapter);
}
private void initViews() {
ImageView imageView = (ImageView) findViewById(R.id.iv_background);
Glide.with(HomeActivity.this)
.load(R.drawable.background)
.crossFade()
.centerCrop()
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(imageView);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Blurry.with(HomeActivity.this)
.radius(25)
.sampling(1)
.async()
.capture(findViewById(R.id.iv_background))
.into((ImageView) findViewById(R.id.iv_background));
}
}, 500);
}
private void initLikeButton() {
LikeButton likeButton = (LikeButton) findViewById(R.id.thumb_button);
likeButton.setOnLikeListener(this);
}
@Override
protected void onResume() {
super.onResume();
mSimpleFacebook = SimpleFacebook.getInstance(this);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
mSimpleFacebook.onActivityResult(requestCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
}
/***************************
* Facebook Methods
*****************************/
OnNewPermissionsListener onNewPermissionListener = new OnNewPermissionsListener() {
@Override
public void onSuccess(String accessToken,
List<Permission> acceptedPermissions,
List<Permission> declinedPermissions) {
Log.d("Access Token: ", accessToken);
Bundle params = new Bundle();
params.putString("fields",
"picture, url, source, created_time");
params.putString("limit", "1000");
String entityId = "957672727688311";
mSimpleFacebook.get(entityId, "photos/uploaded", params, onActionListener);
}
@Override
public void onCancel() {
}
@Override
public void onException(Throwable throwable) {
}
@Override
public void onFail(String reason) {
}
};
OnActionListener<List<Photo>> onActionListener = new OnActionListener<List<Photo>>() {
@Override
public void onComplete(List<Photo> photos) {
configureInfinitiveCycleViewPager();
hideProgressDialog();
for (Photo photo : photos) {
Post post = new Post();
post.setPhotoId(photo.getId());
post.setSource(photo.getSource());
post.setCreatedTime(photo.getCreatedTime());
mPosts.add(post);
}
sortList(mPosts);
infiniteCycleViewPager.notifyDataSetChanged();
}
};
private void sortList(List<Post> posts) {
Collections.sort(posts, new Comparator<Post>() {
@Override
public int compare(Post o1, Post o2) {
if (o1.getCreatedTime() == null || o2.getCreatedTime() == null)
return 0;
return o2.getCreatedTime().compareTo(o1.getCreatedTime());
}
});
}
@Override
public void onBackPressed() {
super.onBackPressed();
this.finish();
}
private void showProgressDialog() {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(progressDialog, "loading");
transaction.commitAllowingStateLoss();
progressDialog.setCancelable(false);
}
private void hideProgressDialog() {
if (progressDialog.isVisible()) {
progressDialog.dismiss();
}
}
public SimpleFacebook getSimpleFacebook() {
return mSimpleFacebook;
}
public VerticalInfiniteCycleViewPager getInfiniteCycleViewPager() {
return infiniteCycleViewPager;
}
@Override
public void liked(LikeButton likeButton) {
int position = infiniteCycleViewPager.getRealItem();
final Post post = mPosts.get(position);
Like like = new Like.Builder().build();
mSimpleFacebook.publish(post.getPhotoId(), like, new OnPublishListener() {
@Override
public void onComplete(String response) {
TastyToast.makeText(HomeActivity.this, response, TastyToast.LENGTH_LONG,
TastyToast.DEFAULT);
}
@Override
public void onException(Throwable throwable) {
super.onException(throwable);
}
@Override
public void onFail(String reason) {
super.onFail(reason);
}
@Override
public void onThinking() {
super.onThinking();
}
});
}
@Override
public void unLiked(LikeButton likeButton) {
}
}
`
from infinitecycleviewpager.
Hello. Thanks for this issue.
I'll try to fix this soon.
from infinitecycleviewpager.
Thank you for responding here so fast. Your library is awesome. Just if this bug can be fixed, it would be great, i really need that feature, getting position of selected item in ViewPager.
from infinitecycleviewpager.
This is very interesting, because method doesnt invoke npe. Try to fix.
from infinitecycleviewpager.
Well i have tried, but i always got null object reference. Can you look at the code and see if you can find any mistake i have made?
from infinitecycleviewpager.
from infinitecycleviewpager.
from infinitecycleviewpager.
Related Issues (20)
- cant swipe page
- Very slow rendering with dynamic data HOT 14
- Infinite scroll HOT 1
- Can you tell how to display more than 3 scroller items
- PageIndicator HOT 2
- Need to restrict after some loop HOT 1
- How to modify item height scale?
- Crash app when size increases
- Support for Android TV
- setCurrentItem(item,false) not working
- Go back to other pages and return to the slide viewpager with a blank page
- ViewPager+Fragment+FragmentPagerAdapter HOT 1
- ViewPager takes the whole screen HOT 3
- CardView & InfiniteCycleViewPager
- Not infinite loop HOT 1
- Is there a way to separate the lateral images, so that it does not look too close?
- Get Every Position HOT 1
- Bug: turn off and on infinite cycle
- Font family of tab
- When I am using infinitecycleviewpager on banners, when I am opening the app the banners are not appearing and taking left position, after swiping the banner it is working fine
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from infinitecycleviewpager.