parent
00f4c565e2
commit
29f9c94e38
@ -0,0 +1,44 @@
|
||||
package com.example.musicplayer.base;
|
||||
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.musicplayer.constant.Constant;
|
||||
import com.example.musicplayer.entiy.AlbumSong;
|
||||
import com.example.musicplayer.util.CommonUtil;
|
||||
import com.example.musicplayer.util.RxApiManager;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
||||
/**
|
||||
* Created by 残渊 on 2018/12/5.
|
||||
*/
|
||||
|
||||
public abstract class BaseObserver<T> implements Observer<T> {
|
||||
private BaseActivity context;
|
||||
|
||||
public BaseObserver(BaseActivity context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
RxApiManager.get().add(Constant.ALBUM,d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
if(e instanceof UnknownHostException){
|
||||
onComplete();
|
||||
CommonUtil.showToast(context,"当前网络不可用,请检查当前网络");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
package com.example.musicplayer.callback;
|
||||
|
||||
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
||||
/**
|
||||
* 主要管理rxJava的Subscription描述
|
||||
* Created by 残渊 on 2018/12/5.
|
||||
*/
|
||||
|
||||
public interface RxActionManager<T> {
|
||||
void add(T tag, Disposable d);
|
||||
void remove(T tag);
|
||||
void cancel(T tag);
|
||||
void cancelAll();
|
||||
}
|
||||
|
@ -0,0 +1,94 @@
|
||||
package com.example.musicplayer.util;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.os.Build;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
import com.example.musicplayer.callback.RxActionManager;
|
||||
|
||||
import org.reactivestreams.Subscription;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
||||
|
||||
/**
|
||||
* Created by 残渊 on 2018/12/5.
|
||||
*/
|
||||
|
||||
public class RxApiManager implements RxActionManager<Object> {
|
||||
private static final String TAG="RxApiManager";
|
||||
|
||||
private static RxApiManager sInstance = null;
|
||||
|
||||
private ArrayMap<Object, Disposable> maps;
|
||||
|
||||
public static RxApiManager get() {
|
||||
|
||||
if (sInstance == null) {
|
||||
synchronized (RxApiManager.class) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new RxApiManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
private RxApiManager() {
|
||||
maps = new ArrayMap<>();
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
@Override
|
||||
public void add(Object tag, Disposable disposable) {
|
||||
maps.put(tag, disposable);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
@Override
|
||||
public void remove(Object tag) {
|
||||
if (!maps.isEmpty()) {
|
||||
maps.remove(tag);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
public void removeAll() {
|
||||
if (!maps.isEmpty()) {
|
||||
maps.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
@Override public void cancel(Object tag) {
|
||||
if (maps.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (maps.get(tag) == null) {
|
||||
return;
|
||||
}
|
||||
if (!maps.get(tag).isDisposed()) {
|
||||
Log.d(TAG, "cancel: "+tag);
|
||||
maps.get(tag).dispose();
|
||||
maps.remove(tag);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
@Override public void cancelAll() {
|
||||
if (maps.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Set<Object> keys = maps.keySet();
|
||||
for (Object apiKey : keys) {
|
||||
cancel(apiKey);
|
||||
}
|
||||
removeAll();
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 60 KiB |
After Width: | Height: | Size: 9.1 KiB |
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_selected="false" android:drawable="@drawable/favorites"/>
|
||||
<item android:state_selected="true" android:drawable="@drawable/favorites_selected"/>
|
||||
<item android:drawable="@drawable/favorites"/>
|
||||
|
||||
</selector>
|
@ -1,34 +1,64 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:background="@drawable/welcome"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
|
||||
|
||||
android:background="@drawable/welcome"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/music"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginStart="50dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/app_name"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginStart="50dp"
|
||||
android:ems="1"
|
||||
android:textStyle="bold"
|
||||
android:text="@string/welcome"
|
||||
android:textColor="@color/musicStyle"
|
||||
android:textSize="30sp"
|
||||
android:typeface="serif"
|
||||
android:textColor="@color/musicStyle"/>
|
||||
android:textStyle="bold"
|
||||
android:typeface="serif" />
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:background="@color/tab"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_icon"
|
||||
android:layout_width="35dp"
|
||||
android:layout_height="35dp"
|
||||
android:src="@mipmap/icon" />
|
||||
|
||||
<TextView
|
||||
android:layout_marginTop="40dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:text="@string/welcome"
|
||||
android:textSize="25sp"
|
||||
android:textColor="@color/musicStyle"
|
||||
android:layout_below="@+id/music"/>
|
||||
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_toRightOf="@+id/iv_icon"
|
||||
android:text="@string/app_name"
|
||||
android:textColor="@color/white_blue"
|
||||
android:textSize="22sp" />
|
||||
</RelativeLayout>
|
||||
<TextView
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_below="@+id/iv_icon"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16sp"
|
||||
android:text="袁健策版权所有@2018"/>
|
||||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
@ -1,23 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_empty_song"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:src="@drawable/song_empty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:src="@drawable/empty_song"
|
||||
android:scaleType="centerCrop"/>
|
||||
|
||||
<TextView
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/iv_empty_song"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_gravity="center"
|
||||
android:text="本地音乐为空,试试点击右上角导入本地歌曲"
|
||||
android:textColor="@color/white_blue"/>
|
||||
android:textColor="@color/player"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</FrameLayout>
|
@ -1,17 +1,59 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<ImageView
|
||||
android:id="@+id/iv_background"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
android:layout_marginBottom="65dp"
|
||||
android:src="@color/translucent"/>
|
||||
|
||||
<com.github.jdsjlzx.recyclerview.LRecyclerView
|
||||
android:id="@+id/recycler_song_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="65dp">
|
||||
android:layout_marginBottom="65dp"
|
||||
android:visibility="gone">
|
||||
|
||||
|
||||
</com.github.jdsjlzx.recyclerview.LRecyclerView>
|
||||
|
||||
<com.wang.avi.AVLoadingIndicatorView
|
||||
android:id="@+id/avi"
|
||||
style="@style/AVLoadingIndicatorView.Small"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:visibility="visible"
|
||||
app:indicatorColor="@color/musicStyle"
|
||||
app:indicatorName="LineScaleIndicator" />
|
||||
<TextView
|
||||
android:id="@+id/tv_loading"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/avi"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:text="加载中,请稍侯"
|
||||
android:textColor="@color/white_blue"
|
||||
android:textSize="16sp"/>
|
||||
|
||||
<de.hdodenhof.circleimageview.CircleImageView
|
||||
android:id="@+id/iv_network_error"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="150dp"
|
||||
android:layout_marginTop="130dp"
|
||||
android:visibility="gone"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:src="@drawable/network_error"
|
||||
android:scaleType="centerCrop"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
After Width: | Height: | Size: 84 KiB |
Loading…
Reference in new issue