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

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" />