修改上滑为显示当前播放列表,下滑为库

新增POPDialog组件
This commit is contained in:
Yutousama 2022-05-27 14:18:10 +08:00
parent 6de3eeeb2f
commit e2285ec1c5
2 changed files with 31 additions and 6 deletions

Binary file not shown.

View File

@ -13,6 +13,7 @@ import android.view.GestureDetector;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
@ -24,10 +25,13 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityOptionsCompat; import androidx.core.app.ActivityOptionsCompat;
import androidx.core.util.Pair; import androidx.core.util.Pair;
import androidx.core.view.GestureDetectorCompat; import androidx.core.view.GestureDetectorCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.RequestOptions;
import com.yutou.nas_music_player.Adapters.MusicLibsAdapter;
import com.yutou.nas_music_player.Datas.MusicData; import com.yutou.nas_music_player.Datas.MusicData;
import com.yutou.nas_music_player.R; import com.yutou.nas_music_player.R;
import com.yutou.nas_music_player.containers.MediaBrowserHelper; import com.yutou.nas_music_player.containers.MediaBrowserHelper;
@ -315,7 +319,8 @@ public class MainActivity extends AppCompatActivity {
public boolean onTouchEvent(MotionEvent event) { public boolean onTouchEvent(MotionEvent event) {
return touch.onTouchEvent(event); return touch.onTouchEvent(event);
} }
private void toPlayList(){
private void toPlayList() {
Pair<View, String> pImage = Pair.create((View) album_image, "main_album_image"); Pair<View, String> pImage = Pair.create((View) album_image, "main_album_image");
Pair<View, String> pPrevious = Pair.create((View) previous, "previous"); Pair<View, String> pPrevious = Pair.create((View) previous, "previous");
Pair<View, String> pPlay = Pair.create((View) play, "play"); Pair<View, String> pPlay = Pair.create((View) play, "play");
@ -342,6 +347,29 @@ public class MainActivity extends AppCompatActivity {
} }
} }
private void showPOPDialog() {
List<MusicData> playList = MusicContainer.getInstance().getPlayList();
POPDialog dialog = new POPDialog(this);
RecyclerView recyclerView = null;
dialog.enableExitButton(true);
if (playList.isEmpty()) {
dialog.setTitle("播放列表");
dialog.setMessage("播放列表为空,正在全列表随机播放");
} else {
dialog.setTitle("播放列表:" + playList.size());
MusicLibsAdapter adapter = new MusicLibsAdapter(this);
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
recyclerView = new RecyclerView(this);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setLayoutParams(params);
recyclerView.setAdapter(adapter);
adapter.setData(playList);
adapter.setBrowserHelper(browserHelper);
dialog.setContentView(recyclerView);
}
dialog.show();
}
private class PlayListener extends MediaControllerCompat.Callback { private class PlayListener extends MediaControllerCompat.Callback {
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
@Override @Override
@ -397,17 +425,14 @@ public class MainActivity extends AppCompatActivity {
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
float x = e1.getX() - e2.getX(); float x = e1.getX() - e2.getX();
float y = e1.getY() - e2.getY(); float y = e1.getY() - e2.getY();
if (Math.abs(x) < 200 && y > 500) { if (Math.abs(x) < 200 && y > 300) {
System.out.println(""); showPOPDialog();
} else if (Math.abs(x) < 200 && y < -500) { } else if (Math.abs(x) < 200 && y < -500) {
toPlayList(); toPlayList();
System.out.println("");
} else if (Math.abs(y) < 200 && x > 300) { } else if (Math.abs(y) < 200 && x > 300) {
next.callOnClick(); next.callOnClick();
System.out.println("");
} else if (Math.abs(y) < 200 && x < -300) { } else if (Math.abs(y) < 200 && x < -300) {
previous.callOnClick(); previous.callOnClick();
System.out.println("");
} }
return super.onFling(e1, e2, velocityX, velocityY); return super.onFling(e1, e2, velocityX, velocityY);
} }