Added menu to download activity

This commit is contained in:
David 2016-05-02 10:19:58 -03:00
parent 730de4061f
commit affce74b84
3 changed files with 58 additions and 12 deletions

View File

@ -16,6 +16,8 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
@ -25,15 +27,21 @@ import android.widget.EditText;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import android.support.v7.widget.SearchView;
import org.schabi.newpipe.ErrorActivity;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.SettingsActivity;
import org.schabi.newpipe.VideoItemDetailActivity; import org.schabi.newpipe.VideoItemDetailActivity;
import org.schabi.newpipe.VideoItemListActivity;
import org.schabi.newpipe.extractor.ServiceList;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.Vector;
import us.shandian.giga.get.DownloadManager; import us.shandian.giga.get.DownloadManager;
import us.shandian.giga.service.DownloadManagerService; import us.shandian.giga.service.DownloadManagerService;
@ -50,6 +58,8 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
private static final String TAG = MainActivity.class.toString(); private static final String TAG = MainActivity.class.toString();
private Menu menu = null;
private MissionsFragment mFragment; private MissionsFragment mFragment;
private DownloadManager mManager; private DownloadManager mManager;
private DownloadManagerService.DMBinder mBinder; private DownloadManagerService.DMBinder mBinder;
@ -230,18 +240,43 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
} }
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
this.menu = menu;
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.download_menu, menu);
return true;
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId(); int id = item.getItemId();
if (id == android.R.id.home) {
Intent intent = new Intent(this, VideoItemDetailActivity.class); switch (id) {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); case android.R.id.home: {
NavUtils.navigateUpTo(this, intent); Intent intent = new Intent(this, VideoItemListActivity.class);
return true; intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
} else { NavUtils.navigateUpTo(this, intent);
return mFragment.onOptionsItemSelected(item) || return true;
super.onOptionsItemSelected(item); }
case R.id.action_settings: {
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
return true;
}
case R.id.action_report_error: {
ErrorActivity.reportError(MainActivity.this, new Vector<Exception>(),
null, null,
ErrorActivity.ErrorInfo.make(ErrorActivity.USER_REPORT,
null,
"user_report", R.string.user_report));
return true;
}
default:
return mFragment.onOptionsItemSelected(item) ||
super.onOptionsItemSelected(item);
} }
} }
} }

View File

@ -91,9 +91,7 @@ public abstract class MissionsFragment extends Fragment
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.frag_mission, menu);
mSwitch = menu.findItem(R.id.switch_mode);
mSwitch.setIcon(mLinear ? R.drawable.grid : R.drawable.list);
} }
@Override @Override

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_settings"
app:showAsAction="never"
android:title="@string/settings"/>
<item android:id="@+id/action_report_error"
app:showAsAction="never"
android:title="@string/report_error" />
</menu>