Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.62 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2.  
  3. private RecyclerView recyclerView;
  4. private ProgressBar progressBar;
  5. private LinearLayoutManager mLayoutManager;
  6. private ArrayList<Model> list;
  7. private RecyclerViewAdapter adapter;
  8. private static List<Recipe>mListrecipe;
  9.  
  10. String url = "https://d17h27t6h515a5.cloudfront.net/";
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.activity_main);
  15.  
  16. recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
  17. progressBar = (ProgressBar) findViewById(R.id.progressbar);
  18.  
  19. mLayoutManager = new LinearLayoutManager(MainActivity.this, LinearLayoutManager.VERTICAL, false);
  20. recyclerView.setLayoutManager(mLayoutManager);
  21.  
  22. /// create a list--
  23. list = new ArrayList<>();
  24. /// get the list from json file
  25. getRetrofitArray();
  26.  
  27. adapter = new RecyclerViewAdapter( list, MainActivity.this);
  28. // set adapter to recyclerview
  29. recyclerView.setAdapter(adapter);
  30.  
  31. }
  32.  
  33. public void getRetrofitArray(){
  34.  
  35. Retrofit retrofit = new Retrofit.Builder()
  36. .baseUrl(url)
  37. .addConverterFactory(GsonConverterFactory.create())
  38. .build();
  39.  
  40. RetrofitArrayAPI service = retrofit.create(RetrofitArrayAPI.class);
  41. Call<List<Recipe>> call = service.getRecipeDetails();
  42. call.enqueue(new Callback<List<Recipe>>() {
  43. @Override
  44. public void onResponse(Call<List<Recipe>> call, Response<List<Recipe>> response) {
  45. Log.e("main ", " retrofit response "+ response.body().toString());
  46. mListrecipe=response.body();
  47. for (int i=0; i<response.body().size();i++){
  48. Log.e("main ", " name "+ response.body().get(i).getName() + " serving "+
  49. response.body().get(i).getServings());
  50. list.add( new Model( Model.IMAGE_TYPE,response.body(), response.body().get(i).getName() ,
  51. " Serving " +response.body().get(i).getServings() ) );
  52.  
  53. }
  54. adapter.notifyDataSetChanged();
  55.  
  56. }
  57.  
  58. @Override
  59. public void onFailure(Call<List<Recipe>> call, Throwable t) {
  60. Log.e("main ", " retrofit error "+ t.toString());
  61. }
  62. });
  63.  
  64.  
  65.  
  66. }
  67.  
  68. public static List<Recipe>getList(){
  69. return mListrecipe;
  70. }
  71. }
  72.  
  73. public class RecyclerViewAdapter extends RecyclerView.Adapter {
  74.  
  75. private ArrayList<Model> dataset;
  76. private Context mContext;
  77. public RecyclerViewAdapter(ArrayList<Model> mlist, Context context) {
  78. this.dataset = mlist;
  79. this.mContext = context;
  80. }
  81.  
  82. public static class ImageTypeViewHolder extends RecyclerView.ViewHolder{
  83.  
  84. ImageView imageView;
  85. TextView title, subtitle;
  86. public ImageTypeViewHolder(View itemView) {
  87. super(itemView);
  88.  
  89. this.title = (TextView) itemView.findViewById(R.id.title);
  90. this.subtitle = (TextView) itemView.findViewById(R.id.subtitle);
  91. this.imageView=(ImageView)itemView.findViewById(R.id.imageview);
  92.  
  93.  
  94. }
  95. }
  96. @Override
  97. public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  98. View view = LayoutInflater.from( parent.getContext()).inflate(R.layout.itemlist, parent, false);
  99. return new ImageTypeViewHolder(view) ;
  100. }
  101.  
  102. @Override
  103. public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
  104. Model object = dataset.get(position);
  105.  
  106. ( (ImageTypeViewHolder) holder).title.setText( object.title );
  107. ( (ImageTypeViewHolder) holder).subtitle.setText( object.subtitle );
  108. /// dataset.get(position)
  109. ( (ImageTypeViewHolder) holder).title.setOnClickListener(new View.OnClickListener() {
  110. @Override
  111. public void onClick(View view) {
  112. Intent intent=new Intent(mContext,SelectReceipe.class);
  113. intent.putExtra("itempostion",position);
  114. mContext.startActivity(intent);
  115. }
  116. });
  117. ( (ImageTypeViewHolder) holder).subtitle.setOnClickListener(new View.OnClickListener() {
  118. @Override
  119. public void onClick(View view) {
  120. Intent intent=new Intent(mContext,SelectReceipe.class);
  121. intent.putExtra("itempostion",position);
  122.  
  123. mContext.startActivity(intent);
  124. }
  125. });
  126. ( (ImageTypeViewHolder) holder).imageView.setOnClickListener(new View.OnClickListener() {
  127. @Override
  128. public void onClick(View view) {
  129. Intent intent=new Intent(mContext,SelectReceipe.class);
  130. intent.putExtra("itempostion",position);
  131.  
  132. mContext.startActivity(intent);
  133. }
  134. });
  135.  
  136. }
  137.  
  138. @Override
  139. public int getItemCount() {
  140. return dataset.size() ;
  141. }
  142. }
  143.  
  144. List<Recipe>sListRecipe;
  145. public int itempostion;
  146. private String TAG;
  147. protected void onCreate(Bundle savedInstanceState) {
  148. super.onCreate(savedInstanceState);
  149. setContentView(R.layout.selectreceipe);
  150.  
  151. sListRecipe=MainActivity.getList();
  152. Intent i =getIntent();
  153. itempostion= i.getExtras().getInt("itempostion");
  154. Log.e(TAG,"itempostion"+String.valueOf(itempostion)+"valou"+sListRecipe.get(itempostion).getName().toString());
  155.  
  156. }
  157.  
  158. [ 09-26 13:34:42.931 31852:31852 D/ ]
  159. HostConnection::get() New Host Connection established 0xb7f81e90, tid 31852
  160. 09-26 13:34:43.019 31852-31852/blueappsoftware.mybakingtips D/libEGL: loaded /system/lib/egl/libGLESv1_CM_genymotion.so
  161. 09-26 13:34:43.035 31852-31852/blueappsoftware.mybakingtips D/libEGL: loaded /system/lib/egl/libGLESv2_genymotion.so
  162. 09-26 13:34:43.111 31852-31852/blueappsoftware.mybakingtips W/EGL_genymotion: eglSurfaceAttrib not implemented
  163. 09-26 13:34:43.127 31852-31852/blueappsoftware.mybakingtips D/OpenGLRenderer: Enabling debug mode 0
  164. 09-26 13:34:43.183 31852-31852/blueappsoftware.mybakingtips D/OpenGLRenderer: TextureCache::get: create texture(0xb7fa1438): name, size, mSize = 1, 4096, 4096
  165. 09-26 13:34:43.339 31852-31877/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
  166. 09-26 13:34:43.343 31852-31877/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
  167. 09-26 13:34:43.343 31852-31877/blueappsoftware.mybakingtips I/dalvikvm: Could not find method java.nio.file.Files.newOutputStream, referenced from method okio.Okio.sink
  168. 09-26 13:34:43.343 31852-31877/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to resolve static method 22787: Ljava/nio/file/Files;.newOutputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/OutputStream;
  169. 09-26 13:34:43.343 31852-31877/blueappsoftware.mybakingtips D/dalvikvm: VFY: replacing opcode 0x71 at 0x000a
  170. 09-26 13:34:43.343 31852-31877/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
  171. 09-26 13:34:43.343 31852-31877/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
  172. 09-26 13:34:43.343 31852-31877/blueappsoftware.mybakingtips I/dalvikvm: Could not find method java.nio.file.Files.newInputStream, referenced from method okio.Okio.source
  173. 09-26 13:34:43.343 31852-31877/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to resolve static method 22786: Ljava/nio/file/Files;.newInputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/InputStream;
  174. 09-26 13:34:43.343 31852-31877/blueappsoftware.mybakingtips D/dalvikvm: VFY: replacing opcode 0x71 at 0x000a
  175. 09-26 13:34:43.567 31852-31853/blueappsoftware.mybakingtips D/dalvikvm: GC_CONCURRENT freed 279K, 4% free 11121K/11527K, paused 24ms+10ms, total 38ms
  176. 09-26 13:34:44.079 31852-31852/blueappsoftware.mybakingtips E/main: retrofit response [blueappsoftware.mybakingtips.Recipe@536b4c20, blueappsoftware.mybakingtips.Recipe@536c68ec, blueappsoftware.mybakingtips.Recipe@536c1a24, blueappsoftware.mybakingtips.Recipe@536e27b8]
  177. 09-26 13:34:44.079 31852-31852/blueappsoftware.mybakingtips E/main: name Nutella Pie serving 8
  178. 09-26 13:34:44.079 31852-31852/blueappsoftware.mybakingtips E/main: name Brownies serving 8
  179. 09-26 13:34:44.079 31852-31852/blueappsoftware.mybakingtips E/main: name Yellow Cake serving 8
  180. 09-26 13:34:44.079 31852-31852/blueappsoftware.mybakingtips E/main: name Cheesecake serving 8
  181. 09-26 13:34:44.119 31852-31853/blueappsoftware.mybakingtips D/dalvikvm: GC_CONCURRENT freed 217K, 4% free 11298K/11655K, paused 15ms+0ms, total 20ms
  182. 09-26 13:34:44.179 31852-31852/blueappsoftware.mybakingtips D/OpenGLRenderer: TextureCache::get: create texture(0xb7f36950): name, size, mSize = 9, 33856, 37952
  183. 09-26 13:34:48.955 31852-31852/blueappsoftware.mybakingtips W/EGL_genymotion: eglSurfaceAttrib not implemented
  184. 09-26 13:34:48.955 31852-31852/blueappsoftware.mybakingtips E/RecyclerView: No adapter attached; skipping layout
  185. 09-26 13:34:48.967 31852-31852/blueappsoftware.mybakingtips E/RecyclerView: No adapter attached; skipping layout
  186. 09-26 13:52:03.367 31852-31853/blueappsoftware.mybakingtips D/dalvikvm: GC_CONCURRENT freed 332K, 4% free 11375K/11847K, paused 6ms+1ms, total 16ms
  187. 09-26 14:16:49.627 31852-31853/blueappsoftware.mybakingtips D/dalvikvm: GC_CONCURRENT freed 426K, 5% free 11345K/11911K, paused 9ms+0ms, total 9ms
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement