Repository: eventfahrplan/eventfahrplan
Issue: Stay at current scroll position when going back from event details view

It is really beneficial for the normal user workflow to stay at the current scroll position.

At the moment, the app **always scrolls back to the current time** and the user has to scroll all the way down again.

Many users go through the schedule and try to decide which lectures/talks to go to.

# Enviroment

- Device vendor: Lenovo/ZUK
- Device model: [ZUK Z1](https://www.gsmarena.com/lenovo_zuk_z1-7511.php) (Smartphone)
- Android version: 5.1.1
- Cyanogen version: 12.1-YOG4PAS9IG
- App version: 1.33.1

# How to reproduce
1. Start the app, navigate to the main view (if necessary)
2. Scroll up or down and tap on a talk to see it's details.
3. Tap the back-button.
4. You are now at the current time again, not where you initially scrolled to.


# Also the following Developer Options were customized
- Window Animation Scale: Off
- Transition Animation Scale: Off
- Animation Duration Scale: Off


Changed files:
app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/MainActivity.java, app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/FahrplanFragment.java

diff --git a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/FahrplanFragment.java b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/FahrplanFragment.java
index 2532aa42..cfab0102 100644
--- a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/FahrplanFragment.java
+++ b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/FahrplanFragment.java
@@ -262,11 +262,6 @@ public class FahrplanFragment extends Fragment implements OnClickListener {
             saveCurrentDay(mDay);
         }
 
-        if (MyApp.meta.getNumDays() != 0) {
-            // auf jeden Fall reload, wenn mit Lecture ID gestartet
-            viewDay(lecture_id != null);
-        }
-
         Log.d(LOG_TAG, "MyApp.task_running = " + MyApp.task_running);
         switch (MyApp.task_running) {
             case FETCH:
@@ -326,7 +321,10 @@ public class FahrplanFragment extends Fragment implements OnClickListener {
             int roomIndex = MyApp.roomList.get(i);
             fillRoom(roomView, roomIndex, MyApp.lectureList, boxHeight);
         }
-        scrollToCurrent(mDay, boxHeight);
+        MainActivity.getInstance().shouldScheduleScrollToCurrentTimeSlot(() -> {
+            scrollToCurrent(mDay, boxHeight);
+            return null;
+        });
         updateNavigationMenuSelection();
     }
 
diff --git a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/MainActivity.java b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/MainActivity.java
index 46bc724f..391f9ae5 100644
--- a/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/MainActivity.java
+++ b/app/src/main/java/nerd/tuxmobil/fahrplan/congress/schedule/MainActivity.java
@@ -30,6 +30,8 @@ import org.ligi.tracedroid.logging.Log;
 
 import java.util.List;
 
+import kotlin.Unit;
+import kotlin.jvm.functions.Function0;
 import nerd.tuxmobil.fahrplan.congress.MyApp;
 import nerd.tuxmobil.fahrplan.congress.MyApp.TASKS;
 import nerd.tuxmobil.fahrplan.congress.R;
@@ -73,6 +75,7 @@ public class MainActivity extends BaseActivity implements
 
     private ProgressBar progressBar = null;
     private boolean requiresScheduleReload = false;
+    private boolean shouldScrollToCurrent = true;
     private boolean showUpdateAction = true;
     private static MainActivity instance;
 
@@ -397,6 +400,10 @@ public class MainActivity extends BaseActivity implements
         switch (requestCode) {
             case MyApp.ALARMLIST:
             case MyApp.EVENTVIEW:
+                if (resultCode == Activity.RESULT_CANCELED) {
+                    shouldScrollToCurrent = false;
+                }
+                break;
             case MyApp.CHANGELOG:
             case MyApp.STARRED:
                 if (resultCode == Activity.RESULT_OK) {
@@ -510,6 +517,13 @@ public class MainActivity extends BaseActivity implements
     public void onDenied(int dlgRequestCode) {
     }
 
+    public void shouldScheduleScrollToCurrentTimeSlot(Function0<Unit> scrollToInstructions) {
+        if (shouldScrollToCurrent) {
+            scrollToInstructions.invoke();
+        }
+        shouldScrollToCurrent = true;
+    }
+
     public static MainActivity getInstance() {
         return instance;
     }