Twidere-App-Android-Twitter.../twidere/src/main/java/org/mariotaku/twidere/fragment/DestroySavedSearchDialogFra...

99 lines
3.7 KiB
Java
Raw Normal View History

2014-07-03 07:48:39 +02:00
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2016-03-18 17:04:03 +01:00
package org.mariotaku.twidere.fragment;
2014-07-03 07:48:39 +02:00
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
2014-07-03 07:48:39 +02:00
import android.support.v4.app.FragmentManager;
2015-10-05 12:00:07 +02:00
import android.support.v7.app.AlertDialog;
2014-07-03 07:48:39 +02:00
import org.mariotaku.twidere.R;
2016-03-07 18:25:18 +01:00
import org.mariotaku.twidere.model.UserKey;
2014-07-03 07:48:39 +02:00
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
2016-05-15 12:18:04 +02:00
public class DestroySavedSearchDialogFragment extends BaseDialogFragment implements
2015-10-05 12:00:07 +02:00
DialogInterface.OnClickListener {
2014-07-03 07:48:39 +02:00
2015-10-05 12:00:07 +02:00
public static final String FRAGMENT_TAG = "destroy_saved_search";
2014-07-03 07:48:39 +02:00
2015-10-05 12:00:07 +02:00
@Override
public void onClick(final DialogInterface dialog, final int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
2016-03-07 18:25:18 +01:00
final UserKey accountKey = getAccountKey();
2015-11-25 01:47:30 +01:00
final long searchId = getSearchId();
2016-07-02 05:54:53 +02:00
final AsyncTwitterWrapper twitter = twitterWrapper;
2016-07-06 15:21:34 +02:00
if (searchId <= 0) return;
2016-03-06 16:17:28 +01:00
twitter.destroySavedSearchAsync(accountKey, searchId);
2015-10-05 12:00:07 +02:00
break;
default:
break;
}
}
2014-07-03 07:48:39 +02:00
2015-10-05 12:00:07 +02:00
@NonNull
@Override
2015-10-05 12:00:07 +02:00
public Dialog onCreateDialog(final Bundle savedInstanceState) {
2016-03-26 06:16:41 +01:00
final Context context = getActivity();
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
2015-10-05 12:00:07 +02:00
final String name = getSearchName();
if (name != null) {
builder.setTitle(getString(R.string.destroy_saved_search, name));
builder.setMessage(getString(R.string.destroy_saved_search_confirm_message, name));
}
builder.setPositiveButton(android.R.string.ok, this);
builder.setNegativeButton(android.R.string.cancel, null);
return builder.create();
}
2014-07-03 07:48:39 +02:00
2016-03-07 18:25:18 +01:00
private UserKey getAccountKey() {
2015-10-05 12:00:07 +02:00
final Bundle args = getArguments();
2016-03-06 16:17:28 +01:00
return args.getParcelable(EXTRA_ACCOUNT_KEY);
2015-10-05 12:00:07 +02:00
}
2014-07-03 07:48:39 +02:00
2015-11-25 01:47:30 +01:00
private long getSearchId() {
2015-10-05 12:00:07 +02:00
final Bundle args = getArguments();
if (!args.containsKey(EXTRA_SEARCH_ID)) return -1;
2015-11-25 01:47:30 +01:00
return args.getLong(EXTRA_SEARCH_ID);
2015-10-05 12:00:07 +02:00
}
2014-07-03 07:48:39 +02:00
2015-10-05 12:00:07 +02:00
private String getSearchName() {
final Bundle args = getArguments();
if (!args.containsKey(EXTRA_NAME)) return null;
return args.getString(EXTRA_NAME);
}
2014-07-03 07:48:39 +02:00
2016-03-07 03:43:09 +01:00
public static DestroySavedSearchDialogFragment show(final FragmentManager fm,
2016-03-07 18:25:18 +01:00
final UserKey accountKey,
2015-11-25 01:47:30 +01:00
final long searchId, final String name) {
2015-10-05 12:00:07 +02:00
final Bundle args = new Bundle();
2016-03-07 03:43:09 +01:00
args.putParcelable(EXTRA_ACCOUNT_KEY, accountKey);
2015-11-25 01:47:30 +01:00
args.putLong(EXTRA_SEARCH_ID, searchId);
2015-10-05 12:00:07 +02:00
args.putString(EXTRA_NAME, name);
final DestroySavedSearchDialogFragment f = new DestroySavedSearchDialogFragment();
f.setArguments(args);
f.show(fm, FRAGMENT_TAG);
return f;
}
2014-07-03 07:48:39 +02:00
}