Skip to content

Commit

Permalink
Add custom download location button in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwinkey04 committed Jan 24, 2022
1 parent 3ab02a5 commit fe2cd8b
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 76 deletions.
8 changes: 6 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ class _MyAppState extends State<MyApp> {
playerProvider.setUpAudio();
}

void initSettings() async => settingsProvider.darkTheme =
await settingsProvider.sharedPreference.getBool(Preferences.THEME_STATUS);
void initSettings() async {
settingsProvider.darkTheme = await settingsProvider.sharedPreference
.getBool(Preferences.THEME_STATUS);
settingsProvider.downloadPath = await settingsProvider.sharedPreference
.getString(Preferences.DOWNLOAD_PATH);
}

@override
Widget build(BuildContext context) {
Expand Down
2 changes: 1 addition & 1 deletion lib/model/SharedPreferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SharedPreferences prefs;

class Preferences {
static const THEME_STATUS = 'THEME_STATUS';
static const DB_POPULATED = 'DB_POPULATED';
static const DOWNLOAD_PATH = 'DOWNLOAD_PATH';
static const ON_BOARDING_DONE = 'ON_BOARDING_DONE';

void setBool(String key, bool value) async {
Expand Down
18 changes: 16 additions & 2 deletions lib/provider/settings_provider.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import 'package:flutter/material.dart';
import 'package:raag/model/SharedPreferences.dart';
import 'package:raag/model/strings.dart';

class SettingsProvider extends ChangeNotifier{
class SettingsProvider extends ChangeNotifier {
Preferences sharedPreference = Preferences();
bool _darkTheme = false;
bool _refreshComplete = false;
String _downloadPath;

bool get darkTheme => _darkTheme;
bool get refreshComplete => _refreshComplete;
String get downloadPath {
if (_downloadPath == null || _downloadPath.isEmpty) {
return "/storage/emulated/0/Music/$appName";
} else
return _downloadPath;
}

set downloadPath(String value) {
_downloadPath = value;
sharedPreference.setString(Preferences.DOWNLOAD_PATH, value);
notifyListeners();
}

set darkTheme(bool value) {
_darkTheme = value;
Expand All @@ -24,4 +38,4 @@ class SettingsProvider extends ChangeNotifier{
_refreshComplete = value;
notifyListeners();
}
}
}
12 changes: 8 additions & 4 deletions lib/view/download_music.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class _DownloadMusicState extends State<DownloadMusic> {
// Preferences sharedPreference = Preferences();
final DBProvider dbProvider =
Provider.of<DBProvider>(context, listen: false);
final settingsProvider =
Provider.of<SettingsProvider>(context, listen: false);

if (await connectivity.isConnected() == false) {
Alert(
context: context,
Expand Down Expand Up @@ -119,8 +122,7 @@ class _DownloadMusicState extends State<DownloadMusic> {
Directory _raagDownloadsDirectory;

if (Platform.isAndroid) {
_raagDownloadsDirectory =
Directory('/storage/emulated/0/Music/$appName');
_raagDownloadsDirectory = Directory(settingsProvider.downloadPath);
} else
_raagDownloadsDirectory = await getExternalStorageDirectory();

Expand Down Expand Up @@ -252,6 +254,7 @@ class _DownloadMusicState extends State<DownloadMusic> {
),
body: Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
Expand Down Expand Up @@ -306,8 +309,9 @@ class _DownloadMusicState extends State<DownloadMusic> {
FlutterClipboard.paste().then((url) {
if (isValidYouTubeURL(url)) {
urlFieldController.text = url;
urlFieldController.selection = TextSelection.fromPosition(
TextPosition(offset: urlFieldController.text.length));
urlFieldController.selection =
TextSelection.fromPosition(TextPosition(
offset: urlFieldController.text.length));
} else {
Fluttertoast.showToast(msg: clipBoardYT);
}
Expand Down
5 changes: 4 additions & 1 deletion lib/view/settings.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:raag/provider/settings_provider.dart';
import 'package:raag/widgets/download_location_button.dart';
import 'package:raag/widgets/theme_button.dart';
import 'package:raag/model/strings.dart';

Expand Down Expand Up @@ -37,7 +40,7 @@ class Settings extends StatelessWidget {
delegate: SliverChildListDelegate([
SizedBox(height: screenHeight * 0.05),
ThemeButton(),
// RefreshButton(),
Platform.isAndroid ? DownloadLocationButton() : SizedBox(),
]),
)
],
Expand Down
52 changes: 52 additions & 0 deletions lib/widgets/download_location_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:raag/model/strings.dart';
import 'package:raag/provider/settings_provider.dart';

class DownloadLocationButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width;
final provider = Provider.of<SettingsProvider>(context);

return Card(
elevation: 3,
child: InkWell(
onTap: () async {
String selectedDirectory =
await FilePicker.platform.getDirectoryPath();

if (selectedDirectory != null) {
provider.downloadPath = selectedDirectory;
}
},
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(mainAxisAlignment: MainAxisAlignment.start, children: [
Container(
padding: EdgeInsets.all(8.0),
child: Icon(
Icons.folder_open,
size: screenWidth * 0.08,
color: Theme.of(context).colorScheme.secondary,
)),
SizedBox(
width: screenWidth * 0.04,
),
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text(
downloadedLocation,
style: Theme.of(context).textTheme.headline3,
),
Text(
provider.downloadPath,
style: Theme.of(context).textTheme.subtitle2,
),
])
]),
),
),
);
}
}
66 changes: 0 additions & 66 deletions lib/widgets/refresh_button.dart

This file was deleted.

14 changes: 14 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.2"
file_picker:
dependency: "direct main"
description:
name: file_picker
url: "https://pub.dartlang.org"
source: hosted
version: "4.3.2"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -202,6 +209,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.2"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
name: flutter_plugin_android_lifecycle
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies:
clipboard: ^0.1.2+8
connectivity: ^3.0.6
cupertino_icons: ^1.0.0
file_picker: ^4.3.2
flutter:
sdk: flutter
fluttertoast: ^8.0.8
Expand Down

0 comments on commit fe2cd8b

Please sign in to comment.