redesign channel activity
This commit is contained in:
parent
89e70626eb
commit
c14771534f
14 changed files with 528 additions and 162 deletions
|
|
@ -1,31 +1,21 @@
|
|||
package org.schabi.newpipe;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.design.widget.CollapsingToolbarLayout;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
|
||||
import org.schabi.newpipe.detail.VideoItemDetailActivity;
|
||||
import org.schabi.newpipe.detail.VideoItemDetailFragment;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.StreamingService;
|
||||
|
|
@ -39,10 +29,6 @@ import org.schabi.newpipe.report.ErrorActivity;
|
|||
import org.schabi.newpipe.util.NavStack;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import static android.os.Build.VERSION.SDK;
|
||||
import static android.os.Build.VERSION.SDK_INT;
|
||||
|
||||
/**
|
||||
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
|
||||
|
|
@ -62,7 +48,7 @@ import static android.os.Build.VERSION.SDK_INT;
|
|||
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
public class ChannelActivity extends AppCompatActivity {
|
||||
public class ChannelActivity extends ThemableActivity {
|
||||
private static final String TAG = ChannelActivity.class.toString();
|
||||
private View rootView = null;
|
||||
|
||||
|
|
@ -75,22 +61,17 @@ public class ChannelActivity extends AppCompatActivity {
|
|||
private ImageLoader imageLoader = ImageLoader.getInstance();
|
||||
private InfoListAdapter infoListAdapter = null;
|
||||
|
||||
private String subS = "";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//since we set themeing we have to set translucent statusBar by hand
|
||||
if (PreferenceManager.getDefaultSharedPreferences(this)
|
||||
.getString("theme", getResources().getString(R.string.light_theme_title)).
|
||||
equals(getResources().getString(R.string.dark_theme_title))) {
|
||||
setTheme(R.style.DarkTheme_NoActionBar);
|
||||
}
|
||||
setTranslucentStatusBar(getWindow());
|
||||
|
||||
setContentView(R.layout.activity_channel);
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
rootView = findViewById(R.id.rootView);
|
||||
setSupportActionBar(toolbar);
|
||||
rootView = findViewById(android.R.id.content);
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setDisplayShowTitleEnabled(true);
|
||||
if(savedInstanceState == null) {
|
||||
Intent i = getIntent();
|
||||
channelUrl = i.getStringExtra(NavStack.URL);
|
||||
|
|
@ -107,6 +88,7 @@ public class ChannelActivity extends AppCompatActivity {
|
|||
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.channel_streams_view);
|
||||
final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
infoListAdapter.setHeader(getLayoutInflater().inflate(R.layout.channel_header, recyclerView, false));
|
||||
recyclerView.setAdapter(infoListAdapter);
|
||||
infoListAdapter.setOnStreamInfoItemSelectedListener(
|
||||
new InfoItemBuilder.OnInfoItemSelectedListener() {
|
||||
|
|
@ -140,6 +122,8 @@ public class ChannelActivity extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
|
||||
subS = getString(R.string.subscriber);
|
||||
|
||||
requestData(false);
|
||||
}
|
||||
|
||||
|
|
@ -153,22 +137,24 @@ public class ChannelActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
private void updateUi(final ChannelInfo info) {
|
||||
CollapsingToolbarLayout ctl = (CollapsingToolbarLayout) findViewById(R.id.channel_toolbar_layout);
|
||||
ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
|
||||
ImageView channelBanner = (ImageView) findViewById(R.id.channel_banner_image);
|
||||
final FloatingActionButton feedButton = (FloatingActionButton) findViewById(R.id.channel_rss_fab);
|
||||
ImageView avatarView = (ImageView) findViewById(R.id.channel_avatar_view);
|
||||
ImageView haloView = (ImageView) findViewById(R.id.channel_avatar_halo);
|
||||
TextView titleView = (TextView) findViewById(R.id.channel_title_view);
|
||||
TextView subscirberView = (TextView) findViewById(R.id.channel_subscriber_view);
|
||||
Button subscriberButton = (Button) findViewById(R.id.channel_subscribe_button);
|
||||
|
||||
progressBar.setVisibility(View.GONE);
|
||||
|
||||
if(info.channel_name != null && !info.channel_name.isEmpty()) {
|
||||
ctl.setTitle(info.channel_name);
|
||||
getSupportActionBar().setTitle(info.channel_name);
|
||||
titleView.setText(info.channel_name);
|
||||
}
|
||||
|
||||
if(info.banner_url != null && !info.banner_url.isEmpty()) {
|
||||
imageLoader.displayImage(info.banner_url, channelBanner,
|
||||
new ImageErrorLoadingListener(this, rootView ,info.service_id));
|
||||
new ImageErrorLoadingListener(this, rootView ,info.service_id));
|
||||
}
|
||||
|
||||
if(info.avatar_url != null && !info.avatar_url.isEmpty()) {
|
||||
|
|
@ -178,8 +164,17 @@ public class ChannelActivity extends AppCompatActivity {
|
|||
new ImageErrorLoadingListener(this, rootView ,info.service_id));
|
||||
}
|
||||
|
||||
if(info.subscriberCount != -1) {
|
||||
subscirberView.setText(buildSubscriberString(info.subscriberCount));
|
||||
}
|
||||
|
||||
if((info.feed_url != null && !info.feed_url.isEmpty()) ||
|
||||
(info.subscriberCount != -1)) {
|
||||
findViewById(R.id.channel_subscriber_layout).setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if(info.feed_url != null && !info.feed_url.isEmpty()) {
|
||||
feedButton.setOnClickListener(new View.OnClickListener() {
|
||||
subscriberButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Log.d(TAG, info.feed_url);
|
||||
|
|
@ -188,8 +183,9 @@ public class ChannelActivity extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
} else {
|
||||
feedButton.setVisibility(View.GONE);
|
||||
subscriberButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void addVideos(final ChannelInfo info) {
|
||||
|
|
@ -297,30 +293,6 @@ public class ChannelActivity extends AppCompatActivity {
|
|||
channelExtractorThread.start();
|
||||
}
|
||||
|
||||
|
||||
// fix transparent statusbar fuckup (fuck google why can't they just leave something that worked
|
||||
// as it is, and everyone gets happy)
|
||||
public static void setTranslucentStatusBar(Window window) {
|
||||
if (window == null) return;
|
||||
int sdkInt = Build.VERSION.SDK_INT;
|
||||
if (sdkInt >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
setTranslucentStatusBarLollipop(window);
|
||||
} else if (sdkInt >= Build.VERSION_CODES.KITKAT) {
|
||||
setTranslucentStatusBarKiKat(window);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
private static void setTranslucentStatusBarLollipop(Window window) {
|
||||
window.setStatusBarColor(
|
||||
ContextCompat.getColor(window.getContext(), android.R.color.transparent));
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
private static void setTranslucentStatusBarKiKat(Window window) {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
try {
|
||||
|
|
@ -331,4 +303,19 @@ public class ChannelActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private String buildSubscriberString(long count) {
|
||||
String out = "";
|
||||
if(count >= 1000000000){
|
||||
out += Long.toString((count/1000000000)%1000)+".";
|
||||
}
|
||||
if(count>=1000000){
|
||||
out += Long.toString((count/1000000)%1000) + ".";
|
||||
}
|
||||
if(count>=1000){
|
||||
out += Long.toString((count/1000)%1000)+".";
|
||||
}
|
||||
out += Long.toString(count%1000) + " " + subS;
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue