| 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 | import android.widget.LinearLayout; |
| 15 | |
| 16 | import androidx.recyclerview.widget.LinearLayoutManager; |
| 17 | import androidx.recyclerview.widget.RecyclerView; |
| 18 | |
| 19 | import org.telegram.messenger.AndroidUtilities; |
| 20 | import org.telegram.messenger.ApplicationLoader; |
| 21 | import org.telegram.messenger.BuildVars; |
| 22 | import org.telegram.messenger.FileLog; |
| 23 | import org.telegram.messenger.LocaleController; |
| 24 | import org.telegram.messenger.MessagesController; |
| 25 | import org.telegram.messenger.NotificationCenter; |
| 26 | import org.telegram.messenger.R; |
| 27 | import org.telegram.messenger.SharedConfig; |
| 28 | import org.telegram.messenger.UserConfig; |
| 29 | import org.telegram.tgnet.ConnectionsManager; |
| 30 | import org.telegram.ui.ActionBar.ActionBar; |
| 31 | import org.telegram.ui.ActionBar.AlertDialog; |
| 32 | import org.telegram.ui.ActionBar.BaseFragment; |
| 33 | import org.telegram.ui.ActionBar.Theme; |
| 34 | import org.telegram.ui.ActionBar.ThemeDescription; |
| 35 | import org.telegram.ui.Cells.EmptyCell; |
| 36 | import org.telegram.ui.Cells.HeaderCell; |
| 37 | import org.telegram.ui.Cells.NotificationsCheckCell; |
| 38 | import org.telegram.ui.Cells.RadioColorCell; |
| 39 | import org.telegram.ui.Cells.ShadowSectionCell; |
| 40 | import org.telegram.ui.Cells.TextCell; |
| 41 | import org.telegram.ui.Cells.TextCheckCell; |
| 42 | import org.telegram.ui.Cells.TextDetailSettingsCell; |
| 43 | import org.telegram.ui.Cells.TextInfoPrivacyCell; |
| 44 | import org.telegram.ui.Cells.TextSettingsCell; |
| 45 | import org.telegram.ui.Components.EditTextBoldCursor; |
| 46 | import org.telegram.ui.Components.LayoutHelper; |
| 47 | import org.telegram.ui.Components.RecyclerListView; |
| 48 | |
| 49 | import java.util.ArrayList; |
| 50 | |
| 51 | public class NekoSettingsActivity extends BaseFragment { |
| 52 | |
| 53 | private RecyclerListView listView; |
| 54 | private ListAdapter listAdapter; |
| 55 | |
| 56 | private int rowCount; |
| 57 | |
| 58 | private int connectionRow; |
| 59 | private int ipv6Row; |
| 60 | private int connection2Row; |
| 61 | |
| 62 | private int messageMenuRow; |
| 63 | private int showAddToSavedMessagesRow; |
| 64 | private int showReportRow; |
| 65 | private int showPrPrRow; |
| 66 | private int showAdminActionsRow; |
| 67 | private int showChangePermissionsRow; |
| 68 | private int messageMenu2Row; |
| 69 | |
| 70 | private int chatRow; |
| 71 | private int inappCameraRow; |
| 72 | private int useSystemEmojiRow; |
| 73 | private int ignoreBlockedRow; |
| 74 | private int mapPreviewRow; |
| 75 | private int chat2Row; |
| 76 | |
| 77 | private int settingsRow; |
| 78 | private int typefaceRow; |
| 79 | private int hidePhoneRow; |
| 80 | private int nameOrderRow; |
| 81 | private int transparentStatusBarRow; |
| 82 | private int forceTabletRow; |
| 83 | private int xmasRow; |
| 84 | private int newYearRow; |
| 85 | private int newYearEveRow; |
| 86 | private int fireworksRow; |
| 87 | private int needRestartRow; |
| 88 | |
| 89 | @Override |
| 90 | public boolean onFragmentCreate() { |
| 91 | super.onFragmentCreate(); |
| 92 | |
| 93 | updateRows(false); |
| 94 | |
| 95 | return true; |
| 96 | } |
| 97 | |
| 98 | @SuppressLint("NewApi") |
| 99 | @Override |
| 100 | public View createView(Context context) { |
| 101 | actionBar.setBackButtonImage(R.drawable.ic_ab_back); |
| 102 | actionBar.setTitle(LocaleController.getString("NekoSettings", R.string.NekoSettings)); |
| 103 | |
| 104 | if (AndroidUtilities.isTablet()) { |
| 105 | actionBar.setOccupyStatusBar(false); |
| 106 | } |
| 107 | actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { |
| 108 | @Override |
| 109 | public void onItemClick(int id) { |
| 110 | if (id == -1) { |
| 111 | finishFragment(); |
| 112 | } |
| 113 | } |
| 114 | }); |
| 115 | |
| 116 | listAdapter = new ListAdapter(context); |
| 117 | |
| 118 | fragmentView = new FrameLayout(context); |
| 119 | fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray)); |
| 120 | FrameLayout frameLayout = (FrameLayout) fragmentView; |
| 121 | |
| 122 | listView = new RecyclerListView(context); |
| 123 | listView.setVerticalScrollBarEnabled(false); |
| 124 | listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) { |
| 125 | @Override |
| 126 | public boolean supportsPredictiveItemAnimations() { |
| 127 | return false; |
| 128 | } |
| 129 | }); |
| 130 | listView.setGlowColor(Theme.getColor(Theme.key_avatar_backgroundActionBarBlue)); |
| 131 | listView.setAdapter(listAdapter); |
| 132 | listView.setItemAnimator(null); |
| 133 | listView.setLayoutAnimation(null); |
| 134 | frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); |
| 135 | listView.setOnItemClickListener((view, position, x, y) -> { |
| 136 | if (position == ipv6Row) { |
| 137 | NekoConfig.toggleIPv6(); |
| 138 | if (view instanceof TextCheckCell) { |
| 139 | ((TextCheckCell) view).setChecked(NekoConfig.useIPv6); |
| 140 | } |
| 141 | for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) { |
| 142 | if (UserConfig.getInstance(a).isClientActivated()) { |
| 143 | ConnectionsManager.native_setUseIpv6(a, NekoConfig.useIPv6); |
| 144 | } |
| 145 | } |
| 146 | } else if (position == hidePhoneRow) { |
| 147 | NekoConfig.toggleHidePhone(); |
| 148 | if (view instanceof TextCheckCell) { |
| 149 | ((TextCheckCell) view).setChecked(NekoConfig.hidePhone); |
| 150 | } |
| 151 | } else if (position == inappCameraRow) { |
| 152 | SharedConfig.toggleInappCamera(); |
| 153 | if (view instanceof TextCheckCell) { |
| 154 | ((TextCheckCell) view).setChecked(SharedConfig.inappCamera); |
| 155 | } |
| 156 | } else if (position == showAddToSavedMessagesRow) { |
| 157 | NekoConfig.toggleShowAddToSavedMessages(); |
| 158 | if (view instanceof TextCheckCell) { |
| 159 | ((TextCheckCell) view).setChecked(NekoConfig.showAddToSavedMessages); |
| 160 | } |
| 161 | } else if (position == showAdminActionsRow) { |
| 162 | NekoConfig.toggleShowAdminActions(); |
| 163 | if (view instanceof TextCheckCell) { |
| 164 | ((TextCheckCell) view).setChecked(NekoConfig.showAdminActions); |
| 165 | } |
| 166 | } else if (position == showChangePermissionsRow) { |
| 167 | NekoConfig.toggleShowChangePermissions(); |
| 168 | if (view instanceof TextCheckCell) { |
| 169 | ((TextCheckCell) view).setChecked(NekoConfig.showChangePermissions); |
| 170 | } |
| 171 | } else if (position == showPrPrRow) { |
| 172 | NekoConfig.toggleShowPrPr(); |
| 173 | if (view instanceof TextCheckCell) { |
| 174 | ((TextCheckCell) view).setChecked(NekoConfig.showPrPr); |
| 175 | } |
| 176 | } else if (position == showReportRow) { |
| 177 | NekoConfig.toggleShowReport(); |
| 178 | if (view instanceof TextCheckCell) { |
| 179 | ((TextCheckCell) view).setChecked(NekoConfig.showReport); |
| 180 | } |
| 181 | } else if (position == forceTabletRow) { |
| 182 | NekoConfig.toggleForceTablet(); |
| 183 | if (view instanceof TextCheckCell) { |
| 184 | ((TextCheckCell) view).setChecked(NekoConfig.forceTablet); |
| 185 | } |
| 186 | } else if (position == ignoreBlockedRow) { |
| 187 | NekoConfig.toggleIgnoreBlocked(); |
| 188 | if (view instanceof TextCheckCell) { |
| 189 | ((TextCheckCell) view).setChecked(NekoConfig.ignoreBlocked); |
| 190 | } |
| 191 | } else if (position == transparentStatusBarRow) { |
| 192 | NekoConfig.toggleTransparentStatusBar(); |
| 193 | if (view instanceof TextCheckCell) { |
| 194 | ((TextCheckCell) view).setChecked(NekoConfig.transparentStatusBar); |
| 195 | } |
| 196 | AndroidUtilities.runOnUIThread(() -> NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.didSetNewTheme, false)); |
| 197 | } else if (position == useSystemEmojiRow) { |
| 198 | SharedConfig.useSystemEmoji = !SharedConfig.useSystemEmoji; |
| 199 | SharedPreferences.Editor editor = MessagesController.getGlobalMainSettings().edit(); |
| 200 | editor.putBoolean("useSystemEmoji", SharedConfig.useSystemEmoji); |
| 201 | editor.commit(); |
| 202 | if (view instanceof TextCheckCell) { |
| 203 | ((TextCheckCell) view).setChecked(SharedConfig.useSystemEmoji); |
| 204 | } |
| 205 | } else if (position == typefaceRow) { |
| 206 | NekoConfig.toggleTypeface(); |
| 207 | if (view instanceof TextCheckCell) { |
| 208 | ((TextCheckCell) view).setChecked(NekoConfig.typeface == 1); |
| 209 | } |
| 210 | } else if (position == mapPreviewRow) { |
| 211 | ArrayList<String> arrayList = new ArrayList<>(); |
| 212 | ArrayList<Integer> types = new ArrayList<>(); |
| 213 | arrayList.add(LocaleController.getString("MapPreviewProviderTelegram", R.string.MapPreviewProviderTelegram)); |
| 214 | types.add(0); |
| 215 | arrayList.add(LocaleController.getString("MapPreviewProviderYandex", R.string.MapPreviewProviderYandex)); |
| 216 | types.add(1); |
| 217 | arrayList.add(LocaleController.getString("MapPreviewProviderNobody", R.string.MapPreviewProviderNobody)); |
| 218 | types.add(2); |
| 219 | |
| 220 | AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 221 | builder.setTitle(LocaleController.getString("MapPreviewProviderTitle", R.string.MapPreviewProviderTitle)); |
| 222 | final LinearLayout linearLayout = new LinearLayout(context); |
| 223 | linearLayout.setOrientation(LinearLayout.VERTICAL); |
| 224 | builder.setView(linearLayout); |
| 225 | |
| 226 | for (int a = 0; a < arrayList.size(); a++) { |
| 227 | RadioColorCell cell = new RadioColorCell(context); |
| 228 | cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0); |
| 229 | cell.setTag(a); |
| 230 | cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked)); |
| 231 | cell.setTextAndValue(arrayList.get(a), NekoConfig.mapPreviewProvider == types.get(a)); |
| 232 | linearLayout.addView(cell); |
| 233 | cell.setOnClickListener(v -> { |
| 234 | Integer which = (Integer) v.getTag(); |
| 235 | NekoConfig.setMapPreviewProvider(types.get(which)); |
| 236 | listAdapter.notifyItemChanged(mapPreviewRow); |
| 237 | builder.getDismissRunnable().run(); |
| 238 | }); |
| 239 | } |
| 240 | builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); |
| 241 | showDialog(builder.create()); |
| 242 | } else if (position == nameOrderRow) { |
| 243 | ArrayList<String> arrayList = new ArrayList<>(); |
| 244 | ArrayList<Integer> types = new ArrayList<>(); |
| 245 | arrayList.add(LocaleController.getString("FirstLast", R.string.FirstLast)); |
| 246 | types.add(1); |
| 247 | arrayList.add(LocaleController.getString("LastFirst", R.string.LastFirst)); |
| 248 | types.add(2); |
| 249 | |
| 250 | AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 251 | builder.setTitle(LocaleController.getString("NameOrder", R.string.NameOrder)); |
| 252 | final LinearLayout linearLayout = new LinearLayout(context); |
| 253 | linearLayout.setOrientation(LinearLayout.VERTICAL); |
| 254 | builder.setView(linearLayout); |
| 255 | |
| 256 | for (int a = 0; a < arrayList.size(); a++) { |
| 257 | RadioColorCell cell = new RadioColorCell(context); |
| 258 | cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0); |
| 259 | cell.setTag(a); |
| 260 | cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked)); |
| 261 | cell.setTextAndValue(arrayList.get(a), NekoConfig.nameOrder == types.get(a)); |
| 262 | linearLayout.addView(cell); |
| 263 | cell.setOnClickListener(v -> { |
| 264 | Integer which = (Integer) v.getTag(); |
| 265 | NekoConfig.setNameOrder(types.get(which)); |
| 266 | listAdapter.notifyItemChanged(nameOrderRow); |
| 267 | builder.getDismissRunnable().run(); |
| 268 | }); |
| 269 | } |
| 270 | builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); |
| 271 | showDialog(builder.create()); |
| 272 | } else if (position == xmasRow) { |
| 273 | NekoConfig.toggleXmas(); |
| 274 | if (view instanceof TextCheckCell) { |
| 275 | ((TextCheckCell) view).setChecked(NekoConfig.xmas); |
| 276 | } |
| 277 | } else if (position == newYearRow) { |
| 278 | NekoConfig.toggleNewYear(); |
| 279 | if (view instanceof TextCheckCell) { |
| 280 | ((TextCheckCell) view).setChecked(NekoConfig.newYear); |
| 281 | } |
| 282 | } else if (position == newYearEveRow) { |
| 283 | NekoConfig.toggleNewYearEve(); |
| 284 | if (view instanceof TextCheckCell) { |
| 285 | ((TextCheckCell) view).setChecked(NekoConfig.newYearEve); |
| 286 | } |
| 287 | } else if (position == fireworksRow) { |
| 288 | NekoConfig.toggleFireworks(); |
| 289 | if (view instanceof TextCheckCell) { |
| 290 | ((TextCheckCell) view).setChecked(NekoConfig.fireworks); |
| 291 | } |
| 292 | } |
| 293 | }); |
| 294 | |
| 295 | return fragmentView; |
| 296 | } |
| 297 | |
| 298 | @Override |
| 299 | public void onResume() { |
| 300 | super.onResume(); |
| 301 | if (listAdapter != null) { |
| 302 | listAdapter.notifyDataSetChanged(); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | private void updateRows(boolean notify) { |
| 307 | rowCount = 0; |
| 308 | connectionRow = rowCount++; |
| 309 | ipv6Row = rowCount++; |
| 310 | connection2Row = rowCount++; |
| 311 | chatRow = rowCount++; |
| 312 | inappCameraRow = rowCount++; |
| 313 | useSystemEmojiRow = rowCount++; |
| 314 | ignoreBlockedRow = rowCount++; |
| 315 | mapPreviewRow = rowCount++; |
| 316 | chat2Row = rowCount++; |
| 317 | messageMenuRow = rowCount++; |
| 318 | showAddToSavedMessagesRow = rowCount++; |
| 319 | showPrPrRow = rowCount++; |
| 320 | showReportRow = rowCount++; |
| 321 | showAdminActionsRow = rowCount++; |
| 322 | showChangePermissionsRow = rowCount++; |
| 323 | messageMenu2Row = rowCount++; |
| 324 | settingsRow = rowCount++; |
| 325 | hidePhoneRow = rowCount++; |
| 326 | typefaceRow = rowCount++; |
| 327 | transparentStatusBarRow = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? rowCount++ : -1; |
| 328 | forceTabletRow = rowCount++; |
| 329 | nameOrderRow = rowCount++; |
| 330 | xmasRow = rowCount++; |
| 331 | newYearRow = rowCount++; |
| 332 | newYearEveRow = rowCount++; |
| 333 | fireworksRow = rowCount++; |
| 334 | needRestartRow = rowCount++; |
| 335 | if (notify && listAdapter != null) { |
| 336 | listAdapter.notifyDataSetChanged(); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | @Override |
| 341 | public ThemeDescription[] getThemeDescriptions() { |
| 342 | return new ThemeDescription[]{ |
| 343 | 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), |
| 344 | new ThemeDescription(fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundGray), |
| 345 | |
| 346 | new ThemeDescription(actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_avatar_backgroundActionBarBlue), |
| 347 | new ThemeDescription(listView, ThemeDescription.FLAG_LISTGLOWCOLOR, null, null, null, null, Theme.key_avatar_backgroundActionBarBlue), |
| 348 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_ITEMSCOLOR, null, null, null, null, Theme.key_avatar_actionBarIconBlue), |
| 349 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_TITLECOLOR, null, null, null, null, Theme.key_actionBarDefaultTitle), |
| 350 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SELECTORCOLOR, null, null, null, null, Theme.key_avatar_actionBarSelectorBlue), |
| 351 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SUBMENUBACKGROUND, null, null, null, null, Theme.key_actionBarDefaultSubmenuBackground), |
| 352 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SUBMENUITEM, null, null, null, null, Theme.key_actionBarDefaultSubmenuItem), |
| 353 | |
| 354 | new ThemeDescription(listView, ThemeDescription.FLAG_SELECTOR, null, null, null, null, Theme.key_listSelector), |
| 355 | |
| 356 | new ThemeDescription(listView, 0, new Class[]{View.class}, Theme.dividerPaint, null, null, Theme.key_divider), |
| 357 | |
| 358 | new ThemeDescription(listView, ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{ShadowSectionCell.class}, null, null, null, Theme.key_windowBackgroundGrayShadow), |
| 359 | |
| 360 | new ThemeDescription(listView, 0, new Class[]{TextSettingsCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText), |
| 361 | new ThemeDescription(listView, 0, new Class[]{TextSettingsCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteValueText), |
| 362 | |
| 363 | new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText), |
| 364 | new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2), |
| 365 | new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrack), |
| 366 | new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrackChecked), |
| 367 | |
| 368 | new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText), |
| 369 | new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2), |
| 370 | new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrack), |
| 371 | new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrackChecked), |
| 372 | |
| 373 | new ThemeDescription(listView, 0, new Class[]{HeaderCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlueHeader), |
| 374 | |
| 375 | new ThemeDescription(listView, 0, new Class[]{TextDetailSettingsCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText), |
| 376 | new ThemeDescription(listView, 0, new Class[]{TextDetailSettingsCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2), |
| 377 | }; |
| 378 | } |
| 379 | |
| 380 | private class ListAdapter extends RecyclerListView.SelectionAdapter { |
| 381 | |
| 382 | private Context mContext; |
| 383 | |
| 384 | public ListAdapter(Context context) { |
| 385 | mContext = context; |
| 386 | } |
| 387 | |
| 388 | @Override |
| 389 | public int getItemCount() { |
| 390 | return rowCount; |
| 391 | } |
| 392 | |
| 393 | @Override |
| 394 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { |
| 395 | switch (holder.getItemViewType()) { |
| 396 | case 1: { |
| 397 | break; |
| 398 | } |
| 399 | case 2: { |
| 400 | TextSettingsCell textCell = (TextSettingsCell) holder.itemView; |
| 401 | if (position == nameOrderRow) { |
| 402 | String value; |
| 403 | switch (NekoConfig.nameOrder) { |
| 404 | case 2: |
| 405 | value = LocaleController.getString("LastFirst", R.string.LastFirst); |
| 406 | break; |
| 407 | case 1: |
| 408 | default: |
| 409 | value = LocaleController.getString("FirstLast", R.string.FirstLast); |
| 410 | break; |
| 411 | } |
| 412 | textCell.setTextAndValue(LocaleController.getString("NameOrder", R.string.NameOrder), value, true); |
| 413 | } else if (position == mapPreviewRow) { |
| 414 | String value; |
| 415 | switch (NekoConfig.mapPreviewProvider) { |
| 416 | case 0: |
| 417 | value = LocaleController.getString("MapPreviewProviderTelegram", R.string.MapPreviewProviderTelegram); |
| 418 | break; |
| 419 | case 1: |
| 420 | value = LocaleController.getString("MapPreviewProviderYandex", R.string.MapPreviewProviderYandex); |
| 421 | break; |
| 422 | case 2: |
| 423 | default: |
| 424 | value = LocaleController.getString("MapPreviewProviderNobody", R.string.MapPreviewProviderNobody); |
| 425 | } |
| 426 | textCell.setTextAndValue(LocaleController.getString("MapPreviewProvider", R.string.MapPreviewProvider), value, false); |
| 427 | } |
| 428 | break; |
| 429 | } |
| 430 | case 3: { |
| 431 | TextCheckCell textCell = (TextCheckCell) holder.itemView; |
| 432 | if (position == ipv6Row) { |
| 433 | textCell.setTextAndCheck(LocaleController.getString("IPv6", R.string.IPv6), NekoConfig.useIPv6, false); |
| 434 | } else if (position == showAddToSavedMessagesRow) { |
| 435 | textCell.setTextAndCheck(LocaleController.getString("AddToSavedMessages", R.string.AddToSavedMessages), NekoConfig.showAddToSavedMessages, true); |
| 436 | } else if (position == showPrPrRow) { |
| 437 | textCell.setTextAndCheck(LocaleController.getString("Prpr", R.string.Prpr), NekoConfig.showPrPr, true); |
| 438 | } else if (position == showReportRow) { |
| 439 | textCell.setTextAndCheck(LocaleController.getString("ReportChat", R.string.ReportChat), NekoConfig.showReport, true); |
| 440 | } else if (position == showAdminActionsRow) { |
| 441 | textCell.setTextAndCheck(LocaleController.getString("EditAdminRights", R.string.EditAdminRights), NekoConfig.showAdminActions, true); |
| 442 | } else if (position == showChangePermissionsRow) { |
| 443 | textCell.setTextAndCheck(LocaleController.getString("ChangePermissions", R.string.ChangePermissions), NekoConfig.showChangePermissions, false); |
| 444 | } else if (position == hidePhoneRow) { |
| 445 | textCell.setTextAndCheck(LocaleController.getString("HidePhone", R.string.HidePhone), NekoConfig.hidePhone, true); |
| 446 | } else if (position == inappCameraRow) { |
| 447 | textCell.setTextAndCheck(LocaleController.getString("DebugMenuEnableCamera", R.string.DebugMenuEnableCamera), SharedConfig.inappCamera, true); |
| 448 | } else if (position == transparentStatusBarRow) { |
| 449 | textCell.setTextAndCheck(LocaleController.getString("TransparentStatusBar", R.string.TransparentStatusBar), NekoConfig.transparentStatusBar, true); |
| 450 | } else if (position == useSystemEmojiRow) { |
| 451 | textCell.setTextAndCheck(LocaleController.getString("EmojiUseDefault", R.string.EmojiUseDefault), SharedConfig.useSystemEmoji, true); |
| 452 | } else if (position == typefaceRow) { |
| 453 | textCell.setTextAndCheck(LocaleController.getString("TypefaceUseDefault", R.string.TypefaceUseDefault), NekoConfig.typeface == 1, true); |
| 454 | } else if (position == ignoreBlockedRow) { |
| 455 | textCell.setTextAndCheck(LocaleController.getString("IgnoreBlocked", R.string.IgnoreBlocked), NekoConfig.ignoreBlocked, true); |
| 456 | } else if (position == forceTabletRow) { |
| 457 | textCell.setTextAndCheck(LocaleController.getString("ForceTabletMode", R.string.ForceTabletMode), NekoConfig.forceTablet, true); |
| 458 | } else if (position == xmasRow) { |
| 459 | textCell.setTextAndCheck(LocaleController.getString("ChristmasEveryday", R.string.ChristmasEveryday), NekoConfig.xmas, true); |
| 460 | } else if (position == newYearRow) { |
| 461 | textCell.setTextAndCheck(LocaleController.getString("NewYearEveryday", R.string.NewYearEveryday), NekoConfig.newYear, true); |
| 462 | } else if (position == newYearEveRow) { |
| 463 | textCell.setTextAndCheck(LocaleController.getString("HappyNewYearEveryday", R.string.HappyNewYearEveryday), NekoConfig.newYearEve, true); |
| 464 | } else if (position == fireworksRow) { |
| 465 | textCell.setTextAndCheck(LocaleController.getString("ShowFireworks", R.string.ShowFireworks), NekoConfig.fireworks, false); |
| 466 | } |
| 467 | break; |
| 468 | } |
| 469 | case 4: { |
| 470 | HeaderCell headerCell = (HeaderCell) holder.itemView; |
| 471 | if (position == settingsRow) { |
| 472 | headerCell.setText(LocaleController.getString("General", R.string.General)); |
| 473 | } else if (position == messageMenuRow) { |
| 474 | headerCell.setText(LocaleController.getString("MessageMenu", R.string.MessageMenu)); |
| 475 | } else if (position == connectionRow) { |
| 476 | headerCell.setText(LocaleController.getString("Connection", R.string.Connection)); |
| 477 | } else if (position == chatRow) { |
| 478 | headerCell.setText(LocaleController.getString("Chat", R.string.Chat)); |
| 479 | } |
| 480 | break; |
| 481 | } |
| 482 | case 7: { |
| 483 | TextInfoPrivacyCell cell = (TextInfoPrivacyCell) holder.itemView; |
| 484 | if (position == needRestartRow) { |
| 485 | cell.setText(LocaleController.getString("SomeItemsNeedRestart", R.string.SomeItemsNeedRestart)); |
| 486 | } |
| 487 | break; |
| 488 | } |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | @Override |
| 493 | public boolean isEnabled(RecyclerView.ViewHolder holder) { |
| 494 | int position = holder.getAdapterPosition(); |
| 495 | return position == hidePhoneRow || position == inappCameraRow || position == ignoreBlockedRow || |
| 496 | position == useSystemEmojiRow || position == ipv6Row || position == typefaceRow || |
| 497 | position == showChangePermissionsRow || position == showAdminActionsRow || position == showReportRow || |
| 498 | position == showPrPrRow || position == showAddToSavedMessagesRow || |
| 499 | position == nameOrderRow || position == forceTabletRow || position == mapPreviewRow || |
| 500 | position == xmasRow || position == newYearRow || position == newYearEveRow || position == fireworksRow || |
| 501 | position == transparentStatusBarRow; |
| 502 | } |
| 503 | |
| 504 | @Override |
| 505 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { |
| 506 | View view = null; |
| 507 | switch (viewType) { |
| 508 | case 1: |
| 509 | view = new ShadowSectionCell(mContext); |
| 510 | break; |
| 511 | case 2: |
| 512 | view = new TextSettingsCell(mContext); |
| 513 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 514 | break; |
| 515 | case 3: |
| 516 | view = new TextCheckCell(mContext); |
| 517 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 518 | break; |
| 519 | case 4: |
| 520 | view = new HeaderCell(mContext); |
| 521 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 522 | break; |
| 523 | case 5: |
| 524 | view = new NotificationsCheckCell(mContext); |
| 525 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 526 | break; |
| 527 | case 6: |
| 528 | view = new TextDetailSettingsCell(mContext); |
| 529 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 530 | break; |
| 531 | case 7: |
| 532 | view = new TextInfoPrivacyCell(mContext); |
| 533 | view.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow)); |
| 534 | break; |
| 535 | } |
| 536 | view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT)); |
| 537 | return new RecyclerListView.Holder(view); |
| 538 | } |
| 539 | |
| 540 | @Override |
| 541 | public int getItemViewType(int position) { |
| 542 | if (position == messageMenu2Row || position == connection2Row || position == chat2Row) { |
| 543 | return 1; |
| 544 | } else if (position == nameOrderRow || position == mapPreviewRow) { |
| 545 | return 2; |
| 546 | } else if (position == ipv6Row || position == hidePhoneRow || position == inappCameraRow || |
| 547 | position == showAddToSavedMessagesRow || position == showPrPrRow || position == showReportRow || |
| 548 | position == showAdminActionsRow || position == showChangePermissionsRow || |
| 549 | position == transparentStatusBarRow || |
| 550 | position == ignoreBlockedRow || position == useSystemEmojiRow || position == typefaceRow || |
| 551 | position == forceTabletRow || position == xmasRow || position == newYearRow || position == newYearEveRow || |
| 552 | position == fireworksRow) { |
| 553 | return 3; |
| 554 | } else if (position == settingsRow || position == connectionRow || position == messageMenuRow || position == chatRow) { |
| 555 | return 4; |
| 556 | } else if (position == needRestartRow) { |
| 557 | return 7; |
| 558 | } |
| 559 | return 6; |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 | |