Search in sources :

Example 6 with Subreddit

use of net.dean.jraw.models.Subreddit in project Slide by ccrama.

the class UserSubscriptions method syncSubredditsGetObject.

public static ArrayList<Subreddit> syncSubredditsGetObject() {
    ArrayList<Subreddit> toReturn = new ArrayList<>();
    if (Authentication.isLoggedIn) {
        UserSubredditsPaginator pag = new UserSubredditsPaginator(Authentication.reddit, "subscriber");
        pag.setLimit(100);
        try {
            while (pag.hasNext()) {
                for (net.dean.jraw.models.Subreddit s : pag.next()) {
                    toReturn.add(s);
                }
            }
        } catch (Exception e) {
            // failed;
            e.printStackTrace();
        }
        addSubsToHistory(toReturn);
        return toReturn;
    }
    return toReturn;
}
Also used : ArrayList(java.util.ArrayList) UserSubredditsPaginator(net.dean.jraw.paginators.UserSubredditsPaginator) Subreddit(net.dean.jraw.models.Subreddit) MultiSubreddit(net.dean.jraw.models.MultiSubreddit) Subreddit(net.dean.jraw.models.Subreddit) ApiException(net.dean.jraw.ApiException) NetworkException(net.dean.jraw.http.NetworkException)

Example 7 with Subreddit

use of net.dean.jraw.models.Subreddit in project Slide by ccrama.

the class UserSubscriptions method syncSubredditsGetObjectAsync.

public static void syncSubredditsGetObjectAsync(final Login mainActivity) {
    final ArrayList<Subreddit> toReturn = new ArrayList<>();
    new AsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackground(Void... params) {
            if (Authentication.isLoggedIn) {
                UserSubredditsPaginator pag = new UserSubredditsPaginator(Authentication.reddit, "subscriber");
                pag.setLimit(100);
                try {
                    while (pag.hasNext()) {
                        for (net.dean.jraw.models.Subreddit s : pag.next()) {
                            toReturn.add(s);
                        }
                    }
                } catch (Exception e) {
                    // failed;
                    e.printStackTrace();
                }
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            mainActivity.doLastStuff(toReturn);
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : ArrayList(java.util.ArrayList) UserSubredditsPaginator(net.dean.jraw.paginators.UserSubredditsPaginator) MultiSubreddit(net.dean.jraw.models.MultiSubreddit) Subreddit(net.dean.jraw.models.Subreddit) ApiException(net.dean.jraw.ApiException) NetworkException(net.dean.jraw.http.NetworkException)

Example 8 with Subreddit

use of net.dean.jraw.models.Subreddit in project Slide by ccrama.

the class SubredditAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder2, final int pos) {
    int i = pos != 0 ? pos - 1 : pos;
    if (holder2 instanceof SubredditViewHolder) {
        final SubredditViewHolder holder = (SubredditViewHolder) holder2;
        final Subreddit sub = dataSet.posts.get(i);
        holder.name.setText(sub.getDisplayName());
        holder.color.setBackgroundResource(R.drawable.circle);
        holder.color.getBackground().setColorFilter(Palette.getColor(sub.getDisplayName().toLowerCase(Locale.ENGLISH)), PorterDuff.Mode.MULTIPLY);
        holder.itemView.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(context, SubredditView.class);
                inte.putExtra(SubredditView.EXTRA_SUBREDDIT, sub.getDisplayName());
                context.startActivityForResult(inte, 4);
            }
        });
        holder.overflow.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(context, SubredditView.class);
                inte.putExtra(SubredditView.EXTRA_SUBREDDIT, sub.getDisplayName());
                context.startActivityForResult(inte, 4);
            }
        });
        holder.body.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(context, SubredditView.class);
                inte.putExtra(SubredditView.EXTRA_SUBREDDIT, sub.getDisplayName());
                context.startActivityForResult(inte, 4);
            }
        });
        if (sub.getDataNode().get("public_description_html").asText().equals("null")) {
            holder.body.setVisibility(View.GONE);
            holder.overflow.setVisibility(View.GONE);
        } else {
            holder.body.setVisibility(View.VISIBLE);
            holder.overflow.setVisibility(View.VISIBLE);
            setViews(sub.getDataNode().get("public_description_html").asText().trim(), sub.getDisplayName().toLowerCase(Locale.ENGLISH), holder.body, holder.overflow);
        }
        try {
            int state = sub.isUserSubscriber() ? View.VISIBLE : View.INVISIBLE;
            holder.subbed.setVisibility(state);
        } catch (Exception e) {
            holder.subbed.setVisibility(View.INVISIBLE);
        }
    } else if (holder2 instanceof SubmissionFooterViewHolder) {
        Handler handler = new Handler();
        final Runnable r = new Runnable() {

            public void run() {
                // the loading spinner to replaced by nomoreposts.xml
                notifyItemChanged(dataSet.posts.size() + 1);
            }
        };
        handler.post(r);
        if (holder2.itemView.findViewById(R.id.reload) != null) {
            holder2.itemView.setVisibility(View.INVISIBLE);
        }
    }
    if (holder2 instanceof SpacerViewHolder) {
        final int height = (context).findViewById(R.id.header).getHeight();
        holder2.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(holder2.itemView.getWidth(), height));
        if (listView.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
            CatchStaggeredGridLayoutManager.LayoutParams layoutParams = new CatchStaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height);
            layoutParams.setFullSpan(true);
            holder2.itemView.setLayoutParams(layoutParams);
        }
    }
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) Handler(android.os.Handler) Intent(android.content.Intent) SubredditView(me.ccrama.redditslide.Activities.SubredditView) SubredditListView(me.ccrama.redditslide.Fragments.SubredditListView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) RecyclerView(android.support.v7.widget.RecyclerView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) View(android.view.View) Subreddit(net.dean.jraw.models.Subreddit) LinearLayout(android.widget.LinearLayout)

Example 9 with Subreddit

use of net.dean.jraw.models.Subreddit in project Slide by ccrama.

the class Login method doSubStrings.

private void doSubStrings(ArrayList<Subreddit> subs) {
    subNames = new CaseInsensitiveArrayList();
    for (Subreddit s : subs) {
        subNames.add(s.getDisplayName().toLowerCase(Locale.ENGLISH));
    }
    subNames = UserSubscriptions.sort(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");
                UserSubscriptions.setSubscriptions(subNames);
                Reddit.forceRestart(Login.this, true);
            }
        }).setNegativeButton(R.string.btn_no, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                UserSubscriptions.setSubscriptions(subNames);
                Reddit.forceRestart(Login.this, true);
            }
        }).setCancelable(false).show();
    } else {
        UserSubscriptions.setSubscriptions(subNames);
        Reddit.forceRestart(Login.this, true);
    }
}
Also used : DialogInterface(android.content.DialogInterface) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) Subreddit(net.dean.jraw.models.Subreddit)

Aggregations

Subreddit (net.dean.jraw.models.Subreddit)9 ArrayList (java.util.ArrayList)5 View (android.view.View)4 ApiException (net.dean.jraw.ApiException)4 MultiSubreddit (net.dean.jraw.models.MultiSubreddit)4 DialogInterface (android.content.DialogInterface)3 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)3 SpoilerRobotoTextView (me.ccrama.redditslide.SpoilerRobotoTextView)3 UserSubredditsPaginator (net.dean.jraw.paginators.UserSubredditsPaginator)3 Dialog (android.app.Dialog)2 Intent (android.content.Intent)2 AsyncTask (android.os.AsyncTask)2 RecyclerView (android.support.v7.widget.RecyclerView)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 Window (android.view.Window)2 ArrayAdapter (android.widget.ArrayAdapter)2 AutoCompleteTextView (android.widget.AutoCompleteTextView)2 EditText (android.widget.EditText)2 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)2