Search in sources :

Example 1 with AwfulError

use of com.ferg.awfulapp.util.AwfulError in project Awful.apk by Awful.

the class FeatureRequest method handleResponse.

@Override
protected Void handleResponse(Document doc) throws AwfulError {
    Element features = doc.getElementsByClass("features").first();
    boolean premium = false;
    boolean archives = false;
    boolean noads = false;
    if (features != null) {
        Elements feature_dts = features.getElementsByTag("dt");
        if (feature_dts.size() == 3) {
            premium = feature_dts.get(0).hasClass("enabled");
            archives = feature_dts.get(1).hasClass("enabled");
            noads = feature_dts.get(2).hasClass("enabled");
            try {
                getPreferences().setPreference(Keys.HAS_PLATINUM, premium);
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                getPreferences().setPreference(Keys.HAS_ARCHIVES, archives);
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                getPreferences().setPreference(Keys.HAS_NO_ADS, noads);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } else {
        throw new AwfulError("Feature page did not load");
    }
    Log.i("FeatureRequest", "Updated account features P:" + premium + " A:" + archives + " NA:" + noads);
    return null;
}
Also used : AwfulError(com.ferg.awfulapp.util.AwfulError) Element(org.jsoup.nodes.Element) Elements(org.jsoup.select.Elements)

Example 2 with AwfulError

use of com.ferg.awfulapp.util.AwfulError in project Awful.apk by Awful.

the class ThreadListRequest method handleResponse.

@Override
protected Void handleResponse(Document doc) throws AwfulError {
    try {
        if (forumId == Constants.USERCP_ID) {
            AwfulForum.parseUCPThreads(doc, page, getContentResolver());
            PmManager.parseUcpPage(doc);
        } else {
            AwfulForum.parseThreads(doc, forumId, page, getContentResolver());
            AnnouncementsManager.getInstance().parseForumPage(doc);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new AwfulError();
    }
    return null;
}
Also used : AwfulError(com.ferg.awfulapp.util.AwfulError)

Example 3 with AwfulError

use of com.ferg.awfulapp.util.AwfulError in project Awful.apk by Awful.

the class AwfulMessage method processMessage.

public static ContentValues processMessage(Document data, int id) throws AwfulError {
    ContentValues message = new ContentValues();
    message.put(ID, id);
    Elements auth = data.getElementsByClass("author");
    if (auth.size() > 0) {
        message.put(AUTHOR, auth.first().text());
    } else {
        throw new AwfulError("Failed parse: author.");
    }
    Elements content = data.getElementsByClass("postbody");
    if (content.size() > 0) {
        message.put(CONTENT, content.first().html());
    } else {
        throw new AwfulError("Failed parse: content.");
    }
    Elements date = data.getElementsByClass("postdate");
    if (date.size() > 0) {
        message.put(DATE, date.first().text().replaceAll("\"", "").trim());
    } else {
        throw new AwfulError("Failed parse: date.");
    }
    return message;
}
Also used : ContentValues(android.content.ContentValues) AwfulError(com.ferg.awfulapp.util.AwfulError) Elements(org.jsoup.select.Elements)

Example 4 with AwfulError

use of com.ferg.awfulapp.util.AwfulError in project Awful.apk by Awful.

the class ThreadDisplayFragment method startPostRedirect.

/**
 * Reload with a new URL
 * @param postUrl	The URL of the post we should land on
 */
private void startPostRedirect(final String postUrl) {
    final AwfulActivity activity = getAwfulActivity();
    if (activity == null) {
        return;
    }
    if (redirect != null) {
        redirect.cancel(false);
    }
    setProgress(50);
    redirect = new RedirectTask(postUrl) {

        @Override
        protected void onPostExecute(String url) {
            if (isCancelled()) {
                return;
            } else if (url == null) {
                getAlertView().show(new AwfulError());
                return;
            }
            AwfulURL result = AwfulURL.parse(url);
            if (postUrl.contains(Constants.VALUE_LASTPOST)) {
                // This is a workaround for how the forums handle the perPage value with goto=lastpost.
                // The redirected url is lacking the perpage=XX value.
                // We just override the assumed (40) with the number we requested when starting the redirect.
                // I gotta ask chooch to fix this at some point.
                result.setPerPage(getPrefs().postPerPage);
            }
            if (result.getType() == TYPE.THREAD) {
                int threadId = (int) result.getId();
                int threadPage = (int) result.getPage(getPrefs().postPerPage);
                String postJump = result.getFragment().replaceAll("\\D", "");
                if (bypassBackStack) {
                    openThread(threadId, threadPage, postJump, true);
                } else {
                    pushThread(threadId, threadPage, postJump);
                }
            } else if (result.getType() == TYPE.INDEX) {
                activity.showForumIndex();
            }
            redirect = null;
            bypassBackStack = false;
            setProgress(100);
        }
    }.execute();
}
Also used : AwfulError(com.ferg.awfulapp.util.AwfulError) RedirectTask(com.ferg.awfulapp.task.RedirectTask) AwfulURL(com.ferg.awfulapp.thread.AwfulURL)

Example 5 with AwfulError

use of com.ferg.awfulapp.util.AwfulError in project Awful.apk by Awful.

the class SearchFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater aInflater, ViewGroup aContainer, Bundle aSavedState) {
    super.onCreateView(aInflater, aContainer, aSavedState);
    Timber.v("onCreateView");
    View result = inflateView(R.layout.search, aContainer, aInflater);
    mSearchQuery = result.findViewById(R.id.search_query);
    mSRL = result.findViewById(R.id.search_srl);
    mSRL.setOnRefreshListener(this);
    mSRL.setColorSchemeResources(ColorProvider.getSRLProgressColors(null));
    mSRL.setProgressBackgroundColor(ColorProvider.getSRLBackgroundColor(null));
    mSRL.setEnabled(false);
    mSearchResultList = result.findViewById(R.id.search_results);
    mSearchResultList.setAdapter(new RecyclerView.Adapter<SearchResultHolder>() {

        @Override
        public SearchResultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.search_result_item, parent, false);
            return new SearchResultHolder(view);
        }

        @Override
        public void onBindViewHolder(SearchResultHolder holder, final int position) {
            AwfulSearch search = mSearchResults.get(position);
            holder.threadName.setText(search.getThreadTitle());
            holder.hitInfo.setText(Html.fromHtml("<b>" + search.getUsername() + "</b> in <b>" + search.getForumTitle() + "</b>"));
            holder.blurb.setText(Html.fromHtml(search.getBlurb()));
            holder.threadName.setText(search.getThreadTitle());
            holder.timestamp.setText(search.getPostDate());
            final String threadlink = search.getThreadLink();
            final int forumId = search.getForumId();
            final ProgressDialog redirectDialog = new ProgressDialog(getContext());
            final RedirectTask redirect = new RedirectTask(Constants.BASE_URL + threadlink) {

                @Override
                protected void onPostExecute(String url) {
                    if (!isCancelled()) {
                        if (url != null) {
                            AwfulURL result = AwfulURL.parse(url);
                            Activity activity = getActivity();
                            Intent openThread = new Intent().setClass(activity, ForumsIndexActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP).putExtra(Constants.THREAD_ID, (int) result.getId()).putExtra(Constants.THREAD_PAGE, (int) result.getPage()).putExtra(Constants.FORUM_ID, forumId).putExtra(Constants.FORUM_PAGE, 1).putExtra(Constants.THREAD_FRAGMENT, result.getFragment().substring(4));
                            redirectDialog.dismiss();
                            activity.finish();
                            startActivity(openThread);
                        } else {
                            getAlertView().show(new AwfulError());
                        }
                    }
                }
            };
            holder.self.setOnClickListener(v -> {
                if (getActivity() != null) {
                    if (redirect.getStatus() == AsyncTask.Status.PENDING) {
                        redirect.execute();
                        redirectDialog.setMessage("Just a second");
                        redirectDialog.setTitle("Loading");
                        redirectDialog.setIndeterminate(true);
                        redirectDialog.setCancelable(false);
                        redirectDialog.show();
                    }
                }
            });
        }

        @Override
        public int getItemCount() {
            if (mSearchResults != null) {
                return mSearchResults.size();
            }
            return 0;
        }
    });
    mSearchResultList.setLayoutManager(new LinearLayoutManager(getContext()));
    return result;
}
Also used : Constants(com.ferg.awfulapp.constants.Constants) SwipyRefreshLayoutDirection(com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayoutDirection) Bundle(android.os.Bundle) AwfulRequest(com.ferg.awfulapp.task.AwfulRequest) RedirectTask(com.ferg.awfulapp.task.RedirectTask) AwfulURL(com.ferg.awfulapp.thread.AwfulURL) Intent(android.content.Intent) ArrayUtils(org.apache.commons.lang3.ArrayUtils) DialogFragment(android.support.v4.app.DialogFragment) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) NetworkUtils(com.ferg.awfulapp.network.NetworkUtils) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) View(android.view.View) ColorProvider(com.ferg.awfulapp.provider.ColorProvider) AsyncTask(android.os.AsyncTask) LayoutInflater(android.view.LayoutInflater) AwfulPreferences(com.ferg.awfulapp.preferences.AwfulPreferences) ProgressDialog(android.app.ProgressDialog) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) VolleyError(com.android.volley.VolleyError) ViewGroup(android.view.ViewGroup) Timber(timber.log.Timber) AwfulError(com.ferg.awfulapp.util.AwfulError) RecyclerView(android.support.v7.widget.RecyclerView) SwipyRefreshLayout(com.ferg.awfulapp.widget.SwipyRefreshLayout) TextView(android.widget.TextView) SearchRequest(com.ferg.awfulapp.task.SearchRequest) SearchResultRequest(com.ferg.awfulapp.task.SearchResultRequest) Html(android.text.Html) AwfulSearch(com.ferg.awfulapp.thread.AwfulSearch) Snackbar(android.support.design.widget.Snackbar) AwfulSearchResult(com.ferg.awfulapp.thread.AwfulSearchResult) Activity(android.app.Activity) EditText(android.widget.EditText) ViewGroup(android.view.ViewGroup) Activity(android.app.Activity) Intent(android.content.Intent) AwfulURL(com.ferg.awfulapp.thread.AwfulURL) AwfulSearch(com.ferg.awfulapp.thread.AwfulSearch) ProgressDialog(android.app.ProgressDialog) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) AwfulError(com.ferg.awfulapp.util.AwfulError) RedirectTask(com.ferg.awfulapp.task.RedirectTask) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

AwfulError (com.ferg.awfulapp.util.AwfulError)8 Element (org.jsoup.nodes.Element)4 Elements (org.jsoup.select.Elements)4 ContentValues (android.content.ContentValues)2 RedirectTask (com.ferg.awfulapp.task.RedirectTask)2 AwfulURL (com.ferg.awfulapp.thread.AwfulURL)2 ArrayList (java.util.ArrayList)2 Activity (android.app.Activity)1 ProgressDialog (android.app.ProgressDialog)1 Intent (android.content.Intent)1 AsyncTask (android.os.AsyncTask)1 Bundle (android.os.Bundle)1 Snackbar (android.support.design.widget.Snackbar)1 DialogFragment (android.support.v4.app.DialogFragment)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Html (android.text.Html)1 LayoutInflater (android.view.LayoutInflater)1 Menu (android.view.Menu)1 MenuInflater (android.view.MenuInflater)1