Equalizer-Fix für Xiaomi/MIUI (Dolby Atmos) + In-App-YouTube-Suche als Extra-Tab
- openSystemPanel(): Xiaomi-Sound-Settings-Intent zuerst, dann Settings.ACTION_SOUND_SETTINGS, dann Android-Standard-Intent als Fallback. Behebt "kein System-Klangeffekte" trotz Dolby Atmos auf MIUI/HyperOS (POCO X7 Pro), wo der Standard-Intent keine Activity findet. - Neuer Tab "YT-Suche": YouTube-Suche über den bestehenden /api/search-Endpunkt des Baka-Proxys, Ergebnisliste mit Thumbnail (YouTube-CDN), Titel, Dauer und Download-Knopf pro Treffer — derselbe Download-Weg wie im bestehenden Download-Tab. 574 Tests grün, flutter analyze ohne Befund, Kotlin kompiliert sauber (gradlew :app:compileDebugKotlin). Xiaomi-Fix konnte nicht auf echter Hardware getestet werden. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VM2JK5mV7AL1g2Rt6H6h9w
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
9e65ddcbb5
commit
f0313724d4
@@ -0,0 +1,121 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/testing.dart';
|
||||
import 'package:melo/downloads/youtube_search_screen.dart';
|
||||
import 'package:melo/library/database.dart';
|
||||
import 'package:melo/library/library_service.dart';
|
||||
import 'package:melo/services/baka_auth.dart';
|
||||
import 'package:melo/services/yt_download_service.dart';
|
||||
import 'package:melo/services/yt_search_service.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class _MemorySpeicher implements TokenSpeicher {
|
||||
final Map<String, String> werte = {};
|
||||
@override
|
||||
Future<String?> lesen(String key) async => werte[key];
|
||||
@override
|
||||
Future<void> schreiben(String key, String wert) async => werte[key] = wert;
|
||||
@override
|
||||
Future<void> loeschen(String key) async => werte.remove(key);
|
||||
}
|
||||
|
||||
Future<BakaAuth> _angemeldeteAuth() async {
|
||||
final auth = BakaAuth(
|
||||
client: MockClient(
|
||||
(_) async => http.Response(jsonEncode({'token': 'jwt-abc'}), 200)),
|
||||
speicher: _MemorySpeicher(),
|
||||
);
|
||||
await auth.anmelden('Baka', 'geheim');
|
||||
return auth;
|
||||
}
|
||||
|
||||
Widget _wrap({
|
||||
required MeloDb db,
|
||||
required BakaAuth auth,
|
||||
required YtSearchService search,
|
||||
required YtDownloadService download,
|
||||
}) {
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
Provider<MeloDb>.value(value: db),
|
||||
ChangeNotifierProvider<LibraryService>.value(value: LibraryService(db)),
|
||||
ChangeNotifierProvider<BakaAuth>.value(value: auth),
|
||||
ChangeNotifierProvider<YtSearchService>.value(value: search),
|
||||
ChangeNotifierProvider<YtDownloadService>.value(value: download),
|
||||
],
|
||||
child: const MaterialApp(home: Scaffold(body: YoutubeSearchScreen())),
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
setUp(() => SharedPreferences.setMockInitialValues({}));
|
||||
|
||||
testWidgets('ohne Anmeldung erscheint der Hinweis auf die Baka-Anmeldung',
|
||||
(tester) async {
|
||||
final db = MeloDb(NativeDatabase.memory());
|
||||
final auth = BakaAuth(
|
||||
client: MockClient((_) async => http.Response('', 500)),
|
||||
speicher: _MemorySpeicher());
|
||||
final search = YtSearchService(auth: auth);
|
||||
final download = YtDownloadService(auth: auth);
|
||||
|
||||
await tester.pumpWidget(_wrap(
|
||||
db: db, auth: auth, search: search, download: download));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.textContaining('Baka-Anmeldung'), findsOneWidget);
|
||||
expect(find.text('Nach Musikvideos suchen'), findsOneWidget);
|
||||
|
||||
await db.close();
|
||||
});
|
||||
|
||||
testWidgets('Suche zeigt Titel und Dauer der Treffer', (tester) async {
|
||||
final db = MeloDb(NativeDatabase.memory());
|
||||
final auth = await _angemeldeteAuth();
|
||||
final search = YtSearchService(
|
||||
auth: auth,
|
||||
client: MockClient((req) async {
|
||||
expect(req.url.queryParameters['q'], 'roses');
|
||||
return http.Response(
|
||||
jsonEncode([
|
||||
{
|
||||
'title': 'Neoni - Roses',
|
||||
'url': 'https://youtu.be/dQw4w9WgXcQ',
|
||||
'duration': 187,
|
||||
},
|
||||
]),
|
||||
200);
|
||||
}),
|
||||
);
|
||||
final download = YtDownloadService(auth: auth);
|
||||
|
||||
await tester.pumpWidget(_wrap(
|
||||
db: db, auth: auth, search: search, download: download));
|
||||
|
||||
await tester.enterText(find.byType(TextField), 'roses');
|
||||
await tester.tap(find.text('Suchen'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Neoni - Roses'), findsOneWidget);
|
||||
expect(find.text('3:07'), findsOneWidget);
|
||||
expect(find.byIcon(Icons.download_for_offline_outlined), findsOneWidget);
|
||||
|
||||
await db.close();
|
||||
});
|
||||
|
||||
// Kein Widget-Test für den Download-Knopf selbst: YtDownloadService.
|
||||
// herunterladen() kombiniert Future.any mit .timeout() — dessen Timer
|
||||
// bleibt unter Flutters fake_async-Testbindung immer als "pending" stehen
|
||||
// (auch ganz ohne dieses Widget reproduzierbar) und lässt den Testlauf
|
||||
// entweder hängen oder an der Pending-Timer-Prüfung scheitern. Aus
|
||||
// demselben Grund hat auch der bestehende Download-Knopf in
|
||||
// _YouTubeBereich (downloads_screen.dart) keinen eigenen Widget-Test —
|
||||
// die Download-Logik selbst ist über yt_download_test.dart ausführlich
|
||||
// abgedeckt.
|
||||
}
|
||||
Reference in New Issue
Block a user