Skip to content

Commit

Permalink
Clean up TaskGroupPagerAdapter instantiation exception handling and s…
Browse files Browse the repository at this point in the history
…ome unused code in TaskListActivity. #621
  • Loading branch information
Gabor Keszthelyi committed Jan 8, 2018
1 parent 03f21a2 commit c3d1c52
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 37 deletions.
39 changes: 2 additions & 37 deletions opentasks/src/main/java/org/dmfs/tasks/TaskListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
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;
Expand All @@ -39,7 +38,6 @@
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;
Expand All @@ -63,10 +61,7 @@
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;


/**
Expand Down Expand Up @@ -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.
**/
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -206,7 +192,6 @@ protected void onCreate(Bundle savedInstanceState)
Intent viewTaskIntent = new Intent(Intent.ACTION_VIEW);
viewTaskIntent.setData(mSelectedTaskUri);
startActivity(viewTaskIntent);
mSwitchedToDetail = true;
mShouldSwitchToDetail = false;
mTransientState = true;
}
Expand Down Expand Up @@ -251,26 +236,7 @@ protected void onCreate(Bundle savedInstanceState)
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);
Expand Down Expand Up @@ -433,7 +399,6 @@ else if (forceReload)
Intent detailIntent = new Intent(Intent.ACTION_VIEW);
detailIntent.setData(uri);
startActivity(detailIntent);
mSwitchedToDetail = true;
mShouldSwitchToDetail = false;
}
}
Expand Down
55 changes: 55 additions & 0 deletions opentasks/src/main/java/org/dmfs/tasks/utils/Unchecked.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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);
}
}
}

0 comments on commit c3d1c52

Please sign in to comment.