fix: error handling

This commit is contained in:
antonio 2023-09-17 22:04:07 +02:00
parent 24747207b8
commit 72bd71dea2
5 changed files with 19 additions and 4 deletions

View file

@ -49,12 +49,14 @@ public class SharingRepository {
public void onResponse(@NonNull Call<ApiResponse> call, @NonNull Response<ApiResponse> response) { public void onResponse(@NonNull Call<ApiResponse> call, @NonNull Response<ApiResponse> response) {
if (response.isSuccessful() && response.body() != null && response.body().getSubsonicResponse().getShares() != null && response.body().getSubsonicResponse().getShares().getShares() != null && response.body().getSubsonicResponse().getShares().getShares().get(0) != null) { if (response.isSuccessful() && response.body() != null && response.body().getSubsonicResponse().getShares() != null && response.body().getSubsonicResponse().getShares().getShares() != null && response.body().getSubsonicResponse().getShares().getShares().get(0) != null) {
share.setValue(response.body().getSubsonicResponse().getShares().getShares().get(0)); share.setValue(response.body().getSubsonicResponse().getShares().getShares().get(0));
} else {
share.setValue(null);
} }
} }
@Override @Override
public void onFailure(@NonNull Call<ApiResponse> call, @NonNull Throwable t) { public void onFailure(@NonNull Call<ApiResponse> call, @NonNull Throwable t) {
share.setValue(null);
} }
}); });

View file

@ -8,6 +8,7 @@ import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.View; import android.view.View;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
@ -107,9 +108,13 @@ public class PlaylistEditorDialog extends DialogFragment {
bind.playlistShareButton.setOnClickListener(view -> { bind.playlistShareButton.setOnClickListener(view -> {
playlistEditorViewModel.sharePlaylist().observe(requireActivity(), sharedPlaylist -> { playlistEditorViewModel.sharePlaylist().observe(requireActivity(), sharedPlaylist -> {
ClipboardManager clipboardManager = (ClipboardManager) requireActivity().getSystemService(Context.CLIPBOARD_SERVICE); if (sharedPlaylist != null) {
ClipData clipData = ClipData.newPlainText(getString(R.string.app_name), sharedPlaylist.getUrl()); ClipboardManager clipboardManager = (ClipboardManager) requireActivity().getSystemService(Context.CLIPBOARD_SERVICE);
clipboardManager.setPrimaryClip(clipData); ClipData clipData = ClipData.newPlainText(getString(R.string.app_name), sharedPlaylist.getUrl());
clipboardManager.setPrimaryClip(clipData);
} else {
Toast.makeText(requireContext(), getString(R.string.share_unsupported_error), Toast.LENGTH_SHORT).show();
}
}); });
}); });

View file

@ -39,6 +39,7 @@ import com.cappielloantonio.tempo.util.Preferences;
import com.cappielloantonio.tempo.viewmodel.AlbumBottomSheetViewModel; import com.cappielloantonio.tempo.viewmodel.AlbumBottomSheetViewModel;
import com.cappielloantonio.tempo.viewmodel.HomeViewModel; import com.cappielloantonio.tempo.viewmodel.HomeViewModel;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment; import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import com.google.android.material.snackbar.Snackbar;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import java.util.ArrayList; import java.util.ArrayList;
@ -198,6 +199,9 @@ public class AlbumBottomSheetDialog extends BottomSheetDialogFragment implements
clipboardManager.setPrimaryClip(clipData); clipboardManager.setPrimaryClip(clipData);
refreshShares(); refreshShares();
dismissBottomSheet(); dismissBottomSheet();
} else {
Toast.makeText(requireContext(), getString(R.string.share_unsupported_error), Toast.LENGTH_SHORT).show();
dismissBottomSheet();
} }
})); }));

View file

@ -216,6 +216,9 @@ public class SongBottomSheetDialog extends BottomSheetDialogFragment implements
clipboardManager.setPrimaryClip(clipData); clipboardManager.setPrimaryClip(clipData);
refreshShares(); refreshShares();
dismissBottomSheet(); dismissBottomSheet();
} else {
Toast.makeText(requireContext(), getString(R.string.share_unsupported_error), Toast.LENGTH_SHORT).show();
dismissBottomSheet();
} }
})); }));

View file

@ -263,6 +263,7 @@
<string name="share_update_dialog_hint_description">Description</string> <string name="share_update_dialog_hint_description">Description</string>
<string name="share_update_dialog_hint_expiration_date">Expiration date</string> <string name="share_update_dialog_hint_expiration_date">Expiration date</string>
<string name="share_update_dialog_title">Share</string> <string name="share_update_dialog_title">Share</string>
<string name="share_unsupported_error">Sharing is not supported or not enabled</string>
<string name="song_bottom_sheet_add_to_playlist">Add to playlist</string> <string name="song_bottom_sheet_add_to_playlist">Add to playlist</string>
<string name="song_bottom_sheet_add_to_queue">Add to queue</string> <string name="song_bottom_sheet_add_to_queue">Add to queue</string>
<string name="song_bottom_sheet_download">Download</string> <string name="song_bottom_sheet_download">Download</string>