Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added alert box while clear button is clicked on the TransactionListFragment #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
package com.readystatesoftware.chuck.internal.ui;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
import android.os.Bundle;
import android.support.annotation.Nullable;
Expand Down Expand Up @@ -48,7 +50,8 @@ public class TransactionListFragment extends Fragment implements
private OnListFragmentInteractionListener listener;
private TransactionAdapter adapter;

public TransactionListFragment() {}
public TransactionListFragment() {
}

public static TransactionListFragment newInstance() {
return new TransactionListFragment();
Expand Down Expand Up @@ -112,8 +115,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.clear) {
getContext().getContentResolver().delete(ChuckContentProvider.TRANSACTION_URI, null, null);
NotificationHelper.clearBuffer();
showClearAllTransactionsDialog();
return true;
} else if (item.getItemId() == R.id.browse_sql) {
SQLiteUtils.browseDatabase(getContext());
Expand All @@ -123,17 +125,38 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
}

private void showClearAllTransactionsDialog() {
new AlertDialog.Builder(getContext())
.setTitle(R.string.chuck_clear)
.setMessage(R.string.chuck_clear_dialog_message)
.setPositiveButton(R.string.chuck_clear, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
getContext().getContentResolver().delete(ChuckContentProvider.TRANSACTION_URI, null, null);
NotificationHelper.clearBuffer();
}
})
.setNegativeButton(R.string.chuck_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.show();
}

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
CursorLoader loader = new CursorLoader(getContext());
loader.setUri(ChuckContentProvider.TRANSACTION_URI);
if (!TextUtils.isEmpty(currentFilter)) {
if (TextUtils.isDigitsOnly(currentFilter)) {
loader.setSelection("responseCode LIKE ?");
loader.setSelectionArgs(new String[]{ currentFilter + "%" });
loader.setSelectionArgs(new String[]{currentFilter + "%"});
} else {
loader.setSelection("path LIKE ?");
loader.setSelectionArgs(new String[]{ "%" + currentFilter + "%" });
loader.setSelectionArgs(new String[]{"%" + currentFilter + "%"});
}
}
loader.setProjection(HttpTransaction.PARTIAL_PROJECTION);
Expand Down
2 changes: 2 additions & 0 deletions library/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@
<string name="chuck_search">Search</string>
<string name="chuck_body_unexpected_eof">\n\n--- Unexpected end of content ---</string>
<string name="chuck_body_content_truncated">\n\n--- Content truncated ---</string>
<string name="chuck_cancel">Cancel</string>
<string name="chuck_clear_dialog_message">Do you want to clear complete http call history from chuck ?</string>
</resources>