Bug 998009 - Add "Clear browsing history" button to history panel. r=bnicholson

This commit is contained in:
Margaret Leibovic 2014-05-28 12:06:57 -07:00
Родитель 6f8d3a728c
Коммит d3c278b1e4
4 изменённых файлов: 63 добавлений и 2 удалений

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

@ -15,10 +15,13 @@ import org.mozilla.gecko.db.BrowserContract.Combined;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.db.BrowserDB.URLColumns;
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import org.mozilla.gecko.util.ThreadUtils;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
@ -48,6 +51,9 @@ public class MostRecentPanel extends HomeFragment {
// The view shown by the fragment.
private HomeListView mList;
// The button view for clearing browsing history.
private View mClearHistoryButton;
// Reference to the View to display when there are no results.
private View mEmptyView;
@ -127,6 +133,40 @@ public class MostRecentPanel extends HomeFragment {
}
});
registerForContextMenu(mList);
mClearHistoryButton = view.findViewById(R.id.clear_history_button);
mClearHistoryButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Context context = getActivity();
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
dialogBuilder.setMessage(R.string.home_clear_history_confirm);
dialogBuilder.setNegativeButton(R.string.button_cancel, new AlertDialog.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
dialog.dismiss();
}
});
dialogBuilder.setPositiveButton(R.string.button_yes, new AlertDialog.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
dialog.dismiss();
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
final ContentResolver cr = context.getContentResolver();
BrowserDB.clearHistory(cr);
}
});
}
});
dialogBuilder.show();
}
});
}
@Override
@ -134,6 +174,7 @@ public class MostRecentPanel extends HomeFragment {
super.onDestroyView();
mList = null;
mEmptyView = null;
mClearHistoryButton = null;
}
@Override
@ -171,10 +212,14 @@ public class MostRecentPanel extends HomeFragment {
private void updateUiFromCursor(Cursor c) {
if (c != null && c.getCount() > 0) {
mClearHistoryButton.setVisibility(View.VISIBLE);
return;
}
// Cursor is empty, so set the empty view if it hasn't been set already.
// Cursor is empty, so hide the "Clear browsing history" button,
// and set the empty view if it hasn't been set already.
mClearHistoryButton.setVisibility(View.GONE);
if (mEmptyView == null) {
// Set empty panel view. We delay this so that the empty view won't flash.
final ViewStub emptyViewStub = (ViewStub) getView().findViewById(R.id.home_empty_view_stub);

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

@ -342,6 +342,8 @@ size. -->
<!ENTITY home_top_sites_add "Add a site">
<!ENTITY home_history_title "History">
<!ENTITY home_clear_history_button "Clear browsing history">
<!ENTITY home_clear_history_confirm "Are you sure you want to clear your history?">
<!ENTITY home_bookmarks_empty "Bookmarks you save show up here.">
<!ENTITY home_last_tabs_title "Tabs from last time">
<!ENTITY home_last_tabs_open "Open all tabs from last time">

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

@ -10,4 +10,16 @@
<include layout="@layout/home_history_list"/>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/home_last_tab_bar_bg">
<Button android:id="@+id/clear_history_button"
style="@style/Widget.Home.ActionButton"
android:text="@string/home_clear_history_button"
android:gravity="center"
android:visibility="gone"/>
</LinearLayout>
</LinearLayout>

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

@ -309,6 +309,8 @@
<string name="home_top_sites_title">&home_top_sites_title;</string>
<string name="home_top_sites_add">&home_top_sites_add;</string>
<string name="home_history_title">&home_history_title;</string>
<string name="home_clear_history_button">&home_clear_history_button;</string>
<string name="home_clear_history_confirm">&home_clear_history_confirm;</string>
<string name="home_bookmarks_empty">&home_bookmarks_empty;</string>
<string name="home_last_tabs_title">&home_last_tabs_title;</string>
<string name="home_last_tabs_open">&home_last_tabs_open;</string>