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