准备重构项目

pull/1/head
jsyjst 6 years ago
parent 6c7b150b13
commit 0e1ed23d08

@ -1,40 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="10">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
<item index="4" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
<item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="9">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
<item index="6" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
</list>
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="JDK" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" /> <mapping directory="" vcs="Git" />
</component> </component>
</project> </project>

@ -1,11 +1,11 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
android { android {
compileSdkVersion 27 compileSdkVersion 28
defaultConfig { defaultConfig {
applicationId "com.example.musicplayer" applicationId "com.example.musicplayer"
minSdkVersion 22 minSdkVersion 22
targetSdkVersion 27 targetSdkVersion 28
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@ -30,15 +30,15 @@ allprojects {
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:27.1.1'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:design:27.1.1' implementation 'com.android.support:design:28.0.0'
implementation 'de.hdodenhof:circleimageview:2.2.0' implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.android.support:recyclerview-v7:27.1.1' implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
//RxJava2 //RxJava2
implementation 'io.reactivex.rxjava2:rxjava:2.0.1' implementation 'io.reactivex.rxjava2:rxjava:2.0.1'
@ -55,7 +55,7 @@ dependencies {
//LRecyclerView //LRecyclerView
implementation 'com.github.jdsjlzx:LRecyclerView:1.5.4.3' implementation 'com.github.jdsjlzx:LRecyclerView:1.5.4.3'
//CardView //CardView
implementation 'com.android.support:cardview-v7:27.1.1' implementation 'com.android.support:cardview-v7:28.0.0'
//page //page
implementation 'com.github.florent37:materialviewpager:1.2.3' implementation 'com.github.florent37:materialviewpager:1.2.3'
implementation 'com.flaviofaria:kenburnsview:1.0.7' implementation 'com.flaviofaria:kenburnsview:1.0.7'

@ -0,0 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]

@ -13,6 +13,7 @@ public class BaseUri {
public static String STORAGE_IMG_FILE=MyApplication.getContext().getExternalFilesDir("") + "/yuanmusic/img/"; public static String STORAGE_IMG_FILE=MyApplication.getContext().getExternalFilesDir("") + "/yuanmusic/img/";
public static String STORAGE_LRC_FILE=MyApplication.getContext().getExternalFilesDir("") + "/yuanmusic/lrc/"; public static String STORAGE_LRC_FILE=MyApplication.getContext().getExternalFilesDir("") + "/yuanmusic/lrc/";
public static String STORAGE_SONG_FILE=MyApplication.getContext().getExternalFilesDir("") + "/yuanmusic/song/";
public static final String BASE_API_URL_LASTFM = "http://ws.audioscrobbler.com/2.0/"; public static final String BASE_API_URL_LASTFM = "http://ws.audioscrobbler.com/2.0/";
} }

@ -13,7 +13,7 @@ import java.util.List;
public interface IPlayContract { public interface IPlayContract {
interface Model{ interface Model{
void getSingerImg(String singer,String song,long duration);//网络请求获得歌手uri void getSingerImg(String singer,String song,long duration);//网络请求获得歌手uri
void getLrc(String song,long duration);//网络获取歌词 void getLrcUrl(String song, long duration);//网络获取歌词地址
void queryLove(String songId);//查询我喜欢的数据库中有没这首歌 void queryLove(String songId);//查询我喜欢的数据库中有没这首歌
void saveToLove(Song song); //添加到我喜欢的表 void saveToLove(Song song); //添加到我喜欢的表
void deleteFromLove(String songId); //从我喜欢的表中移除 void deleteFromLove(String songId); //从我喜欢的表中移除
@ -27,11 +27,11 @@ public interface IPlayContract {
void showLoveAnim(); //喜欢的动画 void showLoveAnim(); //喜欢的动画
void saveToLoveSuccess();//保存到我喜欢数据库成功 void saveToLoveSuccess();//保存到我喜欢数据库成功
void sendUpdateCollection(); //发送广播更新收藏列表 void sendUpdateCollection(); //发送广播更新收藏列表
void showLrcMessage(String lrc); //显示歌词获取信息 void showLrcMessage(String lrc,String id); //显示歌词获取信息
} }
interface Presenter{ interface Presenter{
void getSingerImg(String singer,String song,long duration); void getSingerImg(String singer,String song,long duration);
void getLrc(String song,long duration); void getLrcUrl(String song, long duration);
void getSingerImgSuccess(String ImgUrl); //成功获取图片 void getSingerImgSuccess(String ImgUrl); //成功获取图片
void getSongLrcSuccess(List<SeachSong.DataBean> dataBeans,long duration); //成功获取歌词 void getSongLrcSuccess(List<SeachSong.DataBean> dataBeans,long duration); //成功获取歌词
void getSongLrcFail(); //获取歌词失败 void getSongLrcFail(); //获取歌词失败

@ -29,4 +29,12 @@ public interface SearchApi {
*/ */
@GET("search?key=579621905&type=song&limit=10&offset=0") @GET("search?key=579621905&type=song&limit=10&offset=0")
Observable<SeachSong> search(@Query("s") String seek); Observable<SeachSong> search(@Query("s") String seek);
/**
*
* @param id id
* @return
*/
@GET("lrc?key=579621905")
Observable<String> getLrc(@Query("id") String id);
} }

@ -97,7 +97,7 @@ public class PlayModel implements IPlayContract.Model {
} }
@Override @Override
public void getLrc(String song, long duration) { public void getLrcUrl(String song, long duration) {
NetWork.getSearchApi().search(song) NetWork.getSearchApi().search(song)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())

@ -1,6 +1,5 @@
package com.example.musicplayer.presenter; package com.example.musicplayer.presenter;
import android.support.design.widget.TabLayout;
import android.util.Log; import android.util.Log;
import com.example.musicplayer.base.BasePresenter; import com.example.musicplayer.base.BasePresenter;
@ -30,8 +29,8 @@ public class PlayPresenter extends BasePresenter<IPlayContract.View> implements
} }
@Override @Override
public void getLrc(String song, long duration) { public void getLrcUrl(String song, long duration) {
mModel.getLrc(song,duration); mModel.getLrcUrl(song,duration);
} }
@Override @Override
@ -42,26 +41,25 @@ public class PlayPresenter extends BasePresenter<IPlayContract.View> implements
} }
@Override @Override
public void getSongLrcSuccess(List<SeachSong.DataBean> dataBeans,long duration) { public void getSongLrcSuccess(List<SeachSong.DataBean> dataBeans, long duration) {
if(isAttachView()){ if(isAttachView()){
Log.d(TAG, "getSongLrcSuccess: duration="+MediaUtil.formatLongToThree(duration));
boolean isLrc =false; boolean isLrc =false;
for(SeachSong.DataBean dataBean : dataBeans){ for(SeachSong.DataBean dataBean : dataBeans){
if(dataBean.getTime() == MediaUtil.formatLongToThree(duration)){ if(dataBean.getTime() == MediaUtil.formatLongToThree(duration)){
isLrc = true; isLrc = true;
getMvpView().showLrcMessage(dataBean.getLrc()); getMvpView().showLrcMessage(dataBean.getLrc(),dataBean.getId());
break; break;
} }
} }
Log.d(TAG, "getSongLrcSuccess: "+isLrc); if(!isLrc) getMvpView().showLrcMessage(dataBeans.get(0).getLrc(),dataBeans.get(0).getId());
if(!isLrc) getMvpView().showLrcMessage(dataBeans.get(0).getLrc());
} }
} }
@Override @Override
public void getSongLrcFail() { public void getSongLrcFail() {
if(isAttachView()){ if(isAttachView()){
getMvpView().showLrcMessage(null); getMvpView().showLrcMessage(null,null);
} }
} }

@ -4,6 +4,8 @@ package com.example.musicplayer.view;
import android.animation.ObjectAnimator; import android.animation.ObjectAnimator;
import android.animation.ValueAnimator; import android.animation.ValueAnimator;
import android.app.ActivityOptions; import android.app.ActivityOptions;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
@ -96,6 +98,7 @@ public class MainActivity extends AppCompatActivity {
Intent playIntent = new Intent(MainActivity.this, PlayerService.class); Intent playIntent = new Intent(MainActivity.this, PlayerService.class);
bindService(playIntent, connection, Context.BIND_AUTO_CREATE); bindService(playIntent, connection, Context.BIND_AUTO_CREATE);
initView(); initView();
} }
@Override @Override
public void onDestroy() { public void onDestroy() {

@ -57,6 +57,7 @@ import com.example.musicplayer.widget.BackgroundAnimationRelativeLayout;
import com.example.musicplayer.widget.DiscView; import com.example.musicplayer.widget.DiscView;
import com.example.musicplayer.widget.LrcView; import com.example.musicplayer.widget.LrcView;
import java.io.BufferedOutputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -67,11 +68,18 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.util.List; import java.util.List;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import retrofit2.http.Url;
/** /**
* *
*/ */
@ -104,6 +112,8 @@ public class PlayActivity extends BaseActivity implements IPlayContract.View {
private TextView mCurrentTimeTv; private TextView mCurrentTimeTv;
private TextView mDurationTimeTv; private TextView mDurationTimeTv;
private ImageView mDownLoad; //下载
private String mLrc = null; private String mLrc = null;
@ -208,6 +218,7 @@ public class PlayActivity extends BaseActivity implements IPlayContract.View {
mLoveBtn = findViewById(R.id.btn_love); mLoveBtn = findViewById(R.id.btn_love);
mOrderBtn = findViewById(R.id.btn_order); mOrderBtn = findViewById(R.id.btn_order);
mLrcView = findViewById(R.id.lrcView); mLrcView = findViewById(R.id.lrcView);
mDownLoad = findViewById(R.id.downloadIv);
//界面填充 //界面填充
mSong = FileHelper.getSong(); mSong = FileHelper.getSong();
@ -399,11 +410,11 @@ public class PlayActivity extends BaseActivity implements IPlayContract.View {
mDisc.setOnClickListener(v -> { mDisc.setOnClickListener(v -> {
if (!isOnline) { if (!isOnline) {
if (getLrcFromLocal().equals("")) { if (getLrcFromLocal().equals("")) {
mPresenter.getLrc(getSongName(), mSong.getDuration()); mPresenter.getLrcUrl(getSongName(), mSong.getDuration());
} }
showLrc(getLrcFromLocal()); showLrc(getLrcFromLocal());
} else { } else {
mPresenter.getLrc(getSongName(), mSong.getDuration()); mPresenter.getLrcUrl(getSongName(), mSong.getDuration());
} }
} }
); );
@ -412,6 +423,11 @@ public class PlayActivity extends BaseActivity implements IPlayContract.View {
mLrcView.setVisibility(View.GONE); mLrcView.setVisibility(View.GONE);
mDisc.setVisibility(View.VISIBLE); mDisc.setVisibility(View.VISIBLE);
}); });
//歌曲下载
mDownLoad.setOnClickListener(v -> {
CommonUtil.showToast(this,"开始下载歌曲");
downLoad(mSong.getUrl(), mSong.getSongName());
});
} }
@ -506,7 +522,7 @@ public class PlayActivity extends BaseActivity implements IPlayContract.View {
} }
@Override @Override
public void showLrcMessage(String lrc) { public void showLrcMessage(String lrc, String id) {
if (lrc == null) { if (lrc == null) {
CommonUtil.showToast(PlayActivity.this, "抱歉,获取不到该歌曲的歌词信息"); CommonUtil.showToast(PlayActivity.this, "抱歉,获取不到该歌曲的歌词信息");
mLrc = null; mLrc = null;
@ -670,7 +686,6 @@ public class PlayActivity extends BaseActivity implements IPlayContract.View {
while ((len = inputStream.read(buffer)) != -1) { while ((len = inputStream.read(buffer)) != -1) {
os.write(buffer, 0, len); os.write(buffer, 0, len);
} }
Log.d(TAG, "getLrcFromLocal: "+os.toString("gbk"));
return os.toString("gbk"); //文件编码是gbk return os.toString("gbk"); //文件编码是gbk
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
@ -687,17 +702,57 @@ public class PlayActivity extends BaseActivity implements IPlayContract.View {
* @param lrc * @param lrc
*/ */
private void showLrc(final String lrc) { private void showLrc(final String lrc) {
runOnUiThread(new Runnable() { runOnUiThread(()->{
@Override mDisc.setVisibility(View.GONE);
public void run() { mLrcView.setVisibility(View.VISIBLE);
mDisc.setVisibility(View.GONE); mLrcView.setLrc(lrc);
mLrcView.setVisibility(View.VISIBLE); mLrcView.setHighLineColor(getResources().getColor(R.color.musicStyle));
mLrcView.setLrc(lrc); mLrcView.setPlayer(mPlayStatusBinder.getMediaPlayer());
mLrcView.setHighLineColor(getResources().getColor(R.color.musicStyle)); mLrcView.init();
mLrcView.setPlayer(mPlayStatusBinder.getMediaPlayer()); });
mLrcView.init();
}
private void downLoad(String url, String song) {
new Thread(() -> {
File file = new File(BaseUri.STORAGE_SONG_FILE);
if (!file.exists()) {
file.mkdirs();
} }
File songFile = new File(file, song + ".mp3");
BufferedOutputStream out = null;
try {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(url).build();
Response response = client.newCall(request).execute();
if (response.isSuccessful()){
out = new BufferedOutputStream(new FileOutputStream(songFile));
byte[] bytes = response.body().bytes();
out.write(bytes,0,bytes.length);
out.close();
}
showLoadSuccess();
} catch (IOException e){
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}finally {
try{
if(out != null) out.close();
}catch (Exception e){
e.printStackTrace();
}
}
}).start();
}
private void showLoadSuccess(){
runOnUiThread(()->{
CommonUtil.showToast(this,"歌曲下载成功");
}); });
} }
@Override @Override

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

@ -67,7 +67,7 @@
android:layout_marginTop="@dimen/dp_40" android:layout_marginTop="@dimen/dp_40"
android:layout_marginBottom="@dimen/dp_40" android:layout_marginBottom="@dimen/dp_40"
android:layout_below="@+id/relative_song" android:layout_below="@+id/relative_song"
android:layout_above="@+id/relative_music_time" android:layout_above="@+id/downloadIv"
app:lrcTextSize="18sp" app:lrcTextSize="18sp"
app:hignLineColor="@color/musicStyle" app:hignLineColor="@color/musicStyle"
android:visibility="gone"/> android:visibility="gone"/>
@ -85,12 +85,22 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/disc_view" android:layout_below="@+id/disc_view"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_marginTop="30dp" android:layout_marginTop="10dp"
android:textColor="@color/white" android:textColor="@color/white"
android:background="@drawable/button_bg" android:background="@drawable/button_bg"
android:text="获取封面歌词"/> android:text="获取封面歌词"/>
<ImageView
android:id="@+id/downloadIv"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/download_song"
android:layout_above="@+id/relative_music_time"
android:layout_centerHorizontal="true"
/>
<RelativeLayout <RelativeLayout
android:id="@+id/relative_music_time" android:id="@+id/relative_music_time"
android:layout_width="match_parent" android:layout_width="match_parent"

@ -6,9 +6,10 @@ buildscript {
mavenCentral() mavenCentral()
google() google()
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.0.1' classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong

@ -15,4 +15,4 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit # This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true # org.gradle.parallel=true
android.enableAapt2 = false

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

Loading…
Cancel
Save