Search in sources :

Example 11 with ColorPreferences

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

the class NewsActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    inNightMode = SettingValues.isNight();
    disableSwipeBackLayout();
    super.onCreate(savedInstanceState);
    applyColorTheme();
    setContentView(R.layout.activity_news);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
    setSupportActionBar(mToolbar);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = this.getWindow();
        window.setStatusBarColor(Palette.getDarkerColor(Palette.getDarkerColor(Palette.getDefaultColor())));
    }
    mTabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
    header = findViewById(R.id.header);
    pager = (ToggleSwipeViewPager) findViewById(R.id.content_view);
    mTabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
    UserSubscriptions.doNewsSubs(NewsActivity.this);
    /**
     * int for the current base theme selected.
     * 0 = Dark, 1 = Light, 2 = AMOLED, 3 = Dark blue, 4 = AMOLED with contrast, 5 = Sepia
     */
    SettingValues.currentTheme = new ColorPreferences(this).getFontStyle().getThemeType();
    networkStateReceiver = new NetworkStateReceiver();
    networkStateReceiver.addListener(this);
    try {
        this.registerReceiver(networkStateReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION));
    } catch (Exception e) {
    }
}
Also used : Window(android.view.Window) IntentFilter(android.content.IntentFilter) ColorPreferences(me.ccrama.redditslide.ColorPreferences) NetworkStateReceiver(me.ccrama.redditslide.util.NetworkStateReceiver)

Example 12 with ColorPreferences

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

the class PostReadLater method onCreate.

@Override
public void onCreate(Bundle savedInstance) {
    overrideSwipeFromAnywhere();
    super.onCreate(savedInstance);
    applyColorTheme();
    setContentView(R.layout.activity_read_later);
    setupAppBar(R.id.toolbar, "Read later", true, true);
    mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
    pager = (ViewPager) findViewById(R.id.content_view);
    pager.setAdapter(new ReadLaterAdaptor(getSupportFragmentManager()));
}
Also used : ColorPreferences(me.ccrama.redditslide.ColorPreferences)

Example 13 with ColorPreferences

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

the class Related method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    overrideSwipeFromAnywhere();
    super.onCreate(savedInstanceState);
    applyColorTheme("");
    setContentView(R.layout.activity_search);
    Intent intent = getIntent();
    if (intent.hasExtra(Intent.EXTRA_TEXT) && !intent.getExtras().getString(Intent.EXTRA_TEXT, "").isEmpty()) {
        url = intent.getStringExtra(Intent.EXTRA_TEXT);
    }
    if (intent.hasExtra(EXTRA_URL)) {
        url = intent.getStringExtra(EXTRA_URL);
    }
    if (url == null || url.isEmpty()) {
        new AlertDialogWrapper.Builder(this).setTitle("URL is empty").setMessage("Try again with a different link!").setCancelable(false).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                finish();
            }
        }).show();
    } else {
    }
    setupAppBar(R.id.toolbar, "Related links", true, true);
    // it won't be, trust me
    assert mToolbar != null;
    mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
    final RecyclerView rv = ((RecyclerView) findViewById(R.id.vertical_content));
    final PreCachingLayoutManager mLayoutManager;
    mLayoutManager = new PreCachingLayoutManager(this);
    rv.setLayoutManager(mLayoutManager);
    rv.addOnScrollListener(new ToolbarScrollHideHandler(mToolbar, findViewById(R.id.header)) {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            visibleItemCount = rv.getLayoutManager().getChildCount();
            totalItemCount = rv.getLayoutManager().getItemCount();
            if (rv.getLayoutManager() instanceof PreCachingLayoutManager) {
                pastVisiblesItems = ((PreCachingLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition();
            } else {
                int[] firstVisibleItems = null;
                firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(firstVisibleItems);
                if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                    pastVisiblesItems = firstVisibleItems[0];
                }
            }
            if (!posts.loading && (visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount) {
                posts.loading = true;
                posts.loadMore(adapter, "", "url:" + url, false);
            }
        }
    });
    final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.activity_main_swipe_refresh_layout);
    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors("", this));
    // If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    // So, we estimate the height of the header in dp.
    mSwipeRefreshLayout.setProgressViewOffset(false, Constants.SINGLE_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP, Constants.SINGLE_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);
    mSwipeRefreshLayout.post(new Runnable() {

        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });
    posts = new SubredditSearchPosts("", "url:" + url, this);
    adapter = new ContributionAdapter(this, posts, rv);
    rv.setAdapter(adapter);
    posts.bindAdapter(adapter, mSwipeRefreshLayout);
    // TODO catch errors
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            posts.loadMore(adapter, "", "url:" + url, true);
        // TODO catch errors
        }
    });
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) ColorPreferences(me.ccrama.redditslide.ColorPreferences) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) SubredditSearchPosts(me.ccrama.redditslide.Adapters.SubredditSearchPosts) PreCachingLayoutManager(me.ccrama.redditslide.Views.PreCachingLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) ContributionAdapter(me.ccrama.redditslide.Adapters.ContributionAdapter) RecyclerView(android.support.v7.widget.RecyclerView) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler)

Example 14 with ColorPreferences

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

the class SubredditView method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    overrideSwipeFromAnywhere();
    if (SettingValues.commentPager && SettingValues.single) {
        disableSwipeBackLayout();
    }
    getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    getWindow().getDecorView().setBackgroundDrawable(null);
    super.onCreate(savedInstanceState);
    if (!restarting) {
        overridePendingTransition(R.anim.slideright, 0);
    } else {
        restarting = false;
    }
    subreddit = getIntent().getExtras().getString(EXTRA_SUBREDDIT, "");
    applyColorTheme(subreddit);
    setContentView(R.layout.activity_singlesubreddit);
    setupSubredditAppBar(R.id.toolbar, subreddit, true, subreddit);
    header = findViewById(R.id.header);
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    setResult(3);
    mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
    pager = (ToggleSwipeViewPager) findViewById(R.id.content_view);
    singleMode = SettingValues.single;
    commentPager = false;
    if (singleMode)
        commentPager = SettingValues.commentPager;
    if (commentPager) {
        adapter = new OverviewPagerAdapterComment(getSupportFragmentManager());
        pager.setSwipeLeftOnly(false);
        pager.setSwipingEnabled(true);
    } else {
        adapter = new OverviewPagerAdapter(getSupportFragmentManager());
    }
    pager.setAdapter(adapter);
    pager.setCurrentItem(1);
    mToolbar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            int[] firstVisibleItems;
            int pastVisiblesItems = 0;
            firstVisibleItems = ((CatchStaggeredGridLayoutManager) ((SubmissionsView) (adapter.getCurrentFragment())).rv.getLayoutManager()).findFirstVisibleItemPositions(null);
            if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                for (int firstVisibleItem : firstVisibleItems) {
                    pastVisiblesItems = firstVisibleItem;
                }
            }
            if (pastVisiblesItems > 8) {
                ((SubmissionsView) (adapter.getCurrentFragment())).rv.scrollToPosition(0);
                header.animate().translationY(header.getHeight()).setInterpolator(new LinearInterpolator()).setDuration(180);
            } else {
                ((SubmissionsView) (adapter.getCurrentFragment())).rv.smoothScrollToPosition(0);
            }
            ((SubmissionsView) (adapter.getCurrentFragment())).resetScroll();
        }
    });
    if (!subreddit.equals("random") && !subreddit.equals("all") && !subreddit.equals("frontpage") && !subreddit.equals("friends") && !subreddit.equals("mod") && !subreddit.equals("myrandom") && !subreddit.equals("randnsfw") && !subreddit.equals("popular") && !subreddit.contains("+")) {
        executeAsyncSubreddit(subreddit);
    } else {
        drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, GravityCompat.END);
    }
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) ColorDrawable(android.graphics.drawable.ColorDrawable) ColorPreferences(me.ccrama.redditslide.ColorPreferences) LinearInterpolator(android.view.animation.LinearInterpolator) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) ImageView(android.widget.ImageView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) View(android.view.View) TextView(android.widget.TextView)

Example 15 with ColorPreferences

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

the class Website method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    overrideSwipeFromAnywhere();
    super.onCreate(savedInstanceState);
    applyColorTheme("");
    setContentView(R.layout.activity_web);
    url = getIntent().getExtras().getString(EXTRA_URL, "");
    subredditColor = getIntent().getExtras().getInt(EXTRA_COLOR, Palette.getDefaultColor());
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    setupAppBar(R.id.toolbar, "", true, subredditColor, R.id.appbar);
    mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
    p = (ProgressBar) findViewById(R.id.progress);
    v = (WebView) findViewById(R.id.web);
    client = new MyWebViewClient();
    webClient = new AdBlockWebViewClient();
    if (!SettingValues.cookies) {
        CookieSyncManager.createInstance(this);
        CookieManager cookieManager = CookieManager.getInstance();
        try {
            cookieManager.removeAllCookies(null);
            CookieManager.getInstance().flush();
            cookieManager.setAcceptCookie(false);
        } catch (NoSuchMethodError e) {
        // Although these were added in api 12, some devices don't have this method
        }
        WebSettings ws = v.getSettings();
        ws.setSaveFormData(false);
        ws.setSavePassword(false);
    }
    /* todo in the future, drag left and right to go back and forward in history

        IOverScrollDecor decor = new HorizontalOverScrollBounceEffectDecorator(new WebViewOverScrollDecoratorAdapter(v));

        decor.setOverScrollStateListener(new IOverScrollStateListener() {
                                             @Override
                                             public void onOverScrollStateChange(IOverScrollDecor decor, int oldState, int newState) {
                                                 switch (newState) {
                                                     case IOverScrollState.STATE_IDLE:
                                                         // No over-scroll is in effect.
                                                         break;
                                                     case IOverScrollState.STATE_DRAG_START_SIDE:
                                                         break;
                                                     case IOverScrollState.STATE_DRAG_END_SIDE:
                                                         break;
                                                     case IOverScrollState.STATE_BOUNCE_BACK:
                                                         if (oldState == IOverScrollState.STATE_DRAG_START_SIDE) {
                                                             if(v.canGoBack())
                                                                 v.goBack();
                                                         } else { // i.e. (oldState == STATE_DRAG_END_SIDE)
                                                             if(v.canGoForward())
                                                                 v.goForward();
                                                         }
                                                         break;
                                                 }
                                             }
                                         });
                                         */
    v.setWebChromeClient(client);
    v.setWebViewClient(webClient);
    v.getSettings().setBuiltInZoomControls(true);
    v.getSettings().setDisplayZoomControls(false);
    v.getSettings().setJavaScriptEnabled(true);
    v.getSettings().setLoadWithOverviewMode(true);
    v.getSettings().setUseWideViewPort(true);
    v.setDownloadListener(new DownloadListener() {

        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
            // Downloads using download manager on default browser
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);
        }
    });
    v.loadUrl(url);
}
Also used : ColorPreferences(me.ccrama.redditslide.ColorPreferences) DownloadListener(android.webkit.DownloadListener) WebSettings(android.webkit.WebSettings) Intent(android.content.Intent) CookieManager(android.webkit.CookieManager)

Aggregations

ColorPreferences (me.ccrama.redditslide.ColorPreferences)50 View (android.view.View)23 TextView (android.widget.TextView)22 Intent (android.content.Intent)16 DialogInterface (android.content.DialogInterface)14 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)14 ArrayList (java.util.ArrayList)14 SpoilerRobotoTextView (me.ccrama.redditslide.SpoilerRobotoTextView)13 LayoutInflater (android.view.LayoutInflater)12 RecyclerView (android.support.v7.widget.RecyclerView)10 ImageView (android.widget.ImageView)10 SubmissionsView (me.ccrama.redditslide.Fragments.SubmissionsView)10 Context (android.content.Context)9 ContextThemeWrapper (android.support.v7.view.ContextThemeWrapper)9 HorizontalScrollView (android.widget.HorizontalScrollView)9 Snackbar (android.support.design.widget.Snackbar)8 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)8 CaseInsensitiveArrayList (me.ccrama.redditslide.CaseInsensitiveArrayList)8 LinearInterpolator (android.view.animation.LinearInterpolator)7 Dialog (android.app.Dialog)6