Guest User

Untitled

a guest
Dec 12th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.94 KB | None | 0 0
  1. public class NewsFeedFragment extends FcaFragment {
  2.  
  3. private View view;
  4. private RecyclerView postRecyclerView;
  5. private PostsAdapter postsAdapter;
  6. private List<Post> posts;
  7. private TimelineViewModel timelineViewModel;
  8. private ImageView addPostView;
  9. private View addPostPanel;
  10. private long lastApiCallTime;
  11. private SwipyRefreshLayout swipeRefresh;
  12. private long lastScroolItemInPost= 0;
  13.  
  14. public NewsFeedFragment() {
  15.  
  16. }
  17.  
  18.  
  19. @Override
  20. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  21. Bundle savedInstanceState) {
  22. if(lastScroolItemInPost < 1) {
  23. initViewModel(1 , 0 , true);
  24. lastScroolItemInPost = 1;
  25. }else {
  26. initViewModel(((int) lastScroolItemInPost + 5), lastScroolItemInPost , true);
  27. lastScroolItemInPost += 5;
  28. }
  29.  
  30.  
  31. final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(ownerActivity);
  32.  
  33. view = inflater.inflate(R.layout.fragment_news_feed, container, false);
  34. postRecyclerView = (RecyclerView) view.findViewById(R.id.postRecyclerView);
  35. postRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
  36. @Override
  37. public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
  38. super.onScrollStateChanged(recyclerView, newState);
  39. }
  40.  
  41. @Override
  42. public void onScrolled(RecyclerView postRecyclerView, int dx, int dy) {
  43. super.onScrolled(postRecyclerView, dx, dy);
  44.  
  45.  
  46. int lastVisiableItemInPostList = linearLayoutManager.findLastVisibleItemPosition();
  47.  
  48.  
  49. if(lastScroolItemInPost < lastVisiableItemInPostList)
  50. {
  51. if(lastScroolItemInPost == 1)
  52. {
  53. initViewModel((int) (lastScroolItemInPost + 2), ( lastScroolItemInPost - 2 ) , false);
  54. lastScroolItemInPost += 2;
  55. }else{
  56. initViewModel((int) (lastScroolItemInPost + 2), ( lastScroolItemInPost - 2 ) , false );
  57. lastScroolItemInPost += 2;
  58. }
  59.  
  60.  
  61. }
  62.  
  63. }
  64.  
  65. });
  66.  
  67. posts = new ArrayList<>();
  68.  
  69. postRecyclerView.setLayoutManager(linearLayoutManager);
  70. postsAdapter = new PostsAdapter(ownerActivity,posts,timelineViewModel);
  71. postRecyclerView.setAdapter(postsAdapter);
  72. swipeRefresh = (SwipyRefreshLayout) view.findViewById(R.id.swipeRefresh);
  73. swipeRefresh.setOnRefreshListener(new SwipyRefreshLayout.OnRefreshListener() {
  74. @Override
  75. public void onRefresh(SwipyRefreshLayoutDirection direction) {
  76. if(direction == SwipyRefreshLayoutDirection.TOP){
  77. timelineViewModel.fetchPosts2();
  78. }
  79.  
  80. if(direction == SwipyRefreshLayoutDirection.BOTTOM){
  81. timelineViewModel.fetchPosts();
  82. }
  83. }
  84. });
  85.  
  86.  
  87.  
  88.  
  89. return view;
  90. }
  91.  
  92.  
  93.  
  94.  
  95. private void initViewModel(int lastVisiableItemInPostList , long lastScroolItemInPost , boolean isFirstTimeOpenFeedFragment) {
  96. TimelineViewModel.Factory factory = new TimelineViewModel.Factory(UserPreferences.getToken(ownerActivity), TaskUtils.getMySelfContact(ownerActivity));
  97. timelineViewModel = ViewModelProviders.of(this,factory).get(TimelineViewModel.class);
  98. timelineViewModel.getPostList().observe(this, new Observer<List<Post>>() {
  99. @Override
  100. public void onChanged(@Nullable List<Post> posts) {
  101.  
  102. postsAdapter.setPostList(posts);
  103. swipeRefresh.setRefreshing(false);
  104.  
  105. }
  106. });
  107. timelineViewModel.getPostDeleted().observe(this, new Observer<Boolean>() {
  108. @Override
  109. public void onChanged(@Nullable Boolean aBoolean) {
  110. if(aBoolean){
  111. postsAdapter.setPostList(Post.getAll());
  112. }
  113. }
  114. });
  115. timelineViewModel.init( lastVisiableItemInPostList , lastScroolItemInPost ,isFirstTimeOpenFeedFragment);
  116. }
  117.  
  118. }
  119.  
  120. public class TimelineViewModel extends FCViewModel implements PostDetailsDownloadManager.PostDetailDownloadedListener,OnContactReceivedListner{
  121.  
  122.  
  123.  
  124.  
  125.  
  126. public TimelineViewModel(String token,Contact user){
  127. super(token);
  128. this.user = user;
  129.  
  130. post = new MutableLiveData<>();
  131. postDeleted = new MutableLiveData<>();
  132. }
  133.  
  134. public void init(int lastVisiableItemInPostList , long lastScroolItemInPost , boolean isFirstTimeOpenFeedFragment){
  135. repository =
  136. //postDetailsDownloadManager = ServiceLocator.getServiceLocator().postDetailsDownloadManager;
  137.  
  138. likePostDownloadManager = ServiceLocator.getServiceLocator().likePostDownloadManager;
  139. likePostDownloadManager.setPostDetailDownloadedListener(new DataDownloadManager.DataDownloadedListener<LikePostTouple>() {
  140. @Override
  141. public void onDataDownloaded(List<LikePostTouple> dataTouple) {
  142. TimelineViewModel.this.post.setValue(Post.getAll());
  143. }
  144.  
  145. @Override
  146. public void onSingleDataDownloaded(LikePostTouple dataTouple) {
  147.  
  148. }
  149. });
  150.  
  151. postDetailDownloadManager = ServiceLocator.getServiceLocator().postDetailDownloadManager;
  152. postDetailDownloadManager.setPostDetailDownloadedListener(new DataDownloadManager.DataDownloadedListener<PostTouple>() {
  153. @Override
  154. public void onDataDownloaded(List<PostTouple> dataTouple) {
  155. TimelineViewModel.this.post.setValue(Post.getAll());
  156. }
  157.  
  158. @Override
  159. public void onSingleDataDownloaded(PostTouple dataTouple) {
  160.  
  161. }
  162. });
  163. post.setValue(Post.getAll());
  164. if(isFirstTimeOpenFeedFragment)
  165. {
  166. fetchPosts2();
  167. }
  168.  
  169. try {
  170. if(Post.getAll().size() > 0)
  171. {
  172. List<Post> tempPosts = Post.getAll();
  173. List<Post> passList = tempPosts.subList( (int) lastScroolItemInPost ,lastVisiableItemInPostList);
  174. fetchLikesOfPosts(passList);
  175. }else{
  176. fetchLikesOfPosts(Post.getAll());
  177. }
  178. } catch (Exception e) {
  179. e.printStackTrace();
  180. }
  181.  
  182.  
  183. Log.d("Testing Injecting", repository.toString());
  184. }
  185.  
  186. public LiveData<List<Post>> getPostList() {
  187. return post;
  188. }
  189.  
  190. public MutableLiveData<Boolean> getPostDeleted() {
  191. return postDeleted;
  192. }
  193.  
  194. boolean isContactFetched = false;
  195.  
  196. public void fetchPosts(){
  197. if(Contact.getAll().size() < 1){
  198. fetchContacts();
  199. return;
  200. }
  201. Map<String,Object> requestData = new HashMap<>();
  202. requestData.put("type",1);
  203. requestData.put("cpid",Post.getLastPid());
  204. isDataLoading = true;
  205. repository.getData(new Repository.DataFetchedListener<List<Post>>() {
  206. @Override
  207. public void onDataFetched(List<Post> posts) {
  208. isDataLoading = false;
  209. Log.d("fetched posts",""+posts.size());
  210. post.setValue(Post.getAll());
  211. fetchPostDetails(posts);
  212. if(posts.size() > 0){
  213. fetchLikesOfPosts(posts);
  214. }
  215. }
  216. },requestData);
  217. }
  218.  
  219.  
  220. private boolean isDataLoading = false;
  221. public void fetchPosts2(){
  222. if(Contact.getAll().size() < 1){
  223. fetchContacts();
  224. return;
  225. }
  226. Map<String,Object> requestData = new HashMap<>();
  227. requestData.put("type",2);
  228. requestData.put("cpid", Post.getFirstPid()); // cpid means cursor pid
  229. isDataLoading = true;
  230. repository.getData(new Repository.DataFetchedListener<List<Post>>() {
  231. @Override
  232. public void onDataFetched(List<Post> posts) {
  233. isDataLoading = false;
  234. Log.d("fetched posts",""+posts.size());
  235. post.setValue(Post.getAll());
  236. fetchPostDetails(posts);
  237. if(posts.size() > 0){
  238. fetchLikesOfPosts(posts);
  239. }
  240. }
  241. },requestData);
  242. }
  243.  
  244. public boolean isDataLoading() {
  245. return isDataLoading;
  246. }
  247.  
  248.  
  249.  
  250. private void fetchContacts() {
  251. contactRepository.getData(new Repository.DataFetchedListener<List<Contact>>() {
  252. @Override
  253. public void onDataFetched(List<Contact> data) {
  254. if(data.size()>0 && !isContactFetched) {
  255. fetchPosts2();
  256. isContactFetched = true;
  257. }
  258. }
  259. },null);
  260. }
  261.  
  262.  
  263.  
  264. @NonNull
  265. private PostTouple getPostToubleFromPost(Post post) throws JSONException {
  266. Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
  267. String json = gson.toJson(post);
  268. JSONObject postJson = new JSONObject(json);
  269. return new PostTouple(postJson,post.getPid());
  270. }
  271.  
  272. @NonNull
  273. private LikePostTouple getLkePostToupleFromPost(Post post) throws JSONException {
  274. Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
  275. String json = gson.toJson(post);
  276. JSONObject postJson = new JSONObject(json);
  277. return new LikePostTouple(postJson,post.getPid());
  278. }
  279.  
  280. public void giveLike(String token, final long pid){
  281. Map<String,Object> requestData = new HashMap<>();
  282. requestData.put("token",token);
  283. requestData.put("pid",Long.toString(pid));
  284.  
  285. likeRepository.postData(new Repository.DataFetchedListener<Post>() {
  286. @Override
  287. public void onDataFetched(Post data) {
  288. Log.d("Like post", data.toString());
  289. Post post = getPostById(pid);
  290. post.setLikes(data.getLikes());
  291. post.setComments(data.getComments());
  292. TimelineViewModel.this.post.setValue(TimelineViewModel.this.post.getValue());
  293. fetchLikesOfLikedPost(data);
  294. }
  295. },requestData);
  296. }
  297.  
  298. private void fetchLikesOfLikedPost(Post data) {
  299. try {
  300. likePostDownloadManager.addItemInQueue(getLkePostToupleFromPost(data));
  301. likePostDownloadManager.startDownload();
  302. } catch (JSONException e) {
  303. e.printStackTrace();
  304. }
  305. }
  306.  
  307. private Post getPostById(long pid){
  308. List<Post> posts = post.getValue();
  309. for(Post post : posts){
  310. if(post.getPid()==pid){
  311. return post;
  312. }
  313. }
  314. return null;
  315. }
  316.  
  317. public Contact getSenderContactFromComment(Post post) {
  318. if(post.getPqrc().equals(user.getUserId())){
  319. return user;
  320. }
  321. Contact contact = Contact.getByUserId(post.getPqrc());
  322.  
  323. return contact;
  324. }
  325.  
  326. public String getDescriptionForType5(Post post,String message){
  327.  
  328. try {
  329. PostDetail postDetail = PostDetail.getByPostId(post.getPid());
  330. if(postDetail!=null) {
  331. String qrc = JSonUtils.qrcFromCntOfPostDetails(postDetail.getContent());
  332. int sid = JSonUtils.skillidFromCntOfPostDetails(postDetail.getContent());
  333. if (qrc == null || sid == 0) {
  334. return "";
  335. }
  336. SkillDb skill = SkillDb.getBySId(Integer.toString(sid));
  337.  
  338. Contact contact = getPosterContact(post.getPqrc());
  339.  
  340. return contact.getName() + " " + message + " " + skill.getSkillName() + ".";
  341. }
  342.  
  343. return "";
  344. } catch (Exception e) {
  345. e.printStackTrace();
  346. }
  347. return "";
  348. }
  349.  
  350. public String getDescriptionForPost(Post post, String message){
  351. if(post.getCtype()==1){
  352. return post.getDescr();
  353. }
  354.  
  355. if(post.getCtype() == 2){
  356. String postDetail = getContent(post);
  357. if (postDetail != null) return Html.fromHtml("<a href=""+ postDetail +"">"+postDetail+"</a>").toString();
  358. }
  359.  
  360. if(post.getCtype()==5){
  361. return getDescriptionForType5(post, message);
  362. }
  363.  
  364. return "";
  365.  
  366. }
  367.  
  368. @Nullable
  369. public String getContent(Post post) {
  370. PostDetail postDetail = PostDetail.getByPostId(post.getPid());
  371. if(postDetail!=null){
  372. return postDetail.getContent();
  373. }
  374. return null;
  375. }
  376.  
  377.  
  378. public Contact getPosterContact(String qrc){
  379. try {
  380. String userqrc = user.getUserId();
  381. if (userqrc.equals(qrc)) {
  382. return user;
  383. }
  384. }catch (Exception e){
  385. e.printStackTrace();
  386. }
  387. try {
  388. return Contact.getByUserId(qrc);
  389. }catch (Exception e){
  390. e.printStackTrace();
  391. }
  392. return null;
  393. }
  394.  
  395. public void fetchUrlPreview(String url, final UrlMetaDataFetchListener metaDataFetchListener){
  396. String modifiedUrl = !url.contains("http://")&&!url.contains("https://")? "http://"+url : url;
  397. TextCrawler textCrawler = new TextCrawler();
  398.  
  399.  
  400. LinkPreviewCallback linkPreviewCallback = new LinkPreviewCallback() {
  401. @Override
  402. public void onPre() {
  403.  
  404. }
  405.  
  406. @Override
  407. public void onPos(SourceContent sourceContent, boolean b) {
  408. String imageUrl = sourceContent.getImages().isEmpty()? "" : sourceContent.getImages().get(0);
  409. metaDataFetchListener.onMetaDataFetched(sourceContent.getTitle(),sourceContent.getDescription(), imageUrl);
  410. }
  411. };
  412.  
  413. textCrawler.makePreview(linkPreviewCallback, modifiedUrl,1);
  414. }
  415.  
  416.  
  417. public interface UrlMetaDataFetchListener{
  418. void onMetaDataFetched(String title, String description, String imageUrl);
  419. }
  420.  
  421. @Override
  422. public void onPostDownloaded(PostTouple postTouple) {
  423. this.post.setValue(Post.getAll());
  424. }
  425.  
  426. @Override
  427. public void onContactsReceived() {
  428. fetchPosts();
  429. }
  430.  
  431.  
  432. public void deletePost(long pid) {
  433. Map<String, Object> requestData = new HashMap<>();
  434. requestData.put("token",token);
  435. requestData.put("pid",pid);
  436. repository.postData(new Repository.DataFetchedListener<Post>() {
  437. @Override
  438. public void onDataFetched(Post data) {
  439. postDeleted.setValue(data!=null);
  440. }
  441. },requestData);
  442. }
  443.  
  444. public boolean isMyPost(Post post){
  445. return user.getUserId().equals(post.getPqrc());
  446. }
  447.  
  448. public static class Factory extends ViewModelProvider.NewInstanceFactory {
  449.  
  450. private String token;
  451. private Contact user;
  452.  
  453. public Factory(String token,Contact user) {
  454. this.token = token;
  455. this.user = user;
  456. }
  457.  
  458. @Override
  459. public <T extends ViewModel> T create(Class<T> modelClass) {
  460.  
  461. return (T) new TimelineViewModel(token,user);
  462. }
  463. }
  464. }
  465.  
  466. private Context context;
  467. private List<Post> postList;
  468. private int[] badges = {R.drawable.badge1, R.drawable.badge2, R.drawable.badge3};
  469. private List<Integer> randomNumbers = Utils.getRandomNumberList(2,true);
  470. private ArrayDeque<Integer> randomQueue = new ArrayDeque<>(randomNumbers);
  471. private static Map<Long,URLPreview> urlPreviewMap = new HashMap<>();
  472. private TimelineViewModel timelineViewModel;
  473.  
  474. public PostsAdapter(Context context, List<Post> postList, TimelineViewModel timelineViewModel){
  475. super();
  476. this.context = context;
  477. this.postList = postList;
  478. this.timelineViewModel = timelineViewModel;
  479. }
  480.  
  481. @Override
  482. public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  483. LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  484. View view = inflater.inflate(R.layout.post_item_layout, null);
  485. PostViewHolder postViewHolder = new PostViewHolder(view);
  486. postViewHolder.setIsRecyclable(false);
  487. return postViewHolder;
  488. }
  489.  
  490. @Override
  491. public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
  492. final Post post = postList.get(position);
  493. final PostViewHolder postViewHolder = (PostViewHolder) holder;
  494. final String postDetail = timelineViewModel.getDescriptionForPost(post,context.getResources().getString(R.string.postType5message));
  495.  
  496.  
  497. setPostDescription(post, postViewHolder, postDetail);
  498. handlePreviewVisibility(post, postViewHolder);
  499.  
  500.  
  501. postViewHolder.setLikes(""+post.getLikes()+" Likes");
  502. postViewHolder.setCommentCount("" + post.getComments() + " Comments");
  503. postViewHolder.setSupDescription("Posted By System");
  504.  
  505. int randomNumber = getRandomNumber();
  506. postViewHolder.setBadgeIcon(badges[randomNumber]);
  507.  
  508. setPostLikedIndicator(post, postViewHolder);
  509.  
  510. postViewHolder.getLikeButtonWrapper().setOnClickListener(new View.OnClickListener() {
  511. @Override
  512. public void onClick(View v) {
  513.  
  514.  
  515. giveLikeToPost(post);
  516. if(post.getIsLiked() == 0) {
  517. post.setLikes(post.getLikes() + 1);
  518. postViewHolder.setLikes("" + post.getLikes() + " Likes");
  519. post.setIsLiked(1);
  520. setPostLikedIndicator(post, postViewHolder);
  521. }
  522. }
  523. });
  524.  
  525. postViewHolder.getCommentPanel().setOnClickListener(new View.OnClickListener() {
  526. @Override
  527. public void onClick(View v) {
  528. CommentPostFragment fragment = CommentPostFragment.GetInstance(post.getPid());
  529. ViewUtils.launchFragmentKeepingInBackStack(context,fragment);
  530. }
  531. });
  532.  
  533. Contact contact = timelineViewModel.getPosterContact(post.getPqrc());
  534.  
  535. if(contact!=null && TaskUtils.isNotEmpty(contact.getImageToken())){
  536. Utils.setImageToImageView(postViewHolder.getPosterImage(),timelineViewModel.getToken(),contact.getImageToken());
  537. postViewHolder.getPosterNameTextView().setText(contact.getName());
  538. }
  539.  
  540.  
  541. postViewHolder.getPostingDate().setText(Utils.getDateFromMilliseconds(post.getdC()));
  542. if(post.getCtype() != 3)
  543. {
  544.  
  545. postViewHolder.contentImage.setVisibility(View.GONE);
  546. postViewHolder.fullScreenIndicatorIcon.setVisibility(View.GONE);
  547. }
  548.  
  549. if(post.getCtype() == 3){
  550. setContentOfType3(post, postViewHolder);
  551. }
  552.  
  553.  
  554.  
  555.  
  556. }
  557.  
  558. @Override
  559. public void onViewRecycled(RecyclerView.ViewHolder holder) {
  560. super.onViewRecycled(holder);
  561. PostViewHolder viewHolder = (PostViewHolder) holder;
  562. viewHolder.pTitle.setText("");
  563. viewHolder.pDescription.setText("");
  564. viewHolder.pImage.setImageDrawable(null);
  565.  
  566. }
  567.  
  568. private void handlePreviewVisibility(Post post, PostViewHolder postViewHolder) {
  569. if(post.getCtype()==2){
  570. postViewHolder.preview.setVisibility(View.VISIBLE);
  571. }else{
  572. postViewHolder.preview.setVisibility(View.GONE);
  573. }
  574. }
  575.  
  576. private void handleShowingOptionsIcon(Post post, PostViewHolder postViewHolder) {
  577. if(post.getCtype()!=5 && timelineViewModel.isMyPost(post)){
  578. postViewHolder.options.setVisibility(View.VISIBLE);
  579. }else{
  580. postViewHolder.options.setVisibility(View.GONE);
  581. }
  582. }
  583.  
  584.  
  585.  
  586.  
  587.  
  588. private void giveLikeToPost(Post post) {
  589. post.setLikes(post.getLikes()+1);
  590.  
  591. post.setIsLiked(1);
  592.  
  593. //notifyDataSetChanged();
  594.  
  595. timelineViewModel.giveLike(UserPreferences.getToken(context),post.getPid());
  596.  
  597. }
  598.  
  599. private void setPostLikedIndicator(Post post, PostViewHolder postViewHolder) {
  600. if(post.getIsLiked()==1) {
  601. postViewHolder.getLikeButton().setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.ic_like_red, null));
  602. }else{
  603. postViewHolder.getLikeButton().setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.ic_like_filled, null));
  604. }
  605. }
  606.  
  607. private void setPostDescription(final Post post, final PostViewHolder postViewHolder, final String postDetail) {
  608. if(post.getCtype()==2){
  609.  
  610. String postDescription = "<p>"+ post.getDescr()+"</p>";
  611. postViewHolder.description.setText( Html.fromHtml(postDescription +"<a href=""+ postDetail +"">"+postDetail+"</a>") );
  612. postViewHolder.descriptionContainer.setOnClickListener(new View.OnClickListener() {
  613. @Override
  614. public void onClick(View v) {
  615. String url = !postDetail.contains("http://")&&!postDetail.contains("https://")? "http://"+postDetail : postDetail;
  616. Uri uri = Uri.parse(url);
  617. context.startActivity(new Intent(Intent.ACTION_VIEW,uri));
  618. }
  619. });
  620. URLPreview urlPreview = null;
  621. if((urlPreview=urlPreviewMap.get(post.getPid()))==null) {
  622. timelineViewModel.fetchUrlPreview(postDetail, new TimelineViewModel.UrlMetaDataFetchListener() {
  623. @Override
  624. public void onMetaDataFetched(String title, String description, String imageUrl) {
  625. showURLPreview(title, description, imageUrl, postViewHolder);
  626. urlPreviewMap.put(post.getPid(),new URLPreview(title,description,imageUrl));
  627. }
  628. });
  629. }else {
  630. showURLPreview(urlPreview.getTitle(),urlPreview.getDescription(),urlPreview.getImageUrl(),postViewHolder);
  631. }
  632.  
  633. }else if(post.getCtype() == 3)
  634. {
  635. String postDescription = post.getDescr();
  636. postViewHolder.description.setText(postDescription);
  637. }
  638. else {
  639. postViewHolder.setDescription(postDetail);
  640. }
  641. }
  642. private void initImageClickListener(final ImageView imageView, final String pictureLink) {
  643. imageView.setOnClickListener(new View.OnClickListener() {
  644. @Override
  645. public void onClick(View v) {
  646. List<String> pictureLinks = new ArrayList<String>();
  647. pictureLinks.add(pictureLink);
  648.  
  649.  
  650. int[] screenLocation = new int[2];
  651. imageView.getLocationOnScreen(screenLocation);
  652.  
  653. ImagePagerFragment imagePagerFragment = ImagePagerFragment.newInstance(pictureLinks, 0, screenLocation, imageView.getWidth(), imageView.getHeight());
  654. ViewUtils.launchPopUpFragmentUpdated(context, imagePagerFragment);
  655. }
  656. });
  657. }
  658.  
  659.  
  660. private void showURLPreview(String title, String description, String imageUrl, PostViewHolder postViewHolder) {
  661.  
  662. if(!TaskUtils.isEmpty(imageUrl)) {
  663. Picasso.with(context)
  664. .load(imageUrl)
  665. .into(postViewHolder.pImage);
  666. }
  667.  
  668. postViewHolder.pTitle.setText(title);
  669. postViewHolder.pDescription.setText(description);
  670.  
  671.  
  672. }
  673.  
  674.  
  675. @Override
  676. public int getItemCount() {
  677. return postList.size();
  678. }
  679.  
  680. private int getRandomNumber(){
  681. if(!randomQueue.isEmpty()){
  682. return randomQueue.poll();
  683. }
  684.  
  685. randomQueue = new ArrayDeque<>(randomNumbers);
  686. return randomQueue.poll();
  687. }
  688.  
  689. public void setPostList(List<Post> postList) {
  690. this.postList = postList;
  691. notifyDataSetChanged();
  692. Log.d("Data rec", postList.size()+"");
  693. }
  694.  
  695. class PostViewHolder extends RecyclerView.ViewHolder implements PopupMenu.OnMenuItemClickListener {
  696.  
  697.  
  698.  
  699.  
  700. }
  701.  
  702. public void setLikes(String likes) {
  703. this.likes.setText(likes);
  704. }
  705. public void setCommentCount(String commentCount)
  706. {
  707. this.commentCount.setText(commentCount);
  708. }
  709.  
  710. public void setDescription(String description){
  711. this.description.setText(description);
  712. }
  713.  
  714. public void setSupDescription(String subDescription){
  715. this.supDescription.setText(subDescription);
  716. }
  717.  
  718. public void setBadgeIcon(int resID){
  719. Utils.setImageViewFromResource(badgeIcon,resID);
  720. }
  721.  
  722. public ImageView getLikeButton() {
  723. return likeButton;
  724. }
  725. public RelativeLayout getLikeButtonWrapper()
  726. {
  727. return likeButtonWrapper;
  728. }
  729.  
  730. public ImageView getCommentButton() {
  731. return commentButton;
  732. }
  733.  
  734. public ImageView getPosterImage() {
  735. return posterImage;
  736. }
  737.  
  738. public TextView getPosterNameTextView() {
  739. return posterNameTextView;
  740. }
  741.  
  742. public TextView getPostingDate() {
  743. return postingDate;
  744. }
  745.  
  746. public RelativeLayout getCommentPanel() {
  747. return commentPanel;
  748. }
  749.  
  750. @Override
  751. public boolean onMenuItemClick(MenuItem item) {
  752. timelineViewModel.deletePost(postList.get(getAdapterPosition()).getPid());
  753. return false;
  754. }
  755. }
Add Comment
Please, Sign In to add comment