1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-25 04:22:30 +01:00

add inital drawer hader layout

This commit is contained in:
Christian Schabesberger 2018-02-16 23:56:04 +01:00
parent cc02b01c2b
commit 3e5e7f49cc
5 changed files with 93 additions and 17 deletions

View File

@ -37,12 +37,14 @@ 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.StreamingService;
@ -61,6 +63,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 +86,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 +116,45 @@ 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());
}
@Override
protected void onDestroy() {
super.onDestroy();
@ -148,6 +167,10 @@ 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);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
if (sharedPreferences.getBoolean(Constants.KEY_THEME_CHANGE, false)) {
if (DEBUG) Log.d(TAG, "Theme has changed, recreating activity...");

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@ -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"

View File

@ -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 -->