use of net.dean.jraw.models.CommentSort in project Slide by ccrama.
the class SubmissionComments method getSubmissionNode.
public JsonNode getSubmissionNode(SubmissionRequest request) {
Map<String, String> args = new HashMap<>();
if (request.getDepth() != null)
args.put("depth", Integer.toString(request.getDepth()));
if (request.getContext() != null)
args.put("context", Integer.toString(request.getContext()));
if (request.getLimit() != null)
args.put("limit", Integer.toString(request.getLimit()));
if (request.getFocus() != null && request.getFocus().length() >= 3 && !JrawUtils.isFullname(request.getFocus()))
args.put("comment", request.getFocus());
args.put("feature", "link_preview");
args.put("sr_detail", "true");
args.put("expand_srs", "true");
args.put("from_detail", "true");
args.put("always_show_media", "1");
CommentSort sort = request.getSort();
if (sort == null)
// Reddit sorts by confidence by default
sort = CommentSort.CONFIDENCE;
args.put("sort", sort.name().toLowerCase(Locale.ENGLISH));
RestResponse response = Authentication.reddit.execute(Authentication.reddit.request().path(String.format("/comments/%s", request.getId())).query(args).build());
return response.getJson();
}
use of net.dean.jraw.models.CommentSort in project Slide by ccrama.
the class CommentCacheAsync method doInBackground.
@Override
public Void doInBackground(Object[] params) {
if (Authentication.isLoggedIn && Authentication.me == null || Authentication.reddit == null) {
if (Authentication.reddit == null) {
new Authentication(context);
}
if (Authentication.reddit != null) {
try {
Authentication.me = Authentication.reddit.me();
Authentication.mod = Authentication.me.isMod();
Authentication.authentication.edit().putBoolean(Reddit.SHARED_PREF_IS_MOD, Authentication.mod).apply();
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);
// force commit
Authentication.authentication.edit().putStringSet("accounts", accounts).apply();
}
Authentication.isLoggedIn = true;
Reddit.notFirst = true;
}
} catch (Exception e) {
new Authentication(context);
}
}
}
Map<String, String> multiNameToSubsMap = UserSubscriptions.getMultiNameToSubs(true);
if (Authentication.reddit == null)
Reddit.authentication = new Authentication(context);
ArrayList<String> success = new ArrayList<>();
ArrayList<String> error = new ArrayList<>();
for (final String fSub : subs) {
final String sub;
final String name = fSub;
CommentSort sortType = SettingValues.getCommentSorting(name);
if (multiNameToSubsMap.containsKey(fSub)) {
sub = multiNameToSubsMap.get(fSub);
} else {
sub = fSub;
}
if (!sub.isEmpty()) {
if (!sub.equals(SAVED_SUBMISSIONS)) {
mNotifyManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder = new NotificationCompat.Builder(context);
mBuilder.setOngoing(true);
mBuilder.setChannelId(Reddit.CHANNEL_COMMENT_CACHE);
mBuilder.setContentTitle(context.getString(R.string.offline_caching_title, sub.equalsIgnoreCase("frontpage") ? name : (name.contains("/m/") ? name : "/r/" + name))).setSmallIcon(R.drawable.save_png);
}
List<Submission> submissions = new ArrayList<>();
ArrayList<String> newFullnames = new ArrayList<>();
int count = 0;
if (alreadyReceived != null) {
submissions.addAll(alreadyReceived);
} else {
SubredditPaginator p;
if (name.equalsIgnoreCase("frontpage")) {
p = new SubredditPaginator(Authentication.reddit);
} else {
p = new SubredditPaginator(Authentication.reddit, sub);
}
p.setLimit(Constants.PAGINATOR_POST_LIMIT);
try {
submissions.addAll(p.next());
} catch (Exception e) {
e.printStackTrace();
}
}
int commentDepth = Integer.valueOf(SettingValues.prefs.getString(SettingValues.COMMENT_DEPTH, "5"));
int commentCount = Integer.valueOf(SettingValues.prefs.getString(SettingValues.COMMENT_COUNT, "50"));
Log.v("CommentCacheAsync", "comment count " + commentCount);
int random = (int) (Math.random() * 100);
for (final Submission s : submissions) {
try {
JsonNode n = getSubmission(new SubmissionRequest.Builder(s.getId()).limit(commentCount).depth(commentDepth).sort(sortType).build());
Submission s2 = SubmissionSerializer.withComments(n, CommentSort.CONFIDENCE);
OfflineSubreddit.writeSubmission(n, s2, context);
newFullnames.add(s2.getFullName());
if (!SettingValues.noImages)
loadPhotos(s, context);
switch(ContentType.getContentType(s)) {
case GIF:
if (otherChoices[0]) {
if (context instanceof Activity) {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
ExecutorService service = Executors.newSingleThreadExecutor();
new GifUtils.AsyncLoadGif().executeOnExecutor(service, s.getUrl());
}
});
}
}
break;
case ALBUM:
if (otherChoices[1]) // todo this AlbumUtils.saveAlbumToCache(context, s.getUrl());
{
break;
}
}
} catch (Exception ignored) {
}
count = count + 1;
if (mBuilder != null) {
mBuilder.setProgress(submissions.size(), count, false);
mNotifyManager.notify(random, mBuilder.build());
}
}
OfflineSubreddit.newSubreddit(sub).writeToMemory(newFullnames);
if (mBuilder != null) {
mNotifyManager.cancel(random);
}
if (!submissions.isEmpty())
success.add(sub);
}
}
if (mBuilder != null) {
mBuilder.setContentText(context.getString(R.string.offline_caching_complete)).setSubText(success.size() + " subreddits cached").setProgress(0, 0, false);
mBuilder.setOngoing(false);
mNotifyManager.notify(2001, mBuilder.build());
}
return null;
}
use of net.dean.jraw.models.CommentSort in project Slide by ccrama.
the class SettingsGeneral method onCreate.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
applyColorTheme();
setContentView(R.layout.activity_settings_general);
setupAppBar(R.id.toolbar, R.string.settings_title_general, true, true);
{
SwitchCompat single = (SwitchCompat) findViewById(R.id.immersivemode);
single.setChecked(SettingValues.immersiveMode);
single.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingsTheme.changed = true;
SettingValues.immersiveMode = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_IMMERSIVE_MODE, isChecked).apply();
}
});
}
{
SwitchCompat single = (SwitchCompat) findViewById(R.id.forcelanguage);
single.setChecked(SettingValues.overrideLanguage);
single.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingsTheme.changed = true;
SettingValues.overrideLanguage = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_OVERRIDE_LANGUAGE, isChecked).apply();
}
});
}
{
SwitchCompat single = (SwitchCompat) findViewById(R.id.subfolder);
single.setChecked(SettingValues.imageSubfolders);
single.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingValues.imageSubfolders = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_IMAGE_SUBFOLDERS, isChecked).apply();
}
});
}
{
findViewById(R.id.download).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new FolderChooserDialogCreate.Builder(SettingsGeneral.this).chooseButton(// changes label of the choose button
R.string.btn_select).initialPath(Environment.getExternalStorageDirectory().getPath()).show();
}
});
}
String loc = Reddit.appRestart.getString("imagelocation", getString(R.string.settings_image_location_unset));
((TextView) findViewById(R.id.location)).setText(loc);
{
SwitchCompat single = (SwitchCompat) findViewById(R.id.expandedmenu);
single.setChecked(SettingValues.expandedToolbar);
single.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingValues.expandedToolbar = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_EXPANDED_TOOLBAR, isChecked).apply();
}
});
}
findViewById(R.id.viewtype).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
Intent i = new Intent(SettingsGeneral.this, SettingsViewType.class);
startActivity(i);
}
});
// FAB multi choice//
((TextView) findViewById(R.id.fab_current)).setText(SettingValues.fab ? (SettingValues.fabType == Constants.FAB_DISMISS ? getString(R.string.fab_hide) : getString(R.string.fab_create)) : getString(R.string.fab_disabled));
findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(SettingsGeneral.this, v);
popup.getMenuInflater().inflate(R.menu.fab_settings, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.disabled:
SettingValues.fab = false;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_FAB, false).apply();
break;
case R.id.hide:
SettingValues.fab = true;
SettingValues.fabType = Constants.FAB_DISMISS;
SettingValues.prefs.edit().putInt(SettingValues.PREF_FAB_TYPE, Constants.FAB_DISMISS).apply();
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_FAB, true).apply();
break;
case R.id.create:
SettingValues.fab = true;
SettingValues.fabType = Constants.FAB_POST;
SettingValues.prefs.edit().putInt(SettingValues.PREF_FAB_TYPE, Constants.FAB_POST).apply();
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_FAB, true).apply();
break;
}
((TextView) findViewById(R.id.fab_current)).setText(SettingValues.fab ? (SettingValues.fabType == Constants.FAB_DISMISS ? getString(R.string.fab_hide) : getString(R.string.fab_create)) : getString(R.string.fab_disabled));
return true;
}
});
popup.show();
}
});
// SettingValues.subredditSearchMethod == 1 for drawer, 2 for toolbar, 3 for both
final TextView currentMethodTitle = (TextView) findViewById(R.id.subreddit_search_method_current);
if (SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_DRAWER) {
currentMethodTitle.setText(getString(R.string.subreddit_search_method_drawer));
} else if (SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_TOOLBAR) {
currentMethodTitle.setText(getString(R.string.subreddit_search_method_toolbar));
} else if (SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_BOTH) {
currentMethodTitle.setText(getString(R.string.subreddit_search_method_both));
}
findViewById(R.id.subreddit_search_method).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(SettingsGeneral.this, v);
popup.getMenuInflater().inflate(R.menu.subreddit_search_settings, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.subreddit_search_drawer:
SettingValues.subredditSearchMethod = Constants.SUBREDDIT_SEARCH_METHOD_DRAWER;
SettingValues.prefs.edit().putInt(SettingValues.PREF_SUBREDDIT_SEARCH_METHOD, Constants.SUBREDDIT_SEARCH_METHOD_DRAWER).apply();
SettingsGeneral.searchChanged = true;
break;
case R.id.subreddit_search_toolbar:
SettingValues.subredditSearchMethod = Constants.SUBREDDIT_SEARCH_METHOD_TOOLBAR;
SettingValues.prefs.edit().putInt(SettingValues.PREF_SUBREDDIT_SEARCH_METHOD, Constants.SUBREDDIT_SEARCH_METHOD_TOOLBAR).apply();
SettingsGeneral.searchChanged = true;
break;
case R.id.subreddit_search_both:
SettingValues.subredditSearchMethod = Constants.SUBREDDIT_SEARCH_METHOD_BOTH;
SettingValues.prefs.edit().putInt(SettingValues.PREF_SUBREDDIT_SEARCH_METHOD, Constants.SUBREDDIT_SEARCH_METHOD_BOTH).apply();
SettingsGeneral.searchChanged = true;
break;
}
if (SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_DRAWER) {
currentMethodTitle.setText(getString(R.string.subreddit_search_method_drawer));
} else if (SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_TOOLBAR) {
currentMethodTitle.setText(getString(R.string.subreddit_search_method_toolbar));
} else if (SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_BOTH) {
currentMethodTitle.setText(getString(R.string.subreddit_search_method_both));
}
return true;
}
});
popup.show();
}
});
{
SwitchCompat single = (SwitchCompat) findViewById(R.id.exitcheck);
single.setChecked(SettingValues.exit);
single.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingValues.exit = isChecked;
SettingValues.prefs.edit().putBoolean(SettingValues.PREF_EXIT, isChecked).apply();
}
});
}
if (Reddit.notificationTime > 0) {
((TextView) findViewById(R.id.notifications_current)).setText(getString(R.string.settings_notification_short, TimeUtils.getTimeInHoursAndMins(Reddit.notificationTime, getBaseContext())));
setSubText();
} else {
((TextView) findViewById(R.id.notifications_current)).setText(R.string.settings_notifdisabled);
((TextView) findViewById(R.id.sub_notifs_current)).setText(R.string.settings_enable_notifs);
}
if (Authentication.isLoggedIn) {
findViewById(R.id.notifications).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater inflater = getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.inboxfrequency, null);
setupNotificationSettings(dialoglayout, SettingsGeneral.this);
}
});
findViewById(R.id.sub_notifications).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showSelectDialog();
}
});
} else {
findViewById(R.id.notifications).setEnabled(false);
findViewById(R.id.notifications).setAlpha(0.25f);
findViewById(R.id.sub_notifications).setEnabled(false);
findViewById(R.id.sub_notifications).setAlpha(0.25f);
}
((TextView) findViewById(R.id.sorting_current)).setText(Reddit.getSortingStrings(getBaseContext())[Reddit.getSortingId("")]);
{
findViewById(R.id.sorting).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final DialogInterface.OnClickListener l2 = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
switch(i) {
case 0:
Reddit.defaultSorting = Sorting.HOT;
break;
case 1:
Reddit.defaultSorting = Sorting.NEW;
break;
case 2:
Reddit.defaultSorting = Sorting.RISING;
break;
case 3:
Reddit.defaultSorting = Sorting.TOP;
askTimePeriod();
return;
case 4:
Reddit.defaultSorting = Sorting.CONTROVERSIAL;
askTimePeriod();
return;
}
SettingValues.prefs.edit().putString("defaultSorting", Reddit.defaultSorting.name()).apply();
SettingValues.defaultSorting = Reddit.defaultSorting;
((TextView) findViewById(R.id.sorting_current)).setText(Reddit.getSortingStrings(getBaseContext())[Reddit.getSortingId("")]);
}
};
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(SettingsGeneral.this);
builder.setTitle(R.string.sorting_choose);
builder.setSingleChoiceItems(Reddit.getSortingStrings(getBaseContext()), Reddit.getSortingId(""), l2);
builder.show();
}
});
}
doNotifText();
{
final int i2 = SettingValues.defaultCommentSorting == CommentSort.CONFIDENCE ? 0 : SettingValues.defaultCommentSorting == CommentSort.TOP ? 1 : SettingValues.defaultCommentSorting == CommentSort.NEW ? 2 : SettingValues.defaultCommentSorting == CommentSort.CONTROVERSIAL ? 3 : SettingValues.defaultCommentSorting == CommentSort.OLD ? 4 : SettingValues.defaultCommentSorting == CommentSort.QA ? 5 : 0;
((TextView) findViewById(R.id.sorting_current_comment)).setText(Reddit.getSortingStringsComments(getBaseContext())[i2]);
findViewById(R.id.sorting_comment).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final DialogInterface.OnClickListener l2 = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
CommentSort commentSorting = SettingValues.defaultCommentSorting;
switch(i) {
case 0:
commentSorting = CommentSort.CONFIDENCE;
break;
case 1:
commentSorting = CommentSort.TOP;
break;
case 2:
commentSorting = CommentSort.NEW;
break;
case 3:
commentSorting = CommentSort.CONTROVERSIAL;
break;
case 4:
commentSorting = CommentSort.OLD;
break;
case 5:
commentSorting = CommentSort.QA;
break;
}
SettingValues.prefs.edit().putString("defaultCommentSortingNew", commentSorting.name()).apply();
SettingValues.defaultCommentSorting = commentSorting;
((TextView) findViewById(R.id.sorting_current_comment)).setText(Reddit.getSortingStringsComments(getBaseContext())[i]);
}
};
AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(SettingsGeneral.this);
builder.setTitle(R.string.sorting_choose);
Resources res = getBaseContext().getResources();
builder.setSingleChoiceItems(new String[] { res.getString(R.string.sorting_best), res.getString(R.string.sorting_top), res.getString(R.string.sorting_new), res.getString(R.string.sorting_controversial), res.getString(R.string.sorting_old), res.getString(R.string.sorting_ama) }, i2, l2);
builder.show();
}
});
}
}
use of net.dean.jraw.models.CommentSort in project Slide by ccrama.
the class CommentCacheAsync method getSubmission.
public JsonNode getSubmission(SubmissionRequest request) throws NetworkException {
Map<String, String> args = new HashMap<>();
if (request.getDepth() != null)
args.put("depth", Integer.toString(request.getDepth()));
if (request.getContext() != null) {
args.put("context", Integer.toString(request.getContext()));
}
if (request.getLimit() != null)
args.put("limit", Integer.toString(request.getLimit()));
if (request.getFocus() != null && !JrawUtils.isFullname(request.getFocus())) {
args.put("comment", request.getFocus());
}
CommentSort sort = request.getSort();
if (sort == null) // Reddit sorts by confidence by default
{
sort = CommentSort.CONFIDENCE;
}
args.put("sort", sort.name().toLowerCase(Locale.ENGLISH));
try {
RestResponse response = Authentication.reddit.execute(Authentication.reddit.request().path(String.format("/comments/%s", request.getId())).query(args).build());
return response.getJson();
} catch (Exception e) {
return null;
}
}
Aggregations