Пример #1
0
 // 更新界面
 @Override
 public void UpdateUI(MP3Item MP3Item, boolean isplay) {
   // 底部状态兰
   mBottombar.UpdateBottomStatus(MP3Item, isplay);
   // 更新高亮歌曲
   if (mAdapter != null) mAdapter.notifyDataSetChanged();
 }
Пример #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_child_holder);
    ButterKnife.bind(this);

    mInstance = this;
    MusicService.addCallback(ChildHolderActivity.this);
    mMultiChoice.setOnUpdateOptionMenuListener(
        new OnUpdateOptionMenuListener() {
          @Override
          public void onUpdate(final boolean multiShow) {
            mMultiChoice.setShowing(multiShow);
            mToolBar.setNavigationIcon(
                mMultiChoice.isShow() ? R.drawable.actionbar_delete : R.drawable.actionbar_menu);
            mToolBar.setNavigationOnClickListener(
                new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                    if (mMultiChoice.isShow()) {
                      mMultiChoice.UpdateOptionMenu(false);
                      mMultiChoice.clear();
                    } else {
                      finish();
                    }
                  }
                });
            if (!mMultiChoice.isShow()) {
              mMultiChoice.clear();
            }
            invalidateOptionsMenu();
          }
        });

    // 参数id,类型,标题
    mId = getIntent().getIntExtra("Id", -1);
    mType = getIntent().getIntExtra("Type", -1);
    mArg = getIntent().getStringExtra("Title");

    new Thread() {
      @Override
      public void run() {
        mInfoList = getMP3List();
        mRefreshHandler.sendEmptyMessage(Constants.UPDATE_ADAPTER);
      }
    }.start();

    mAdapter = new ChildHolderAdapter(this, mType, mArg, mMultiChoice);
    mAdapter.setOnItemClickLitener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(View view, int position) {
            long songid = mInfoList.get(position).getId();
            if (songid > 0 && !mMultiChoice.itemAddorRemoveWithClick(view, position, songid, TAG)) {
              if (mInfoList != null && mInfoList.size() == 0) return;
              ArrayList<Integer> ids = new ArrayList<>();
              for (MP3Item info : mInfoList) {
                if (info != null && info.getId() > 0) ids.add(info.getId());
              }
              // 设置正在播放列表
              Global.setPlayingList(ids);

              Intent intent = new Intent(Constants.CTL_ACTION);
              Bundle arg = new Bundle();
              arg.putInt("Control", Constants.PLAYSELECTEDSONG);
              arg.putInt("Position", position);
              intent.putExtras(arg);
              sendBroadcast(intent);
            }
          }

          @Override
          public void onItemLongClick(View view, int position) {
            long songid = mInfoList.get(position).getId();
            if (songid > 0) mMultiChoice.itemAddorRemoveWithLongClick(view, position, songid, TAG);
          }
        });
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.addItemDecoration(
        new ListItemDecoration(
            this,
            ListItemDecoration.VERTICAL_LIST,
            getResources().getDrawable(R.drawable.divider)));
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());

    // 歌曲数目与标题
    if (mType != Constants.FOLDER) {
      if (mArg.contains("unknown")) {
        if (mType == Constants.ARTIST) Title = getString(R.string.unknow_artist);
        else if (mType == Constants.ALBUM) {
          Title = getString(R.string.unknow_album);
        }
      } else {
        Title = mArg;
      }
    } else Title = mArg.substring(mArg.lastIndexOf("/") + 1, mArg.length());
    // 初始化toolbar
    initToolbar(mToolBar, Title);
    // 初始化底部状态栏
    mBottombar =
        (BottomActionBarFragment)
            getSupportFragmentManager().findFragmentById(R.id.bottom_actionbar_new);
    if (Global.mPlayingList == null || Global.mPlayingList.size() == 0) return;

    mBottombar.UpdateBottomStatus(MusicService.getCurrentMP3(), MusicService.getIsplay());
  }