|
@@ -1,20 +1,24 @@
|
1
|
1
|
package com.rthoni.stssaguenay.ui.fragments;
|
2
|
2
|
|
|
3
|
+import android.content.DialogInterface;
|
3
|
4
|
import android.os.Bundle;
|
4
|
5
|
import android.support.annotation.Nullable;
|
5
|
6
|
import android.support.v4.app.Fragment;
|
|
7
|
+import android.support.v7.app.AlertDialog;
|
6
|
8
|
import android.support.v7.widget.LinearLayoutManager;
|
7
|
9
|
import android.support.v7.widget.RecyclerView;
|
8
|
10
|
import android.view.LayoutInflater;
|
9
|
11
|
import android.view.View;
|
10
|
12
|
import android.view.ViewGroup;
|
11
|
13
|
import android.widget.TextView;
|
|
14
|
+import android.widget.Toast;
|
12
|
15
|
|
13
|
16
|
import com.rthoni.stssaguenay.R;
|
14
|
17
|
import com.rthoni.stssaguenay.business.STSBusiness;
|
15
|
18
|
import com.rthoni.stssaguenay.dbo.FavouriteStopDbo;
|
16
|
19
|
|
17
|
20
|
import java.util.List;
|
|
21
|
+import java.util.Vector;
|
18
|
22
|
|
19
|
23
|
import butterknife.BindView;
|
20
|
24
|
import butterknife.ButterKnife;
|
|
@@ -61,6 +65,13 @@ public class HomeFragment extends Fragment {
|
61
|
65
|
onFavouriteClicked(favouriteStopDbo);
|
62
|
66
|
}
|
63
|
67
|
});
|
|
68
|
+ holder._parentView.setOnLongClickListener(new View.OnLongClickListener() {
|
|
69
|
+ @Override
|
|
70
|
+ public boolean onLongClick(View v) {
|
|
71
|
+ onFavouriteLongClicked(favouriteStopDbo);
|
|
72
|
+ return true;
|
|
73
|
+ }
|
|
74
|
+ });
|
64
|
75
|
}
|
65
|
76
|
|
66
|
77
|
@Override
|
|
@@ -97,6 +108,33 @@ public class HomeFragment extends Fragment {
|
97
|
108
|
|
98
|
109
|
public void onFavouriteClicked(FavouriteStopDbo favouriteStopDbo)
|
99
|
110
|
{
|
|
111
|
+ }
|
100
|
112
|
|
|
113
|
+ public void onFavouriteLongClicked(final FavouriteStopDbo favouriteStopDbo)
|
|
114
|
+ {
|
|
115
|
+ new AlertDialog.Builder(getContext())
|
|
116
|
+ .setIcon(android.R.drawable.ic_dialog_alert)
|
|
117
|
+ .setTitle(R.string.favourite_remove)
|
|
118
|
+ .setMessage(getString(R.string.favourite_remove_confirm, favouriteStopDbo.getStop().getFullName()))
|
|
119
|
+ .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener()
|
|
120
|
+ {
|
|
121
|
+ @Override
|
|
122
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
123
|
+
|
|
124
|
+ List<FavouriteStopDbo> favouriteStopDbos = STSBusiness.getFavouriteStops(getContext());
|
|
125
|
+ for (int i = 0; i < favouriteStopDbos.size(); ++i) {
|
|
126
|
+ if (favouriteStopDbos.get(i).getStop().getId().equals(favouriteStopDbo.getStop().getId())) {
|
|
127
|
+ favouriteStopDbos.remove(i--);
|
|
128
|
+ }
|
|
129
|
+ }
|
|
130
|
+ STSBusiness.setFavouriteStops(getContext(), favouriteStopDbos);
|
|
131
|
+
|
|
132
|
+ Toast.makeText(getContext(), getString(R.string.favourite_removed, favouriteStopDbo.getStop().getFullName()), Toast.LENGTH_LONG).show();
|
|
133
|
+ loadFavourites();
|
|
134
|
+ }
|
|
135
|
+
|
|
136
|
+ })
|
|
137
|
+ .setNegativeButton(android.R.string.no, null)
|
|
138
|
+ .show();
|
101
|
139
|
}
|
102
|
140
|
}
|