From c622923edd7e5fa3c8de39074fd3acf4f1007599 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 27 Apr 2016 06:51:47 -0300 Subject: [PATCH] Fixed the download dialog. Next take it to the previous activity --- .../schabi/newpipe/download/MainActivity.java | 60 +------------------ .../res/drawable/ic_arrow_back_black_24dp.xml | 10 ++++ app/src/main/res/layout/dialog_url.xml | 49 ++++++++------- 3 files changed, 39 insertions(+), 80 deletions(-) create mode 100644 app/src/main/res/drawable/ic_arrow_back_black_24dp.xml diff --git a/app/src/main/java/org/schabi/newpipe/download/MainActivity.java b/app/src/main/java/org/schabi/newpipe/download/MainActivity.java index d69c8aaa6..5d8295f36 100644 --- a/app/src/main/java/org/schabi/newpipe/download/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/download/MainActivity.java @@ -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 { - - @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) { diff --git a/app/src/main/res/drawable/ic_arrow_back_black_24dp.xml b/app/src/main/res/drawable/ic_arrow_back_black_24dp.xml new file mode 100644 index 000000000..8d8acb883 --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_back_black_24dp.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_url.xml b/app/src/main/res/layout/dialog_url.xml index b797325c1..46a816282 100644 --- a/app/src/main/res/layout/dialog_url.xml +++ b/app/src/main/res/layout/dialog_url.xml @@ -5,11 +5,10 @@ android:orientation="vertical"> + android:theme="@style/NewPipeActionbarTheme" /> - - - - @@ -60,15 +47,33 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true"/> - -