some checks

This commit is contained in:
Thomas 2020-10-03 16:22:19 +02:00
parent 30d344987c
commit 8548777c50
11 changed files with 183 additions and 85 deletions

View File

@ -9,4 +9,10 @@
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>

View File

@ -8,4 +8,10 @@
<item name="colorAccent">@color/colorAccent_full</item>
</style>
<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary_full</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark_full</item>
<item name="colorAccent">@color/colorAccent_full</item>
</style>
</resources>

View File

@ -27,8 +27,10 @@
tools:replace="android:allowBackup">
<activity
android:name=".MainActivity"
android:theme="@style/AppThemeNoActionBar"
android:configChanges="orientation|screenSize"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

View File

@ -31,6 +31,7 @@ import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.navigation.NavController;
import androidx.navigation.NavGraph;
import androidx.navigation.NavInflater;
@ -75,6 +76,8 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
BottomNavigationView navView = findViewById(R.id.nav_view);
if (Helper.isLoggedIn(MainActivity.this)) {

View File

@ -98,15 +98,14 @@ import app.fedilab.fedilabtube.client.data.PlaylistData.Playlist;
import app.fedilab.fedilabtube.client.data.VideoData;
import app.fedilab.fedilabtube.client.entities.File;
import app.fedilab.fedilabtube.client.entities.ItemStr;
import app.fedilab.fedilabtube.client.entities.PlaylistExist;
import app.fedilab.fedilabtube.client.entities.Report;
import app.fedilab.fedilabtube.drawer.CommentListAdapter;
import app.fedilab.fedilabtube.fragment.DisplayAccountsFragment;
import app.fedilab.fedilabtube.helper.CacheDataSourceFactory;
import app.fedilab.fedilabtube.helper.FullScreenMediaController;
import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.sqlite.AccountDAO;
import app.fedilab.fedilabtube.sqlite.Sqlite;
import app.fedilab.fedilabtube.viewmodel.AccountsVM;
import app.fedilab.fedilabtube.viewmodel.CaptionsVM;
import app.fedilab.fedilabtube.viewmodel.CommentVM;
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
@ -125,7 +124,6 @@ import static app.fedilab.fedilabtube.helper.Helper.getAttColor;
import static app.fedilab.fedilabtube.helper.Helper.getLiveInstance;
import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn;
import static app.fedilab.fedilabtube.viewmodel.PlaylistsVM.action.GET_PLAYLISTS;
import static app.fedilab.fedilabtube.viewmodel.PlaylistsVM.action.GET_PLAYLIST_FOR_VIDEO;
public class PeertubeActivity extends AppCompatActivity implements CommentListAdapter.AllCommentRemoved {
@ -148,7 +146,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
private ImageView send;
private TextView add_comment_read;
private EditText add_comment_write;
private List<Playlist> playlistForVideo;
private List<String> playlistForVideo;
private List<Playlist> playlists;
private PlaylistsVM playlistsViewModel;
private boolean playInMinimized;
@ -365,7 +363,11 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
peertube_playlist.setVisibility(View.VISIBLE);
peertube_bookmark.setVisibility(View.GONE);
List<String> videoIds = new ArrayList<>();
videoIds.add(videoId);
if (Helper.isLoggedIn(PeertubeActivity.this)) {
playlistsViewModel.videoExists(videoIds).observe(PeertubeActivity.this, this::manageVIewVideosExist);
}
TimelineVM feedsViewModel = new ViewModelProvider(PeertubeActivity.this).get(TimelineVM.class);
feedsViewModel.getVideo(videoId).observe(PeertubeActivity.this, this::manageVIewVideo);
CaptionsVM captionsViewModel = new ViewModelProvider(PeertubeActivity.this).get(CaptionsVM.class);
@ -509,8 +511,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
peertube = apiResponse.getPeertubes().get(0);
//TODO: currently streaming service gives the wrong values for duration
playlistsViewModel.manage(GET_PLAYLIST_FOR_VIDEO, null, peertube.getId()).observe(PeertubeActivity.this, apiResponse2 -> manageVIewPlaylists(GET_PLAYLIST_FOR_VIDEO, apiResponse2));
add_comment_read.setOnClickListener(v -> {
if (isLoggedIn(PeertubeActivity.this)) {
@ -550,13 +552,11 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
String title = null;
boolean isPresent = false;
String elementId = null;
Playlist playlistElementFinal = null;
for (Playlist playlistElement : playlistForVideo) {
if (playlist.getId().equals(playlistElement.getId())) {
for (String playlistId : playlistForVideo) {
if (playlist.getId().compareTo(playlistId) == 0) {
title = "" + playlist.getDisplayName();
isPresent = true;
elementId = playlistElement.getId();
playlistElementFinal = playlistElement;
elementId = playlistId;
break;
}
}
@ -566,7 +566,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
MenuItem item = popup.getMenu().add(0, 0, Menu.NONE, title);
boolean finalIsPresent = isPresent;
String finalElementId = elementId;
Playlist finalPlaylistElementFinal = playlistElementFinal;
item.setOnMenuItemClickListener(item1 -> {
item1.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
item1.setActionView(new View(PeertubeActivity.this));
@ -584,13 +583,11 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
if (finalIsPresent) {
item1.setTitle(playlist.getDisplayName());
playlistsViewModel.manage(PlaylistsVM.action.DELETE_VIDEOS, playlist, finalElementId).observe(PeertubeActivity.this, apiResponse3 -> manageVIewPlaylists(PlaylistsVM.action.DELETE_VIDEOS, apiResponse3));
playlistForVideo.remove(finalPlaylistElementFinal);
playlistForVideo.remove(playlist.getId());
} else {
item1.setTitle("" + playlist.getDisplayName());
playlistsViewModel.manage(PlaylistsVM.action.ADD_VIDEOS, playlist, peertube.getId()).observe(PeertubeActivity.this, apiResponse3 -> manageVIewPlaylists(PlaylistsVM.action.ADD_VIDEOS, apiResponse3));
Playlist playlistElement = new Playlist();
playlistElement.setId(playlist.getId());
playlistForVideo.add(playlistElement);
playlistForVideo.add(playlist.getId());
}
return false;
});
@ -1078,13 +1075,22 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
public void manageVIewPlaylists(PlaylistsVM.action actionType, APIResponse apiResponse) {
if (actionType == GET_PLAYLIST_FOR_VIDEO && apiResponse != null) {
playlistForVideo = apiResponse.getPlaylists();
} else if (actionType == GET_PLAYLISTS && apiResponse != null) {
if (actionType == GET_PLAYLISTS && apiResponse != null) {
playlists = apiResponse.getPlaylists();
}
}
public void manageVIewVideosExist(APIResponse apiResponse) {
playlistForVideo = new ArrayList<>();
if( apiResponse.getError() == null && apiResponse.getVideoExistPlaylist() != null) {
List<PlaylistExist.VideoId> videoIds = apiResponse.getVideoExistPlaylist();
for(PlaylistExist.VideoId videoId: videoIds) {
playlistForVideo.add(videoId.getPlaylistId());
}
}
}
@Override
public void onAllCommentRemoved() {
no_action_text.setVisibility(View.VISIBLE);

View File

@ -29,6 +29,7 @@ import app.fedilab.fedilabtube.client.data.VideoData;
import app.fedilab.fedilabtube.client.data.VideoPlaylistData.VideoPlaylist;
import app.fedilab.fedilabtube.client.entities.Error;
import app.fedilab.fedilabtube.client.entities.OverviewVideo;
import app.fedilab.fedilabtube.client.entities.PlaylistExist.VideoId;
import app.fedilab.fedilabtube.client.entities.Rating;
@SuppressWarnings({"unused", "RedundantSuppression"})
@ -40,6 +41,7 @@ public class APIResponse {
private String actionReturn = null;
private Rating rating;
private OverviewVideo overviewVideo = null;
private List<VideoId> videoExistPlaylist = null;
private List<VideoData.Video> peertubes = null;
private List<CommentData.Comment> comments = null;
private List<Block> muted;
@ -237,4 +239,12 @@ public class APIResponse {
public void setVideoPlaylist(List<VideoPlaylist> videoPlaylist) {
this.videoPlaylist = videoPlaylist;
}
public List<VideoId> getVideoExistPlaylist() {
return videoExistPlaylist;
}
public void setVideoExistPlaylist(List<VideoId> videoExistPlaylist) {
this.videoExistPlaylist = videoExistPlaylist;
}
}

View File

@ -238,7 +238,7 @@ public interface PeertubeService {
Call<VideoPlaylistData> getVideosPlayList(@Header("Authorization") String credentials, @Path("id") String id);
@GET("users/me/video-playlists/videos-exist")
Call<List<PlaylistExist>> getVideoExistsInPlaylist(@Query("videoIds") List<String> videoIds);
Call<PlaylistExist> getVideoExistsInPlaylist(@Header("Authorization") String credentials, @Query("videoIds") List<String> videoIds);
@Multipart
@POST("video-playlists")
@ -262,8 +262,9 @@ public interface PeertubeService {
@Part MultipartBody.Part thumbnailfil);
@FormUrlEncoded
@POST("video-playlists/{id}/videos")
Call<String> addVideoInPlaylist(@Header("Authorization") String credentials, @Path("id") String id, @Query("videoId") String videoId);
Call<String> addVideoInPlaylist(@Header("Authorization") String credentials, @Path("id") String id, @Field("videoId") String videoId);
@DELETE("video-playlists/{id}")

View File

@ -54,6 +54,7 @@ import app.fedilab.fedilabtube.client.entities.Oauth;
import app.fedilab.fedilabtube.client.entities.OauthParams;
import app.fedilab.fedilabtube.client.entities.OverviewVideo;
import app.fedilab.fedilabtube.client.entities.PeertubeInformation;
import app.fedilab.fedilabtube.client.entities.PlaylistExist;
import app.fedilab.fedilabtube.client.entities.PlaylistParams;
import app.fedilab.fedilabtube.client.entities.Rating;
import app.fedilab.fedilabtube.client.entities.Report;
@ -1052,6 +1053,31 @@ public class RetrofitPeertubeAPI {
return apiResponse;
}
/**
* Retrieves playlists for a video *synchronously*
*
* @param videoIds List<String> ids of videos
* @return APIResponse
*/
public APIResponse getVideosExist(List<String> videoIds) {
PeertubeService peertubeService = init();
APIResponse apiResponse = new APIResponse();
try {
Call<PlaylistExist> videoExistsInPlaylist = peertubeService.getVideoExistsInPlaylist(getToken(), videoIds);
Response<PlaylistExist> response = videoExistsInPlaylist.execute();
if (response.isSuccessful() && response.body() != null) {
apiResponse.setVideoExistPlaylist(response.body().getVideoId());
} else {
setError(apiResponse, response.code(), response.errorBody());
}
} catch (IOException e) {
e.printStackTrace();
}
return apiResponse;
}
/**
* Retrieves playlist *synchronously*
*
@ -1085,7 +1111,7 @@ public class RetrofitPeertubeAPI {
} else {
setError(apiResponse, response.code(), response.errorBody());
}
} else if (type == PlaylistsVM.action.GET_LIST_VIDEOS) {
} else if (type == PlaylistsVM.action.GET_LIST_VIDEOS) {
Call<VideoPlaylistData> videosPlayList = peertubeService.getVideosPlayList(getToken(), playlistId);
Response<VideoPlaylistData> response = videosPlayList.execute();
if (response.isSuccessful() && response.body() != null) {

View File

@ -16,46 +16,61 @@ package app.fedilab.fedilabtube.client.entities;
import com.google.gson.annotations.SerializedName;
import java.util.List;
public class PlaylistExist {
@SerializedName("playlistElementId")
private String playlistElementId;
@SerializedName("playlistId")
private String playlistId;
@SerializedName("startTimestamp")
private long startTimestamp;
@SerializedName("stopTimestamp")
private long stopTimestamp;
@SerializedName("videoId")
private List<VideoId> videoId;
public String getPlaylistElementId() {
return playlistElementId;
public List<VideoId> getVideoId() {
return videoId;
}
public void setPlaylistElementId(String playlistElementId) {
this.playlistElementId = playlistElementId;
public void setVideoId(List<VideoId> videoId) {
this.videoId = videoId;
}
public String getPlaylistId() {
return playlistId;
}
public static class VideoId {
@SerializedName("playlistElementId")
private String playlistElementId;
@SerializedName("playlistId")
private String playlistId;
@SerializedName("startTimestamp")
private long startTimestamp;
@SerializedName("stopTimestamp")
private long stopTimestamp;
public void setPlaylistId(String playlistId) {
this.playlistId = playlistId;
}
public String getPlaylistElementId() {
return playlistElementId;
}
public long getStartTimestamp() {
return startTimestamp;
}
public void setPlaylistElementId(String playlistElementId) {
this.playlistElementId = playlistElementId;
}
public void setStartTimestamp(long startTimestamp) {
this.startTimestamp = startTimestamp;
}
public String getPlaylistId() {
return playlistId;
}
public long getStopTimestamp() {
return stopTimestamp;
}
public void setPlaylistId(String playlistId) {
this.playlistId = playlistId;
}
public void setStopTimestamp(long stopTimestamp) {
this.stopTimestamp = stopTimestamp;
public long getStartTimestamp() {
return startTimestamp;
}
public void setStartTimestamp(long startTimestamp) {
this.startTimestamp = startTimestamp;
}
public long getStopTimestamp() {
return stopTimestamp;
}
public void setStopTimestamp(long stopTimestamp) {
this.stopTimestamp = stopTimestamp;
}
}
}

View File

@ -28,6 +28,7 @@ import androidx.lifecycle.MutableLiveData;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
@ -52,16 +53,16 @@ public class PlaylistsVM extends AndroidViewModel {
return apiResponseMutableLiveData;
}
public LiveData<APIResponse> updateCreate(action apiAction, String playlistId, PlaylistParams playlistParams, File thumbnail) {
public LiveData<APIResponse> videoExists(List<String> videoIds) {
apiResponseMutableLiveData = new MutableLiveData<>();
createOrUpdate(apiAction, playlistId, playlistParams, thumbnail);
checkVideosExist(videoIds);
return apiResponseMutableLiveData;
}
private void createOrUpdate(action apiAction, String playlistId, PlaylistParams playlistParams, File thumbnail) {
private void checkVideosExist(List<String> videoIds) {
Context _mContext = getApplication().getApplicationContext();
new Thread(() -> {
APIResponse apiResponse = new RetrofitPeertubeAPI(_mContext).createOrUpdatePlaylist(apiAction, playlistId, playlistParams, thumbnail);
APIResponse apiResponse = new RetrofitPeertubeAPI(_mContext).getVideosExist(videoIds);
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
mainHandler.post(myRunnable);
@ -106,7 +107,6 @@ public class PlaylistsVM extends AndroidViewModel {
UPDATE_PLAYLIST,
DELETE_PLAYLIST,
ADD_VIDEOS,
DELETE_VIDEOS,
GET_PLAYLIST_FOR_VIDEO,
DELETE_VIDEOS
}
}

View File

@ -14,36 +14,59 @@
You should have received a copy of the GNU General Public License along with TubeLab; if not,
see <http://www.gnu.org/licenses>.
-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:itemIconTint="@color/bottom_nav_color"
app:itemTextColor="@color/bottom_nav_color"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@id/nav_view"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/mobile_navigation" />
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways"
android:fitsSystemWindows="true"
/>
</com.google.android.material.appbar.AppBarLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<fragment
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/mobile_navigation" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:itemIconTint="@color/bottom_nav_color"
app:itemTextColor="@color/bottom_nav_color"
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.drawerlayout.widget.DrawerLayout>