use of me.ccrama.redditslide.CaseInsensitiveArrayList in project Slide by ccrama.
the class MultiredditOverview method doDrawerSubs.
public void doDrawerSubs(int position) {
MultiReddit current = usedArray.get(position);
LinearLayout l = (LinearLayout) findViewById(R.id.sidebar_scroll);
l.removeAllViews();
CaseInsensitiveArrayList toSort = new CaseInsensitiveArrayList();
for (MultiSubreddit s : current.getSubreddits()) {
toSort.add(s.getDisplayName().toLowerCase(Locale.ENGLISH));
}
for (String sub : UserSubscriptions.sortNoExtras(toSort)) {
final View convertView = getLayoutInflater().inflate(R.layout.subforsublist, l, false);
final String subreddit = sub;
final TextView t = ((TextView) convertView.findViewById(R.id.name));
t.setText(subreddit);
convertView.findViewById(R.id.color).setBackgroundResource(R.drawable.circle);
convertView.findViewById(R.id.color).getBackground().setColorFilter(Palette.getColor(subreddit), PorterDuff.Mode.MULTIPLY);
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent inte = new Intent(MultiredditOverview.this, SubredditView.class);
inte.putExtra(SubredditView.EXTRA_SUBREDDIT, subreddit);
MultiredditOverview.this.startActivityForResult(inte, 4);
}
});
l.addView(convertView);
}
}
use of me.ccrama.redditslide.CaseInsensitiveArrayList 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 me.ccrama.redditslide.CaseInsensitiveArrayList in project Slide by ccrama.
the class ReorderSubreddits method onPause.
@Override
public void onPause() {
try {
UserSubscriptions.setSubscriptions(new CaseInsensitiveArrayList(subs));
SettingsTheme.changed = true;
} catch (Exception e) {
}
super.onPause();
}
use of me.ccrama.redditslide.CaseInsensitiveArrayList in project Slide by ccrama.
the class MainActivity method setDataSet.
public void setDataSet(List<String> data) {
if (data != null && !data.isEmpty()) {
usedArray = new CaseInsensitiveArrayList(data);
if (adapter == null) {
if (commentPager && singleMode) {
adapter = new OverviewPagerAdapterComment(getSupportFragmentManager());
} else {
adapter = new OverviewPagerAdapter(getSupportFragmentManager());
}
} else {
adapter.notifyDataSetChanged();
}
pager.setAdapter(adapter);
pager.setOffscreenPageLimit(1);
if (toGoto == -1) {
toGoto = 0;
}
if (toGoto >= usedArray.size()) {
toGoto -= 1;
}
shouldLoad = usedArray.get(toGoto);
selectedSub = (usedArray.get(toGoto));
themeSystemBars(usedArray.get(toGoto));
final String USEDARRAY_0 = usedArray.get(0);
header.setBackgroundColor(Palette.getColor(USEDARRAY_0));
if (hea != null) {
hea.setBackgroundColor(Palette.getColor(USEDARRAY_0));
if (accountsArea != null) {
accountsArea.setBackgroundColor(Palette.getDarkerColor(USEDARRAY_0));
}
}
if (!SettingValues.single) {
mTabLayout.setSelectedTabIndicatorColor(new ColorPreferences(MainActivity.this).getColor(USEDARRAY_0));
pager.setCurrentItem(toGoto);
mTabLayout.setupWithViewPager(pager);
if (mTabLayout != null) {
mTabLayout.setupWithViewPager(pager);
scrollToTabAfterLayout(toGoto);
}
} else {
getSupportActionBar().setTitle(usedArray.get(toGoto));
pager.setCurrentItem(toGoto);
}
setToolbarClick();
setRecentBar(usedArray.get(toGoto));
doSubSidebarNoLoad(usedArray.get(toGoto));
} else if (NetworkUtil.isConnected(this)) {
UserSubscriptions.doMainActivitySubs(this);
}
}
use of me.ccrama.redditslide.CaseInsensitiveArrayList in project Slide by ccrama.
the class NewsActivity method setDataSet.
public void setDataSet(List<String> data) {
if (data != null && !data.isEmpty()) {
usedArray = new CaseInsensitiveArrayList(data);
if (adapter == null) {
adapter = new OverviewPagerAdapter(getSupportFragmentManager());
} else {
adapter.notifyDataSetChanged();
}
pager.setAdapter(adapter);
pager.setOffscreenPageLimit(1);
if (toGoto == -1) {
toGoto = 0;
}
if (toGoto >= usedArray.size()) {
toGoto -= 1;
}
shouldLoad = usedArray.get(toGoto);
selectedSub = (usedArray.get(toGoto));
themeSystemBars(usedArray.get(toGoto));
final String USEDARRAY_0 = usedArray.get(0);
mTabLayout.setSelectedTabIndicatorColor(new ColorPreferences(NewsActivity.this).getColor(USEDARRAY_0));
pager.setCurrentItem(toGoto);
mTabLayout.setupWithViewPager(pager);
if (mTabLayout != null) {
mTabLayout.setupWithViewPager(pager);
scrollToTabAfterLayout(toGoto);
}
setToolbarClick();
} else if (NetworkUtil.isConnected(this)) {
UserSubscriptions.doNewsSubs(this);
}
}
Aggregations