Search in sources :

Example 1 with Replyable

use of com.winsonchiu.reader.data.reddit.Replyable in project Reader by TheKeeperOfPie.

the class ControllerSearch method setReplyTextLinksSubreddit.

public boolean setReplyTextLinksSubreddit(String name, String text, boolean collapsed) {
    for (int index = 0; index < linksSubreddit.getChildren().size(); index++) {
        Thing thing = linksSubreddit.getChildren().get(index);
        if (thing.getName().equals(name)) {
            ((Replyable) thing).setReplyText(text);
            ((Replyable) thing).setReplyExpanded(!collapsed);
            eventHolder.callLinksSubreddit(new RxAdapterEvent<>(getLinksSubredditModel(), RxAdapterEvent.Type.CHANGE, index + 1));
            return true;
        }
    }
    return false;
}
Also used : Replyable(com.winsonchiu.reader.data.reddit.Replyable) Thing(com.winsonchiu.reader.data.reddit.Thing)

Example 2 with Replyable

use of com.winsonchiu.reader.data.reddit.Replyable in project Reader by TheKeeperOfPie.

the class ControllerProfile method setReplyText.

@Override
public boolean setReplyText(String name, String text, boolean collapsed) {
    if (topLink != null && name.equals(topLink.getName())) {
        topLink.setReplyText(text);
        topLink.setReplyExpanded(!collapsed);
        for (Listener listener : listeners) {
            listener.getAdapter().notifyItemChanged(2);
        }
        return true;
    }
    if (topComment != null && name.equals(topComment.getName())) {
        topComment.setReplyText(text);
        topComment.setReplyExpanded(!collapsed);
        for (Listener listener : listeners) {
            listener.getAdapter().notifyItemChanged(4);
        }
        return true;
    }
    for (int index = 0; index < data.getChildren().size(); index++) {
        Thing thing = data.getChildren().get(index);
        if (thing.getName().equals(name)) {
            ((Replyable) thing).setReplyText(text);
            ((Replyable) thing).setReplyExpanded(!collapsed);
            for (Listener listener : listeners) {
                listener.getAdapter().notifyItemChanged(index + 6);
            }
            return true;
        }
    }
    return false;
}
Also used : ControllerListener(com.winsonchiu.reader.utils.ControllerListener) Replyable(com.winsonchiu.reader.data.reddit.Replyable) Thing(com.winsonchiu.reader.data.reddit.Thing)

Example 3 with Replyable

use of com.winsonchiu.reader.data.reddit.Replyable in project Reader by TheKeeperOfPie.

the class ControllerHistory method setReplyText.

@Override
public boolean setReplyText(String name, String text, boolean collapsed) {
    for (int index = 0; index < history.getChildren().size(); index++) {
        Thing thing = history.getChildren().get(index);
        if (thing.getName().equals(name)) {
            ((Replyable) thing).setReplyText(text);
            ((Replyable) thing).setReplyExpanded(!collapsed);
            eventHolder.call(new RxAdapterEvent<>(getData(), RxAdapterEvent.Type.CHANGE, index + 1));
            return true;
        }
    }
    return false;
}
Also used : Replyable(com.winsonchiu.reader.data.reddit.Replyable) Thing(com.winsonchiu.reader.data.reddit.Thing)

Example 4 with Replyable

use of com.winsonchiu.reader.data.reddit.Replyable in project Reader by TheKeeperOfPie.

the class ActivityMain method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    componentActivity = (ComponentActivity) getLastCustomNonConfigurationInstance();
    if (componentActivity == null) {
        componentActivity = CustomApplication.getComponentMain().componentActivity();
    }
    componentActivity.inject(this);
    themer = new Themer(this);
    int colorResourcePrimary = UtilsColor.showOnWhite(themer.getColorPrimary()) ? R.color.darkThemeIconFilter : R.color.lightThemeIconFilter;
    int resourceIcon = UtilsColor.showOnWhite(themer.getColorPrimary()) ? R.mipmap.app_icon_white_outline : R.mipmap.app_icon_dark_outline;
    colorFilterPrimary = new CustomColorFilter(ContextCompat.getColor(this, colorResourcePrimary), PorterDuff.Mode.MULTIPLY);
    /**
         * Required for {@link YouTubePlayerSupportFragment} to inflate proper UI
         */
    getLayoutInflater().setFactory(this);
    super.onCreate(savedInstanceState);
    handler = new Handler();
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    inflateNavigationDrawer();
    Receiver.setAlarm(this);
    layoutDrawer.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {

        @Override
        public void onDrawerClosed(View drawerView) {
            if (loadId != 0) {
                selectNavigationItem(loadId, null, true);
            }
            setAccountsVisible(false);
        }
    });
    eventListenerBase = new EventListenerBase(componentActivity) {

        @Override
        public void onClickComments(Link link, AdapterLink.ViewHolderLink viewHolderLink, Source source) {
            int color = viewHolderLink.getBackgroundColor();
            FragmentBase fragment = (FragmentBase) getSupportFragmentManager().findFragmentById(R.id.frame_fragment);
            fragment.onWindowTransitionStart();
            FragmentComments fragmentComments = FragmentComments.newInstance(viewHolderLink, color);
            fragmentComments.setFragmentToHide(fragment, viewHolderLink.itemView);
            getSupportFragmentManager().beginTransaction().add(R.id.frame_fragment, fragmentComments, FragmentComments.TAG).addToBackStack(null).commit();
            controllerCommentsTop.setLink(link, source);
        }

        @Override
        public void loadUrl(String urlString) {
            if (sharedPreferences.getBoolean(AppSettings.PREF_EXTERNAL_BROWSER, false)) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(urlString));
                startActivity(intent);
                return;
            }
            Log.d(TAG, "loadUrl: " + loadId);
            URL url = null;
            try {
                url = new URL(urlString);
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            if (url != null && url.getHost().contains("reddit.com")) {
                Intent intent = new Intent(ActivityMain.this, ActivityMain.class);
                intent.setAction(Intent.ACTION_VIEW);
                intent.putExtra(REDDIT_PAGE, urlString);
                startActivity(intent);
                return;
            }
            launchUrl(urlString, false);
        }

        @Override
        public void downloadImage(String title, String fileName, String url) {
            imageDownload = new ImageDownload(title, fileName, url);
            ActivityCompat.requestPermissions(ActivityMain.this, new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_PERMISSION_WRITE_EXTERNAL_STORAGE);
        }

        @Override
        public void editLink(Link link) {
            FragmentNewPost fragmentNewPost = FragmentNewPost.newInstanceEdit(controllerUser.getUser().getName(), link);
            getSupportFragmentManager().beginTransaction().hide(getSupportFragmentManager().findFragmentById(R.id.frame_fragment)).add(R.id.frame_fragment, fragmentNewPost, FragmentNewPost.TAG).addToBackStack(null).commit();
        }

        @Override
        public void showReplyEditor(Replyable replyable) {
            FragmentReply fragmentReply = FragmentReply.newInstance(replyable);
            fragmentReply.setFragmentToHide(getSupportFragmentManager().findFragmentById(R.id.frame_fragment));
            getSupportFragmentManager().beginTransaction().add(R.id.frame_fragment, fragmentReply, FragmentReply.TAG).addToBackStack(null).commit();
        }

        @Override
        public void loadWebFragment(String url) {
            launchUrl(url, false);
        }

        @Override
        public void launchScreen(Intent intent) {
            startActivity(intent);
        }
    };
    eventListenerComment = (comment, subreddit, linkId) -> {
        if (comment.getCount() == 0) {
            Intent intentCommentThread = new Intent(ActivityMain.this, ActivityMain.class);
            intentCommentThread.setAction(Intent.ACTION_VIEW);
            // Double slashes used to trigger parseUrl correctly
            intentCommentThread.putExtra(REDDIT_PAGE, Reddit.BASE_URL + "/r/" + subreddit + "/comments/" + linkId + "/title/" + comment.getParentId() + "/");
            startActivity(intentCommentThread);
            return true;
        }
        return false;
    };
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("Reader", BitmapFactory.decodeResource(getResources(), resourceIcon), themer.getColorPrimary());
        setTaskDescription(taskDescription);
    }
    customTabsServiceConnection = new CustomTabsServiceConnection() {

        @Override
        public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient customTabsClient) {
            customTabsClient.warmup(0);
            customTabsSession = customTabsClient.newSession(new CustomTabsCallback() {

                @Override
                public void onNavigationEvent(int navigationEvent, Bundle extras) {
                    super.onNavigationEvent(navigationEvent, extras);
                    Log.d(TAG, "onNavigationEvent() called with: " + "navigationEvent = [" + navigationEvent + "], extras = [" + extras + "]");
                }

                @Override
                public void extraCallback(String callbackName, Bundle args) {
                    super.extraCallback(callbackName, args);
                    Log.d(TAG, "extraCallback() called with: " + "callbackName = [" + callbackName + "], args = [" + args + "]");
                }
            });
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
        }
    };
    CustomTabsClient.bindCustomTabsService(this, getPackageName(), customTabsServiceConnection);
    handleFirstLaunch(savedInstanceState);
    showBetaNotice();
    loadAccount();
    UtilsImage.checkMaxTextureSize(handler, () -> {
    });
}
Also used : MalformedURLException(java.net.MalformedURLException) AdapterLink(com.winsonchiu.reader.links.AdapterLink) ImageDownload(com.winsonchiu.reader.utils.ImageDownload) ActivityManager(android.app.ActivityManager) Source(com.winsonchiu.reader.comments.Source) URL(java.net.URL) CustomTabsCallback(android.support.customtabs.CustomTabsCallback) ComponentName(android.content.ComponentName) DrawerLayout(android.support.v4.widget.DrawerLayout) CustomTabsClient(android.support.customtabs.CustomTabsClient) CustomColorFilter(com.winsonchiu.reader.utils.CustomColorFilter) Bundle(android.os.Bundle) Themer(com.winsonchiu.reader.theme.Themer) Handler(android.os.Handler) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) FragmentReply(com.winsonchiu.reader.comments.FragmentReply) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) RecyclerView(android.support.v7.widget.RecyclerView) NavigationView(android.support.design.widget.NavigationView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) EventListenerBase(com.winsonchiu.reader.utils.EventListenerBase) Replyable(com.winsonchiu.reader.data.reddit.Replyable) CustomTabsServiceConnection(android.support.customtabs.CustomTabsServiceConnection) Link(com.winsonchiu.reader.data.reddit.Link) AdapterLink(com.winsonchiu.reader.links.AdapterLink) FragmentComments(com.winsonchiu.reader.comments.FragmentComments)

Example 5 with Replyable

use of com.winsonchiu.reader.data.reddit.Replyable in project Reader by TheKeeperOfPie.

the class ControllerComments method setReplyText.

public boolean setReplyText(ReplyModel replyModel) {
    String name = replyModel.getNameParent();
    String text = replyModel.getText();
    boolean collapsed = replyModel.isCollapsed();
    if (name.equals(link.getName())) {
        link.setReplyText(text);
        link.setReplyExpanded(!collapsed);
        eventHolder.call(new RxAdapterEvent<>(getData(), RxAdapterEvent.Type.CHANGE, 0));
        return true;
    }
    for (int index = 0; index < listingComments.getChildren().size(); index++) {
        Thing thing = listingComments.getChildren().get(index);
        if (thing.getName().equals(name)) {
            ((Replyable) thing).setReplyText(text);
            ((Replyable) thing).setReplyExpanded(!collapsed);
            eventHolder.call(new RxAdapterEvent<>(getData(), RxAdapterEvent.Type.CHANGE, index + 1));
            return true;
        }
    }
    return false;
}
Also used : Replyable(com.winsonchiu.reader.data.reddit.Replyable) Thing(com.winsonchiu.reader.data.reddit.Thing)

Aggregations

Replyable (com.winsonchiu.reader.data.reddit.Replyable)7 Thing (com.winsonchiu.reader.data.reddit.Thing)6 ControllerListener (com.winsonchiu.reader.utils.ControllerListener)2 ActivityManager (android.app.ActivityManager)1 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 CustomTabsCallback (android.support.customtabs.CustomTabsCallback)1 CustomTabsClient (android.support.customtabs.CustomTabsClient)1 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)1 CustomTabsServiceConnection (android.support.customtabs.CustomTabsServiceConnection)1 NavigationView (android.support.design.widget.NavigationView)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 HorizontalScrollView (android.widget.HorizontalScrollView)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1