Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DrKLO committed Oct 23, 2014
1 parent d03fa95 commit abf8f6f
Show file tree
Hide file tree
Showing 17 changed files with 364 additions and 625 deletions.
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
## 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
Expand Down
4 changes: 2 additions & 2 deletions TMessagesProj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies {

android {
compileSdkVersion 21
buildToolsVersion '21.0.1'
buildToolsVersion '21.0.2'

signingConfigs {
debug {
Expand Down Expand Up @@ -80,7 +80,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 372
versionCode 374
versionName "1.9.6"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public static void hideKeyboard(View view) {
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1711,7 +1711,7 @@ public int compare(TLRPC.TL_dialog tl_dialog, TLRPC.TL_dialog tl_dialog2) {
}

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;
Expand All @@ -1726,10 +1726,8 @@ public void markMessageAsRead(final long dialog_id, final long random_id, int tt
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) {
Expand Down
774 changes: 234 additions & 540 deletions TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,12 @@ private void sendMessage(String message, Double lat, Double lon, TLRPC.TL_photo
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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,25 @@ public void run() {

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);
}
}
Expand Down Expand Up @@ -197,7 +210,16 @@ public View getView(int i, View view, ViewGroup viewGroup) {
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) {
Expand All @@ -206,7 +228,7 @@ public View getView(int i, View view, ViewGroup viewGroup) {
}
}

((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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ private void openAddMenu() {
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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,10 @@ public boolean onFragmentCreate() {
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();
}
});
Expand All @@ -95,7 +94,7 @@ public void run() {
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (error[0]) {
if (usersToLoad.size() != users.size()) {
return false;
}
if (!users.isEmpty()) {
Expand Down
78 changes: 42 additions & 36 deletions TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -775,17 +775,19 @@ public boolean hasStableIds() {

@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;
Expand All @@ -795,7 +797,7 @@ public View getView(int i, View view, ViewGroup viewGroup) {
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);
Expand All @@ -805,7 +807,16 @@ public View getView(int i, View view, ViewGroup viewGroup) {
}

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) {
Expand All @@ -814,36 +825,31 @@ public View getView(int i, View view, ViewGroup viewGroup) {
}
}

((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;
Expand Down
2 changes: 2 additions & 0 deletions TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,7 @@ private void onPhotoShow(final MessageObject messageObject, final TLRPC.FileLoca
menuItem.hideSubItem(gallery_menu_save);
shareButton.setVisibility(View.GONE);
} else {
menuItem.showSubItem(gallery_menu_save);
shareButton.setVisibility(View.VISIBLE);
}
setImageIndex(0, true);
Expand Down Expand Up @@ -1215,6 +1216,7 @@ private void onPhotoShow(final MessageObject messageObject, final TLRPC.FileLoca
menuItem.hideSubItem(gallery_menu_save);
shareButton.setVisibility(View.GONE);
} else {
menuItem.showSubItem(gallery_menu_save);
shareButton.setVisibility(View.VISIBLE);
}
opennedFromMedia = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ public void onResume() {
}

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")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,17 @@ public void onSurfaceTextureUpdated(SurfaceTexture surface) {
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,24 +597,22 @@ public void onBackspace() {
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) {
Expand Down
Loading

0 comments on commit abf8f6f

Please sign in to comment.