From ed6927b7db7696c0f2dd64c89190e5ff12bce883 Mon Sep 17 00:00:00 2001 From: IvanaE Date: Thu, 1 Nov 2018 12:49:40 -0400 Subject: [PATCH] trying some wild stuff --- OlympusServices/.idea/assetWizardSettings.xml | 14 ++++ .../.idea/caches/build_file_checksums.ser | Bin 537 -> 537 bytes OlympusServices/app/build.gradle | 1 + .../olympus/olympusservices/MyAdapter.java | 70 ++++++++++++++++++ .../olympus/olympusservices/ServicesList.java | 41 +++++----- .../res/layout/activity_services_list.xml | 14 ++-- .../app/src/main/res/layout/list_item.xml | 24 ++++++ 7 files changed, 137 insertions(+), 27 deletions(-) create mode 100644 OlympusServices/.idea/assetWizardSettings.xml create mode 100644 OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/MyAdapter.java create mode 100644 OlympusServices/app/src/main/res/layout/list_item.xml diff --git a/OlympusServices/.idea/assetWizardSettings.xml b/OlympusServices/.idea/assetWizardSettings.xml new file mode 100644 index 0000000..6b96cf0 --- /dev/null +++ b/OlympusServices/.idea/assetWizardSettings.xml @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file diff --git a/OlympusServices/.idea/caches/build_file_checksums.ser b/OlympusServices/.idea/caches/build_file_checksums.ser index 2d1081553c3cf2b2dafd64f2eaf06167f8bf0fe8..279981b2a134d265bb09c0a2497c3c9eef68fb12 100644 GIT binary patch delta 56 zcmV-80LTBC1epYom;}%0<0z4wcMyK%iP%&EV~=8R5)pg}v4oQ&0Ywl~v{%iO{5SlP Onzwq5UREuWcmbitBpC?+ delta 56 zcmV-80LTBC1epYom;}6dwGNS-cMu>+%lW-X^`!p?`h;9GqY;xM0Ywm@mD5OQwx+K- Ou-xT<#7$e1cmbi{ZyLD( diff --git a/OlympusServices/app/build.gradle b/OlympusServices/app/build.gradle index 51596d7..7bdef2b 100644 --- a/OlympusServices/app/build.gradle +++ b/OlympusServices/app/build.gradle @@ -35,6 +35,7 @@ dependencies { implementation 'com.jaredrummler:material-spinner:1.2.5' implementation 'com.android.support:design:28.0.0-alpha3' implementation 'com.rengwuxian.materialedittext:library:2.1.4' + implementation 'com.android.support:recyclerview-v7:28.0.0' } repositories { diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/MyAdapter.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/MyAdapter.java new file mode 100644 index 0000000..fe56680 --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/MyAdapter.java @@ -0,0 +1,70 @@ +package com.uottawa.olympus.olympusservices; + +import android.content.Context; +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +public class MyAdapter extends RecyclerView.Adapter { + + private Service[] services; + + // Provide a reference to the views for each data item + // Complex data items may need more than one view per item, and + // you provide access to all the views for a data item in a view holder + + // Provide a suitable constructor (depends on the kind of dataset) + public MyAdapter(Service[] services) { + this.services = services; + } + + // Create new views (invoked by the layout manager) + @NonNull + @Override + public ServicesHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View v = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.list_item, parent, false); + ServicesHolder vh = new ServicesHolder(v); + return vh; + } + + // Replace the contents of a view (invoked by the layout manager) + @Override + public void onBindViewHolder(ServicesHolder holder, int position) { + Service service = services[position]; + holder.name.setText(service.getName()); + holder.rate.setText(""+service.getRate()); + + + + } + + // Return the size of your dataset (invoked by the layout manager) + @Override + public int getItemCount() { + return services.length; + } + + class ServicesHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ + + TextView name; + TextView rate; + + public ServicesHolder(View row){ + super(row); + name = row.findViewById(R.id.Name); + rate = row.findViewById(R.id.Rate); + row.setOnClickListener(this); + } + @Override + public void onClick(View view) { + } + + + } + + +} diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServicesList.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServicesList.java index 8f29a44..4f9e008 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServicesList.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServicesList.java @@ -3,6 +3,8 @@ package com.uottawa.olympus.olympusservices; import android.support.v4.app.DialogFragment; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; @@ -14,31 +16,34 @@ import java.util.List; public class ServicesList extends AppCompatActivity implements NewServiceDialogFragment.NoticeDialogListener, EditServiceDialogFragment.NoticeDialogListener{ + private RecyclerView mRecyclerView; + private RecyclerView.Adapter mAdapter; + private RecyclerView.LayoutManager mLayoutManager; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_services_list); DBHelper dbHelper = new DBHelper(this); - List users = dbHelper.getAllServices(); - String[] services = new String[(users.size()+1)*2]; - services[0] = "Name"; - services[1] = "Rate"; - Iterator iter = users.iterator(); - for (int i=0; i serviceslist = dbHelper.getAllServices(); + Service[] services = new Service[(serviceslist.size())]; + Iterator iter = serviceslist.iterator(); + for (int i=0; i(this, R.layout.simple_list_item_1_customized, services); - GridView gridView = findViewById(R.id.Services); - gridView.setAdapter(adapter); - gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, - int position, long id) { - editService(view); - } - }); + + mRecyclerView = (RecyclerView) findViewById(R.id.Services); + + + mLayoutManager = new LinearLayoutManager(this); + mRecyclerView.setLayoutManager(mLayoutManager); + + mAdapter = new MyAdapter(services); + mRecyclerView.setAdapter(mAdapter); + + + } public void addService(View view) { DialogFragment newFragment = new NewServiceDialogFragment(); diff --git a/OlympusServices/app/src/main/res/layout/activity_services_list.xml b/OlympusServices/app/src/main/res/layout/activity_services_list.xml index a899d83..e9742e0 100644 --- a/OlympusServices/app/src/main/res/layout/activity_services_list.xml +++ b/OlympusServices/app/src/main/res/layout/activity_services_list.xml @@ -26,17 +26,13 @@ app:fontFamily="@font/julius_sans_one" /> + android:layout_height="wrap_content"> - + android:scrollbars="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"/>