Best Unobtainium_ruby code snippet using Unobtainium.length
PrescriptionsFragment.java
Source:PrescriptionsFragment.java
1package com.development.unobtainium.cimedic2.fragments;2import android.content.Context;3import android.net.Uri;4import android.os.AsyncTask;5import android.os.Bundle;6import android.app.Fragment;7import android.view.LayoutInflater;8import android.view.View;9import android.view.ViewGroup;10import android.widget.ListView;11import android.widget.Toast;12import com.development.unobtainium.cimedic2.R;13import com.development.unobtainium.cimedic2.adapters.PrescriptionsListAdapter;14import com.development.unobtainium.cimedic2.managers.PatientSessionManager;15import com.development.unobtainium.cimedic2.models.Prescription;16import com.development.unobtainium.cimedic2.responses.PrescriptionsResponse;17import com.development.unobtainium.cimedic2.retrofit.ServiceError;18import com.development.unobtainium.cimedic2.retrofit.ServicesInterface;19import com.google.gson.Gson;20import java.io.IOException;21import java.util.ArrayList;22import retrofit2.Call;23import retrofit2.Response;24import retrofit2.Retrofit;25import retrofit2.converter.gson.GsonConverterFactory;26public class PrescriptionsFragment extends Fragment {27 // TODO: Rename parameter arguments, choose names that match28 // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER29 private PrescriptionsTask mPrescriptionsTask = null;30 final String api_endpoint = "https://medic-1.herokuapp.com/api/v1/"; //"http://192.168.1.105:3000/api/v1/";31 private ArrayList<Prescription> prescriptions;32 private ServiceError sError;33 private String error = "";34 private View mProgressView;35 Gson gson;36 ListView listView;37 // TODO: Rename and change types of parameters38 private String mParam1;39 private String mParam2;40 private OnFragmentInteractionListener mListener;41 public PrescriptionsFragment() {42 // Required empty public constructor43 }44 // TODO: Rename and change types and number of parameters45 public static PrescriptionsFragment newInstance() {46 PrescriptionsFragment fragment = new PrescriptionsFragment();47 return fragment;48 }49 public class PrescriptionsTask extends AsyncTask<Void, Void, Boolean> {50 final Context context = getContext();51 PrescriptionsTask() {52 }53 @Override54 protected Boolean doInBackground(Void... params) {55 // TODO: attempt authentication against a network service.56 final String BASE_URL = api_endpoint;57 Retrofit retrofit = new Retrofit.Builder()58 .baseUrl(BASE_URL)59 .addConverterFactory(GsonConverterFactory.create())60 .build();61 ServicesInterface apiService =62 retrofit.create(ServicesInterface.class);63 final Call<PrescriptionsResponse> call = apiService.getPrescriptions(PatientSessionManager.getInstance(getContext()).getLoggedPatientId());64 try {65 Response<PrescriptionsResponse> response = call.execute();66 prescriptions = response.body().prescriptions;67 sError = response.body().error;68 } catch (IOException e) {69 error = e.getMessage();70 }71 return error.isEmpty();72 }73 @Override74 protected void onPostExecute(final Boolean success) {75 mPrescriptionsTask = null;76 showProgress(false);77 if (success) {78 if (sError == null){79// Toast.makeText(getContext(), gson.toJson(schedules), Toast.LENGTH_LONG).show();80 listView = (ListView) getView().findViewById(R.id.prescription_list);81 if (listView != null){82 listView.setAdapter(new PrescriptionsListAdapter(getContext(), prescriptions));83 }84 } else {85 Toast.makeText(getContext(), sError.getDescription(), Toast.LENGTH_SHORT).show();86 }87 } else{88 Toast.makeText(getContext(), error, Toast.LENGTH_LONG).show();89 }90 }91 @Override92 protected void onCancelled() {93 mPrescriptionsTask = null;94 showProgress(false);95 }96 }97 @Override98 public void onActivityCreated(Bundle savedInstanceState) {99 listView = (ListView) getView().findViewById(R.id.prescription_list);100 mProgressView = getView().findViewById(R.id.prescription_progress);101 showProgress(true);102 mPrescriptionsTask = new PrescriptionsTask();103 mPrescriptionsTask.execute((Void) null);104 super.onActivityCreated(savedInstanceState);105 }106 @Override107 public void onCreate(Bundle savedInstanceState) {108 super.onCreate(savedInstanceState);109 }110 private void showProgress(final boolean show) {111 mProgressView.setVisibility(show ? View.VISIBLE : View.INVISIBLE);112 }113 @Override114 public View onCreateView(LayoutInflater inflater, ViewGroup container,115 Bundle savedInstanceState) {116 // Inflate the layout for this fragment117 return inflater.inflate(R.layout.fragment_prescriptions, container, false);118 }119 // TODO: Rename method, update argument and hook method into UI event120 public void onButtonPressed(Uri uri) {121 if (mListener != null) {122 mListener.onFragmentInteraction(uri);123 }124 }125 @Override126 public void onAttach(Context context) {127 super.onAttach(context);128 if (context instanceof OnFragmentInteractionListener) {129 mListener = (OnFragmentInteractionListener) context;130 } else {131 throw new RuntimeException(context.toString()132 + " must implement OnFragmentInteractionListener");133 }134 }135 @Override136 public void onDetach() {137 super.onDetach();138 mListener = null;139 }140 /**141 * This interface must be implemented by activities that contain this142 * fragment to allow an interaction in this fragment to be communicated143 * to the activity and potentially other fragments contained in that144 * activity.145 * <p>146 * See the Android Training lesson <a href=147 * "http://developer.android.com/training/basics/fragments/communicating.html"148 * >Communicating with Other Fragments</a> for more information.149 */150 public interface OnFragmentInteractionListener {151 // TODO: Update argument type and name152 void onFragmentInteraction(Uri uri);153 }154}...
SchedulesListAdapter.java
Source:SchedulesListAdapter.java
1package com.development.unobtainium.cimedic2.adapters;2import android.app.Activity;3import android.app.FragmentManager;4import android.app.FragmentTransaction;5import android.content.Context;6import android.graphics.Color;7import android.graphics.PorterDuff;8import android.graphics.drawable.Drawable;9import android.graphics.drawable.shapes.Shape;10import android.view.LayoutInflater;11import android.view.View;12import android.view.ViewGroup;13import android.widget.BaseAdapter;14import android.widget.TextView;15import android.widget.Toast;16import com.development.unobtainium.cimedic2.R;17import com.development.unobtainium.cimedic2.fragments.AppointmentPreviewFragment;18import com.development.unobtainium.cimedic2.fragments.SchedulesFragment;19import com.development.unobtainium.cimedic2.managers.PatientSessionManager;20import com.development.unobtainium.cimedic2.models.Doctor;21import com.development.unobtainium.cimedic2.models.Patient;22import com.development.unobtainium.cimedic2.models.Schedule;23import java.util.ArrayList;24import java.util.Collections;25import java.util.Comparator;26/**27 * Created by Kevin on 10/11/16.28 */29public class SchedulesListAdapter extends BaseAdapter {30 private Context mContext;31 private SchedulesFragment sFragment;32 private ArrayList<Schedule> schedulesList = new ArrayList<Schedule>();33 public SchedulesListAdapter(Context mContext, ArrayList<Schedule> schedulesList, SchedulesFragment fragment) {34 this.mContext = mContext;35// this.dFragment = fragment;36// if (schedulesList.size() > 1) {37// Collections.sort(schedulesList, new Comparator<Schedule>() {38// public int compare(Schedule sch1, Schedule sch2) {39// // ## Ascending order40// return Integer.getInteger(sch1.getStart()) - Integer.getInteger(sch2.getStart());41// }42// });43// }44 this.sFragment = fragment;45 this.schedulesList = schedulesList;46 }47 @Override48 public int getCount() {49 return schedulesList.size();50 }51 @Override52 public Object getItem(int position) {53 return null;54 }55 @Override56 public long getItemId(int position) {57 return 0;58 }59 public class Holder {60 TextView text;61 }62 @Override63 public View getView(final int position, View convertView, ViewGroup parent) {64 Holder holder = new Holder();65 View row;66 row = LayoutInflater.from(parent.getContext()).inflate(R.layout.schedule_item, parent, false);67// String loggedPatientId = PatientSessionManager.getInstance(parent.getContext()).getLoggedPatientId();68 holder.text = (TextView) row.findViewById(R.id.scheduleText);69 holder.text.setText(schedulesList.get(position).hoursString());70 if (schedulesList.get(position).taken){71 row.setBackground(parent.getResources().getDrawable(R.drawable.red_rounded_text_view));72 holder.text.setTextColor(Color.WHITE);73 } else {74 row.setBackground(parent.getResources().getDrawable(R.drawable.rounded_text_view));75 }76 row.setOnClickListener(new View.OnClickListener() {77 @Override78 public void onClick(View v) {79 if (schedulesList.get(position).taken){80 Toast.makeText(mContext, "Este horario ya ha sido reservado", Toast.LENGTH_SHORT).show();81 } else {82 FragmentManager fm = ((Activity) mContext).getFragmentManager();83 FragmentTransaction ft = fm.beginTransaction();84 AppointmentPreviewFragment llf = AppointmentPreviewFragment.newInstance(sFragment, PatientSessionManager.getInstance(mContext).getLoggedPatientName(), PatientSessionManager.getInstance(mContext).getLoggedPatientImage(), schedulesList.get(position));85 ft.replace(R.id.currentFragment, llf);86 ft.addToBackStack(null);87 ft.commit();88 }89 }90 });91 return row;92 }93}...
Item.java
Source:Item.java
...43 public String toString() {44 return displayName;45 }46 public static void init(){47 LogManager.getLogger(Item.class).info("Items loaded: " + values().length);48 }49}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!