| 1 | package tw.nekomimi.nekogram; |
| 2 | |
| 3 | import android.animation.Animator; |
| 4 | import android.animation.AnimatorListenerAdapter; |
| 5 | import android.animation.AnimatorSet; |
| 6 | import android.annotation.SuppressLint; |
| 7 | import android.content.Context; |
| 8 | import android.content.DialogInterface; |
| 9 | import android.graphics.Canvas; |
| 10 | import android.graphics.Paint; |
| 11 | import android.os.Build; |
| 12 | import android.text.TextPaint; |
| 13 | import android.view.Gravity; |
| 14 | import android.view.View; |
| 15 | import android.view.ViewGroup; |
| 16 | import android.view.WindowManager; |
| 17 | import android.widget.FrameLayout; |
| 18 | import android.widget.LinearLayout; |
| 19 | import android.widget.TextView; |
| 20 | |
| 21 | import androidx.recyclerview.widget.LinearLayoutManager; |
| 22 | import androidx.recyclerview.widget.RecyclerView; |
| 23 | |
| 24 | import org.telegram.messenger.AndroidUtilities; |
| 25 | import org.telegram.messenger.FileLog; |
| 26 | import org.telegram.messenger.LocaleController; |
| 27 | import org.telegram.messenger.MessagesController; |
| 28 | import org.telegram.messenger.NotificationCenter; |
| 29 | import org.telegram.messenger.R; |
| 30 | import org.telegram.messenger.SharedConfig; |
| 31 | import org.telegram.messenger.UserConfig; |
| 32 | import org.telegram.tgnet.ConnectionsManager; |
| 33 | import org.telegram.tgnet.TLRPC; |
| 34 | import org.telegram.ui.ActionBar.ActionBar; |
| 35 | import org.telegram.ui.ActionBar.ActionBarMenuItem; |
| 36 | import org.telegram.ui.ActionBar.AlertDialog; |
| 37 | import org.telegram.ui.ActionBar.BaseFragment; |
| 38 | import org.telegram.ui.ActionBar.BottomSheet; |
| 39 | import org.telegram.ui.ActionBar.Theme; |
| 40 | import org.telegram.ui.ActionBar.ThemeDescription; |
| 41 | import org.telegram.ui.Cells.EmptyCell; |
| 42 | import org.telegram.ui.Cells.HeaderCell; |
| 43 | import org.telegram.ui.Cells.NotificationsCheckCell; |
| 44 | import org.telegram.ui.Cells.RadioColorCell; |
| 45 | import org.telegram.ui.Cells.ShadowSectionCell; |
| 46 | import org.telegram.ui.Cells.TextCheckCell; |
| 47 | import org.telegram.ui.Cells.TextDetailSettingsCell; |
| 48 | import org.telegram.ui.Cells.TextInfoPrivacyCell; |
| 49 | import org.telegram.ui.Cells.TextSettingsCell; |
| 50 | import org.telegram.ui.Components.AlertsCreator; |
| 51 | import org.telegram.ui.Components.LayoutHelper; |
| 52 | import org.telegram.ui.Components.RecyclerListView; |
| 53 | import org.telegram.ui.Components.SeekBarView; |
| 54 | |
| 55 | import java.util.ArrayList; |
| 56 | |
| 57 | @SuppressLint("RtlHardcoded") |
| 58 | public class NekoSettingsActivity extends BaseFragment { |
| 59 | |
| 60 | private RecyclerListView listView; |
| 61 | private ListAdapter listAdapter; |
| 62 | private AnimatorSet animatorSet; |
| 63 | |
| 64 | private boolean sensitiveCanChange = false; |
| 65 | private boolean sensitiveEnabled = false; |
| 66 | |
| 67 | private int rowCount; |
| 68 | |
| 69 | private int connectionRow; |
| 70 | private int ipv6Row; |
| 71 | private int connection2Row; |
| 72 | |
| 73 | private int chatRow; |
| 74 | private int inappCameraRow; |
| 75 | private int useSystemEmojiRow; |
| 76 | private int ignoreBlockedRow; |
| 77 | private int hideProxySponsorChannelRow; |
| 78 | private int saveCacheToPrivateDirectoryRow; |
| 79 | private int pauseMusicOnRecordRow; |
| 80 | private int disablePhotoSideActionRow; |
| 81 | private int hideKeyboardOnChatScrollRow; |
| 82 | private int mapPreviewRow; |
| 83 | private int stickerSizeRow; |
| 84 | private int translationProviderRow; |
| 85 | private int messageMenuRow; |
| 86 | private int chat2Row; |
| 87 | |
| 88 | private int settingsRow; |
| 89 | private int typefaceRow; |
| 90 | private int hidePhoneRow; |
| 91 | private int nameOrderRow; |
| 92 | private int transparentStatusBarRow; |
| 93 | private int forceTabletRow; |
| 94 | private int openArchiveOnPullRow; |
| 95 | private int avatarAsDrawerBackgroundRow; |
| 96 | private int eventTypeRow; |
| 97 | private int newYearRow; |
| 98 | private int actionBarDecorationRow; |
| 99 | private int needRestartRow; |
| 100 | |
| 101 | private int experimentRow; |
| 102 | private int smoothKeyboardRow; |
| 103 | private int disableFilteringRow; |
| 104 | private int unlimitedFavedStickersRow; |
| 105 | private int unlimitedPinnedDialogsRow; |
| 106 | private int deleteAccountRow; |
| 107 | private int experiment2Row; |
| 108 | |
| 109 | @Override |
| 110 | public boolean onFragmentCreate() { |
| 111 | super.onFragmentCreate(); |
| 112 | |
| 113 | updateRows(); |
| 114 | |
| 115 | return true; |
| 116 | } |
| 117 | |
| 118 | @SuppressLint("NewApi") |
| 119 | @Override |
| 120 | public View createView(Context context) { |
| 121 | actionBar.setBackButtonImage(R.drawable.ic_ab_back); |
| 122 | actionBar.setTitle(LocaleController.getString("NekoSettings", R.string.NekoSettings)); |
| 123 | |
| 124 | if (AndroidUtilities.isTablet()) { |
| 125 | actionBar.setOccupyStatusBar(false); |
| 126 | } |
| 127 | actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { |
| 128 | @Override |
| 129 | public void onItemClick(int id) { |
| 130 | if (id == -1) { |
| 131 | finishFragment(); |
| 132 | } |
| 133 | } |
| 134 | }); |
| 135 | |
| 136 | listAdapter = new ListAdapter(context); |
| 137 | |
| 138 | fragmentView = new FrameLayout(context); |
| 139 | fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray)); |
| 140 | FrameLayout frameLayout = (FrameLayout) fragmentView; |
| 141 | |
| 142 | listView = new RecyclerListView(context); |
| 143 | listView.setVerticalScrollBarEnabled(false); |
| 144 | listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)); |
| 145 | frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); |
| 146 | listView.setAdapter(listAdapter); |
| 147 | listView.setOnItemClickListener((view, position, x, y) -> { |
| 148 | if (position == ipv6Row) { |
| 149 | NekoConfig.toggleIPv6(); |
| 150 | if (view instanceof TextCheckCell) { |
| 151 | ((TextCheckCell) view).setChecked(NekoConfig.useIPv6); |
| 152 | } |
| 153 | for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) { |
| 154 | if (UserConfig.getInstance(a).isClientActivated()) { |
| 155 | ConnectionsManager.native_setUseIpv6(a, NekoConfig.useIPv6); |
| 156 | } |
| 157 | } |
| 158 | } else if (position == hidePhoneRow) { |
| 159 | NekoConfig.toggleHidePhone(); |
| 160 | if (view instanceof TextCheckCell) { |
| 161 | ((TextCheckCell) view).setChecked(NekoConfig.hidePhone); |
| 162 | } |
| 163 | } else if (position == inappCameraRow) { |
| 164 | SharedConfig.toggleInappCamera(); |
| 165 | if (view instanceof TextCheckCell) { |
| 166 | ((TextCheckCell) view).setChecked(SharedConfig.inappCamera); |
| 167 | } |
| 168 | } else if (position == forceTabletRow) { |
| 169 | NekoConfig.toggleForceTablet(); |
| 170 | if (view instanceof TextCheckCell) { |
| 171 | ((TextCheckCell) view).setChecked(NekoConfig.forceTablet); |
| 172 | } |
| 173 | } else if (position == ignoreBlockedRow) { |
| 174 | NekoConfig.toggleIgnoreBlocked(); |
| 175 | if (view instanceof TextCheckCell) { |
| 176 | ((TextCheckCell) view).setChecked(NekoConfig.ignoreBlocked); |
| 177 | } |
| 178 | } else if (position == transparentStatusBarRow) { |
| 179 | NekoConfig.toggleTransparentStatusBar(); |
| 180 | if (view instanceof TextCheckCell) { |
| 181 | ((TextCheckCell) view).setChecked(NekoConfig.transparentStatusBar); |
| 182 | } |
| 183 | AndroidUtilities.runOnUIThread(() -> NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.didSetNewTheme, false)); |
| 184 | } else if (position == hideProxySponsorChannelRow) { |
| 185 | NekoConfig.toggleHideProxySponsorChannel(); |
| 186 | if (view instanceof TextCheckCell) { |
| 187 | ((TextCheckCell) view).setChecked(NekoConfig.hideProxySponsorChannel); |
| 188 | } |
| 189 | for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) { |
| 190 | if (UserConfig.getInstance(a).isClientActivated()) { |
| 191 | MessagesController.getInstance(a).checkProxyInfo(true); |
| 192 | } |
| 193 | } |
| 194 | } else if (position == saveCacheToPrivateDirectoryRow) { |
| 195 | NekoConfig.toggleSaveCacheToPrivateDirectory(); |
| 196 | if (view instanceof TextCheckCell) { |
| 197 | ((TextCheckCell) view).setChecked(NekoConfig.saveCacheToPrivateDirectory); |
| 198 | } |
| 199 | } else if (position == useSystemEmojiRow) { |
| 200 | NekoConfig.toggleUseSystemEmoji(); |
| 201 | if (view instanceof TextCheckCell) { |
| 202 | ((TextCheckCell) view).setChecked(NekoConfig.useSystemEmoji); |
| 203 | } |
| 204 | } else if (position == typefaceRow) { |
| 205 | NekoConfig.toggleTypeface(); |
| 206 | if (view instanceof TextCheckCell) { |
| 207 | ((TextCheckCell) view).setChecked(NekoConfig.typeface == 1); |
| 208 | } |
| 209 | } else if (position == mapPreviewRow) { |
| 210 | ArrayList<String> arrayList = new ArrayList<>(); |
| 211 | ArrayList<Integer> types = new ArrayList<>(); |
| 212 | arrayList.add(LocaleController.getString("MapPreviewProviderTelegram", R.string.MapPreviewProviderTelegram)); |
| 213 | types.add(0); |
| 214 | arrayList.add(LocaleController.getString("MapPreviewProviderYandex", R.string.MapPreviewProviderYandex)); |
| 215 | types.add(1); |
| 216 | arrayList.add(LocaleController.getString("MapPreviewProviderNobody", R.string.MapPreviewProviderNobody)); |
| 217 | types.add(2); |
| 218 | |
| 219 | AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 220 | builder.setTitle(LocaleController.getString("MapPreviewProviderTitle", R.string.MapPreviewProviderTitle)); |
| 221 | final LinearLayout linearLayout = new LinearLayout(context); |
| 222 | linearLayout.setOrientation(LinearLayout.VERTICAL); |
| 223 | builder.setView(linearLayout); |
| 224 | |
| 225 | for (int a = 0; a < arrayList.size(); a++) { |
| 226 | RadioColorCell cell = new RadioColorCell(context); |
| 227 | cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0); |
| 228 | cell.setTag(a); |
| 229 | cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked)); |
| 230 | cell.setTextAndValue(arrayList.get(a), NekoConfig.mapPreviewProvider == types.get(a)); |
| 231 | linearLayout.addView(cell); |
| 232 | cell.setOnClickListener(v -> { |
| 233 | Integer which = (Integer) v.getTag(); |
| 234 | NekoConfig.setMapPreviewProvider(types.get(which)); |
| 235 | listAdapter.notifyItemChanged(mapPreviewRow); |
| 236 | builder.getDismissRunnable().run(); |
| 237 | }); |
| 238 | } |
| 239 | builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); |
| 240 | showDialog(builder.create()); |
| 241 | } else if (position == nameOrderRow) { |
| 242 | ArrayList<String> arrayList = new ArrayList<>(); |
| 243 | ArrayList<Integer> types = new ArrayList<>(); |
| 244 | arrayList.add(LocaleController.getString("FirstLast", R.string.FirstLast)); |
| 245 | types.add(1); |
| 246 | arrayList.add(LocaleController.getString("LastFirst", R.string.LastFirst)); |
| 247 | types.add(2); |
| 248 | |
| 249 | AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 250 | builder.setTitle(LocaleController.getString("NameOrder", R.string.NameOrder)); |
| 251 | final LinearLayout linearLayout = new LinearLayout(context); |
| 252 | linearLayout.setOrientation(LinearLayout.VERTICAL); |
| 253 | builder.setView(linearLayout); |
| 254 | |
| 255 | for (int a = 0; a < arrayList.size(); a++) { |
| 256 | RadioColorCell cell = new RadioColorCell(context); |
| 257 | cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0); |
| 258 | cell.setTag(a); |
| 259 | cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked)); |
| 260 | cell.setTextAndValue(arrayList.get(a), NekoConfig.nameOrder == types.get(a)); |
| 261 | linearLayout.addView(cell); |
| 262 | cell.setOnClickListener(v -> { |
| 263 | Integer which = (Integer) v.getTag(); |
| 264 | NekoConfig.setNameOrder(types.get(which)); |
| 265 | listAdapter.notifyItemChanged(nameOrderRow); |
| 266 | builder.getDismissRunnable().run(); |
| 267 | }); |
| 268 | } |
| 269 | builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); |
| 270 | showDialog(builder.create()); |
| 271 | } else if (position == eventTypeRow) { |
| 272 | ArrayList<String> arrayList = new ArrayList<>(); |
| 273 | ArrayList<Integer> types = new ArrayList<>(); |
| 274 | arrayList.add(LocaleController.getString("DependsOnDate", R.string.DependsOnDate)); |
| 275 | types.add(0); |
| 276 | arrayList.add(LocaleController.getString("Christmas", R.string.Christmas)); |
| 277 | types.add(1); |
| 278 | arrayList.add(LocaleController.getString("Valentine", R.string.Valentine)); |
| 279 | types.add(2); |
| 280 | |
| 281 | AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 282 | builder.setTitle(LocaleController.getString("EventType", R.string.EventType)); |
| 283 | final LinearLayout linearLayout = new LinearLayout(context); |
| 284 | linearLayout.setOrientation(LinearLayout.VERTICAL); |
| 285 | builder.setView(linearLayout); |
| 286 | |
| 287 | for (int a = 0; a < arrayList.size(); a++) { |
| 288 | RadioColorCell cell = new RadioColorCell(context); |
| 289 | cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0); |
| 290 | cell.setTag(a); |
| 291 | cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked)); |
| 292 | cell.setTextAndValue(arrayList.get(a), NekoConfig.eventType == types.get(a)); |
| 293 | linearLayout.addView(cell); |
| 294 | cell.setOnClickListener(v -> { |
| 295 | Integer which = (Integer) v.getTag(); |
| 296 | NekoConfig.setEventType(types.get(which)); |
| 297 | listAdapter.notifyItemChanged(eventTypeRow); |
| 298 | builder.getDismissRunnable().run(); |
| 299 | }); |
| 300 | } |
| 301 | builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); |
| 302 | showDialog(builder.create()); |
| 303 | } else if (position == actionBarDecorationRow) { |
| 304 | ArrayList<String> arrayList = new ArrayList<>(); |
| 305 | ArrayList<Integer> types = new ArrayList<>(); |
| 306 | arrayList.add(LocaleController.getString("DependsOnDate", R.string.DependsOnDate)); |
| 307 | types.add(0); |
| 308 | arrayList.add(LocaleController.getString("Snowflakes", R.string.Snowflakes)); |
| 309 | types.add(1); |
| 310 | arrayList.add(LocaleController.getString("Fireworks", R.string.Fireworks)); |
| 311 | types.add(2); |
| 312 | |
| 313 | AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 314 | builder.setTitle(LocaleController.getString("ActionBarDecoration", R.string.ActionBarDecoration)); |
| 315 | final LinearLayout linearLayout = new LinearLayout(context); |
| 316 | linearLayout.setOrientation(LinearLayout.VERTICAL); |
| 317 | builder.setView(linearLayout); |
| 318 | |
| 319 | for (int a = 0; a < arrayList.size(); a++) { |
| 320 | RadioColorCell cell = new RadioColorCell(context); |
| 321 | cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0); |
| 322 | cell.setTag(a); |
| 323 | cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked)); |
| 324 | cell.setTextAndValue(arrayList.get(a), NekoConfig.actionBarDecoration == types.get(a)); |
| 325 | linearLayout.addView(cell); |
| 326 | cell.setOnClickListener(v -> { |
| 327 | Integer which = (Integer) v.getTag(); |
| 328 | NekoConfig.setActionBarDecoration(types.get(which)); |
| 329 | listAdapter.notifyItemChanged(actionBarDecorationRow); |
| 330 | builder.getDismissRunnable().run(); |
| 331 | }); |
| 332 | } |
| 333 | builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); |
| 334 | showDialog(builder.create()); |
| 335 | } else if (position == newYearRow) { |
| 336 | NekoConfig.toggleNewYear(); |
| 337 | if (view instanceof TextCheckCell) { |
| 338 | ((TextCheckCell) view).setChecked(NekoConfig.newYear); |
| 339 | } |
| 340 | } else if (position == disableFilteringRow) { |
| 341 | sensitiveEnabled = !sensitiveEnabled; |
| 342 | TLRPC.TL_account_setContentSettings req = new TLRPC.TL_account_setContentSettings(); |
| 343 | req.sensitive_enabled = sensitiveEnabled; |
| 344 | AlertDialog progressDialog = new AlertDialog(getParentActivity(), 3); |
| 345 | progressDialog.show(); |
| 346 | getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { |
| 347 | progressDialog.dismiss(); |
| 348 | if (error == null) { |
| 349 | if (response instanceof TLRPC.TL_boolTrue && view instanceof TextCheckCell) { |
| 350 | ((TextCheckCell) view).setChecked(sensitiveEnabled); |
| 351 | } |
| 352 | } else { |
| 353 | AndroidUtilities.runOnUIThread(() -> AlertsCreator.processError(currentAccount, error, this, req)); |
| 354 | } |
| 355 | })); |
| 356 | } else if (position == stickerSizeRow) { |
| 357 | showStickerSizeAlert(); |
| 358 | } else if (position == unlimitedFavedStickersRow) { |
| 359 | NekoConfig.toggleUnlimitedFavedStickers(); |
| 360 | if (view instanceof TextCheckCell) { |
| 361 | ((TextCheckCell) view).setChecked(NekoConfig.unlimitedFavedStickers); |
| 362 | } |
| 363 | } else if (position == messageMenuRow) { |
| 364 | showMessageMenuAlert(); |
| 365 | } else if (position == deleteAccountRow) { |
| 366 | AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); |
| 367 | builder.setMessage(LocaleController.getString("TosDeclineDeleteAccount", R.string.TosDeclineDeleteAccount)); |
| 368 | builder.setTitle(LocaleController.getString("DeleteAccount", R.string.DeleteAccount)); |
| 369 | builder.setPositiveButton(LocaleController.getString("Deactivate", R.string.Deactivate), (dialog, which) -> { |
| 370 | ArrayList<TLRPC.Dialog> dialogs = new ArrayList<>(getMessagesController().getAllDialogs()); |
| 371 | for (TLRPC.Dialog TLdialog : dialogs) { |
| 372 | if (TLdialog instanceof TLRPC.TL_dialogFolder) { |
| 373 | continue; |
| 374 | } |
| 375 | TLRPC.Peer peer = getMessagesController().getPeer((int) TLdialog.id); |
| 376 | if (peer.channel_id != 0) { |
| 377 | TLRPC.Chat chat = getMessagesController().getChat(peer.channel_id); |
| 378 | if (!chat.broadcast) { |
| 379 | MessageHelper.getInstance(currentAccount).deleteUserChannelHistoryWithSearch(TLdialog.id, getMessagesController().getUser(getUserConfig().clientUserId)); |
| 380 | } |
| 381 | } |
| 382 | if (peer.user_id != 0) { |
| 383 | getMessagesController().deleteDialog(TLdialog.id, 0, true); |
| 384 | } |
| 385 | } |
| 386 | AlertDialog.Builder builder12 = new AlertDialog.Builder(getParentActivity()); |
| 387 | builder12.setMessage(LocaleController.getString("TosDeclineDeleteAccount", R.string.TosDeclineDeleteAccount)); |
| 388 | builder12.setTitle(LocaleController.getString("DeleteAccount", R.string.DeleteAccount)); |
| 389 | builder12.setPositiveButton(LocaleController.getString("Deactivate", R.string.Deactivate), (dialogInterface, i) -> { |
| 390 | final AlertDialog progressDialog = new AlertDialog(getParentActivity(), 3); |
| 391 | progressDialog.setCanCacnel(false); |
| 392 | |
| 393 | TLRPC.TL_account_deleteAccount req = new TLRPC.TL_account_deleteAccount(); |
| 394 | req.reason = "Meow"; |
| 395 | ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { |
| 396 | try { |
| 397 | progressDialog.dismiss(); |
| 398 | } catch (Exception e) { |
| 399 | FileLog.e(e); |
| 400 | } |
| 401 | if (response instanceof TLRPC.TL_boolTrue) { |
| 402 | MessagesController.getInstance(currentAccount).performLogout(0); |
| 403 | } else if (error == null || error.code != -1000) { |
| 404 | String errorText = LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred); |
| 405 | if (error != null) { |
| 406 | errorText += "\n" + error.text; |
| 407 | } |
| 408 | AlertDialog.Builder builder1 = new AlertDialog.Builder(getParentActivity()); |
| 409 | builder1.setTitle(LocaleController.getString("AppName", R.string.AppName)); |
| 410 | builder1.setMessage(errorText); |
| 411 | builder1.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); |
| 412 | builder1.show(); |
| 413 | } |
| 414 | })); |
| 415 | progressDialog.show(); |
| 416 | }); |
| 417 | builder12.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); |
| 418 | AlertDialog dialog12 = builder12.create(); |
| 419 | showDialog(dialog12); |
| 420 | TextView button = (TextView) dialog12.getButton(DialogInterface.BUTTON_POSITIVE); |
| 421 | if (button != null) { |
| 422 | button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2)); |
| 423 | } |
| 424 | }); |
| 425 | builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); |
| 426 | builder.show(); |
| 427 | AlertDialog dialog = builder.create(); |
| 428 | showDialog(dialog); |
| 429 | TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE); |
| 430 | if (button != null) { |
| 431 | button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2)); |
| 432 | } |
| 433 | } else if (position == translationProviderRow) { |
| 434 | ArrayList<String> arrayList = new ArrayList<>(); |
| 435 | ArrayList<Integer> types = new ArrayList<>(); |
| 436 | arrayList.add(LocaleController.getString("ProviderGoogleTranslate", R.string.ProviderGoogleTranslate)); |
| 437 | types.add(1); |
| 438 | arrayList.add(LocaleController.getString("ProviderGoogleTranslateCN", R.string.ProviderGoogleTranslateCN)); |
| 439 | types.add(2); |
| 440 | arrayList.add(LocaleController.getString("ProviderLingocloud", R.string.ProviderLingocloud)); |
| 441 | types.add(3); |
| 442 | arrayList.add(LocaleController.getString("ProviderGoogleTranslateWeb", R.string.ProviderGoogleTranslateWeb)); |
| 443 | types.add(-1); |
| 444 | arrayList.add(LocaleController.getString("ProviderGoogleTranslateCNWeb", R.string.ProviderGoogleTranslateCNWeb)); |
| 445 | types.add(-2); |
| 446 | arrayList.add(LocaleController.getString("ProviderBaiduFanyiWeb", R.string.ProviderBaiduFanyiWeb)); |
| 447 | types.add(-3); |
| 448 | |
| 449 | AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 450 | builder.setTitle(LocaleController.getString("TranslationProvider", R.string.TranslationProvider)); |
| 451 | final LinearLayout linearLayout = new LinearLayout(context); |
| 452 | linearLayout.setOrientation(LinearLayout.VERTICAL); |
| 453 | builder.setView(linearLayout); |
| 454 | |
| 455 | for (int a = 0; a < arrayList.size(); a++) { |
| 456 | RadioColorCell cell = new RadioColorCell(context); |
| 457 | cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0); |
| 458 | cell.setTag(a); |
| 459 | cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked)); |
| 460 | cell.setTextAndValue(arrayList.get(a), NekoConfig.translationProvider == types.get(a)); |
| 461 | linearLayout.addView(cell); |
| 462 | cell.setOnClickListener(v -> { |
| 463 | Integer which = (Integer) v.getTag(); |
| 464 | NekoConfig.setTranslationProvider(types.get(which)); |
| 465 | listAdapter.notifyItemChanged(translationProviderRow); |
| 466 | builder.getDismissRunnable().run(); |
| 467 | }); |
| 468 | } |
| 469 | builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); |
| 470 | showDialog(builder.create()); |
| 471 | } else if (position == pauseMusicOnRecordRow) { |
| 472 | SharedConfig.togglePauseMusicOnRecord(); |
| 473 | if (view instanceof TextCheckCell) { |
| 474 | ((TextCheckCell) view).setChecked(SharedConfig.pauseMusicOnRecord); |
| 475 | } |
| 476 | } else if (position == smoothKeyboardRow) { |
| 477 | SharedConfig.toggleSmoothKeyboard(); |
| 478 | if (view instanceof TextCheckCell) { |
| 479 | ((TextCheckCell) view).setChecked(SharedConfig.smoothKeyboard); |
| 480 | } |
| 481 | if (SharedConfig.smoothKeyboard && getParentActivity() != null) { |
| 482 | getParentActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); |
| 483 | } |
| 484 | } else if (position == disablePhotoSideActionRow) { |
| 485 | NekoConfig.toggleDisablePhotoSideAction(); |
| 486 | if (view instanceof TextCheckCell) { |
| 487 | ((TextCheckCell) view).setChecked(NekoConfig.disablePhotoSideAction); |
| 488 | } |
| 489 | } else if (position == unlimitedPinnedDialogsRow) { |
| 490 | NekoConfig.toggleUnlimitedPinnedDialogs(); |
| 491 | if (view instanceof TextCheckCell) { |
| 492 | ((TextCheckCell) view).setChecked(NekoConfig.unlimitedPinnedDialogs); |
| 493 | } |
| 494 | } else if (position == openArchiveOnPullRow) { |
| 495 | NekoConfig.toggleOpenArchiveOnPull(); |
| 496 | if (view instanceof TextCheckCell) { |
| 497 | ((TextCheckCell) view).setChecked(NekoConfig.openArchiveOnPull); |
| 498 | } |
| 499 | } else if (position == connection2Row) { |
| 500 | NekoConfig.toggleShowHiddenFeature(); |
| 501 | updateRows(); |
| 502 | } else if (position == hideKeyboardOnChatScrollRow) { |
| 503 | NekoConfig.toggleHideKeyboardOnChatScroll(); |
| 504 | if (view instanceof TextCheckCell) { |
| 505 | ((TextCheckCell) view).setChecked(NekoConfig.hideKeyboardOnChatScroll); |
| 506 | } |
| 507 | } else if (position == avatarAsDrawerBackgroundRow) { |
| 508 | NekoConfig.toggleAvatarAsDrawerBackground(); |
| 509 | NotificationCenter.getInstance(UserConfig.selectedAccount).postNotificationName(NotificationCenter.mainUserInfoChanged); |
| 510 | if (view instanceof TextCheckCell) { |
| 511 | ((TextCheckCell) view).setChecked(NekoConfig.avatarAsDrawerBackground); |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | }); |
| 516 | |
| 517 | return fragmentView; |
| 518 | } |
| 519 | |
| 520 | @Override |
| 521 | public void onResume() { |
| 522 | super.onResume(); |
| 523 | if (listAdapter != null) { |
| 524 | checkSensitive(); |
| 525 | listAdapter.notifyDataSetChanged(); |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | private void updateRows() { |
| 530 | rowCount = 0; |
| 531 | connectionRow = rowCount++; |
| 532 | ipv6Row = rowCount++; |
| 533 | connection2Row = rowCount++; |
| 534 | chatRow = rowCount++; |
| 535 | inappCameraRow = rowCount++; |
| 536 | useSystemEmojiRow = rowCount++; |
| 537 | ignoreBlockedRow = rowCount++; |
| 538 | hideProxySponsorChannelRow = rowCount++; |
| 539 | saveCacheToPrivateDirectoryRow = NekoConfig.showHiddenFeature && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? rowCount++ : -1; |
| 540 | pauseMusicOnRecordRow = rowCount++; |
| 541 | disablePhotoSideActionRow = rowCount++; |
| 542 | hideKeyboardOnChatScrollRow = rowCount++; |
| 543 | mapPreviewRow = rowCount++; |
| 544 | stickerSizeRow = rowCount++; |
| 545 | messageMenuRow = rowCount++; |
| 546 | translationProviderRow = rowCount++; |
| 547 | chat2Row = rowCount++; |
| 548 | settingsRow = rowCount++; |
| 549 | hidePhoneRow = rowCount++; |
| 550 | typefaceRow = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? rowCount++ : -1; |
| 551 | transparentStatusBarRow = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? rowCount++ : -1; |
| 552 | forceTabletRow = rowCount++; |
| 553 | openArchiveOnPullRow = rowCount++; |
| 554 | avatarAsDrawerBackgroundRow = rowCount++; |
| 555 | nameOrderRow = rowCount++; |
| 556 | eventTypeRow = NekoConfig.showHiddenFeature ? rowCount++ : -1; |
| 557 | newYearRow = NekoConfig.showHiddenFeature ? rowCount++ : -1; |
| 558 | actionBarDecorationRow = NekoConfig.showHiddenFeature ? rowCount++ : -1; |
| 559 | needRestartRow = rowCount++; |
| 560 | experimentRow = rowCount++; |
| 561 | smoothKeyboardRow = !AndroidUtilities.isTablet() ? rowCount++ : -1; |
| 562 | disableFilteringRow = rowCount++; |
| 563 | unlimitedFavedStickersRow = rowCount++; |
| 564 | unlimitedPinnedDialogsRow = rowCount++; |
| 565 | deleteAccountRow = NekoConfig.showHiddenFeature ? rowCount++ : -1; |
| 566 | experiment2Row = rowCount++; |
| 567 | if (listAdapter != null) { |
| 568 | listAdapter.notifyDataSetChanged(); |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | @Override |
| 573 | public ThemeDescription[] getThemeDescriptions() { |
| 574 | return new ThemeDescription[]{ |
| 575 | new ThemeDescription(listView, ThemeDescription.FLAG_CELLBACKGROUNDCOLOR, new Class[]{EmptyCell.class, TextSettingsCell.class, TextCheckCell.class, HeaderCell.class, TextDetailSettingsCell.class, NotificationsCheckCell.class}, null, null, null, Theme.key_windowBackgroundWhite), |
| 576 | new ThemeDescription(fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundGray), |
| 577 | |
| 578 | new ThemeDescription(actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_avatar_backgroundActionBarBlue), |
| 579 | new ThemeDescription(listView, ThemeDescription.FLAG_LISTGLOWCOLOR, null, null, null, null, Theme.key_avatar_backgroundActionBarBlue), |
| 580 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_ITEMSCOLOR, null, null, null, null, Theme.key_avatar_actionBarIconBlue), |
| 581 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_TITLECOLOR, null, null, null, null, Theme.key_actionBarDefaultTitle), |
| 582 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SELECTORCOLOR, null, null, null, null, Theme.key_avatar_actionBarSelectorBlue), |
| 583 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SUBMENUBACKGROUND, null, null, null, null, Theme.key_actionBarDefaultSubmenuBackground), |
| 584 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SUBMENUITEM, null, null, null, null, Theme.key_actionBarDefaultSubmenuItem), |
| 585 | |
| 586 | new ThemeDescription(listView, ThemeDescription.FLAG_SELECTOR, null, null, null, null, Theme.key_listSelector), |
| 587 | |
| 588 | new ThemeDescription(listView, 0, new Class[]{View.class}, Theme.dividerPaint, null, null, Theme.key_divider), |
| 589 | |
| 590 | new ThemeDescription(listView, ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{ShadowSectionCell.class}, null, null, null, Theme.key_windowBackgroundGrayShadow), |
| 591 | |
| 592 | new ThemeDescription(listView, 0, new Class[]{TextSettingsCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText), |
| 593 | new ThemeDescription(listView, 0, new Class[]{TextSettingsCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteValueText), |
| 594 | |
| 595 | new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText), |
| 596 | new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2), |
| 597 | new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrack), |
| 598 | new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrackChecked), |
| 599 | |
| 600 | new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText), |
| 601 | new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2), |
| 602 | new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrack), |
| 603 | new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrackChecked), |
| 604 | |
| 605 | new ThemeDescription(listView, 0, new Class[]{HeaderCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlueHeader), |
| 606 | |
| 607 | new ThemeDescription(listView, 0, new Class[]{TextDetailSettingsCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText), |
| 608 | new ThemeDescription(listView, 0, new Class[]{TextDetailSettingsCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2), |
| 609 | }; |
| 610 | } |
| 611 | |
| 612 | private void checkSensitive() { |
| 613 | TLRPC.TL_account_getContentSettings req = new TLRPC.TL_account_getContentSettings(); |
| 614 | getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { |
| 615 | if (error == null) { |
| 616 | TLRPC.TL_account_contentSettings settings = (TLRPC.TL_account_contentSettings) response; |
| 617 | sensitiveEnabled = settings.sensitive_enabled; |
| 618 | sensitiveCanChange = settings.sensitive_can_change; |
| 619 | int count = listView.getChildCount(); |
| 620 | ArrayList<Animator> animators = new ArrayList<>(); |
| 621 | for (int a = 0; a < count; a++) { |
| 622 | View child = listView.getChildAt(a); |
| 623 | RecyclerListView.Holder holder = (RecyclerListView.Holder) listView.getChildViewHolder(child); |
| 624 | int position = holder.getAdapterPosition(); |
| 625 | if (position == disableFilteringRow) { |
| 626 | TextCheckCell checkCell = (TextCheckCell) holder.itemView; |
| 627 | checkCell.setChecked(sensitiveEnabled); |
| 628 | checkCell.setEnabled(sensitiveCanChange, animators); |
| 629 | if (sensitiveCanChange) { |
| 630 | if (!animators.isEmpty()) { |
| 631 | if (animatorSet != null) { |
| 632 | animatorSet.cancel(); |
| 633 | } |
| 634 | animatorSet = new AnimatorSet(); |
| 635 | animatorSet.playTogether(animators); |
| 636 | animatorSet.addListener(new AnimatorListenerAdapter() { |
| 637 | @Override |
| 638 | public void onAnimationEnd(Animator animator) { |
| 639 | if (animator.equals(animatorSet)) { |
| 640 | animatorSet = null; |
| 641 | } |
| 642 | } |
| 643 | }); |
| 644 | animatorSet.setDuration(150); |
| 645 | animatorSet.start(); |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | } |
| 650 | } |
| 651 | } else { |
| 652 | AndroidUtilities.runOnUIThread(() -> AlertsCreator.processError(currentAccount, error, this, req)); |
| 653 | } |
| 654 | })); |
| 655 | } |
| 656 | |
| 657 | private void showMessageMenuAlert() { |
| 658 | if (getParentActivity() == null) { |
| 659 | return; |
| 660 | } |
| 661 | Context context = getParentActivity(); |
| 662 | AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 663 | builder.setTitle(LocaleController.getString("MessageMenu", R.string.MessageMenu)); |
| 664 | |
| 665 | LinearLayout linearLayout = new LinearLayout(context); |
| 666 | linearLayout.setOrientation(LinearLayout.VERTICAL); |
| 667 | |
| 668 | LinearLayout linearLayoutInviteContainer = new LinearLayout(context); |
| 669 | linearLayoutInviteContainer.setOrientation(LinearLayout.VERTICAL); |
| 670 | linearLayout.addView(linearLayoutInviteContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); |
| 671 | |
| 672 | int count = NekoConfig.showHiddenFeature ? 10 : 9; |
| 673 | for (int a = 0; a < count; a++) { |
| 674 | TextCheckCell textCell = new TextCheckCell(context); |
| 675 | switch (a) { |
| 676 | case 0: { |
| 677 | textCell.setTextAndCheck(LocaleController.getString("DeleteDownloadedFile", R.string.DeleteDownloadedFile), NekoConfig.showDeleteDownloadedFile, false); |
| 678 | break; |
| 679 | } |
| 680 | case 1: { |
| 681 | textCell.setTextAndCheck(LocaleController.getString("AddToSavedMessages", R.string.AddToSavedMessages), NekoConfig.showAddToSavedMessages, false); |
| 682 | break; |
| 683 | } |
| 684 | case 2: { |
| 685 | textCell.setTextAndCheck(LocaleController.getString("Repeat", R.string.Repeat), NekoConfig.showRepeat, false); |
| 686 | break; |
| 687 | } |
| 688 | case 3: { |
| 689 | textCell.setTextAndCheck(LocaleController.getString("Prpr", R.string.Prpr), NekoConfig.showPrPr, false); |
| 690 | break; |
| 691 | } |
| 692 | case 4: { |
| 693 | textCell.setTextAndCheck(LocaleController.getString("ViewHistory", R.string.ViewHistory), NekoConfig.showViewHistory, false); |
| 694 | break; |
| 695 | } |
| 696 | case 5: { |
| 697 | textCell.setTextAndCheck(LocaleController.getString("Translate", R.string.Translate), NekoConfig.showTranslate, false); |
| 698 | break; |
| 699 | } |
| 700 | case 6: { |
| 701 | textCell.setTextAndCheck(LocaleController.getString("ReportChat", R.string.ReportChat), NekoConfig.showReport, false); |
| 702 | break; |
| 703 | } |
| 704 | case 7: { |
| 705 | textCell.setTextAndCheck(LocaleController.getString("EditAdminRights", R.string.EditAdminRights), NekoConfig.showAdminActions, false); |
| 706 | break; |
| 707 | } |
| 708 | case 8: { |
| 709 | textCell.setTextAndCheck(LocaleController.getString("ChangePermissions", R.string.ChangePermissions), NekoConfig.showChangePermissions, false); |
| 710 | break; |
| 711 | } |
| 712 | case 9: { |
| 713 | textCell.setTextAndCheck(LocaleController.getString("MessageDetails", R.string.MessageDetails), NekoConfig.showMessageDetails, false); |
| 714 | break; |
| 715 | } |
| 716 | } |
| 717 | textCell.setTag(a); |
| 718 | textCell.setBackground(Theme.getSelectorDrawable(false)); |
| 719 | linearLayoutInviteContainer.addView(textCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); |
| 720 | textCell.setOnClickListener(v2 -> { |
| 721 | Integer tag = (Integer) v2.getTag(); |
| 722 | switch (tag) { |
| 723 | case 0: { |
| 724 | NekoConfig.toggleShowDeleteDownloadedFile(); |
| 725 | textCell.setChecked(NekoConfig.showDeleteDownloadedFile); |
| 726 | break; |
| 727 | } |
| 728 | case 1: { |
| 729 | NekoConfig.toggleShowAddToSavedMessages(); |
| 730 | textCell.setChecked(NekoConfig.showAddToSavedMessages); |
| 731 | break; |
| 732 | } |
| 733 | case 2: { |
| 734 | NekoConfig.toggleShowRepeat(); |
| 735 | textCell.setChecked(NekoConfig.showRepeat); |
| 736 | break; |
| 737 | } |
| 738 | case 3: { |
| 739 | NekoConfig.toggleShowPrPr(); |
| 740 | textCell.setChecked(NekoConfig.showPrPr); |
| 741 | break; |
| 742 | } |
| 743 | case 4: { |
| 744 | NekoConfig.toggleShowViewHistory(); |
| 745 | textCell.setChecked(NekoConfig.showViewHistory); |
| 746 | break; |
| 747 | } |
| 748 | case 5: { |
| 749 | NekoConfig.toggleShowTranslate(); |
| 750 | textCell.setChecked(NekoConfig.showTranslate); |
| 751 | break; |
| 752 | } |
| 753 | case 6: { |
| 754 | NekoConfig.toggleShowReport(); |
| 755 | textCell.setChecked(NekoConfig.showReport); |
| 756 | break; |
| 757 | } |
| 758 | case 7: { |
| 759 | NekoConfig.toggleShowAdminActions(); |
| 760 | textCell.setChecked(NekoConfig.showAdminActions); |
| 761 | break; |
| 762 | } |
| 763 | case 8: { |
| 764 | NekoConfig.toggleShowChangePermissions(); |
| 765 | textCell.setChecked(NekoConfig.showChangePermissions); |
| 766 | break; |
| 767 | } |
| 768 | case 9: { |
| 769 | NekoConfig.toggleShowMessageDetails(); |
| 770 | textCell.setChecked(NekoConfig.showMessageDetails); |
| 771 | break; |
| 772 | } |
| 773 | } |
| 774 | }); |
| 775 | } |
| 776 | builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); |
| 777 | builder.setView(linearLayout); |
| 778 | showDialog(builder.create()); |
| 779 | } |
| 780 | |
| 781 | private void showStickerSizeAlert() { |
| 782 | if (getParentActivity() == null) { |
| 783 | return; |
| 784 | } |
| 785 | Context context = getParentActivity(); |
| 786 | BottomSheet.Builder builder = new BottomSheet.Builder(context); |
| 787 | builder.setApplyTopPadding(false); |
| 788 | builder.setApplyBottomPadding(false); |
| 789 | |
| 790 | LinearLayout linearLayout = new LinearLayout(context); |
| 791 | linearLayout.setOrientation(LinearLayout.VERTICAL); |
| 792 | |
| 793 | FrameLayout titleLayout = new FrameLayout(context); |
| 794 | linearLayout.addView(titleLayout); |
| 795 | |
| 796 | HeaderCell headerCell = new HeaderCell(context, Theme.key_windowBackgroundWhiteBlueHeader, 23, 15, false); |
| 797 | headerCell.setHeight(47); |
| 798 | headerCell.setText(LocaleController.getString("StickerSize", R.string.StickerSize)); |
| 799 | titleLayout.addView(headerCell); |
| 800 | |
| 801 | ActionBarMenuItem optionsButton = new ActionBarMenuItem(context, null, 0, Theme.getColor(Theme.key_sheet_other)); |
| 802 | optionsButton.setLongClickEnabled(false); |
| 803 | optionsButton.setSubMenuOpenSide(2); |
| 804 | optionsButton.setIcon(R.drawable.ic_ab_other); |
| 805 | optionsButton.setBackground(Theme.createSelectorDrawable(Theme.getColor(Theme.key_player_actionBarSelector), 1)); |
| 806 | optionsButton.addSubItem(1, R.drawable.msg_reset, LocaleController.getString("Reset", R.string.Reset)); |
| 807 | optionsButton.setOnClickListener(v -> optionsButton.toggleSubMenu()); |
| 808 | optionsButton.setContentDescription(LocaleController.getString("AccDescrMoreOptions", R.string.AccDescrMoreOptions)); |
| 809 | titleLayout.addView(optionsButton, LayoutHelper.createFrame(40, 40, Gravity.TOP | Gravity.RIGHT, 0, 8, 5, 0)); |
| 810 | |
| 811 | LinearLayout linearLayoutInviteContainer = new LinearLayout(context); |
| 812 | linearLayoutInviteContainer.setOrientation(LinearLayout.VERTICAL); |
| 813 | linearLayout.addView(linearLayoutInviteContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); |
| 814 | StickerSizeCell stickerSizeCell = new StickerSizeCell(context); |
| 815 | optionsButton.setDelegate(id -> { |
| 816 | if (id == 1) { |
| 817 | NekoConfig.setStickerSize(14.0f); |
| 818 | stickerSizeCell.invalidate(); |
| 819 | } |
| 820 | }); |
| 821 | linearLayoutInviteContainer.addView(stickerSizeCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); |
| 822 | builder.setCustomView(linearLayout); |
| 823 | showDialog(builder.create()); |
| 824 | } |
| 825 | |
| 826 | private class StickerSizeCell extends FrameLayout { |
| 827 | |
| 828 | private StickerSizePreviewMessagesCell messagesCell; |
| 829 | private SeekBarView sizeBar; |
| 830 | private int startStickerSize = 2; |
| 831 | private int endStickerSize = 20; |
| 832 | |
| 833 | private TextPaint textPaint; |
| 834 | |
| 835 | public StickerSizeCell(Context context) { |
| 836 | super(context); |
| 837 | |
| 838 | setWillNotDraw(false); |
| 839 | |
| 840 | textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); |
| 841 | textPaint.setTextSize(AndroidUtilities.dp(16)); |
| 842 | |
| 843 | sizeBar = new SeekBarView(context); |
| 844 | sizeBar.setReportChanges(true); |
| 845 | sizeBar.setDelegate(new SeekBarView.SeekBarViewDelegate() { |
| 846 | @Override |
| 847 | public void onSeekBarDrag(boolean stop, float progress) { |
| 848 | NekoConfig.setStickerSize(startStickerSize + (endStickerSize - startStickerSize) * progress); |
| 849 | StickerSizeCell.this.invalidate(); |
| 850 | } |
| 851 | |
| 852 | @Override |
| 853 | public void onSeekBarPressed(boolean pressed) { |
| 854 | |
| 855 | } |
| 856 | }); |
| 857 | addView(sizeBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 38, Gravity.LEFT | Gravity.TOP, 9, 5, 43, 11)); |
| 858 | |
| 859 | messagesCell = new StickerSizePreviewMessagesCell(context, parentLayout); |
| 860 | addView(messagesCell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, 53, 0, 0)); |
| 861 | } |
| 862 | |
| 863 | @Override |
| 864 | protected void onDraw(Canvas canvas) { |
| 865 | textPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteValueText)); |
| 866 | canvas.drawText("" + Math.round(NekoConfig.stickerSize), getMeasuredWidth() - AndroidUtilities.dp(39), AndroidUtilities.dp(28), textPaint); |
| 867 | } |
| 868 | |
| 869 | @Override |
| 870 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 871 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 872 | sizeBar.setProgress((NekoConfig.stickerSize - startStickerSize) / (float) (endStickerSize - startStickerSize)); |
| 873 | } |
| 874 | |
| 875 | @Override |
| 876 | public void invalidate() { |
| 877 | super.invalidate(); |
| 878 | listAdapter.notifyItemChanged(stickerSizeRow); |
| 879 | messagesCell.invalidate(); |
| 880 | sizeBar.invalidate(); |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | private class ListAdapter extends RecyclerListView.SelectionAdapter { |
| 885 | |
| 886 | private Context mContext; |
| 887 | |
| 888 | public ListAdapter(Context context) { |
| 889 | mContext = context; |
| 890 | } |
| 891 | |
| 892 | @Override |
| 893 | public int getItemCount() { |
| 894 | return rowCount; |
| 895 | } |
| 896 | |
| 897 | @Override |
| 898 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { |
| 899 | switch (holder.getItemViewType()) { |
| 900 | case 1: { |
| 901 | if (position == experiment2Row) { |
| 902 | holder.itemView.setBackground(Theme.getThemedDrawable(mContext, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow)); |
| 903 | } else { |
| 904 | holder.itemView.setBackground(Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow)); |
| 905 | } |
| 906 | break; |
| 907 | } |
| 908 | case 2: { |
| 909 | TextSettingsCell textCell = (TextSettingsCell) holder.itemView; |
| 910 | textCell.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); |
| 911 | if (position == nameOrderRow) { |
| 912 | String value; |
| 913 | switch (NekoConfig.nameOrder) { |
| 914 | case 2: |
| 915 | value = LocaleController.getString("LastFirst", R.string.LastFirst); |
| 916 | break; |
| 917 | case 1: |
| 918 | default: |
| 919 | value = LocaleController.getString("FirstLast", R.string.FirstLast); |
| 920 | break; |
| 921 | } |
| 922 | textCell.setTextAndValue(LocaleController.getString("NameOrder", R.string.NameOrder), value, eventTypeRow != -1); |
| 923 | } else if (position == mapPreviewRow) { |
| 924 | String value; |
| 925 | switch (NekoConfig.mapPreviewProvider) { |
| 926 | case 0: |
| 927 | value = LocaleController.getString("MapPreviewProviderTelegram", R.string.MapPreviewProviderTelegram); |
| 928 | break; |
| 929 | case 1: |
| 930 | value = LocaleController.getString("MapPreviewProviderYandex", R.string.MapPreviewProviderYandex); |
| 931 | break; |
| 932 | case 2: |
| 933 | default: |
| 934 | value = LocaleController.getString("MapPreviewProviderNobody", R.string.MapPreviewProviderNobody); |
| 935 | } |
| 936 | textCell.setTextAndValue(LocaleController.getString("MapPreviewProvider", R.string.MapPreviewProvider), value, true); |
| 937 | } else if (position == eventTypeRow) { |
| 938 | String value; |
| 939 | switch (NekoConfig.eventType) { |
| 940 | case 1: |
| 941 | value = LocaleController.getString("Christmas", R.string.Christmas); |
| 942 | break; |
| 943 | case 2: |
| 944 | value = LocaleController.getString("Valentine", R.string.Valentine); |
| 945 | break; |
| 946 | case 0: |
| 947 | default: |
| 948 | value = LocaleController.getString("DependsOnDate", R.string.DependsOnDate); |
| 949 | } |
| 950 | textCell.setTextAndValue(LocaleController.getString("EventType", R.string.EventType), value, true); |
| 951 | } else if (position == actionBarDecorationRow) { |
| 952 | String value; |
| 953 | switch (NekoConfig.actionBarDecoration) { |
| 954 | case 1: |
| 955 | value = LocaleController.getString("Snowflakes", R.string.Snowflakes); |
| 956 | break; |
| 957 | case 2: |
| 958 | value = LocaleController.getString("Fireworks", R.string.Fireworks); |
| 959 | break; |
| 960 | case 0: |
| 961 | default: |
| 962 | value = LocaleController.getString("DependsOnDate", R.string.DependsOnDate); |
| 963 | } |
| 964 | textCell.setTextAndValue(LocaleController.getString("ActionBarDecoration", R.string.ActionBarDecoration), value, false); |
| 965 | } else if (position == stickerSizeRow) { |
| 966 | textCell.setTextAndValue(LocaleController.getString("StickerSize", R.string.StickerSize), String.valueOf(Math.round(NekoConfig.stickerSize)), true); |
| 967 | } else if (position == messageMenuRow) { |
| 968 | textCell.setText(LocaleController.getString("MessageMenu", R.string.MessageMenu), true); |
| 969 | } else if (position == deleteAccountRow) { |
| 970 | textCell.setText(LocaleController.getString("DeleteAccount", R.string.DeleteAccount), false); |
| 971 | textCell.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText)); |
| 972 | } else if (position == translationProviderRow) { |
| 973 | String value; |
| 974 | switch (NekoConfig.translationProvider) { |
| 975 | case 1: |
| 976 | value = LocaleController.getString("ProviderGoogleTranslate", R.string.ProviderGoogleTranslate); |
| 977 | break; |
| 978 | case -1: |
| 979 | value = LocaleController.getString("ProviderGoogleTranslateWeb", R.string.ProviderGoogleTranslateWeb); |
| 980 | break; |
| 981 | case 2: |
| 982 | value = LocaleController.getString("ProviderGoogleTranslateCN", R.string.ProviderGoogleTranslateCN); |
| 983 | break; |
| 984 | case -2: |
| 985 | value = LocaleController.getString("ProviderGoogleTranslateCNWeb", R.string.ProviderGoogleTranslateCNWeb); |
| 986 | break; |
| 987 | case -3: |
| 988 | value = LocaleController.getString("ProviderBaiduFanyiWeb", R.string.ProviderBaiduFanyiWeb); |
| 989 | break; |
| 990 | case 3: |
| 991 | default: |
| 992 | value = LocaleController.getString("ProviderLingocloud", R.string.ProviderLingocloud); |
| 993 | break; |
| 994 | } |
| 995 | textCell.setTextAndValue(LocaleController.getString("TranslationProvider", R.string.TranslationProvider), value, false); |
| 996 | } |
| 997 | break; |
| 998 | } |
| 999 | case 3: { |
| 1000 | TextCheckCell textCell = (TextCheckCell) holder.itemView; |
| 1001 | textCell.setEnabled(true, null); |
| 1002 | if (position == ipv6Row) { |
| 1003 | textCell.setTextAndCheck(LocaleController.getString("IPv6", R.string.IPv6), NekoConfig.useIPv6, false); |
| 1004 | } else if (position == hidePhoneRow) { |
| 1005 | textCell.setTextAndCheck(LocaleController.getString("HidePhone", R.string.HidePhone), NekoConfig.hidePhone, true); |
| 1006 | } else if (position == inappCameraRow) { |
| 1007 | textCell.setTextAndCheck(LocaleController.getString("DebugMenuEnableCamera", R.string.DebugMenuEnableCamera), SharedConfig.inappCamera, true); |
| 1008 | } else if (position == transparentStatusBarRow) { |
| 1009 | textCell.setTextAndCheck(LocaleController.getString("TransparentStatusBar", R.string.TransparentStatusBar), NekoConfig.transparentStatusBar, true); |
| 1010 | } else if (position == hideProxySponsorChannelRow) { |
| 1011 | textCell.setTextAndCheck(LocaleController.getString("HideProxySponsorChannel", R.string.HideProxySponsorChannel), NekoConfig.hideProxySponsorChannel, true); |
| 1012 | } else if (position == saveCacheToPrivateDirectoryRow) { |
| 1013 | textCell.setTextAndCheck(LocaleController.getString("SaveCacheToPrivateDirectory", R.string.SaveCacheToPrivateDirectory), NekoConfig.saveCacheToPrivateDirectory, true); |
| 1014 | } else if (position == useSystemEmojiRow) { |
| 1015 | textCell.setTextAndCheck(LocaleController.getString("EmojiUseDefault", R.string.EmojiUseDefault), NekoConfig.useSystemEmoji, true); |
| 1016 | } else if (position == typefaceRow) { |
| 1017 | textCell.setTextAndCheck(LocaleController.getString("TypefaceUseDefault", R.string.TypefaceUseDefault), NekoConfig.typeface == 1, true); |
| 1018 | } else if (position == ignoreBlockedRow) { |
| 1019 | textCell.setTextAndCheck(LocaleController.getString("IgnoreBlocked", R.string.IgnoreBlocked), NekoConfig.ignoreBlocked, true); |
| 1020 | } else if (position == forceTabletRow) { |
| 1021 | textCell.setTextAndCheck(LocaleController.getString("ForceTabletMode", R.string.ForceTabletMode), NekoConfig.forceTablet, true); |
| 1022 | } else if (position == newYearRow) { |
| 1023 | textCell.setTextAndCheck(LocaleController.getString("ChristmasHat", R.string.ChristmasHat), NekoConfig.newYear, true); |
| 1024 | } else if (position == disableFilteringRow) { |
| 1025 | textCell.setTextAndValueAndCheck(LocaleController.getString("SensitiveDisableFiltering", R.string.SensitiveDisableFiltering), LocaleController.getString("SensitiveAbout", R.string.SensitiveAbout), sensitiveEnabled, true, true); |
| 1026 | textCell.setEnabled(sensitiveCanChange, null); |
| 1027 | } else if (position == unlimitedFavedStickersRow) { |
| 1028 | textCell.setTextAndValueAndCheck(LocaleController.getString("UnlimitedFavoredStickers", R.string.UnlimitedFavoredStickers), LocaleController.getString("UnlimitedFavoredStickersAbout", R.string.UnlimitedFavoredStickersAbout), NekoConfig.unlimitedFavedStickers, true, true); |
| 1029 | } else if (position == pauseMusicOnRecordRow) { |
| 1030 | textCell.setTextAndCheck(LocaleController.getString("DebugMenuEnablePauseMusic", R.string.DebugMenuEnablePauseMusic), SharedConfig.pauseMusicOnRecord, true); |
| 1031 | } else if (position == smoothKeyboardRow) { |
| 1032 | textCell.setTextAndCheck(LocaleController.getString("DebugMenuEnableSmoothKeyboard", R.string.DebugMenuEnableSmoothKeyboard), SharedConfig.smoothKeyboard, true); |
| 1033 | } else if (position == disablePhotoSideActionRow) { |
| 1034 | textCell.setTextAndCheck(LocaleController.getString("DisablePhotoViewerSideAction", R.string.DisablePhotoViewerSideAction), NekoConfig.disablePhotoSideAction, true); |
| 1035 | } else if (position == unlimitedPinnedDialogsRow) { |
| 1036 | textCell.setTextAndValueAndCheck(LocaleController.getString("UnlimitedPinnedDialogs", R.string.UnlimitedPinnedDialogs), LocaleController.getString("UnlimitedPinnedDialogsAbout", R.string.UnlimitedPinnedDialogsAbout), NekoConfig.unlimitedPinnedDialogs, true, deleteAccountRow != -1); |
| 1037 | } else if (position == openArchiveOnPullRow) { |
| 1038 | textCell.setTextAndCheck(LocaleController.getString("OpenArchiveOnPull", R.string.OpenArchiveOnPull), NekoConfig.openArchiveOnPull, true); |
| 1039 | } else if (position == hideKeyboardOnChatScrollRow) { |
| 1040 | textCell.setTextAndCheck(LocaleController.getString("HideKeyboardOnChatScroll", R.string.HideKeyboardOnChatScroll), NekoConfig.hideKeyboardOnChatScroll, true); |
| 1041 | } else if (position == avatarAsDrawerBackgroundRow) { |
| 1042 | textCell.setTextAndCheck(LocaleController.getString("UseAvatarAsDrawerBackground", R.string.UseAvatarAsDrawerBackground), NekoConfig.avatarAsDrawerBackground, true); |
| 1043 | } |
| 1044 | break; |
| 1045 | } |
| 1046 | case 4: { |
| 1047 | HeaderCell headerCell = (HeaderCell) holder.itemView; |
| 1048 | if (position == settingsRow) { |
| 1049 | headerCell.setText(LocaleController.getString("General", R.string.General)); |
| 1050 | } else if (position == connectionRow) { |
| 1051 | headerCell.setText(LocaleController.getString("Connection", R.string.Connection)); |
| 1052 | } else if (position == chatRow) { |
| 1053 | headerCell.setText(LocaleController.getString("Chat", R.string.Chat)); |
| 1054 | } else if (position == experimentRow) { |
| 1055 | headerCell.setText(LocaleController.getString("Experiment", R.string.Experiment)); |
| 1056 | } |
| 1057 | break; |
| 1058 | } |
| 1059 | case 7: { |
| 1060 | TextInfoPrivacyCell cell = (TextInfoPrivacyCell) holder.itemView; |
| 1061 | if (position == needRestartRow) { |
| 1062 | cell.setText(LocaleController.getString("SomeItemsNeedRestart", R.string.SomeItemsNeedRestart)); |
| 1063 | } |
| 1064 | break; |
| 1065 | } |
| 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | @Override |
| 1070 | public boolean isEnabled(RecyclerView.ViewHolder holder) { |
| 1071 | int position = holder.getAdapterPosition(); |
| 1072 | return position == hidePhoneRow || position == inappCameraRow || position == ignoreBlockedRow || |
| 1073 | position == useSystemEmojiRow || position == ipv6Row || position == typefaceRow || position == nameOrderRow || |
| 1074 | position == forceTabletRow || position == mapPreviewRow || position == newYearRow || |
| 1075 | position == actionBarDecorationRow || position == eventTypeRow || position == transparentStatusBarRow || |
| 1076 | position == hideProxySponsorChannelRow || position == saveCacheToPrivateDirectoryRow || |
| 1077 | position == disableFilteringRow || position == stickerSizeRow || |
| 1078 | position == unlimitedFavedStickersRow || position == messageMenuRow || position == deleteAccountRow || |
| 1079 | position == translationProviderRow || position == smoothKeyboardRow || position == pauseMusicOnRecordRow || |
| 1080 | position == disablePhotoSideActionRow || position == unlimitedPinnedDialogsRow || position == openArchiveOnPullRow || |
| 1081 | position == connection2Row || position == hideKeyboardOnChatScrollRow || position == avatarAsDrawerBackgroundRow; |
| 1082 | } |
| 1083 | |
| 1084 | @Override |
| 1085 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { |
| 1086 | View view = null; |
| 1087 | switch (viewType) { |
| 1088 | case 1: |
| 1089 | view = new ShadowSectionCell(mContext); |
| 1090 | break; |
| 1091 | case 2: |
| 1092 | view = new TextSettingsCell(mContext); |
| 1093 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 1094 | break; |
| 1095 | case 3: |
| 1096 | view = new TextCheckCell(mContext); |
| 1097 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 1098 | break; |
| 1099 | case 4: |
| 1100 | view = new HeaderCell(mContext); |
| 1101 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 1102 | break; |
| 1103 | case 5: |
| 1104 | view = new NotificationsCheckCell(mContext); |
| 1105 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 1106 | break; |
| 1107 | case 6: |
| 1108 | view = new TextDetailSettingsCell(mContext); |
| 1109 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 1110 | break; |
| 1111 | case 7: |
| 1112 | view = new TextInfoPrivacyCell(mContext); |
| 1113 | view.setBackground(Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow)); |
| 1114 | break; |
| 1115 | } |
| 1116 | //noinspection ConstantConditions |
| 1117 | view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT)); |
| 1118 | return new RecyclerListView.Holder(view); |
| 1119 | } |
| 1120 | |
| 1121 | @Override |
| 1122 | public int getItemViewType(int position) { |
| 1123 | if (position == connection2Row || position == chat2Row || position == experiment2Row) { |
| 1124 | return 1; |
| 1125 | } else if (position == nameOrderRow || position == mapPreviewRow || position == stickerSizeRow || position == messageMenuRow || |
| 1126 | position == deleteAccountRow || position == translationProviderRow || position == eventTypeRow || position == actionBarDecorationRow) { |
| 1127 | return 2; |
| 1128 | } else if (position == ipv6Row || position == hidePhoneRow || position == inappCameraRow || |
| 1129 | position == transparentStatusBarRow || position == hideProxySponsorChannelRow || |
| 1130 | position == ignoreBlockedRow || position == useSystemEmojiRow || position == typefaceRow || |
| 1131 | position == forceTabletRow || position == newYearRow || |
| 1132 | position == saveCacheToPrivateDirectoryRow || position == unlimitedFavedStickersRow || |
| 1133 | position == disableFilteringRow || position == smoothKeyboardRow || position == pauseMusicOnRecordRow || |
| 1134 | position == disablePhotoSideActionRow || position == unlimitedPinnedDialogsRow || position == openArchiveOnPullRow || |
| 1135 | position == hideKeyboardOnChatScrollRow || position == avatarAsDrawerBackgroundRow) { |
| 1136 | return 3; |
| 1137 | } else if (position == settingsRow || position == connectionRow || position == chatRow || position == experimentRow) { |
| 1138 | return 4; |
| 1139 | } else if (position == needRestartRow) { |
| 1140 | return 7; |
| 1141 | } |
| 1142 | return 6; |
| 1143 | } |
| 1144 | } |
| 1145 | } |
| 1146 | |