This commit is contained in:
Yutousama 2020-12-02 20:30:00 +08:00
parent 7492f06fd3
commit 08ec84d1d5
10 changed files with 139 additions and 21 deletions

View File

@ -46,6 +46,7 @@ android {
dependencies {
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
def room_version = "2.2.5"
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
@ -66,7 +67,7 @@ dependencies {
implementation 'androidx.palette:palette:1.0.0'
implementation 'com.github.zrunker:ZTextView:v1.0.2'
//debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.5'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.5' //
implementation 'com.kaopiz:kprogresshud:1.2.0'
implementation 'com.ogaclejapan.smarttablayout:library:2.0.0@aar'
implementation 'com.ogaclejapan.smarttablayout:utils-v4:2.0.0@aar'

View File

@ -22,6 +22,7 @@ import com.kaopiz.kprogresshud.KProgressHUD;
import com.yutou.nas_music_player.Datas.MusicData;
import com.yutou.nas_music_player.Interfaces.NetworkInterface;
import com.yutou.nas_music_player.R;
import com.yutou.nas_music_player.containers.MediaBrowserHelper;
import com.yutou.nas_music_player.containers.MusicContainer;
import com.yutou.nas_music_player.tools.AppTools;
@ -33,6 +34,7 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
public class AlbumsRecyclerAdapter extends RecyclerView.Adapter<AlbumsRecyclerAdapter.AlbumHolder> {
List<MusicData> list;
Context context;
MediaBrowserHelper browserHelper;
public AlbumsRecyclerAdapter(Context context, List<MusicData> list) {
this.list = list;
@ -44,6 +46,9 @@ public class AlbumsRecyclerAdapter extends RecyclerView.Adapter<AlbumsRecyclerAd
public AlbumHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new AlbumHolder(LayoutInflater.from(context).inflate(R.layout.layout_music_libs_item, parent, false));
}
public void onStop(){
list.clear();
}
@SuppressLint("SetTextI18n")
@Override
@ -57,9 +62,20 @@ public class AlbumsRecyclerAdapter extends RecyclerView.Adapter<AlbumsRecyclerAd
holder.message.setVisibility(View.VISIBLE);
holder.artist.setVisibility(View.VISIBLE);
// holder.icon.setImageBitmap(ThumbnailUtils.extractThumbnail(data.getImg(), 64,64));
Glide.with(context).load(data.getImg(-1, -1))
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3)))
.into(holder.icon);
data.getImg(-1, -1, new NetworkInterface() {
@Override
public void httpGetData(Object data, int state) {
Glide.with(context).load(data)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3)))
.into(holder.icon);
}
@Override
public void httpError(Exception e) {
}
});
holder.icon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -89,6 +105,17 @@ public class AlbumsRecyclerAdapter extends RecyclerView.Adapter<AlbumsRecyclerAd
}
});
holder.layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
browserHelper.play(data);
}
});
if(MusicContainer.getInstance().getNowPlayData().getMd5().equals(data.getMd5())){
holder.play_mask.setVisibility(View.VISIBLE);
}else{
holder.play_mask.setVisibility(View.GONE);
}
}
@Override
@ -96,9 +123,17 @@ public class AlbumsRecyclerAdapter extends RecyclerView.Adapter<AlbumsRecyclerAd
return list.size();
}
public void setData(List<MusicData> list) {
this.list = list;
}
public void setPlayListener(MediaBrowserHelper browserHelper) {
this.browserHelper = browserHelper;
}
public static class AlbumHolder extends RecyclerView.ViewHolder {
MarqueeTextView title, artist, message;
LinearLayout buttons;
LinearLayout buttons, layout;
ImageButton collection, top, dislike;
ImageView icon, play_mask;
@ -108,6 +143,7 @@ public class AlbumsRecyclerAdapter extends RecyclerView.Adapter<AlbumsRecyclerAd
artist = itemView.findViewById(R.id.artist);
message = itemView.findViewById(R.id.message);
buttons = itemView.findViewById(R.id.buttons);
layout = itemView.findViewById(R.id.layout);
collection = itemView.findViewById(R.id.collection);
top = itemView.findViewById(R.id.top);
dislike = itemView.findViewById(R.id.dislike);

View File

@ -106,6 +106,27 @@ public class MusicLibsAdapter extends ArrayAdapter<MusicData> {
list.addAll(MusicContainer.getInstance().getPlayList());
break;
case LIBS_MODEL_PLAY_Collection:
new Thread(new Runnable() {
@Override
public void run() {
String collection=null;
MusicContainer.getLibs().onCollectionList(collection,new NetworkInterface(){
@Override
public void httpGetData(Object data, int state) {
list.clear();
if (data != null && state == 0)
list.addAll((List<MusicData>) data);
notifyDataSetChanged();
}
@Override
public void httpError(Exception e) {
}
});
}
}).start();
list = new ArrayList<>();
break;
case LIBS_MODEL_ALL:
@ -113,13 +134,6 @@ public class MusicLibsAdapter extends ArrayAdapter<MusicData> {
new Thread(new Runnable() {
@Override
public void run() {
if (musicPath.equals("root")) {
try {
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
MusicContainer.getLibs().onDirMusicData(musicPath, new NetworkInterface() {
@Override
public void httpGetData(Object data, int state) {
@ -219,6 +233,11 @@ public class MusicLibsAdapter extends ArrayAdapter<MusicData> {
holder.play_mask.setVisibility(View.GONE);
holder.icon.setImageResource(R.drawable.ic_dir);
}
if(MusicContainer.getInstance().getNowPlayData().getMd5().equals(data.getMd5())){
holder.play_mask.setVisibility(View.VISIBLE);
}else{
holder.play_mask.setVisibility(View.GONE);
}
holder.top.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -291,7 +310,7 @@ public class MusicLibsAdapter extends ArrayAdapter<MusicData> {
}
private void showImage(MusicData musicData, ViewHolder holder) {
musicData.getImg(64, 64, new NetworkInterface() {
musicData.getImg(-1, -1, new NetworkInterface() {
@Override
public void httpGetData(Object data, int state) {
icons.put(musicData.getFile(), (Bitmap) data);

View File

@ -449,7 +449,7 @@ public class MusicContainer {
return collectionMapList;
}
public class MusicLibs {
public class MusicLibs {
private List<MusicData> mainData;
private MusicLibs() {
@ -457,6 +457,21 @@ public class MusicContainer {
initData();
}
public void onCollectionList(String collection, NetworkInterface networkInterface) {
JSONObject json=new JSONObject();
NetworkTool.init().httpGet(NetworkTool.NetworkAPI.MUSIC_Collection_List, json, new NetworkInterface() {
@Override
public void httpGetData(Object data, int state) {
}
@Override
public void httpError(Exception e) {
}
});
}
public List<MusicData> getMainData() {
return mainData;
}

View File

@ -37,6 +37,7 @@ public class NetworkTool {
public static String HOME = "";
public static String MUSIC_LIST = HOME + "/music/list.do";
public static String MUSIC_Album = HOME + "/music/getAlbum.do";
public static String MUSIC_Collection_List = HOME + "/music/favorite/dir/list.do";
public static String MUSIC_ALL = HOME + "/music/all.do";
public static String MUSIC_METADATA = HOME + "/music/find/file.do";
public static String MUSIC_IMAGE = HOME + "/music/image.do";
@ -52,7 +53,7 @@ public class NetworkTool {
public static String donwloadPath = AppData.dir + AppData.download_dir + File.separator;
private NetworkTool() {
HOME = "http://192.168.137.1:8000/nas";
HOME = "http://192.168.31.92:8000/nas";
if (StringUtil.isEmpty(HOME)) {
httpGet("http://tools.yutou233.cn/nas/music/getlocalhost.do", new JSONObject(), new NetworkInterface() {
@Override

View File

@ -2,6 +2,8 @@ package com.yutou.nas_music_player.views;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.session.MediaControllerCompat;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
@ -13,18 +15,25 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.yutou.nas_music_player.Adapters.AlbumsRecyclerAdapter;
import com.yutou.nas_music_player.Datas.MusicData;
import com.yutou.nas_music_player.Interfaces.NetworkInterface;
import com.yutou.nas_music_player.R;
import com.yutou.nas_music_player.containers.MediaBrowserHelper;
import com.yutou.nas_music_player.containers.MusicContainer;
import java.util.ArrayList;
import java.util.List;
import jp.wasabeef.glide.transformations.BlurTransformation;
public class AlbumsActivity extends AppCompatActivity {
private ImageView album_image;
private ImageView album_image,image_background;
private RecyclerView listView;
private MediaBrowserHelper browserHelper;
private AlbumsRecyclerAdapter adapter;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -32,6 +41,13 @@ public class AlbumsActivity extends AppCompatActivity {
String album=getIntent().getStringExtra("album");
initView();
initData(album);
browserHelper=new MediaBrowserHelper(this);
browserHelper.regPlayListener(new PlayListener());
adapter.setPlayListener(browserHelper);
}
private static class PlayListener extends MediaControllerCompat.Callback {
}
private void initData(String album) {
@ -39,11 +55,16 @@ public class AlbumsActivity extends AppCompatActivity {
@Override
public void httpGetData(Object data, int state) {
List<MusicData> list= (List<MusicData>) data;
listView.setAdapter(new AlbumsRecyclerAdapter(AlbumsActivity.this,list));
adapter.setData(list);
adapter.notifyDataSetChanged();
list.get(0).getImg(-1, -1, new NetworkInterface() {
@Override
public void httpGetData(Object data, int state) {
album_image.setImageBitmap((Bitmap) data);
Glide.with(AlbumsActivity.this).load(data)
.apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3)))
.into(image_background);
listView.setBackgroundColor(list.get(0).getImageColor());
}
@Override
@ -64,7 +85,17 @@ public class AlbumsActivity extends AppCompatActivity {
private void initView() {
album_image=findViewById(R.id.album_image);
image_background=findViewById(R.id.image_background);
listView=findViewById(R.id.album_list);
listView.setLayoutManager(new LinearLayoutManager(this));
adapter=new AlbumsRecyclerAdapter(AlbumsActivity.this,new ArrayList<>());
listView.setAdapter(adapter);
}
@Override
protected void onDestroy() {
super.onDestroy();
adapter.onStop();
browserHelper.onStop();
}
}

View File

@ -181,4 +181,9 @@ public class MusicLibsFragment extends Fragment {
});
}
@Override
public void onDestroyView() {
super.onDestroyView();
map.clear();
}
}

View File

@ -122,6 +122,7 @@ public class PlayLibsActivity extends AppCompatActivity {
getSupportFragmentManager(), FragmentPagerItems.with(this)
.add("全部", MusicLibsFragment.class)
.add("专辑", MusicLibsFragment.class)
.add("收藏夹", MusicLibsFragment.class)
.add("队列", MusicLibsFragment.class)
.create());
viewPager.setAdapter(adapter);
@ -155,6 +156,9 @@ public class PlayLibsActivity extends AppCompatActivity {
fragment.setModel(MusicLibsAdapter.LIBS_MODEL_Album);
break;
case 2:
fragment.setModel(MusicLibsAdapter.LIBS_MODEL_PLAY_Collection);
break;
case 3:
fragment.setModel(MusicLibsAdapter.LIBS_MODEL_Tmp);
break;
}

View File

@ -18,7 +18,11 @@
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="@+id/toolbar">
<ImageView
android:id="@+id/image_background"
android:scaleType="fitXY"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ImageView
android:id="@+id/album_image"
android:layout_width="match_parent"

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
@ -27,8 +28,8 @@
android:layout_width="64dp"
android:layout_height="64dp"
android:background="#66000000"
android:visibility="gone"
android:scaleType="center"
android:visibility="gone"
app:srcCompat="@android:drawable/ic_media_play" />
</FrameLayout>
@ -62,7 +63,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textSize="10sp"
android:layout_marginTop="2dp"
android:shadowColor="@color/textColorGray"
android:shadowDx="5"
@ -70,7 +70,9 @@
android:shadowRadius="1"
android:text="TextView"
android:textColor="@color/colorBlack"
android:textSize="10sp"
android:transitionName="artist" />
<cc.ibooker.ztextviewlib.MarqueeTextView
android:id="@+id/message"
android:layout_width="wrap_content"
@ -81,9 +83,9 @@
android:shadowDx="5"
android:shadowDy="5"
android:shadowRadius="1"
android:textSize="8sp"
android:text="TextView"
android:textColor="@color/colorBlack"
android:textSize="8sp"
android:transitionName="artist" />
</LinearLayout>