mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-22 11:02:35 +01:00
add inital drawer hader layout
This commit is contained in:
parent
cc02b01c2b
commit
3e5e7f49cc
@ -37,12 +37,14 @@ import android.support.v7.app.ActionBarDrawerToggle;
|
|||||||
import android.support.v7.app.AppCompatActivity;
|
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.Gravity;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
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");
|
public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release");
|
||||||
|
|
||||||
private ActionBarDrawerToggle toggle = null;
|
private ActionBarDrawerToggle toggle = null;
|
||||||
|
private DrawerLayout drawer = null;
|
||||||
|
private NavigationView drawerItems = null;
|
||||||
|
private TextView headerServiceView = null;
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Activity's LifeCycle
|
// Activity's LifeCycle
|
||||||
@ -81,13 +86,12 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
setSupportActionBar(findViewById(R.id.toolbar));
|
setSupportActionBar(findViewById(R.id.toolbar));
|
||||||
setupDrawer();
|
setupDrawer();
|
||||||
setupDrawerFooter();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupDrawer() {
|
private void setupDrawer() {
|
||||||
final Toolbar toolbar = findViewById(R.id.toolbar);
|
final Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
final DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
drawer = findViewById(R.id.drawer_layout);
|
||||||
final NavigationView drawerItems = findViewById(R.id.navigation);
|
drawerItems = findViewById(R.id.navigation);
|
||||||
|
|
||||||
//drawerItems.setItemIconTintList(null); // Set null to use the original icon
|
//drawerItems.setItemIconTintList(null); // Set null to use the original icon
|
||||||
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(true);
|
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(true);
|
||||||
@ -112,18 +116,26 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
drawerItems.setNavigationItemSelectedListener(item -> {
|
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) {
|
if (item.getGroupId() == R.id.menu_services_group) {
|
||||||
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(false);
|
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(false);
|
||||||
ServiceHelper.setSelectedServiceId(this, item.getTitle().toString());
|
ServiceHelper.setSelectedServiceId(this, item.getTitle().toString());
|
||||||
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(true);
|
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(true);
|
||||||
|
headerServiceView.setText("gurken");
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
drawer.closeDrawers();
|
drawer.closeDrawers();
|
||||||
return true;
|
return true;
|
||||||
});
|
|
||||||
} else {
|
|
||||||
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupDrawerFooter() {
|
private void setupDrawerFooter() {
|
||||||
@ -136,6 +148,13 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
history.setOnClickListener(view -> NavigationHelper.openHistory(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
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
@ -148,6 +167,10 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.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);
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
if (sharedPreferences.getBoolean(Constants.KEY_THEME_CHANGE, false)) {
|
if (sharedPreferences.getBoolean(Constants.KEY_THEME_CHANGE, false)) {
|
||||||
if (DEBUG) Log.d(TAG, "Theme has changed, recreating activity...");
|
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,9 +6,11 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_gravity="start"
|
android:layout_gravity="start"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
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:id="@+id/drawer_header"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="150dp"
|
android:layout_height="150dp"
|
||||||
@ -16,7 +18,57 @@
|
|||||||
android:layout_alignRight="@id/navigation"
|
android:layout_alignRight="@id/navigation"
|
||||||
android:layout_alignStart="@id/navigation"
|
android:layout_alignStart="@id/navigation"
|
||||||
android:layout_alignEnd="@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.support.design.widget.NavigationView
|
||||||
android:id="@+id/navigation"
|
android:id="@+id/navigation"
|
||||||
|
@ -366,6 +366,7 @@
|
|||||||
<string name="drawer_close">Close Drawer</string>
|
<string name="drawer_close">Close Drawer</string>
|
||||||
<string name="youtube" translatable="false">YouTube</string>
|
<string name="youtube" translatable="false">YouTube</string>
|
||||||
<string name="soundcloud" translatable="false">SoundCloud</string>
|
<string name="soundcloud" translatable="false">SoundCloud</string>
|
||||||
|
<string name="drawer_header_action_paceholder_text">Something will come here soon ;D</string>
|
||||||
|
|
||||||
|
|
||||||
<!-- Preferred player -->
|
<!-- Preferred player -->
|
||||||
|
Loading…
Reference in New Issue
Block a user