From 7a99b655eccd5e3a333ca84e96a4657cd2662a10 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Fri, 18 Nov 2016 00:35:00 +0100 Subject: [PATCH] Unify group and chat creation. --- TMessagesProj/jni/mr_wrapper.c | 25 +- .../telegram/messenger/ApplicationLoader.java | 2 - .../messenger/MessagesController.java | 155 +------- .../org/telegram/messenger/MrMailbox.java | 17 +- .../main/java/org/telegram/tgnet/TLRPC.java | 18 - .../org/telegram/ui/BlockedUsersActivity.java | 96 ++--- .../java/org/telegram/ui/ChatActivity.java | 15 +- .../ui/Components/ChatActivityEnterView.java | 8 +- .../org/telegram/ui/ContactsActivity.java | 301 +++++----------- .../java/org/telegram/ui/DialogsActivity.java | 2 +- .../org/telegram/ui/GroupCreateActivity.java | 12 +- .../org/telegram/ui/GroupInviteActivity.java | 340 ------------------ .../java/org/telegram/ui/LaunchActivity.java | 25 +- .../java/org/telegram/ui/ProfileActivity.java | 39 +- .../src/main/res/values-de/strings.xml | 5 +- .../src/main/res/values-es/strings.xml | 3 +- .../src/main/res/values-it/strings.xml | 3 +- .../src/main/res/values-nl/strings.xml | 3 +- .../src/main/res/values-pt/strings.xml | 3 +- TMessagesProj/src/main/res/values/strings.xml | 7 +- 20 files changed, 225 insertions(+), 854 deletions(-) delete mode 100644 TMessagesProj/src/main/java/org/telegram/ui/GroupInviteActivity.java diff --git a/TMessagesProj/jni/mr_wrapper.c b/TMessagesProj/jni/mr_wrapper.c index d25f3c77b..d0bfddde6 100644 --- a/TMessagesProj/jni/mr_wrapper.c +++ b/TMessagesProj/jni/mr_wrapper.c @@ -204,9 +204,23 @@ JNIEXPORT jintArray Java_org_telegram_messenger_MrMailbox_MrMailboxGetKnownConta return carray2jintArray_n_carray_free(env, ca); } -JNIEXPORT jlong Java_org_telegram_messenger_MrMailbox_MrMailboxGetContact(JNIEnv *env, jclass c, jlong hMailbox, jint id) + +JNIEXPORT jintArray Java_org_telegram_messenger_MrMailbox_MrMailboxGetBlockedContacts(JNIEnv *env, jclass c, jlong hMailbox) { - return (jlong)mrmailbox_get_contact((mrmailbox_t*)hMailbox, id); + carray* ca = mrmailbox_get_blocked_contacts((mrmailbox_t*)hMailbox); + return carray2jintArray_n_carray_free(env, ca); +} + + +JNIEXPORT jlong Java_org_telegram_messenger_MrMailbox_MrMailboxGetContact(JNIEnv *env, jclass c, jlong hMailbox, jint contact_id) +{ + return (jlong)mrmailbox_get_contact((mrmailbox_t*)hMailbox, contact_id); +} + + +JNIEXPORT jint Java_org_telegram_messenger_MrMailbox_MrMailboxBlockContact(JNIEnv *env, jclass c, jlong hMailbox, jint contact_id, jint block) +{ + return (jint)mrmailbox_block_contact((mrmailbox_t*)hMailbox, contact_id, block); } @@ -627,6 +641,13 @@ JNIEXPORT jstring Java_org_telegram_messenger_MrMailbox_MrContactGetAddr(JNIEnv } +JNIEXPORT jint Java_org_telegram_messenger_MrMailbox_MrContactIsBlocked(JNIEnv *env, jclass c, jlong hContact) +{ + mrcontact_t* ths = (mrcontact_t*)hContact; if( ths == NULL ) { return 0; } + return (jint)ths->m_blocked; +} + + /******************************************************************************* * MrPoortext ******************************************************************************/ diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ApplicationLoader.java b/TMessagesProj/src/main/java/org/telegram/messenger/ApplicationLoader.java index 7ece26e90..1d1c08cad 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/ApplicationLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/ApplicationLoader.java @@ -228,8 +228,6 @@ public class ApplicationLoader extends Application { ConnectionsManager.getInstance().init(deviceModel, systemVersion, appVersion, langCode, configPath, FileLog.getNetworkLogPath(), UserConfig.getClientUserId(), enablePushConnection); if (UserConfig.getCurrentUser() != null) { MessagesController.getInstance().putUser(UserConfig.getCurrentUser(), true); - //ConnectionsManager.getInstance().applyCountryPortNumber(UserConfig.getCurrentUser().phone); - MessagesController.getInstance().getBlockedUsers(true); SendMessagesHelper.getInstance().checkUnsentMessages(); } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java index 2b36d3f33..42015720c 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java @@ -14,13 +14,10 @@ import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.SharedPreferences; import android.os.Bundle; -import android.util.SparseArray; -import android.util.SparseIntArray; import org.telegram.messenger.query.DraftQuery; import org.telegram.messenger.query.MessagesQuery; import org.telegram.messenger.query.SearchQuery; -import org.telegram.messenger.query.StickersQuery; import org.telegram.tgnet.ConnectionsManager; import org.telegram.tgnet.TLObject; import org.telegram.tgnet.TLRPC; @@ -46,79 +43,29 @@ public class MessagesController implements NotificationCenter.NotificationCenter public ArrayList dialogsServerOnly = new ArrayList<>(); public ArrayList dialogsGroupsOnly = new ArrayList<>(); public int nextDialogsCacheOffset; - public ConcurrentHashMap dialogs_read_inbox_max = new ConcurrentHashMap<>(100, 1.0f, 2); - public ConcurrentHashMap dialogs_read_outbox_max = new ConcurrentHashMap<>(100, 1.0f, 2); public ConcurrentHashMap dialogs_dict = new ConcurrentHashMap<>(100, 1.0f, 2); public HashMap dialogMessage = new HashMap<>(); public HashMap dialogMessagesByRandomIds = new HashMap<>(); public HashMap dialogMessagesByIds = new HashMap<>(); - public ConcurrentHashMap> printingUsers = new ConcurrentHashMap<>(20, 1.0f, 2); public HashMap printingStrings = new HashMap<>(); - public HashMap printingStringsTypes = new HashMap<>(); - public HashMap> sendingTypings = new HashMap<>(); public ConcurrentHashMap onlinePrivacy = new ConcurrentHashMap<>(20, 1.0f, 2); - private int lastPrintingStringCount = 0; - - private HashMap loadingPeerSettings = new HashMap<>(); private ArrayList createdDialogIds = new ArrayList<>(); - private SparseIntArray shortPollChannels = new SparseIntArray(); - private SparseIntArray needShortPollChannels = new SparseIntArray(); - - public boolean loadingBlockedUsers = false; - public ArrayList blockedUsers = new ArrayList<>(); - - private SparseArray> channelViewsToSend = new SparseArray<>(); - private SparseArray> channelViewsToReload = new SparseArray<>(); - - private HashMap> updatesQueueChannels = new HashMap<>(); - private HashMap updatesStartWaitTimeChannels = new HashMap<>(); - private HashMap channelsPts = new HashMap<>(); - private HashMap gettingDifferenceChannels = new HashMap<>(); - - private HashMap gettingUnknownChannels = new HashMap<>(); - private HashMap checkingLastMessagesDialogs = new HashMap<>(); - - private ArrayList loadingFullUsers = new ArrayList<>(); private ArrayList loadedFullUsers = new ArrayList<>(); - private ArrayList loadingFullChats = new ArrayList<>(); - private ArrayList loadingFullParticipants = new ArrayList<>(); - private ArrayList loadedFullParticipants = new ArrayList<>(); private ArrayList loadedFullChats = new ArrayList<>(); private HashMap> reloadingWebpages = new HashMap<>(); - private HashMap> reloadingWebpagesPending = new HashMap<>(); - - private HashMap> reloadingMessages = new HashMap<>(); - - private boolean gettingNewDeleteTask = false; - private int currentDeletingTaskTime = 0; - private ArrayList currentDeletingTaskMids = null; - private Runnable currentDeleteTaskRunnable = null; public boolean loadingDialogs = false; public boolean dialogsEndReached = false; - public boolean gettingDifference = false; - public boolean updatingState = false; - public boolean firstGettingTask = false; - public boolean registeringForPush = false; public int secretWebpagePreview = 2; - private int statusRequest = 0; - private int statusSettingState = 0; - private boolean offlineSent = false; private String uploadingAvatar = null; public boolean enableJoined = true; public int fontSize = AndroidUtilities.dp(16); - public int maxGroupCount = 200; - public int maxBroadcastCount = 100; - public int maxMegagroupCount = 5000; - public int minGroupConvertSize = 200; - public int maxEditTime = 172800; - public int groupBigSize; public int ratingDecay; public static final int UPDATE_MASK_NAME = 1; @@ -136,11 +83,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter public static final int UPDATE_MASK_CHANNEL = 8192; public static final int UPDATE_MASK_CHAT_ADMINS = 16384; - public static class PrintingUser { - public int userId; - public TLRPC.SendMessageAction action; - } - private static volatile MessagesController Instance = null; private final Comparator dialogComparator = new Comparator() { @@ -185,10 +127,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); secretWebpagePreview = preferences.getInt("secretWebpage2", 2); - maxGroupCount = preferences.getInt("maxGroupCount", 200); - maxMegagroupCount = preferences.getInt("maxMegagroupCount", 1000); - maxEditTime = preferences.getInt("maxEditTime", 3600); - groupBigSize = preferences.getInt("groupBigSize", 10); ratingDecay = preferences.getInt("ratingDecay", 2419200); fontSize = preferences.getInt("fons_size", AndroidUtilities.isTablet() ? 18 : 16); } @@ -239,16 +177,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter public static TLRPC.Peer getPeer(int id) { TLRPC.Peer inputPeer; if (id < 0) { - TLRPC.Chat chat = getInstance().getChat(-id); - /*if (chat instanceof TLRPC.TL_channel || chat instanceof TLRPC.TL_channelForbidden) { - inputPeer = new TLRPC.TL_peerChannel(); - inputPeer.channel_id = -id; - } else*/ { - inputPeer = new TLRPC.TL_peerChat(); - inputPeer.chat_id = -id; - } + inputPeer = new TLRPC.TL_peerChat(); + inputPeer.chat_id = -id; } else { - TLRPC.User user = getInstance().getUser(id); inputPeer = new TLRPC.TL_peerUser(); inputPeer.user_id = id; } @@ -682,80 +613,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter } */ - public void blockUser(int user_id) { - final TLRPC.User user = getUser(user_id); - if (user == null || blockedUsers.contains(user_id)) { - return; - } - blockedUsers.add(user_id); - if (user.bot) { - SearchQuery.removeInline(user_id); - } else { - SearchQuery.removePeer(user_id); - } - NotificationCenter.getInstance().postNotificationName(NotificationCenter.blockedUsersDidLoaded); - TLRPC.TL_contacts_block req = new TLRPC.TL_contacts_block(); - req.id = getInputUser(user); - /*ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { - @Override - public void run(TLObject response, TLRPC.TL_error error) { - if (error == null) { - ArrayList ids = new ArrayList<>(); - ids.add(user.id); - //MessagesStorage.getInstance().putBlockedUsers(ids, false); - } - } - });*/ - } - - public void unblockUser(int user_id) { - TLRPC.TL_contacts_unblock req = new TLRPC.TL_contacts_unblock(); - final TLRPC.User user = getUser(user_id); - if (user == null) { - return; - } - blockedUsers.remove((Integer) user.id); - req.id = getInputUser(user); - NotificationCenter.getInstance().postNotificationName(NotificationCenter.blockedUsersDidLoaded); - /*ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { - @Override - public void run(TLObject response, TLRPC.TL_error error) { - //MessagesStorage.getInstance().deleteBlockedUser(user.id); - } - });*/ - } - - public void getBlockedUsers(boolean cache) { - if (!UserConfig.isClientActivated() || loadingBlockedUsers) { - return; - } - loadingBlockedUsers = true; - if (cache) { - //MessagesStorage.getInstance().getBlockedUsers(); - } else { - TLRPC.TL_contacts_getBlocked req = new TLRPC.TL_contacts_getBlocked(); - req.offset = 0; - req.limit = 200; - /*ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { - @Override - public void run(TLObject response, TLRPC.TL_error error) { - ArrayList blocked = new ArrayList<>(); - ArrayList users = null; - if (error == null) { - final TLRPC.contacts_Blocked res = (TLRPC.contacts_Blocked) response; - for (TLRPC.TL_contactBlocked contactBlocked : res.blocked) { - blocked.add(contactBlocked.user_id); - } - users = res.users; - //MessagesStorage.getInstance().putUsersAndChats(res.users, null, true, true); - //MessagesStorage.getInstance().putBlockedUsers(blocked, true); - } - processLoadedBlockedUsers(blocked, users, false); - } - });*/ - } - } - public void deleteMessages(ArrayList messages, ArrayList randoms, TLRPC.EncryptedChat encryptedChat, final int channelId) { } @@ -1035,14 +892,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter public void addUserToChat(final int chat_id, final TLRPC.User user, final TLRPC.ChatFull info, int count_fwd, String botHash, final BaseFragment fragment) { } - public void deleteUserFromChat(final int chat_id, final TLRPC.User user, final TLRPC.ChatFull info) { - } - - /* - public void changeChatTitle(int chat_id, String title) { - } - */ - public void changeChatAvatar(int chat_id, TLRPC.InputFile uploadedAvatar) { TLObject request; { diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MrMailbox.java b/TMessagesProj/src/main/java/org/telegram/messenger/MrMailbox.java index 8d819dece..45b920442 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MrMailbox.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MrMailbox.java @@ -172,6 +172,7 @@ public class MrMailbox { // this function is called from within the C-wrapper public final static int MR_EVENT_MSGS_UPDATED = 2000; + public final static int MR_EVENT_BLOCKING_CHANGED = 2020; public final static int MR_EVENT_IS_EMAIL_KNOWN = 2010; public final static int MR_EVENT_MSG_DELIVERED = 3000; public final static int MR_EVENT_MSG_READ = 3010; @@ -179,7 +180,6 @@ public class MrMailbox { { switch(event) { case MR_EVENT_MSGS_UPDATED: - Log.i(TAG, "Received MR_EVENT_MSGS_UPDATED!"); AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { @@ -201,6 +201,17 @@ public class MrMailbox { }); return 0; + case MR_EVENT_BLOCKING_CHANGED: + AndroidUtilities.runOnUIThread(new Runnable() { + @Override + public void run() { + reloadMainChatlist(); + NotificationCenter.getInstance().postNotificationName(NotificationCenter.blockedUsersDidLoaded); + NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload); + } + }); + return 0; + case MR_EVENT_IS_EMAIL_KNOWN: String emailAdr = CPtr2String(data1); return 0; @@ -219,7 +230,9 @@ public class MrMailbox { public native static int MrMailboxFetch (long hMailbox); public native static int[] MrMailboxGetKnownContacts (long hMailbox); + public native static int[] MrMailboxGetBlockedContacts(long hMailbox); public native static long MrMailboxGetContact (long hMailbox, int id);// returns hContact which must be unref'd after usage + public native static int MrMailboxBlockContact (long hMailbox, int id, int block); public native static long MrMailboxGetChatlist (long hMailbox); // returns hChatlist which must be unref'd after usage public native static long MrMailboxGetChat (long hMailbox, int chat_id); // return hChat which must be unref'd after usage @@ -279,13 +292,13 @@ public class MrMailbox { public native static String MrMsgGetParam (long hMsg, int key, String def); public native static int MrMsgGetParamInt (long hMsg, int key, int def); - // MrContact objects public native static void MrContactUnref (long hContact); public native static String MrContactGetName (long hContact); public native static String MrContactGetAddr (long hContact); public static String MrContactGetDisplayName (long hContact) { String s=MrContactGetName(hContact); if(s.isEmpty()) {s=MrContactGetAddr(hContact);} return s; } public static String MrContactGetNameNAddr (long hContact) { String s=MrContactGetName(hContact); if(s.isEmpty()) {s=MrContactGetAddr(hContact);} else { s+=" ("+MrContactGetAddr(hContact)+")"; } return s; } + public native static int MrContactIsBlocked (long hContact); // MrPoortext objects public native static void MrPoortextUnref (long hPoortext); diff --git a/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java b/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java index e2acbcc8c..864e35941 100644 --- a/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java +++ b/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java @@ -584,7 +584,6 @@ public class TLRPC { public int id; public String title; public ChatPhoto photo; - public int participants_count; public int date; public int version; public boolean editor; @@ -677,10 +676,6 @@ public class TLRPC { public static class TL_photoCachedSize extends PhotoSize { } - public static class ExportedChatInvite extends TLObject { - public String link; - } - public static class InputFile extends TLObject { public long id; public int parts; @@ -779,19 +774,6 @@ public class TLRPC { public ArrayList id = new ArrayList<>(); } - public static class TL_contacts_block extends TLObject { - public InputUser id; - } - - public static class TL_contacts_unblock extends TLObject { - public InputUser id; - } - - public static class TL_contacts_getBlocked extends TLObject { - public int offset; - public int limit; - } - public static class TL_messages_getDialogs extends TLObject { public int offset_date; public int offset_id; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/BlockedUsersActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/BlockedUsersActivity.java index a395366f3..9e4232511 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/BlockedUsersActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/BlockedUsersActivity.java @@ -1,4 +1,6 @@ /* + * This part of the Delta Chat fronted is based on Telegram which is covered by the following note: + * * This is the source code of Telegram for Android v. 3.x.x. * It is licensed under GNU GPL v. 2 or later. * You should have received a copy of the license in this archive (see LICENSE). @@ -22,12 +24,12 @@ import android.widget.ListView; import android.widget.TextView; import org.telegram.messenger.LocaleController; +import org.telegram.messenger.MrMailbox; import org.telegram.tgnet.TLRPC; import org.telegram.messenger.MessagesController; import org.telegram.messenger.NotificationCenter; import org.telegram.messenger.R; import org.telegram.ui.Adapters.BaseFragmentAdapter; -import org.telegram.ui.Cells.TextInfoCell; import org.telegram.ui.Cells.UserCell; import org.telegram.ui.ActionBar.ActionBar; import org.telegram.ui.ActionBar.ActionBarMenu; @@ -38,19 +40,19 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe private ListView listView; private ListAdapter listViewAdapter; - //private FrameLayout progressView; -- EDIT BY MR private TextView emptyTextView; private int selectedUserId; - private final static int block_user = 1; + private int[] blockedUserIds; + @Override public boolean onFragmentCreate() { super.onFragmentCreate(); + blockedUserIds = MrMailbox.MrMailboxGetBlockedContacts(MrMailbox.hMailbox); NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces); NotificationCenter.getInstance().addObserver(this, NotificationCenter.blockedUsersDidLoaded); - MessagesController.getInstance().getBlockedUsers(false); return true; } @@ -73,8 +75,7 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe finishFragment(); } else if (id == block_user) { Bundle args = new Bundle(); - args.putBoolean("onlyUsers", true); - args.putBoolean("returnAsResult", true); + args.putInt("do_what", ContactsActivity.SELECT_CONTACT_TO_BLOCK); ContactsActivity fragment = new ContactsActivity(args); fragment.setDelegate(BlockedUsersActivity.this); presentFragment(fragment); @@ -102,14 +103,6 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe } }); - /* EDIT BY MR - progressView = new FrameLayout(context); - frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); - - ProgressBar progressBar = new ProgressBar(context); - progressView.addView(progressBar, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); - */ - listView = new ListView(context); listView.setEmptyView(emptyTextView); listView.setVerticalScrollBarEnabled(false); @@ -122,9 +115,9 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView adapterView, View view, int i, long l) { - if (i < MessagesController.getInstance().blockedUsers.size()) { + if (i>=0 && i < blockedUserIds.length) { Bundle args = new Bundle(); - args.putInt("user_id", MessagesController.getInstance().blockedUsers.get(i)); + args.putInt("user_id", blockedUserIds[i]); presentFragment(new ProfileActivity(args)); } } @@ -133,37 +126,27 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView adapterView, View view, int i, long l) { - if (i < 0 || i >= MessagesController.getInstance().blockedUsers.size() || getParentActivity() == null) { + if (i < 0 || i >= blockedUserIds.length || getParentActivity() == null) { return true; } - selectedUserId = MessagesController.getInstance().blockedUsers.get(i); + selectedUserId = blockedUserIds[i]; AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); - CharSequence[] items = new CharSequence[]{LocaleController.getString("Unblock", R.string.Unblock)}; + CharSequence[] items = new CharSequence[]{LocaleController.getString("UnblockContact", R.string.UnblockContact)}; builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (i == 0) { - MessagesController.getInstance().unblockUser(selectedUserId); + MrMailbox.MrMailboxBlockContact(MrMailbox.hMailbox, selectedUserId, 0); } } }); showDialog(builder.create()); - return true; } }); - /* EDIT BY MR - if (MessagesController.getInstance().loadingBlockedUsers) { - progressView.setVisibility(View.VISIBLE); - emptyTextView.setVisibility(View.GONE); - listView.setEmptyView(null); - } else { - progressView.setVisibility(View.GONE); - */ - listView.setEmptyView(emptyTextView); - //} EDIT BY MR + listView.setEmptyView(emptyTextView); return fragmentView; } @@ -175,11 +158,7 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe updateVisibleRows(mask); } } else if (id == NotificationCenter.blockedUsersDidLoaded) { - /* EDIT BY MR - if (progressView != null) { - progressView.setVisibility(View.GONE); - } - */ + blockedUserIds = MrMailbox.MrMailboxGetBlockedContacts(MrMailbox.hMailbox); if (listView != null && listView.getEmptyView() == null) { listView.setEmptyView(emptyTextView); } @@ -215,7 +194,7 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe if (user == null) { return; } - MessagesController.getInstance().blockUser(user.id); + MrMailbox.MrMailboxBlockContact(MrMailbox.hMailbox, user.id, 1); } private class ListAdapter extends BaseFragmentAdapter { @@ -232,15 +211,12 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe @Override public boolean isEnabled(int i) { - return i != MessagesController.getInstance().blockedUsers.size(); + return true; } @Override public int getCount() { - if (MessagesController.getInstance().blockedUsers.isEmpty()) { - return 0; - } - return MessagesController.getInstance().blockedUsers.size() + 1; + return blockedUserIds.length; } @Override @@ -260,48 +236,30 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe @Override public View getView(int i, View view, ViewGroup viewGroup) { - int type = getItemViewType(i); - if (type == 0) { - if (view == null) { - view = new UserCell(mContext, 1, 0); - } - TLRPC.User user = MessagesController.getInstance().getUser(MessagesController.getInstance().blockedUsers.get(i)); - if (user != null) { - /*String number; - if (user.bot) { - number = LocaleController.getString("Bot", R.string.Bot).substring(0, 1).toUpperCase() + LocaleController.getString("Bot", R.string.Bot).substring(1); - } else if (user.phone != null && user.phone.length() != 0) { - number = PhoneFormat.getInstance().format("+" + user.phone); - } else { - number = LocaleController.getString("NumberUnknown", R.string.NumberUnknown); - }*/ - ((UserCell) view).setData(123, 0, "ErrUserName", "ErrUserStatus", 0); - } - } else if (type == 1) { - if (view == null) { - view = new TextInfoCell(mContext); - ((TextInfoCell) view).setText(LocaleController.getString("UnblockText", R.string.UnblockText)); - } + if (view == null) { + view = new UserCell(mContext, 1, 0); + } + if (i>=0 && i MessagesController.getInstance().groupBigSize) { + /*if (currentChat.participants_count > MessagesController.getInstance().groupBigSize) { if (which == attach_photo || which == attach_gallery) { action = "bigchat_upload_photo"; } else { action = "bigchat_upload_document"; } - } else { + } else*/ { if (which == attach_photo || which == attach_gallery) { action = "chat_upload_photo"; } else { @@ -5304,7 +5304,11 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } else if (id == NotificationCenter.blockedUsersDidLoaded) { if (currentUser != null) { boolean oldValue = userBlocked; - userBlocked = MessagesController.getInstance().blockedUsers.contains(currentUser.id); + + long hContact = MrMailbox.MrMailboxGetContact(MrMailbox.hMailbox, currentUser.id); + userBlocked = MrMailbox.MrContactIsBlocked(hContact)!=0; + MrMailbox.MrContactUnref(hContact); + if (oldValue != userBlocked) { updateBottomOverlay(); } @@ -5575,7 +5579,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not /*if (currentUser.bot) { bottomOverlayChatText.setText(LocaleController.getString("BotUnblock", R.string.BotUnblock)); } else*/ { - bottomOverlayChatText.setText(LocaleController.getString("Unblock", R.string.Unblock)); + bottomOverlayChatText.setText(LocaleController.getString("UnblockContact", R.string.UnblockContact)); } } /*else if (botUser != null && currentUser.bot) { @@ -7129,9 +7133,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } else if (uid != UserConfig.getClientUserId()) { Bundle args = new Bundle(); args.putInt("user_id", uid); - /*if (currentEncryptedChat != null && uid == currentUser.id) { - args.putLong("dialog_id", dialog_id); - }*/ ProfileActivity fragment = new ProfileActivity(args); fragment.setPlayProfileAnimation(currentUser != null && currentUser.id == uid); presentFragment(fragment); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java index 4c3abaeb7..78e955e1c 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java @@ -860,9 +860,9 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe TLRPC.Chat currentChat; if ((int) dialog_id < 0) { currentChat = MessagesController.getInstance().getChat(-(int) dialog_id); - if (currentChat != null && currentChat.participants_count > MessagesController.getInstance().groupBigSize) { + /*if (currentChat != null && currentChat.participants_count > MessagesController.getInstance().groupBigSize) { action = "bigchat_upload_audio"; - } else { + } else*/ { action = "chat_upload_audio"; } } else { @@ -1320,9 +1320,9 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe TLRPC.Chat currentChat; if ((int) dialog_id < 0) { currentChat = MessagesController.getInstance().getChat(-(int) dialog_id); - if (currentChat != null && currentChat.participants_count > MessagesController.getInstance().groupBigSize) { + /*if (currentChat != null && currentChat.participants_count > MessagesController.getInstance().groupBigSize) { action = "bigchat_message"; - } else { + } else*/ { action = "chat_message"; } } else { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java index f88320357..ff9c9e123 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java @@ -13,8 +13,6 @@ package org.telegram.ui; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; -import android.content.Intent; -import android.net.Uri; import android.os.Bundle; import android.text.Editable; import android.text.InputType; @@ -46,7 +44,6 @@ import org.telegram.messenger.R; import org.telegram.messenger.Utilities; import org.telegram.ui.Adapters.BaseFragmentAdapter; import org.telegram.ui.Adapters.ContactsAdapter; -import org.telegram.ui.Adapters.SearchAdapter; import org.telegram.ui.Cells.UserCell; import org.telegram.ui.ActionBar.ActionBar; import org.telegram.ui.ActionBar.ActionBarMenu; @@ -60,23 +57,28 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter private BaseFragmentAdapter listViewAdapter; private TextView emptyTextView; private ListView listView; + private EditText userSelectEditText; + + private int do_what = 0; + public final static int SELECT_CONTACT_FOR_NEW_CHAT = 1; + public final static int SELECT_CONTACTS_FOR_NEW_GROUP = 2; + public final static int ADD_CONTACTS_TO_GROUP = 3; + public final static int SELECT_CONTACT_TO_BLOCK = 4; + + boolean createNewChatOnItemClick; //private SearchAdapter searchListViewAdapter; //private boolean searchWas; //private boolean searching; - private boolean returnAsResult; - private boolean needForwardCount = true; - private int chat_id; - private String selectAlertString = null; - private boolean allowUsernameSearch = true; private ContactsActivityDelegate delegate; private String title; private String subtitle; private final static int id_add_contact = 2; - private final static int id_new_group = 3; + private final static int id_done_button = 3; + private final static int id_toggle = 4; public interface ContactsActivityDelegate { void didSelectContact(TLRPC.User user, String param); @@ -84,30 +86,37 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter public ContactsActivity(Bundle args) { super(args); + if( args != null ) { + do_what = args.getInt("do_what", 0); + } } - @SuppressWarnings("unchecked") @Override public boolean onFragmentCreate() { super.onFragmentCreate(); NotificationCenter.getInstance().addObserver(this, NotificationCenter.contactsDidLoaded); NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces); NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeChats); - if (arguments != null) { - - returnAsResult = arguments.getBoolean("returnAsResult", false); - selectAlertString = arguments.getString("selectAlertString"); - allowUsernameSearch = arguments.getBoolean("allowUsernameSearch", true); - needForwardCount = arguments.getBoolean("needForwardCount", true); - chat_id = arguments.getInt("chat_id", 0); - - if( arguments.getBoolean("do_create_new_chat", false) ) { - title = LocaleController.getString("NewChat", R.string.NewChat); - subtitle = LocaleController.getString("SendMessageTo", R.string.SendMessageTo); - } - + if( do_what == SELECT_CONTACT_FOR_NEW_CHAT ) + { + title = LocaleController.getString("NewChat", R.string.NewChat); + subtitle = LocaleController.getString("SendMessageTo", R.string.SendMessageTo); + createNewChatOnItemClick = true; } + else if( do_what == SELECT_CONTACTS_FOR_NEW_GROUP ) + { + title = LocaleController.getString("NewGroup", R.string.NewGroup); + } + else if( do_what == ADD_CONTACTS_TO_GROUP ) + { + ; + } + else if( do_what == SELECT_CONTACT_TO_BLOCK ) + { + title = LocaleController.getString("BlockContact", R.string.BlockContact); + } + return true; } @@ -138,68 +147,41 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { - if (id == -1) { + if (id == -1) + { finishFragment(); } - else if( id == id_new_group ) { - presentFragment(new GroupCreateActivity(), true); + else if( id == id_toggle ) + { + Bundle args = new Bundle(); + args.putInt("do_what", do_what==SELECT_CONTACTS_FOR_NEW_GROUP? SELECT_CONTACT_FOR_NEW_CHAT : SELECT_CONTACTS_FOR_NEW_GROUP); + presentFragment(new ContactsActivity(args), true); } - else if( id == id_add_contact ) { + else if( id == id_add_contact ) + { Toast.makeText(getParentActivity(), LocaleController.getString("NotYetImplemented", R.string.NotYetImplemented), Toast.LENGTH_LONG).show(); } + else if( id == id_done_button ) + { + + } } }); ActionBarMenu menu = actionBar.createMenu(); - ActionBarMenuItem item = menu.addItem(10, R.drawable.ic_ab_other); - item.addSubItem(id_add_contact, LocaleController.getString("AddContactTitle", R.string.AddContactTitle), 0); - item.addSubItem(id_new_group, LocaleController.getString("NewGroup", R.string.NewGroup), 0); - /* - ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { - @Override - public void onSearchExpand() { - searching = true; - } - @Override - public void onSearchCollapse() { - searchListViewAdapter.searchDialogs(null); - searching = false; - searchWas = false; - listView.setAdapter(listViewAdapter); - listViewAdapter.notifyDataSetChanged(); - listView.setFastScrollAlwaysVisible(true); - listView.setFastScrollEnabled(true); - listView.setVerticalScrollBarEnabled(false); - emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts)); - } + if( do_what == SELECT_CONTACTS_FOR_NEW_GROUP || do_what == ADD_CONTACTS_TO_GROUP ) { + menu.addItem(id_done_button, R.drawable.ic_done); + } - @Override - public void onTextChanged(EditText editText) { - if (searchListViewAdapter == null) { - return; - } - String text = editText.getText().toString(); - if (text.length() != 0) { - searchWas = true; - if (listView != null) { - listView.setAdapter(searchListViewAdapter); - searchListViewAdapter.notifyDataSetChanged(); - listView.setFastScrollAlwaysVisible(false); - listView.setFastScrollEnabled(false); - listView.setVerticalScrollBarEnabled(true); - } - if (emptyTextView != null) { - emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult)); - } - } - searchListViewAdapter.searchDialogs(text); + if( do_what != SELECT_CONTACT_TO_BLOCK ) { + ActionBarMenuItem item = menu.addItem(10, R.drawable.ic_ab_other); + if (do_what == SELECT_CONTACT_FOR_NEW_CHAT || do_what == SELECT_CONTACTS_FOR_NEW_GROUP) { + item.addSubItem(id_toggle, do_what == SELECT_CONTACT_FOR_NEW_CHAT ? LocaleController.getString("NewGroup", R.string.NewGroup) : LocaleController.getString("NewChat", R.string.NewChat), 0); } - }); - item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search)); + item.addSubItem(id_add_contact, LocaleController.getString("AddContactTitle", R.string.AddContactTitle), 0); + } - searchListViewAdapter = new SearchAdapter(context, null, allowUsernameSearch, false, false, true); - */ listViewAdapter = new ContactsAdapter(context); fragmentView = new FrameLayout(context); @@ -259,61 +241,44 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView adapterView, View view, int i, long l) { - /* - if (searching && searchWas) { - TLRPC.User user = (TLRPC.User) searchListViewAdapter.getItem(i); - if (user == null) { - return; - } - if (searchListViewAdapter.isGlobalSearch(i)) { - ArrayList users = new ArrayList<>(); - users.add(user); - //MessagesController.getInstance().putUsers(users, false); - //MessagesStorage.getInstance().putUsersAndChats(users, null, false, true); - } - if (returnAsResult) { - didSelectResult(user, true, null); - } else { - Bundle args = new Bundle(); - args.putInt("user_id", user.id); - presentFragment(new ChatActivity(args), true); - } - } else*/ { - Object item = listViewAdapter.getItem(i); - if (item instanceof TLRPC.User) { - final TLRPC.User user = (TLRPC.User) item; - if (returnAsResult) { - didSelectResult(user, true, null); - } else { - int belonging_chat_id = MrMailbox.MrMailboxGetChatIdByContactId(MrMailbox.hMailbox, user.id); - if( belonging_chat_id!=0 ) { - Bundle args = new Bundle(); - args.putInt("chat_id", belonging_chat_id); - presentFragment(new ChatActivity(args), true); - return; - } - - long hContact = MrMailbox.MrMailboxGetContact(MrMailbox.hMailbox, user.id); - String name = MrMailbox.MrContactGetNameNAddr(hContact); - MrMailbox.MrContactUnref(hContact); - - AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); - builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - int belonging_chat_id = MrMailbox.MrMailboxCreateChatByContactId(MrMailbox.hMailbox, user.id); - if( belonging_chat_id != 0 ) { - Bundle args = new Bundle(); - args.putInt("chat_id", belonging_chat_id); - presentFragment(new ChatActivity(args), true); - return; - } - } - }); - builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); - builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("AskStartChatWith", R.string.AskStartChatWith, name))); - showDialog(builder.create()); + // a single click on an contact item + Object item = listViewAdapter.getItem(i); + if (item instanceof TLRPC.User) { + final TLRPC.User user = (TLRPC.User) item; + if( do_what == SELECT_CONTACT_FOR_NEW_CHAT ) { + int belonging_chat_id = MrMailbox.MrMailboxGetChatIdByContactId(MrMailbox.hMailbox, user.id); + if( belonging_chat_id!=0 ) { + Bundle args = new Bundle(); + args.putInt("chat_id", belonging_chat_id); + presentFragment(new ChatActivity(args), true); + return; } + + long hContact = MrMailbox.MrMailboxGetContact(MrMailbox.hMailbox, user.id); + String name = MrMailbox.MrContactGetNameNAddr(hContact); + MrMailbox.MrContactUnref(hContact); + + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); + builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + int belonging_chat_id = MrMailbox.MrMailboxCreateChatByContactId(MrMailbox.hMailbox, user.id); + if( belonging_chat_id != 0 ) { + Bundle args = new Bundle(); + args.putInt("chat_id", belonging_chat_id); + presentFragment(new ChatActivity(args), true); + return; + } + } + }); + builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); + builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("AskStartChatWith", R.string.AskStartChatWith, name))); + showDialog(builder.create()); + } + else if (delegate != null) { + delegate.didSelectContact(user, null); + delegate = null; + finishFragment(); } } } @@ -338,90 +303,6 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter return fragmentView; } - private void didSelectResult(final TLRPC.User user, boolean useAlert, String param) { - if (useAlert && selectAlertString != null) { - if (getParentActivity() == null) { - return; - } - - AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); - String message = LocaleController.formatStringSimple(selectAlertString, UserObject.getUserName(user)); - EditText editText = null; - if ( needForwardCount ) { - message = String.format("%s\n\n%s", message, LocaleController.getString("AddToTheGroupForwardCount", R.string.AddToTheGroupForwardCount)); - editText = new EditText(getParentActivity()); - editText.setTextSize(18); - editText.setText("50"); - editText.setGravity(Gravity.CENTER); - editText.setInputType(InputType.TYPE_CLASS_NUMBER); - editText.setImeOptions(EditorInfo.IME_ACTION_DONE); - final EditText editTextFinal = editText; - editText.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - - } - - @Override - public void afterTextChanged(Editable s) { - try { - String str = s.toString(); - if (str.length() != 0) { - int value = Utilities.parseInt(str); - if (value < 0) { - editTextFinal.setText("0"); - editTextFinal.setSelection(editTextFinal.length()); - } else if (value > 300) { - editTextFinal.setText("300"); - editTextFinal.setSelection(editTextFinal.length()); - } else if (!str.equals("" + value)) { - editTextFinal.setText("" + value); - editTextFinal.setSelection(editTextFinal.length()); - } - } - } catch (Exception e) { - FileLog.e("tmessages", e); - } - } - - }); - builder.setView(editText); - } - builder.setMessage(message); - final EditText finalEditText = editText; - builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - didSelectResult(user, false, finalEditText != null ? finalEditText.getText().toString() : "0"); - } - }); - builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); - showDialog(builder.create()); - if (editText != null) { - ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) editText.getLayoutParams(); - if (layoutParams != null) { - if (layoutParams instanceof FrameLayout.LayoutParams) { - ((FrameLayout.LayoutParams) layoutParams).gravity = Gravity.CENTER_HORIZONTAL; - } - layoutParams.rightMargin = layoutParams.leftMargin = AndroidUtilities.dp(10); - editText.setLayoutParams(layoutParams); - } - editText.setSelection(editText.getText().length()); - } - } else { - if (delegate != null) { - delegate.didSelectContact(user, param); - delegate = null; - } - finishFragment(); - } - } - @Override public void onResume() { super.onResume(); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java index d0778e2f8..83d835439 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java @@ -525,7 +525,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. @Override public void onClick(View v) { Bundle args = new Bundle(); - args.putBoolean("do_create_new_chat", true); + args.putInt("do_what", ContactsActivity.SELECT_CONTACT_FOR_NEW_CHAT); presentFragment(new ContactsActivity(args)); } }); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java index 2a2850d6b..5bc29b7a5 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java @@ -173,12 +173,14 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen listViewAdapter.setCheckedMap(selectedContacts); fragmentView = new LinearLayout(context); + LinearLayout linearLayout = (LinearLayout) fragmentView; linearLayout.setOrientation(LinearLayout.VERTICAL); FrameLayout frameLayout = new FrameLayout(context); linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); + // START SEARCH FIELD userSelectEditText = new EditText(context); userSelectEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); userSelectEditText.setHintTextColor(0xff979797); @@ -291,6 +293,9 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen } } }); + // END SEARCH FIELD + + LinearLayout emptyTextLayout = new LinearLayout(context); emptyTextLayout.setVisibility(View.INVISIBLE); @@ -354,13 +359,6 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen FileLog.e("tmessages", e); } } else { - if (chatType == ChatObject.CHAT_TYPE_CHAT && selectedContacts.size() == MessagesController.getInstance().maxGroupCount - 1) { - AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); - builder.setMessage(LocaleController.getString("SoftUserLimitAlert", R.string.SoftUserLimitAlert)); - builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); - showDialog(builder.create()); - return; - } ignoreChange = true; ChipSpan span = createAndPutChipForUser(user); span.uid = user.id; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/GroupInviteActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/GroupInviteActivity.java deleted file mode 100644 index 62622f43f..000000000 --- a/TMessagesProj/src/main/java/org/telegram/ui/GroupInviteActivity.java +++ /dev/null @@ -1,340 +0,0 @@ -/* - * This is the source code of Telegram for Android v. 3.x.x - * It is licensed under GNU GPL v. 2 or later. - * You should have received a copy of the license in this archive (see LICENSE). - * - * Copyright Nikolai Kudashov, 2013-2016. - */ - -package org.telegram.ui; - -import android.app.AlertDialog; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.view.Gravity; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.FrameLayout; -import android.widget.ListView; -import android.widget.ProgressBar; -import android.widget.Toast; - -import org.telegram.messenger.LocaleController; -import org.telegram.messenger.NotificationCenter; -import org.telegram.messenger.ApplicationLoader; -import org.telegram.messenger.FileLog; -import org.telegram.messenger.R; -import org.telegram.tgnet.TLRPC; -import org.telegram.ui.ActionBar.ActionBar; -import org.telegram.ui.ActionBar.BaseFragment; -import org.telegram.ui.Adapters.BaseFragmentAdapter; -import org.telegram.ui.Cells.TextBlockCell; -import org.telegram.ui.Cells.TextInfoPrivacyCell; -import org.telegram.ui.Cells.TextSettingsCell; -import org.telegram.ui.Components.LayoutHelper; - -public class GroupInviteActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate { - - private ListAdapter listAdapter; - - private int chat_id; - private boolean loading; - private TLRPC.ExportedChatInvite invite; - - private int linkRow; - private int linkInfoRow; - private int copyLinkRow; - private int revokeLinkRow; - private int shareLinkRow; - private int shadowRow; - private int rowCount; - - public GroupInviteActivity(int cid) { - super(); - chat_id = cid; - } - - @Override - public boolean onFragmentCreate() { - super.onFragmentCreate(); - - //NotificationCenter.getInstance().addObserver(this, NotificationCenter.chatInfoDidLoaded); - //MessagesController.getInstance().loadFullChat(chat_id, classGuid, true); - loading = true; - - rowCount = 0; - linkRow = rowCount++; - linkInfoRow = rowCount++; - copyLinkRow = rowCount++; - revokeLinkRow = rowCount++; - shareLinkRow = rowCount++; - shadowRow = rowCount++; - - return true; - } - - @Override - public void onFragmentDestroy() { - //NotificationCenter.getInstance().removeObserver(this, NotificationCenter.chatInfoDidLoaded); - } - - @Override - public View createView(Context context) { - actionBar.setBackButtonImage(R.drawable.ic_ab_back); - actionBar.setAllowOverlayTitle(true); - actionBar.setTitle(LocaleController.getString("InviteLink", R.string.InviteLink)); - actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { - @Override - public void onItemClick(int id) { - if (id == -1) { - finishFragment(); - } - } - }); - - listAdapter = new ListAdapter(context); - - fragmentView = new FrameLayout(context); - FrameLayout frameLayout = (FrameLayout) fragmentView; - frameLayout.setBackgroundColor(0xfff0f0f0); - - FrameLayout progressView = new FrameLayout(context); - frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); - - ProgressBar progressBar = new ProgressBar(context); - progressView.addView(progressBar, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); - - ListView listView = new ListView(context); - listView.setDivider(null); - listView.setDividerHeight(0); - listView.setEmptyView(progressView); - listView.setVerticalScrollBarEnabled(false); - listView.setDrawSelectorOnTop(true); - frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); - listView.setAdapter(listAdapter); - listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView adapterView, View view, final int i, long l) { - if (getParentActivity() == null) { - return; - } - if (i == copyLinkRow || i == linkRow) { - if (invite == null) { - return; - } - try { - android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE); - android.content.ClipData clip = android.content.ClipData.newPlainText("label", invite.link); - clipboard.setPrimaryClip(clip); - Toast.makeText(getParentActivity(), LocaleController.getString("LinkCopied", R.string.LinkCopied), Toast.LENGTH_SHORT).show(); - } catch (Exception e) { - FileLog.e("tmessages", e); - } - } else if (i == shareLinkRow) { - if (invite == null) { - return; - } - try { - Intent intent = new Intent(Intent.ACTION_SEND); - intent.setType("text/plain"); - intent.putExtra(Intent.EXTRA_TEXT, invite.link); - getParentActivity().startActivityForResult(Intent.createChooser(intent, LocaleController.getString("InviteToGroupByLink", R.string.InviteToGroupByLink)), 500); - } catch (Exception e) { - FileLog.e("tmessages", e); - } - } else if (i == revokeLinkRow) { - AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); - builder.setMessage(LocaleController.getString("RevokeAlert", R.string.RevokeAlert)); - builder.setTitle(LocaleController.getString("RevokeLink", R.string.RevokeLink)); - builder.setPositiveButton(LocaleController.getString("RevokeButton", R.string.RevokeButton), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - generateLink(true); - } - }); - builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); - showDialog(builder.create()); - } - } - }); - - return fragmentView; - } - - @Override - public void didReceivedNotification(int id, Object... args) { - /*if (id == NotificationCenter.chatInfoDidLoaded) { - TLRPC.ChatFull info = (TLRPC.ChatFull) args[0]; - int guid = (int) args[1]; - if (info.id == chat_id && guid == classGuid) { - invite = MessagesController.getInstance().getExportedInvite(chat_id); - if (!(invite instanceof TLRPC.TL_chatInviteExported)) { - generateLink(false); - } else { - loading = false; - if (listAdapter != null) { - listAdapter.notifyDataSetChanged(); - } - } - } - }*/ - } - - @Override - public void onResume() { - super.onResume(); - if (listAdapter != null) { - listAdapter.notifyDataSetChanged(); - } - } - - private void generateLink(final boolean newRequest) { - /* - loading = true; - TLObject request; - if (ChatObject.isChannel(chat_id)) { - TLRPC.TL_channels_exportInvite req = new TLRPC.TL_channels_exportInvite(); - req.channel = MessagesController.getInputChannel(chat_id); - request = req; - } else { - TLRPC.TL_messages_exportChatInvite req = new TLRPC.TL_messages_exportChatInvite(); - req.chat_id = chat_id; - request = req; - } - final int reqId = ConnectionsManager.getInstance().sendRequest(request, new RequestDelegate() { - @Override - public void run(final TLObject response, final TLRPC.TL_error error) { - AndroidUtilities.runOnUIThread(new Runnable() { - @Override - public void run() { - if (error == null) { - invite = (TLRPC.ExportedChatInvite) response; - if (newRequest) { - if (getParentActivity() == null) { - return; - } - AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); - builder.setMessage(LocaleController.getString("RevokeAlertNewLink", R.string.RevokeAlertNewLink)); - builder.setTitle(LocaleController.getString("RevokeLink", R.string.RevokeLink)); - builder.setNegativeButton(LocaleController.getString("OK", R.string.OK), null); - showDialog(builder.create()); - } - } - loading = false; - listAdapter.notifyDataSetChanged(); - } - }); - } - }); - ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid); - if (listAdapter != null) { - listAdapter.notifyDataSetChanged(); - } - */ - } - - private class ListAdapter extends BaseFragmentAdapter { - private Context mContext; - - public ListAdapter(Context context) { - mContext = context; - } - - @Override - public boolean areAllItemsEnabled() { - return false; - } - - @Override - public boolean isEnabled(int i) { - return i == revokeLinkRow || i == copyLinkRow || i == shareLinkRow || i == linkRow; - } - - @Override - public int getCount() { - return loading ? 0 : rowCount; - } - - @Override - public Object getItem(int i) { - return null; - } - - @Override - public long getItemId(int i) { - return i; - } - - @Override - public boolean hasStableIds() { - return false; - } - - @Override - public View getView(int i, View view, ViewGroup viewGroup) { - int type = getItemViewType(i); - if (type == 0) { - if (view == null) { - view = new TextSettingsCell(mContext); - view.setBackgroundColor(0xffffffff); - } - TextSettingsCell textCell = (TextSettingsCell) view; - if (i == copyLinkRow) { - textCell.setText(LocaleController.getString("CopyLink", R.string.CopyLink), true); - } else if (i == shareLinkRow) { - textCell.setText(LocaleController.getString("ShareLink", R.string.ShareLink), false); - } else if (i == revokeLinkRow) { - textCell.setText(LocaleController.getString("RevokeLink", R.string.RevokeLink), true); - } - } else if (type == 1) { - if (view == null) { - view = new TextInfoPrivacyCell(mContext); - } - if (i == shadowRow) { - ((TextInfoPrivacyCell) view).setText(""); - view.setBackgroundResource(R.drawable.greydivider_bottom); - } else if (i == linkInfoRow) { - /*TLRPC.Chat chat = MessagesController.getInstance().getChat(chat_id); - if (ChatObject.isChannel(chat) && !chat.megagroup) { - ((TextInfoPrivacyCell) view).setText(LocaleController.getString("ChannelLinkInfo", R.string.ChannelLinkInfo)); - } else { - ((TextInfoPrivacyCell) view).setText(LocaleController.getString("LinkInfo", R.string.LinkInfo)); - }*/ - ((TextInfoPrivacyCell) view).setText(LocaleController.getString("NotYetImplemented", R.string.NotYetImplemented)); - view.setBackgroundResource(R.drawable.greydivider); - } - } else if (type == 2) { - if (view == null) { - view = new TextBlockCell(mContext); - view.setBackgroundColor(0xffffffff); - } - ((TextBlockCell) view).setText(invite != null ? invite.link : "error", false); - } - return view; - } - - @Override - public int getItemViewType(int i) { - if (i == copyLinkRow || i == shareLinkRow || i == revokeLinkRow) { - return 0; - } else if (i == shadowRow || i == linkInfoRow) { - return 1; - } else if (i == linkRow) { - return 2; - } - return 0; - } - - @Override - public int getViewTypeCount() { - return 3; - } - - @Override - public boolean isEmpty() { - return loading; - } - } -} diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java index 097be0d97..08d576700 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java @@ -292,26 +292,29 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - if (position == DrawerLayoutAdapter.iNewGroup) { - /*if (!MessagesController.isFeatureEnabled("chat_create", actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1))) { - return; - }*/ - presentFragment(new GroupCreateActivity()); - drawerLayoutContainer.closeDrawer(false); - } else if (position == DrawerLayoutAdapter.iNewChat) { + if (position == DrawerLayoutAdapter.iNewChat) { Bundle args = new Bundle(); - args.putBoolean("do_create_new_chat", true); + args.putInt("do_what", ContactsActivity.SELECT_CONTACT_FOR_NEW_CHAT); presentFragment(new ContactsActivity(args)); drawerLayoutContainer.closeDrawer(false); - } else if (position == DrawerLayoutAdapter.iStrangers) { + } + else if (position == DrawerLayoutAdapter.iNewGroup) { + Bundle args = new Bundle(); + args.putInt("do_what", ContactsActivity.SELECT_CONTACTS_FOR_NEW_GROUP); + presentFragment(new ContactsActivity(args)); + drawerLayoutContainer.closeDrawer(false); + } + else if (position == DrawerLayoutAdapter.iStrangers) { Bundle args = new Bundle(); args.putInt("chat_id", (int) MrMailbox.MR_CHAT_ID_STRANGERS); presentFragment(new ChatActivity(args)); drawerLayoutContainer.closeDrawer(false); - } else if (position == DrawerLayoutAdapter.iSettings) { + } + else if (position == DrawerLayoutAdapter.iSettings) { presentFragment(new SettingsActivity()); drawerLayoutContainer.closeDrawer(false); - } else if (position == DrawerLayoutAdapter.iFaq) { + } + else if (position == DrawerLayoutAdapter.iFaq) { Browser.openUrl(LaunchActivity.this, "https://messenger.b44t.com/help"); drawerLayoutContainer.closeDrawer(false); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java index d9ed57ca3..9e733eb5b 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java @@ -40,6 +40,7 @@ import android.view.animation.AccelerateInterpolator; import android.view.animation.DecelerateInterpolator; import android.widget.FrameLayout; import android.widget.ImageView; +import android.widget.TextView; import android.widget.Toast; import org.telegram.messenger.AndroidUtilities; @@ -104,6 +105,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. private AvatarDrawable avatarDrawable; private ActionBarMenuItem animatingItem; private TopView topView; + private TextView blockTextView; private long dialog_id; private boolean userBlocked; @@ -190,7 +192,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces); NotificationCenter.getInstance().addObserver(this, NotificationCenter.contactsDidLoaded); NotificationCenter.getInstance().addObserver(this, NotificationCenter.userInfoDidLoaded); - userBlocked = false; //MessagesController.getInstance().blockedUsers.contains(user_id); + } else if (chat_id != 0) { currentChat = MrMailbox.chatId2chat(chat_id); @@ -270,17 +272,23 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. if (id == -1) { finishFragment(); } else if (id == block_contact) { - - AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); - builder.setMessage(userBlocked? LocaleController.getString("AreYouSureUnblockContact", R.string.AreYouSureUnblockContact) : LocaleController.getString("AreYouSureBlockContact", R.string.AreYouSureBlockContact)); - builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - Toast.makeText(getParentActivity(), LocaleController.getString("NotYetImplemented", R.string.NotYetImplemented), Toast.LENGTH_LONG).show(); - } - }); - builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); - showDialog(builder.create()); + if( userBlocked ) { + MrMailbox.MrMailboxBlockContact(MrMailbox.hMailbox, user_id, 0); + finishFragment(); /* got to the parent, this is important eg. when editing blocking in the BlockedUserActivitiy. Moreover, this saves us updating all the states in the profile */ + } + else { + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); + builder.setMessage(LocaleController.getString("AreYouSureBlockContact", R.string.AreYouSureBlockContact)); + builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + MrMailbox.MrMailboxBlockContact(MrMailbox.hMailbox, user_id, 1); + finishFragment(); /* got to the parent, this is important eg. when editing blocking in the BlockedUserActivitiy. Moreover, this saves us updating all the states in the profile */ + } + }); + builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); + showDialog(builder.create()); + } } else if (id == add_contact) { TLRPC.User user = MessagesController.getInstance().getUser(user_id); @@ -1222,6 +1230,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. long hContact = MrMailbox.MrMailboxGetContact(MrMailbox.hMailbox, user_id); newString = MrMailbox.MrContactGetDisplayName(hContact); newString2 = MrMailbox.MrContactGetAddr(hContact); + userBlocked = MrMailbox.MrContactIsBlocked(hContact)!=0; MrMailbox.MrContactUnref(hContact); } else { @@ -1231,6 +1240,10 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. MrMailbox.MrChatUnref(hChat); } + if( blockTextView != null ) { + blockTextView.setText(!userBlocked ? LocaleController.getString("BlockContact", R.string.BlockContact) : LocaleController.getString("UnblockContact", R.string.UnblockContact)); + } + for (int a = 0; a < 2; a++) { if (nameTextView[a] == null) { continue; @@ -1272,7 +1285,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. ActionBarMenuItem item = menu.addItem(10, R.drawable.ic_ab_other); if (user_id != 0) { - item.addSubItem(block_contact, !userBlocked ? LocaleController.getString("BlockContact", R.string.BlockContact) : LocaleController.getString("Unblock", R.string.Unblock), 0); + blockTextView = item.addSubItem(block_contact, "X", 0); } if( chat_id!=0 || MrMailbox.MrMailboxGetChatIdByContactId(MrMailbox.hMailbox, user_id)!=0 ) { diff --git a/TMessagesProj/src/main/res/values-de/strings.xml b/TMessagesProj/src/main/res/values-de/strings.xml index 3d8126657..c3b6abdd3 100644 --- a/TMessagesProj/src/main/res/values-de/strings.xml +++ b/TMessagesProj/src/main/res/values-de/strings.xml @@ -214,7 +214,7 @@ Teilen Hinzufügen Kontakt hinzufügen - Blockieren + Benutzer blockieren Bearbeiten Löschen Festnetz @@ -246,8 +246,7 @@ Textgröße für Nachrichten Übergänge animieren - Freigeben - Gedrückt halten um freizugeben. + Benutzer nicht mehr blockieren Keine blockierten Benutzer Nachrichten Benachrichtigung diff --git a/TMessagesProj/src/main/res/values-es/strings.xml b/TMessagesProj/src/main/res/values-es/strings.xml index f069bd427..e9016906c 100644 --- a/TMessagesProj/src/main/res/values-es/strings.xml +++ b/TMessagesProj/src/main/res/values-es/strings.xml @@ -247,8 +247,7 @@ Tamaño del texto Activar animaciones - Desbloquear - Mantén pulsado sobre un usuario para desbloquearlo. + Desbloquear Sin usuarios bloqueados Notificación de mensajes Alerta diff --git a/TMessagesProj/src/main/res/values-it/strings.xml b/TMessagesProj/src/main/res/values-it/strings.xml index 30a033576..927683ac4 100644 --- a/TMessagesProj/src/main/res/values-it/strings.xml +++ b/TMessagesProj/src/main/res/values-it/strings.xml @@ -247,8 +247,7 @@ Dimensione testo messaggi Abilita animazioni - Sblocca - Tieni premuto sull’utente per sbloccarlo. + Sblocca Ancora nessun utente bloccato Notifiche messaggio Avviso diff --git a/TMessagesProj/src/main/res/values-nl/strings.xml b/TMessagesProj/src/main/res/values-nl/strings.xml index 882125574..0f384a0c1 100644 --- a/TMessagesProj/src/main/res/values-nl/strings.xml +++ b/TMessagesProj/src/main/res/values-nl/strings.xml @@ -247,8 +247,7 @@ Tekstgrootte berichten Animaties - Deblokkeer - Gebruiker vasthouden om te deblokkeren. + Deblokkeer Geen geblokkeerde gebruikers Berichtmeldingen Waarschuwing diff --git a/TMessagesProj/src/main/res/values-pt/strings.xml b/TMessagesProj/src/main/res/values-pt/strings.xml index 01bae48aa..311b0b57b 100644 --- a/TMessagesProj/src/main/res/values-pt/strings.xml +++ b/TMessagesProj/src/main/res/values-pt/strings.xml @@ -247,8 +247,7 @@ Tamanho do texto nas mensagens Permitir Animações - Desbloquear - Toque e segure no usuário para desbloquear + Desbloquear Nenhum usuário bloqueado Notificações de mensagens Alerta diff --git a/TMessagesProj/src/main/res/values/strings.xml b/TMessagesProj/src/main/res/values/strings.xml index 921406820..a4c34a554 100644 --- a/TMessagesProj/src/main/res/values/strings.xml +++ b/TMessagesProj/src/main/res/values/strings.xml @@ -215,7 +215,7 @@ Share Add Add contact - Block + Block contact Edit Delete Home @@ -247,8 +247,7 @@ Messages Text Size Transition animation - Unblock - Tap and hold on user to unblock. + Unblock contact No blocked users yet Message notifications Alert @@ -264,7 +263,7 @@ Reset All Notifications Undo all custom notification settings for all your contacts and groups Notifications and Sounds - Blocked Users + Blocked contacts Log out No sound Default