Fixed the download dialog. Next take it to the previous activity
This commit is contained in:
parent
6940021293
commit
c622923edd
3 changed files with 39 additions and 80 deletions
|
@ -144,12 +144,10 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
|
|||
// Create the view
|
||||
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
View v = inflater.inflate(R.layout.dialog_url, null);
|
||||
final EditText text = Utility.findViewById(v, R.id.url);
|
||||
final EditText name = Utility.findViewById(v, R.id.file_name);
|
||||
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 Button fetch = Utility.findViewById(v, R.id.fetch_name);
|
||||
|
||||
threads.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
|
||||
|
@ -174,14 +172,10 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
|
|||
threads.setProgress(def - 1);
|
||||
tCount.setText(String.valueOf(def));
|
||||
|
||||
if (mPendingUrl != null) {
|
||||
text.setText(mPendingUrl);
|
||||
}
|
||||
|
||||
name.setText(getIntent().getStringExtra("fileName"));
|
||||
|
||||
toolbar.setTitle(R.string.add);
|
||||
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
|
||||
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_black_24dp);
|
||||
toolbar.inflateMenu(R.menu.dialog_url);
|
||||
|
||||
// Show the dialog
|
||||
|
@ -192,13 +186,6 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
|
|||
|
||||
dialog.show();
|
||||
|
||||
fetch.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
new NameFetcherTask().execute(text, name);
|
||||
}
|
||||
});
|
||||
|
||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -210,20 +197,17 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
|
|||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
if (item.getItemId() == R.id.okay) {
|
||||
String url = text.getText().toString().trim();
|
||||
String fName = name.getText().toString().trim();
|
||||
|
||||
File f = new File(mManager.getLocation() + "/" + fName);
|
||||
|
||||
if (f.exists()) {
|
||||
Toast.makeText(MainActivity.this, R.string.msg_exists, Toast.LENGTH_SHORT).show();
|
||||
} else if (!checkURL(url)) {
|
||||
Toast.makeText(MainActivity.this, R.string.msg_url_malform, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
|
||||
while (mBinder == null);
|
||||
|
||||
int res = mManager.startMission(url, fName, threads.getProgress() + 1);
|
||||
int res = mManager.startMission(getIntent().getData().toString(), fName, threads.getProgress() + 1);
|
||||
mBinder.onMissionAdded(mManager.getMission(res));
|
||||
mFragment.notifyChange();
|
||||
|
||||
|
@ -241,46 +225,6 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
|
|||
|
||||
}
|
||||
|
||||
private boolean checkURL(String url) {
|
||||
try {
|
||||
URL u = new URL(url);
|
||||
u.openConnection();
|
||||
return true;
|
||||
} catch (MalformedURLException e) {
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private class NameFetcherTask extends AsyncTask<View, Void, Object[]> {
|
||||
|
||||
@Override
|
||||
protected Object[] doInBackground(View[] params) {
|
||||
try {
|
||||
URL url = new URL(((EditText) params[0]).getText().toString());
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
String header = conn.getHeaderField("Content-Disposition");
|
||||
|
||||
if (header != null && header.indexOf("=") != -1) {
|
||||
return new Object[]{params[1], header.split("=")[1].replace("\"", "")};
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Object[] result) {
|
||||
super.onPostExecute(result);
|
||||
|
||||
if (result != null) {
|
||||
((EditText) result[0]).setText(result[1].toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
|
||||
|
|
10
app/src/main/res/drawable/ic_arrow_back_black_24dp.xml
Normal file
10
app/src/main/res/drawable/ic_arrow_back_black_24dp.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/>
|
||||
</vector>
|
|
@ -5,11 +5,10 @@
|
|||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/actionBarItemBackground"/>
|
||||
android:theme="@style/NewPipeActionbarTheme" />
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
|
@ -26,18 +25,6 @@
|
|||
android:gravity="center_vertical"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/msg_url"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/url"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:ems="10"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
@ -61,14 +48,32 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/fetch_name"
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="24dp"
|
||||
android:layout_marginRight="24dp"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="vertical">
|
||||
<RadioGroup
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:checkedButton="@+id/video">
|
||||
<RadioButton android:id="@+id/video"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/msg_fetch_filename"
|
||||
android:textColor="?attr/colorPrimary"
|
||||
android:background="?android:selectableItemBackground"/>
|
||||
|
||||
android:text="@string/video"
|
||||
android:onClick="onRadioButtonClicked"/>
|
||||
<RadioButton android:id="@+id/audio"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/audio"
|
||||
android:onClick="onRadioButtonClicked"/>
|
||||
</RadioGroup>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
|
Loading…
Reference in a new issue