Address non-final resource IDs warnings

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta 2026-02-04 16:36:12 +08:00
parent feb442492b
commit 5b009453f2
9 changed files with 357 additions and 395 deletions

View File

@ -309,24 +309,20 @@ public class MainActivity extends AppCompatActivity {
}
private boolean drawerItemSelected(final MenuItem item) {
switch (item.getGroupId()) {
case R.id.menu_services_group:
final int groupId = item.getGroupId();
if (groupId == R.id.menu_services_group) {
changeService(item);
break;
case R.id.menu_tabs_group:
} else if (groupId == R.id.menu_tabs_group) {
tabSelected(item);
break;
case R.id.menu_kiosks_group:
} else if (groupId == R.id.menu_kiosks_group) {
try {
kioskSelected(item);
} catch (final Exception e) {
ErrorUtil.showUiErrorSnackbar(this, "Selecting drawer kiosk", e);
}
break;
case R.id.menu_options_about_group:
} else if (groupId == R.id.menu_options_about_group) {
optionsAboutSelected(item);
break;
default:
} else {
return false;
}

View File

@ -41,18 +41,18 @@ public final class QueueItemMenuUtil {
}
popupMenu.setOnMenuItemClickListener(menuItem -> {
switch (menuItem.getItemId()) {
case R.id.menu_item_remove:
final int itemId = menuItem.getItemId();
if (itemId == R.id.menu_item_remove) {
final int index = playQueue.indexOf(item);
playQueue.remove(index);
return true;
case R.id.menu_item_details:
} else if (itemId == R.id.menu_item_details) {
// playQueue is null since we don't want any queue change
NavigationHelper.openVideoDetail(context, item.getServiceId(),
item.getUrl(), item.getTitle(), null,
false);
return true;
case R.id.menu_item_append_playlist:
} else if (itemId == R.id.menu_item_append_playlist) {
PlaylistDialog.createCorrespondingDialog(
context,
List.of(new StreamEntity(item)),
@ -63,7 +63,7 @@ public final class QueueItemMenuUtil {
);
return true;
case R.id.menu_item_channel_details:
} else if (itemId == R.id.menu_item_channel_details) {
SparseItemUtil.fetchUploaderUrlIfSparse(context, item.getServiceId(),
item.getUrl(), item.getUploaderUrl(),
// An intent must be used here.
@ -73,11 +73,11 @@ public final class QueueItemMenuUtil {
context, item.getServiceId(), uploaderUrl, item.getUploader()
));
return true;
case R.id.menu_item_share:
} else if (itemId == R.id.menu_item_share) {
shareText(context, item.getTitle(), item.getUrl(),
item.getThumbnails());
return true;
case R.id.menu_item_download:
} else if (itemId == R.id.menu_item_download) {
fetchStreamInfoAndSaveToDatabase(context, item.getServiceId(), item.getUrl(),
info -> {
final DownloadDialog downloadDialog = new DownloadDialog(context,

View File

@ -558,17 +558,13 @@ public class DownloadDialog extends DialogFragment
}
boolean flag = true;
switch (checkedId) {
case R.id.audio_button:
if (checkedId == R.id.audio_button) {
setupAudioSpinner();
break;
case R.id.video_button:
} else if (checkedId == R.id.video_button) {
setupVideoSpinner();
break;
case R.id.subtitle_button:
} else if (checkedId == R.id.subtitle_button) {
setupSubtitleSpinner();
flag = false;
break;
}
dialogBinding.threads.setEnabled(flag);
@ -585,28 +581,25 @@ public class DownloadDialog extends DialogFragment
+ "position = [" + position + "], id = [" + id + "]");
}
switch (parent.getId()) {
case R.id.quality_spinner:
switch (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()) {
case R.id.video_button:
final int parentId = parent.getId();
if (parentId == R.id.quality_spinner) {
final int checkedRadioButtonId = dialogBinding.videoAudioGroup
.getCheckedRadioButtonId();
if (checkedRadioButtonId == R.id.video_button) {
selectedVideoIndex = position;
onVideoStreamSelected();
break;
case R.id.subtitle_button:
} else if (checkedRadioButtonId == R.id.subtitle_button) {
selectedSubtitleIndex = position;
break;
}
onItemSelectedSetFileName();
break;
case R.id.audio_track_spinner:
} else if (parentId == R.id.audio_track_spinner) {
final boolean trackChanged = selectedAudioTrackIndex != position;
selectedAudioTrackIndex = position;
if (trackChanged) {
updateSecondaryStreams();
fetchStreamsSize();
}
break;
case R.id.audio_stream_spinner:
} else if (parentId == R.id.audio_stream_spinner) {
selectedAudioIndex = position;
}
}
@ -622,23 +615,20 @@ public class DownloadDialog extends DialogFragment
|| prevFileName.startsWith(getString(R.string.caption_file_name, fileName, ""))) {
// only update the file name field if it was not edited by the user
switch (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()) {
case R.id.audio_button:
case R.id.video_button:
final int radioButtonId = dialogBinding.videoAudioGroup
.getCheckedRadioButtonId();
if (radioButtonId == R.id.audio_button || radioButtonId == R.id.video_button) {
if (!prevFileName.equals(fileName)) {
// since the user might have switched between audio and video, the correct
// text might already be in place, so avoid resetting the cursor position
dialogBinding.fileName.setText(fileName);
}
break;
case R.id.subtitle_button:
} else if (radioButtonId == R.id.subtitle_button) {
final String setSubtitleLanguageCode = subtitleStreamsAdapter
.getItem(selectedSubtitleIndex).getLanguageTag();
// this will reset the cursor position, which is bad UX, but it can't be avoided
dialogBinding.fileName.setText(getString(
R.string.caption_file_name, fileName, setSubtitleLanguageCode));
break;
}
}
}
@ -770,8 +760,8 @@ public class DownloadDialog extends DialogFragment
filenameTmp = getNameEditText().concat(".");
switch (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()) {
case R.id.audio_button:
final int checkedRadioButtonId = dialogBinding.videoAudioGroup.getCheckedRadioButtonId();
if (checkedRadioButtonId == R.id.audio_button) {
selectedMediaType = getString(R.string.last_download_type_audio_key);
mainStorage = mainStorageAudio;
format = audioStreamsAdapter.getItem(selectedAudioIndex).getFormat();
@ -783,8 +773,7 @@ public class DownloadDialog extends DialogFragment
mimeTmp = format.mimeType;
filenameTmp += format.getSuffix();
}
break;
case R.id.video_button:
} else if (checkedRadioButtonId == R.id.video_button) {
selectedMediaType = getString(R.string.last_download_type_video_key);
mainStorage = mainStorageVideo;
format = videoStreamsAdapter.getItem(selectedVideoIndex).getFormat();
@ -793,8 +782,7 @@ public class DownloadDialog extends DialogFragment
mimeTmp = format.mimeType;
filenameTmp += format.getSuffix();
}
break;
case R.id.subtitle_button:
} else if (checkedRadioButtonId == R.id.subtitle_button) {
selectedMediaType = getString(R.string.last_download_type_subtitle_key);
mainStorage = mainStorageVideo; // subtitle & video files go together
format = subtitleStreamsAdapter.getItem(selectedSubtitleIndex).getFormat();
@ -808,8 +796,7 @@ public class DownloadDialog extends DialogFragment
} else if (format != null) {
filenameTmp += format.getSuffix();
}
break;
default:
} else {
throw new RuntimeException("No stream selected");
}
@ -1057,8 +1044,8 @@ public class DownloadDialog extends DialogFragment
long nearLength = 0;
// more download logic: select muxer, subtitle converter, etc.
switch (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()) {
case R.id.audio_button:
final int checkedRadioButtonId = dialogBinding.videoAudioGroup.getCheckedRadioButtonId();
if (checkedRadioButtonId == R.id.audio_button) {
kind = 'a';
selectedStream = audioStreamsAdapter.getItem(selectedAudioIndex);
@ -1067,8 +1054,7 @@ public class DownloadDialog extends DialogFragment
} else if (selectedStream.getFormat() == MediaFormat.WEBMA_OPUS) {
psName = Postprocessing.ALGORITHM_OGG_FROM_WEBM_DEMUXER;
}
break;
case R.id.video_button:
} else if (checkedRadioButtonId == R.id.video_button) {
kind = 'v';
selectedStream = videoStreamsAdapter.getItem(selectedVideoIndex);
@ -1094,21 +1080,19 @@ public class DownloadDialog extends DialogFragment
nearLength = secondary.getSizeInBytes() + videoSize;
}
}
break;
case R.id.subtitle_button:
} else if (checkedRadioButtonId == R.id.subtitle_button) {
threads = 1; // use unique thread for subtitles due small file size
kind = 's';
selectedStream = subtitleStreamsAdapter.getItem(selectedSubtitleIndex);
if (selectedStream.getFormat() == MediaFormat.TTML) {
psName = Postprocessing.ALGORITHM_TTML_CONVERTER;
psArgs = new String[] {
psArgs = new String[]{
selectedStream.getFormat().getSuffix(),
"false" // ignore empty frames
};
}
break;
default:
} else {
return;
}

View File

@ -160,33 +160,28 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo>
@Override
public boolean onMenuItemSelected(@NonNull final MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_item_notify:
final int itemId = item.getItemId();
if (itemId == R.id.menu_item_notify) {
final boolean value = !item.isChecked();
item.setEnabled(false);
setNotify(value);
break;
case R.id.action_settings:
} else if (itemId == R.id.action_settings) {
NavigationHelper.openSettings(requireContext());
break;
case R.id.menu_item_rss:
} else if (itemId == R.id.menu_item_rss) {
if (currentInfo != null) {
ShareUtils.openUrlInApp(requireContext(), currentInfo.getFeedUrl());
}
break;
case R.id.menu_item_openInBrowser:
} else if (itemId == R.id.menu_item_openInBrowser) {
if (currentInfo != null) {
ShareUtils.openUrlInBrowser(requireContext(),
currentInfo.getOriginalUrl());
}
break;
case R.id.menu_item_share:
} else if (itemId == R.id.menu_item_share) {
if (currentInfo != null) {
ShareUtils.shareText(requireContext(), name,
currentInfo.getOriginalUrl(), currentInfo.getAvatars());
}
break;
default:
} else {
return false;
}
return true;

View File

@ -232,21 +232,17 @@ public class PlaylistFragment extends BaseListInfoFragment<StreamInfoItem, Playl
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case R.id.action_settings:
final int itemId = item.getItemId();
if (itemId == R.id.action_settings) {
NavigationHelper.openSettings(requireContext());
break;
case R.id.menu_item_openInBrowser:
} else if (itemId == R.id.menu_item_openInBrowser) {
ShareUtils.openUrlInBrowser(requireContext(), url);
break;
case R.id.menu_item_share:
} else if (itemId == R.id.menu_item_share) {
ShareUtils.shareText(requireContext(), name, url,
currentInfo == null ? List.of() : currentInfo.getThumbnails());
break;
case R.id.menu_item_bookmark:
} else if (itemId == R.id.menu_item_bookmark) {
onBookmarkClicked();
break;
case R.id.menu_item_append_playlist:
} else if (itemId == R.id.menu_item_append_playlist) {
if (currentInfo != null) {
disposables.add(PlaylistDialog.createCorrespondingDialog(
getContext(),
@ -258,8 +254,7 @@ public class PlaylistFragment extends BaseListInfoFragment<StreamInfoItem, Playl
dialog -> dialog.show(getFM(), TAG)
));
}
break;
default:
} else {
return super.onOptionsItemSelected(item);
}
return true;

View File

@ -127,36 +127,36 @@ public final class PlayQueueActivity extends AppCompatActivity
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
final int itemId = item.getItemId();
if (itemId == android.R.id.home) {
finish();
return true;
case R.id.action_settings:
} else if (itemId == R.id.action_settings) {
NavigationHelper.openSettings(this);
return true;
case R.id.action_append_playlist:
} else if (itemId == R.id.action_append_playlist) {
PlaylistDialog.showForPlayQueue(player, getSupportFragmentManager());
return true;
case R.id.action_playback_speed:
} else if (itemId == R.id.action_playback_speed) {
openPlaybackParameterDialog();
return true;
case R.id.action_mute:
} else if (itemId == R.id.action_mute) {
player.toggleMute();
return true;
case R.id.action_system_audio:
} else if (itemId == R.id.action_system_audio) {
startActivity(new Intent(Settings.ACTION_SOUND_SETTINGS));
return true;
case R.id.action_switch_main:
} else if (itemId == R.id.action_switch_main) {
this.player.setRecovery();
NavigationHelper.playOnMainPlayer(this, player.getPlayQueue(), true);
return true;
case R.id.action_switch_popup:
} else if (itemId == R.id.action_switch_popup) {
if (PermissionHelper.isPopupEnabledElseAsk(this)) {
this.player.setRecovery();
NavigationHelper.playOnPopupPlayer(this, player.getPlayQueue(), true);
}
return true;
case R.id.action_switch_background:
} else if (itemId == R.id.action_switch_background) {
this.player.setRecovery();
NavigationHelper.playOnBackgroundPlayer(this, player.getPlayQueue(), true);
return true;

View File

@ -632,24 +632,23 @@ public class MissionAdapter extends Adapter<ViewHolder> implements Handler.Callb
DownloadMission mission = h.item.mission instanceof DownloadMission ? (DownloadMission) h.item.mission : null;
if (mission != null) {
switch (id) {
case R.id.start:
if (id == R.id.start) {
h.status.setText(UNDEFINED_PROGRESS);
mDownloadManager.resumeMission(mission);
return true;
case R.id.pause:
} else if (id == R.id.pause) {
mDownloadManager.pauseMission(mission);
return true;
case R.id.error_message_view:
} else if (id == R.id.error_message_view) {
showError(mission);
return true;
case R.id.queue:
} else if (id == R.id.queue) {
boolean flag = !h.queue.isChecked();
h.queue.setChecked(flag);
mission.setEnqueued(flag);
updateProgress(h);
return true;
case R.id.retry:
} else if (id == R.id.retry) {
if (mission.isPsRunning()) {
mission.psContinue(true);
} else {
@ -660,30 +659,26 @@ public class MissionAdapter extends Adapter<ViewHolder> implements Handler.Callb
recoverMission(mission);
}
return true;
case R.id.cancel:
} else if (id == R.id.cancel) {
mission.psContinue(false);
return false;
}
}
switch (id) {
case R.id.menu_item_share:
if (id == R.id.menu_item_share) {
shareFile(h.item.mission);
return true;
case R.id.delete:
// delete the entry and the file
} else if (id == R.id.delete) {// delete the entry and the file
mDeleter.append(h.item.mission, true);
applyChanges();
checkMasterButtonsVisibility();
return true;
case R.id.delete_entry:
// just delete the entry
} else if (id == R.id.delete_entry) {// just delete the entry
mDeleter.append(h.item.mission, false);
applyChanges();
checkMasterButtonsVisibility();
return true;
case R.id.md5:
case R.id.sha1:
} else if (id == R.id.md5 || id == R.id.sha1) {
final StoredFileHelper storage = h.item.mission.storage;
if (!storage.existsAsFile()) {
Toast.makeText(mContext, R.string.missing_file, Toast.LENGTH_SHORT).show();
@ -715,9 +710,7 @@ public class MissionAdapter extends Adapter<ViewHolder> implements Handler.Callb
})
);
return true;
case R.id.source:
/*Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(h.item.mission.source));
mContext.startActivity(intent);*/
} else if (id == R.id.source) {
try {
Intent intent = NavigationHelper.getIntentByLink(mContext, h.item.mission.source);
intent.addFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
@ -726,9 +719,8 @@ public class MissionAdapter extends Adapter<ViewHolder> implements Handler.Callb
Log.w(TAG, "Selected item has a invalid source", e);
}
return true;
default:
return false;
}
return false;
}
public void applyChanges() {

View File

@ -186,23 +186,24 @@ public class MissionsFragment extends Fragment {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.switch_mode:
int itemId = item.getItemId();
if (itemId == R.id.switch_mode) {
mLinear = !mLinear;
updateList();
return true;
case R.id.clear_list:
} else if (itemId == R.id.clear_list) {
showClearDownloadHistoryPrompt();
return true;
case R.id.start_downloads:
} else if (itemId == R.id.start_downloads) {
mBinder.getDownloadManager().startAllMissions();
return true;
case R.id.pause_downloads:
} else if (itemId == R.id.pause_downloads) {
mBinder.getDownloadManager().pauseAllMissions(false);
mAdapter.refreshMissionItems();// update items view
default:
return super.onOptionsItemSelected(item);
}
return super.onOptionsItemSelected(item);
}
public void showClearDownloadHistoryPrompt() {

View File

@ -1,4 +1,3 @@
android.nonFinalResIds=false
android.useAndroidX=true
org.gradle.jvmargs=-Xmx2048M --add-opens jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
systemProp.file.encoding=utf-8