Skip to content

Commit

Permalink
[TF][PUSH] add UnifiedPush settings in "Notifications and Sounds"
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy Redaelli committed Dec 10, 2023
1 parent 01e8799 commit 1b67551
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import org.json.JSONStringer;
import org.unifiedpush.android.connector.UnifiedPush;
import org.unifiedpush.android.connector.RegistrationDialogContent;

import org.json.JSONArray;
import org.json.JSONObject;
Expand Down Expand Up @@ -1577,10 +1576,9 @@ public void onRequestPushToken() {
try {
SharedConfig.pushStringGetTimeStart = SystemClock.elapsedRealtime();
SharedConfig.saveConfig();
UnifiedPush.registerAppWithDialog(
UnifiedPush.registerApp(
ApplicationLoader.applicationContext,
"default",
new RegistrationDialogContent(),
new ArrayList<>(),
"Telegram WebPush"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.telegram.ui;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
Expand All @@ -23,12 +24,15 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import org.unifiedpush.android.connector.UnifiedPush;

import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.ChatObject;
Expand All @@ -53,6 +57,7 @@
import org.telegram.ui.ActionBar.ThemeDescription;
import org.telegram.ui.Cells.HeaderCell;
import org.telegram.ui.Cells.NotificationsCheckCell;
import org.telegram.ui.Cells.RadioColorCell;
import org.telegram.ui.Cells.ShadowSectionCell;
import org.telegram.ui.Cells.TextCheckCell;
import org.telegram.ui.Cells.TextDetailSettingsCell;
Expand All @@ -67,6 +72,8 @@
import java.util.Comparator;
import java.util.HashSet;
import java.util.Map;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

public class NotificationsSettingsActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {

Expand Down Expand Up @@ -127,6 +134,7 @@ public static class NotificationException {
private int badgeNumberSection2Row;
private int androidAutoAlertRow;
private int repeatRow;
private int unifiedPushDistributorRow;
private int resetSection2Row;
private int resetSectionRow;
private int resetNotificationsRow;
Expand All @@ -136,6 +144,7 @@ public static class NotificationException {
private boolean updateVibrate;
private boolean updateRingtone;
private boolean updateRepeatNotifications;
private boolean updateUnifiedPushDistributor;

@Override
public boolean onFragmentCreate() {
Expand Down Expand Up @@ -192,6 +201,7 @@ public boolean onFragmentCreate() {
notificationsServiceConnectionRow = rowCount++;
androidAutoAlertRow = -1;
repeatRow = rowCount++;
unifiedPushDistributorRow = rowCount++;
resetSection2Row = rowCount++;
resetSectionRow = rowCount++;
resetNotificationsRow = rowCount++;
Expand Down Expand Up @@ -735,6 +745,48 @@ public boolean supportsPredictiveItemAnimations() {
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(!enabled);
}
else if (position == unifiedPushDistributorRow) {
AtomicReference<Dialog> dialogRef = new AtomicReference<>();

LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);

List<String> distributors = UnifiedPush.getDistributors(ApplicationLoader.applicationContext, new ArrayList<>());
CharSequence[] items = distributors.toArray(new CharSequence[distributors.size()]);

String distributor = UnifiedPush.getDistributor(ApplicationLoader.applicationContext);

for (int i = 0; i < items.length; ++i) {
final int index = i;
RadioColorCell cell = new RadioColorCell(getParentActivity());
cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
cell.setTextAndValue(items[index], items[index].equals(distributor));
cell.setBackground(Theme.createSelectorDrawable(Theme.getColor(Theme.key_listSelector), Theme.RIPPLE_MASK_ALL));
linearLayout.addView(cell);
cell.setOnClickListener(v -> {
UnifiedPush.saveDistributor(ApplicationLoader.applicationContext, items[index].toString());
UnifiedPush.registerApp(ApplicationLoader.applicationContext,
"default",
new ArrayList<String>(),
"Telegram WebPush");
updateUnifiedPushDistributor = true;
adapter.notifyItemChanged(position);
dialogRef.get().dismiss();
});
}

Dialog dialog = new AlertDialog.Builder(getParentActivity())
.setTitle(LocaleController.getString("UnifiedPushDistributor", R.string.UnifiedPushDistributor))
.setView(linearLayout)
.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null)
.create();
dialogRef.set(dialog);
showDialog(dialog);
}
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(!enabled);
}
});

return fragmentView;
Expand Down Expand Up @@ -1086,6 +1138,10 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
}
textCell.setTextAndValue(LocaleController.getString("RepeatNotifications", R.string.RepeatNotifications), value, updateRepeatNotifications, false);
updateRepeatNotifications = false;
} else if (position == unifiedPushDistributorRow) {
String value = UnifiedPush.getDistributor(ApplicationLoader.applicationContext);
textCell.setTextAndValue(LocaleController.getString("UnifiedPushDistributor", R.string.UnifiedPushDistributor), value, updateUnifiedPushDistributor, false);
updateUnifiedPushDistributor = false;
}
break;
}
Expand Down
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2526,6 +2526,7 @@
<string name="DistanceUnitsAutomatic">Automatic</string>
<string name="DistanceUnitsKilometers">Kilometers</string>
<string name="DistanceUnitsMiles">Miles</string>
<string name="UnifiedPushDistributor">UnifiedPush Distributors</string>
<string name="AuthAnotherClient">Scan QR Code</string>
<string name="AuthAnotherClientScan">Scan QR Code</string>
<string name="AuthAnotherClientTokenError">Token invalid or already expired.</string>
Expand Down

0 comments on commit 1b67551

Please sign in to comment.