make service items in drawer be dynamicly generated
This commit is contained in:
parent
1af6dc614a
commit
fae777c14c
|
@ -44,7 +44,6 @@ 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.TextView;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
|
@ -94,7 +93,15 @@ public class MainActivity extends AppCompatActivity {
|
||||||
drawer = findViewById(R.id.drawer_layout);
|
drawer = findViewById(R.id.drawer_layout);
|
||||||
drawerItems = findViewById(R.id.navigation);
|
drawerItems = findViewById(R.id.navigation);
|
||||||
|
|
||||||
//drawerItems.setItemIconTintList(null); // Set null to use the original icon
|
for(StreamingService s : NewPipe.getServices()) {
|
||||||
|
String title =
|
||||||
|
s.getServiceInfo().getName() +
|
||||||
|
(ServiceHelper.isBeta(s) ? " (beta)" : "");
|
||||||
|
MenuItem item = drawerItems.getMenu()
|
||||||
|
.add(R.id.menu_services_group, s.getServiceId(), 0, title);
|
||||||
|
item.setIcon(ServiceHelper.getIcon(s.getServiceId()));
|
||||||
|
}
|
||||||
|
|
||||||
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(true);
|
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(true);
|
||||||
|
|
||||||
toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.drawer_open, R.string.drawer_close);
|
toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.drawer_open, R.string.drawer_close);
|
||||||
|
@ -126,9 +133,8 @@ public class MainActivity extends AppCompatActivity {
|
||||||
private boolean changeService(MenuItem item) {
|
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.getItemId());
|
||||||
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(true);
|
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(true);
|
||||||
headerServiceView.setText("gurken");
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,4 +109,11 @@ public class ServiceHelper {
|
||||||
return TimeUnit.MILLISECONDS.convert(1, TimeUnit.HOURS);
|
return TimeUnit.MILLISECONDS.convert(1, TimeUnit.HOURS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isBeta(final StreamingService s) {
|
||||||
|
switch(s.getServiceInfo().getName()) {
|
||||||
|
case "YouTube": return false;
|
||||||
|
default: return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,8 +75,8 @@
|
||||||
android:layout_below="@id/drawer_header"
|
android:layout_below="@id/drawer_header"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:menu="@menu/drawer_items"
|
|
||||||
app:elevation="0dp"/>
|
app:elevation="0dp"/>
|
||||||
|
<!-- app:menu="@menu/drawer_items" -->
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/navigation_drawer_footer"
|
android:id="@+id/navigation_drawer_footer"
|
||||||
|
|
Loading…
Reference in New Issue