Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 1d2063f2 authored by Gitsaibot's avatar Gitsaibot Committed by Michael Bestas
Browse files

Go back to default view instead of quitting

Change-Id: Iea38bc99c0924b7ac35904281f0eb970eea2cdfa
parent cca1fb36
Loading
Loading
Loading
Loading
+25 −10
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.Manifest;
import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.AsyncQueryHandler;
import android.content.BroadcastReceiver;
@@ -65,6 +66,7 @@ import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.OnBackPressedCallback;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
@@ -194,6 +196,7 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH
    private long mIntentEventEndMillis = -1;
    private int mIntentAttendeeResponse = Attendees.ATTENDEE_STATUS_NONE;
    private boolean mIntentAllDay = false;
    private Activity mActivity;
    private DrawerLayout mDrawerLayout;
    private Toolbar mToolbar;
    private NavigationView mNavigationView;
@@ -259,7 +262,7 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH
        setTheme(R.style.CalendarTheme_WithActionBarWallpaper);
        super.onCreate(icicle);
        dynamicTheme.onCreate(this);

        mActivity = this;
        // This needs to be created before setContentView
        mController = CalendarController.getInstance(this);

@@ -380,6 +383,27 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH
        prefs.registerOnSharedPreferenceChangeListener(this);

        mContentResolver = getContentResolver();

        getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
            @Override
            public void handleOnBackPressed() {
                if (mCurrentView == ViewType.EDIT || mBackToPreviousView) {
                    mController.sendEvent(this, EventType.GO_TO, null, null, -1, mPreviousView);
                } else {
                    int defaultStartView = Utils.getViewTypeFromIntentAndSharedPref(mActivity);

                    // If the current view is the default one, quit app. If not, go back to default view.
                    if (mCurrentView == defaultStartView
                            || defaultStartView == com.android.calendar.CalendarController.ViewType.AGENDA
                            || defaultStartView == com.android.calendar.CalendarController.ViewType.DAY ) {
                       finish();
                    } else {
                        mController.sendEvent(this, EventType.GO_TO, null, null, -1, defaultStartView);
                    }
                }
            }
        });

    }

    private void checkAppPermissions() {
@@ -801,15 +825,6 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH
        }
    }

    @Override
    public void onBackPressed() {
        if (mCurrentView == ViewType.EDIT || mBackToPreviousView) {
            mController.sendEvent(this, EventType.GO_TO, null, null, -1, mPreviousView);
        } else {
            super.onBackPressed();
        }
    }

    protected void updateViewSettingsVisiblility() {
        if (mViewSettings != null) {
            boolean viewSettingsVisible = mController.getViewType() == ViewType.MONTH;