@Override public void initDisplayOptions(Context context) { mColorCoded = Preferences.colorCodeEnabled(context); mColorOpacity = Preferences.colorCodeOpacity(context); super.initDisplayOptions(context); }
@Override protected Fragment instantiateListFragment() { Bundle args = new Bundle(); setRange(Preferences.getPopularRange(this)); args.putString(ListFragment.EXTRA_FILTER, mRange); args.putString(ListFragment.EXTRA_ITEM_MANAGER, AlgoliaPopularClient.class.getName()); return Fragment.instantiate(this, ListFragment.class.getName(), args); }
@SuppressLint("MissingPermission") public static void registerAccountsUpdatedListener(final Context context) { AccountManager.get(context).addOnAccountsUpdatedListener(accounts -> { String username = Preferences.getUsername(context); if (TextUtils.isEmpty(username)) { return; } for (Account account : accounts) { if (TextUtils.equals(account.name, username)) { return; } } Preferences.setUsername(context, null); }, null, true); }
public void initDisplayOptions(Context context) { mContentMaxLines = Preferences.getCommentMaxLines(context); mUsername = Preferences.getUsername(context); mLineHeight = Preferences.getLineHeight(context); }
public CommentItemDecoration(Context context) { mPaint = new Paint(); mPaint.setStrokeWidth(context.getResources().getDimensionPixelSize(R.dimen.divider)); mHorizontalMargin = context.getResources() .getDimensionPixelSize(R.dimen.cardview_horizontal_margin); mLevelIndicatorWidth = AppUtils.getDimensionInDp(context, R.dimen.level_indicator_width); mColors = context.getResources().obtainTypedArray(R.array.color_codes); mColorCodeEnabled = Preferences.colorCodeEnabled(context); mThreadIndicatorEnabled = Preferences.threadIndicatorEnabled(context); }
private void addAccount(String username, String password) { Account account = new Account(username, BuildConfig.APPLICATION_ID); mAccountManager.addAccountExplicitly(account, password, null); mAccountManager.setPassword(account, password); // for re-login with updated password Bundle bundle = new Bundle(); bundle.putString(AccountManager.KEY_ACCOUNT_NAME, username); bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, BuildConfig.APPLICATION_ID); setAccountAuthenticatorResult(bundle); Preferences.setUsername(this, username); finish(); }
@Override public void onBackPressed() { if (mEditText.length() == 0 || mSending || TextUtils.equals(Preferences.getDraft(this, mParentId), mEditText.getText().toString())) { super.onBackPressed(); return; } mAlertDialogBuilder .init(this) .setMessage(R.string.confirm_save_draft) .setNegativeButton(android.R.string.no, (dialog, which) -> ComposeActivity.super.onBackPressed()) .setPositiveButton(android.R.string.yes, (dialog, which) -> { Preferences.saveDraft(this, mParentId, mEditText.getText().toString()); ComposeActivity.super.onBackPressed(); }) .show(); }
private void setUsername() { String username = Preferences.getUsername(this); if (!TextUtils.isEmpty(username)) { mDrawerAccount.setText(username); mDrawerLogout.setVisibility(View.VISIBLE); mDrawerUser.setVisibility(View.VISIBLE); } else { mDrawerAccount.setText(R.string.login); mDrawerLogout.setVisibility(View.GONE); mDrawerUser.setVisibility(View.GONE); } }
public static void setUsername(Context context, String username) { set(context, R.string.pref_username, username); }
@Test public void testSaveDiscardDraft() { ((EditText) activity.findViewById(R.id.edittext_body)).setText("Reply"); shadowOf(activity).clickMenuItem(R.id.menu_save_draft); assertThat(Preferences.getDraft(activity, "1")).contains("Reply"); shadowOf(activity).clickMenuItem(R.id.menu_discard_draft); assertThat(Preferences.getDraft(activity, "1")).isNullOrEmpty(); } @Test
private void onPreferenceChanged(int key, boolean contextChanged) { if (contextChanged || key == R.string.pref_comment_display) { load(); } else if (mAdapter != null) { mScrollableHelper.smoothScrollEnabled(Preferences.smoothScrollEnabled(getActivity())); mItemDecoration.setColorCodeEnabled(Preferences.colorCodeEnabled(getActivity())); mItemDecoration.setThreadIndicatorEnabled(Preferences.threadIndicatorEnabled(getActivity())); mAdapter.initDisplayOptions(getActivity()); mAdapter.notifyDataSetChanged(); } }
private void bindKidData() { if (mItem == null || mItem.getKidCount() == 0) { mEmptyView.setVisibility(View.VISIBLE); return; } mEmptyView.setVisibility(View.GONE); String displayOption = Preferences.getCommentDisplayOption(getActivity()); if (Preferences.isSinglePage(getActivity(), displayOption)) { boolean autoExpand = Preferences.isAutoExpand(getActivity(), displayOption); // if collapsed or no saved state then start a fresh (adapter items all collapsed) if (!autoExpand || mAdapterItems == null) { mAdapterItems = new SinglePageItemRecyclerViewAdapter.SavedState( new ArrayList<>(Arrays.asList(mItem.getKidItems()))); } mAdapter = new SinglePageItemRecyclerViewAdapter(mItemManager, mAdapterItems, autoExpand); } else { mAdapter = new MultiPageItemRecyclerViewAdapter(mItemManager, mItem.getKidItems()); } mAdapter.setCacheMode(mCacheMode); mAdapter.initDisplayOptions(getActivity()); mAdapter.attach(getActivity(), mRecyclerView); mRecyclerView.setAdapter(mAdapter); }
public void initDisplayOptions(RecyclerView recyclerView) { mHighlightUpdated = Preferences.highlightUpdatedEnabled(recyclerView.getContext()); mUsername = Preferences.getUsername(recyclerView.getContext()); if (isAttached()) { toggleAutoMarkAsViewed(recyclerView); notifyDataSetChanged(); } }
@Test public void testNoMigrate() { assertFalse(PreferenceManager.getDefaultSharedPreferences(RuntimeEnvironment.application) .contains(RuntimeEnvironment.application.getString(oldKey))); Preferences.migrate(RuntimeEnvironment.application); assertNull(RuntimeEnvironment.application.getString(newValue), PreferenceManager.getDefaultSharedPreferences(RuntimeEnvironment.application) .getString(RuntimeEnvironment.application.getString(newKey), null)); }
Preferences.saveDraft(this, mParentId, mEditText.getText().toString()); return true; Preferences.deleteDraft(this, mParentId); return true;
@Override public void onCreate() { super.onCreate(); AppCompatDelegate.setDefaultNightMode(Preferences.Theme.getAutoDayNightMode(this)); AlgoliaClient.sSortByTime = Preferences.isSortByRecent(this); mRefWatcher = LeakCanary.install(this); if (BuildConfig.DEBUG) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyFlashScreen() .build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectAll() .penaltyLog() .build()); } Preferences.migrate(this); TYPE_FACE = FontCache.getInstance().get(this, Preferences.Theme.getTypeface(this)); AppUtils.registerAccountsUpdatedListener(this); AdBlocker.init(this, Schedulers.io()); }
private void assertMultiplePage() { assertEquals(activity.getString(R.string.pref_comment_display_value_multiple), Preferences.getCommentDisplayOption(activity)); assertThat(recyclerView.getAdapter()).isInstanceOf(MultiPageItemRecyclerViewAdapter.class); } }
private void send() { String content = mEditText.getText().toString(); Preferences.saveDraft(this, mParentId, content); toggleControls(true); Toast.makeText(this, R.string.sending, Toast.LENGTH_SHORT).show(); mUserServices.reply(this, mParentId, content, new ComposeCallback(this, mParentId)); }
@Test public void testReset() { PreferenceManager.getDefaultSharedPreferences(activity) .edit() .putBoolean(activity.getString(R.string.pref_color_code), false) .apply(); assertFalse(Preferences.colorCodeEnabled(activity)); assertNotNull(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_reset)); shadowOf(activity).clickMenuItem(R.id.menu_reset); AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog(); assertNotNull(alertDialog); alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick(); assertTrue(Preferences.colorCodeEnabled(activity)); }
private void loadArticle(@NonNull final HackerNewsItem item) { mWebView = new CacheableWebView(mContext); mWebView.setWebViewClient(new AdBlockWebViewClient(Preferences.adBlockEnabled(mContext))); mWebView.setWebChromeClient(new CacheableWebView.ArchiveClient() { @Override public void onProgressChanged(WebView view, int newProgress) { super.onProgressChanged(view, newProgress); notifyArticle(newProgress); } }); notifyArticle(0); mWebView.loadUrl(item.getUrl()); }