Added sync settings in preferences

This commit is contained in:
CappielloAntonio 2021-04-15 10:37:08 +02:00
parent 26ba9467f1
commit a68f45e7dc
8 changed files with 114 additions and 35 deletions

View file

@ -226,6 +226,13 @@ public class MainActivity extends BaseActivity {
} }
} }
public void goFromSettingsToSync(Bundle bundle) {
setBottomNavigationBarVisibility(false);
setBottomSheetVisibility(false);
navController.navigate(R.id.action_settingsFragment_to_syncFragment, bundle);
}
public void goToHome() { public void goToHome() {
bottomNavigationView.setVisibility(View.VISIBLE); bottomNavigationView.setVisibility(View.VISIBLE);

View file

@ -98,19 +98,6 @@ public class HomeFragment extends Fragment {
bundle.putString(Song.IS_FAVORITE, Song.IS_FAVORITE); bundle.putString(Song.IS_FAVORITE, Song.IS_FAVORITE);
activity.navController.navigate(R.id.action_homeFragment_to_songListPageFragment, bundle); activity.navController.navigate(R.id.action_homeFragment_to_songListPageFragment, bundle);
}); });
bind.syncMusicButton.setOnClickListener(v -> {
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
builder.setMessage("Force reload your entire music library")
.setTitle("Force sync")
.setNegativeButton(R.string.ignore, null)
.setPositiveButton("Sync", (dialog, id) -> {
PreferenceUtil.getInstance(requireContext()).setSync(false);
PreferenceUtil.getInstance(requireContext()).setSongGenreSync(false);
activity.goToSync();
})
.show();
});
} }
private void initDiscoverSongSlideView() { private void initDiscoverSongSlideView() {

View file

@ -122,12 +122,8 @@ public class LibraryFragment extends Fragment {
builder.setMessage("Sync song's genres otherwise nothing will be shown in each genre category") builder.setMessage("Sync song's genres otherwise nothing will be shown in each genre category")
.setTitle("Song's genres not synchronized") .setTitle("Song's genres not synchronized")
.setNegativeButton(R.string.ignore, null) .setNegativeButton(R.string.ignore, null)
.setPositiveButton("Sync", (dialog, id) -> syncSongsPerGenre()) .setPositiveButton("Sync", (dialog, id) -> activity.goToSync())
.show(); .show();
} }
} }
private void syncSongsPerGenre() {
activity.goToSync();
}
} }

View file

@ -1,16 +1,35 @@
package com.cappielloantonio.play.ui.fragment; package com.cappielloantonio.play.ui.fragment;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.preference.ListPreference; import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceFragmentCompat;
import com.cappielloantonio.play.R; import com.cappielloantonio.play.R;
import com.cappielloantonio.play.helper.ThemeHelper; import com.cappielloantonio.play.helper.ThemeHelper;
import com.cappielloantonio.play.ui.activities.MainActivity;
import com.cappielloantonio.play.util.PreferenceUtil;
import com.cappielloantonio.play.util.SyncUtil;
public class SettingsFragment extends PreferenceFragmentCompat { public class SettingsFragment extends PreferenceFragmentCompat {
private static final String TAG = "SettingsFragment"; private static final String TAG = "SettingsFragment";
private MainActivity activity;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) getActivity();
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override @Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.global_preferences, rootKey); setPreferencesFromResource(R.xml.global_preferences, rootKey);
@ -24,5 +43,37 @@ public class SettingsFragment extends PreferenceFragmentCompat {
return true; return true;
}); });
} }
Preference music_sync_button = findPreference(getString(R.string.music_sync));
music_sync_button.setOnPreferenceClickListener(preference -> {
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
builder.setMessage("Force reload your entire music library")
.setTitle("Force sync")
.setNegativeButton(R.string.ignore, null)
.setPositiveButton("Sync", (dialog, id) -> {
PreferenceUtil.getInstance(requireContext()).setSync(false);
PreferenceUtil.getInstance(requireContext()).setSongGenreSync(false);
Bundle bundle = SyncUtil.getSyncBundle(true, true, true, true, true, false);
activity.goFromSettingsToSync(bundle);
})
.show();
return true;
});
Preference cross_sync_button = findPreference(getString(R.string.genres_music_cross_sync));
cross_sync_button.setOnPreferenceClickListener(preference -> {
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
builder.setMessage("Sync song's genres otherwise nothing will be shown in each genre category")
.setTitle("Song's genres not synchronized")
.setNegativeButton(R.string.ignore, null)
.setPositiveButton("Sync", (dialog, id) -> {
Bundle bundle = SyncUtil.getSyncBundle(false, false, true, false, false, true);
activity.goFromSettingsToSync(bundle);
})
.show();
return true;
});
} }
} }

View file

@ -293,21 +293,6 @@
android:paddingEnd="8dp" android:paddingEnd="8dp"
android:paddingBottom="8dp" /> android:paddingBottom="8dp" />
</LinearLayout> </LinearLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/sync_music_button"
style="@style/Widget.MaterialComponents.Button.TextButton.Icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="8dp"
android:paddingTop="8dp"
android:paddingEnd="8dp"
android:layout_gravity="center"
android:textColor="@color/titleTextColor"
android:textAllCaps="false"
app:iconTint="@color/titleTextColor"
android:text="@string/action_sync_music"
app:icon="@drawable/ic_downloading" />
</LinearLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>

View file

@ -111,7 +111,13 @@
android:id="@+id/settingsFragment" android:id="@+id/settingsFragment"
android:name="com.cappielloantonio.play.ui.fragment.SettingsFragment" android:name="com.cappielloantonio.play.ui.fragment.SettingsFragment"
android:label="SettingsFragment" android:label="SettingsFragment"
tools:layout="@layout/fragment_settings"/> tools:layout="@layout/fragment_settings">
<action
android:id="@+id/action_settingsFragment_to_syncFragment"
app:destination="@id/syncFragment"
app:popUpTo="@id/settingsFragment"
app:popUpToInclusive="true" />
</fragment>
<fragment <fragment
android:id="@+id/searchFragment" android:id="@+id/searchFragment"
android:name="com.cappielloantonio.play.ui.fragment.SearchFragment" android:name="com.cappielloantonio.play.ui.fragment.SearchFragment"

View file

@ -24,6 +24,19 @@
<string name="label_placeholder">--</string> <string name="label_placeholder">--</string>
<string name="save_filters">Save filters between sessions</string> <string name="save_filters">Save filters between sessions</string>
<string name="sync_header">Synchronization</string>
<string name="music_sync">Music sync</string>
<string name="music_sync_caption">Sync tracks, albums, artists, genres and playlists</string>
<string name="genres_music_cross_sync">Genres-music cross sync</string>
<string name="genres_music_cross_sync_caption">Cross sync genres for each track</string>
<string name="about_header">About</string>
<string name="summary_about">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</string>
<string name="app_version">1.1</string>
<string name="title_version">Version</string>
<string name="github_page">Github</string>
<string name="development">Follow the development</string>
<string name="github_url">https://github.com/CappielloAntonio/Play</string>
<string name="battery_optimizations_title">Battery Optimizations</string> <string name="battery_optimizations_title">Battery Optimizations</string>
<string name="battery_optimizations_message">Please disable battery optimizations for media playback while the screen is off.</string> <string name="battery_optimizations_message">Please disable battery optimizations for media playback while the screen is off.</string>

View file

@ -1,4 +1,5 @@
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"> <PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory app:title="@string/general_header"> <PreferenceCategory app:title="@string/general_header">
<ListPreference <ListPreference
app:defaultValue="400000000" app:defaultValue="400000000"
@ -27,4 +28,37 @@
app:title="@string/save_filters" app:title="@string/save_filters"
app:useSimpleSummaryProvider="true" /> app:useSimpleSummaryProvider="true" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory app:title="@string/sync_header">
<Preference
android:title="@string/music_sync"
android:key="@string/music_sync"
android:summary="@string/music_sync_caption" />
<Preference
android:title="@string/genres_music_cross_sync"
android:key="@string/genres_music_cross_sync"
android:summary="@string/genres_music_cross_sync_caption" />
</PreferenceCategory>
<PreferenceCategory app:title="@string/about_header">
<Preference
app:selectable="false"
app:summary="@string/summary_about" />
<Preference
app:title="@string/title_version"
app:summary="@string/app_version" />
<!-- preference opens url in browser -->
<Preference
app:title="@string/github_page"
app:summary="@string/development">
<intent
android:action="android.intent.action.VIEW"
android:data="@string/github_url" />
</Preference>
</PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>