2016-07-26 13:50:52 +02:00
|
|
|
package org.schabi.newpipe;
|
|
|
|
|
2016-08-01 01:56:19 +02:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.net.Uri;
|
2016-07-26 13:50:52 +02:00
|
|
|
import android.os.Bundle;
|
2016-08-01 01:56:19 +02:00
|
|
|
import android.os.Handler;
|
|
|
|
import android.support.design.widget.CollapsingToolbarLayout;
|
2016-07-26 13:50:52 +02:00
|
|
|
import android.support.design.widget.FloatingActionButton;
|
|
|
|
import android.support.design.widget.Snackbar;
|
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
import android.support.v7.widget.Toolbar;
|
2016-08-01 01:56:19 +02:00
|
|
|
import android.util.Log;
|
2016-07-26 13:50:52 +02:00
|
|
|
import android.view.View;
|
2016-08-01 01:56:19 +02:00
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.ProgressBar;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
|
|
|
import com.nostra13.universalimageloader.core.assist.FailReason;
|
|
|
|
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
|
|
|
|
|
|
|
import org.schabi.newpipe.extractor.ChannelExtractor;
|
|
|
|
import org.schabi.newpipe.extractor.ChannelInfo;
|
|
|
|
import org.schabi.newpipe.extractor.ExtractionException;
|
|
|
|
import org.schabi.newpipe.extractor.ParsingException;
|
|
|
|
import org.schabi.newpipe.extractor.ServiceList;
|
|
|
|
import org.schabi.newpipe.extractor.StreamingService;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2016-07-26 13:50:52 +02:00
|
|
|
|
|
|
|
public class ChannelActivity extends AppCompatActivity {
|
|
|
|
|
2016-08-01 01:56:19 +02:00
|
|
|
private static final String TAG = ChannelActivity.class.toString();
|
|
|
|
private View rootView = null;
|
|
|
|
|
|
|
|
class FailedThumbnailListener implements ImageLoadingListener {
|
|
|
|
|
|
|
|
int serviceId = -1;
|
|
|
|
|
|
|
|
public FailedThumbnailListener(int serviceId) {
|
|
|
|
this.serviceId= serviceId;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoadingStarted(String imageUri, View view) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
|
|
|
ErrorActivity.reportError(ChannelActivity.this,
|
|
|
|
failReason.getCause(), null, rootView,
|
|
|
|
ErrorActivity.ErrorInfo.make(ErrorActivity.LOAD_IMAGE,
|
|
|
|
ServiceList.getNameOfService(serviceId), imageUri,
|
|
|
|
R.string.could_not_load_image));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoadingCancelled(String imageUri, View view) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// intent const
|
|
|
|
public static final String CHANNEL_URL = "channel_url";
|
|
|
|
public static final String SERVICE_ID = "service_id";
|
|
|
|
|
|
|
|
private int serviceId = -1;
|
|
|
|
private String channelUrl = "";
|
|
|
|
|
|
|
|
private ImageLoader imageLoader = ImageLoader.getInstance();
|
|
|
|
|
2016-07-26 13:50:52 +02:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_channel);
|
|
|
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
2016-08-01 01:56:19 +02:00
|
|
|
rootView = findViewById(R.id.rootView);
|
2016-07-26 13:50:52 +02:00
|
|
|
setSupportActionBar(toolbar);
|
2016-08-01 01:56:19 +02:00
|
|
|
Intent i = getIntent();
|
|
|
|
channelUrl = i.getStringExtra(CHANNEL_URL);
|
|
|
|
serviceId = i.getIntExtra(SERVICE_ID, -1);
|
|
|
|
|
|
|
|
// start processing
|
|
|
|
Thread channelExtractorThread = new Thread(new Runnable() {
|
|
|
|
Handler h = new Handler();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
StreamingService service = ServiceList.getService(serviceId);
|
|
|
|
ChannelExtractor extractor = service.getChannelExtractorInstance(
|
|
|
|
channelUrl, new Downloader());
|
|
|
|
|
|
|
|
final ChannelInfo info = ChannelInfo.getInfo(extractor, new Downloader());
|
|
|
|
|
|
|
|
|
|
|
|
h.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
updateUi(info);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch(IOException ioe) {
|
|
|
|
postNewErrorToast(h, R.string.network_error);
|
|
|
|
ioe.printStackTrace();
|
|
|
|
} catch(ParsingException pe) {
|
|
|
|
pe.printStackTrace();
|
|
|
|
} catch(ExtractionException ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
} catch(Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
channelExtractorThread.start();
|
|
|
|
}
|
|
|
|
|
2016-07-26 13:50:52 +02:00
|
|
|
|
2016-08-01 01:56:19 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
View channelContentView = (View) findViewById(R.id.channel_content_view);
|
|
|
|
FloatingActionButton feedButton = (FloatingActionButton) findViewById(R.id.channel_rss_fab);
|
2016-08-01 11:48:52 +02:00
|
|
|
ImageView avatarView = (ImageView) findViewById(R.id.channel_avatar_view);
|
|
|
|
ImageView haloView = (ImageView) findViewById(R.id.channel_avatar_halo);
|
2016-08-01 01:56:19 +02:00
|
|
|
|
|
|
|
progressBar.setVisibility(View.GONE);
|
|
|
|
channelContentView.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
if(info.channel_name != null && !info.channel_name.isEmpty()) {
|
|
|
|
ctl.setTitle(info.channel_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(info.banner_url != null && !info.banner_url.isEmpty()) {
|
|
|
|
imageLoader.displayImage(info.banner_url, channelBanner,
|
|
|
|
new FailedThumbnailListener(info.service_id));
|
|
|
|
}
|
|
|
|
|
2016-08-01 11:48:52 +02:00
|
|
|
if(info.avatar_url != null && !info.avatar_url.isEmpty()) {
|
|
|
|
avatarView.setVisibility(View.VISIBLE);
|
|
|
|
haloView.setVisibility(View.VISIBLE);
|
|
|
|
imageLoader.displayImage(info.avatar_url, avatarView,
|
|
|
|
new FailedThumbnailListener(info.service_id));
|
|
|
|
}
|
|
|
|
|
2016-08-01 01:56:19 +02:00
|
|
|
if(info.feed_url != null && !info.feed_url.isEmpty()) {
|
|
|
|
feedButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
Log.d(TAG, info.feed_url);
|
2016-08-01 02:10:38 +02:00
|
|
|
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(info.feed_url));
|
2016-08-01 01:56:19 +02:00
|
|
|
startActivity(i);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
feedButton.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void postNewErrorToast(Handler h, final int stringResource) {
|
|
|
|
h.post(new Runnable() {
|
2016-07-26 13:50:52 +02:00
|
|
|
@Override
|
2016-08-01 01:56:19 +02:00
|
|
|
public void run() {
|
|
|
|
Toast.makeText(ChannelActivity.this,
|
|
|
|
stringResource, Toast.LENGTH_LONG).show();
|
2016-07-26 13:50:52 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-08-01 01:56:19 +02:00
|
|
|
|
|
|
|
|
2016-07-26 13:50:52 +02:00
|
|
|
}
|