fixed .webm download locatiion issue
This commit is contained in:
parent
920c169d55
commit
f9ac199c1f
|
@ -133,7 +133,7 @@
|
||||||
|
|
||||||
<!-- giga get related -->
|
<!-- giga get related -->
|
||||||
<activity
|
<activity
|
||||||
android:name=".download.MainActivity"
|
android:name=".download.DownloadActivity"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
android:theme="@style/AppTheme" />
|
android:theme="@style/AppTheme" />
|
||||||
|
|
|
@ -16,7 +16,7 @@ import org.schabi.newpipe.settings.SettingsActivity;
|
||||||
* Created by Christian Schabesberger on 02.08.16.
|
* Created by Christian Schabesberger on 02.08.16.
|
||||||
*
|
*
|
||||||
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
|
* 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
|
* NewPipe is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -73,7 +73,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case R.id.action_show_downloads: {
|
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);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,7 +183,7 @@ class ActionBarHandler {
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_item_downloads: {
|
case R.id.menu_item_downloads: {
|
||||||
Intent intent =
|
Intent intent =
|
||||||
new Intent(activity, org.schabi.newpipe.download.MainActivity.class);
|
new Intent(activity, org.schabi.newpipe.download.DownloadActivity.class);
|
||||||
activity.startActivity(intent);
|
activity.startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import android.view.View;
|
||||||
import android.view.ViewTreeObserver;
|
import android.view.ViewTreeObserver;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
import android.widget.RadioButton;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
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.CrashHandler;
|
||||||
import us.shandian.giga.util.Utility;
|
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_DOWNLOAD = "us.shandian.giga.intent.DOWNLOAD";
|
||||||
|
|
||||||
public static final String INTENT_LIST = "us.shandian.giga.intent.LIST";
|
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";
|
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 TextView tCount = Utility.findViewById(v, R.id.threads_count);
|
||||||
final SeekBar threads = Utility.findViewById(v, R.id.threads);
|
final SeekBar threads = Utility.findViewById(v, R.id.threads);
|
||||||
final Toolbar toolbar = Utility.findViewById(v, R.id.toolbar);
|
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() {
|
threads.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||||
|
|
||||||
|
@ -204,12 +207,16 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
|
||||||
File f = new File(mManager.getLocation() + "/" + fName);
|
File f = new File(mManager.getLocation() + "/" + fName);
|
||||||
|
|
||||||
if (f.exists()) {
|
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 {
|
} else {
|
||||||
|
|
||||||
while (mBinder == null);
|
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));
|
mBinder.onMissionAdded(mManager.getMission(res));
|
||||||
mFragment.notifyChange();
|
mFragment.notifyChange();
|
||||||
|
|
||||||
|
@ -258,7 +265,7 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case R.id.action_report_error: {
|
case R.id.action_report_error: {
|
||||||
ErrorActivity.reportError(MainActivity.this, new Vector<Throwable>(),
|
ErrorActivity.reportError(DownloadActivity.this, new Vector<Throwable>(),
|
||||||
null, null,
|
null, null,
|
||||||
ErrorActivity.ErrorInfo.make(ErrorActivity.USER_REPORT,
|
ErrorActivity.ErrorInfo.make(ErrorActivity.USER_REPORT,
|
||||||
null,
|
null,
|
|
@ -225,6 +225,7 @@ public class DownloadDialog extends DialogFragment {
|
||||||
int res = mManager.startMission(
|
int res = mManager.startMission(
|
||||||
arguments.getString(AUDIO_URL),
|
arguments.getString(AUDIO_URL),
|
||||||
fName + arguments.getString(FILE_SUFFIX_AUDIO),
|
fName + arguments.getString(FILE_SUFFIX_AUDIO),
|
||||||
|
audioButton.isChecked(),
|
||||||
threads.getProgress() + 1);
|
threads.getProgress() + 1);
|
||||||
mBinder.onMissionAdded(mManager.getMission(res));
|
mBinder.onMissionAdded(mManager.getMission(res));
|
||||||
}
|
}
|
||||||
|
@ -233,6 +234,7 @@ public class DownloadDialog extends DialogFragment {
|
||||||
int res = mManager.startMission(
|
int res = mManager.startMission(
|
||||||
arguments.getString(VIDEO_URL),
|
arguments.getString(VIDEO_URL),
|
||||||
fName + arguments.getString(FILE_SUFFIX_VIDEO),
|
fName + arguments.getString(FILE_SUFFIX_VIDEO),
|
||||||
|
audioButton.isChecked(),
|
||||||
threads.getProgress() + 1);
|
threads.getProgress() + 1);
|
||||||
mBinder.onMissionAdded(mManager.getMission(res));
|
mBinder.onMissionAdded(mManager.getMission(res));
|
||||||
}
|
}
|
||||||
|
@ -255,8 +257,8 @@ public class DownloadDialog extends DialogFragment {
|
||||||
//we'll see later
|
//we'll see later
|
||||||
FileDownloader.downloadFile(getContext(), url, saveFilePath, title);
|
FileDownloader.downloadFile(getContext(), url, saveFilePath, title);
|
||||||
} else {
|
} else {
|
||||||
Intent intent = new Intent(getContext(), MainActivity.class);
|
Intent intent = new Intent(getContext(), DownloadActivity.class);
|
||||||
intent.setAction(MainActivity.INTENT_DOWNLOAD);
|
intent.setAction(DownloadActivity.INTENT_DOWNLOAD);
|
||||||
intent.setData(Uri.parse(url));
|
intent.setData(Uri.parse(url));
|
||||||
intent.putExtra("fileName", createFileName(title) + fileSuffix);
|
intent.putExtra("fileName", createFileName(title) + fileSuffix);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
|
|
|
@ -89,14 +89,6 @@ public class NewPipeSettings {
|
||||||
return downloadPath;
|
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) {
|
private static File getFolder(Context context, int keyID, String defaultDirectoryName) {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
final String key = context.getString(keyID);
|
final String key = context.getString(keyID);
|
||||||
|
|
|
@ -4,7 +4,7 @@ public interface DownloadManager
|
||||||
{
|
{
|
||||||
int BLOCK_SIZE = 512 * 1024;
|
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 resumeMission(int id);
|
||||||
void pauseMission(int id);
|
void pauseMission(int id);
|
||||||
void deleteMission(int id);
|
void deleteMission(int id);
|
||||||
|
|
|
@ -31,11 +31,15 @@ public class DownloadManagerImpl implements DownloadManager
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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();
|
DownloadMission mission = new DownloadMission();
|
||||||
mission.url = url;
|
mission.url = url;
|
||||||
mission.name = name;
|
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.timestamp = System.currentTimeMillis();
|
||||||
mission.threadCount = threads;
|
mission.threadCount = threads;
|
||||||
new Initializer(mContext, mission).start();
|
new Initializer(mContext, mission).start();
|
||||||
|
|
|
@ -14,12 +14,12 @@ import android.os.Message;
|
||||||
import android.support.v4.app.NotificationCompat.Builder;
|
import android.support.v4.app.NotificationCompat.Builder;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.download.DownloadActivity;
|
||||||
import org.schabi.newpipe.settings.NewPipeSettings;
|
import org.schabi.newpipe.settings.NewPipeSettings;
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
import us.shandian.giga.get.DownloadManager;
|
import us.shandian.giga.get.DownloadManager;
|
||||||
import us.shandian.giga.get.DownloadManagerImpl;
|
import us.shandian.giga.get.DownloadManagerImpl;
|
||||||
import us.shandian.giga.get.DownloadMission;
|
import us.shandian.giga.get.DownloadMission;
|
||||||
import org.schabi.newpipe.download.MainActivity;
|
|
||||||
import static org.schabi.newpipe.BuildConfig.DEBUG;
|
import static org.schabi.newpipe.BuildConfig.DEBUG;
|
||||||
|
|
||||||
public class DownloadManagerService extends Service implements DownloadMission.MissionListener
|
public class DownloadManagerService extends Service implements DownloadMission.MissionListener
|
||||||
|
@ -53,7 +53,7 @@ public class DownloadManagerService extends Service implements DownloadMission.M
|
||||||
|
|
||||||
Intent i = new Intent();
|
Intent i = new Intent();
|
||||||
i.setAction(Intent.ACTION_MAIN);
|
i.setAction(Intent.ACTION_MAIN);
|
||||||
i.setClass(this, MainActivity.class);
|
i.setClass(this, DownloadActivity.class);
|
||||||
|
|
||||||
Drawable icon = this.getResources().getDrawable(R.mipmap.ic_launcher);
|
Drawable icon = this.getResources().getDrawable(R.mipmap.ic_launcher);
|
||||||
|
|
||||||
|
@ -68,8 +68,8 @@ public class DownloadManagerService extends Service implements DownloadMission.M
|
||||||
PendingIntent.getActivity(
|
PendingIntent.getActivity(
|
||||||
this,
|
this,
|
||||||
0,
|
0,
|
||||||
new Intent(this, MainActivity.class)
|
new Intent(this, DownloadActivity.class)
|
||||||
.setAction(MainActivity.INTENT_LIST),
|
.setAction(DownloadActivity.INTENT_LIST),
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT
|
PendingIntent.FLAG_UPDATE_CURRENT
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,8 @@ public class Utility
|
||||||
{
|
{
|
||||||
|
|
||||||
public static enum FileType {
|
public static enum FileType {
|
||||||
APP,
|
|
||||||
VIDEO,
|
VIDEO,
|
||||||
EXCEL,
|
|
||||||
WORD,
|
|
||||||
POWERPOINT,
|
|
||||||
MUSIC,
|
MUSIC,
|
||||||
ARCHIVE,
|
|
||||||
UNKNOWN
|
UNKNOWN
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,22 +137,11 @@ public class Utility
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FileType getFileType(String file) {
|
public static FileType getFileType(String file) {
|
||||||
if (file.endsWith(".apk")) {
|
if (file.endsWith(".mp3") || file.endsWith(".wav") || file.endsWith(".flac") || file.endsWith(".m4a")) {
|
||||||
return FileType.APP;
|
|
||||||
} else if (file.endsWith(".mp3") || file.endsWith(".wav") || file.endsWith(".flac") || file.endsWith(".m4a")) {
|
|
||||||
return FileType.MUSIC;
|
return FileType.MUSIC;
|
||||||
} else if (file.endsWith(".mp4") || file.endsWith(".mpeg") || file.endsWith(".rm") || file.endsWith(".rmvb")
|
} else if (file.endsWith(".mp4") || file.endsWith(".mpeg") || file.endsWith(".rm") || file.endsWith(".rmvb")
|
||||||
|| file.endsWith(".flv") || file.endsWith(".webp") || file.endsWith(".webm")) {
|
|| file.endsWith(".flv") || file.endsWith(".webp") || file.endsWith(".webm")) {
|
||||||
return FileType.VIDEO;
|
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 {
|
} else {
|
||||||
return FileType.UNKNOWN;
|
return FileType.UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue