mirror of https://github.com/TeamNewPipe/NewPipe
77 lines
2.9 KiB
Java
77 lines
2.9 KiB
Java
package org.schabi.newpipe.fragments;
|
|
|
|
import android.content.Context;
|
|
import android.os.Bundle;
|
|
import android.support.annotation.Nullable;
|
|
import android.support.v4.app.Fragment;
|
|
import android.support.v7.app.ActionBar;
|
|
import android.support.v7.app.AppCompatActivity;
|
|
import android.util.Log;
|
|
import android.view.LayoutInflater;
|
|
import android.view.Menu;
|
|
import android.view.MenuInflater;
|
|
import android.view.MenuItem;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
|
|
import org.schabi.newpipe.MainActivity;
|
|
import org.schabi.newpipe.R;
|
|
import org.schabi.newpipe.util.NavigationHelper;
|
|
|
|
public class MainFragment extends Fragment {
|
|
private final String TAG = "MainFragment@" + Integer.toHexString(hashCode());
|
|
private static final boolean DEBUG = MainActivity.DEBUG;
|
|
|
|
private AppCompatActivity activity;
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
// Fragment's LifeCycle
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
@Override
|
|
public void onAttach(Context context) {
|
|
super.onAttach(context);
|
|
if (DEBUG) Log.d(TAG, "onAttach() called with: context = [" + context + "]");
|
|
activity = ((AppCompatActivity) context);
|
|
}
|
|
|
|
@Override
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
if (DEBUG) Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]");
|
|
setHasOptionsMenu(true);
|
|
}
|
|
|
|
@Override
|
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
if (DEBUG) Log.d(TAG, "onCreateView() called with: inflater = [" + inflater + "], container = [" + container + "], savedInstanceState = [" + savedInstanceState + "]");
|
|
return inflater.inflate(R.layout.fragment_main, container, false);
|
|
}
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
// Menu
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
@Override
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
super.onCreateOptionsMenu(menu, inflater);
|
|
if (DEBUG) Log.d(TAG, "onCreateOptionsMenu() called with: menu = [" + menu + "], inflater = [" + inflater + "]");
|
|
inflater.inflate(R.menu.main_fragment_menu, menu);
|
|
|
|
ActionBar supportActionBar = activity.getSupportActionBar();
|
|
if (supportActionBar != null) {
|
|
supportActionBar.setDisplayShowTitleEnabled(false);
|
|
supportActionBar.setDisplayHomeAsUpEnabled(false);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
switch (item.getItemId()) {
|
|
case R.id.action_search:
|
|
NavigationHelper.openSearch(activity, 0, "");
|
|
return true;
|
|
}
|
|
return super.onOptionsItemSelected(item);
|
|
}
|
|
}
|