Skip to content

Commit

Permalink
added about page
Browse files Browse the repository at this point in the history
  • Loading branch information
raysummee committed Jul 22, 2020
1 parent 4164f8b commit 1d9227f
Show file tree
Hide file tree
Showing 14 changed files with 285 additions and 38 deletions.
76 changes: 76 additions & 0 deletions lib/logic/loveDb.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import 'package:Raylex/logic/models/songInfo.dart';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';

class LoveDb{
get tableLove => "loved";

Future<Database> db() async {
return openDatabase(
join(await getDatabasesPath(), 'loved_database.db'),
onCreate: (db, version) {
return db.execute(
'CREATE TABLE IF NOT EXISTS $tableLove(id INTEGER PRIMARY KEY, artist TEXT, title TEXT, album TEXT, albumId INTERGER, duration INTEGER, uri TEXT, albumArt TEXT, trackId INTEGER)',
);
},
// Version provides path to perform database upgrades and downgrades.
version: 1,
);
}


Future<void> insertLove(SongInfo songInfo) async {
// Get a reference to the database.
final Database database = await db();

// Insert the Product into the correct table.
// Specify `conflictAlgorithm`.
// In this case, if the same product is inserted
// multiple times, it replaces the previous data.
await database.insert(
tableLove,
songInfo.toMap(),
conflictAlgorithm: ConflictAlgorithm.replace,
);
}

Future<void> deleteLove(int id) async {
// Get a reference to the database.
final database = await db();

// Remove the Product from the database.
await database.delete(
tableLove,
// Use a `where` clause to delete a specific product.
where: "id = ?",
// Pass the Products's id as a whereArg to prevent SQL injection.
whereArgs: [id],
);
}

Future<List<SongInfo>> allLove() async {
// Get a reference to the database.
final Database database = await db();

// Query the table for all The Products.
final List<Map<String, dynamic>> maps = await database.query(tableLove);

// Convert the List<Map<String, dynamic> into a List<Product>.
return List.generate(
maps.length,
(i) {
return SongInfo(
maps[i]['id'],
maps[i]['artist'],
maps[i]['title'],
maps[i]['album'],
maps[i]['albumId'],
maps[i]['duration'],
maps[i]['uri'],
maps[i]['albumArt'],
maps[i]['trackId']
);
},
);
}
}
14 changes: 14 additions & 0 deletions lib/logic/models/songInfo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,19 @@ class SongInfo{
albumArt = m["albumArt"];
trackId = m["trackId"];
}

Map<String, dynamic> toMap() {
return {
'id': id,
'artist': artist,
'title': title,
'album': album,
'albumId': albumId,
'duration': duration,
'uri': uri,
'albumArt': albumArt,
'trackId': trackId
};
}

}
2 changes: 1 addition & 1 deletion lib/logic/playerLogic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class PlayerLogic{
}

void nextSong(List<SongInfo> songinfos, int currentpos, {bool playFromBeg:false}) async{
if(currentpos<songinfos.length){
if(currentpos<songinfos.length-1){
playMusic(songinfos.elementAt(++currentpos).uri);
print("nextsong ${++currentpos}");
}else{
Expand Down
5 changes: 3 additions & 2 deletions lib/ux/components/appBars/libraryAppBar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import 'package:flutter/material.dart';


class LibraryAppBar extends StatelessWidget implements PreferredSizeWidget{

final String title;
LibraryAppBar({this.title:"Library"});
@override
Widget build(BuildContext context) {
return AppBar(
backgroundColor: Colors.lightBlue.withAlpha(200),
title: Text("Library")
title: Text(title)
);
}

Expand Down
10 changes: 9 additions & 1 deletion lib/ux/components/appBars/playerAppBar.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import 'package:Raylex/logic/loveDb.dart';
import 'package:Raylex/logic/models/playerStateNotify.dart';
import 'package:Raylex/logic/models/playlistPosition.dart';
import 'package:Raylex/logic/models/songInfo.dart';
import 'package:Raylex/logic/playerLogic.dart';
import 'package:Raylex/ux/components/dialog/editLyricsDialog.dart';
import 'package:Raylex/ux/pages/lyricsPage.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class PlayerAppBar extends StatelessWidget {
final bool inLyrics;
final PlayerLogic playerLogic;
PlayerAppBar(this.playerLogic, {this.inLyrics:false});
@override
Widget build(BuildContext context) {
var appstatelist = Provider.of<PlayerStateNotify>(context);
var appstatepos = Provider.of<PlaylistPosition>(context);
return Container(
margin: EdgeInsets.fromLTRB(10, 10, 10, 10),
alignment: Alignment.topLeft,
Expand Down Expand Up @@ -62,7 +69,8 @@ class PlayerAppBar extends StatelessWidget {
onSelected: (selected){
switch (selected) {
case 0:
print("selected add to liked");
SongInfo songInfo = appstatelist.songinfos.elementAt(appstatepos.index);
LoveDb().insertLove(songInfo);
break;
case 1:
print("selected equalizer");
Expand Down
8 changes: 5 additions & 3 deletions lib/ux/components/cards/miniPlayer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ class _MiniPlayerState extends State<MiniPlayer> with SingleTickerProviderStateM
if(!songended){
print("next song ${appstatepos.index+1}");
if(_playerLogic.repeat!=2){
_playerLogic.nextSong(appstatelist.songinfos, appstatepos.index);
++appstatepos.index;
if(appstatepos.index<appstatelist.songinfos.length-1){
_playerLogic.nextSong(appstatelist.songinfos, appstatepos.index);
++appstatepos.index;
}
if(_playerLogic.repeat==1 && appstatepos.index==appstatelist.songinfos.length-1){
_playerLogic.nextSong(appstatelist.songinfos, 0, playFromBeg: true);
appstatepos.index = 0;
Expand Down Expand Up @@ -191,7 +193,7 @@ class _MiniPlayerState extends State<MiniPlayer> with SingleTickerProviderStateM
color: Colors.white,
icon: Icon(FlutterIcons.fast_forward_mdi),
onPressed: (){
if(appstate.songinfos!=null&&appstatepos!=null){
if(appstate.songinfos!=null&&appstatepos!=null&&appstatepos.index<appstate.songinfos.length-1){
_playerLogic.nextSong(appstate.songinfos, appstatepos.index);
++appstatepos.index;
}
Expand Down
12 changes: 8 additions & 4 deletions lib/ux/components/groups/groupPlayerControl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ class _GroupPlayerControlState extends State<GroupPlayerControl> with TickerProv
color: Colors.grey.shade600,
),
onPressed: (){
widget._playerLogic.prevSong(appstatelist.songinfos, appstatepos.index);
--appstatepos.index;
if(appstatepos.index<appstatelist.songinfos.length-1){
widget._playerLogic.prevSong(appstatelist.songinfos, appstatepos.index);
--appstatepos.index;
}
},
),
IconButton(
Expand Down Expand Up @@ -229,8 +231,10 @@ class _GroupPlayerControlState extends State<GroupPlayerControl> with TickerProv
color: Colors.grey.shade600,
),
onPressed: (){
widget._playerLogic.nextSong(appstatelist.songinfos, appstatepos.index);
++appstatepos.index;
if(appstatepos.index<appstatelist.songinfos.length-1){
widget._playerLogic.nextSong(appstatelist.songinfos, appstatepos.index);
++appstatepos.index;
}
}
)
],
Expand Down
45 changes: 38 additions & 7 deletions lib/ux/components/lists/songList.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';

import 'package:Raylex/logic/loveDb.dart';
import 'package:Raylex/logic/models/playerStateNotify.dart';
import 'package:Raylex/logic/models/playlistPosition.dart';
import 'package:Raylex/logic/models/songInfo.dart';
Expand All @@ -12,7 +13,8 @@ import 'package:provider/provider.dart';

class SongList extends StatefulWidget {
final List<SongInfo> songinfos;
SongList(this.songinfos);
final bool isInLovePlaylist;
SongList(this.songinfos,{this.isInLovePlaylist:false});
@override
_SongListState createState() => _SongListState();
}
Expand All @@ -21,6 +23,7 @@ class _SongListState extends State<SongList> {
@override
Widget build(BuildContext context) {
var appstatepos = Provider.of<PlaylistPosition>(context);
var appstatelist = Provider.of<PlayerStateNotify>(context);
return Container(
alignment: Alignment.center,
child: ListView.builder(
Expand All @@ -46,7 +49,7 @@ class _SongListState extends State<SongList> {
overflow: TextOverflow.fade,
style: TextStyle(
fontSize: 16,
color: appstatepos.index==index?Colors.red:Colors.black
color: appstatepos.index==index&&appstatelist.songinfos.elementAt(index).title==widget.songinfos.elementAt(index).title?Colors.red:Colors.black
),
),
subtitle: Text(
Expand All @@ -59,14 +62,42 @@ class _SongListState extends State<SongList> {

),
),
trailing: IconButton(
icon: Icon(
FlutterIcons.md_more_ion
),
onPressed: (){},
trailing: PopupMenuButton(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
onSelected: (selected){
switch (selected) {
case 0:
SongInfo songInfo = widget.songinfos.elementAt(index);
LoveDb().insertLove(songInfo);
break;
case 2:
LoveDb().deleteLove(widget.songinfos.elementAt(index).id);

}
},
itemBuilder: (context) => [
((){
if(widget.isInLovePlaylist){
return PopupMenuItem(
child: Text("Delete from Liked"),
value: 2,
);
}else{
return PopupMenuItem(
child: Text("Add to Liked"),
value: 0,
);
}
}()),
PopupMenuItem(
child: Text("Play Next"),
value: 1,
),
]
),
onTap: (){
PlayerLogic().playMusic(widget.songinfos.elementAt(index).uri);
appstatelist.songinfos = widget.songinfos;
appstatepos.index = index;
},
);
Expand Down
30 changes: 30 additions & 0 deletions lib/ux/components/loader/futureLoveSongsList.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:Raylex/logic/loveDb.dart';
import 'package:Raylex/logic/models/playerStateNotify.dart';
import 'package:Raylex/logic/models/songInfo.dart';
import 'package:Raylex/ux/components/lists/songList.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class FutureLoveSongList extends StatelessWidget {
@override
Widget build(BuildContext context) {
var appstate = Provider.of<PlayerStateNotify>(context, listen: false);
return FutureBuilder(
future: LoveDb().allLove(),
builder: (context, snap){
if(snap.data!=null){
List<SongInfo> songinfos = snap.data;
if(songinfos.isNotEmpty)
return SongList(songinfos,isInLovePlaylist: true,);
else
return Center(child: Text("Mark heart to have song here"),);
}else{
return Center(
child: CupertinoActivityIndicator(),
);
}
},
);
}
}
1 change: 0 additions & 1 deletion lib/ux/components/loader/futureSongList.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class FutureSongList extends StatelessWidget {
builder: (context, snap){
if(snap.data!=null){
List<SongInfo> list = snap.data;
appstate.songinfos = list;
return list.isNotEmpty?SongList(list):Center(
child: Text("No songs found"),
);
Expand Down
Loading

0 comments on commit 1d9227f

Please sign in to comment.