Commit c4d7463f authored by Paded's avatar Paded

return bus success

parent 396711c0
......@@ -55,6 +55,8 @@ public class CreateAccountActivity extends AppCompatActivity implements ItemAdap
BottomSheetBehavior behavior;
ArrayList<String> items;
Map<String,String> myLine;
String start_busstop_id;
String stop_busstop_id;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -269,8 +271,9 @@ public class CreateAccountActivity extends AppCompatActivity implements ItemAdap
}
public void insertData(String uid, String name, String select_bus){
public void insertData(final String uid, final String name, String select_bus){
String busid = "";
if(select_bus.equalsIgnoreCase("สาย ม.")){
busid = "B00";
}else if(select_bus.equalsIgnoreCase("สาย 1")){
......@@ -293,11 +296,41 @@ public class CreateAccountActivity extends AppCompatActivity implements ItemAdap
busid = "B012";
}
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("users/"+uid);
myRef.child("name").setValue(name);
myRef.child("bus_id").setValue(busid);
myRef.child("status").setValue("on");
DatabaseReference keyReference = FirebaseDatabase.getInstance().getReference().child("allbus/" + busid);
final String finalBusid = busid;
keyReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String x = dataSnapshot.child("bus_stop").getValue(String.class);
// String string = dataSnapshot.getValue(String.class);
String[] bus_stop = x.split(",");
int bus_stop_size = bus_stop.length;
// String start_stop_busstop[] = new String[2];
// start_stop_busstop[0] = bus_stop[0];
// start_stop_busstop[1] = bus_stop[bus_stop_size - 1];
start_busstop_id = bus_stop[0];
stop_busstop_id = bus_stop[bus_stop_size - 1];
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("users/"+uid);
myRef.child("name").setValue(name);
myRef.child("bus_id").setValue(finalBusid);
myRef.child("status").setValue("off");
myRef.child("start_busstop").setValue(start_busstop_id);
myRef.child("stop_busstop").setValue(stop_busstop_id);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.d(TAG, "Read failed");
}
});
Log.d(TAG, "insertData: "+start_busstop_id);
Log.d(TAG, "insertData: "+stop_busstop_id);
}
@Override
......
package ubontransitdriver.paded.com.ubontransitdriver;
import android.app.Activity;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
......@@ -44,8 +45,12 @@ public class ProfileSettingActivity extends AppCompatActivity {
progressBar.setVisibility(View.GONE);
// user auth state is changed - user is null
// launch login activity
startActivity(new Intent(ProfileSettingActivity.this, LoginActivity.class));
Intent returnIntent = new Intent();
returnIntent.putExtra("logout",true);
setResult(Activity.RESULT_OK,returnIntent);
finish();
// startActivity(new Intent(ProfileSettingActivity.this, LoginActivity.class));
// finish();
}
}
};
......
......@@ -28,6 +28,12 @@ import com.google.android.gms.location.LocationServices;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
public class TrackerService extends Service {
private static final String TAG = "GPS2";
private boolean isRunning = false;
......@@ -144,7 +150,13 @@ public class TrackerService extends Service {
Log.d(TAG, "location update " + location);
ref.child("latitude").setValue(location.getLatitude());
ref.child("longitude").setValue(location.getLongitude());
ref.child("time").setValue(location.getTime());
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = df.format(c.getTime());
Log.d("dddd", "onLocationResult: "+formattedDate);
ref.child("time").setValue(formattedDate);
}
}
......
......@@ -23,6 +23,7 @@ import com.google.android.gms.location.LocationServices;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
......@@ -44,6 +45,7 @@ public class TrackerService3 extends Service implements
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("dddd", "onStartCommand: ");
user_id = intent.getStringExtra("user_id");
bus_id = intent.getStringExtra("bus_id");
destination = intent.getStringExtra("destination");
......@@ -96,7 +98,14 @@ public class TrackerService3 extends Service implements
DatabaseReference ref = FirebaseDatabase.getInstance().getReference(path);
ref.child("latitude").setValue(location.getLatitude());
ref.child("longitude").setValue(location.getLongitude());
ref.child("time").setValue(location.getTime());
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = df.format(c.getTime());
Log.d("dddd", "onLocationResult: "+formattedDate);
ref.child("time").setValue(formattedDate);
ref.child("destination").setValue(destination);
// Date currentTime = Calendar.getInstance().getTime();
// Log.d(TAG, "Location: " + location.getLatitude() + " " + location.getLongitude()+" "+location.getTime()+" "+currentTime);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment