Check bind object existence in SyncFragment

This commit is contained in:
CappielloAntonio 2021-05-02 12:36:30 +02:00
parent 8b73e99311
commit e7f43d158c
3 changed files with 127 additions and 93 deletions

View file

@ -68,7 +68,7 @@ public class LoginFragment extends Fragment {
} }
if (TextUtils.isEmpty(server)) { if (TextUtils.isEmpty(server)) {
Toast.makeText(requireContext(), "Empty server", Toast.LENGTH_SHORT).show(); Toast.makeText(requireContext(), "Empty server url", Toast.LENGTH_SHORT).show();
return false; return false;
} }

View file

@ -380,115 +380,148 @@ public class SyncFragment extends Fragment {
switch (sector) { switch (sector) {
case LIBRARIES: case LIBRARIES:
if (isSuccess) { if (isSuccess) {
if (bind != null) {
bind.syncLibrariesStatusLabel.setText("Status: SUCCESS"); bind.syncLibrariesStatusLabel.setText("Status: SUCCESS");
bind.syncLibrariesDetailLabel.setVisibility(View.GONE); bind.syncLibrariesDetailLabel.setVisibility(View.GONE);
bind.syncLibrariesRetryImageView.setVisibility(View.GONE); bind.syncLibrariesRetryImageView.setVisibility(View.GONE);
}
syncNextSector(LIBRARIES); syncNextSector(LIBRARIES);
} else { } else {
if (bind != null) {
bind.syncLibrariesStatusLabel.setText("Status: ERROR"); bind.syncLibrariesStatusLabel.setText("Status: ERROR");
bind.syncLibrariesDetailLabel.setText(message); bind.syncLibrariesDetailLabel.setText(message);
bind.syncLibrariesDetailLabel.setVisibility(View.VISIBLE); bind.syncLibrariesDetailLabel.setVisibility(View.VISIBLE);
bind.syncLibrariesRetryImageView.setVisibility(View.VISIBLE); bind.syncLibrariesRetryImageView.setVisibility(View.VISIBLE);
} }
}
break; break;
case ALBUMS: case ALBUMS:
if (isSuccess) { if (isSuccess) {
if (bind != null) {
bind.syncAlbumsStatusLabel.setText("Status: SUCCESS"); bind.syncAlbumsStatusLabel.setText("Status: SUCCESS");
bind.syncAlbumsDetailLabel.setText(message); bind.syncAlbumsDetailLabel.setText(message);
bind.syncAlbumsRetryImageView.setVisibility(View.GONE); bind.syncAlbumsRetryImageView.setVisibility(View.GONE);
}
syncViewModel.increaseProggress(); syncViewModel.increaseProggress();
checkStep(); checkStep();
syncNextSector(ALBUMS); syncNextSector(ALBUMS);
} else { } else {
if (bind != null) {
bind.syncLibrariesStatusLabel.setText("Status: ERROR"); bind.syncLibrariesStatusLabel.setText("Status: ERROR");
bind.syncAlbumsDetailLabel.setText(message); bind.syncAlbumsDetailLabel.setText(message);
bind.syncAlbumsRetryImageView.setVisibility(View.VISIBLE); bind.syncAlbumsRetryImageView.setVisibility(View.VISIBLE);
} }
}
break; break;
case ARTISTS: case ARTISTS:
if (isSuccess) { if (isSuccess) {
if (bind != null) {
bind.syncArtistsStatusLabel.setText("Status: SUCCESS"); bind.syncArtistsStatusLabel.setText("Status: SUCCESS");
bind.syncArtistsDetailLabel.setText(message); bind.syncArtistsDetailLabel.setText(message);
bind.syncArtistsRetryImageView.setVisibility(View.GONE); bind.syncArtistsRetryImageView.setVisibility(View.GONE);
}
syncViewModel.increaseProggress(); syncViewModel.increaseProggress();
checkStep(); checkStep();
syncNextSector(ARTISTS); syncNextSector(ARTISTS);
} else { } else {
if (bind != null) {
bind.syncArtistsStatusLabel.setText("Status: ERROR"); bind.syncArtistsStatusLabel.setText("Status: ERROR");
bind.syncArtistsDetailLabel.setText(message); bind.syncArtistsDetailLabel.setText(message);
bind.syncArtistsRetryImageView.setVisibility(View.VISIBLE); bind.syncArtistsRetryImageView.setVisibility(View.VISIBLE);
} }
}
break; break;
case GENRES: case GENRES:
if (isSuccess) { if (isSuccess) {
if (bind != null) {
bind.syncGenresStatusLabel.setText("Status: SUCCESS"); bind.syncGenresStatusLabel.setText("Status: SUCCESS");
bind.syncGenresDetailLabel.setText(message); bind.syncGenresDetailLabel.setText(message);
bind.syncGenresRetryImageView.setVisibility(View.GONE); bind.syncGenresRetryImageView.setVisibility(View.GONE);
}
syncViewModel.increaseProggress(); syncViewModel.increaseProggress();
checkStep(); checkStep();
syncNextSector(GENRES); syncNextSector(GENRES);
} else { } else {
if (bind != null) {
bind.syncGenresStatusLabel.setText("Status: ERROR"); bind.syncGenresStatusLabel.setText("Status: ERROR");
bind.syncGenresDetailLabel.setText(message); bind.syncGenresDetailLabel.setText(message);
bind.syncGenresRetryImageView.setVisibility(View.VISIBLE); bind.syncGenresRetryImageView.setVisibility(View.VISIBLE);
} }
}
break; break;
case PLAYLISTS: case PLAYLISTS:
if (isSuccess) { if (isSuccess) {
if (bind != null) {
bind.syncPlaylistsStatusLabel.setText("Status: SUCCESS"); bind.syncPlaylistsStatusLabel.setText("Status: SUCCESS");
bind.syncPlaylistsDetailLabel.setText(message); bind.syncPlaylistsDetailLabel.setText(message);
bind.syncPlaylistsRetryImageView.setVisibility(View.GONE); bind.syncPlaylistsRetryImageView.setVisibility(View.GONE);
}
syncViewModel.increaseProggress(); syncViewModel.increaseProggress();
checkStep(); checkStep();
syncNextSector(PLAYLISTS); syncNextSector(PLAYLISTS);
} else { } else {
if (bind != null) {
bind.syncPlaylistsStatusLabel.setText("Status: ERROR"); bind.syncPlaylistsStatusLabel.setText("Status: ERROR");
bind.syncPlaylistsDetailLabel.setText(message); bind.syncPlaylistsDetailLabel.setText(message);
bind.syncPlaylistsRetryImageView.setVisibility(View.VISIBLE); bind.syncPlaylistsRetryImageView.setVisibility(View.VISIBLE);
} }
}
break; break;
case SONGS: case SONGS:
if (isSuccess) { if (isSuccess) {
if (bind != null) {
bind.syncSongsStatusLabel.setText("Status: SUCCESS"); bind.syncSongsStatusLabel.setText("Status: SUCCESS");
bind.syncSongsDetailLabel.setText(message); bind.syncSongsDetailLabel.setText(message);
bind.syncSongsRetryImageView.setVisibility(View.GONE); bind.syncSongsRetryImageView.setVisibility(View.GONE);
}
syncViewModel.increaseProggress(); syncViewModel.increaseProggress();
checkStep(); checkStep();
syncNextSector(SONGS); syncNextSector(SONGS);
} else { } else {
if (bind != null) {
bind.syncSongsStatusLabel.setText("Status: ERROR"); bind.syncSongsStatusLabel.setText("Status: ERROR");
bind.syncSongsDetailLabel.setText(message); bind.syncSongsDetailLabel.setText(message);
bind.syncSongsRetryImageView.setVisibility(View.VISIBLE); bind.syncSongsRetryImageView.setVisibility(View.VISIBLE);
} }
}
break; break;
case SONG_X_GENRE: case SONG_X_GENRE:
if (isSuccess) { if (isSuccess) {
if (bind != null) {
bind.syncSongXGenreStatusLabel.setText("Status: SUCCESS"); bind.syncSongXGenreStatusLabel.setText("Status: SUCCESS");
bind.syncSongXGenreDetailLabel.setText(message); bind.syncSongXGenreDetailLabel.setText(message);
bind.syncSongXGenreRetryImageView.setVisibility(View.GONE); bind.syncSongXGenreRetryImageView.setVisibility(View.GONE);
}
checkStep(); checkStep();
} else { } else {
if (bind != null) {
bind.syncSongXGenreStatusLabel.setText("Status: ERROR"); bind.syncSongXGenreStatusLabel.setText("Status: ERROR");
bind.syncSongXGenreDetailLabel.setText(message); bind.syncSongXGenreDetailLabel.setText(message);
bind.syncSongXGenreRetryImageView.setVisibility(View.VISIBLE); bind.syncSongXGenreRetryImageView.setVisibility(View.VISIBLE);
} }
}
break; break;
case SONG_X_PLAYLIST: case SONG_X_PLAYLIST:
if (isSuccess) { if (isSuccess) {
if (bind != null) {
bind.syncSongXPlaylistStatusLabel.setText("Status: SUCCESS"); bind.syncSongXPlaylistStatusLabel.setText("Status: SUCCESS");
bind.syncSongXPlaylistDetailLabel.setText(message); bind.syncSongXPlaylistDetailLabel.setText(message);
bind.syncSongXPlaylistRetryImageView.setVisibility(View.GONE); bind.syncSongXPlaylistRetryImageView.setVisibility(View.GONE);
}
checkStep(); checkStep();
} else { } else {
if (bind != null) {
bind.syncSongXPlaylistStatusLabel.setText("Status: ERROR"); bind.syncSongXPlaylistStatusLabel.setText("Status: ERROR");
bind.syncSongXPlaylistDetailLabel.setText(message); bind.syncSongXPlaylistDetailLabel.setText(message);
bind.syncSongXPlaylistRetryImageView.setVisibility(View.VISIBLE); bind.syncSongXPlaylistRetryImageView.setVisibility(View.VISIBLE);
} }
}
break; break;
} }
} }
private void resetSectorInfo(int sector) { private void resetSectorInfo(int sector) {
if (bind != null) {
switch (sector) { switch (sector) {
case LIBRARIES: case LIBRARIES:
bind.syncLibrariesStatusLabel.setText("Loading..."); bind.syncLibrariesStatusLabel.setText("Loading...");
@ -533,6 +566,7 @@ public class SyncFragment extends Fragment {
break; break;
} }
} }
}
private void syncNextSector(int sector) { private void syncNextSector(int sector) {
switch (sector) { switch (sector) {

View file

@ -83,7 +83,7 @@
android:id="@+id/server_text_view" android:id="@+id/server_text_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="Server" android:hint="Server URL"
android:inputType="textNoSuggestions" android:inputType="textNoSuggestions"
android:text="http://192.168.1.81:8096" /> android:text="http://192.168.1.81:8096" />