Bug 1142171: Split history List view for tablet landscape mode r=sebastian.

--HG--
extra : commitid : 6sIgUCTyxLY
extra : rebase_source : b7133ccffc1a69d2bf59f682a57ab39326d8c6d7
This commit is contained in:
vivek 2015-08-13 02:49:11 +03:00
Родитель 297b2d1402
Коммит 7f1348d1b2
7 изменённых файлов: 221 добавлений и 4 удалений

Просмотреть файл

@ -0,0 +1,53 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.home;
import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.CursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.mozilla.gecko.db.BrowserContract;
/**
* A Cursor adapter that is used to populate the history list items in split plane mode.
*/
public class HistoryItemAdapter extends CursorAdapter implements HistoryPanel.HistoryUrlProvider {
private final int resource;
public HistoryItemAdapter(Context context, Cursor c, int resource) {
super(context, c, false);
this.resource = resource;
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(resource, parent, false);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return super.getView(position, convertView, parent);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
final TwoLinePageRow row = (TwoLinePageRow) view;
row.updateFromCursor(cursor);
}
@Override
public String getURL(int position) {
final Cursor cursor = getCursor();
if (cursor == null || !cursor.moveToPosition(position)) {
throw new IllegalStateException("Couldn't move cursor to position " + position);
}
return cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.History.URL));
}
}

Просмотреть файл

@ -18,6 +18,7 @@ import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.GeckoScreenOrientation;
import org.mozilla.gecko.R;
import org.mozilla.gecko.RestrictedProfiles;
import org.mozilla.gecko.Telemetry;
@ -27,11 +28,14 @@ import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.home.HomeContextMenuInfo.RemoveItemType;
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import org.mozilla.gecko.restrictions.Restriction;
import org.mozilla.gecko.util.ColorUtils;
import org.mozilla.gecko.util.HardwareUtils;
import android.app.AlertDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Configuration;
import android.database.Cursor;
import android.graphics.Typeface;
import android.os.Bundle;
@ -50,6 +54,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
@ -79,8 +84,12 @@ public class HistoryPanel extends HomeFragment {
// Adapter for the list of recent history entries.
private CursorAdapter mAdapter;
// Adapter for the timeline of history entries.
private ArrayAdapter<MostRecentSection> mRangeAdapter;
// The view shown by the fragment.
private HomeListView mList;
private HomeListView mRangeList;
// The button view for clearing browsing history.
private View mClearHistoryButton;
@ -111,14 +120,38 @@ public class HistoryPanel extends HomeFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.home_history_panel, container, false);
if (HardwareUtils.isTablet() && GeckoScreenOrientation.getInstance().getAndroidOrientation() == Configuration.ORIENTATION_LANDSCAPE) {
return inflater.inflate(R.layout.home_history_split_pane_panel, container, false);
} else {
return inflater.inflate(R.layout.home_history_panel, container, false);
}
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mRangeList = (HomeListView) view.findViewById(R.id.range_list);
mList = (HomeListView) view.findViewById(R.id.list);
mList.setTag(HomePager.LIST_TAG_HISTORY);
if (mRangeList != null) {
mRangeList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
final MostRecentSection rangeItem = (MostRecentSection) adapter.getItemAtPosition(position);
if (rangeItem != null) {
// Notify data has changed for both range and item adapter.
// This will update selected rangeItem item background and the tabs list.
// This will also update the selected range along with cursor start and end.
selected = rangeItem;
mRangeAdapter.notifyDataSetChanged();
getLoaderManager().getLoader(LOADER_ID_HISTORY).forceLoad();
}
}
});
}
mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
@ -204,6 +237,7 @@ public class HistoryPanel extends HomeFragment {
@Override
public void onDestroyView() {
super.onDestroyView();
mRangeList = null;
mList = null;
mEmptyView = null;
mClearHistoryButton = null;
@ -214,17 +248,39 @@ public class HistoryPanel extends HomeFragment {
super.onActivityCreated(savedInstanceState);
// Reset selection.
selected = MostRecentSection.THIS_MONTH;
selected = mRangeList == null ? MostRecentSection.THIS_MONTH : MostRecentSection.TODAY;
// Initialize adapter
mAdapter = new HistoryHeaderListCursorAdapter(getActivity());
mList.setAdapter(mAdapter);
if (mRangeList != null) {
mAdapter = new HistoryItemAdapter(getActivity(), null, R.layout.home_item_row);
mRangeAdapter = new HistoryRangeAdapter(getActivity(), R.layout.home_history_range_item);
mRangeList.setAdapter(mRangeAdapter);
mList.setAdapter(mAdapter);
} else {
mAdapter = new HistoryHeaderListCursorAdapter(getActivity());
mList.setAdapter(mAdapter);
}
// Create callbacks before the initial loader is started
mCursorLoaderCallbacks = new CursorLoaderCallbacks();
// Update the section string with current time as reference.
updateRecentSectionOffset(getActivity());
loadIfVisible();
}
@Override
protected void loadIfVisible() {
// Force reload fragment only in tablets.
if (canLoad() && HardwareUtils.isTablet()) {
load();
return;
}
super.loadIfVisible();
}
@Override
protected void load() {
getLoaderManager().initLoader(LOADER_ID_HISTORY, null, mCursorLoaderCallbacks);
@ -404,6 +460,35 @@ public class HistoryPanel extends HomeFragment {
}
}
private static class HistoryRangeAdapter extends ArrayAdapter<MostRecentSection> {
private final Context context;
private final int resource;
public HistoryRangeAdapter(Context context, int resource) {
super(context, resource, MostRecentSection.values());
this.context = context;
this.resource = resource;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final View view;
if (convertView != null) {
view = convertView;
} else {
final LayoutInflater inflater = LayoutInflater.from(context);
view = inflater.inflate(resource, parent, false);
view.setTag(view.findViewById(R.id.range_title));
}
final MostRecentSection current = getItem(position);
final TextView textView = (TextView) view.getTag();
textView.setText(getMostRecentSectionTitle(current));
textView.setTextColor(ColorUtils.getColor(context, current == selected ? R.color.text_and_tabs_tray_grey : R.color.disabled_grey));
textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, current == selected ? R.drawable.home_group_collapsed : 0, 0);
return view;
}
}
private class CursorLoaderCallbacks extends TransitionAwareCursorLoaderCallbacks {
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {

Просмотреть файл

@ -314,6 +314,7 @@ gbjar.sources += [
'home/DynamicPanel.java',
'home/FramePanelLayout.java',
'home/HistoryHeaderListCursorAdapter.java',
'home/HistoryItemAdapter.java',
'home/HistoryPanel.java',
'home/HomeAdapter.java',
'home/HomeBanner.java',

Просмотреть файл

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/about_page_header_grey"
android:layout_width="match_parent"
android:layout_height="@dimen/page_row_height">
<TextView android:id="@+id/range_title"
style="@style/Widget.TwoLinePageRow.Title"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</FrameLayout>

Просмотреть файл

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<org.mozilla.gecko.home.HomeListView
android:id="@+id/range_list"
style="@style/Widget.HistoryListView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="@dimen/split_plane_left_pane_weight"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/divider_light"/>
<ViewStub android:id="@id/home_empty_view_stub"
android:layout="@layout/home_empty_panel"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="@dimen/split_plane_right_pane_weight"/>
<org.mozilla.gecko.home.HomeListView
android:id="@+id/list"
style="@style/Widget.HistoryListView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="@dimen/split_plane_right_pane_weight"/>
</LinearLayout>
<Button android:id="@+id/clear_history_button"
style="@style/Widget.Home.ActionButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/home_button_bar_bg"
android:text="@string/home_clear_history_button"
android:gravity="center"
android:visibility="gone"/>
</LinearLayout>

Просмотреть файл

@ -218,4 +218,6 @@
<item name="tab_strip_content_start" type="dimen">12dp</item>
<item name="split_plane_left_pane_weight" format="float" type="dimen">0.32</item>
<item name="split_plane_right_pane_weight" format="float" type="dimen">0.68</item>
</resources>

Просмотреть файл

@ -578,6 +578,11 @@
<item name="android:drawSelectorOnTop">true</item>
</style>
<style name="Widget.HistoryListView" parent="Widget.HomeListView">
<item name="android:childDivider">@color/divider_light</item>
<item name="android:drawSelectorOnTop">true</item>
</style>
<!-- TabsLayout Row -->
<style name="TabLayoutItemTextAppearance">
<item name="android:textColor">#FFFFFFFF</item>