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// //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// //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.app.Service;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder; 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.GetArrivals;
import com.example.myapp_1.DB.RetrofitClient; import com.example.myapp_1.DB.RetrofitClient;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit; import retrofit2.Retrofit;
public class FetchArrival extends Service public class FetchArrival extends Service
{ {
private GetArrivals apiService = RetrofitClient.getRetrofitInstance().create(GetArrivals.class); private static final String TAG = "MyActivity";
@Override @Override
public int onStartCommand(Intent intent, int flags, int Startid) { 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; return START_NOT_STICKY;
} }

View File

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

View File

@@ -1,14 +1,21 @@
package com.example.myapp_1; package com.example.myapp_1;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
public class NotificationActivity extends AppCompatActivity { public class NotificationActivity extends AppCompatActivity {
ImageView vec_back;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notification); 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,17 +38,16 @@ public class Predict extends AppCompatActivity {
edi_weather = findViewById(R.id.editTextText2); edi_weather = findViewById(R.id.editTextText2);
btn_pred = findViewById(R.id.button4); btn_pred = findViewById(R.id.button4);
prog_bar = findViewById(R.id.progressBar); 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); txt_pred_time = findViewById(R.id.predicted_time);
vec_back = findViewById(R.id.predictBackButton);
vec_back.setOnClickListener(view -> { vec_back.setOnClickListener(view -> {
Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class); Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(newScreen); startActivity(newScreen);
}); });
btn_pred.setOnClickListener(new View.OnClickListener() { btn_pred.setOnClickListener(view -> {
@Override
public void onClick(View view) {
String station = edi_station.getText().toString(); String station = edi_station.getText().toString();
String weather = edi_weather.getText().toString(); String weather = edi_weather.getText().toString();
@@ -76,10 +75,11 @@ public class Predict extends AppCompatActivity {
txt_pred_time.setText(sdf.format(new Date(currentTimeMillis))); txt_pred_time.setText(sdf.format(new Date(currentTimeMillis)));
} }
}); });
Intent apiService = new Intent(this, FetchArrival.class);
startService(apiService);
thread.start(); thread.start();
} }
}
}); });
} }
} }

View File

@@ -2,13 +2,21 @@ package com.example.myapp_1;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.widget.ImageView;
public class Schedule extends AppCompatActivity { public class Schedule extends AppCompatActivity {
ImageView vec_back;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_schedule); 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" /> app:layout_constraintTop_toBottomOf="@+id/train_image" />
<TextView <TextView
android:id="@+id/textView4" android:id="@+id/prediction"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="20dp" android:layout_marginLeft="20dp"

View File

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

View File

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

View File

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