use of me.ccrama.redditslide.Autocache.AutoCacheScheduler in project Slide by ccrama.
the class ManageOfflineContent method onCreate.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
applyColorTheme();
setContentView(R.layout.activity_manage_history);
setupAppBar(R.id.toolbar, R.string.manage_offline_content, true, true);
if (!NetworkUtil.isConnected(this))
SettingsTheme.changed = true;
findViewById(R.id.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();
finish();
}
});
if (NetworkUtil.isConnectedNoOverride(this)) {
findViewById(R.id.sync_now).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new CommentCacheAsync(ManageOfflineContent.this, Reddit.cachedData.getString("toCache", "").split(",")).execute();
}
});
} else {
findViewById(R.id.sync_now).setVisibility(View.GONE);
}
{
SwitchCompat single = (SwitchCompat) findViewById(R.id.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()];
findViewById(R.id.comments_depth).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String commentDepth = SettingValues.prefs.getString(SettingValues.COMMENT_DEPTH, "2");
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(ManageOfflineContent.this);
builder.setTitle(R.string.comments_depth);
builder.setSingleChoiceItems(commentDepths.toArray(commentDepthArray), commentDepths.indexOf(commentDepth), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SettingValues.prefs.edit().putString(SettingValues.COMMENT_DEPTH, commentDepths.get(which)).apply();
}
});
builder.show();
}
});
final List<String> commentCounts = ImmutableList.of("20", "40", "60", "80", "100");
final String[] commentCountArray = new String[commentCounts.size()];
findViewById(R.id.comments_count).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String commentCount = SettingValues.prefs.getString(SettingValues.COMMENT_COUNT, "2");
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(ManageOfflineContent.this);
builder.setTitle(R.string.comments_count);
builder.setSingleChoiceItems(commentCounts.toArray(commentCountArray), commentCounts.indexOf(commentCount), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SettingValues.prefs.edit().putString(SettingValues.COMMENT_COUNT, commentCounts.get(which)).apply();
}
});
builder.show();
}
});
findViewById(R.id.autocache).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<String> sorted = UserSubscriptions.sort(UserSubscriptions.getSubscriptions(ManageOfflineContent.this));
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<>();
toCheck.addAll(s2);
new AlertDialogWrapper.Builder(ManageOfflineContent.this).alwaysCallMultiChoiceCallback().setMultiChoiceItems(all, checked, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if (!isChecked) {
toCheck.remove(all[which]);
} else {
toCheck.add(all[which]);
}
}
}).setTitle(R.string.multireddit_selector).setPositiveButton(getString(R.string.btn_add).toUpperCase(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Reddit.cachedData.edit().putString("toCache", Reddit.arrayToString(toCheck)).apply();
updateBackup();
}
}).show();
}
});
updateTime();
findViewById(R.id.autocache_time_touch).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final TimePickerDialog d = new TimePickerDialog(ManageOfflineContent.this);
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(ManageOfflineContent.this).getFontStyle().getBaseId());
d.positiveAction("SET");
TypedValue typedValue = new TypedValue();
Resources.Theme theme = getTheme();
theme.resolveAttribute(R.attr.activity_background, typedValue, true);
int color = typedValue.data;
d.backgroundColor(color);
d.actionTextColor(getResources().getColor(new ColorPreferences(ManageOfflineContent.this).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(ManageOfflineContent.this);
Reddit.autoCache.start(getApplicationContext());
updateTime();
d.dismiss();
}
});
theme.resolveAttribute(R.attr.fontColor, typedValue, true);
int color2 = typedValue.data;
d.setTitle(getString(R.string.choose_sync_time));
d.titleColor(color2);
d.show();
}
});
}
use of me.ccrama.redditslide.Autocache.AutoCacheScheduler in project Slide by ccrama.
the class ListViewRemoteViewsFactory method onCreate.
// Initialize the data set.
public void onCreate() {
// In onCreate() you set up any connections / cursors to your data source. Heavy lifting,
// for example downloading or creating content etc, should be deferred to onDataSetChanged()
// or getViewAt(). Taking more than 20 seconds in this call will result in an ANR.
records = new ArrayList<>();
if (NetworkUtil.isConnected(mContext)) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
if (Authentication.reddit == null) {
new Authentication(mContext.getApplicationContext());
Authentication.me = Authentication.reddit.me();
Authentication.mod = Authentication.me.isMod();
Authentication.authentication.edit().putBoolean(Reddit.SHARED_PREF_IS_MOD, Authentication.mod).apply();
if (Reddit.notificationTime != -1) {
Reddit.notifications = new NotificationJobScheduler(mContext);
Reddit.notifications.start(mContext.getApplicationContext());
}
if (Reddit.cachedData.contains("toCache")) {
Reddit.autoCache = new AutoCacheScheduler(mContext);
Reddit.autoCache.start(mContext.getApplicationContext());
}
final String name = Authentication.me.getFullName();
Authentication.name = name;
LogUtil.v("AUTHENTICATED");
if (Authentication.reddit.isAuthenticated()) {
final Set<String> accounts = Authentication.authentication.getStringSet("accounts", new HashSet<String>());
if (accounts.contains(name)) {
// convert to new system
accounts.remove(name);
accounts.add(name + ":" + Authentication.refresh);
Authentication.authentication.edit().putStringSet("accounts", accounts).apply();
}
Authentication.isLoggedIn = true;
Reddit.notFirst = true;
}
}
String sub = SubredditWidgetProvider.getSubFromId(id, mContext);
Paginator p;
if (sub.equals("frontpage")) {
p = new SubredditPaginator(Authentication.reddit);
} else if (!sub.contains(".")) {
p = new SubredditPaginator(Authentication.reddit, sub);
} else {
p = new DomainPaginator(Authentication.reddit, sub);
}
p.setLimit(50);
switch(SubredditWidgetProvider.getSorting(id, mContext)) {
case 0:
p.setSorting(Sorting.HOT);
break;
case 1:
p.setSorting(Sorting.NEW);
break;
case 2:
p.setSorting(Sorting.RISING);
break;
case 3:
p.setSorting(Sorting.TOP);
break;
case 4:
p.setSorting(Sorting.CONTROVERSIAL);
break;
}
switch(SubredditWidgetProvider.getSortingTime(id, mContext)) {
case 0:
p.setTimePeriod(TimePeriod.HOUR);
break;
case 1:
p.setTimePeriod(TimePeriod.DAY);
break;
case 2:
p.setTimePeriod(TimePeriod.WEEK);
break;
case 3:
p.setTimePeriod(TimePeriod.MONTH);
break;
case 4:
p.setTimePeriod(TimePeriod.YEAR);
break;
case 5:
p.setTimePeriod(TimePeriod.ALL);
break;
}
try {
ArrayList<Submission> s = new ArrayList<>(p.next());
records = new ArrayList<>();
for (Submission subm : s) {
if (!PostMatch.doesMatch(subm) && !subm.isStickied()) {
records.add(subm);
}
}
} catch (Exception e) {
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
Intent widgetUpdateIntent = new Intent(mContext, SubredditWidgetProvider.class);
widgetUpdateIntent.setAction(SubredditWidgetProvider.UPDATE_MEETING_ACTION);
widgetUpdateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
mContext.sendBroadcast(widgetUpdateIntent);
}
}.execute();
} else {
Intent widgetUpdateIntent = new Intent(mContext, SubredditWidgetProvider.class);
widgetUpdateIntent.setAction(SubredditWidgetProvider.UPDATE_MEETING_ACTION);
widgetUpdateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
mContext.sendBroadcast(widgetUpdateIntent);
}
}
use of me.ccrama.redditslide.Autocache.AutoCacheScheduler in project Slide by ccrama.
the class Inbox method onCreate.
@Override
public void onCreate(Bundle savedInstance) {
overrideSwipeFromAnywhere();
if (Authentication.reddit == null || !Authentication.reddit.isAuthenticated() || Authentication.me == null) {
LogUtil.v("Reauthenticating");
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
if (Authentication.reddit == null) {
new Authentication(getApplicationContext());
}
try {
Authentication.me = Authentication.reddit.me();
Authentication.mod = Authentication.me.isMod();
Authentication.authentication.edit().putBoolean(Reddit.SHARED_PREF_IS_MOD, Authentication.mod).apply();
if (Reddit.notificationTime != -1) {
Reddit.notifications = new NotificationJobScheduler(Inbox.this);
Reddit.notifications.start(getApplicationContext());
}
if (Reddit.cachedData.contains("toCache")) {
Reddit.autoCache = new AutoCacheScheduler(Inbox.this);
Reddit.autoCache.start(getApplicationContext());
}
final String name = Authentication.me.getFullName();
Authentication.name = name;
LogUtil.v("AUTHENTICATED");
UserSubscriptions.doCachedModSubs();
if (Authentication.reddit.isAuthenticated()) {
final Set<String> accounts = Authentication.authentication.getStringSet("accounts", new HashSet<String>());
if (accounts.contains(name)) {
// convert to new system
accounts.remove(name);
accounts.add(name + ":" + Authentication.refresh);
Authentication.authentication.edit().putStringSet("accounts", accounts).apply();
}
Authentication.isLoggedIn = true;
Reddit.notFirst = true;
}
} catch (Exception ignored) {
}
return null;
}
}.execute();
}
super.onCreate(savedInstance);
last = SettingValues.prefs.getLong("lastInbox", System.currentTimeMillis() - (60 * 1000 * 60));
SettingValues.prefs.edit().putLong("lastInbox", System.currentTimeMillis()).apply();
applyColorTheme("");
setContentView(R.layout.activity_inbox);
setupAppBar(R.id.toolbar, R.string.title_inbox, true, true);
mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
tabs = (TabLayout) findViewById(R.id.sliding_tabs);
tabs.setTabMode(TabLayout.MODE_SCROLLABLE);
tabs.setSelectedTabIndicatorColor(new ColorPreferences(Inbox.this).getColor("no sub"));
pager = (ViewPager) findViewById(R.id.content_view);
findViewById(R.id.header).setBackgroundColor(Palette.getDefaultColor());
adapter = new OverviewPagerAdapter(getSupportFragmentManager());
pager.setAdapter(adapter);
if (getIntent() != null && getIntent().hasExtra(EXTRA_UNREAD)) {
pager.setCurrentItem(1);
}
tabs.setupWithViewPager(pager);
pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
findViewById(R.id.header).animate().translationY(0).setInterpolator(new LinearInterpolator()).setDuration(180);
if (position == 3 && findViewById(R.id.read) != null) {
findViewById(R.id.read).setVisibility(View.GONE);
} else if (findViewById(R.id.read) != null) {
findViewById(R.id.read).setVisibility(View.VISIBLE);
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
}
use of me.ccrama.redditslide.Autocache.AutoCacheScheduler in project Slide by ccrama.
the class CommentsScreenSingle method onCreate.
@Override
public void onCreate(Bundle savedInstance) {
disableSwipeBackLayout();
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
getWindow().getDecorView().setBackgroundDrawable(null);
super.onCreate(savedInstance);
applyColorTheme();
setContentView(R.layout.activity_slide);
name = getIntent().getExtras().getString(EXTRA_SUBMISSION, "");
subreddit = getIntent().getExtras().getString(EXTRA_SUBREDDIT, "");
np = getIntent().getExtras().getBoolean(EXTRA_NP, false);
context = getIntent().getExtras().getString(EXTRA_CONTEXT, "");
contextNumber = getIntent().getExtras().getInt(EXTRA_CONTEXT_NUMBER, 5);
if (subreddit.equals(Reddit.EMPTY_STRING)) {
new AsyncGetSubredditName().execute(name);
TypedValue typedValue = new TypedValue();
getTheme().resolveAttribute(R.attr.activity_background, typedValue, true);
int color = typedValue.data;
findViewById(R.id.content_view).setBackgroundColor(color);
} else {
setupAdapter();
}
if (Authentication.isLoggedIn && Authentication.me == null) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
if (Authentication.reddit == null) {
new Authentication(getApplicationContext());
} else {
try {
Authentication.me = Authentication.reddit.me();
Authentication.mod = Authentication.me.isMod();
Authentication.authentication.edit().putBoolean(Reddit.SHARED_PREF_IS_MOD, Authentication.mod).apply();
if (Reddit.notificationTime != -1) {
Reddit.notifications = new NotificationJobScheduler(CommentsScreenSingle.this);
Reddit.notifications.start(getApplicationContext());
}
if (Reddit.cachedData.contains("toCache")) {
Reddit.autoCache = new AutoCacheScheduler(CommentsScreenSingle.this);
Reddit.autoCache.start(getApplicationContext());
}
final String name = Authentication.me.getFullName();
Authentication.name = name;
LogUtil.v("AUTHENTICATED");
UserSubscriptions.doCachedModSubs();
if (Authentication.reddit.isAuthenticated()) {
final Set<String> accounts = Authentication.authentication.getStringSet("accounts", new HashSet<String>());
if (accounts.contains(name)) {
// convert to new system
accounts.remove(name);
accounts.add(name + ":" + Authentication.refresh);
Authentication.authentication.edit().putStringSet("accounts", accounts).apply();
}
Authentication.isLoggedIn = true;
Reddit.notFirst = true;
}
} catch (Exception e) {
new Authentication(getApplicationContext());
}
}
return null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
Aggregations