How to video with peertube API
This commit is contained in:
parent
5e4f0c28dc
commit
ea063bf343
|
@ -96,6 +96,7 @@ import fr.gouv.etalab.mastodon.fragments.DisplayBookmarksFragment;
|
||||||
import fr.gouv.etalab.mastodon.fragments.DisplayDraftsFragment;
|
import fr.gouv.etalab.mastodon.fragments.DisplayDraftsFragment;
|
||||||
import fr.gouv.etalab.mastodon.fragments.DisplayFiltersFragment;
|
import fr.gouv.etalab.mastodon.fragments.DisplayFiltersFragment;
|
||||||
import fr.gouv.etalab.mastodon.fragments.DisplayFollowRequestSentFragment;
|
import fr.gouv.etalab.mastodon.fragments.DisplayFollowRequestSentFragment;
|
||||||
|
import fr.gouv.etalab.mastodon.fragments.DisplayHowToFragment;
|
||||||
import fr.gouv.etalab.mastodon.fragments.DisplayListsFragment;
|
import fr.gouv.etalab.mastodon.fragments.DisplayListsFragment;
|
||||||
import fr.gouv.etalab.mastodon.fragments.DisplayMutedInstanceFragment;
|
import fr.gouv.etalab.mastodon.fragments.DisplayMutedInstanceFragment;
|
||||||
import fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment;
|
import fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment;
|
||||||
|
@ -1494,6 +1495,12 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
fragmentTag = "BLOCKED_DOMAINS";
|
fragmentTag = "BLOCKED_DOMAINS";
|
||||||
fragmentManager.beginTransaction()
|
fragmentManager.beginTransaction()
|
||||||
.replace(R.id.main_app_container, displayMutedInstanceFragment, fragmentTag).commit();
|
.replace(R.id.main_app_container, displayMutedInstanceFragment, fragmentTag).commit();
|
||||||
|
}else if (id == R.id.nav_how_to) {
|
||||||
|
toot.hide();
|
||||||
|
DisplayHowToFragment displayHowToFragment = new DisplayHowToFragment();
|
||||||
|
fragmentTag = "HOW_TO_VIDEOS";
|
||||||
|
fragmentManager.beginTransaction()
|
||||||
|
.replace(R.id.main_app_container, displayHowToFragment, fragmentTag).commit();
|
||||||
}else if (id == R.id.nav_muted) {
|
}else if (id == R.id.nav_muted) {
|
||||||
toot.hide();
|
toot.hide();
|
||||||
accountsFragment = new DisplayAccountsFragment();
|
accountsFragment = new DisplayAccountsFragment();
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
/* Copyright 2018 Thomas Schneider
|
||||||
|
*
|
||||||
|
* This file is a part of Mastalab
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||||
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
package fr.gouv.etalab.mastodon.asynctasks;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
import fr.gouv.etalab.mastodon.client.API;
|
||||||
|
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||||
|
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveHowToInterface;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Thomas on 29/09/2018.
|
||||||
|
* Retrieves how to videos
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class RetrieveHowToAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
|
|
||||||
|
private APIResponse apiResponse;
|
||||||
|
private OnRetrieveHowToInterface listener;
|
||||||
|
private WeakReference<Context> contextReference;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public RetrieveHowToAsyncTask(Context context, OnRetrieveHowToInterface onRetrieveHowToInterface){
|
||||||
|
this.contextReference = new WeakReference<>(context);
|
||||||
|
this.listener = onRetrieveHowToInterface;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... params) {
|
||||||
|
API api = new API(this.contextReference.get());
|
||||||
|
apiResponse = api.getHowTo();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void result) {
|
||||||
|
listener.onRetrieveHowTo(apiResponse);
|
||||||
|
}
|
||||||
|
}
|
|
@ -549,6 +549,33 @@ public class API {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves home timeline for the account *synchronously*
|
||||||
|
* @return APIResponse
|
||||||
|
*/
|
||||||
|
public APIResponse getHowTo() {
|
||||||
|
|
||||||
|
List<HowToVideo> howToVideos = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||||
|
String response = httpsConnection.get("https://peertube.fr/api/v1/video-channels/bb32394a-a6d2-4f41-9b8e-ad9514a66009/videos", 60, null, null);
|
||||||
|
JSONArray jsonArray = new JSONObject(response).getJSONArray("data");
|
||||||
|
howToVideos = parseHowTos(jsonArray);
|
||||||
|
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||||
|
setError(e.getStatusCode(), e);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (KeyManagementException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
apiResponse.setHowToVideos(howToVideos);
|
||||||
|
return apiResponse;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Retrieves public timeline for the account *synchronously*
|
* Retrieves public timeline for the account *synchronously*
|
||||||
* @param local boolean only local timeline
|
* @param local boolean only local timeline
|
||||||
|
@ -2134,6 +2161,52 @@ public class API {
|
||||||
}
|
}
|
||||||
return list_tmp;
|
return list_tmp;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Parse json response for several howto
|
||||||
|
* @param jsonArray JSONArray
|
||||||
|
* @return List<HowToVideo>
|
||||||
|
*/
|
||||||
|
private List<HowToVideo> parseHowTos(JSONArray jsonArray){
|
||||||
|
|
||||||
|
List<HowToVideo> howToVideos = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
int i = 0;
|
||||||
|
while (i < jsonArray.length() ){
|
||||||
|
|
||||||
|
JSONObject resobj = jsonArray.getJSONObject(i);
|
||||||
|
HowToVideo howToVideo = parseHowTo(context, resobj);
|
||||||
|
i++;
|
||||||
|
howToVideos.add(howToVideo);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (JSONException e) {
|
||||||
|
setDefaultError(e);
|
||||||
|
}
|
||||||
|
return howToVideos;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse json response for unique how to
|
||||||
|
* @param resobj JSONObject
|
||||||
|
* @return HowToVideo
|
||||||
|
*/
|
||||||
|
private static HowToVideo parseHowTo(Context context, JSONObject resobj){
|
||||||
|
HowToVideo howToVideo = new HowToVideo();
|
||||||
|
try {
|
||||||
|
howToVideo.setId(resobj.get("id").toString());
|
||||||
|
howToVideo.setUuid(resobj.get("uuid").toString());
|
||||||
|
howToVideo.setName(resobj.get("name").toString());
|
||||||
|
howToVideo.setDescription(resobj.get("description").toString());
|
||||||
|
howToVideo.setEmbedPath(resobj.get("embedPath").toString());
|
||||||
|
howToVideo.setPreviewPath(resobj.get("previewPath").toString());
|
||||||
|
howToVideo.setThumbnailPath(resobj.get("thumbnailPath").toString());
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return howToVideo;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse json response for several status
|
* Parse json response for several status
|
||||||
* @param jsonArray JSONArray
|
* @param jsonArray JSONArray
|
||||||
|
@ -2750,4 +2823,5 @@ public class API {
|
||||||
private String getAbsoluteUrlCommunitywiki(String action) {
|
private String getAbsoluteUrlCommunitywiki(String action) {
|
||||||
return "https://communitywiki.org/trunk/api/v1" + action;
|
return "https://communitywiki.org/trunk/api/v1" + action;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ public class APIResponse {
|
||||||
private List<Context> contexts = null;
|
private List<Context> contexts = null;
|
||||||
private List<Notification> notifications = null;
|
private List<Notification> notifications = null;
|
||||||
private List<Relationship> relationships = null;
|
private List<Relationship> relationships = null;
|
||||||
|
private List<HowToVideo> howToVideos = null;
|
||||||
private List<Filters> filters = null;
|
private List<Filters> filters = null;
|
||||||
private List<String> domains = null;
|
private List<String> domains = null;
|
||||||
private List<fr.gouv.etalab.mastodon.client.Entities.List> lists = null;
|
private List<fr.gouv.etalab.mastodon.client.Entities.List> lists = null;
|
||||||
|
@ -141,4 +142,12 @@ public class APIResponse {
|
||||||
public void setDomains(List<String> domains) {
|
public void setDomains(List<String> domains) {
|
||||||
this.domains = domains;
|
this.domains = domains;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<HowToVideo> getHowToVideos() {
|
||||||
|
return howToVideos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHowToVideos(List<HowToVideo> howToVideos) {
|
||||||
|
this.howToVideos = howToVideos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
/* Copyright 2018 Thomas Schneider
|
||||||
|
*
|
||||||
|
* This file is a part of Mastalab
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||||
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
package fr.gouv.etalab.mastodon.client.Entities;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Thomas on 29/09/2018.
|
||||||
|
* Manage how to videos
|
||||||
|
*/
|
||||||
|
public class HowToVideo {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private String uuid;
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
private String thumbnailPath;
|
||||||
|
private String previewPath;
|
||||||
|
private String embedPath;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUuid() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUuid(String uuid) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getThumbnailPath() {
|
||||||
|
return thumbnailPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThumbnailPath(String thumbnailPath) {
|
||||||
|
this.thumbnailPath = thumbnailPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPreviewPath() {
|
||||||
|
return previewPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPreviewPath(String previewPath) {
|
||||||
|
this.previewPath = previewPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmbedPath() {
|
||||||
|
return embedPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmbedPath(String embedPath) {
|
||||||
|
this.embedPath = embedPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,148 @@
|
||||||
|
package fr.gouv.etalab.mastodon.drawers;
|
||||||
|
/* Copyright 2018 Thomas Schneider
|
||||||
|
*
|
||||||
|
* This file is a part of Mastalab
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||||
|
* 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;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
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.RelativeLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import fr.gouv.etalab.mastodon.R;
|
||||||
|
import fr.gouv.etalab.mastodon.activities.ListActivity;
|
||||||
|
import fr.gouv.etalab.mastodon.activities.WebviewActivity;
|
||||||
|
import fr.gouv.etalab.mastodon.asynctasks.ManageListsAsyncTask;
|
||||||
|
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||||
|
import fr.gouv.etalab.mastodon.client.Entities.HowToVideo;
|
||||||
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||||
|
import fr.gouv.etalab.mastodon.interfaces.OnListActionInterface;
|
||||||
|
|
||||||
|
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Thomas on 29/09/2018.
|
||||||
|
* Adapter for how to videos
|
||||||
|
*/
|
||||||
|
public class HowToVideosAdapter extends BaseAdapter implements OnListActionInterface {
|
||||||
|
|
||||||
|
private List<HowToVideo> howToVideos;
|
||||||
|
private LayoutInflater layoutInflater;
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
public HowToVideosAdapter(Context context, List<HowToVideo> howToVideos){
|
||||||
|
this.howToVideos = howToVideos;
|
||||||
|
layoutInflater = LayoutInflater.from(context);
|
||||||
|
this.context = context;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@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) {
|
||||||
|
|
||||||
|
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);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||||
|
|
||||||
|
if( theme == Helper.THEME_LIGHT){
|
||||||
|
holder.how_to_container.setBackgroundResource(R.color.mastodonC3__);
|
||||||
|
changeDrawableColor(context, R.drawable.ic_keyboard_arrow_right,R.color.black);
|
||||||
|
}else if(theme == Helper.THEME_DARK){
|
||||||
|
holder.how_to_container.setBackgroundResource(R.color.mastodonC1_);
|
||||||
|
changeDrawableColor(context, R.drawable.ic_keyboard_arrow_right,R.color.dark_text);
|
||||||
|
}else if(theme == Helper.THEME_BLACK) {
|
||||||
|
holder.how_to_container.setBackgroundResource(R.color.black_2);
|
||||||
|
changeDrawableColor(context, R.drawable.ic_keyboard_arrow_right,R.color.dark_text);
|
||||||
|
}
|
||||||
|
Drawable next = ContextCompat.getDrawable(context, R.drawable.ic_keyboard_arrow_right);
|
||||||
|
holder.how_to_description.setText(howToVideo.getDescription());
|
||||||
|
assert next != null;
|
||||||
|
final float scale = context.getResources().getDisplayMetrics().density;
|
||||||
|
next.setBounds(0,0,(int) (30 * scale + 0.5f),(int) (30 * scale + 0.5f));
|
||||||
|
holder.how_to_description.setCompoundDrawables(null, null, next, null);
|
||||||
|
Glide.with(holder.how_to_image.getContext())
|
||||||
|
.load(howToVideo.getThumbnailPath())
|
||||||
|
.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();
|
||||||
|
String finalUrl = "https://peertube.fr/" + howToVideo.getEmbedPath();
|
||||||
|
b.putString("url", finalUrl);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,107 @@
|
||||||
|
package fr.gouv.etalab.mastodon.fragments;
|
||||||
|
/* Copyright 2018 Thomas Schneider
|
||||||
|
*
|
||||||
|
* This file is a part of Mastalab
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||||
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
import android.widget.Toast;
|
||||||
|
import java.util.List;
|
||||||
|
import fr.gouv.etalab.mastodon.R;
|
||||||
|
import fr.gouv.etalab.mastodon.asynctasks.RetrieveHowToAsyncTask;
|
||||||
|
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||||
|
import fr.gouv.etalab.mastodon.client.Entities.HowToVideo;
|
||||||
|
import fr.gouv.etalab.mastodon.drawers.HowToVideosAdapter;
|
||||||
|
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveHowToInterface;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Thomas on 29/09/2018.
|
||||||
|
* Fragment to display how to videos
|
||||||
|
*/
|
||||||
|
public class DisplayHowToFragment extends Fragment implements OnRetrieveHowToInterface {
|
||||||
|
|
||||||
|
|
||||||
|
private Context context;
|
||||||
|
private AsyncTask<Void, Void, Void> asyncTask;
|
||||||
|
|
||||||
|
private RelativeLayout mainLoader;
|
||||||
|
private ListView lv_howto;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
//View for fragment is the same that fragment accounts
|
||||||
|
View rootView = inflater.inflate(R.layout.fragment_how_to, container, false);
|
||||||
|
|
||||||
|
context = getContext();
|
||||||
|
lv_howto = rootView.findViewById(R.id.lv_howto);
|
||||||
|
mainLoader = rootView.findViewById(R.id.loader);
|
||||||
|
mainLoader.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
asyncTask = new RetrieveHowToAsyncTask(context, DisplayHowToFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
|
||||||
|
|
||||||
|
return rootView;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle saveInstance)
|
||||||
|
{
|
||||||
|
super.onCreate(saveInstance);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
if(asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING)
|
||||||
|
asyncTask.cancel(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRetrieveHowTo(APIResponse apiResponse) {
|
||||||
|
mainLoader.setVisibility(View.GONE);
|
||||||
|
if( apiResponse.getError() != null){
|
||||||
|
Toast.makeText(context, apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<HowToVideo> howToVideos = apiResponse.getHowToVideos();
|
||||||
|
if( howToVideos == null || howToVideos.size() == 0 ){
|
||||||
|
Toast.makeText(context, R.string.toast_error,Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
HowToVideosAdapter howToVideosAdapter = new HowToVideosAdapter(context, howToVideos);
|
||||||
|
lv_howto.setAdapter(howToVideosAdapter);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
/* Copyright 2018 Thomas Schneider
|
||||||
|
*
|
||||||
|
* This file is a part of Mastalab
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||||
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
package fr.gouv.etalab.mastodon.interfaces;
|
||||||
|
|
||||||
|
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Thomas on 29/09/2018.
|
||||||
|
* Interface when how to videos have been retrieved
|
||||||
|
*/
|
||||||
|
public interface OnRetrieveHowToInterface {
|
||||||
|
void onRetrieveHowTo(APIResponse apiResponse);
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 155 B |
Binary file not shown.
After Width: | Height: | Size: 216 B |
Binary file not shown.
After Width: | Height: | Size: 133 B |
Binary file not shown.
After Width: | Height: | Size: 173 B |
Binary file not shown.
After Width: | Height: | Size: 234 B |
Binary file not shown.
After Width: | Height: | Size: 252 B |
|
@ -0,0 +1,44 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright 2018 Thomas Schneider
|
||||||
|
|
||||||
|
This file is a part of Mastalab
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||||
|
see <http://www.gnu.org/licenses>.
|
||||||
|
-->
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/how_to_container"
|
||||||
|
android:divider="?android:dividerHorizontal"
|
||||||
|
android:showDividers="end"
|
||||||
|
android:paddingTop="5dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/how_to_image"
|
||||||
|
android:layout_width="200dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
/>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/how_to_description"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:paddingBottom="10dp"
|
||||||
|
android:paddingTop="10dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:layout_marginBottom="5dp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
</LinearLayout>
|
|
@ -0,0 +1,45 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright 2018 Thomas Schneider
|
||||||
|
|
||||||
|
This file is a part of Mastalab
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||||
|
see <http://www.gnu.org/licenses>.
|
||||||
|
-->
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:paddingLeft="@dimen/fab_margin"
|
||||||
|
android:paddingRight="@dimen/fab_margin"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
<!-- Listview list -->
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/lv_howto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:scrollbars="none"
|
||||||
|
android:divider="@null"
|
||||||
|
/>
|
||||||
|
<!-- Main Loader -->
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/loader"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center"
|
||||||
|
>
|
||||||
|
<ProgressBar
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:indeterminate="true" />
|
||||||
|
</RelativeLayout>
|
||||||
|
</RelativeLayout>
|
||||||
|
|
|
@ -71,6 +71,10 @@
|
||||||
android:id="@+id/nav_blocked_domains"
|
android:id="@+id/nav_blocked_domains"
|
||||||
android:icon="@drawable/ic_block"
|
android:icon="@drawable/ic_block"
|
||||||
android:title="@string/blocked_domains" />
|
android:title="@string/blocked_domains" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/nav_how_to"
|
||||||
|
android:icon="@drawable/ic_videocam"
|
||||||
|
android:title="@string/how_to_videos" />
|
||||||
</group>
|
</group>
|
||||||
</menu>
|
</menu>
|
||||||
</item>
|
</item>
|
||||||
|
|
Loading…
Reference in New Issue