Add "show call history" list item.

+ Add new VIEW_TYPE to the CallLogAdapter.
+ Reintroduce boolean on CallLogAdapter to specify if a call history
list item should be shown.
+ Add new ViewHolder and layout for footer.
+ Some minor styling tweaks and cleanups.

Bug: 20108202
Change-Id: Ie4a86bff9e53cfd69ef8b061af048f40f4358579
diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java
index 167c131..1e0b7e0 100644
--- a/src/com/android/dialer/DialtactsActivity.java
+++ b/src/com/android/dialer/DialtactsActivity.java
@@ -609,7 +609,10 @@
     public boolean onMenuItemClick(MenuItem item) {
         switch (item.getItemId()) {
             case R.id.menu_history:
-                showCallHistory();
+                // Use explicit CallLogActivity intent instead of ACTION_VIEW +
+                // CONTENT_TYPE, so that we always open our call log from our dialer
+                final Intent intent = new Intent(this, CallLogActivity.class);
+                startActivity(intent);
                 break;
             case R.id.menu_add_contact:
                 try {
@@ -1101,14 +1104,6 @@
         return resolveInfo != null && resolveInfo.size() > 0;
     }
 
-    @Override
-    public void showCallHistory() {
-        // Use explicit CallLogActivity intent instead of ACTION_VIEW +
-        // CONTENT_TYPE, so that we always open our call log from our dialer
-        final Intent intent = new Intent(this, CallLogActivity.class);
-        startActivity(intent);
-    }
-
     /**
      * Called when the user has long-pressed a contact tile to start a drag operation.
      */
diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java
index f2a84c9..8e22834 100644
--- a/src/com/android/dialer/calllog/CallLogAdapter.java
+++ b/src/com/android/dialer/calllog/CallLogAdapter.java
@@ -78,6 +78,8 @@
         public void onReportButtonClick(String number);
     }
 
+    private static final int VIEW_TYPE_SHOW_CALL_HISTORY_LIST_ITEM = 10;
+
     /** Constant used to indicate no row is expanded. */
     private static final long NONE_EXPANDED = -1;
 
@@ -89,6 +91,8 @@
 
     protected ContactInfoCache mContactInfoCache;
 
+    private boolean mShowCallHistoryListItem = false;
+
     /**
      * Tracks the currently expanded call log row.
      */
@@ -254,6 +258,9 @@
 
     @Override
     public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+        if (viewType == VIEW_TYPE_SHOW_CALL_HISTORY_LIST_ITEM) {
+            return ShowCallHistoryViewHolder.create(mContext, parent);
+        }
         return createCallLogEntryViewHolder(parent);
     }
 
@@ -287,6 +294,10 @@
      * @param count the number of entries in the current item, greater than 1 if it is a group
      */
     public void onBindViewHolder(ViewHolder viewHolder, int position) {
+        if (getItemViewType(position) == VIEW_TYPE_SHOW_CALL_HISTORY_LIST_ITEM) {
+            return;
+        }
+
         Cursor c = (Cursor) getItem(position);
         if (c == null) {
             return;
@@ -414,6 +425,23 @@
         }
     }
 
+    @Override
+    public int getItemCount() {
+        return super.getItemCount() + (mShowCallHistoryListItem ? 1 : 0);
+    }
+
+    @Override
+    public int getItemViewType(int position) {
+        if (position == getItemCount() - 1 && mShowCallHistoryListItem) {
+            return VIEW_TYPE_SHOW_CALL_HISTORY_LIST_ITEM;
+        }
+        return super.getItemViewType(position);
+    }
+
+    public void setShowCallHistoryListItem(boolean show) {
+        mShowCallHistoryListItem = show;
+    }
+
     /**
      * Retrieves the day group of the previous call in the call log.  Used to determine if the day
      * group has changed and to trigger display of the day group text.
diff --git a/src/com/android/dialer/calllog/CallLogFragment.java b/src/com/android/dialer/calllog/CallLogFragment.java
index 4f4fc1b..85fca91 100644
--- a/src/com/android/dialer/calllog/CallLogFragment.java
+++ b/src/com/android/dialer/calllog/CallLogFragment.java
@@ -77,6 +77,11 @@
     private static final String KEY_LOG_LIMIT = "log_limit";
     private static final String KEY_DATE_LIMIT = "date_limit";
 
+    // No limit specified for the number of logs to show; use the CallLogQueryHandler's default.
+    private static final int NO_LOG_LIMIT = -1;
+    // No date-based filtering.
+    private static final int NO_DATE_LIMIT = 0;
+
     private RecyclerView mRecyclerView;
     private LinearLayoutManager mLayoutManager;
     private CallLogAdapter mAdapter;
@@ -123,18 +128,18 @@
 
     // Log limit - if no limit is specified, then the default in {@link CallLogQueryHandler}
     // will be used.
-    private int mLogLimit = -1;
+    private int mLogLimit = NO_LOG_LIMIT;
 
     // Date limit (in millis since epoch) - when non-zero, only calls which occurred on or after
     // the date filter are included.  If zero, no date-based filtering occurs.
-    private long mDateLimit = 0;
+    private long mDateLimit = NO_DATE_LIMIT;
 
     public CallLogFragment() {
-        this(CallLogQueryHandler.CALL_TYPE_ALL, -1);
+        this(CallLogQueryHandler.CALL_TYPE_ALL, NO_LOG_LIMIT);
     }
 
     public CallLogFragment(int filterType) {
-        this(filterType, -1);
+        this(filterType, NO_LOG_LIMIT);
     }
 
     public CallLogFragment(int filterType, int logLimit) {
@@ -150,7 +155,7 @@
      * @param dateLimit limits results to calls occurring on or after the specified date.
      */
     public CallLogFragment(int filterType, long dateLimit) {
-        this(filterType, -1, dateLimit);
+        this(filterType, NO_LOG_LIMIT, dateLimit);
     }
 
     /**
@@ -278,6 +283,9 @@
         String currentCountryIso = GeoUtil.getCurrentCountryIso(getActivity());
         mAdapter = ObjectFactory.newCallLogAdapter(getActivity(), this,
                 new ContactInfoHelper(getActivity(), currentCountryIso), this);
+        if (mLogLimit != NO_LOG_LIMIT || mDateLimit != NO_DATE_LIMIT) {
+            mAdapter.setShowCallHistoryListItem(true);
+        }
         mRecyclerView.setAdapter(mAdapter);
 
         mVoicemailStatusHelper = new VoicemailStatusHelperImpl();
diff --git a/src/com/android/dialer/calllog/ShowCallHistoryViewHolder.java b/src/com/android/dialer/calllog/ShowCallHistoryViewHolder.java
new file mode 100644
index 0000000..af36a4d
--- /dev/null
+++ b/src/com/android/dialer/calllog/ShowCallHistoryViewHolder.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * 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 com.android.dialer.calllog;
+
+import android.content.Context;
+import android.content.Intent;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import com.android.dialer.R;
+
+public final class ShowCallHistoryViewHolder extends RecyclerView.ViewHolder {
+
+    private ShowCallHistoryViewHolder(final Context context, View view) {
+        super(view);
+        view.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                final Intent intent = new Intent(context, CallLogActivity.class);
+                context.startActivity(intent);
+            }
+        });
+    }
+
+    public static ShowCallHistoryViewHolder create(Context context, ViewGroup parent) {
+        LayoutInflater inflater = LayoutInflater.from(context);
+        View view = inflater.inflate(R.layout.show_call_history_list_item, parent, false);
+        return new ShowCallHistoryViewHolder(context, view);
+    }
+}
diff --git a/src/com/android/dialer/list/ListsFragment.java b/src/com/android/dialer/list/ListsFragment.java
index f22a5d1..4e7e00d 100644
--- a/src/com/android/dialer/list/ListsFragment.java
+++ b/src/com/android/dialer/list/ListsFragment.java
@@ -60,7 +60,6 @@
             "key_last_dismissed_call_shortcut_date";
 
     public interface HostInterface {
-        public void showCallHistory();
         public ActionBarController getActionBarController();
     }