1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-08 14:18:08 +02:00

Music Files (WIP)

This commit is contained in:
José Rebelo 2023-08-21 21:46:56 +01:00
parent ff2ba22287
commit 51f23a30ea
7 changed files with 130 additions and 0 deletions

View File

@ -577,6 +577,10 @@
android:name=".activities.ConfigureWorldClocks"
android:label="@string/pref_world_clocks_title"
android:parentActivityName=".activities.ControlCenterv2" />
<activity
android:name=".activities.MusicFilesActivity"
android:label="@string/menuitem_music"
android:parentActivityName=".activities.ControlCenterv2" />
<activity
android:name=".activities.devicesettings.DeviceSettingsActivity"
android:label="@string/title_activity_device_specific_settings"

View File

@ -0,0 +1,76 @@
/* Copyright (C) 2023 José Rebelo
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.activities;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
public class MusicFilesActivity extends AbstractGBActivity {
private static final Logger LOG = LoggerFactory.getLogger(MusicFilesActivity.class);
private GBDevice gbDevice;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gbDevice = getIntent().getParcelableExtra(GBDevice.EXTRA_DEVICE);
setContentView(R.layout.activity_music_files);
final ActivityResultLauncher<String> activityResultLauncher = this.registerForActivityResult(
new ActivityResultContracts.GetMultipleContents(),
urilist -> LOG.info("got {}", urilist)
);
final FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(v -> {
final Intent intent = new Intent();
intent.setType("audio/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
activityResultLauncher.launch("audio/*");
});
}
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// back button
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}

View File

@ -226,6 +226,7 @@ public class DeviceSettingsPreferenceConst {
public static final String PREF_WORLD_CLOCKS = "pref_world_clocks";
public static final String PREF_CONTACTS = "pref_contacts";
public static final String PREF_MUSIC_FILES = "pref_music_files";
public static final String PREF_ANTILOST_ENABLED = "pref_antilost_enabled";
public static final String PREF_HYDRATION_SWITCH = "pref_hydration_switch";

View File

@ -41,6 +41,7 @@ import nodomain.freeyourgadget.gadgetbridge.activities.CalBlacklistActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.ConfigureContacts;
import nodomain.freeyourgadget.gadgetbridge.activities.ConfigureWorldClocks;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractPreferenceFragment;
import nodomain.freeyourgadget.gadgetbridge.activities.MusicFilesActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.loyaltycards.LoyaltyCardsSettingsActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.loyaltycards.LoyaltyCardsSettingsConst;
import nodomain.freeyourgadget.gadgetbridge.capabilities.HeartRateCapability;
@ -740,6 +741,16 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
});
}
final Preference musicFiles = findPreference(PREF_MUSIC_FILES);
if (musicFiles != null) {
musicFiles.setOnPreferenceClickListener(preference -> {
final Intent intent = new Intent(getContext(), MusicFilesActivity.class);
intent.putExtra(GBDevice.EXTRA_DEVICE, device);
startActivity(intent);
return true;
});
}
final Preference calendarBlacklist = findPreference("blacklist_calendars");
if (calendarBlacklist != null) {
calendarBlacklist.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

View File

@ -283,6 +283,9 @@ public abstract class Huami2021Coordinator extends HuamiCoordinator {
// TODO: These should go somewhere else
//
settings.add(R.xml.devicesettings_header_apps);
if (supportsWifiHotspot(device) && supportsFtpServer(device)) {
settings.add(R.xml.devicesettings_music_files);
}
if (ZeppOsLoyaltyCardService.isSupported(getPrefs(device))) {
settings.add(R.xml.devicesettings_loyalty_cards);
}

View File

@ -0,0 +1,27 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fitsSystemWindows="true"
tools:context="nodomain.freeyourgadget.gadgetbridge.activities.MusicFilesActivity">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:divider="@null"
android:id="@+id/files_list" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_gravity="bottom|end"
app:srcCompat="@drawable/ic_file_upload"
android:layout_margin="16dp" />
</RelativeLayout>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<Preference
android:icon="@drawable/ic_music_note"
android:key="pref_music_files"
android:summary="Copy music files to the watch"
android:title="Music" />
</androidx.preference.PreferenceScreen>