parent
0961bdac43
commit
733250899f
@ -0,0 +1,137 @@
|
||||
package com.example.musicplayer.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.musicplayer.R;
|
||||
import com.example.musicplayer.entiy.Love;
|
||||
import com.example.musicplayer.util.FileHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by 残渊 on 2018/11/30.
|
||||
*/
|
||||
|
||||
public class LoveSongAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
private static final String TAG = "LoveSongAdapter";
|
||||
private int footerViewType = 1;
|
||||
private int itemViewType = 0;
|
||||
private List<Love> mLoveList;
|
||||
private Context mContext;
|
||||
private int mLastPosition = -1;
|
||||
private OnItemClickListener onItemClickListener;
|
||||
|
||||
public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
|
||||
this.onItemClickListener = onItemClickListener;
|
||||
}
|
||||
|
||||
public LoveSongAdapter(Context context, List<Love> loveList) {
|
||||
mContext = context;
|
||||
mLoveList = loveList;
|
||||
}
|
||||
|
||||
|
||||
class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView songNameTv;
|
||||
TextView singerTv;
|
||||
View mItemView;
|
||||
View playLine;
|
||||
|
||||
public ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
songNameTv = itemView.findViewById(R.id.tv_title);
|
||||
singerTv = itemView.findViewById(R.id.tv_artist);
|
||||
playLine = itemView.findViewById(R.id.line_play);
|
||||
mItemView = itemView;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 底部holder
|
||||
*/
|
||||
static class FooterHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
TextView numTv;
|
||||
|
||||
public FooterHolder(View itemView) {
|
||||
super(itemView);
|
||||
numTv = itemView.findViewById(R.id.tv_song_num);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
if (viewType == itemViewType) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.recycler_song_search_item, parent, false);
|
||||
ViewHolder viewHolder = new ViewHolder(view);
|
||||
return viewHolder;
|
||||
} else {
|
||||
View footerView = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.footer_local_songs_item, parent, false);
|
||||
FooterHolder footerHolder = new FooterHolder(footerView);
|
||||
return footerHolder;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
|
||||
if (viewHolder instanceof ViewHolder) {
|
||||
ViewHolder holder = (ViewHolder) viewHolder;
|
||||
final Love love = mLoveList.get(position);
|
||||
|
||||
holder.songNameTv.setText(love.getName());
|
||||
holder.singerTv.setText(love.getSinger());
|
||||
//根据点击显示
|
||||
if(love.getSongId().equals(FileHelper.getSong().getOnlineId())){
|
||||
holder.playLine.setVisibility(View.VISIBLE);
|
||||
mLastPosition =position;
|
||||
holder.mItemView.setBackgroundResource(R.color.click);
|
||||
}else {
|
||||
holder.playLine.setVisibility(View.INVISIBLE);
|
||||
holder.mItemView.setBackgroundResource(R.color.transparent);
|
||||
}
|
||||
holder.mItemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onItemClickListener.onSongClick(position);
|
||||
equalPosition(position);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
FooterHolder footerHolder = (FooterHolder) viewHolder;
|
||||
footerHolder.numTv.setText("共" + mLoveList.size() + "首音乐");
|
||||
}
|
||||
}
|
||||
|
||||
//判断点击的是否为上一个点击的项目
|
||||
public void equalPosition(int position) {
|
||||
if (position != mLastPosition) {
|
||||
notifyItemChanged(mLastPosition);
|
||||
mLastPosition = position;
|
||||
}
|
||||
notifyItemChanged(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mLoveList.size() + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return position + 1 == getItemCount() ? footerViewType : itemViewType;
|
||||
}
|
||||
|
||||
|
||||
public interface OnItemClickListener {
|
||||
void onSongClick(int position);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package com.example.musicplayer.entiy;
|
||||
|
||||
import org.litepal.crud.LitePalSupport;
|
||||
|
||||
/**
|
||||
* Created by 残渊 on 2018/11/30.
|
||||
*/
|
||||
|
||||
public class Love extends LitePalSupport{
|
||||
private int id;
|
||||
private String songId;
|
||||
private String name;
|
||||
private String singer;
|
||||
private String url;
|
||||
private String pic;
|
||||
private boolean isOnline;
|
||||
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSinger() {
|
||||
return singer;
|
||||
}
|
||||
|
||||
public void setSinger(String singer) {
|
||||
this.singer = singer;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getPic() {
|
||||
return pic;
|
||||
}
|
||||
|
||||
public void setPic(String pic) {
|
||||
this.pic = pic;
|
||||
}
|
||||
|
||||
|
||||
public String getSongId() {
|
||||
return songId;
|
||||
}
|
||||
|
||||
public void setSongId(String songId) {
|
||||
this.songId = songId;
|
||||
}
|
||||
|
||||
public void setOnline(boolean online) {
|
||||
isOnline = online;
|
||||
}
|
||||
|
||||
public boolean isOnline() {
|
||||
return isOnline;
|
||||
}
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
package com.example.musicplayer.view;
|
||||
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.example.musicplayer.R;
|
||||
import com.example.musicplayer.adapter.LoveSongAdapter;
|
||||
import com.example.musicplayer.adapter.SongAdapter;
|
||||
import com.example.musicplayer.constant.BroadcastName;
|
||||
import com.example.musicplayer.constant.Constant;
|
||||
import com.example.musicplayer.entiy.LocalSong;
|
||||
import com.example.musicplayer.entiy.Love;
|
||||
import com.example.musicplayer.entiy.Song;
|
||||
import com.example.musicplayer.service.PlayerService;
|
||||
import com.example.musicplayer.util.FileHelper;
|
||||
|
||||
import org.litepal.LitePal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by 残渊 on 2018/11/30.
|
||||
*/
|
||||
|
||||
public class CollectionFragment extends Fragment {
|
||||
private RecyclerView mRecycler;
|
||||
private ImageView mBackIv;
|
||||
private LinearLayoutManager mManager;
|
||||
private LoveSongAdapter mAdapter;
|
||||
private LinearLayout mSongListLinear;
|
||||
private RelativeLayout mEmptyRelative;
|
||||
private List<Love> mLoveList;
|
||||
private List<Love> mTempList;
|
||||
|
||||
//注册广播
|
||||
private IntentFilter intentFilter;
|
||||
private SongChangeReceiver songChangeReceiver;
|
||||
|
||||
private PlayerService.PlayStatusBinder mPlayStatusBinder;
|
||||
private ServiceConnection connection = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
mPlayStatusBinder = (PlayerService.PlayStatusBinder) service;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View mView = inflater.inflate(R.layout.fragment_love_music, container, false);
|
||||
mRecycler = mView.findViewById(R.id.recycler_love_songs);
|
||||
mBackIv = mView.findViewById(R.id.iv_back);
|
||||
mEmptyRelative = mView.findViewById(R.id.relative_empty);
|
||||
mSongListLinear = mView.findViewById(R.id.linear_song_list);
|
||||
mTempList =new ArrayList<>();
|
||||
mLoveList = new ArrayList<>();
|
||||
return mView;
|
||||
}
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState){
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
//启动服务
|
||||
Intent playIntent = new Intent(getActivity(), PlayerService.class);
|
||||
getActivity().bindService(playIntent, connection, Context.BIND_AUTO_CREATE);
|
||||
//注册广播
|
||||
intentFilter=new IntentFilter();
|
||||
intentFilter.addAction(BroadcastName.LOVE_SONG_CHANGE);
|
||||
songChangeReceiver=new SongChangeReceiver();
|
||||
getActivity().registerReceiver(songChangeReceiver,intentFilter);
|
||||
showSongList();
|
||||
onClick();
|
||||
}
|
||||
|
||||
|
||||
private void showSongList(){
|
||||
mLoveList.clear();
|
||||
mTempList = LitePal.findAll(Love.class);
|
||||
if(mTempList.size()==0){
|
||||
mEmptyRelative.setVisibility(View.VISIBLE);
|
||||
mSongListLinear.setVisibility(View.GONE);
|
||||
}else{
|
||||
mEmptyRelative.setVisibility(View.GONE);
|
||||
mSongListLinear.setVisibility(View.VISIBLE);
|
||||
}
|
||||
//对数据库的数据倒序显示
|
||||
for(int i=mTempList.size()-1;i>=0;i--){
|
||||
mLoveList.add(mTempList.get(i));
|
||||
}
|
||||
mAdapter = new LoveSongAdapter(getActivity(),mLoveList);
|
||||
mManager = new LinearLayoutManager(getActivity());
|
||||
mRecycler.setLayoutManager(mManager);
|
||||
mRecycler.setAdapter(mAdapter);
|
||||
}
|
||||
private void onClick(){
|
||||
mAdapter.setOnItemClickListener(new LoveSongAdapter.OnItemClickListener() {
|
||||
@Override
|
||||
public void onSongClick(int position) {
|
||||
Love love = mLoveList.get(position);
|
||||
Song song =new Song();
|
||||
song.setOnlineId(love.getSongId());
|
||||
song.setSongName(love.getName());
|
||||
song.setSinger(love.getSinger());
|
||||
song.setOnline(love.isOnline());
|
||||
song.setUrl(love.getUrl());
|
||||
song.setImgUrl(love.getPic());
|
||||
song.setCurrent(position);
|
||||
song.setListType(Constant.LIST_TYPE_LOVE);
|
||||
FileHelper.saveSong(song);
|
||||
|
||||
mPlayStatusBinder.play(Constant.LIST_TYPE_LOVE);
|
||||
}
|
||||
});
|
||||
}
|
||||
private class SongChangeReceiver extends BroadcastReceiver{
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
if(FileHelper.getSong()!=null) {
|
||||
mManager.scrollToPositionWithOffset(FileHelper.getSong().getCurrent()+4, mRecycler.getHeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:ordering="together">
|
||||
|
||||
<objectAnimator
|
||||
android:propertyName="scaleX"
|
||||
android:valueFrom="1.5"
|
||||
android:valueTo="1.0"
|
||||
android:valueType="floatType"/>
|
||||
|
||||
<objectAnimator
|
||||
android:propertyName="scaleY"
|
||||
android:valueFrom="1.5"
|
||||
android:valueTo="1.0"
|
||||
android:valueType="floatType"/>
|
||||
|
||||
</set>
|
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 2.1 KiB |
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<solid android:color="@color/player"/>
|
||||
<corners android:radius="10dp"/>
|
||||
|
||||
</shape>
|
After Width: | Height: | Size: 7.7 KiB |
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_selected="true" android:drawable="@drawable/favorites_selected"/>
|
||||
<item android:drawable="@drawable/favorites"/>
|
||||
|
||||
</selector>
|
@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/dialog_bg">
|
||||
<TextView
|
||||
android:id="@+id/tv_dialog_delete_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="2"
|
||||
android:text="确定删除这张照片?"
|
||||
android:textColor="@color/white_blue"
|
||||
android:textSize="14sp"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0.3dp"
|
||||
android:background="@color/gray"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_dialog_delete_photo_cancel"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/cancel"
|
||||
android:clickable="true"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@color/white_blue"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"/>
|
||||
|
||||
<View
|
||||
android:layout_width="0.3dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/gray"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_dialog_delete_photo_delete"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/sure"
|
||||
android:clickable="true"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@color/yellow"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -0,0 +1,86 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/background"
|
||||
android:orientation="vertical">
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="20dp"
|
||||
android:background="@color/actionBarColor" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?android:attr/actionBarSize"
|
||||
android:background="@color/actionBarColor">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_back"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginStart="10dp"
|
||||
android:src="@drawable/back" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_toRightOf="@id/iv_back"
|
||||
android:text="@string/collection"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</RelativeLayout>
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="20dp"
|
||||
android:background="@color/seekColor">
|
||||
</View>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_song_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/translucent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/recycler_love_songs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="65dp">
|
||||
|
||||
</android.support.v7.widget.RecyclerView>
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="65dp"/>
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/relative_empty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/translucent">
|
||||
<ImageView
|
||||
android:id="@+id/iv_empty"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="120dp"
|
||||
android:src="@drawable/empty_song"
|
||||
android:scaleType="centerCrop"
|
||||
android:layout_centerInParent="true"/>
|
||||
<TextView
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_below="@+id/iv_empty"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@color/white_blue"
|
||||
android:text="收藏列表为空,赶紧去收藏自己喜欢的歌吧"
|
||||
android:layout_centerHorizontal="true"
|
||||
/>
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
Loading…
Reference in new issue