Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(need help) Cover image feature #6278

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ dependencies {
// Date and time formatting
implementation "org.ocpsoft.prettytime:prettytime:5.0.0.Final"

// File Metadata Changing
implementation group: 'org', name: 'jaudiotagger', version: '2.0.3'

/** Debugging **/
// Memory leak detection
implementation "com.squareup.leakcanary:leakcanary-object-watcher-android:${leakCanaryVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import us.shandian.giga.service.DownloadManagerService.DownloadManagerBinder;
import us.shandian.giga.service.MissionState;


import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;

public class DownloadDialog extends DialogFragment
Expand Down Expand Up @@ -287,6 +288,10 @@ public void onViewCreated(@NonNull final View view, @Nullable final Bundle saved

prefs = PreferenceManager.getDefaultSharedPreferences(requireContext());

final boolean cover = prefs.getBoolean(getString(R.string.download_cover_pref), false);
Log.i("DEBUG_COVER", "" + cover);
dialogBinding.coverButton.setChecked(cover);

final int threads = prefs.getInt(getString(R.string.default_download_threads), 3);
dialogBinding.threadsCount.setText(String.valueOf(threads));
dialogBinding.threads.setProgress(threads - 1);
Expand Down Expand Up @@ -852,6 +857,9 @@ private void continueSelectedDownload(@NonNull final StoredFileHelper storage) {
long nearLength = 0;

// more download logic: select muxer, subtitle converter, etc.
final boolean cover;
cover = dialogBinding.coverButton.isChecked();

switch (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()) {
case R.id.audio_button:
kind = 'a';
Expand Down Expand Up @@ -923,7 +931,7 @@ private void continueSelectedDownload(@NonNull final StoredFileHelper storage) {
new MissionRecoveryInfo(secondaryStream)};
}

DownloadManagerService.startMission(context, urls, storage, kind, threads,
DownloadManagerService.startMission(context, urls, storage, kind, cover, threads,
currentInfo.getUrl(), psName, psArgs, nearLength, recoveryInfo);

Toast.makeText(context, getString(R.string.download_has_started),
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/us/shandian/giga/get/DownloadMission.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ public class DownloadMission extends Mission {
*/
volatile long fallbackResumeOffset;

/**
* If the cover gets downloaded, chosen by the user
*/
public boolean cover = false;

/**
* Maximum of download threads running, chosen by the user
*/
Expand Down Expand Up @@ -159,6 +164,7 @@ public DownloadMission(String[] urls, StoredFileHelper storage, char kind, Postp
throw new IllegalArgumentException("urls array is empty");
this.urls = urls;
this.kind = kind;
this.cover = false;
this.offsets = new long[urls.length];
this.enqueued = true;
this.maxRetry = 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import us.shandian.giga.io.StoredFileHelper;
import us.shandian.giga.util.Utility;

import org.jaudiotagger.tag.Tag;

import static org.schabi.newpipe.BuildConfig.DEBUG;

public class DownloadManager {
Expand Down Expand Up @@ -247,6 +249,10 @@ void startMission(DownloadMission mission) {
if (canDownloadInCurrentNetwork() && start) {
mission.start();
}
// add cover image
if (mission.cover) {
Log.i("DEBUG_COVER", "Adding a cover is set to true");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class DownloadManagerService extends Service {

private static final String EXTRA_URLS = "DownloadManagerService.extra.urls";
private static final String EXTRA_KIND = "DownloadManagerService.extra.kind";
private static final String EXTRA_COVER = "DownloadManagerService.extra.cover";
private static final String EXTRA_THREADS = "DownloadManagerService.extra.threads";
private static final String EXTRA_POSTPROCESSING_NAME = "DownloadManagerService.extra.postprocessingName";
private static final String EXTRA_POSTPROCESSING_ARGS = "DownloadManagerService.extra.postprocessingArgs";
Expand Down Expand Up @@ -378,6 +379,7 @@ public void updateForegroundState(boolean state) {
* @param urls array of urls to download
* @param storage where the file is saved
* @param kind type of file (a: audio v: video s: subtitle ?: file-extension defined)
* @param cover if the cover image gets downloaded
* @param threads the number of threads maximal used to download chunks of the file.
* @param psName the name of the required post-processing algorithm, or {@code null} to ignore.
* @param source source url of the resource
Expand All @@ -386,12 +388,13 @@ public void updateForegroundState(boolean state) {
* @param recoveryInfo array of MissionRecoveryInfo, in case is required recover the download
*/
public static void startMission(Context context, String[] urls, StoredFileHelper storage,
char kind, int threads, String source, String psName,
char kind, boolean cover, int threads, String source, String psName,
String[] psArgs, long nearLength, MissionRecoveryInfo[] recoveryInfo) {
Intent intent = new Intent(context, DownloadManagerService.class);
intent.setAction(Intent.ACTION_RUN);
intent.putExtra(EXTRA_URLS, urls);
intent.putExtra(EXTRA_KIND, kind);
intent.putExtra(EXTRA_COVER, cover);
intent.putExtra(EXTRA_THREADS, threads);
intent.putExtra(EXTRA_SOURCE, source);
intent.putExtra(EXTRA_POSTPROCESSING_NAME, psName);
Expand All @@ -412,6 +415,7 @@ private void startMission(Intent intent) {
Uri parentPath = intent.getParcelableExtra(EXTRA_PARENT_PATH);
int threads = intent.getIntExtra(EXTRA_THREADS, 1);
char kind = intent.getCharExtra(EXTRA_KIND, '?');
boolean cover = intent.getBooleanExtra(EXTRA_COVER, false);
String psName = intent.getStringExtra(EXTRA_POSTPROCESSING_NAME);
String[] psArgs = intent.getStringArrayExtra(EXTRA_POSTPROCESSING_ARGS);
String source = intent.getStringExtra(EXTRA_SOURCE);
Expand All @@ -437,6 +441,7 @@ private void startMission(Intent intent) {
recovery[i] = (MissionRecoveryInfo) parcelRecovery[i];

final DownloadMission mission = new DownloadMission(urls, storage, kind, ps);
mission.cover = cover;
mission.threadCount = threads;
mission.source = source;
mission.nearLength = nearLength;
Expand Down
20 changes: 19 additions & 1 deletion app/src/main/res/layout/download_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
android:layout_height="wrap_content"
android:layout_below="@+id/file_name"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="6dp"
android:gravity="left"
android:orientation="horizontal"
Expand All @@ -44,28 +45,33 @@
android:id="@+id/video_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:checked="true"
android:text="@string/video" />

<RadioButton
android:id="@+id/audio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:text="@string/audio" />

<RadioButton
android:id="@+id/subtitle_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:text="@string/caption_setting_title" />

</RadioGroup>

<Spinner
android:id="@+id/quality_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/video_audio_group"
android:layout_below="@+id/cover_button"
android:layout_marginLeft="20dp"
android:layout_marginTop="6dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="12dp"
android:minWidth="150dp"
Expand All @@ -81,6 +87,17 @@
android:layout_marginBottom="6dp"
android:text="@string/msg_threads" />

<CheckBox
android:id="@+id/cover_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/video_audio_group"
android:layout_alignParentStart="false"
android:layout_marginStart="20dp"
android:layout_marginTop="0dp"
android:checked="true"
android:text="@string/cover_image" />

<LinearLayout
android:id="@+id/threads_layout"
android:layout_width="match_parent"
Expand All @@ -107,4 +124,5 @@
android:max="31"
android:progress="3" />
</LinearLayout>

</RelativeLayout>
8 changes: 8 additions & 0 deletions app/src/main/res/xml/download_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,13 @@
android:summary="@string/enable_queue_limit_desc"
android:title="@string/enable_queue_limit"
app:iconSpaceReserved="false" />
<SwitchPreferenceCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:defaultValue="false"
android:key="@string/download_cover_pref"
android:summary="@string/download_cover_pref_summary"
android:title="@string/download_cover_pref_title"
app:iconSpaceReserved="false" />

</PreferenceScreen>
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ include ':app'
// dependencySubstitution {
// substitute module('com.github.TeamNewPipe:NewPipeExtractor') with project(':extractor')
// }
//}
//}