-
Notifications
You must be signed in to change notification settings - Fork 0
/
Home.java
264 lines (238 loc) · 10.9 KB
/
Home.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
package com.example.trainbook;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class Home extends AppCompatActivity
implements CallbackInterface {
user currentUser;
private DrawerLayout drawer;
private FragmentManager fragmentManager;
private FragmentTransaction fragmentTransaction;
private FirstFragment firstFragment;
private SecondFragment secondFragment;
private Ticket_fragment ticketFragment;
private Schedule_fragment scheduleFragment;
private Help_fragment helpFragment;
private ContactFragment contactFragment;
private TicketView ticketView;
private static final String TAG = "Home";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
/*FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});*/
drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.open, R.string.close);
drawer.addDrawerListener(toggle);
toggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
NavigationView navigationView = findViewById(R.id.nav_view);
// navigationView.inflateMenu(R.menu.activity_home_drawer);
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {// Handle navigation view item clicks here.
Log.i(TAG, "onNavigationItemSelected: called");
itemSelected(item);
//
// DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return false;
}
});
// navigationView.setNavigationItemSelectedListener(this);
init();
ticketFragment = new Ticket_fragment();
helpFragment = new Help_fragment();
scheduleFragment = new Schedule_fragment();
contactFragment = new ContactFragment();
ticketView = new TicketView();
ticketFragment.setAnInterface(this);
}
private void init(){
Bundle bundle = getIntent().getExtras();
currentUser = new user(bundle.getInt(CallbackInterface.ID),
bundle.getString(CallbackInterface.NAME),
bundle.getString(CallbackInterface.EMAIL),
bundle.getInt(CallbackInterface.MOBILE_NUMBER),
bundle.getInt(CallbackInterface.AGE),
bundle.getString(CallbackInterface.PASSWORD));
firstFragment = new FirstFragment();
firstFragment.setCallbackInterface(this);
fragmentManager = getSupportFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.home_frame, firstFragment);
fragmentTransaction.commit();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
itemSelected(item);
return super.onOptionsItemSelected(item);
}
private void itemSelected(MenuItem item){
switch(item.getItemId()){
case R.id.Booking:{
Log.i(TAG, "onNavigationItemSelected: menuItem click Booking");
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.home_frame, firstFragment);
fragmentTransaction.commit();
break;
}
case R.id.Ticket:{
Log.i(TAG, "onNavigationItemSelected: menuItem click Ticket");
fragmentTransaction = fragmentManager.beginTransaction();
Bundle bundle = new Bundle();
bundle.putInt(CallbackInterface.ID, currentUser.getId_number());
ticketFragment.setAnInterface(this);
ticketFragment.setArguments(bundle);
fragmentTransaction.replace(R.id.home_frame, ticketFragment);
fragmentTransaction.commit();
break;
}
case R.id.Schedule:{
Log.i(TAG, "onNavigationItemSelected: menuItem click Schedule");
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.home_frame, scheduleFragment);
fragmentTransaction.commit();
break;
}
case R.id.Help:{
Log.i(TAG, "onNavigationItemSelected: menuItem click Help");
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.home_frame, helpFragment);
fragmentTransaction.commit();
break;
}
case R.id.nav_contact:{
Log.i(TAG, "onNavigationItemSelected: menuItem click Contact");
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.home_frame, contactFragment);
fragmentTransaction.commit();
break;
}
}
}
@Override
public void onBackPressed() {
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
/* @Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
Log.i(TAG, "onNavigationItemSelected: called");
switch(item.getItemId()){
case R.id.Booking:{
Log.i(TAG, "onNavigationItemSelected: menuItem click Booking");
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.home_frame, firstFragment);
fragmentTransaction.commit();
break;
}
case R.id.Ticket:{
Log.i(TAG, "onNavigationItemSelected: menuItem click Ticket");
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.home_frame, ticketFragment);
fragmentTransaction.commit();
break;
}
case R.id.Schedule:{
Log.i(TAG, "onNavigationItemSelected: menuItem click Schedule");
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.home_frame, scheduleFragment);
fragmentTransaction.commit();
break;
}
case R.id.Help:{
Log.i(TAG, "onNavigationItemSelected: menuItem click Help");
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.home_frame, helpFragment);
fragmentTransaction.commit();
break;
}
case R.id.nav_contact:{
Log.i(TAG, "onNavigationItemSelected: menuItem click Contact");
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.home_frame, contactFragment);
fragmentTransaction.commit();
break;
}
}
DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return false;
}*/
@Override
public void firsttoSecond(Ticket ticket, int price) {
Ticket ticket1 = ticket;
ticket1.setCustomerId(currentUser.getId_number());
Bundle bundle = new Bundle();
bundle.putString(CallbackInterface.TRAIN_TYPE, ticket1.getType());
bundle.putString(CallbackInterface.ORIGIN, ticket1.getOrigin());
bundle.putString(CallbackInterface.DESTINATION, ticket1.getDestination());
bundle.putString(CallbackInterface.COACH, ticket1.getCoach());
bundle.putInt(CallbackInterface.ID, currentUser.getId_number());
bundle.putInt(CallbackInterface.PRICE, price);
secondFragment = new SecondFragment();
secondFragment.setArguments(bundle);
secondFragment.setCallbackInterface(this);
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.home_frame, secondFragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
@Override
public void signUpSuccess() {
//super.onBackPressed();
}
@Override
public void ticketDetails(Ticket ticket) {
Bundle bundle = new Bundle();
bundle.putInt(CallbackInterface.ID, ticket.getId());
bundle.putInt(CallbackInterface.CUSTOMER, ticket.getCustomerId());
bundle.putString(CallbackInterface.ORIGIN, ticket.getOrigin());
bundle.putString(CallbackInterface.DESTINATION, ticket.getDestination());
bundle.putString(CallbackInterface.COACH, ticket.getCoach());
bundle.putInt(CallbackInterface.MOBILE_NUMBER, ticket.getMobile());
bundle.putString(CallbackInterface.DDATE, String.valueOf(ticket.getDate()));
ticketView.setArguments(bundle);
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.home_frame, ticketView);
fragmentTransaction.addToBackStack("VIEW TICKET");
fragmentTransaction.commit();
}
@Override
public void viewTicket(Bundle bundle) {
fragmentTransaction = fragmentManager.beginTransaction();
ticketFragment.setAnInterface(this);
ticketFragment.setArguments(bundle);
fragmentTransaction.replace(R.id.home_frame, ticketFragment);
fragmentTransaction.commit();
}
}