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