From e3c7675c6ade375edb93aa11fa62825bc212dc89 Mon Sep 17 00:00:00 2001 From: David Katrinka Date: Thu, 15 Jan 2026 20:25:09 +0100 Subject: [PATCH] fixed refresh on rate and auto refresh, fixed some button designs and username in post title --- .../com/example/gallery/MainActivity.java | 20 ++++++++++ .../gallery/adapters/PostsAdapter.java | 39 ++++++++++--------- .../example/gallery/models/Publication.java | 15 +++++-- app/src/main/res/layout/activity_main.xml | 10 ++++- 4 files changed, 60 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/example/gallery/MainActivity.java b/app/src/main/java/com/example/gallery/MainActivity.java index 61395e9..a4b9d4d 100644 --- a/app/src/main/java/com/example/gallery/MainActivity.java +++ b/app/src/main/java/com/example/gallery/MainActivity.java @@ -2,6 +2,7 @@ package com.example.gallery; import android.content.Intent; import android.os.Bundle; +import android.os.Handler; import android.view.View; import android.widget.Button; import android.widget.ImageButton; @@ -36,6 +37,16 @@ public class MainActivity extends AppCompatActivity { private TextView menuLogout, menuNewPost; private ImageButton filterBtnToolbar; + private final int REFRESH_INTERVAL = 30000; // 30 seconds + private final Handler autoRefreshHandler = new Handler(); + private final Runnable autoRefreshRunnable = new Runnable() { + @Override + public void run() { + loadPublications(); // reload posts + autoRefreshHandler.postDelayed(this, REFRESH_INTERVAL); // schedule next refresh + } + }; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -199,5 +210,14 @@ public class MainActivity extends AppCompatActivity { super.onResume(); updateAuthUI(); loadPublications(); + + autoRefreshHandler.postDelayed(autoRefreshRunnable, REFRESH_INTERVAL); + } + + + @Override + protected void onPause() { + super.onPause(); + autoRefreshHandler.removeCallbacks(autoRefreshRunnable); } } \ No newline at end of file diff --git a/app/src/main/java/com/example/gallery/adapters/PostsAdapter.java b/app/src/main/java/com/example/gallery/adapters/PostsAdapter.java index 92dca03..54951cb 100644 --- a/app/src/main/java/com/example/gallery/adapters/PostsAdapter.java +++ b/app/src/main/java/com/example/gallery/adapters/PostsAdapter.java @@ -16,6 +16,7 @@ import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; +import com.example.gallery.MainActivity; import com.example.gallery.R; import com.example.gallery.VideoPlayerActivity; import com.example.gallery.api.ApiClient; @@ -117,28 +118,31 @@ public class PostsAdapter extends RecyclerView.Adapter { + // Make the thumbnail clickable to play video + holder.postImage.setOnClickListener(v -> { Intent i = new Intent(context, VideoPlayerActivity.class); i.putExtra("videoUrl", post.video); context.startActivity(i); - }; + }); - holder.postImage.setOnClickListener(play); - holder.videoPlayButton.setOnClickListener(play); } else { - holder.videoPlayButton.setVisibility(View.GONE); + // Load image for normal posts Glide.with(context).load(post.image).into(holder.postImage); } + + + // ---------- AVERAGE ---------- holder.txtAverageValue.setText(String.format("%.1f", post.average_score)); holder.averageRatingBar.setRating(post.average_score); @@ -175,6 +179,7 @@ public class PostsAdapter extends RecyclerView.Adapter { + ((MainActivity) context).loadPublications(); + }); + } } @Override @@ -215,7 +224,7 @@ public class PostsAdapter extends RecyclerView.Adapter @@ -147,20 +148,25 @@ android:id="@+id/btnLogout" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:background="@drawable/button_background" android:text="Logout" - android:layout_margin="16dp" android:visibility="gone" + android:textColor="@color/white" app:layout_constraintTop_toTopOf="@id/toolbar" - app:layout_constraintStart_toStartOf="parent"/> + app:layout_constraintBottom_toBottomOf="@id/toolbar" + app:layout_constraintStart_toEndOf="@id/burgerMenuBtn" + android:layout_marginStart="8dp"/>