Merged JUnit with Master

This commit is contained in:
Batuhan Berk Başoğlu 2018-11-02 11:40:15 -04:00
commit 03558823e9
10 changed files with 193 additions and 45 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

@ -39,6 +39,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 {

View file

@ -45,7 +45,7 @@ public interface NoticeDialogListener {
public void onClick(DialogInterface dialog, int id) {
Bundle args = new Bundle();
//@anshu: get the name and rate to come from the dialog_service_new dialog
args.putString("name", "hey");
args.putString("name", (String)getArguments().get("name"));
args.putDouble("rate", 2.5);
//
EditServiceDialogFragment.this.setArguments(args);
@ -56,12 +56,13 @@ public interface NoticeDialogListener {
public void onClick(DialogInterface dialog, int id) {
Bundle args = new Bundle();
//@anshu: get the name and rate to come from the dialog_service_new dialog
args.putString("name", "hey");
args.putString("name", (String)getArguments().get("name"));
//
EditServiceDialogFragment.this.setArguments(args);
mListener.onDialogDelete(EditServiceDialogFragment.this);
}
});
})
.setTitle((String)getArguments().get("name"));
return builder.create();
}
}

View file

@ -0,0 +1,10 @@
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;

View file

@ -45,7 +45,7 @@ public class NewServiceDialogFragment extends DialogFragment {
public void onClick(DialogInterface dialog, int id) {
Bundle args = new Bundle();
//@anshu: get the name and rate to come from the dialog_service_new dialog
args.putString("name", "hey");
args.putString("name", "test2");
args.putDouble("rate", 2.5);
///
NewServiceDialogFragment.this.setArguments(args);

View file

@ -1,9 +1,15 @@
package com.uottawa.olympus.olympusservices;
import android.content.Context;
import android.support.annotation.NonNull;
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.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
@ -14,39 +20,45 @@ 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<String[]> 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<users.size();i++){
List<String[]> serviceslist = dbHelper.getAllServices();
Service[] services = new Service[(serviceslist.size())];
Iterator iter = serviceslist.iterator();
for (int i=0; i<serviceslist.size();i++){
String[] current = (String[])iter.next();
services[(i+1)*2] = current[0];
services[(i+1)*2+1] = current[1];
services[i] = new Service(current[0], Double.parseDouble(current[1]));
}
ArrayAdapter adapter = new ArrayAdapter<String>(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, this);
mRecyclerView.setAdapter(mAdapter);
}
public void addService(View view) {
DialogFragment newFragment = new NewServiceDialogFragment();
newFragment.show(getSupportFragmentManager(), "addService");
}
public void editService(View view) {
public void editService(View view, String name) {
DialogFragment newFragment = new EditServiceDialogFragment();
newFragment.show(getSupportFragmentManager(), "editService");
Bundle args = new Bundle();
args.putString("name", name);
newFragment.setArguments(args);
}
//add new service
@Override
@ -83,4 +95,70 @@ public class ServicesList extends AppCompatActivity implements NewServiceDialogF
this.recreate();
}
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ServicesHolder> {
private Service[] services;
private Context context;
// 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, Context context) {
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) {
TextView nameview = (TextView)view.findViewById(R.id.Name);
String name = nameview.getText().toString();
editService(view, name);
}
}
}
}

View file

@ -15,7 +15,7 @@
<TextView
android:id="@+id/Welcome"
android:layout_width="300dp"
android:layout_height="80dp"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:gravity="center"
android:text="List of Services"
@ -24,20 +24,48 @@
android:textSize="20sp"
android:layout_marginTop="10dp"
app:fontFamily="@font/julius_sans_one" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:orientation="horizontal"
android:paddingBottom="10dp">
<GridView
android:id="@+id/Services"
android:layout_width="fill_parent"
<TextView
android:id="@+id/Title1"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:layout_height="250dp"
android:numColumns="2"
android:text="Name"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="@android:color/white"
android:textSize="15sp" />
<TextView
android:id="@+id/Title2"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="Hourly Rate"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="@android:color/white"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/Services"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="250dp"/>
</LinearLayout>
<Button
android:id="@+id/newService"

View file

@ -5,21 +5,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content">
//component used from https://github.com/rengwuxian/MaterialEditText
<com.rengwuxian.materialedittext.MaterialEditText
android:id="@+id/NameInput"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginTop="20dp"
android:hint="@string/servicename"
android:textCursorDrawable="@color/colorWhite"
android:textSize="15sp"
app:met_baseColor="@android:color/black"
app:met_floatingLabel="highlight"
app:met_primaryColor="@color/colorBlack"
app:met_singleLineEllipsis="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"/>
//component used from https://github.com/rengwuxian/MaterialEditText
<com.rengwuxian.materialedittext.MaterialEditText

View file

@ -0,0 +1,31 @@
<?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="45dp"
android:clickable="true"
android:background="@drawable/customborder"
android:layout_marginBottom="5dp">
<TextView
android:paddingLeft="10dp"
android:paddingTop="8dp"
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:paddingLeft="10dp"
android:paddingTop="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:textColor="@color/colorWhite"
android:textSize="15sp"/>
</LinearLayout>