Search in sources :

Example 1 with AwfulPreferences

use of com.ferg.awfulapp.preferences.AwfulPreferences in project Awful.apk by Awful.

the class AwfulWebView method init.

/**
 * Do the basic configuration for the app's WebViews.
 */
private void init() {
    AwfulPreferences prefs = AwfulPreferences.getInstance();
    WebSettings webSettings = getSettings();
    setWebChromeClient(new LoggingWebChromeClient());
    // explicitly setting this since some people are complaining the screen stays on until they toggle it on and off
    setKeepScreenOn(false);
    setBackgroundColor(Color.TRANSPARENT);
    setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDefaultFontSize(prefs.postFontSizeSp);
    webSettings.setDefaultFixedFontSize(prefs.postFixedFontSizeSp);
    webSettings.setDomStorageEnabled(true);
    webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    if (DEBUG) {
        WebView.setWebContentsDebuggingEnabled(true);
    }
    if (prefs.inlineWebm || prefs.inlineVines) {
        webSettings.setMediaPlaybackRequiresUserGesture(false);
    }
    if (prefs.inlineTweets) {
        webSettings.setAllowUniversalAccessFromFileURLs(true);
        webSettings.setAllowFileAccess(true);
        webSettings.setAllowContentAccess(true);
    }
}
Also used : WebSettings(android.webkit.WebSettings) AwfulPreferences(com.ferg.awfulapp.preferences.AwfulPreferences)

Example 2 with AwfulPreferences

use of com.ferg.awfulapp.preferences.AwfulPreferences in project Awful.apk by Awful.

the class WebViewJsInterface method updatePreferences.

/**
 * Updates the JavaScript-accessible preference store from the current values in AwfulPreferences.
 */
public final void updatePreferences() {
    AwfulPreferences aPrefs = AwfulPreferences.getInstance();
    preferences.clear();
    preferences.put("username", aPrefs.username);
    preferences.put("showSpoilers", Boolean.toString(aPrefs.showAllSpoilers));
    preferences.put("highlightUserQuote", Boolean.toString(aPrefs.highlightUserQuote));
    preferences.put("highlightUsername", Boolean.toString(aPrefs.highlightUsername));
    preferences.put("inlineTweets", Boolean.toString(aPrefs.inlineTweets));
    preferences.put("inlineInstagram", Boolean.toString(aPrefs.getPreference(Keys.INLINE_INSTAGRAM, false)));
    preferences.put("inlineTwitch", Boolean.toString(aPrefs.getPreference(Keys.INLINE_TWITCH, false)));
    preferences.put("inlineWebm", Boolean.toString(aPrefs.inlineWebm));
    preferences.put("autostartWebm", Boolean.toString(aPrefs.autostartWebm));
    preferences.put("inlineVines", Boolean.toString(aPrefs.inlineVines));
    preferences.put("disableGifs", Boolean.toString(aPrefs.disableGifs));
    preferences.put("hideSignatures", Boolean.toString(aPrefs.hideSignatures));
    preferences.put("disablePullNext", Boolean.toString(aPrefs.disablePullNext));
    setCustomPreferences(preferences);
}
Also used : AwfulPreferences(com.ferg.awfulapp.preferences.AwfulPreferences)

Example 3 with AwfulPreferences

use of com.ferg.awfulapp.preferences.AwfulPreferences in project Awful.apk by Awful.

the class LoginRequest method handleError.

@Override
protected boolean handleError(AwfulError error, Document doc) {
    if (error.networkResponse != null && error.networkResponse.statusCode == 302) {
        Boolean result = NetworkUtils.saveLoginCookies(getContext());
        if (result) {
            AwfulPreferences prefs = AwfulPreferences.getInstance(getContext());
            prefs.setPreference(Keys.USERNAME, username);
        }
        return result;
    } else {
        return error.isCritical();
    }
}
Also used : AwfulPreferences(com.ferg.awfulapp.preferences.AwfulPreferences)

Example 4 with AwfulPreferences

use of com.ferg.awfulapp.preferences.AwfulPreferences in project Awful.apk by Awful.

the class AwfulLoginActivity method loginClick.

private void loginClick() {
    final String username = NetworkUtils.encodeHtml(mUsername.getText().toString());
    final String password = NetworkUtils.encodeHtml(mPassword.getText().toString());
    mDialog = ProgressDialog.show(AwfulLoginActivity.this, "Logging In", "Hold on...", true);
    final AwfulLoginActivity self = this;
    NetworkUtils.queueRequest(new LoginRequest(this, username, password).build(null, new AwfulRequest.AwfulResultCallback<Boolean>() {

        @Override
        public void success(Boolean result) {
            onLoginSuccess();
        }

        @Override
        public void failure(VolleyError error) {
            // Volley sometimes generates NetworkErrors with no response set, or wraps them
            NetworkResponse response = error.networkResponse;
            if (response == null) {
                Throwable cause = error.getCause();
                if (cause != null && cause instanceof VolleyError) {
                    response = ((VolleyError) cause).networkResponse;
                }
            }
            if (response != null && response.statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
                Boolean result = NetworkUtils.saveLoginCookies(getApplicationContext());
                if (result) {
                    // TODO: this should probably be handled by firing a ProfileRequest and getting the username from there, maybe through SyncManager
                    AwfulPreferences prefs = AwfulPreferences.getInstance(getApplicationContext());
                    prefs.setPreference(Keys.USERNAME, username);
                    onLoginSuccess();
                } else {
                    onLoginFailed();
                }
            } else {
                onLoginFailed();
            }
        }

        private void onLoginSuccess() {
            mDialog.dismiss();
            Toast.makeText(AwfulLoginActivity.this, R.string.login_succeeded, Toast.LENGTH_SHORT).show();
            setResult(Activity.RESULT_OK);
            self.finish();
        }

        private void onLoginFailed() {
            mDialog.dismiss();
            Toast.makeText(AwfulLoginActivity.this, R.string.login_failed, Toast.LENGTH_SHORT).show();
            setResult(Activity.RESULT_CANCELED);
        }
    }));
}
Also used : VolleyError(com.android.volley.VolleyError) NetworkResponse(com.android.volley.NetworkResponse) LoginRequest(com.ferg.awfulapp.task.LoginRequest) AwfulPreferences(com.ferg.awfulapp.preferences.AwfulPreferences)

Example 5 with AwfulPreferences

use of com.ferg.awfulapp.preferences.AwfulPreferences in project Awful.apk by Awful.

the class PostContextMenu method generateMenuItems.

@NonNull
@Override
List<PostMenuAction> generateMenuItems() {
    AwfulPreferences prefs = AwfulPreferences.getInstance();
    boolean youHavePlat = prefs.hasPlatinum;
    boolean ownPost = prefs.username.equals(posterUsername);
    List<PostMenuAction> awfulActions = new ArrayList<>();
    awfulActions.add(PostMenuAction.QUOTE);
    if (editable) {
        awfulActions.add(EDIT);
    }
    awfulActions.add(MARK_LAST_SEEN);
    if (!ownPost && youHavePlat && (posterHasPlat || posterIsAdminOrMod)) {
        awfulActions.add(SEND_PM);
    }
    awfulActions.add(ownPost ? YOUR_POSTS : USER_POSTS);
    if (!ownPost) {
        awfulActions.add(prefs.markedUsers.contains(posterUsername) ? UNMARK_USER : MARK_USER);
    }
    if (!ownPost && youHavePlat && !posterIsAdminOrMod) {
        awfulActions.add(REPORT_POST);
    }
    awfulActions.add(COPY_URL);
    if (!ownPost) {
        awfulActions.add(IGNORE_USER);
    }
    return awfulActions;
}
Also used : ArrayList(java.util.ArrayList) AwfulPreferences(com.ferg.awfulapp.preferences.AwfulPreferences) NonNull(android.support.annotation.NonNull)

Aggregations

AwfulPreferences (com.ferg.awfulapp.preferences.AwfulPreferences)7 NonNull (android.support.annotation.NonNull)2 ArrayList (java.util.ArrayList)2 WebSettings (android.webkit.WebSettings)1 NetworkResponse (com.android.volley.NetworkResponse)1 VolleyError (com.android.volley.VolleyError)1 LoginRequest (com.ferg.awfulapp.task.LoginRequest)1 AwfulPost (com.ferg.awfulapp.thread.AwfulPost)1 Element (org.jsoup.nodes.Element)1 Elements (org.jsoup.select.Elements)1