Compare commits

..

158 Commits

Author SHA1 Message Date
B. Petersen 227f129455 Update changelog. 2017-03-10 13:43:32 +01:00
B. Petersen 4e683e5b37 Update messenger-backend submodule. 2017-03-10 13:29:38 +01:00
B. Petersen c5a0a00dd8 In video editor, show resulting length and size in action bar. 2017-03-10 13:25:46 +01:00
B. Petersen de0bce163f Move 'done' button in the group-creation dialog to the very most right position. 2017-03-10 12:05:46 +01:00
B. Petersen 9dcb58c1ea Use SI-prefix for file sizes. 2017-03-10 11:30:33 +01:00
B. Petersen 4729642f87 Show play-button overlay in video preview. 2017-03-10 01:28:58 +01:00
B. Petersen 751cbfa635 Create and use video thumbnails. 2017-03-10 01:17:26 +01:00
B. Petersen e40cae149b Mark some members as being final or remove them. 2017-03-09 21:33:49 +01:00
B. Petersen 758dfbaa67 Remove unneeded FileDidUpload and FileDidFailUpload notifications. 2017-03-09 19:08:48 +01:00
B. Petersen 29ec49b806 Show sended video messages immediately by using the new .increation method (before, video messages are shown after compression is done; this may take several 10th's seconds). 2017-03-09 18:43:07 +01:00
B. Petersen 8afb5595d0 Read bytes from file system, not from database. 2017-03-09 12:25:33 +01:00
B. Petersen 8430e9ddc6 In full-screen-dialogs with okay-checkmarks, we use a cancel-button instead of an ambiguous back-button, see the Material Design Guidelines, https://material.io/guidelines/components/dialogs.html#dialogs-alerts . 2017-03-09 11:44:29 +01:00
B. Petersen 7439fafe2b Name passcode activity screens. 2017-03-09 11:33:51 +01:00
B. Petersen e1655a40bd Start showing MiB already at 999 KiB, this avoids confusion with four digit KiB which may be being already Megabytes ... 2017-03-09 10:00:04 +01:00
B. Petersen 92fc521d5b If we're not playing, a long press on the waveform selects the whole message as usual. 2017-03-09 09:30:49 +01:00
B. Petersen 023d34f2b6 Simplify size formatting.. 2017-03-09 09:15:58 +01:00
B. Petersen 8fc064a5a4 Show videos using the system player, this seems to be more reliable. 2017-03-08 22:04:17 +01:00
B. Petersen b9a329f416 Recode and send videos. 2017-03-08 21:59:39 +01:00
B. Petersen 4997fa7301 Prepare sendMessage() function for async messages (needed for videos which must be recorded first). 2017-03-08 20:51:14 +01:00
B. Petersen e267d67d6e Stop playback if the playing message gets deleted. 2017-03-08 20:48:02 +01:00
B. Petersen 83b04a97ef Recode videos with the same size but different rotation. 2017-03-08 20:44:06 +01:00
B. Petersen 7852c9e9f9 Light video editor layout. 2017-03-08 16:09:54 +01:00
B. Petersen 009adc09bc Removed unneeded image search function, cleanup gallery code. 2017-03-08 13:57:18 +01:00
B. Petersen 4d3929576d Use light gallery theme, use default colors. 2017-03-08 12:23:39 +01:00
B. Petersen 7712def225 Prepare sending videos. 2017-03-08 00:19:28 +01:00
B. Petersen 9509919431 Repeat the normal play/pause buttons in the status-bar-player for internal consistence. 2017-03-07 23:13:26 +01:00
B. Petersen 15cc62f559 Make status-bar-player layout more compatible. 2017-03-07 22:44:26 +01:00
B. Petersen ae46cbbf5e Remove content intent for status-bar-player (unexpected behaviour). 2017-03-07 19:20:00 +01:00
B. Petersen 1664fcdc84 Remove suspicious voice proximity commands. 2017-03-07 19:17:16 +01:00
B. Petersen 2c45f4af37 Allow generating waveforms without a messsage object. 2017-03-07 19:00:14 +01:00
B. Petersen b3d1747c0b Fix a redrawing bug on Kit Kat. 2017-03-07 18:05:40 +01:00
B. Petersen 693952d0eb Show waveform for voice messages. 2017-03-07 17:17:37 +01:00
B. Petersen 0ad5bd6e48 Update some colors and measures. 2017-03-07 14:47:34 +01:00
B. Petersen 89c34f89c9 Remove screenshot observer. We do not want to observe the users of the app; moreover, this is useless and results in false security. 2017-03-07 13:13:20 +01:00
B. Petersen 70971a73ad Remove unused download queues, this stuff goes to the backend, if needed. 2017-03-07 12:39:28 +01:00
B. Petersen 2c5b377712 Check permission on raise-to-speak. 2017-03-07 12:06:35 +01:00
B. Petersen ae4b5a711b Go to previous/next media. 2017-03-06 19:31:52 +01:00
B. Petersen 252bc52d47 Show correct media information from the backend. 2017-03-06 17:11:12 +01:00
B. Petersen 655783db1e Make mrpoortext_t more general-purpose-use. 2017-03-05 16:53:16 +01:00
B. Petersen 10b2af3656 Simplify audio select dialog. 2017-03-05 14:23:31 +01:00
B. Petersen 54c3a963a4 Smarter voice message preview. 2017-03-03 21:32:56 +01:00
B. Petersen a7836eaded Sending voice messages using 'Raise to speak' :-) 2017-03-03 19:20:25 +01:00
B. Petersen 10fcbdc81d Bump version. 2017-03-03 16:33:32 +01:00
B. Petersen b2a5885787 Show ABI separated from version. 2017-03-03 16:15:35 +01:00
B. Petersen 9886a4feb4 Add advanced settings dialog, remove some upload functions. 2017-03-03 15:26:17 +01:00
B. Petersen dcd04f7064 Remove always-empty-objects. 2017-03-03 15:05:37 +01:00
B. Petersen 5773ce8b83 Update gradle. 2017-03-03 14:38:46 +01:00
B. Petersen 0c3eb19de6 Rewrite settings dialogs. 2017-03-03 14:37:30 +01:00
B. Petersen 5e72e30d58 Fix endless redraw loop for voice message showing. 2017-03-02 23:23:48 +01:00
B. Petersen c9d8ad3d4a Show the status-bar-player for music as well as for voice messages. 2017-03-02 22:26:57 +01:00
B. Petersen 62bd4f6d9f Cleanup some ChatMessageCell conditions. 2017-03-02 21:48:02 +01:00
B. Petersen 15e1d55a77 Send voice messages as voice messages. 2017-03-02 21:22:34 +01:00
B. Petersen 04cab2ee0c Remove webpage message types. 2017-03-02 21:19:51 +01:00
B. Petersen fd28868ea8 Stop player when deselecting an audio track in the audio-select-activity. 2017-03-02 17:43:00 +01:00
B. Petersen 129e6ad487 Do not hide the default-send-key if send-by-enter is enables (looks like a bug). 2017-03-02 16:43:37 +01:00
B. Petersen 082f7229f2 Visualise enabled send-by-enter-function by hiding the normal send-button and showing a send key instead of a new-line-key on the keyboard. 2017-03-02 15:09:29 +01:00
B. Petersen 1c6001ed92 Remove unused top-view from ChatActivityEnterView. 2017-03-02 13:43:27 +01:00
B. Petersen 2ec48ef1e6 Remove unused cancelBotButton. 2017-03-02 13:19:43 +01:00
B. Petersen 04397f3cb0 Remove unused caption-text-view-layout. 2017-03-02 12:51:18 +01:00
B. Petersen 8697756083 Cleanup setting page. 2017-03-02 11:32:07 +01:00
B. Petersen 7be5ec589c Remove unneded permissions. 2017-03-01 22:05:57 +01:00
B. Petersen d3fbf529eb Remove (hopefully) unneeded AbstractThreadedSyncAdapter. 2017-03-01 20:14:39 +01:00
B. Petersen e47818b5df Remove currently unused and not implemented ChooserTargetService. 2017-03-01 18:56:23 +01:00
B. Petersen 201c9ebf4c Remove currently unused AccountAuthenticator service. 2017-03-01 18:36:14 +01:00
B. Petersen 0626192659 Allow 'Open messages' only for messages with an attachment. 2017-03-01 17:57:10 +01:00
B. Petersen 0acdd3f885 Enable basic voice message recording. 2017-03-01 15:18:26 +01:00
B. Petersen 6f0fd1072d Remove disturbing 'big' notification-music-player. Update notification-music-player logo and colors. 2017-03-01 14:22:36 +01:00
B. Petersen d17579b928 Do not expose data through MediaBrowserService, this seems unexpected for an messenger. Instead, the user can use 'save to music' or 'share' explicitly for items not privacy related. 2017-03-01 11:30:39 +01:00
B. Petersen 090039ec29 Remove internal player and rely on the MusicService 2017-02-28 23:18:07 +01:00
B. Petersen df8bbcd00a Orange audio seekbar. 2017-02-28 22:19:23 +01:00
B. Petersen fffc77cc82 Play audio files. 2017-02-28 21:53:49 +01:00
B. Petersen 9ee5af9fd2 Update German. 2017-02-28 20:53:45 +01:00
B. Petersen 5462f3d341 Add 'Open' command for all file types. 2017-02-28 19:15:31 +01:00
B. Petersen 46dca0d212 Remove unused resources. 2017-02-28 18:39:25 +01:00
B. Petersen 603572c796 Remove (hopefully) unneeded ShareBroadcastReceiver class. 2017-02-28 17:45:11 +01:00
B. Petersen db6c2d9d7c Show 'File not found' hint. 2017-02-28 17:03:25 +01:00
B. Petersen b6c6375492 More senseful name for new-chat-from-deaddrop-button. 2017-02-28 16:08:52 +01:00
B. Petersen 3f5255c116 Remove load and cancel buttons from ChatMessageCell, cleanup. 2017-02-28 15:59:15 +01:00
B. Petersen 68f3974aa2 Name button states. 2017-02-28 14:26:45 +01:00
B. Petersen 2c062d8d51 Select and send audio attachments via the music browser. 2017-02-27 22:35:20 +01:00
B. Petersen 1097157f69 Show icon for incoming audio files. 2017-02-27 22:01:52 +01:00
B. Petersen 21784aa951 Simplify and rework message sending. 2017-02-27 19:24:55 +01:00
B. Petersen f980f7285a Remove unused 'Reply'-parameters, continued. 2017-02-27 17:12:04 +01:00
B. Petersen 622b6bc786 Remove unused 'Reply'-parameters. 2017-02-27 16:26:44 +01:00
B. Petersen 61fc0485b7 Unify attach icons. 2017-02-27 12:25:22 +01:00
B. Petersen be2af9c871 Name the request codes. Wondering how this was editable before. 2017-02-24 21:42:31 +01:00
B. Petersen 898e4a45e3 Remove unneeded merge-dialog option. 2017-02-24 20:48:04 +01:00
B. Petersen e47c6406f8 Implement share from chat/photo view. 2017-02-24 19:41:18 +01:00
B. Petersen 1d0ed83bad Implement save to downloads/music/gallery. 2017-02-24 17:34:54 +01:00
Björn Petersen 404f6ea9da Update CHANGELOG.md 2017-02-24 12:00:52 +01:00
B. Petersen 8d75f867fd Add menu buttons for saving and sharing attachments. 2017-02-23 23:59:45 +01:00
B. Petersen 83f60e6252 Remove unused file observers. 2017-02-23 22:44:03 +01:00
B. Petersen c4bd6576d8 Simplify object creation. 2017-02-23 22:43:31 +01:00
B. Petersen 12df911162 Use the standard text view for pincode entering; otherwise, the last entered number is always shown for a moment, independently of the system setting (in fact, for pincodes, currently, the number is _never_ shown as setText() does not work this way; however, this is just fine, much better). 2017-02-23 21:06:53 +01:00
B. Petersen f5a37ee185 Redo false commit. 2017-02-23 20:36:01 +01:00
B. Petersen 92d71ad150 When locking the app, try to clear the screenshot that is shown in the task switcher. 2017-02-23 20:30:15 +01:00
B. Petersen 8824b30c4a Remove unused import. 2017-02-23 16:38:37 +01:00
B. Petersen 741e281a37 Dismiss app when touching the lock-symbol. 2017-02-23 16:37:22 +01:00
B. Petersen 354295ae7a Unify passcode-enter-dialog background. 2017-02-23 15:15:43 +01:00
B. Petersen 09af0640c7 Simplify fingerprint dialog. 2017-02-23 14:50:28 +01:00
B. Petersen 1485eeecf6 Do not use the new AttachmentsContentProvider for pulic URLs as used when attaching local files. 2017-02-23 13:28:31 +01:00
B. Petersen 8b78df6a14 Remove attach size limit. 2017-02-22 23:09:56 +01:00
B. Petersen 686ee6c246 Coloize attachment file name in chat view. 2017-02-22 22:56:32 +01:00
B. Petersen ca8114d9af Simplify and beautify file selector. 2017-02-22 22:33:23 +01:00
B. Petersen b2392c90c2 Use the same colors for the time and for the forward title. 2017-02-22 21:18:51 +01:00
B. Petersen d207fa67e5 Remove unused URL-searching when entering text. 2017-02-22 20:53:13 +01:00
B. Petersen 2e41fe756a Show correct error box when an attachment cannot be opened. 2017-02-22 20:43:05 +01:00
B. Petersen d533ea5c37 Open attachments by using a content provider. 2017-02-22 19:26:18 +01:00
B. Petersen 4365e176d8 Remove dead code. 2017-02-22 17:53:21 +01:00
B. Petersen 486b03e031 Update messenger-backend submodule. 2017-02-22 17:34:15 +01:00
B. Petersen 1dbf08327c Ignore some files. 2017-02-22 16:56:30 +01:00
B. Petersen 0d15bb3544 Add missing file, ignore files marked as .prv (useful for scripts etc.). 2017-02-22 16:18:57 +01:00
B. Petersen e3b48206e9 Remove 'Done'-hint after message deletion; as normally at least one of the selected message is in view when this function is used, there is enough visual feedback (we want the 'Done'-hint only for actions without visual feedback as copy-to-clipboard). 2017-02-22 15:50:25 +01:00
B. Petersen a0e364a50f Show any documents attached (opening still not working). 2017-02-21 23:21:09 +01:00
B. Petersen 0db3fc55c6 Use binary prefix for file sizes. 2017-02-21 22:18:47 +01:00
B. Petersen 95c3fca389 Show some hints on silent actions as copy-to-clipboard or delete-contact. 2017-02-21 21:52:24 +01:00
B. Petersen 68a72fb8fd Typo. 2017-02-21 18:43:15 +01:00
B. Petersen 473410ece2 Change urls to https://getdelta.org . 2017-02-21 18:40:42 +01:00
B. Petersen 4f760a790a Differ betweend music and voice messages. 2017-02-21 17:02:49 +01:00
B. Petersen ad7ee4428f Remove duplicate strings. 2017-02-21 14:28:31 +01:00
B. Petersen 92cf756ad2 Cleanup reply option in ChatMessageCell. 2017-02-20 22:38:24 +01:00
B. Petersen 3d746f08ba Remove unused message object types. 2017-02-20 21:58:25 +01:00
B. Petersen e272459fc9 Use named values for MessageObject.type; wondering how and by whom this was ever usable before. 2017-02-20 21:43:50 +01:00
B. Petersen a793ae52f9 Make file selection dialog usable. 2017-02-20 20:43:18 +01:00
B. Petersen f2349a9bdd Accept vcards shared to us by external apps. Remove unused contact and location code. 2017-02-20 19:12:29 +01:00
B. Petersen 7082798c03 Swap File- and Contact-attach icons. 2017-02-20 14:44:35 +01:00
B. Petersen f4fc5fae2b Cleanup camera preview code. 2017-02-20 13:57:36 +01:00
B. Petersen 5799e43b3a Update Polish. 2017-02-20 11:54:51 +01:00
B. Petersen f929d6cc31 Cleanup SendMessagesHelper.sendMessage__(), fix a crash when trying to send music files. 2017-02-19 13:04:17 +01:00
B. Petersen 9f92efc554 More neutral language when choosing contacts. 2017-02-19 12:14:23 +01:00
B. Petersen 3338b83910 Pimp attach gui. 2017-02-18 23:57:43 +01:00
B. Petersen a4c104431d Show a hint after deletion of a contact. 2017-02-18 22:49:08 +01:00
B. Petersen 31ba521244 Prefer the term 'contact' over 'user', unify usage. 2017-02-18 22:26:16 +01:00
B. Petersen 50dfe15f09 Show a hint if a user is already in a group. 2017-02-18 21:38:04 +01:00
Dr. Tobias Quathamer 4b06d19787 Add item to changelog for v0.1.20 2017-02-18 16:58:27 +01:00
B. Petersen 66d147eb8b Implement sending contact's addresses. 2017-02-17 21:50:31 +01:00
Björn Petersen d2591922a6 Update CHANGELOG.md 2017-02-17 21:14:34 +01:00
B. Petersen bcc6f79373 More options in URL's context menu: Create chat, create user, open externally, copy to clipboard. 2017-02-17 21:03:25 +01:00
B. Petersen 015edd6053 Create a new chat by clicking on email-links. 2017-02-17 19:26:25 +01:00
B. Petersen bec562bfb2 Linkify email-addresses. 2017-02-17 19:08:32 +01:00
B. Petersen 01a7c93771 If an avatar is shown for a message in group layout, make the bubble a little bit smaller. 2017-02-17 17:06:18 +01:00
B. Petersen 502bae625f Cleanup MessageObject. 2017-02-17 16:33:48 +01:00
B. Petersen a34d511922 Update Polish. 2017-02-17 15:50:57 +01:00
B. Petersen e65aa19109 Fix a null-pointer exception when using tablets. 2017-02-17 13:38:23 +01:00
B. Petersen 30585b8de4 More background wallpaper dynamic. 2017-02-16 23:19:09 +01:00
B. Petersen 0bd4234214 Cleanup drawer profile cell. 2017-02-16 22:42:07 +01:00
B. Petersen db4ceb6d68 Prepare release v0.1.20 (we forgot to update the submodule in v0.1.19). 2017-02-16 20:49:29 +01:00
B. Petersen 1612a5d7cd Update messenger-backend submodule. 2017-02-16 20:42:11 +01:00
B. Petersen f60f4539b5 Prepare release v0.1.19 2017-02-16 16:30:38 +01:00
B. Petersen db7c8a9dfc Update changelog. 2017-02-16 15:19:45 +01:00
B. Petersen 9d1f4266c2 Update changelog. 2017-02-15 22:46:07 +01:00
Björn Petersen 0614c4fc32 Update README.md 2017-02-14 19:57:56 +01:00
B. Petersen 58e452b711 Update polish. 2017-02-14 15:26:58 +01:00
Dr. Tobias Quathamer b478696bed Target API level 25 (Nougat 7.1) 2017-02-13 21:19:47 +01:00
B. Petersen f3584d9eaf Update Portuguese. 2017-02-13 20:37:35 +01:00
B. Petersen d9998167f4 Colorize the background image. 2017-02-13 17:59:06 +01:00
Dr. Tobias Quathamer 874e300220 Remove LocaleController calls 2017-02-11 17:48:41 +01:00
Dr. Tobias Quathamer 49e4b90cc3 Remove unused code 2017-02-11 17:42:35 +01:00
619 changed files with 2842 additions and 13482 deletions
+3
View File
@@ -6,3 +6,6 @@ obj/
local.properties
*.keystore
libs/
# ignore private scripts and directories, eg. local2github.prv.sh
*.prv*
+27
View File
@@ -1,5 +1,32 @@
# Delta Chat Changelog
## v0.1.21
2017-03-10
* Record and send voice messages
* Record and send videos
* Send and play music
* Send contacts and email addresses
* Sending and opening attachments of any type
* Share and open commands for all attachments
* Accept VCards send to us by other apps
* Clickable email addresses
* Update Polish translation
* Fix tablet startup bug
* Close the app when using the lock-app-via-pincode function
* Protect data by using a content provider for sharing
* Try to clear the task switcher's screenshots when locking the app via pincode
* Pimp GUI
## v0.1.20
2017-02-16
* Avoid unwanted downloads of lots of old messages
* Make the "Chats" folder visible if the server hides new folders by default
* Fix a crash when the server returns empty folders
* Update Polish and Portuguese translations
* Use API level 25 (Nougat 7.1) as target
## v0.1.18
2017-02-11
+6 -6
View File
@@ -24,15 +24,15 @@ tasks.withType(JavaCompile) {
}
dependencies {
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.googlecode.mp4parser:isoparser:1.0.6'
compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
}
android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
compileSdkVersion 25
buildToolsVersion '25.0.2'
useLibrary 'org.apache.http.legacy'
defaultConfig.applicationId = "com.b44t.messenger"
@@ -76,7 +76,7 @@ android {
}
}
defaultConfig.versionCode = 17
defaultConfig.versionCode = 20
sourceSets.main {
jniLibs.srcDir 'libs'
@@ -116,7 +116,7 @@ android {
defaultConfig {
minSdkVersion 14 // 14: Android 4.0 Ice Cream Sandwich 2011 (Telegram default), 21: Android 5.0 Lollipop 2014 (recommended for InstantRun)
targetSdkVersion 23
versionName "0.1.18"
targetSdkVersion 25
versionName "0.1.21" // do NOT forget to increase defaultConfig.versionCode!
}
}
+77 -18
View File
@@ -384,6 +384,12 @@ JNIEXPORT jint Java_com_b44t_messenger_MrMailbox_createGroupChat(JNIEnv *env, jc
}
JNIEXPORT jint Java_com_b44t_messenger_MrMailbox_isContactInChat(JNIEnv *env, jclass cls, jint chat_id, jint contact_id)
{
return (jint)mrmailbox_is_contact_in_chat(get_mrmailbox_t(env, cls), chat_id, contact_id);
}
JNIEXPORT jint Java_com_b44t_messenger_MrMailbox_addContactToChat(JNIEnv *env, jclass cls, jint chat_id, jint contact_id)
{
return (jint)mrmailbox_add_contact_to_chat(get_mrmailbox_t(env, cls), chat_id, contact_id);
@@ -649,20 +655,20 @@ JNIEXPORT jint Java_com_b44t_messenger_MrChat_MrChatSetDraft(JNIEnv *env, jclass
}
JNIEXPORT jint Java_com_b44t_messenger_MrChat_MrChatSendText(JNIEnv *env, jclass c, jlong hChat, jstring text)
JNIEXPORT jint Java_com_b44t_messenger_MrChat_sendText(JNIEnv *env, jclass cls, jstring text)
{
mrmsg_t* msg = mrmsg_new();
msg->m_type = MR_MSG_TEXT;
CHAR_REF(text);
msg->m_text = textPtr? strdup(textPtr) : NULL;
CHAR_UNREF(text);
jint msg_id = mrchat_send_msg((mrchat_t*)hChat, msg);
jint msg_id = mrchat_send_msg(get_mrchat_t(env, cls), msg);
mrmsg_unref(msg);
return msg_id;
}
JNIEXPORT jint Java_com_b44t_messenger_MrChat_MrChatSendMedia(JNIEnv *env, jclass c, jlong hChat, jint type, jstring file, jstring mime, jint w, jint h, jint ms)
JNIEXPORT jint Java_com_b44t_messenger_MrChat_sendMedia(JNIEnv *env, jclass cls, jint type, jstring file, jstring mime, jint w, jint h, jint ms, jstring author, jstring trackname)
{
mrmsg_t* msg = mrmsg_new();
msg->m_type = type;
@@ -676,22 +682,36 @@ JNIEXPORT jint Java_com_b44t_messenger_MrChat_MrChatSendMedia(JNIEnv *env, jclas
mrparam_set_int(msg->m_param, 'w', w);
mrparam_set_int(msg->m_param, 'h', h);
}
if( type == MR_MSG_AUDIO || type == MR_MSG_VIDEO ) {
if( type == MR_MSG_AUDIO || type == MR_MSG_VOICE || type == MR_MSG_VIDEO ) {
mrparam_set_int(msg->m_param, 'd', ms);
}
jint msg_id = mrchat_send_msg((mrchat_t*)hChat, msg);
if( type == MR_MSG_AUDIO ) {
CHAR_REF(author);
mrparam_set(msg->m_param, 'N', authorPtr);
CHAR_UNREF(author);
CHAR_REF(trackname);
mrparam_set(msg->m_param, 'n', tracknamePtr);
CHAR_UNREF(trackname);
}
jint msg_id = mrchat_send_msg(get_mrchat_t(env, cls), msg);
mrmsg_unref(msg);
return msg_id;
}
JNIEXPORT jintArray Java_com_b44t_messenger_MrMailbox_MrMailboxGetChatMedia(JNIEnv *env, jclass c, jlong hMailbox, jint chat_id, jint msg_type, jint or_msg_type)
JNIEXPORT jintArray Java_com_b44t_messenger_MrMailbox_getChatMedia(JNIEnv *env, jclass cls, jint chat_id, jint msg_type, jint or_msg_type)
{
carray* ca = mrmailbox_get_chat_media((mrmailbox_t*)hMailbox, chat_id, msg_type, or_msg_type);
carray* ca = mrmailbox_get_chat_media(get_mrmailbox_t(env, cls), chat_id, msg_type, or_msg_type);
return carray2jintArray_n_carray_free(env, ca);
}
JNIEXPORT jint Java_com_b44t_messenger_MrMailbox_getNextMedia(JNIEnv *env, jclass cls, jint msg_id, jint dir)
{
return mrmailbox_get_next_media(get_mrmailbox_t(env, cls), msg_id, dir);
}
JNIEXPORT jintArray Java_com_b44t_messenger_MrMailbox_getChatMsgs(JNIEnv *env, jclass cls, jint chat_id, jint flags, jint marker1before)
{
carray* ca = mrmailbox_get_chat_msgs(get_mrmailbox_t(env, cls), chat_id, flags, marker1before);
@@ -803,9 +823,9 @@ JNIEXPORT jint Java_com_b44t_messenger_MrMsg_MrMsgGetToId(JNIEnv *env, jclass c,
}
JNIEXPORT jstring Java_com_b44t_messenger_MrMsg_MrMsgGetParam(JNIEnv *env, jclass c, jlong hMsg, jint key, jstring def)
JNIEXPORT jstring Java_com_b44t_messenger_MrMsg_getParam(JNIEnv *env, jobject obj, jint key, jstring def)
{
mrmsg_t* ths = (mrmsg_t*)hMsg;
mrmsg_t* ths = get_mrmsg_t(env, obj);
CHAR_REF(def);
char* temp = mrparam_get(ths? ths->m_param:NULL, key, defPtr);
jstring ret = JSTRING_NEW(temp);
@@ -815,17 +835,38 @@ JNIEXPORT jstring Java_com_b44t_messenger_MrMsg_MrMsgGetParam(JNIEnv *env, jclas
}
JNIEXPORT jint Java_com_b44t_messenger_MrMsg_MrMsgGetParamInt(JNIEnv *env, jclass c, jlong hMsg, jint key, jint def)
JNIEXPORT jint Java_com_b44t_messenger_MrMsg_getParamInt(JNIEnv *env, jobject obj, jint key, jint def)
{
mrmsg_t* ths = (mrmsg_t*)hMsg;
mrmsg_t* ths = get_mrmsg_t(env, obj);
return mrparam_get_int(ths? ths->m_param:NULL, key, def);
}
JNIEXPORT void Java_com_b44t_messenger_MrMsg_setParamInt(JNIEnv *env, jobject obj, jint key, jint value)
{
mrmsg_t* ths = get_mrmsg_t(env, obj);
mrparam_set_int(ths? ths->m_param:NULL, key, value);
}
JNIEXPORT void Java_com_b44t_messenger_MrMsg_saveParamToDisk(JNIEnv *env, jobject obj)
{
mrmsg_save_param_to_disk(get_mrmsg_t(env, obj));
}
JNIEXPORT jint Java_com_b44t_messenger_MrMsg_getBytes(JNIEnv *env, jobject obj)
{
jint ret = 0;
mrmsg_t* ths = get_mrmsg_t(env, obj);
return ths? ths->m_bytes : 0;
if( ths ) {
const char* file = mrparam_get(ths->m_param, 'f', NULL);
if( file ) {
ret = mr_get_filebytes(file);
free(file);
}
}
return ret;
}
@@ -841,6 +882,24 @@ JNIEXPORT jint Java_com_b44t_messenger_MrMsg_getSummarytext(JNIEnv *env, jobject
}
JNIEXPORT jint Java_com_b44t_messenger_MrMsg_getFilename(JNIEnv *env, jobject obj)
{
return JSTRING_NEW(mrmsg_get_filename(get_mrmsg_t(env, obj)));
}
JNIEXPORT jlong Java_com_b44t_messenger_MrMsg_getMediainfoCPtr(JNIEnv *env, jobject obj)
{
return (jlong)mrmsg_get_mediainfo(get_mrmsg_t(env, obj));
}
JNIEXPORT jint Java_com_b44t_messenger_MrMsg_isIncreation(JNIEnv *env, jobject obj)
{
return (jint)mrmsg_is_increation(get_mrmsg_t(env, obj));
}
/*******************************************************************************
* MrContact
******************************************************************************/
@@ -884,24 +943,24 @@ JNIEXPORT void Java_com_b44t_messenger_MrPoortext_MrPoortextUnref(JNIEnv *env, j
}
JNIEXPORT jstring Java_com_b44t_messenger_MrPoortext_MrPoortextGetTitle(JNIEnv *env, jclass c, jlong hPoortext)
JNIEXPORT jstring Java_com_b44t_messenger_MrPoortext_MrPoortextGetText1(JNIEnv *env, jclass c, jlong hPoortext)
{
mrpoortext_t* ths = (mrpoortext_t*)hPoortext; if( ths == NULL ) { return JSTRING_NEW(NULL); }
return JSTRING_NEW(ths->m_title);
return JSTRING_NEW(ths->m_text1);
}
JNIEXPORT jint Java_com_b44t_messenger_MrPoortext_MrPoortextGetTitleMeaning(JNIEnv *env, jclass c, jlong hPoortext)
JNIEXPORT jint Java_com_b44t_messenger_MrPoortext_MrPoortextGetText1Meaning(JNIEnv *env, jclass c, jlong hPoortext)
{
mrpoortext_t* ths = (mrpoortext_t*)hPoortext; if( ths == NULL ) { return 0; }
return ths->m_title_meaning;
return ths->m_text1_meaning;
}
JNIEXPORT jstring Java_com_b44t_messenger_MrPoortext_MrPoortextGetText(JNIEnv *env, jclass c, jlong hPoortext)
JNIEXPORT jstring Java_com_b44t_messenger_MrPoortext_MrPoortextGetText2(JNIEnv *env, jclass c, jlong hPoortext)
{
mrpoortext_t* ths = (mrpoortext_t*)hPoortext; if( ths == NULL ) { return JSTRING_NEW(NULL); }
return JSTRING_NEW(ths->m_text);
return JSTRING_NEW(ths->m_text2);
}
+28 -16
View File
@@ -20,28 +20,28 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- we need it eg. for getActiveNetworkInfo() -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- <uses-permission android:name="android.permission.GET_ACCOUNTS" /> - required for AccountManager -->
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>
<uses-permission android:name="android.permission.READ_PROFILE"/>
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"/>
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
<!-- <uses-permission android:name="android.permission.WRITE_CONTACTS" /> -->
<!-- <uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/> - required for AccountManager in API level <= 22 -->
<!-- <uses-permission android:name="android.permission.READ_PROFILE"/> - required for ContactsContract.Profile -->
<!-- <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"/> required for AbstractThreadedSyncAdapter-->
<!-- <uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/> - required for AbstractThreadedSyncAdapter -->
<!-- <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/> - seems to be unneeded and is no longer supported by Android, was needed for AbstractAccountAuthenticator, see http://stackoverflow.com/questions/32601456/marshmallow-permission-implementation#36907308 -->
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> - required for windows using the TYPE_SYSTEM_ALERT flag -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> <!-- we need the TelephonyManager to pause the audio player on calls -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
<uses-permission android:name="android.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/>
<!--<uses-permission android:name="android.permission.CAMERA" />-->
<!-- <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" /> - required for AndroidUtilities.uninstallShortcut() -->
<!-- <uses-permission android:name="android.permission.CAMERA" /> - also disabled in T'gram; we're using the camera via an intent only -->
<application
android:name=".ApplicationLoader"
@@ -114,7 +114,7 @@
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tg" />
</intent-filter> -->
<meta-data android:name="android.service.chooser.chooser_target_service" android:value=".TgChooserTargetService" />
<!-- see note below, <meta-data android:name="android.service.chooser.chooser_target_service" android:value=".TgChooserTargetService" /> -->
</activity>
<activity
android:name="com.b44t.ui.ManageSpaceActivity"
@@ -157,6 +157,7 @@
</receiver>
-->
<!-- currently, we do not use the android account system
<service android:name=".AuthenticatorService" android:exported="true">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator"/>
@@ -164,7 +165,9 @@
<meta-data android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/auth"/>
</service>
-->
<!-- seems to be not needed, derived from AbstractThreadedSyncAdapter, would need the READ/WRITE_SYNC_SETTINGS
<service android:name=".ContactsSyncAdapterService" android:exported="true">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
@@ -174,7 +177,11 @@
<meta-data android:name="android.provider.CONTACTS_STRUCTURE"
android:resource="@xml/contacts" />
</service>
-->
<!-- this would implement the "direct share" functionality (the system shows some direct links eg.
to the most recent chats when calling "share" from another app, see https://developer.android.com/reference/android/service/chooser/ChooserTargetService.html )
however, if we want this feature, we have to reimplement TgChooserTargetService or sth. like that.
<service
android:name="com.b44t.messenger.TgChooserTargetService"
android:label="@string/AppName"
@@ -182,18 +189,19 @@
<intent-filter>
<action android:name="android.service.chooser.ChooserTargetService" />
</intent-filter>
</service>
</service> -->
<service android:name=".NotificationsService" android:enabled="true"/>
<service android:name=".NotificationRepeat" android:exported="false"/>
<service android:name=".ClearCacheService" android:exported="false"/>
<service android:name=".VideoEncodingService" android:enabled="true"/>
<service android:name=".MusicPlayerService" android:exported="true" android:enabled="true"/>
<!-- Do not expose data through MediaBrowserService, this seems unexpected for an messenger.
Instead, the user can use 'save to music' or 'share' explicitly for items not privacy related.
<service android:name=".MusicBrowserService" android:exported="true">
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService"/>
</intent-filter>
</service>
</service> -->
<receiver android:name=".MusicPlayerReceiver" >
<intent-filter>
@@ -217,10 +225,14 @@
<receiver android:name=".WearReplyReceiver" android:enabled="true"/>
<!-- <receiver android:name=".NetworkAlarm" android:enabled="true"/> -->
<!-- seems to be unneeded (bp)
<receiver android:name=".ShareBroadcastReceiver" android:enabled="true"/>
-->
<receiver android:name=".NotificationDismissReceiver" android:exported="false"/>
<provider android:name=".AttachmentsContentProvider" android:authorities="${applicationId}.attachments" android:exported="true" />
<uses-library android:name="com.sec.android.app.multiwindow" android:required="false" />
<meta-data android:name="com.sec.android.support.multiwindow" android:value="true" />
<meta-data android:name="com.sec.android.multiwindow.DEFAULT_SIZE_W" android:value="632dp" />
@@ -22,15 +22,15 @@
package com.b44t.messenger;
import android.Manifest;
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DownloadManager;
import android.content.ContentUris;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
@@ -41,8 +41,6 @@ import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
@@ -64,8 +62,8 @@ import android.widget.AbsListView;
import android.widget.EdgeEffect;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.b44t.ui.Components.ForegroundDetector;
import com.b44t.ui.Components.TypefaceSpan;
@@ -79,6 +77,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@@ -100,7 +99,6 @@ public class AndroidUtilities {
private static Boolean isTablet = null;
private static int adjustOwnerClassGuid = 0;
public static Pattern WEB_URL = null;
static {
try {
final String GOOD_IRI_CHAR = "a-zA-Z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF";
@@ -114,15 +112,6 @@ public class AndroidUtilities {
final String GTLD = "[" + GOOD_GTLD_CHAR + "]{2,63}";
final String HOST_NAME = "(" + IRI + "\\.)+" + GTLD;
final Pattern DOMAIN_NAME = Pattern.compile("(" + HOST_NAME + "|" + IP_ADDRESS + ")");
WEB_URL = Pattern.compile(
"((?:(http|https|Http|Https):\\/\\/(?:(?:[a-zA-Z0-9\\$\\-\\_\\.\\+\\!\\*\\'\\(\\)"
+ "\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,64}(?:\\:(?:[a-zA-Z0-9\\$\\-\\_"
+ "\\.\\+\\!\\*\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,25})?\\@)?)?"
+ "(?:" + DOMAIN_NAME + ")"
+ "(?:\\:\\d{1,5})?)" // plus option port number
+ "(\\/(?:(?:[" + GOOD_IRI_CHAR + "\\;\\/\\?\\:\\@\\&\\=\\#\\~" // plus option query params
+ "\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_])|(?:\\%[a-fA-F0-9]{2}))*)?"
+ "(?:\\b|$)");
} catch (Exception e) {
FileLog.e("messenger", e);
}
@@ -234,19 +223,6 @@ public class AndroidUtilities {
}
}
public static boolean isKeyboardShowed(View view) {
if (view == null) {
return false;
}
try {
InputMethodManager inputManager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
return inputManager.isActive(view);
} catch (Exception e) {
FileLog.e("messenger", e);
}
return false;
}
public static void hideKeyboard(View view) {
if (view == null) {
return;
@@ -408,19 +384,6 @@ public class AndroidUtilities {
}
}
public static void setProgressBarAnimationDuration(ProgressBar progressBar, int duration) {
if (progressBar == null) {
return;
}
try {
Field mCursorDrawableRes = ProgressBar.class.getDeclaredField("mDuration");
mCursorDrawableRes.setAccessible(true);
mCursorDrawableRes.setInt(progressBar, duration);
} catch (Exception e) {
FileLog.e("messenger", e);
}
}
private static Intent createShortcutIntent(int did, Bitmap bitmap) {
Intent shortcutIntent = new Intent(ApplicationLoader.applicationContext, OpenChatReceiver.class);
@@ -451,6 +414,9 @@ public class AndroidUtilities {
}
}
/* -- uninstalling shortcuts would be needed if a chat is deleted. However,
-- com.b44t.messenger.openchatNNN just opens the overview in this case, which is okay for the moment.
-- uninstalling shortcuts would required the permission com.android.launcher.permission.UNINSTALL_SHORTCUT
public static void uninstallShortcut(int did) {
try {
Intent addIntent = createShortcutIntent(did, null);
@@ -459,7 +425,7 @@ public class AndroidUtilities {
} catch (Exception e) {
FileLog.e("messenger", e);
}
}
}*/
public static int getViewInset(View view) {
if (view == null || Build.VERSION.SDK_INT < 21 || view.getHeight() == AndroidUtilities.displaySize.y || view.getHeight() == AndroidUtilities.displaySize.y - statusBarHeight) {
@@ -647,6 +613,26 @@ public class AndroidUtilities {
animatorSet.start();
}
public static void showDoneHint(Context context)
{
// this hint should be shown when an action is complete and not directly visible on the screen,
// eg. copy-to-clipboard or item deletion in a long list
Toast.makeText(context, ApplicationLoader.applicationContext.getString(R.string.DoneHint), Toast.LENGTH_SHORT).show();
}
public static void showErrorHint(Context context)
{
// this hint should be shown on errors that normally should not happen.
showHint(context, ApplicationLoader.applicationContext.getString(R.string.ErrorHint));
}
public static Toast showHint(Context context, String text)
{
Toast t = Toast.makeText(context, text, Toast.LENGTH_LONG);
t.show();
return t;
}
public static void addToClipboard(CharSequence str) {
try {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
@@ -802,49 +788,6 @@ public class AndroidUtilities {
return null;
}
public static CharSequence generateSearchName(String name, String name2, String q) {
if (name == null && name2 == null) {
return "";
}
SpannableStringBuilder builder = new SpannableStringBuilder();
String wholeString = name;
if (wholeString == null || wholeString.length() == 0) {
wholeString = name2;
} else if (name2 != null && name2.length() != 0) {
wholeString += " " + name2;
}
wholeString = wholeString.trim();
String lower = " " + wholeString.toLowerCase();
int index;
int lastIndex = 0;
while ((index = lower.indexOf(" " + q, lastIndex)) != -1) {
int idx = index - (index == 0 ? 0 : 1);
int end = q.length() + (index == 0 ? 0 : 1) + idx;
if (lastIndex != 0 && lastIndex != idx + 1) {
builder.append(wholeString.substring(lastIndex, idx));
} else if (lastIndex == 0 && idx != 0) {
builder.append(wholeString.substring(0, idx));
}
String query = wholeString.substring(idx, end);
if (query.startsWith(" ")) {
builder.append(" ");
}
query = query.trim();
builder.append(AndroidUtilities.replaceTags("<c#ff4d83b3>" + query + "</c>"));
lastIndex = end;
}
if (lastIndex != -1 && lastIndex != wholeString.length()) {
builder.append(wholeString.substring(lastIndex, wholeString.length()));
}
return builder;
}
public static File generateVideoPath() {
try {
File storageDir = getAlbumDir();
@@ -856,15 +799,15 @@ public class AndroidUtilities {
return null;
}
public static String formatFileSize(long size) {
if (size < 1024) {
return String.format("%d B", size);
} else if (size < 1024 * 1024) {
return String.format("%.1f KB", size / 1024.0f);
} else if (size < 1024 * 1024 * 1024) {
return String.format("%.1f MB", size / 1024.0f / 1024.0f);
public static String formatFileSize(long bytes) {
// We use the SI-prefix with the usual base as defined in the 1990's.
// The other option would be to show MiB and KiB, however, these abbreviations are not very usual.
if (bytes < 1000) {
return String.format("%d Byte", bytes);
} else if (bytes < (1000 * 1000)-500) { // 999499 Byte=999 KB, 999500 Byte=1,0 MB
return String.format("%.0f KB", bytes / 1000.0f);
} else {
return String.format("%.1f GB", size / 1024.0f / 1024.0f / 1024.0f);
return String.format("%.1f MB", bytes / 1000.0f / 1000.0f);
}
}
@@ -933,56 +876,186 @@ public class AndroidUtilities {
return true;
}
public static byte[] calcAuthKeyHash(byte[] auth_key) {
byte[] sha1 = Utilities.computeSHA1(auth_key);
byte[] key_hash = new byte[16];
System.arraycopy(sha1, 0, key_hash, 0, 16);
return key_hash;
}
/* open, view, download files
**********************************************************************************************/
public static void openForView(MessageObject message, Activity activity) throws Exception {
File f = null;
String fileName = message.getFileName();
if (message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0) {
f = new File(message.messageOwner.attachPath);
}
if (f == null || !f.exists()) {
f = FileLoader.getPathToMessage(message.messageOwner);
}
if (f != null && f.exists()) {
String realMimeType = null;
Intent intent = new Intent(Intent.ACTION_VIEW);
MimeTypeMap myMime = MimeTypeMap.getSingleton();
public static String getMimetype(String fileName, String def)
{
String mimeType = "application/octet-stream";
try {
MimeTypeMap mimeMap = MimeTypeMap.getSingleton();
int idx = fileName.lastIndexOf('.');
if (idx != -1) {
String ext = fileName.substring(idx + 1);
realMimeType = myMime.getMimeTypeFromExtension(ext.toLowerCase());
if (realMimeType == null) {
if (message.type == 9 || message.type == 0) {
realMimeType = message.getDocument().mime_type;
}
if (realMimeType == null || realMimeType.length() == 0) {
realMimeType = null;
}
}
if (realMimeType != null) {
intent.setDataAndType(Uri.fromFile(f), realMimeType);
} else {
intent.setDataAndType(Uri.fromFile(f), "text/plain");
}
} else {
intent.setDataAndType(Uri.fromFile(f), "text/plain");
mimeType = mimeMap.getMimeTypeFromExtension(ext.toLowerCase());
}
if (realMimeType != null) {
try {
activity.startActivityForResult(intent, 500);
} catch (Exception e) {
intent.setDataAndType(Uri.fromFile(f), "text/plain");
activity.startActivityForResult(intent, 500);
}
} else {
activity.startActivityForResult(intent, 500);
if (mimeType == null) {
mimeType = def==null? "application/octet-stream" : def;
}
}
catch(Exception e) {
}
return mimeType;
}
public static void openForViewOrShare(Activity activity, int msg_id, String cmd)
{
MrMsg msg = MrMailbox.getMsg(msg_id);
String path = msg.getParam('f', "");
String mimeType = getMimetype(path, msg.getParam('m', "application/octet-stream"));
try {
File file = new File(path);
if( !file.exists() ) {
showHint(activity, LocaleController.formatString("FileNotFound", R.string.FileNotFound, path));
return;
}
Uri uri;
if (path.startsWith(MrMailbox.getBlobdir())) {
uri = Uri.parse("content://" + BuildConfig.APPLICATION_ID + ".attachments/" + file.getName());
} else {
uri = Uri.fromFile(file);
}
if( cmd == Intent.ACTION_VIEW ) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, mimeType);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
activity.startActivity(intent);
}
else {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType(mimeType);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
activity.startActivity(Intent.createChooser(intent, ApplicationLoader.applicationContext.getString(R.string.Share)));
}
}
catch (Exception e) {
showHint(activity, LocaleController.formatString("NoHandleAppInstalled", R.string.NoHandleAppInstalled, mimeType));
}
}
private static File getFineFilename(File path, String desiredName)
{
// get a fine file name by adding a number to the basename and avoid overwrites
for( int i = 0; i < 1000; i++ ) {
String testName = desiredName;
if( i > 0 ) {
String baseName=desiredName, ext = "";
int idx = desiredName.lastIndexOf('.');
if( idx != -1 ) {
baseName = desiredName.substring(0, idx);
ext = desiredName.substring(idx);
}
testName = String.format("%s-%d%s", baseName, i, ext);
}
File pathNFile = new File(path, testName);
if (!pathNFile.exists()) {
return pathNFile;
}
}
return null;
}
public static void saveMessageFileToExt(final Activity context, int msg_id)
{
if (Build.VERSION.SDK_INT >= 23 && context.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
context.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 4);
return;
}
MrMsg msg = MrMailbox.getMsg(msg_id);
final int msg_type = msg.getType();
String msg_file_path = msg.getParam('f', "");
final String msg_mime = msg.getParam('m', "application/octet-stream");
final String msg_file_name = msg.getFilename();
final File sourceFile = new File(msg_file_path);
if( !sourceFile.exists() ) {
showHint(context, LocaleController.formatString("FileNotFound", R.string.FileNotFound, msg_file_path));
return;
}
final Toast waitingHint = showHint(context, ApplicationLoader.applicationContext.getString(R.string.OneMoment));
new Thread(new Runnable() {
@Override
public void run() {
boolean allOkay = false;
try {
// get destination path
File destPath = null;
boolean add_to_download_manager = false;
if (msg_type == MrMsg.MR_MSG_IMAGE || msg_type == MrMsg.MR_MSG_VIDEO) {
destPath = AndroidUtilities.getAlbumDir();
} else if (msg_type == MrMsg.MR_MSG_FILE) {
destPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
add_to_download_manager = true;
} else if (msg_type == MrMsg.MR_MSG_AUDIO || msg_type == MrMsg.MR_MSG_VOICE ) {
destPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
}
// create destination path (must be done, see documentation for getExternalStoragePublicDirectory())
destPath.mkdirs();
File destPathNFile = getFineFilename(destPath, msg_file_name);
if( destPathNFile != null )
{
destPathNFile.createNewFile();
boolean copied = true;
FileChannel source = null;
FileChannel destination = null;
try {
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destPathNFile).getChannel();
long size = source.size();
for (long a = 0; a < size; a += 4096) {
destination.transferFrom(source, a, Math.min(4096, size - a));
}
} catch (Exception e) {
copied = false;
} finally {
if (source != null) {
source.close();
}
if (destination != null) {
destination.close();
}
}
if (copied) {
if ( add_to_download_manager ) {
DownloadManager downloadManager = (DownloadManager) ApplicationLoader.applicationContext.getSystemService(Context.DOWNLOAD_SERVICE);
downloadManager.addCompletedDownload(destPathNFile.getName(), destPathNFile.getName(), false, getMimetype(msg_file_name, msg_mime), destPathNFile.getAbsolutePath(), destPathNFile.length(), true);
} else {
addMediaToGallery(Uri.fromFile(destPathNFile));
}
allOkay = true;
}
}
}
catch (Exception e) {
;
}
final boolean allOkayFinal = allOkay;
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
waitingHint.cancel();
if( allOkayFinal ) {
showDoneHint(context);
}
else {
showHint(context, ApplicationLoader.applicationContext.getString(R.string.AccessError));
}
}
});
}
}).start();
}
}
@@ -0,0 +1,85 @@
/*******************************************************************************
*
* Messenger Android Frontend
* (C) 2017 Björn Petersen
* Contact: r10s@b44t.com, http://b44t.com
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/ .
*
******************************************************************************/
package com.b44t.messenger;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import java.io.File;
import java.io.FileNotFoundException;
public class AttachmentsContentProvider extends ContentProvider {
/* We save all attachments in our private files-directory
that cannot be read by other apps.
So starting, when starting an Intent for viewing (eg. openForView()), we cannot use the paths.
Instead, we give a content://-url that results in calls to this class.
(An alternative would be to copy files to view to a public directory, however, this would
lead to duplicate data.
Another alterntive would be to write all attachments to a public directory, however, this
may lead to security problems as files are system-wide-readable and would also cause problems
if the user or another app deletes these files) */
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
File privateFile = new File(MrMailbox.getBlobdir(), uri.getPath());
return ParcelFileDescriptor.open(privateFile, ParcelFileDescriptor.MODE_READ_ONLY);
}
@Override
public int delete(Uri arg0, String arg1, String[] arg2) {
return 0;
}
@Override
public String getType(Uri arg0) {
return null;
}
@Override
public Uri insert(Uri arg0, ContentValues arg1) {
return null;
}
@Override
public boolean onCreate() {
return false;
}
@Override
public Cursor query(Uri arg0, String[] arg1, String arg2, String[] arg3,
String arg4) {
return null;
}
@Override
public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) {
return 0;
}
}
@@ -1,112 +0,0 @@
/*******************************************************************************
*
* Messenger Android Frontend
* (C) 2013-2016 Nikolai Kudashov
* (C) 2017 Björn Petersen
* Contact: r10s@b44t.com, http://b44t.com
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/ .
*
******************************************************************************/
package com.b44t.messenger;
import android.accounts.AbstractAccountAuthenticator;
import android.accounts.Account;
import android.accounts.AccountAuthenticatorResponse;
import android.accounts.AccountManager;
import android.accounts.NetworkErrorException;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
public class AuthenticatorService extends Service {
private static class Authenticator extends AbstractAccountAuthenticator {
private final Context context;
public Authenticator(Context context) {
super(context);
this.context = context;
}
@Override
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options)
throws NetworkErrorException {
return null;
}
@Override
public Bundle getAccountRemovalAllowed(AccountAuthenticatorResponse response, Account account) throws NetworkErrorException {
return super.getAccountRemovalAllowed(response, account);
}
@Override
public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) throws NetworkErrorException {
return null;
}
@Override
public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) {
return null;
}
@Override
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options)
throws NetworkErrorException {
return null;
}
@Override
public String getAuthTokenLabel(String authTokenType) {
return null;
}
@Override
public Bundle hasFeatures(AccountAuthenticatorResponse response,
Account account, String[] features)
throws NetworkErrorException {
return null;
}
@Override
public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options)
throws NetworkErrorException {
return null;
}
}
private static Authenticator authenticator = null;
protected Authenticator getAuthenticator() {
if (authenticator == null) {
authenticator = new Authenticator(this);
}
return authenticator;
}
@Override
public IBinder onBind(Intent intent) {
if (intent.getAction().equals(AccountManager.ACTION_AUTHENTICATOR_INTENT)) {
return getAuthenticator().getIBinder();
} else {
return null;
}
}
}
@@ -47,7 +47,7 @@ public class AutoMessageReplyReceiver extends BroadcastReceiver {
if (dialog_id == 0 || max_id == 0) {
return;
}
SendMessagesHelper.getInstance().sendMessageText(text.toString(), dialog_id, null, null);
SendMessagesHelper.getInstance().sendMessageText(text.toString(), dialog_id, null);
MrMailbox.markseenChat((int)dialog_id);
NotificationsController.getInstance().removeSeenMessages();
}
@@ -117,6 +117,7 @@ public class ConnectionsManager {
return lastClassGuid++;
}
/* -- leave this for future use
public static boolean isRoaming() {
try {
ConnectivityManager cm = (ConnectivityManager) ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
@@ -128,8 +129,9 @@ public class ConnectionsManager {
FileLog.e("messenger", e);
}
return false;
}
} */
/* -- leave this for future use
public static boolean isConnectedToWiFi() {
try {
ConnectivityManager cm = (ConnectivityManager) ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
@@ -141,7 +143,7 @@ public class ConnectionsManager {
FileLog.e("messenger", e);
}
return false;
}
} */
public static boolean isNetworkOnline() {
try {
@@ -1,78 +0,0 @@
/*******************************************************************************
*
* Messenger Android Frontend
* (C) 2013-2016 Nikolai Kudashov
* (C) 2017 Björn Petersen
* Contact: r10s@b44t.com, http://b44t.com
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/ .
*
******************************************************************************/
package com.b44t.messenger;
import android.accounts.Account;
import android.accounts.OperationCanceledException;
import android.app.Service;
import android.content.AbstractThreadedSyncAdapter;
import android.content.ContentProviderClient;
import android.content.Context;
import android.content.Intent;
import android.content.SyncResult;
import android.os.Bundle;
import android.os.IBinder;
public class ContactsSyncAdapterService extends Service {
private static SyncAdapterImpl sSyncAdapter = null;
public ContactsSyncAdapterService() {
super();
}
private static class SyncAdapterImpl extends AbstractThreadedSyncAdapter {
private Context mContext;
public SyncAdapterImpl(Context context) {
super(context, true);
mContext = context;
}
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
try {
ContactsSyncAdapterService.performSync(mContext, account, extras, authority, provider, syncResult);
} catch (OperationCanceledException e) {
FileLog.e("messenger", e);
}
}
}
@Override
public IBinder onBind(Intent intent) {
return getSyncAdapter().getSyncAdapterBinder();
}
private SyncAdapterImpl getSyncAdapter() {
if (sSyncAdapter == null) {
sSyncAdapter = new SyncAdapterImpl(this);
}
return sSyncAdapter;
}
private static void performSync(Context context, Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult)
throws OperationCanceledException {
FileLog.d("messenger", "performSync: " + account.toString());
}
}
@@ -1,30 +0,0 @@
/*******************************************************************************
*
* Messenger Android Frontend
* (C) 2013-2016 Nikolai Kudashov
* (C) 2017 Björn Petersen
* Contact: r10s@b44t.com, http://b44t.com
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/ .
*
******************************************************************************/
package com.b44t.messenger;
public class DownloadObject {
public TLObject object;
public int type;
public long id;
}
@@ -33,11 +33,6 @@ import java.util.concurrent.Semaphore;
public class FileLoader {
public interface FileLoaderDelegate {
void fileUploadProgressChanged(String location, float progress, boolean isEncrypted);
void fileDidUploaded(String location, TLRPC.InputFile inputFile, TLRPC.InputEncryptedFile inputEncryptedFile, byte[] key, byte[] iv, long totalFileSize);
void fileDidFailedUpload(String location, boolean isEncrypted);
void fileDidLoaded(String location, File finalFile, int type);
@@ -55,23 +50,16 @@ public class FileLoader {
private HashMap<Integer, File> mediaDirs = null;
private volatile DispatchQueue fileLoaderQueue = new DispatchQueue("fileUploadQueue");
private LinkedList<FileUploadOperation> uploadOperationQueue = new LinkedList<>();
private LinkedList<FileUploadOperation> uploadSmallOperationQueue = new LinkedList<>();
private LinkedList<FileLoadOperation> loadOperationQueue = new LinkedList<>();
private LinkedList<FileLoadOperation> audioLoadOperationQueue = new LinkedList<>();
private LinkedList<FileLoadOperation> photoLoadOperationQueue = new LinkedList<>();
private ConcurrentHashMap<String, FileUploadOperation> uploadOperationPaths = new ConcurrentHashMap<>();
private ConcurrentHashMap<String, FileUploadOperation> uploadOperationPathsEnc = new ConcurrentHashMap<>();
private ConcurrentHashMap<String, FileLoadOperation> loadOperationPaths = new ConcurrentHashMap<>();
private HashMap<String, Long> uploadSizes = new HashMap<>();
private FileLoaderDelegate delegate = null;
private int currentLoadOperationsCount = 0;
private int currentAudioLoadOperationsCount = 0;
private int currentPhotoLoadOperationsCount = 0;
private int currentUploadOperationsCount = 0;
private int currentUploadSmallOperationsCount = 0;
private static volatile FileLoader Instance = null;
@@ -92,12 +80,6 @@ public class FileLoader {
mediaDirs = dirs;
}
/*
public File checkDirectory(int type) {
return mediaDirs.get(type);
}
*/
public File getDirectory(int type) { // always returns the cache directory as this is the only one set in mediaDirs[] - we do not use the other directories at the moment
File dir = mediaDirs.get(type);
if (dir == null && type != MEDIA_DIR_CACHE) {
@@ -113,160 +95,6 @@ public class FileLoader {
return dir;
}
/*
public void checkUploadNewDataAvailable(final String location, final boolean encrypted, final long finalSize) {
fileLoaderQueue.postRunnable(new Runnable() {
@Override
public void run() {
FileUploadOperation operation;
if (encrypted) {
operation = uploadOperationPathsEnc.get(location);
} else {
operation = uploadOperationPaths.get(location);
}
if (operation != null) {
operation.checkNewDataAvailable(finalSize);
} else if (finalSize != 0) {
uploadSizes.put(location, finalSize);
}
}
});
}
*/
public void uploadFile(final String location, final boolean encrypted, final boolean small) {
uploadFile(location, encrypted, small, 0);
}
public void uploadFile(final String location, final boolean encrypted, final boolean small, final int estimatedSize) {
if (location == null) {
return;
}
fileLoaderQueue.postRunnable(new Runnable() {
@Override
public void run() {
if (encrypted) {
if (uploadOperationPathsEnc.containsKey(location)) {
return;
}
} else {
if (uploadOperationPaths.containsKey(location)) {
return;
}
}
int esimated = estimatedSize;
if (esimated != 0) {
Long finalSize = uploadSizes.get(location);
if (finalSize != null) {
esimated = 0;
uploadSizes.remove(location);
}
}
FileUploadOperation operation = new FileUploadOperation(location, encrypted, esimated);
if (encrypted) {
uploadOperationPathsEnc.put(location, operation);
} else {
uploadOperationPaths.put(location, operation);
}
operation.delegate = new FileUploadOperation.FileUploadOperationDelegate() {
@Override
public void didFinishUploadingFile(final FileUploadOperation operation, final TLRPC.InputFile inputFile, final TLRPC.InputEncryptedFile inputEncryptedFile, final byte[] key, final byte[] iv) {
fileLoaderQueue.postRunnable(new Runnable() {
@Override
public void run() {
if (encrypted) {
uploadOperationPathsEnc.remove(location);
} else {
uploadOperationPaths.remove(location);
}
if (small) {
currentUploadSmallOperationsCount--;
if (currentUploadSmallOperationsCount < 1) {
FileUploadOperation operation = uploadSmallOperationQueue.poll();
if (operation != null) {
currentUploadSmallOperationsCount++;
operation.start();
}
}
} else {
currentUploadOperationsCount--;
if (currentUploadOperationsCount < 1) {
FileUploadOperation operation = uploadOperationQueue.poll();
if (operation != null) {
currentUploadOperationsCount++;
operation.start();
}
}
}
if (delegate != null) {
delegate.fileDidUploaded(location, inputFile, inputEncryptedFile, key, iv, operation.getTotalFileSize());
}
}
});
}
@Override
public void didFailedUploadingFile(final FileUploadOperation operation) {
fileLoaderQueue.postRunnable(new Runnable() {
@Override
public void run() {
if (encrypted) {
uploadOperationPathsEnc.remove(location);
} else {
uploadOperationPaths.remove(location);
}
if (delegate != null) {
delegate.fileDidFailedUpload(location, encrypted);
}
if (small) {
currentUploadSmallOperationsCount--;
if (currentUploadSmallOperationsCount < 1) {
FileUploadOperation operation = uploadSmallOperationQueue.poll();
if (operation != null) {
currentUploadSmallOperationsCount++;
operation.start();
}
}
} else {
currentUploadOperationsCount--;
if (currentUploadOperationsCount < 1) {
FileUploadOperation operation = uploadOperationQueue.poll();
if (operation != null) {
currentUploadOperationsCount++;
operation.start();
}
}
}
}
});
}
@Override
public void didChangedUploadProgress(FileUploadOperation operation, final float progress) {
if (delegate != null) {
delegate.fileUploadProgressChanged(location, progress, encrypted);
}
}
};
if (small) {
if (currentUploadSmallOperationsCount < 1) {
currentUploadSmallOperationsCount++;
operation.start();
} else {
uploadSmallOperationQueue.add(operation);
}
} else {
if (currentUploadOperationsCount < 1) {
currentUploadOperationsCount++;
operation.start();
} else {
uploadOperationQueue.add(operation);
}
}
}
});
}
public void cancelLoadFile(TLRPC.Document document) {
cancelLoadFile(document, null, null);
}
@@ -1,94 +0,0 @@
/*******************************************************************************
*
* Messenger Android Frontend
* (C) 2013-2016 Nikolai Kudashov
* (C) 2017 Björn Petersen
* Contact: r10s@b44t.com, http://b44t.com
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/ .
*
******************************************************************************/
package com.b44t.messenger;
import java.io.FileInputStream;
public class FileUploadOperation {
public int state = 0;
public FileUploadOperationDelegate delegate;
private int requestToken = 0;
private long totalFileSize = 0;
private boolean isEncrypted = false;
private int estimatedSize = 0;
private FileInputStream stream;
public interface FileUploadOperationDelegate {
void didFinishUploadingFile(FileUploadOperation operation, TLRPC.InputFile inputFile, TLRPC.InputEncryptedFile inputEncryptedFile, byte[] key, byte[] iv);
void didFailedUploadingFile(FileUploadOperation operation);
void didChangedUploadProgress(FileUploadOperation operation, float progress);
}
public FileUploadOperation(String location, boolean encrypted, int estimated) {
isEncrypted = encrypted;
estimatedSize = estimated;
}
public long getTotalFileSize() {
return totalFileSize;
}
public void start() {
}
public void cancel() {
if (state == 3) {
return;
}
state = 2;
if (requestToken != 0) {
ConnectionsManager.getInstance().cancelRequest(requestToken, true);
}
delegate.didFailedUploadingFile(this);
cleanup();
}
private void cleanup() {
}
/*
protected void checkNewDataAvailable(final long finalSize) {
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
if (estimatedSize != 0 && finalSize != 0) {
estimatedSize = 0;
totalFileSize = finalSize;
totalPartsCount = (int) (totalFileSize + uploadChunkSize - 1) / uploadChunkSize;
if (started) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("uploadinfo", Activity.MODE_PRIVATE);
storeFileUploadInfo(preferences);
}
}
if (requestToken == 0) {
startUploadRequest();
}
}
});
}
*/
}
@@ -37,7 +37,6 @@ import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;
import com.b44t.ui.Components.AnimatedFileDrawable;
@@ -96,8 +95,6 @@ public class ImageLoader {
private int lastImageNum = 0;
private long lastProgressUpdateTime = 0;
private File messengerPath = null;
private class ThumbGenerateInfo {
private int count;
private TLRPC.FileLocation fileLocation;
@@ -530,16 +527,6 @@ public class ImageLoader {
kf += "@" + filter;
}
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageThumbGenerated, bitmapDrawable, kf);
/*BitmapDrawable old = memCache.get(kf);
if (old != null) {
Bitmap image = old.getBitmap();
if (runtimeHack != null) {
runtimeHack.trackAlloc(image.getRowBytes() * image.getHeight());
}
if (!image.isRecycled()) {
image.recycle();
}
}*/
memCache.put(kf, bitmapDrawable);
}
});
@@ -1120,6 +1107,7 @@ public class ImageLoader {
};
FileLoader.getInstance().setDelegate(new FileLoader.FileLoaderDelegate() {
/*
@Override
public void fileUploadProgressChanged(final String location, final float progress, final boolean isEncrypted) {
fileProgresses.put(location, progress);
@@ -1167,6 +1155,7 @@ public class ImageLoader {
}
});
}
*/
@Override
public void fileDidLoaded(final String location, final File finalFile, final int type) {
@@ -1256,149 +1245,6 @@ public class ImageLoader {
mediaDirs.put(FileLoader.MEDIA_DIR_CACHE, cachePath);
FileLoader.getInstance().setMediaDirs(mediaDirs);
/*
cacheOutQueue.postRunnable(new Runnable() {
@Override
public void run() {
final HashMap<Integer, File> paths = createMediaPaths();
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
FileLoader.getInstance().setMediaDirs(paths);
}
});
}
});
*/
}
/*
public HashMap<Integer, File> createMediaPaths() { // not sure, but it seems as if these paths are not needed
HashMap<Integer, File> mediaDirs = new HashMap<>();
File cachePath = AndroidUtilities.getCacheDir();
if (!cachePath.isDirectory()) {
try {
cachePath.mkdirs();
} catch (Exception e) {
FileLog.e("messenger", e);
}
}
try {
new File(cachePath, ".nomedia").createNewFile();
} catch (Exception e) {
FileLog.e("messenger", e);
}
mediaDirs.put(FileLoader.MEDIA_DIR_CACHE, cachePath);
FileLog.e("messenger", "cache path = " + cachePath);
try {
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
messengerPath = new File(Environment.getExternalStorageDirectory(), "Delta Chat");
messengerPath.mkdirs();
if (messengerPath.isDirectory()) {
try {
File imagePath = new File(messengerPath, "Delta Chat Images");
imagePath.mkdir();
if (imagePath.isDirectory() && canMoveFiles(cachePath, imagePath, FileLoader.MEDIA_DIR_IMAGE)) {
mediaDirs.put(FileLoader.MEDIA_DIR_IMAGE, imagePath);
FileLog.e("messenger", "image path = " + imagePath);
}
} catch (Exception e) {
FileLog.e("messenger", e);
}
try {
File videoPath = new File(messengerPath, "Delta Chat Video");
videoPath.mkdir();
if (videoPath.isDirectory() && canMoveFiles(cachePath, videoPath, FileLoader.MEDIA_DIR_VIDEO)) {
mediaDirs.put(FileLoader.MEDIA_DIR_VIDEO, videoPath);
FileLog.e("messenger", "video path = " + videoPath);
}
} catch (Exception e) {
FileLog.e("messenger", e);
}
try {
File audioPath = new File(messengerPath, "Delta Chat Audio");
audioPath.mkdir();
if (audioPath.isDirectory() && canMoveFiles(cachePath, audioPath, FileLoader.MEDIA_DIR_AUDIO)) {
new File(audioPath, ".nomedia").createNewFile();
mediaDirs.put(FileLoader.MEDIA_DIR_AUDIO, audioPath);
FileLog.e("messenger", "audio path = " + audioPath);
}
} catch (Exception e) {
FileLog.e("messenger", e);
}
try {
File documentPath = new File(messengerPath, "Delta Chat Documents");
documentPath.mkdir();
if (documentPath.isDirectory() && canMoveFiles(cachePath, documentPath, FileLoader.MEDIA_DIR_DOCUMENT)) {
new File(documentPath, ".nomedia").createNewFile();
mediaDirs.put(FileLoader.MEDIA_DIR_DOCUMENT, documentPath);
FileLog.e("messenger", "documents path = " + documentPath);
}
} catch (Exception e) {
FileLog.e("messenger", e);
}
}
} else {
FileLog.e("messenger", "this Android can't rename files");
}
MediaController.getInstance().checkSaveToGalleryFiles();
} catch (Exception e) {
FileLog.e("messenger", e);
}
return mediaDirs;
}
*/
private boolean canMoveFiles(File from, File to, int type) {
RandomAccessFile file = null;
try {
File srcFile = null;
File dstFile = null;
if (type == FileLoader.MEDIA_DIR_IMAGE) {
srcFile = new File(from, "000000000_999999_temp.jpg");
dstFile = new File(to, "000000000_999999.jpg");
} else if (type == FileLoader.MEDIA_DIR_DOCUMENT) {
srcFile = new File(from, "000000000_999999_temp.doc");
dstFile = new File(to, "000000000_999999.doc");
} else if (type == FileLoader.MEDIA_DIR_AUDIO) {
srcFile = new File(from, "000000000_999999_temp.ogg");
dstFile = new File(to, "000000000_999999.ogg");
} else if (type == FileLoader.MEDIA_DIR_VIDEO) {
srcFile = new File(from, "000000000_999999_temp.mp4");
dstFile = new File(to, "000000000_999999.mp4");
}
byte[] buffer = new byte[1024];
srcFile.createNewFile();
file = new RandomAccessFile(srcFile, "rws");
file.write(buffer);
file.close();
file = null;
boolean canRename = srcFile.renameTo(dstFile);
srcFile.delete();
dstFile.delete();
if (canRename) {
return true;
}
} catch (Exception e) {
FileLog.e("messenger", e);
} finally {
try {
if (file != null) {
file.close();
}
} catch (Exception e) {
FileLog.e("messenger", e);
}
}
return false;
}
public Float getFileProgress(String location) {
@@ -1408,21 +1254,6 @@ public class ImageLoader {
return fileProgresses.get(location);
}
private void performReplace(String oldKey, String newKey) {
BitmapDrawable b = memCache.get(oldKey);
if (b != null) {
ignoreRemoval = oldKey;
memCache.remove(oldKey);
memCache.put(newKey, b);
ignoreRemoval = null;
}
Integer val = bitmapUseCounts.get(oldKey);
if (val != null) {
bitmapUseCounts.put(newKey, val);
bitmapUseCounts.remove(oldKey);
}
}
public void incrementUseCount(String key) {
Integer count = bitmapUseCounts.get(key);
if (count == null) {
@@ -1503,65 +1334,6 @@ public class ImageLoader {
});
}
public BitmapDrawable getImageFromMemory(String key) {
return memCache.get(key);
}
public BitmapDrawable getImageFromMemory(TLObject fileLocation, String httpUrl, String filter) {
if (fileLocation == null && httpUrl == null) {
return null;
}
String key = null;
if (httpUrl != null) {
key = Utilities.MD5(httpUrl);
} else {
if (fileLocation instanceof TLRPC.FileLocation) {
TLRPC.FileLocation location = (TLRPC.FileLocation) fileLocation;
key = location.volume_id + "_" + location.local_id;
} else if (fileLocation instanceof TLRPC.Document) {
TLRPC.Document location = (TLRPC.Document) fileLocation;
key = location.dc_id + "_" + location.id;
}
}
if (filter != null) {
key += "@" + filter;
}
return memCache.get(key);
}
private void replaceImageInCacheInternal(final String oldKey, final String newKey, final TLRPC.FileLocation newLocation) {
ArrayList<String> arr = memCache.getFilterKeys(oldKey);
if (arr != null) {
for (int a = 0; a < arr.size(); a++) {
String filter = arr.get(a);
String oldK = oldKey + "@" + filter;
String newK = newKey + "@" + filter;
performReplace(oldK, newK);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.didReplacedPhotoInMemCache, oldK, newK, newLocation);
}
} else {
performReplace(oldKey, newKey);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.didReplacedPhotoInMemCache, oldKey, newKey, newLocation);
}
}
public void replaceImageInCache(final String oldKey, final String newKey, final TLRPC.FileLocation newLocation, boolean post) {
if (post) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
replaceImageInCacheInternal(oldKey, newKey, newLocation);
}
});
} else {
replaceImageInCacheInternal(oldKey, newKey, newLocation);
}
}
public void putImageToCache(BitmapDrawable bitmap, String key) {
memCache.put(key, bitmap);
}
private void generateThumb(int mediaType, File originalPath, TLRPC.FileLocation thumbLocation, String filter) {
if (mediaType != FileLoader.MEDIA_DIR_IMAGE && mediaType != FileLoader.MEDIA_DIR_VIDEO && mediaType != FileLoader.MEDIA_DIR_DOCUMENT || originalPath == null || thumbLocation == null) {
return;
@@ -1619,7 +1391,6 @@ public class ImageLoader {
if (!added) {
boolean onlyCache = false;
boolean isQuality = false;
File cacheFile = null;
if (httpLocation != null) {
@@ -1932,34 +1703,6 @@ public class ImageLoader {
}
}
public void loadHttpFile(String url, String defaultExt) {
if (url == null || url.length() == 0 || httpFileLoadTasksByKeys.containsKey(url)) {
return;
}
String ext = getHttpUrlExtension(url, defaultExt);
File file = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), Utilities.MD5(url) + "_temp." + ext);
file.delete();
HttpFileTask task = new HttpFileTask(url, file, ext);
httpFileLoadTasks.add(task);
httpFileLoadTasksByKeys.put(url, task);
runHttpFileLoadTasks(null, 0);
}
public void cancelLoadHttpFile(String url) {
HttpFileTask task = httpFileLoadTasksByKeys.get(url);
if (task != null) {
task.cancel(true);
httpFileLoadTasksByKeys.remove(url);
httpFileLoadTasks.remove(task);
}
Runnable runnable = retryHttpsTasks.get(url);
if (runnable != null) {
AndroidUtilities.cancelRunOnUIThread(runnable);
}
runHttpFileLoadTasks(null, 0);
}
private void runHttpFileLoadTasks(final HttpFileTask oldTask, final int reason) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
@@ -2005,7 +1748,6 @@ public class ImageLoader {
InputStream inputStream = null;
if (path == null && uri != null && uri.getScheme() != null) {
String imageFilePath = null;
if (uri.getScheme().contains("file")) {
path = uri.getPath();
} else {
@@ -2020,7 +1762,6 @@ public class ImageLoader {
if (path != null) {
BitmapFactory.decodeFile(path, bmOptions);
} else if (uri != null) {
boolean error = false;
try {
inputStream = ApplicationLoader.applicationContext.getContentResolver().openInputStream(uri);
BitmapFactory.decodeStream(inputStream, null, bmOptions);
@@ -2134,7 +1875,7 @@ public class ImageLoader {
return b;
}
private static TLRPC.PhotoSize scaleAndSaveImageInternal(Bitmap bitmap, int w, int h, float photoW, float photoH, float scaleFactor, int quality, boolean cache, boolean scaleAnyway) throws Exception {
private static TLRPC.PhotoSize scaleAndSaveImageInternal(File cacheFile, Bitmap bitmap, int w, int h, float photoW, float photoH, float scaleFactor, int quality, boolean cache, boolean scaleAnyway) throws Exception {
Bitmap scaledBitmap;
if (scaleFactor > 1 || scaleAnyway) {
scaledBitmap = Bitmaps.createScaledBitmap(bitmap, w, h, true);
@@ -2163,8 +1904,11 @@ public class ImageLoader {
size.type = "w";
}
String fileName = location.volume_id + "_" + location.local_id + ".jpg";
final File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
if( cacheFile == null ) {
String fileName = location.volume_id + "_" + location.local_id + ".jpg";
cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
}
FileOutputStream stream = new FileOutputStream(cacheFile);
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream);
if (cache) {
@@ -2185,10 +1929,18 @@ public class ImageLoader {
}
public static TLRPC.PhotoSize scaleAndSaveImage(Bitmap bitmap, float maxWidth, float maxHeight, int quality, boolean cache) {
return scaleAndSaveImage(bitmap, maxWidth, maxHeight, quality, cache, 0, 0);
return scaleAndSaveImage(null, bitmap, maxWidth, maxHeight, quality, cache, 0, 0);
}
public static TLRPC.PhotoSize scaleAndSaveImage(Bitmap bitmap, float maxWidth, float maxHeight, int quality, boolean cache, int minWidth, int minHeight) {
return scaleAndSaveImage(null, bitmap, maxWidth, maxHeight, quality, cache, minWidth, minHeight);
}
public static TLRPC.PhotoSize scaleAndSaveImage(File cacheFile, Bitmap bitmap, float maxWidth, float maxHeight, int quality, boolean cache) {
return scaleAndSaveImage(cacheFile, bitmap, maxWidth, maxHeight, quality, cache, 0, 0);
}
private static TLRPC.PhotoSize scaleAndSaveImage(File cacheFile, Bitmap bitmap, float maxWidth, float maxHeight, int quality, boolean cache, int minWidth, int minHeight) {
if (bitmap == null) {
return null;
}
@@ -2216,13 +1968,13 @@ public class ImageLoader {
}
try {
return scaleAndSaveImageInternal(bitmap, w, h, photoW, photoH, scaleFactor, quality, cache, scaleAnyway);
return scaleAndSaveImageInternal(cacheFile, bitmap, w, h, photoW, photoH, scaleFactor, quality, cache, scaleAnyway);
} catch (Throwable e) {
FileLog.e("messenger", e);
ImageLoader.getInstance().clearMemory();
System.gc();
try {
return scaleAndSaveImageInternal(bitmap, w, h, photoW, photoH, scaleFactor, quality, cache, scaleAnyway);
return scaleAndSaveImageInternal(cacheFile, bitmap, w, h, photoW, photoH, scaleFactor, quality, cache, scaleAnyway);
} catch (Throwable e2) {
FileLog.e("messenger", e2);
return null;
@@ -564,30 +564,6 @@ public class LocaleController {
return "LOC_ERR: formatDateChat";
}
public static String formatDateAudio(long date) {
try {
Calendar rightNow = Calendar.getInstance();
int day = rightNow.get(Calendar.DAY_OF_YEAR);
int year = rightNow.get(Calendar.YEAR);
rightNow.setTimeInMillis(date * 1000);
int dateDay = rightNow.get(Calendar.DAY_OF_YEAR);
int dateYear = rightNow.get(Calendar.YEAR);
if (dateDay == day && year == dateYear) {
return String.format("%s %s", LocaleController.getString("TodayAt", R.string.TodayAt), getInstance().formatterDay.format(new Date(date * 1000)));
} else if (dateDay + 1 == day && year == dateYear) {
return String.format("%s %s", LocaleController.getString("YesterdayAt", R.string.YesterdayAt), getInstance().formatterDay.format(new Date(date * 1000)));
} else if (year == dateYear) {
return LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, getInstance().formatterMonth.format(new Date(date * 1000)), getInstance().formatterDay.format(new Date(date * 1000)));
} else {
return LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, getInstance().formatterYear.format(new Date(date * 1000)), getInstance().formatterDay.format(new Date(date * 1000)));
}
} catch (Exception e) {
FileLog.e("messenger", e);
}
return "LOC_ERR";
}
private FastDateFormat createFormatter(Locale locale, String format, String defaultFormat) {
if (format == null || format.length() == 0) {
format = defaultFormat;
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -26,29 +26,13 @@ package com.b44t.messenger;
import android.app.Activity;
import android.content.SharedPreferences;
import com.b44t.ui.ActionBar.BaseFragment;
import com.b44t.ui.SettingsActivity;
import com.b44t.ui.SettingsAdvActivity;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
public class MessagesController implements NotificationCenter.NotificationCenterDelegate {
public class MessagesController {
public ArrayList<TLRPC.TL_dialog> dialogs = new ArrayList<>();
public int nextDialogsCacheOffset;
public ConcurrentHashMap<Long, TLRPC.TL_dialog> dialogs_dict = new ConcurrentHashMap<>(100, 1.0f, 2);
public HashMap<Long, MessageObject> dialogMessage = new HashMap<>();
public HashMap<Long, MessageObject> dialogMessagesByRandomIds = new HashMap<>();
public HashMap<Integer, MessageObject> dialogMessagesByIds = new HashMap<>();
public HashMap<Long, CharSequence> printingStrings = new HashMap<>();
public int secretWebpagePreview = 2;
private String uploadingAvatar = null;
public int fontSize = AndroidUtilities.dp(16);
public int ratingDecay;
public int fontSize;
public static final int UPDATE_MASK_NAME = 1;
public static final int UPDATE_MASK_AVATAR = 2;
@@ -56,8 +40,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public static final int UPDATE_MASK_CHAT_AVATAR = 8;
public static final int UPDATE_MASK_CHAT_NAME = 16;
public static final int UPDATE_MASK_CHAT_MEMBERS = 32;
public static final int UPDATE_MASK_USER_PRINT = 64;
public static final int UPDATE_MASK_READ_DIALOG_MESSAGE = 256;
public static final int UPDATE_MASK_SELECT_DIALOG = 512;
public static final int UPDATE_MASK_NEW_MESSAGE = 2048;
public static final int UPDATE_MASK_SEND_STATE = 4096;
@@ -79,91 +61,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public MessagesController() {
ImageLoader.getInstance();
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidUpload);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailUpload);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidLoaded);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailedLoad);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
secretWebpagePreview = preferences.getInt("secretWebpage2", 2);
ratingDecay = preferences.getInt("ratingDecay", 2419200);
fontSize = preferences.getInt("msg_font_size", SettingsActivity.defMsgFontSize());
}
public static TLRPC.Peer getPeer(int id) {
TLRPC.Peer inputPeer;
/*if (id < 0) {
inputPeer = new TLRPC.TL_peerChat();
inputPeer.chat_id = -id;
} else*/ {
inputPeer = new TLRPC.TL_peerUser();
inputPeer.user_id = id;
}
return inputPeer;
}
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.FileDidUpload) {
final String location = (String) args[0];
final TLRPC.InputFile file = (TLRPC.InputFile) args[1];
if (uploadingAvatar != null && uploadingAvatar.equals(location)) {
/*TLRPC.TL_photos_uploadProfilePhoto req = new TLRPC.TL_photos_uploadProfilePhoto();
req.caption = "";
req.crop = new TLRPC.TL_inputPhotoCropAuto();
req.file = file;
req.geo_point = new TLRPC.TL_inputGeoPointEmpty();*/
/*ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
if (error == null) {
TLRPC.User user = getUser(UserConfig.getClientUserId());
if (user == null) {
user = UserConfig.getCurrentUser();
putUser(user, true);
} else {
UserConfig.setCurrentUser(user);
}
if (user == null) {
return;
}
TLRPC.TL_photos_photo photo = (TLRPC.TL_photos_photo) response;
ArrayList<TLRPC.PhotoSize> sizes = photo.photo.sizes;
TLRPC.PhotoSize smallSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 100);
TLRPC.PhotoSize bigSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 1000);
user.photo = new TLRPC.TL_userProfilePhoto();
user.photo.photo_id = photo.photo.id;
if (smallSize != null) {
user.photo.photo_small = smallSize.location;
}
if (bigSize != null) {
user.photo.photo_big = bigSize.location;
} else if (smallSize != null) {
user.photo.photo_small = smallSize.location;
}
//MessagesStorage.getInstance().clearUserPhotos(user.id);
ArrayList<TLRPC.User> users = new ArrayList<>();
users.add(user);
//MessagesStorage.getInstance().putUsersAndChats(users, null, false, true);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, UPDATE_MASK_AVATAR);
UserConfig.saveConfig(true);
}
});
}
}
});*/
}
} else if (id == NotificationCenter.FileDidFailUpload) {
final String location = (String) args[0];
if (uploadingAvatar != null && uploadingAvatar.equals(location)) {
uploadingAvatar = null;
}
}
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
fontSize = preferences.getInt("msg_font_size", SettingsAdvActivity.defMsgFontSize());
}
public TLRPC.User getUser(Integer id) {
@@ -173,14 +73,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
return u;
}
public TLRPC.Chat getChat(Integer id) {
return null;
}
public void deleteMessages(ArrayList<Integer> messages, ArrayList<Long> randoms, Object encryptedChat, final int channelId) {
}
public MediaController.SearchImage saveGif(TLRPC.Document document) {
MediaController.SearchImage searchImage = new MediaController.SearchImage();
searchImage.type = 2;
@@ -214,9 +106,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void markMessageContentAsRead(final MessageObject messageObject) {
}
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 changeChatAvatar(int chat_id, TLRPC.InputFile uploadedAvatar) {
/*TLObject request;
{
@@ -255,89 +144,4 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
return false;
}
protected void updateInterfaceWithMessages(long uid, ArrayList<MessageObject> messages) {
updateInterfaceWithMessages(uid, messages, false);
}
protected static void addNewGifToRecent(TLRPC.Document document, int date) {
ArrayList<MediaController.SearchImage> arrayList = new ArrayList<>();
MediaController.SearchImage searchImage = new MediaController.SearchImage();
searchImage.type = 2;
searchImage.document = document;
searchImage.date = date;
searchImage.id = "" + searchImage.document.id;
arrayList.add(searchImage);
}
protected void updateInterfaceWithMessages(final long uid, final ArrayList<MessageObject> messages, boolean isBroadcast) {
if (messages == null || messages.isEmpty()) {
return;
}
final boolean isEncryptedChat = false;
MessageObject lastMessage = null;
int channelId = 0;
for (int a = 0; a < messages.size(); a++) {
MessageObject message = messages.get(a);
if (lastMessage == null || (!isEncryptedChat && message.getId() > lastMessage.getId() || (isEncryptedChat || message.getId() < 0 && lastMessage.getId() < 0) && message.getId() < lastMessage.getId()) || message.messageOwner.date > lastMessage.messageOwner.date) {
lastMessage = message;
}
if (message.isOut() && message.isNewGif() && !message.isSending() && !message.isForwarded()) {
addNewGifToRecent(message.messageOwner.media.document, message.messageOwner.date);
}
}
//MessagesQuery.loadReplyMessagesForMessages(messages, uid);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.didReceivedNewMessages, uid, messages);
if (lastMessage == null) {
return;
}
TLRPC.TL_dialog dialog = dialogs_dict.get(uid);
if (dialog == null) {
if (!isBroadcast) {
TLRPC.Chat chat = getChat(channelId);
if (channelId != 0 && chat == null || chat != null && false/*chat.left*/) {
return;
}
dialog = new TLRPC.TL_dialog();
dialog.id = uid;
dialog.unread_count = 0;
dialog.top_message = lastMessage.getId();
dialog.last_message_date = lastMessage.messageOwner.date;
//dialog.flags = ChatObject.isChannel(chat) ? 1 : 0;
dialogs_dict.put(uid, dialog);
dialogs.add(dialog);
dialogMessage.put(uid, lastMessage);
if (lastMessage.messageOwner.to_id.channel_id == 0) {
dialogMessagesByIds.put(lastMessage.getId(), lastMessage);
if (lastMessage.messageOwner.random_id != 0) {
dialogMessagesByRandomIds.put(lastMessage.messageOwner.random_id, lastMessage);
}
}
nextDialogsCacheOffset++;
}
} else {
if ((dialog.top_message > 0 && lastMessage.getId() > 0 && lastMessage.getId() > dialog.top_message) ||
(dialog.top_message < 0 && lastMessage.getId() < 0 && lastMessage.getId() < dialog.top_message) ||
!dialogMessage.containsKey(uid) || dialog.top_message < 0 || dialog.last_message_date <= lastMessage.messageOwner.date) {
MessageObject object = dialogMessagesByIds.remove(dialog.top_message);
if (object != null && object.messageOwner.random_id != 0) {
dialogMessagesByRandomIds.remove(object.messageOwner.random_id);
}
dialog.top_message = lastMessage.getId();
if (!isBroadcast) {
dialog.last_message_date = lastMessage.messageOwner.date;
}
dialogMessage.put(uid, lastMessage);
if (lastMessage.messageOwner.to_id.channel_id == 0) {
dialogMessagesByIds.put(lastMessage.getId(), lastMessage);
if (lastMessage.messageOwner.random_id != 0) {
dialogMessagesByRandomIds.put(lastMessage.messageOwner.random_id, lastMessage);
}
}
}
}
}
}
@@ -76,13 +76,9 @@ public class MrChat {
return MrChatGetTotalMsgCount(m_hChat);
}
public int sendText(String text) {
return MrChatSendText(m_hChat, text);
}
public native int sendText(String text);
public int sendMedia(int type, String file, String mime, int w, int h, int time_ms) {
return MrChatSendMedia(m_hChat, type, file, mime, w, h, time_ms);
}
public native int sendMedia(int type, String file, String mime, int w, int h, int time_ms, String author, String trackname);
private long m_hChat; // must not be renamed as referenced by JNI under the name "m_hChat"
private native static void MrChatUnref (long hChat);
@@ -92,8 +88,6 @@ public class MrChat {
private native static int MrChatSetDraft (long hChat, String draft/*NULL=delete*/, long replyToMsgId);
private native static int MrChatGetUnseenCount (long hChat);
private native static int MrChatGetTotalMsgCount (long hChat);
private native static int MrChatSendText (long hChat, String text); // returns message id
private native static int MrChatSendMedia (long hChat, int type, String file, String mime, int w, int h, int time_ms);
/* additional functions that are not 1:1 available in the backend
@@ -139,6 +139,7 @@ public class MrMailbox {
}
public native static int createGroupChat (String name);
public native static int isContactInChat (int chat_id, int contact_id);
public native static int addContactToChat (int chat_id, int contact_id);
public native static int removeContactFromChat (int chat_id, int contact_id);
public native static int setChatName (int chat_id, String name);
@@ -150,10 +151,8 @@ public class MrMailbox {
public native static int[] getUnseenMsgs();
public static int[] getChatMedia(int chat_id, int msg_type, int or_msg_type) {
return MrMailboxGetChatMedia(m_hMailbox, chat_id, msg_type, or_msg_type);
}
public native static int[] getChatMedia(int chat_id, int msg_type, int or_msg_type);
public native static int getNextMedia(int msg_id, int dir);
public native static int[] getChatContacts(int chat_id);
public native static int deleteChat(int chat_id);
@@ -161,7 +160,6 @@ public class MrMailbox {
private native static long MrMailboxGetChat (long hMailbox, int chat_id); // return hChat which must be unref'd after usage
private native static int MrMailboxGetChatIdByContactId (long hMailbox, int contact_id);
private native static int MrMailboxCreateChatByContactId(long hMailbox, int contact_id); // returns chat_id
private native static int[] MrMailboxGetChatMedia (long hMailbox, int chat_id, int msg_type, int or_msg_type);
// msgs
@@ -276,21 +274,22 @@ public class MrMailbox {
case MR_EVENT_GET_STRING:
String s = "ErrStrBadId";
switch( (int)data1 ) {
case 1: s = LocaleController.getString("NoMessages", R.string.NoMessages); break;
case 2: s = LocaleController.getString("FromSelf", R.string.FromSelf); break;
case 3: s = LocaleController.getString("Draft", R.string.Draft); break;
case 8: s = LocaleController.getString("Deaddrop", R.string.Deaddrop); break;
case 9: s = LocaleController.getString("AttachPhoto", R.string.AttachPhoto); break;
case 10: s = LocaleController.getString("AttachVideo", R.string.AttachVideo); break;
case 11: s = LocaleController.getString("AttachAudio", R.string.AttachAudio); break;
case 12: s = LocaleController.getString("AttachDocument", R.string.AttachDocument); break;
case 13: s = LocaleController.getString("DefaultStatusText", R.string.DefaultStatusText); break;
case 14: s = LocaleController.getString("MsgNewGroupDraft", R.string.MsgNewGroupDraft); break;
case 15: s = LocaleController.getString("MsgGroupNameChanged", R.string.MsgGroupNameChanged); break;
case 16: s = LocaleController.getString("MsgGroupImageChanged", R.string.MsgGroupImageChanged); break;
case 17: s = LocaleController.getString("MsgMemberAddedToGroup", R.string.MsgMemberAddedToGroup); break;
case 18: s = LocaleController.getString("MsgMemberRemovedFromToGroup", R.string.MsgMemberRemovedFromToGroup); break;
case 19: s = LocaleController.getString("MsgGroupLeft", R.string.MsgGroupLeft); break;
case 1: s = ApplicationLoader.applicationContext.getString(R.string.NoMessages); break;
case 2: s = ApplicationLoader.applicationContext.getString(R.string.FromSelf); break;
case 3: s = ApplicationLoader.applicationContext.getString(R.string.Draft); break;
case 7: s = ApplicationLoader.applicationContext.getString(R.string.AttachVoiceMessage); break;
case 8: s = ApplicationLoader.applicationContext.getString(R.string.Deaddrop); break;
case 9: s = ApplicationLoader.applicationContext.getString(R.string.AttachPhoto); break;
case 10: s = ApplicationLoader.applicationContext.getString(R.string.AttachVideo); break;
case 11: s = ApplicationLoader.applicationContext.getString(R.string.AttachMusic); break;
case 12: s = ApplicationLoader.applicationContext.getString(R.string.AttachDocument); break;
case 13: s = ApplicationLoader.applicationContext.getString(R.string.DefaultStatusText); break;
case 14: s = ApplicationLoader.applicationContext.getString(R.string.MsgNewGroupDraft); break;
case 15: s = ApplicationLoader.applicationContext.getString(R.string.MsgGroupNameChanged); break;
case 16: s = ApplicationLoader.applicationContext.getString(R.string.MsgGroupImageChanged); break;
case 17: s = ApplicationLoader.applicationContext.getString(R.string.MsgMemberAddedToGroup); break;
case 18: s = ApplicationLoader.applicationContext.getString(R.string.MsgMemberRemovedFromToGroup); break;
case 19: s = ApplicationLoader.applicationContext.getString(R.string.MsgGroupLeft); break;
}
return String2CPtr(s);
@@ -27,8 +27,13 @@
package com.b44t.messenger;
import android.graphics.Bitmap;
import android.media.ThumbnailUtils;
import android.provider.MediaStore;
import android.util.Log;
import java.io.File;
public class MrMsg {
private static final String TAG = "MrMsg";
@@ -37,6 +42,7 @@ public class MrMsg {
public final static int MR_MSG_TEXT = 10;
public final static int MR_MSG_IMAGE = 20;
public final static int MR_MSG_AUDIO = 40;
public final static int MR_MSG_VOICE = 41;
public final static int MR_MSG_VIDEO = 50;
public final static int MR_MSG_FILE = 60;
@@ -90,17 +96,19 @@ public class MrMsg {
return MrMsgGetToId(m_hMsg);
}
public String getParam (int key, String def) {
return MrMsgGetParam(m_hMsg, key, def);
}
public int getParamInt(int key, int def) {
return MrMsgGetParamInt(m_hMsg, key, def);
}
public native String getParam(int key, String def);
public native int getParamInt(int key, int def);
public native void setParamInt(int key, int def);
public native void saveParamToDisk();
public native int getBytes();
public MrPoortext getSummary(MrChat chat) { return new MrPoortext(getSummaryCPtr(chat.getCPtr())); }
private native long getSummaryCPtr(long hChat);
public native String getSummarytext(int approx_characters);
public MrPoortext getMediainfo() { return new MrPoortext(getMediainfoCPtr()); }
private native long getMediainfoCPtr();
public native String getFilename();
public native int isIncreation();
private long m_hMsg; // must not be renamed as referenced by JNI under the name "m_hMsg"
private native static void MrMsgUnref (long hMsg);
@@ -112,8 +120,6 @@ public class MrMsg {
private native static int MrMsgGetChatId (long hMsg);
private native static int MrMsgGetFromId (long hMsg);
private native static int MrMsgGetToId (long hMsg);
private native static String MrMsgGetParam (long hMsg, int key, String def);
private native static int MrMsgGetParamInt (long hMsg, int key, int def);
/* additional functions that are not 1:1 available in the backend
@@ -143,7 +149,6 @@ public class MrMsg {
ret.unread = state!=MR_OUT_READ; // the state of outgoing messages
ret.media_unread = ret.unread;
ret.flags = 0; // posible flags: MESSAGE_FLAG_HAS_FROM_ID, however, this seems to be read only
ret.post = false; // ? true=avatar wird in gruppen nicht angezeigt, wird aber in isFromUser() auch überprüft...
ret.out = ret.from_id==MrContact.MR_CONTACT_ID_SELF; // true=outgoing message, read eg. in MessageObject.isOutOwner()
ret.created_by_mr = true;
@@ -190,31 +195,60 @@ public class MrMsg {
ret.message = "<cannot load image>";
}
}
else if( type == MR_MSG_AUDIO || type == MR_MSG_VIDEO ) {
else if( type == MR_MSG_AUDIO || type == MR_MSG_VOICE || type == MR_MSG_VIDEO || type == MR_MSG_FILE ) {
String path = getParam('f', "");
if( !path.isEmpty()) {
ret.message = "-1"; // may be misused for video editing information
ret.media = new TLRPC.TL_messageMediaDocument();
ret.media.caption = "";
ret.media.document = new TLRPC.TL_document();
ret.media.document.file_name = getFilename();
ret.media.document.mr_path = path;
if( type == MR_MSG_AUDIO ) {
ret.media.document.size = getBytes();
if( type == MR_MSG_AUDIO || type == MR_MSG_VOICE ) {
TLRPC.TL_documentAttributeAudio attr = new TLRPC.TL_documentAttributeAudio();
attr.voice = true; // !voice = music
attr.voice = type == MR_MSG_VOICE;
attr.duration = getParamInt('d', 0) / 1000;
ret.media.document.attributes.add(attr);
}
else if( type == MR_MSG_VIDEO) {
else if( type == MR_MSG_VIDEO ) {
File vfile = new File(path);
File tfile = new File(MrMailbox.getBlobdir(), vfile.getName()+"-preview.jpg");
if( !tfile.exists() ) {
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(path, MediaStore.Video.Thumbnails.MINI_KIND);
TLRPC.PhotoSize size = ImageLoader.scaleAndSaveImage(tfile, thumb, 90, 90, 55, false);
size.location.mr_path = tfile.getAbsolutePath();
size.type = "s";
ret.media.document.thumb = size;
setParamInt('w', size.w);
setParamInt('h', size.h);
saveParamToDisk();
}
else {
TLRPC.PhotoSize size = new TLRPC.PhotoSize();
size.location = new TLRPC.TL_fileLocation();
size.location.mr_path = tfile.getAbsolutePath();
size.location.local_id = -ret.id;
size.w = getParamInt('w', 320);
size.h = getParamInt('h', 240);
size.type = "s";
ret.media.document.thumb = size;
}
TLRPC.TL_documentAttributeVideo attr = new TLRPC.TL_documentAttributeVideo();
attr.duration = getParamInt('d', 0) / 1000;
attr.w = getParamInt('w', 0);
attr.h = getParamInt('h', 0);
attr.w = ret.media.document.thumb.w;
attr.h = ret.media.document.thumb.h;
ret.media.document.attributes.add(attr);
}
else {
ret.media.document.mime_type = getParam('m', "application/octet-stream");
}
}
else {
ret.message = "<path missing>";
ret.message = "<file path missing>";
}
}
else {
@@ -30,10 +30,10 @@ package com.b44t.messenger;
public class MrPoortext {
public final static int MR_TITLE_NORMAL = 0;
public final static int MR_TITLE_DRAFT = 1;
public final static int MR_TITLE_USERNAME = 2;
public final static int MR_TITLE_SELF = 3;
public final static int MR_TEXT1_NORMAL = 0;
public final static int MR_TEXT1_DRAFT = 1;
public final static int MR_TEXT1_USERNAME = 2;
public final static int MR_TEXT1_SELF = 3;
public MrPoortext(long hPoortext) {
m_hPoortext = hPoortext;
@@ -44,16 +44,16 @@ public class MrPoortext {
MrPoortextUnref(m_hPoortext);
}
public String getTitle() {
return MrPoortextGetTitle(m_hPoortext);
public String getText1() {
return MrPoortextGetText1(m_hPoortext);
}
public int getTitleMeaning() {
return MrPoortextGetTitleMeaning(m_hPoortext);
public int getText1Meaning() {
return MrPoortextGetText1Meaning(m_hPoortext);
}
public String getText() {
return MrPoortextGetText(m_hPoortext);
public String getText2() {
return MrPoortextGetText2(m_hPoortext);
}
public long getTimestamp() {
@@ -66,9 +66,9 @@ public class MrPoortext {
private long m_hPoortext;
private native static void MrPoortextUnref (long hPoortext);
private native static String MrPoortextGetTitle (long hPoortext);
private native static int MrPoortextGetTitleMeaning (long hPoortext);
private native static String MrPoortextGetText (long hPoortext);
private native static String MrPoortextGetText1 (long hPoortext);
private native static int MrPoortextGetText1Meaning (long hPoortext);
private native static String MrPoortextGetText2 (long hPoortext);
private native static long MrPoortextGetTimestamp (long hPoortext);
private native static int MrPoortextGetState (long hPoortext);
}
@@ -1,604 +0,0 @@
/*******************************************************************************
*
* Messenger Android Frontend
* (C) 2013-2016 Nikolai Kudashov
* (C) 2017 Björn Petersen
* Contact: r10s@b44t.com, http://b44t.com
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/ .
*
******************************************************************************/
package com.b44t.messenger;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
import android.media.MediaDescription;
import android.media.MediaMetadata;
import android.media.browse.MediaBrowser;
import android.media.session.MediaSession;
import android.media.session.PlaybackState;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Process;
import android.os.SystemClock;
import android.service.media.MediaBrowserService;
import com.b44t.messenger.audioinfo.AudioInfo;
import com.b44t.ui.LaunchActivity;
import java.io.File;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class MusicBrowserService extends MediaBrowserService implements NotificationCenter.NotificationCenterDelegate {
private static final String AUTO_APP_PACKAGE_NAME = "com.google.android.projection.gearhead";
private static final String SLOT_RESERVATION_SKIP_TO_NEXT = "com.google.android.gms.car.media.ALWAYS_RESERVE_SPACE_FOR.ACTION_SKIP_TO_NEXT";
private static final String SLOT_RESERVATION_SKIP_TO_PREV = "com.google.android.gms.car.media.ALWAYS_RESERVE_SPACE_FOR.ACTION_SKIP_TO_PREVIOUS";
private static final String SLOT_RESERVATION_QUEUE = "com.google.android.gms.car.media.ALWAYS_RESERVE_SPACE_FOR.ACTION_QUEUE";
private MediaSession mediaSession;
private static final String MEDIA_ID_ROOT = "__ROOT__";
private boolean chatsLoaded;
private boolean loadingChats;
private ArrayList<Integer> dialogs = new ArrayList<>();
private HashMap<Integer, TLRPC.User> users = new HashMap<>();
private HashMap<Integer, TLRPC.Chat> chats = new HashMap<>();
private HashMap<Integer, ArrayList<MessageObject>> musicObjects = new HashMap<>();
private HashMap<Integer, ArrayList<MediaSession.QueueItem>> musicQueues = new HashMap<>();
public static final String ACTION_CMD = "com.example.android.mediabrowserservice.ACTION_CMD";
public static final String CMD_NAME = "CMD_NAME";
public static final String CMD_PAUSE = "CMD_PAUSE";
private Paint roundPaint;
private RectF bitmapRect;
private boolean serviceStarted;
private int lastSelectedDialog;
private static final int STOP_DELAY = 30000;
private DelayedStopHandler delayedStopHandler = new DelayedStopHandler(this);
@Override
public void onCreate() {
super.onCreate();
ApplicationLoader.postInitApplication();
lastSelectedDialog = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE).getInt("auto_lastSelectedDialog", 0);
mediaSession = new MediaSession(this, "MusicService");
setSessionToken(mediaSession.getSessionToken());
mediaSession.setCallback(new MediaSessionCallback());
mediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
Context context = getApplicationContext();
Intent intent = new Intent(context, LaunchActivity.class);
PendingIntent pi = PendingIntent.getActivity(context, 99, intent, PendingIntent.FLAG_UPDATE_CURRENT);
mediaSession.setSessionActivity(pi);
Bundle extras = new Bundle();
extras.putBoolean(SLOT_RESERVATION_QUEUE, true);
extras.putBoolean(SLOT_RESERVATION_SKIP_TO_PREV, true);
extras.putBoolean(SLOT_RESERVATION_SKIP_TO_NEXT, true);
mediaSession.setExtras(extras);
updatePlaybackState(null);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioPlayStateChanged);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidStarted);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidReset);
}
@Override
public int onStartCommand(Intent startIntent, int flags, int startId) {
/*if (startIntent != null) {
String action = startIntent.getAction();
String command = startIntent.getStringExtra(CMD_NAME);
if (ACTION_CMD.equals(action)) {
if (CMD_PAUSE.equals(command)) {
if (mPlayback != null && mPlayback.isPlaying()) {
handlePauseRequest();
}
}
}
}*/
return START_STICKY;
}
@Override
public void onDestroy() {
handleStopRequest(null);
delayedStopHandler.removeCallbacksAndMessages(null);
mediaSession.release();
}
@Override
public BrowserRoot onGetRoot(String clientPackageName, int clientUid, Bundle rootHints) {
if (clientPackageName == null || Process.SYSTEM_UID != clientUid && Process.myUid() != clientUid && !clientPackageName.equals("com.google.android.mediasimulator") && !clientPackageName.equals("com.google.android.projection.gearhead")) {
return null;
}
return new BrowserRoot(MEDIA_ID_ROOT, null);
}
@Override
public void onLoadChildren(final String parentMediaId, final Result<List<MediaBrowser.MediaItem>> result) {
if (!chatsLoaded) {
result.detach();
if (loadingChats) {
return;
}
loadingChats = true;
/*
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
try {
ArrayList<Integer> usersToLoad = new ArrayList<>();
ArrayList<Integer> chatsToLoad = new ArrayList<>();
SQLiteCursor cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT DISTINCT uid FROM media_v2 WHERE uid != 0 AND mid > 0 AND type = %d", SharedMediaQuery.MEDIA_MUSIC));
while (cursor.next()) {
int lower_part = (int) cursor.longValue(0);
if (lower_part == 0) {
continue;
}
dialogs.add(lower_part);
if (lower_part > 0) {
usersToLoad.add(lower_part);
} else {
chatsToLoad.add(-lower_part);
}
}
cursor.dispose();
if (!dialogs.isEmpty()) {
String ids = TextUtils.join(",", dialogs);
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT uid, data, mid FROM media_v2 WHERE uid IN (%s) AND mid > 0 AND type = %d ORDER BY date DESC, mid DESC", ids, SharedMediaQuery.MEDIA_MUSIC));
while (cursor.next()) {
NativeByteBuffer data = cursor.byteBufferValue(1);
if (data != null) {
TLRPC.Message message = TLRPC.Message.TLdeserialize(data, data.readInt32(false), false);
data.reuse();
if (MessageObject.isMusicMessage(message)) {
int did = cursor.intValue(0);
message.id = cursor.intValue(2);
message.dialog_id = did;
ArrayList<MessageObject> arrayList = musicObjects.get(did);
ArrayList<MediaSession.QueueItem> arrayList1 = musicQueues.get(did);
if (arrayList == null) {
arrayList = new ArrayList<>();
musicObjects.put(did, arrayList);
arrayList1 = new ArrayList<>();
musicQueues.put(did, arrayList1);
}
MessageObject messageObject = new MessageObject(message, null, false);
arrayList.add(0, messageObject);
MediaDescription.Builder builder = new MediaDescription.Builder().setMediaId(did + "_" + arrayList.size());
builder.setTitle(messageObject.getMusicTitle());
builder.setSubtitle(messageObject.getMusicAuthor());
arrayList1.add(0, new MediaSession.QueueItem(builder.build(), arrayList1.size()));
}
}
}
cursor.dispose();
if (!usersToLoad.isEmpty()) {
ArrayList<TLRPC.User> usersArrayList = new ArrayList<>();
//MessagesStorage.getInstance().getUsersInternal(TextUtils.join(",", usersToLoad), usersArrayList);
for (int a = 0; a < usersArrayList.size(); a++) {
TLRPC.User user = usersArrayList.get(a);
users.put(user.id, user);
}
}
if (!chatsToLoad.isEmpty()) {
ArrayList<TLRPC.Chat> chatsArrayList = new ArrayList<>();
//MessagesStorage.getInstance().getChatsInternal(TextUtils.join(",", chatsToLoad), chatsArrayList);
for (int a = 0; a < chatsArrayList.size(); a++) {
TLRPC.Chat chat = chatsArrayList.get(a);
chats.put(chat.id, chat);
}
}
}
} catch (Exception e) {
FileLog.e("messenger", e);
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
chatsLoaded = true;
loadingChats = false;
loadChildrenImpl(parentMediaId, result);
if (lastSelectedDialog == 0 && !dialogs.isEmpty()) {
lastSelectedDialog = dialogs.get(0);
}
if (lastSelectedDialog != 0) {
ArrayList<MessageObject> arrayList = musicObjects.get(lastSelectedDialog);
ArrayList<MediaSession.QueueItem> arrayList1 = musicQueues.get(lastSelectedDialog);
if (arrayList != null && !arrayList.isEmpty()) {
mediaSession.setQueue(arrayList1);
if (lastSelectedDialog > 0) {
TLRPC.User user = users.get(lastSelectedDialog);
if (user != null) {
mediaSession.setQueueTitle(ContactsController.formatName(user.first_name, user.last_name));
} else {
mediaSession.setQueueTitle("DELETED USER");
}
} else {
TLRPC.Chat chat = chats.get(-lastSelectedDialog);
if (chat != null) {
mediaSession.setQueueTitle(chat.title);
} else {
mediaSession.setQueueTitle("DELETED CHAT");
}
}
MessageObject messageObject = arrayList.get(0);
MediaMetadata.Builder builder = new MediaMetadata.Builder();
builder.putLong(MediaMetadata.METADATA_KEY_DURATION, messageObject.getDuration() * 1000);
builder.putString(MediaMetadata.METADATA_KEY_ARTIST, messageObject.getMusicAuthor());
builder.putString(MediaMetadata.METADATA_KEY_TITLE, messageObject.getMusicTitle());
mediaSession.setMetadata(builder.build());
}
}
updatePlaybackState(null);
}
});
}
});
*/
} else {
loadChildrenImpl(parentMediaId, result);
}
}
private void loadChildrenImpl(final String parentMediaId, final Result<List<MediaBrowser.MediaItem>> result) {
List<MediaBrowser.MediaItem> mediaItems = new ArrayList<>();
if (MEDIA_ID_ROOT.equals(parentMediaId)) {
for (int a = 0; a < dialogs.size(); a++) {
int did = dialogs.get(a);
MediaDescription.Builder builder = new MediaDescription.Builder().setMediaId("__CHAT_" + did);
TLRPC.FileLocation avatar = null;
if (did > 0) {
TLRPC.User user = users.get(did);
if (user != null) {
builder.setTitle(ContactsController.formatName(user.first_name, user.last_name));
if (user.photo != null && user.photo.photo_small instanceof TLRPC.TL_fileLocation) {
avatar = user.photo.photo_small;
}
} else {
builder.setTitle("DELETED USER");
}
} else {
TLRPC.Chat chat = chats.get(-did);
if (chat != null) {
builder.setTitle(chat.title);
if (chat.photo != null && chat.photo.photo_small instanceof TLRPC.TL_fileLocation) {
avatar = chat.photo.photo_small;
}
} else {
builder.setTitle("DELETED CHAT");
}
}
Bitmap bitmap = null;
if (avatar != null) {
bitmap = createRoundBitmap(FileLoader.getPathToAttach(avatar, true));
if (bitmap != null) {
builder.setIconBitmap(bitmap);
}
}
if (avatar == null || bitmap == null) {
builder.setIconUri(Uri.parse("android.resource://" + getApplicationContext().getPackageName() + "/drawable/contact_blue"));
}
mediaItems.add(new MediaBrowser.MediaItem(builder.build(), MediaBrowser.MediaItem.FLAG_BROWSABLE));
}
} else if (parentMediaId != null && parentMediaId.startsWith("__CHAT_")) {
int did = 0;
try {
did = Integer.parseInt(parentMediaId.replace("__CHAT_", ""));
} catch (Exception e) {
FileLog.e("messenger", e);
}
ArrayList<MessageObject> arrayList = musicObjects.get(did);
if (arrayList != null) {
for (int a = 0; a < arrayList.size(); a++) {
MessageObject messageObject = arrayList.get(a);
MediaDescription.Builder builder = new MediaDescription.Builder().setMediaId(did + "_" + a);
builder.setTitle(messageObject.getMusicTitle());
builder.setSubtitle(messageObject.getMusicAuthor());
mediaItems.add(new MediaBrowser.MediaItem(builder.build(), MediaBrowser.MediaItem.FLAG_PLAYABLE));
}
}
}
result.sendResult(mediaItems);
}
private Bitmap createRoundBitmap(File path) {
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
Bitmap bitmap = BitmapFactory.decodeFile(path.toString(), options);
if (bitmap != null) {
Bitmap result = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
result.eraseColor(Color.TRANSPARENT);
Canvas canvas = new Canvas(result);
BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
if (roundPaint == null) {
roundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
bitmapRect = new RectF();
}
roundPaint.setShader(shader);
bitmapRect.set(0, 0, bitmap.getWidth(), bitmap.getHeight());
canvas.drawRoundRect(bitmapRect, bitmap.getWidth(), bitmap.getHeight(), roundPaint);
return result;
}
} catch (Throwable e) {
FileLog.e("messenger", e);
}
return null;
}
private final class MediaSessionCallback extends MediaSession.Callback {
@Override
public void onPlay() {
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
if (messageObject == null) {
onPlayFromMediaId(lastSelectedDialog + "_" + 0, null);
} else {
MediaController.getInstance().playAudio(messageObject);
}
}
@Override
public void onSkipToQueueItem(long queueId) {
MediaController.getInstance().playMessageAtIndex((int) queueId);
handlePlayRequest();
}
@Override
public void onSeekTo(long position) {
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
if (messageObject != null) {
MediaController.getInstance().seekToProgress(messageObject, position / 1000 / (float) messageObject.getDuration());
}
}
@Override
public void onPlayFromMediaId(String mediaId, Bundle extras) {
String args[] = mediaId.split("_");
if (args.length != 2) {
return;
}
try {
int did = Integer.parseInt(args[0]);
int id = Integer.parseInt(args[1]);
ArrayList<MessageObject> arrayList = musicObjects.get(did);
ArrayList<MediaSession.QueueItem> arrayList1 = musicQueues.get(did);
if (arrayList == null || id < 0 || id >= arrayList.size()) {
return;
}
lastSelectedDialog = did;
ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE).edit().putInt("auto_lastSelectedDialog", did).apply();
MediaController.getInstance().setPlaylist(arrayList, arrayList.get(id), false);
mediaSession.setQueue(arrayList1);
if (did > 0) {
TLRPC.User user = users.get(did);
if (user != null) {
mediaSession.setQueueTitle(ContactsController.formatName(user.first_name, user.last_name));
} else {
mediaSession.setQueueTitle("DELETED USER");
}
} else {
TLRPC.Chat chat = chats.get(-did);
if (chat != null) {
mediaSession.setQueueTitle(chat.title);
} else {
mediaSession.setQueueTitle("DELETED CHAT");
}
}
} catch (Exception e) {
FileLog.e("messenger", e);
}
handlePlayRequest();
}
@Override
public void onPause() {
handlePauseRequest();
}
@Override
public void onStop() {
handleStopRequest(null);
}
@Override
public void onSkipToNext() {
MediaController.getInstance().playNextMessage();
}
@Override
public void onSkipToPrevious() {
MediaController.getInstance().playPreviousMessage();
}
@Override
public void onPlayFromSearch(String query, Bundle extras) {
if (query == null || query.length() == 0) {
return;
}
query = query.toLowerCase();
for (int a = 0; a < dialogs.size(); a++) {
int did = dialogs.get(a);
if (did > 0) {
TLRPC.User user = users.get(did);
if (user == null) {
continue;
}
if (user.first_name != null && user.first_name.startsWith(query) || user.last_name != null && user.last_name.startsWith(query)) {
onPlayFromMediaId(did + "_" + 0, null);
break;
}
} else {
TLRPC.Chat chat = chats.get(-did);
if (chat == null) {
continue;
}
if (chat.title != null && chat.title.toLowerCase().contains(query)) {
onPlayFromMediaId(did + "_" + 0, null);
break;
}
}
}
}
}
private void updatePlaybackState(String error) {
long position = PlaybackState.PLAYBACK_POSITION_UNKNOWN;
MessageObject playingMessageObject = MediaController.getInstance().getPlayingMessageObject();
if (playingMessageObject != null) {
position = playingMessageObject.audioProgressSec * 1000;
}
PlaybackState.Builder stateBuilder = new PlaybackState.Builder().setActions(getAvailableActions());
int state;
if (playingMessageObject == null) {
state = PlaybackState.STATE_STOPPED;
} else {
if (MediaController.getInstance().isDownloadingCurrentMessage()) {
state = PlaybackState.STATE_BUFFERING;
} else {
state = MediaController.getInstance().isAudioPaused() ? PlaybackState.STATE_PAUSED : PlaybackState.STATE_PLAYING;
}
}
if (error != null) {
stateBuilder.setErrorMessage(error);
state = PlaybackState.STATE_ERROR;
}
stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime());
if (playingMessageObject != null) {
stateBuilder.setActiveQueueItemId(MediaController.getInstance().getPlayingMessageObjectNum());
} else {
stateBuilder.setActiveQueueItemId(0);
}
mediaSession.setPlaybackState(stateBuilder.build());
}
private long getAvailableActions() {
long actions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_FROM_MEDIA_ID | PlaybackState.ACTION_PLAY_FROM_SEARCH;
MessageObject playingMessageObject = MediaController.getInstance().getPlayingMessageObject();
if (playingMessageObject != null) {
if (!MediaController.getInstance().isAudioPaused()) {
actions |= PlaybackState.ACTION_PAUSE;
}
actions |= PlaybackState.ACTION_SKIP_TO_PREVIOUS;
actions |= PlaybackState.ACTION_SKIP_TO_NEXT;
}
return actions;
}
private void handleStopRequest(String withError) {
delayedStopHandler.removeCallbacksAndMessages(null);
delayedStopHandler.sendEmptyMessageDelayed(0, STOP_DELAY);
updatePlaybackState(withError);
stopSelf();
serviceStarted = false;
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioPlayStateChanged);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioDidStarted);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioDidReset);
}
private void handlePlayRequest() {
delayedStopHandler.removeCallbacksAndMessages(null);
if (!serviceStarted) {
startService(new Intent(getApplicationContext(), MusicBrowserService.class));
serviceStarted = true;
}
if (!mediaSession.isActive()) {
mediaSession.setActive(true);
}
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
if (messageObject == null) {
return;
}
MediaMetadata.Builder builder = new MediaMetadata.Builder();
builder.putLong(MediaMetadata.METADATA_KEY_DURATION, messageObject.getDuration() * 1000);
builder.putString(MediaMetadata.METADATA_KEY_ARTIST, messageObject.getMusicAuthor());
builder.putString(MediaMetadata.METADATA_KEY_TITLE, messageObject.getMusicTitle());
AudioInfo audioInfo = MediaController.getInstance().getAudioInfo();
if (audioInfo != null) {
Bitmap bitmap = audioInfo.getCover();
if (bitmap != null) {
builder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, bitmap);
}
}
mediaSession.setMetadata(builder.build());
}
private void handlePauseRequest() {
MediaController.getInstance().pauseAudio(MediaController.getInstance().getPlayingMessageObject());
delayedStopHandler.removeCallbacksAndMessages(null);
delayedStopHandler.sendEmptyMessageDelayed(0, STOP_DELAY);
}
@Override
public void didReceivedNotification(int id, Object... args) {
updatePlaybackState(null);
handlePlayRequest();
}
private static class DelayedStopHandler extends Handler {
private final WeakReference<MusicBrowserService> mWeakReference;
private DelayedStopHandler(MusicBrowserService service) {
mWeakReference = new WeakReference<>(service);
}
@Override
public void handleMessage(Message msg) {
MusicBrowserService service = mWeakReference.get();
if (service != null) {
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
if (messageObject != null && !MediaController.getInstance().isAudioPaused()) {
return;
}
service.stopSelf();
service.serviceStarted = false;
}
}
}
}
@@ -61,10 +61,10 @@ public class MusicPlayerReceiver extends BroadcastReceiver {
case KeyEvent.KEYCODE_MEDIA_STOP:
break;
case KeyEvent.KEYCODE_MEDIA_NEXT:
MediaController.getInstance().playNextMessage();
MediaController.getInstance().playNextMessage(+1, false);
break;
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
MediaController.getInstance().playPreviousMessage();
MediaController.getInstance().playNextMessage(-1, false);
break;
}
} else {
@@ -73,11 +73,11 @@ public class MusicPlayerReceiver extends BroadcastReceiver {
} else if (intent.getAction().equals(MusicPlayerService.NOTIFY_PAUSE) || intent.getAction().equals(android.media.AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
MediaController.getInstance().pauseAudio(MediaController.getInstance().getPlayingMessageObject());
} else if (intent.getAction().equals(MusicPlayerService.NOTIFY_NEXT)) {
MediaController.getInstance().playNextMessage();
MediaController.getInstance().playNextMessage(+1, false);
} else if (intent.getAction().equals(MusicPlayerService.NOTIFY_CLOSE)) {
MediaController.getInstance().cleanupPlayer(true, true);
} else if (intent.getAction().equals(MusicPlayerService.NOTIFY_PREVIOUS)) {
MediaController.getInstance().playPreviousMessage();
MediaController.getInstance().playNextMessage(-1, false);
}
}
}
@@ -53,7 +53,6 @@ public class MusicPlayerService extends Service implements NotificationCenter.No
private RemoteControlClient remoteControlClient;
private AudioManager audioManager;
private static boolean supportBigNotifications = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
private static boolean supportLockScreenControls = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
@Override
@@ -108,95 +107,70 @@ public class MusicPlayerService extends Service implements NotificationCenter.No
}
@SuppressLint("NewApi")
private void createNotification(MessageObject messageObject) {
String songName = messageObject.getMusicTitle();
String authorName = messageObject.getMusicAuthor();
private void createNotification(MessageObject messageObject)
{
AudioInfo audioInfo = MediaController.getInstance().getAudioInfo();
RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.player_small_notification);
RemoteViews expandedView = null;
if (supportBigNotifications) {
expandedView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.player_big_notification);
MrPoortext pt = MrMailbox.getMsg(messageObject.getId()).getMediainfo();
String authorName = pt.getText1();
String songName = pt.getText2();
if( songName == null || songName.length()==0 ) {
TLRPC.Document document = messageObject.messageOwner.media.document;
for (int i = 0; i < document.attributes.size(); i++) {
TLRPC.DocumentAttribute attr = document.attributes.get(i);
if (attr instanceof TLRPC.TL_documentAttributeAudio) {
authorName = attr.performer;
songName = attr.title;
break;
}
}
}
Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
intent.setAction("com.b44t.messenger.openplayer");
intent.setFlags(32768);
PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, 0);
if( songName == null || songName.length()==0 ) {
// preview of just recorded and not send voice messages
authorName = ApplicationLoader.applicationContext.getString(R.string.FromSelf);
songName = ApplicationLoader.applicationContext.getString(R.string.AttachVoiceMessage);
}
RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.player_small_notification);
//Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
//intent.setAction("com.b44t.messenger.openchat"+messageObject.getDialogId());
//intent.setFlags(32768);
//PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, 0);
Notification notification = new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.drawable.player)
.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.notification_player)
//.setContentIntent(contentIntent)
.setContentTitle(songName).build();
notification.contentView = simpleContentView;
if (supportBigNotifications) {
notification.bigContentView = expandedView;
}
setListeners(simpleContentView);
if (supportBigNotifications) {
setListeners(expandedView);
}
Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover() : null;
if (albumArt != null) {
notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt);
if (supportBigNotifications) {
notification.bigContentView.setImageViewBitmap(R.id.player_album_art, albumArt);
}
notification.contentView.setViewVisibility(R.id.player_album_art, View.VISIBLE);
} else {
notification.contentView.setImageViewResource(R.id.player_album_art, R.drawable.nocover_small);
if (supportBigNotifications) {
notification.bigContentView.setImageViewResource(R.id.player_album_art, R.drawable.nocover_big);
}
notification.contentView.setViewVisibility(R.id.player_album_art, View.GONE);
}
if (MediaController.getInstance().isDownloadingCurrentMessage()) {
notification.contentView.setViewVisibility(R.id.player_pause, View.GONE);
notification.contentView.setViewVisibility(R.id.player_play, View.GONE);
notification.contentView.setViewVisibility(R.id.player_next, View.GONE);
notification.contentView.setViewVisibility(R.id.player_previous, View.GONE);
notification.contentView.setViewVisibility(R.id.player_progress_bar, View.VISIBLE);
if (supportBigNotifications) {
notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE);
notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE);
notification.bigContentView.setViewVisibility(R.id.player_next, View.GONE);
notification.bigContentView.setViewVisibility(R.id.player_previous, View.GONE);
notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.VISIBLE);
}
} else {
notification.contentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
{
notification.contentView.setViewVisibility(R.id.player_next, View.VISIBLE);
notification.contentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
if (supportBigNotifications) {
notification.bigContentView.setViewVisibility(R.id.player_next, View.VISIBLE);
notification.bigContentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
}
if (MediaController.getInstance().isAudioPaused()) {
notification.contentView.setViewVisibility(R.id.player_pause, View.GONE);
notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE);
if (supportBigNotifications) {
notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE);
notification.bigContentView.setViewVisibility(R.id.player_play, View.VISIBLE);
}
} else {
notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
notification.contentView.setViewVisibility(R.id.player_play, View.GONE);
if (supportBigNotifications) {
notification.bigContentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE);
}
}
}
notification.contentView.setTextViewText(R.id.player_song_name, songName);
notification.contentView.setTextViewText(R.id.player_author_name, authorName);
if (supportBigNotifications) {
notification.bigContentView.setTextViewText(R.id.player_song_name, songName);
notification.bigContentView.setTextViewText(R.id.player_author_name, authorName);
}
notification.flags |= Notification.FLAG_ONGOING_EVENT;
startForeground(5, notification);
@@ -218,12 +192,16 @@ public class MusicPlayerService extends Service implements NotificationCenter.No
public void setListeners(RemoteViews view) {
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PREVIOUS), PendingIntent.FLAG_UPDATE_CURRENT);
view.setOnClickPendingIntent(R.id.player_previous, pendingIntent);
pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_CLOSE), PendingIntent.FLAG_UPDATE_CURRENT);
view.setOnClickPendingIntent(R.id.player_close, pendingIntent);
pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PAUSE), PendingIntent.FLAG_UPDATE_CURRENT);
view.setOnClickPendingIntent(R.id.player_pause, pendingIntent);
pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_NEXT), PendingIntent.FLAG_UPDATE_CURRENT);
view.setOnClickPendingIntent(R.id.player_next, pendingIntent);
pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PLAY), PendingIntent.FLAG_UPDATE_CURRENT);
view.setOnClickPendingIntent(R.id.player_play, pendingIntent);
}
@@ -48,17 +48,14 @@ public class NotificationCenter {
//public static final int pushMessagesUpdated = totalEvents++;
public static final int blockedUsersDidLoaded = totalEvents++;
public static final int openedChatChanged = totalEvents++;
public static final int stopEncodingService = totalEvents++;
public static final int mainUserInfoChanged = totalEvents++;
public static final int recentImagesDidLoaded = totalEvents++;
public static final int replaceMessagesObjects = totalEvents++;
public static final int waveformCalculated = totalEvents++;
public static final int didSetPasscode = totalEvents++;
//public static final int screenStateChanged = totalEvents++; -- currently not used, but this may get handy
public static final int stickersDidLoaded = totalEvents++;
public static final int didReplacedPhotoInMemCache = totalEvents++;
public static final int musicDidLoaded = totalEvents++;
public static final int locationPermissionGranted = totalEvents++;
public static final int wasUnableToFindCurrentLocation = totalEvents++;
//public static final int musicDidLoaded = totalEvents++;
public static final int reloadHints = totalEvents++;
public static final int httpFileDidLoaded = totalEvents++;
@@ -71,9 +68,6 @@ public class NotificationCenter {
public static final int didUpdatedConnectionState = totalEvents++;
public static final int emojiDidLoaded = totalEvents++;
public static final int FileDidUpload = totalEvents++;
public static final int FileDidFailUpload = totalEvents++;
public static final int FileUploadProgressChanged = totalEvents++;
public static final int FileLoadProgressChanged = totalEvents++;
public static final int FileDidLoaded = totalEvents++;
public static final int FileDidFailedLoad = totalEvents++;
@@ -88,7 +82,6 @@ public class NotificationCenter {
public static final int recordStarted = totalEvents++;
public static final int recordStartError = totalEvents++;
public static final int recordStopped = totalEvents++;
public static final int screenshotTook = totalEvents++;
public static final int albumsDidLoaded = totalEvents++;
public static final int audioDidSent = totalEvents++;
public static final int audioDidStarted = totalEvents++;
@@ -70,7 +70,6 @@ public class NotificationsController {
private HashMap<Long, Integer> autoNotificationsIds = new HashMap<>();
private int wearNotificationId = 10000;
private int autoNotificationId = 20000;
public ArrayList<MessageObject> popupMessages = new ArrayList<>();
private long opened_dialog_id = 0;
private int total_unread_count = 0;
private int personal_count = 0;
@@ -408,7 +407,7 @@ public class NotificationsController {
return;
}
TLRPC.Message tmsg = mrMsg.get_TLRPC_Message();
MessageObject msgDrawObj = new MessageObject(tmsg, null, true);
MessageObject msgDrawObj = new MessageObject(tmsg, true);
delayedPushMessages.add(msgDrawObj);
pushMessages.add(0, msgDrawObj);
@@ -935,7 +934,7 @@ public class NotificationsController {
}
}
private void scheduleNotificationDelay(boolean onlineReason) {
/*private void scheduleNotificationDelay(boolean onlineReason) {
try {
FileLog.e("messenger", "delay notification start, onlineReason = " + onlineReason);
notificationDelayWakelock.acquire(10000);
@@ -945,7 +944,7 @@ public class NotificationsController {
FileLog.e("messenger", e);
showOrUpdateNotification(notifyCheck);
}
}
}*/
protected void repeatNotificationMaybe() {
notificationsQueue.postRunnable(new Runnable() {
@@ -1327,10 +1326,10 @@ public class NotificationsController {
continue;
}
} else {
chat = MessagesController.getInstance().getChat(-(int)dialog_id);
if (chat == null) {
/*chat = MessagesController.getInstance().getChat(-(int)dialog_id);
if (chat == null) {*/
continue;
}
//}
}
TLRPC.FileLocation photoPath = null;
if (AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) {
@@ -1397,7 +1396,7 @@ public class NotificationsController {
if (chat != null) {
replyToString = String.format(mContext.getString(R.string.ReplyToGroup), name);
} else {
replyToString = String.format(mContext.getString(R.string.ReplyToUser), name);
replyToString = String.format(mContext.getString(R.string.ReplyToContact), name);
}
wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon, replyToString, replyPendingIntent).addRemoteInput(remoteInputWear).build();
}
File diff suppressed because it is too large Load Diff
@@ -1,44 +0,0 @@
/*******************************************************************************
*
* Messenger Android Frontend
* (C) 2013-2016 Nikolai Kudashov
* (C) 2017 Björn Petersen
* Contact: r10s@b44t.com, http://b44t.com
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/ .
*
******************************************************************************/
package com.b44t.messenger;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class ShareBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String url = intent.getDataString();
if (url != null) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, url);
Intent chooserIntent = Intent.createChooser(shareIntent, LocaleController.getString("ShareLink", R.string.ShareLink));
chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(chooserIntent);
}
}
}
@@ -41,7 +41,6 @@ public class TLRPC {
}
public static class ChatPhoto extends TLObject {
public FileLocation photo_small;
public FileLocation photo_big;
}
@@ -51,7 +50,6 @@ public class TLRPC {
public int duration;
public String alt;
public InputStickerSet stickerset;
public int flags;
public boolean voice;
public String title;
public String performer;
@@ -77,20 +75,7 @@ public class TLRPC {
public static class TL_documentAttributeFilename extends DocumentAttribute {
}
public static class messages_Messages extends TLObject {
public ArrayList<Message> messages = new ArrayList<>();
public ArrayList<Chat> chats = new ArrayList<>();
public ArrayList<User> users = new ArrayList<>();
public int flags;
public int pts;
public int count;
}
public static class TL_messages_messages extends messages_Messages {
}
public static class Peer extends TLObject {
public final int channel_id = 0;
public int user_id;
public final int chat_id = 0;
}
@@ -98,85 +83,28 @@ public class TLRPC {
public static class TL_peerUser extends Peer {
}
public static class GeoPoint extends TLObject {
public double _long;
public double lat;
}
public static class TL_geoPoint extends GeoPoint {
}
public static class TL_messageMediaEmpty extends MessageMedia {
}
public static class TL_messageMediaVenue extends MessageMedia {
}
public static class TL_messageMediaDocument extends MessageMedia {
}
public static class TL_messageMediaContact extends MessageMedia {
}
public static class TL_messageMediaPhoto extends MessageMedia {
}
public static class TL_messageMediaGeo extends MessageMedia {
}
public static class PeerNotifySettings extends TLObject {
public int flags;
public boolean silent;
public int mute_until;
public String sound;
}
public static class TL_peerNotifySettings extends PeerNotifySettings {
}
public static class TL_messages_stickerSet extends TLObject {
public StickerSet set;
public ArrayList<Document> documents = new ArrayList<>();
}
public static class InputGeoPoint extends TLObject {
public double lat;
public double _long;
}
public static class TL_inputGeoPoint extends InputGeoPoint {
}
public static class Audio extends TLObject {
public long id;
public int date;
public int duration;
public String mime_type;
public int size;
public int dc_id;
public final int dc_id = 0;
public int user_id;
public byte[] key;
public byte[] iv;
}
public static class ChatFull extends TLObject {
public int flags;
public int id;
public String about;
}
public static class WebPage extends TLObject {
public int flags;
public long id;
public String url;
public String type;
public String title;
public String description;
public Photo photo;
public int duration;
public String author;
public int date;
public Document document;
}
public static class InputFileLocation extends TLObject {
@@ -184,7 +112,6 @@ public class TLRPC {
public long access_hash;
public long volume_id;
public int local_id;
public long secret;
}
public static class TL_inputDocumentFileLocation extends InputFileLocation {
@@ -198,17 +125,10 @@ public class TLRPC {
public String first_name;
public String last_name;
public String username;
public String phone;
public UserProfilePhoto photo;
public int flags;
public boolean self;
public boolean contact;
public boolean min;
}
public static class TL_userContact_old2 extends User {
}
public static class Video extends TLObject {
public long id;
public int user_id;
@@ -221,16 +141,6 @@ public class TLRPC {
public int h;
public String mime_type;
public String caption;
public byte[] key;
public byte[] iv;
}
public static class InputDocument extends TLObject {
public long id;
public long access_hash;
}
public static class TL_inputDocument extends InputDocument {
}
public static class Document extends TLObject {
@@ -253,53 +163,6 @@ public class TLRPC {
public static class TL_document extends Document {
}
public static class InputMedia extends TLObject {
public InputFile file;
public InputFile thumb;
public String mime_type;
public ArrayList<DocumentAttribute> attributes = new ArrayList<>();
public String caption;
public InputGeoPoint geo_point;
public String title;
public String address;
public String provider;
public String venue_id;
public String phone_number;
public String first_name;
public String last_name;
public String url;
public String q;
}
public static class TL_inputMediaContact extends InputMedia {
}
public static class TL_inputMediaUploadedThumbDocument extends InputMedia {
}
public static class TL_inputMediaDocument extends InputMedia {
public InputDocument id;
}
public static class TL_inputMediaGifExternal extends InputMedia {
}
public static class TL_inputMediaGeoPoint extends InputMedia {
}
public static class TL_inputMediaUploadedPhoto extends InputMedia {
}
public static class TL_inputMediaVenue extends InputMedia {
}
public static class TL_inputMediaUploadedDocument extends InputMedia {
}
public static class TL_inputMediaPhoto extends InputMedia {
public InputPhoto id;
}
public static class InputStickerSet extends TLObject {
public long id;
public String short_name;
@@ -308,11 +171,6 @@ public class TLRPC {
public static class TL_inputStickerSetEmpty extends InputStickerSet {
}
public static class InputEncryptedFile extends TLObject {
public long id;
public int parts;
}
public static class UserProfilePhoto extends TLObject {
public FileLocation photo_small;
public FileLocation photo_big;
@@ -320,7 +178,6 @@ public class TLRPC {
public static class Photo extends TLObject {
public long id;
public long access_hash;
public int user_id;
public int date;
public String caption;
@@ -340,12 +197,12 @@ public class TLRPC {
public String title;
public final ChatPhoto photo = null;
public int date;
public int version;
public boolean editor;
public final int version = 0;
public final boolean editor = false;
public String username;
public boolean signatures;
public boolean min;
public String address;
public final boolean signatures = false;
public final boolean min = false;
public final String address = null;
}
public static class StickerSet extends TLObject {
@@ -417,29 +274,15 @@ public class TLRPC {
public static class TL_wallPaperSolid extends WallPaper {
}
public static class InputPhoto extends TLObject {
public long id;
public long access_hash;
}
public static class TL_inputPhoto extends InputPhoto {
}
public static class MessageMedia extends TLObject {
public byte[] bytes;
public Photo photo;
public GeoPoint geo;
public String title;
public String address;
public String provider;
public String venue_id;
public Document document;
public String caption;
public String phone_number;
public String first_name;
public String last_name;
public int user_id;
public WebPage webpage;
}
public static class Message extends TLObject {
@@ -447,25 +290,22 @@ public class TLRPC {
public int from_id;
public Peer to_id;
public int date;
public int reply_to_msg_id;
public long reply_to_random_id;
public final int reply_to_msg_id = 0;
public String message;
public MessageMedia media;
public int flags;
public boolean media_unread;
public boolean out;
public boolean unread;
public int views;
public boolean silent;
public boolean post;
public final int views = 0;
public final boolean silent = false;
public final boolean post = false;// ? true=avatar wird in gruppen nicht angezeigt, wird aber in isFromUser() auch überprüft...
public TL_messageFwdHeader fwd_from;
public int send_state = 0; //custom
public String attachPath = ""; //custom
public HashMap<String, String> params; //custom
public long random_id; //custom
public long dialog_id; //custom
public int layer; //custom
public TLRPC.Message replyMessage; //custom
public final int layer = 0; //custom
public boolean created_by_mr;
}
@@ -475,16 +315,10 @@ public class TLRPC {
public static class TL_dialog extends TLObject {
final public int flags = 0;
public Peer peer;
public int top_message;
public int unread_count;
public PeerNotifySettings notify_settings;
public int pts;
public final int top_message = 0;
public final int unread_count = 0;
public final int pts = 0;
public DraftMessage draft;
public int last_message_date; //custom
public long id; //custom
}
public static class Vector extends TLObject {
public ArrayList<Object> objects = new ArrayList<>();
}
}
@@ -1,187 +0,0 @@
/*******************************************************************************
*
* Messenger Android Frontend
* (C) 2013-2016 Nikolai Kudashov
* (C) 2017 Björn Petersen
* Contact: r10s@b44t.com, http://b44t.com
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/ .
*
******************************************************************************/
package com.b44t.messenger;
// ChooserTargetService, see https://developer.android.com/reference/android/service/chooser/ChooserTargetService.html
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ComponentName;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Build;
import android.service.chooser.ChooserTarget;
import android.service.chooser.ChooserTargetService;
import com.b44t.ui.LaunchActivity;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Semaphore;
@TargetApi(Build.VERSION_CODES.M)
public class TgChooserTargetService extends ChooserTargetService {
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
final List<ChooserTarget> targets = new ArrayList<>();
if (!UserConfig.isClientActivated()) {
return targets;
}
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
if (!preferences.getBoolean("direct_share", true)) {
return targets;
}
ImageLoader imageLoader = ImageLoader.getInstance();
final Semaphore semaphore = new Semaphore(0);
final ComponentName componentName = new ComponentName(getPackageName(), LaunchActivity.class.getCanonicalName());
/*
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
ArrayList<Integer> dialogs = new ArrayList<>();
ArrayList<TLRPC.Chat> chats = new ArrayList<>();
ArrayList<TLRPC.User> users = new ArrayList<>();
try {
ArrayList<Integer> usersToLoad = new ArrayList<>();
usersToLoad.add(UserConfig.getClientUserId());
ArrayList<Integer> chatsToLoad = new ArrayList<>();
SQLiteCursor cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT did FROM dialogs ORDER BY date DESC LIMIT %d,%d", 0, 30));
while (cursor.next()) {
long id = cursor.longValue(0);
int lower_id = (int) id;
int high_id = (int) (id >> 32);
if (lower_id != 0) {
if (high_id == 1) {
continue;
} else {
if (lower_id > 0) {
if (!usersToLoad.contains(lower_id)) {
usersToLoad.add(lower_id);
}
} else {
if (!chatsToLoad.contains(-lower_id)) {
chatsToLoad.add(-lower_id);
}
}
}
} else {
continue;
}
dialogs.add(lower_id);
if (dialogs.size() == 8) {
break;
}
}
cursor.dispose();
if (!chatsToLoad.isEmpty()) {
//MessagesStorage.getInstance().getChatsInternal(TextUtils.join(",", chatsToLoad), chats);
}
if (!usersToLoad.isEmpty()) {
//MessagesStorage.getInstance().getUsersInternal(TextUtils.join(",", usersToLoad), users);
}
} catch (Exception e) {
FileLog.e("messenger", e);
}
for (int a = 0; a < dialogs.size(); a++) {
Bundle extras = new Bundle();
Icon icon = null;
String name = null;
int id = dialogs.get(a);
if (id > 0) {
for (int b = 0; b < users.size(); b++) {
TLRPC.User user = users.get(b);
if (user.id == id) {
if (!user.bot) {
extras.putLong("dialogId", (long) id);
if (user.photo != null && user.photo.photo_small != null) {
icon = createRoundBitmap(FileLoader.getPathToAttach(user.photo.photo_small, true));
}
name = ContactsController.formatName(user.first_name, user.last_name);
}
break;
}
}
} else {
for (int b = 0; b < chats.size(); b++) {
TLRPC.Chat chat = chats.get(b);
if (chat.id == -id) {
if (!ChatObject.isNotInChat(chat) && (!ChatObject.isChannel(chat) || chat.megagroup)) {
extras.putLong("dialogId", (long) id);
if (chat.photo != null && chat.photo.photo_small != null) {
icon = createRoundBitmap(FileLoader.getPathToAttach(chat.photo.photo_small, true));
}
name = chat.title;
}
break;
}
}
}
if (name != null) {
if (icon == null) {
icon = Icon.createWithResource(ApplicationLoader.applicationContext, R.drawable.logo_avatar);
}
targets.add(new ChooserTarget(name, icon, 1.0f, componentName, extras));
}
}
semaphore.release();
}
});
*/
try {
semaphore.acquire();
} catch (Exception e) {
FileLog.e("messenger", e);
}
return targets;
}
/*
private Icon createRoundBitmap(File path) {
try {
Bitmap bitmap = BitmapFactory.decodeFile(path.toString());
if (bitmap != null) {
Bitmap result = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
result.eraseColor(Color.TRANSPARENT);
Canvas canvas = new Canvas(result);
BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
if (roundPaint == null) {
roundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
bitmapRect = new RectF();
}
roundPaint.setShader(shader);
bitmapRect.set(0, 0, bitmap.getWidth(), bitmap.getHeight());
canvas.drawRoundRect(bitmapRect, bitmap.getWidth(), bitmap.getHeight(), roundPaint);
return Icon.createWithBitmap(result);
}
} catch (Throwable e) {
FileLog.e("messenger", e);
}
return null;
}
*/
}
@@ -32,15 +32,8 @@ import java.io.File;
public class UserConfig {
private static TLRPC.User currentUser;
public static boolean registeredForPush;
public static String pushString = "";
public static int lastSendMessageId = -210000;
public static int lastLocalId = -210000;
public static int lastBroadcastId = -1;
public static String contactsHash = "";
public static boolean blockedUsersLoaded;
private final static Object sync = new Object();
public static boolean saveIncomingPhotos;
public static String passcodeHash = "";
public static byte[] passcodeSalt = new byte[0];
public static boolean appLocked;
@@ -49,26 +42,6 @@ public class UserConfig {
public static int lastPauseTime;
public static boolean isWaitingForPasscodeEnter;
public static boolean useFingerprint = true;
public static String lastUpdateVersion;
public static int lastContactsSyncTime;
public static int lastHintsSyncTime;
public static boolean draftsLoaded;
public static int migrateOffsetId = -1;
public static int migrateOffsetDate = -1;
public static int migrateOffsetUserId = -1;
public static int migrateOffsetChatId = -1;
public static int migrateOffsetChannelId = -1;
public static long migrateOffsetAccess = -1;
public static int getNewMessageId() {
int id;
synchronized (sync) {
id = lastSendMessageId;
lastSendMessageId--;
}
return id;
}
public static void saveConfig(boolean withFile) {
saveConfig(withFile, null);
@@ -79,34 +52,14 @@ public class UserConfig {
try {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("userconfing", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("registeredForPush", registeredForPush);
editor.putString("pushString2", pushString);
editor.putInt("lastSendMessageId", lastSendMessageId);
editor.putInt("lastLocalId", lastLocalId);
editor.putString("contactsHash", contactsHash);
editor.putBoolean("saveIncomingPhotos", saveIncomingPhotos);
editor.putInt("lastBroadcastId", lastBroadcastId);
editor.putBoolean("blockedUsersLoaded", blockedUsersLoaded);
editor.putString("passcodeHash1", passcodeHash);
editor.putString("passcodeSalt", passcodeSalt.length > 0 ? Base64.encodeToString(passcodeSalt, Base64.DEFAULT) : "");
editor.putBoolean("appLocked", appLocked);
editor.putInt("passcodeType", passcodeType);
editor.putInt("autoLockIn", autoLockIn);
editor.putInt("lastPauseTime", lastPauseTime);
editor.putString("lastUpdateVersion2", lastUpdateVersion);
editor.putInt("lastContactsSyncTime", lastContactsSyncTime);
editor.putBoolean("useFingerprint", useFingerprint);
editor.putInt("lastHintsSyncTime", lastHintsSyncTime);
editor.putBoolean("draftsLoaded", draftsLoaded);
editor.putInt("migrateOffsetId", migrateOffsetId);
if (migrateOffsetId != -1) {
editor.putInt("migrateOffsetDate", migrateOffsetDate);
editor.putInt("migrateOffsetUserId", migrateOffsetUserId);
editor.putInt("migrateOffsetChatId", migrateOffsetChatId);
editor.putInt("migrateOffsetChannelId", migrateOffsetChannelId);
editor.putLong("migrateOffsetAccess", migrateOffsetAccess);
}
/*
if (currentUser != null) {
@@ -231,33 +184,13 @@ public class UserConfig {
*/
{
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("userconfing", Context.MODE_PRIVATE);
registeredForPush = preferences.getBoolean("registeredForPush", false);
pushString = preferences.getString("pushString2", "");
lastSendMessageId = preferences.getInt("lastSendMessageId", -210000);
lastLocalId = preferences.getInt("lastLocalId", -210000);
contactsHash = preferences.getString("contactsHash", "");
saveIncomingPhotos = preferences.getBoolean("saveIncomingPhotos", false);
lastBroadcastId = preferences.getInt("lastBroadcastId", -1);
blockedUsersLoaded = preferences.getBoolean("blockedUsersLoaded", false);
passcodeHash = preferences.getString("passcodeHash1", "");
appLocked = preferences.getBoolean("appLocked", false);
passcodeType = preferences.getInt("passcodeType", 0);
autoLockIn = preferences.getInt("autoLockIn", 60 * 60);
lastPauseTime = preferences.getInt("lastPauseTime", 0);
useFingerprint = preferences.getBoolean("useFingerprint", true);
lastUpdateVersion = preferences.getString("lastUpdateVersion2", "3.5");
lastContactsSyncTime = preferences.getInt("lastContactsSyncTime", (int) (System.currentTimeMillis() / 1000) - 23 * 60 * 60);
lastHintsSyncTime = preferences.getInt("lastHintsSyncTime", (int) (System.currentTimeMillis() / 1000) - 25 * 60 * 60);
draftsLoaded = preferences.getBoolean("draftsLoaded", false);
migrateOffsetId = preferences.getInt("migrateOffsetId", 0);
if (migrateOffsetId != -1) {
migrateOffsetDate = preferences.getInt("migrateOffsetDate", 0);
migrateOffsetUserId = preferences.getInt("migrateOffsetUserId", 0);
migrateOffsetChatId = preferences.getInt("migrateOffsetChatId", 0);
migrateOffsetChannelId = preferences.getInt("migrateOffsetChannelId", 0);
migrateOffsetAccess = preferences.getLong("migrateOffsetAccess", 0);
}
/*
String user = preferences.getString("user", null);
@@ -25,10 +25,6 @@ package com.b44t.messenger;
public class UserObject {
public static boolean isUserSelf(TLRPC.User user) {
return user.self;
}
public static String getUserName(TLRPC.User user) {
return "ErrName"; // use MrContact.getName() instead
}
@@ -1,97 +0,0 @@
/*******************************************************************************
*
* Messenger Android Frontend
* (C) 2013-2016 Nikolai Kudashov
* (C) 2017 Björn Petersen
* Contact: r10s@b44t.com, http://b44t.com
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/ .
*
******************************************************************************/
package com.b44t.messenger;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
public class VideoEncodingService extends Service implements NotificationCenter.NotificationCenterDelegate {
private Context mContext = ApplicationLoader.applicationContext;
private NotificationCompat.Builder builder = null;
private String path = null;
private int currentProgress = 0;
public VideoEncodingService() {
super();
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileUploadProgressChanged);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.stopEncodingService);
}
public IBinder onBind(Intent arg2) {
return null;
}
public void onDestroy() {
stopForeground(true);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileUploadProgressChanged);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.stopEncodingService);
FileLog.e("messenger", "destroy video service");
}
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.FileUploadProgressChanged) {
String fileName = (String)args[0];
if (path != null && path.equals(fileName)) {
Float progress = (Float) args[1];
Boolean enc = (Boolean) args[2];
currentProgress = (int)(progress * 100);
builder.setProgress(100, currentProgress, currentProgress == 0);
NotificationManagerCompat.from(mContext).notify(4, builder.build());
}
} else if (id == NotificationCenter.stopEncodingService) {
String filepath = (String)args[0];
if (filepath == null || filepath.equals(path)) {
stopSelf();
}
}
}
public int onStartCommand(Intent intent, int flags, int startId) {
path = intent.getStringExtra("path");
if (path == null) {
stopSelf();
return Service.START_NOT_STICKY;
}
FileLog.e("messenger", "start video service");
if (builder == null) {
builder = new NotificationCompat.Builder(mContext);
builder.setSmallIcon(android.R.drawable.stat_sys_upload);
builder.setWhen(System.currentTimeMillis());
builder.setContentTitle(mContext.getString(R.string.AppName));
builder.setTicker(mContext.getString(R.string.SendingVideo));
builder.setContentText(mContext.getString(R.string.SendingVideo));
}
currentProgress = 0;
builder.setProgress(100, currentProgress, currentProgress == 0);
startForeground(4, builder.build());
NotificationManagerCompat.from(mContext).notify(4, builder.build());
return Service.START_NOT_STICKY;
}
}
@@ -47,7 +47,7 @@ public class WearReplyReceiver extends BroadcastReceiver {
if (dialog_id == 0 || max_id == 0) {
return;
}
SendMessagesHelper.getInstance().sendMessageText(text.toString(), dialog_id, null, null);
SendMessagesHelper.getInstance().sendMessageText(text.toString(), dialog_id, null);
MrMailbox.markseenChat((int)dialog_id);
NotificationsController.getInstance().removeSeenMessages();
}
@@ -147,7 +147,7 @@ public class AccountSettingsActivity extends BaseFragment implements Notificatio
// create action bar
if( !fromIntro ) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setBackButtonImage(R.drawable.ic_close_white);
}
actionBar.setAllowOverlayTitle(true);
@@ -156,7 +156,7 @@ public class AccountSettingsActivity extends BaseFragment implements Notificatio
@Override
public void onItemClick(int id) {
if (id == -1 && !fromIntro ) {
if( isModified() ) { // TODO: maybe we should also ask if the user presses the "back" button
if( isModified() ) { // as we use "close/ok" buttons instead of a "back" button it is more clear what happens, however, an additional question does not disturb here
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("DiscardChanges", R.string.DiscardChanges));
builder.setPositiveButton(LocaleController.getString("Yes", R.string.Yes), new DialogInterface.OnClickListener() {
@@ -301,7 +301,10 @@ public class AccountSettingsActivity extends BaseFragment implements Notificatio
if( (int)args[0]==1 ) {
if( fromIntro ) {
presentFragment(new DialogsActivity(null), true);
((LaunchActivity)getParentActivity()).drawerLayoutContainer.setAllowOpenDrawer(true, false);
LaunchActivity la = ((LaunchActivity)getParentActivity());
if( la != null ) {
la.drawerLayoutContainer.setAllowOpenDrawer(true, false);
}
}
else {
finishFragment();
@@ -655,7 +655,7 @@ public class ActionBarLayout extends FrameLayout {
if (parentActivity.getCurrentFocus() != null) {
AndroidUtilities.hideKeyboard(parentActivity.getCurrentFocus());
}
boolean needAnimation = !forceWithoutAnimation && parentActivity.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).getBoolean("view_animations", true);
boolean needAnimation = !forceWithoutAnimation && parentActivity.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).getBoolean("view_animations2", true);
final BaseFragment currentFragment = !fragmentsStack.isEmpty() ? fragmentsStack.get(fragmentsStack.size() - 1) : null;
@@ -863,7 +863,7 @@ public class ActionBarLayout extends FrameLayout {
AndroidUtilities.hideKeyboard(parentActivity.getCurrentFocus());
}
setInnerTranslationX(0);
boolean needAnimation = animated && parentActivity.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).getBoolean("view_animations", true);
boolean needAnimation = animated && parentActivity.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).getBoolean("view_animations2", true);
final BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
BaseFragment previousFragment = null;
if (fragmentsStack.size() > 1) {
@@ -49,6 +49,19 @@ public class BaseFragment {
protected boolean swipeBackEnabled = true;
protected boolean hasOwnBackground = false;
// IDs forwarded from startActivityForResult() to onActivityResultFragment()
public final static int
RC0_CHAT_IMAGE_CAPTURE = 0,
RC1_CHAT_PICK = 1,
RC2_CHAT_VIDEO_CAPTURE = 2,
RC10_WALLPAPER_IMAGE_CAPTURE = 10,
RC11_WALLPAPER_PICK = 11,
RC12_PROFILE_RINGTONE_PICKER = 12,
RC13_AVATAR_IMAGE_CAPTURE = 13,
RC14_AVATAR_GET_CONTENT = 14,
RC21_CHAT_PICK_WO_COMPR = 21,
RC500_PHOTO_VIEW = 500;
public BaseFragment() {
classGuid = ConnectionsManager.getInstance().generateClassGuid();
}
@@ -43,10 +43,9 @@ import com.b44t.ui.Components.ChatAttachAlert;
public class Theme {
public static final int ACTION_BAR_COLOR = 0xff415e6b; // also used for the notification icon background
public static final int ACTION_BAR_COLOR = 0xff415e6b; // also used for the notification icon background and as pincode-default-background color, TODO: let player_big_notification/player_small_notification use this color automatically
public static final int ACTION_BAR_PHOTO_VIEWER_COLOR = 0x7f000000;
public static final int ACTION_BAR_MEDIA_PICKER_COLOR = 0xff333333;
public static final int ACTION_BAR_PLAYER_COLOR = 0xffffffff;
public static final int ACTION_BAR_TITLE_COLOR = 0xffffffff;
public static final int ACTION_BAR_SUBTITLE_COLOR = 0xffd5e8f7;
public static final int ACTION_BAR_ACTION_MODE_TEXT_COLOR = 0xff737373;
@@ -69,13 +68,8 @@ public class Theme {
public static final int DIALOGS_DRAFT_TEXT_COLOR = 0xffdd4b39;
public static final int CHAT_BOTTOM_OVERLAY_TEXT_COLOR = 0xff7f7f7f;
public static final int CHAT_GIF_HINT_TEXT_COLOR = 0xffffffff;
public static final int CHAT_EMPTY_VIEW_TEXT_COLOR = 0xffffffff;
public static final int INAPP_PLAYER_PERFORMER_TEXT_COLOR = 0xff2f3438;
public static final int INAPP_PLAYER_TITLE_TEXT_COLOR = 0xff2f3438;
public static final int INAPP_PLAYER_BACKGROUND_COLOR = 0xffffffff;
public static final int STICKERS_SHEET_TITLE_TEXT_COLOR = 0xff212121;
public static final int STICKERS_SHEET_SEND_TEXT_COLOR = 0xff3a8ccf;
public static final int STICKERS_SHEET_ADD_TEXT_COLOR = 0xff3a8ccf;
@@ -83,87 +77,24 @@ public class Theme {
public static final int STICKERS_SHEET_REMOVE_TEXT_COLOR = 0xffcd5a5a;
public static final int MSG_SELECTED_BACKGROUND_COLOR = 0x6633b5e5;
public static final int MSG_WEB_PREVIEW_DURATION_TEXT_COLOR = 0xffffffff;
public static final int MSG_STICKER_NAME_TEXT_COLOR = 0xffffffff;
public static final int MSG_IN_FORDWARDED_NAME_TEXT_COLOR = 0xff3886c7;
public static final int MSG_OUT_FORDWARDED_NAME_TEXT_COLOR = 0xff55ab4f;
public static final int MSG_IN_REPLY_LINE_COLOR = 0xff70b4e8;
public static final int MSG_OUT_REPLY_LINE_COLOR = 0xff88c97b;
public static final int MSG_STICKER_REPLY_LINE_COLOR = 0xffffffff;
public static final int MSG_IN_REPLY_NAME_TEXT_COLOR = 0xff3a8ccf;
public static final int MSG_OUT_REPLY_NAME_TEXT_COLOR = 0xff55ab4f;
public static final int MSG_STICKER_REPLY_NAME_TEXT_COLOR = 0xffffffff;
public static final int MSG_IN_REPLY_MESSAGE_TEXT_COLOR = 0xff000000;
public static final int MSG_OUT_REPLY_MESSAGE_TEXT_COLOR = 0xff000000;
public static final int MSG_IN_REPLY_MEDIA_MESSAGE_TEXT_COLOR = 0xffa1aab3;
public static final int MSG_OUT_REPLY_MEDIA_MESSAGE_TEXT_COLOR = 0xff65b05b;
public static final int MSG_IN_REPLY_MEDIA_MESSAGE_SELETED_TEXT_COLOR = 0xff89b4c1;
public static final int MSG_OUT_REPLY_MEDIA_MESSAGE_SELETED_TEXT_COLOR = 0xff65b05b;
public static final int MSG_STICKER_REPLY_MESSAGE_TEXT_COLOR = 0xffffffff;
public static final int MSG_IN_WEB_PREVIEW_LINE_COLOR = 0xff70b4e8;
public static final int MSG_OUT_WEB_PREVIEW_LINE_COLOR = 0xff88c97b;
public static final int MSG_IN_SITE_NAME_TEXT_COLOR = 0xff3a8ccf;
public static final int MSG_OUT_SITE_NAME_TEXT_COLOR = 0xff55ab4f;
public static final int MSG_IN_CONTACT_NAME_TEXT_COLOR = 0xff4e9ad4;
public static final int MSG_OUT_CONTACT_NAME_TEXT_COLOR = 0xff55ab4f;
public static final int MSG_IN_CONTACT_PHONE_TEXT_COLOR = 0xff2f3438;
public static final int MSG_OUT_CONTACT_PHONE_TEXT_COLOR = 0xff354234;
public static final int MSG_MEDIA_PROGRESS_COLOR = 0xffffffff;
public static final int MSG_IN_AUDIO_PROGRESS_COLOR = 0xffffffff;
public static final int MSG_OUT_AUDIO_PROGRESS_COLOR = 0xffefffde;
public static final int MSG_IN_AUDIO_SELECTED_PROGRESS_COLOR = 0xffe2f8ff;
public static final int MSG_OUT_AUDIO_SELECTED_PROGRESS_COLOR = 0xffd4f5bc;
public static final int MSG_MEDIA_TIME_TEXT_COLOR = 0xffffffff;
public static final int MSG_IN_TIME_TEXT_COLOR = 0xffa1aab3;
public static final int MSG_IN_TIME_N_FWD_TEXT_COLOR = 0xff9ea7b0;
public static final int MSG_OUT_TIME_TEXT_COLOR = 0xff70b15c;
public static final int MSG_IN_TIME_SELECTED_TEXT_COLOR = 0xff89b4c1;
public static final int MSG_OUT_TIME_SELECTED_TEXT_COLOR = 0xff70b15c;
public static final int MSG_IN_AUDIO_PERFORMER_TEXT_COLOR = 0xff2f3438;
public static final int MSG_OUT_AUDIO_PERFORMER_TEXT_COLOR = 0xff354234;
public static final int MSG_IN_AUDIO_TITLE_TEXT_COLOR = 0xff4e9ad4;
public static final int MSG_OUT_AUDIO_TITLE_TEXT_COLOR = 0xff55ab4f;
public static final int MSG_IN_AUDIO_DURATION_TEXT_COLOR = 0xffa1aab3;
public static final int MSG_OUT_AUDIO_DURATION_TEXT_COLOR = 0xff65b05b;
public static final int MSG_IN_AUDIO_DURATION_SELECTED_TEXT_COLOR = 0xff89b4c1;
public static final int MSG_OUT_AUDIO_DURATION_SELECTED_TEXT_COLOR = 0xff65b05b;
public static final int MSG_IN_AUDIO_SEEKBAR_COLOR = 0xffe4eaf0;
public static final int MSG_OUT_AUDIO_SEEKBAR_COLOR = 0xffbbe3ac;
public static final int MSG_IN_AUDIO_SEEKBAR_SELECTED_COLOR = 0xffbcdee8;
public static final int MSG_OUT_AUDIO_SEEKBAR_SELECTED_COLOR = 0xffa9dd96;
public static final int MSG_IN_AUDIO_SEEKBAR_FILL_COLOR = 0xff72b5e8;
public static final int MSG_OUT_AUDIO_SEEKBAR_FILL_COLOR = 0xff78c272;
public static final int MSG_IN_VOICE_SEEKBAR_COLOR = 0xffdee5eb;
public static final int MSG_OUT_VOICE_SEEKBAR_COLOR = 0xffbbe3ac;
public static final int MSG_IN_VOICE_SEEKBAR_SELECTED_COLOR = 0xffbcdee8;
public static final int MSG_OUT_VOICE_SEEKBAR_SELECTED_COLOR = 0xffa9dd96;
public static final int MSG_IN_VOICE_SEEKBAR_FILL_COLOR = 0xff72b5e8;
public static final int MSG_OUT_VOICE_SEEKBAR_FILL_COLOR = 0xff78c272;
public static final int MSG_IN_FILE_PROGRESS_COLOR = 0xffebf0f5;
public static final int MSG_OUT_FILE_PROGRESS_COLOR = 0xffdaf5c3;
public static final int MSG_IN_FILE_PROGRESS_SELECTED_COLOR = 0xffcbeaf6;
public static final int MSG_OUT_FILE_PROGRESS_SELECTED_COLOR = 0xffc5eca7;
public static final int MSG_IN_FILE_NAME_TEXT_COLOR = 0xff4e9ad4;
public static final int MSG_OUT_FILE_NAME_TEXT_COLOR = 0xff55ab4f;
public static final int MSG_IN_FILE_INFO_TEXT_COLOR = 0xffa1aab3;
public static final int MSG_OUT_FILE_INFO_TEXT_COLOR = 0xff65b05b;
public static final int MSG_IN_FILE_INFO_SELECTED_TEXT_COLOR = 0xff89b4c1;
public static final int MSG_OUT_FILE_INFO_SELECTED_TEXT_COLOR = 0xff65b05b;
public static final int MSG_MEDIA_TIME_TEXT_COLOR = 0xffffffff;
public static final int MSG_IN_FILE_BACKGROUND_COLOR = 0xffebf0f5;
public static final int MSG_OUT_FILE_BACKGROUND_COLOR = 0xffdaf5c3;
public static final int MSG_IN_FILE_BACKGROUND_SELECTED_COLOR = 0xffcbeaf6;
public static final int MSG_OUT_FILE_BACKGROUND_SELECTED_COLOR = 0xffc5eca7;
public static final int MSG_IN_VENUE_NAME_TEXT_COLOR = 0xff4e9ad4;
public static final int MSG_OUT_VENUE_NAME_TEXT_COLOR = 0xff55ab4f;
public static final int MSG_IN_VENUE_INFO_TEXT_COLOR = 0xffa1aab3;
public static final int MSG_OUT_VENUE_INFO_TEXT_COLOR = 0xff65b05b;
public static final int MSG_IN_VENUE_INFO_SELECTED_TEXT_COLOR = 0xff89b4c1;
public static final int MSG_OUT_VENUE_INFO_SELECTED_TEXT_COLOR = 0xff65b05b;
public static final int MSG_MEDIA_INFO_TEXT_COLOR = 0xffffffff;
public static final int MSG_TEXT_COLOR = 0xff000000;
public static final int MSG_LINK_TEXT_COLOR = 0xff2678b6;
public static final int MSG_LINK_SELECT_BACKGROUND_COLOR = 0x3362a9e3;
public static final int MSG_TEXT_SELECT_BACKGROUND_COLOR = 0x6662a9e3;
public static final int MSG_DOC_NAME_COLOR = 0xFF3093e0; // similar color as the file-icon
public static final int MSG_AUDIO_NAME_COLOR = 0xFFed824e; // similar color as the audio-icon
public static final int MSG_AUDIO_SEEKBAR_DARK_COLOR = 0xFFf68751; // same color as in audio-icon, also used for the record-button
public static final int MSG_AUDIO_SEEKBAR_LITE_COLOR = 0xFFfbc8af;
public static Drawable backgroundDrawableIn;
public static Drawable backgroundDrawableInSelected;
@@ -183,12 +114,14 @@ public class Theme {
public static Drawable[] cornerOuter = new Drawable[4];
public static Drawable[] cornerInner = new Drawable[4];
public static Drawable shareIconDrawable;
public static Drawable newchatIconDrawable;
public static Drawable[] contactDrawable = new Drawable[2];
public static Drawable[][] fileStatesDrawable = new Drawable[10][2];
public static Drawable[][] photoStatesDrawables = new Drawable[13][2];
public static Drawable[] docMenuDrawable = new Drawable[4];
public static final int INLIST_FILE = 0;
public static final int INLIST_PLAY = 1;
public static final int INLIST_PAUSE = 2;
public static final int INLIST_TRANSP_PLAY = 3;
public static final int INLIST_COUNT = 4;
public static Drawable[] inlistDrawable = new Drawable[INLIST_COUNT];
public static PorterDuffColorFilter colorFilter;
private static int currentColor;
@@ -214,63 +147,12 @@ public class Theme {
timeStickerBackgroundDrawable = context.getResources().getDrawable(R.drawable.phototime2);
systemDrawable = context.getResources().getDrawable(R.drawable.system);
fileStatesDrawable[0][0] = context.getResources().getDrawable(R.drawable.play_g); // self
fileStatesDrawable[0][1] = context.getResources().getDrawable(R.drawable.play_g_s);
fileStatesDrawable[1][0] = context.getResources().getDrawable(R.drawable.pause_g);
fileStatesDrawable[1][1] = context.getResources().getDrawable(R.drawable.pause_g_s);
fileStatesDrawable[2][0] = context.getResources().getDrawable(R.drawable.file_g_load);
fileStatesDrawable[2][1] = context.getResources().getDrawable(R.drawable.file_g_load_s);
fileStatesDrawable[3][0] = context.getResources().getDrawable(R.drawable.file_g);
fileStatesDrawable[3][1] = context.getResources().getDrawable(R.drawable.file_g_s);
fileStatesDrawable[4][0] = context.getResources().getDrawable(R.drawable.file_g_cancel);
fileStatesDrawable[4][1] = context.getResources().getDrawable(R.drawable.file_g_cancel_s);
fileStatesDrawable[5][0] = context.getResources().getDrawable(R.drawable.play_b); // from other = self+5
fileStatesDrawable[5][1] = context.getResources().getDrawable(R.drawable.play_b_s);
fileStatesDrawable[6][0] = context.getResources().getDrawable(R.drawable.pause_b);
fileStatesDrawable[6][1] = context.getResources().getDrawable(R.drawable.pause_b_s);
fileStatesDrawable[7][0] = context.getResources().getDrawable(R.drawable.file_b_load);
fileStatesDrawable[7][1] = context.getResources().getDrawable(R.drawable.file_b_load_s);
fileStatesDrawable[8][0] = context.getResources().getDrawable(R.drawable.file_b);
fileStatesDrawable[8][1] = context.getResources().getDrawable(R.drawable.file_b_s);
fileStatesDrawable[9][0] = context.getResources().getDrawable(R.drawable.file_b_cancel);
fileStatesDrawable[9][1] = context.getResources().getDrawable(R.drawable.file_b_cancel_s);
inlistDrawable[INLIST_FILE] = context.getResources().getDrawable(R.drawable.attach_file_inlist);
inlistDrawable[INLIST_PLAY] = context.getResources().getDrawable(R.drawable.attach_audio_inlist_play);
inlistDrawable[INLIST_TRANSP_PLAY] = context.getResources().getDrawable(R.drawable.video_play);
inlistDrawable[INLIST_PAUSE] = context.getResources().getDrawable(R.drawable.attach_audio_inlist_pause);
photoStatesDrawables[0][0] = context.getResources().getDrawable(R.drawable.photoload);
photoStatesDrawables[0][1] = context.getResources().getDrawable(R.drawable.photoload_pressed);
photoStatesDrawables[1][0] = context.getResources().getDrawable(R.drawable.photocancel);
photoStatesDrawables[1][1] = context.getResources().getDrawable(R.drawable.photocancel_pressed);
photoStatesDrawables[2][0] = context.getResources().getDrawable(R.drawable.photogif);
photoStatesDrawables[2][1] = context.getResources().getDrawable(R.drawable.photogif_pressed);
photoStatesDrawables[3][0] = context.getResources().getDrawable(R.drawable.playvideo);
photoStatesDrawables[3][1] = context.getResources().getDrawable(R.drawable.playvideo_pressed);
//photoStatesDrawables[4] = context.getResources().getDrawable(R.drawable.photopause);
photoStatesDrawables[4][0] = photoStatesDrawables[4][1] = context.getResources().getDrawable(R.drawable.burn);
photoStatesDrawables[5][0] = photoStatesDrawables[5][1] = context.getResources().getDrawable(R.drawable.circle);
photoStatesDrawables[6][0] = photoStatesDrawables[6][1] = context.getResources().getDrawable(R.drawable.photocheck);
photoStatesDrawables[7][0] = context.getResources().getDrawable(R.drawable.photoload_g);
photoStatesDrawables[7][1] = context.getResources().getDrawable(R.drawable.photoload_g_s);
photoStatesDrawables[8][0] = context.getResources().getDrawable(R.drawable.photocancel_g);
photoStatesDrawables[8][1] = context.getResources().getDrawable(R.drawable.photocancel_g_s);
photoStatesDrawables[9][0] = context.getResources().getDrawable(R.drawable.doc_green);
photoStatesDrawables[9][1] = context.getResources().getDrawable(R.drawable.doc_green);
photoStatesDrawables[10][0] = context.getResources().getDrawable(R.drawable.photoload_b);
photoStatesDrawables[10][1] = context.getResources().getDrawable(R.drawable.photoload_b_s);
photoStatesDrawables[11][0] = context.getResources().getDrawable(R.drawable.photocancel_b);
photoStatesDrawables[11][1] = context.getResources().getDrawable(R.drawable.photocancel_b_s);
photoStatesDrawables[12][0] = context.getResources().getDrawable(R.drawable.doc_blue);
photoStatesDrawables[12][1] = context.getResources().getDrawable(R.drawable.doc_blue_s);
docMenuDrawable[0] = context.getResources().getDrawable(R.drawable.doc_actions_b);
docMenuDrawable[1] = context.getResources().getDrawable(R.drawable.doc_actions_g);
docMenuDrawable[2] = context.getResources().getDrawable(R.drawable.doc_actions_b_s);
docMenuDrawable[3] = context.getResources().getDrawable(R.drawable.video_actions);
contactDrawable[0] = context.getResources().getDrawable(R.drawable.contact_blue);
contactDrawable[1] = context.getResources().getDrawable(R.drawable.contact_green);
shareIconDrawable = context.getResources().getDrawable(R.drawable.ic_ab_reply);
newchatIconDrawable = context.getResources().getDrawable(R.drawable.ic_ab_reply);
cornerOuter[0] = context.getResources().getDrawable(R.drawable.corner_out_tl);
cornerOuter[1] = context.getResources().getDrawable(R.drawable.corner_out_tr);
@@ -303,7 +185,7 @@ public class Theme {
attachButtonDrawables[ChatAttachAlert.ATTACH_BUTTON_IDX_MUSIC] = context.getResources().getDrawable(R.drawable.attach_audio_states);
attachButtonDrawables[ChatAttachAlert.ATTACH_BUTTON_IDX_FILE] = context.getResources().getDrawable(R.drawable.attach_file_states);
attachButtonDrawables[ChatAttachAlert.ATTACH_BUTTON_IDX_CONTACT] = context.getResources().getDrawable(R.drawable.attach_contact_states);
attachButtonDrawables[ChatAttachAlert.ATTACH_BUTTON_IDX_LOCATION] = context.getResources().getDrawable(R.drawable.attach_location_states);
attachButtonDrawables[ChatAttachAlert.ATTACH_BUTTON_IDX_EMPTY] = context.getResources().getDrawable(R.drawable.attach_empty_states);
attachButtonDrawables[ChatAttachAlert.ATTACH_BUTTON_IDX_SENDSELECTED]= context.getResources().getDrawable(R.drawable.attach_hide_states);
}
}
@@ -313,7 +195,6 @@ public class Theme {
}
public static Drawable createBarSelectorDrawable(int color, boolean masked) {
Drawable drawable;
if (Build.VERSION.SDK_INT >= 21) {
Drawable maskDrawable = null;
if (masked) {
@@ -30,7 +30,6 @@ import android.widget.BaseAdapter;
import com.b44t.messenger.AndroidUtilities;
import com.b44t.messenger.LocaleController;
import com.b44t.messenger.MessagesController;
import com.b44t.messenger.R;
import com.b44t.messenger.UserConfig;
import com.b44t.ui.Cells.DrawerActionCell;
@@ -99,7 +98,7 @@ public class DrawerLayoutAdapter extends BaseAdapter {
if (view == null) {
view = new DrawerProfileCell(mContext);
}
((DrawerProfileCell) view).setUser(MessagesController.getInstance().getUser(UserConfig.getClientUserId()));
((DrawerProfileCell) view).updateUserName();
} else if (type == typeEmpty) {
if (view == null) {
view = new EmptyCell(mContext, AndroidUtilities.dp(8));
@@ -1,483 +0,0 @@
/*******************************************************************************
*
* Messenger Android Frontend
* (C) 2013-2016 Nikolai Kudashov
* (C) 2017 Björn Petersen
* Contact: r10s@b44t.com, http://b44t.com
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/ .
*
******************************************************************************/
package com.b44t.ui;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.b44t.messenger.AndroidUtilities;
import com.b44t.messenger.ImageLoader;
import com.b44t.messenger.MediaController;
import com.b44t.messenger.MessageObject;
import com.b44t.messenger.NotificationCenter;
import com.b44t.messenger.audioinfo.AudioInfo;
import com.b44t.messenger.FileLoader;
import com.b44t.messenger.R;
import com.b44t.messenger.TLRPC;
import com.b44t.ui.ActionBar.ActionBar;
import com.b44t.ui.ActionBar.BaseFragment;
import com.b44t.ui.ActionBar.Theme;
import com.b44t.ui.Components.LayoutHelper;
import com.b44t.ui.Components.LineProgressView;
import java.io.File;
public class AudioPlayerActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, MediaController.FileDownloadProgressListener {
//private MessageObject lastMessageObject;
private ImageView placeholder;
private ImageView playButton;
private ImageView nextButton;
private ImageView prevButton;
private ImageView shuffleButton;
private LineProgressView progressView;
private ImageView repeatButton;
private ImageView[] buttons = new ImageView[5];
private TextView durationTextView;
private TextView timeTextView;
private SeekBarView seekBarView;
private int TAG;
private String lastTimeString;
private class SeekBarView extends FrameLayout {
private Paint innerPaint1;
private Paint outerPaint1;
private int thumbWidth;
private int thumbHeight;
public int thumbX = 0;
public int thumbDX = 0;
private boolean pressed = false;
public SeekBarView(Context context) {
super(context);
setWillNotDraw(false);
innerPaint1 = new Paint(Paint.ANTI_ALIAS_FLAG);
innerPaint1.setColor(0x19000000);
outerPaint1 = new Paint(Paint.ANTI_ALIAS_FLAG);
outerPaint1.setColor(0xff23afef);
thumbWidth = AndroidUtilities.dp(24);
thumbHeight = AndroidUtilities.dp(24);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return onTouch(ev);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return onTouch(event);
}
boolean onTouch(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
getParent().requestDisallowInterceptTouchEvent(true);
int additionWidth = (getMeasuredHeight() - thumbWidth) / 2;
if (thumbX - additionWidth <= ev.getX() && ev.getX() <= thumbX + thumbWidth + additionWidth && ev.getY() >= 0 && ev.getY() <= getMeasuredHeight()) {
pressed = true;
thumbDX = (int)(ev.getX() - thumbX);
invalidate();
return true;
}
} else if (ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_CANCEL) {
if (pressed) {
if (ev.getAction() == MotionEvent.ACTION_UP) {
onSeekBarDrag((float) thumbX / (float) (getMeasuredWidth() - thumbWidth));
}
pressed = false;
invalidate();
return true;
}
} else if (ev.getAction() == MotionEvent.ACTION_MOVE) {
if (pressed) {
thumbX = (int)(ev.getX() - thumbDX);
if (thumbX < 0) {
thumbX = 0;
} else if (thumbX > getMeasuredWidth() - thumbWidth) {
thumbX = getMeasuredWidth() - thumbWidth;
}
invalidate();
return true;
}
}
return false;
}
public void setProgress(float progress) {
int newThumbX = (int)Math.ceil((getMeasuredWidth() - thumbWidth) * progress);
if (thumbX != newThumbX) {
thumbX = newThumbX;
if (thumbX < 0) {
thumbX = 0;
} else if (thumbX > getMeasuredWidth() - thumbWidth) {
thumbX = getMeasuredWidth() - thumbWidth;
}
invalidate();
}
}
public boolean isDragging() {
return pressed;
}
@Override
protected void onDraw(Canvas canvas) {
int y = (getMeasuredHeight() - thumbHeight) / 2;
canvas.drawRect(thumbWidth / 2, getMeasuredHeight() / 2 - AndroidUtilities.dp(1), getMeasuredWidth() - thumbWidth / 2, getMeasuredHeight() / 2 + AndroidUtilities.dp(1), innerPaint1);
canvas.drawRect(thumbWidth / 2, getMeasuredHeight() / 2 - AndroidUtilities.dp(1), thumbWidth / 2 + thumbX, getMeasuredHeight() / 2 + AndroidUtilities.dp(1), outerPaint1);
canvas.drawCircle(thumbX + thumbWidth / 2, y + thumbHeight / 2, AndroidUtilities.dp(pressed ? 8 : 6), outerPaint1);
}
}
@Override
public boolean onFragmentCreate() {
TAG = MediaController.getInstance().generateObserverTag();
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidReset);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioPlayStateChanged);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidStarted);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioProgressDidChanged);
return super.onFragmentCreate();
}
@Override
public void onFragmentDestroy() {
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioDidReset);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioPlayStateChanged);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioDidStarted);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioProgressDidChanged);
MediaController.getInstance().removeLoadingFileObserver(this);
super.onFragmentDestroy();
}
@Override
public View createView(Context context) {
FrameLayout frameLayout = new FrameLayout(context);
frameLayout.setBackgroundColor(0xfff0f0f0);
frameLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
fragmentView = frameLayout;
actionBar.setBackgroundColor(Theme.ACTION_BAR_PLAYER_COLOR);
actionBar.setBackButtonImage(R.drawable.pl_back);
actionBar.setItemsBackgroundColor(Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR);
/*if (!AndroidUtilities.isTablet()) {
actionBar.showActionModeTop();
}*/
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
placeholder = new ImageView(context);
frameLayout.addView(placeholder, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 66));
View shadow = new View(context);
shadow.setBackgroundResource(R.drawable.header_shadow_reverse);
frameLayout.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 96));
FrameLayout seekBarContainer = new FrameLayout(context);
seekBarContainer.setBackgroundColor(0xe5ffffff);
frameLayout.addView(seekBarContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 30, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 66));
timeTextView = new TextView(context);
timeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
timeTextView.setTextColor(0xff19a7e8);
timeTextView.setGravity(Gravity.CENTER);
timeTextView.setText("0:00");
seekBarContainer.addView(timeTextView, LayoutHelper.createFrame(44, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
durationTextView = new TextView(context);
durationTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
durationTextView.setTextColor(0xff8a8a8a);
durationTextView.setGravity(Gravity.CENTER);
durationTextView.setText("3:00");
seekBarContainer.addView(durationTextView, LayoutHelper.createFrame(44, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT));
seekBarView = new SeekBarView(context);
seekBarContainer.addView(seekBarView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 32, 0, 32, 0));
progressView = new LineProgressView(context);
progressView.setVisibility(View.INVISIBLE);
progressView.setBackgroundColor(0x19000000);
progressView.setProgressColor(0xff23afef);
seekBarContainer.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 2, Gravity.CENTER_VERTICAL | Gravity.LEFT, 44, 0, 44, 0));
FrameLayout bottomView = new FrameLayout(context) {
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
int dist = ((right - left) - AndroidUtilities.dp(30 + 48 * 5)) / 4;
for (int a = 0; a < 5; a++) {
int l = AndroidUtilities.dp(15 + 48 * a) + dist * a;
int t = AndroidUtilities.dp(9);
buttons[a].layout(l, t, l + buttons[a].getMeasuredWidth(), t + buttons[a].getMeasuredHeight());
}
}
};
bottomView.setBackgroundColor(0xffffffff);
frameLayout.addView(bottomView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 66, Gravity.BOTTOM | Gravity.LEFT));
buttons[0] = repeatButton = new ImageView(context);
repeatButton.setScaleType(ImageView.ScaleType.CENTER);
bottomView.addView(repeatButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP));
repeatButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MediaController.getInstance().toggleRepeatMode();
updateRepeatButton();
}
});
buttons[1] = prevButton = new ImageView(context);
prevButton.setScaleType(ImageView.ScaleType.CENTER);
prevButton.setImageResource(R.drawable.player_prev_states);
bottomView.addView(prevButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP));
prevButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MediaController.getInstance().playPreviousMessage();
}
});
buttons[2] = playButton = new ImageView(context);
playButton.setScaleType(ImageView.ScaleType.CENTER);
playButton.setImageResource(R.drawable.player_play_states);
bottomView.addView(playButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP));
playButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (MediaController.getInstance().isDownloadingCurrentMessage()) {
return;
}
if (MediaController.getInstance().isAudioPaused()) {
MediaController.getInstance().playAudio(MediaController.getInstance().getPlayingMessageObject());
} else {
MediaController.getInstance().pauseAudio(MediaController.getInstance().getPlayingMessageObject());
}
}
});
buttons[3] = nextButton = new ImageView(context);
nextButton.setScaleType(ImageView.ScaleType.CENTER);
nextButton.setImageResource(R.drawable.player_next_states);
bottomView.addView(nextButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP));
nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MediaController.getInstance().playNextMessage();
}
});
buttons[4] = shuffleButton = new ImageView(context);
shuffleButton.setScaleType(ImageView.ScaleType.CENTER);
bottomView.addView(shuffleButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP));
shuffleButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MediaController.getInstance().toggleShuffleMusic();
updateShuffleButton();
}
});
updateTitle(false);
updateRepeatButton();
updateShuffleButton();
return frameLayout;
}
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.audioDidStarted || id == NotificationCenter.audioPlayStateChanged || id == NotificationCenter.audioDidReset) {
updateTitle(id == NotificationCenter.audioDidReset && (Boolean) args[1]);
} else if (id == NotificationCenter.audioProgressDidChanged) {
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
if (messageObject != null && messageObject.isMusic()) {
updateProgress(messageObject);
}
}
}
@Override
public void onFailedDownload(String fileName) {
}
@Override
public void onSuccessDownload(String fileName) {
}
@Override
public void onProgressDownload(String fileName, float progress) {
progressView.setProgress(progress, true);
}
@Override
public void onProgressUpload(String fileName, float progress, boolean isEncrypted) {
}
@Override
public int getObserverTag() {
return TAG;
}
private void onSeekBarDrag(float progress) {
MediaController.getInstance().seekToProgress(MediaController.getInstance().getPlayingMessageObject(), progress);
}
private void updateShuffleButton() {
if (MediaController.getInstance().isShuffleMusic()) {
shuffleButton.setImageResource(R.drawable.pl_shuffle_active);
} else {
shuffleButton.setImageResource(R.drawable.pl_shuffle);
}
}
private void updateRepeatButton() {
int mode = MediaController.getInstance().getRepeatMode();
if (mode == 0) {
repeatButton.setImageResource(R.drawable.pl_repeat);
} else if (mode == 1) {
repeatButton.setImageResource(R.drawable.pl_repeat_active);
} else if (mode == 2) {
repeatButton.setImageResource(R.drawable.pl_repeat1_active);
}
}
private void updateProgress(MessageObject messageObject) {
if (seekBarView != null) {
if (!seekBarView.isDragging()) {
seekBarView.setProgress(messageObject.audioProgress);
}
String timeString = String.format("%d:%02d", messageObject.audioProgressSec / 60, messageObject.audioProgressSec % 60);
if (lastTimeString == null || lastTimeString != null && !lastTimeString.equals(timeString)) {
lastTimeString = timeString;
timeTextView.setText(timeString);
}
}
}
private void checkIfMusicDownloaded(MessageObject messageObject) {
File cacheFile = null;
if (messageObject.messageOwner.attachPath != null && messageObject.messageOwner.attachPath.length() > 0) {
cacheFile = new File(messageObject.messageOwner.attachPath);
if(!cacheFile.exists()) {
cacheFile = null;
}
}
if (cacheFile == null) {
cacheFile = FileLoader.getPathToMessage(messageObject.messageOwner);
}
if (!cacheFile.exists()) {
String fileName = messageObject.getFileName();
MediaController.getInstance().addLoadingFileObserver(fileName, this);
Float progress = ImageLoader.getInstance().getFileProgress(fileName);
progressView.setProgress(progress != null ? progress : 0, false);
progressView.setVisibility(View.VISIBLE);
seekBarView.setVisibility(View.INVISIBLE);
playButton.setEnabled(false);
} else {
MediaController.getInstance().removeLoadingFileObserver(this);
progressView.setVisibility(View.INVISIBLE);
seekBarView.setVisibility(View.VISIBLE);
playButton.setEnabled(true);
}
}
private void updateTitle(boolean shutdown) {
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
if (messageObject == null && shutdown || messageObject != null && !messageObject.isMusic()) {
if (parentLayout != null && !parentLayout.fragmentsStack.isEmpty() && parentLayout.fragmentsStack.get(parentLayout.fragmentsStack.size() - 1) == this) {
finishFragment();
} else {
removeSelfFromStack();
}
} else {
if (messageObject == null) {
return;
}
checkIfMusicDownloaded(messageObject);
updateProgress(messageObject);
if (MediaController.getInstance().isAudioPaused()) {
playButton.setImageResource(R.drawable.player_play_states);
} else {
playButton.setImageResource(R.drawable.player_pause_states);
}
if (actionBar != null) {
actionBar.setTitle(messageObject.getMusicTitle());
actionBar.getTitleTextView().setTextColor(0xff212121);
actionBar.setSubtitle(messageObject.getMusicAuthor());
actionBar.getSubtitleTextView().setTextColor(0xff8a8a8a);
}
AudioInfo audioInfo = MediaController.getInstance().getAudioInfo();
if (audioInfo != null && audioInfo.getCover() != null) {
placeholder.setImageBitmap(audioInfo.getCover());
placeholder.setPadding(0, 0, 0, 0);
placeholder.setScaleType(ImageView.ScaleType.CENTER_CROP);
} else {
placeholder.setImageResource(R.drawable.nocover);
placeholder.setPadding(0, 0, 0, AndroidUtilities.dp(30));
placeholder.setScaleType(ImageView.ScaleType.CENTER);
}
if (durationTextView != null) {
int duration = 0;
TLRPC.Document document = messageObject.getDocument();
if (document != null) {
for (int a = 0; a < document.attributes.size(); a++) {
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
duration = attribute.duration;
break;
}
}
}
durationTextView.setText(duration != 0 ? String.format("%d:%02d", duration / 60, duration % 60) : "-:--");
}
}
}
}
@@ -89,7 +89,7 @@ public class AudioSelectActivity extends BaseFragment implements NotificationCen
super.onFragmentDestroy();
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioDidReset);
if (playingAudio != null && MediaController.getInstance().isPlayingAudio(playingAudio)) {
if (playingAudio != null && MediaController.getInstance().isMessageOnAir(playingAudio)) {
MediaController.getInstance().cleanupPlayer(true, true);
}
}
@@ -207,8 +207,7 @@ public class AudioSelectActivity extends BaseFragment implements NotificationCen
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Media.ALBUM
MediaStore.Audio.Media.DURATION
};
final ArrayList<MediaController.AudioEntry> newAudioEntries = new ArrayList<>();
@@ -223,7 +222,6 @@ public class AudioSelectActivity extends BaseFragment implements NotificationCen
audioEntry.title = cursor.getString(2);
audioEntry.path = cursor.getString(3);
audioEntry.duration = (int) (cursor.getLong(4) / 1000);
audioEntry.genre = cursor.getString(5);
File file = new File(audioEntry.path);
@@ -254,14 +252,13 @@ public class AudioSelectActivity extends BaseFragment implements NotificationCen
attributeAudio.duration = audioEntry.duration;
attributeAudio.title = audioEntry.title;
attributeAudio.performer = audioEntry.author;
attributeAudio.flags |= 3;
message.media.document.attributes.add(attributeAudio);
TLRPC.TL_documentAttributeFilename fileName = new TLRPC.TL_documentAttributeFilename();
fileName.file_name = file.getName();
message.media.document.attributes.add(fileName);
audioEntry.messageObject = new MessageObject(message, null, false);
audioEntry.messageObject = new MessageObject(message, false);
newAudioEntries.add(audioEntry);
id--;
@@ -335,7 +332,7 @@ public class AudioSelectActivity extends BaseFragment implements NotificationCen
});
}
MediaController.AudioEntry audioEntry = audioEntries.get(i);
((AudioCell) view).setAudio(audioEntries.get(i), i != audioEntries.size() - 1, selectedAudios.containsKey(audioEntry.id));
((AudioCell) view).setAudio(audioEntries.get(i), selectedAudios.containsKey(audioEntry.id));
return view;
}
@@ -36,6 +36,7 @@ import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.TextView;
import com.b44t.messenger.ApplicationLoader;
import com.b44t.messenger.LocaleController;
import com.b44t.messenger.MrContact;
import com.b44t.messenger.MrMailbox;
@@ -81,7 +82,7 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("BlockedUsers", R.string.BlockedUsers));
actionBar.setTitle(ApplicationLoader.applicationContext.getString(R.string.BlockedContacts));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
@@ -215,110 +215,6 @@ public class CacheControlActivity extends BaseFragment {
return size;
}
/*
private void cleanupFolders() {
final ProgressDialog progressDialog = new ProgressDialog(getParentActivity());
progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setCancelable(false);
progressDialog.show();
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
public void run() {
boolean imagesCleared = false;
for (int a = 0; a < 6; a++) {
if (!clear[a]) {
continue;
}
int type = -1;
int documentsMusicType = 0;
if (a == 0) {
type = FileLoader.MEDIA_DIR_IMAGE;
} else if (a == 1) {
type = FileLoader.MEDIA_DIR_VIDEO;
} else if (a == 2) {
type = FileLoader.MEDIA_DIR_DOCUMENT;
documentsMusicType = 1;
} else if (a == 3) {
type = FileLoader.MEDIA_DIR_DOCUMENT;
documentsMusicType = 2;
} else if (a == 4) {
type = FileLoader.MEDIA_DIR_AUDIO;
} else if (a == 5) {
type = FileLoader.MEDIA_DIR_CACHE;
}
if (type == -1) {
continue;
}
File file = FileLoader.getInstance().checkDirectory(type);
if (file != null) {
try {
File[] array = file.listFiles();
if (array != null) {
for (int b = 0; b < array.length; b++) {
String name = array[b].getName().toLowerCase();
if (documentsMusicType == 1 || documentsMusicType == 2) {
if (name.endsWith(".mp3") || name.endsWith(".m4a")) {
if (documentsMusicType == 1) {
continue;
}
} else if (documentsMusicType == 2) {
continue;
}
}
if (name.equals(".nomedia")) {
continue;
}
if (array[b].isFile()) {
array[b].delete();
}
}
}
} catch (Throwable e) {
FileLog.e("messenger", e);
}
}
if (type == FileLoader.MEDIA_DIR_CACHE) {
cacheSize = getDirectorySize(FileLoader.getInstance().checkDirectory(FileLoader.MEDIA_DIR_CACHE), documentsMusicType);
imagesCleared = true;
} else if (type == FileLoader.MEDIA_DIR_AUDIO) {
audioSize = getDirectorySize(FileLoader.getInstance().checkDirectory(FileLoader.MEDIA_DIR_AUDIO), documentsMusicType);
} else if (type == FileLoader.MEDIA_DIR_DOCUMENT) {
if (documentsMusicType == 1) {
documentsSize = getDirectorySize(FileLoader.getInstance().checkDirectory(FileLoader.MEDIA_DIR_DOCUMENT), documentsMusicType);
} else {
musicSize = getDirectorySize(FileLoader.getInstance().checkDirectory(FileLoader.MEDIA_DIR_DOCUMENT), documentsMusicType);
}
} else if (type == FileLoader.MEDIA_DIR_IMAGE) {
imagesCleared = true;
photoSize = getDirectorySize(FileLoader.getInstance().checkDirectory(FileLoader.MEDIA_DIR_IMAGE), documentsMusicType);
} else if (type == FileLoader.MEDIA_DIR_VIDEO) {
videoSize = getDirectorySize(FileLoader.getInstance().checkDirectory(FileLoader.MEDIA_DIR_VIDEO), documentsMusicType);
}
}
final boolean imagesClearedFinal = imagesCleared;
totalSize = cacheSize + videoSize + audioSize + photoSize + documentsSize + musicSize;
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if (imagesClearedFinal) {
ImageLoader.getInstance().clearMemory();
}
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e("messenger", e);
}
}
});
}
});
}
*/
@Override
public View createView(final Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
@@ -49,12 +49,10 @@ public class AudioCell extends FrameLayout {
private ImageView playButton;
private TextView titleTextView;
private TextView authorTextView;
private TextView genreTextView;
private TextView timeTextView;
private CheckBox checkBox;
private MediaController.AudioEntry audioEntry;
private boolean needDivider;
private static Paint paint;
private AudioCellDelegate delegate;
@@ -79,14 +77,12 @@ public class AudioCell extends FrameLayout {
@Override
public void onClick(View v) {
if (audioEntry != null) {
if (MediaController.getInstance().isPlayingAudio(audioEntry.messageObject) && !MediaController.getInstance().isAudioPaused()) {
MediaController.getInstance().pauseAudio(audioEntry.messageObject);
playButton.setImageResource(R.drawable.audiosend_play);
if (MediaController.getInstance().isMessageOnAir(audioEntry.messageObject) && !MediaController.getInstance().isAudioPaused()) {
MediaController.getInstance().stopAudio();
playButton.setImageResource(R.drawable.attach_audio_inlist_play);
} else {
ArrayList<MessageObject> arrayList = new ArrayList<>();
arrayList.add(audioEntry.messageObject);
if (MediaController.getInstance().setPlaylist(arrayList, audioEntry.messageObject)) {
playButton.setImageResource(R.drawable.audiosend_pause);
if (MediaController.getInstance().playAudio(audioEntry.messageObject)) {
playButton.setImageResource(R.drawable.attach_audio_inlist_pause);
if (delegate != null) {
delegate.startedPlayingAudio(audioEntry.messageObject);
}
@@ -106,16 +102,6 @@ public class AudioCell extends FrameLayout {
titleTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
addView(titleTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 50 : 72, 7, LocaleController.isRTL ? 72 : 50, 0));
genreTextView = new TextView(context);
genreTextView.setTextColor(0xff8a8a8a);
genreTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
genreTextView.setLines(1);
genreTextView.setMaxLines(1);
genreTextView.setSingleLine(true);
genreTextView.setEllipsize(TextUtils.TruncateAt.END);
genreTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
addView(genreTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 50 : 72, 28, LocaleController.isRTL ? 72 : 50, 0));
authorTextView = new TextView(context);
authorTextView.setTextColor(0xff8a8a8a);
authorTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
@@ -124,40 +110,43 @@ public class AudioCell extends FrameLayout {
authorTextView.setSingleLine(true);
authorTextView.setEllipsize(TextUtils.TruncateAt.END);
authorTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
addView(authorTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 50 : 72, 44, LocaleController.isRTL ? 72 : 50, 0));
addView(authorTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 50 : 72, 28, LocaleController.isRTL ? 72 : 50, 0));
timeTextView = new TextView(context);
timeTextView.setTextColor(0xff999999);
timeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
timeTextView.setTextColor(0xff8a8a8a);
timeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
timeTextView.setLines(1);
timeTextView.setMaxLines(1);
timeTextView.setSingleLine(true);
timeTextView.setEllipsize(TextUtils.TruncateAt.END);
timeTextView.setGravity((LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP);
addView(timeTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP, LocaleController.isRTL ? 18 : 0, 11, LocaleController.isRTL ? 0 : 18, 0));
timeTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
addView(timeTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 50 : 72, 44, LocaleController.isRTL ? 72 : 50, 0));
checkBox = new CheckBox(context, R.drawable.round_check2);
checkBox.setVisibility(VISIBLE);
checkBox.setColor(0xff29b6f7);
addView(checkBox, LayoutHelper.createFrame(22, 22, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP, LocaleController.isRTL ? 18 : 0, 39, LocaleController.isRTL ? 0 : 18, 0));
addView(checkBox, LayoutHelper.createFrame(
22, // width
22, // height
(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, // gravity
LocaleController.isRTL ? 0 : 44, // marginLeft
39, // marginTop
LocaleController.isRTL ? 44 : 0, // marginRight
0)); // marginBottom
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(72) + (needDivider ? 1 : 0), MeasureSpec.EXACTLY));
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(72), MeasureSpec.EXACTLY));
}
public void setAudio(MediaController.AudioEntry entry, boolean divider, boolean checked) {
public void setAudio(MediaController.AudioEntry entry, boolean checked) {
audioEntry = entry;
titleTextView.setText(audioEntry.title);
genreTextView.setText(audioEntry.genre);
authorTextView.setText(audioEntry.author);
timeTextView.setText(String.format("%d:%02d", audioEntry.duration / 60, audioEntry.duration % 60));
playButton.setImageResource(MediaController.getInstance().isPlayingAudio(audioEntry.messageObject) && !MediaController.getInstance().isAudioPaused() ? R.drawable.audiosend_pause : R.drawable.audiosend_play);
needDivider = divider;
setWillNotDraw(!divider);
playButton.setImageResource(MediaController.getInstance().isMessageOnAir(audioEntry.messageObject) && !MediaController.getInstance().isAudioPaused() ? R.drawable.attach_audio_inlist_pause : R.drawable.attach_audio_inlist_play);
checkBox.setChecked(checked, false);
}
@@ -173,11 +162,4 @@ public class AudioCell extends FrameLayout {
public MediaController.AudioEntry getAudioEntry() {
return audioEntry;
}
@Override
protected void onDraw(Canvas canvas) {
if (needDivider) {
canvas.drawLine(AndroidUtilities.dp(72), getHeight() - 1, getWidth(), getHeight() - 1, paint);
}
}
}
@@ -131,7 +131,7 @@ public class ChatActionCell extends BaseCell {
textY = AndroidUtilities.dp(7);
textXLeft = (width - textLayout.getWidth()) / 2;
}
setMeasuredDimension(width, textHeight + AndroidUtilities.dp(14 + (currentMessageObject.type == 11 ? 70 : 0)));
setMeasuredDimension(width, textHeight + AndroidUtilities.dp(14 + 0));
}
private int findMaxWidthAroundLine(int line) {
File diff suppressed because it is too large Load Diff
@@ -51,7 +51,7 @@ public class ChatUnreadCell extends FrameLayout {
textView = new TextView(context);
textView.setPadding(0, 0, 0, AndroidUtilities.dp(1));
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, MessagesController.getInstance().fontSize-2);
textView.setTextColor(Theme.MSG_IN_TIME_TEXT_COLOR);
textView.setTextColor(Theme.MSG_IN_TIME_N_FWD_TEXT_COLOR);
textView.setTypeface(Typeface.DEFAULT_BOLD);
addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
}
@@ -62,7 +62,7 @@ public class ContextLinkCell extends View implements MediaController.FileDownloa
private final static int DOCUMENT_ATTACH_TYPE_NONE = 0;
private final static int DOCUMENT_ATTACH_TYPE_DOCUMENT = 1;
private final static int DOCUMENT_ATTACH_TYPE_GIF = 2;
private final static int DOCUMENT_ATTACH_TYPE_AUDIO = 3;
private final static int DOCUMENT_ATTACH_TYPE_VOICE = 3;
private final static int DOCUMENT_ATTACH_TYPE_VIDEO = 4;
private final static int DOCUMENT_ATTACH_TYPE_MUSIC = 5;
private final static int DOCUMENT_ATTACH_TYPE_STICKER = 6;
@@ -390,7 +390,7 @@ public class ContextLinkCell extends View implements MediaController.FileDownloa
}
private Drawable getDrawableForCurrentState() {
return buttonState == 1 ? Theme.photoStatesDrawables[5][0] : null;
return buttonState == 1 ? Theme.inlistDrawable[Theme.INLIST_FILE] : null;
}
public void updateButtonState(boolean animated) {
@@ -80,18 +80,16 @@ public class DialogCell extends BaseCell {
private long currentDialogId;
private final boolean isDialogCell = true; // if it is no dialog cell, it is a search cell ...
private int unreadCount;
private boolean lastUnreadState;
private int lastSendState;
private boolean dialogMuted;
private MessageObject message;
private final MessageObject message = null;
private int index;
private ImageReceiver avatarImage;
private AvatarDrawable avatarDrawable;
private TLRPC.User user = null;
private TLRPC.Chat chat = null;
private CharSequence lastPrintString = null;
private final Object user = null;
private final Object chat = null;
public boolean useSeparator = false;
@@ -291,18 +289,18 @@ public class DialogCell extends BaseCell {
{
checkMessage = false;
String mess = m_summary.getText();
String mess = m_summary.getText2();
if (mess.length() > 150) {
mess = mess.substring(0, 150);
}
String title = m_summary.getTitle();
String title = m_summary.getText1();
if( !title.isEmpty() )
{
int title_meaning = m_summary.getTitleMeaning();
int title_meaning = m_summary.getText1Meaning();
int title_color = Theme.DIALOGS_NAME_TEXT_COLOR;
switch( title_meaning ) {
case MrPoortext.MR_TITLE_SELF: title_color = Theme.DIALOGS_SELF_TEXT_COLOR; break;
case MrPoortext.MR_TITLE_DRAFT: title_color = Theme.DIALOGS_DRAFT_TEXT_COLOR; break;
case MrPoortext.MR_TEXT1_SELF: title_color = Theme.DIALOGS_SELF_TEXT_COLOR; break;
case MrPoortext.MR_TEXT1_DRAFT: title_color = Theme.DIALOGS_DRAFT_TEXT_COLOR; break;
}
SpannableStringBuilder stringBuilder = SpannableStringBuilder.valueOf(String.format("%s: %s", title, mess));
stringBuilder.setSpan(new ForegroundColorSpan(title_color), 0, title.length() + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
@@ -534,7 +532,7 @@ public class DialogCell extends BaseCell {
public void checkCurrentDialogIndex() {
if (index < MrMailbox.m_currChatlist.getCnt()) { // EDIT BY MR - was: index < getDialogsArray().size()
TLRPC.TL_dialog dialog = MrMailbox.m_currChatlist.get_TLRPC_TL_dialog(index); // EDIT BY MR - was: getDialogsArray().get(index);
MessageObject newMessageObject = MessagesController.getInstance().dialogMessage.get(dialog.id);
final MessageObject newMessageObject = null;
if (currentDialogId != dialog.id ||
message != null && message.getId() != dialog.top_message ||
unreadCount != dialog.unread_count ||
@@ -553,14 +551,6 @@ public class DialogCell extends BaseCell {
if (mask != 0) {
boolean continueUpdate = false;
if (isDialogCell) {
if ((mask & MessagesController.UPDATE_MASK_USER_PRINT) != 0) {
CharSequence printString = MessagesController.getInstance().printingStrings.get(currentDialogId);
if (lastPrintString != null && printString == null || lastPrintString == null && printString != null || lastPrintString != null && printString != null && !lastPrintString.equals(printString)) {
continueUpdate = true;
}
}
}
if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_AVATAR) != 0) {
if (chat == null) {
continueUpdate = true;
@@ -581,18 +571,6 @@ public class DialogCell extends BaseCell {
continueUpdate = true;
}
}
if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_READ_DIALOG_MESSAGE) != 0) {
if (message != null && lastUnreadState != message.isUnread()) {
lastUnreadState = message.isUnread();
continueUpdate = true;
} else if (isDialogCell) {
TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict.get(currentDialogId);
if (dialog != null && unreadCount != dialog.unread_count) {
unreadCount = dialog.unread_count;
continueUpdate = true;
}
}
}
if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_SEND_STATE) != 0) {
if (message != null && lastSendState != message.messageOwner.send_state) {
lastSendState = message.messageOwner.send_state;
@@ -606,10 +584,10 @@ public class DialogCell extends BaseCell {
}
dialogMuted = isDialogCell && MessagesController.getInstance().isDialogMuted(currentDialogId);
user = null;
chat = null;
//user = null;
//chat = null;
int lower_id = (int)currentDialogId;
/*int lower_id = (int)currentDialogId;
int high_id = (int)(currentDialogId >> 32);
if (lower_id != 0) {
if (high_id == 1) {
@@ -621,7 +599,7 @@ public class DialogCell extends BaseCell {
user = MessagesController.getInstance().getUser(lower_id);
}
}
}
}*/
ContactsController.setupAvatar(this, avatarImage, avatarDrawable, null, m_mrChat);
@@ -55,18 +55,15 @@ public class DrawerProfileCell extends FrameLayout {
private TextView nameTextView;
private TextView subtitleTextView;
private ImageView shadowView;
private Rect srcRect = new Rect();
private Rect destRect = new Rect();
private Paint paint = new Paint();
private int currentColor;
public DrawerProfileCell(Context context) {
super(context);
setBackgroundColor(Theme.ACTION_BAR_COLOR);
shadowView = new ImageView(context);
shadowView.setVisibility(INVISIBLE);
ImageView shadowView = new ImageView(context);
shadowView.setScaleType(ImageView.ScaleType.FIT_XY);
shadowView.setImageResource(R.drawable.bottom_shadow);
addView(shadowView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 100/*EDIT BY MR, was 70*/, Gravity.LEFT | Gravity.BOTTOM));
@@ -88,12 +85,13 @@ public class DrawerProfileCell extends FrameLayout {
subtitleTextView.setMaxLines(1);
subtitleTextView.setSingleLine(true);
subtitleTextView.setGravity(Gravity.LEFT);
subtitleTextView.setTextColor(0xffffffff);
addView(subtitleTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.BOTTOM, 16, 0, 16, 9));
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int mrHeight = 180; // EDIT BY MR -- was: 148
int mrHeight = 180;
if (Build.VERSION.SDK_INT >= 21) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(mrHeight) + AndroidUtilities.statusBarHeight, MeasureSpec.EXACTLY));
} else {
@@ -109,43 +107,25 @@ public class DrawerProfileCell extends FrameLayout {
@Override
protected void onDraw(Canvas canvas) {
Drawable backgroundDrawable = ApplicationLoader.getCachedWallpaper();
int color = ApplicationLoader.getServiceMessageColor();
if (currentColor != color) {
currentColor = color;
shadowView.getDrawable().setColorFilter(new PorterDuffColorFilter(color | 0xff000000, PorterDuff.Mode.MULTIPLY));
}
if ( backgroundDrawable != null) {
subtitleTextView.setTextColor(0xffffffff);
shadowView.setVisibility(VISIBLE);
if (backgroundDrawable instanceof ColorDrawable) {
backgroundDrawable.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
backgroundDrawable.draw(canvas);
} else if (backgroundDrawable instanceof BitmapDrawable) {
Bitmap bitmap = ((BitmapDrawable) backgroundDrawable).getBitmap();
float scaleX = (float) getMeasuredWidth() / (float) bitmap.getWidth();
float scaleY = (float) getMeasuredHeight() / (float) bitmap.getHeight();
float scale = scaleX < scaleY ? scaleY : scaleX;
int width = (int) (getMeasuredWidth() / scale);
int height = (int) (getMeasuredHeight() / scale);
int x = (bitmap.getWidth() - width) / 2;
int y = (bitmap.getHeight() - height) / 2;
srcRect.set(x, y, x + width, y + height);
destRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
canvas.drawBitmap(bitmap, srcRect, destRect, paint);
}
} else {
shadowView.setVisibility(INVISIBLE);
subtitleTextView.setTextColor(0xffc2e5ff);
super.onDraw(canvas);
if (backgroundDrawable instanceof ColorDrawable) {
backgroundDrawable.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
backgroundDrawable.draw(canvas);
} else if (backgroundDrawable instanceof BitmapDrawable) {
Bitmap bitmap = ((BitmapDrawable) backgroundDrawable).getBitmap();
float scaleX = (float) getMeasuredWidth() / (float) bitmap.getWidth();
float scaleY = (float) getMeasuredHeight() / (float) bitmap.getHeight();
float scale = scaleX < scaleY ? scaleY : scaleX;
int width = (int) (getMeasuredWidth() / scale);
int height = (int) (getMeasuredHeight() / scale);
int x = (bitmap.getWidth() - width) / 2;
int y = (bitmap.getHeight() - height) / 2;
srcRect.set(x, y, x + width, y + height);
destRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
canvas.drawBitmap(bitmap, srcRect, destRect, paint);
}
}
public void setUser(TLRPC.User user) {
if (user == null) {
return;
}
public void updateUserName() {
String displayname = MrMailbox.getConfig("displayname", LocaleController.getString("MyAccount", R.string.MyAccount));
String addr;
if( MrMailbox.isConfigured()!=0) {
@@ -1,51 +0,0 @@
/*******************************************************************************
*
* Messenger Android Frontend
* (C) 2013-2016 Nikolai Kudashov
* (C) 2017 Björn Petersen
* Contact: r10s@b44t.com, http://b44t.com
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/ .
*
******************************************************************************/
package com.b44t.ui.Cells;
import android.annotation.SuppressLint;
import android.content.Context;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.b44t.messenger.AndroidUtilities;
import com.b44t.messenger.R;
import com.b44t.ui.Components.LayoutHelper;
@SuppressLint("NewApi")
public class PhotoAttachCameraCell extends FrameLayout {
public PhotoAttachCameraCell(Context context) {
super(context);
ImageView imageView = new ImageView(context);
imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setImageResource(R.drawable.instant_camera);
addView(imageView, LayoutHelper.createFrame(80, 80));
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(86), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(80), MeasureSpec.EXACTLY));
}
}
@@ -70,7 +70,7 @@ public class PhotoPickerAlbumsCell extends FrameLayout {
addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 28, Gravity.LEFT | Gravity.BOTTOM));
nameTextView = new TextView(context);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
nameTextView.setTextColor(0xffffffff);
nameTextView.setSingleLine(true);
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
@@ -75,7 +75,7 @@ public class PhotoPickerPhotoCell extends FrameLayout {
}
if (animated) {
if (checked) {
setBackgroundColor(0xff0A0A0A);
setBackgroundColor(0xffffffff);
}
animator = new AnimatorSet();
animator.playTogether(ObjectAnimator.ofFloat(photoImage, "scaleX", checked ? 0.85f : 1.0f),
@@ -101,7 +101,7 @@ public class PhotoPickerPhotoCell extends FrameLayout {
});
animator.start();
} else {
setBackgroundColor(checked ? 0xff0A0A0A : 0);
setBackgroundColor(checked ? 0xffffffff : 0);
photoImage.setScaleX(checked ? 0.85f : 1.0f);
photoImage.setScaleY(checked ? 0.85f : 1.0f);
}
@@ -1,163 +0,0 @@
/*******************************************************************************
*
* Messenger Android Frontend
* (C) 2013-2016 Nikolai Kudashov
* (C) 2017 Björn Petersen
* Contact: r10s@b44t.com, http://b44t.com
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/ .
*
******************************************************************************/
package com.b44t.ui.Cells;
import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.b44t.messenger.AndroidUtilities;
import com.b44t.messenger.LocaleController;
import com.b44t.messenger.R;
import com.b44t.ui.Components.LayoutHelper;
public class PhotoPickerSearchCell extends LinearLayout {
public interface PhotoPickerSearchCellDelegate {
void didPressedSearchButton(int index);
}
private class SearchButton extends FrameLayout {
private TextView textView1;
private TextView textView2;
private ImageView imageView;
private View selector;
public SearchButton(Context context) {
super(context);
setBackgroundColor(0xff1a1a1a);
selector = new View(context);
selector.setBackgroundResource(R.drawable.list_selector);
addView(selector, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
imageView = new ImageView(context);
imageView.setScaleType(ImageView.ScaleType.CENTER);
addView(imageView, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP));
textView1 = new TextView(context);
textView1.setGravity(Gravity.CENTER_VERTICAL);
textView1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
textView1.setTextColor(0xffffffff);
textView1.setSingleLine(true);
textView1.setEllipsize(TextUtils.TruncateAt.END);
addView(textView1, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 51, 8, 4, 0));
textView2 = new TextView(context);
textView2.setGravity(Gravity.CENTER_VERTICAL);
textView2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
textView2.setTextColor(0xff666666);
textView2.setSingleLine(true);
textView2.setEllipsize(TextUtils.TruncateAt.END);
addView(textView2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 51, 26, 4, 0));
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (Build.VERSION.SDK_INT >= 21) {
selector.drawableHotspotChanged(event.getX(), event.getY());
}
return super.onTouchEvent(event);
}
}
private PhotoPickerSearchCellDelegate delegate;
public PhotoPickerSearchCell(Context context, boolean allowGifs) {
super(context);
setOrientation(HORIZONTAL);
SearchButton searchButton = new SearchButton(context);
searchButton.textView1.setText(LocaleController.getString("SearchImages", R.string.SearchImages));
searchButton.textView2.setText(LocaleController.getString("SearchImagesInfo", R.string.SearchImagesInfo));
searchButton.imageView.setImageResource(R.drawable.search_web);
addView(searchButton);
LayoutParams layoutParams = (LayoutParams) searchButton.getLayoutParams();
layoutParams.weight = 0.5f;
layoutParams.topMargin = AndroidUtilities.dp(4);
layoutParams.height = AndroidUtilities.dp(48);
layoutParams.width = 0;
searchButton.setLayoutParams(layoutParams);
searchButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (delegate != null) {
delegate.didPressedSearchButton(0);
}
}
});
FrameLayout frameLayout = new FrameLayout(context);
frameLayout.setBackgroundColor(0);
addView(frameLayout);
layoutParams = (LayoutParams) frameLayout.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(4);
layoutParams.height = AndroidUtilities.dp(48);
layoutParams.width = AndroidUtilities.dp(4);
frameLayout.setLayoutParams(layoutParams);
searchButton = new SearchButton(context);
searchButton.textView1.setText(LocaleController.getString("SearchGifs", R.string.SearchGifs));
searchButton.textView2.setText("GIPHY");
searchButton.imageView.setImageResource(R.drawable.search_gif);
addView(searchButton);
layoutParams = (LayoutParams) searchButton.getLayoutParams();
layoutParams.weight = 0.5f;
layoutParams.topMargin = AndroidUtilities.dp(4);
layoutParams.height = AndroidUtilities.dp(48);
layoutParams.width = 0;
searchButton.setLayoutParams(layoutParams);
if (allowGifs) {
searchButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (delegate != null) {
delegate.didPressedSearchButton(1);
}
}
});
} else {
searchButton.setAlpha(0.5f);
}
}
public void setDelegate(PhotoPickerSearchCellDelegate delegate) {
this.delegate = delegate;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(52), MeasureSpec.EXACTLY));
}
}
@@ -34,48 +34,24 @@ import android.widget.ImageView;
import android.widget.TextView;
import com.b44t.messenger.AndroidUtilities;
import com.b44t.messenger.ImageLoader;
import com.b44t.messenger.ImageReceiver;
import com.b44t.messenger.LocaleController;
import com.b44t.messenger.MediaController;
import com.b44t.messenger.MessageObject;
import com.b44t.messenger.FileLoader;
import com.b44t.messenger.R;
import com.b44t.ui.Components.BackupImageView;
import com.b44t.ui.Components.CheckBox;
import com.b44t.ui.Components.LayoutHelper;
import com.b44t.ui.Components.LineProgressView;
import java.io.File;
public class SharedDocumentCell extends FrameLayout {
public class SharedDocumentCell extends FrameLayout implements MediaController.FileDownloadProgressListener {
private ImageView placeholderImabeView;
private ImageView placeholderImageView;
private BackupImageView thumbImageView;
private TextView nameTextView;
private TextView extTextView;
private TextView dateTextView;
private ImageView statusImageView;
private LineProgressView progressView;
private CheckBox checkBox;
private boolean needDivider;
private static Paint paint;
private int TAG;
private MessageObject message;
private boolean loading;
private boolean loaded;
private int icons[] = {
R.drawable.media_doc_blue,
R.drawable.media_doc_green,
R.drawable.media_doc_red,
R.drawable.media_doc_yellow
};
public SharedDocumentCell(Context context) {
super(context);
@@ -85,28 +61,15 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.F
paint.setStrokeWidth(1);
}
TAG = MediaController.getInstance().generateObserverTag();
placeholderImabeView = new ImageView(context);
addView(placeholderImabeView, LayoutHelper.createFrame(40, 40, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 12, 8, LocaleController.isRTL ? 12 : 0, 0));
extTextView = new TextView(context);
extTextView.setTextColor(0xffffffff);
extTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
extTextView.setLines(1);
extTextView.setMaxLines(1);
extTextView.setSingleLine(true);
extTextView.setGravity(Gravity.CENTER);
extTextView.setEllipsize(TextUtils.TruncateAt.END);
addView(extTextView, LayoutHelper.createFrame(32, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 16, 22, LocaleController.isRTL ? 16 : 0, 0));
placeholderImageView = new ImageView(context);
addView(placeholderImageView, LayoutHelper.createFrame(40, 40, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 12, 8, LocaleController.isRTL ? 12 : 0, 0));
thumbImageView = new BackupImageView(context);
addView(thumbImageView, LayoutHelper.createFrame(40, 40, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 12, 8, LocaleController.isRTL ? 12 : 0, 0));
thumbImageView.getImageReceiver().setDelegate(new ImageReceiver.ImageReceiverDelegate() {
@Override
public void didSetImage(ImageReceiver imageReceiver, boolean set, boolean thumb) {
extTextView.setVisibility(set ? INVISIBLE : VISIBLE);
placeholderImabeView.setVisibility(set ? INVISIBLE : VISIBLE);
placeholderImageView.setVisibility(set ? INVISIBLE : VISIBLE);
}
});
@@ -120,10 +83,6 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.F
nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 8 : 72, 5, LocaleController.isRTL ? 72 : 8, 0));
statusImageView = new ImageView(context);
statusImageView.setVisibility(INVISIBLE);
addView(statusImageView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 8 : 72, 35, LocaleController.isRTL ? 72 : 8, 0));
dateTextView = new TextView(context);
dateTextView.setTextColor(0xff999999);
dateTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
@@ -134,54 +93,24 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.F
dateTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
addView(dateTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 8 : 72, 30, LocaleController.isRTL ? 72 : 8, 0));
progressView = new LineProgressView(context);
addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 2, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 72, 54, LocaleController.isRTL ? 72 : 0, 0));
checkBox = new CheckBox(context, R.drawable.round_check2);
checkBox.setVisibility(INVISIBLE);
addView(checkBox, LayoutHelper.createFrame(22, 22, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 34, 30, LocaleController.isRTL ? 34 : 0, 0));
}
private int getThumbForNameOrMime(String name, String mime) {
if (name != null && name.length() != 0) {
int color = -1;
if (name.contains(".doc") || name.contains(".txt") || name.contains(".psd")) {
color = 0;
} else if (name.contains(".xls") || name.contains(".csv")) {
color = 1;
} else if (name.contains(".pdf") || name.contains(".ppt") || name.contains(".key")) {
color = 2;
} else if (name.contains(".zip") || name.contains(".rar") || name.contains(".ai") || name.contains(".mp3") || name.contains(".mov") || name.contains(".avi")) {
color = 3;
}
if (color == -1) {
int idx;
String ext = (idx = name.lastIndexOf('.')) == -1 ? "" : name.substring(idx + 1);
if (ext.length() != 0) {
color = ext.charAt(0) % icons.length;
} else {
color = name.charAt(0) % icons.length;
}
}
return icons[color];
}
return icons[0];
}
public void setTextAndValueAndTypeAndThumb(String text, String value, String type, String thumb, int resId) {
nameTextView.setText(text);
dateTextView.setText(value);
if (type != null) {
extTextView.setVisibility(VISIBLE);
extTextView.setText(type);
} else {
extTextView.setVisibility(INVISIBLE);
if( type != null ) {
dateTextView.setText(value + " " + type);
}
else {
dateTextView.setText(value);
}
if (resId == 0) {
placeholderImabeView.setImageResource(getThumbForNameOrMime(text, type));
placeholderImabeView.setVisibility(VISIBLE);
placeholderImageView.setImageResource(R.drawable.attach_file_inlist);
placeholderImageView.setVisibility(VISIBLE);
} else {
placeholderImabeView.setVisibility(INVISIBLE);
placeholderImageView.setVisibility(INVISIBLE);
}
if (thumb != null || resId != 0) {
if (thumb != null) {
@@ -195,12 +124,6 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.F
}
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
MediaController.getInstance().removeLoadingFileObserver(this);
}
public void setChecked(boolean checked, boolean animated) {
if (checkBox.getVisibility() != VISIBLE) {
checkBox.setVisibility(VISIBLE);
@@ -208,161 +131,8 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.F
checkBox.setChecked(checked, animated);
}
/*
public void setDocument(MessageObject messageObject, boolean divider) {
needDivider = divider;
message = messageObject;
loaded = false;
loading = false;
if (messageObject != null && messageObject.getDocument() != null) {
int idx;
String name = null;
if (messageObject.isMusic()) {
TLRPC.Document document;
if (messageObject.type == 0) {
document = messageObject.messageOwner.media.webpage.document;
} else {
document = messageObject.messageOwner.media.document;
}
for (int a = 0; a < document.attributes.size(); a++) {
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
if (attribute.performer != null && attribute.performer.length() != 0 || attribute.title != null && attribute.title.length() != 0) {
name = messageObject.getMusicAuthor() + " - " + messageObject.getMusicTitle();
}
}
}
}
String fileName = FileLoader.getDocumentFileName(messageObject.getDocument());
if (name == null) {
name = fileName;
}
nameTextView.setText(name);
placeholderImabeView.setVisibility(VISIBLE);
extTextView.setVisibility(VISIBLE);
placeholderImabeView.setImageResource(getThumbForNameOrMime(fileName, messageObject.getDocument().mime_type));
extTextView.setText((idx = fileName.lastIndexOf('.')) == -1 ? "" : fileName.substring(idx + 1).toLowerCase());
if (messageObject.getDocument().thumb instanceof TLRPC.TL_photoSizeEmpty || messageObject.getDocument().thumb == null) {
thumbImageView.setVisibility(INVISIBLE);
thumbImageView.setImageBitmap(null);
} else {
thumbImageView.setVisibility(VISIBLE);
thumbImageView.setImage(messageObject.getDocument().thumb.location, "40_40", (Drawable) null);
}
long date = (long) messageObject.messageOwner.date * 1000;
dateTextView.setText(String.format("%s, %s", AndroidUtilities.formatFileSize(messageObject.getDocument().size), LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(new Date(date)), LocaleController.getInstance().formatterDay.format(new Date(date)))));
} else {
nameTextView.setText("");
extTextView.setText("");
dateTextView.setText("");
placeholderImabeView.setVisibility(VISIBLE);
extTextView.setVisibility(VISIBLE);
thumbImageView.setVisibility(INVISIBLE);
thumbImageView.setImageBitmap(null);
}
setWillNotDraw(!needDivider);
progressView.setProgress(0, false);
updateFileExistIcon();
}
*/
public void updateFileExistIcon() {
if (message != null && message.messageOwner.media != null) {
String fileName = null;
File cacheFile;
if (message.messageOwner.attachPath == null || message.messageOwner.attachPath.length() == 0 || !(new File(message.messageOwner.attachPath).exists())) {
cacheFile = FileLoader.getPathToMessage(message.messageOwner);
if (!cacheFile.exists()) {
fileName = FileLoader.getAttachFileName(message.getDocument());
}
}
loaded = false;
if (fileName == null) {
statusImageView.setVisibility(INVISIBLE);
dateTextView.setPadding(0, 0, 0, 0);
loading = false;
loaded = true;
MediaController.getInstance().removeLoadingFileObserver(this);
} else {
MediaController.getInstance().addLoadingFileObserver(fileName, this);
loading = FileLoader.getInstance().isLoadingFile(fileName);
statusImageView.setVisibility(VISIBLE);
statusImageView.setImageResource(loading ? R.drawable.media_doc_pause : R.drawable.media_doc_load);
dateTextView.setPadding(LocaleController.isRTL ? 0 : AndroidUtilities.dp(14), 0, LocaleController.isRTL ? AndroidUtilities.dp(14) : 0, 0);
if (loading) {
progressView.setVisibility(VISIBLE);
Float progress = ImageLoader.getInstance().getFileProgress(fileName);
if (progress == null) {
progress = 0.0f;
}
progressView.setProgress(progress, false);
} else {
progressView.setVisibility(INVISIBLE);
}
}
} else {
loading = false;
loaded = true;
progressView.setVisibility(INVISIBLE);
progressView.setProgress(0, false);
statusImageView.setVisibility(INVISIBLE);
dateTextView.setPadding(0, 0, 0, 0);
MediaController.getInstance().removeLoadingFileObserver(this);
}
}
public MessageObject getMessage() {
return message;
}
public boolean isLoaded() {
return loaded;
}
public boolean isLoading() {
return loading;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(56) + (needDivider ? 1 : 0), MeasureSpec.EXACTLY));
}
@Override
protected void onDraw(Canvas canvas) {
if (needDivider) {
canvas.drawLine(AndroidUtilities.dp(72), getHeight() - 1, getWidth() - getPaddingRight(), getHeight() - 1, paint);
}
}
@Override
public void onFailedDownload(String name) {
updateFileExistIcon();
}
@Override
public void onSuccessDownload(String name) {
progressView.setProgress(1, true);
updateFileExistIcon();
}
@Override
public void onProgressDownload(String fileName, float progress) {
if (progressView.getVisibility() != VISIBLE) {
updateFileExistIcon();
}
progressView.setProgress(progress, true);
}
@Override
public void onProgressUpload(String fileName, float progress, boolean isEncrypted) {
}
@Override
public int getObserverTag() {
return TAG;
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(56) /*+ (needDivider ? 1 : 0)*/, MeasureSpec.EXACTLY));
}
}
File diff suppressed because it is too large Load Diff
@@ -40,7 +40,6 @@ import com.b44t.messenger.MediaController;
import com.b44t.messenger.TLRPC;
import com.b44t.messenger.FileLoader;
import com.b44t.messenger.FileLog;
import com.b44t.messenger.NotificationCenter;
import com.b44t.messenger.UserConfig;
import com.b44t.ui.LaunchActivity;
import com.b44t.ui.PhotoAlbumPickerActivity;
@@ -51,7 +50,7 @@ import com.b44t.ui.PhotoViewer;
import java.io.File;
import java.util.ArrayList;
public class AvatarUpdater implements NotificationCenter.NotificationCenterDelegate, PhotoCropActivity.PhotoEditActivityDelegate {
public class AvatarUpdater implements PhotoCropActivity.PhotoEditActivityDelegate {
public String currentPicturePath;
private TLRPC.PhotoSize smallPhoto;
@@ -84,7 +83,7 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
currentPicturePath = image.getAbsolutePath();
}
parentFragment.startActivityForResult(takePictureIntent, 13);
parentFragment.startActivityForResult(takePictureIntent, BaseFragment.RC13_AVATAR_IMAGE_CAPTURE);
} catch (Exception e) {
FileLog.e("messenger", e);
}
@@ -97,10 +96,10 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
return;
}
}
PhotoAlbumPickerActivity fragment = new PhotoAlbumPickerActivity(true, false, null);
PhotoAlbumPickerActivity fragment = new PhotoAlbumPickerActivity(true, null);
fragment.setDelegate(new PhotoAlbumPickerActivity.PhotoAlbumPickerActivityDelegate() {
@Override
public void didSelectPhotos(ArrayList<String> photos, ArrayList<String> captions, ArrayList<MediaController.SearchImage> webPhotos) {
public void didSelectPhotos(ArrayList<String> photos, ArrayList<String> captions) {
if (!photos.isEmpty()) {
Bitmap bitmap = ImageLoader.loadBitmap(photos.get(0), null, 800, 800, true);
processBitmap(bitmap);
@@ -109,13 +108,14 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
@Override
public void startPhotoSelectActivity() {
/* -- this is the fallback implementation of the gallery selection, see ID_OPEN_SYSTEM_SELECTOR
try {
Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
photoPickerIntent.setType("image/*");
parentFragment.startActivityForResult(photoPickerIntent, 14);
parentFragment.startActivityForResult(photoPickerIntent, BaseFragment.RC14_AVATAR_GET_CONTENT);
} catch (Exception e) {
FileLog.e("messenger", e);
}
} */
}
@Override
@@ -150,7 +150,7 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
if (requestCode == 13) {
if (requestCode == BaseFragment.RC13_AVATAR_IMAGE_CAPTURE) {
PhotoViewer.getInstance().setParentActivity(parentFragment.getParentActivity());
int orientation = 0;
try {
@@ -188,11 +188,12 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
}, null);
AndroidUtilities.addMediaToGallery(currentPicturePath);
currentPicturePath = null;
} else if (requestCode == 14) {
} else if (requestCode == BaseFragment.RC14_AVATAR_GET_CONTENT) {
/* -- this is the fallback implementation of the gallery selection, see ID_OPEN_SYSTEM_SELECTOR
if (data == null || data.getData() == null) {
return;
}
startCrop(null, data.getData());
startCrop(null, data.getData()); */
}
}
}
@@ -212,9 +213,7 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
} else {
UserConfig.saveConfig(false);
uploadingAvatar = FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE) + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
NotificationCenter.getInstance().addObserver(AvatarUpdater.this, NotificationCenter.FileDidUpload);
NotificationCenter.getInstance().addObserver(AvatarUpdater.this, NotificationCenter.FileDidFailUpload);
FileLoader.getInstance().uploadFile(uploadingAvatar, false, true);
//FileLoader.getInstance().uploadFile(uploadingAvatar, false, true);
}
}
}
@@ -223,34 +222,4 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
public void didFinishEdit(Bitmap bitmap) {
processBitmap(bitmap);
}
@Override
public void didReceivedNotification(int id, final Object... args) {
if (id == NotificationCenter.FileDidUpload) {
String location = (String)args[0];
if (uploadingAvatar != null && location.equals(uploadingAvatar)) {
NotificationCenter.getInstance().removeObserver(AvatarUpdater.this, NotificationCenter.FileDidUpload);
NotificationCenter.getInstance().removeObserver(AvatarUpdater.this, NotificationCenter.FileDidFailUpload);
if (delegate != null) {
delegate.didUploadedPhoto((TLRPC.InputFile)args[1], smallPhoto, bigPhoto);
}
uploadingAvatar = null;
if (clearAfterUpdate) {
parentFragment = null;
delegate = null;
}
}
} else if (id == NotificationCenter.FileDidFailUpload) {
String location = (String)args[0];
if (uploadingAvatar != null && location.equals(uploadingAvatar)) {
NotificationCenter.getInstance().removeObserver(AvatarUpdater.this, NotificationCenter.FileDidUpload);
NotificationCenter.getInstance().removeObserver(AvatarUpdater.this, NotificationCenter.FileDidFailUpload);
uploadingAvatar = null;
if (clearAfterUpdate) {
parentFragment = null;
delegate = null;
}
}
}
}
}
File diff suppressed because it is too large Load Diff
@@ -29,11 +29,7 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.*;
import android.graphics.Rect;
@@ -42,12 +38,9 @@ import android.os.Build;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.HapticFeedbackConstants;
import android.view.MotionEvent;
import android.view.SoundEffectConstants;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;
import android.widget.FrameLayout;
@@ -55,8 +48,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import com.b44t.messenger.AndroidUtilities;
import com.b44t.messenger.MessagesController;
import com.b44t.messenger.ContactsController;
import com.b44t.messenger.ApplicationLoader;
import com.b44t.messenger.FileLog;
import com.b44t.messenger.LocaleController;
import com.b44t.messenger.MediaController;
@@ -68,13 +60,10 @@ import com.b44t.messenger.support.widget.RecyclerView;
import com.b44t.messenger.TLRPC;
import com.b44t.ui.ActionBar.BottomSheet;
import com.b44t.ui.ActionBar.Theme;
import com.b44t.ui.Cells.PhotoAttachCameraCell;
import com.b44t.ui.Cells.PhotoAttachPhotoCell;
import com.b44t.ui.Cells.ShadowSectionCell;
import com.b44t.ui.ChatActivity;
import com.b44t.ui.PhotoViewer;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
@@ -82,10 +71,10 @@ public class ChatAttachAlert extends BottomSheet implements NotificationCenter.N
public final static int ATTACH_BUTTON_IDX_CAMERA = 0;
public final static int ATTACH_BUTTON_IDX_VIDEO = 1;
public final static int ATTACH_BUTTON_IDX_LOCATION = 2;
public final static int ATTACH_BUTTON_IDX_CONTACT = 3;
public final static int ATTACH_BUTTON_IDX_GALLERY = 4;
public final static int ATTACH_BUTTON_IDX_FILE = 5;
public final static int ATTACH_BUTTON_IDX_GALLERY = 2;
public final static int ATTACH_BUTTON_IDX_EMPTY = 3;
public final static int ATTACH_BUTTON_IDX_FILE = 4;
public final static int ATTACH_BUTTON_IDX_CONTACT = 5;
public final static int ATTACH_BUTTON_IDX_MUSIC = 6;
public final static int ATTACH_BUTTON_IDX_SENDSELECTED = 7;
public final static int ATTACH_BUTTON_COUNT = 8;
@@ -113,16 +102,8 @@ public class ChatAttachAlert extends BottomSheet implements NotificationCenter.N
private LinearLayoutManager layoutManager;
private Drawable shadowDrawable;
private ViewGroup attachView;
private ListAdapter adapter;
//private TextView hintTextView;
private ArrayList<InnerAnimator> innerAnimators = new ArrayList<>();
//private AnimatorSet currentHintAnimation;
//private boolean hintShowed;
//private Runnable hideHintRunnable;
private boolean deviceHasGoodCamera = false;//Build.VERSION.SDK_INT >= 16;
private DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator();
private boolean loading = true;
@@ -180,9 +161,6 @@ public class ChatAttachAlert extends BottomSheet implements NotificationCenter.N
super(context, false);
setDelegate(this);
setUseRevealAnimation(true);
if (deviceHasGoodCamera) {
//CameraController.getInstance().initCamera();
}
NotificationCenter.getInstance().addObserver(this, NotificationCenter.albumsDidLoaded);
shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow);
@@ -260,7 +238,7 @@ public class ChatAttachAlert extends BottomSheet implements NotificationCenter.N
listView.setClipToPadding(false);
listView.setLayoutManager(layoutManager = new LinearLayoutManager(getContext()));
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
listView.setAdapter(adapter = new ListAdapter(context));
listView.setAdapter(new ListAdapter(context));
listView.setVerticalScrollBarEnabled(false);
listView.setEnabled(true);
listView.setGlowColor(0xfff5f6f7);
@@ -280,13 +258,6 @@ public class ChatAttachAlert extends BottomSheet implements NotificationCenter.N
if (listView.getChildCount() <= 0) {
return;
}
/*if (hintShowed) {
if (layoutManager.findLastVisibleItemPosition() > 1) {
hideHint();
hintShowed = false;
ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).edit().putBoolean("bothint", true).commit();
}
}*/
updateLayout();
}
});
@@ -306,7 +277,6 @@ public class ChatAttachAlert extends BottomSheet implements NotificationCenter.N
attachPhotoRecyclerView.layout(0, t, width, t + attachPhotoRecyclerView.getMeasuredHeight());
progressView.layout(0, t, width, t + progressView.getMeasuredHeight());
lineView.layout(0, AndroidUtilities.dp(96), width, AndroidUtilities.dp(96) + lineView.getMeasuredHeight());
//hintTextView.layout(width - hintTextView.getMeasuredWidth() - AndroidUtilities.dp(5), height - hintTextView.getMeasuredHeight() - AndroidUtilities.dp(5), width - AndroidUtilities.dp(5), height - AndroidUtilities.dp(5));
int diff = (width - AndroidUtilities.dp(85 * 4 + 20)) / 3;
for (int a = 0; a < 8; a++) {
@@ -341,60 +311,13 @@ public class ChatAttachAlert extends BottomSheet implements NotificationCenter.N
if (baseFragment == null || baseFragment.getParentActivity() == null) {
return;
}
if (!deviceHasGoodCamera || position != 0) {
if (deviceHasGoodCamera) {
position--;
}
ArrayList<Object> arrayList = (ArrayList) MediaController.allPhotosAlbumEntry.photos;
if (position < 0 || position >= arrayList.size()) {
return;
}
PhotoViewer.getInstance().setParentActivity(baseFragment.getParentActivity());
PhotoViewer.getInstance().openPhotoForSelect(arrayList, position, 0, ChatAttachAlert.this, baseFragment);
AndroidUtilities.hideKeyboard(baseFragment.getFragmentView().findFocus());
} else {
final File path = AndroidUtilities.generatePicturePath();
/*CameraController.getInstance().takePicture(path, ((PhotoAttachCameraCell) view).cameraSession, new Runnable() {
@Override
public void run() {
PhotoViewer.getInstance().setParentActivity(baseFragment.getParentActivity());
final ArrayList<Object> arrayList = new ArrayList<>();
int orientation = 0;
try {
ExifInterface ei = new ExifInterface(path.getAbsolutePath());
int exif = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (exif) {
case ExifInterface.ORIENTATION_ROTATE_90:
orientation = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
orientation = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
orientation = 270;
break;
}
} catch (Exception e) {
FileLog.e("messenger", e);
}
arrayList.add(new MediaController.PhotoEntry(0, 0, 0, path.getAbsolutePath(), orientation, false));
PhotoViewer.getInstance().openPhotoForSelect(arrayList, 0, 2, new PhotoViewer.EmptyPhotoViewerProvider() {
@Override
public void sendButtonPressed(int index) {
AndroidUtilities.addMediaToGallery(path.getAbsolutePath());
baseFragment.sendPhoto((MediaController.PhotoEntry) arrayList.get(0));
}
@Override
public boolean cancelButtonPressed() {
path.delete();
return true;
}
}, baseFragment);
}
});*/
ArrayList<Object> arrayList = (ArrayList) MediaController.allPhotosAlbumEntry.photos;
if (position < 0 || position >= arrayList.size()) {
return;
}
PhotoViewer.getInstance().setParentActivity(baseFragment.getParentActivity());
PhotoViewer.getInstance().openPhotoForSelect(arrayList, position, 0, ChatAttachAlert.this, baseFragment);
AndroidUtilities.hideKeyboard(baseFragment.getFragmentView().findFocus());
}
});
@@ -419,13 +342,13 @@ public class ChatAttachAlert extends BottomSheet implements NotificationCenter.N
attachView.addView(lineView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1, Gravity.TOP | Gravity.LEFT));
CharSequence[] labels = new CharSequence[ATTACH_BUTTON_COUNT];
labels[ATTACH_BUTTON_IDX_CAMERA] = LocaleController.getString("ChatCamera", R.string.ChatCamera);
labels[ATTACH_BUTTON_IDX_GALLERY] = LocaleController.getString("ChatGallery", R.string.ChatGallery);
labels[ATTACH_BUTTON_IDX_VIDEO] = LocaleController.getString("ChatVideo", R.string.ChatVideo);
labels[ATTACH_BUTTON_IDX_MUSIC] = LocaleController.getString("AttachMusic", R.string.AttachMusic);
labels[ATTACH_BUTTON_IDX_FILE] = LocaleController.getString("ChatDocument", R.string.ChatDocument);
labels[ATTACH_BUTTON_IDX_CONTACT] = LocaleController.getString("AttachContact", R.string.AttachContact);
labels[ATTACH_BUTTON_IDX_LOCATION] = LocaleController.getString("ChatLocation", R.string.ChatLocation);
labels[ATTACH_BUTTON_IDX_CAMERA] = ApplicationLoader.applicationContext.getString(R.string.ChatCamera);
labels[ATTACH_BUTTON_IDX_GALLERY] = ApplicationLoader.applicationContext.getString(R.string.ChatGallery);
labels[ATTACH_BUTTON_IDX_VIDEO] = ApplicationLoader.applicationContext.getString(R.string.AttachVideo);
labels[ATTACH_BUTTON_IDX_MUSIC] = ApplicationLoader.applicationContext.getString(R.string.AttachMusic);
labels[ATTACH_BUTTON_IDX_FILE] = ApplicationLoader.applicationContext.getString(R.string.AttachDocument);
labels[ATTACH_BUTTON_IDX_CONTACT] = ApplicationLoader.applicationContext.getString(R.string.AttachContact);
labels[ATTACH_BUTTON_IDX_EMPTY] = "";
labels[ATTACH_BUTTON_IDX_SENDSELECTED]= "";
for (int a = 0; a < ATTACH_BUTTON_COUNT; a++) {
@@ -446,20 +369,6 @@ public class ChatAttachAlert extends BottomSheet implements NotificationCenter.N
});
}
/*
hintTextView = new TextView(context);
hintTextView.setBackgroundResource(R.drawable.tooltip);
hintTextView.setTextColor(Theme.CHAT_GIF_HINT_TEXT_COLOR);
hintTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
hintTextView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0);
hintTextView.setText(LocaleController.getString("AttachBotsHelp", R.string.AttachBotsHelp));
hintTextView.setGravity(Gravity.CENTER_VERTICAL);
hintTextView.setVisibility(View.INVISIBLE);
hintTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.scroll_tip, 0, 0, 0);
hintTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8));
attachView.addView(hintTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 32, Gravity.RIGHT | Gravity.BOTTOM, 5, 0, 5, 5));
*/
for (int a = 0; a < 8; a++) {
viewsCache.add(photoAttachAdapter.createHolder());
}
@@ -471,90 +380,6 @@ public class ChatAttachAlert extends BottomSheet implements NotificationCenter.N
}
}
/*
private void hideHint() {
if (hideHintRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(hideHintRunnable);
hideHintRunnable = null;
}
if (hintTextView == null) {
return;
}
currentHintAnimation = new AnimatorSet();
currentHintAnimation.playTogether(
ObjectAnimator.ofFloat(hintTextView, "alpha", 0.0f)
);
currentHintAnimation.setInterpolator(decelerateInterpolator);
currentHintAnimation.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
if (currentHintAnimation == null || !currentHintAnimation.equals(animation)) {
return;
}
currentHintAnimation = null;
if (hintTextView != null) {
hintTextView.setVisibility(View.INVISIBLE);
}
}
@Override
public void onAnimationCancel(Animator animation) {
if (currentHintAnimation != null && currentHintAnimation.equals(animation)) {
currentHintAnimation = null;
}
}
});
currentHintAnimation.setDuration(300);
currentHintAnimation.start();
}
private void showHint() {
if (SearchQuery.inlineBots.isEmpty()) {
return;
}
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
if (preferences.getBoolean("bothint", false)) {
return;
}
hintShowed = true;
hintTextView.setVisibility(View.VISIBLE);
currentHintAnimation = new AnimatorSet();
currentHintAnimation.playTogether(
ObjectAnimator.ofFloat(hintTextView, "alpha", 0.0f, 1.0f)
);
currentHintAnimation.setInterpolator(decelerateInterpolator);
currentHintAnimation.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
if (currentHintAnimation == null || !currentHintAnimation.equals(animation)) {
return;
}
currentHintAnimation = null;
AndroidUtilities.runOnUIThread(hideHintRunnable = new Runnable() {
@Override
public void run() {
if (hideHintRunnable != this) {
return;
}
hideHintRunnable = null;
hideHint();
}
}, 2000);
}
@Override
public void onAnimationCancel(Animator animation) {
if (currentHintAnimation != null && currentHintAnimation.equals(animation)) {
currentHintAnimation = null;
}
}
});
currentHintAnimation.setDuration(300);
currentHintAnimation.start();
}
*/
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.albumsDidLoaded) {
@@ -631,14 +456,7 @@ public class ChatAttachAlert extends BottomSheet implements NotificationCenter.N
photoEntry.thumbPath = null;
}
}
/*
if (currentHintAnimation != null) {
currentHintAnimation.cancel();
currentHintAnimation = null;
}
hintTextView.setAlpha(0.0f);
hintTextView.setVisibility(View.INVISIBLE);
*/
attachPhotoLayoutManager.scrollToPositionWithOffset(0, 1000000);
photoAttachAdapter.clearSelectedPhotos();
baseFragment = parentFragment;
@@ -802,9 +620,6 @@ public class ChatAttachAlert extends BottomSheet implements NotificationCenter.N
if (open && Build.VERSION.SDK_INT <= 19 && MediaController.allPhotosAlbumEntry == null) {
MediaController.loadGalleryPhotosAlbums(0);
}
/*if (open) {
showHint();
}*/
}
@Override
@@ -826,63 +641,19 @@ public class ChatAttachAlert extends BottomSheet implements NotificationCenter.N
private class ListAdapter extends RecyclerView.Adapter {
private Context mContext;
private final int TYPE_ATTACH_CELLS = 0;
public ListAdapter(Context context) {
mContext = context;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view;
switch (viewType) {
case 0:
view = attachView;
break;
case 1:
view = new ShadowSectionCell(mContext);
break;
default:
FrameLayout frameLayout = new FrameLayout(mContext);/* -- not used, this is the old "swipe up bot stuff" -- {
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
int diff = (right - left - AndroidUtilities.dp(85 * 4 + 20)) / 3;
for (int a = 0; a < 4; a++) {
int x = AndroidUtilities.dp(10) + (a % 4) * (AndroidUtilities.dp(85) + diff);
View child = getChildAt(a);
child.layout(x, 0, x + child.getMeasuredWidth(), child.getMeasuredHeight());
}
}
};
for (int a = 0; a < 4; a++) {
frameLayout.addView(new AttachBotButton(mContext));
}*/
view = frameLayout;
//frameLayout.setLayoutParams(new RecyclerView.LayoutParams(LayoutHelper.MATCH_PARENT, AndroidUtilities.dp(100)));
break;
}
return new Holder(view);
// currently, we only use one viewType, TYPE_ATTACH_CELLS
return new Holder(attachView);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (position > 1) {
/*
position -= 2;
position *= 4;
FrameLayout frameLayout = (FrameLayout) holder.itemView;
for (int a = 0; a < 4; a++) {
AttachBotButton child = (AttachBotButton) frameLayout.getChildAt(a);
if (position + a >= SearchQuery.inlineBots.size()) {
child.setVisibility(View.INVISIBLE);
} else {
child.setVisibility(View.VISIBLE);
child.setTag(position + a);
child.setUser(MessagesController.getInstance().getUser(SearchQuery.inlineBots.get(position + a).peer.user_id));
}
}
*/
}
}
@Override
@@ -892,19 +663,14 @@ public class ChatAttachAlert extends BottomSheet implements NotificationCenter.N
@Override
public int getItemViewType(int position) {
switch (position) {
case 0:
return 0;
case 1:
return 1;
default:
return 2;
}
return TYPE_ATTACH_CELLS;
}
}
private class PhotoAttachAdapter extends RecyclerView.Adapter {
private final int TYPE_ATTACH_PHOTO_CELL = 0;
private Context mContext;
private HashMap<Integer, MediaController.PhotoEntry> selectedPhotos = new HashMap<>();
@@ -954,45 +720,30 @@ public class ChatAttachAlert extends BottomSheet implements NotificationCenter.N
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (!deviceHasGoodCamera || position != 0) {
if (deviceHasGoodCamera) {
position--;
}
PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) holder.itemView;
MediaController.PhotoEntry photoEntry = MediaController.allPhotosAlbumEntry.photos.get(position);
cell.setPhotoEntry(photoEntry, position == MediaController.allPhotosAlbumEntry.photos.size() - 1);
cell.setChecked(selectedPhotos.containsKey(photoEntry.imageId), false);
cell.getImageView().setTag(position);
cell.setTag(position);
}
PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) holder.itemView;
MediaController.PhotoEntry photoEntry = MediaController.allPhotosAlbumEntry.photos.get(position);
cell.setPhotoEntry(photoEntry, position == MediaController.allPhotosAlbumEntry.photos.size() - 1);
cell.setChecked(selectedPhotos.containsKey(photoEntry.imageId), false);
cell.getImageView().setTag(position);
cell.setTag(position);
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// currently, we only use one viewType, TYPE_ATTACH_PHOTO_CELL
Holder holder;
switch (viewType) {
case 1:
holder = new Holder(new PhotoAttachCameraCell(mContext));
break;
default:
if (!viewsCache.isEmpty()) {
holder = viewsCache.get(0);
viewsCache.remove(0);
} else {
holder = createHolder();
}
break;
if (!viewsCache.isEmpty()) {
holder = viewsCache.get(0);
viewsCache.remove(0);
} else {
holder = createHolder();
}
return holder;
}
@Override
public int getItemCount() {
int count = 0;
if (deviceHasGoodCamera) {
count++;
}
if (MediaController.allPhotosAlbumEntry != null) {
count += MediaController.allPhotosAlbumEntry.photos.size();
}
@@ -1001,10 +752,7 @@ public class ChatAttachAlert extends BottomSheet implements NotificationCenter.N
@Override
public int getItemViewType(int position) {
if (deviceHasGoodCamera && position == 0) {
return 1;
}
return 0;
return TYPE_ATTACH_PHOTO_CELL;
}
}
@@ -1,158 +0,0 @@
/*******************************************************************************
*
* Messenger Android Frontend
* (C) 2013-2016 Nikolai Kudashov
* (C) 2017 Björn Petersen
* Contact: r10s@b44t.com, http://b44t.com
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/ .
*
******************************************************************************/
package com.b44t.ui.Components;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.view.animation.DecelerateInterpolator;
import com.b44t.messenger.AndroidUtilities;
public class CloseProgressDrawable2 extends Drawable {
private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
private long lastFrameTime;
private DecelerateInterpolator interpolator = new DecelerateInterpolator();
private RectF rect = new RectF();
private float angle;
private boolean animating;
public CloseProgressDrawable2() {
super();
paint.setColor(0xffadadad);
paint.setStrokeWidth(AndroidUtilities.dp(2));
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setStyle(Paint.Style.STROKE);
}
public void startAnimation() {
animating = true;
lastFrameTime = System.currentTimeMillis();
invalidateSelf();
}
public void stopAnimation() {
animating = false;
}
@Override
public void draw(Canvas canvas) {
long newTime = System.currentTimeMillis();
boolean invalidate = false;
if (lastFrameTime != 0) {
long dt = (newTime - lastFrameTime);
if (animating || angle != 0) {
angle += 360 * dt / 500.0f;
if (!animating && angle >= 720) {
angle = 0;
} else {
angle -= (int) (angle / 720) * 720;
}
invalidateSelf();
}
}
canvas.save();
canvas.translate(getIntrinsicWidth() / 2, getIntrinsicHeight() / 2);
canvas.rotate(-45);
float progress1 = 1.0f;
float progress2 = 1.0f;
float progress3 = 1.0f;
float progress4 = 0.0f;
if (angle >= 0 && angle < 90) {
progress1 = (1.0f - angle / 90.0f);
} else if (angle >= 90 && angle < 180) {
progress1 = 0.0f;
progress2 = 1.0f - (angle - 90) / 90.0f;
} else if (angle >= 180 && angle < 270) {
progress1 = progress2 = 0;
progress3 = 1.0f - (angle - 180) / 90.0f;
} else if (angle >= 270 && angle < 360) {
progress1 = progress2 = progress3 = 0;
progress4 = (angle - 270) / 90.0f;
} else if (angle >= 360 && angle < 450) {
progress1 = progress2 = progress3 = 0;
progress4 = 1.0f - (angle - 360) / 90.0f;
} else if (angle >= 450 && angle < 540) {
progress2 = progress3 = 0;
progress1 = (angle - 450) / 90.0f;
} else if (angle >= 540 && angle < 630) {
progress3 = 0;
progress2 = (angle - 540) / 90.0f;
} else if (angle >= 630 && angle < 720) {
progress3 = (angle - 630) / 90.0f;
}
if (progress1 != 0) {
canvas.drawLine(0, 0, 0, AndroidUtilities.dp(8) * progress1, paint);
}
if (progress2 != 0) {
canvas.drawLine(-AndroidUtilities.dp(8) * progress2, 0, 0, 0, paint);
}
if (progress3 != 0) {
canvas.drawLine(0, -AndroidUtilities.dp(8) * progress3, 0, 0, paint);
}
if (progress4 != 1) {
canvas.drawLine(AndroidUtilities.dp(8) * progress4, 0, AndroidUtilities.dp(8), 0, paint);
}
canvas.restore();
int cx = getBounds().centerX();
int cy = getBounds().centerY();
rect.set(cx - AndroidUtilities.dp(8), cy - AndroidUtilities.dp(8), cx + AndroidUtilities.dp(8), cy + AndroidUtilities.dp(8));
canvas.drawArc(rect, (angle < 360 ? 0 : angle - 360) - 45, (angle < 360 ? angle : 720 - angle), false, paint);
lastFrameTime = newTime;
}
@Override
public void setAlpha(int alpha) {
}
@Override
public void setColorFilter(ColorFilter cf) {
}
@Override
public int getOpacity() {
return PixelFormat.TRANSPARENT;
}
@Override
public int getIntrinsicWidth() {
return AndroidUtilities.dp(24);
}
@Override
public int getIntrinsicHeight() {
return AndroidUtilities.dp(24);
}
}
@@ -1,127 +0,0 @@
/*******************************************************************************
*
* Messenger Android Frontend
* (C) 2013-2016 Nikolai Kudashov
* (C) 2017 Björn Petersen
* Contact: r10s@b44t.com, http://b44t.com
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/ .
*
******************************************************************************/
package com.b44t.ui.Components;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import com.b44t.messenger.AndroidUtilities;
public class LineProgressView extends View {
private long lastUpdateTime = 0;
private float currentProgress = 0;
private float animationProgressStart = 0;
private long currentProgressTime = 0;
private float animatedProgressValue = 0;
private float animatedAlphaValue = 1.0f;
private int backColor;
private int progressColor = 0xff36a2ee;
private static DecelerateInterpolator decelerateInterpolator = null;
private static Paint progressPaint = null;
public LineProgressView(Context context) {
super(context);
if (decelerateInterpolator == null) {
decelerateInterpolator = new DecelerateInterpolator();
progressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
progressPaint.setStyle(Paint.Style.STROKE);
progressPaint.setStrokeCap(Paint.Cap.ROUND);
progressPaint.setStrokeWidth(AndroidUtilities.dp(2));
}
}
private void updateAnimation() {
long newTime = System.currentTimeMillis();
long dt = newTime - lastUpdateTime;
lastUpdateTime = newTime;
if (animatedProgressValue != 1 && animatedProgressValue != currentProgress) {
float progressDiff = currentProgress - animationProgressStart;
if (progressDiff > 0) {
currentProgressTime += dt;
if (currentProgressTime >= 300) {
animatedProgressValue = currentProgress;
animationProgressStart = currentProgress;
currentProgressTime = 0;
} else {
animatedProgressValue = animationProgressStart + progressDiff * decelerateInterpolator.getInterpolation(currentProgressTime / 300.0f);
}
}
invalidate();
}
if (animatedProgressValue >= 1 && animatedProgressValue == 1 && animatedAlphaValue != 0) {
animatedAlphaValue -= dt / 200.0f;
if (animatedAlphaValue <= 0) {
animatedAlphaValue = 0.0f;
}
invalidate();
}
}
public void setProgressColor(int color) {
progressColor = color;
}
public void setBackColor(int color) {
backColor = color;
}
public void setProgress(float value, boolean animated) {
if (!animated) {
animatedProgressValue = value;
animationProgressStart = value;
} else {
animationProgressStart = animatedProgressValue;
}
if (value != 1) {
animatedAlphaValue = 1;
}
currentProgress = value;
currentProgressTime = 0;
lastUpdateTime = System.currentTimeMillis();
invalidate();
}
public void onDraw(Canvas canvas) {
if (backColor != 0 && animatedProgressValue != 1) {
progressPaint.setColor(backColor);
progressPaint.setAlpha((int) (255 * animatedAlphaValue));
int start = (int) (getWidth() * animatedProgressValue);
canvas.drawRect(start, 0, getWidth(), getHeight(), progressPaint);
}
progressPaint.setColor(progressColor);
progressPaint.setAlpha((int)(255 * animatedAlphaValue));
canvas.drawRect(0, 0, getWidth() * animatedProgressValue, getHeight(), progressPaint);
updateAnimation();
}
}
@@ -30,7 +30,6 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Canvas;
import android.graphics.Rect;
@@ -49,7 +48,6 @@ import android.text.method.PasswordTransformationMethod;
import android.util.TypedValue;
import android.view.ActionMode;
import android.view.Gravity;
import android.view.HapticFeedbackConstants;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
@@ -70,6 +68,7 @@ import com.b44t.messenger.FileLog;
import com.b44t.messenger.R;
import com.b44t.messenger.UserConfig;
import com.b44t.messenger.AnimatorListenerAdapterProxy;
import com.b44t.ui.ActionBar.Theme;
import java.util.ArrayList;
import java.util.Locale;
@@ -80,336 +79,6 @@ public class PasscodeView extends FrameLayout {
void didAcceptedPassword();
}
private class AnimatingTextView extends FrameLayout {
private ArrayList<TextView> characterTextViews;
private ArrayList<TextView> dotTextViews;
private StringBuilder stringBuilder;
private String DOT = "\u2022";
private AnimatorSet currentAnimation;
private Runnable dotRunnable;
public AnimatingTextView(Context context) {
super(context);
characterTextViews = new ArrayList<>(4);
dotTextViews = new ArrayList<>(4);
stringBuilder = new StringBuilder(4);
for (int a = 0; a < 4; a++) {
TextView textView = new TextView(context);
textView.setTextColor(0xffffffff);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36);
textView.setGravity(Gravity.CENTER);
textView.setAlpha(0);
textView.setPivotX(AndroidUtilities.dp(25));
textView.setPivotY(AndroidUtilities.dp(25));
addView(textView);
LayoutParams layoutParams = (LayoutParams) textView.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(50);
layoutParams.height = AndroidUtilities.dp(50);
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
textView.setLayoutParams(layoutParams);
characterTextViews.add(textView);
textView = new TextView(context);
textView.setTextColor(0xffffffff);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36);
textView.setGravity(Gravity.CENTER);
textView.setAlpha(0);
textView.setText(DOT);
textView.setPivotX(AndroidUtilities.dp(25));
textView.setPivotY(AndroidUtilities.dp(25));
addView(textView);
layoutParams = (LayoutParams) textView.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(50);
layoutParams.height = AndroidUtilities.dp(50);
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
textView.setLayoutParams(layoutParams);
dotTextViews.add(textView);
}
}
private int getXForTextView(int pos) {
return (getMeasuredWidth() - stringBuilder.length() * AndroidUtilities.dp(30)) / 2 + pos * AndroidUtilities.dp(30) - AndroidUtilities.dp(10);
}
public void appendCharacter(String c) {
if (stringBuilder.length() == 4) {
return;
}
try {
performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
} catch (Exception e) {
FileLog.e("messenger", e);
}
ArrayList<Animator> animators = new ArrayList<>();
final int newPos = stringBuilder.length();
stringBuilder.append(c);
TextView textView = characterTextViews.get(newPos);
textView.setText(c);
textView.setTranslationX(getXForTextView(newPos));
animators.add(ObjectAnimator.ofFloat(textView, "scaleX", 0, 1));
animators.add(ObjectAnimator.ofFloat(textView, "scaleY", 0, 1));
animators.add(ObjectAnimator.ofFloat(textView, "alpha", 0, 1));
animators.add(ObjectAnimator.ofFloat(textView, "translationY", AndroidUtilities.dp(20), 0));
textView = dotTextViews.get(newPos);
textView.setTranslationX(getXForTextView(newPos));
textView.setAlpha(0);
animators.add(ObjectAnimator.ofFloat(textView, "scaleX", 0, 1));
animators.add(ObjectAnimator.ofFloat(textView, "scaleY", 0, 1));
animators.add(ObjectAnimator.ofFloat(textView, "translationY", AndroidUtilities.dp(20), 0));
for (int a = newPos + 1; a < 4; a++) {
textView = characterTextViews.get(a);
if (textView.getAlpha() != 0) {
animators.add(ObjectAnimator.ofFloat(textView, "scaleX", 0));
animators.add(ObjectAnimator.ofFloat(textView, "scaleY", 0));
animators.add(ObjectAnimator.ofFloat(textView, "alpha", 0));
}
textView = dotTextViews.get(a);
if (textView.getAlpha() != 0) {
animators.add(ObjectAnimator.ofFloat(textView, "scaleX", 0));
animators.add(ObjectAnimator.ofFloat(textView, "scaleY", 0));
animators.add(ObjectAnimator.ofFloat(textView, "alpha", 0));
}
}
if (dotRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(dotRunnable);
}
dotRunnable = new Runnable() {
@Override
public void run() {
if (dotRunnable != this) {
return;
}
ArrayList<Animator> animators = new ArrayList<>();
TextView textView = characterTextViews.get(newPos);
animators.add(ObjectAnimator.ofFloat(textView, "scaleX", 0));
animators.add(ObjectAnimator.ofFloat(textView, "scaleY", 0));
animators.add(ObjectAnimator.ofFloat(textView, "alpha", 0));
textView = dotTextViews.get(newPos);
animators.add(ObjectAnimator.ofFloat(textView, "scaleX", 1));
animators.add(ObjectAnimator.ofFloat(textView, "scaleY", 1));
animators.add(ObjectAnimator.ofFloat(textView, "alpha", 1));
currentAnimation = new AnimatorSet();
currentAnimation.setDuration(150);
currentAnimation.playTogether(animators);
currentAnimation.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
if (currentAnimation != null && currentAnimation.equals(animation)) {
currentAnimation = null;
}
}
});
currentAnimation.start();
}
};
AndroidUtilities.runOnUIThread(dotRunnable, 1500);
for (int a = 0; a < newPos; a++) {
textView = characterTextViews.get(a);
animators.add(ObjectAnimator.ofFloat(textView, "translationX", getXForTextView(a)));
animators.add(ObjectAnimator.ofFloat(textView, "scaleX", 0));
animators.add(ObjectAnimator.ofFloat(textView, "scaleY", 0));
animators.add(ObjectAnimator.ofFloat(textView, "alpha", 0));
animators.add(ObjectAnimator.ofFloat(textView, "translationY", 0));
textView = dotTextViews.get(a);
animators.add(ObjectAnimator.ofFloat(textView, "translationX", getXForTextView(a)));
animators.add(ObjectAnimator.ofFloat(textView, "scaleX", 1));
animators.add(ObjectAnimator.ofFloat(textView, "scaleY", 1));
animators.add(ObjectAnimator.ofFloat(textView, "alpha", 1));
animators.add(ObjectAnimator.ofFloat(textView, "translationY", 0));
}
if (currentAnimation != null) {
currentAnimation.cancel();
}
currentAnimation = new AnimatorSet();
currentAnimation.setDuration(150);
currentAnimation.playTogether(animators);
currentAnimation.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
if (currentAnimation != null && currentAnimation.equals(animation)) {
currentAnimation = null;
}
}
});
currentAnimation.start();
}
public String getString() {
return stringBuilder.toString();
}
public int lenght() {
return stringBuilder.length();
}
public void eraseLastCharacter() {
if (stringBuilder.length() == 0) {
return;
}
try {
performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
} catch (Exception e) {
FileLog.e("messenger", e);
}
ArrayList<Animator> animators = new ArrayList<>();
int deletingPos = stringBuilder.length() - 1;
if (deletingPos != 0) {
stringBuilder.deleteCharAt(deletingPos);
}
for (int a = deletingPos; a < 4; a++) {
TextView textView = characterTextViews.get(a);
if (textView.getAlpha() != 0) {
animators.add(ObjectAnimator.ofFloat(textView, "scaleX", 0));
animators.add(ObjectAnimator.ofFloat(textView, "scaleY", 0));
animators.add(ObjectAnimator.ofFloat(textView, "alpha", 0));
animators.add(ObjectAnimator.ofFloat(textView, "translationY", 0));
animators.add(ObjectAnimator.ofFloat(textView, "translationX", getXForTextView(a)));
}
textView = dotTextViews.get(a);
if (textView.getAlpha() != 0) {
animators.add(ObjectAnimator.ofFloat(textView, "scaleX", 0));
animators.add(ObjectAnimator.ofFloat(textView, "scaleY", 0));
animators.add(ObjectAnimator.ofFloat(textView, "alpha", 0));
animators.add(ObjectAnimator.ofFloat(textView, "translationY", 0));
animators.add(ObjectAnimator.ofFloat(textView, "translationX", getXForTextView(a)));
}
}
if (deletingPos == 0) {
stringBuilder.deleteCharAt(deletingPos);
}
for (int a = 0; a < deletingPos; a++) {
TextView textView = characterTextViews.get(a);
animators.add(ObjectAnimator.ofFloat(textView, "translationX", getXForTextView(a)));
textView = dotTextViews.get(a);
animators.add(ObjectAnimator.ofFloat(textView, "translationX", getXForTextView(a)));
}
if (dotRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(dotRunnable);
dotRunnable = null;
}
if (currentAnimation != null) {
currentAnimation.cancel();
}
currentAnimation = new AnimatorSet();
currentAnimation.setDuration(150);
currentAnimation.playTogether(animators);
currentAnimation.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
if (currentAnimation != null && currentAnimation.equals(animation)) {
currentAnimation = null;
}
}
});
currentAnimation.start();
}
private void eraseAllCharacters(final boolean animated) {
if (stringBuilder.length() == 0) {
return;
}
if (dotRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(dotRunnable);
dotRunnable = null;
}
if (currentAnimation != null) {
currentAnimation.cancel();
currentAnimation = null;
}
stringBuilder.delete(0, stringBuilder.length());
if (animated) {
ArrayList<Animator> animators = new ArrayList<>();
for (int a = 0; a < 4; a++) {
TextView textView = characterTextViews.get(a);
if (textView.getAlpha() != 0) {
animators.add(ObjectAnimator.ofFloat(textView, "scaleX", 0));
animators.add(ObjectAnimator.ofFloat(textView, "scaleY", 0));
animators.add(ObjectAnimator.ofFloat(textView, "alpha", 0));
}
textView = dotTextViews.get(a);
if (textView.getAlpha() != 0) {
animators.add(ObjectAnimator.ofFloat(textView, "scaleX", 0));
animators.add(ObjectAnimator.ofFloat(textView, "scaleY", 0));
animators.add(ObjectAnimator.ofFloat(textView, "alpha", 0));
}
}
currentAnimation = new AnimatorSet();
currentAnimation.setDuration(150);
currentAnimation.playTogether(animators);
currentAnimation.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
if (currentAnimation != null && currentAnimation.equals(animation)) {
currentAnimation = null;
}
}
});
currentAnimation.start();
} else {
for (int a = 0; a < 4; a++) {
characterTextViews.get(a).setAlpha(0);
dotTextViews.get(a).setAlpha(0);
}
}
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
if (dotRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(dotRunnable);
dotRunnable = null;
}
if (currentAnimation != null) {
currentAnimation.cancel();
currentAnimation = null;
}
for (int a = 0; a < 4; a++) {
if (a < stringBuilder.length()) {
TextView textView = characterTextViews.get(a);
textView.setAlpha(0);
textView.setScaleX(1);
textView.setScaleY(1);
textView.setTranslationY(0);
textView.setTranslationX(getXForTextView(a));
textView = dotTextViews.get(a);
textView.setAlpha(1);
textView.setScaleX(1);
textView.setScaleY(1);
textView.setTranslationY(0);
textView.setTranslationX(getXForTextView(a));
} else {
characterTextViews.get(a).setAlpha(0);
dotTextViews.get(a).setAlpha(0);
}
}
super.onLayout(changed, left, top, right, bottom);
}
}
private Drawable backgroundDrawable;
private FrameLayout numbersFrameLayout;
private ArrayList<TextView> numberTextViews;
@@ -418,14 +87,12 @@ public class PasscodeView extends FrameLayout {
private FrameLayout passwordFrameLayout;
private ImageView eraseView;
private EditText passwordEditText;
private AnimatingTextView passwordEditText2;
private FrameLayout backgroundFrameLayout;
private TextView passcodeTextView;
private ImageView checkImage;
private int keyboardHeight = 0;
private CancellationSignal cancellationSignal;
private ImageView fingerprintImageView;
private TextView fingerprintStatusTextView;
private boolean selfCancelled;
private AlertDialog fingerprintDialog;
@@ -434,9 +101,6 @@ public class PasscodeView extends FrameLayout {
private PasscodeViewDelegate delegate;
private final static int id_fingerprint_textview = 1000;
private final static int id_fingerprint_imageview = 1001;
public PasscodeView(final Context context) {
super(context);
@@ -486,17 +150,6 @@ public class PasscodeView extends FrameLayout {
layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
passcodeTextView.setLayoutParams(layoutParams);
passwordEditText2 = new AnimatingTextView(context);
passwordFrameLayout.addView(passwordEditText2);
layoutParams = (FrameLayout.LayoutParams) passwordEditText2.getLayoutParams();
layoutParams.height = LayoutHelper.WRAP_CONTENT;
layoutParams.width = LayoutHelper.MATCH_PARENT;
layoutParams.leftMargin = AndroidUtilities.dp(70);
layoutParams.rightMargin = AndroidUtilities.dp(70);
layoutParams.bottomMargin = AndroidUtilities.dp(6);
layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
passwordEditText2.setLayoutParams(layoutParams);
passwordEditText = new EditText(context);
passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36);
passwordEditText.setTextColor(0xffffffff);
@@ -678,7 +331,6 @@ public class PasscodeView extends FrameLayout {
@Override
public boolean onLongClick(View v) {
passwordEditText.setText("");
passwordEditText2.eraseAllCharacters(true);
return true;
}
});
@@ -689,40 +341,43 @@ public class PasscodeView extends FrameLayout {
int tag = (Integer) v.getTag();
switch (tag) {
case 0:
passwordEditText2.appendCharacter("0");
appendCharacter("0");
break;
case 1:
passwordEditText2.appendCharacter("1");
appendCharacter("1");
break;
case 2:
passwordEditText2.appendCharacter("2");
appendCharacter("2");
break;
case 3:
passwordEditText2.appendCharacter("3");
appendCharacter("3");
break;
case 4:
passwordEditText2.appendCharacter("4");
appendCharacter("4");
break;
case 5:
passwordEditText2.appendCharacter("5");
appendCharacter("5");
break;
case 6:
passwordEditText2.appendCharacter("6");
appendCharacter("6");
break;
case 7:
passwordEditText2.appendCharacter("7");
appendCharacter("7");
break;
case 8:
passwordEditText2.appendCharacter("8");
appendCharacter("8");
break;
case 9:
passwordEditText2.appendCharacter("9");
appendCharacter("9");
break;
case 10:
passwordEditText2.eraseLastCharacter();
String text = passwordEditText.getText().toString();
if( text.length()>0) {
passwordEditText.setText(text.substring(0,text.length()-1));
}
break;
}
if (passwordEditText2.lenght() == 4) {
if (passwordEditText.getText().toString().length() == 4) {
processDone(false);
}
}
@@ -740,25 +395,24 @@ public class PasscodeView extends FrameLayout {
}
}
private void appendCharacter(String c)
{
passwordEditText.setText(passwordEditText.getText()+c);
}
public void setDelegate(PasscodeViewDelegate delegate) {
this.delegate = delegate;
}
private void processDone(boolean fingerprint) {
if (!fingerprint) {
String password = "";
if (UserConfig.passcodeType == 0) {
password = passwordEditText2.getString();
} else if (UserConfig.passcodeType == 1) {
password = passwordEditText.getText().toString();
}
String password = passwordEditText.getText().toString();
if (password.length() == 0) {
onPasscodeError();
return;
}
if (!UserConfig.checkPasscode(password)) {
passwordEditText.setText("");
passwordEditText2.eraseAllCharacters(true);
onPasscodeError();
return;
}
@@ -866,35 +520,14 @@ public class PasscodeView extends FrameLayout {
FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.from(ApplicationLoader.applicationContext);
if (fingerprintManager.isHardwareDetected() && fingerprintManager.hasEnrolledFingerprints()) {
RelativeLayout relativeLayout = new RelativeLayout(getContext());
relativeLayout.setPadding(AndroidUtilities.dp(24), AndroidUtilities.dp(16), AndroidUtilities.dp(24), AndroidUtilities.dp(8));
TextView fingerprintTextView = new TextView(getContext());
fingerprintTextView.setTextColor(0xff939393);
fingerprintTextView.setId(id_fingerprint_textview);
fingerprintTextView.setTextAppearance(android.R.style.TextAppearance_Material_Subhead);
fingerprintTextView.setText(LocaleController.getString("FingerprintInfo", R.string.FingerprintInfo));
relativeLayout.addView(fingerprintTextView);
RelativeLayout.LayoutParams layoutParams = LayoutHelper.createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START);
fingerprintTextView.setLayoutParams(layoutParams);
fingerprintImageView = new ImageView(getContext());
fingerprintImageView.setImageResource(R.drawable.ic_fp_40px);
fingerprintImageView.setId(id_fingerprint_imageview);
relativeLayout.addView(fingerprintImageView, LayoutHelper.createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, 0, 20, 0, 0, RelativeLayout.ALIGN_PARENT_START, RelativeLayout.BELOW, id_fingerprint_textview));
relativeLayout.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(16), AndroidUtilities.dp(16), AndroidUtilities.dp(8));
fingerprintStatusTextView = new TextView(getContext());
fingerprintStatusTextView.setGravity(Gravity.CENTER_VERTICAL);
fingerprintStatusTextView.setText(LocaleController.getString("FingerprintHelp", R.string.FingerprintHelp));
fingerprintStatusTextView.setTextAppearance(android.R.style.TextAppearance_Material_Body1);
fingerprintStatusTextView.setTextColor(0x42000000);
fingerprintStatusTextView.setText(ApplicationLoader.applicationContext.getString(R.string.FingerprintInfo));
fingerprintStatusTextView.setTextAppearance(android.R.style.TextAppearance_Material_Subhead);
relativeLayout.addView(fingerprintStatusTextView);
layoutParams = LayoutHelper.createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT);
layoutParams.setMarginStart(AndroidUtilities.dp(16));
layoutParams.addRule(RelativeLayout.ALIGN_BOTTOM, id_fingerprint_imageview);
layoutParams.addRule(RelativeLayout.ALIGN_TOP, id_fingerprint_imageview);
layoutParams.addRule(RelativeLayout.END_OF, id_fingerprint_imageview);
RelativeLayout.LayoutParams layoutParams = LayoutHelper.createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT);
fingerprintStatusTextView.setLayoutParams(layoutParams);
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
@@ -983,46 +616,31 @@ public class PasscodeView extends FrameLayout {
}
setAlpha(1.0f);
setTranslationY(0);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
int selectedBackground = preferences.getInt("selectedBackground", 1000001);
if (selectedBackground == 1000001) {
backgroundFrameLayout.setBackgroundColor(0xff517c9e);
backgroundDrawable = ApplicationLoader.getCachedWallpaper();
if (backgroundDrawable != null) {
backgroundFrameLayout.setBackgroundColor(0xb6000000);
} else {
backgroundDrawable = ApplicationLoader.getCachedWallpaper();
if (backgroundDrawable != null) {
backgroundFrameLayout.setBackgroundColor(0xbf000000);
} else {
backgroundFrameLayout.setBackgroundColor(0xff517c9e);
}
backgroundFrameLayout.setBackgroundColor(Theme.ACTION_BAR_COLOR);
}
passcodeTextView.setText(LocaleController.getString("EnterYourPasscode", R.string.EnterYourPasscode));
if (UserConfig.passcodeType == 0) {
//InputFilter[] filterArray = new InputFilter[1];
//filterArray[0] = new InputFilter.LengthFilter(4);
//passwordEditText.setFilters(filterArray);
//passwordEditText.setInputType(InputType.TYPE_CLASS_PHONE);
//passwordEditText.setFocusable(false);
//passwordEditText.setFocusableInTouchMode(false);
numbersFrameLayout.setVisibility(VISIBLE);
passwordEditText.setVisibility(GONE);
passwordEditText2.setVisibility(VISIBLE);
passwordEditText.setFocusable(false);
passwordEditText.setFocusableInTouchMode(false);
checkImage.setVisibility(GONE);
} else if (UserConfig.passcodeType == 1) {
passwordEditText.setFilters(new InputFilter[0]);
passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
numbersFrameLayout.setVisibility(GONE);
passwordEditText.setFocusable(true);
passwordEditText.setFocusableInTouchMode(true);
passwordEditText.setVisibility(VISIBLE);
passwordEditText2.setVisibility(GONE);
checkImage.setVisibility(VISIBLE);
}
setVisibility(VISIBLE);
passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_PASSWORD);
passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
passwordEditText.setText("");
passwordEditText2.eraseAllCharacters(false);
setOnTouchListener(new OnTouchListener() {
@Override
@@ -1033,7 +651,6 @@ public class PasscodeView extends FrameLayout {
}
private void showFingerprintError(CharSequence error) {
fingerprintImageView.setImageResource(R.drawable.ic_fingerprint_error);
fingerprintStatusTextView.setText(error);
fingerprintStatusTextView.setTextColor(0xfff4511e);
Vibrator v = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
@@ -1,276 +0,0 @@
/*******************************************************************************
*
* Messenger Android Frontend
* (C) 2013-2016 Nikolai Kudashov
* (C) 2017 Björn Petersen
* Contact: r10s@b44t.com, http://b44t.com
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/ .
*
******************************************************************************/
package com.b44t.ui.Components;
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Typeface;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.b44t.messenger.AndroidUtilities;
import com.b44t.messenger.AnimatorListenerAdapterProxy;
import com.b44t.messenger.MediaController;
import com.b44t.messenger.MessageObject;
import com.b44t.messenger.NotificationCenter;
import com.b44t.messenger.R;
import com.b44t.ui.ActionBar.BaseFragment;
import com.b44t.ui.ActionBar.Theme;
import com.b44t.ui.AudioPlayerActivity;
public class PlayerView extends FrameLayout implements NotificationCenter.NotificationCenterDelegate {
private ImageView playButton;
private TextView titleTextView;
private MessageObject lastMessageObject;
private AnimatorSet animatorSet;
private float yPosition;
private BaseFragment fragment;
private float topPadding;
private boolean visible;
public PlayerView(Context context, BaseFragment parentFragment) {
super(context);
fragment = parentFragment;
visible = true;
((ViewGroup) fragment.getFragmentView()).setClipToPadding(false);
setTag(1);
FrameLayout frameLayout = new FrameLayout(context);
frameLayout.setBackgroundColor(Theme.INAPP_PLAYER_BACKGROUND_COLOR);
addView(frameLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 36, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 0));
View shadow = new View(context);
shadow.setBackgroundResource(R.drawable.header_shadow);
addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.LEFT | Gravity.TOP, 0, 36, 0, 0));
playButton = new ImageView(context);
playButton.setScaleType(ImageView.ScaleType.CENTER);
addView(playButton, LayoutHelper.createFrame(36, 36, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 0));
playButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (MediaController.getInstance().isAudioPaused()) {
MediaController.getInstance().playAudio(MediaController.getInstance().getPlayingMessageObject());
} else {
MediaController.getInstance().pauseAudio(MediaController.getInstance().getPlayingMessageObject());
}
}
});
titleTextView = new TextView(context);
titleTextView.setTextColor(Theme.INAPP_PLAYER_TITLE_TEXT_COLOR);
titleTextView.setMaxLines(1);
titleTextView.setLines(1);
titleTextView.setSingleLine(true);
titleTextView.setEllipsize(TextUtils.TruncateAt.END);
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
titleTextView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
addView(titleTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 36, Gravity.LEFT | Gravity.TOP, 35, 0, 36, 0));
ImageView closeButton = new ImageView(context);
closeButton.setImageResource(R.drawable.miniplayer_close);
closeButton.setScaleType(ImageView.ScaleType.CENTER);
addView(closeButton, LayoutHelper.createFrame(36, 36, Gravity.RIGHT | Gravity.TOP));
closeButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MediaController.getInstance().cleanupPlayer(true, true);
}
});
setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
if (messageObject != null && messageObject.isMusic() && fragment != null) {
fragment.presentFragment(new AudioPlayerActivity());
}
}
});
}
public float getTopPadding() {
return topPadding;
}
public void setTopPadding(float value) {
topPadding = value;
if (fragment != null) {
View view = fragment.getFragmentView();
if (view != null) {
view.setPadding(0, (int) topPadding, 0, 0);
}
}
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
topPadding = 0;
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioDidReset);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioPlayStateChanged);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioDidStarted);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidReset);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioPlayStateChanged);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidStarted);
checkPlayer(true);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, AndroidUtilities.dp(39));
}
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.audioDidStarted || id == NotificationCenter.audioPlayStateChanged || id == NotificationCenter.audioDidReset) {
checkPlayer(false);
}
}
private void checkPlayer(boolean create) {
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
View fragmentView = fragment.getFragmentView();
if (!create && fragmentView != null) {
if (fragmentView.getParent() == null || ((View) fragmentView.getParent()).getVisibility() != VISIBLE) {
create = true;
}
}
if (messageObject == null || messageObject.getId() == 0/* || !messageObject.isMusic()*/) {
lastMessageObject = null;
if (visible) {
visible = false;
if (create) {
if (getVisibility() != GONE) {
setVisibility(GONE);
}
setTopPadding(0);
} else {
if (animatorSet != null) {
animatorSet.cancel();
animatorSet = null;
}
animatorSet = new AnimatorSet();
animatorSet.playTogether(ObjectAnimator.ofFloat(this, "translationY", -AndroidUtilities.dp(36)),
ObjectAnimator.ofFloat(this, "topPadding", 0));
animatorSet.setDuration(200);
animatorSet.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
if (animatorSet != null && animatorSet.equals(animation)) {
setVisibility(GONE);
animatorSet = null;
}
}
});
animatorSet.start();
}
}
} else {
if (create && topPadding == 0) {
setTopPadding(AndroidUtilities.dp(36));
setTranslationY(0);
yPosition = 0;
}
if (!visible) {
if (!create) {
if (animatorSet != null) {
animatorSet.cancel();
animatorSet = null;
}
animatorSet = new AnimatorSet();
animatorSet.playTogether(ObjectAnimator.ofFloat(this, "translationY", -AndroidUtilities.dp(36), 0),
ObjectAnimator.ofFloat(this, "topPadding", AndroidUtilities.dp(36)));
animatorSet.setDuration(200);
animatorSet.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Animator animation) {
if (animatorSet != null && animatorSet.equals(animation)) {
animatorSet = null;
}
}
});
animatorSet.start();
}
visible = true;
setVisibility(VISIBLE);
}
if (MediaController.getInstance().isAudioPaused()) {
playButton.setImageResource(R.drawable.miniplayer_play);
} else {
playButton.setImageResource(R.drawable.miniplayer_pause);
}
if (lastMessageObject != messageObject) {
lastMessageObject = messageObject;
SpannableStringBuilder stringBuilder;
if (lastMessageObject.isVoice()) {
stringBuilder = new SpannableStringBuilder(String.format("%s %s", messageObject.getMusicAuthor(), messageObject.getMusicTitle()));
titleTextView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
} else {
stringBuilder = new SpannableStringBuilder(String.format("%s - %s", messageObject.getMusicAuthor(), messageObject.getMusicTitle()));
titleTextView.setEllipsize(TextUtils.TruncateAt.END);
}
TypefaceSpan span = new TypefaceSpan(Typeface.DEFAULT_BOLD, 0, Theme.INAPP_PLAYER_PERFORMER_TEXT_COLOR);
stringBuilder.setSpan(span, 0, messageObject.getMusicAuthor().length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
titleTextView.setText(stringBuilder);
}
}
}
@Override
public void setTranslationY(float translationY) {
super.setTranslationY(translationY);
yPosition = translationY;
invalidate();
}
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
int restoreToCount = canvas.save();
if (yPosition < 0) {
canvas.clipRect(0, (int) -yPosition, child.getMeasuredWidth(), AndroidUtilities.dp(39));
}
final boolean result = super.drawChild(canvas, child, drawingTime);
canvas.restoreToCount(restoreToCount);
return result;
}
}
@@ -30,7 +30,6 @@ import android.view.MotionEvent;
import android.view.View;
import com.b44t.messenger.AndroidUtilities;
import com.b44t.messenger.MessageObject;
public class SeekBarWaveform {
@@ -45,13 +44,10 @@ public class SeekBarWaveform {
private int height;
private SeekBar.SeekBarDelegate delegate;
private byte[] waveformBytes;
private MessageObject messageObject;
private View parentView;
private boolean selected;
private int innerColor;
private int outerColor;
private int selectedColor;
public SeekBarWaveform(Context context) {
if (paintInner == null) {
@@ -64,24 +60,15 @@ public class SeekBarWaveform {
delegate = seekBarDelegate;
}
public void setColors(int inner, int outer, int selected) {
public void setColors(int inner, int outer) {
innerColor = inner;
outerColor = outer;
selectedColor = selected;
}
public void setWaveform(byte[] waveform) {
waveformBytes = waveform;
}
public void setSelected(boolean value) {
selected = value;
}
public void setMessageObject(MessageObject object) {
messageObject = object;
}
public void setParentView(View view) {
parentView = view;
}
@@ -162,7 +149,7 @@ public class SeekBarWaveform {
float barCounter = 0;
int nextBarNum = 0;
paintInner.setColor(messageObject != null && !messageObject.isOutOwner() && messageObject.isContentUnread() && messageObject.messageOwner.to_id.channel_id == 0 ? outerColor : (selected ? selectedColor : innerColor));
paintInner.setColor(innerColor);
paintOuter.setColor(outerColor);
int y = (height - AndroidUtilities.dp(14)) / 2;
@@ -45,6 +45,7 @@ import android.widget.TextView;
import com.b44t.messenger.AndroidUtilities;
import com.b44t.messenger.AnimatorListenerAdapterProxy;
import com.b44t.messenger.ApplicationLoader;
import com.b44t.messenger.Emoji;
import com.b44t.messenger.LocaleController;
import com.b44t.messenger.NotificationCenter;
@@ -341,7 +342,7 @@ public class StickersAlert extends BottomSheet implements NotificationCenter.Not
stickerPreviewLayout.addView(previewSendButtonShadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48));
if (delegate != null) {
previewSendButton.setText(LocaleController.getString("SendSticker", R.string.SendSticker).toUpperCase());
previewSendButton.setText(ApplicationLoader.applicationContext.getString(R.string.Send).toUpperCase());
stickerImageView.setLayoutParams(LayoutHelper.createFrame(size, size, Gravity.CENTER, 0, 0, 0, 30));
previewSendButton.setVisibility(View.VISIBLE);
previewSendButtonShadow.setVisibility(View.VISIBLE);
@@ -1,39 +0,0 @@
/*******************************************************************************
*
* Messenger Android Frontend
* (C) 2013-2016 Nikolai Kudashov
* (C) 2017 Björn Petersen
* Contact: r10s@b44t.com, http://b44t.com
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/ .
*
******************************************************************************/
package com.b44t.ui.Components;
import android.text.TextPaint;
import android.text.style.URLSpan;
public class URLSpanNoUnderline extends URLSpan {
public URLSpanNoUnderline(String url) {
super(url);
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
}
@@ -1,32 +0,0 @@
/*******************************************************************************
*
* Messenger Android Frontend
* (C) 2013-2016 Nikolai Kudashov
* (C) 2017 Björn Petersen
* Contact: r10s@b44t.com, http://b44t.com
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/ .
*
******************************************************************************/
package com.b44t.ui.Components;
import android.text.style.URLSpan;
public class URLSpanReplacement extends URLSpan {
public URLSpanReplacement(String url) {
super(url);
}
}
@@ -37,7 +37,7 @@ import com.b44t.messenger.R;
public class VideoSeekBarView extends View {
private static Drawable thumbDrawable1;
private static Paint innerPaint1 = new Paint();
//private static Paint innerPaint1 = new Paint();
private static int thumbWidth;
private static int thumbHeight;
private int thumbDX = 0;
@@ -52,7 +52,7 @@ public class VideoSeekBarView extends View {
private void init(Context context) {
if (thumbDrawable1 == null) {
thumbDrawable1 = context.getResources().getDrawable(R.drawable.videolapse);
innerPaint1.setColor(0x99999999);
//innerPaint1.setColor(0x99999999);
thumbWidth = thumbDrawable1.getIntrinsicWidth();
thumbHeight = thumbDrawable1.getIntrinsicHeight();
}
@@ -133,7 +133,7 @@ public class VideoSeekBarView extends View {
protected void onDraw(Canvas canvas) {
int y = (getMeasuredHeight() - thumbHeight) / 2;
int thumbX = (int)((getMeasuredWidth() - thumbWidth) * progress);
canvas.drawRect(thumbWidth / 2, getMeasuredHeight() / 2 - AndroidUtilities.dp(1), getMeasuredWidth() - thumbWidth / 2, getMeasuredHeight() / 2 + AndroidUtilities.dp(1), innerPaint1);
//canvas.drawRect(thumbWidth / 2, getMeasuredHeight() / 2 - AndroidUtilities.dp(1), getMeasuredWidth() - thumbWidth / 2, getMeasuredHeight() / 2 + AndroidUtilities.dp(1), innerPaint1);
thumbDrawable1.setBounds(thumbX, y, thumbX + thumbWidth, y + thumbHeight);
thumbDrawable1.draw(canvas);
}
@@ -113,7 +113,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setBackButtonImage(R.drawable.ic_close_white);
actionBar.setAllowOverlayTitle(true);
if (do_what==CREATE_CONTACT) {
actionBar.setTitle(LocaleController.getString("NewContactTitle", R.string.NewContactTitle));
@@ -99,6 +99,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
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;
public final static int SELECT_CONTACT_TO_ATTACH = 5;
private ContactsActivityDelegate delegate;
@@ -146,6 +147,10 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
{
title = LocaleController.getString("BlockContact", R.string.BlockContact);
}
else if( do_what == SELECT_CONTACT_TO_ATTACH )
{
title = ApplicationLoader.applicationContext.getString(R.string.SelectContact);
}
return true;
}
@@ -175,12 +180,12 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
}
// initialize action
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setBackButtonImage(do_what == SELECT_CONTACTS_FOR_NEW_GROUP? R.drawable.ic_close_white : R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if( title != null ) {
actionBar.setTitle(title);
if( subtitle != null ) {
actionBar.setSubtitle(do_sync_now? LocaleController.getString("OneMomentPlease", R.string.OneMomentPlease) : subtitle);
actionBar.setSubtitle(do_sync_now? ApplicationLoader.applicationContext.getString(R.string.OneMoment) : subtitle);
}
}
@@ -250,9 +255,6 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
ActionBarMenu menu = actionBar.createMenu();
if( do_what == SELECT_CONTACTS_FOR_NEW_GROUP ) {
menu.addItem(id_done_button, R.drawable.ic_done);
}
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) {
@@ -260,6 +262,12 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
}
item.addSubItem(id_add_contact, LocaleController.getString("NewContactTitle", R.string.NewContactTitle), 0);
if( do_what == SELECT_CONTACTS_FOR_NEW_GROUP ) {
menu.addItem(id_done_button, R.drawable.ic_done); // this should be the very most right icon
}
listViewAdapter = new ContactsAdapter(context);
listViewAdapter.setCheckedMap(selectedContacts);
@@ -290,7 +298,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
AndroidUtilities.clearCursorDrawable(userSelectEditText);
frameLayout.addView(userSelectEditText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 10, 0, 10, 0));
userSelectEditText.setHint(LocaleController.getString("SeachUser", R.string.SeachUser));
userSelectEditText.setHint(ApplicationLoader.applicationContext.getString(R.string.Search));
userSelectEditText.setTextIsSelectable(false);
userSelectEditText.addTextChangedListener(new TextWatcher() {
@Override
@@ -43,6 +43,7 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewOutlineProvider;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.EditText;
import android.widget.FrameLayout;
@@ -57,6 +58,7 @@ import com.b44t.messenger.LocaleController;
import com.b44t.messenger.MrChat;
import com.b44t.messenger.MrMailbox;
import com.b44t.messenger.MrMsg;
import com.b44t.messenger.Utilities;
import com.b44t.messenger.support.widget.LinearLayoutManager;
import com.b44t.messenger.support.widget.RecyclerView;
import com.b44t.messenger.FileLog;
@@ -73,7 +75,6 @@ import com.b44t.ui.ActionBar.ActionBarMenu;
import com.b44t.ui.ActionBar.ActionBarMenuItem;
import com.b44t.ui.ActionBar.BaseFragment;
import com.b44t.ui.ActionBar.MenuDrawable;
import com.b44t.ui.Components.PlayerView;
import com.b44t.ui.Components.EmptyTextProgressView;
import com.b44t.ui.Components.LayoutHelper;
import com.b44t.ui.Components.RecyclerListView;
@@ -118,6 +119,8 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
private DialogsActivityDelegate delegate;
private static final int ID_LOCK_APP = 1;
public interface DialogsActivityDelegate {
void didSelectDialog(DialogsActivity fragment, long dialog_id, boolean param);
}
@@ -187,7 +190,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
ActionBarMenu menu = actionBar.createMenu();
if (!onlySelect ) {
passcodeItem = menu.addItem(1, R.drawable.lock_close);
passcodeItem = menu.addItem(ID_LOCK_APP, R.drawable.lock_close);
updatePasscodeButton();
}
final ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true, true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@@ -273,10 +276,32 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
} else if (parentLayout != null) {
parentLayout.getDrawerLayoutContainer().openDrawer(false);
}
} else if (id == 1) {
} else if (id == ID_LOCK_APP) {
listView.setVisibility(View.INVISIBLE);
UserConfig.appLocked = !UserConfig.appLocked;
UserConfig.saveConfig(false);
updatePasscodeButton();
if( UserConfig.appLocked )
{
// hide list as it is visible in the "last app switcher" otherwise, save state
updatePasscodeButton();
// finish the activity after a little delay; 200 ms shoud be enough to
// let the system update its screenshots for the "last app switcher".
// FLAG_SECURE may be a little too much as it affects display and screenshots;
// it also does not really direct this problem.
Utilities.searchQueue.postRunnable(new Runnable() {
@Override
public void run() {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
getParentActivity().finish();
}
});
}
}, 200);
}
}
}
});
@@ -480,10 +505,6 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
searchEmptyView.setVisibility(View.GONE);
listView.setEmptyView(emptyView);
if (!onlySelect ) {
frameLayout.addView(new PlayerView(context, this), LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 39, Gravity.TOP | Gravity.LEFT, 0, -36, 0, 0));
}
return fragmentView;
}
@@ -516,8 +537,8 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
ArrayList<String> permissons = new ArrayList<>();
if (activity.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
permissons.add(Manifest.permission.READ_CONTACTS);
permissons.add(Manifest.permission.WRITE_CONTACTS);
permissons.add(Manifest.permission.GET_ACCOUNTS);
//permissons.add(Manifest.permission.WRITE_CONTACTS);
//permissons.add(Manifest.permission.GET_ACCOUNTS);
}
if (activity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
permissons.add(Manifest.permission.READ_EXTERNAL_STORAGE);
@@ -27,7 +27,6 @@ import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -85,7 +84,6 @@ public class DocumentSelectActivity extends BaseFragment {
private ArrayList<ListItem> items = new ArrayList<>();
private boolean receiverRegistered = false;
private ArrayList<HistoryEntry> history = new ArrayList<>();
private long sizeLimit = 1024 * 1024 * 1536;
private DocumentSelectActivityDelegate delegate;
private HashMap<String, ListItem> selectedFiles = new HashMap<>();
private ArrayList<View> actionModeViews = new ArrayList<>();
@@ -238,15 +236,9 @@ public class DocumentSelectActivity extends BaseFragment {
File file = item.file;
if (file != null && !file.isDirectory()) {
if (!file.canRead()) {
showErrorBox(LocaleController.getString("AccessError", R.string.AccessError));
showErrorBox(ApplicationLoader.applicationContext.getString(R.string.AccessError));
return false;
}
if (sizeLimit != 0) {
if (file.length() > sizeLimit) {
showErrorBox(LocaleController.formatString("FileUploadLimit", R.string.FileUploadLimit, AndroidUtilities.formatFileSize(sizeLimit)));
return false;
}
}
if (file.length() == 0) {
return false;
}
@@ -311,15 +303,9 @@ public class DocumentSelectActivity extends BaseFragment {
listView.setSelection(0);
} else {
if (!file.canRead()) {
showErrorBox(LocaleController.getString("AccessError", R.string.AccessError));
showErrorBox(ApplicationLoader.applicationContext.getString(R.string.AccessError));
file = new File("/mnt/sdcard");
}
if (sizeLimit != 0) {
if (file.length() > sizeLimit) {
showErrorBox(LocaleController.formatString("FileUploadLimit", R.string.FileUploadLimit, AndroidUtilities.formatFileSize(sizeLimit)));
return;
}
}
if (file.length() == 0) {
return;
}
@@ -431,7 +417,7 @@ public class DocumentSelectActivity extends BaseFragment {
return true;
}
}
showErrorBox(LocaleController.getString("AccessError", R.string.AccessError));
showErrorBox(ApplicationLoader.applicationContext.getString(R.string.AccessError));
return false;
}
emptyView.setText(LocaleController.getString("NoFiles", R.string.NoFiles));
@@ -443,7 +429,7 @@ public class DocumentSelectActivity extends BaseFragment {
return false;
}
if (files == null) {
showErrorBox(LocaleController.getString("UnknownError", R.string.UnknownError));
showErrorBox(ApplicationLoader.applicationContext.getString(R.string.ErrorHint));
return false;
}
currentDir = dir;
@@ -511,10 +497,7 @@ public class DocumentSelectActivity extends BaseFragment {
}
private void showErrorBox(String error) {
if (getParentActivity() == null) {
return;
}
new AlertDialog.Builder(getParentActivity()).setTitle(LocaleController.getString("AppName", R.string.AppName)).setMessage(error).setPositiveButton(LocaleController.getString("OK", R.string.OK), null).show();
AndroidUtilities.showHint(getParentActivity(), error);
}
@SuppressLint("NewApi")
@@ -524,7 +507,6 @@ public class DocumentSelectActivity extends BaseFragment {
HashSet<String> paths = new HashSet<>();
String defaultPath = Environment.getExternalStorageDirectory().getPath();
boolean isDefaultPathRemovable = Environment.isExternalStorageRemovable();
String defaultPathState = Environment.getExternalStorageState();
if (defaultPathState.equals(Environment.MEDIA_MOUNTED) || defaultPathState.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
ListItem ext = new ListItem();
@@ -115,7 +115,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setBackButtonImage(R.drawable.ic_close_white);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("NewGroup", R.string.NewGroup));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@@ -27,10 +27,10 @@ import android.Manifest;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Application;
import android.content.ContentResolver;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Point;
@@ -60,8 +60,6 @@ import android.widget.Toast;
import com.b44t.messenger.AndroidUtilities;
import com.b44t.messenger.ContactsController;
import com.b44t.messenger.ImageLoader;
import com.b44t.messenger.MessageObject;
import com.b44t.messenger.MessagesController;
import com.b44t.messenger.MrChat;
import com.b44t.messenger.MrMailbox;
import com.b44t.messenger.SendMessagesHelper;
@@ -86,23 +84,19 @@ import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class LaunchActivity extends Activity implements ActionBarLayout.ActionBarLayoutDelegate, NotificationCenter.NotificationCenterDelegate, DialogsActivity.DialogsActivityDelegate {
private boolean finished;
private String videoPath;
private String sendingText;
private TLRPC.TL_messageMediaGeo sendingLocation;
private ArrayList<Uri> photoPathsArray;
private ArrayList<String> documentsPathsArray;
private ArrayList<Uri> documentsUrisArray;
private String documentsMimeType;
private ArrayList<String> documentsOriginalPathsArray;
private ArrayList<TLRPC.User> contactsToSend;
private ArrayList<Integer> contactsToSend;
private int currentConnectionState;
private static ArrayList<BaseFragment> mainFragmentsStack = new ArrayList<>();
private static ArrayList<BaseFragment> layerFragmentsStack = new ArrayList<>();
@@ -331,7 +325,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, MrMailbox.getInviteText());
startActivityForResult(Intent.createChooser(intent, LocaleController.getString("InviteMenuEntry", R.string.InviteMenuEntry)), 500);
startActivity(Intent.createChooser(intent, LocaleController.getString("InviteMenuEntry", R.string.InviteMenuEntry)));
} catch (Exception e) {
FileLog.e("tmessages", e);
}
@@ -348,7 +342,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
drawerLayoutContainer.closeDrawer(false);
}
else if (position == DrawerLayoutAdapter.iFaq) {
Browser.openUrl(LaunchActivity.this, "https://messenger.b44t.com/help");
Browser.openUrl(LaunchActivity.this, "https://getdelta.org/help");
drawerLayoutContainer.closeDrawer(false);
}
}
@@ -374,7 +368,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
NotificationCenter.getInstance().addObserver(this, NotificationCenter.mainUserInfoChanged);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeOtherAppActivities);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.didUpdatedConnectionState);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.wasUnableToFindCurrentLocation);
if (actionBarLayout.fragmentsStack.isEmpty()) {
if ( MrMailbox.isConfigured()==0 ) {
@@ -516,7 +509,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
private class VcardData {
String name;
ArrayList<String> phones = new ArrayList<>();
ArrayList<String> emails = new ArrayList<>();
}
private boolean handleIntent(Intent intent, boolean isNew, boolean restore, boolean fromPassword) {
@@ -530,13 +523,10 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
} else {
boolean pushOpened = false;
//Integer push_user_id = 0;
Integer push_chat_id = 0;
//Integer push_enc_id = 0;
Integer open_settings = 0;
//Integer open_settings = 0;
long dialogId = intent != null && intent.getExtras() != null ? intent.getExtras().getLong("dialogId", 0) : 0;
boolean showDialogsList = false;
boolean showPlayer = false;
photoPathsArray = null;
videoPath = null;
@@ -610,10 +600,10 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
}
}
}
} else if (args[0].startsWith("TEL")) {
String phone = "";//PhoneFormat.stripExceptNumbers(args[1], true);
if (phone.length() > 0) {
currentData.phones.add(phone);
} else if (args[0].startsWith("EMAIL")) {
String email = args[1];
if (email.length() > 0) {
currentData.emails.add(email);
}
}
}
@@ -625,22 +615,20 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
}
for (int a = 0; a < vcardDatas.size(); a++) {
VcardData vcardData = vcardDatas.get(a);
if (vcardData.name != null && !vcardData.phones.isEmpty()) {
if (vcardData.name != null && !vcardData.emails.isEmpty()) {
if (contactsToSend == null) {
contactsToSend = new ArrayList<>();
}
for (int b = 0; b < vcardData.phones.size(); b++) {
String phone = vcardData.phones.get(b);
TLRPC.User user = new TLRPC.TL_userContact_old2();
user.phone = phone;
user.first_name = vcardData.name;
user.last_name = "";
user.id = 0;
contactsToSend.add(user);
for (int b = 0; b < vcardData.emails.size(); b++) {
int contact_to_send_id = MrMailbox.createContact(vcardData.name, vcardData.emails.get(b));
contactsToSend.add(contact_to_send_id);
}
}
}
if( contactsToSend==null ) {
Toast.makeText(this, ApplicationLoader.applicationContext.getString(R.string.BadEmailAddress), Toast.LENGTH_SHORT).show();;
}
} else {
error = true;
}
@@ -663,14 +651,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
}
else {
String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
Pattern r = Pattern.compile("geo: ?(-?\\d+\\.\\d+),(-?\\d+\\.\\d+)(,|\\?z=)(-?\\d+)");
Matcher m = r.matcher(text);
if (m.find()) {
sendingLocation = new TLRPC.TL_messageMediaGeo();
sendingLocation.geo = new TLRPC.TL_geoPoint();
sendingLocation.geo.lat = Double.parseDouble(m.group(1));
sendingLocation.geo._long = Double.parseDouble(m.group(2));
} else if (text != null && text.length() != 0) {
if (text != null && text.length() != 0) {
if ((text.startsWith("http://") || text.startsWith("https://")) && subject != null && subject.length() != 0) {
text = subject + "\n" + text;
}
@@ -722,7 +703,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
}
}
}
} else if (sendingText == null && sendingLocation == null) {
} else if (sendingText == null) {
error = true;
}
}
@@ -911,9 +892,11 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
}
*/
}
} else if (intent.getAction().equals("com.b44t.messenger.OPEN_ACCOUNT")) {
}
/*else if (intent.getAction().equals("com.b44t.messenger.OPEN_ACCOUNT")) {
open_settings = 1;
} else if (intent.getAction().startsWith("com.b44t.messenger.openchat")) {
} */
else if (intent.getAction().startsWith("com.b44t.messenger.openchat")) {
String temp = intent.getAction().substring(27);
int chatId = 0;
try {
@@ -927,8 +910,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
} else {
showDialogsList = true;
}
} else if (intent.getAction().equals("com.b44t.messenger.openplayer")) {
showPlayer = true;
}
}
}
@@ -972,42 +953,15 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
}
pushOpened = false;
isNew = false;
} else if (showPlayer) {
if (AndroidUtilities.isTablet()) {
for (int a = 0; a < layersActionBarLayout.fragmentsStack.size(); a++) {
BaseFragment fragment = layersActionBarLayout.fragmentsStack.get(a);
if (fragment instanceof AudioPlayerActivity) {
layersActionBarLayout.removeFragmentFromStack(fragment);
break;
}
}
actionBarLayout.showLastFragment();
rightActionBarLayout.showLastFragment();
drawerLayoutContainer.setAllowOpenDrawer(false, false);
} else {
for (int a = 0; a < actionBarLayout.fragmentsStack.size(); a++) {
BaseFragment fragment = actionBarLayout.fragmentsStack.get(a);
if (fragment instanceof AudioPlayerActivity) {
actionBarLayout.removeFragmentFromStack(fragment);
break;
}
}
drawerLayoutContainer.setAllowOpenDrawer(true, false);
}
actionBarLayout.presentFragment(new AudioPlayerActivity(), false, true, true);
pushOpened = true;
} else if (videoPath != null || photoPathsArray != null || sendingText != null || sendingLocation != null || documentsPathsArray != null || contactsToSend != null || documentsUrisArray != null) {
}
else if (videoPath != null || photoPathsArray != null || sendingText != null || documentsPathsArray != null || contactsToSend != null || documentsUrisArray != null) {
if (!AndroidUtilities.isTablet()) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
}
if (dialogId == 0) {
Bundle args = new Bundle();
args.putBoolean("onlySelect", true);
if (contactsToSend != null) {
args.putString("selectAlertString", LocaleController.getString("SendMessagesTo", R.string.SendMessagesTo));
} else {
args.putString("selectAlertString", LocaleController.getString("SendMessagesTo", R.string.SendMessagesTo));
}
args.putString("selectAlertString", LocaleController.getString("SendMessagesTo", R.string.SendMessagesTo));
DialogsActivity fragment = new DialogsActivity(args);
fragment.setDelegate(this);
boolean removeLast;
@@ -1032,7 +986,8 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
} else {
didSelectDialog(null, dialogId, false);
}
} else if (open_settings != 0) {
}
/*else if (open_settings != 0) {
actionBarLayout.presentFragment(new SettingsActivity(), false, true, true);
if (AndroidUtilities.isTablet()) {
actionBarLayout.showLastFragment();
@@ -1042,7 +997,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
drawerLayoutContainer.setAllowOpenDrawer(true, false);
}
pushOpened = true;
}
}*/
if (!pushOpened && !isNew) {
if (AndroidUtilities.isTablet()) {
@@ -1114,7 +1069,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
}
} else {
actionBarLayout.presentFragment(fragment, dialogsFragment != null, dialogsFragment == null, true);
SendMessagesHelper.prepareSendingVideo(videoPath, 0, 0, 0, 0, null, dialog_id, null);
SendMessagesHelper.prepareSendingVideo(videoPath, 0, 0, 0, 0, null, dialog_id);
}
} else {
actionBarLayout.presentFragment(fragment, dialogsFragment != null, dialogsFragment == null, true);
@@ -1126,7 +1081,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
captions.add(sendingText);
sendingText = null;
}
SendMessagesHelper.prepareSendingPhotos(null, photoPathsArray, dialog_id, null, captions);
SendMessagesHelper.prepareSendingPhotos(null, photoPathsArray, dialog_id, captions);
}
if (sendingText != null) {
@@ -1134,11 +1089,11 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
}
if (documentsPathsArray != null || documentsUrisArray != null) {
SendMessagesHelper.prepareSendingDocuments(documentsPathsArray, documentsOriginalPathsArray, documentsUrisArray, documentsMimeType, dialog_id, null);
SendMessagesHelper.prepareSendingDocuments(documentsPathsArray, documentsOriginalPathsArray, documentsUrisArray, documentsMimeType, dialog_id);
}
if (contactsToSend != null && !contactsToSend.isEmpty()) {
for (TLRPC.User user : contactsToSend) {
SendMessagesHelper.getInstance().sendMessageContact(user, dialog_id, null, null);
for (int user_id : contactsToSend) {
SendMessagesHelper.getInstance().sendMessageContact(user_id, (int)dialog_id);
}
}
}
@@ -1146,7 +1101,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
photoPathsArray = null;
videoPath = null;
sendingText = null;
sendingLocation = null;
documentsPathsArray = null;
documentsOriginalPathsArray = null;
contactsToSend = null;
@@ -1165,7 +1119,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.mainUserInfoChanged);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeOtherAppActivities);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didUpdatedConnectionState);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.wasUnableToFindCurrentLocation);
}
public void presentFragment(BaseFragment fragment) {
@@ -1357,10 +1310,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show();
return;
} else if (requestCode == 2) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.locationPermissionGranted);
}
}
if (actionBarLayout.fragmentsStack.size() != 0) {
BaseFragment fragment = actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1);
@@ -1484,41 +1433,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
}
} else if (id == NotificationCenter.mainUserInfoChanged) {
drawerLayoutAdapter.notifyDataSetChanged();
} else if (id == NotificationCenter.wasUnableToFindCurrentLocation) {
final HashMap<String, MessageObject> waitingForLocation = (HashMap<String, MessageObject>) args[0];
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
builder.setNegativeButton(LocaleController.getString("ShareYouLocationUnableManually", R.string.ShareYouLocationUnableManually), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
/*Telegram FOSS: manual Location selection not available */
Toast.makeText(getApplicationContext(),"Disabled for now.", Toast.LENGTH_LONG).show();
/*
if (mainFragmentsStack.isEmpty()) {
return;
}
BaseFragment lastFragment = mainFragmentsStack.get(mainFragmentsStack.size() - 1);
if (!AndroidUtilities.isGoogleMapsInstalled(lastFragment)) {
return;
}
LocationActivity fragment = new LocationActivity();
fragment.setDelegate(new LocationActivity.LocationActivityDelegate() {
@Override
public void didSelectLocation(TLRPC.MessageMedia location) {
for (HashMap.Entry<String, MessageObject> entry : waitingForLocation.entrySet()) {
MessageObject messageObject = entry.getValue();
SendMessagesHelper.getInstance().sendMessage(location, messageObject.getDialogId(), messageObject, null, null);
}
}
});
presentFragment(fragment);
*/
}
});
builder.setMessage(LocaleController.getString("ShareYouLocationUnable", R.string.ShareYouLocationUnable));
if (!mainFragmentsStack.isEmpty()) {
mainFragmentsStack.get(mainFragmentsStack.size() - 1).showDialog(builder.create());
}
}
}
@@ -68,7 +68,6 @@ public class NameSettingsActivity extends BaseFragment {
EditTextCell displaynameCell; // warning all these objects may be null!
// misc.
private View doneButton;
private final static int done_button = 1;
@Override
@@ -92,28 +91,14 @@ public class NameSettingsActivity extends BaseFragment {
public View createView(Context context) {
// create action bar
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setBackButtonImage(R.drawable.ic_close_white);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("MyName", R.string.MyName));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
if( isModified() ) { // TODO: maybe we should also ask if the user presses the "back" button
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("DiscardChanges", R.string.DiscardChanges));
builder.setPositiveButton(LocaleController.getString("Yes", R.string.Yes), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
finishFragment();
}
});
builder.setNegativeButton(LocaleController.getString("No", R.string.No), null);
showDialog(builder.create());
}
else {
finishFragment();
}
finishFragment();
} else if (id == done_button) {
saveData();
}
@@ -121,7 +106,7 @@ public class NameSettingsActivity extends BaseFragment {
});
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
// create object to hold the whole view
fragmentView = new FrameLayout(context);
@@ -83,7 +83,11 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
private TextView dropDown;
private ActionBarMenuItem dropDownContainer;
private int type;
public final static int SCREEN0_SETTINGS = 0;
public final static int SCREEN1_ENTER_CODE1 = 1;
public final static int SCREEN2_ENTER_CODE2 = 2;
private int screen;
private int currentPasswordType = 0;
private int passcodeSetStep = 0;
private String firstPassword;
@@ -100,16 +104,16 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
private final static int pin_item = 2;
private final static int password_item = 3;
public PasscodeActivity(int type) {
public PasscodeActivity(int screen) {
super();
this.type = type;
this.screen = screen;
}
@Override
public boolean onFragmentCreate() {
super.onFragmentCreate();
updateRows();
if (type == 0) {
if (screen == SCREEN0_SETTINGS ) {
NotificationCenter.getInstance().addObserver(this, NotificationCenter.didSetPasscode);
}
return true;
@@ -118,16 +122,14 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
@Override
public void onFragmentDestroy() {
super.onFragmentDestroy();
if (type == 0) {
if (screen == SCREEN0_SETTINGS ) {
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didSetPasscode);
}
}
@Override
public View createView(Context context) {
if (type != 3) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
}
actionBar.setBackButtonImage(screen == SCREEN0_SETTINGS? R.drawable.ic_ab_back : R.drawable.ic_close_white);
actionBar.setAllowOverlayTitle(false);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
@@ -153,13 +155,13 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
if (type != 0) {
if (screen != SCREEN0_SETTINGS ) {
ActionBarMenu menu = actionBar.createMenu();
menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
titleTextView = new TextView(context);
titleTextView.setTextColor(0xff757575);
if (type == 1) {
if (screen == SCREEN1_ENTER_CODE1) {
if (UserConfig.passcodeHash.length() != 0) {
titleTextView.setText(LocaleController.getString("EnterNewPasscode", R.string.EnterNewPasscode));
} else {
@@ -185,7 +187,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
passwordEditText.setLines(1);
passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL);
passwordEditText.setSingleLine(true);
if (type == 1) {
if (screen == SCREEN1_ENTER_CODE1) {
passcodeSetStep = 0;
passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
} else {
@@ -231,9 +233,9 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
@Override
public void afterTextChanged(Editable s) {
if (passwordEditText.length() == 4) {
if (type == 2 && UserConfig.passcodeType == 0) {
if (screen == SCREEN2_ENTER_CODE2 && UserConfig.passcodeType == 0) {
processDone();
} else if (type == 1 && currentPasswordType == 0) {
} else if (screen == SCREEN1_ENTER_CODE1 && currentPasswordType == 0) {
if (passcodeSetStep == 0) {
processNext();
} else if (passcodeSetStep == 1) {
@@ -261,7 +263,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
}
});
if (type == 1) {
if (screen == SCREEN1_ENTER_CODE1) {
dropDownContainer = new ActionBarMenuItem(context, menu, 0);
dropDownContainer.setSubMenuOpenSide(1);
dropDownContainer.addSubItem(pin_item, LocaleController.getString("PasscodePIN", R.string.PasscodePIN), 0);
@@ -323,7 +325,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
@Override
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
if (i == changePasscodeRow) {
presentFragment(new PasscodeActivity(1));
presentFragment(new PasscodeActivity(SCREEN1_ENTER_CODE1));
} else if (i == passcodeOnOffRow) {
TextCheckCell cell = (TextCheckCell) view;
if (UserConfig.passcodeHash.length() != 0) {
@@ -342,7 +344,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
cell.setChecked(UserConfig.passcodeHash.length() != 0);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.didSetPasscode);
} else {
presentFragment(new PasscodeActivity(1));
presentFragment(new PasscodeActivity(SCREEN1_ENTER_CODE1));
}
} else if (i == autoLockRow) {
if (getParentActivity() == null) {
@@ -381,6 +383,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
return "";
}
});
numberPicker.setWrapSelectorWheel(false);
builder.setView(numberPicker);
builder.setNegativeButton(LocaleController.getString("Done", R.string.Done), new DialogInterface.OnClickListener() {
@Override
@@ -420,7 +423,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
if (type != 0) {
if (screen != SCREEN0_SETTINGS) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
@@ -437,7 +440,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.didSetPasscode) {
if (type == 0) {
if (screen == SCREEN0_SETTINGS) {
updateRows();
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
@@ -489,7 +492,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
@Override
public void onTransitionAnimationEnd(boolean isOpen, boolean backward) {
if (isOpen && type != 0) {
if (isOpen && screen != SCREEN0_SETTINGS) {
AndroidUtilities.showKeyboard(passwordEditText);
}
}
@@ -502,13 +505,13 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
dropDown.setText(LocaleController.getString("PasscodePassword", R.string.PasscodePassword));
}
}
if (type == 1 && currentPasswordType == 0 || type == 2 && UserConfig.passcodeType == 0) {
if (screen == SCREEN1_ENTER_CODE1 && currentPasswordType == 0 || screen == SCREEN2_ENTER_CODE2 && UserConfig.passcodeType == 0) {
InputFilter[] filterArray = new InputFilter[1];
filterArray[0] = new InputFilter.LengthFilter(4);
passwordEditText.setFilters(filterArray);
passwordEditText.setInputType(InputType.TYPE_CLASS_PHONE);
passwordEditText.setKeyListener(DigitsKeyListener.getInstance("1234567890"));
} else if (type == 1 && currentPasswordType == 1 || type == 2 && UserConfig.passcodeType == 1) {
} else if (screen == SCREEN1_ENTER_CODE1 && currentPasswordType == 1 || screen == SCREEN2_ENTER_CODE2 && UserConfig.passcodeType == 1) {
passwordEditText.setFilters(new InputFilter[0]);
passwordEditText.setKeyListener(null);
passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
@@ -538,7 +541,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
onPasscodeError();
return;
}
if (type == 1) {
if (screen == SCREEN1_ENTER_CODE1) {
if (!firstPassword.equals(passwordEditText.getText().toString())) {
try {
Toast.makeText(getParentActivity(), LocaleController.getString("PasscodeDoNotMatch", R.string.PasscodeDoNotMatch), Toast.LENGTH_SHORT).show();
@@ -569,7 +572,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
NotificationCenter.getInstance().postNotificationName(NotificationCenter.didSetPasscode);
passwordEditText.clearFocus();
AndroidUtilities.hideKeyboard(passwordEditText);
} else if (type == 2) {
} else if (screen == SCREEN2_ENTER_CODE2) {
if (!UserConfig.checkPasscode(passwordEditText.getText().toString())) {
passwordEditText.setText("");
onPasscodeError();
@@ -577,7 +580,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
}
passwordEditText.clearFocus();
AndroidUtilities.hideKeyboard(passwordEditText);
presentFragment(new PasscodeActivity(0), true);
presentFragment(new PasscodeActivity(SCREEN0_SETTINGS), true);
}
}
@@ -54,7 +54,6 @@ import com.b44t.ui.ActionBar.BaseFragment;
import com.b44t.ui.ActionBar.Theme;
import com.b44t.ui.Adapters.BaseFragmentAdapter;
import com.b44t.ui.Cells.PhotoPickerAlbumsCell;
import com.b44t.ui.Cells.PhotoPickerSearchCell;
import com.b44t.ui.Components.LayoutHelper;
import com.b44t.ui.Components.PickerBottomLayout;
@@ -64,7 +63,7 @@ import java.util.HashMap;
public class PhotoAlbumPickerActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
public interface PhotoAlbumPickerActivityDelegate {
void didSelectPhotos(ArrayList<String> photos, ArrayList<String> captions, ArrayList<MediaController.SearchImage> webPhotos);
void didSelectPhotos(ArrayList<String> photos, ArrayList<String> captions);
boolean didSelectVideo(String path);
void startPhotoSelectActivity();
}
@@ -72,11 +71,6 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
private ArrayList<MediaController.AlbumEntry> albumsSorted = null;
private ArrayList<MediaController.AlbumEntry> videoAlbumsSorted = null;
private HashMap<Integer, MediaController.PhotoEntry> selectedPhotos = new HashMap<>();
private HashMap<String, MediaController.SearchImage> selectedWebPhotos = new HashMap<>();
private HashMap<String, MediaController.SearchImage> recentImagesWebKeys = new HashMap<>();
private HashMap<String, MediaController.SearchImage> recentImagesGifKeys = new HashMap<>();
private ArrayList<MediaController.SearchImage> recentWebImages = new ArrayList<>();
private ArrayList<MediaController.SearchImage> recentGifImages = new ArrayList<>();
private boolean loading = false;
private int columnsCount = 2;
@@ -89,20 +83,23 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
private PickerBottomLayout pickerBottomLayout;
private boolean sendPressed;
private boolean singlePhoto;
private boolean allowGifs;
private final static int SELECTMODE0_PHOTOS = 0;
private final static int SELECTMODE1_VIDEOS = 1;
private int selectedMode;
private ChatActivity chatActivity;
private PhotoAlbumPickerActivityDelegate delegate;
private final static int item_photos = 2;
private final static int item_video = 3;
private final static int ID_OPEN_SYSTEM_SELECTOR = 1;
private final static int ID_ITEM_PHOTOS = 2;
private final static int ID_ITEM_VIDEO = 3;
public PhotoAlbumPickerActivity(boolean singlePhoto, boolean allowGifs, ChatActivity chatActivity) {
public PhotoAlbumPickerActivity(boolean singlePhoto, ChatActivity chatActivity) {
super();
this.chatActivity = chatActivity;
this.singlePhoto = singlePhoto;
this.allowGifs = allowGifs;
}
@Override
@@ -110,7 +107,6 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
loading = true;
MediaController.loadGalleryPhotosAlbums(classGuid);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.albumsDidLoaded);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.recentImagesDidLoaded);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeChats);
return super.onFragmentCreate();
}
@@ -118,7 +114,6 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
@Override
public void onFragmentDestroy() {
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.albumsDidLoaded);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.recentImagesDidLoaded);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
super.onFragmentDestroy();
}
@@ -126,32 +121,30 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
@SuppressWarnings("unchecked")
@Override
public View createView(Context context) {
actionBar.setBackgroundColor(Theme.ACTION_BAR_MEDIA_PICKER_COLOR);
actionBar.setItemsBackgroundColor(Theme.ACTION_BAR_PICKER_SELECTOR_COLOR);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == 1) {
} else if (id == ID_OPEN_SYSTEM_SELECTOR) {
if (delegate != null) {
finishFragment(false);
delegate.startPhotoSelectActivity();
}
} else if (id == item_photos) {
if (selectedMode == 0) {
} else if (id == ID_ITEM_PHOTOS) {
if (selectedMode == SELECTMODE0_PHOTOS) {
return;
}
selectedMode = 0;
selectedMode = SELECTMODE0_PHOTOS;
dropDown.setText(LocaleController.getString("PickerPhotos", R.string.PickerPhotos));
emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
listAdapter.notifyDataSetChanged();
} else if (id == item_video) {
if (selectedMode == 1) {
} else if (id == ID_ITEM_VIDEO) {
if (selectedMode == SELECTMODE1_VIDEOS) {
return;
}
selectedMode = 1;
selectedMode = SELECTMODE1_VIDEOS;
dropDown.setText(LocaleController.getString("PickerVideo", R.string.PickerVideo));
emptyView.setText(LocaleController.getString("NoVideo", R.string.NoVideo));
listAdapter.notifyDataSetChanged();
@@ -160,20 +153,20 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
});
ActionBarMenu menu = actionBar.createMenu();
menu.addItem(1, R.drawable.ic_ab_other);
//menu.addItem(ID_OPEN_SYSTEM_SELECTOR, R.drawable.ic_ab_other); -- fallback-selector not needed
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(0xff000000);
frameLayout.setBackgroundColor(0xffffffff);
if (!singlePhoto) {
selectedMode = 0;
selectedMode = SELECTMODE0_PHOTOS;
dropDownContainer = new ActionBarMenuItem(context, menu, 0);
dropDownContainer.setSubMenuOpenSide(1);
dropDownContainer.addSubItem(item_photos, LocaleController.getString("PickerPhotos", R.string.PickerPhotos), 0);
dropDownContainer.addSubItem(item_video, LocaleController.getString("PickerVideo", R.string.PickerVideo), 0);
dropDownContainer.addSubItem(ID_ITEM_PHOTOS, LocaleController.getString("PickerPhotos", R.string.PickerPhotos), 0);
dropDownContainer.addSubItem(ID_ITEM_VIDEO, LocaleController.getString("PickerVideo", R.string.PickerVideo), 0);
actionBar.addView(dropDownContainer);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams();
layoutParams.height = LayoutHelper.MATCH_PARENT;
@@ -228,7 +221,7 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
layoutParams.bottomMargin = AndroidUtilities.dp(48);
listView.setLayoutParams(layoutParams);
listView.setAdapter(listAdapter = new ListAdapter(context));
AndroidUtilities.setListViewEdgeEffectColor(listView, 0xff333333);
AndroidUtilities.setListViewEdgeEffectColor(listView, Theme.ACTION_BAR_COLOR);
emptyView = new TextView(context);
emptyView.setTextColor(0xff808080);
@@ -266,7 +259,7 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
layoutParams.gravity = Gravity.CENTER;
progressView.setLayoutParams(layoutParams);
pickerBottomLayout = new PickerBottomLayout(context);
pickerBottomLayout = new PickerBottomLayout(context, false);
frameLayout.addView(pickerBottomLayout);
layoutParams = (FrameLayout.LayoutParams) pickerBottomLayout.getLayoutParams();
layoutParams.width = LayoutHelper.MATCH_PARENT;
@@ -294,7 +287,11 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
progressView.setVisibility(View.GONE);
listView.setEmptyView(emptyView);
}
pickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);
pickerBottomLayout.updateSelectedCount(selectedPhotos.size(), true);
View shadow = new View(context);
shadow.setBackgroundResource(R.drawable.header_shadow_reverse);
frameLayout.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.LEFT | Gravity.BOTTOM, 0, 0, 0, 48));
return fragmentView;
}
@@ -343,21 +340,6 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
}
} else if (id == NotificationCenter.closeChats) {
removeSelfFromStack();
} else if (id == NotificationCenter.recentImagesDidLoaded) {
int type = (Integer) args[0];
if (type == 0) {
recentWebImages = (ArrayList<MediaController.SearchImage>) args[1];
recentImagesWebKeys.clear();
for (MediaController.SearchImage searchImage : recentWebImages) {
recentImagesWebKeys.put(searchImage.id, searchImage);
}
} else if (type == 1) {
recentGifImages = (ArrayList<MediaController.SearchImage>) args[1];
recentImagesGifKeys.clear();
for (MediaController.SearchImage searchImage : recentGifImages) {
recentImagesGifKeys.put(searchImage.id, searchImage);
}
}
}
}
@@ -366,7 +348,7 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
}
private void sendSelectedPhotos() {
if (selectedPhotos.isEmpty() && selectedWebPhotos.isEmpty() || delegate == null || sendPressed) {
if (selectedPhotos.isEmpty() || delegate == null || sendPressed) {
return;
}
sendPressed = true;
@@ -382,47 +364,8 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
captions.add(photoEntry.caption != null ? photoEntry.caption.toString() : null);
}
}
ArrayList<MediaController.SearchImage> webPhotos = new ArrayList<>();
boolean gifChanged = false;
boolean webChange = false;
for (HashMap.Entry<String, MediaController.SearchImage> entry : selectedWebPhotos.entrySet()) {
MediaController.SearchImage searchImage = entry.getValue();
if (searchImage.imagePath != null) {
photos.add(searchImage.imagePath);
captions.add(searchImage.caption != null ? searchImage.caption.toString() : null);
} else {
webPhotos.add(searchImage);
}
searchImage.date = (int) (System.currentTimeMillis() / 1000);
if (searchImage.type == 0) {
webChange = true;
MediaController.SearchImage recentImage = recentImagesWebKeys.get(searchImage.id);
if (recentImage != null) {
recentWebImages.remove(recentImage);
recentWebImages.add(0, recentImage);
} else {
recentWebImages.add(0, searchImage);
}
} else if (searchImage.type == 1) {
gifChanged = true;
MediaController.SearchImage recentImage = recentImagesGifKeys.get(searchImage.id);
if (recentImage != null) {
recentGifImages.remove(recentImage);
recentGifImages.add(0, recentImage);
} else {
recentGifImages.add(0, searchImage);
}
}
}
if (webChange) {
//MessagesStorage.getInstance().putWebRecent(recentWebImages);
}
if (gifChanged) {
//MessagesStorage.getInstance().putWebRecent(recentGifImages);
}
delegate.didSelectPhotos(photos, captions, webPhotos);
delegate.didSelectPhotos(photos, captions);
}
private void fixLayout() {
@@ -469,21 +412,16 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
}
}
private void openPhotoPicker(MediaController.AlbumEntry albumEntry, int type) {
ArrayList<MediaController.SearchImage> recentImages = null;
if (albumEntry == null) {
if (type == 0) {
recentImages = recentWebImages;
} else if (type == 1) {
recentImages = recentGifImages;
}
private void openPhotoPicker(MediaController.AlbumEntry albumEntry) {
if( albumEntry == null ) {
return;
}
PhotoPickerActivity fragment = new PhotoPickerActivity(type, albumEntry, selectedPhotos, selectedWebPhotos, recentImages, singlePhoto, chatActivity);
PhotoPickerActivity fragment = new PhotoPickerActivity(albumEntry, selectedPhotos, singlePhoto, chatActivity);
fragment.setDelegate(new PhotoPickerActivity.PhotoPickerActivityDelegate() {
@Override
public void selectedPhotosChanged() {
if (pickerBottomLayout != null) {
pickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);
pickerBottomLayout.updateSelectedCount(selectedPhotos.size(), true);
}
}
@@ -523,11 +461,8 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
@Override
public int getCount() {
if (singlePhoto || selectedMode == 0) {
if (singlePhoto) {
return albumsSorted != null ? (int) Math.ceil(albumsSorted.size() / (float) columnsCount) : 0;
}
return 1 + (albumsSorted != null ? (int) Math.ceil(albumsSorted.size() / (float) columnsCount) : 0);
if (singlePhoto || selectedMode == SELECTMODE0_PHOTOS) {
return (albumsSorted != null ? (int) Math.ceil(albumsSorted.size() / (float) columnsCount) : 0);
} else {
return (videoAlbumsSorted != null ? (int) Math.ceil(videoAlbumsSorted.size() / (float) columnsCount) : 0);
}
@@ -559,7 +494,7 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
photoPickerAlbumsCell.setDelegate(new PhotoPickerAlbumsCell.PhotoPickerAlbumsCellDelegate() {
@Override
public void didSelectAlbum(MediaController.AlbumEntry albumEntry) {
openPhotoPicker(albumEntry, 0);
openPhotoPicker(albumEntry);
}
});
} else {
@@ -567,13 +502,8 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
}
photoPickerAlbumsCell.setAlbumsCount(columnsCount);
for (int a = 0; a < columnsCount; a++) {
int index;
if (singlePhoto || selectedMode == 1) {
index = i * columnsCount + a;
} else {
index = (i - 1) * columnsCount + a;
}
if (singlePhoto || selectedMode == 0) {
int index = i * columnsCount + a;
if (singlePhoto || selectedMode == SELECTMODE0_PHOTOS) {
if (index < albumsSorted.size()) {
MediaController.AlbumEntry albumEntry = albumsSorted.get(index);
photoPickerAlbumsCell.setAlbum(a, albumEntry);
@@ -590,37 +520,18 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
}
}
photoPickerAlbumsCell.requestLayout();
} else if (type == 1) {
if (view == null) {
view = new PhotoPickerSearchCell(mContext, allowGifs);
((PhotoPickerSearchCell) view).setDelegate(new PhotoPickerSearchCell.PhotoPickerSearchCellDelegate() {
@Override
public void didPressedSearchButton(int index) {
openPhotoPicker(null, index);
}
});
}
}
return view;
}
@Override
public int getItemViewType(int i) {
if (singlePhoto || selectedMode == 1) {
return 0;
}
if (i == 0) {
return 1;
}
return 0;
}
@Override
public int getViewTypeCount() {
if (singlePhoto || selectedMode == 1) {
return 1;
}
return 2;
return 1;
}
@Override
@@ -27,34 +27,25 @@ import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.b44t.messenger.AndroidUtilities;
import com.b44t.messenger.FileLoader;
import com.b44t.messenger.LocaleController;
import com.b44t.messenger.MediaController;
import com.b44t.messenger.NotificationCenter;
import com.b44t.messenger.volley.RequestQueue;
import com.b44t.messenger.volley.toolbox.Volley;
import com.b44t.messenger.ApplicationLoader;
import com.b44t.messenger.R;
import com.b44t.messenger.TLRPC;
import com.b44t.messenger.MessageObject;
import com.b44t.ui.ActionBar.ActionBarMenu;
import com.b44t.ui.ActionBar.ActionBarMenuItem;
import com.b44t.ui.ActionBar.Theme;
import com.b44t.ui.Adapters.BaseFragmentAdapter;
import com.b44t.ui.ActionBar.ActionBar;
@@ -77,34 +68,13 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
boolean didSelectVideo(String path);
}
private RequestQueue requestQueue;
private int type;
private HashMap<String, MediaController.SearchImage> selectedWebPhotos;
private HashMap<Integer, MediaController.PhotoEntry> selectedPhotos;
private ArrayList<MediaController.SearchImage> recentImages;
private ArrayList<MediaController.SearchImage> searchResult = new ArrayList<>();
private HashMap<String, MediaController.SearchImage> searchResultKeys = new HashMap<>();
private HashMap<String, MediaController.SearchImage> searchResultUrls = new HashMap<>();
private boolean searching;
private String nextSearchBingString;
private boolean giphySearchEndReached = true;
private String lastSearchString;
private boolean loadingRecent;
private int nextGiphySearchOffset;
private int giphyReqId;
private int lastSearchToken;
private MediaController.AlbumEntry selectedAlbum;
private GridView listView;
private ListAdapter listAdapter;
private PickerBottomLayout pickerBottomLayout;
private FrameLayout progressView;
private TextView emptyView;
private ActionBarMenuItem searchItem;
private int itemWidth = 100;
private boolean sendPressed;
private boolean singlePhoto;
@@ -112,16 +82,13 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
private PhotoPickerActivityDelegate delegate;
public PhotoPickerActivity(int type, MediaController.AlbumEntry selectedAlbum, HashMap<Integer, MediaController.PhotoEntry> selectedPhotos, HashMap<String, MediaController.SearchImage> selectedWebPhotos, ArrayList<MediaController.SearchImage> recentImages, boolean onlyOnePhoto, ChatActivity chatActivity) {
public PhotoPickerActivity(MediaController.AlbumEntry selectedAlbum, HashMap<Integer, MediaController.PhotoEntry> selectedPhotos, boolean onlyOnePhoto, ChatActivity chatActivity) {
super();
this.selectedAlbum = selectedAlbum;
this.selectedAlbum = selectedAlbum; // must never be null
this.selectedPhotos = selectedPhotos;
this.selectedWebPhotos = selectedWebPhotos;
this.type = type;
this.recentImages = recentImages;
this.singlePhoto = onlyOnePhoto;
this.chatActivity = chatActivity;
if (selectedAlbum != null && selectedAlbum.isVideo) {
if (selectedAlbum.isVideo) {
singlePhoto = true;
}
}
@@ -129,41 +96,20 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
@Override
public boolean onFragmentCreate() {
NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeChats);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.recentImagesDidLoaded);
if (selectedAlbum == null) {
requestQueue = Volley.newRequestQueue(ApplicationLoader.applicationContext);
if (recentImages.isEmpty()) {
//MessagesStorage.getInstance().loadWebRecent(type);
loadingRecent = true;
}
}
return super.onFragmentCreate();
}
@Override
public void onFragmentDestroy() {
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.recentImagesDidLoaded);
if (requestQueue != null) {
requestQueue.cancelAll("search");
requestQueue.stop();
}
super.onFragmentDestroy();
}
@SuppressWarnings("unchecked")
@Override
public View createView(Context context) {
actionBar.setBackgroundColor(Theme.ACTION_BAR_MEDIA_PICKER_COLOR);
actionBar.setItemsBackgroundColor(Theme.ACTION_BAR_PICKER_SELECTOR_COLOR);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
if (selectedAlbum != null) {
actionBar.setTitle(selectedAlbum.bucketName);
} else if (type == 0) {
actionBar.setTitle(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
} else if (type == 1) {
actionBar.setTitle(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
}
actionBar.setTitle(selectedAlbum.bucketName);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
@@ -173,40 +119,10 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
}
});
if (selectedAlbum == null) {
ActionBarMenu menu = actionBar.createMenu();
searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true, false).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
}
@Override
public boolean canCollapseSearch() {
finishFragment();
return false;
}
@Override
public void onSearchPressed(EditText editText) {
// Telegram-FOSS doesn't support searching with external engines (privacy issues)
return;
}
});
}
if (selectedAlbum == null) {
if (type == 0) {
searchItem.getSearchField().setHint(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
} else if (type == 1) {
searchItem.getSearchField().setHint(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
}
}
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(0xff000000);
frameLayout.setBackgroundColor(0xffffffff);
listView = new GridView(context);
listView.setPadding(AndroidUtilities.dp(4), AndroidUtilities.dp(4), AndroidUtilities.dp(4), AndroidUtilities.dp(4));
@@ -226,11 +142,11 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
layoutParams.bottomMargin = singlePhoto ? 0 : AndroidUtilities.dp(48);
listView.setLayoutParams(layoutParams);
listView.setAdapter(listAdapter = new ListAdapter(context));
AndroidUtilities.setListViewEdgeEffectColor(listView, 0xff333333);
AndroidUtilities.setListViewEdgeEffectColor(listView, Theme.ACTION_BAR_COLOR);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (selectedAlbum != null && selectedAlbum.isVideo) {
if (selectedAlbum.isVideo) {
if (i < 0 || i >= selectedAlbum.photos.size()) {
return;
}
@@ -238,52 +154,23 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
finishFragment();
}
} else {
ArrayList<Object> arrayList;
if (selectedAlbum != null) {
arrayList = (ArrayList) selectedAlbum.photos;
} else {
if (searchResult.isEmpty() && lastSearchString == null) {
arrayList = (ArrayList) recentImages;
} else {
arrayList = (ArrayList) searchResult;
}
}
ArrayList<Object> arrayList = (ArrayList) selectedAlbum.photos;
if (i < 0 || i >= arrayList.size()) {
return;
}
if (searchItem != null) {
AndroidUtilities.hideKeyboard(searchItem.getSearchField());
}
PhotoViewer.getInstance().setParentActivity(getParentActivity());
PhotoViewer.getInstance().openPhotoForSelect(arrayList, i, singlePhoto ? 1 : 0, PhotoPickerActivity.this, chatActivity);
}
}
});
if (selectedAlbum == null) {
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
// Telegram-FOSS doesn't support searching with external engines (privacy issues)
return false;
}
});
}
emptyView = new TextView(context);
TextView emptyView = new TextView(context);
emptyView.setTextColor(0xff808080);
emptyView.setTextSize(20);
emptyView.setGravity(Gravity.CENTER);
emptyView.setVisibility(View.GONE);
if (selectedAlbum != null) {
emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
} else {
if (type == 0) {
emptyView.setText(LocaleController.getString("NoRecentPhotos", R.string.NoRecentPhotos));
} else if (type == 1) {
emptyView.setText(LocaleController.getString("NoRecentGIFs", R.string.NoRecentGIFs));
}
}
emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
frameLayout.addView(emptyView);
layoutParams = (FrameLayout.LayoutParams) emptyView.getLayoutParams();
layoutParams.width = LayoutHelper.MATCH_PARENT;
@@ -297,43 +184,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
}
});
if (selectedAlbum == null) {
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
if (i == SCROLL_STATE_TOUCH_SCROLL) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
// Telegram-FOSS doesn't support searching with external engines (privacy issues)
return;
}
});
progressView = new FrameLayout(context);
progressView.setVisibility(View.GONE);
frameLayout.addView(progressView);
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
layoutParams.width = LayoutHelper.MATCH_PARENT;
layoutParams.height = LayoutHelper.MATCH_PARENT;
layoutParams.bottomMargin = singlePhoto ? 0 : AndroidUtilities.dp(48);
progressView.setLayoutParams(layoutParams);
ProgressBar progressBar = new ProgressBar(context);
progressView.addView(progressBar);
layoutParams = (FrameLayout.LayoutParams) progressBar.getLayoutParams();
layoutParams.width = LayoutHelper.WRAP_CONTENT;
layoutParams.height = LayoutHelper.WRAP_CONTENT;
layoutParams.gravity = Gravity.CENTER;
progressBar.setLayoutParams(layoutParams);
updateSearchInterface();
}
pickerBottomLayout = new PickerBottomLayout(context);
pickerBottomLayout = new PickerBottomLayout(context, false);
frameLayout.addView(pickerBottomLayout);
layoutParams = (FrameLayout.LayoutParams) pickerBottomLayout.getLayoutParams();
layoutParams.width = LayoutHelper.MATCH_PARENT;
@@ -353,12 +204,18 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
sendSelectedPhotos();
}
});
if (singlePhoto) {
pickerBottomLayout.setVisibility(View.GONE);
}
listView.setEmptyView(emptyView);
pickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);
pickerBottomLayout.updateSelectedCount(selectedPhotos.size(), true);
if(singlePhoto) {
pickerBottomLayout.setVisibility(View.GONE);
}
else {
View shadow = new View(context);
shadow.setBackgroundResource(R.drawable.header_shadow_reverse);
frameLayout.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.LEFT | Gravity.BOTTOM, 0, 0, 0, 48));
}
return fragmentView;
}
@@ -369,10 +226,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
if (searchItem != null) {
searchItem.openSearch(true);
getParentActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
}
fixLayout();
}
@@ -387,12 +240,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.closeChats) {
removeSelfFromStack();
} else if (id == NotificationCenter.recentImagesDidLoaded) {
if (selectedAlbum == null && type == (Integer) args[0]) {
recentImages = (ArrayList<MediaController.SearchImage>) args[1];
loadingRecent = false;
updateSearchInterface();
}
}
}
@@ -404,21 +251,10 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
if (view instanceof PhotoPickerPhotoCell) {
PhotoPickerPhotoCell cell = (PhotoPickerPhotoCell) view;
int num = (Integer) cell.photoImage.getTag();
if (selectedAlbum != null) {
if (num < 0 || num >= selectedAlbum.photos.size()) {
continue;
}
} else {
ArrayList<MediaController.SearchImage> array;
if (searchResult.isEmpty() && lastSearchString == null) {
array = recentImages;
} else {
array = searchResult;
}
if (num < 0 || num >= array.size()) {
continue;
}
if (num < 0 || num >= selectedAlbum.photos.size()) {
continue;
}
if (num == index) {
return cell;
}
@@ -450,7 +286,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
public void updatePhotoAtIndex(int index) {
PhotoPickerPhotoCell cell = getCellForIndex(index);
if (cell != null) {
if (selectedAlbum != null) {
cell.photoImage.setOrientation(0, true);
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
if (photoEntry.thumbPath != null) {
@@ -465,24 +300,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
} else {
cell.photoImage.setImageResource(R.drawable.nophotos);
}
} else {
ArrayList<MediaController.SearchImage> array;
if (searchResult.isEmpty() && lastSearchString == null) {
array = recentImages;
} else {
array = searchResult;
}
MediaController.SearchImage photoEntry = array.get(index);
if (photoEntry.document != null && photoEntry.document.thumb != null) {
cell.photoImage.setImage(photoEntry.document.thumb.location, null, cell.getContext().getResources().getDrawable(R.drawable.nophotos));
} else if (photoEntry.thumbPath != null) {
cell.photoImage.setImage(photoEntry.thumbPath, null, cell.getContext().getResources().getDrawable(R.drawable.nophotos));
} else if (photoEntry.thumbUrl != null && photoEntry.thumbUrl.length() > 0) {
cell.photoImage.setImage(photoEntry.thumbUrl, null, cell.getContext().getResources().getDrawable(R.drawable.nophotos));
} else {
cell.photoImage.setImageResource(R.drawable.nophotos);
}
}
}
}
@@ -505,21 +322,9 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
}
PhotoPickerPhotoCell cell = (PhotoPickerPhotoCell) view;
int num = (Integer) view.getTag();
if (selectedAlbum != null) {
if (num < 0 || num >= selectedAlbum.photos.size()) {
continue;
}
} else {
ArrayList<MediaController.SearchImage> array;
if (searchResult.isEmpty() && lastSearchString == null) {
array = recentImages;
} else {
array = searchResult;
}
if (num < 0 || num >= array.size()) {
continue;
}
}
if (num == index) {
cell.checkBox.setVisibility(View.VISIBLE);
break;
@@ -536,23 +341,12 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
@Override
public boolean isPhotoChecked(int index) {
if (selectedAlbum != null) {
return !(index < 0 || index >= selectedAlbum.photos.size()) && selectedPhotos.containsKey(selectedAlbum.photos.get(index).imageId);
} else {
ArrayList<MediaController.SearchImage> array;
if (searchResult.isEmpty() && lastSearchString == null) {
array = recentImages;
} else {
array = searchResult;
}
return !(index < 0 || index >= array.size()) && selectedWebPhotos.containsKey(array.get(index).id);
}
}
@Override
public void setPhotoChecked(int index) {
boolean add = true;
if (selectedAlbum != null) {
if (index < 0 || index >= selectedAlbum.photos.size()) {
return;
}
@@ -563,25 +357,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
} else {
selectedPhotos.put(photoEntry.imageId, photoEntry);
}
} else {
MediaController.SearchImage photoEntry;
ArrayList<MediaController.SearchImage> array;
if (searchResult.isEmpty() && lastSearchString == null) {
array = recentImages;
} else {
array = searchResult;
}
if (index < 0 || index >= array.size()) {
return;
}
photoEntry = array.get(index);
if (selectedWebPhotos.containsKey(photoEntry.id)) {
selectedWebPhotos.remove(photoEntry.id);
add = false;
} else {
selectedWebPhotos.put(photoEntry.id, photoEntry);
}
}
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View view = listView.getChildAt(a);
@@ -591,7 +366,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
break;
}
}
pickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);
pickerBottomLayout.updateSelectedCount(selectedPhotos.size(), true);
delegate.selectedPhotosChanged();
}
@@ -604,7 +379,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
@Override
public void sendButtonPressed(int index) {
if (selectedAlbum != null) {
if (selectedPhotos.isEmpty()) {
if (index < 0 || index >= selectedAlbum.photos.size()) {
return;
@@ -612,47 +386,12 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
selectedPhotos.put(photoEntry.imageId, photoEntry);
}
} else if (selectedPhotos.isEmpty()) {
ArrayList<MediaController.SearchImage> array;
if (searchResult.isEmpty() && lastSearchString == null) {
array = recentImages;
} else {
array = searchResult;
}
if (index < 0 || index >= array.size()) {
return;
}
MediaController.SearchImage photoEntry = array.get(index);
selectedWebPhotos.put(photoEntry.id, photoEntry);
}
sendSelectedPhotos();
}
@Override
public int getSelectedCount() {
return selectedPhotos.size() + selectedWebPhotos.size();
}
@Override
public void onTransitionAnimationEnd(boolean isOpen, boolean backward) {
if (isOpen && searchItem != null) {
AndroidUtilities.showKeyboard(searchItem.getSearchField());
}
}
private void updateSearchInterface() {
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
if (searching && searchResult.isEmpty() || loadingRecent && lastSearchString == null) {
progressView.setVisibility(View.VISIBLE);
listView.setEmptyView(null);
emptyView.setVisibility(View.GONE);
} else {
progressView.setVisibility(View.GONE);
emptyView.setVisibility(View.VISIBLE);
listView.setEmptyView(emptyView);
}
return selectedPhotos.size();
}
public void setDelegate(PhotoPickerActivityDelegate delegate) {
@@ -660,7 +399,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
}
private void sendSelectedPhotos() {
if (selectedPhotos.isEmpty() && selectedWebPhotos.isEmpty() || delegate == null || sendPressed) {
if (selectedPhotos.isEmpty() || delegate == null || sendPressed) {
return;
}
sendPressed = true;
@@ -712,10 +451,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
listAdapter.notifyDataSetChanged();
listView.setSelection(position);
if (selectedAlbum == null) {
emptyView.setPadding(0, 0, 0, (int) ((AndroidUtilities.displaySize.y - ActionBar.getCurrentActionBarHeight()) * 0.4f));
}
}
private class ListAdapter extends BaseFragmentAdapter {
@@ -727,32 +462,16 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
@Override
public boolean areAllItemsEnabled() {
return selectedAlbum != null;
return true;
}
@Override
public boolean isEnabled(int i) {
if (selectedAlbum == null) {
if (searchResult.isEmpty() && lastSearchString == null) {
return i < recentImages.size();
} else {
return i < searchResult.size();
}
}
return true;
}
@Override
public int getCount() {
if (selectedAlbum == null) {
if (searchResult.isEmpty() && lastSearchString == null) {
return recentImages.size();
} else if (type == 0) {
return searchResult.size() + (nextSearchBingString == null ? 0 : 1);
} else if (type == 1) {
return searchResult.size() + (giphySearchEndReached ? 0 : 1);
}
}
return selectedAlbum.photos.size();
}
@@ -773,8 +492,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
int viewType = getItemViewType(i);
if (viewType == 0) {
PhotoPickerPhotoCell cell = (PhotoPickerPhotoCell) view;
if (view == null) {
view = new PhotoPickerPhotoCell(mContext);
@@ -783,7 +500,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
@Override
public void onClick(View v) {
int index = (Integer) ((View) v.getParent()).getTag();
if (selectedAlbum != null) {
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
if (selectedPhotos.containsKey(photoEntry.imageId)) {
selectedPhotos.remove(photoEntry.imageId);
@@ -794,25 +510,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
selectedPhotos.put(photoEntry.imageId, photoEntry);
}
((PhotoPickerPhotoCell) v.getParent()).setChecked(selectedPhotos.containsKey(photoEntry.imageId), true);
} else {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
MediaController.SearchImage photoEntry;
if (searchResult.isEmpty() && lastSearchString == null) {
photoEntry = recentImages.get((Integer) ((View) v.getParent()).getTag());
} else {
photoEntry = searchResult.get((Integer) ((View) v.getParent()).getTag());
}
if (selectedWebPhotos.containsKey(photoEntry.id)) {
selectedWebPhotos.remove(photoEntry.id);
photoEntry.imagePath = null;
photoEntry.thumbPath = null;
updatePhotoAtIndex(index);
} else {
selectedWebPhotos.put(photoEntry.id, photoEntry);
}
((PhotoPickerPhotoCell) v.getParent()).setChecked(selectedWebPhotos.containsKey(photoEntry.id), true);
}
pickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);
pickerBottomLayout.updateSelectedCount(selectedPhotos.size(), true);
delegate.selectedPhotosChanged();
}
});
@@ -825,7 +523,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
boolean showing;
imageView.setOrientation(0, true);
if (selectedAlbum != null) {
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(i);
if (photoEntry.thumbPath != null) {
imageView.setImage(photoEntry.thumbPath, null, mContext.getResources().getDrawable(R.drawable.nophotos));
@@ -841,68 +538,24 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
}
cell.setChecked(selectedPhotos.containsKey(photoEntry.imageId), false);
showing = PhotoViewer.getInstance().isShowingImage(photoEntry.path);
} else {
MediaController.SearchImage photoEntry;
if (searchResult.isEmpty() && lastSearchString == null) {
photoEntry = recentImages.get(i);
} else {
photoEntry = searchResult.get(i);
}
if (photoEntry.thumbPath != null) {
imageView.setImage(photoEntry.thumbPath, null, mContext.getResources().getDrawable(R.drawable.nophotos));
} else if (photoEntry.thumbUrl != null && photoEntry.thumbUrl.length() > 0) {
imageView.setImage(photoEntry.thumbUrl, null, mContext.getResources().getDrawable(R.drawable.nophotos));
} else if (photoEntry.document != null && photoEntry.document.thumb != null) {
imageView.setImage(photoEntry.document.thumb.location, null, mContext.getResources().getDrawable(R.drawable.nophotos));
} else {
imageView.setImageResource(R.drawable.nophotos);
}
cell.setChecked(selectedWebPhotos.containsKey(photoEntry.id), false);
if (photoEntry.document != null) {
showing = PhotoViewer.getInstance().isShowingImage(FileLoader.getPathToAttach(photoEntry.document, true).getAbsolutePath());
} else {
showing = PhotoViewer.getInstance().isShowingImage(photoEntry.imageUrl);
}
}
imageView.getImageReceiver().setVisible(!showing, true);
cell.checkBox.setVisibility(singlePhoto || showing ? View.GONE : View.VISIBLE);
} else if (viewType == 1) {
if (view == null) {
LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.media_loading_layout, viewGroup, false);
}
ViewGroup.LayoutParams params = view.getLayoutParams();
params.width = itemWidth;
params.height = itemWidth;
view.setLayoutParams(params);
}
return view;
}
@Override
public int getItemViewType(int i) {
if (selectedAlbum != null || searchResult.isEmpty() && lastSearchString == null && i < recentImages.size() || i < searchResult.size()) {
return 0;
}
return 1;
return 0;
}
@Override
public int getViewTypeCount() {
return 2;
return 1;
}
@Override
public boolean isEmpty() {
if (selectedAlbum != null) {
return selectedAlbum.photos.isEmpty();
} else {
if (searchResult.isEmpty() && lastSearchString == null) {
return recentImages.isEmpty();
} else {
return searchResult.isEmpty();
}
}
return selectedAlbum.photos.isEmpty();
}
}
}
@@ -22,7 +22,6 @@
package com.b44t.ui;
import android.Manifest;
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
@@ -32,7 +31,6 @@ import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
@@ -62,14 +60,12 @@ import android.view.WindowManager;
import android.view.animation.DecelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Scroller;
import android.widget.TextView;
import android.widget.Toast;
import com.b44t.messenger.AndroidUtilities;
import com.b44t.messenger.ImageLoader;
import com.b44t.messenger.MrChat;
import com.b44t.messenger.MrContact;
import com.b44t.messenger.MrMailbox;
import com.b44t.messenger.exoplayer.AspectRatioFrameLayout;
@@ -86,6 +82,7 @@ import com.b44t.messenger.ConnectionsManager;
import com.b44t.messenger.TLRPC;
import com.b44t.messenger.MessageObject;
import com.b44t.messenger.Utilities;
import com.b44t.ui.ActionBar.BaseFragment;
import com.b44t.ui.ActionBar.Theme;
import com.b44t.messenger.AnimatorListenerAdapterProxy;
import com.b44t.ui.ActionBar.ActionBar;
@@ -133,7 +130,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
private TextView nameTextView;
private TextView dateTextView;
private ActionBarMenuItem menuItem;
//private ImageView shareButton; -- we have a menu atop, this is clearer, tg uses different positions for image/video
private BackgroundDrawable backgroundDrawable = new BackgroundDrawable(0xff000000);
private CheckBox checkImageView;
private PickerBottomLayout pickerView;
@@ -220,7 +216,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
private int avatarsDialogId;
private long currentDialogId;
private long mergeDialogId;
private final long mergeDialogId = 0;
private int totalImagesCount;
private int totalImagesCountMerge;
private boolean isFirstLoading;
@@ -280,7 +276,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
private final static int gallery_menu_save = 1;
//private final static int gallery_menu_showall = 2;
private final static int gallery_menu_send = 3;
private final static int gallery_menu_crop = 4;
private final static int gallery_menu_forward = 5;
private final static int gallery_menu_delete = 6;
@@ -288,7 +283,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
//private final static int gallery_menu_caption = 8;-- currently, we do not allow messages along images; KISS: just use a separate message
//private final static int gallery_menu_caption_done = 9;
private final static int gallery_menu_share = 10;
private final static int gallery_menu_openin = 11;
private final static int PAGE_SPACING = AndroidUtilities.dp(30);
@@ -941,42 +935,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}*/
}
private void onSharePressed() {
if (parentActivity == null) {
return;
}
try {
File f = null;
boolean isVideo = false;
if (currentMessageObject != null) {
isVideo = currentMessageObject.isVideo();
f = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
} else if (currentFileLocation != null) {
f = FileLoader.getPathToAttach(currentFileLocation, avatarsDialogId != 0);
}
if (f.exists()) {
Intent intent = new Intent(Intent.ACTION_SEND);
if (isVideo) {
intent.setType("video/mp4");
} else {
intent.setType("image/jpeg");
}
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
parentActivity.startActivityForResult(Intent.createChooser(intent, LocaleController.getString("ShareFile", R.string.ShareFile)), 500);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
builder.setMessage(LocaleController.getString("PleaseDownload", R.string.PleaseDownload));
showAlertDialog(builder);
}
} catch (Exception e) {
FileLog.e("messenger", e);
}
}
public void setParentActivity(final Activity activity) {
if (parentActivity == activity) {
return;
@@ -1064,25 +1022,8 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}*/
closePhoto(true, false);
} else if (id == gallery_menu_save) {
if (Build.VERSION.SDK_INT >= 23 && parentActivity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
parentActivity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 4);
return;
}
File f = null;
if (currentMessageObject != null) {
f = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
} else if (currentFileLocation != null) {
f = FileLoader.getPathToAttach(currentFileLocation, avatarsDialogId != 0);
}
if (f != null && f.exists()) {
MediaController.saveFile(f.toString(), parentActivity, currentMessageObject != null && currentMessageObject.isVideo() ? 1 : 0, null, null);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
builder.setMessage(LocaleController.getString("PleaseDownload", R.string.PleaseDownload));
showAlertDialog(builder);
AndroidUtilities.saveMessageFileToExt(parentActivity, currentMessageObject.getId());
}
}
/*else if (id == gallery_menu_showall) {
@@ -1097,40 +1038,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
}
*/
else if (id == gallery_menu_send) {
/*Intent intent = new Intent(this, MessagesActivity.class);
intent.putExtra("onlySelect", true);
startActivityForResult(intent, 10);
if (requestCode == 10) {
int chatId = data.getIntExtra("chatId", 0);
int userId = data.getIntExtra("userId", 0);
int dialog_id = 0;
if (chatId != 0) {
dialog_id = -chatId;
} else if (userId != 0) {
dialog_id = userId;
}
TLRPC.FileLocation location = getCurrentFile();
if (dialog_id != 0 && location != null) {
Intent intent = new Intent(GalleryImageViewer.this, ChatActivity.class);
if (chatId != 0) {
intent.putExtra("chatId", chatId);
} else {
intent.putExtra("userId", userId);
}
startActivity(intent);
NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
finish();
if (withoutBottom) {
MessagesController.getInstance().sendMessage(location, dialog_id);
} else {
int item = mViewPager.getCurrentItem();
MessageObject obj = localPagerAdapter.imagesArr.get(item);
MessagesController.getInstance().sendMessage(obj, dialog_id);
}
}
}*/
} else if (id == gallery_menu_crop) {
else if (id == gallery_menu_crop) {
switchToEditMode(1);
} else if (id == gallery_menu_tune) {
switchToEditMode(2);
@@ -1250,14 +1158,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
*/
else if (id == gallery_menu_share) {
onSharePressed();
} else if (id == gallery_menu_openin) {
try {
AndroidUtilities.openForView(currentMessageObject, parentActivity);
closePhoto(false, false);
} catch (Exception e) {
FileLog.e("messenger", e);
}
AndroidUtilities.openForViewOrShare(parentActivity, currentMessageObject.getId(), Intent.ACTION_SEND);
}
}
@@ -1281,17 +1182,8 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
ActionBarMenu menu = actionBar.createMenu();
menuItem = menu.addItem(0, R.drawable.ic_ab_other);
String str = LocaleController.getString("OpenInBrowser", R.string.OpenInBrowser);
if (!TextUtils.isEmpty(str)) { //TODO add new string later
str = str.substring(0,1).toUpperCase() + str.substring(1).toLowerCase();
}
menuItem.addSubItem(gallery_menu_openin, str, 0);
menuItem.addSubItem(gallery_menu_save, LocaleController.getString("SaveToGallery", R.string.SaveToGallery), 0);
//menuItem.addSubItem(gallery_menu_showall, LocaleController.getString("ShowAllMedia", R.string.ShowAllMedia), 0);
// the following 3 options are disabled for the moment, we'll add them if we have the time (bp)
// (as a replacement, you can use "save to gallery" for sharing or the options from the chat for forwarding/delete)
//menuItem.addSubItem(gallery_menu_share, LocaleController.getString("ShareFile", R.string.ShareFile), 0);
menuItem.addSubItem(gallery_menu_save, ApplicationLoader.applicationContext.getString(R.string.SaveToGallery), 0);
menuItem.addSubItem(gallery_menu_share, ApplicationLoader.applicationContext.getString(R.string.Share), 0);
//menuItem.addSubItem(gallery_menu_forward, LocaleController.getString("Forward", R.string.Forward), 0);
//menuItem.addSubItem(gallery_menu_delete, LocaleController.getString("Delete", R.string.Delete), 0);
@@ -1335,20 +1227,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
radialProgressViews[2] = new RadialProgressView(containerView.getContext(), containerView);
radialProgressViews[2].setBackgroundState(0, false);
/*
shareButton = new ImageView(containerView.getContext());
shareButton.setImageResource(R.drawable.share);
shareButton.setScaleType(ImageView.ScaleType.CENTER);
shareButton.setBackgroundDrawable(Theme.createBarSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
bottomLayout.addView(shareButton, LayoutHelper.createFrame(50, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT));
shareButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onSharePressed();
}
});
*/
nameTextView = new TextView(containerView.getContext());
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
nameTextView.setSingleLine(true);
@@ -1845,8 +1723,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
videoPlayerControlFrameLayout.setVisibility(View.VISIBLE);
dateTextView.setVisibility(View.GONE);
nameTextView.setVisibility(View.GONE);
//shareButton.setVisibility(View.GONE);
//menuItem.showSubItem(gallery_menu_share);
}
if (videoTextureView.getSurfaceTexture() != null) {
videoPlayer.setSurface(new Surface(videoTextureView.getSurfaceTexture()));
@@ -1875,8 +1751,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
videoPlayerControlFrameLayout.setVisibility(View.GONE);
dateTextView.setVisibility(View.VISIBLE);
nameTextView.setVisibility(View.VISIBLE);
//shareButton.setVisibility(View.VISIBLE);
//menuItem.hideSubItem(gallery_menu_share);
}
}
@@ -2544,10 +2418,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
currentThumb = object != null ? object.thumb : null;
menuItem.setVisibility(View.VISIBLE);
bottomLayout.setVisibility(View.VISIBLE);
//shareButton.setVisibility(View.GONE);
//menuItem.hideSubItem(gallery_menu_showall);
//menuItem.hideSubItem(gallery_menu_share);
menuItem.hideSubItem(gallery_menu_openin);
actionBar.setTranslationY(0);
pickerView.setTranslationY(0);
checkImageView.setAlpha(1.0f);
@@ -2591,13 +2462,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
imagesArrLocations.add(fileLocation);
imagesArrLocationsSizes.add(object.size);
avatarsArr.add(new TLRPC.TL_photoEmpty());
//shareButton.setVisibility(videoPlayerControlFrameLayout == null || videoPlayerControlFrameLayout.getVisibility() != View.VISIBLE ? View.VISIBLE : View.GONE);
//menuItem.hideSubItem(gallery_menu_showall);
/*if (shareButton.getVisibility() == View.VISIBLE) {
menuItem.hideSubItem(gallery_menu_share);
} else*/ {
menuItem.showSubItem(gallery_menu_share);
}
setImageIndex(0, true);
//currentUserAvatarLocation = fileLocation;
} else if (messages != null) {
@@ -2690,20 +2554,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
currentMessageObject = newMessageObject;
isVideo = currentMessageObject.isVideo();
/*
if (currentMessageObject.canDeleteMessage(null)) {
menuItem.showSubItem(gallery_menu_delete);
} else {
menuItem.hideSubItem(gallery_menu_delete);
}
*/
if (isVideo && Build.VERSION.SDK_INT >= 16) {
menuItem.showSubItem(gallery_menu_openin);
} else {
menuItem.hideSubItem(gallery_menu_openin);
}
if( currentMessageObject!=null && currentMessageObject.messageOwner!=null )
{
MrContact mrContact = MrMailbox.getContact(currentMessageObject.messageOwner.from_id);
@@ -2741,12 +2591,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (currentAnimation != null) {
menuItem.hideSubItem(gallery_menu_save);
menuItem.hideSubItem(gallery_menu_share);
/*
if (!currentMessageObject.canDeleteMessage(null)) {
menuItem.setVisibility(View.GONE);
}
*/
//shareButton.setVisibility(View.VISIBLE);
actionBar.setTitle(LocaleController.getString("AttachGif", R.string.AttachGif));
} else {
if (totalImagesCount + totalImagesCountMerge != 0 && !needSearchImageInArr) {
@@ -2781,27 +2625,10 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, (totalImagesCount + totalImagesCountMerge - imagesArr.size()) + currentIndex + 1, totalImagesCount + totalImagesCountMerge));
}
} /*else if (currentMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) {
if (currentMessageObject.isVideo()) {
actionBar.setTitle(LocaleController.getString("AttachVideo", R.string.AttachVideo));
} else {
actionBar.setTitle(LocaleController.getString("AttachPhoto", R.string.AttachPhoto));
}
}*/
/*if (currentMessageObject.messageOwner.ttl != 0) {
menuItem.hideSubItem(gallery_menu_save);
//shareButton.setVisibility(View.GONE);
menuItem.hideSubItem(gallery_menu_share);
} else*/ {
menuItem.showSubItem(gallery_menu_save);
//shareButton.setVisibility(videoPlayerControlFrameLayout == null || videoPlayerControlFrameLayout.getVisibility() != View.VISIBLE ? View.VISIBLE : View.GONE);
/*if (shareButton.getVisibility() == View.VISIBLE) {
menuItem.hideSubItem(gallery_menu_share);
} else*/ {
menuItem.showSubItem(gallery_menu_share);
}
}
menuItem.showSubItem(gallery_menu_save);
menuItem.showSubItem(gallery_menu_share);
}
} else if (!imagesArrLocations.isEmpty()) {
nameTextView.setText("");
@@ -2824,12 +2651,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, currentIndex + 1, imagesArrLocations.size()));
menuItem.showSubItem(gallery_menu_save);
//shareButton.setVisibility(videoPlayerControlFrameLayout == null || videoPlayerControlFrameLayout.getVisibility() != View.VISIBLE ? View.VISIBLE : View.GONE);
/*if (shareButton.getVisibility() == View.VISIBLE) {
menuItem.hideSubItem(gallery_menu_share);
} else*/ {
menuItem.showSubItem(gallery_menu_share);
}
menuItem.showSubItem(gallery_menu_share);
} else if (!imagesArrLocals.isEmpty()) {
Object object = imagesArrLocals.get(index);
if (index < 0 || index >= imagesArrLocals.size()) {
@@ -3156,24 +2978,24 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
return isVisible && !disableShowCheck && object != null && currentPathObject != null && object.equals(currentPathObject);
}
public void openPhoto(final MessageObject messageObject, long dialogId, long mergeDialogId, final PhotoViewerProvider provider) {
openPhoto(messageObject, null, null, null, 0, provider, null, dialogId, mergeDialogId);
public void openPhoto(final MessageObject messageObject, long dialogId, final PhotoViewerProvider provider) {
openPhoto(messageObject, null, null, null, 0, provider, null, dialogId);
}
public void openPhoto(final TLRPC.FileLocation fileLocation, final PhotoViewerProvider provider) {
openPhoto(null, fileLocation, null, null, 0, provider, null, 0, 0);
openPhoto(null, fileLocation, null, null, 0, provider, null, 0);
}
public void openPhoto(final ArrayList<MessageObject> messages, final int index, long dialogId, long mergeDialogId, final PhotoViewerProvider provider) {
openPhoto(messages.get(index), null, messages, null, index, provider, null, dialogId, mergeDialogId);
}
/*public void openPhoto(final ArrayList<MessageObject> messages, final int index, long dialogId, final PhotoViewerProvider provider) {
openPhoto(messages.get(index), null, messages, null, index, provider, null, dialogId);
}*/
public void openPhotoForSelect(final ArrayList<Object> photos, final int index, int type, final PhotoViewerProvider provider, ChatActivity chatActivity) {
sendPhotoType = type;
if (pickerView != null) {
pickerView.doneButtonTextView.setText(sendPhotoType == 1 ? LocaleController.getString("Set", R.string.Set).toUpperCase() : LocaleController.getString("Send", R.string.Send).toUpperCase());
}
openPhoto(null, null, null, photos, index, provider, chatActivity, 0, 0);
openPhoto(null, null, null, photos, index, provider, chatActivity, 0);
}
private boolean checkAnimation() {
@@ -3189,7 +3011,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
return animationInProgress != 0;
}
public void openPhoto(final MessageObject messageObject, final TLRPC.FileLocation fileLocation, final ArrayList<MessageObject> messages, final ArrayList<Object> photos, final int index, final PhotoViewerProvider provider, ChatActivity chatActivity, long dialogId, long mDialogId) {
public void openPhoto(final MessageObject messageObject, final TLRPC.FileLocation fileLocation, final ArrayList<MessageObject> messages, final ArrayList<Object> photos, final int index, final PhotoViewerProvider provider, ChatActivity chatActivity, long dialogId) {
if (parentActivity == null || isVisible || provider == null && checkAnimation() || messageObject == null && fileLocation == null && messages == null && photos == null) {
return;
}
@@ -3232,7 +3054,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);
placeProvider = provider;
mergeDialogId = mDialogId;
currentDialogId = dialogId;
if (velocityTracker == null) {
@@ -4368,7 +4189,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
} else {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "video/mp4");
parentActivity.startActivityForResult(intent, 500);
parentActivity.startActivityForResult(intent, BaseFragment.RC500_PHOTO_VIEW);
}
}
}
@@ -77,11 +77,11 @@ public class PrivacySettingsActivity extends BaseFragment implements Notificatio
rowCount = 0;
privacySectionRow = -1;
e2eEncryptionRow = rowCount++;
readReceiptsRow = rowCount++;
blockedRow = rowCount++;
passcodeRow = rowCount++;
blockedRow = rowCount++;
showUnknownSendersRow = rowCount++;
readReceiptsRow = rowCount++;
e2eEncryptionRow = rowCount++;
manageKeysRow = rowCount++;
securitySectionRow = -1;
secretDetailRow = rowCount++;
@@ -131,9 +131,9 @@ public class PrivacySettingsActivity extends BaseFragment implements Notificatio
presentFragment(new BlockedUsersActivity());
} else if (i == passcodeRow) {
if (UserConfig.passcodeHash.length() > 0) {
presentFragment(new PasscodeActivity(2));
presentFragment(new PasscodeActivity(PasscodeActivity.SCREEN2_ENTER_CODE2));
} else {
presentFragment(new PasscodeActivity(0));
presentFragment(new PasscodeActivity(PasscodeActivity.SCREEN0_SETTINGS));
}
}
else if(i==e2eEncryptionRow )
@@ -291,7 +291,7 @@ public class PrivacySettingsActivity extends BaseFragment implements Notificatio
TextSettingsCell textCell = (TextSettingsCell) view;
if (i == blockedRow) {
String cntStr = String.format("%d", MrMailbox.getBlockedCount());
textCell.setTextAndValue(LocaleController.getString("BlockedUsers", R.string.BlockedUsers), cntStr, true);
textCell.setTextAndValue(ApplicationLoader.applicationContext.getString(R.string.BlockedContacts), cntStr, true);
} else if (i == passcodeRow) {
String val = UserConfig.passcodeHash.length() > 0? LocaleController.getString("Enabled", R.string.Enabled) : LocaleController.getString("Disabled", R.string.Disabled);
textCell.setTextAndValue(LocaleController.getString("Passcode", R.string.Passcode), val, true);
@@ -38,7 +38,7 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.view.Gravity;
@@ -59,7 +59,6 @@ import com.b44t.messenger.LocaleController;
import com.b44t.messenger.MrChat;
import com.b44t.messenger.MrContact;
import com.b44t.messenger.MrMailbox;
import com.b44t.messenger.SendMessagesHelper;
import com.b44t.messenger.ApplicationLoader;
import com.b44t.messenger.support.widget.LinearLayoutManager;
import com.b44t.messenger.support.widget.RecyclerView;
@@ -92,7 +91,7 @@ import com.b44t.ui.ActionBar.Theme;
import java.util.ArrayList;
public class ProfileActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, DialogsActivity.DialogsActivityDelegate, PhotoViewer.PhotoViewerProvider {
public class ProfileActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, PhotoViewer.PhotoViewerProvider {
private int user_id; // show the profile of a single user
private int chat_id; // show the profile of a group
@@ -296,9 +295,10 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if( MrMailbox.deleteContact(user_id)==0 ) {
Toast.makeText(getParentActivity(), LocaleController.getString("CannotDeleteContact", R.string.CannotDeleteContact), Toast.LENGTH_LONG).show();
AndroidUtilities.showHint(getParentActivity(), ApplicationLoader.applicationContext.getString(R.string.CannotDeleteContact));
}
else {
AndroidUtilities.showDoneHint(getParentActivity());
finishFragment();
}
}
@@ -444,18 +444,24 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
fragment.setDelegate(new ContactsActivity.ContactsActivityDelegate() {
@Override
public void didSelectContact(final int added_user_id) {
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) {
MrMailbox.addContactToChat(chat_id, added_user_id);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_CHAT_MEMBERS);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
String name = MrMailbox.getContact(added_user_id).getDisplayName();
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("AskAddMemberToGroup", R.string.AskAddMemberToGroup, name)));
showDialog(builder.create());
if( MrMailbox.isContactInChat(chat_id, added_user_id)!=0 )
{
Toast.makeText(getParentActivity(), ApplicationLoader.applicationContext.getString(R.string.ContactAlreadyInGroup), Toast.LENGTH_SHORT).show();
}
else {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setPositiveButton(ApplicationLoader.applicationContext.getString(R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
MrMailbox.addContactToChat(chat_id, added_user_id);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_CHAT_MEMBERS);
}
});
builder.setNegativeButton(ApplicationLoader.applicationContext.getString(R.string.Cancel), null);
String name = MrMailbox.getContact(added_user_id).getDisplayName();
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("AskAddMemberToGroup", R.string.AskAddMemberToGroup, name)));
showDialog(builder.create());
}
}
});
presentFragment(fragment);
@@ -855,7 +861,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
public void setPlayProfileAnimation(boolean value) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
if (!AndroidUtilities.isTablet() && preferences.getBoolean("view_animations", true)) {
if (!AndroidUtilities.isTablet() && preferences.getBoolean("view_animations2", true)) {
playProfileAnimation = value;
}
}
@@ -1199,7 +1205,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
}
if (user_id != 0) {
item.addSubItem(ID_STOP_ENCRYPTION_FOR_THIS_USER, LocaleController.getString("ResetUserKey", R.string.ResetUserKey), 0);
item.addSubItem(ID_STOP_ENCRYPTION_FOR_THIS_USER, ApplicationLoader.applicationContext.getString(R.string.ResetContactsKey), 0);
item.addSubItem(ID_BLOCK_CONTACT, userBlocked()? LocaleController.getString("UnblockContact", R.string.UnblockContact) : LocaleController.getString("BlockContact", R.string.BlockContact), 0);
item.addSubItem(ID_DELETE_CONTACT, LocaleController.getString("DeleteContact", R.string.DeleteContact), 0);
}
@@ -1214,31 +1220,6 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
}
}
@Override
public void didSelectDialog(DialogsActivity fragment, long dialog_id, boolean param) {
if (dialog_id != 0) {
Bundle args = new Bundle();
args.putBoolean("scrollToTopOnResume", true);
int lower_part = (int) dialog_id;
if (lower_part != 0) {
if (lower_part > 0) {
args.putInt("user_id", lower_part);
} else if (lower_part < 0) {
args.putInt("chat_id", -lower_part);
}
} else {
args.putInt("enc_id", (int) (dialog_id >> 32));
}
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
presentFragment(new ChatActivity(args), true);
removeSelfFromStack();
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
SendMessagesHelper.getInstance().sendMessageContact(user, dialog_id, null, null);
}
}
private class ListAdapter extends RecyclerListView.Adapter {
private Context mContext;
@@ -46,7 +46,6 @@ import android.widget.ListView;
import android.widget.TextView;
import com.b44t.messenger.AndroidUtilities;
import com.b44t.messenger.MessagesController;
import com.b44t.messenger.MrChat;
import com.b44t.messenger.MrMailbox;
import com.b44t.messenger.NotificationsController;
@@ -56,7 +55,6 @@ import com.b44t.messenger.LocaleController;
import com.b44t.messenger.NotificationCenter;
import com.b44t.messenger.R;
import com.b44t.messenger.ConnectionsManager;
import com.b44t.messenger.TLRPC;
import com.b44t.ui.ActionBar.Theme;
import com.b44t.ui.Adapters.BaseFragmentAdapter;
import com.b44t.ui.Cells.HeaderCell;
@@ -211,13 +209,13 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
}*/
//MessagesStorage.getInstance().setDialogFlags(dialog_id, which == 2 ? 1 : 0);
editor.apply();
TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict.get(dialog_id);
/*TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict.get(dialog_id);
if (dialog != null) {
dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
if (which == 2) {
dialog.notify_settings.mute_until = Integer.MAX_VALUE;
}
}
}*/
if (listView != null) {
listView.invalidateViews();
}
@@ -251,7 +249,7 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
}
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
startActivityForResult(tmpIntent, 12);
startActivityForResult(tmpIntent, RC12_PROFILE_RINGTONE_PICKER);
} catch (Exception e) {
FileLog.e("messenger", e);
}
@@ -482,7 +480,7 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (requestCode == 12) {
if (requestCode == RC12_PROFILE_RINGTONE_PICKER) {
if (name != null) {
editor.putString("sound_" + dialog_id, name);
editor.putString("sound_path_" + dialog_id, ringtone.toString());
@@ -1,7 +1,6 @@
/*******************************************************************************
*
* Messenger Android Frontend
* (C) 2013-2016 Nikolai Kudashov
* (C) 2017 Björn Petersen
* Contact: r10s@b44t.com, http://b44t.com
*
@@ -18,141 +17,91 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/ .
*
*******************************************************************************
*
* File: SettingsActivity.java
* Purpose: Basic settings dialog, has mainly items to open other settings pages
*
******************************************************************************/
package com.b44t.ui;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ListView;
import com.b44t.messenger.AndroidUtilities;
import com.b44t.messenger.MediaController;
import com.b44t.messenger.MrMailbox;
import com.b44t.messenger.ApplicationLoader;
import com.b44t.messenger.LocaleController;
import com.b44t.messenger.MessagesController;
import com.b44t.messenger.NotificationCenter;
import com.b44t.messenger.MrMailbox;
import com.b44t.messenger.R;
import com.b44t.ui.Adapters.BaseFragmentAdapter;
import com.b44t.ui.Cells.EmptyCell;
import com.b44t.ui.Cells.HeaderCell;
import com.b44t.ui.Cells.ShadowSectionCell;
import com.b44t.ui.Cells.TextCheckCell;
import com.b44t.ui.Cells.TextDetailSettingsCell;
import com.b44t.ui.Cells.TextInfoPrivacyCell;
import com.b44t.ui.Cells.TextSettingsCell;
import com.b44t.ui.ActionBar.ActionBar;
import com.b44t.ui.ActionBar.BaseFragment;
import com.b44t.ui.Components.LayoutHelper;
import com.b44t.ui.Components.NumberPicker;
import com.b44t.ui.ActionBar.Theme;
import com.b44t.ui.Adapters.BaseFragmentAdapter;
import com.b44t.ui.Cells.HeaderCell;
import com.b44t.ui.Cells.ShadowSectionCell;
import com.b44t.ui.Cells.TextDetailSettingsCell;
import com.b44t.ui.Cells.TextSettingsCell;
import com.b44t.ui.Components.LayoutHelper;
import java.util.Locale;
public class SettingsActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate /*, PhotoViewer.PhotoViewerProvider -- EDIT BY MR */ {
public class SettingsActivity extends BaseFragment {
// the list
private int accountHeaderRow, usernameRow, accountSettingsRow, accountShadowRow;
private int settingsHeaderRow, privacyRow, notificationRow, backgroundRow, advRow, settingsShadowRow;
private int aboutHeaderRow, aboutRow, aboutShadowRow;
private int rowCount;
private static final int ROWTYPE_SHADOW = 0;
private static final int ROWTYPE_TEXT_SETTINGS = 1;
private static final int ROWTYPE_CHECK = 2;
private static final int ROWTYPE_HEADER = 3;
private static final int ROWTYPE_DETAIL_SETTINGS = 4;
private static final int ROWTYPE_HEADER = 2;
private static final int ROWTYPE_DETAIL_SETTINGS = 3;
private static final int ROWTYPE_COUNT = 5;
private ListView listView;
private ListAdapter listAdapter;
private int numberSectionRow;
private int accountSettingsRow;
private int usernameRow;
private int settingsSectionRow;
private int settingsSectionRow2;
private int enableAnimationsRow;
private int notificationRow;
private int backgroundRow;
private int languageRow;
private int privacyRow;
private int messagesSectionRow;
private int messagesSectionRow2;
private int directShareRow;
private int textSizeRow;
private int cacheRow;
private int raiseToSpeakRow;
private int sendByEnterRow;
private int supportSectionRow;
private int supportSectionRow2;
private int aboutRow;
private int rowCount;
public static int defMsgFontSize() {
return AndroidUtilities.isTablet() ? 18 : 16;
}
@Override
public boolean onFragmentCreate() {
public boolean onFragmentCreate()
{
super.onFragmentCreate();
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
rowCount = 0;
numberSectionRow = rowCount++;
usernameRow = rowCount++;
accountHeaderRow = rowCount++;
usernameRow = rowCount++;
accountSettingsRow = rowCount++;
settingsSectionRow = rowCount++;
settingsSectionRow2 = rowCount++;
privacyRow = rowCount++;
notificationRow = rowCount++;
backgroundRow = rowCount++;
languageRow = rowCount++;
// saveToGalleryRow: for now, we do not use this option, this results in confusing folders ("AppName" and "AppName Images" etc.); instead, for now, the user can use the option to manually save a media. Moreover, we also avoid the problem to double-save each image _or_ to handle the case a user deletes an image in the gallery.
messagesSectionRow = rowCount++;
messagesSectionRow2 = rowCount++;
textSizeRow = rowCount++; // incoming messages
if (Build.VERSION.SDK_INT >= 23) {
directShareRow = -1; // for now, seems not really to work, however, in T'gram it does
}
else {
directShareRow = -1;
}
raiseToSpeakRow = rowCount++; // outgoing message
sendByEnterRow = rowCount++;
enableAnimationsRow = rowCount++;
cacheRow = -1; // for now, the page is still reachable by the "storage settings" in the "android App Settings"
supportSectionRow = rowCount++;
supportSectionRow2 = rowCount++;
aboutRow = rowCount++;
accountShadowRow = rowCount++;
settingsHeaderRow = rowCount++;
privacyRow = rowCount++;
notificationRow = rowCount++;
backgroundRow = rowCount++;
advRow = rowCount++;
settingsShadowRow = rowCount++;
aboutHeaderRow = rowCount++;
aboutRow = rowCount++;
aboutShadowRow = rowCount++;
return true;
}
@Override
public void onFragmentDestroy() {
super.onFragmentDestroy();
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces);
}
@Override
public View createView(Context context) {
public View createView(Context context)
{
// create action bar
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("Settings", R.string.Settings));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
@@ -162,129 +111,57 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
}
});
listAdapter = new ListAdapter(context);
fragmentView = new FrameLayout(context) {
};
// create object to hold the whole view
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(0xfff0f0f0);
listView = new ListView(context);
// create the main layout list
ListAdapter listAdapter = new ListAdapter(context);
ListView listView = new ListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
AndroidUtilities.setListViewEdgeEffectColor(listView, Theme.ACTION_BAR_COLOR);
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
listView.setAdapter(listAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
if (i == textSizeRow) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("TextSize", R.string.TextSize));
final NumberPicker numberPicker = new NumberPicker(getParentActivity());
final int MIN_VAL = 12;
final int MAX_VAL = 30;
final int DEF_VAL = defMsgFontSize();
String displayValues[] = new String[MAX_VAL-MIN_VAL+1];
for( int v = MIN_VAL; v <= MAX_VAL; v++ ) {
String cur = String.format("%d", v);
if( v==DEF_VAL ) {
cur += " (" +LocaleController.getString("Default", R.string.Default)+ ")";
}
displayValues[v-MIN_VAL] = cur;
}
numberPicker.setMinValue(MIN_VAL);
numberPicker.setMaxValue(MAX_VAL);
numberPicker.setDisplayedValues(displayValues);
numberPicker.setWrapSelectorWheel(false);
numberPicker.setValue(MessagesController.getInstance().fontSize);
builder.setView(numberPicker);
builder.setNegativeButton(LocaleController.getString("Done", R.string.Done), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("msg_font_size", numberPicker.getValue());
MessagesController.getInstance().fontSize = numberPicker.getValue();
editor.apply();
if (listView != null) {
listView.invalidateViews();
}
}
});
showDialog(builder.create());
} else if (i == enableAnimationsRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations", true);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("view_animations", !animations);
editor.apply();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(!animations);
}
} else if (i == notificationRow) {
presentFragment(new NotificationsSettingsActivity());
} else if (i == backgroundRow) {
presentFragment(new WallpapersActivity());
} else if (i == sendByEnterRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean send = preferences.getBoolean("send_by_enter", false);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("send_by_enter", !send);
editor.apply();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(!send);
}
} else if (i == raiseToSpeakRow) {
MediaController.getInstance().toogleRaiseToSpeak();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(MediaController.getInstance().canRaiseToSpeak());
}
} else if(i == directShareRow) {
MediaController.getInstance().toggleDirectShare();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(MediaController.getInstance().canDirectShare());
}
} else if (i == privacyRow) {
public void onItemClick(final AdapterView<?> adapterView, View view, final int i, long l) {
if (i == usernameRow) {
presentFragment(new NameSettingsActivity());
}
else if (i == accountSettingsRow) {
presentFragment(new AccountSettingsActivity(null));
}
else if (i == privacyRow) {
presentFragment(new PrivacySettingsActivity());
} else if (i == languageRow) {
presentFragment(new LanguageSelectActivity());
} else if (i == aboutRow) {
}
else if (i == notificationRow) {
presentFragment(new NotificationsSettingsActivity());
}
else if (i == backgroundRow) {
presentFragment(new WallpapersActivity());
}
else if (i == advRow) {
presentFragment(new SettingsAdvActivity());
}
else if (i == aboutRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName) + " " + getVersion());
builder.setTitle(ApplicationLoader.applicationContext.getString(R.string.AppName) + " v" + getVersion());
builder.setMessage(MrMailbox.getInfo() + "\n\n" + getAndroidInfo());
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
;
;
}
});
showDialog(builder.create());
} else if (i == usernameRow) {
presentFragment(new NameSettingsActivity());
} else if (i == accountSettingsRow) {
presentFragment(new AccountSettingsActivity(null));
} else if (i == cacheRow) {
presentFragment(new CacheControlActivity());
}
}
});
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
return false;
}
});
frameLayout.addView(actionBar);
needLayout();
return fragmentView;
}
@@ -292,8 +169,18 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
{
try {
PackageInfo pInfo = ApplicationLoader.applicationContext.getPackageManager().getPackageInfo(ApplicationLoader.applicationContext.getPackageName(), 0);
int code = pInfo.versionCode / 10;
String abi = "";
return pInfo.versionName;
}
catch(Exception e) {
return "ErrVersion";
}
}
private String getAbi() // ABI = Application Binary Interface
{
try {
PackageInfo pInfo = ApplicationLoader.applicationContext.getPackageManager().getPackageInfo(ApplicationLoader.applicationContext.getPackageName(), 0);
String abi = "ErrAbi";
switch (pInfo.versionCode % 10) {
case 0:
abi = "arm";
@@ -308,80 +195,16 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
abi = "universal";
break;
}
return String.format(Locale.US, "V%s-%s", pInfo.versionName, abi);
return abi;
} catch (Exception e) {
return "ErrVersion";
return "ErrAbi";
}
}
private String getAndroidInfo()
{
return "Build.VERSION.SDK_INT=" + Build.VERSION.SDK_INT;
}
@Override
protected void onDialogDismiss(Dialog dialog) {
MediaController.getInstance().checkAutodownloadSettings();
}
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
}
@Override
public void saveSelfArgs(Bundle args) {
}
@Override
public void restoreSelfArgs(Bundle args) {
}
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.updateInterfaces) {
int mask = (Integer) args[0];
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0) {
updateUserData();
}
}
}
@Override
public void onResume() {
super.onResume();
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
updateUserData();
fixLayout();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
fixLayout();
}
private void needLayout() {
}
private void fixLayout() {
if (fragmentView == null) {
return;
}
fragmentView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
if (fragmentView != null) {
needLayout();
fragmentView.getViewTreeObserver().removeOnPreDrawListener(this);
}
return true;
}
});
}
private void updateUserData() {
return "Build.VERSION.SDK_INT=" + Build.VERSION.SDK_INT + "\n"
+ "ABI=" + getAbi();
}
private class ListAdapter extends BaseFragmentAdapter {
@@ -398,11 +221,9 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
@Override
public boolean isEnabled(int i) {
return i == textSizeRow || i == enableAnimationsRow || i == notificationRow || i == backgroundRow || i == accountSettingsRow ||
i == sendByEnterRow || i == privacyRow ||
i == languageRow || i == usernameRow ||
i == aboutRow ||
i == cacheRow || i == raiseToSpeakRow || i == directShareRow ;
return i == usernameRow || i == accountSettingsRow ||
i == privacyRow || i == notificationRow || i == backgroundRow || i == advRow ||
i == aboutRow;
}
@Override
@@ -432,60 +253,49 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
if (view == null) {
view = new ShadowSectionCell(mContext);
}
} else if (type == ROWTYPE_TEXT_SETTINGS) {
view.setBackgroundResource(i == aboutShadowRow? R.drawable.greydivider_bottom : R.drawable.greydivider);
}
else if (type == ROWTYPE_TEXT_SETTINGS) {
if (view == null) {
view = new TextSettingsCell(mContext);
view.setBackgroundColor(0xffffffff);
}
TextSettingsCell textCell = (TextSettingsCell) view;
if (i == textSizeRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
int size = preferences.getInt("msg_font_size", defMsgFontSize());
textCell.setTextAndValue(LocaleController.getString("TextSize", R.string.TextSize), String.format("%d", size), true);
} else if (i == languageRow) {
textCell.setTextAndValue(LocaleController.getString("Language", R.string.Language), LocaleController.getCurrentLanguageName(), false);
} else if (i == notificationRow) {
textCell.setText(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds), true);
} else if (i == backgroundRow) {
textCell.setText(LocaleController.getString("ChatBackground", R.string.ChatBackground), true);
} else if (i == privacyRow) {
if (i == privacyRow) {
textCell.setText(LocaleController.getString("PrivacySettings", R.string.PrivacySettings), true);
} else if (i == aboutRow) {
textCell.setText(LocaleController.getString("AboutThisProgram", R.string.AboutThisProgram), true);
} else if (i == cacheRow) {
textCell.setText(LocaleController.getString("CacheSettings", R.string.CacheSettings), false);
}
} else if (type == ROWTYPE_CHECK) {
if (view == null) {
view = new TextCheckCell(mContext);
}
TextCheckCell textCell = (TextCheckCell) view;
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
if (i == enableAnimationsRow) {
textCell.setTextAndCheck(LocaleController.getString("EnableAnimations", R.string.EnableAnimations), preferences.getBoolean("view_animations", true), false);
} else if (i == sendByEnterRow) {
textCell.setTextAndCheck(LocaleController.getString("SendByEnter", R.string.SendByEnter), preferences.getBoolean("send_by_enter", false), true);
} else if (i == raiseToSpeakRow) {
textCell.setTextAndCheck(LocaleController.getString("RaiseToSpeak", R.string.RaiseToSpeak), MediaController.getInstance().canRaiseToSpeak(), true);
} else if (i == directShareRow) {
textCell.setTextAndValueAndCheck(LocaleController.getString("DirectShare", R.string.DirectShare), LocaleController.getString("DirectShareInfo", R.string.DirectShareInfo), MediaController.getInstance().canDirectShare(), false, true);
else if (i == notificationRow) {
textCell.setText(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds), true);
}
} else if (type == ROWTYPE_HEADER) {
else if (i == backgroundRow) {
textCell.setText(LocaleController.getString("ChatBackground", R.string.ChatBackground), true);
}
else if (i == advRow) {
textCell.setText(ApplicationLoader.applicationContext.getString(R.string.AdvancedSettings), false);
}
else if (i == aboutRow) {
textCell.setText(ApplicationLoader.applicationContext.getString(R.string.AboutThisProgram), false);
}
}
else if (type == ROWTYPE_HEADER) {
if (view == null) {
view = new HeaderCell(mContext);
view.setBackgroundColor(0xffffffff);
}
if (i == settingsSectionRow2) {
((HeaderCell) view).setText(LocaleController.getString("SETTINGS", R.string.SETTINGS));
} else if (i == supportSectionRow2) {
if (i == settingsHeaderRow) {
((HeaderCell) view).setText(ApplicationLoader.applicationContext.getString(R.string.Settings));
}
else if (i == aboutHeaderRow) {
((HeaderCell) view).setText(LocaleController.getString("Info", R.string.Info));
} else if (i == messagesSectionRow2) {
((HeaderCell) view).setText(LocaleController.getString("AdvancedSettings", R.string.AdvancedSettings));
} else if (i == numberSectionRow) {
}
else if (i == accountHeaderRow) {
((HeaderCell) view).setText(LocaleController.getString("MyAccount", R.string.MyAccount));
}
} else if (type == ROWTYPE_DETAIL_SETTINGS) {
}
else if (type == ROWTYPE_DETAIL_SETTINGS) {
if (view == null) {
view = new TextDetailSettingsCell(mContext);
view.setBackgroundColor(0xffffffff);
}
TextDetailSettingsCell textCell = (TextDetailSettingsCell) view;
if (i == accountSettingsRow) {
@@ -498,7 +308,8 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
}
textCell.setTextAndValue(LocaleController.getString("AccountSettings", R.string.AccountSettings), subtitle, false);
} else if (i == usernameRow) {
}
else if (i == usernameRow) {
String subtitle = MrMailbox.getConfig("displayname", "");
if( subtitle.isEmpty()) {
subtitle = LocaleController.getString("NotSet", R.string.NotSet);
@@ -511,15 +322,16 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
@Override
public int getItemViewType(int i) {
if (i == settingsSectionRow || i == supportSectionRow || i == messagesSectionRow ) {
if (i == accountShadowRow || i == settingsShadowRow || i == aboutShadowRow ) {
return ROWTYPE_SHADOW;
} else if (i == enableAnimationsRow || i == sendByEnterRow || i == raiseToSpeakRow || i == directShareRow) {
return ROWTYPE_CHECK;
} else if ( i == accountSettingsRow || i == usernameRow) {
}
else if ( i == accountSettingsRow || i == usernameRow) {
return ROWTYPE_DETAIL_SETTINGS;
} else if (i == settingsSectionRow2 || i == messagesSectionRow2 || i == supportSectionRow2 || i == numberSectionRow ) {
}
else if (i == settingsHeaderRow || i == aboutHeaderRow || i == accountHeaderRow) {
return ROWTYPE_HEADER;
} else {
}
else {
return ROWTYPE_TEXT_SETTINGS;
}
}
@@ -0,0 +1,311 @@
/*******************************************************************************
*
* Messenger Android Frontend
* (C) 2017 Björn Petersen
* Contact: r10s@b44t.com, http://b44t.com
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/ .
*
******************************************************************************/
package com.b44t.ui;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Build;
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 com.b44t.messenger.AndroidUtilities;
import com.b44t.messenger.MediaController;
import com.b44t.messenger.ApplicationLoader;
import com.b44t.messenger.LocaleController;
import com.b44t.messenger.MessagesController;
import com.b44t.messenger.R;
import com.b44t.ui.Adapters.BaseFragmentAdapter;
import com.b44t.ui.Cells.ShadowSectionCell;
import com.b44t.ui.Cells.TextCheckCell;
import com.b44t.ui.Cells.TextSettingsCell;
import com.b44t.ui.ActionBar.ActionBar;
import com.b44t.ui.ActionBar.BaseFragment;
import com.b44t.ui.Components.LayoutHelper;
import com.b44t.ui.Components.NumberPicker;
import com.b44t.ui.ActionBar.Theme;
public class SettingsAdvActivity extends BaseFragment {
// the list
private int enableAnimationsRow, languageRow, directShareRow, textSizeRow, cacheRow, raiseToSpeakRow, sendByEnterRow, finalShadowRow;
private int rowCount;
private static final int ROWTYPE_SHADOW = 0;
private static final int ROWTYPE_TEXT_SETTINGS = 1;
private static final int ROWTYPE_CHECK = 2;
private static final int ROWTYPE_COUNT = 3;
private ListView listView;
public static int defMsgFontSize() {
return AndroidUtilities.isTablet() ? 18 : 16;
}
@Override
public boolean onFragmentCreate() {
super.onFragmentCreate();
rowCount = 0;
if (Build.VERSION.SDK_INT >= 23) {
directShareRow = -1; // for now, seems not really to work, however, in T'gram it does
}
else {
directShareRow = -1;
}
textSizeRow = rowCount++;
sendByEnterRow = rowCount++;
raiseToSpeakRow = rowCount++; // outgoing message
enableAnimationsRow = -1;//rowCount++; -- for now, we disable this option, maybe we can add it later to a "view" settings, however, in general, this should be more a system-option
cacheRow = -1; // for now, the page is still reachable by the "storage settings" in the "android App Settings"
languageRow = rowCount++;
finalShadowRow = rowCount++;
return true;
}
@Override
public View createView(Context context)
{
// create action bar
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(ApplicationLoader.applicationContext.getString(R.string.AdvancedSettings));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
// create object to hold the whole view
fragmentView = new FrameLayout(context) {};
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(0xfff0f0f0);
// create the main layout list
ListAdapter listAdapter = new ListAdapter(context);
listView = new ListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
AndroidUtilities.setListViewEdgeEffectColor(listView, Theme.ACTION_BAR_COLOR);
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 (i == textSizeRow) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("TextSize", R.string.TextSize));
final NumberPicker numberPicker = new NumberPicker(getParentActivity());
final int MIN_VAL = 12;
final int MAX_VAL = 30;
final int DEF_VAL = defMsgFontSize();
String displayValues[] = new String[MAX_VAL-MIN_VAL+1];
for( int v = MIN_VAL; v <= MAX_VAL; v++ ) {
String cur = String.format("%d", v);
if( v==DEF_VAL ) {
cur += " (" +LocaleController.getString("Default", R.string.Default)+ ")";
}
displayValues[v-MIN_VAL] = cur;
}
numberPicker.setMinValue(MIN_VAL);
numberPicker.setMaxValue(MAX_VAL);
numberPicker.setDisplayedValues(displayValues);
numberPicker.setWrapSelectorWheel(false);
numberPicker.setValue(MessagesController.getInstance().fontSize);
builder.setView(numberPicker);
builder.setNegativeButton(LocaleController.getString("Done", R.string.Done), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("msg_font_size", numberPicker.getValue());
MessagesController.getInstance().fontSize = numberPicker.getValue();
editor.apply();
if (listView != null) {
listView.invalidateViews();
}
}
});
showDialog(builder.create());
} else if (i == enableAnimationsRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations2", true);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("view_animations2", !animations);
editor.apply();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(!animations);
}
} else if (i == sendByEnterRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean send = preferences.getBoolean("send_by_enter", false);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("send_by_enter", !send);
editor.apply();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(!send);
}
} else if (i == raiseToSpeakRow) {
MediaController.getInstance().toogleRaiseToSpeak();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(MediaController.getInstance().canRaiseToSpeak());
}
} else if(i == directShareRow) {
MediaController.getInstance().toggleDirectShare();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(MediaController.getInstance().canDirectShare());
}
} else if (i == languageRow) {
presentFragment(new LanguageSelectActivity());
} else if (i == cacheRow) {
presentFragment(new CacheControlActivity());
}
}
});
return fragmentView;
}
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 == textSizeRow || i == enableAnimationsRow ||
i == sendByEnterRow ||
i == languageRow ||
i == cacheRow || i == raiseToSpeakRow || i == directShareRow ;
}
@Override
public int getCount() {
return 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 == ROWTYPE_SHADOW) {
if (view == null) {
view = new ShadowSectionCell(mContext);
}
view.setBackgroundResource(i == finalShadowRow? R.drawable.greydivider_bottom : R.drawable.greydivider);
} else if (type == ROWTYPE_TEXT_SETTINGS) {
if (view == null) {
view = new TextSettingsCell(mContext);
view.setBackgroundColor(0xffffffff);
}
TextSettingsCell textCell = (TextSettingsCell) view;
if (i == textSizeRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
int size = preferences.getInt("msg_font_size", defMsgFontSize());
textCell.setTextAndValue(LocaleController.getString("TextSize", R.string.TextSize), String.format("%d", size), true);
} else if (i == languageRow) {
textCell.setTextAndValue(LocaleController.getString("Language", R.string.Language), LocaleController.getCurrentLanguageName(), false);
} else if (i == cacheRow) {
textCell.setText(LocaleController.getString("CacheSettings", R.string.CacheSettings), false);
}
} else if (type == ROWTYPE_CHECK) {
if (view == null) {
view = new TextCheckCell(mContext);
view.setBackgroundColor(0xffffffff);
}
TextCheckCell textCell = (TextCheckCell) view;
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
if (i == enableAnimationsRow) {
textCell.setTextAndCheck(LocaleController.getString("EnableAnimations", R.string.EnableAnimations), preferences.getBoolean("view_animations2", true), false);
} else if (i == sendByEnterRow) {
textCell.setTextAndCheck(LocaleController.getString("SendByEnter", R.string.SendByEnter), preferences.getBoolean("send_by_enter", false), true);
} else if (i == raiseToSpeakRow) {
textCell.setTextAndCheck(LocaleController.getString("RaiseToSpeak", R.string.RaiseToSpeak), MediaController.getInstance().canRaiseToSpeak(), true);
} else if (i == directShareRow) {
textCell.setTextAndValueAndCheck(LocaleController.getString("DirectShare", R.string.DirectShare), LocaleController.getString("DirectShareInfo", R.string.DirectShareInfo), MediaController.getInstance().canDirectShare(), false, true);
}
}
return view;
}
@Override
public int getItemViewType(int i) {
if (i == finalShadowRow ) {
return ROWTYPE_SHADOW;
} else if (i == enableAnimationsRow || i == sendByEnterRow || i == raiseToSpeakRow || i == directShareRow) {
return ROWTYPE_CHECK;
} else {
return ROWTYPE_TEXT_SETTINGS;
}
}
@Override
public int getViewTypeCount() {
return ROWTYPE_COUNT;
}
@Override
public boolean isEmpty() {
return false;
}
}
}
@@ -24,9 +24,7 @@
package com.b44t.ui;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.SurfaceTexture;
import android.media.MediaCodecInfo;
@@ -38,8 +36,6 @@ import android.view.Surface;
import android.view.TextureView;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
@@ -64,7 +60,6 @@ import com.b44t.messenger.R;
import com.b44t.ui.ActionBar.ActionBar;
import com.b44t.ui.ActionBar.ActionBarMenu;
import com.b44t.ui.ActionBar.BaseFragment;
import com.b44t.ui.ActionBar.Theme;
import com.b44t.ui.Components.LayoutHelper;
import com.b44t.ui.Components.VideoSeekBarView;
import com.b44t.ui.Components.VideoTimelineView;
@@ -79,14 +74,14 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
private MediaPlayer videoPlayer = null;
private VideoTimelineView videoTimelineView = null;
private View videoContainerView = null;
private TextView originalSizeTextView = null;
private TextView editedSizeTextView = null;
private View textContainerView = null;
//private TextView originalSizeTextView = null;
//private TextView editedSizeTextView = null;
//private View textContainerView = null;
private ImageView playButton = null;
private VideoSeekBarView videoSeekBarView = null;
private TextureView textureView = null;
private View controlView = null;
private CheckBox compressVideo = null;
//private CheckBox compressVideo = null;
private boolean playerPrepared = false;
private String videoPath = null;
@@ -241,10 +236,8 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
@Override
public View createView(Context context) {
actionBar.setBackgroundColor(Theme.ACTION_BAR_MEDIA_PICKER_COLOR);
actionBar.setItemsBackgroundColor(Theme.ACTION_BAR_PICKER_SELECTOR_COLOR);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setTitle(LocaleController.getString("EditVideo", R.string.EditVideo));
actionBar.setBackButtonImage(R.drawable.ic_close_white);
actionBar.setTitle(ApplicationLoader.applicationContext.getString(R.string.SendVideo));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
@@ -263,9 +256,9 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
}
}
if (delegate != null) {
if (compressVideo.getVisibility() == View.GONE || compressVideo.getVisibility() == View.VISIBLE && !compressVideo.isChecked()) {
/*if (compressVideo.getVisibility() == View.GONE || compressVideo.getVisibility() == View.VISIBLE && !compressVideo.isChecked()) {
delegate.didFinishEditVideo(videoPath, startTime, endTime, originalWidth, originalHeight, rotationValue, originalWidth, originalHeight, originalBitrate, estimatedSize, esimatedDuration);
} else {
} else*/ {
delegate.didFinishEditVideo(videoPath, startTime, endTime, resultWidth, resultHeight, rotationValue, originalWidth, originalHeight, bitrate, estimatedSize, esimatedDuration);
}
}
@@ -278,12 +271,12 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
menu.addItemWithWidth(1, R.drawable.ic_done, AndroidUtilities.dp(56));
fragmentView = getParentActivity().getLayoutInflater().inflate(R.layout.video_editor_layout, null, false);
originalSizeTextView = (TextView) fragmentView.findViewById(R.id.original_size);
editedSizeTextView = (TextView) fragmentView.findViewById(R.id.edited_size);
//originalSizeTextView = (TextView) fragmentView.findViewById(R.id.original_size);
//editedSizeTextView = (TextView) fragmentView.findViewById(R.id.edited_size);
videoContainerView = fragmentView.findViewById(R.id.video_container);
textContainerView = fragmentView.findViewById(R.id.info_container);
//textContainerView = fragmentView.findViewById(R.id.info_container);
controlView = fragmentView.findViewById(R.id.control_layout);
compressVideo = (CheckBox) fragmentView.findViewById(R.id.compress_video);
/*compressVideo = (CheckBox) fragmentView.findViewById(R.id.compress_video);
compressVideo.setText(LocaleController.getString("CompressVideo", R.string.CompressVideo));
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
compressVideo.setVisibility(originalHeight != resultHeight || originalWidth != resultWidth ? View.VISIBLE : View.GONE);
@@ -297,13 +290,13 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
editor.apply();
updateVideoEditedInfo();
}
});
});*/
if (Build.VERSION.SDK_INT < 18) {
try {
MediaCodecInfo codecInfo = MediaController.selectCodec(MediaController.MIME_TYPE);
if (codecInfo == null) {
compressVideo.setVisibility(View.GONE);
//compressVideo.setVisibility(View.GONE);
} else {
String name = codecInfo.getName();
if (name.equals("OMX.google.h264.encoder") ||
@@ -313,23 +306,23 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
name.equals("OMX.MARVELL.VIDEO.H264ENCODER") ||
name.equals("OMX.k3.video.encoder.avc") || //fix this later
name.equals("OMX.TI.DUCATI1.VIDEO.H264E")) { //fix this later
compressVideo.setVisibility(View.GONE);
//compressVideo.setVisibility(View.GONE);
} else {
if (MediaController.selectColorFormat(codecInfo, MediaController.MIME_TYPE) == 0) {
compressVideo.setVisibility(View.GONE);
//compressVideo.setVisibility(View.GONE);
}
}
}
} catch (Exception e) {
compressVideo.setVisibility(View.GONE);
//compressVideo.setVisibility(View.GONE);
FileLog.e("messenger", e);
}
}
TextView titleTextView = (TextView) fragmentView.findViewById(R.id.original_title);
/*TextView titleTextView = (TextView) fragmentView.findViewById(R.id.original_title);
titleTextView.setText(LocaleController.getString("OriginalVideo", R.string.OriginalVideo));
titleTextView = (TextView) fragmentView.findViewById(R.id.edited_title);
titleTextView.setText(LocaleController.getString("EditedVideo", R.string.EditedVideo));
titleTextView.setText(LocaleController.getString("EditedVideo", R.string.EditedVideo));*/
videoTimelineView = (VideoTimelineView) fragmentView.findViewById(R.id.video_timeline_view);
videoTimelineView.setVideoPath(videoPath);
@@ -414,7 +407,7 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
textureView = (TextureView) fragmentView.findViewById(R.id.video_view);
textureView.setSurfaceTextureListener(this);
updateVideoOriginalInfo();
//updateVideoOriginalInfo();
updateVideoEditedInfo();
return fragmentView;
@@ -496,7 +489,7 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
}
}
private void updateVideoOriginalInfo() {
/*private void updateVideoOriginalInfo() {
if (originalSizeTextView == null) {
return;
}
@@ -508,24 +501,24 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
int seconds = (int) Math.ceil(duration / 1000) - minutes * 60;
String videoTimeSize = String.format("%d:%02d, %s", minutes, seconds, AndroidUtilities.formatFileSize(originalSize));
originalSizeTextView.setText(String.format("%s, %s", videoDimension, videoTimeSize));
}
}*/
private void updateVideoEditedInfo() {
if (editedSizeTextView == null) {
if (videoTimelineView == null) {
return;
}
esimatedDuration = (long) Math.ceil((videoTimelineView.getRightProgress() - videoTimelineView.getLeftProgress()) * videoDuration);
int width;
/*int width;
int height;
if (compressVideo.getVisibility() == View.GONE || compressVideo.getVisibility() == View.VISIBLE && !compressVideo.isChecked()) {
width = rotationValue == 90 || rotationValue == 270 ? originalHeight : originalWidth;
height = rotationValue == 90 || rotationValue == 270 ? originalWidth : originalHeight;
estimatedSize = (int) (originalSize * ((float) esimatedDuration / videoDuration));
} else {
width = rotationValue == 90 || rotationValue == 270 ? resultHeight : resultWidth;
height = rotationValue == 90 || rotationValue == 270 ? resultWidth : resultHeight;
} else*/ {
//width = rotationValue == 90 || rotationValue == 270 ? resultHeight : resultWidth;
//height = rotationValue == 90 || rotationValue == 270 ? resultWidth : resultHeight;
estimatedSize = calculateEstimatedSize((float) esimatedDuration / videoDuration);
}
@@ -540,11 +533,11 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
endTime = (long) (videoTimelineView.getRightProgress() * videoDuration) * 1000;
}
String videoDimension = String.format("%dx%d", width, height);
//String videoDimension = String.format("%dx%d", width, height);
int minutes = (int) (esimatedDuration / 1000 / 60);
int seconds = (int) Math.ceil(esimatedDuration / 1000) - minutes * 60;
String videoTimeSize = String.format("%d:%02d, ~%s", minutes, seconds, AndroidUtilities.formatFileSize(estimatedSize));
editedSizeTextView.setText(String.format("%s, %s", videoDimension, videoTimeSize));
actionBar.setSubtitle(videoTimeSize);
}
private void fixVideoSize() {
@@ -562,14 +555,14 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
int height;
if (AndroidUtilities.isTablet()) {
width = AndroidUtilities.dp(490);
height = viewHeight - AndroidUtilities.dp(276 + (compressVideo.getVisibility() == View.VISIBLE ? 20 : 0));
height = viewHeight - AndroidUtilities.dp(276 + (/*compressVideo.getVisibility() == View.VISIBLE ? 20 :*/ 0));
} else {
if (getParentActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
width = AndroidUtilities.displaySize.x / 3 - AndroidUtilities.dp(24);
height = viewHeight - AndroidUtilities.dp(32);
} else {
width = AndroidUtilities.displaySize.x;
height = viewHeight - AndroidUtilities.dp(276 + (compressVideo.getVisibility() == View.VISIBLE ? 20 : 0));
height = viewHeight - AndroidUtilities.dp(276 + (/*compressVideo.getVisibility() == View.VISIBLE ? 20 :*/ 0));
}
}
@@ -602,11 +595,11 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
return;
}
if (!AndroidUtilities.isTablet() && getParentActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
// landscape orientation
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) videoContainerView.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(16);
layoutParams.bottomMargin = AndroidUtilities.dp(16);
layoutParams.width = AndroidUtilities.displaySize.x / 3 - AndroidUtilities.dp(24);
layoutParams.leftMargin = AndroidUtilities.dp(16);
videoContainerView.setLayoutParams(layoutParams);
layoutParams = (FrameLayout.LayoutParams) controlView.getLayoutParams();
@@ -617,34 +610,20 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
layoutParams.gravity = Gravity.TOP;
controlView.setLayoutParams(layoutParams);
layoutParams = (FrameLayout.LayoutParams) textContainerView.getLayoutParams();
layoutParams.width = AndroidUtilities.displaySize.x / 3 * 2 - AndroidUtilities.dp(32);
layoutParams.leftMargin = AndroidUtilities.displaySize.x / 3 + AndroidUtilities.dp(16);
layoutParams.rightMargin = AndroidUtilities.dp(16);
layoutParams.bottomMargin = AndroidUtilities.dp(16);
textContainerView.setLayoutParams(layoutParams);
} else {
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) videoContainerView.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(16);
layoutParams.bottomMargin = AndroidUtilities.dp(260 + (compressVideo.getVisibility() == View.VISIBLE ? 20 : 0));
layoutParams.bottomMargin = AndroidUtilities.dp(260 + (/*compressVideo.getVisibility() == View.VISIBLE ? 20 :*/ 0));
layoutParams.width = LayoutHelper.MATCH_PARENT;
layoutParams.leftMargin = 0;
videoContainerView.setLayoutParams(layoutParams);
layoutParams = (FrameLayout.LayoutParams) controlView.getLayoutParams();
layoutParams.topMargin = 0;
layoutParams.leftMargin = 0;
layoutParams.bottomMargin = AndroidUtilities.dp(150 + (compressVideo.getVisibility() == View.VISIBLE ? 20 : 0));
layoutParams.bottomMargin = AndroidUtilities.dp(150 + (/*compressVideo.getVisibility() == View.VISIBLE ? 20 :*/ 0));
layoutParams.width = LayoutHelper.MATCH_PARENT;
layoutParams.gravity = Gravity.BOTTOM;
controlView.setLayoutParams(layoutParams);
layoutParams = (FrameLayout.LayoutParams) textContainerView.getLayoutParams();
layoutParams.width = LayoutHelper.MATCH_PARENT;
layoutParams.leftMargin = AndroidUtilities.dp(16);
layoutParams.rightMargin = AndroidUtilities.dp(16);
layoutParams.bottomMargin = AndroidUtilities.dp(16);
textContainerView.setLayoutParams(layoutParams);
}
fixVideoSize();
videoTimelineView.clearFrames();
@@ -803,7 +782,7 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
videoDuration *= 1000;
updateVideoOriginalInfo();
//updateVideoOriginalInfo();
updateVideoEditedInfo();
return true;
@@ -129,7 +129,7 @@ public class WallpapersActivity extends BaseFragment implements NotificationCent
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setBackButtonImage(R.drawable.ic_close_white);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("ChatBackground", R.string.ChatBackground));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@@ -230,11 +230,11 @@ public class WallpapersActivity extends BaseFragment implements NotificationCent
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
currentPicturePath = image.getAbsolutePath();
}
startActivityForResult(takePictureIntent, 10);
startActivityForResult(takePictureIntent, RC10_WALLPAPER_IMAGE_CAPTURE);
} else if (i == 1) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 11);
startActivityForResult(photoPickerIntent, RC11_WALLPAPER_PICK);
}
} catch (Exception e) {
FileLog.e("messenger", e);
@@ -262,7 +262,7 @@ public class WallpapersActivity extends BaseFragment implements NotificationCent
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
if (requestCode == 10) {
if (requestCode == RC10_WALLPAPER_IMAGE_CAPTURE) {
AndroidUtilities.addMediaToGallery(currentPicturePath);
FileOutputStream stream = null;
try {
@@ -287,7 +287,7 @@ public class WallpapersActivity extends BaseFragment implements NotificationCent
}
}
currentPicturePath = null;
} else if (requestCode == 11) {
} else if (requestCode == RC11_WALLPAPER_PICK) {
if (data == null || data.getData() == null) {
return;
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 954 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 989 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Some files were not shown because too many files have changed in this diff Show More