2019-05-18 11:10:30 +02:00
|
|
|
package app.fedilab.android.drawers;
|
2018-09-29 09:58:46 +02:00
|
|
|
/* Copyright 2018 Thomas Schneider
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* This file is a part of Fedilab
|
2018-09-29 09:58:46 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
2018-09-29 09:58:46 +02:00
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
2018-09-29 09:58:46 +02:00
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.os.Bundle;
|
2019-09-06 17:55:14 +02:00
|
|
|
|
2019-06-11 19:38:26 +02:00
|
|
|
import androidx.core.content.ContextCompat;
|
2019-09-06 17:55:14 +02:00
|
|
|
|
2018-09-29 09:58:46 +02:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.BaseAdapter;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import com.bumptech.glide.Glide;
|
|
|
|
|
|
|
|
import java.util.List;
|
2018-09-29 14:11:42 +02:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
2018-09-29 09:58:46 +02:00
|
|
|
|
2019-05-18 11:10:30 +02:00
|
|
|
import app.fedilab.android.client.APIResponse;
|
|
|
|
import app.fedilab.android.client.Entities.HowToVideo;
|
|
|
|
import app.fedilab.android.helper.Helper;
|
|
|
|
import app.fedilab.android.R;
|
|
|
|
import app.fedilab.android.activities.WebviewActivity;
|
|
|
|
import app.fedilab.android.asynctasks.ManageListsAsyncTask;
|
|
|
|
import app.fedilab.android.interfaces.OnListActionInterface;
|
2018-09-29 09:58:46 +02:00
|
|
|
|
2019-05-18 11:10:30 +02:00
|
|
|
import static app.fedilab.android.helper.Helper.changeDrawableColor;
|
2018-09-29 09:58:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Thomas on 29/09/2018.
|
|
|
|
* Adapter for how to videos
|
|
|
|
*/
|
|
|
|
public class HowToVideosAdapter extends BaseAdapter implements OnListActionInterface {
|
|
|
|
|
|
|
|
private List<HowToVideo> howToVideos;
|
|
|
|
private Context context;
|
|
|
|
|
2019-09-06 17:55:14 +02:00
|
|
|
public HowToVideosAdapter(List<HowToVideo> howToVideos) {
|
2018-09-29 09:58:46 +02:00
|
|
|
this.howToVideos = howToVideos;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCount() {
|
|
|
|
return howToVideos.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getItem(int position) {
|
|
|
|
return howToVideos.get(position);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int position) {
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getView(final int position, View convertView, ViewGroup parent) {
|
|
|
|
|
2019-08-19 09:44:15 +02:00
|
|
|
context = parent.getContext();
|
2019-11-12 18:55:06 +01:00
|
|
|
LayoutInflater layoutInflater = LayoutInflater.from(context);
|
2018-09-29 09:58:46 +02:00
|
|
|
final HowToVideo howToVideo = howToVideos.get(position);
|
|
|
|
final ViewHolder holder;
|
|
|
|
if (convertView == null) {
|
|
|
|
convertView = layoutInflater.inflate(R.layout.drawer_how_to_videos, parent, false);
|
|
|
|
holder = new ViewHolder();
|
|
|
|
holder.how_to_description = convertView.findViewById(R.id.how_to_description);
|
2018-09-29 10:43:10 +02:00
|
|
|
holder.how_to_title = convertView.findViewById(R.id.how_to_title);
|
2018-09-29 09:58:46 +02:00
|
|
|
holder.how_to_image = convertView.findViewById(R.id.how_to_image);
|
|
|
|
holder.how_to_container = convertView.findViewById(R.id.how_to_container);
|
|
|
|
convertView.setTag(holder);
|
|
|
|
} else {
|
|
|
|
holder = (ViewHolder) convertView.getTag();
|
|
|
|
}
|
2019-11-12 18:55:06 +01:00
|
|
|
Helper.changeDrawableColor(context, R.drawable.ic_keyboard_arrow_right, R.attr.iconColorMenu);
|
2018-09-29 09:58:46 +02:00
|
|
|
Drawable next = ContextCompat.getDrawable(context, R.drawable.ic_keyboard_arrow_right);
|
|
|
|
holder.how_to_description.setText(howToVideo.getDescription());
|
2018-09-29 10:43:10 +02:00
|
|
|
holder.how_to_title.setText(howToVideo.getName());
|
2018-09-29 09:58:46 +02:00
|
|
|
assert next != null;
|
|
|
|
final float scale = context.getResources().getDisplayMetrics().density;
|
2019-09-06 17:55:14 +02:00
|
|
|
next.setBounds(0, 0, (int) (30 * scale + 0.5f), (int) (30 * scale + 0.5f));
|
2018-09-29 09:58:46 +02:00
|
|
|
holder.how_to_description.setCompoundDrawables(null, null, next, null);
|
|
|
|
Glide.with(holder.how_to_image.getContext())
|
2019-07-13 17:51:05 +02:00
|
|
|
.load("https://peertube.fedilab.app" + howToVideo.getThumbnailPath())
|
2018-09-29 09:58:46 +02:00
|
|
|
.into(holder.how_to_image);
|
|
|
|
holder.how_to_container.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent intent = new Intent(context, WebviewActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
2019-07-13 17:51:05 +02:00
|
|
|
String finalUrl = "https://peertube.fedilab.app" + howToVideo.getEmbedPath();
|
2018-09-29 09:58:46 +02:00
|
|
|
b.putString("url", finalUrl);
|
2018-09-29 14:11:42 +02:00
|
|
|
b.putBoolean("peertubeLink", true);
|
|
|
|
Pattern link = Pattern.compile("(https?:\\/\\/[\\da-z\\.-]+\\.[a-z\\.]{2,10})\\/videos\\/embed\\/(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})$");
|
|
|
|
Matcher matcherLink = link.matcher(finalUrl);
|
2019-09-06 17:55:14 +02:00
|
|
|
if (matcherLink.find()) {
|
2018-09-29 14:11:42 +02:00
|
|
|
String url = matcherLink.group(1) + "/videos/watch/" + matcherLink.group(2);
|
|
|
|
b.putString("peertubeLinkToFetch", url);
|
|
|
|
}
|
2018-09-29 09:58:46 +02:00
|
|
|
intent.putExtras(b);
|
|
|
|
context.startActivity(intent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return convertView;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActionDone(ManageListsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private class ViewHolder {
|
|
|
|
LinearLayout how_to_container;
|
|
|
|
ImageView how_to_image;
|
|
|
|
TextView how_to_description;
|
2018-09-29 10:43:10 +02:00
|
|
|
TextView how_to_title;
|
2018-09-29 09:58:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|