Skip to content

Commit af48f9e

Browse files
Improvements and bug fixed
1 parent bc5bef3 commit af48f9e

18 files changed

+308
-257
lines changed

.idea/libraries/Dart_Packages.xml

+40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/Flutter_Plugins.xml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/app/.classpath

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
<classpath>
33
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
44
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
5-
<classpathentry kind="output" path="bin"/>
5+
<classpathentry kind="output" path="bin/default"/>
66
</classpath>

android/app/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ android {
2828
applicationId "com.onedreamers.musicplayer"
2929
minSdkVersion 16
3030
targetSdkVersion 27
31-
versionCode 5
31+
versionCode 6
3232
multiDexEnabled = true
33-
versionName "0.8"
33+
versionName "1.0 beta"
3434
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
3535
}
3636

android/app/src/main/AndroidManifest.xml

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
android:name="io.flutter.app.FlutterApplication"
2121
android:label="Music player"
2222
android:icon="@mipmap/ic_launcher">
23+
<meta-data
24+
android:name="com.google.android.gms.ads.APPLICATION_ID"
25+
android:value="ca-app-pub-1268517211128422~7673583142"/>
26+
2327

2428
<activity
2529
android:name=".MainActivity"
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,27 @@
11
package com.onedreamers.musicplayer;
22

3-
import android.Manifest;
4-
import android.annotation.TargetApi;
5-
import android.content.Context;
6-
import android.content.ContextWrapper;
7-
import android.content.Intent;
8-
import android.graphics.Bitmap;
9-
import android.graphics.BitmapFactory;
10-
import android.media.MediaMetadataRetriever;
11-
import android.net.Uri;
12-
import android.os.Build;
133
import android.os.Bundle;
144
import android.util.Log;
155
import io.flutter.app.FlutterActivity;
166
import io.flutter.plugin.common.MethodCall;
177
import io.flutter.plugin.common.MethodChannel;
8+
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
189
import io.flutter.plugins.GeneratedPluginRegistrant;
1910

20-
import java.io.File;
21-
import java.io.FileOutputStream;
22-
import java.io.IOException;
23-
import java.util.HashMap;
24-
import java.util.Map;
25-
2611
public class MainActivity extends FlutterActivity {
27-
MediaMetadataRetriever metaRetriver;
28-
byte[] art;
29-
Map<String, String> song;
30-
Uri file;
31-
Intent intent;
32-
int requestcode = 1;
33-
34-
@TargetApi(Build.VERSION_CODES.M)
3512
@Override
3613
protected void onCreate(Bundle savedInstanceState) {
3714
super.onCreate(savedInstanceState);
3815
GeneratedPluginRegistrant.registerWith(this);
39-
try {
40-
intent = getIntent();
41-
String action = intent.getAction();
42-
String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
43-
if (action == Intent.ACTION_VIEW) {
44-
requestPermissions(permissions, requestcode);
45-
handle(intent);
46-
new MethodChannel(getFlutterView(), "app.channel.shared.data").setMethodCallHandler(new MethodChannel.MethodCallHandler() {
47-
@Override
48-
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
49-
if (methodCall.method.contentEquals("getSharedData")) {
50-
result.success(song);
51-
}
52-
}
53-
});
54-
}
55-
} catch (Exception e) {
56-
Log.d("cdve", e.getMessage());
57-
}
58-
}
59-
60-
void handle(Intent intent) {
61-
file = intent.getData();
62-
song = new HashMap<>();
63-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
64-
metaRetriver = new MediaMetadataRetriever();
65-
metaRetriver.setDataSource(file.getPath());
66-
try {
67-
art = metaRetriver.getEmbeddedPicture();
68-
song.put("album", metaRetriver.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM));
69-
song.put("artist", metaRetriver.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST));
70-
song.put("duration", metaRetriver.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
71-
String title = metaRetriver.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
72-
song.put("title", title);
73-
song.put("uri", file.getPath());
74-
if (art != null) {
75-
Bitmap songImage = BitmapFactory.decodeByteArray(art, 0, art.length);
76-
song.put("albumArt", saveToInternalStorage(songImage, title));
77-
} else {
78-
song.put("albumArt", null);
16+
new MethodChannel(getFlutterView(), "android_app_retain").setMethodCallHandler(new MethodCallHandler() {
17+
@Override
18+
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
19+
if (call.method.equals("sendToBackground")) {
20+
Log.d("abc", "Backkkkk");
21+
moveTaskToBack(true);
7922
}
80-
81-
} catch (Exception e) {
82-
Log.d("23456543", e.getMessage());
8323
}
84-
}
85-
}
24+
});
8625

87-
private String saveToInternalStorage(Bitmap bitmapImage, String title) {
88-
ContextWrapper cw = new ContextWrapper(getApplicationContext());
89-
File directory = cw.getDir("thumbs", Context.MODE_PRIVATE);
90-
91-
File file = new File(directory, title + ".png");
92-
FileOutputStream fos = null;
93-
try {
94-
fos = new FileOutputStream(file);
95-
bitmapImage.compress(Bitmap.CompressFormat.PNG, 50, fos);
96-
} catch (Exception e) {
97-
e.printStackTrace();
98-
} finally {
99-
try {
100-
fos.close();
101-
} catch (IOException e) {
102-
e.printStackTrace();
103-
}
104-
}
105-
return file.getAbsolutePath();
10626
}
10727
}

android/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
}
66

77
dependencies {
8-
classpath 'com.android.tools.build:gradle:3.0.1'
8+
classpath 'com.android.tools.build:gradle:3.2.1'
99
classpath 'com.google.gms:google-services:3.2.1'
1010
}
1111
}

android/gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip

lib/database/database_client.dart

+15
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,21 @@ class DatabaseClient {
4646
return id;
4747
}
4848

49+
Future<int> updateList(Song song) async {
50+
song.count = 0;
51+
song.timestamp = new DateTime.now().millisecondsSinceEpoch;
52+
;
53+
song.isFav = 0;
54+
55+
int id = 0;
56+
var count = Sqflite.firstIntValue(await _db
57+
.rawQuery("SELECT COUNT(*) FROM songs WHERE title = ?", [song.title]));
58+
if (count == 0) {
59+
id = await _db.insert("songs", song.toMap());
60+
}
61+
return id;
62+
}
63+
4964
Future<bool> alreadyLoaded() async {
5065
var count =
5166
Sqflite.firstIntValue(await _db.rawQuery("SELECT COUNT(*) FROM songs"));

lib/musichome.dart

+11-31
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import 'package:musicplayer/views/playlists.dart';
1717
import 'package:musicplayer/views/songs.dart';
1818
import 'package:share/share.dart';
1919
import 'package:url_launcher/url_launcher.dart';
20-
2120
class MusicHome extends StatefulWidget {
2221
List<Song> songs;
2322
MusicHome();
@@ -42,6 +41,8 @@ class _musicState extends State<MusicHome> {
4241
bool isLoading = true;
4342
Song last;
4443
Color color = Colors.deepPurple;
44+
45+
4546
getDrawerItemWidget(int pos) {
4647
switch (pos) {
4748
case 0:
@@ -71,38 +72,11 @@ class _musicState extends State<MusicHome> {
7172
getLast();
7273
}
7374

75+
7476
@override
7577
void dispose() async {
7678
super.dispose();
7779
}
78-
79-
// void initPlayer() async {
80-
// db = new DatabaseClient();
81-
// await db.create();
82-
// if (await db.alreadyLoaded()) {
83-
// setState(() {
84-
// isLoading = false;
85-
// getLast();
86-
// });
87-
// } else {
88-
// var songs;
89-
// try {
90-
// songs = await MusicFinder.allSongs();
91-
// } catch (e) {
92-
// //"failed to get songs");
93-
// }
94-
// List<Song> list = new List.from(songs);
95-
// for (Song song in list) db.upsertSOng(song);
96-
// if (!mounted) {
97-
// return;
98-
// }
99-
// setState(() {
100-
// isLoading = false;
101-
// getLast();
102-
// });
103-
// }
104-
// }
105-
10680
// getSharedData() async {
10781
// const platform = const MethodChannel('app.channel.shared.data');
10882
// Map sharedData = await platform.invokeMethod("getSharedData");
@@ -276,12 +250,17 @@ class _musicState extends State<MusicHome> {
276250
? new Center(
277251
child: new CircularProgressIndicator(),
278252
)
279-
: getDrawerItemWidget(_selectedDrawerIndex),
280-
bottomNavigationBar: new BottomNavigationBar(
253+
: Padding(
254+
padding: EdgeInsets.only(bottom: 0),
255+
child: getDrawerItemWidget(_selectedDrawerIndex),
256+
),
257+
bottomNavigationBar: BottomNavigationBar(
281258
items: bottomOptions,
282259
onTap: (index) => _onSelectItem(index),
283260
currentIndex: _selectedDrawerIndex,
284261
),
262+
263+
285264
),
286265
onWillPop: _onWillPop,
287266
);
@@ -318,6 +297,7 @@ class _musicState extends State<MusicHome> {
318297
false;
319298
}
320299

300+
321301
launchUrl(url) async {
322302
if (await canLaunch(url)) {
323303
await launch(url);

0 commit comments

Comments
 (0)