Search in sources :

Example 66 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project Shuttle by timusus.

the class DialogUtils method showWhitelistDialog.

public static void showWhitelistDialog(final Context context) {
    View view = LayoutInflater.from(context).inflate(R.layout.dialog_blacklist, null);
    final MaterialDialog.Builder builder = getBuilder(context).title(R.string.whitelist_title).customView(view, false).positiveText(R.string.close).negativeText(R.string.pref_title_clear_whitelist).onNegative((materialDialog, dialogAction) -> {
        WhitelistHelper.deleteAllFolders();
        Toast.makeText(context, R.string.whitelist_deleted, Toast.LENGTH_SHORT).show();
    });
    final Dialog dialog = builder.build();
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(context));
    final WhitelistAdapter whitelistadapter = new WhitelistAdapter();
    whitelistadapter.setWhitelistListener((v, position, songWhitelist) -> {
        WhitelistHelper.deleteFolder(songWhitelist);
        whitelistadapter.removeItem(position);
        if (whitelistadapter.items.size() == 0) {
            dialog.dismiss();
        }
    });
    recyclerView.setAdapter(whitelistadapter);
    Subscription subscription = WhitelistHelper.getWhitelistFolders().map(whitelistFolders -> Stream.of(whitelistFolders).map(folder -> (AdaptableItem) new WhitelistView(folder)).collect(Collectors.toList())).observeOn(AndroidSchedulers.mainThread()).subscribe(whitelistViews -> {
        if (whitelistViews.size() == 0) {
            whitelistadapter.addItem(0, new EmptyView(R.string.whitelist_empty));
        } else {
            whitelistadapter.setItems(whitelistViews);
        }
    });
    dialog.setOnDismissListener(dialogInterface -> subscription.unsubscribe());
    dialog.show();
}
Also used : WhitelistAdapter(com.simplecity.amp_library.ui.adapters.WhitelistAdapter) WhitelistView(com.simplecity.amp_library.ui.modelviews.WhitelistView) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Dialog(android.app.Dialog) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Subscription(rx.Subscription) View(android.view.View) BlacklistView(com.simplecity.amp_library.ui.modelviews.BlacklistView) ColorView(com.simplecity.amp_library.ui.modelviews.ColorView) TextView(android.widget.TextView) ListView(android.widget.ListView) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) WhitelistView(com.simplecity.amp_library.ui.modelviews.WhitelistView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView)

Example 67 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project Shuttle by timusus.

the class DialogUtils method createRestartDialog.

public static void createRestartDialog(final Context context) {
    MaterialDialog.Builder builder = getBuilder(context).title(R.string.restart_tite).content(R.string.restart_message).positiveText(R.string.restart_button).onPositive((materialDialog, dialogAction) -> {
        Intent intent = new Intent(context, MainActivity.class);
        ComponentName componentNAme = intent.getComponent();
        Intent mainIntent = IntentCompat.makeRestartActivityTask(componentNAme);
        context.startActivity(mainIntent);
    });
    if (!((Activity) context).isFinishing()) {
        builder.show();
    }
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Example 68 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project Shuttle by timusus.

the class SleepTimer method createTimer.

/**
     * Constructor for <code>SleepTimer</code>
     *
     * @param context   The {@link Activity} to use
     * @param active    True if the timer is active, false otherwise
     * @param remaining The remaining time of the current track
     */
public static void createTimer(final Context context, boolean active, final long remaining) {
    final View view = LayoutInflater.from(context).inflate(R.layout.dialog_timer, null);
    final HmsPicker hmsPicker = (HmsPicker) view.findViewById(R.id.hms_picker);
    final HmsView hmsView = (HmsView) view.findViewById(R.id.hms_view);
    ThemeUtils.themeHmsPicker(hmsPicker);
    ThemeUtils.themeHmsView(hmsView);
    final long timeMillis = remaining - System.currentTimeMillis();
    final int minutes = (int) ((timeMillis / (1000 * 60)) % 60);
    final int hours = (int) ((timeMillis / (1000 * 60 * 60)) % 24);
    int minutesFirstDigit = 0;
    int minuteSecondDigit = 0;
    if (minutes > 0) {
        minutesFirstDigit = minutes / 10;
        minuteSecondDigit = minutes % 10;
    }
    hmsView.setTime(hours, minutesFirstDigit, minuteSecondDigit);
    final SharedPreferences mPrefs;
    mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    final CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkbox);
    checkBox.setChecked(mPrefs.getBoolean("sleep_timer_wait_til_end", true));
    checkBox.setOnCheckedChangeListener((compoundButton, b) -> mPrefs.edit().putBoolean("sleep_timer_wait_til_end", b).apply());
    final MaterialDialog.Builder builder = DialogUtils.getBuilder(context).customView(view, false).negativeText(R.string.close);
    if (active) {
        hmsView.setVisibility(View.VISIBLE);
        hmsPicker.setVisibility(View.GONE);
        builder.positiveText(R.string.timer_stop).onPositive((materialDialog, dialogAction) -> MusicUtils.stopTimer());
    } else {
        hmsView.setVisibility(View.GONE);
        hmsPicker.setVisibility(View.VISIBLE);
        builder.positiveText(R.string.timer_set).onPositive((materialDialog, dialogAction) -> {
            if (hmsPicker.getTime() != 0) {
                MusicUtils.setTimer(hmsPicker.getTime() * 1000);
            }
            hmsPicker.setVisibility(View.GONE);
            hmsView.setVisibility(View.VISIBLE);
        });
    }
    builder.show();
    new CountDownTimer(timeMillis, 1000) {

        @Override
        public void onTick(long millisUntilFinished) {
            final long timeMillis = remaining - System.currentTimeMillis();
            final int minutes = (int) ((timeMillis / (1000 * 60)) % 60);
            final int hours = (int) ((timeMillis / (1000 * 60 * 60)) % 24);
            int minutesFirstDigit = 0;
            int minuteSecondDigit = 0;
            if (minutes > 0) {
                minutesFirstDigit = minutes / 10;
                minuteSecondDigit = minutes % 10;
            }
            hmsView.setTime(hours, minutesFirstDigit, minuteSecondDigit);
        }

        @Override
        public void onFinish() {
        }
    }.start();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SharedPreferences(android.content.SharedPreferences) CheckBox(android.widget.CheckBox) CountDownTimer(android.os.CountDownTimer) HmsPicker(com.doomonafireball.betterpickers.hmspicker.HmsPicker) View(android.view.View) HmsView(com.doomonafireball.betterpickers.hmspicker.HmsView) HmsView(com.doomonafireball.betterpickers.hmspicker.HmsView)

Example 69 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project Shuttle by timusus.

the class FolderFragment method onOverflowClick.

@Override
public void onOverflowClick(View v, int position, BaseFileObject fileObject) {
    PopupMenu menu = new PopupMenu(getActivity(), v);
    if (fileObject.fileType == FileType.FILE) {
        //Play this song next
        menu.getMenu().add(FRAGMENT_GROUPID, PLAY_NEXT, 4, R.string.play_next);
        //Tag editor
        if (ShuttleUtils.isUpgraded()) {
            menu.getMenu().add(FRAGMENT_GROUPID, TAGGER, 5, R.string.edit_tags);
        }
        //Set this song as the ringtone
        menu.getMenu().add(FRAGMENT_GROUPID, USE_AS_RINGTONE, 6, R.string.ringtone_menu);
        if (FileHelper.canReadWrite(new File(fileObject.path))) {
            //Rename File
            menu.getMenu().add(FRAGMENT_GROUPID, RENAME, 7, R.string.rename_file);
            //Delete File
            menu.getMenu().add(FRAGMENT_GROUPID, DELETE_ITEM, 8, R.string.delete_item);
        }
        menu.getMenu().add(FRAGMENT_GROUPID, VIEW_INFO, 9, R.string.song_info);
    } else {
        //Play all files in this dir
        menu.getMenu().add(FRAGMENT_GROUPID, PLAY_SELECTION, 0, R.string.play_selection);
        //Set this directory as initial directory
        menu.getMenu().add(FRAGMENT_GROUPID, SET_INITIAL_DIR, 4, R.string.set_initial_dir);
        if (FileHelper.canReadWrite(new File(fileObject.path))) {
            //Rename dir
            menu.getMenu().add(FRAGMENT_GROUPID, RENAME, 5, R.string.rename_folder);
            //Delete dir
            menu.getMenu().add(FRAGMENT_GROUPID, DELETE_ITEM, 6, R.string.delete_item);
        }
    }
    //Bring up the add to playlist menu
    SubMenu sub = menu.getMenu().addSubMenu(FRAGMENT_GROUPID, ADD_TO_PLAYLIST, 2, R.string.add_to_playlist);
    PlaylistUtils.makePlaylistMenu(getActivity(), sub, FRAGMENT_GROUPID);
    //Add to queue
    menu.getMenu().add(FRAGMENT_GROUPID, QUEUE, 3, R.string.add_to_queue);
    menu.getMenu().add(FRAGMENT_GROUPID, RESCAN, 4, R.string.scan_file);
    menu.setOnMenuItemClickListener(item -> {
        switch(item.getItemId()) {
            case TAGGER:
                FileHelper.getSong(new File(fileObject.path)).subscribeOn(Schedulers.io()).subscribe(song -> TaggerDialog.newInstance(song).show(getFragmentManager()));
                return true;
            case QUEUE:
                FileHelper.getSongList(new File(fileObject.path), true, false).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> MusicUtils.addToQueue(getActivity(), songs));
                return true;
            case DELETE_ITEM:
                MaterialDialog.Builder builder = DialogUtils.getBuilder(getActivity()).title(R.string.delete_item).icon(DrawableUtils.getBlackDrawable(getActivity(), R.drawable.ic_dialog_alert));
                if (fileObject.fileType == FileType.FILE) {
                    builder.content(String.format(getResources().getString(R.string.delete_file_confirmation_dialog), fileObject.name));
                } else {
                    builder.content(String.format(getResources().getString(R.string.delete_folder_confirmation_dialog), fileObject.path));
                }
                builder.positiveText(R.string.button_ok).onPositive((materialDialog, dialogAction) -> {
                    if (FileHelper.deleteFile(new File(fileObject.path))) {
                        mAdapter.removeItem(position);
                        CustomMediaScanner.scanFiles(Collections.singletonList(fileObject.path), null);
                    } else {
                        Toast.makeText(getActivity(), fileObject.fileType == FileType.FOLDER ? R.string.delete_folder_failed : R.string.delete_file_failed, Toast.LENGTH_LONG).show();
                    }
                });
                builder.negativeText(R.string.cancel).show();
                return true;
            case RENAME:
                View customView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_rename, null);
                final CustomEditText editText = (CustomEditText) customView.findViewById(R.id.editText);
                ThemeUtils.themeEditText(editText);
                editText.setText(fileObject.name);
                builder = DialogUtils.getBuilder(getActivity());
                if (fileObject.fileType == FileType.FILE) {
                    builder.title(R.string.rename_file);
                } else {
                    builder.title(R.string.rename_folder);
                }
                builder.customView(customView, false);
                builder.positiveText(R.string.save).onPositive((materialDialog, dialogAction) -> {
                    if (editText.getText() != null) {
                        if (FileHelper.renameFile(getActivity(), fileObject, editText.getText().toString())) {
                            mAdapter.notifyDataSetChanged();
                        } else {
                            Toast.makeText(getActivity(), fileObject.fileType == FileType.FOLDER ? R.string.rename_folder_failed : R.string.rename_file_failed, Toast.LENGTH_LONG).show();
                        }
                    }
                });
                builder.negativeText(R.string.cancel).show();
                return true;
            case USE_AS_RINGTONE:
                FileHelper.getSong(new File(fileObject.path)).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(song -> ShuttleUtils.setRingtone(getContext(), song));
                return true;
            case PLAY_NEXT:
                FileHelper.getSongList(new File(fileObject.path), false, false).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> MusicUtils.playNext(getActivity(), songs));
                return true;
            case PLAY_SELECTION:
                final ProgressDialog progressDialog = ProgressDialog.show(getActivity(), "", getString(R.string.gathering_songs), false);
                FileHelper.getSongList(new File(fileObject.path), true, fileObject.fileType == FileType.FILE).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> {
                    MusicUtils.playAll(songs, 0, () -> {
                        final String message = getContext().getString(R.string.emptyplaylist);
                        Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
                    });
                    if (isAdded() && progressDialog.isShowing()) {
                        progressDialog.dismiss();
                    }
                });
                return true;
            case NEW_PLAYLIST:
                List<BaseFileObject> fileObjects = new ArrayList<>();
                fileObjects.add(fileObject);
                PlaylistUtils.createFileObjectPlaylistDialog(getActivity(), fileObjects);
                return true;
            case PLAYLIST_SELECTED:
                final Playlist playlist = (Playlist) item.getIntent().getSerializableExtra(ShuttleUtils.ARG_PLAYLIST);
                FileHelper.getSongList(new File(fileObject.path), true, false).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> PlaylistUtils.addToPlaylist(getContext(), playlist, songs));
                return true;
            case SET_INITIAL_DIR:
                SettingsManager.getInstance().setFolderBrowserInitialDir(fileObject.path);
                Toast.makeText(getActivity(), fileObject.path + getResources().getString(R.string.initial_dir_set_message), Toast.LENGTH_SHORT).show();
                return true;
            case RESCAN:
                if (fileObject instanceof FolderObject) {
                    View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_progress, null);
                    TextView pathsTextView = (TextView) view.findViewById(R.id.paths);
                    pathsTextView.setText(fileObject.path);
                    ProgressBar indeterminateProgress = (ProgressBar) view.findViewById(R.id.indeterminateProgress);
                    DrawableCompat.setTint(DrawableCompat.wrap(indeterminateProgress.getIndeterminateDrawable()), ColorUtils.getAccentColor());
                    ProgressBar horizontalProgress = (ProgressBar) view.findViewById(R.id.horizontalProgress);
                    DrawableCompat.setTint(DrawableCompat.wrap(horizontalProgress.getProgressDrawable()), ColorUtils.getAccentColor());
                    MaterialDialog dialog = DialogUtils.getBuilder(getContext()).title(R.string.scanning).customView(view, false).negativeText(R.string.close).show();
                    FileHelper.getSongList(new File(fileObject.path), true, false).map(songs -> Stream.of(songs).map(song -> song.path).collect(Collectors.toList())).observeOn(AndroidSchedulers.mainThread()).subscribe(paths -> {
                        ViewUtils.fadeOut(indeterminateProgress, null);
                        ViewUtils.fadeIn(horizontalProgress, null);
                        horizontalProgress.setMax(paths.size());
                        CustomMediaScanner.scanFiles(paths, new CustomMediaScanner.ScanCompletionListener() {

                            @Override
                            public void onPathScanned(String path) {
                                horizontalProgress.setProgress(horizontalProgress.getProgress() + 1);
                                pathsTextView.setText(path);
                            }

                            @Override
                            public void onScanCompleted() {
                                if (isAdded() && dialog.isShowing()) {
                                    dialog.dismiss();
                                }
                            }
                        });
                    });
                } else {
                    CustomMediaScanner.scanFiles(Collections.singletonList(fileObject.path), new CustomMediaScanner.ScanCompletionListener() {

                        @Override
                        public void onPathScanned(String path) {
                        }

                        @Override
                        public void onScanCompleted() {
                            Toast.makeText(getContext(), R.string.scan_complete, Toast.LENGTH_LONG).show();
                        }
                    });
                }
                return true;
            case VIEW_INFO:
                DialogUtils.showFileInfoDialog(getActivity(), (FileObject) fileObject);
                break;
        }
        return false;
    });
    menu.show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) CustomEditText(com.simplecity.amp_library.ui.views.CustomEditText) ArrayList(java.util.ArrayList) SubMenu(android.view.SubMenu) ProgressDialog(android.app.ProgressDialog) View(android.view.View) TextView(android.widget.TextView) FolderView(com.simplecity.amp_library.ui.modelviews.FolderView) RecyclerView(android.support.v7.widget.RecyclerView) BreadcrumbsView(com.simplecity.amp_library.ui.modelviews.BreadcrumbsView) Playlist(com.simplecity.amp_library.model.Playlist) BaseFileObject(com.simplecity.amp_library.model.BaseFileObject) TextView(android.widget.TextView) FolderObject(com.simplecity.amp_library.model.FolderObject) File(java.io.File) ProgressBar(android.widget.ProgressBar) PopupMenu(android.support.v7.widget.PopupMenu) CustomMediaScanner(com.simplecity.amp_library.utils.CustomMediaScanner)

Example 70 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project CoCoin by Nightonke.

the class AccountBookSettingActivity method init.

// Init the setting activity////////////////////////////////////////////////////////////////////////
private void init() {
    back = (MaterialIconView) findViewById(R.id.icon_left);
    back.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    logo = (CircleImageView) findViewById(R.id.profile_image);
    logo.setOnClickListener(this);
    profileLayout = (MaterialRippleLayout) findViewById(R.id.profile_layout);
    userNameIcon = (MaterialIconView) findViewById(R.id.user_name_icon);
    userEmailIcon = (MaterialIconView) findViewById(R.id.user_email_icon);
    userName = (TextView) findViewById(R.id.user_name);
    userName.setTypeface(CoCoinUtil.typefaceLatoLight);
    userEmail = (TextView) findViewById(R.id.user_email);
    userEmail.setTypeface(CoCoinUtil.typefaceLatoLight);
    loginButton = (TextView) findViewById(R.id.login_button);
    loginButton.setTypeface(CoCoinUtil.typefaceLatoLight);
    loginButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            userOperator();
        }
    });
    expense = (RiseNumberTextView) findViewById(R.id.expense);
    expense.setTypeface(CoCoinUtil.typefaceLatoLight);
    records = (RiseNumberTextView) findViewById(R.id.records);
    records.setTypeface(CoCoinUtil.typefaceLatoLight);
    expenseTV = (TextView) findViewById(R.id.expense_text);
    expenseTV.setTypeface(CoCoinUtil.GetTypeface());
    recordsTV = (TextView) findViewById(R.id.records_text);
    recordsTV.setTypeface(CoCoinUtil.GetTypeface());
    expense.withNumber(RecordManager.SUM).setDuration(1500).start();
    records.withNumber(RecordManager.RECORDS.size()).setDuration(1500).start();
    monthLayout = (MaterialRippleLayout) findViewById(R.id.month_layout);
    monthIcon = (MaterialIconView) findViewById(R.id.month_limit_icon);
    monthMaxExpenseIcon = (MaterialIconView) findViewById(R.id.month_expense_icon);
    monthColorRemindIcon = (MaterialIconView) findViewById(R.id.month_color_icon);
    monthWarningIcon = (MaterialIconView) findViewById(R.id.warning_expense_icon);
    monthColorRemindTypeIcon = (MaterialIconView) findViewById(R.id.month_color_type_icon);
    monthColorRemindSelect = (MaterialIconView) findViewById(R.id.month_color_type);
    monthColorRemindSelect.setColor(SettingManager.getInstance().getRemindColor());
    monthForbiddenIcon = (MaterialIconView) findViewById(R.id.month_forbidden_icon);
    monthSB = (Switch) findViewById(R.id.month_limit_enable_button);
    monthSB.setOnCheckedChangeListener(this);
    monthColorRemindSB = (Switch) findViewById(R.id.month_color_remind_button);
    monthColorRemindSB.setOnCheckedChangeListener(this);
    monthForbiddenSB = (Switch) findViewById(R.id.month_forbidden_button);
    monthForbiddenSB.setOnCheckedChangeListener(this);
    monthMaxExpense = (RiseNumberTextView) findViewById(R.id.month_expense);
    if (SettingManager.getInstance().getIsMonthLimit())
        monthMaxExpense.withNumber(SettingManager.getInstance().getMonthLimit()).setDuration(1000).start();
    // change the month limit///////////////////////////////////////////////////////////////////////////
    monthMaxExpense.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (SettingManager.getInstance().getIsMonthLimit()) {
                new MaterialDialog.Builder(mContext).theme(Theme.LIGHT).typeface(CoCoinUtil.GetTypeface(), CoCoinUtil.GetTypeface()).title(R.string.set_month_expense_dialog_title).inputType(InputType.TYPE_CLASS_NUMBER).positiveText(R.string.submit).inputRange(3, 5).input(SettingManager.getInstance().getMonthLimit().toString(), null, new MaterialDialog.InputCallback() {

                    @Override
                    public void onInput(MaterialDialog dialog, CharSequence input) {
                        int newExpense = SettingManager.getInstance().getMonthLimit();
                        if (input.length() != 0) {
                            newExpense = Integer.parseInt(input.toString());
                        }
                        // the month limit must be smaller than the month warning
                        if (newExpense < SettingManager.getInstance().getMonthWarning()) {
                            SettingManager.getInstance().setMonthWarning(((int) (newExpense * 0.8) / 100 * 100));
                            if (SettingManager.getInstance().getMonthWarning() < 100) {
                                SettingManager.getInstance().setMonthWarning(100);
                            }
                            updateSettingsToServer(UPDATE_MONTH_WARNING);
                            SettingManager.getInstance().setMainViewRemindColorShouldChange(true);
                            monthWarning.setText(SettingManager.getInstance().getMonthWarning().toString());
                        }
                        SettingManager.getInstance().setMonthLimit(newExpense);
                        updateSettingsToServer(UPDATE_MONTH_LIMIT);
                        SettingManager.getInstance().setTodayViewMonthExpenseShouldChange(true);
                        SettingManager.getInstance().setMainViewMonthExpenseShouldChange(true);
                        monthMaxExpense.withNumber(SettingManager.getInstance().getMonthLimit()).setDuration(1000).start();
                    }
                }).show();
            }
        }
    });
    monthWarning = (RiseNumberTextView) findViewById(R.id.warning_expense);
    monthWarning.setText(SettingManager.getInstance().getMonthWarning().toString());
    if (SettingManager.getInstance().getIsMonthLimit() && SettingManager.getInstance().getIsColorRemind())
        monthWarning.withNumber(SettingManager.getInstance().getMonthWarning()).setDuration(1000).start();
    // change month warning/////////////////////////////////////////////////////////////////////////////
    monthWarning.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (SettingManager.getInstance().getIsMonthLimit() && SettingManager.getInstance().getIsColorRemind()) {
                new MaterialDialog.Builder(mContext).theme(Theme.LIGHT).typeface(CoCoinUtil.GetTypeface(), CoCoinUtil.GetTypeface()).title(R.string.set_month_expense_dialog_title).inputType(InputType.TYPE_CLASS_NUMBER).positiveText(R.string.submit).alwaysCallInputCallback().input(null, null, new MaterialDialog.InputCallback() {

                    @Override
                    public void onInput(final MaterialDialog dialog, final CharSequence input) {
                        if (input.length() == 0) {
                            dialog.setContent(mContext.getResources().getString(R.string.set_warning_expense_dialog_title));
                            dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false);
                        } else if (Integer.parseInt(input.toString()) < 100) {
                            dialog.setContent("≥ 100");
                            dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false);
                        } else if (Integer.parseInt(input.toString()) > SettingManager.getInstance().getMonthLimit()) {
                            dialog.setContent("≤ " + SettingManager.getInstance().getMonthLimit().toString());
                            dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false);
                        } else {
                            dialog.setContent(mContext.getResources().getString(R.string.set_warning_expense_dialog_title));
                            dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
                        }
                        dialog.getActionButton(DialogAction.POSITIVE).setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                SettingManager.getInstance().setMonthWarning(Integer.parseInt(input.toString()));
                                updateSettingsToServer(UPDATE_MONTH_WARNING);
                                SettingManager.getInstance().setMainViewRemindColorShouldChange(true);
                                monthWarning.withNumber(SettingManager.getInstance().getMonthWarning()).setDuration(1000).start();
                                dialog.dismiss();
                            }
                        });
                    }
                }).show();
            }
        }
    });
    // change month remind color////////////////////////////////////////////////////////////////////////
    monthColorRemindSelect.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            SettingManager.getInstance().setMainViewRemindColorShouldChange(true);
            remindColorSelectDialog.show((AppCompatActivity) mContext);
        }
    });
    monthMaxExpense.setTypeface(CoCoinUtil.typefaceLatoLight);
    monthWarning.setTypeface(CoCoinUtil.typefaceLatoLight);
    monthLimitTV = (TextView) findViewById(R.id.month_limit_text);
    monthLimitTV.setTypeface(CoCoinUtil.GetTypeface());
    monthWarningTV = (TextView) findViewById(R.id.warning_expense_text);
    monthWarningTV.setTypeface(CoCoinUtil.GetTypeface());
    monthMaxExpenseTV = (TextView) findViewById(R.id.month_expense_text);
    monthMaxExpenseTV.setTypeface(CoCoinUtil.GetTypeface());
    monthColorRemindTV = (TextView) findViewById(R.id.month_color_remind_text);
    monthColorRemindTV.setTypeface(CoCoinUtil.GetTypeface());
    monthColorRemindTypeTV = (TextView) findViewById(R.id.month_color_type_text);
    monthColorRemindTypeTV.setTypeface(CoCoinUtil.GetTypeface());
    monthForbiddenTV = (TextView) findViewById(R.id.month_forbidden_text);
    monthForbiddenTV.setTypeface(CoCoinUtil.GetTypeface());
    accountBookNameLayout = (MaterialRippleLayout) findViewById(R.id.account_book_name_layout);
    accountBookNameLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            changeAccountBookName();
        }
    });
    accountBookName = (TextView) findViewById(R.id.account_book_name);
    accountBookName.setTypeface(CoCoinUtil.GetTypeface());
    accountBookName.setText(SettingManager.getInstance().getAccountBookName());
    accountBookNameTV = (TextView) findViewById(R.id.account_book_name_text);
    accountBookNameTV.setTypeface(CoCoinUtil.GetTypeface());
    changePasswordLayout = (MaterialRippleLayout) findViewById(R.id.change_password_layout);
    changePasswordLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            changePassword();
        }
    });
    changePasswordTV = (TextView) findViewById(R.id.change_password_text);
    changePasswordTV.setTypeface(CoCoinUtil.GetTypeface());
    sortTagsLayout = (MaterialRippleLayout) findViewById(R.id.sort_tags_layout);
    sortTagsLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            sortTags();
        }
    });
    sortTagsTV = (TextView) findViewById(R.id.sort_tags_text);
    sortTagsTV.setTypeface(CoCoinUtil.GetTypeface());
    showPictureLayout = (MaterialRippleLayout) findViewById(R.id.whether_show_picture_layout);
    showPictureIcon = (MaterialIconView) findViewById(R.id.whether_show_picture_icon);
    showPictureSB = (Switch) findViewById(R.id.whether_show_picture_button);
    showPictureSB.setOnCheckedChangeListener(this);
    showPictureTV = (TextView) findViewById(R.id.whether_show_picture_text);
    showPictureTV.setTypeface(CoCoinUtil.GetTypeface());
    hollowLayout = (MaterialRippleLayout) findViewById(R.id.whether_show_circle_layout);
    hollowIcon = (MaterialIconView) findViewById(R.id.whether_show_circle_icon);
    hollowSB = (Switch) findViewById(R.id.whether_show_circle_button);
    hollowSB.setOnCheckedChangeListener(this);
    hollowTV = (TextView) findViewById(R.id.whether_show_circle_text);
    hollowTV.setTypeface(CoCoinUtil.GetTypeface());
    updateLayout = (MaterialRippleLayout) findViewById(R.id.update_layout);
    updateLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            CoCoinUtil.showToast(mContext, mContext.getResources().getString(R.string.checking_update), SuperToast.Background.BLUE);
            AppUpdateManager appUpdateManager = new AppUpdateManager(mContext);
            appUpdateManager.checkUpdateInfo(true);
        }
    });
    currentVersionTV = (TextView) findViewById(R.id.update_text);
    currentVersionTV.setTypeface(CoCoinUtil.GetTypeface());
    currentVersionTV.setText(mContext.getResources().getString(R.string.current_version) + CoCoinUtil.GetCurrentVersion());
    canBeUpdatedTV = (TextView) findViewById(R.id.update_tag);
    canBeUpdatedTV.setTypeface(CoCoinUtil.GetTypeface());
    if (SettingManager.getInstance().getCanBeUpdated()) {
        canBeUpdatedTV.setVisibility(View.VISIBLE);
    } else {
        canBeUpdatedTV.setVisibility(View.GONE);
    }
    boolean loggenOn = SettingManager.getInstance().getLoggenOn();
    if (loggenOn) {
        // is logged on, set the user name and email
        userName.setText(SettingManager.getInstance().getUserName());
        userEmail.setText(SettingManager.getInstance().getUserEmail());
        loginButton.setText(mContext.getResources().getText(R.string.logout_button));
        loginButton.setBackgroundResource(R.drawable.button_logout);
    } else {
        userName.setText("");
        userEmail.setText("");
        loginButton.setText(getResourceString(R.string.login_button));
    }
    setIconEnable(userNameIcon, loggenOn);
    setIconEnable(userEmailIcon, loggenOn);
    loadLogo();
    monthSB.setCheckedImmediately(SettingManager.getInstance().getIsMonthLimit());
    setMonthState();
    showPictureSB.setCheckedImmediately(SettingManager.getInstance().getShowPicture());
    setShowPictureState(SettingManager.getInstance().getShowPicture());
    hollowSB.setCheckedImmediately(SettingManager.getInstance().getIsHollow());
    setHollowState(SettingManager.getInstance().getIsHollow());
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) AppCompatActivity(android.support.v7.app.AppCompatActivity) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) RiseNumberTextView(com.nightonke.saver.ui.RiseNumberTextView) View(android.view.View) TextView(android.widget.TextView) MaterialIconView(net.steamcrafted.materialiconlib.MaterialIconView) AppUpdateManager(com.nightonke.saver.model.AppUpdateManager)

Aggregations

MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)90 View (android.view.View)57 DialogAction (com.afollestad.materialdialogs.DialogAction)45 TextView (android.widget.TextView)36 NonNull (android.support.annotation.NonNull)33 Intent (android.content.Intent)21 File (java.io.File)21 RecyclerView (android.support.v7.widget.RecyclerView)20 ImageView (android.widget.ImageView)19 SuppressLint (android.annotation.SuppressLint)18 List (java.util.List)16 LayoutInflater (android.view.LayoutInflater)14 MenuItem (android.view.MenuItem)14 Context (android.content.Context)13 PopupMenu (android.widget.PopupMenu)12 Activity (android.app.Activity)11 ListView (android.widget.ListView)11 Toast (android.widget.Toast)11 ArrayList (java.util.ArrayList)11 Bundle (android.os.Bundle)8