| 1 | package tw.nekomimi.nekogram; |
| 2 | |
| 3 | import android.annotation.SuppressLint; |
| 4 | import android.content.Context; |
| 5 | import android.content.DialogInterface; |
| 6 | import android.content.SharedPreferences; |
| 7 | import android.os.Build; |
| 8 | import android.util.TypedValue; |
| 9 | import android.view.Gravity; |
| 10 | import android.view.View; |
| 11 | import android.view.ViewGroup; |
| 12 | import android.view.inputmethod.EditorInfo; |
| 13 | import android.widget.FrameLayout; |
| 14 | |
| 15 | import androidx.recyclerview.widget.LinearLayoutManager; |
| 16 | import androidx.recyclerview.widget.RecyclerView; |
| 17 | |
| 18 | import org.telegram.messenger.AndroidUtilities; |
| 19 | import org.telegram.messenger.ApplicationLoader; |
| 20 | import org.telegram.messenger.BuildVars; |
| 21 | import org.telegram.messenger.FileLog; |
| 22 | import org.telegram.messenger.LocaleController; |
| 23 | import org.telegram.messenger.MessagesController; |
| 24 | import org.telegram.messenger.R; |
| 25 | import org.telegram.messenger.SharedConfig; |
| 26 | import org.telegram.messenger.UserConfig; |
| 27 | import org.telegram.tgnet.ConnectionsManager; |
| 28 | import org.telegram.ui.ActionBar.ActionBar; |
| 29 | import org.telegram.ui.ActionBar.AlertDialog; |
| 30 | import org.telegram.ui.ActionBar.BaseFragment; |
| 31 | import org.telegram.ui.ActionBar.Theme; |
| 32 | import org.telegram.ui.ActionBar.ThemeDescription; |
| 33 | import org.telegram.ui.Cells.EmptyCell; |
| 34 | import org.telegram.ui.Cells.HeaderCell; |
| 35 | import org.telegram.ui.Cells.NotificationsCheckCell; |
| 36 | import org.telegram.ui.Cells.ShadowSectionCell; |
| 37 | import org.telegram.ui.Cells.TextCell; |
| 38 | import org.telegram.ui.Cells.TextCheckCell; |
| 39 | import org.telegram.ui.Cells.TextDetailSettingsCell; |
| 40 | import org.telegram.ui.Cells.TextSettingsCell; |
| 41 | import org.telegram.ui.Components.EditTextBoldCursor; |
| 42 | import org.telegram.ui.Components.LayoutHelper; |
| 43 | import org.telegram.ui.Components.RecyclerListView; |
| 44 | |
| 45 | public class NekoSettingsActivity extends BaseFragment { |
| 46 | |
| 47 | private RecyclerListView listView; |
| 48 | private ListAdapter listAdapter; |
| 49 | |
| 50 | private int rowCount; |
| 51 | |
| 52 | private int connectionRow; |
| 53 | private int ipv6Row; |
| 54 | private int connection2Row; |
| 55 | |
| 56 | private int emojiRow; |
| 57 | private int useSystemEmojiRow; |
| 58 | private int singleBigEmojiRow; |
| 59 | private int emoji2Row; |
| 60 | |
| 61 | private int chatRow; |
| 62 | private int ignoreBlockedRow; |
| 63 | private int nyaRow; |
| 64 | private int nyaSuffixRow; |
| 65 | private int chat2Row; |
| 66 | |
| 67 | private int settingsRow; |
| 68 | private int hidePhoneRow; |
| 69 | private int inappCameraRow; |
| 70 | private int nameOrderRow; |
| 71 | private int transparentStatusBarRow; |
| 72 | private int navigationBarTintRow; |
| 73 | private int navigationBarColorRow; |
| 74 | private int forceTabletRow; |
| 75 | private int settings2Row; |
| 76 | |
| 77 | @Override |
| 78 | public boolean onFragmentCreate() { |
| 79 | super.onFragmentCreate(); |
| 80 | |
| 81 | updateRows(false); |
| 82 | |
| 83 | return true; |
| 84 | } |
| 85 | |
| 86 | @SuppressLint("NewApi") |
| 87 | @Override |
| 88 | public View createView(Context context) { |
| 89 | actionBar.setBackButtonImage(R.drawable.ic_ab_back); |
| 90 | actionBar.setTitle(LocaleController.getString("NekoSettings", R.string.NekoSettings)); |
| 91 | |
| 92 | if (AndroidUtilities.isTablet()) { |
| 93 | actionBar.setOccupyStatusBar(false); |
| 94 | } |
| 95 | actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { |
| 96 | @Override |
| 97 | public void onItemClick(int id) { |
| 98 | if (id == -1) { |
| 99 | finishFragment(); |
| 100 | } |
| 101 | } |
| 102 | }); |
| 103 | |
| 104 | listAdapter = new ListAdapter(context); |
| 105 | |
| 106 | fragmentView = new FrameLayout(context); |
| 107 | fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray)); |
| 108 | FrameLayout frameLayout = (FrameLayout) fragmentView; |
| 109 | |
| 110 | listView = new RecyclerListView(context); |
| 111 | listView.setVerticalScrollBarEnabled(false); |
| 112 | listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) { |
| 113 | @Override |
| 114 | public boolean supportsPredictiveItemAnimations() { |
| 115 | return false; |
| 116 | } |
| 117 | }); |
| 118 | listView.setGlowColor(Theme.getColor(Theme.key_avatar_backgroundActionBarBlue)); |
| 119 | listView.setAdapter(listAdapter); |
| 120 | listView.setItemAnimator(null); |
| 121 | listView.setLayoutAnimation(null); |
| 122 | frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); |
| 123 | listView.setOnItemClickListener((view, position, x, y) -> { |
| 124 | if (position == ipv6Row) { |
| 125 | NekoConfig.toggleIPv6(); |
| 126 | if (view instanceof TextCheckCell) { |
| 127 | ((TextCheckCell) view).setChecked(NekoConfig.useIPv6); |
| 128 | } |
| 129 | for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) { |
| 130 | if (UserConfig.getInstance(a).isClientActivated()) { |
| 131 | ConnectionsManager.native_setUseIpv6(a, NekoConfig.useIPv6); |
| 132 | } |
| 133 | } |
| 134 | } else if (position == hidePhoneRow) { |
| 135 | NekoConfig.toggleHidePhone(); |
| 136 | if (view instanceof TextCheckCell) { |
| 137 | ((TextCheckCell) view).setChecked(NekoConfig.hidePhone); |
| 138 | } |
| 139 | } else if (position == inappCameraRow) { |
| 140 | SharedConfig.toggleInappCamera(); |
| 141 | if (view instanceof TextCheckCell) { |
| 142 | ((TextCheckCell) view).setChecked(SharedConfig.inappCamera); |
| 143 | } |
| 144 | } else if (position == forceTabletRow) { |
| 145 | NekoConfig.toggleForceTablet(); |
| 146 | if (view instanceof TextCheckCell) { |
| 147 | ((TextCheckCell) view).setChecked(NekoConfig.forceTablet); |
| 148 | } |
| 149 | } else if (position == ignoreBlockedRow) { |
| 150 | NekoConfig.toggleIgnoreBlocked(); |
| 151 | if (view instanceof TextCheckCell) { |
| 152 | ((TextCheckCell) view).setChecked(NekoConfig.ignoreBlocked); |
| 153 | } |
| 154 | } else if (position == nyaRow) { |
| 155 | NekoConfig.toggleNya(); |
| 156 | if (view instanceof TextCheckCell) { |
| 157 | ((TextCheckCell) view).setChecked(NekoConfig.nya); |
| 158 | } |
| 159 | updateRows(true); |
| 160 | } else if (position == transparentStatusBarRow) { |
| 161 | if (!(NekoConfig.navigationBarTint || Build.VERSION.SDK_INT < Build.VERSION_CODES.O)) |
| 162 | return; |
| 163 | NekoConfig.toggleTransparentStatusBar(); |
| 164 | if (view instanceof TextCheckCell) { |
| 165 | ((TextCheckCell) view).setChecked(NekoConfig.transparentStatusBar); |
| 166 | } |
| 167 | UIHelper.updateStatusBarColor(getParentActivity()); |
| 168 | } else if (position == navigationBarTintRow) { |
| 169 | NekoConfig.toggleNavigationBarTint(); |
| 170 | if (view instanceof TextCheckCell) { |
| 171 | ((TextCheckCell) view).setChecked(NekoConfig.navigationBarTint); |
| 172 | } |
| 173 | updateRows(true); |
| 174 | UIHelper.updateStatusBarColor(getParentActivity()); |
| 175 | UIHelper.updateNavigationBarColor(getParentActivity()); |
| 176 | } else if (position == navigationBarColorRow) { |
| 177 | if (!NekoConfig.navigationBarTint) |
| 178 | return; |
| 179 | AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); |
| 180 | builder.setTitle(LocaleController.getString("NavigationBarColor", R.string.NavigationBarColor)); |
| 181 | CharSequence[] items = new CharSequence[]{ |
| 182 | LocaleController.getString("NavigationBarColorBlack", R.string.NavigationBarColorBlack), |
| 183 | LocaleController.getString("NavigationBarColorActionBar", R.string.NavigationBarColorActionBar), |
| 184 | LocaleController.getString("NavigationBarColorMessagePanel", R.string.NavigationBarColorMessagePanel), |
| 185 | }; |
| 186 | builder.setItems(items, (dialog, which) -> { |
| 187 | NekoConfig.setNavigationBarColor(which + 1); |
| 188 | listAdapter.notifyItemChanged(navigationBarColorRow); |
| 189 | UIHelper.updateNavigationBarColor(getParentActivity()); |
| 190 | }); |
| 191 | showDialog(builder.create()); |
| 192 | } else if (position == useSystemEmojiRow) { |
| 193 | SharedConfig.useSystemEmoji = !SharedConfig.useSystemEmoji; |
| 194 | SharedPreferences.Editor editor = MessagesController.getGlobalMainSettings().edit(); |
| 195 | editor.putBoolean("useSystemEmoji", SharedConfig.useSystemEmoji); |
| 196 | editor.commit(); |
| 197 | if (view instanceof TextCheckCell) { |
| 198 | ((TextCheckCell) view).setChecked(SharedConfig.useSystemEmoji); |
| 199 | } |
| 200 | } else if (position == singleBigEmojiRow) { |
| 201 | SharedConfig.allowBigEmoji = !SharedConfig.allowBigEmoji; |
| 202 | SharedPreferences.Editor editor = MessagesController.getGlobalMainSettings().edit(); |
| 203 | editor.putBoolean("allowBigEmoji", SharedConfig.allowBigEmoji); |
| 204 | editor.commit(); |
| 205 | if (view instanceof TextCheckCell) { |
| 206 | ((TextCheckCell) view).setChecked(SharedConfig.allowBigEmoji); |
| 207 | } |
| 208 | } else if (position == nameOrderRow) { |
| 209 | AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); |
| 210 | builder.setTitle(LocaleController.getString("NameOrder", R.string.NameOrder)); |
| 211 | CharSequence[] items = new CharSequence[]{ |
| 212 | LocaleController.getString("FirstLast", R.string.FirstLast), |
| 213 | LocaleController.getString("LastFirst", R.string.LastFirst), |
| 214 | }; |
| 215 | builder.setItems(items, (dialog, which) -> { |
| 216 | NekoConfig.setNameOrder(which + 1); |
| 217 | listAdapter.notifyItemChanged(nameOrderRow); |
| 218 | }); |
| 219 | showDialog(builder.create()); |
| 220 | } else if (position == nyaSuffixRow) { |
| 221 | if (!NekoConfig.nya) |
| 222 | return; |
| 223 | |
| 224 | AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 225 | builder.setTitle(LocaleController.getString("NyaSuffix", R.string.NyaSuffix)); |
| 226 | |
| 227 | final EditTextBoldCursor editText = new EditTextBoldCursor(context) { |
| 228 | @Override |
| 229 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 230 | super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(64), MeasureSpec.EXACTLY)); |
| 231 | } |
| 232 | }; |
| 233 | editText.setText(NekoConfig.nyaSuffix); |
| 234 | editText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack)); |
| 235 | editText.setHintText(LocaleController.getString("NyaSuffixHint", R.string.NyaSuffixHint)); |
| 236 | editText.setHeaderHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader)); |
| 237 | editText.setSingleLine(true); |
| 238 | editText.setFocusable(true); |
| 239 | editText.setTransformHintToHeader(true); |
| 240 | editText.setLineColors(Theme.getColor(Theme.key_windowBackgroundWhiteInputField), Theme.getColor(Theme.key_windowBackgroundWhiteInputFieldActivated), Theme.getColor(Theme.key_windowBackgroundWhiteRedText3)); |
| 241 | editText.setImeOptions(EditorInfo.IME_ACTION_DONE); |
| 242 | editText.setBackgroundDrawable(null); |
| 243 | editText.requestFocus(); |
| 244 | editText.setPadding(0, 0, 0, 0); |
| 245 | builder.setView(editText); |
| 246 | |
| 247 | |
| 248 | builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { |
| 249 | @Override |
| 250 | public void onClick(DialogInterface dialogInterface, int i) { |
| 251 | if (getParentActivity() == null) { |
| 252 | return; |
| 253 | } |
| 254 | String suffix = editText.getText().toString(); |
| 255 | NekoConfig.setNyaSuffix(suffix); |
| 256 | listAdapter.notifyItemChanged(nyaSuffixRow); |
| 257 | } |
| 258 | }); |
| 259 | builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); |
| 260 | builder.show().setOnShowListener(new DialogInterface.OnShowListener() { |
| 261 | @Override |
| 262 | public void onShow(DialogInterface dialog) { |
| 263 | editText.requestFocus(); |
| 264 | AndroidUtilities.showKeyboard(editText); |
| 265 | } |
| 266 | }); |
| 267 | if (editText != null) { |
| 268 | ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) editText.getLayoutParams(); |
| 269 | if (layoutParams != null) { |
| 270 | if (layoutParams instanceof FrameLayout.LayoutParams) { |
| 271 | ((FrameLayout.LayoutParams) layoutParams).gravity = Gravity.CENTER_HORIZONTAL; |
| 272 | } |
| 273 | layoutParams.rightMargin = layoutParams.leftMargin = AndroidUtilities.dp(24); |
| 274 | layoutParams.height = AndroidUtilities.dp(36); |
| 275 | editText.setLayoutParams(layoutParams); |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | }); |
| 280 | |
| 281 | return fragmentView; |
| 282 | } |
| 283 | |
| 284 | @Override |
| 285 | public void onResume() { |
| 286 | super.onResume(); |
| 287 | if (listAdapter != null) { |
| 288 | listAdapter.notifyDataSetChanged(); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | private void updateRows(boolean notify) { |
| 293 | rowCount = 0; |
| 294 | connectionRow = rowCount++; |
| 295 | ipv6Row = rowCount++; |
| 296 | connection2Row = rowCount++; |
| 297 | emojiRow = rowCount++; |
| 298 | useSystemEmojiRow = rowCount++; |
| 299 | singleBigEmojiRow = rowCount++; |
| 300 | emoji2Row = rowCount++; |
| 301 | chatRow = rowCount++; |
| 302 | ignoreBlockedRow = rowCount++; |
| 303 | nyaRow = rowCount++; |
| 304 | nyaSuffixRow = rowCount++; |
| 305 | chat2Row = rowCount++; |
| 306 | settingsRow = rowCount++; |
| 307 | hidePhoneRow = rowCount++; |
| 308 | inappCameraRow = rowCount++; |
| 309 | navigationBarTintRow = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? rowCount++ : -1; |
| 310 | transparentStatusBarRow = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? rowCount++ : -1; |
| 311 | navigationBarColorRow = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? rowCount++ : -1; |
| 312 | forceTabletRow = rowCount++; |
| 313 | nameOrderRow = rowCount++; |
| 314 | settings2Row = rowCount++; |
| 315 | if (notify && listAdapter != null) { |
| 316 | listAdapter.notifyDataSetChanged(); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | @Override |
| 321 | public ThemeDescription[] getThemeDescriptions() { |
| 322 | return new ThemeDescription[]{ |
| 323 | 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), |
| 324 | new ThemeDescription(fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundGray), |
| 325 | |
| 326 | new ThemeDescription(actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_avatar_backgroundActionBarBlue), |
| 327 | new ThemeDescription(listView, ThemeDescription.FLAG_LISTGLOWCOLOR, null, null, null, null, Theme.key_avatar_backgroundActionBarBlue), |
| 328 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_ITEMSCOLOR, null, null, null, null, Theme.key_avatar_actionBarIconBlue), |
| 329 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_TITLECOLOR, null, null, null, null, Theme.key_actionBarDefaultTitle), |
| 330 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SELECTORCOLOR, null, null, null, null, Theme.key_avatar_actionBarSelectorBlue), |
| 331 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SUBMENUBACKGROUND, null, null, null, null, Theme.key_actionBarDefaultSubmenuBackground), |
| 332 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SUBMENUITEM, null, null, null, null, Theme.key_actionBarDefaultSubmenuItem), |
| 333 | |
| 334 | new ThemeDescription(listView, ThemeDescription.FLAG_SELECTOR, null, null, null, null, Theme.key_listSelector), |
| 335 | |
| 336 | new ThemeDescription(listView, 0, new Class[]{View.class}, Theme.dividerPaint, null, null, Theme.key_divider), |
| 337 | |
| 338 | new ThemeDescription(listView, ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{ShadowSectionCell.class}, null, null, null, Theme.key_windowBackgroundGrayShadow), |
| 339 | |
| 340 | new ThemeDescription(listView, 0, new Class[]{TextSettingsCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText), |
| 341 | new ThemeDescription(listView, 0, new Class[]{TextSettingsCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteValueText), |
| 342 | |
| 343 | new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText), |
| 344 | new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2), |
| 345 | new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrack), |
| 346 | new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrackChecked), |
| 347 | |
| 348 | new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText), |
| 349 | new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2), |
| 350 | new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrack), |
| 351 | new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrackChecked), |
| 352 | |
| 353 | new ThemeDescription(listView, 0, new Class[]{HeaderCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlueHeader), |
| 354 | |
| 355 | new ThemeDescription(listView, 0, new Class[]{TextDetailSettingsCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText), |
| 356 | new ThemeDescription(listView, 0, new Class[]{TextDetailSettingsCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2), |
| 357 | }; |
| 358 | } |
| 359 | |
| 360 | private class ListAdapter extends RecyclerListView.SelectionAdapter { |
| 361 | |
| 362 | private Context mContext; |
| 363 | |
| 364 | public ListAdapter(Context context) { |
| 365 | mContext = context; |
| 366 | } |
| 367 | |
| 368 | @Override |
| 369 | public int getItemCount() { |
| 370 | return rowCount; |
| 371 | } |
| 372 | |
| 373 | @Override |
| 374 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { |
| 375 | switch (holder.getItemViewType()) { |
| 376 | case 1: { |
| 377 | break; |
| 378 | } |
| 379 | case 2: { |
| 380 | TextSettingsCell textCell = (TextSettingsCell) holder.itemView; |
| 381 | if (position == nameOrderRow) { |
| 382 | String value; |
| 383 | switch (NekoConfig.nameOrder) { |
| 384 | case 2: |
| 385 | value = LocaleController.getString("LastFirst", R.string.LastFirst); |
| 386 | break; |
| 387 | case 1: |
| 388 | default: |
| 389 | value = LocaleController.getString("FirstLast", R.string.FirstLast); |
| 390 | break; |
| 391 | } |
| 392 | textCell.setTextAndValue(LocaleController.getString("NameOrder", R.string.NameOrder), value, false); |
| 393 | } else if (position == navigationBarColorRow) { |
| 394 | String value; |
| 395 | switch (NekoConfig.navigationBarColor) { |
| 396 | case 3: |
| 397 | value = LocaleController.getString("NavigationBarColorMessagePanel", R.string.NavigationBarColorMessagePanel); |
| 398 | break; |
| 399 | case 2: |
| 400 | value = LocaleController.getString("NavigationBarColorActionBar", R.string.NavigationBarColorActionBar); |
| 401 | break; |
| 402 | case 1: |
| 403 | default: |
| 404 | value = LocaleController.getString("NavigationBarColorBlack", R.string.NavigationBarColorBlack); |
| 405 | } |
| 406 | textCell.setTextAndValue(LocaleController.getString("NavigationBarColor", R.string.NavigationBarColor), value, true); |
| 407 | } |
| 408 | break; |
| 409 | } |
| 410 | case 3: { |
| 411 | TextCheckCell textCell = (TextCheckCell) holder.itemView; |
| 412 | if (position == ipv6Row) { |
| 413 | textCell.setTextAndCheck(LocaleController.getString("IPv6", R.string.IPv6), NekoConfig.useIPv6, false); |
| 414 | } else if (position == hidePhoneRow) { |
| 415 | textCell.setTextAndCheck(LocaleController.getString("HidePhone", R.string.HidePhone), NekoConfig.hidePhone, true); |
| 416 | } else if (position == inappCameraRow) { |
| 417 | textCell.setTextAndCheck(LocaleController.getString("DebugMenuEnableCamera", R.string.DebugMenuEnableCamera), SharedConfig.inappCamera, true); |
| 418 | } else if (position == transparentStatusBarRow) { |
| 419 | textCell.setTextAndCheck(LocaleController.getString("TransparentStatusBar", R.string.TransparentStatusBar), NekoConfig.transparentStatusBar, true); |
| 420 | } else if (position == navigationBarTintRow) { |
| 421 | textCell.setTextAndCheck(LocaleController.getString("NavigationBarTint", R.string.NavigationBarTint), NekoConfig.navigationBarTint, true); |
| 422 | } else if (position == useSystemEmojiRow) { |
| 423 | textCell.setTextAndCheck(LocaleController.getString("EmojiUseDefault", R.string.EmojiUseDefault), SharedConfig.useSystemEmoji, true); |
| 424 | } else if (position == singleBigEmojiRow) { |
| 425 | textCell.setTextAndCheck(LocaleController.getString("EmojiBigSize", R.string.EmojiBigSize), SharedConfig.allowBigEmoji, false); |
| 426 | } else if (position == ignoreBlockedRow) { |
| 427 | textCell.setTextAndCheck(LocaleController.getString("IgnoreBlocked", R.string.IgnoreBlocked), NekoConfig.ignoreBlocked, true); |
| 428 | } else if (position == forceTabletRow) { |
| 429 | textCell.setTextAndCheck(LocaleController.getString("ForceTabletMode", R.string.ForceTabletMode), NekoConfig.forceTablet, true); |
| 430 | } else if (position == nyaRow) { |
| 431 | textCell.setTextAndCheck(LocaleController.getString("EnableNya", R.string.EnableNya), NekoConfig.nya, true); |
| 432 | } |
| 433 | break; |
| 434 | } |
| 435 | case 4: { |
| 436 | HeaderCell headerCell = (HeaderCell) holder.itemView; |
| 437 | if (position == settingsRow) { |
| 438 | headerCell.setText(LocaleController.getString("Settings", R.string.Settings)); |
| 439 | } else if (position == emojiRow) { |
| 440 | headerCell.setText(LocaleController.getString("Emoji", R.string.Emoji)); |
| 441 | } else if (position == connectionRow) { |
| 442 | headerCell.setText(LocaleController.getString("Connection", R.string.Connection)); |
| 443 | } else if (position == chatRow) { |
| 444 | headerCell.setText(LocaleController.getString("Chat", R.string.Chat)); |
| 445 | } |
| 446 | break; |
| 447 | } |
| 448 | case 6: { |
| 449 | TextDetailSettingsCell textCell = (TextDetailSettingsCell) holder.itemView; |
| 450 | if (position == nyaSuffixRow) { |
| 451 | textCell.setTextAndValue(LocaleController.getString("NyaSuffix", R.string.NyaSuffix), NekoConfig.nyaSuffix, false); |
| 452 | } |
| 453 | break; |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | @Override |
| 459 | public boolean isEnabled(RecyclerView.ViewHolder holder) { |
| 460 | int position = holder.getAdapterPosition(); |
| 461 | return position == hidePhoneRow || position == inappCameraRow || position == ignoreBlockedRow || position == navigationBarTintRow || |
| 462 | position == useSystemEmojiRow || position == singleBigEmojiRow || position == ipv6Row || |
| 463 | position == nameOrderRow || position == forceTabletRow || position == nyaRow || |
| 464 | (position == nyaSuffixRow && NekoConfig.nya) || |
| 465 | (position == transparentStatusBarRow && (NekoConfig.navigationBarTint || Build.VERSION.SDK_INT < Build.VERSION_CODES.O)) || |
| 466 | (position == navigationBarColorRow && NekoConfig.navigationBarTint); |
| 467 | } |
| 468 | |
| 469 | @Override |
| 470 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { |
| 471 | View view = null; |
| 472 | switch (viewType) { |
| 473 | case 1: |
| 474 | view = new ShadowSectionCell(mContext); |
| 475 | break; |
| 476 | case 2: |
| 477 | view = new TextSettingsCell(mContext); |
| 478 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 479 | break; |
| 480 | case 3: |
| 481 | view = new TextCheckCell(mContext); |
| 482 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 483 | break; |
| 484 | case 4: |
| 485 | view = new HeaderCell(mContext); |
| 486 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 487 | break; |
| 488 | case 5: |
| 489 | view = new NotificationsCheckCell(mContext); |
| 490 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 491 | break; |
| 492 | case 6: |
| 493 | view = new TextDetailSettingsCell(mContext); |
| 494 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 495 | break; |
| 496 | } |
| 497 | view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT)); |
| 498 | return new RecyclerListView.Holder(view); |
| 499 | } |
| 500 | |
| 501 | @Override |
| 502 | public int getItemViewType(int position) { |
| 503 | if (position == settings2Row || position == emoji2Row || position == connection2Row || position == chat2Row) { |
| 504 | return 1; |
| 505 | } else if (position == nameOrderRow || position == navigationBarColorRow) { |
| 506 | return 2; |
| 507 | } else if (position == ipv6Row || position == hidePhoneRow || position == inappCameraRow || |
| 508 | position == transparentStatusBarRow || position == navigationBarTintRow || |
| 509 | position == ignoreBlockedRow || position == useSystemEmojiRow || position == singleBigEmojiRow || |
| 510 | position == forceTabletRow || position == nyaRow) { |
| 511 | return 3; |
| 512 | } else if (position == settingsRow || position == connectionRow || position == emojiRow || position == chatRow) { |
| 513 | return 4; |
| 514 | } |
| 515 | return 6; |
| 516 | } |
| 517 | } |
| 518 | } |
| 519 | |