Good enough

This commit is contained in:
2023-12-20 12:57:16 +02:00
parent 667d9e9a7e
commit 7f9b30271c
10 changed files with 108 additions and 79 deletions

View File

@@ -8,7 +8,7 @@ public interface GetArrivals
{
//Specify the request type and pass the relative URL//
@GET("/users")
@GET("/arrivals/all")
//Wrap the response in a Call object with the type of the expected result//

View File

@@ -3,19 +3,54 @@ package com.example.myapp_1;
import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
import com.example.myapp_1.DB.Arrival;
import com.example.myapp_1.DB.GetArrivals;
import com.example.myapp_1.DB.RetrofitClient;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
public class FetchArrival extends Service
{
private GetArrivals apiService = RetrofitClient.getRetrofitInstance().create(GetArrivals.class);
private static final String TAG = "MyActivity";
@Override
public int onStartCommand(Intent intent, int flags, int Startid) {
GetArrivals apiService = RetrofitClient.getRetrofitInstance().create(GetArrivals.class);
Call<List<Arrival>> call = apiService.getAllArrivals();
//Execute the request asynchronously//
call.enqueue(new Callback<List<Arrival>>() {
//Handle a successful response//
@Override
public void onResponse(Call<List<Arrival>> call, Response<List<Arrival>> response) {
SharedPreferences sp = getApplicationContext().getSharedPreferences("UserData", MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
// Log.d(TAG, response.body().toString());
editor.putString("response", response.body().toString());
}
//Handle execution failures//
public void onFailure(Call<List<Arrival>> call, Throwable throwable) {
System.out.println("A");
}
});
//Display the retrieved data as a list//
return START_NOT_STICKY;
}

View File

@@ -52,6 +52,9 @@ public class HomeActivity extends AppCompatActivity {
if (user != null)
userGreeting.setText("Welcome " + user + "!");
String response = currentUserThings.getString("response", "");
TextView prediction = findViewById(R.id.prediction);
prediction.setText(response);
vec_back.setOnClickListener(view -> {
Intent newScreen = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(newScreen);

View File

@@ -1,14 +1,21 @@
package com.example.myapp_1;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
public class NotificationActivity extends AppCompatActivity {
ImageView vec_back;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notification);
vec_back = findViewById(R.id.notificationBackButton);
vec_back.setOnClickListener(view -> {
Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(newScreen);
});
}
}

View File

@@ -38,47 +38,47 @@ public class Predict extends AppCompatActivity {
edi_weather = findViewById(R.id.editTextText2);
btn_pred = findViewById(R.id.button4);
prog_bar = findViewById(R.id.progressBar);
txt_station = findViewById(R.id.textView4);
txt_station = findViewById(R.id.prediction);
txt_pred_time = findViewById(R.id.predicted_time);
vec_back = findViewById(R.id.predictBackButton);
vec_back.setOnClickListener(view -> {
Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(newScreen);
});
btn_pred.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String station = edi_station.getText().toString();
String weather = edi_weather.getText().toString();
btn_pred.setOnClickListener(view -> {
String station = edi_station.getText().toString();
String weather = edi_weather.getText().toString();
if(station.isEmpty() || weather.isEmpty()) {
Toast.makeText(Predict.this, "Please enter something", Toast.LENGTH_SHORT).show();
}else{
// we will pass the input features to the model to predict
// then display predictions
if(station.isEmpty() || weather.isEmpty()) {
Toast.makeText(Predict.this, "Please enter something", Toast.LENGTH_SHORT).show();
}else{
// we will pass the input features to the model to predict
// then display predictions
txt_station.setText(station);
txt_station.setText(station);
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
for(int i = 0; i < 10; i++){
prog_bar.incrementProgressBy(10);
SystemClock.sleep(500);
}
prog_bar.setVisibility(View.GONE);
long currentTimeMillis = System.currentTimeMillis();
// Create a SimpleDateFormat object to format the time
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// Format the time and set it to the TextView
txt_pred_time.setText(sdf.format(new Date(currentTimeMillis)));
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
for(int i = 0; i < 10; i++){
prog_bar.incrementProgressBy(10);
SystemClock.sleep(500);
}
});
thread.start();
prog_bar.setVisibility(View.GONE);
long currentTimeMillis = System.currentTimeMillis();
// Create a SimpleDateFormat object to format the time
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// Format the time and set it to the TextView
txt_pred_time.setText(sdf.format(new Date(currentTimeMillis)));
}
});
Intent apiService = new Intent(this, FetchArrival.class);
startService(apiService);
thread.start();
}
}
});
}

View File

@@ -2,13 +2,21 @@ package com.example.myapp_1;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
public class Schedule extends AppCompatActivity {
ImageView vec_back;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_schedule);
vec_back = findViewById(R.id.ScheduleBackButton);
vec_back.setOnClickListener(view -> {
Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(newScreen);
});
}
}

View File

@@ -55,7 +55,7 @@
app:layout_constraintTop_toBottomOf="@+id/train_image" />
<TextView
android:id="@+id/textView4"
android:id="@+id/prediction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"

View File

@@ -5,40 +5,23 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/notifBottomView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/material_dynamic_primary60"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/botton_menu" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/material_dynamic_primary60"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintEnd_toEndOf="parent"
<ImageView
android:id="@+id/notificationBackButton"
android:layout_width="42dp"
android:layout_height="40dp"
android:layout_marginStart="16dp"
android:layout_marginTop="72dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navigationIcon="@drawable/baseline_arrow_back_ios"
app:title="Notification"
app:titleCentered="true" />
app:srcCompat="@drawable/_vector" />
<ListView
android:layout_width="409dp"
android:layout_height="471dp"
app:layout_constraintBottom_toTopOf="@+id/notifBottomView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar3"
app:layout_constraintVertical_bias="0.0" />
tools:layout_editor_absoluteY="188dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -135,7 +135,7 @@
app:layout_constraintTop_toBottomOf="@+id/userGreeting" />
<TextView
android:id="@+id/textView4"
android:id="@+id/prediction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"

View File

@@ -6,33 +6,27 @@
android:layout_height="match_parent"
tools:context=".Schedule">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/material_dynamic_primary60"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
<ImageView
android:id="@+id/ScheduleBackButton"
android:layout_width="55dp"
android:layout_height="48dp"
android:layout_marginStart="4dp"
android:layout_marginTop="24dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navigationIcon="@drawable/baseline_arrow_back_ios"
app:title="Schedule"
app:titleCentered="true" />
app:srcCompat="@drawable/_vector" />
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="36dp"
android:text="Start Startion:"
android:textColor="@color/black"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar" />
tools:layout_editor_absoluteY="92dp" />
<TextView
android:id="@+id/textView9"
@@ -167,13 +161,12 @@
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="44dp"
android:text="Search Tram"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar"
app:layout_constraintVertical_bias="0.931" />
app:layout_constraintHorizontal_bias="0.486"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>