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

Commit d047d075 authored by Gabor Keszthelyi's avatar Gabor Keszthelyi Committed by Marten Gajda
Browse files

Clean up TaskGroupPagerAdapter instantiation exception handling and some...

Clean up TaskGroupPagerAdapter instantiation exception handling and some unused code in TaskListActivity. #621 (#622)
parent 03f21a26
Loading
Loading
Loading
Loading
+2 −37
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.ColorInt;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
@@ -39,7 +38,6 @@ import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.SearchView.OnQueryTextListener;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -63,10 +61,7 @@ import org.dmfs.tasks.model.ContentSet;
import org.dmfs.tasks.utils.BaseActivity;
import org.dmfs.tasks.utils.ExpandableGroupDescriptor;
import org.dmfs.tasks.utils.SearchHistoryHelper;
import org.dmfs.xmlobjects.pull.XmlObjectPullParserException;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import org.dmfs.tasks.utils.Unchecked;


/**
@@ -142,12 +137,6 @@ public class TaskListActivity extends BaseActivity implements TaskListFragment.C

    private boolean mAutoExpandSearchView = false;

    /**
     * Indicates that the activity switched to detail view due to rotation.
     **/
    @Retain
    private boolean mSwitchedToDetail = false;

    /**
     * The Uri of the task to display/highlight in the list view.
     **/
@@ -181,8 +170,6 @@ public class TaskListActivity extends BaseActivity implements TaskListFragment.C
     **/
    private boolean mTransientState = false;

    private CollapsingToolbarLayout mToolbarLayout;

    private AppBarLayout mAppBarLayout;

    private FloatingActionButton mFloatingActionButton;
@@ -191,7 +178,6 @@ public class TaskListActivity extends BaseActivity implements TaskListFragment.C
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        Log.d(TAG, "onCreate called again");
        super.onCreate(savedInstanceState);

        // check for single pane activity change
@@ -206,7 +192,6 @@ public class TaskListActivity extends BaseActivity implements TaskListFragment.C
                Intent viewTaskIntent = new Intent(Intent.ACTION_VIEW);
                viewTaskIntent.setData(mSelectedTaskUri);
                startActivity(viewTaskIntent);
                mSwitchedToDetail = true;
                mShouldSwitchToDetail = false;
                mTransientState = true;
            }
@@ -251,26 +236,7 @@ public class TaskListActivity extends BaseActivity implements TaskListFragment.C
                new ByList(mAuthority, this), new ByDueDate(mAuthority), new ByStartDate(mAuthority),
                new ByPriority(mAuthority, this), new ByProgress(mAuthority), new BySearch(mAuthority, mSearchHistoryHelper) };

        // set up pager adapter
        try
        {
            mPagerAdapter = new TaskGroupPagerAdapter(getSupportFragmentManager(), mGroupingFactories, this, R.xml.listview_tabs);
        }
        catch (XmlPullParserException e)
        {
            // TODO Automatisch generierter Erfassungsblock
            e.printStackTrace();
        }
        catch (IOException e)
        {
            // TODO Automatisch generierter Erfassungsblock
            e.printStackTrace();
        }
        catch (XmlObjectPullParserException e)
        {
            // TODO Automatisch generierter Erfassungsblock
            e.printStackTrace();
        }
        mPagerAdapter = new Unchecked<>(() -> new TaskGroupPagerAdapter(getSupportFragmentManager(), mGroupingFactories, this, R.xml.listview_tabs)).value();

        // Setup ViewPager
        mPagerAdapter.setTwoPaneLayout(mTwoPane);
@@ -433,7 +399,6 @@ public class TaskListActivity extends BaseActivity implements TaskListFragment.C
                Intent detailIntent = new Intent(Intent.ACTION_VIEW);
                detailIntent.setData(uri);
                startActivity(detailIntent);
                mSwitchedToDetail = true;
                mShouldSwitchToDetail = false;
            }
        }
+55 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 dmfs GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.dmfs.tasks.utils;

import org.dmfs.jems.single.Single;


/**
 * 'Unchecks' an Exception, i.e. turns a {@link Fragile} into a {@link Single} by rethrowing
 * the possible {@link Exception} as {@link RuntimeException}.
 * <p>
 * Note: This should be used with care for obvious reasons, only at appropriate places.
 *
 * @author Gabor Keszthelyi
 * @deprecated use it from jems when available
 */
@Deprecated
public final class Unchecked<T> implements Single<T>
{
    private final Fragile<T, Exception> mDelegate;


    public Unchecked(Fragile<T, Exception> delegate)
    {
        mDelegate = delegate;
    }


    @Override
    public T value()
    {
        try
        {
            return mDelegate.value();
        }
        catch (Exception e)
        {
            throw new RuntimeException("Exception in Unchecked", e);
        }
    }
}