use of me.ccrama.redditslide.Visuals.ColorPreferences in project Slide by ccrama.
the class PostReadLater method onCreate.
@Override
public void onCreate(Bundle savedInstance) {
overrideSwipeFromAnywhere();
super.onCreate(savedInstance);
applyColorTheme();
setContentView(R.layout.activity_read_later);
setupAppBar(R.id.toolbar, "Read later", true, true);
mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
ViewPager pager = (ViewPager) findViewById(R.id.content_view);
pager.setAdapter(new ReadLaterPagerAdapter(getSupportFragmentManager()));
}
use of me.ccrama.redditslide.Visuals.ColorPreferences in project Slide by ccrama.
the class Website method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
overrideSwipeFromAnywhere();
super.onCreate(savedInstanceState);
applyColorTheme("");
setContentView(R.layout.activity_web);
url = getIntent().getExtras().getString(LinkUtil.EXTRA_URL, "");
subredditColor = getIntent().getExtras().getInt(LinkUtil.EXTRA_COLOR, Palette.getDefaultColor());
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
setupAppBar(R.id.toolbar, "", true, subredditColor, R.id.appbar);
mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
p = (ProgressBar) findViewById(R.id.progress);
v = (WebView) findViewById(R.id.web);
client = new MyWebViewClient();
webClient = new AdBlockWebViewClient();
if (!SettingValues.cookies) {
final CookieManager cookieManager = CookieManager.getInstance();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cookieManager.removeAllCookies(null);
cookieManager.flush();
} else {
final CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(this);
cookieSyncMngr.startSync();
cookieManager.removeAllCookie();
cookieManager.removeSessionCookie();
cookieSyncMngr.stopSync();
cookieSyncMngr.sync();
}
cookieManager.setAcceptCookie(false);
WebSettings ws = v.getSettings();
ws.setSaveFormData(false);
ws.setSavePassword(false);
}
/* todo in the future, drag left and right to go back and forward in history
IOverScrollDecor decor = new HorizontalOverScrollBounceEffectDecorator(new WebViewOverScrollDecoratorAdapter(v));
decor.setOverScrollStateListener(new IOverScrollStateListener() {
@Override
public void onOverScrollStateChange(IOverScrollDecor decor, int oldState, int newState) {
switch (newState) {
case IOverScrollState.STATE_IDLE:
// No over-scroll is in effect.
break;
case IOverScrollState.STATE_DRAG_START_SIDE:
break;
case IOverScrollState.STATE_DRAG_END_SIDE:
break;
case IOverScrollState.STATE_BOUNCE_BACK:
if (oldState == IOverScrollState.STATE_DRAG_START_SIDE) {
if(v.canGoBack())
v.goBack();
} else { // i.e. (oldState == STATE_DRAG_END_SIDE)
if(v.canGoForward())
v.goForward();
}
break;
}
}
});
*/
v.setWebChromeClient(client);
v.setWebViewClient(webClient);
v.getSettings().setBuiltInZoomControls(true);
v.getSettings().setDisplayZoomControls(false);
v.getSettings().setJavaScriptEnabled(true);
v.getSettings().setLoadWithOverviewMode(true);
v.getSettings().setUseWideViewPort(true);
v.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
// Downloads using download manager on default browser
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
v.loadUrl(url);
}
use of me.ccrama.redditslide.Visuals.ColorPreferences in project Slide by ccrama.
the class ManageOfflineContentFragment method Bind.
public void Bind() {
if (!NetworkUtil.isConnected(context))
SettingsThemeFragment.changed = true;
context.findViewById(R.id.manage_history_clear_all).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean wifi = Reddit.cachedData.getBoolean("wifiOnly", false);
String sync = Reddit.cachedData.getString("toCache", "");
int hour = (Reddit.cachedData.getInt("hour", 0));
int minute = (Reddit.cachedData.getInt("minute", 0));
Reddit.cachedData.edit().clear().apply();
Reddit.cachedData.edit().putBoolean("wifiOnly", wifi).putString("toCache", sync).putInt("hour", hour).putInt("minute", minute).apply();
context.finish();
}
});
if (NetworkUtil.isConnectedNoOverride(context)) {
context.findViewById(R.id.manage_history_sync_now).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new CommentCacheAsync(context, Reddit.cachedData.getString("toCache", "").split(",")).execute();
}
});
} else {
context.findViewById(R.id.manage_history_sync_now).setVisibility(View.GONE);
}
{
SwitchCompat single = context.findViewById(R.id.manage_history_wifi);
single.setChecked(Reddit.cachedData.getBoolean("wifiOnly", false));
single.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Reddit.cachedData.edit().putBoolean("wifiOnly", isChecked).apply();
}
});
}
updateBackup();
updateFilters();
final List<String> commentDepths = ImmutableList.of("2", "4", "6", "8", "10");
final String[] commentDepthArray = new String[commentDepths.size()];
context.findViewById(R.id.manage_history_comments_depth).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String commentDepth = SettingValues.prefs.getString(SettingValues.COMMENT_DEPTH, "2");
new AlertDialog.Builder(context).setTitle(R.string.comments_depth).setSingleChoiceItems(commentDepths.toArray(commentDepthArray), commentDepths.indexOf(commentDepth), (dialog, which) -> SettingValues.prefs.edit().putString(SettingValues.COMMENT_DEPTH, commentDepths.get(which)).apply()).show();
}
});
final List<String> commentCounts = ImmutableList.of("20", "40", "60", "80", "100");
final String[] commentCountArray = new String[commentCounts.size()];
context.findViewById(R.id.manage_history_comments_count).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String commentCount = SettingValues.prefs.getString(SettingValues.COMMENT_COUNT, "2");
new AlertDialog.Builder(context).setTitle(R.string.comments_count).setSingleChoiceItems(commentCounts.toArray(commentCountArray), commentCounts.indexOf(commentCount), (dialog, which) -> SettingValues.prefs.edit().putString(SettingValues.COMMENT_COUNT, commentCounts.get(which)).apply()).show();
}
});
context.findViewById(R.id.manage_history_autocache).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<String> sorted = UserSubscriptions.sort(UserSubscriptions.getSubscriptions(context));
final String[] all = new String[sorted.size()];
boolean[] checked = new boolean[all.length];
int i = 0;
List<String> s2 = new ArrayList<>();
Collections.addAll(s2, Reddit.cachedData.getString("toCache", "").split(","));
for (String s : sorted) {
all[i] = s;
if (s2.contains(s)) {
checked[i] = true;
}
i++;
}
final ArrayList<String> toCheck = new ArrayList<>(s2);
new AlertDialog.Builder(context).setMultiChoiceItems(all, checked, (dialog, which, isChecked) -> {
if (!isChecked) {
toCheck.remove(all[which]);
} else {
toCheck.add(all[which]);
}
}).setTitle(R.string.multireddit_selector).setPositiveButton(context.getString(R.string.btn_add).toUpperCase(), (dialog, which) -> {
Reddit.cachedData.edit().putString("toCache", StringUtil.arrayToString(toCheck)).apply();
updateBackup();
}).show();
}
});
updateTime();
context.findViewById(R.id.manage_history_autocache_time_touch).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final TimePickerDialog d = new TimePickerDialog(context);
d.hour(Reddit.cachedData.getInt("hour", 0));
d.minute(Reddit.cachedData.getInt("minute", 0));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
d.applyStyle(new ColorPreferences(context).getFontStyle().getBaseId());
d.positiveAction("SET");
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
theme.resolveAttribute(R.attr.activity_background, typedValue, true);
int color = typedValue.data;
d.backgroundColor(color);
d.actionTextColor(context.getResources().getColor(new ColorPreferences(context).getFontStyle().getColor()));
d.positiveActionClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Reddit.cachedData.edit().putInt("hour", d.getHour()).putInt("minute", d.getMinute()).commit();
Reddit.autoCache = new AutoCacheScheduler(context);
Reddit.autoCache.start();
updateTime();
d.dismiss();
}
});
theme.resolveAttribute(R.attr.fontColor, typedValue, true);
int color2 = typedValue.data;
d.setTitle(context.getString(R.string.choose_sync_time));
d.titleColor(color2);
d.show();
}
});
}
use of me.ccrama.redditslide.Visuals.ColorPreferences in project Slide by ccrama.
the class ReorderSubreddits method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
disableSwipeBackLayout();
super.onCreate(savedInstanceState);
applyColorTheme();
setContentView(R.layout.activity_sort);
setupAppBar(R.id.toolbar, R.string.settings_manage_subscriptions, false, true);
mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
isSubscribed = new HashMap<>();
if (Authentication.isLoggedIn) {
new AsyncTask<Void, Void, Void>() {
boolean success = true;
@Override
protected Void doInBackground(Void... params) {
ArrayList<Subreddit> subs = new ArrayList<>();
UserSubredditsPaginator p = new UserSubredditsPaginator(Authentication.reddit, "subscriber");
try {
while (p.hasNext()) {
subs.addAll(p.next());
}
} catch (Exception e) {
success = false;
return null;
}
for (Subreddit s : subs) {
isSubscribed.put(s.getDisplayName().toLowerCase(Locale.ENGLISH), true);
}
if (UserSubscriptions.multireddits == null) {
UserSubscriptions.loadMultireddits();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
if (success) {
d.dismiss();
doShowSubs();
} else {
new AlertDialog.Builder(ReorderSubreddits.this).setTitle(R.string.err_title).setMessage(R.string.misc_please_try_again_soon).setCancelable(false).setPositiveButton(R.string.btn_ok, (dialog, which) -> finish()).show();
}
}
Dialog d;
@Override
protected void onPreExecute() {
d = new MaterialDialog.Builder(ReorderSubreddits.this).progress(true, 100).content(R.string.misc_please_wait).title(R.string.reorder_loading_title).cancelable(false).show();
}
}.execute();
} else {
doShowSubs();
}
}
use of me.ccrama.redditslide.Visuals.ColorPreferences in project Slide by ccrama.
the class SettingsSubAdapter method prepareAndShowSubEditor.
private void prepareAndShowSubEditor(String subreddit) {
int style = new ColorPreferences(context).getThemeSubreddit(subreddit);
final Context contextThemeWrapper = new ContextThemeWrapper(context, style);
LayoutInflater localInflater = context.getLayoutInflater().cloneInContext(contextThemeWrapper);
final View dialoglayout = localInflater.inflate(R.layout.colorsub, null);
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add(subreddit);
showSubThemeEditor(arrayList, context, dialoglayout);
}
Aggregations