Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///CUSTOM ADAPTER
- package com.example.cristinica.foodhelper;
- /**
- * Created by alex on 3/24/2018.
- */
- import android.content.Context;
- import android.content.Intent;
- import android.support.v7.widget.RecyclerView;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ImageView;
- import android.widget.TextView;
- import com.example.cristinica.foodhelper.models.Companys;
- import java.util.ArrayList;
- public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.MyViewHolder> {
- private ArrayList<Companys> dataSet;
- public static class MyViewHolder extends RecyclerView.ViewHolder {
- TextView textViewName;
- TextView textViewDescriere;
- TextView textViewDates;
- TextView textViewLocatie;
- ImageView coperta;
- public Context context;
- public MyViewHolder(View itemView) {
- super(itemView);
- this.textViewName = (TextView) itemView.findViewById(R.id.titlu);
- this.textViewDescriere = (TextView) itemView.findViewById(R.id.descriere);
- this.textViewDates = (TextView) itemView.findViewById(R.id.dates);
- this.textViewLocatie = (TextView) itemView.findViewById(R.id.locatie);
- this.coperta = (ImageView) itemView.findViewById(R.id.coperta);
- }
- }
- public CustomAdapter(ArrayList<Companys> data) {
- this.dataSet = data;
- }
- @Override
- public MyViewHolder onCreateViewHolder(ViewGroup parent,
- int viewType) {
- View view = LayoutInflater.from(parent.getContext())
- .inflate(R.layout.cards_layout, parent, false);
- MyViewHolder myViewHolder = new MyViewHolder(view);
- return myViewHolder;
- }
- @Override
- public void onBindViewHolder(final MyViewHolder holder, final int listPosition) {
- TextView textViewName = holder.textViewName;
- TextView textViewDescriere = holder.textViewDescriere;
- TextView textViewDates = holder.textViewDates;
- TextView textViewLocatie = holder.textViewLocatie;
- ImageView coperta = holder.coperta;
- textViewName.setText(dataSet.get(listPosition).adresa);
- textViewDescriere.setText(dataSet.get(listPosition).nume_reprezentant);
- textViewDates.setText(dataSet.get(listPosition).nume);
- textViewLocatie.setText(dataSet.get(listPosition).telefon);
- coperta.setImageResource(R.drawable.background);
- holder.itemView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent intent=new Intent(v.getContext(), FoodDetails.class);
- intent.putExtra("position",listPosition);
- v.getContext().startActivity(intent);
- }
- } );
- }
- @Override
- public int getItemCount() {
- return dataSet.size();
- }
- }
- //// FOOD DETAILS
- package com.example.cristinica.foodhelper;
- import android.Manifest;
- import android.content.Intent;
- import android.content.pm.PackageManager;
- import android.net.Uri;
- import android.support.v4.app.ActivityCompat;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.ListAdapter;
- import android.widget.ListView;
- import android.widget.TextView;
- import com.example.cristinica.foodhelper.models.Companys;
- import com.example.cristinica.foodhelper.models.Food;
- import org.w3c.dom.Text;
- import java.util.ArrayList;
- public class FoodDetails extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_food_details);
- getSupportActionBar().setTitle("Details");
- TextView name = findViewById(R.id.textView2);
- TextView locatie = findViewById(R.id.textView8);
- TextView telefon = findViewById(R.id.textView9);
- TextView persoana = findViewById(R.id.textView10);
- Intent intent = getIntent();
- int position = intent.getIntExtra("position", -1);
- final Companys companys = SearchFood.arr.get(position);
- name.setText(companys.nume);
- locatie.setText(companys.adresa);
- telefon.setText(companys.telefon);
- persoana.setText(companys.nume_reprezentant);
- findViewById(R.id.call).setBackgroundDrawable(getResources().getDrawable(R.drawable.round2));
- findViewById(R.id.go_to).setBackgroundDrawable(getResources().getDrawable(R.drawable.round2));
- ArrayList<Food> foods;
- ListAdapter adapter;
- ListView listView;
- listView = findViewById(R.id.list);
- adapter = new SecondListAdapter(FoodDetails.this, companys.foods);
- listView.setAdapter(adapter);
- Button call = findViewById(R.id.call);
- call.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- String phone = companys.telefon;
- Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", phone, null));
- startActivity(intent);
- }
- });
- Button goTo = findViewById(R.id.go_to);
- goTo.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- // Uri gmmIntentUri = Uri.parse("geo:0,0?q=1600 Amphitheatre Parkway, Mountain+View, California");
- String[] arr = companys.adresa.split(" ");
- Uri gmmIntentUri = Uri.parse("geo:0,0?q=" + companys.adresa);
- Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
- mapIntent.setPackage("com.google.android.apps.maps");
- startActivity(mapIntent);
- }
- });
- }
- }
- ///// MAIN
- package com.example.cristinica.foodhelper;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.RelativeLayout;
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- RelativeLayout help = findViewById(R.id.share_food);
- RelativeLayout need = findViewById(R.id.need_food);
- SharedPreferences sharedPreferences = MainActivity.this.getSharedPreferences("type", Context
- .MODE_PRIVATE);
- final SharedPreferences.Editor editor = sharedPreferences.edit();
- SharedPreferences sharedPreferences2 = MainActivity.this.getSharedPreferences("logged", Context
- .MODE_PRIVATE);
- int logged = sharedPreferences2.getInt("logged", -1);
- int type = sharedPreferences.getInt("type", -1);
- if (logged == 1 && type == 0) {
- Intent intent = new Intent(MainActivity.this, GiverActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
- startActivity(intent);
- } else if (logged == 1 && type == 1) {
- Intent intent = new Intent(MainActivity.this, ReceiverActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
- startActivity(intent);
- }
- //companie
- help.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- editor.putInt("type", 0);
- editor.apply();
- Intent intent = new Intent(MainActivity.this, Login.class);
- startActivity(intent);
- }
- });
- //azil
- need.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- editor.putInt("type", 1);
- editor.apply();
- Intent intent = new Intent(MainActivity.this, Login.class);
- startActivity(intent);
- }
- });
- }
- }
- /// SEARCH FOOD
- package com.example.cristinica.foodhelper;
- import android.annotation.SuppressLint;
- import android.content.Context;
- import android.net.Uri;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.support.v4.app.Fragment;
- import android.support.v4.widget.SwipeRefreshLayout;
- import android.support.v7.widget.DefaultItemAnimator;
- import android.support.v7.widget.LinearLayoutManager;
- import android.support.v7.widget.RecyclerView;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import com.example.cristinica.foodhelper.CustomAdapter;
- import com.example.cristinica.foodhelper.apiConnector.GetFoodApi;
- import com.example.cristinica.foodhelper.models.Companys;
- import com.example.cristinica.foodhelper.models.Food;
- import com.google.gson.Gson;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.io.IOException;
- import java.util.ArrayList;
- public class SearchFood extends Fragment {
- public static ArrayList<Companys> arr = new ArrayList<>();
- private RecyclerView.LayoutManager layoutManager;
- SwipeRefreshLayout swipeRefreshLayout;
- CustomAdapter adapter;
- RecyclerView recyclerView;
- View view;
- static public ArrayList<Companys> events = new ArrayList<Companys>();
- // TODO: Rename parameter arguments, choose names that match
- // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
- private static final String ARG_PARAM1 = "param1";
- private static final String ARG_PARAM2 = "param2";
- // TODO: Rename and change types of parameters
- private String mParam1;
- private String mParam2;
- private OnFragmentInteractionListener mListener;
- public SearchFood() {
- // Required empty public constructor
- }
- /**
- * Use this factory method to create a new instance of
- * this fragment using the provided parameters.
- *
- * @param param1 Parameter 1.
- * @param param2 Parameter 2.
- * @return A new instance of fragment FoodFragment.
- */
- // TODO: Rename and change types and number of parameters
- public static FoodFragment newInstance(String param1, String param2) {
- FoodFragment fragment = new FoodFragment();
- Bundle args = new Bundle();
- args.putString(ARG_PARAM1, param1);
- args.putString(ARG_PARAM2, param2);
- fragment.setArguments(args);
- return fragment;
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- if (getArguments() != null) {
- mParam1 = getArguments().getString(ARG_PARAM1);
- mParam2 = getArguments().getString(ARG_PARAM2);
- }
- }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- // Inflate the layout for this fragment
- view = inflater.inflate(R.layout.fragment_search_food, container, false);
- recyclerView = (RecyclerView) view.findViewById(R.id.my_recycler_view);
- swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipeRefreshLayout);
- @SuppressLint("StaticFieldLeak") AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
- @Override
- protected Void doInBackground(Void... params) {
- /* String s = ApiConnectionGetEvents.getEvents();
- Log.v("am primit la get Events", s);
- Gson g = new Gson();
- events = g.fromJson(s, new TypeToken<ArrayList<Event>>(){}.getType());*/
- try {
- String s = GetFoodApi.getAllFood();
- Gson g = new Gson();
- JSONArray jsonArray = new JSONArray(s);
- Companys companys = new Companys();
- for (int i = 0; i < jsonArray.length(); i++) {
- JSONObject jsonObject = jsonArray.getJSONObject(i);
- companys = g.fromJson(jsonObject.toString(), Companys.class);
- JSONArray jsonArray1 = jsonObject.getJSONArray("produse");
- for (int j = 0; j < jsonArray1.length(); j++){
- Food food = new Food();
- food = g.fromJson(jsonArray1.get(j).toString(), Food.class);
- companys.foods.add(food);
- }
- arr.add(companys);
- }
- } catch (IOException e) {
- e.printStackTrace();
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return null;
- }
- @Override
- protected void onPostExecute(Void aVoid) {
- super.onPostExecute(aVoid);
- recyclerView.setHasFixedSize(true);
- layoutManager = new LinearLayoutManager(getContext());
- recyclerView.setLayoutManager(layoutManager);
- recyclerView.setItemAnimator(new DefaultItemAnimator());
- // removedItems = new ArrayList<Integer>();
- adapter = new CustomAdapter(arr);
- recyclerView.setAdapter(adapter);
- }
- };
- task.execute();
- swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
- @Override
- public void onRefresh() {
- }
- });
- return view;
- }
- // TODO: Rename method, update argument and hook method into UI event
- public void onButtonPressed(Uri uri) {
- if (mListener != null) {
- mListener.onFragmentInteraction(uri);
- }
- }
- @Override
- public void onAttach(Context context) {
- super.onAttach(context);
- if (context instanceof OnFragmentInteractionListener) {
- mListener = (OnFragmentInteractionListener) context;
- } else {
- throw new RuntimeException(context.toString()
- + " must implement OnFragmentInteractionListener");
- }
- }
- @Override
- public void onDetach() {
- super.onDetach();
- mListener = null;
- }
- /**
- * This interface must be implemented by activities that contain this
- * fragment to allow an interaction in this fragment to be communicated
- * to the activity and potentially other fragments contained in that
- * activity.
- * <p>
- * See the Android Training lesson <a href=
- * "http://developer.android.com/training/basics/fragments/communicating.html"
- * >Communicating with Other Fragments</a> for more information.
- */
- public interface OnFragmentInteractionListener {
- // TODO: Update argument type and name
- void onFragmentInteraction(Uri uri);
- }
- }
- ///SECOND LIST ADAPTER
- package com.example.cristinica.foodhelper;
- import android.content.Context;
- import android.support.design.widget.Snackbar;
- import android.support.v7.widget.RecyclerView;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ArrayAdapter;
- import android.widget.BaseAdapter;
- import android.widget.ImageView;
- import android.widget.TextView;
- import com.example.cristinica.foodhelper.models.Companys;
- import com.example.cristinica.foodhelper.models.Food;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * Created by alex on 3/24/2018.
- */
- public class SecondListAdapter extends BaseAdapter {
- private Context context;
- private ArrayList<Food> orderName;
- public SecondListAdapter(Context context, ArrayList<Food> orderName){
- this.context = context;
- this.orderName = orderName;
- }
- @Override
- public int getCount() {
- return orderName.size();
- }
- @Override
- public Object getItem(int position) {
- return orderName.get(position);
- }
- @Override
- public long getItemId(int position) {
- return 0;
- }
- @Override
- public View getView(final int position, View convertView, ViewGroup parent) {
- final View listView;
- final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- listView = inflater.inflate(R.layout.list_layout, null);
- TextView name = (TextView) listView.findViewById(R.id.nameFood);
- TextView data = (TextView) listView.findViewById(R.id.dateFood);
- TextView cantitate = (TextView) listView.findViewById(R.id.cantitateFood);
- TextView um = (TextView) listView.findViewById(R.id.umFood);
- ImageView imageView = listView.findViewById(R.id.item_info);
- //imageView.setAlpha(0);
- name.setText(orderName.get(position).nume);
- data.setText(orderName.get(position).data_expirare);
- cantitate.setText(String.valueOf(orderName.get(position).cantitate));
- um.setText(orderName.get(position).um);
- imageView.setAlpha(0);
- return listView;
- }
- }
- //// ACTIVITY FOOD DETAILS
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context="com.example.cristinica.foodhelper.FoodDetails">
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="220dp"
- android:layout_marginTop="5dp">
- <ImageView
- android:id="@+id/imageView5"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true"
- android:layout_alignParentTop="true"
- android:layout_marginLeft="18dp"
- android:layout_marginStart="18dp"
- android:layout_marginTop="13dp"
- app:srcCompat="@drawable/user_name" />
- <TextView
- android:id="@+id/textView2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBottom="@+id/imageView5"
- android:layout_marginLeft="23dp"
- android:layout_marginStart="23dp"
- android:layout_toEndOf="@+id/imageView5"
- android:layout_toRightOf="@+id/imageView5"
- android:text="nume" />
- <ImageView
- android:id="@+id/imageView7"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/imageView5"
- android:layout_alignStart="@+id/imageView5"
- android:layout_below="@+id/textView2"
- android:layout_marginTop="12dp"
- app:srcCompat="@drawable/placeholder" />
- <TextView
- android:id="@+id/textView8"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBottom="@+id/imageView7"
- android:layout_alignLeft="@+id/textView2"
- android:layout_alignStart="@+id/textView2"
- android:text="locatie" />
- <ImageView
- android:id="@+id/imageView8"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignEnd="@+id/imageView7"
- android:layout_alignRight="@+id/imageView7"
- android:layout_centerVertical="true"
- app:srcCompat="@drawable/smartphone_call" />
- <TextView
- android:id="@+id/textView9"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBottom="@+id/imageView8"
- android:layout_alignLeft="@+id/textView8"
- android:layout_alignStart="@+id/textView8"
- android:text="tele" />
- <ImageView
- android:id="@+id/imageView9"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignEnd="@+id/imageView8"
- android:layout_alignRight="@+id/imageView8"
- android:layout_below="@+id/textView9"
- app:srcCompat="@drawable/user_name" />
- <TextView
- android:id="@+id/textView10"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBottom="@+id/imageView9"
- android:layout_alignLeft="@+id/textView9"
- android:layout_alignStart="@+id/textView9"
- android:text="persoana" />
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="75dp"
- android:layout_marginTop="155dp">
- <Button
- android:id="@+id/go_to"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentEnd="true"
- android:layout_alignParentRight="true"
- android:layout_marginRight="30dp"
- android:layout_marginTop="10dp"
- android:text="GO TO"
- android:textColor="@color/button_text_color" />
- <Button
- android:id="@+id/call"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBaseline="@+id/go_to"
- android:layout_alignBottom="@+id/go_to"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true"
- android:layout_marginLeft="29dp"
- android:layout_marginStart="29dp"
- android:layout_marginTop="10dp"
- android:text="Call"
- android:textColor="@color/button_text_color" />
- </RelativeLayout>
- </RelativeLayout>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:layout_marginTop="235dp"
- android:padding="10dp">
- <ListView
- android:id="@+id/list"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
- </RelativeLayout>
- </RelativeLayout>
- ////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement