Skip to content

Commit

Permalink
feat: Update to 1672
Browse files Browse the repository at this point in the history
  • Loading branch information
jplie committed Dec 30, 2023
2 parents 96d34b5 + 4c1efa8 commit 56984e3
Show file tree
Hide file tree
Showing 118 changed files with 3,680 additions and 1,132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* File created on 22/10/2022
*/
package org.thunderdog.challegram;
package org.thunderdog.challegram.location;

import android.location.Location;

Expand All @@ -26,6 +26,8 @@
import com.google.android.gms.location.LocationSettingsResult;
import com.google.android.gms.location.LocationSettingsStatusCodes;

import org.thunderdog.challegram.BaseActivity;
import org.thunderdog.challegram.Log;
import org.thunderdog.challegram.tool.Intents;
import org.thunderdog.challegram.tool.UI;
import org.thunderdog.challegram.unsorted.LocationRetriever;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
*
* File created on 22/10/2022
*/
package org.thunderdog.challegram;
package org.thunderdog.challegram.location;

import org.thunderdog.challegram.BaseActivity;
import org.thunderdog.challegram.unsorted.LocationRetriever;

public class LocationRetrieverFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,29 @@
*
* File created on 22/10/2022
*/
package org.thunderdog.challegram;
package org.thunderdog.challegram.push;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.messaging.FirebaseMessaging;

import org.drinkless.tdlib.TdApi;
import org.thunderdog.challegram.Log;
import org.thunderdog.challegram.TDLib;
import org.thunderdog.challegram.tool.UI;
import org.thunderdog.challegram.util.TokenRetriever;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import me.vkryl.core.StringUtils;

public final class FirebaseTokenRetriever extends TokenRetriever {
final class FirebaseTokenRetriever extends TokenRetriever {
@Override
protected boolean performInitialization (Context context) {
try {
Expand All @@ -44,6 +51,19 @@ protected boolean performInitialization (Context context) {
return false;
}

@NonNull
@Override
public String getName () {
return "firebase";
}

@Override
@Nullable
public String getConfiguration () {
FirebaseOptions options = FirebaseOptions.fromResource(UI.getAppContext());
return options != null ? options.toString() : null;
}

private static String extractFirebaseErrorName (Throwable e) {
String message = e.getMessage();
if (!StringUtils.isEmpty(message)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
*
* File created on 22/10/2022
*/
package org.thunderdog.challegram;
package org.thunderdog.challegram.push;

import android.content.Context;

import org.thunderdog.challegram.util.TokenRetriever;

public class TokenRetrieverFactory {
public final class TokenRetrieverFactory {
public static TokenRetriever newRetriever (Context context) {
return new FirebaseTokenRetriever();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

import me.vkryl.td.JSON;

public class FirebaseListenerService extends FirebaseMessagingService {
public final class FirebaseListenerService extends FirebaseMessagingService {
@Override
public void onNewToken (@NonNull String newToken) {
UI.initApp(getApplicationContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import org.thunderdog.challegram.telegram.Tdlib;

public class MapControllerFactory {
public final class MapControllerFactory {
public static MapController<?,?> newMapController (Context context, Tdlib tdlib) {
return new MapGoogleController(context, tdlib);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
import me.vkryl.core.lambda.Destroyable;
import me.vkryl.td.MessageId;

public class MapGoogleController extends MapController<MapView, MapGoogleController.MarkerData> implements OnMapReadyCallback, GoogleMap.OnMyLocationChangeListener, GoogleMap.OnCameraMoveStartedListener, GoogleMap.OnMarkerClickListener {
final class MapGoogleController extends MapController<MapView, MapGoogleController.MarkerData> implements OnMapReadyCallback, GoogleMap.OnMyLocationChangeListener, GoogleMap.OnCameraMoveStartedListener, GoogleMap.OnMarkerClickListener {
private static final float DEFAULT_ZOOM_LEVEL = 16.0f;
private static final float CLICK_ZOOM_LEVEL = 17.0f;

Expand Down
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,10 @@

<meta-data
android:name="com.samsung.android.icon_container.has_icon_container"
android:value="@bool/com_samsung_android_icon_container_has_icon_container"/>
android:value="@bool/com_samsung_android_icon_container_has_icon_container" />

<meta-data
android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc"/>
</application>
</manifest>
16 changes: 9 additions & 7 deletions app/src/main/java/org/thunderdog/challegram/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1809,7 +1809,7 @@ public void hideContextualPopups (boolean byNavigation) {
PopupLayout window = windows.get(i);
View boundView = window.getBoundView();
ViewController<?> boundController = window.getBoundController();
if (isContextual(boundView) || (byNavigation && boundView instanceof StickerSetWrap) || (boundView instanceof MediaLayout && !(navigation.getCurrentStackItem() instanceof MessagesController)) || (byNavigation && isContextual(boundController)) ) {
if (isContextual(boundView) || (byNavigation && boundView instanceof StickerSetWrap) || (boundView instanceof MediaLayout && !((navigation.getCurrentStackItem() instanceof MessagesController) || (((MediaLayout) boundView).getMode() == MediaLayout.MODE_AVATAR_PICKER))) || (byNavigation && isContextual(boundController)) ) {
window.hideWindow(true);
}
}
Expand Down Expand Up @@ -3040,15 +3040,17 @@ public void checkCameraApi () {
}

private void initializeCamera (ViewController.CameraOpenOptions options) {
if (camera == null) {
final boolean needCreateCamera = camera == null;
if (needCreateCamera) {
camera = new CameraController(this);
camera.setMode(options.mode, options.readyListener);
camera.setQrListener(options.qrCodeListener, options.qrModeSubtitle, options.qrModeDebug);
}
camera.setMode(options.mode, options.readyListener);
camera.setAvatarPickerMode(options.avatarPickerMode);
camera.setQrListener(options.qrCodeListener, options.qrModeSubtitle, options.qrModeDebug);
camera.setMediaEditorDelegates(options.delegate, options.selectDelegate, options.sendDelegate);
if (needCreateCamera) {
camera.getValue(); // Ensure view creation
addActivityListener(camera);
} else {
camera.setMode(options.mode, options.readyListener);
camera.setQrListener(options.qrCodeListener, options.qrModeSubtitle, options.qrModeDebug);
}
hideContextualPopups(false);
closeAllMedia(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.thunderdog.challegram.data.TD;
import org.thunderdog.challegram.loader.ImageFile;
import org.thunderdog.challegram.loader.ImageGalleryFile;
import org.thunderdog.challegram.mediaview.AvatarPickerMode;
import org.thunderdog.challegram.mediaview.MediaSelectDelegate;
import org.thunderdog.challegram.mediaview.MediaSendDelegate;
import org.thunderdog.challegram.mediaview.MediaViewController;
Expand All @@ -56,6 +57,7 @@
import org.thunderdog.challegram.navigation.Menu;
import org.thunderdog.challegram.navigation.MenuMoreWrap;
import org.thunderdog.challegram.navigation.ToggleHeaderView;
import org.thunderdog.challegram.navigation.ViewController;
import org.thunderdog.challegram.telegram.Tdlib;
import org.thunderdog.challegram.theme.ColorId;
import org.thunderdog.challegram.tool.Intents;
Expand Down Expand Up @@ -102,7 +104,9 @@ protected int getMenuId () {
@Override
public void fillMenuItems (int id, HeaderView header, LinearLayout menu) {
if (id == R.id.menu_more) {
header.addSearchButton(menu, this);
if (mediaLayout.getMode() != MediaLayout.MODE_AVATAR_PICKER) {
header.addSearchButton(menu, this);
}
header.addMoreButton(menu, this);
} else if (id == R.id.menu_clear) {
header.addClearButton(menu, this);
Expand Down Expand Up @@ -208,7 +212,8 @@ protected View onCreateView (Context context) {
decoration = new GridSpacingItemDecoration(spanCount, Screen.dp(4f), true, true, true);
GridLayoutManager manager = new RtlGridLayoutManager(context(), spanCount);

int options = MediaGalleryAdapter.OPTION_SELECTABLE | MediaGalleryAdapter.OPTION_ALWAYS_SELECTABLE;
int options = inAvatarPickerMode() ? MediaGalleryAdapter.OPTION_NEVER_SELECTABLE :
MediaGalleryAdapter.OPTION_SELECTABLE | MediaGalleryAdapter.OPTION_ALWAYS_SELECTABLE;
/*if (U.deviceHasAnyCamera(context)) {
options |= MediaGalleryAdapter.OPTION_CAMERA_AVAILABLE;
}*/
Expand All @@ -230,7 +235,7 @@ protected View onCreateView (Context context) {
if (MoexConfig.disableCameraButton || mediaLayout.needCameraButton()) {
cameraBadgeView = new CircleCounterBadgeView(this, R.id.btn_camera, this::onCameraButtonClick, null);
cameraBadgeView.init(R.drawable.deproko_baseline_camera_26, 48f, 4f, ColorId.circleButtonChat, ColorId.circleButtonChatIcon);
cameraBadgeView.setLayoutParams(FrameLayoutFix.newParams(Screen.dp(CircleCounterBadgeView.BUTTON_WRAPPER_WIDTH), Screen.dp(74f), Gravity.BOTTOM | Gravity.RIGHT, 0, 0, Screen.dp(12), Screen.dp(12 + 60)));
cameraBadgeView.setLayoutParams(FrameLayoutFix.newParams(Screen.dp(CircleCounterBadgeView.BUTTON_WRAPPER_WIDTH), Screen.dp(74f), Gravity.BOTTOM | Gravity.RIGHT, 0, 0, Screen.dp(12), Screen.dp(12) + mediaLayout.getCameraButtonOffset()));
contentView.addView(cameraBadgeView);
}

Expand All @@ -252,6 +257,12 @@ protected void onUpdateBottomBarFactor (float bottomBarFactor, float counterFact
}

private void onCameraButtonClick (View v) {
if (mediaLayout.getMode() == MediaLayout.MODE_AVATAR_PICKER) {
mediaLayout.hidePopupAndOpenCamera(new ViewController.CameraOpenOptions().anchor(v)
.setAvatarPickerMode(mediaLayout.getAvatarPickerMode()).setMediaEditorDelegates(this, this, this));
return;
}

MessagesController c = mediaLayout.parentMessageController();
if (c == null) return;

Expand Down Expand Up @@ -566,7 +577,7 @@ public boolean onPhotoOrVideoOpenRequested (ImageFile fromFile) {
MediaViewController controller = new MediaViewController(context, tdlib);
controller.setArguments(
MediaViewController.Args.fromGallery(this, this, this, this, stack, mediaLayout.areScheduledOnly())
.setReceiverChatId(mediaLayout.getTargetChatId())
.setReceiverChatId(mediaLayout.getTargetChatId()).setAvatarPickerMode(mediaLayout.getAvatarPickerMode())
);
controller.open();

Expand All @@ -576,13 +587,20 @@ public boolean onPhotoOrVideoOpenRequested (ImageFile fromFile) {
return false;
}

private boolean inAvatarPickerMode () {
return mediaLayout.getAvatarPickerMode() != AvatarPickerMode.NONE;
}

@Override
public boolean isMediaItemSelected (int index, MediaItem item) {
return adapter.getSelectionIndex(item.getSourceGalleryFile()) >= 0;
}

@Override
public void setMediaItemSelected (int index, MediaItem item, boolean isSelected) {
if (mediaLayout.getMode() == MediaLayout.MODE_AVATAR_PICKER) {
return;
}
adapter.setSelected(item.getSourceGalleryFile(), isSelected);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,20 @@ public interface Callback {
boolean onPhotoOrVideoOpenRequested (ImageFile fromFile);
}

public static final int OPTION_SELECTABLE = 0x01;
public static final int OPTION_ALWAYS_SELECTABLE = 0x02;
public static final int OPTION_NEED_COUNTER = 0x04;
public static final int OPTION_CAMERA_AVAILABLE = 0x08;
public static final int OPTION_NEED_CAMERA = 0x10;
public static final int OPTION_SELECTABLE = 1;
public static final int OPTION_ALWAYS_SELECTABLE = 1 << 1;
public static final int OPTION_NEED_COUNTER = 1 << 2;
public static final int OPTION_CAMERA_AVAILABLE = 1 << 3;
public static final int OPTION_NEED_CAMERA = 1 << 4;
public static final int OPTION_NEVER_SELECTABLE = 1 << 5;

private final Context context;
private final RecyclerView parent;
private final GridLayoutManager manager;
private final Callback callback;
private final boolean isSelectable;
private final boolean isAlwaysSelectable; // when we click on a first photo, it will be selected
private final boolean isNeverSelectable; // hide all checkboxes
private final boolean needCounter;
private final boolean cameraAvailable;
private boolean animationsEnabled;
Expand All @@ -64,6 +66,7 @@ public MediaGalleryAdapter (Context context, RecyclerView parent, GridLayoutMana
this.needCounter = (options & OPTION_NEED_COUNTER) != 0;
this.cameraAvailable = false; // (options & OPTION_CAMERA_AVAILABLE) != 0 && (!Config.CUSTOM_CAMERA_ENABLED || (options & OPTION_NEED_CAMERA) != 0);
this.showCamera = cameraAvailable && (options & OPTION_NEED_CAMERA) != 0;
this.isNeverSelectable = (options & OPTION_NEVER_SELECTABLE) != 0;
this.selected = new ArrayList<>();
}

Expand Down Expand Up @@ -244,6 +247,7 @@ public void onBindViewHolder (MediaHolder holder, int position) {
ImageFile imageFile = images.get(showCamera ? position - 1 : position);
holder.setImage(imageFile, getSelectionIndex(imageFile), isSelectable, isVisible(imageFile));
holder.setAnimationsDisabled(!animationsEnabled);
((MediaGalleryImageView) holder.itemView).setAlwaysInvisible(isNeverSelectable);
break;
}
case MediaHolder.VIEW_TYPE_COUNTER: {
Expand Down Expand Up @@ -293,7 +297,7 @@ public int measureScrollTop (int position) {
public void onClick (View view, boolean isSelect) {
ImageFile image = ((MediaGalleryImageView) view).getImage();

if (!isSelect && callback.onPhotoOrVideoOpenRequested(image)) {
if ((!isSelect || isNeverSelectable) && callback.onPhotoOrVideoOpenRequested(image)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ public void setClickListener (ClickListener listener) {
}

private boolean isInvisible;
private boolean isAlwaysInvisible;

public void setAlwaysInvisible (boolean alwaysInvisible) {
isAlwaysInvisible = alwaysInvisible;
invalidate();
}

public void setInvisible (boolean isInvisible, boolean needInvalidate) {
if (this.isInvisible != isInvisible) {
Expand Down Expand Up @@ -322,7 +328,7 @@ protected void onDraw (Canvas c) {
c.restore();
}

if (!isInvisible) {
if (!isInvisible && !isAlwaysInvisible) {
final int centerX = receiver.centerX() + (int) ((float) receiver.getWidth() * (1f - SCALE)) / 2;
final int centerY = receiver.centerY() - (int) ((float) receiver.getHeight() * (1f - SCALE)) / 2;
final int radius = Screen.dp(9f + 2f * factor);
Expand Down
Loading

0 comments on commit 56984e3

Please sign in to comment.