Search in sources :

Example 56 with START

use of android.support.v7.widget.helper.ItemTouchHelper.START in project instructure-android by instructure.

the class ExpandCollapseItemAnimator method animateChangeImpl.

private void animateChangeImpl(final ChangeInfo changeInfo) {
    final ViewHolder holder = changeInfo.oldHolder;
    final View view = holder == null ? null : holder.itemView;
    final ViewHolder newHolder = changeInfo.newHolder;
    final View newView = newHolder != null ? newHolder.itemView : null;
    if (view != null) {
        final ViewPropertyAnimatorCompat oldViewAnim = ViewCompat.animate(view).setDuration(getChangeDuration());
        mChangeAnimations.add(changeInfo.oldHolder);
        oldViewAnim.translationX(changeInfo.toX - changeInfo.fromX);
        oldViewAnim.translationY(changeInfo.toY - changeInfo.fromY);
        oldViewAnim.alpha(0).setListener(new VpaListenerAdapter() {

            @Override
            public void onAnimationStart(View view) {
                dispatchChangeStarting(changeInfo.oldHolder, true);
            }

            @Override
            public void onAnimationEnd(View view) {
                oldViewAnim.setListener(null);
                ViewCompat.setAlpha(view, 1);
                ViewCompat.setTranslationX(view, 0);
                ViewCompat.setTranslationY(view, 0);
                dispatchChangeFinished(changeInfo.oldHolder, true);
                mChangeAnimations.remove(changeInfo.oldHolder);
                dispatchFinishedWhenDone();
            }
        }).start();
    }
    if (newView != null) {
        final ViewPropertyAnimatorCompat newViewAnimation = ViewCompat.animate(newView);
        mChangeAnimations.add(changeInfo.newHolder);
        newViewAnimation.translationX(0).translationY(0).setDuration(getChangeDuration()).alpha(1).setListener(new VpaListenerAdapter() {

            @Override
            public void onAnimationStart(View view) {
                dispatchChangeStarting(changeInfo.newHolder, false);
            }

            @Override
            public void onAnimationEnd(View view) {
                newViewAnimation.setListener(null);
                ViewCompat.setAlpha(newView, 1);
                ViewCompat.setTranslationX(newView, 0);
                ViewCompat.setTranslationY(newView, 0);
                dispatchChangeFinished(changeInfo.newHolder, false);
                mChangeAnimations.remove(changeInfo.newHolder);
                dispatchFinishedWhenDone();
            }
        }).start();
    }
}
Also used : ViewHolder(android.support.v7.widget.RecyclerView.ViewHolder) ViewPropertyAnimatorCompat(android.support.v4.view.ViewPropertyAnimatorCompat) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 57 with START

use of android.support.v7.widget.helper.ItemTouchHelper.START in project android_packages_apps_Settings by LineageOS.

the class AccountTypePreferenceLoader method updatePreferenceIntents.

/**
 * Recursively filters through the preference list provided by GoogleLoginService.
 *
 * This method removes all the invalid intent from the list, adds account name as extra into the
 * intent, and hack the location settings to start it as a fragment.
 */
public void updatePreferenceIntents(PreferenceGroup prefs, final String acccountType, Account account) {
    final PackageManager pm = mFragment.getActivity().getPackageManager();
    for (int i = 0; i < prefs.getPreferenceCount(); ) {
        Preference pref = prefs.getPreference(i);
        if (pref instanceof PreferenceGroup) {
            updatePreferenceIntents((PreferenceGroup) pref, acccountType, account);
        }
        Intent intent = pref.getIntent();
        if (intent != null) {
            // preference click event here directly.
            if (intent.getAction().equals(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)) {
                // The OnPreferenceClickListener overrides the click event completely. No intent
                // will get fired.
                pref.setOnPreferenceClickListener(new FragmentStarter(LocationSettings.class.getName(), R.string.location_settings_title));
            } else {
                ResolveInfo ri = pm.resolveActivityAsUser(intent, PackageManager.MATCH_DEFAULT_ONLY, mUserHandle.getIdentifier());
                if (ri == null) {
                    prefs.removePreference(pref);
                    continue;
                }
                intent.putExtra(ACCOUNT_KEY, account);
                intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
                pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        Intent prefIntent = preference.getIntent();
                        /*
                                 * Check the intent to see if it resolves to a exported=false
                                 * activity that doesn't share a uid with the authenticator.
                                 *
                                 * Otherwise the intent is considered unsafe in that it will be
                                 * exploiting the fact that settings has system privileges.
                                 */
                        if (isSafeIntent(pm, prefIntent, acccountType)) {
                            mFragment.getActivity().startActivityAsUser(prefIntent, mUserHandle);
                        } else {
                            Log.e(TAG, "Refusing to launch authenticator intent because" + "it exploits Settings permissions: " + prefIntent);
                        }
                        return true;
                    }
                });
            }
        }
        i++;
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) OnPreferenceClickListener(android.support.v7.preference.Preference.OnPreferenceClickListener) PackageManager(android.content.pm.PackageManager) Preference(android.support.v7.preference.Preference) PreferenceGroup(android.support.v7.preference.PreferenceGroup) Intent(android.content.Intent)

Example 58 with START

use of android.support.v7.widget.helper.ItemTouchHelper.START in project RxTools by vondear.

the class ActivityContact method initView.

private void initView() {
    mRxTitle.setLeftFinish(mContext);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    final PinnedHeaderDecoration decoration = new PinnedHeaderDecoration();
    decoration.registerTypePinnedHeader(1, new PinnedHeaderDecoration.PinnedHeaderCreator() {

        @Override
        public boolean create(RecyclerView parent, int adapterPosition) {
            return true;
        }
    });
    mRecyclerView.addItemDecoration(decoration);
    new Thread(new Runnable() {

        @Override
        public void run() {
            Type listType = new TypeToken<ArrayList<ModelContactCity>>() {
            }.getType();
            Gson gson = new Gson();
            final List<ModelContactCity> list = gson.fromJson(ModelContactCity.DATA, listType);
            Collections.sort(list, new ComparatorLetter());
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    mAdapterContactCity = new AdapterContactCity(mContext, list);
                    mRecyclerView.setAdapter(mAdapterContactCity);
                }
            });
        }
    }).start();
    mSideBarView.setOnTouchLetterChangeListener(new WaveSideBarView.OnTouchLetterChangeListener() {

        @Override
        public void onLetterChange(String letter) {
            int pos = mAdapterContactCity.getLetterPosition(letter);
            if (pos != -1) {
                mRecyclerView.scrollToPosition(pos);
                LinearLayoutManager mLayoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
                mLayoutManager.scrollToPositionWithOffset(pos, 0);
            }
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Type(java.lang.reflect.Type) ComparatorLetter(com.vondear.tools.tools.ComparatorLetter) WaveSideBarView(com.vondear.rxtools.view.sidebar.WaveSideBarView) ModelContactCity(com.vondear.tools.model.ModelContactCity) PinnedHeaderDecoration(com.vondear.rxtools.view.sidebar.PinnedHeaderDecoration) RecyclerView(android.support.v7.widget.RecyclerView) AdapterContactCity(com.vondear.tools.adapter.AdapterContactCity)

Example 59 with START

use of android.support.v7.widget.helper.ItemTouchHelper.START in project instructure-android by instructure.

the class SubmissionDetailsFragment method setupListeners.

private void setupListeners() {
    if (addSubmission != null) {
        addSubmission.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO  Open Submission view, "Go To Discussion" or "Go To Quiz"
                if (// Allow the user to go to the discussion.
                assignment.getDiscussionTopicHeader() != null && assignment.getDiscussionTopicHeader().getId() > 0 && assignment.getCourseId() > 0) {
                    String url = DiscussionTopic.getDiscussionURL(ApiPrefs.getProtocol(), ApiPrefs.getDomain(), assignment.getCourseId(), assignment.getDiscussionTopicHeader().getId());
                    if (!RouterUtils.canRouteInternally(getActivity(), url, ApiPrefs.getDomain(), true)) {
                        Intent intent = new Intent(getActivity(), InternalWebViewActivity.class);
                        getActivity().startActivity(intent);
                    }
                } else if (assignment.getQuizId() > 0) {
                    String url = getQuizURL(getActivity(), assignment.getCourseId(), assignment.getQuizId());
                    if (!RouterUtils.canRouteInternally(getActivity(), url, ApiPrefs.getDomain(), true)) {
                        Intent intent = new Intent(getActivity(), InternalWebViewActivity.class);
                        getActivity().startActivity(intent);
                    }
                } else if (assignment.getTurnInType() == Assignment.TURN_IN_TYPE.EXTERNAL_TOOL) {
                    // TODO stream doesn't pass the LTI url. Grab it now if we need it
                    String authenticationURL = assignment.getUrl();
                    if (authenticationURL == null || authenticationURL.equalsIgnoreCase("null")) {
                        // get the assignment
                        AssignmentManager.getAssignment(assignment.getId(), course.getId(), true, canvasCallbackAssignment);
                        return;
                    } else {
                        SubmissionManager.getLtiFromAuthenticationUrl(assignment.getUrl(), canvasCallbackLTITool, true);
                    }
                } else {
                    if (!APIHelper.hasNetworkConnection()) {
                        Toast.makeText(getContext(), getContext().getString(R.string.notAvailableOffline), Toast.LENGTH_SHORT).show();
                        return;
                    }
                    // open add submission view
                    // start it for xml so we can update the results if we need to. Need to call it on the parent fragment
                    // and it will call onActivityResult in the current child fragment.
                    Navigation navigation = getNavigation();
                    if (navigation != null) {
                        Bundle bundle = AddSubmissionFragment.createBundle((Course) getCanvasContext(), assignment, isOnlineTextAllowed, isUrlEntryAllowed, isFileEntryAllowed, isMediaRecording);
                        navigation.addFragment(FragUtils.getFrag(AddSubmissionFragment.class, bundle));
                    }
                }
            }
        });
    }
    // Handle pressing of the send button.
    if (submitComment != null) {
        submitComment.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // try to submit the comment
                if (!APIHelper.hasNetworkConnection()) {
                    Toast.makeText(getContext(), getContext().getString(R.string.notAvailableOffline), Toast.LENGTH_SHORT).show();
                    return;
                }
                sendMessage(assignment.getId());
            }
        });
        mediaComment.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                ListView listView = new ListView(getActivity());
                AttachmentAdapter adapter = new AttachmentAdapter(getActivity(), android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.discussion_attachments));
                listView.setAdapter(adapter);
                listView.setDivider(null);
                listView.setPadding((int) Utils.dpToPx(getActivity(), 10), (int) Utils.dpToPx(getActivity(), 10), (int) Utils.dpToPx(getActivity(), 10), (int) Utils.dpToPx(getActivity(), 16));
                final AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.commentUpload).setView(listView).create();
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        switch(position) {
                            case 0:
                                // Use File Upload Dialog
                                showUploadFileDialog();
                                dialog.dismiss();
                                break;
                            case 1:
                                if (message.getText().toString().trim().length() != 0 || attachmentIds.size() > 0) {
                                    Toast.makeText(getContext(), R.string.unableToUploadMediaComment, Toast.LENGTH_SHORT).show();
                                } else {
                                    // Use Notorious
                                    Intent intent = NotoriousMediaUploadPicker.createIntentForSubmissionComment(getContext(), assignment);
                                    assignmentFragment.get().startActivityForResult(intent, RequestCodes.NOTORIOUS_REQUEST);
                                    dialog.dismiss();
                                }
                                break;
                            default:
                                break;
                        }
                    }
                });
                dialog.show();
            }
        });
    }
    // Handle if they hit the send button in landscape mode.
    message.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
            // Try to send the message.
            if (actionId == EditorInfo.IME_ACTION_SEND) {
                sendMessage(assignment.getId());
                // Hide keyboard
                InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(message.getWindowToken(), 0);
                return true;
            }
            return false;
        }
    });
    if (listView != null) {
        listView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
                Submission submission = (Submission) adapter.getAdapter().getItem(position);
                // it has the details that we need
                if (submission.getSubmissionComments().size() == 0) {
                    if (submission.getSubmissionType().equals("online_upload") || submission.getSubmissionType().equals("media_recording")) {
                        if (submission.getAttachments().size() == 1) {
                            // makes more sense to open the file since they should already have it on their device
                            if (submission.getAttachments().get(0).getContentType().contains("pdf")) {
                                startActivity(StudentSubmissionActivity.createIntent(getActivity(), course, assignment, new GradeableStudentSubmission(new StudentAssignee(ApiPrefs.getUser(), ApiPrefs.getUser().getId(), ApiPrefs.getUser().getName()), null, false)));
                            } else {
                                openMedia(submission.getAttachments().get(0).getContentType(), submission.getAttachments().get(0).getUrl(), submission.getAttachments().get(0).getFilename());
                            }
                        } else if (submission.getMediaComment() != null) {
                            MediaComment mediaComment = submission.getMediaComment();
                            openMedia(mediaComment.getContentType(), mediaComment.getUrl(), mediaComment.get_fileName());
                        } else {
                            // show a list dialog of the files to download.
                            showFileList(submission.getAttachments());
                        }
                    } else if (submission.getSubmissionType().equals("online_text_entry")) {
                        Navigation navigation = getNavigation();
                        if (navigation != null) {
                            Bundle bundle = InternalWebviewFragment.Companion.createBundleHTML(getCanvasContext(), submission.getBody());
                            navigation.addFragment(FragUtils.getFrag(InternalWebviewFragment.class, bundle));
                        }
                    } else if (submission.getSubmissionType().equals("online_url")) {
                        // Take the user to viewing the online url submission. If the image hasn't processed yet they'll see a toast and it
                        // will match what the web does - show the url and say it might be different from when they submitted.
                        Navigation navigation = getNavigation();
                        if (navigation != null) {
                            Bundle bundle = SubmissionViewOnlineURLFragment.createBundle(getCanvasContext(), submission);
                            navigation.addFragment(FragUtils.getFrag(SubmissionViewOnlineURLFragment.class, bundle));
                        }
                        if (submission.getAttachments().size() == 0) {
                            // the server hasn't processed the image for the submitted url yet, show a crouton and reload
                            showToast(R.string.itemStillProcessing);
                            loadData(assignment.getId(), false, false);
                        }
                    }
                }
            }
        });
    }
    addComment.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!APIHelper.hasNetworkConnection()) {
                Toast.makeText(getContext(), getContext().getString(R.string.notAvailableOffline), Toast.LENGTH_SHORT).show();
                return;
            }
            // Only show the header if it hasn't been added prior.
            if (listView.getHeaderViewsCount() == 1) {
                listView.addHeaderView(composeHeaderView, null, false);
            }
            // add the compose header (the comment box)
            composeHeaderView.setVisibility(View.VISIBLE);
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) StudentAssignee(com.instructure.canvasapi2.models.StudentAssignee) InputMethodManager(android.view.inputmethod.InputMethodManager) KeyEvent(android.view.KeyEvent) ListView(android.widget.ListView) TextView(android.widget.TextView) Course(com.instructure.canvasapi2.models.Course) MediaComment(com.instructure.canvasapi2.models.MediaComment) Navigation(com.instructure.interactions.Navigation) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) Submission(com.instructure.canvasapi2.models.Submission) GradeableStudentSubmission(com.instructure.canvasapi2.models.GradeableStudentSubmission) Bundle(android.os.Bundle) Intent(android.content.Intent) ImageView(android.widget.ImageView) AttachmentView(com.instructure.candroid.view.AttachmentView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) View(android.view.View) AdapterView(android.widget.AdapterView) BeforePageView(com.instructure.canvasapi2.utils.pageview.BeforePageView) PageView(com.instructure.canvasapi2.utils.pageview.PageView) TextView(android.widget.TextView) ListView(android.widget.ListView) Paint(android.graphics.Paint) InternalWebViewActivity(com.instructure.candroid.activity.InternalWebViewActivity) GradeableStudentSubmission(com.instructure.canvasapi2.models.GradeableStudentSubmission) OnClickListener(android.view.View.OnClickListener) AdapterView(android.widget.AdapterView)

Example 60 with START

use of android.support.v7.widget.helper.ItemTouchHelper.START in project Slide by ccrama.

the class MainActivity method doDrawer.

public void doDrawer() {
    drawerSubList = (ListView) findViewById(R.id.drawerlistview);
    drawerSubList.setDividerHeight(0);
    drawerSubList.setDescendantFocusability(ListView.FOCUS_BEFORE_DESCENDANTS);
    final LayoutInflater inflater = getLayoutInflater();
    final View header;
    if (Authentication.isLoggedIn && Authentication.didOnline) {
        header = inflater.inflate(R.layout.drawer_loggedin, drawerSubList, false);
        headerMain = header;
        hea = header.findViewById(R.id.back);
        drawerSubList.addHeaderView(header, null, false);
        ((TextView) header.findViewById(R.id.name)).setText(Authentication.name);
        header.findViewById(R.id.multi).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                if (runAfterLoad == null) {
                    Intent inte = new Intent(MainActivity.this, MultiredditOverview.class);
                    MainActivity.this.startActivity(inte);
                }
            }
        });
        header.findViewById(R.id.multi).setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                new MaterialDialog.Builder(MainActivity.this).inputRange(3, 20).alwaysCallInputCallback().input(getString(R.string.user_enter), null, new MaterialDialog.InputCallback() {

                    @Override
                    public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
                        final EditText editText = dialog.getInputEditText();
                        EditTextValidator.validateUsername(editText);
                        if (input.length() >= 3 && input.length() <= 20) {
                            dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
                        }
                    }
                }).positiveText(R.string.user_btn_gotomultis).onPositive(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        if (runAfterLoad == null) {
                            Intent inte = new Intent(MainActivity.this, MultiredditOverview.class);
                            inte.putExtra(Profile.EXTRA_PROFILE, dialog.getInputEditText().getText().toString());
                            MainActivity.this.startActivity(inte);
                        }
                    }
                }).negativeText(R.string.btn_cancel).show();
                return true;
            }
        });
        header.findViewById(R.id.discover).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Discover.class);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.prof_click).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Profile.class);
                inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.saved).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Profile.class);
                inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
                inte.putExtra(Profile.EXTRA_SAVED, true);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.later).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, PostReadLater.class);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.history).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Profile.class);
                inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
                inte.putExtra(Profile.EXTRA_HISTORY, true);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.commented).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Profile.class);
                inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
                inte.putExtra(Profile.EXTRA_COMMENT, true);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.submitted).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Profile.class);
                inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
                inte.putExtra(Profile.EXTRA_SUBMIT, true);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.upvoted).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Profile.class);
                inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
                inte.putExtra(Profile.EXTRA_UPVOTE, true);
                MainActivity.this.startActivity(inte);
            }
        });
        /**
         * If the user is a known mod, show the "Moderation" drawer item quickly to
         * stop the UI from jumping
         */
        if (modOf != null && !modOf.isEmpty() && Authentication.mod) {
            header.findViewById(R.id.mod).setVisibility(View.VISIBLE);
        }
        // update notification badge
        final LinearLayout profStuff = header.findViewById(R.id.accountsarea);
        profStuff.setVisibility(View.GONE);
        findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (profStuff.getVisibility() == View.GONE) {
                    expand(profStuff);
                    flipAnimator(false, header.findViewById(R.id.headerflip)).start();
                } else {
                    collapse(profStuff);
                    flipAnimator(true, header.findViewById(R.id.headerflip)).start();
                }
            }
        });
        for (String s : Authentication.authentication.getStringSet("accounts", new HashSet<String>())) {
            if (s.contains(":")) {
                accounts.put(s.split(":")[0], s.split(":")[1]);
            } else {
                accounts.put(s, "");
            }
        }
        final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
        final String guest = getString(R.string.guest);
        keys.add(guest);
        final LinearLayout accountList = header.findViewById(R.id.accountsarea);
        for (final String accName : keys) {
            LogUtil.v(accName);
            final View t = getLayoutInflater().inflate(R.layout.account_textview_white, accountList, false);
            ((TextView) t.findViewById(R.id.name)).setText(accName);
            LogUtil.v("Adding click to " + ((TextView) t.findViewById(R.id.name)).getText());
            if (!accName.equals(guest)) {
                t.findViewById(R.id.remove).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        new AlertDialogWrapper.Builder(MainActivity.this).setTitle(R.string.profile_remove).setMessage(R.string.profile_remove_account).setNegativeButton(R.string.btn_delete, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog2, int which2) {
                                Set<String> accounts2 = Authentication.authentication.getStringSet("accounts", new HashSet<String>());
                                Set<String> done = new HashSet<>();
                                for (String s : accounts2) {
                                    if (!s.contains(accName)) {
                                        done.add(s);
                                    }
                                }
                                Authentication.authentication.edit().putStringSet("accounts", done).commit();
                                dialog2.dismiss();
                                accountList.removeView(t);
                                if (accName.equalsIgnoreCase(Authentication.name)) {
                                    boolean d = false;
                                    for (String s : keys) {
                                        if (!s.equalsIgnoreCase(accName)) {
                                            d = true;
                                            LogUtil.v("Switching to " + s);
                                            for (Map.Entry<String, String> e : accounts.entrySet()) {
                                                LogUtil.v(e.getKey() + ":" + e.getValue());
                                            }
                                            if (accounts.containsKey(s) && !accounts.get(s).isEmpty()) {
                                                Authentication.authentication.edit().putString("lasttoken", accounts.get(s)).remove("backedCreds").commit();
                                            } else {
                                                ArrayList<String> tokens = new ArrayList<>(Authentication.authentication.getStringSet("tokens", new HashSet<String>()));
                                                int index = keys.indexOf(s);
                                                if (keys.indexOf(s) > tokens.size()) {
                                                    index -= 1;
                                                }
                                                Authentication.authentication.edit().putString("lasttoken", tokens.get(index)).remove("backedCreds").commit();
                                            }
                                            Authentication.name = s;
                                            UserSubscriptions.switchAccounts();
                                            Reddit.forceRestart(MainActivity.this, true);
                                            break;
                                        }
                                    }
                                    if (!d) {
                                        Authentication.name = "LOGGEDOUT";
                                        Authentication.isLoggedIn = false;
                                        Authentication.authentication.edit().remove("lasttoken").remove("backedCreds").commit();
                                        UserSubscriptions.switchAccounts();
                                        Reddit.forceRestart(MainActivity.this, true);
                                    }
                                } else {
                                    accounts.remove(accName);
                                    keys.remove(accName);
                                }
                            }
                        }).setPositiveButton(R.string.btn_cancel, null).show();
                    }
                });
            } else {
                t.findViewById(R.id.remove).setVisibility(View.GONE);
            }
            t.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    String accName = ((TextView) t.findViewById(R.id.name)).getText().toString();
                    LogUtil.v("Found name is " + accName);
                    if (!accName.equalsIgnoreCase(Authentication.name)) {
                        LogUtil.v("Switching to " + accName);
                        if (!accName.equals(guest)) {
                            if (!accounts.get(accName).isEmpty()) {
                                LogUtil.v("Using token " + accounts.get(accName));
                                Authentication.authentication.edit().putString("lasttoken", accounts.get(accName)).remove("backedCreds").apply();
                            } else {
                                ArrayList<String> tokens = new ArrayList<>(Authentication.authentication.getStringSet("tokens", new HashSet<String>()));
                                Authentication.authentication.edit().putString("lasttoken", tokens.get(keys.indexOf(accName))).remove("backedCreds").apply();
                            }
                            Authentication.name = accName;
                        } else {
                            Authentication.name = "LOGGEDOUT";
                            Authentication.isLoggedIn = false;
                            Authentication.authentication.edit().remove("lasttoken").remove("backedCreds").apply();
                        }
                        UserSubscriptions.switchAccounts();
                        Reddit.forceRestart(MainActivity.this, true);
                    }
                }
            });
            accountList.addView(t);
        }
        header.findViewById(R.id.godown).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                LinearLayout body = header.findViewById(R.id.expand_profile);
                if (body.getVisibility() == View.GONE) {
                    expand(body);
                    flipAnimator(false, view).start();
                } else {
                    collapse(body);
                    flipAnimator(true, view).start();
                }
            }
        });
        header.findViewById(R.id.add).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Login.class);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.offline).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Reddit.appRestart.edit().putBoolean("forceoffline", true).commit();
                Reddit.forceRestart(MainActivity.this);
            }
        });
        header.findViewById(R.id.inbox).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Inbox.class);
                MainActivity.this.startActivityForResult(inte, INBOX_RESULT);
            }
        });
        headerMain = header;
        if (runAfterLoad == null) {
            new AsyncNotificationBadge().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    } else if (Authentication.didOnline) {
        header = inflater.inflate(R.layout.drawer_loggedout, drawerSubList, false);
        drawerSubList.addHeaderView(header, null, false);
        headerMain = header;
        hea = header.findViewById(R.id.back);
        final LinearLayout profStuff = header.findViewById(R.id.accountsarea);
        profStuff.setVisibility(View.GONE);
        findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (profStuff.getVisibility() == View.GONE) {
                    expand(profStuff);
                    flipAnimator(false, header.findViewById(R.id.headerflip)).start();
                } else {
                    collapse(profStuff);
                    flipAnimator(true, header.findViewById(R.id.headerflip)).start();
                }
            }
        });
        final HashMap<String, String> accounts = new HashMap<>();
        for (String s : Authentication.authentication.getStringSet("accounts", new HashSet<String>())) {
            if (s.contains(":")) {
                accounts.put(s.split(":")[0], s.split(":")[1]);
            } else {
                accounts.put(s, "");
            }
        }
        final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
        final String guest = getString(R.string.guest);
        keys.add(guest);
        final LinearLayout accountList = header.findViewById(R.id.accountsarea);
        for (final String accName : keys) {
            LogUtil.v(accName);
            final View t = getLayoutInflater().inflate(R.layout.account_textview_white, accountList, false);
            ((TextView) t.findViewById(R.id.name)).setText(accName);
            if (!accName.equals(guest)) {
                t.findViewById(R.id.remove).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        new AlertDialogWrapper.Builder(MainActivity.this).setTitle(R.string.profile_remove).setMessage(R.string.profile_remove_account).setNegativeButton(R.string.btn_delete, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog2, int which2) {
                                Set<String> accounts2 = Authentication.authentication.getStringSet("accounts", new HashSet<String>());
                                Set<String> done = new HashSet<>();
                                for (String s : accounts2) {
                                    if (!s.contains(accName)) {
                                        done.add(s);
                                    }
                                }
                                Authentication.authentication.edit().putStringSet("accounts", done).commit();
                                dialog2.dismiss();
                                accountList.removeView(t);
                                if (accName.equalsIgnoreCase(Authentication.name)) {
                                    boolean d = false;
                                    for (String s : keys) {
                                        if (!s.equalsIgnoreCase(accName)) {
                                            d = true;
                                            LogUtil.v("Switching to " + s);
                                            if (!accounts.get(s).isEmpty()) {
                                                Authentication.authentication.edit().putString("lasttoken", accounts.get(s)).remove("backedCreds").commit();
                                            } else {
                                                ArrayList<String> tokens = new ArrayList<>(Authentication.authentication.getStringSet("tokens", new HashSet<String>()));
                                                Authentication.authentication.edit().putString("lasttoken", tokens.get(keys.indexOf(s))).remove("backedCreds").commit();
                                            }
                                            Authentication.name = s;
                                            UserSubscriptions.switchAccounts();
                                            Reddit.forceRestart(MainActivity.this, true);
                                        }
                                    }
                                    if (!d) {
                                        Authentication.name = "LOGGEDOUT";
                                        Authentication.isLoggedIn = false;
                                        Authentication.authentication.edit().remove("lasttoken").remove("backedCreds").commit();
                                        UserSubscriptions.switchAccounts();
                                        Reddit.forceRestart(MainActivity.this, true);
                                    }
                                } else {
                                    accounts.remove(accName);
                                    keys.remove(accName);
                                }
                            }
                        }).setPositiveButton(R.string.btn_cancel, null).show();
                    }
                });
            } else {
                t.findViewById(R.id.remove).setVisibility(View.GONE);
            }
            t.setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    if (!accName.equalsIgnoreCase(Authentication.name) && !accName.equals(guest)) {
                        if (!accounts.get(accName).isEmpty()) {
                            Authentication.authentication.edit().putString("lasttoken", accounts.get(accName)).remove("backedCreds").commit();
                        } else {
                            ArrayList<String> tokens = new ArrayList<>(Authentication.authentication.getStringSet("tokens", new HashSet<String>()));
                            Authentication.authentication.edit().putString("lasttoken", tokens.get(keys.indexOf(accName))).remove("backedCreds").commit();
                        }
                        Authentication.isLoggedIn = true;
                        Authentication.name = accName;
                        UserSubscriptions.switchAccounts();
                        Reddit.forceRestart(MainActivity.this, true);
                    }
                }
            });
            accountList.addView(t);
        }
        header.findViewById(R.id.add).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Login.class);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.offline).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Reddit.appRestart.edit().putBoolean("forceoffline", true).commit();
                Reddit.forceRestart(MainActivity.this);
            }
        });
        headerMain = header;
        header.findViewById(R.id.multi).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                new MaterialDialog.Builder(MainActivity.this).inputRange(3, 20).alwaysCallInputCallback().input(getString(R.string.user_enter), null, new MaterialDialog.InputCallback() {

                    @Override
                    public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
                        final EditText editText = dialog.getInputEditText();
                        EditTextValidator.validateUsername(editText);
                        if (input.length() >= 3 && input.length() <= 20) {
                            dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
                        }
                    }
                }).positiveText(R.string.user_btn_gotomultis).onPositive(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        if (runAfterLoad == null) {
                            Intent inte = new Intent(MainActivity.this, MultiredditOverview.class);
                            inte.putExtra(Profile.EXTRA_PROFILE, dialog.getInputEditText().getText().toString());
                            MainActivity.this.startActivity(inte);
                        }
                    }
                }).negativeText(R.string.btn_cancel).show();
            }
        });
    } else {
        header = inflater.inflate(R.layout.drawer_offline, drawerSubList, false);
        headerMain = header;
        drawerSubList.addHeaderView(header, null, false);
        hea = header.findViewById(R.id.back);
        header.findViewById(R.id.online).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Reddit.appRestart.edit().remove("forceoffline").commit();
                Reddit.forceRestart(MainActivity.this);
            }
        });
    }
    header.findViewById(R.id.manage).setOnClickListener(new OnSingleClickListener() {

        @Override
        public void onSingleClick(View view) {
            Intent i = new Intent(MainActivity.this, ManageOfflineContent.class);
            startActivity(i);
        }
    });
    if (Authentication.didOnline) {
        View support = header.findViewById(R.id.support);
        if (SettingValues.tabletUI) {
            support.setVisibility(View.GONE);
        } else {
            header.findViewById(R.id.support).setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View view) {
                    new AlertDialogWrapper.Builder(MainActivity.this).setTitle(R.string.settings_support_slide).setMessage(R.string.pro_upgrade_msg).setPositiveButton(R.string.btn_yes_exclaim, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            try {
                                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=me.ccrama.slideforreddittabletuiunlock")));
                            } catch (ActivityNotFoundException e) {
                                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=me.ccrama.slideforreddittabletuiunlock")));
                            }
                        }
                    }).setNegativeButton(R.string.btn_no_danks, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.dismiss();
                        }
                    }).show();
                }
            });
        }
        header.findViewById(R.id.prof).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                new MaterialDialog.Builder(MainActivity.this).inputRange(3, 20).alwaysCallInputCallback().input(getString(R.string.user_enter), null, new MaterialDialog.InputCallback() {

                    @Override
                    public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
                        final EditText editText = dialog.getInputEditText();
                        EditTextValidator.validateUsername(editText);
                        if (input.length() >= 3 && input.length() <= 20) {
                            dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
                        }
                    }
                }).positiveText(R.string.user_btn_goto).onPositive(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        Intent inte = new Intent(MainActivity.this, Profile.class);
                        // noinspection ConstantConditions
                        inte.putExtra(Profile.EXTRA_PROFILE, dialog.getInputEditText().getText().toString());
                        MainActivity.this.startActivity(inte);
                    }
                }).negativeText(R.string.btn_cancel).show();
            }
        });
    }
    header.findViewById(R.id.settings).setOnClickListener(new OnSingleClickListener() {

        @Override
        public void onSingleClick(View v) {
            Intent i = new Intent(MainActivity.this, Settings.class);
            startActivity(i);
            // Cancel sub loading because exiting the settings will reload it anyway
            if (mAsyncGetSubreddit != null)
                mAsyncGetSubreddit.cancel(true);
            drawerLayout.closeDrawers();
        }
    });
    /*  footer.findViewById(R.id.settings).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent inte = new Intent(Overview.this, Setting.class);
                Overview.this.startActivityForResult(inte, 3);
            }
        });*/
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    final ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(MainActivity.this, drawerLayout, toolbar, R.string.btn_open, R.string.btn_close) {

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            // this disables the animation
            super.onDrawerSlide(drawerView, 0);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (drawerLayout.isDrawerOpen(GravityCompat.END)) {
                int current = pager.getCurrentItem();
                if (current == toOpenComments && toOpenComments != 0) {
                    current -= 1;
                }
                String compare = usedArray.get(current);
                if (compare.equals("random") || compare.equals("myrandom") || compare.equals("randnsfw")) {
                    if (adapter != null && adapter.getCurrentFragment() != null && ((SubmissionsView) adapter.getCurrentFragment()).adapter.dataSet.subredditRandom != null) {
                        String sub = ((SubmissionsView) adapter.getCurrentFragment()).adapter.dataSet.subredditRandom;
                        doSubSidebarNoLoad(sub);
                        doSubSidebar(sub);
                    }
                } else {
                    doSubSidebar(usedArray.get(current));
                }
            }
        }

        @Override
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(drawerLayout.getWindowToken(), 0);
        }
    };
    drawerLayout.setDrawerListener(actionBarDrawerToggle);
    actionBarDrawerToggle.syncState();
    header.findViewById(R.id.back).setBackgroundColor(Palette.getColor("alsdkfjasld"));
    accountsArea = header.findViewById(R.id.accountsarea);
    if (accountsArea != null) {
        accountsArea.setBackgroundColor(Palette.getDarkerColor("alsdkfjasld"));
    }
    setDrawerSubList();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) NonNull(android.support.annotation.NonNull) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) HashSet(java.util.HashSet) Toolbar(android.support.v7.widget.Toolbar) EditText(android.widget.EditText) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ActivityNotFoundException(android.content.ActivityNotFoundException) DialogAction(com.afollestad.materialdialogs.DialogAction) LayoutInflater(android.view.LayoutInflater) Map(java.util.Map) HashMap(java.util.HashMap) Set(java.util.Set) HashSet(java.util.HashSet) DialogInterface(android.content.DialogInterface) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) InputMethodManager(android.view.inputmethod.InputMethodManager) Intent(android.content.Intent) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) ListView(android.widget.ListView) Point(android.graphics.Point) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) LinearLayout(android.widget.LinearLayout)

Aggregations

View (android.view.View)367 RecyclerView (android.support.v7.widget.RecyclerView)271 TextView (android.widget.TextView)175 Intent (android.content.Intent)109 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)84 Toolbar (android.support.v7.widget.Toolbar)77 TextWatcher (android.text.TextWatcher)77 Editable (android.text.Editable)76 ImageView (android.widget.ImageView)76 ArrayList (java.util.ArrayList)68 Bundle (android.os.Bundle)48 DialogInterface (android.content.DialogInterface)47 AlertDialog (android.support.v7.app.AlertDialog)47 AdapterView (android.widget.AdapterView)46 EditText (android.widget.EditText)42 SuppressLint (android.annotation.SuppressLint)39 Button (android.widget.Button)39 ActionBar (android.support.v7.app.ActionBar)34 List (java.util.List)34 ViewPropertyAnimatorCompat (android.support.v4.view.ViewPropertyAnimatorCompat)33