Search in sources :

Example 21 with DialogAction

use of com.afollestad.materialdialogs.DialogAction in project BBS-Android by bdpqchen.

the class HomeActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mHomeActivity = this;
    mContext = this;
    LogUtil.dd("token", PrefUtil.getAuthToken());
    // 登录后的渐变,
    if (!PrefUtil.isNoAccountUser()) {
        PrefUtil.setHadLogin(true);
    }
    mMask.setVisibility(View.VISIBLE);
    ObjectAnimator animator = ObjectAnimator.ofFloat(findViewById(R.id.mask_home), "alpha", 0f).setDuration(600);
    animator.setStartDelay(400);
    animator.start();
    mMainFragment = MainFragment.newInstance();
    mForumFragment = ForumFragment.newInstance();
    mIndividualFragment = IndividualFragment.newInstance();
    loadMultipleRootFragment(R.id.fl_main_container, 0, mMainFragment, mForumFragment, mIndividualFragment);
    mNearBy = mBottomBar.getTabWithId(R.id.bottom_bar_tab_individual);
    mBottomBar.setOnTabSelectListener(i -> {
        LogUtil.dd("onTabSelected()");
        if (PrefUtil.hadLogin()) {
            if (i == R.id.bottom_bar_tab_main) {
                mShowingFragment = Constants.FRAGMENT_MAIN;
            } else if (i == R.id.bottom_bar_tab_forum) {
                mShowingFragment = Constants.FRAGMENT_FORUM;
            } else if (i == R.id.bottom_bar_tab_individual) {
                mShowingFragment = Constants.FRAGMENT_INDIVIDUAL;
            }
            loadFragment();
        } else if (i == R.id.bottom_bar_tab_individual && !PrefUtil.hadLogin()) {
            startActivity(new Intent(this, LoginActivity.class));
        }
    });
    // TODO: 17-5-22 解决夜间模式View的空指针问题
    if (PrefUtil.hadLogin()) {
        mPresenter.initIndividualInfo();
    }
    HandlerUtil.postDelay(() -> {
        PgyUpdateManager.register(this, "9981", new UpdateManagerListener() {

            @Override
            public void onNoUpdateAvailable() {
                LogUtil.dd("not update available");
            }

            @Override
            public void onUpdateAvailable(final String result) {
                // 将新版本信息封装到AppBean中
                final AppBean appBean = getAppBeanFromString(result);
                new MaterialDialog.Builder(mContext).cancelable(false).title("最新版本更新").content(appBean.getReleaseNote()).positiveText("立即下载").positiveColor(ResourceUtil.getColor(mContext, R.color.colorPrimary)).onPositive((new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                        hasPermission(appBean);
                    }
                })).negativeText("再说吧").show();
            }
        });
    }, 1000);
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ObjectAnimator(android.animation.ObjectAnimator) DialogAction(com.afollestad.materialdialogs.DialogAction) Intent(android.content.Intent) UpdateManagerListener(com.pgyersdk.update.UpdateManagerListener) AppBean(com.pgyersdk.javabean.AppBean)

Example 22 with DialogAction

use of com.afollestad.materialdialogs.DialogAction in project Tapad by berict.

the class PresetStoreAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final PresetViewHolder holder, int position) {
    final Preset preset = firebaseMetadata.getPreset(position);
    // set gesture
    if (preset.getMusic().getGesture()) {
        // preset is gesture
        holder.presetGesture.setVisibility(View.VISIBLE);
        holder.presetGesture.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                new MaterialDialog.Builder(activity).title(R.string.preset_store_gesture_help_dialog_title).content(R.string.preset_store_gesture_help_dialog_text).contentColorRes(R.color.dark_primary).positiveText(R.string.dialog_close).positiveColorRes(R.color.colorAccent).show();
            }
        });
    } else {
        holder.presetGesture.setVisibility(View.GONE);
    }
    // load preset image
    String imageUrl = window.getStringFromId(R.string.google_firebase_link_root, activity) + "/presets%2F" + preset.getFirebaseLocation() + "%2F" + "album_art.jpg" + "?alt=media";
    String presetName = preset.getAbout().getTitle();
    String[] presetString = presetName.split(" - ");
    // set title
    holder.presetTitle.setText(presetString[1]);
    // set artist name
    holder.presetArtist.setText(presetString[0]);
    // set preset creator
    holder.presetCreator.setText(window.getStringFromId(R.string.preset_store_preset_by, activity) + " " + preset.getAbout().getPresetCreator());
    // actions
    if (isPresetExists(preset.getFirebaseLocation())) {
        if (isPresetAvailable(preset.getFirebaseLocation())) {
            // exists, select | remove action
            holder.presetSelect.setVisibility(View.VISIBLE);
            holder.presetSelect.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // select and load preset
                    preset.setLoadPreset(activity);
                }
            });
            // load local image
            Picasso.with(activity).load("file:" + PROJECT_LOCATION_PRESETS + "/" + preset.getFirebaseLocation() + "/about/album_art.jpg").placeholder(R.drawable.ic_image_album_placeholder).error(R.drawable.ic_image_album_error).into(holder.presetImage);
            onFirebasePresetUpdated(preset.getFirebaseLocation(), new Runnable() {

                @Override
                public void run() {
                    // preset updated
                    holder.presetUpdate.setVisibility(View.VISIBLE);
                    holder.presetUpdate.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            // re-download the preset
                            preset.repairPreset(parentView, activity, new Runnable() {

                                @Override
                                public void run() {
                                    notifyItemChanged(holder.getAdapterPosition());
                                }
                            });
                        }
                    });
                    // show warning
                    holder.presetWarningLayout.setVisibility(View.VISIBLE);
                    holder.presetWarning.setText(R.string.preset_store_action_update_available);
                }
            });
        } else {
            // corrupted, show repair
            holder.presetSelect.setVisibility(View.VISIBLE);
            holder.presetSelect.setTextColor(activity.getResources().getColor(R.color.colorAccent));
            holder.presetSelect.setText(R.string.preset_store_action_repair);
            // show warning
            holder.presetWarningLayout.setVisibility(View.VISIBLE);
            holder.presetWarning.setText(R.string.preset_store_action_repair_needed);
            holder.presetSelect.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // show repair dialog
                    new MaterialDialog.Builder(activity).title(R.string.preset_store_action_repair_dialog_title).content(R.string.preset_store_action_repair_dialog_text).contentColorRes(R.color.dark_primary).positiveText(R.string.preset_store_action_repair).positiveColorRes(R.color.colorAccent).onPositive(new MaterialDialog.SingleButtonCallback() {

                        @Override
                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                            dialog.dismiss();
                            // repair the preset
                            preset.repairPreset(parentView, activity, new Runnable() {

                                @Override
                                public void run() {
                                    notifyItemChanged(holder.getAdapterPosition());
                                }
                            });
                        }
                    }).negativeText(R.string.dialog_cancel).show();
                }
            });
            // load url image
            Picasso.with(activity).load(imageUrl).placeholder(R.drawable.ic_image_album_placeholder).error(R.drawable.ic_image_album_error).into(holder.presetImage);
        }
        holder.presetRemove.setVisibility(View.VISIBLE);
        holder.presetRemove.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // remove confirm dialog
                new MaterialDialog.Builder(activity).content(R.string.preset_store_remove_warning_dialog_text).contentColorRes(R.color.dark_secondary).positiveText(R.string.remove_ac).positiveColorRes(R.color.red).onPositive(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        dialog.dismiss();
                        // repair the preset
                        preset.removePreset(new Runnable() {

                            @Override
                            public void run() {
                                notifyItemChanged(holder.getAdapterPosition());
                            }
                        }, activity);
                    }
                }).negativeText(R.string.dialog_cancel).show();
            }
        });
        holder.presetUpdate.setVisibility(View.GONE);
        holder.presetDownload.setVisibility(View.GONE);
    } else {
        // doesn't exist, download action
        holder.presetSelect.setVisibility(View.GONE);
        holder.presetRemove.setVisibility(View.GONE);
        holder.presetUpdate.setVisibility(View.GONE);
        holder.presetDownload.setVisibility(View.VISIBLE);
        holder.presetDownload.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                preset.downloadPreset(parentView, activity, new Runnable() {

                    @Override
                    public void run() {
                        notifyItemChanged(holder.getAdapterPosition());
                    }
                });
            }
        });
        // load url image
        Picasso.with(activity).load(imageUrl).placeholder(R.drawable.ic_image_album_placeholder).error(R.drawable.ic_image_album_error).into(holder.presetImage);
    }
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Preset(com.bedrock.padder.model.preset.Preset) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull)

Example 23 with DialogAction

use of com.afollestad.materialdialogs.DialogAction in project Tapad by berict.

the class FileHelper method refreshPresetAdapterActions.

private void refreshPresetAdapterActions(String presetName, View parentView, final Activity activity) {
    TextView presetDownload = (TextView) parentView.findViewById(R.id.layout_preset_store_action_download);
    TextView presetSelect = (TextView) parentView.findViewById(R.id.layout_preset_store_action_select);
    TextView presetRemove = (TextView) parentView.findViewById(R.id.layout_preset_store_action_remove);
    if (isPresetExists(presetName)) {
        if (isPresetAvailable(presetName)) {
            // exists, select | remove action
            presetSelect.setVisibility(View.VISIBLE);
            presetSelect.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                // select and load preset
                // TODO need to revise the loading method
                }
            });
        } else {
            // corrupted, disable select
            presetSelect.setVisibility(View.VISIBLE);
            presetSelect.setAlpha(0.5f);
            presetSelect.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // show repair dialog
                    new MaterialDialog.Builder(activity).title(R.string.preset_store_action_repair_dialog_title).content(R.string.preset_store_action_repair_dialog_text).contentColorRes(R.color.dark_primary).positiveText(R.string.preset_store_action_repair).positiveColorRes(R.color.colorAccent).onPositive(new MaterialDialog.SingleButtonCallback() {

                        @Override
                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                            dialog.dismiss();
                        // remove and download the preset
                        }
                    }).negativeText(R.string.dialog_cancel).show();
                }
            });
        }
        presetRemove.setVisibility(View.VISIBLE);
        //            presetRemove.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    // remove confirm dialog
        //                }
        //            });
        presetDownload.setVisibility(View.GONE);
    } else {
        // doesn't exist, download action
        presetSelect.setVisibility(View.GONE);
        presetRemove.setVisibility(View.GONE);
        presetDownload.setVisibility(View.VISIBLE);
    //            presetDownload.setOnClickListener(new View.OnClickListener() {
    //                @Override
    //                public void onClick(View v) {
    //
    //                }
    //            });
    }
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View)

Example 24 with DialogAction

use of com.afollestad.materialdialogs.DialogAction in project ListenerMusicPlayer by hefuyicoder.

the class FolderAdapter method setOnPopupMenuListener.

private void setOnPopupMenuListener(final ItemHolder itemHolder, final int position) {
    itemHolder.popupMenu.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final PopupMenu menu = new PopupMenu(mContext, v);
            int adapterPosition = itemHolder.getAdapterPosition();
            final FolderInfo folderInfo = arraylist.get(adapterPosition);
            menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.popup_folder_addto_queue:
                            getSongListIdByFolder(folderInfo.folderPath).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {

                                @Override
                                public void call(long[] ids) {
                                    MusicPlayer.addToQueue(mContext, ids, -1, ListenerUtil.IdType.Folder);
                                }
                            });
                            break;
                        case R.id.popup_folder_addto_playlist:
                            getSongListIdByFolder(folderInfo.folderPath).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {

                                @Override
                                public void call(long[] ids) {
                                    ListenerUtil.showAddPlaylistDialog(mContext, ids);
                                }
                            });
                            break;
                        case R.id.popup_folder_delete:
                            new MaterialDialog.Builder(mContext).title(mContext.getResources().getString(R.string.delete_folder)).content("删除文件夹下" + folderInfo.songCount + "首歌曲?").positiveText(R.string.delete).negativeText(R.string.cancel).onPositive(new MaterialDialog.SingleButtonCallback() {

                                @Override
                                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                    getSongListIdByFolder(folderInfo.folderPath).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {

                                        @Override
                                        public void call(long[] ids) {
                                            ListenerUtil.deleteTracks(mContext, ids);
                                            RxBus.getInstance().post(new MediaUpdateEvent());
                                        }
                                    });
                                }
                            }).onNegative(new MaterialDialog.SingleButtonCallback() {

                                @Override
                                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                    dialog.dismiss();
                                }
                            }).show();
                            break;
                    }
                    return false;
                }
            });
            menu.inflate(R.menu.popup_folder);
            menu.show();
        }
    });
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Action1(rx.functions.Action1) MediaUpdateEvent(io.hefuyi.listener.event.MediaUpdateEvent) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) FastScrollRecyclerView(io.hefuyi.listener.widget.fastscroller.FastScrollRecyclerView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) FolderInfo(io.hefuyi.listener.mvp.model.FolderInfo) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) PopupMenu(android.widget.PopupMenu)

Example 25 with DialogAction

use of com.afollestad.materialdialogs.DialogAction in project ListenerMusicPlayer by hefuyicoder.

the class PlaylistAdapter method setOnPopupMenuListener.

private void setOnPopupMenuListener(final ItemHolder itemHolder, final int position) {
    itemHolder.popupMenu.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final PopupMenu menu = new PopupMenu(mContext, v);
            menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    final Playlist playlist = arraylist.get(itemHolder.getAdapterPosition());
                    switch(item.getItemId()) {
                        case R.id.popup_playlist_rename:
                            new MaterialDialog.Builder(mContext).title(R.string.rename_playlist).positiveText("确定").negativeText(R.string.cancel).input(null, playlist.name, false, new MaterialDialog.InputCallback() {

                                @Override
                                public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
                                    MusicPlayer.renamePlaylist(mContext, playlist.id, input.toString());
                                    itemHolder.title.setText(input.toString());
                                    Toast.makeText(mContext, R.string.rename_playlist_success, Toast.LENGTH_SHORT).show();
                                }
                            }).show();
                            break;
                        case R.id.popup_playlist_addto_playlist:
                            getSongListIdByPlaylist(playlist.id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {

                                @Override
                                public void call(long[] ids) {
                                    ListenerUtil.showAddPlaylistDialog(mFragment.getActivity(), ids);
                                }
                            });
                            break;
                        case R.id.popup_playlist_addto_queue:
                            getSongListIdByPlaylist(playlist.id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {

                                @Override
                                public void call(long[] ids) {
                                    MusicPlayer.addToQueue(mContext, ids, -1, ListenerUtil.IdType.Playlist);
                                }
                            });
                            break;
                        case R.id.popup_playlist_delete:
                            new MaterialDialog.Builder(mContext).title(R.string.delete_playlist).positiveText(R.string.delete).negativeText(R.string.cancel).onPositive(new MaterialDialog.SingleButtonCallback() {

                                @Override
                                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                    PlaylistLoader.deletePlaylists(mContext, playlist.id);
                                    arraylist.remove(itemHolder.getAdapterPosition());
                                    notifyItemRemoved(itemHolder.getAdapterPosition());
                                    Toast.makeText(mContext, R.string.delete_playlist_success, Toast.LENGTH_SHORT).show();
                                }
                            }).onNegative(new MaterialDialog.SingleButtonCallback() {

                                @Override
                                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                    dialog.dismiss();
                                }
                            }).show();
                            break;
                    }
                    return false;
                }
            });
            menu.inflate(R.menu.popup_playlist);
            menu.show();
        }
    });
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) FastScrollRecyclerView(io.hefuyi.listener.widget.fastscroller.FastScrollRecyclerView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Playlist(io.hefuyi.listener.mvp.model.Playlist) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) PopupMenu(android.widget.PopupMenu)

Aggregations

DialogAction (com.afollestad.materialdialogs.DialogAction)42 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)42 NonNull (android.support.annotation.NonNull)27 View (android.view.View)27 TextView (android.widget.TextView)21 ImageView (android.widget.ImageView)15 RecyclerView (android.support.v7.widget.RecyclerView)13 MenuItem (android.view.MenuItem)12 PopupMenu (android.widget.PopupMenu)12 Intent (android.content.Intent)7 File (java.io.File)7 LayoutInflater (android.view.LayoutInflater)6 Song (io.hefuyi.listener.mvp.model.Song)6 FastScrollRecyclerView (io.hefuyi.listener.widget.fastscroller.FastScrollRecyclerView)6 List (java.util.List)6 Activity (android.app.Activity)4 Bundle (android.os.Bundle)4 ListView (android.widget.ListView)4 IOException (java.io.IOException)4 SuppressLint (android.annotation.SuppressLint)3