Search in sources :

Example 1 with Authentication

use of me.ccrama.redditslide.Authentication in project Slide by ccrama.

the class Login method onCreate.

@Override
public void onCreate(Bundle savedInstance) {
    overrideSwipeFromAnywhere();
    super.onCreate(savedInstance);
    applyColorTheme("");
    try {
        setContentView(R.layout.activity_login);
    } catch (Exception e) {
        finish();
        return;
    }
    setupAppBar(R.id.toolbar, R.string.title_login, true, true);
    String[] scopes = { "identity", "modcontributors", "modconfig", "modothers", "modwiki", "creddits", "livemanage", "account", "privatemessages", "modflair", "modlog", "report", "modposts", "modwiki", "read", "vote", "edit", "submit", "subscribe", "save", "wikiread", "flair", "history", "mysubreddits" };
    if (Authentication.reddit == null) {
        new Authentication(getApplicationContext());
    }
    final OAuthHelper oAuthHelper = Authentication.reddit.getOAuthHelper();
    final Credentials credentials = Credentials.installedApp(CLIENT_ID, REDIRECT_URL);
    String authorizationUrl = oAuthHelper.getAuthorizationUrl(credentials, true, scopes).toExternalForm();
    authorizationUrl = authorizationUrl.replace("www.", "i.");
    authorizationUrl = authorizationUrl.replace("%3A%2F%2Fi", "://www");
    Log.v(LogUtil.getTag(), "Auth URL: " + authorizationUrl);
    final WebView webView = (WebView) findViewById(R.id.web);
    webView.clearCache(true);
    webView.clearHistory();
    WebSettings webSettings = webView.getSettings();
    webSettings.setSaveFormData(false);
    // Not needed for API level 18 or greater (deprecated)
    webSettings.setSavePassword(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        CookieManager.getInstance().removeAllCookies(null);
        CookieManager.getInstance().flush();
    } else {
        CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(this);
        cookieSyncMngr.startSync();
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncMngr.stopSync();
        cookieSyncMngr.sync();
    }
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            if (url.contains("code=")) {
                Log.v(LogUtil.getTag(), "WebView URL: " + url);
                // Authentication code received, prevent HTTP call from being made.
                webView.stopLoading();
                new UserChallengeTask(oAuthHelper, credentials).execute(url);
                webView.setVisibility(View.GONE);
            }
        }
    });
    webView.loadUrl(authorizationUrl);
}
Also used : OAuthHelper(net.dean.jraw.http.oauth.OAuthHelper) OAuthException(net.dean.jraw.http.oauth.OAuthException) NetworkException(net.dean.jraw.http.NetworkException) Bitmap(android.graphics.Bitmap) Authentication(me.ccrama.redditslide.Authentication) WebSettings(android.webkit.WebSettings) CookieSyncManager(android.webkit.CookieSyncManager) WebView(android.webkit.WebView) Credentials(net.dean.jraw.http.oauth.Credentials) CookieManager(android.webkit.CookieManager) WebViewClient(android.webkit.WebViewClient)

Example 2 with Authentication

use of me.ccrama.redditslide.Authentication in project Slide by ccrama.

the class CheckForMailSingle method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    c = context;
    if (Authentication.reddit == null || !Authentication.reddit.isAuthenticated()) {
        Reddit.authentication = new Authentication(context);
    }
    new AsyncGetMailSingle().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Authentication(me.ccrama.redditslide.Authentication)

Example 3 with Authentication

use of me.ccrama.redditslide.Authentication in project Slide by ccrama.

the class ListViewRemoteViewsFactory method onCreate.

// Initialize the data set.
public void onCreate() {
    // In onCreate() you set up any connections / cursors to your data source. Heavy lifting,
    // for example downloading or creating content etc, should be deferred to onDataSetChanged()
    // or getViewAt(). Taking more than 20 seconds in this call will result in an ANR.
    records = new ArrayList<>();
    if (NetworkUtil.isConnected(mContext)) {
        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                if (Authentication.reddit == null) {
                    new Authentication(mContext.getApplicationContext());
                    Authentication.me = Authentication.reddit.me();
                    Authentication.mod = Authentication.me.isMod();
                    Authentication.authentication.edit().putBoolean(Reddit.SHARED_PREF_IS_MOD, Authentication.mod).apply();
                    if (Reddit.notificationTime != -1) {
                        Reddit.notifications = new NotificationJobScheduler(mContext);
                        Reddit.notifications.start(mContext.getApplicationContext());
                    }
                    if (Reddit.cachedData.contains("toCache")) {
                        Reddit.autoCache = new AutoCacheScheduler(mContext);
                        Reddit.autoCache.start(mContext.getApplicationContext());
                    }
                    final String name = Authentication.me.getFullName();
                    Authentication.name = name;
                    LogUtil.v("AUTHENTICATED");
                    if (Authentication.reddit.isAuthenticated()) {
                        final Set<String> accounts = Authentication.authentication.getStringSet("accounts", new HashSet<String>());
                        if (accounts.contains(name)) {
                            // convert to new system
                            accounts.remove(name);
                            accounts.add(name + ":" + Authentication.refresh);
                            Authentication.authentication.edit().putStringSet("accounts", accounts).apply();
                        }
                        Authentication.isLoggedIn = true;
                        Reddit.notFirst = true;
                    }
                }
                String sub = SubredditWidgetProvider.getSubFromId(id, mContext);
                Paginator p;
                if (sub.equals("frontpage")) {
                    p = new SubredditPaginator(Authentication.reddit);
                } else if (!sub.contains(".")) {
                    p = new SubredditPaginator(Authentication.reddit, sub);
                } else {
                    p = new DomainPaginator(Authentication.reddit, sub);
                }
                p.setLimit(50);
                switch(SubredditWidgetProvider.getSorting(id, mContext)) {
                    case 0:
                        p.setSorting(Sorting.HOT);
                        break;
                    case 1:
                        p.setSorting(Sorting.NEW);
                        break;
                    case 2:
                        p.setSorting(Sorting.RISING);
                        break;
                    case 3:
                        p.setSorting(Sorting.TOP);
                        break;
                    case 4:
                        p.setSorting(Sorting.CONTROVERSIAL);
                        break;
                }
                switch(SubredditWidgetProvider.getSortingTime(id, mContext)) {
                    case 0:
                        p.setTimePeriod(TimePeriod.HOUR);
                        break;
                    case 1:
                        p.setTimePeriod(TimePeriod.DAY);
                        break;
                    case 2:
                        p.setTimePeriod(TimePeriod.WEEK);
                        break;
                    case 3:
                        p.setTimePeriod(TimePeriod.MONTH);
                        break;
                    case 4:
                        p.setTimePeriod(TimePeriod.YEAR);
                        break;
                    case 5:
                        p.setTimePeriod(TimePeriod.ALL);
                        break;
                }
                try {
                    ArrayList<Submission> s = new ArrayList<>(p.next());
                    records = new ArrayList<>();
                    for (Submission subm : s) {
                        if (!PostMatch.doesMatch(subm) && !subm.isStickied()) {
                            records.add(subm);
                        }
                    }
                } catch (Exception e) {
                }
                return null;
            }

            @Override
            protected void onPostExecute(Void aVoid) {
                Intent widgetUpdateIntent = new Intent(mContext, SubredditWidgetProvider.class);
                widgetUpdateIntent.setAction(SubredditWidgetProvider.UPDATE_MEETING_ACTION);
                widgetUpdateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
                mContext.sendBroadcast(widgetUpdateIntent);
            }
        }.execute();
    } else {
        Intent widgetUpdateIntent = new Intent(mContext, SubredditWidgetProvider.class);
        widgetUpdateIntent.setAction(SubredditWidgetProvider.UPDATE_MEETING_ACTION);
        widgetUpdateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
        mContext.sendBroadcast(widgetUpdateIntent);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) AutoCacheScheduler(me.ccrama.redditslide.Autocache.AutoCacheScheduler) Submission(net.dean.jraw.models.Submission) ArrayList(java.util.ArrayList) DomainPaginator(net.dean.jraw.paginators.DomainPaginator) Intent(android.content.Intent) NotificationJobScheduler(me.ccrama.redditslide.Notifications.NotificationJobScheduler) DomainPaginator(net.dean.jraw.paginators.DomainPaginator) SubredditPaginator(net.dean.jraw.paginators.SubredditPaginator) Paginator(net.dean.jraw.paginators.Paginator) SubredditPaginator(net.dean.jraw.paginators.SubredditPaginator) Authentication(me.ccrama.redditslide.Authentication) HashSet(java.util.HashSet)

Example 4 with Authentication

use of me.ccrama.redditslide.Authentication in project Slide by ccrama.

the class Inbox method onCreate.

@Override
public void onCreate(Bundle savedInstance) {
    overrideSwipeFromAnywhere();
    if (Authentication.reddit == null || !Authentication.reddit.isAuthenticated() || Authentication.me == null) {
        LogUtil.v("Reauthenticating");
        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                if (Authentication.reddit == null) {
                    new Authentication(getApplicationContext());
                }
                try {
                    Authentication.me = Authentication.reddit.me();
                    Authentication.mod = Authentication.me.isMod();
                    Authentication.authentication.edit().putBoolean(Reddit.SHARED_PREF_IS_MOD, Authentication.mod).apply();
                    if (Reddit.notificationTime != -1) {
                        Reddit.notifications = new NotificationJobScheduler(Inbox.this);
                        Reddit.notifications.start(getApplicationContext());
                    }
                    if (Reddit.cachedData.contains("toCache")) {
                        Reddit.autoCache = new AutoCacheScheduler(Inbox.this);
                        Reddit.autoCache.start(getApplicationContext());
                    }
                    final String name = Authentication.me.getFullName();
                    Authentication.name = name;
                    LogUtil.v("AUTHENTICATED");
                    UserSubscriptions.doCachedModSubs();
                    if (Authentication.reddit.isAuthenticated()) {
                        final Set<String> accounts = Authentication.authentication.getStringSet("accounts", new HashSet<String>());
                        if (accounts.contains(name)) {
                            // convert to new system
                            accounts.remove(name);
                            accounts.add(name + ":" + Authentication.refresh);
                            Authentication.authentication.edit().putStringSet("accounts", accounts).apply();
                        }
                        Authentication.isLoggedIn = true;
                        Reddit.notFirst = true;
                    }
                } catch (Exception ignored) {
                }
                return null;
            }
        }.execute();
    }
    super.onCreate(savedInstance);
    last = SettingValues.prefs.getLong("lastInbox", System.currentTimeMillis() - (60 * 1000 * 60));
    SettingValues.prefs.edit().putLong("lastInbox", System.currentTimeMillis()).apply();
    applyColorTheme("");
    setContentView(R.layout.activity_inbox);
    setupAppBar(R.id.toolbar, R.string.title_inbox, true, true);
    mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
    tabs = (TabLayout) findViewById(R.id.sliding_tabs);
    tabs.setTabMode(TabLayout.MODE_SCROLLABLE);
    tabs.setSelectedTabIndicatorColor(new ColorPreferences(Inbox.this).getColor("no sub"));
    pager = (ViewPager) findViewById(R.id.content_view);
    findViewById(R.id.header).setBackgroundColor(Palette.getDefaultColor());
    adapter = new OverviewPagerAdapter(getSupportFragmentManager());
    pager.setAdapter(adapter);
    if (getIntent() != null && getIntent().hasExtra(EXTRA_UNREAD)) {
        pager.setCurrentItem(1);
    }
    tabs.setupWithViewPager(pager);
    pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            findViewById(R.id.header).animate().translationY(0).setInterpolator(new LinearInterpolator()).setDuration(180);
            if (position == 3 && findViewById(R.id.read) != null) {
                findViewById(R.id.read).setVisibility(View.GONE);
            } else if (findViewById(R.id.read) != null) {
                findViewById(R.id.read).setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) AutoCacheScheduler(me.ccrama.redditslide.Autocache.AutoCacheScheduler) ColorPreferences(me.ccrama.redditslide.ColorPreferences) NotificationJobScheduler(me.ccrama.redditslide.Notifications.NotificationJobScheduler) ViewPager(android.support.v4.view.ViewPager) LinearInterpolator(android.view.animation.LinearInterpolator) Authentication(me.ccrama.redditslide.Authentication) HashSet(java.util.HashSet)

Example 5 with Authentication

use of me.ccrama.redditslide.Authentication in project Slide by ccrama.

the class CommentsScreenSingle method onCreate.

@Override
public void onCreate(Bundle savedInstance) {
    disableSwipeBackLayout();
    getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    getWindow().getDecorView().setBackgroundDrawable(null);
    super.onCreate(savedInstance);
    applyColorTheme();
    setContentView(R.layout.activity_slide);
    name = getIntent().getExtras().getString(EXTRA_SUBMISSION, "");
    subreddit = getIntent().getExtras().getString(EXTRA_SUBREDDIT, "");
    np = getIntent().getExtras().getBoolean(EXTRA_NP, false);
    context = getIntent().getExtras().getString(EXTRA_CONTEXT, "");
    contextNumber = getIntent().getExtras().getInt(EXTRA_CONTEXT_NUMBER, 5);
    if (subreddit.equals(Reddit.EMPTY_STRING)) {
        new AsyncGetSubredditName().execute(name);
        TypedValue typedValue = new TypedValue();
        getTheme().resolveAttribute(R.attr.activity_background, typedValue, true);
        int color = typedValue.data;
        findViewById(R.id.content_view).setBackgroundColor(color);
    } else {
        setupAdapter();
    }
    if (Authentication.isLoggedIn && Authentication.me == null) {
        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                if (Authentication.reddit == null) {
                    new Authentication(getApplicationContext());
                } else {
                    try {
                        Authentication.me = Authentication.reddit.me();
                        Authentication.mod = Authentication.me.isMod();
                        Authentication.authentication.edit().putBoolean(Reddit.SHARED_PREF_IS_MOD, Authentication.mod).apply();
                        if (Reddit.notificationTime != -1) {
                            Reddit.notifications = new NotificationJobScheduler(CommentsScreenSingle.this);
                            Reddit.notifications.start(getApplicationContext());
                        }
                        if (Reddit.cachedData.contains("toCache")) {
                            Reddit.autoCache = new AutoCacheScheduler(CommentsScreenSingle.this);
                            Reddit.autoCache.start(getApplicationContext());
                        }
                        final String name = Authentication.me.getFullName();
                        Authentication.name = name;
                        LogUtil.v("AUTHENTICATED");
                        UserSubscriptions.doCachedModSubs();
                        if (Authentication.reddit.isAuthenticated()) {
                            final Set<String> accounts = Authentication.authentication.getStringSet("accounts", new HashSet<String>());
                            if (accounts.contains(name)) {
                                // convert to new system
                                accounts.remove(name);
                                accounts.add(name + ":" + Authentication.refresh);
                                Authentication.authentication.edit().putStringSet("accounts", accounts).apply();
                            }
                            Authentication.isLoggedIn = true;
                            Reddit.notFirst = true;
                        }
                    } catch (Exception e) {
                        new Authentication(getApplicationContext());
                    }
                }
                return null;
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) AutoCacheScheduler(me.ccrama.redditslide.Autocache.AutoCacheScheduler) NotificationJobScheduler(me.ccrama.redditslide.Notifications.NotificationJobScheduler) ColorDrawable(android.graphics.drawable.ColorDrawable) Authentication(me.ccrama.redditslide.Authentication) TypedValue(android.util.TypedValue) HashSet(java.util.HashSet)

Aggregations

Authentication (me.ccrama.redditslide.Authentication)5 HashSet (java.util.HashSet)3 Set (java.util.Set)3 AutoCacheScheduler (me.ccrama.redditslide.Autocache.AutoCacheScheduler)3 NotificationJobScheduler (me.ccrama.redditslide.Notifications.NotificationJobScheduler)3 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 ViewPager (android.support.v4.view.ViewPager)1 TypedValue (android.util.TypedValue)1 LinearInterpolator (android.view.animation.LinearInterpolator)1 CookieManager (android.webkit.CookieManager)1 CookieSyncManager (android.webkit.CookieSyncManager)1 WebSettings (android.webkit.WebSettings)1 WebView (android.webkit.WebView)1 WebViewClient (android.webkit.WebViewClient)1 ArrayList (java.util.ArrayList)1 ColorPreferences (me.ccrama.redditslide.ColorPreferences)1 NetworkException (net.dean.jraw.http.NetworkException)1 Credentials (net.dean.jraw.http.oauth.Credentials)1