trying some wild stuff

This commit is contained in:
IvanaE 2018-11-01 12:49:40 -04:00
parent 674ed9352f
commit 695ab61b15
7 changed files with 137 additions and 27 deletions

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="WizardSettings">
<option name="children">
<map>
<entry key="vectorWizard">
<value>
<PersistentState />
</value>
</entry>
</map>
</option>
</component>
</project>

View file

@ -35,6 +35,7 @@ dependencies {
implementation 'com.jaredrummler:material-spinner:1.2.5' implementation 'com.jaredrummler:material-spinner:1.2.5'
implementation 'com.android.support:design:28.0.0-alpha3' implementation 'com.android.support:design:28.0.0-alpha3'
implementation 'com.rengwuxian.materialedittext:library:2.1.4' implementation 'com.rengwuxian.materialedittext:library:2.1.4'
implementation 'com.android.support:recyclerview-v7:28.0.0'
} }
repositories { repositories {

View file

@ -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<MyAdapter.ServicesHolder> {
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) {
}
}
}

View file

@ -3,6 +3,8 @@ package com.uottawa.olympus.olympusservices;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
@ -14,31 +16,34 @@ import java.util.List;
public class ServicesList extends AppCompatActivity implements NewServiceDialogFragment.NoticeDialogListener, EditServiceDialogFragment.NoticeDialogListener{ public class ServicesList extends AppCompatActivity implements NewServiceDialogFragment.NoticeDialogListener, EditServiceDialogFragment.NoticeDialogListener{
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_services_list); setContentView(R.layout.activity_services_list);
DBHelper dbHelper = new DBHelper(this); DBHelper dbHelper = new DBHelper(this);
List<String[]> users = dbHelper.getAllServices(); List<String[]> serviceslist = dbHelper.getAllServices();
String[] services = new String[(users.size()+1)*2]; Service[] services = new Service[(serviceslist.size())];
services[0] = "Name"; Iterator iter = serviceslist.iterator();
services[1] = "Rate"; for (int i=0; i<serviceslist.size();i++){
Iterator iter = users.iterator();
for (int i=0; i<users.size();i++){
String[] current = (String[])iter.next(); String[] current = (String[])iter.next();
services[(i+1)*2] = current[0]; services[i] = new Service(current[0], Double.parseDouble(current[1]));
services[(i+1)*2+1] = current[1];
} }
ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.simple_list_item_1_customized, services);
GridView gridView = findViewById(R.id.Services); mRecyclerView = (RecyclerView) findViewById(R.id.Services);
gridView.setAdapter(adapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override mLayoutManager = new LinearLayoutManager(this);
public void onItemClick(AdapterView<?> parent, View view, mRecyclerView.setLayoutManager(mLayoutManager);
int position, long id) {
editService(view); mAdapter = new MyAdapter(services);
} mRecyclerView.setAdapter(mAdapter);
});
} }
public void addService(View view) { public void addService(View view) {
DialogFragment newFragment = new NewServiceDialogFragment(); DialogFragment newFragment = new NewServiceDialogFragment();

View file

@ -26,17 +26,13 @@
app:fontFamily="@font/julius_sans_one" /> app:fontFamily="@font/julius_sans_one" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
android:orientation="horizontal">
<GridView <android.support.v7.widget.RecyclerView
android:id="@+id/Services" android:id="@+id/Services"
android:layout_width="fill_parent" android:scrollbars="vertical"
android:layout_weight="1" android:layout_width="match_parent"
android:layout_height="250dp" android:layout_height="match_parent"/>
android:numColumns="2"
android:textColor="@android:color/white"
android:textSize="15sp" />
</LinearLayout> </LinearLayout>
<Button <Button

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:textColor="@color/colorWhite"
android:textSize="15sp"/>
<TextView
android:id="@+id/Rate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:textColor="@color/colorWhite"
android:textSize="15sp"/>
</LinearLayout>