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

Commit a59aea20 authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #1804 from sedrubal/swipe-to-refresh

Replace Android-PullToRefresh with android.support SwipeRefreshLayout
parents 0d77e8ea dab9f39f
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ configurations.all {

dependencies {
    compile project(':k9mail-library')
    compile project(':plugins:Android-PullToRefresh:library')
    compile project(':plugins:HoloColorPicker')
    compile project(':plugins:openpgp-api-lib:openpgp-api')
    compile "com.squareup.okio:okio:${okioVersion}"
+0 −1
Original line number Diff line number Diff line
@@ -1259,7 +1259,6 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
        new String[] {"Commons IO", "http://commons.apache.org/io/"},
        new String[] {"Mime4j", "http://james.apache.org/mime4j/"},
        new String[] {"HtmlCleaner", "http://htmlcleaner.sourceforge.net/"},
        new String[] {"Android-PullToRefresh", "https://github.com/chrisbanes/Android-PullToRefresh"},
        new String[] {"ckChangeLog", "https://github.com/cketti/ckChangeLog"},
        new String[] {"HoloColorPicker", "https://github.com/LarsWerkman/HoloColorPicker"},
        new String[] {"Glide", "https://github.com/bumptech/glide"},
+28 −54
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@ import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.Future;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.DialogFragment;
import android.app.Fragment;
@@ -37,6 +36,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
@@ -114,9 +114,6 @@ import com.fsck.k9.search.SearchSpecification;
import com.fsck.k9.search.SearchSpecification.SearchCondition;
import com.fsck.k9.search.SearchSpecification.SearchField;
import com.fsck.k9.search.SqlQueryBuilder;
import com.handmark.pulltorefresh.library.ILoadingLayout;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;


public class MessageListFragment extends Fragment implements OnItemClickListener,
@@ -219,7 +216,7 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
    }

    private ListView mListView;
    private PullToRefreshListView mPullToRefreshView;
    private SwipeRefreshLayout mSwipeRefreshLayout;
    private Parcelable mSavedListState;

    private int mPreviewLines = 0;
@@ -571,8 +568,8 @@ public class MessageListFragment extends Fragment implements OnItemClickListener

    private void progress(final boolean progress) {
        mFragmentListener.enableActionBarProgress(progress);
        if (mPullToRefreshView != null && !progress) {
            mPullToRefreshView.onRefreshComplete();
        if (mSwipeRefreshLayout != null && !progress) {
            mSwipeRefreshLayout.setRefreshing(false);
        }
    }

@@ -675,7 +672,7 @@ public class MessageListFragment extends Fragment implements OnItemClickListener

        View view = inflater.inflate(R.layout.message_list_fragment, container, false);

        initializePullToRefresh(inflater, view);
        initializePullToRefresh(view);

        initializeLayout();
        mListView.setVerticalFadingEdgeEnabled(false);
@@ -945,56 +942,35 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
        }
    }

    private void initializePullToRefresh(LayoutInflater inflater, View layout) {
        mPullToRefreshView = (PullToRefreshListView) layout.findViewById(R.id.message_list);

        @SuppressLint("InflateParams")
        View loadingView = inflater.inflate(R.layout.message_list_loading, null);
        mPullToRefreshView.setEmptyView(loadingView);
    private void initializePullToRefresh(View layout) {
        mSwipeRefreshLayout = (SwipeRefreshLayout) layout.findViewById(R.id.swiperefresh);
        mListView = (ListView) layout.findViewById(R.id.message_list);

        if (isRemoteSearchAllowed()) {
            // "Pull to search server"
            mPullToRefreshView.setOnRefreshListener(
                    new PullToRefreshBase.OnRefreshListener<ListView>() {
            mSwipeRefreshLayout.setOnRefreshListener(
                    new SwipeRefreshLayout.OnRefreshListener() {
                        @Override
                        public void onRefresh(PullToRefreshBase<ListView> refreshView) {
                            mPullToRefreshView.onRefreshComplete();
                        public void onRefresh() {
                            onRemoteSearchRequested();
                        }
                    });
            ILoadingLayout proxy = mPullToRefreshView.getLoadingLayoutProxy();
            proxy.setPullLabel(getString(
                    R.string.pull_to_refresh_remote_search_from_local_search_pull));
            proxy.setReleaseLabel(getString(
                    R.string.pull_to_refresh_remote_search_from_local_search_release));
                    }
            );
        } else if (isCheckMailSupported()) {
            // "Pull to refresh"
            mPullToRefreshView.setOnRefreshListener(
                    new PullToRefreshBase.OnRefreshListener<ListView>() {
            mSwipeRefreshLayout.setOnRefreshListener(
                    new SwipeRefreshLayout.OnRefreshListener() {
                        @Override
                public void onRefresh(PullToRefreshBase<ListView> refreshView) {
                        public void onRefresh() {
                            checkMail();
                        }
            });
                    }

        // Disable pull-to-refresh until the message list has been loaded
        setPullToRefreshEnabled(false);
            );
        }

    /**
     * Enable or disable pull-to-refresh.
     *
     * @param enable
     *         {@code true} to enable. {@code false} to disable.
     */
    private void setPullToRefreshEnabled(boolean enable) {
        mPullToRefreshView.setMode((enable) ?
                PullToRefreshBase.Mode.PULL_FROM_START : PullToRefreshBase.Mode.DISABLED);
        // Disable pull-to-refresh until the message list has been loaded
        mSwipeRefreshLayout.setEnabled(false);
    }

    private void initializeLayout() {
        mListView = mPullToRefreshView.getRefreshableView();
        mListView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        mListView.setLongClickable(true);
        mListView.setFastScrollEnabled(true);
@@ -1053,7 +1029,7 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
        mRemoteSearchFuture = mController.searchRemoteMessages(searchAccount, searchFolder,
                queryString, null, null, mListener);

        setPullToRefreshEnabled(false);
        mSwipeRefreshLayout.setEnabled(false);

        mFragmentListener.remoteSearchStarted();
    }
@@ -1536,8 +1512,8 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
    }

    private int listViewToAdapterPosition(int position) {
        if (position > 0 && position <= mAdapter.getCount()) {
            return position - 1;
        if (position >= 0 && position < mAdapter.getCount()) {
            return position;
        }

        return AdapterView.INVALID_POSITION;
@@ -1545,7 +1521,7 @@ public class MessageListFragment extends Fragment implements OnItemClickListener

    private int adapterToListViewPosition(int position) {
        if (position >= 0 && position < mAdapter.getCount()) {
            return position + 1;
            return position;
        }

        return AdapterView.INVALID_POSITION;
@@ -3261,10 +3237,8 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
            return;
        }

        // Remove the "Loading..." view
        mPullToRefreshView.setEmptyView(null);

        setPullToRefreshEnabled(isPullToRefreshAllowed());
        mSwipeRefreshLayout.setRefreshing(false);
        mSwipeRefreshLayout.setEnabled(isPullToRefreshAllowed());

        final int loaderId = loader.getId();
        mCursors[loaderId] = data;
+0 −59
Original line number Diff line number Diff line
package com.fsck.k9.view;

import android.content.Context;
import android.graphics.Canvas;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.widget.ListView;

import com.handmark.pulltorefresh.library.PullToRefreshListView;


public class K9PullToRefreshListView extends PullToRefreshListView {

    public K9PullToRefreshListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected ListView createListView(Context context, AttributeSet attrs) {
        return new ListView(context, attrs) {
            @Override
            public void onRestoreInstanceState(Parcelable state) {
                super.onRestoreInstanceState(state);

                /*
                 * Force the list view to apply the restored state instantly instead of
                 * asynchronously, so potential data changes (which in turn cause an internal
                 * position save/restore) don't overwrite our saved position.
                 */
                layoutChildren();
            }

            @Override
            protected void dispatchDraw(Canvas canvas) {
                if (getAdapter() != null) {
                    int count = getChildCount();
                    int itemCount = getAdapter().getCount();

                    /*
                     * 2013-03-18 - cketti
                     *
                     * Work around a bug in ListView (?) that leads to a crash deep inside the
                     * framework code.
                     * I didn't track down the exact cause of this. My best guess is that we change
                     * the data (remove items) while the ListView isn't visible. Probably because
                     * the view is hidden, layoutChildren() is never called and when this method
                     * runs the layout contains more item views than the adapter contains elements
                     * and bad things(tm) happen.
                     */
                    if (itemCount < count) {
                        layoutChildren();
                    }
                }

                super.dispatchDraw(canvas);
            }
        };
    }
}
+13 −5
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<com.fsck.k9.view.K9PullToRefreshListView

<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swiperefresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/message_list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="5" />

</android.support.v4.widget.SwipeRefreshLayout>
Loading