Skip to content

Commit 3ba39d8

Browse files
committed
Minor update
Added more color for the rounded TextView Setting both time and date now, was only setting date
1 parent cbe1eab commit 3ba39d8

10 files changed

Lines changed: 80 additions & 61 deletions

File tree

‎.idea/misc.xml‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎app/build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ dependencies {
2727
compile 'com.android.support:appcompat-v7:23.4.0'
2828
compile 'com.android.support:support-v4:23.4.0'
2929
compile 'com.android.support:design:23.4.0'
30-
compile 'com.wdullaer:materialdatetimepicker:1.4.2'
30+
compile 'com.wdullaer:materialdatetimepicker:3.0.0'
3131
testCompile 'junit:junit:4.12'
3232
}

‎app/src/androidTest/java/com/example/yoga/sqliteexample/ExampleInstrumentedTest.java‎

Lines changed: 0 additions & 26 deletions
This file was deleted.

‎app/src/main/java/com/example/yoga/sqliteexample/Adapter/BillRecyclerViewAdapter.java‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.example.yoga.sqliteexample.Adapter;
22

33
import android.app.Activity;
4+
import android.graphics.drawable.GradientDrawable;
45
import android.support.v7.widget.RecyclerView;
56
import android.view.LayoutInflater;
67
import android.view.View;
@@ -18,6 +19,7 @@
1819
import java.util.ArrayList;
1920
import java.util.List;
2021
import java.util.Locale;
22+
import java.util.Random;
2123

2224

2325
/**
@@ -29,6 +31,7 @@ public class BillRecyclerViewAdapter extends RecyclerView.Adapter<BillRecyclerVi
2931
private List<String> placeList, dateList;
3032
private List<Person> payerList;
3133
private Activity activity;
34+
private int[] colorArr = new int[4];
3235

3336

3437
public interface BillRecyclerInterface {
@@ -50,6 +53,11 @@ public BillRecyclerViewAdapter(Activity activity, List<Bill> billList, List<Pers
5053
placeList.add(b.getPlace());
5154
dateList.add(dateFormat.format(b.getDate()));
5255
}
56+
57+
colorArr[0] = activity.getResources().getColor(R.color.roundedLetter1);
58+
colorArr[1] = activity.getResources().getColor(R.color.roundedLetter2);
59+
colorArr[2] = activity.getResources().getColor(R.color.roundedLetter3);
60+
colorArr[3] = activity.getResources().getColor(R.color.roundedLetter4);
5361
}
5462

5563
public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
@@ -107,8 +115,14 @@ public int getItemCount() {
107115
// Replace the contents of a view (invoked by the layout manager)
108116
@Override
109117
public void onBindViewHolder(BillRecyclerViewAdapter.ViewHolder holder, int position) {
110-
char c = Character.toUpperCase(placeList.get(position).charAt(0));
111-
holder.mTitle.setText(String.valueOf(c));
118+
if (!placeList.get(position).equals("")) {
119+
char c = Character.toUpperCase(placeList.get(position).charAt(0));
120+
holder.mTitle.setText(String.valueOf(c));
121+
122+
holder.mTitle.setBackgroundResource(R.drawable.circle);
123+
GradientDrawable drawable = (GradientDrawable) holder.mTitle.getBackground();
124+
drawable.setColor(colorArr[Character.getNumericValue(c) % 4]);
125+
}
112126

113127
holder.textView_line1.setText(placeList.get(position));
114128
holder.textView_line2.setText(dateList.get(position));

‎app/src/main/java/com/example/yoga/sqliteexample/Fragment/AddBillFragment.java‎

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,27 @@
2121
import com.example.yoga.sqliteexample.R;
2222
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
2323
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog.OnDateSetListener;
24+
import com.wdullaer.materialdatetimepicker.time.TimePickerDialog;
2425

26+
import java.text.SimpleDateFormat;
2527
import java.util.ArrayList;
2628
import java.util.Calendar;
2729
import java.util.Date;
2830
import java.util.GregorianCalendar;
2931
import java.util.List;
32+
import java.util.Locale;
3033

3134
/**
3235
* Created by YOGA on 11/6/2016.
3336
*/
34-
public class AddBillFragment extends Fragment implements OnDateSetListener {
37+
public class AddBillFragment extends Fragment implements OnDateSetListener, TimePickerDialog.OnTimeSetListener {
3538
Spinner spinner_add_bill;
36-
Button button_add_bill_pickdate, button_add_bill_add;
39+
Button button_add_bill_pickdate, button_add_bill_add, button_add_bill_picktime;
3740
EditText editText_add_bill;
38-
private Date date = null;
41+
private Date date = null, time = null;
3942
List<Person> personList;
4043
int payer_id = -1;
4144

42-
4345
public interface AddBillInterface {
4446
List<Person> getAllPeople();
4547
long createBill(Bill bill);
@@ -71,6 +73,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
7173
final View myView = inflater.inflate(R.layout.fragment_add_bill, container, false);
7274
spinner_add_bill = (Spinner) myView.findViewById(R.id.spinner_add_bill);
7375
button_add_bill_pickdate = (Button) myView.findViewById(R.id.button_add_bill_pickdate);
76+
button_add_bill_picktime = (Button) myView.findViewById(R.id.button_add_bill_picktime);
7477
button_add_bill_add = (Button) myView.findViewById(R.id.button_add_bill_add);
7578
editText_add_bill = (EditText) myView.findViewById(R.id.editText_add_bill);
7679

@@ -84,9 +87,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
8487

8588
// Create an ArrayAdapter using the string array and a default spinner layout
8689
ArrayAdapter<String> adapter = new ArrayAdapter<>(myView.getContext(), android.R.layout.simple_spinner_item, personStringList);
87-
// Specify the layout to use when the list of choices appears
8890
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
89-
// Apply the adapter to the spinner
9091
spinner_add_bill.setAdapter(adapter);
9192
spinner_add_bill.setOnItemSelectedListener(new OnItemSelectedListener() {
9293
@Override
@@ -114,6 +115,21 @@ public void onClick(View v) {
114115
}
115116
});
116117

118+
button_add_bill_picktime.setOnClickListener(new View.OnClickListener() {
119+
@Override
120+
public void onClick(View v) {
121+
Calendar now = Calendar.getInstance();
122+
TimePickerDialog tpd = TimePickerDialog.newInstance(
123+
AddBillFragment.this,
124+
now.get(Calendar.HOUR_OF_DAY),
125+
now.get(Calendar.MINUTE),
126+
now.get(Calendar.SECOND),
127+
true
128+
);
129+
tpd.show(getFragmentManager(), "Timepickerdialog");
130+
}
131+
});
132+
117133
button_add_bill_add.setOnClickListener(new View.OnClickListener() {
118134
@Override
119135
public void onClick(View v) {
@@ -123,11 +139,14 @@ public void onClick(View v) {
123139
imm.hideSoftInputFromWindow(myView.getWindowToken(), 0);
124140
}
125141

126-
if (date == null || payer_id == -1) {
142+
if (date == null || time == null || payer_id == -1 || editText_add_bill.getText().toString().equals("")) {
127143
Toast.makeText(myView.getContext(), "Please select date and payer.", Toast.LENGTH_SHORT).show();
128144
} else {
129145
Bill bill = new Bill();
130146
bill.setPlace(editText_add_bill.getText().toString());
147+
date.setHours(time.getHours());
148+
date.setMinutes(time.getMinutes());
149+
date.setSeconds(time.getSeconds());
131150
bill.setDate(date);
132151
bill.setPayer(payer_id);
133152
if(mListener.createBill(bill) == -1) {
@@ -147,6 +166,15 @@ public void onClick(View v) {
147166
public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
148167
Calendar c = new GregorianCalendar(year, monthOfYear, dayOfMonth);
149168
date = c.getTime();
150-
button_add_bill_pickdate.setText(date.toString());
169+
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
170+
button_add_bill_pickdate.setText(dateFormat.format(date));
171+
}
172+
173+
@Override
174+
public void onTimeSet(TimePickerDialog view, int hourOfDay, int minute, int second) {
175+
Calendar c = new GregorianCalendar(0, 0, 0, hourOfDay, minute, second);
176+
time = c.getTime();
177+
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm", Locale.getDefault());
178+
button_add_bill_picktime.setText(dateFormat.format(time));
151179
}
152180
}

‎app/src/main/res/layout/fragment_add_bill.xml‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,26 @@
2323
android:ems="10"
2424
android:id="@+id/editText_add_bill" />
2525

26-
<Button
26+
<LinearLayout
2727
android:layout_width="match_parent"
2828
android:layout_height="wrap_content"
29-
android:text="Pick a date"
30-
android:id="@+id/button_add_bill_pickdate" />
29+
android:orientation="horizontal">
30+
<Button
31+
android:layout_width="0dp"
32+
android:layout_height="wrap_content"
33+
android:layout_weight="1"
34+
android:text="Pick a date"
35+
android:id="@+id/button_add_bill_pickdate" />
36+
37+
<Button
38+
android:layout_width="0dp"
39+
android:layout_height="wrap_content"
40+
android:layout_weight="1"
41+
android:text="Pick a time"
42+
android:id="@+id/button_add_bill_picktime" />
43+
</LinearLayout>
44+
45+
3146

3247
<LinearLayout
3348
android:layout_width="match_parent"

‎app/src/main/res/layout/fragment_list_bill.xml‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
<android.support.v7.widget.RecyclerView
77
android:id="@+id/my_recycler_view"
88
android:scrollbars="vertical"
9-
android:clickable="true"
10-
android:focusable="true"
11-
android:background="?android:attr/selectableItemBackground"
129
android:layout_width="match_parent"
1310
android:layout_height="match_parent">
1411

‎app/src/main/res/layout/listview_layout.xml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
android:layout_height="wrap_content"
66
android:layout_width="match_parent"
77
android:orientation="horizontal"
8+
android:clickable="true"
9+
android:focusable="true"
10+
android:background="?android:attr/selectableItemBackground"
811
android:weightSum="1"
912
android:padding="10sp">
1013
<TextView

‎app/src/main/res/values/colors.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@
99
<color name="icons">#212121</color>
1010
<color name="divider">#BDBDBD</color>
1111

12+
<color name="roundedLetter1">#7c4dff</color>
13+
<color name="roundedLetter2">#03A9F4</color>
14+
<color name="roundedLetter3">#E91E63</color>
15+
<color name="roundedLetter4">#FFEB3B</color>
16+
1217
</resources>

‎app/src/test/java/com/example/yoga/sqliteexample/ExampleUnitTest.java‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)