Guest User

Untitled

a guest
Nov 22nd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.43 KB | None | 0 0
  1. {
  2. "posts": [
  3. {
  4. "id": "1",
  5. "userid": "1831",
  6. "authorname": "WhatsApp",
  7. "message": "There are only two times that I want to be with you: Now and Forever.",
  8. "likes": "0",
  9. "type": "romantic",
  10. "Likes": [
  11. {
  12. "userid": "814",
  13. "username": "jhon",
  14. "postid": "1"
  15. }
  16. ]
  17. },
  18. {
  19. "id": "2",
  20. "userid": "1831",
  21. "authorname": "WhatsApp",
  22. "message": "My six word love story: β€œI can’t imagine life without you.”",
  23. "likes": "0",
  24. "type": "romantic",
  25. "Likes": [
  26.  
  27. ]
  28. },
  29. {
  30. "id": "3",
  31. "userid": "1831",
  32. "authorname": "WhatsApp",
  33. "message": "You have no idea how much my heart races when I see you.",
  34. "likes": "0",
  35. "type": "romantic",
  36. "Likes": [
  37. {
  38. "userid": "38919",
  39. "username": "Roman",
  40. "postid": "3"
  41. },
  42. {
  43. "userid": "291",
  44. "username": "haley",
  45. "postid": "3"
  46. }
  47. ]
  48. },
  49. {
  50. "id": "4",
  51. "userid": "1831",
  52. "authorname": "WhatsApp",
  53. "message": "Since the time I’ve met you, I cry a little less, laugh a little harder and smile all the more, just because I have you, my life is a better place.",
  54. "likes": "0",
  55. "type": "romantic",
  56. "Likes": [
  57.  
  58. ]
  59. },
  60.  
  61. ]
  62. }
  63.  
  64. import android.content.ClipData;
  65. import android.content.ClipboardManager;
  66. import android.content.Context;
  67. import android.content.Intent;
  68. import android.graphics.Typeface;
  69. import android.support.v7.widget.RecyclerView;
  70. import android.view.LayoutInflater;
  71. import android.view.View;
  72. import android.view.ViewGroup;
  73. import android.widget.ImageView;
  74. import android.widget.TextView;
  75. import android.widget.Toast;
  76.  
  77. import com.like.IconType;
  78. import com.like.LikeButton;
  79. import com.like.OnLikeListener;
  80. import com.squareup.picasso.Picasso;
  81.  
  82. import java.util.ArrayList;
  83.  
  84. import de.hdodenhof.circleimageview.CircleImageView;
  85.  
  86. public class Adapter_Messages extends RecyclerView.Adapter<Adapter_Messages.AdapterHolder>{
  87. ArrayList<Item_Messages> CategoriesList;
  88. Context context;
  89. Intent intent;
  90. Typeface typeface;
  91.  
  92.  
  93.  
  94.  
  95. public Adapter_Messages(Context context , ArrayList<Item_Messages> categories) {
  96. this.context = context;
  97. CategoriesList = categories;
  98. }
  99.  
  100. @Override
  101. public AdapterHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  102. View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_messages,parent,false);
  103. AdapterHolder adapterHolder = new AdapterHolder(v);
  104. typeface = Typeface.createFromAsset(context.getAssets(),"fonts/font-en.otf");
  105. return adapterHolder;
  106. }
  107.  
  108. @Override
  109. public void onBindViewHolder(final AdapterHolder holder, final int position) {
  110. final Item_Messages item_messages = CategoriesList.get(position);
  111. Picasso.with(context).load("https://graph.facebook.com/" + item_messages.userid + "/picture?type=large").into(holder.profile_image_message);
  112. holder.txt_authorname.setText(item_messages.authorname);
  113. holder.txt_message.setText(item_messages.message);
  114. holder.txt_type.setText(item_messages.type);
  115. holder.txt_message.setTypeface(typeface);
  116. holder.txt_type.setTypeface(typeface);
  117. holder.txt_likes.setTypeface(typeface);
  118. holder.txt_authorname.setTypeface(typeface);
  119. holder.likeButton.setIcon(IconType.Thumb);
  120. holder.favoritebutton.setIcon(IconType.Heart);
  121.  
  122. if(item_messages.likes.equals("0"))
  123. {
  124. holder.txt_likes.setText("there are no likes");
  125. }
  126. else{
  127. holder.txt_likes.setText(item_messages.likes + " Likes");
  128. }
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135. holder.img_facebook.setOnClickListener(new View.OnClickListener() {
  136. @Override
  137. public void onClick(View view) {
  138. Toast.makeText(context, "soon", Toast.LENGTH_SHORT).show();
  139. }
  140. });
  141.  
  142.  
  143. holder.img_whatsapp.setOnClickListener(new View.OnClickListener() {
  144. @Override
  145. public void onClick(View view) {
  146. Toast.makeText(context, "soon", Toast.LENGTH_SHORT).show();
  147. }
  148. });
  149.  
  150.  
  151. holder.likeButton.setOnLikeListener(new OnLikeListener() {
  152. @Override
  153. public void liked(LikeButton likeButton) {
  154. if(Information.userid.equals(""))
  155. {
  156. holder.likeButton.setLiked(false);
  157. Toast.makeText(context, "First Login", Toast.LENGTH_SHORT).show();
  158. }
  159. }
  160.  
  161. @Override
  162. public void unLiked(LikeButton likeButton) {
  163. if(Information.userid.equals(""))
  164. {
  165. Toast.makeText(context, "First Login", Toast.LENGTH_SHORT).show();
  166. }
  167. }
  168. });
  169.  
  170.  
  171. holder.favoritebutton.setOnLikeListener(new OnLikeListener() {
  172. @Override
  173. public void liked(LikeButton likeButton) {
  174.  
  175. }
  176.  
  177. @Override
  178. public void unLiked(LikeButton likeButton) {
  179.  
  180. }
  181. });
  182.  
  183.  
  184.  
  185. }
  186.  
  187. @Override
  188. public int getItemCount() {
  189. return CategoriesList.size();
  190. }
  191.  
  192. class AdapterHolder extends RecyclerView.ViewHolder
  193. {
  194.  
  195.  
  196.  
  197. CircleImageView profile_image_message;
  198. TextView txt_message,txt_type,txt_likes,txt_authorname;
  199. LikeButton likeButton,favoritebutton;
  200. ImageView img_copy,img_facebook,img_whatsapp;
  201. public AdapterHolder(View itemView) {
  202. super(itemView);
  203. profile_image_message = (CircleImageView)itemView.findViewById(R.id.profile_image_message);
  204. txt_authorname = (TextView)itemView.findViewById(R.id.txt_authorname);
  205. txt_message = (TextView)itemView.findViewById(R.id.txt_message);
  206. txt_type = (TextView)itemView.findViewById(R.id.txt_type);
  207. txt_likes = (TextView)itemView.findViewById(R.id.txt_likes);
  208. likeButton = (LikeButton)itemView.findViewById(R.id.likebutton);
  209. favoritebutton = (LikeButton)itemView.findViewById(R.id.favoritebutton);
  210. img_copy = (ImageView)itemView.findViewById(R.id.img_copy);
  211. img_facebook = (ImageView)itemView.findViewById(R.id.img_facebook);
  212. img_whatsapp = (ImageView)itemView.findViewById(R.id.img_whatsapp);
  213. }
  214. }
  215.  
  216.  
  217. }
  218.  
  219. import java.util.ArrayList;
  220.  
  221. public class Item_Messages {
  222.  
  223.  
  224. String id,userid,authorname,message,likes,type;
  225.  
  226.  
  227. public Item_Messages(String id, String userid, String authorname, String message, String likes, String type) {
  228. this.id = id;
  229. this.userid = userid;
  230. this.authorname = authorname;
  231. this.message = message;
  232. this.likes = likes;
  233. this.type = type;
  234. }
  235. }
  236.  
  237. import android.content.Intent;
  238. import android.support.v7.app.AppCompatActivity;
  239. import android.os.Bundle;
  240. import android.support.v7.widget.LinearLayoutManager;
  241. import android.support.v7.widget.RecyclerView;
  242. import android.widget.Toast;
  243.  
  244. import com.android.volley.Request;
  245. import com.android.volley.RequestQueue;
  246. import com.android.volley.Response;
  247. import com.android.volley.VolleyError;
  248. import com.android.volley.toolbox.JsonArrayRequest;
  249. import com.android.volley.toolbox.JsonObjectRequest;
  250. import com.android.volley.toolbox.Volley;
  251.  
  252. import org.json.JSONArray;
  253. import org.json.JSONException;
  254. import org.json.JSONObject;
  255.  
  256. import java.util.ArrayList;
  257.  
  258. import es.dmoral.toasty.Toasty;
  259.  
  260. public class ShowMessages extends AppCompatActivity {
  261.  
  262. String type;
  263. ArrayList<Item_Messages> item_messages = new ArrayList<>();
  264. RecyclerView rv_message;
  265.  
  266.  
  267.  
  268.  
  269. @Override
  270. protected void onCreate(Bundle savedInstanceState) {
  271. super.onCreate(savedInstanceState);
  272. setContentView(R.layout.activity_show_messages);
  273.  
  274.  
  275.  
  276.  
  277. Intent intent = getIntent();
  278. type = intent.getStringExtra("type");
  279.  
  280.  
  281.  
  282.  
  283. RequestQueue requestQueue = Volley.newRequestQueue(this);
  284. JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, Information.URL_Messages + type, null, new Response.Listener<JSONObject>() {
  285. @Override
  286. public void onResponse(JSONObject response) {
  287. try {
  288.  
  289.  
  290. for (int x = 0; x < response.getJSONArray("posts").getJSONObject(x).length() ; x++) {
  291. item_messages.add(new Item_Messages(response.getJSONArray("posts").getJSONObject(x).getString("id"),response.getJSONArray("posts").getJSONObject(x).getString("userid"),response.getJSONArray("posts").getJSONObject(x).getString("authorname"),response.getJSONArray("posts").getJSONObject(x).getString("message"),String.valueOf(response.getJSONArray("posts").getJSONObject(x).getJSONArray("Likes").length()),response.getJSONArray("posts").getJSONObject(x).getString("type")));
  292. }
  293. } catch (JSONException e) {
  294. e.printStackTrace();
  295. }
  296. rv_message = (RecyclerView)findViewById(R.id.rv_message);
  297. rv_message.setLayoutManager(new LinearLayoutManager(ShowMessages.this,LinearLayoutManager.VERTICAL,false));
  298. Adapter_Messages adapterview = new Adapter_Messages(ShowMessages.this, item_messages);
  299. rv_message.setAdapter(adapterview);
  300.  
  301. }
  302. }, new Response.ErrorListener() {
  303. @Override
  304. public void onErrorResponse(VolleyError error) {
  305.  
  306. }
  307. });
  308. requestQueue.add(jsonObjectRequest);
  309.  
  310.  
  311.  
  312. }
  313. }
Add Comment
Please, Sign In to add comment