Commit abf8f6f6 authored by DrKLO's avatar DrKLO

Bug fixes

parent d03fa955
## Telegram messenger for Android
[Telegram](http://telegram.org) is a messaging app with a focus on speed and security. It’s superfast, simple and free.
This repo contains the official source code for [Telegram App for Android](https://play.google.com/store/apps/details?id=org.telegram.messenger).
This repo contains official [Telegram App for Android](https://play.google.com/store/apps/details?id=org.telegram.messenger) source code.
##Creating your Telegram Application
We welcome all developers to use our API and source code to create applications on our platform.
There are several things we require from **all developers** for the moment.
1. [**Obtain your own api_id**](https://core.telegram.org/api/obtaining_api_id) for your application.
2. Please **do not** use the name Telegram for your app — or make sure your users understand that it is unofficial.
3. Kindly **do not** use our standard logo (white paper plane in a blue circle) as your app's logo.
3. Please study our [**security guidelines**](https://core.telegram.org/mtproto/security_guidelines) and take good care of your users' data and privacy.
4. Please remember to publish **your** code too in order to comply with the licences.
### API, Protocol documentation
Documentation for Telegram API is available here: http://core.telegram.org/api
Telegram API manuals: http://core.telegram.org/api
Documentation for MTproto protocol is available here: http://core.telegram.org/mtproto
MTproto protocol manuals: http://core.telegram.org/mtproto
### Usage
**Beware of using dev branch and uploading it to any markets, in most cases it will work as you expecting**
First of all your should take a look to **src/main/java/org/telegram/messenger/BuildVars.java** and fill it with correct values.
**Beware of using the dev branch and uploading it to any markets, in many cases it not will work as expected**.
First of all, take a look at **src/main/java/org/telegram/messenger/BuildVars.java** and fill it with correct values.
Import the root folder into your IDE (tested on Android Studio), then run project.
### Localization
......
......@@ -25,7 +25,7 @@ dependencies {
android {
compileSdkVersion 21
buildToolsVersion '21.0.1'
buildToolsVersion '21.0.2'
signingConfigs {
debug {
......@@ -80,7 +80,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 372
versionCode 374
versionName "1.9.6"
}
}
......@@ -218,7 +218,7 @@ public class AndroidUtilities {
}
public static File getCacheDir() {
if (Environment.getExternalStorageState().startsWith(Environment.MEDIA_MOUNTED)) {
if (Environment.getExternalStorageState() == null || Environment.getExternalStorageState().startsWith(Environment.MEDIA_MOUNTED)) {
try {
File file = ApplicationLoader.applicationContext.getExternalCacheDir();
if (file != null) {
......
......@@ -1711,7 +1711,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
public void markMessageAsRead(final long dialog_id, final long random_id, int ttl) {
if (random_id == 0 || dialog_id == 0) {
if (random_id == 0 || dialog_id == 0 || ttl <= 0) {
return;
}
int lower_part = (int)dialog_id;
......@@ -1726,10 +1726,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
ArrayList<Long> random_ids = new ArrayList<Long>();
random_ids.add(random_id);
SendMessagesHelper.getInstance().sendMessagesReadMessage(chat, random_ids, null);
if (ttl > 0) {
int time = ConnectionsManager.getInstance().getCurrentTime();
MessagesStorage.getInstance().createTaskForSecretChat(chat.id, time, time, 0, random_ids);
}
int time = ConnectionsManager.getInstance().getCurrentTime();
MessagesStorage.getInstance().createTaskForSecretChat(chat.id, time, time, 0, random_ids);
}
public void markDialogAsRead(final long dialog_id, final int max_id, final int max_positive_id, final int offset, final int max_date, final boolean was, final boolean popup) {
......
......@@ -626,10 +626,12 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
newMsg.to_id.user_id = encryptedChat.participant_id;
}
newMsg.ttl = encryptedChat.ttl;
if (newMsg.media instanceof TLRPC.TL_messageMediaAudio) {
newMsg.ttl = Math.max(encryptedChat.ttl, newMsg.media.audio.duration + 1);
} else if (newMsg.media instanceof TLRPC.TL_messageMediaVideo) {
newMsg.ttl = Math.max(encryptedChat.ttl, newMsg.media.video.duration + 1);
if (newMsg.ttl != 0) {
if (newMsg.media instanceof TLRPC.TL_messageMediaAudio) {
newMsg.ttl = Math.max(encryptedChat.ttl, newMsg.media.audio.duration + 1);
} else if (newMsg.media instanceof TLRPC.TL_messageMediaVideo) {
newMsg.ttl = Math.max(encryptedChat.ttl, newMsg.media.video.duration + 1);
}
}
}
......
......@@ -99,12 +99,25 @@ public class ContactsActivitySearchAdapter extends BaseContactsSearchAdapter {
for (TLRPC.TL_contact contact : contactsCopy) {
TLRPC.User user = MessagesController.getInstance().getUser(contact.user_id);
if (user.id == UserConfig.getClientUserId()) {
continue;
}
String name = ContactsController.formatName(user.first_name, user.last_name).toLowerCase();
int found = 0;
if (name.startsWith(q) || name.contains(" " + q)) {
if (user.id == UserConfig.getClientUserId()) {
continue;
found = 1;
} else if (user.username != null && user.username.startsWith(q)) {
found = 2;
}
if (found != 0) {
if (found == 1) {
resultArrayNames.add(Utilities.generateSearchName(user.first_name, user.last_name, q));
} else {
resultArrayNames.add(Utilities.generateSearchName("@" + user.username, null, "@" + q));
}
resultArrayNames.add(Utilities.generateSearchName(user.first_name, user.last_name, q));
resultArray.add(user);
}
}
......@@ -197,7 +210,16 @@ public class ContactsActivitySearchAdapter extends BaseContactsSearchAdapter {
TLRPC.User user = getItem(i);
if (user != null) {
CharSequence username = null;
if (i > searchResult.size() && user.username != null) {
CharSequence name = null;
if (i < searchResult.size()) {
name = searchResultNames.get(i);
if (name != null && user != null && user.username != null && user.username.length() > 0) {
if (name.toString().startsWith("@" + user.username)) {
username = name;
name = null;
}
}
} else if (i > searchResult.size() && user.username != null) {
try {
username = Html.fromHtml(String.format("<font color=\"#357aa8\">@%s</font>%s", user.username.substring(0, lastFoundUsername.length()), user.username.substring(lastFoundUsername.length())));
} catch (Exception e) {
......@@ -206,7 +228,7 @@ public class ContactsActivitySearchAdapter extends BaseContactsSearchAdapter {
}
}
((ChatOrUserCell) view).setData(user, null, null, i < searchResult.size() ? searchResultNames.get(i) : null, username);
((ChatOrUserCell) view).setData(user, null, null, name, username);
if (ignoreUsers != null) {
if (ignoreUsers.containsKey(user.id)) {
......
......@@ -1040,7 +1040,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
private boolean sendSecretMessageRead(MessageObject messageObject) {
if (messageObject == null || messageObject.isOut() || !messageObject.isSecretMedia() || messageObject.messageOwner.destroyTime != 0) {
if (messageObject == null || messageObject.isOut() || !messageObject.isSecretMedia() || messageObject.messageOwner.destroyTime != 0 || messageObject.messageOwner.ttl <= 0) {
return false;
}
MessagesController.getInstance().markMessageAsRead(dialog_id, messageObject.messageOwner.random_id, messageObject.messageOwner.ttl);
......
......@@ -477,7 +477,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
args.putBoolean("destroyAfterSelect", true);
args.putBoolean("usersAsSections", true);
args.putBoolean("returnAsResult", true);
args.putBoolean("allowUsernameSearch", false);
//args.putBoolean("allowUsernameSearch", false);
if (chat_id > 0) {
args.putString("selectAlertString", LocaleController.getString("AddToTheGroup", R.string.AddToTheGroup));
}
......
......@@ -82,11 +82,10 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
if (!usersToLoad.isEmpty()) {
final Semaphore semaphore = new Semaphore(0);
final ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
final boolean[] error = new boolean[1];
MessagesStorage.getInstance().storageQueue.postRunnable(new Runnable() {
@Override
public void run() {
users.addAll(MessagesStorage.getInstance().getUsers(usersToLoad, error));
users.addAll(MessagesStorage.getInstance().getUsers(usersToLoad));
semaphore.release();
}
});
......@@ -95,7 +94,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (error[0]) {
if (usersToLoad.size() != users.size()) {
return false;
}
if (!users.isEmpty()) {
......
......@@ -775,17 +775,19 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
if (searching && searchWas) {
if (i == searchResult.size()) {
if (view == null) {
view = new SettingsSectionLayout(mContext);
((SettingsSectionLayout) view).setText(LocaleController.getString("GlobalSearch", R.string.GlobalSearch));
view.setPadding(AndroidUtilities.dp(11), 0, AndroidUtilities.dp(11), 0);
}
} else {
if (view == null) {
view = new ChatOrUserCell(mContext);
}
int type = getItemViewType(i);
if (type == 3) {
if (view == null) {
view = new SettingsSectionLayout(mContext);
((SettingsSectionLayout) view).setText(LocaleController.getString("GlobalSearch", R.string.GlobalSearch));
view.setPadding(AndroidUtilities.dp(11), 0, AndroidUtilities.dp(11), 0);
}
} else if (type == 2) {
if (view == null) {
view = new ChatOrUserCell(mContext);
}
if (searching && searchWas) {
TLRPC.User user = null;
TLRPC.Chat chat = null;
TLRPC.EncryptedChat encryptedChat = null;
......@@ -795,7 +797,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
if (obj instanceof TLRPC.User) {
user = MessagesController.getInstance().getUser(((TLRPC.User) obj).id);
if (user == null) {
user = (TLRPC.User)obj;
user = (TLRPC.User) obj;
}
} else if (obj instanceof TLRPC.Chat) {
chat = MessagesController.getInstance().getChat(((TLRPC.Chat) obj).id);
......@@ -805,7 +807,16 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
}
CharSequence username = null;
if (i > searchResult.size() && user != null && user.username != null) {
CharSequence name = null;
if (i < searchResult.size()) {
name = searchResultNames.get(i);
if (name != null && user != null && user.username != null && user.username.length() > 0) {
if (name.toString().startsWith("@" + user.username)) {
username = name;
name = null;
}
}
} else if (i > searchResult.size() && user != null && user.username != null) {
try {
username = Html.fromHtml(String.format("<font color=\"#357aa8\">@%s</font>%s", user.username.substring(0, lastFoundUsername.length()), user.username.substring(lastFoundUsername.length())));
} catch (Exception e) {
......@@ -814,36 +825,31 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
}
}
((ChatOrUserCell) view).setData(user, chat, encryptedChat, i < searchResult.size() ? searchResultNames.get(i) : null, username);
((ChatOrUserCell) view).setData(user, chat, encryptedChat, name, username);
}
return view;
}
int type = getItemViewType(i);
if (type == 1) {
} else if (type == 1) {
if (view == null) {
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.loading_more_layout, viewGroup, false);
}
return view;
}
if (view == null) {
view = new DialogCell(mContext);
}
((DialogCell) view).useSeparator = (i != getCount() - 1);
if (serverOnly) {
((DialogCell)view).setDialog(MessagesController.getInstance().dialogsServerOnly.get(i));
} else {
TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs.get(i);
if (AndroidUtilities.isTablet()) {
if (dialog.id == openedDialogId) {
view.setBackgroundColor(0x0f000000);
} else {
view.setBackgroundColor(0);
} else if (type == 0) {
if (view == null) {
view = new DialogCell(mContext);
}
((DialogCell) view).useSeparator = (i != getCount() - 1);
if (serverOnly) {
((DialogCell) view).setDialog(MessagesController.getInstance().dialogsServerOnly.get(i));
} else {
TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs.get(i);
if (AndroidUtilities.isTablet()) {
if (dialog.id == openedDialogId) {
view.setBackgroundColor(0x0f000000);
} else {
view.setBackgroundColor(0);
}
}
((DialogCell) view).setDialog(dialog);
}
((DialogCell)view).setDialog(dialog);
}
return view;
......
......@@ -1173,6 +1173,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
menuItem.hideSubItem(gallery_menu_save);
shareButton.setVisibility(View.GONE);
} else {
menuItem.showSubItem(gallery_menu_save);
shareButton.setVisibility(View.VISIBLE);
}
setImageIndex(0, true);
......@@ -1215,6 +1216,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
menuItem.hideSubItem(gallery_menu_save);
shareButton.setVisibility(View.GONE);
} else {
menuItem.showSubItem(gallery_menu_save);
shareButton.setVisibility(View.VISIBLE);
}
opennedFromMedia = true;
......
......@@ -194,6 +194,9 @@ public class SettingsChangeUsernameActivity extends BaseFragment {
}
private void showErrorAlert(String error) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
if (error.equals("USERNAME_INVALID")) {
......
......@@ -457,11 +457,17 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
}
private void onPlayComplete() {
playButton.setImageResource(R.drawable.video_play);
videoSeekBarView.setProgress(videoTimelineView.getLeftProgress());
if (playButton != null) {
playButton.setImageResource(R.drawable.video_play);
}
if (videoSeekBarView != null && videoTimelineView != null) {
videoSeekBarView.setProgress(videoTimelineView.getLeftProgress());
}
try {
if (videoPlayer != null) {
videoPlayer.seekTo((int) (videoTimelineView.getLeftProgress() * videoDuration));
if (videoTimelineView != null) {
videoPlayer.seekTo((int) (videoTimelineView.getLeftProgress() * videoDuration));
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);
......
......@@ -597,24 +597,22 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
messsageEditText.dispatchKeyEvent(new KeyEvent(0, 67));
}
public void onEmojiSelected(String paramAnonymousString) {
public void onEmojiSelected(String symbol) {
int i = messsageEditText.getSelectionEnd();
CharSequence localCharSequence = Emoji.replaceEmoji(paramAnonymousString, messsageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20));
messsageEditText.setText(messsageEditText.getText().insert(i, localCharSequence));
int j = i + localCharSequence.length();
messsageEditText.setSelection(j, j);
if (i < 0) {
i = 0;
}
try {
CharSequence localCharSequence = Emoji.replaceEmoji(symbol, messsageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20));
messsageEditText.setText(messsageEditText.getText().insert(i, localCharSequence));
int j = i + localCharSequence.length();
messsageEditText.setSelection(j, j);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
emojiPopup = new PopupWindow(emojiView);
/*try {
Method method = emojiPopup.getClass().getMethod("setWindowLayoutType", int.class);
if (method != null) {
method.invoke(emojiPopup, WindowManager.LayoutParams.LAST_SUB_WINDOW);
}
} catch (Exception e) {
//don't promt
}*/
}
public void setDelegate(ChatActivityEnterViewDelegate delegate) {
......
......@@ -20,12 +20,12 @@
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@anim/decelerate_cubic"
android:duration="220"/>
android:duration="150"/>
<scale
android:fromXScale=".8" android:toXScale="1.0"
android:fromYScale=".8" android:toYScale="1.0"
android:pivotX="50%p" android:pivotY="50%p"
android:interpolator="@anim/decelerate_cubic"
android:duration="220"/>
android:duration="150"/>
</set>
\ No newline at end of file
......@@ -20,7 +20,7 @@
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:interpolator="@anim/decelerate_cubic"
android:duration="220"/>
android:duration="150"/>
<scale
android:fromXScale="1.0"
......@@ -30,5 +30,5 @@
android:pivotX="50%p"
android:pivotY="50%p"
android:interpolator="@anim/decelerate_cubic"
android:duration="220"/>
android:duration="150"/>
</set>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment