use of net.dean.jraw.models.MultiReddit in project Slide by ccrama.
the class ReorderSubreddits method doShowSubs.
public void doShowSubs() {
subs = new CaseInsensitiveArrayList(UserSubscriptions.getSubscriptions(this));
recyclerView = (RecyclerView) findViewById(R.id.subslist);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setItemAnimator(null);
DragSortRecycler dragSortRecycler = new DragSortRecycler();
dragSortRecycler.setViewHandleId();
dragSortRecycler.setFloatingAlpha();
dragSortRecycler.setAutoScrollSpeed();
dragSortRecycler.setAutoScrollWindow();
dragSortRecycler.setOnItemMovedListener(new DragSortRecycler.OnItemMovedListener() {
@Override
public void onItemMoved(int from, int to) {
if (to == subs.size()) {
to -= 1;
}
String item = subs.remove(from);
subs.add(to, item);
adapter.notifyDataSetChanged();
CaseInsensitiveArrayList pinned = UserSubscriptions.getPinned();
if (pinned.contains(item) && pinned.size() != 1) {
pinned.remove(item);
if (to > pinned.size()) {
to = pinned.size();
}
pinned.add(to, item);
setPinned(pinned);
}
}
});
dragSortRecycler.setOnDragStateChangedListener(new DragSortRecycler.OnDragStateChangedListener() {
@Override
public void onDragStart() {
}
@Override
public void onDragStop() {
}
});
final FloatingActionsMenu fab = (FloatingActionsMenu) findViewById(R.id.add);
{
FloatingActionButton collection = (FloatingActionButton) findViewById(R.id.collection);
Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.collection, null);
collection.setIconDrawable(icon);
collection.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fab.collapse();
if (UserSubscriptions.multireddits != null && !UserSubscriptions.multireddits.isEmpty()) {
new AlertDialogWrapper.Builder(ReorderSubreddits.this).setTitle(R.string.create_or_import_multi).setPositiveButton(R.string.btn_new, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
doCollection();
}
}).setNegativeButton(R.string.btn_import_multi, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final String[] multis = new String[UserSubscriptions.multireddits.size()];
int i = 0;
for (MultiReddit m : UserSubscriptions.multireddits) {
multis[i] = m.getDisplayName();
i++;
}
MaterialDialog.Builder builder = new MaterialDialog.Builder(ReorderSubreddits.this);
builder.title(R.string.reorder_subreddits_title).items(multis).itemsCallbackSingleChoice(-1, new MaterialDialog.ListCallbackSingleChoice() {
@Override
public boolean onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
String name = multis[which];
MultiReddit r = UserSubscriptions.getMultiredditByDisplayName(name);
StringBuilder b = new StringBuilder();
for (MultiSubreddit s : r.getSubreddits()) {
b.append(s.getDisplayName());
b.append("+");
}
int pos = addSubAlphabetically(MULTI_REDDIT + r.getDisplayName());
UserSubscriptions.setSubNameToProperties(MULTI_REDDIT + r.getDisplayName(), b.toString());
adapter.notifyDataSetChanged();
recyclerView.smoothScrollToPosition(pos);
return false;
}
}).show();
}
}).show();
} else {
doCollection();
}
}
});
}
{
FloatingActionButton collection = (FloatingActionButton) findViewById(R.id.sub);
Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.sub, null);
collection.setIconDrawable(icon);
collection.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fab.collapse();
MaterialDialog.Builder b = new MaterialDialog.Builder(ReorderSubreddits.this).title(R.string.reorder_add_or_search_subreddit).alwaysCallInputCallback().input(getString(R.string.reorder_subreddit_name), null, false, new MaterialDialog.InputCallback() {
@Override
public void onInput(MaterialDialog dialog, CharSequence raw) {
input = raw.toString();
}
}).positiveText(R.string.btn_add).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(MaterialDialog dialog, DialogAction which) {
new AsyncGetSubreddit().execute(input);
}
}).negativeText(R.string.btn_cancel).onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(MaterialDialog dialog, DialogAction which) {
}
});
b.show();
}
});
}
{
FloatingActionButton collection = (FloatingActionButton) findViewById(R.id.domain);
Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.link, null);
collection.setIconDrawable(icon);
collection.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fab.collapse();
new MaterialDialog.Builder(ReorderSubreddits.this).title(R.string.reorder_add_domain).alwaysCallInputCallback().input("example.com" + getString(R.string.reorder_domain_placeholder), null, false, new MaterialDialog.InputCallback() {
@Override
public void onInput(MaterialDialog dialog, CharSequence raw) {
input = raw.toString().replaceAll("\\s", // remove whitespace from input
"");
if (input.contains(".")) {
dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
} else {
dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false);
}
}
}).positiveText(R.string.btn_add).inputRange(1, 35).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(MaterialDialog dialog, DialogAction which) {
try {
String url = (input);
List<String> sortedSubs = UserSubscriptions.sortNoExtras(subs);
if (sortedSubs.equals(subs)) {
subs.add(url);
subs = UserSubscriptions.sortNoExtras(subs);
adapter = new CustomAdapter(subs);
recyclerView.setAdapter(adapter);
} else {
int pos = addSubAlphabetically(url);
adapter.notifyDataSetChanged();
recyclerView.smoothScrollToPosition(pos);
}
} catch (Exception e) {
e.printStackTrace();
// todo make this better
new AlertDialogWrapper.Builder(ReorderSubreddits.this).setTitle(R.string.reorder_url_err).setMessage(R.string.misc_please_try_again).show();
}
}
}).negativeText(R.string.btn_cancel).onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(MaterialDialog dialog, DialogAction which) {
}
}).show();
}
});
}
recyclerView.addItemDecoration(dragSortRecycler);
recyclerView.addOnItemTouchListener(dragSortRecycler);
recyclerView.addOnScrollListener(dragSortRecycler.getScrollListener());
dragSortRecycler.setViewHandleId();
if (subs != null && !subs.isEmpty()) {
adapter = new CustomAdapter(subs);
// adapter.setHasStableIds(true);
recyclerView.setAdapter(adapter);
} else {
subs = new CaseInsensitiveArrayList();
}
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (recyclerView.getScrollState() == RecyclerView.SCROLL_STATE_DRAGGING) {
diff += dy;
} else {
diff = 0;
}
if (dy <= 0 && fab.getId() != 0) {
} else {
fab.collapse();
}
}
});
}
use of net.dean.jraw.models.MultiReddit in project Slide by ccrama.
the class UserSubscriptions method syncMultiReddits.
public static void syncMultiReddits(Context c) {
try {
multireddits = new ArrayList<>(new MultiRedditManager(Authentication.reddit).mine());
for (MultiReddit multiReddit : multireddits) {
if (MainActivity.multiNameToSubsMap.containsKey(ReorderSubreddits.MULTI_REDDIT + multiReddit.getDisplayName())) {
StringBuilder concatenatedSubs = new StringBuilder();
for (MultiSubreddit subreddit : multiReddit.getSubreddits()) {
concatenatedSubs.append(subreddit.getDisplayName());
concatenatedSubs.append("+");
}
MainActivity.multiNameToSubsMap.put(ReorderSubreddits.MULTI_REDDIT + multiReddit.getDisplayName(), concatenatedSubs.toString());
UserSubscriptions.setSubNameToProperties(ReorderSubreddits.MULTI_REDDIT + multiReddit.getDisplayName(), concatenatedSubs.toString());
}
}
} catch (ApiException e) {
e.printStackTrace();
} catch (NetworkException e) {
e.printStackTrace();
}
}
use of net.dean.jraw.models.MultiReddit in project Slide by ccrama.
the class CreateMulti method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
overrideRedditSwipeAnywhere();
super.onCreate(savedInstanceState);
applyColorTheme();
setContentView(R.layout.activity_createmulti);
setupAppBar(R.id.toolbar, "", true, true);
findViewById(R.id.add).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showSelectDialog();
}
});
title = (EditText) findViewById(R.id.name);
subs = new ArrayList<>();
if (getIntent().hasExtra(EXTRA_MULTI)) {
final String multi = getIntent().getExtras().getString(EXTRA_MULTI);
old = multi;
title.setText(multi.replace("%20", " "));
UserSubscriptions.getMultireddits(new UserSubscriptions.MultiCallback() {
@Override
public void onComplete(List<MultiReddit> multis) {
for (MultiReddit multiReddit : multis) {
if (multiReddit.getDisplayName().equals(multi)) {
for (MultiSubreddit sub : multiReddit.getSubreddits()) {
subs.add(sub.getDisplayName().toLowerCase(Locale.ENGLISH));
}
}
}
}
});
}
recyclerView = (RecyclerView) findViewById(R.id.subslist);
adapter = new CustomAdapter(subs);
// adapter.setHasStableIds(true);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
}
Aggregations