1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-06-18 03:10:00 +00:00

fixed .webm download locatiion issue

This commit is contained in:
Christian Schabesberger 2016-09-27 21:33:26 +02:00
parent 920c169d55
commit f9ac199c1f
10 changed files with 32 additions and 43 deletions

View File

@ -133,7 +133,7 @@
<!-- giga get related -->
<activity
android:name=".download.MainActivity"
android:name=".download.DownloadActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:theme="@style/AppTheme" />

View File

@ -16,7 +16,7 @@ import org.schabi.newpipe.settings.SettingsActivity;
* Created by Christian Schabesberger on 02.08.16.
*
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
* MainActivity.java is part of NewPipe.
* DownloadActivity.java is part of NewPipe.
*
* NewPipe is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -73,7 +73,7 @@ public class MainActivity extends AppCompatActivity {
return true;
}
case R.id.action_show_downloads: {
Intent intent = new Intent(this, org.schabi.newpipe.download.MainActivity.class);
Intent intent = new Intent(this, org.schabi.newpipe.download.DownloadActivity.class);
startActivity(intent);
return true;
}

View File

@ -183,7 +183,7 @@ class ActionBarHandler {
return true;
case R.id.menu_item_downloads: {
Intent intent =
new Intent(activity, org.schabi.newpipe.download.MainActivity.class);
new Intent(activity, org.schabi.newpipe.download.DownloadActivity.class);
activity.startActivity(intent);
return true;
}

View File

@ -23,6 +23,7 @@ import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
@ -41,13 +42,13 @@ import us.shandian.giga.ui.fragment.MissionsFragment;
import us.shandian.giga.util.CrashHandler;
import us.shandian.giga.util.Utility;
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener{
public class DownloadActivity extends AppCompatActivity implements AdapterView.OnItemClickListener{
public static final String INTENT_DOWNLOAD = "us.shandian.giga.intent.DOWNLOAD";
public static final String INTENT_LIST = "us.shandian.giga.intent.LIST";
private static final String TAG = MainActivity.class.toString();
private static final String TAG = DownloadActivity.class.toString();
public static final String THREADS = "threads";
@ -150,6 +151,8 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
final TextView tCount = Utility.findViewById(v, R.id.threads_count);
final SeekBar threads = Utility.findViewById(v, R.id.threads);
final Toolbar toolbar = Utility.findViewById(v, R.id.toolbar);
final RadioButton audioButton = (RadioButton) Utility.findViewById(v, R.id.audio_button);
threads.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@ -204,12 +207,16 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
File f = new File(mManager.getLocation() + "/" + fName);
if (f.exists()) {
Toast.makeText(MainActivity.this, R.string.msg_exists, Toast.LENGTH_SHORT).show();
Toast.makeText(DownloadActivity.this, R.string.msg_exists, Toast.LENGTH_SHORT).show();
} else {
while (mBinder == null);
int res = mManager.startMission(getIntent().getData().toString(), fName, threads.getProgress() + 1);
int res = mManager.startMission(
getIntent().getData().toString(),
fName,
audioButton.isChecked(),
threads.getProgress() + 1);
mBinder.onMissionAdded(mManager.getMission(res));
mFragment.notifyChange();
@ -258,7 +265,7 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
return true;
}
case R.id.action_report_error: {
ErrorActivity.reportError(MainActivity.this, new Vector<Throwable>(),
ErrorActivity.reportError(DownloadActivity.this, new Vector<Throwable>(),
null, null,
ErrorActivity.ErrorInfo.make(ErrorActivity.USER_REPORT,
null,

View File

@ -225,6 +225,7 @@ public class DownloadDialog extends DialogFragment {
int res = mManager.startMission(
arguments.getString(AUDIO_URL),
fName + arguments.getString(FILE_SUFFIX_AUDIO),
audioButton.isChecked(),
threads.getProgress() + 1);
mBinder.onMissionAdded(mManager.getMission(res));
}
@ -233,6 +234,7 @@ public class DownloadDialog extends DialogFragment {
int res = mManager.startMission(
arguments.getString(VIDEO_URL),
fName + arguments.getString(FILE_SUFFIX_VIDEO),
audioButton.isChecked(),
threads.getProgress() + 1);
mBinder.onMissionAdded(mManager.getMission(res));
}
@ -255,8 +257,8 @@ public class DownloadDialog extends DialogFragment {
//we'll see later
FileDownloader.downloadFile(getContext(), url, saveFilePath, title);
} else {
Intent intent = new Intent(getContext(), MainActivity.class);
intent.setAction(MainActivity.INTENT_DOWNLOAD);
Intent intent = new Intent(getContext(), DownloadActivity.class);
intent.setAction(DownloadActivity.INTENT_DOWNLOAD);
intent.setData(Uri.parse(url));
intent.putExtra("fileName", createFileName(title) + fileSuffix);
startActivity(intent);

View File

@ -89,14 +89,6 @@ public class NewPipeSettings {
return downloadPath;
}
public static String getDownloadPath(Context context, String fileName)
{
if(Utility.isVideoFile(fileName)) {
return NewPipeSettings.getVideoDownloadPath(context);
}
return NewPipeSettings.getAudioDownloadPath(context);
}
private static File getFolder(Context context, int keyID, String defaultDirectoryName) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
final String key = context.getString(keyID);

View File

@ -4,7 +4,7 @@ public interface DownloadManager
{
int BLOCK_SIZE = 512 * 1024;
int startMission(String url, String name, int threads);
int startMission(String url, String name, boolean isAudio, int threads);
void resumeMission(int id);
void pauseMission(int id);
void deleteMission(int id);

View File

@ -31,11 +31,15 @@ public class DownloadManagerImpl implements DownloadManager
}
@Override
public int startMission(String url, String name, int threads) {
public int startMission(String url, String name, boolean isAudio, int threads) {
DownloadMission mission = new DownloadMission();
mission.url = url;
mission.name = name;
mission.location = NewPipeSettings.getDownloadPath(mContext, name);
if(isAudio) {
mission.location = NewPipeSettings.getAudioDownloadPath(mContext);
} else {
mission.location = NewPipeSettings.getVideoDownloadPath(mContext);
}
mission.timestamp = System.currentTimeMillis();
mission.threadCount = threads;
new Initializer(mContext, mission).start();

View File

@ -14,12 +14,12 @@ import android.os.Message;
import android.support.v4.app.NotificationCompat.Builder;
import android.util.Log;
import org.schabi.newpipe.download.DownloadActivity;
import org.schabi.newpipe.settings.NewPipeSettings;
import org.schabi.newpipe.R;
import us.shandian.giga.get.DownloadManager;
import us.shandian.giga.get.DownloadManagerImpl;
import us.shandian.giga.get.DownloadMission;
import org.schabi.newpipe.download.MainActivity;
import static org.schabi.newpipe.BuildConfig.DEBUG;
public class DownloadManagerService extends Service implements DownloadMission.MissionListener
@ -53,7 +53,7 @@ public class DownloadManagerService extends Service implements DownloadMission.M
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.setClass(this, MainActivity.class);
i.setClass(this, DownloadActivity.class);
Drawable icon = this.getResources().getDrawable(R.mipmap.ic_launcher);
@ -68,8 +68,8 @@ public class DownloadManagerService extends Service implements DownloadMission.M
PendingIntent.getActivity(
this,
0,
new Intent(this, MainActivity.class)
.setAction(MainActivity.INTENT_LIST),
new Intent(this, DownloadActivity.class)
.setAction(DownloadActivity.INTENT_LIST),
PendingIntent.FLAG_UPDATE_CURRENT
);

View File

@ -27,13 +27,8 @@ public class Utility
{
public static enum FileType {
APP,
VIDEO,
EXCEL,
WORD,
POWERPOINT,
MUSIC,
ARCHIVE,
UNKNOWN
}
@ -142,22 +137,11 @@ public class Utility
}
public static FileType getFileType(String file) {
if (file.endsWith(".apk")) {
return FileType.APP;
} else if (file.endsWith(".mp3") || file.endsWith(".wav") || file.endsWith(".flac") || file.endsWith(".m4a")) {
if (file.endsWith(".mp3") || file.endsWith(".wav") || file.endsWith(".flac") || file.endsWith(".m4a")) {
return FileType.MUSIC;
} else if (file.endsWith(".mp4") || file.endsWith(".mpeg") || file.endsWith(".rm") || file.endsWith(".rmvb")
|| file.endsWith(".flv") || file.endsWith(".webp") || file.endsWith(".webm")) {
return FileType.VIDEO;
} else if (file.endsWith(".doc") || file.endsWith(".docx")) {
return FileType.WORD;
} else if (file.endsWith(".xls") || file.endsWith(".xlsx")) {
return FileType.EXCEL;
} else if (file.endsWith(".ppt") || file.endsWith(".pptx")) {
return FileType.POWERPOINT;
} else if (file.endsWith(".zip") || file.endsWith(".rar") || file.endsWith(".7z") || file.endsWith(".gz")
|| file.endsWith("tar") || file.endsWith(".bz")) {
return FileType.ARCHIVE;
} else {
return FileType.UNKNOWN;
}