mirror of
				https://framagit.org/tom79/fedilab-tube
				synced 2025-06-05 21:09:11 +02:00 
			
		
		
		
	Fix duration
This commit is contained in:
		| @@ -1,3 +1,4 @@ | ||||
|  | ||||
| package app.fedilab.fedilabtube; | ||||
|  | ||||
|  | ||||
| @@ -61,6 +62,7 @@ import java.util.Objects; | ||||
|  | ||||
| import javax.net.ssl.HttpsURLConnection; | ||||
|  | ||||
|  | ||||
| import app.fedilab.fedilabtube.asynctasks.ManagePlaylistsAsyncTask; | ||||
| import app.fedilab.fedilabtube.asynctasks.PostActionAsyncTask; | ||||
| import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeSingleAsyncTask; | ||||
| @@ -160,6 +162,7 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee | ||||
|         peertube_bookmark.setVisibility(View.GONE); | ||||
|  | ||||
|  | ||||
|  | ||||
|         SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); | ||||
|         String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); | ||||
|         instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(PeertubeActivity.this)); | ||||
| @@ -175,6 +178,8 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee | ||||
|             getSupportActionBar().setDisplayHomeAsUpEnabled(true); | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|         mode = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_DIRECT); | ||||
|         if (mode != Helper.VIDEO_MODE_WEBVIEW && mode != Helper.VIDEO_MODE_DIRECT) | ||||
|             mode = Helper.VIDEO_MODE_DIRECT; | ||||
| @@ -310,87 +315,89 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee | ||||
|         } | ||||
|  | ||||
|         peertube = apiResponse.getPeertubes().get(0); | ||||
|  | ||||
|         //TODO: currently streaming service gives the wrong values for duration | ||||
|         peertube.setStreamService(false); | ||||
|         new ManagePlaylistsAsyncTask(PeertubeActivity.this, GET_PLAYLIST_FOR_VIDEO, null, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | ||||
|  | ||||
|  | ||||
|         peertube_playlist.setOnClickListener(v -> { | ||||
|             if (isLoggedIn(PeertubeActivity.this)) { | ||||
|                 if (playlists != null && peertube.getId() != null) { | ||||
|                     PopupMenu popup = new PopupMenu(PeertubeActivity.this, peertube_playlist); | ||||
|  | ||||
|                     for (Playlist playlist : playlists) { | ||||
|                         String title = null; | ||||
|                         for (String id : playlistForVideo) { | ||||
|                             if (playlist.getId().equals(id)) { | ||||
|                                 title = "✔ " + playlist.getDisplayName(); | ||||
|                                 break; | ||||
|             peertube_playlist.setOnClickListener(v -> { | ||||
|                 if( isLoggedIn(PeertubeActivity.this) ) { | ||||
|                     if (playlists != null && peertube.getId() != null) { | ||||
|                         PopupMenu popup = new PopupMenu(PeertubeActivity.this, peertube_playlist); | ||||
|  | ||||
|                         for (Playlist playlist : playlists) { | ||||
|                             String title = null; | ||||
|                             for (String id : playlistForVideo) { | ||||
|                                 if (playlist.getId().equals(id)) { | ||||
|                                     title = "✔ " + playlist.getDisplayName(); | ||||
|                                     break; | ||||
|                                 } | ||||
|                             } | ||||
|                         } | ||||
|                         if (title == null) { | ||||
|                             title = playlist.getDisplayName(); | ||||
|                         } | ||||
|                         MenuItem item = popup.getMenu().add(0, 0, Menu.NONE, title); | ||||
|                         item.setOnMenuItemClickListener(item1 -> { | ||||
|                             item1.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); | ||||
|                             item1.setActionView(new View(PeertubeActivity.this)); | ||||
|                             item1.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { | ||||
|                                 @Override | ||||
|                                 public boolean onMenuItemActionExpand(MenuItem item1) { | ||||
|                                     return false; | ||||
|                                 } | ||||
|                             if (title == null) { | ||||
|                                 title = playlist.getDisplayName(); | ||||
|                             } | ||||
|                             MenuItem item = popup.getMenu().add(0, 0, Menu.NONE, title); | ||||
|                             item.setOnMenuItemClickListener(item1 -> { | ||||
|                                 item1.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); | ||||
|                                 item1.setActionView(new View(PeertubeActivity.this)); | ||||
|                                 item1.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { | ||||
|                                     @Override | ||||
|                                     public boolean onMenuItemActionExpand(MenuItem item1) { | ||||
|                                         return false; | ||||
|                                     } | ||||
|  | ||||
|                                 @Override | ||||
|                                 public boolean onMenuItemActionCollapse(MenuItem item1) { | ||||
|                                     return false; | ||||
|                                     @Override | ||||
|                                     public boolean onMenuItemActionCollapse(MenuItem item1) { | ||||
|                                         return false; | ||||
|                                     } | ||||
|                                 }); | ||||
|                                 if (playlistForVideo.contains(playlist.getId())) { | ||||
|                                     item1.setTitle(playlist.getDisplayName()); | ||||
|                                     new ManagePlaylistsAsyncTask(PeertubeActivity.this, ManagePlaylistsAsyncTask.action.DELETE_VIDEOS, playlist, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | ||||
|                                     playlistForVideo.remove(playlist.getId()); | ||||
|                                 } else { | ||||
|                                     item1.setTitle("✔ " + playlist.getDisplayName()); | ||||
|                                     new ManagePlaylistsAsyncTask(PeertubeActivity.this, ManagePlaylistsAsyncTask.action.ADD_VIDEOS, playlist, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | ||||
|                                     playlistForVideo.add(playlist.getId()); | ||||
|                                 } | ||||
|                                 return false; | ||||
|                             }); | ||||
|                             if (playlistForVideo.contains(playlist.getId())) { | ||||
|                                 item1.setTitle(playlist.getDisplayName()); | ||||
|                                 new ManagePlaylistsAsyncTask(PeertubeActivity.this, ManagePlaylistsAsyncTask.action.DELETE_VIDEOS, playlist, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | ||||
|                                 playlistForVideo.remove(playlist.getId()); | ||||
|                             } else { | ||||
|                                 item1.setTitle("✔ " + playlist.getDisplayName()); | ||||
|                                 new ManagePlaylistsAsyncTask(PeertubeActivity.this, ManagePlaylistsAsyncTask.action.ADD_VIDEOS, playlist, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | ||||
|                                 playlistForVideo.add(playlist.getId()); | ||||
|                             } | ||||
|                             return false; | ||||
|                         }); | ||||
|                         popup.show(); | ||||
|                             popup.show(); | ||||
|                         } | ||||
|                     } | ||||
|                 }else { | ||||
|                     Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show(); | ||||
|                 } | ||||
|             } else { | ||||
|                 Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show(); | ||||
|             } | ||||
|         }); | ||||
|             }); | ||||
|  | ||||
|         add_comment_read.setOnClickListener(v -> { | ||||
|             if (isLoggedIn(PeertubeActivity.this)) { | ||||
|                 add_comment_read.setVisibility(View.GONE); | ||||
|                 add_comment_write.setVisibility(View.VISIBLE); | ||||
|                 send.setVisibility(View.VISIBLE); | ||||
|                 add_comment_write.requestFocus(); | ||||
|                 add_comment_write.setSelection(add_comment_write.getText().length()); | ||||
|             } else { | ||||
|                 Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show(); | ||||
|             } | ||||
|  | ||||
|         }); | ||||
|         send.setOnClickListener(v -> { | ||||
|             if (isLoggedIn(PeertubeActivity.this)) { | ||||
|                 String comment = add_comment_write.getText().toString(); | ||||
|                 if (comment.trim().length() > 0) { | ||||
|                     new PostActionAsyncTask(PeertubeActivity.this, PeertubeAPI.StatusAction.PEERTUBECOMMENT, peertube.getId(), null, comment, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | ||||
|                     add_comment_write.setText(""); | ||||
|                     add_comment_read.setVisibility(View.VISIBLE); | ||||
|                     add_comment_write.setVisibility(View.GONE); | ||||
|                     send.setVisibility(View.GONE); | ||||
|                     add_comment_read.requestFocus(); | ||||
|             add_comment_read.setOnClickListener(v -> { | ||||
|                 if( isLoggedIn(PeertubeActivity.this) ) { | ||||
|                     add_comment_read.setVisibility(View.GONE); | ||||
|                     add_comment_write.setVisibility(View.VISIBLE); | ||||
|                     send.setVisibility(View.VISIBLE); | ||||
|                     add_comment_write.requestFocus(); | ||||
|                     add_comment_write.setSelection(add_comment_write.getText().length()); | ||||
|                 }else { | ||||
|                     Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show(); | ||||
|                 } | ||||
|             } else { | ||||
|                 Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show(); | ||||
|             } | ||||
|         }); | ||||
|  | ||||
|             }); | ||||
|             send.setOnClickListener(v -> { | ||||
|                 if( isLoggedIn(PeertubeActivity.this) ) { | ||||
|                     String comment = add_comment_write.getText().toString(); | ||||
|                     if (comment.trim().length() > 0) { | ||||
|                         new PostActionAsyncTask(PeertubeActivity.this, PeertubeAPI.StatusAction.PEERTUBECOMMENT, peertube.getId(), null, comment, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | ||||
|                         add_comment_write.setText(""); | ||||
|                         add_comment_read.setVisibility(View.VISIBLE); | ||||
|                         add_comment_write.setVisibility(View.GONE); | ||||
|                         send.setVisibility(View.GONE); | ||||
|                         add_comment_read.requestFocus(); | ||||
|                     } | ||||
|                 }else { | ||||
|                     Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show(); | ||||
|                 } | ||||
|             }); | ||||
|  | ||||
|  | ||||
|         peertube_playlist.setOnClickListener(v -> { | ||||
| @@ -464,22 +471,22 @@ public class PeertubeActivity extends AppCompatActivity implements OnRetrievePee | ||||
|         initResolution(); | ||||
|  | ||||
|         peertube_like_count.setOnClickListener(v -> { | ||||
|             if (isLoggedIn(PeertubeActivity.this)) { | ||||
|             if( isLoggedIn(PeertubeActivity.this) ) { | ||||
|                 String newState = peertube.getMyRating().equals("like") ? "none" : "like"; | ||||
|                 new PostActionAsyncTask(PeertubeActivity.this, PeertubeAPI.StatusAction.RATEVIDEO, peertube.getId(), null, newState, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | ||||
|                 peertube.setMyRating(newState); | ||||
|                 changeColor(); | ||||
|             } else { | ||||
|             }else { | ||||
|                 Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show(); | ||||
|             } | ||||
|         }); | ||||
|         peertube_dislike_count.setOnClickListener(v -> { | ||||
|             if (isLoggedIn(PeertubeActivity.this)) { | ||||
|             if( isLoggedIn(PeertubeActivity.this) ) { | ||||
|                 String newState = peertube.getMyRating().equals("dislike") ? "none" : "dislike"; | ||||
|                 new PostActionAsyncTask(PeertubeActivity.this, PeertubeAPI.StatusAction.RATEVIDEO, peertube.getId(), null, newState, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | ||||
|                 peertube.setMyRating(newState); | ||||
|                 changeColor(); | ||||
|             } else { | ||||
|             }else { | ||||
|                 Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show(); | ||||
|             } | ||||
|         }); | ||||
|   | ||||
| @@ -165,7 +165,7 @@ public class Peertube { | ||||
|             resolution = this.getResolution().get(0); | ||||
|         if (resolution == null) | ||||
|             return null; | ||||
|         if (streamService) { | ||||
|         if (streamService ) { | ||||
|             return "https://" + this.host + "/static/streaming-playlists/hls/" + getUuid() + "/" + getUuid() + "-" + resolution + "-fragmented.mp4"; | ||||
|         } else { | ||||
|             return "https://" + this.host + "/static/webseed/" + getUuid() + "-" + resolution + ".mp4"; | ||||
|   | ||||
| @@ -75,7 +75,8 @@ | ||||
|             android:paddingLeft="4dp" | ||||
|             android:paddingRight="4dp" | ||||
|             android:textColor="#FFBEBEBE" | ||||
|             android:textSize="12sp" /> | ||||
|             android:textSize="14sp" | ||||
|             android:textStyle="bold"/> | ||||
|  | ||||
|         <TextView | ||||
|             android:id="@id/exo_position" | ||||
| @@ -85,8 +86,8 @@ | ||||
|             android:paddingLeft="4dp" | ||||
|             android:paddingRight="4dp" | ||||
|             android:textColor="#FFBEBEBE" | ||||
|             android:textSize="14sp" | ||||
|             android:textStyle="bold" /> | ||||
|             android:textSize="12sp" | ||||
|              /> | ||||
|  | ||||
|         <com.google.android.exoplayer2.ui.DefaultTimeBar | ||||
|             android:id="@id/exo_progress" | ||||
| @@ -102,8 +103,8 @@ | ||||
|             android:paddingLeft="4dp" | ||||
|             android:paddingRight="4dp" | ||||
|             android:textColor="#FFBEBEBE" | ||||
|             android:textSize="14sp" | ||||
|             android:textStyle="bold" /> | ||||
|             android:textSize="12sp" | ||||
|             /> | ||||
|  | ||||
|         <FrameLayout | ||||
|             android:id="@+id/exo_fullscreen_button" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user