mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 16:40:32 +00:00
commit
76c59cbdea
@ -37,19 +37,23 @@ import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.StreamingService;
|
||||
import org.schabi.newpipe.fragments.BackPressable;
|
||||
import org.schabi.newpipe.fragments.MainFragment;
|
||||
import org.schabi.newpipe.fragments.detail.VideoDetailFragment;
|
||||
import org.schabi.newpipe.fragments.list.search.SearchFragment;
|
||||
import org.schabi.newpipe.report.ErrorActivity;
|
||||
import org.schabi.newpipe.util.Constants;
|
||||
import org.schabi.newpipe.util.NavigationHelper;
|
||||
import org.schabi.newpipe.util.ServiceHelper;
|
||||
@ -61,6 +65,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release");
|
||||
|
||||
private ActionBarDrawerToggle toggle = null;
|
||||
private DrawerLayout drawer = null;
|
||||
private NavigationView drawerItems = null;
|
||||
private TextView headerServiceView = null;
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
// Activity's LifeCycle
|
||||
@ -81,13 +88,12 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
setSupportActionBar(findViewById(R.id.toolbar));
|
||||
setupDrawer();
|
||||
setupDrawerFooter();
|
||||
}
|
||||
|
||||
private void setupDrawer() {
|
||||
final Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
final DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||
final NavigationView drawerItems = findViewById(R.id.navigation);
|
||||
drawer = findViewById(R.id.drawer_layout);
|
||||
drawerItems = findViewById(R.id.navigation);
|
||||
|
||||
//drawerItems.setItemIconTintList(null); // Set null to use the original icon
|
||||
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(true);
|
||||
@ -112,30 +118,48 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
|
||||
drawerItems.setNavigationItemSelectedListener(item -> {
|
||||
if (item.getGroupId() == R.id.menu_services_group) {
|
||||
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(false);
|
||||
ServiceHelper.setSelectedServiceId(this, item.getTitle().toString());
|
||||
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(true);
|
||||
}
|
||||
drawer.closeDrawers();
|
||||
return true;
|
||||
});
|
||||
drawerItems.setNavigationItemSelectedListener(this::changeService);
|
||||
|
||||
setupDrawerFooter();
|
||||
setupDrawerHeader();
|
||||
} else {
|
||||
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean changeService(MenuItem item) {
|
||||
if (item.getGroupId() == R.id.menu_services_group) {
|
||||
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(false);
|
||||
ServiceHelper.setSelectedServiceId(this, item.getTitle().toString());
|
||||
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(true);
|
||||
headerServiceView.setText("gurken");
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
drawer.closeDrawers();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void setupDrawerFooter() {
|
||||
ImageButton settings = findViewById(R.id.drawer_settings);
|
||||
ImageButton downloads = findViewById(R.id.drawer_downloads);
|
||||
ImageButton history = findViewById(R.id.drawer_history);
|
||||
|
||||
settings.setOnClickListener(view -> NavigationHelper.openSettings(this) );
|
||||
downloads.setOnClickListener(view -> NavigationHelper.openDownloads(this));
|
||||
settings.setOnClickListener(view -> NavigationHelper.openSettings(this));
|
||||
downloads.setOnClickListener(view ->NavigationHelper.openDownloads(this));
|
||||
history.setOnClickListener(view -> NavigationHelper.openHistory(this));
|
||||
}
|
||||
|
||||
private void setupDrawerHeader() {
|
||||
headerServiceView = findViewById(R.id.drawer_header_service_view);
|
||||
Button action = findViewById(R.id.drawer_header_action_button);
|
||||
action.setOnClickListener(view -> {
|
||||
Toast.makeText(this,
|
||||
R.string.drawer_header_action_paceholder_text, Toast.LENGTH_SHORT).show();
|
||||
drawer.closeDrawers();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
@ -148,6 +172,17 @@ public class MainActivity extends AppCompatActivity {
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
// close drawer on return, and don't show animation, so its looks like the drawer isn't open
|
||||
// when the user returns to MainActivity
|
||||
drawer.closeDrawer(Gravity.START, false);
|
||||
try {
|
||||
String selectedServiceName = NewPipe.getService(
|
||||
ServiceHelper.getSelectedServiceId(this)).getServiceInfo().getName();
|
||||
headerServiceView.setText(selectedServiceName);
|
||||
} catch (Exception e) {
|
||||
ErrorActivity.reportUiError(this, e);
|
||||
}
|
||||
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
if (sharedPreferences.getBoolean(Constants.KEY_THEME_CHANGE, false)) {
|
||||
if (DEBUG) Log.d(TAG, "Theme has changed, recreating activity...");
|
||||
|
BIN
app/src/main/res/drawable-nodpi/background_header.png
Normal file
BIN
app/src/main/res/drawable-nodpi/background_header.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
BIN
app/src/main/res/drawable-nodpi/np_logo_nude_shadow.png
Normal file
BIN
app/src/main/res/drawable-nodpi/np_logo_nude_shadow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.3 KiB |
@ -6,6 +6,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
@ -20,6 +21,6 @@
|
||||
<include layout="@layout/toolbar_layout" />
|
||||
</FrameLayout>
|
||||
|
||||
<include layout="@layout/drawer_laoyut"/>
|
||||
<include layout="@layout/drawer_layout"/>
|
||||
|
||||
</android.support.v4.widget.DrawerLayout>
|
@ -6,9 +6,11 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_gravity="start"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:background="?attr/android:windowBackground">
|
||||
android:background="?attr/android:windowBackground"
|
||||
android:clickable="true"
|
||||
android:focusable="true">
|
||||
|
||||
<View
|
||||
<RelativeLayout
|
||||
android:id="@+id/drawer_header"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="150dp"
|
||||
@ -16,7 +18,57 @@
|
||||
android:layout_alignRight="@id/navigation"
|
||||
android:layout_alignStart="@id/navigation"
|
||||
android:layout_alignEnd="@id/navigation"
|
||||
android:background="?attr/colorPrimary"/>
|
||||
android:clickable="true"
|
||||
android:focusable="true">
|
||||
|
||||
<Button
|
||||
android:id="@+id/drawer_header_action_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?android:attr/selectableItemBackground"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:src="@drawable/background_header"
|
||||
android:scaleType="centerCrop"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/drawer_header_np_nude_view"
|
||||
android:layout_marginLeft="30dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginTop="20dp"
|
||||
|
||||
android:layout_width="70dp"
|
||||
android:layout_height="70dp"
|
||||
android:src="@drawable/np_logo_nude_shadow"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/drawer_header_np_text_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:text="@string/app_name"
|
||||
android:layout_toRightOf="@id/drawer_header_np_nude_view"
|
||||
android:layout_toEndOf="@id/drawer_header_np_nude_view"
|
||||
android:layout_alignTop="@id/drawer_header_np_nude_view"
|
||||
android:layout_alignBottom="@id/drawer_header_np_nude_view"
|
||||
android:gravity="center"
|
||||
android:textSize="30dp"
|
||||
android:textStyle="bold|italic"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/drawer_header_service_view"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:text="YouTube"
|
||||
android:layout_below="@id/drawer_header_np_text_view"
|
||||
android:layout_alignLeft="@id/drawer_header_np_text_view"
|
||||
android:layout_alignStart="@id/drawer_header_np_text_view"
|
||||
android:textSize="18dp"
|
||||
android:textStyle="italic"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<android.support.design.widget.NavigationView
|
||||
android:id="@+id/navigation"
|
@ -366,6 +366,7 @@
|
||||
<string name="drawer_close">Close Drawer</string>
|
||||
<string name="youtube" translatable="false">YouTube</string>
|
||||
<string name="soundcloud" translatable="false">SoundCloud</string>
|
||||
<string name="drawer_header_action_paceholder_text">Something will come here soon ;D</string>
|
||||
|
||||
|
||||
<!-- Preferred player -->
|
||||
|
1252
assets/NewPipe_background_just1.svg
Normal file
1252
assets/NewPipe_background_just1.svg
Normal file
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 102 KiB |
Loading…
Reference in New Issue
Block a user