Skip to content

Commit

Permalink
[WIP] Using an object for subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
l3d00m committed Apr 15, 2016
1 parent edc22d1 commit 3c7ef2e
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 101 deletions.
Expand Up @@ -146,7 +146,7 @@ public void onClick(DialogInterface dialog, int which) {
String[] all;

public void showSelectDialog() {
ArrayList<String> sorted = UserSubscriptions.sort(UserSubscriptions.getSubscriptions(this));
ArrayList<String> sorted = UserSubscriptions.sort(UserSubscriptions.getSubscriptionNames(this));
sorted.addAll(subs);
final List<String> s2 = new ArrayList<>(subs);
all = new String[sorted.size()];
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/me/ccrama/redditslide/Activities/Login.java
Expand Up @@ -85,21 +85,21 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) {
}

Dialog d;
ArrayList<String> subNames;
ArrayList<UserSubscriptions.Subscription> subNames;

private void doSubStrings(ArrayList<Subreddit> subs) {
subNames = new ArrayList<>();
for (Subreddit s : subs) {
subNames.add(s.getDisplayName().toLowerCase());
subNames.add(new UserSubscriptions.Subscription(s));
}
subNames = UserSubscriptions.sort(subNames);
subNames = UserSubscriptions.sortSubscriptions(subNames);
if (!subNames.contains("slideforreddit")) {
new AlertDialogWrapper.Builder(Login.this).setTitle(R.string.login_subscribe_rslideforreddit)
.setMessage(R.string.login_subscribe_rslideforreddit_desc)
.setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
subNames.add(2, "slideforreddit");
subNames.add(2, new UserSubscriptions.Subscription("slideforreddit", false));
UserSubscriptions.setSubscriptions(subNames);
Reddit.forceRestart(Login.this, true);
}
Expand Down
Expand Up @@ -115,6 +115,7 @@
import me.ccrama.redditslide.Synccit.SynccitRead;
import me.ccrama.redditslide.TimeUtils;
import me.ccrama.redditslide.UserSubscriptions;
import me.ccrama.redditslide.UserSubscriptions.Subscription;
import me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager;
import me.ccrama.redditslide.Views.CommentOverflow;
import me.ccrama.redditslide.Views.PreCachingLayoutManager;
Expand Down Expand Up @@ -143,7 +144,7 @@ public class MainActivity extends BaseActivity {
public static boolean datasetChanged;
public boolean singleMode;
public ToggleSwipeViewPager pager;
public List<String> usedArray;
public List<Subscription> usedArray;
public DrawerLayout drawerLayout;
public View hea;
public EditText e;
Expand All @@ -162,7 +163,6 @@ public class MainActivity extends BaseActivity {
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putStringArrayList(SUBS, (ArrayList<String>) usedArray);
savedInstanceState.putBoolean(LOGGED_IN, Authentication.isLoggedIn);
savedInstanceState.putBoolean(IS_ONLINE, Authentication.didOnline);
savedInstanceState.putString(USERNAME, Authentication.name);
Expand Down Expand Up @@ -200,7 +200,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
drawerLayout.closeDrawers();
}
} else if (requestCode == TUTORIAL_RESULT) {
UserSubscriptions.doMainActivitySubs(this);
updateSubs(UserSubscriptions.getSubscriptions(this));
} else if (requestCode == INBOX_RESULT) {
//update notification badge
new AsyncNotificationBadge().execute();
Expand Down Expand Up @@ -425,7 +425,8 @@ public void onClick(View v) {
LogUtil.v("Starting main " + Authentication.name);
Authentication.isLoggedIn = Reddit.appRestart.getBoolean("loggedin", false);
Authentication.name = Reddit.appRestart.getString("name", "LOGGEDOUT");
UserSubscriptions.doMainActivitySubs(this);
updateSubs(UserSubscriptions.getSubscriptions(this));

} else if (!first)

{
Expand All @@ -434,7 +435,7 @@ public void onClick(View v) {
Authentication.name = Reddit.appRestart.getString("name", "LOGGEDOUT");
Reddit.appRestart.edit().putBoolean("isRestarting", false).commit();
Reddit.isRestarting = false;
UserSubscriptions.doMainActivitySubs(this);
updateSubs(UserSubscriptions.getSubscriptions(this));
}

if (mTabLayout != null)
Expand Down Expand Up @@ -468,7 +469,7 @@ public void onClick(View v) {
public Runnable runAfterLoad;


public void updateSubs(ArrayList<String> subs) {
public void updateSubs(ArrayList<Subscription> subs) {
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

if (loader != null) {
Expand Down Expand Up @@ -546,7 +547,8 @@ protected Void doInBackground(Void... params) {
}.execute();
}

public void doSubSidebar(final String subreddit) {
public void doSubSidebar(final Subscription subscription) {
final String subreddit = subscription.getName();
if (mAsyncGetSubreddit != null) {
mAsyncGetSubreddit.cancel(true);
}
Expand Down Expand Up @@ -711,7 +713,7 @@ public void reloadSubs() {
}

if (SettingValues.single)
getSupportActionBar().setTitle(shouldLoad);
getSupportActionBar().setTitle(shouldLoad.getName());

}

Expand Down Expand Up @@ -746,7 +748,7 @@ public void updateColor(int color, String subreddit) {

}

public void setDataSet(List<String> data) {
public void setDataSet(List<Subscription> data) {
if (data != null) {
usedArray = data;
if (adapter == null) {
Expand All @@ -763,16 +765,16 @@ public void setDataSet(List<String> data) {
if (toGoto == -1) toGoto = 0;
shouldLoad = usedArray.get(toGoto);
selectedSub = (usedArray.get(toGoto));
themeSystemBars(usedArray.get(toGoto));

header.setBackgroundColor(Palette.getColor(usedArray.get(0)));
themeSystemBars(usedArray.get(toGoto).getName());
header.setBackgroundColor(Palette.getColor(usedArray.get(0).getName()));

if (hea != null) {
hea.setBackgroundColor(Palette.getColor(usedArray.get(0)));
findViewById(R.id.accountsarea).setBackgroundColor(Palette.getDarkerColor(usedArray.get(0)));
hea.setBackgroundColor(Palette.getColor(usedArray.get(0).getName()));
findViewById(R.id.accountsarea).setBackgroundColor(Palette.getDarkerColor(usedArray.get(0).getName()));
}

if (!SettingValues.single) {
mTabLayout.setSelectedTabIndicatorColor(new ColorPreferences(MainActivity.this).getColor(usedArray.get(0)));
mTabLayout.setSelectedTabIndicatorColor(new ColorPreferences(MainActivity.this).getColor(usedArray.get(0).getName()));
shouldLoad = usedArray.get(toGoto);
pager.setCurrentItem(toGoto);
mTabLayout.setupWithViewPager(pager);
Expand All @@ -781,17 +783,17 @@ public void setDataSet(List<String> data) {
scrollToTabAfterLayout(toGoto);
}
} else {
getSupportActionBar().setTitle(usedArray.get(toGoto));
getSupportActionBar().setTitle(usedArray.get(toGoto).getName());
shouldLoad = usedArray.get(toGoto);
pager.setCurrentItem(toGoto);
}

setRecentBar(usedArray.get(toGoto));
setRecentBar(usedArray.get(toGoto).getName());
doSubSidebar(usedArray.get(toGoto));


} else {
UserSubscriptions.doMainActivitySubs(this);
updateSubs(UserSubscriptions.getSubscriptions(this));
}

}
Expand Down Expand Up @@ -863,7 +865,7 @@ public void onCheckedChanged(CompoundButton buttonView, final boolean isChecked)
@Override
public void onPostExecute(Void voids) {
if (isChecked) {
UserSubscriptions.addSubreddit(subreddit.getDisplayName().toLowerCase(), MainActivity.this);
UserSubscriptions.addSubreddit(subreddit, MainActivity.this);
} else {
UserSubscriptions.removeSubreddit(subreddit.getDisplayName().toLowerCase(), MainActivity.this);
pager.setCurrentItem(pager.getCurrentItem() - 1);
Expand Down Expand Up @@ -1173,7 +1175,7 @@ public void onClick(View view) {
@Override
public void onClick(View view) {
Intent inte = new Intent(MainActivity.this, Submit.class);
inte.putExtra(Submit.EXTRA_SUBREDDIT, selectedSub);
inte.putExtra(Submit.EXTRA_SUBREDDIT, selectedSub.getName());
MainActivity.this.startActivity(inte);
}
});
Expand Down Expand Up @@ -1622,7 +1624,7 @@ public void onDrawerOpened(View drawerView) {
SideArrayAdapter sideArrayAdapter;

public void setDrawerSubList() {
ArrayList<String> copy = new ArrayList<>(usedArray);
ArrayList<String> copy = new ArrayList<>(UserSubscriptions.getNamesFromSubscriptions(new ArrayList<Subscription>(usedArray), false));

e = ((EditText) headerMain.findViewById(R.id.sort));

Expand Down Expand Up @@ -1829,7 +1831,7 @@ public boolean onPrepareOptionsMenu(Menu menu) {
mToolbar.getMenu().findItem(R.id.theme).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
final String subreddit = usedArray.get(pager.getCurrentItem());
final String subreddit = usedArray.get(pager.getCurrentItem()).getName();

int style = new ColorPreferences(MainActivity.this).getThemeSubreddit(subreddit);
final Context contextThemeWrapper = new ContextThemeWrapper(MainActivity.this, style);
Expand Down Expand Up @@ -2045,7 +2047,7 @@ public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogActio
return true;
case R.id.submit: {
Intent i = new Intent(this, Submit.class);
i.putExtra(Submit.EXTRA_SUBREDDIT, selectedSub);
i.putExtra(Submit.EXTRA_SUBREDDIT, selectedSub.getName());
startActivity(i);
}
return true;
Expand Down Expand Up @@ -2084,7 +2086,8 @@ public void onClick(DialogInterface dialog, int whichButton) {

boolean[] chosen;

public void filterContent(final String subreddit) {
public void filterContent(final Subscription subscription) {
final String subreddit = subscription.getName();
chosen = new boolean[]{PostMatch.isGif(subreddit), PostMatch.isAlbums(subreddit), PostMatch.isImage(subreddit), PostMatch.isNsfw(subreddit), PostMatch.isSelftext(subreddit), PostMatch.isUrls(subreddit)};

new AlertDialogWrapper.Builder(this)
Expand Down Expand Up @@ -2287,7 +2290,7 @@ public boolean dispatchKeyEvent(KeyEvent event) {
}


public static String shouldLoad;
public static Subscription shouldLoad;

public class OverviewPagerAdapter extends FragmentStatePagerAdapter {
private SubmissionsView mCurrentFragment;
Expand Down Expand Up @@ -2323,20 +2326,22 @@ public void onPageSelected(final int position) {
Toast.makeText(MainActivity.this, getString(R.string.offline_last_update, TimeUtils.getTimeAgo(p.cached.time, MainActivity.this)), Toast.LENGTH_LONG).show();
}
}
final String subName = usedArray.get(position).getName();

if (hea != null) {
hea.setBackgroundColor(Palette.getColor(usedArray.get(position)));
findViewById(R.id.accountsarea).setBackgroundColor(Palette.getDarkerColor(usedArray.get(position)));
hea.setBackgroundColor(Palette.getColor(subName));
findViewById(R.id.accountsarea).setBackgroundColor(Palette.getDarkerColor(subName));
}
header.setBackgroundColor(Palette.getColor(usedArray.get(position)));
header.setBackgroundColor(Palette.getColor(subName));

themeSystemBars(subName);
setRecentBar(subName);

themeSystemBars(usedArray.get(position));
setRecentBar(usedArray.get(position));

if (SettingValues.single || mTabLayout == null)
getSupportActionBar().setTitle(usedArray.get(position));
getSupportActionBar().setTitle(subName);
else mTabLayout.setSelectedTabIndicatorColor(
new ColorPreferences(MainActivity.this).getColor(usedArray.get(position)));
new ColorPreferences(MainActivity.this).getColor(subName));

selectedSub = usedArray.get(position);

Expand Down Expand Up @@ -2386,7 +2391,7 @@ public Fragment getItem(int i) {

SubmissionsView f = new SubmissionsView();
Bundle args = new Bundle();
args.putString("id", usedArray.get(i));
args.putString("id", usedArray.get(i).getName());
f.setArguments(args);

return f;
Expand All @@ -2409,7 +2414,7 @@ public int getCount() {
public CharSequence getPageTitle(int position) {

if (usedArray != null) {
return StringUtils.abbreviate(usedArray.get(position), 25);
return StringUtils.abbreviate(usedArray.get(position).getName(), 25);
} else {
return "";
}
Expand Down Expand Up @@ -2443,20 +2448,22 @@ public void doPageSelectedComments(int position) {
Toast.makeText(MainActivity.this, getString(R.string.offline_last_update, TimeUtils.getTimeAgo(p.cached.time, MainActivity.this)), Toast.LENGTH_LONG).show();
}
}
final String subName = usedArray.get(position).getName();

if (hea != null) {
hea.setBackgroundColor(Palette.getColor(usedArray.get(position)));
findViewById(R.id.accountsarea).setBackgroundColor(Palette.getDarkerColor(usedArray.get(position)));
hea.setBackgroundColor(Palette.getColor(subName));
findViewById(R.id.accountsarea).setBackgroundColor(Palette.getDarkerColor(subName));
}
header.setBackgroundColor(Palette.getColor(usedArray.get(position)));
header.setBackgroundColor(Palette.getColor(subName));

themeSystemBars(subName);
setRecentBar(subName);

themeSystemBars(usedArray.get(position));
setRecentBar(usedArray.get(position));

if (SettingValues.single)
getSupportActionBar().setTitle(usedArray.get(position));
getSupportActionBar().setTitle(subName);
else mTabLayout.setSelectedTabIndicatorColor(
new ColorPreferences(MainActivity.this).getColor(usedArray.get(position)));
new ColorPreferences(MainActivity.this).getColor(subName));

selectedSub = usedArray.get(position);
}
Expand Down Expand Up @@ -2561,7 +2568,7 @@ public Fragment getItem(int i) {
if (openingComments == null || i != toOpenComments) {
SubmissionsView f = new SubmissionsView();
Bundle args = new Bundle();
if (usedArray.size() > i) args.putString("id", usedArray.get(i));
if (usedArray.size() > i) args.putString("id", usedArray.get(i).getName());
f.setArguments(args);
return f;

Expand Down Expand Up @@ -2597,7 +2604,7 @@ public int getCount() {
public CharSequence getPageTitle(int position) {

if (usedArray != null && position != toOpenComments) {
return StringUtils.abbreviate(usedArray.get(position), 25);
return StringUtils.abbreviate(usedArray.get(position).getName(), 25);
} else {
return "";
}
Expand All @@ -2606,7 +2613,7 @@ public CharSequence getPageTitle(int position) {
}
}

public String selectedSub;
public Subscription selectedSub;

public int getCurrentPage() {
int position = 0;
Expand Down
Expand Up @@ -94,7 +94,7 @@ public void onClick(DialogInterface dialog, int which) {
findViewById(R.id.post_floating_action_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final ArrayList<String> subs = UserSubscriptions.sort(UserSubscriptions.getSubscriptions(SettingsSubreddit.this));
final ArrayList<UserSubscriptions.Subscription> subs = UserSubscriptions.sortSubscriptions(UserSubscriptions.getSubscriptions(SettingsSubreddit.this));
final CharSequence[] subsAsChar = subs.toArray(new CharSequence[subs.size()]);

MaterialDialog.Builder builder = new MaterialDialog.Builder(SettingsSubreddit.this);
Expand Down
Expand Up @@ -599,7 +599,7 @@ public void onCheckedChanged(CompoundButton buttonView, final boolean isChecked)
@Override
public void onPostExecute(Void voids) {
if (isChecked) {
UserSubscriptions.addSubreddit(subreddit.getDisplayName().toLowerCase(), SubredditView.this);
UserSubscriptions.addSubreddit(subreddit, SubredditView.this);
} else {
UserSubscriptions.removeSubreddit(subreddit.getDisplayName().toLowerCase(), SubredditView.this);

Expand Down

0 comments on commit 3c7ef2e

Please sign in to comment.