| 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 useMessagePanelColorRow; |
| 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 == useMessagePanelColorRow) { |
| 177 | if (!NekoConfig.navigationBarTint) |
| 178 | return; |
| 179 | NekoConfig.toggleUseMessagePanelColor(); |
| 180 | if (view instanceof TextCheckCell) { |
| 181 | ((TextCheckCell) view).setChecked(NekoConfig.useMessagePanelColor); |
| 182 | } |
| 183 | UIHelper.updateNavigationBarColor(getParentActivity()); |
| 184 | } else if (position == useSystemEmojiRow) { |
| 185 | SharedConfig.useSystemEmoji = !SharedConfig.useSystemEmoji; |
| 186 | SharedPreferences.Editor editor = MessagesController.getGlobalMainSettings().edit(); |
| 187 | editor.putBoolean("useSystemEmoji", SharedConfig.useSystemEmoji); |
| 188 | editor.commit(); |
| 189 | if (view instanceof TextCheckCell) { |
| 190 | ((TextCheckCell) view).setChecked(SharedConfig.useSystemEmoji); |
| 191 | } |
| 192 | } else if (position == singleBigEmojiRow) { |
| 193 | SharedConfig.allowBigEmoji = !SharedConfig.allowBigEmoji; |
| 194 | SharedPreferences.Editor editor = MessagesController.getGlobalMainSettings().edit(); |
| 195 | editor.putBoolean("allowBigEmoji", SharedConfig.allowBigEmoji); |
| 196 | editor.commit(); |
| 197 | if (view instanceof TextCheckCell) { |
| 198 | ((TextCheckCell) view).setChecked(SharedConfig.allowBigEmoji); |
| 199 | } |
| 200 | } else if (position == nameOrderRow) { |
| 201 | AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); |
| 202 | builder.setTitle(LocaleController.getString("NameOrder", R.string.NameOrder)); |
| 203 | CharSequence[] items = new CharSequence[]{ |
| 204 | LocaleController.getString("FirstLast", R.string.FirstLast), |
| 205 | LocaleController.getString("LastFirst", R.string.LastFirst), |
| 206 | }; |
| 207 | builder.setItems(items, (dialog, which) -> { |
| 208 | NekoConfig.setNameOrder(which + 1); |
| 209 | listAdapter.notifyItemChanged(nameOrderRow); |
| 210 | }); |
| 211 | showDialog(builder.create()); |
| 212 | } else if (position == nyaSuffixRow) { |
| 213 | if (!NekoConfig.nya) |
| 214 | return; |
| 215 | |
| 216 | AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 217 | builder.setTitle(LocaleController.getString("NyaSuffix", R.string.NyaSuffix)); |
| 218 | |
| 219 | final EditTextBoldCursor editText = new EditTextBoldCursor(context) { |
| 220 | @Override |
| 221 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 222 | super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(64), MeasureSpec.EXACTLY)); |
| 223 | } |
| 224 | }; |
| 225 | editText.setText(NekoConfig.nyaSuffix); |
| 226 | editText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack)); |
| 227 | editText.setHintText(LocaleController.getString("NyaSuffixHint", R.string.NyaSuffixHint)); |
| 228 | editText.setHeaderHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader)); |
| 229 | editText.setSingleLine(true); |
| 230 | editText.setFocusable(true); |
| 231 | editText.setTransformHintToHeader(true); |
| 232 | editText.setLineColors(Theme.getColor(Theme.key_windowBackgroundWhiteInputField), Theme.getColor(Theme.key_windowBackgroundWhiteInputFieldActivated), Theme.getColor(Theme.key_windowBackgroundWhiteRedText3)); |
| 233 | editText.setImeOptions(EditorInfo.IME_ACTION_DONE); |
| 234 | editText.setBackgroundDrawable(null); |
| 235 | editText.requestFocus(); |
| 236 | editText.setPadding(0, 0, 0, 0); |
| 237 | builder.setView(editText); |
| 238 | |
| 239 | |
| 240 | builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { |
| 241 | @Override |
| 242 | public void onClick(DialogInterface dialogInterface, int i) { |
| 243 | if (getParentActivity() == null) { |
| 244 | return; |
| 245 | } |
| 246 | String suffix = editText.getText().toString(); |
| 247 | NekoConfig.setNyaSuffix(suffix); |
| 248 | listAdapter.notifyItemChanged(nyaSuffixRow); |
| 249 | } |
| 250 | }); |
| 251 | builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); |
| 252 | builder.show().setOnShowListener(new DialogInterface.OnShowListener() { |
| 253 | @Override |
| 254 | public void onShow(DialogInterface dialog) { |
| 255 | editText.requestFocus(); |
| 256 | AndroidUtilities.showKeyboard(editText); |
| 257 | } |
| 258 | }); |
| 259 | if (editText != null) { |
| 260 | ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) editText.getLayoutParams(); |
| 261 | if (layoutParams != null) { |
| 262 | if (layoutParams instanceof FrameLayout.LayoutParams) { |
| 263 | ((FrameLayout.LayoutParams) layoutParams).gravity = Gravity.CENTER_HORIZONTAL; |
| 264 | } |
| 265 | layoutParams.rightMargin = layoutParams.leftMargin = AndroidUtilities.dp(24); |
| 266 | layoutParams.height = AndroidUtilities.dp(36); |
| 267 | editText.setLayoutParams(layoutParams); |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | }); |
| 272 | |
| 273 | return fragmentView; |
| 274 | } |
| 275 | |
| 276 | @Override |
| 277 | public void onResume() { |
| 278 | super.onResume(); |
| 279 | if (listAdapter != null) { |
| 280 | listAdapter.notifyDataSetChanged(); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | private void updateRows(boolean notify) { |
| 285 | rowCount = 0; |
| 286 | connectionRow = rowCount++; |
| 287 | ipv6Row = rowCount++; |
| 288 | connection2Row = rowCount++; |
| 289 | emojiRow = rowCount++; |
| 290 | useSystemEmojiRow = rowCount++; |
| 291 | singleBigEmojiRow = rowCount++; |
| 292 | emoji2Row = rowCount++; |
| 293 | chatRow = rowCount++; |
| 294 | ignoreBlockedRow = rowCount++; |
| 295 | nyaRow = rowCount++; |
| 296 | nyaSuffixRow = rowCount++; |
| 297 | chat2Row = rowCount++; |
| 298 | settingsRow = rowCount++; |
| 299 | hidePhoneRow = rowCount++; |
| 300 | inappCameraRow = rowCount++; |
| 301 | navigationBarTintRow = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? rowCount++ : -1; |
| 302 | transparentStatusBarRow = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? rowCount++ : -1; |
| 303 | useMessagePanelColorRow = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? rowCount++ : -1; |
| 304 | forceTabletRow = rowCount++; |
| 305 | nameOrderRow = rowCount++; |
| 306 | settings2Row = rowCount++; |
| 307 | if (notify && listAdapter != null) { |
| 308 | listAdapter.notifyDataSetChanged(); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | @Override |
| 313 | public ThemeDescription[] getThemeDescriptions() { |
| 314 | return new ThemeDescription[]{ |
| 315 | 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), |
| 316 | new ThemeDescription(fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundGray), |
| 317 | |
| 318 | new ThemeDescription(actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_avatar_backgroundActionBarBlue), |
| 319 | new ThemeDescription(listView, ThemeDescription.FLAG_LISTGLOWCOLOR, null, null, null, null, Theme.key_avatar_backgroundActionBarBlue), |
| 320 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_ITEMSCOLOR, null, null, null, null, Theme.key_avatar_actionBarIconBlue), |
| 321 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_TITLECOLOR, null, null, null, null, Theme.key_actionBarDefaultTitle), |
| 322 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SELECTORCOLOR, null, null, null, null, Theme.key_avatar_actionBarSelectorBlue), |
| 323 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SUBMENUBACKGROUND, null, null, null, null, Theme.key_actionBarDefaultSubmenuBackground), |
| 324 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SUBMENUITEM, null, null, null, null, Theme.key_actionBarDefaultSubmenuItem), |
| 325 | |
| 326 | new ThemeDescription(listView, ThemeDescription.FLAG_SELECTOR, null, null, null, null, Theme.key_listSelector), |
| 327 | |
| 328 | new ThemeDescription(listView, 0, new Class[]{View.class}, Theme.dividerPaint, null, null, Theme.key_divider), |
| 329 | |
| 330 | new ThemeDescription(listView, ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{ShadowSectionCell.class}, null, null, null, Theme.key_windowBackgroundGrayShadow), |
| 331 | |
| 332 | new ThemeDescription(listView, 0, new Class[]{TextSettingsCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText), |
| 333 | new ThemeDescription(listView, 0, new Class[]{TextSettingsCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteValueText), |
| 334 | |
| 335 | new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText), |
| 336 | new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2), |
| 337 | new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrack), |
| 338 | new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrackChecked), |
| 339 | |
| 340 | new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText), |
| 341 | new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2), |
| 342 | new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrack), |
| 343 | new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrackChecked), |
| 344 | |
| 345 | new ThemeDescription(listView, 0, new Class[]{HeaderCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlueHeader), |
| 346 | |
| 347 | new ThemeDescription(listView, 0, new Class[]{TextDetailSettingsCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText), |
| 348 | new ThemeDescription(listView, 0, new Class[]{TextDetailSettingsCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2), |
| 349 | }; |
| 350 | } |
| 351 | |
| 352 | private class ListAdapter extends RecyclerListView.SelectionAdapter { |
| 353 | |
| 354 | private Context mContext; |
| 355 | |
| 356 | public ListAdapter(Context context) { |
| 357 | mContext = context; |
| 358 | } |
| 359 | |
| 360 | @Override |
| 361 | public int getItemCount() { |
| 362 | return rowCount; |
| 363 | } |
| 364 | |
| 365 | @Override |
| 366 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { |
| 367 | switch (holder.getItemViewType()) { |
| 368 | case 1: { |
| 369 | break; |
| 370 | } |
| 371 | case 2: { |
| 372 | TextSettingsCell textCell = (TextSettingsCell) holder.itemView; |
| 373 | if (position == nameOrderRow) { |
| 374 | String value; |
| 375 | switch (NekoConfig.nameOrder) { |
| 376 | case 2: |
| 377 | value = LocaleController.getString("LastFirst", R.string.LastFirst); |
| 378 | break; |
| 379 | case 1: |
| 380 | default: |
| 381 | value = LocaleController.getString("FirstLast", R.string.FirstLast); |
| 382 | break; |
| 383 | } |
| 384 | textCell.setTextAndValue(LocaleController.getString("NameOrder", R.string.NameOrder), value, false); |
| 385 | } |
| 386 | break; |
| 387 | } |
| 388 | case 3: { |
| 389 | TextCheckCell textCell = (TextCheckCell) holder.itemView; |
| 390 | if (position == ipv6Row) { |
| 391 | textCell.setTextAndCheck(LocaleController.getString("IPv6", R.string.IPv6), NekoConfig.useIPv6, false); |
| 392 | } else if (position == hidePhoneRow) { |
| 393 | textCell.setTextAndCheck(LocaleController.getString("HidePhone", R.string.HidePhone), NekoConfig.hidePhone, true); |
| 394 | } else if (position == inappCameraRow) { |
| 395 | textCell.setTextAndCheck(LocaleController.getString("DebugMenuEnableCamera", R.string.DebugMenuEnableCamera), SharedConfig.inappCamera, true); |
| 396 | } else if (position == transparentStatusBarRow) { |
| 397 | textCell.setTextAndCheck(LocaleController.getString("TransparentStatusBar", R.string.TransparentStatusBar), NekoConfig.transparentStatusBar, true); |
| 398 | } else if (position == navigationBarTintRow) { |
| 399 | textCell.setTextAndCheck(LocaleController.getString("NavigationBarTint", R.string.NavigationBarTint), NekoConfig.navigationBarTint, true); |
| 400 | } else if (position == useMessagePanelColorRow) { |
| 401 | textCell.setTextAndCheck(LocaleController.getString("UseMessagePanelColor", R.string.UseMessagePanelColor), NekoConfig.useMessagePanelColor, true); |
| 402 | } else if (position == useSystemEmojiRow) { |
| 403 | textCell.setTextAndCheck(LocaleController.getString("EmojiUseDefault", R.string.EmojiUseDefault), SharedConfig.useSystemEmoji, true); |
| 404 | } else if (position == singleBigEmojiRow) { |
| 405 | textCell.setTextAndCheck(LocaleController.getString("EmojiBigSize", R.string.EmojiBigSize), SharedConfig.allowBigEmoji, false); |
| 406 | } else if (position == ignoreBlockedRow) { |
| 407 | textCell.setTextAndCheck(LocaleController.getString("IgnoreBlocked", R.string.IgnoreBlocked), NekoConfig.ignoreBlocked, true); |
| 408 | } else if (position == forceTabletRow) { |
| 409 | textCell.setTextAndCheck(LocaleController.getString("ForceTabletMode", R.string.ForceTabletMode), NekoConfig.forceTablet, true); |
| 410 | } else if (position == nyaRow) { |
| 411 | textCell.setTextAndCheck(LocaleController.getString("EnableNya", R.string.EnableNya), NekoConfig.nya, true); |
| 412 | } |
| 413 | break; |
| 414 | } |
| 415 | case 4: { |
| 416 | HeaderCell headerCell = (HeaderCell) holder.itemView; |
| 417 | if (position == settingsRow) { |
| 418 | headerCell.setText(LocaleController.getString("Settings", R.string.Settings)); |
| 419 | } else if (position == emojiRow) { |
| 420 | headerCell.setText(LocaleController.getString("Emoji", R.string.Emoji)); |
| 421 | } else if (position == connectionRow) { |
| 422 | headerCell.setText(LocaleController.getString("Connection", R.string.Connection)); |
| 423 | } else if (position == chatRow) { |
| 424 | headerCell.setText(LocaleController.getString("Chat", R.string.Chat)); |
| 425 | } |
| 426 | break; |
| 427 | } |
| 428 | case 6: { |
| 429 | TextDetailSettingsCell textCell = (TextDetailSettingsCell) holder.itemView; |
| 430 | if (position == nyaSuffixRow) { |
| 431 | textCell.setTextAndValue(LocaleController.getString("NyaSuffix", R.string.NyaSuffix), NekoConfig.nyaSuffix, false); |
| 432 | } |
| 433 | break; |
| 434 | } |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | @Override |
| 439 | public boolean isEnabled(RecyclerView.ViewHolder holder) { |
| 440 | int position = holder.getAdapterPosition(); |
| 441 | return position == hidePhoneRow || position == inappCameraRow || position == ignoreBlockedRow || position == navigationBarTintRow || |
| 442 | position == useSystemEmojiRow || position == singleBigEmojiRow || position == ipv6Row || |
| 443 | position == nameOrderRow || position == forceTabletRow || position == nyaRow || |
| 444 | (position == nyaSuffixRow && NekoConfig.nya) || |
| 445 | (position == transparentStatusBarRow && (NekoConfig.navigationBarTint || Build.VERSION.SDK_INT < Build.VERSION_CODES.O)) || |
| 446 | (position == useMessagePanelColorRow && NekoConfig.navigationBarTint); |
| 447 | } |
| 448 | |
| 449 | @Override |
| 450 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { |
| 451 | View view = null; |
| 452 | switch (viewType) { |
| 453 | case 1: |
| 454 | view = new ShadowSectionCell(mContext); |
| 455 | break; |
| 456 | case 2: |
| 457 | view = new TextSettingsCell(mContext); |
| 458 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 459 | break; |
| 460 | case 3: |
| 461 | view = new TextCheckCell(mContext); |
| 462 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 463 | break; |
| 464 | case 4: |
| 465 | view = new HeaderCell(mContext); |
| 466 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 467 | break; |
| 468 | case 5: |
| 469 | view = new NotificationsCheckCell(mContext); |
| 470 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 471 | break; |
| 472 | case 6: |
| 473 | view = new TextDetailSettingsCell(mContext); |
| 474 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 475 | break; |
| 476 | } |
| 477 | view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT)); |
| 478 | return new RecyclerListView.Holder(view); |
| 479 | } |
| 480 | |
| 481 | @Override |
| 482 | public int getItemViewType(int position) { |
| 483 | if (position == settings2Row || position == emoji2Row || position == connection2Row || position == chat2Row) { |
| 484 | return 1; |
| 485 | } else if (position == nameOrderRow) { |
| 486 | return 2; |
| 487 | } else if (position == ipv6Row || position == hidePhoneRow || position == inappCameraRow || |
| 488 | position == transparentStatusBarRow || position == navigationBarTintRow || position == useMessagePanelColorRow || |
| 489 | position == ignoreBlockedRow || position == useSystemEmojiRow || position == singleBigEmojiRow || |
| 490 | position == forceTabletRow || position == nyaRow) { |
| 491 | return 3; |
| 492 | } else if (position == settingsRow || position == connectionRow || position == emojiRow || position == chatRow) { |
| 493 | return 4; |
| 494 | } |
| 495 | return 6; |
| 496 | } |
| 497 | } |
| 498 | } |
| 499 | |