Allow editing sensitive content filtering

This commit is contained in:
NekoInverter 2020-01-14 15:54:41 +08:00
parent d2f832d49e
commit a60a363ed7
5 changed files with 157 additions and 22 deletions

View File

@ -42230,6 +42230,63 @@ public class TLRPC {
}
}
public static class TL_account_setContentSettings extends TLObject {
public static int constructor = 0xb574b16b;
public int flags;
public boolean sensitive_enabled;
public TLObject deserializeResponse(AbstractSerializedData stream, int constructor, boolean exception) {
return Bool.TLdeserialize(stream, constructor, exception);
}
public void serializeToStream(AbstractSerializedData stream) {
stream.writeInt32(constructor);
flags = sensitive_enabled ? (flags | 1) : (flags &~ 1);
stream.writeInt32(flags);
}
}
public static class TL_account_getContentSettings extends TLObject {
public static int constructor = 0x8b9b4dae;
public TLObject deserializeResponse(AbstractSerializedData stream, int constructor, boolean exception) {
return TL_account_contentSettings.TLdeserialize(stream, constructor, exception);
}
public void serializeToStream(AbstractSerializedData stream) {
stream.writeInt32(constructor);
}
}
public static class TL_account_contentSettings extends TLObject {
public static int constructor = 0x57e28221;
public int flags;
public boolean sensitive_enabled;
public boolean sensitive_can_change;
public static TL_account_contentSettings TLdeserialize(AbstractSerializedData stream, int constructor, boolean exception) {
if (TL_account_contentSettings.constructor != constructor) {
if (exception) {
throw new RuntimeException(String.format("can't parse magic %x in TL_account_contentSettings", constructor));
} else {
return null;
}
}
TL_account_contentSettings result = new TL_account_contentSettings();
result.readParams(stream, exception);
return result;
}
public void readParams(AbstractSerializedData stream, boolean exception) {
flags = stream.readInt32(exception);
sensitive_enabled = (flags & 1) != 0;
sensitive_can_change = (flags & 2) != 0;
}
}
//functions
public static class Vector extends TLObject {

View File

@ -147,7 +147,7 @@ public class FilterPopup {
for (TLRPC.Dialog dialog : allDialogs) {
if (dialog instanceof TLRPC.TL_dialogFolder) {
folders.add(dialog);
TLRPC.TL_dialogFolder dialogFolder = (TLRPC.TL_dialogFolder)dialog;
TLRPC.TL_dialogFolder dialogFolder = (TLRPC.TL_dialogFolder) dialog;
folderDialogs.add(new ArrayList<>(messagesController.getDialogs(dialogFolder.folder.id)));
}
}
@ -222,7 +222,7 @@ public class FilterPopup {
int count = 0;
for (TLRPC.Dialog dialog : dialogs) {
if (!(dialog instanceof TLRPC.TL_dialogFolder)
&& !MessagesController.getInstance(currentAccount).isDialogMuted(dialog.id)) {
&& !MessagesController.getInstance(currentAccount).isDialogMuted(dialog.id)) {
count += dialog.unread_count;
}
}
@ -420,9 +420,6 @@ public class FilterPopup {
}
public static class DialogType {
public static boolean isDialogsType(int dialogsType) {
return dialogsType == 0 || (dialogsType >= 7 && dialogsType <= 12);
}
public static final int All = 0;
public static final int Users = 7;
public static final int Groups = 8;
@ -430,5 +427,9 @@ public class FilterPopup {
public static final int Bots = 10;
public static final int Admin = 11;
public static final int Unmuted = 12;
public static boolean isDialogsType(int dialogsType) {
return dialogsType == 0 || (dialogsType >= 7 && dialogsType <= 12);
}
}
}

View File

@ -1,7 +1,6 @@
package tw.nekomimi.nekogram;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.UserConfig;
import org.telegram.tgnet.ConnectionsManager;

View File

@ -1,15 +1,15 @@
package tw.nekomimi.nekogram;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Build;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
@ -17,9 +17,6 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.BuildVars;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.NotificationCenter;
@ -27,6 +24,7 @@ import org.telegram.messenger.R;
import org.telegram.messenger.SharedConfig;
import org.telegram.messenger.UserConfig;
import org.telegram.tgnet.ConnectionsManager;
import org.telegram.tgnet.TLRPC;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.AlertDialog;
import org.telegram.ui.ActionBar.BaseFragment;
@ -37,12 +35,11 @@ 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.TextCell;
import org.telegram.ui.Cells.TextCheckCell;
import org.telegram.ui.Cells.TextDetailSettingsCell;
import org.telegram.ui.Cells.TextInfoPrivacyCell;
import org.telegram.ui.Cells.TextSettingsCell;
import org.telegram.ui.Components.EditTextBoldCursor;
import org.telegram.ui.Components.AlertsCreator;
import org.telegram.ui.Components.LayoutHelper;
import org.telegram.ui.Components.RecyclerListView;
@ -52,9 +49,17 @@ public class NekoSettingsActivity extends BaseFragment {
private RecyclerListView listView;
private ListAdapter listAdapter;
private AnimatorSet animatorSet;
private boolean sensitiveCanChange = false;
private boolean sensitiveEnabled = false;
private int rowCount;
private int sensitiveRow;
private int disableFilteringRow;
private int sensitive2Row;
private int connectionRow;
private int ipv6Row;
private int connection2Row;
@ -318,6 +323,22 @@ public class NekoSettingsActivity extends BaseFragment {
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(NekoConfig.fireworks);
}
} else if (position == disableFilteringRow) {
sensitiveEnabled = !sensitiveEnabled;
TLRPC.TL_account_setContentSettings req = new TLRPC.TL_account_setContentSettings();
req.sensitive_enabled = sensitiveEnabled;
AlertDialog progressDialog = new AlertDialog(getParentActivity(), 3);
progressDialog.show();
getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
progressDialog.dismiss();
if (error == null) {
if (response instanceof TLRPC.TL_boolTrue && view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(sensitiveEnabled);
}
} else {
AndroidUtilities.runOnUIThread(() -> AlertsCreator.processError(currentAccount, error, this, req));
}
}));
}
});
@ -328,6 +349,7 @@ public class NekoSettingsActivity extends BaseFragment {
public void onResume() {
super.onResume();
if (listAdapter != null) {
checkSensitive();
listAdapter.notifyDataSetChanged();
}
}
@ -365,6 +387,9 @@ public class NekoSettingsActivity extends BaseFragment {
newYearEveRow = rowCount++;
fireworksRow = rowCount++;
needRestartRow = rowCount++;
sensitiveRow = rowCount++;
disableFilteringRow = rowCount++;
sensitive2Row = rowCount++;
if (notify && listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
@ -410,6 +435,52 @@ public class NekoSettingsActivity extends BaseFragment {
};
}
private void checkSensitive() {
TLRPC.TL_account_getContentSettings req = new TLRPC.TL_account_getContentSettings();
getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (error == null) {
TLRPC.TL_account_contentSettings settings = (TLRPC.TL_account_contentSettings) response;
sensitiveEnabled = settings.sensitive_enabled;
sensitiveCanChange = settings.sensitive_can_change;
int count = listView.getChildCount();
ArrayList<Animator> animators = new ArrayList<>();
for (int a = 0; a < count; a++) {
View child = listView.getChildAt(a);
RecyclerListView.Holder holder = (RecyclerListView.Holder) listView.getChildViewHolder(child);
int position = holder.getAdapterPosition();
if (position == disableFilteringRow) {
TextCheckCell checkCell = (TextCheckCell) holder.itemView;
checkCell.setChecked(sensitiveEnabled);
checkCell.setEnabled(sensitiveCanChange, animators);
if (sensitiveCanChange) {
if (!animators.isEmpty()) {
if (animatorSet != null) {
animatorSet.cancel();
}
animatorSet = new AnimatorSet();
animatorSet.playTogether(animators);
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animator) {
if (animator.equals(animatorSet)) {
animatorSet = null;
}
}
});
animatorSet.setDuration(150);
animatorSet.start();
}
}
}
}
} else {
AndroidUtilities.runOnUIThread(() -> AlertsCreator.processError(currentAccount, error, this, req));
}
}));
}
private class ListAdapter extends RecyclerListView.SelectionAdapter {
private Context mContext;
@ -486,7 +557,7 @@ public class NekoSettingsActivity extends BaseFragment {
textCell.setTextAndCheck(LocaleController.getString("TransparentStatusBar", R.string.TransparentStatusBar), NekoConfig.transparentStatusBar, true);
} else if (position == hideProxySponsorChannelRow) {
textCell.setTextAndCheck(LocaleController.getString("HideProxySponsorChannel", R.string.HideProxySponsorChannel), NekoConfig.hideProxySponsorChannel, true);
} else if(position == saveCacheToPrivateDirectoryRow) {
} else if (position == saveCacheToPrivateDirectoryRow) {
textCell.setTextAndCheck(LocaleController.getString("saveCacheToPrivateDirectory", R.string.saveCacheToPrivateDirectory), NekoConfig.saveCacheToPrivateDirectory, true);
} else if (position == useSystemEmojiRow) {
textCell.setTextAndCheck(LocaleController.getString("EmojiUseDefault", R.string.EmojiUseDefault), SharedConfig.useSystemEmoji, true);
@ -504,6 +575,9 @@ public class NekoSettingsActivity extends BaseFragment {
textCell.setTextAndCheck(LocaleController.getString("HappyNewYearEveryday", R.string.HappyNewYearEveryday), NekoConfig.newYearEve, true);
} else if (position == fireworksRow) {
textCell.setTextAndCheck(LocaleController.getString("ShowFireworks", R.string.ShowFireworks), NekoConfig.fireworks, false);
} else if (position == disableFilteringRow) {
textCell.setTextAndCheck("Disable filtering", sensitiveEnabled, false);
textCell.setEnabled(sensitiveCanChange, null);
}
break;
}
@ -517,6 +591,8 @@ public class NekoSettingsActivity extends BaseFragment {
headerCell.setText(LocaleController.getString("Connection", R.string.Connection));
} else if (position == chatRow) {
headerCell.setText(LocaleController.getString("Chat", R.string.Chat));
} else if (position == sensitiveRow) {
headerCell.setText("Sensitive content");
}
break;
}
@ -524,6 +600,8 @@ public class NekoSettingsActivity extends BaseFragment {
TextInfoPrivacyCell cell = (TextInfoPrivacyCell) holder.itemView;
if (position == needRestartRow) {
cell.setText(LocaleController.getString("SomeItemsNeedRestart", R.string.SomeItemsNeedRestart));
} else if (position == sensitive2Row) {
cell.setText("Display sensitive media in public channels on all your Telegram devices.");
}
break;
}
@ -539,7 +617,8 @@ public class NekoSettingsActivity extends BaseFragment {
position == showPrPrRow || position == showViewHistoryRow || position == showAddToSavedMessagesRow ||
position == nameOrderRow || position == forceTabletRow || position == mapPreviewRow ||
position == xmasRow || position == newYearRow || position == newYearEveRow || position == fireworksRow ||
position == transparentStatusBarRow || position == hideProxySponsorChannelRow || position == saveCacheToPrivateDirectoryRow;
position == transparentStatusBarRow || position == hideProxySponsorChannelRow ||
position == saveCacheToPrivateDirectoryRow || (position == disableFilteringRow && sensitiveCanChange);
}
@Override
@ -590,11 +669,12 @@ public class NekoSettingsActivity extends BaseFragment {
position == transparentStatusBarRow || position == hideProxySponsorChannelRow || position == showViewHistoryRow ||
position == ignoreBlockedRow || position == useSystemEmojiRow || position == typefaceRow ||
position == forceTabletRow || position == xmasRow || position == newYearRow || position == newYearEveRow ||
position == fireworksRow || position == saveCacheToPrivateDirectoryRow) {
position == fireworksRow || position == saveCacheToPrivateDirectoryRow || position == disableFilteringRow) {
return 3;
} else if (position == settingsRow || position == connectionRow || position == messageMenuRow || position == chatRow) {
} else if (position == settingsRow || position == connectionRow || position == messageMenuRow ||
position == chatRow || position == sensitiveRow) {
return 4;
} else if (position == needRestartRow) {
} else if (position == needRestartRow || position == sensitive2Row) {
return 7;
}
return 6;

View File

@ -9,16 +9,14 @@ import android.text.StaticLayout;
import android.view.View;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.LocaleController;
import org.telegram.ui.ActionBar.Theme;
public class UnreadCountBadgeView extends View {
public String countString;
private RectF rect = new RectF();
StaticLayout countLayout;
int countWidth;
private RectF rect = new RectF();
public UnreadCountBadgeView(Context context, String countString) {
super(context);