| 6 | import android.os.Build; |
| 7 | import android.view.Gravity; |
| 8 | import android.view.View; |
| 9 | import android.view.ViewGroup; |
| 10 | import android.widget.FrameLayout; |
| 11 |
| 12 | import androidx.recyclerview.widget.LinearLayoutManager; |
| 13 | import androidx.recyclerview.widget.RecyclerView; |
| 14 |
| 15 | import org.telegram.messenger.AndroidUtilities; |
| 16 | import org.telegram.messenger.ApplicationLoader; |
| 17 | import org.telegram.messenger.BuildVars; |
| 18 | import org.telegram.messenger.FileLog; |
| 19 | import org.telegram.messenger.LocaleController; |
| 20 | import org.telegram.messenger.MessagesController; |
| 21 | import org.telegram.messenger.R; |
| 22 | import org.telegram.messenger.SharedConfig; |
| 23 | import org.telegram.messenger.UserConfig; |
| 24 | import org.telegram.tgnet.ConnectionsManager; |
| 25 | import org.telegram.ui.ActionBar.ActionBar; |
| 26 | import org.telegram.ui.ActionBar.AlertDialog; |
| 27 | import org.telegram.ui.ActionBar.BaseFragment; |
| 28 | import org.telegram.ui.ActionBar.Theme; |
| 29 | import org.telegram.ui.ActionBar.ThemeDescription; |
| 30 | import org.telegram.ui.Cells.EmptyCell; |
| 31 | import org.telegram.ui.Cells.HeaderCell; |
| 32 | import org.telegram.ui.Cells.NotificationsCheckCell; |
| 33 | import org.telegram.ui.Cells.ShadowSectionCell; |
| 34 | import org.telegram.ui.Cells.TextCheckCell; |
| 35 | import org.telegram.ui.Cells.TextDetailSettingsCell; |
| 36 | import org.telegram.ui.Cells.TextSettingsCell; |
| 37 | import org.telegram.ui.Components.LayoutHelper; |
| 38 | import org.telegram.ui.Components.RecyclerListView; |
| 39 |
| 40 | public class NekoSettingsActivity extends BaseFragment { |
| 41 |
| 42 | private RecyclerListView listView; |
| 43 | private ListAdapter listAdapter; |
| 44 |
| 45 | private int rowCount; |
| 46 |
| 47 | private int connectionRow; |
| 48 | private int ipv6Row; |
| 49 | private int connection2Row; |
| 50 |
| 51 | private int emojiRow; |
| 52 | private int useSystemEmojiRow; |
| 53 | private int singleBigEmojiRow; |
| 54 | private int emoji2Row; |
| 55 |
| 56 | private int settingsRow; |
| 57 | private int hidePhoneRow; |
| 58 | private int inappCameraRow; |
| 59 | private int ignoreBlockedRow; |
| 60 | private int nameOrderRow; |
| 61 | private int forceTabletRow; |
| 62 | private int settings2Row; |
| 63 |
| 64 | private int debugRow; |
| 65 | private int enableLogsRow; |
| 66 | private int clearLogsRow; |
| 67 | private int debug2Row; |
| 68 |
| 69 | private boolean showDebug = false; |
| 70 |
| 71 | @Override |
| 72 | public boolean onFragmentCreate() { |
| 73 | super.onFragmentCreate(); |
| 74 |
| 75 | updateRows(false); |
| 76 |
| 77 | return true; |
| 78 | } |
| 79 |
| 80 | @SuppressLint("NewApi") |
| 81 | @Override |
| 82 | public View createView(Context context) { |
| 83 | actionBar.setBackButtonImage(R.drawable.ic_ab_back); |
| 84 | actionBar.setTitle(LocaleController.getString("NekoSettings", R.string.NekoSettings)); |
| 85 |
| 86 | if (AndroidUtilities.isTablet()) { |
| 87 | actionBar.setOccupyStatusBar(false); |
| 88 | } |
| 89 | actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { |
| 90 | @Override |
| 91 | public void onItemClick(int id) { |
| 92 | if (id == -1) { |
| 93 | finishFragment(); |
| 94 | } |
| 95 | } |
| 96 | }); |
| 97 |
| 98 | listAdapter = new ListAdapter(context); |
| 99 |
| 100 | fragmentView = new FrameLayout(context); |
| 101 | fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray)); |
| 102 | FrameLayout frameLayout = (FrameLayout) fragmentView; |
| 103 |
| 104 | listView = new RecyclerListView(context); |
| 105 | listView.setVerticalScrollBarEnabled(false); |
| 106 | listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) { |
| 107 | @Override |
| 108 | public boolean supportsPredictiveItemAnimations() { |
| 109 | return false; |
| 110 | } |
| 111 | }); |
| 112 | listView.setGlowColor(Theme.getColor(Theme.key_avatar_backgroundActionBarBlue)); |
| 113 | listView.setAdapter(listAdapter); |
| 114 | listView.setItemAnimator(null); |
| 115 | listView.setLayoutAnimation(null); |
| 116 | frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); |
| 117 | listView.setOnItemClickListener((view, position, x, y) -> { |
| 118 | if (position == ipv6Row) { |
| 119 | NekoConfig.toggleIPv6(); |
| 120 | if (view instanceof TextCheckCell) { |
| 121 | ((TextCheckCell) view).setChecked(NekoConfig.useIPv6); |
| 122 | } |
| 123 | for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) { |
| 124 | if (UserConfig.getInstance(a).isClientActivated()) { |
| 125 | ConnectionsManager.native_setUseIpv6(a, NekoConfig.useIPv6); |
| 126 | } |
| 127 | } |
| 128 | } else if (position == hidePhoneRow) { |
| 129 | NekoConfig.toggleHidePhone(); |
| 130 | if (view instanceof TextCheckCell) { |
| 131 | ((TextCheckCell) view).setChecked(NekoConfig.hidePhone); |
| 132 | } |
| 133 | } else if (position == inappCameraRow) { |
| 134 | SharedConfig.toggleInappCamera(); |
| 135 | if (view instanceof TextCheckCell) { |
| 136 | ((TextCheckCell) view).setChecked(SharedConfig.inappCamera); |
| 137 | } |
| 138 | } else if (position == forceTabletRow) { |
| 139 | NekoConfig.toggleForceTablet(); |
| 140 | if (view instanceof TextCheckCell) { |
| 141 | ((TextCheckCell) view).setChecked(NekoConfig.forceTablet); |
| 142 | } |
| 143 | } else if (position == ignoreBlockedRow) { |
| 144 | NekoConfig.toggleIgnoreBlocked(); |
| 145 | if (view instanceof TextCheckCell) { |
| 146 | ((TextCheckCell) view).setChecked(NekoConfig.ignoreBlocked); |
| 147 | } |
| 148 | } else if (position == useSystemEmojiRow) { |
| 149 | SharedConfig.useSystemEmoji = !SharedConfig.useSystemEmoji; |
| 150 | SharedPreferences.Editor editor = MessagesController.getGlobalMainSettings().edit(); |
| 151 | editor.putBoolean("useSystemEmoji", SharedConfig.useSystemEmoji); |
| 152 | editor.commit(); |
| 153 | if (view instanceof TextCheckCell) { |
| 154 | ((TextCheckCell) view).setChecked(SharedConfig.useSystemEmoji); |
| 155 | } |
| 156 | } else if (position == singleBigEmojiRow) { |
| 157 | SharedConfig.allowBigEmoji = !SharedConfig.allowBigEmoji; |
| 158 | SharedPreferences.Editor editor = MessagesController.getGlobalMainSettings().edit(); |
| 159 | editor.putBoolean("allowBigEmoji", SharedConfig.allowBigEmoji); |
| 160 | editor.commit(); |
| 161 | if (view instanceof TextCheckCell) { |
| 162 | ((TextCheckCell) view).setChecked(SharedConfig.allowBigEmoji); |
| 163 | } |
| 164 | } else if (position == nameOrderRow) { |
| 165 | AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); |
| 166 | builder.setTitle(LocaleController.getString("NameOrder", R.string.NameOrder)); |
| 167 | CharSequence[] items = new CharSequence[]{ |
| 168 | LocaleController.getString("FirstLast", R.string.FirstLast), |
| 169 | LocaleController.getString("LastFirst", R.string.LastFirst), |
| 170 | }; |
| 171 | builder.setItems(items, (dialog, which) -> { |
| 172 | NekoConfig.setNameOrder(which + 1); |
| 173 | listAdapter.notifyItemChanged(nameOrderRow); |
| 174 | }); |
| 175 | showDialog(builder.create()); |
| 176 | } else if (position == enableLogsRow) { |
| 177 | BuildVars.LOGS_ENABLED = !BuildVars.LOGS_ENABLED; |
| 178 | SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("systemConfig", Context.MODE_PRIVATE); |
| 179 | sharedPreferences.edit().putBoolean("logsEnabled", BuildVars.LOGS_ENABLED).commit(); |
| 180 | if (view instanceof TextCheckCell) { |
| 181 | ((TextCheckCell) view).setChecked(BuildVars.LOGS_ENABLED); |
| 182 | } |
| 183 | } else if (position == settings2Row) { |
| 184 | showDebug = !showDebug; |
| 185 | updateRows(true); |
| 186 | } else if (position == clearLogsRow) { |
| 187 | FileLog.cleanupLogs(); |
| 188 | } |
| 189 | }); |
| 190 |
| 191 | return fragmentView; |
| 192 | } |
| 193 |
| 194 | @Override |
| 195 | public void onResume() { |
| 196 | super.onResume(); |
| 197 | if (listAdapter != null) { |
| 198 | listAdapter.notifyDataSetChanged(); |
| 199 | } |
| 200 | } |
| 201 |
| 202 | private void updateRows(boolean notify) { |
| 203 | rowCount = 0; |
| 204 | connectionRow = rowCount++; |
| 205 | ipv6Row = rowCount++; |
| 206 | connection2Row = rowCount++; |
| 207 | emojiRow = rowCount++; |
| 208 | useSystemEmojiRow = rowCount++; |
| 209 | singleBigEmojiRow = rowCount++; |
| 210 | emoji2Row = rowCount++; |
| 211 | settingsRow = rowCount++; |
| 212 | hidePhoneRow = rowCount++; |
| 213 | inappCameraRow = rowCount++; |
| 214 | ignoreBlockedRow = rowCount++; |
| 215 | forceTabletRow = rowCount++; |
| 216 | nameOrderRow = rowCount++; |
| 217 | settings2Row = rowCount++; |
| 218 | if (showDebug) { |
| 219 | debugRow = rowCount++; |
| 220 | enableLogsRow = rowCount++; |
| 221 | clearLogsRow = rowCount++; |
| 222 | debug2Row = rowCount++; |
| 223 | } else { |
| 224 | debugRow = -1; |
| 225 | enableLogsRow = -1; |
| 226 | clearLogsRow = -1; |
| 227 | debug2Row = -1; |
| 228 | } |
| 229 | if (notify && listAdapter != null) { |
| 230 | listAdapter.notifyDataSetChanged(); |
| 231 | } |
| 232 | } |
| 233 |
| 234 | @Override |
| 235 | public ThemeDescription[] getThemeDescriptions() { |
| 236 | return new ThemeDescription[]{ |
| 237 | 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), |
| 238 | new ThemeDescription(fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundGray), |
| 239 |
| 240 | new ThemeDescription(actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_avatar_backgroundActionBarBlue), |
| 241 | new ThemeDescription(listView, ThemeDescription.FLAG_LISTGLOWCOLOR, null, null, null, null, Theme.key_avatar_backgroundActionBarBlue), |
| 242 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_ITEMSCOLOR, null, null, null, null, Theme.key_avatar_actionBarIconBlue), |
| 243 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_TITLECOLOR, null, null, null, null, Theme.key_actionBarDefaultTitle), |
| 244 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SELECTORCOLOR, null, null, null, null, Theme.key_avatar_actionBarSelectorBlue), |
| 245 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SUBMENUBACKGROUND, null, null, null, null, Theme.key_actionBarDefaultSubmenuBackground), |
| 246 | new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SUBMENUITEM, null, null, null, null, Theme.key_actionBarDefaultSubmenuItem), |
| 247 |
| 248 | new ThemeDescription(listView, ThemeDescription.FLAG_SELECTOR, null, null, null, null, Theme.key_listSelector), |
| 249 |
| 250 | new ThemeDescription(listView, 0, new Class[]{View.class}, Theme.dividerPaint, null, null, Theme.key_divider), |
| 251 |
| 252 | new ThemeDescription(listView, ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{ShadowSectionCell.class}, null, null, null, Theme.key_windowBackgroundGrayShadow), |
| 253 |
| 254 | new ThemeDescription(listView, 0, new Class[]{TextSettingsCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText), |
| 255 | new ThemeDescription(listView, 0, new Class[]{TextSettingsCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteValueText), |
| 256 |
| 257 | new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText), |
| 258 | new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2), |
| 259 | new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrack), |
| 260 | new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrackChecked), |
| 261 |
| 262 | new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText), |
| 263 | new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2), |
| 264 | new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrack), |
| 265 | new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrackChecked), |
| 266 |
| 267 | new ThemeDescription(listView, 0, new Class[]{HeaderCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlueHeader), |
| 268 |
| 269 | new ThemeDescription(listView, 0, new Class[]{TextDetailSettingsCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText), |
| 270 | new ThemeDescription(listView, 0, new Class[]{TextDetailSettingsCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2), |
| 271 | }; |
| 272 | } |
| 273 |
| 274 | private class ListAdapter extends RecyclerListView.SelectionAdapter { |
| 275 |
| 276 | private Context mContext; |
| 277 |
| 278 | public ListAdapter(Context context) { |
| 279 | mContext = context; |
| 280 | } |
| 281 |
| 282 | @Override |
| 283 | public int getItemCount() { |
| 284 | return rowCount; |
| 285 | } |
| 286 |
| 287 | @Override |
| 288 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { |
| 289 | switch (holder.getItemViewType()) { |
| 290 | case 1: { |
| 291 | break; |
| 292 | } |
| 293 | case 2: { |
| 294 | TextSettingsCell textCell = (TextSettingsCell) holder.itemView; |
| 295 | if (position == nameOrderRow) { |
| 296 | String value; |
| 297 | switch (NekoConfig.nameOrder) { |
| 298 | case 2: |
| 299 | value = LocaleController.getString("LastFirst", R.string.LastFirst); |
| 300 | break; |
| 301 | case 1: |
| 302 | default: |
| 303 | value = LocaleController.getString("FirstLast", R.string.FirstLast); |
| 304 | break; |
| 305 | } |
| 306 | textCell.setTextAndValue(LocaleController.getString("NameOrder", R.string.NameOrder), value, false); |
| 307 | } else if (position == clearLogsRow) { |
| 308 | textCell.setText(LocaleController.getString("DebugClearLogs", R.string.DebugClearLogs), false); |
| 309 | } |
| 310 | break; |
| 311 | } |
| 312 | case 3: { |
| 313 | TextCheckCell textCell = (TextCheckCell) holder.itemView; |
| 314 | if (position == ipv6Row) { |
| 315 | textCell.setTextAndCheck(LocaleController.getString("IPv6", R.string.IPv6), NekoConfig.useIPv6, false); |
| 316 | } else if (position == hidePhoneRow) { |
| 317 | textCell.setTextAndCheck(LocaleController.getString("HidePhone", R.string.HidePhone), NekoConfig.hidePhone, true); |
| 318 | } else if (position == inappCameraRow) { |
| 319 | textCell.setTextAndCheck(LocaleController.getString("DebugMenuEnableCamera", R.string.DebugMenuEnableCamera), SharedConfig.inappCamera, true); |
| 320 | } else if (position == useSystemEmojiRow) { |
| 321 | textCell.setTextAndCheck(LocaleController.getString("EmojiUseDefault", R.string.EmojiUseDefault), SharedConfig.useSystemEmoji, true); |
| 322 | } else if (position == singleBigEmojiRow) { |
| 323 | textCell.setTextAndCheck(LocaleController.getString("EmojiBigSize", R.string.EmojiBigSize), SharedConfig.allowBigEmoji, false); |
| 324 | } else if (position == ignoreBlockedRow) { |
| 325 | textCell.setTextAndCheck(LocaleController.getString("IgnoreBlocked", R.string.IgnoreBlocked), NekoConfig.ignoreBlocked, true); |
| 326 | } else if (position == enableLogsRow) { |
| 327 | textCell.setTextAndCheck(LocaleController.getString("DebugMenuEnableLogs", R.string.DebugMenuEnableLogs), BuildVars.LOGS_ENABLED, true); |
| 328 | } else if (position == forceTabletRow) { |
| 329 | textCell.setTextAndCheck(LocaleController.getString("ForceTabletMode", R.string.ForceTabletMode), NekoConfig.forceTablet, true); |
| 330 | } |
| 331 | break; |
| 332 | } |
| 333 | case 4: { |
| 334 | HeaderCell headerCell = (HeaderCell) holder.itemView; |
| 335 | if (position == settingsRow) { |
| 336 | headerCell.setText(LocaleController.getString("Settings", R.string.Settings)); |
| 337 | } else if (position == emojiRow) { |
| 338 | headerCell.setText(LocaleController.getString("Emoji", R.string.Emoji)); |
| 339 | } else if (position == connectionRow) { |
| 340 | headerCell.setText(LocaleController.getString("Connection", R.string.Connection)); |
| 341 | } else if (position == debugRow) { |
| 342 | headerCell.setText(LocaleController.getString("DebugMenu", R.string.DebugMenu)); |
| 343 | } |
| 344 | break; |
| 345 | } |
| 346 | case 5: { |
| 347 | break; |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 |
| 352 | @Override |
| 353 | public boolean isEnabled(RecyclerView.ViewHolder holder) { |
| 354 | int position = holder.getAdapterPosition(); |
| 355 | return position == hidePhoneRow || position == inappCameraRow || position == ignoreBlockedRow || |
| 356 | position == useSystemEmojiRow || position == singleBigEmojiRow || position == ipv6Row || |
| 357 | position == nameOrderRow || position == settings2Row || position == enableLogsRow || |
| 358 | position == clearLogsRow || position == forceTabletRow; |
| 359 | } |
| 360 |
| 361 | @Override |
| 362 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { |
| 363 | View view = null; |
| 364 | switch (viewType) { |
| 365 | case 1: |
| 366 | view = new ShadowSectionCell(mContext); |
| 367 | break; |
| 368 | case 2: |
| 369 | view = new TextSettingsCell(mContext); |
| 370 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 371 | break; |
| 372 | case 3: |
| 373 | view = new TextCheckCell(mContext); |
| 374 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 375 | break; |
| 376 | case 4: |
| 377 | view = new HeaderCell(mContext); |
| 378 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 379 | break; |
| 380 | case 5: |
| 381 | view = new NotificationsCheckCell(mContext); |
| 382 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 383 | break; |
| 384 | case 6: |
| 385 | view = new TextDetailSettingsCell(mContext); |
| 386 | view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite)); |
| 387 | break; |
| 388 | } |
| 389 | view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT)); |
| 390 | return new RecyclerListView.Holder(view); |
| 391 | } |
| 392 |
| 393 | @Override |
| 394 | public int getItemViewType(int position) { |
| 395 | if (position == settings2Row || position == emoji2Row || position == connection2Row || |
| 396 | position == debug2Row) { |
| 397 | return 1; |
| 398 | } else if (position == nameOrderRow || position == clearLogsRow) { |
| 399 | return 2; |
| 400 | } else if (position == ipv6Row || position == hidePhoneRow || position == inappCameraRow || |
| 401 | position == ignoreBlockedRow || position == useSystemEmojiRow || position == singleBigEmojiRow || |
| 402 | position == enableLogsRow || position == forceTabletRow) { |
| 403 | return 3; |
| 404 | } else if (position == settingsRow || position == connectionRow || position == emojiRow || |
| 405 | position == debugRow) { |
| 406 | return 4; |
| 407 | } |
| 408 | return 6; |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 |