2015-06-29 19:12:11 +02:00
|
|
|
/*
|
2015-10-29 18:10:07 +01:00
|
|
|
* This is the source code of Telegram for Android v. 3.x.x.
|
2015-06-29 19:12:11 +02:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
2016-01-11 18:19:48 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2016.
|
2015-06-29 19:12:11 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui.Components;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
2015-09-24 22:52:02 +02:00
|
|
|
import android.app.AlertDialog;
|
2015-06-29 19:12:11 +02:00
|
|
|
import android.app.Dialog;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
2015-09-24 22:52:02 +02:00
|
|
|
import android.content.Intent;
|
2015-06-29 19:12:11 +02:00
|
|
|
import android.content.SharedPreferences;
|
2015-09-24 22:52:02 +02:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.provider.Browser;
|
2015-06-29 19:12:11 +02:00
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.FileLog;
|
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
|
import org.telegram.messenger.MessagesController;
|
|
|
|
import org.telegram.messenger.MessagesStorage;
|
|
|
|
import org.telegram.messenger.NotificationsController;
|
2015-06-29 19:12:11 +02:00
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
|
|
|
import org.telegram.messenger.R;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
|
|
|
import org.telegram.tgnet.TLRPC;
|
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
2015-06-29 19:12:11 +02:00
|
|
|
import org.telegram.ui.ActionBar.BottomSheet;
|
|
|
|
|
|
|
|
public class AlertsCreator {
|
|
|
|
|
|
|
|
public static Dialog createMuteAlert(Context context, final long dialog_id) {
|
|
|
|
if (context == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
BottomSheet.Builder builder = new BottomSheet.Builder(context);
|
|
|
|
builder.setTitle(LocaleController.getString("Notifications", R.string.Notifications));
|
|
|
|
CharSequence[] items = new CharSequence[]{
|
|
|
|
LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 1)),
|
|
|
|
LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 8)),
|
|
|
|
LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Days", 2)),
|
|
|
|
LocaleController.getString("MuteDisable", R.string.MuteDisable)
|
|
|
|
};
|
|
|
|
builder.setItems(items, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
int untilTime = ConnectionsManager.getInstance().getCurrentTime();
|
|
|
|
if (i == 0) {
|
|
|
|
untilTime += 60 * 60;
|
|
|
|
} else if (i == 1) {
|
|
|
|
untilTime += 60 * 60 * 8;
|
|
|
|
} else if (i == 2) {
|
|
|
|
untilTime += 60 * 60 * 48;
|
|
|
|
} else if (i == 3) {
|
|
|
|
untilTime = Integer.MAX_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
long flags;
|
|
|
|
if (i == 3) {
|
|
|
|
editor.putInt("notify2_" + dialog_id, 2);
|
|
|
|
flags = 1;
|
|
|
|
} else {
|
|
|
|
editor.putInt("notify2_" + dialog_id, 3);
|
|
|
|
editor.putInt("notifyuntil_" + dialog_id, untilTime);
|
|
|
|
flags = ((long) untilTime << 32) | 1;
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
NotificationsController.getInstance().removeNotificationsForDialog(dialog_id);
|
2015-06-29 19:12:11 +02:00
|
|
|
MessagesStorage.getInstance().setDialogFlags(dialog_id, flags);
|
|
|
|
editor.commit();
|
2015-09-24 22:52:02 +02:00
|
|
|
TLRPC.Dialog dialog = MessagesController.getInstance().dialogs_dict.get(dialog_id);
|
2015-06-29 19:12:11 +02:00
|
|
|
if (dialog != null) {
|
|
|
|
dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
|
|
|
|
dialog.notify_settings.mute_until = untilTime;
|
|
|
|
}
|
|
|
|
NotificationsController.updateServerNotificationsSettings(dialog_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return builder.create();
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
|
2015-11-26 22:04:02 +01:00
|
|
|
public static void showAddUserAlert(String error, final BaseFragment fragment, boolean isChannel) {
|
2015-09-24 22:52:02 +02:00
|
|
|
if (error == null || fragment == null || fragment.getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity());
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
switch (error) {
|
|
|
|
case "PEER_FLOOD":
|
|
|
|
builder.setMessage(LocaleController.getString("NobodyLikesSpam2", R.string.NobodyLikesSpam2));
|
|
|
|
builder.setNegativeButton(LocaleController.getString("MoreInfo", R.string.MoreInfo), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
try {
|
2015-10-29 18:10:07 +01:00
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(LocaleController.getString("NobodyLikesSpamUrl", R.string.NobodyLikesSpamUrl)));
|
2015-09-24 22:52:02 +02:00
|
|
|
intent.putExtra(Browser.EXTRA_APPLICATION_ID, fragment.getParentActivity().getPackageName());
|
|
|
|
fragment.getParentActivity().startActivity(intent);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case "USER_BLOCKED":
|
2015-10-29 18:10:07 +01:00
|
|
|
case "USER_BOT":
|
2015-09-24 22:52:02 +02:00
|
|
|
case "USER_ID_INVALID":
|
2015-11-26 22:04:02 +01:00
|
|
|
if (isChannel) {
|
|
|
|
builder.setMessage(LocaleController.getString("ChannelUserCantAdd", R.string.ChannelUserCantAdd));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("GroupUserCantAdd", R.string.GroupUserCantAdd));
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
break;
|
|
|
|
case "USERS_TOO_MUCH":
|
2015-11-26 22:04:02 +01:00
|
|
|
if (isChannel) {
|
|
|
|
builder.setMessage(LocaleController.getString("ChannelUserAddLimit", R.string.ChannelUserAddLimit));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("GroupUserAddLimit", R.string.GroupUserAddLimit));
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
break;
|
|
|
|
case "USER_NOT_MUTUAL_CONTACT":
|
2015-11-26 22:04:02 +01:00
|
|
|
if (isChannel) {
|
|
|
|
builder.setMessage(LocaleController.getString("ChannelUserLeftError", R.string.ChannelUserLeftError));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("GroupUserLeftError", R.string.GroupUserLeftError));
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
break;
|
2015-10-29 18:10:07 +01:00
|
|
|
case "ADMINS_TOO_MUCH":
|
2015-11-26 22:04:02 +01:00
|
|
|
if (isChannel) {
|
|
|
|
builder.setMessage(LocaleController.getString("ChannelUserCantAdmin", R.string.ChannelUserCantAdmin));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("GroupUserCantAdmin", R.string.GroupUserCantAdmin));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "BOTS_TOO_MUCH":
|
|
|
|
if (isChannel) {
|
|
|
|
builder.setMessage(LocaleController.getString("ChannelUserCantBot", R.string.ChannelUserCantBot));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.getString("GroupUserCantBot", R.string.GroupUserCantBot));
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
break;
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
|
|
|
fragment.showDialog(builder.create(), true);
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|