Skip to content

Commit

Permalink
Merge pull request #2 from harikris001:dev
Browse files Browse the repository at this point in the history
version update Ui and backend changes
  • Loading branch information
harikris001 authored Aug 31, 2024
2 parents 9b48799 + 905bb4e commit f8f03c8
Show file tree
Hide file tree
Showing 20 changed files with 310 additions and 13 deletions.
3 changes: 3 additions & 0 deletions jam_it/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,8 @@
<action android:name="android.intent.action.PROCESS_TEXT"/>
<data android:mimeType="text/plain"/>
</intent>
<intent>
<action android:name="android.support.customtabs.action.CustomTabsService" />
</intent>
</queries>
</manifest>
Binary file added jam_it/assets/images/appicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions jam_it/lib/features/home/repositories/home_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,38 @@ class HomeRepository {
}
}

Future<Either<AppFailure, List<SongModel>>> getSearchResults({
required String query,
required String token,
}) async {
try {
final res = await http.get(
Uri.parse('${ServerConstants.serverUrl}/song/search/?query=$query'),
headers: {
'Content-Type': 'application/json',
'x-auth-token': token,
},
);

var resBodyMap = jsonDecode(res.body);
if (res.statusCode != 200) {
resBodyMap = resBodyMap as Map<String, dynamic>;
return Left(AppFailure(message: resBodyMap['detail']));
}

resBodyMap = resBodyMap as List;
List<SongModel> songs = [];

for (final map in resBodyMap) {
songs.add(SongModel.fromMap(map));
}

return Right(songs);
} catch (e) {
return Left(AppFailure(message: e.toString()));
}
}

Future<Either<AppFailure, bool>> favSongs({
required String token,
required String songId,
Expand Down
39 changes: 32 additions & 7 deletions jam_it/lib/features/home/view/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:jam_it/core/providers/current_song_notifier.dart';
import 'package:jam_it/core/theme/app_pallete.dart';
import 'package:jam_it/core/utils/utils.dart';
import 'package:jam_it/features/auth/view/widgets/hero_image.dart';
import 'package:jam_it/features/home/view/pages/library_page.dart';
import 'package:jam_it/features/home/view/pages/search_page.dart';
import 'package:jam_it/features/home/view/pages/songs_page.dart';
import 'package:jam_it/features/home/view/pages/upload_song_page.dart';
import 'package:jam_it/features/home/view/widgets/about_info.dart';
import 'package:jam_it/features/home/view/widgets/music_slab.dart';
import 'package:url_launcher/url_launcher.dart';

class HomePage extends ConsumerStatefulWidget {
const HomePage({super.key});
Expand All @@ -25,6 +28,17 @@ class _HomePageState extends ConsumerState<HomePage> {
SearchPage(),
];

Future<void> _launchGithubRepo() async {
final url = Uri.parse("https://github.com/harikris001/JAM-IT");
if (await canLaunchUrl(url)) {
await launchUrl(url);
} else {
if (context.mounted) {
snackBarPopUp(context, "Unable to open");
}
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -33,7 +47,7 @@ class _HomePageState extends ConsumerState<HomePage> {
children: [
const DrawerHeader(
child: HeroImage(
angle: 1,
angle: 0,
)),
const SizedBox(
height: 20,
Expand All @@ -54,13 +68,24 @@ class _HomePageState extends ConsumerState<HomePage> {
leading: Icon(Icons.settings),
title: Text('Settings'),
),
const ListTile(
leading: Icon(Icons.info),
title: Text('About'),
ListTile(
leading: const Icon(Icons.info),
title: const Text('About'),
onTap: () {
Navigator.of(context).pop();
showDialog(
context: context,
builder: (context) => const AboutInfo(),
);
},
),
const ListTile(
leading: Icon(Icons.web),
title: Text('Support Project on Github'),
ListTile(
leading: const Icon(Icons.web),
title: const Text('Support Project on Github'),
onTap: () async {
Navigator.of(context).pop();
await _launchGithubRepo();
},
),
],
),
Expand Down
2 changes: 2 additions & 0 deletions jam_it/lib/features/home/view/pages/library_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class LibraryPage extends ConsumerWidget {
style: TextStyle(fontSize: 20),
),
ListView.builder(
shrinkWrap: true,
itemCount: data.length,
itemBuilder: (context, index) {
final song = data[index];
Expand All @@ -56,6 +57,7 @@ class LibraryPage extends ConsumerWidget {
);
},
),
const Expanded(child: SizedBox()),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Pallete.borderColor,
Expand Down
9 changes: 7 additions & 2 deletions jam_it/lib/features/home/view/pages/search_page.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:jam_it/features/home/view/widgets/search_list.dart';
import 'package:jam_it/features/home/viewmodel/query_viewmodel.dart';

class SearchPage extends ConsumerWidget {
const SearchPage({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final serachController = TextEditingController();
return Scaffold(
appBar: AppBar(
title: const Text(
"Search",
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w600),
),
centerTitle: true,
),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 14.0),
child: Column(
children: [
TextField(
controller: serachController,
onChanged: (value) =>
ref.read(queryNotifierProvider.notifier).updateQuery(value),
),
const SearchList(),
],
),
),
);
}
}
//
26 changes: 26 additions & 0 deletions jam_it/lib/features/home/view/widgets/about_info.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';

class AboutInfo extends StatelessWidget {
const AboutInfo({super.key});

@override
Widget build(BuildContext context) {
return AboutDialog(
applicationName: "Jam-It!",
applicationIcon: Image.asset(
"assets/images/appicon.png",
height: 80,
width: 80,
),
applicationVersion: "0.1.3",
applicationLegalese: "© Made by Harikrishna.",
children: const [
Text("A Crowd source initiative"),
Text(
"Support the project on GitHub",
style: TextStyle(fontWeight: FontWeight.w300),
)
],
);
}
}
51 changes: 51 additions & 0 deletions jam_it/lib/features/home/view/widgets/search_list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:jam_it/core/providers/current_song_notifier.dart';
import 'package:jam_it/core/theme/app_pallete.dart';
import 'package:jam_it/core/widgets/Loader/loader.dart';
import 'package:jam_it/features/home/viewmodel/home_viewmodel.dart';

class SearchList extends ConsumerWidget {
const SearchList({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
return ref.watch(getSearchResultProvider).when(
data: (data) {
return ListView.builder(
shrinkWrap: true,
itemCount: data.length,
itemBuilder: (context, index) {
final song = data[index];
return ListTile(
onTap: () => ref
.watch(currentSongNotifierProvider.notifier)
.updateSong(song),
leading: CircleAvatar(
backgroundImage: NetworkImage(song.thumbnail_url),
radius: 35,
backgroundColor: Pallete.backgroundColor,
),
title: Text(
song.song_name,
style: const TextStyle(
fontSize: 15, fontWeight: FontWeight.w700),
),
subtitle: Text(
song.artist,
style: const TextStyle(
fontSize: 13, fontWeight: FontWeight.w600),
),
);
},
);
},
error: (error, stackTrace) {
return const Center(
child: Text("Some error occured"),
);
},
loading: () => const Loader(),
);
}
}
15 changes: 15 additions & 0 deletions jam_it/lib/features/home/viewmodel/home_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:jam_it/features/home/model/fav_song_model.dart';
import 'package:jam_it/features/home/model/song_model.dart';
import 'package:jam_it/features/home/repositories/home_local_repository.dart';
import 'package:jam_it/features/home/repositories/home_repository.dart';
import 'package:jam_it/features/home/viewmodel/query_viewmodel.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'home_viewmodel.g.dart';
Expand Down Expand Up @@ -36,6 +37,20 @@ Future<List<SongModel>> getFavSongs(GetFavSongsRef ref) async {
};
}

@riverpod
Future<List<SongModel>> getSearchResult(GetSearchResultRef ref) async {
final token =
ref.watch(currentUserNotifierProvider.select((user) => user!.token));
final query = ref.watch(queryNotifierProvider);
final res = await ref
.watch(homeRepositoryProvider)
.getSearchResults(token: token, query: query);
return switch (res) {
Left(value: final l) => throw l.message,
Right(value: final r) => r,
};
}

@riverpod
class HomeViewModel extends _$HomeViewModel {
late HomeRepository _homeRepository;
Expand Down
16 changes: 16 additions & 0 deletions jam_it/lib/features/home/viewmodel/home_viewmodel.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions jam_it/lib/features/home/viewmodel/query_viewmodel.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'query_viewmodel.g.dart';

@riverpod
class QueryNotifier extends _$QueryNotifier {
@override
String build() {
return "";
}

void updateQuery(String query) {
state = query;
}
}
26 changes: 26 additions & 0 deletions jam_it/lib/features/home/viewmodel/query_viewmodel.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions jam_it/linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
#include "generated_plugin_registrant.h"

#include <isar_flutter_libs/isar_flutter_libs_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) isar_flutter_libs_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "IsarFlutterLibsPlugin");
isar_flutter_libs_plugin_register_with_registrar(isar_flutter_libs_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
}
1 change: 1 addition & 0 deletions jam_it/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
isar_flutter_libs
url_launcher_linux
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
2 changes: 2 additions & 0 deletions jam_it/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import just_audio
import path_provider_foundation
import shared_preferences_foundation
import sqflite
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AudioServicePlugin.register(with: registry.registrar(forPlugin: "AudioServicePlugin"))
Expand All @@ -21,4 +22,5 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}
Loading

0 comments on commit f8f03c8

Please sign in to comment.