Skip to content

Commit 55ccb7c

Browse files
author
DrKLO
committed
New photo picker in chats
1 parent db64b2f commit 55ccb7c

File tree

93 files changed

+1349
-144
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1349
-144
lines changed

TMessagesProj/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ android {
8181
defaultConfig {
8282
minSdkVersion 8
8383
targetSdkVersion 19
84-
versionCode 244
85-
versionName "1.4.15"
84+
versionCode 245
85+
versionName "1.5.0"
8686
}
8787
}

TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,56 @@ public AudioBuffer(int capacity) {
7979
long pcmOffset;
8080
}
8181

82+
private static final String[] projectionPhotos = {
83+
MediaStore.Images.Media._ID,
84+
MediaStore.Images.Media.BUCKET_ID,
85+
MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
86+
MediaStore.Images.Media.DATA,
87+
MediaStore.Images.Media.DATE_TAKEN,
88+
MediaStore.Images.Media.ORIENTATION
89+
};
90+
91+
public static class AlbumEntry {
92+
public int bucketId;
93+
public String bucketName;
94+
public PhotoEntry coverPhoto;
95+
public ArrayList<PhotoEntry> photos = new ArrayList<PhotoEntry>();
96+
97+
public AlbumEntry(int bucketId, String bucketName, PhotoEntry coverPhoto) {
98+
this.bucketId = bucketId;
99+
this.bucketName = bucketName;
100+
this.coverPhoto = coverPhoto;
101+
}
102+
103+
public void addPhoto(PhotoEntry photoEntry) {
104+
photos.add(photoEntry);
105+
}
106+
}
107+
108+
public static class PhotoEntry {
109+
public int bucketId;
110+
public int imageId;
111+
public long dateTaken;
112+
public String path;
113+
public int orientation;
114+
115+
public PhotoEntry(int bucketId, int imageId, long dateTaken, String path, int orientation) {
116+
this.bucketId = bucketId;
117+
this.imageId = imageId;
118+
this.dateTaken = dateTaken;
119+
this.path = path;
120+
this.orientation = orientation;
121+
}
122+
}
123+
82124
public final static int audioProgressDidChanged = 50001;
83125
public final static int audioDidReset = 50002;
84126
public final static int recordProgressChanged = 50003;
85127
public final static int recordStarted = 50004;
86128
public final static int recordStartError = 50005;
87129
public final static int recordStopped = 50006;
88130
public final static int screenshotTook = 50007;
131+
public final static int albumsDidLoaded = 50008;
89132

90133
private HashMap<String, ArrayList<WeakReference<FileDownloadProgressListener>>> loadingFileObservers = new HashMap<String, ArrayList<WeakReference<FileDownloadProgressListener>>>();
91134
private HashMap<Integer, String> observersByTag = new HashMap<Integer, String>();
@@ -412,7 +455,7 @@ public void startMediaObserver() {
412455
}
413456

414457
public void stopMediaObserver() {
415-
if (android.os.Build.VERSION.SDK_INT < 10) { //disable while it's not perferct
458+
if (android.os.Build.VERSION.SDK_INT > 0) { //disable while it's not perferct
416459
return;
417460
}
418461
if (stopMediaObserverRunnable == null) {
@@ -1533,4 +1576,80 @@ public static String copyDocumentToCache(Uri uri) {
15331576
}
15341577
return null;
15351578
}
1579+
1580+
public static void loadGalleryPhotosAlbums(final int guid) {
1581+
Utilities.globalQueue.postRunnable(new Runnable() {
1582+
@Override
1583+
public void run() {
1584+
final ArrayList<AlbumEntry> albumsSorted = new ArrayList<AlbumEntry>();
1585+
HashMap<Integer, AlbumEntry> albums = new HashMap<Integer, AlbumEntry>();
1586+
AlbumEntry allPhotosAlbum = null;
1587+
String cameraFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath() + "/" + "Camera/";
1588+
Integer cameraAlbumId = null;
1589+
1590+
Cursor cursor = null;
1591+
try {
1592+
cursor = MediaStore.Images.Media.query(ApplicationLoader.applicationContext.getContentResolver(), MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projectionPhotos, "", null, MediaStore.Images.Media.DATE_TAKEN + " DESC");
1593+
if (cursor != null) {
1594+
int imageIdColumn = cursor.getColumnIndex(MediaStore.Images.Media._ID);
1595+
int bucketIdColumn = cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_ID);
1596+
int bucketNameColumn = cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
1597+
int dataColumn = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
1598+
int dateColumn = cursor.getColumnIndex(MediaStore.Images.Media.DATE_TAKEN);
1599+
int orientationColumn = cursor.getColumnIndex(MediaStore.Images.Media.ORIENTATION);
1600+
1601+
while (cursor.moveToNext()) {
1602+
int imageId = cursor.getInt(imageIdColumn);
1603+
int bucketId = cursor.getInt(bucketIdColumn);
1604+
String bucketName = cursor.getString(bucketNameColumn);
1605+
String path = cursor.getString(dataColumn);
1606+
long dateTaken = cursor.getLong(dateColumn);
1607+
int orientation = cursor.getInt(orientationColumn);
1608+
1609+
PhotoEntry photoEntry = new PhotoEntry(bucketId, imageId, dateTaken, path, orientation);
1610+
1611+
if (allPhotosAlbum == null) {
1612+
allPhotosAlbum = new AlbumEntry(0, LocaleController.getString("AllPhotos", R.string.AllPhotos), photoEntry);
1613+
albumsSorted.add(0, allPhotosAlbum);
1614+
}
1615+
if (allPhotosAlbum != null) {
1616+
allPhotosAlbum.addPhoto(photoEntry);
1617+
}
1618+
1619+
AlbumEntry albumEntry = albums.get(bucketId);
1620+
if (albumEntry == null) {
1621+
albumEntry = new AlbumEntry(bucketId, bucketName, photoEntry);
1622+
albums.put(bucketId, albumEntry);
1623+
if (cameraAlbumId == null && cameraFolder != null && path != null && path.startsWith(cameraFolder)) {
1624+
albumsSorted.add(0, albumEntry);
1625+
cameraAlbumId = bucketId;
1626+
} else {
1627+
albumsSorted.add(albumEntry);
1628+
}
1629+
}
1630+
1631+
albumEntry.addPhoto(photoEntry);
1632+
}
1633+
}
1634+
} catch (Exception e) {
1635+
FileLog.e("tmessages", e);
1636+
} finally {
1637+
if (cursor != null) {
1638+
try {
1639+
cursor.close();
1640+
} catch (Exception e) {
1641+
FileLog.e("tmessages", e);
1642+
}
1643+
}
1644+
}
1645+
final Integer cameraAlbumIdFinal = cameraAlbumId;
1646+
Utilities.RunOnUIThread(new Runnable() {
1647+
@Override
1648+
public void run() {
1649+
NotificationCenter.getInstance().postNotificationName(albumsDidLoaded, guid, albumsSorted, cameraAlbumIdFinal);
1650+
}
1651+
});
1652+
}
1653+
});
1654+
}
15361655
}

TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4516,9 +4516,9 @@ private void showInAppNotification(MessageObject messageObject) {
45164516

45174517
if (choosenSoundPath != null && !choosenSoundPath.equals("NoSound")) {
45184518
if (choosenSoundPath.equals(defaultPath)) {
4519-
mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
4519+
mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI, AudioManager.STREAM_NOTIFICATION);
45204520
} else {
4521-
mBuilder.setSound(Uri.parse(choosenSoundPath));
4521+
mBuilder.setSound(Uri.parse(choosenSoundPath), AudioManager.STREAM_NOTIFICATION);
45224522
}
45234523
}
45244524

TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ public void setMessageObject(MessageObject messageObject) {
387387
w = (int) (currentPhotoObject.photoOwner.w / hScale);
388388
}
389389
}
390+
int timeWidthTotal = timeWidth + Utilities.dp(14 + (currentMessageObject.isOut() ? 20 : 0));
391+
if (w < timeWidthTotal) {
392+
w = timeWidthTotal;
393+
}
390394

391395
photoWidth = w;
392396
photoHeight = h;

TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@
101101
import java.util.HashMap;
102102
import java.util.concurrent.Semaphore;
103103

104-
public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLayout.SizeNotifierRelativeLayoutDelegate, NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate, DocumentSelectActivity.DocumentSelectActivityDelegate, PhotoViewer.PhotoViewerProvider {
104+
public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLayout.SizeNotifierRelativeLayoutDelegate,
105+
NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate,
106+
DocumentSelectActivity.DocumentSelectActivityDelegate, PhotoViewer.PhotoViewerProvider,
107+
PhotoPickerActivity.PhotoPickerActivityDelegate {
105108

106109
private View timeItem;
107110
private View menuItem;
@@ -414,7 +417,7 @@ public void onFragmentDestroy() {
414417

415418
public View createView(LayoutInflater inflater, ViewGroup container) {
416419
if (fragmentView == null) {
417-
actionBarLayer.setDisplayHomeAsUpEnabled(true);
420+
actionBarLayer.setDisplayHomeAsUpEnabled(true, R.drawable.ic_ab_back);
418421
actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() {
419422
@Override
420423
public void onItemClick(int id) {
@@ -438,13 +441,9 @@ public void onItemClick(int id) {
438441
FileLog.e("tmessages", e);
439442
}
440443
} else if (id == attach_gallery) {
441-
try {
442-
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
443-
photoPickerIntent.setType("image/*");
444-
getParentActivity().startActivityForResult(photoPickerIntent, 1);
445-
} catch (Exception e) {
446-
FileLog.e("tmessages", e);
447-
}
444+
PhotoPickerActivity fragment = new PhotoPickerActivity();
445+
fragment.setDelegate(ChatActivity.this);
446+
presentFragment(fragment);
448447
} else if (id == attach_video) {
449448
try {
450449
Intent pickIntent = new Intent();
@@ -1987,7 +1986,7 @@ public void run() {
19871986
View firstVisView = chatListView.getChildAt(chatListView.getChildCount() - 1);
19881987
int top = ((firstVisView == null) ? 0 : firstVisView.getTop()) - chatListView.getPaddingTop();
19891988
chatAdapter.notifyDataSetChanged();
1990-
chatListView.setSelectionFromTop(firstVisPos + newRowsCount, top);
1989+
chatListView.setSelectionFromTop(firstVisPos + newRowsCount - (endReached ? 1 : 0), top);
19911990
}
19921991

19931992
if (paused) {
@@ -2676,6 +2675,24 @@ public void run() {
26762675
}
26772676
}
26782677

2678+
@Override
2679+
public void didSelectPhotos(ArrayList<String> photos) {
2680+
for (String path : photos) {
2681+
processSendingPhoto(path, null);
2682+
}
2683+
}
2684+
2685+
@Override
2686+
public void startPhotoSelectActivity() {
2687+
try {
2688+
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
2689+
photoPickerIntent.setType("image/*");
2690+
getParentActivity().startActivityForResult(photoPickerIntent, 1);
2691+
} catch (Exception e) {
2692+
FileLog.e("tmessages", e);
2693+
}
2694+
}
2695+
26792696
@Override
26802697
public void onBeginSlide() {
26812698
super.onBeginSlide();
@@ -3327,7 +3344,7 @@ private void alertUserOpenError(MessageObject message) {
33273344
}
33283345

33293346
@Override
3330-
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation) {
3347+
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
33313348
if (messageObject == null) {
33323349
return null;
33333350
}
@@ -3372,9 +3389,25 @@ public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObj
33723389
}
33733390

33743391
@Override
3375-
public void willHidePhotoViewer() {
3376-
updateVisibleRows();
3377-
}
3392+
public void willSwitchFromPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) { }
3393+
3394+
@Override
3395+
public void willHidePhotoViewer() { }
3396+
3397+
@Override
3398+
public boolean isPhotoChecked(int index) { return false; }
3399+
3400+
@Override
3401+
public void setPhotoChecked(int index) { }
3402+
3403+
@Override
3404+
public void cancelButtonPressed() { }
3405+
3406+
@Override
3407+
public void sendButtonPressed(int index) { }
3408+
3409+
@Override
3410+
public int getSelectedCount() { return 0; }
33783411

33793412
private class ChatAdapter extends BaseAdapter {
33803413

TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public void onFragmentDestroy() {
144144

145145
public View createView(LayoutInflater inflater, ViewGroup container) {
146146
if (fragmentView == null) {
147-
actionBarLayer.setDisplayHomeAsUpEnabled(true);
147+
actionBarLayer.setDisplayHomeAsUpEnabled(true, R.drawable.ic_ab_back);
148148
actionBarLayer.setTitle(LocaleController.getString("GroupInfo", R.string.GroupInfo));
149149
actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() {
150150
@Override
@@ -337,7 +337,7 @@ public void restoreSelfArgs(Bundle args) {
337337
}
338338

339339
@Override
340-
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation) {
340+
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
341341
if (fileLocation == null) {
342342
return null;
343343
}
@@ -368,9 +368,25 @@ public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObj
368368
}
369369

370370
@Override
371-
public void willHidePhotoViewer() {
371+
public void willSwitchFromPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) { }
372372

373-
}
373+
@Override
374+
public void willHidePhotoViewer() { }
375+
376+
@Override
377+
public boolean isPhotoChecked(int index) { return false; }
378+
379+
@Override
380+
public void setPhotoChecked(int index) { }
381+
382+
@Override
383+
public void cancelButtonPressed() { }
384+
385+
@Override
386+
public void sendButtonPressed(int index) { }
387+
388+
@Override
389+
public int getSelectedCount() { return 0; }
374390

375391
public void didReceivedNotification(int id, Object... args) {
376392
if (id == MessagesController.updateInterfaces) {

TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public void onFragmentDestroy() {
115115
@Override
116116
public View createView(LayoutInflater inflater, ViewGroup container) {
117117
if (fragmentView == null) {
118-
actionBarLayer.setDisplayHomeAsUpEnabled(true);
118+
actionBarLayer.setDisplayHomeAsUpEnabled(true, R.drawable.ic_ab_back);
119119
if (destroyAfterSelect) {
120120
actionBarLayer.setTitle(LocaleController.getString("SelectContact", R.string.SelectContact));
121121
} else {

TMessagesProj/src/main/java/org/telegram/ui/CountrySelectActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void onFragmentDestroy() {
118118
@Override
119119
public View createView(LayoutInflater inflater, ViewGroup container) {
120120
if (fragmentView == null) {
121-
actionBarLayer.setDisplayHomeAsUpEnabled(true);
121+
actionBarLayer.setDisplayHomeAsUpEnabled(true, R.drawable.ic_ab_back);
122122
actionBarLayer.setTitle(LocaleController.getString("ChooseCountry", R.string.ChooseCountry));
123123

124124
actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() {

TMessagesProj/src/main/java/org/telegram/ui/DocumentSelectActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public View createView(LayoutInflater inflater, ViewGroup container) {
126126
}
127127

128128
if (fragmentView == null) {
129-
actionBarLayer.setDisplayHomeAsUpEnabled(true);
129+
actionBarLayer.setDisplayHomeAsUpEnabled(true, R.drawable.ic_ab_back);
130130
actionBarLayer.setTitle(LocaleController.getString("SelectFile", R.string.SelectFile));
131131
actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() {
132132
@Override

TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void onFragmentDestroy() {
123123
@Override
124124
public View createView(LayoutInflater inflater, ViewGroup container) {
125125
if (fragmentView == null) {
126-
actionBarLayer.setDisplayHomeAsUpEnabled(true);
126+
actionBarLayer.setDisplayHomeAsUpEnabled(true, R.drawable.ic_ab_back);
127127
actionBarLayer.setTitle(LocaleController.getString("NewGroup", R.string.NewGroup));
128128
actionBarLayer.setSubtitle(String.format("%d/200 %s", selectedContacts.size(), LocaleController.getString("Members", R.string.Members)));
129129

0 commit comments

Comments
 (0)