diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java index a07f04e..4eb9981 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java @@ -160,6 +160,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd private boolean isMyVideo; private List comments; private CommentListAdapter commentListAdapter; + private boolean sepiaSearch; public static void hideKeyboard(Activity activity) { if (activity != null && activity.getWindow() != null) { @@ -198,7 +199,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); - if (Helper.isLoggedIn(PeertubeActivity.this)) { + if (Helper.isLoggedIn(PeertubeActivity.this) && !sepiaSearch) { Account account = new AccountDAO(PeertubeActivity.this, db).getAccountByToken(token); Helper.loadGiF(PeertubeActivity.this, account.getAvatar() != null ? account.getAvatar().getPath() : null, my_pp); } @@ -224,6 +225,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd peertubeInstance = b.getString("peertube_instance", Helper.getLiveInstance(PeertubeActivity.this)); videoUuid = b.getString("video_uuid", null); isMyVideo = b.getBoolean("isMyVideo", false); + sepiaSearch = b.getBoolean("sepia_search", false); } @@ -299,7 +301,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd if (firstVisibleItem + visibleItemCount == totalItemCount) { if (!flag_loading) { CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class); - commentViewModel.getThread(videoUuid, max_id).observe(PeertubeActivity.this, apiresponse -> manageVIewComment(apiresponse)); + commentViewModel.getThread(sepiaSearch?peertubeInstance:null, videoUuid, max_id).observe(PeertubeActivity.this, apiresponse -> manageVIewComment(apiresponse)); } } } @@ -360,9 +362,9 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd peertube_playlist.setVisibility(View.VISIBLE); peertube_bookmark.setVisibility(View.GONE); TimelineVM feedsViewModel = new ViewModelProvider(PeertubeActivity.this).get(TimelineVM.class); - feedsViewModel.getVideo(videoUuid, isMyVideo).observe(PeertubeActivity.this, this::manageVIewVideo); + feedsViewModel.getVideo(sepiaSearch?peertubeInstance:null, videoUuid, isMyVideo).observe(PeertubeActivity.this, this::manageVIewVideo); CaptionsVM captionsViewModel = new ViewModelProvider(PeertubeActivity.this).get(CaptionsVM.class); - captionsViewModel.getCaptions(videoUuid).observe(PeertubeActivity.this, this::manageCaptions); + captionsViewModel.getCaptions(sepiaSearch?peertubeInstance:null, videoUuid).observe(PeertubeActivity.this, this::manageCaptions); } public void change() { @@ -502,7 +504,9 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd peertube = apiResponse.getPeertubes().get(0); - + if( sepiaSearch) { + peertubeInstance = peertube.getAccount().getHost(); + } List videoIds = new ArrayList<>(); videoIds.add(peertube.getId()); PlaylistsVM viewModel = new ViewModelProvider(this).get(PlaylistsVM.class); @@ -510,7 +514,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd add_comment_read.setOnClickListener(v -> { - if (isLoggedIn(PeertubeActivity.this)) { + if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) { add_comment_read.setVisibility(View.GONE); add_comment_write.setVisibility(View.VISIBLE); send.setVisibility(View.VISIBLE); @@ -522,7 +526,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd }); send.setOnClickListener(v -> { - if (isLoggedIn(PeertubeActivity.this)) { + if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) { String comment = add_comment_write.getText().toString(); if (comment.trim().length() > 0) { PostActionsVM viewModelComment = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); @@ -547,7 +551,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd if (peertube.isCommentsEnabled()) { CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class); - commentViewModel.getThread(videoUuid, max_id).observe(PeertubeActivity.this, this::manageVIewComment); + commentViewModel.getThread(sepiaSearch?peertubeInstance:null, videoUuid, max_id).observe(PeertubeActivity.this, this::manageVIewComment); write_comment_container.setVisibility(View.VISIBLE); } else { @@ -570,7 +574,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd initResolution(); peertube_like_count.setOnClickListener(v -> { - if (isLoggedIn(PeertubeActivity.this)) { + if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) { String newState = peertube.getMyRating().equals("like") ? "none" : "like"; PostActionsVM viewModelLike = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); viewModelLike.post(RATEVIDEO, peertube.getId(), newState).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(RATEVIDEO, apiResponse1)); @@ -591,7 +595,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd } }); peertube_dislike_count.setOnClickListener(v -> { - if (isLoggedIn(PeertubeActivity.this)) { + if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) { String newState = peertube.getMyRating().equals("dislike") ? "none" : "dislike"; PostActionsVM viewModelLike = new ViewModelProvider(PeertubeActivity.this).get(PostActionsVM.class); viewModelLike.post(RATEVIDEO, peertube.getId(), newState).observe(PeertubeActivity.this, apiResponse1 -> manageVIewPostActions(RATEVIDEO, apiResponse1)); @@ -712,7 +716,11 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd Uri uri = null; if (which > 0) { - uri = Uri.parse("https://" + getLiveInstance(PeertubeActivity.this) + captions.get(which - 1).getCaptionPath()); + if( !sepiaSearch) { + uri = Uri.parse("https://" + getLiveInstance(PeertubeActivity.this) + captions.get(which - 1).getCaptionPath()); + }else{ + uri = Uri.parse("https://" + peertubeInstance + captions.get(which - 1).getCaptionPath()); + } } int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB); @@ -934,7 +942,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd if (peertube.isCommentsEnabled() && statusAction == ADD_COMMENT) { CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class); - commentViewModel.getThread(videoUuid, max_id).observe(PeertubeActivity.this, this::manageVIewComment); + commentViewModel.getThread(sepiaSearch?peertubeInstance:null, videoUuid, max_id).observe(PeertubeActivity.this, this::manageVIewComment); } else if (statusAction == RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT) { Toasty.success(PeertubeActivity.this, getString(R.string.successful_report), Toasty.LENGTH_LONG).show(); } else if (statusAction == RetrofitPeertubeAPI.ActionType.REPORT_VIDEO) { diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java index fb2d616..ce8b7bc 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java @@ -224,7 +224,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { TimelineVM feedsViewModel = new ViewModelProvider(PeertubeEditUploadActivity.this).get(TimelineVM.class); - feedsViewModel.getMyVideo(videoId).observe(PeertubeEditUploadActivity.this, this::manageVIewVideo); + feedsViewModel.getMyVideo(null, videoId).observe(PeertubeEditUploadActivity.this, this::manageVIewVideo); channels = new LinkedHashMap<>(); setTitle(R.string.edit_video); diff --git a/app/src/main/java/app/fedilab/fedilabtube/SepiaSearchActivity.java b/app/src/main/java/app/fedilab/fedilabtube/SepiaSearchActivity.java index aedda59..7322319 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/SepiaSearchActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/SepiaSearchActivity.java @@ -14,6 +14,8 @@ package app.fedilab.fedilabtube; * You should have received a copy of the GNU General Public License along with TubeLab; if not, * see . */ +import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.MenuItem; import android.view.View; @@ -25,7 +27,9 @@ import android.widget.Spinner; import androidx.appcompat.app.AppCompatActivity; import androidx.constraintlayout.widget.ConstraintLayout; -import androidx.lifecycle.ViewModelProvider; +import androidx.fragment.app.FragmentTransaction; + +import com.mancj.materialsearchbar.MaterialSearchBar; import java.util.ArrayList; import java.util.Calendar; @@ -36,10 +40,9 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import app.fedilab.fedilabtube.client.data.VideoData; import app.fedilab.fedilabtube.client.entities.SepiaSearch; +import app.fedilab.fedilabtube.fragment.DisplaySepiaSearchFragment; import app.fedilab.fedilabtube.helper.Helper; -import app.fedilab.fedilabtube.viewmodel.SepiaSearchVM; import mabbas007.tagsedittext.TagsEditText; import static app.fedilab.fedilabtube.MainActivity.peertubeInformation; @@ -48,10 +51,10 @@ import static app.fedilab.fedilabtube.MainActivity.peertubeInformation; public class SepiaSearchActivity extends AppCompatActivity { - private SepiaSearch sepiaSearchVideo; - private SepiaSearch sepiaSearchChannel; - - + private SepiaSearch sepiaSearchVideo, sepiaSearchChannel; + private TagsEditText sepia_element_all_of_tags, sepia_element_one_of_tags; + private MaterialSearchBar searchBar; + private ConstraintLayout filter_elements; @Override protected void onCreate(Bundle savedInstanceState) { @@ -61,12 +64,17 @@ public class SepiaSearchActivity extends AppCompatActivity { sepiaSearchVideo = new SepiaSearch(); sepiaSearchChannel = new SepiaSearch(); + SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + sepiaSearchVideo.setCount(String.valueOf(sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE))); + sepiaSearchVideo.setDurationMin(0); + sepiaSearchVideo.setDurationMax(9999999); + sepiaSearchVideo.setSort("-match"); if (getSupportActionBar() != null) getSupportActionBar().setDisplayHomeAsUpEnabled(true); Button filter = findViewById(R.id.filter); - ConstraintLayout filter_elements = findViewById(R.id.filter_elements); + filter_elements = findViewById(R.id.filter_elements); filter.setOnClickListener(view -> { if( filter_elements.getVisibility() == View.VISIBLE) { filter_elements.setVisibility(View.GONE); @@ -178,8 +186,8 @@ public class SepiaSearchActivity extends AppCompatActivity { Spinner sepia_element_license = findViewById(R.id.sepia_element_license); Spinner sepia_element_language = findViewById(R.id.sepia_element_language); - TagsEditText sepia_element_all_of_tags = findViewById(R.id.sepia_element_all_of_tags); - TagsEditText sepia_element_one_of_tags = findViewById(R.id.sepia_element_one_of_tags); + sepia_element_all_of_tags = findViewById(R.id.sepia_element_all_of_tags); + sepia_element_one_of_tags = findViewById(R.id.sepia_element_one_of_tags); LinkedHashMap categories = new LinkedHashMap<>(peertubeInformation.getCategories()); LinkedHashMap licences = new LinkedHashMap<>(peertubeInformation.getLicences()); @@ -281,23 +289,48 @@ public class SepiaSearchActivity extends AppCompatActivity { - Button apply_filter = findViewById(R.id.apply_filter); - apply_filter.setOnClickListener(v->{ - if( sepia_element_one_of_tags.getTags().size() > 0 ) { - sepiaSearchVideo.setTagsOneOf(sepia_element_one_of_tags.getTags()); - }else{ - sepiaSearchVideo.setTagsOneOf(null); + searchBar = findViewById(R.id.searchBar); + + searchBar.setOnSearchActionListener(new MaterialSearchBar.OnSearchActionListener() { + @Override + public void onSearchStateChanged(boolean enabled) { + } - if( sepia_element_all_of_tags.getTags().size() > 0 ) { - sepiaSearchVideo.setTagsAllOf(sepia_element_all_of_tags.getTags()); - }else{ - sepiaSearchVideo.setTagsAllOf(null); + + @Override + public void onSearchConfirmed(CharSequence text) { + makeSearch(); + } + + @Override + public void onButtonClicked(int buttonCode) { + makeSearch(); } - SepiaSearchVM sepiaSearchVM = new ViewModelProvider(SepiaSearchActivity.this).get(SepiaSearchVM.class); - sepiaSearchVM.sepiaSearch(sepiaSearchVideo).observe(SepiaSearchActivity.this, this::manageVideos); }); + Button apply_filter = findViewById(R.id.apply_filter); + apply_filter.setOnClickListener(v-> makeSearch()); } + private void makeSearch(){ + if( sepia_element_one_of_tags.getTags().size() > 0 ) { + sepiaSearchVideo.setTagsOneOf(sepia_element_one_of_tags.getTags()); + }else{ + sepiaSearchVideo.setTagsOneOf(null); + } + if( sepia_element_all_of_tags.getTags().size() > 0 ) { + sepiaSearchVideo.setTagsAllOf(sepia_element_all_of_tags.getTags()); + }else{ + sepiaSearchVideo.setTagsAllOf(null); + } + filter_elements.setVisibility(View.GONE); + sepiaSearchVideo.setSearch(searchBar.getText()); + DisplaySepiaSearchFragment displaySepiaSearchFragment = new DisplaySepiaSearchFragment(); + Bundle bundle = new Bundle(); + bundle.putParcelable("sepiaSearchVideo", sepiaSearchVideo); + displaySepiaSearchFragment.setArguments(bundle); + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + ft.add(R.id.container, displaySepiaSearchFragment).commit(); + } @Override public boolean onOptionsItemSelected(MenuItem item) { @@ -308,10 +341,6 @@ public class SepiaSearchActivity extends AppCompatActivity { return super.onOptionsItemSelected(item); } - private void manageVideos(VideoData videoData) { - - } - private void updateLanguagesPosition(int position) { LinkedHashMap languagesCheck = new LinkedHashMap<>(peertubeInformation.getLanguages()); Iterator> it = languagesCheck.entrySet().iterator(); diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java b/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java index fdadd52..e3de5c9 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java @@ -86,7 +86,7 @@ public class RetrofitPeertubeAPI { private String instance; private String token; private Set selection; - private String count = String.valueOf(Helper.VIDEOS_PER_PAGE); + private String count; public RetrofitPeertubeAPI(Context context) { _context = context; @@ -1334,6 +1334,7 @@ public class RetrofitPeertubeAPI { APIResponse apiResponse = new APIResponse(); try { Response response = video.execute(); + if (response.isSuccessful()) { List videos = new ArrayList<>(); videos.add(response.body()); diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitSepiaSearchAPI.java b/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitSepiaSearchAPI.java index 6f55875..ca8d4d8 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitSepiaSearchAPI.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitSepiaSearchAPI.java @@ -14,10 +14,11 @@ package app.fedilab.fedilabtube.client; * You should have received a copy of the GNU General Public License along with TubeLab; if not, * see . */ -import android.content.Context; -import android.content.SharedPreferences; import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Locale; + import app.fedilab.fedilabtube.client.data.VideoData; import app.fedilab.fedilabtube.client.entities.SepiaSearch; import app.fedilab.fedilabtube.helper.Helper; @@ -30,13 +31,10 @@ public class RetrofitSepiaSearchAPI { private String finalUrl; - private String count; - public RetrofitSepiaSearchAPI(Context context) { + public RetrofitSepiaSearchAPI() { finalUrl = "https://search.joinpeertube.org/api/v1/"; - SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - count = String.valueOf(sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE)); } private SepiaSearchService init() { @@ -54,12 +52,18 @@ public class RetrofitSepiaSearchAPI { */ public VideoData getVideos(SepiaSearch sepiaSearch) { SepiaSearchService sepiaSearchService = init(); + SimpleDateFormat fmtOut = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH); + String startDate = null; + if(sepiaSearch.getStartDate() != null) { + startDate = fmtOut.format(sepiaSearch.getStartDate()); + } Call videoDataCall = sepiaSearchService.getVideos( sepiaSearch.getStart(), - count, + sepiaSearch.getCount(), sepiaSearch.getSearch(), + sepiaSearch.getDurationMin(), sepiaSearch.getDurationMax(), - sepiaSearch.getStartDate(), + startDate, sepiaSearch.getBoostLanguages(), sepiaSearch.getCategoryOneOf(), sepiaSearch.getLicenceOneOf(), @@ -67,6 +71,7 @@ public class RetrofitSepiaSearchAPI { sepiaSearch.getTagsAllOf(), sepiaSearch.isNsfw(), sepiaSearch.getSort()); + try { Response response = videoDataCall.execute(); if (response.isSuccessful() && response.body() != null) { diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/SepiaSearchService.java b/app/src/main/java/app/fedilab/fedilabtube/client/SepiaSearchService.java index 8c42845..a05d162 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/SepiaSearchService.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/SepiaSearchService.java @@ -30,8 +30,9 @@ interface SepiaSearchService { @Query("start") String maxId, @Query("count") String count, @Query("search") String search, + @Query("durationMin") int durationMin, @Query("durationMax") int durationMax, - @Query("startDate") Date startDate, + @Query("startDate") String startDate, @Query("boostLanguages") List languageOneOf, @Query("categoryOneOf") List categoryOneOf, @Query("licenceOneOf") List licenceOneOf, diff --git a/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java b/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java index bffd7d0..ed122f7 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java +++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java @@ -58,6 +58,7 @@ import es.dmoral.toasty.Toasty; import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.FOLLOW; import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.UNFOLLOW; import static app.fedilab.fedilabtube.viewmodel.TimelineVM.TimelineType.MY_VIDEOS; +import static app.fedilab.fedilabtube.viewmodel.TimelineVM.TimelineType.SEPIA_SEARCH; public class PeertubeAdapter extends RecyclerView.Adapter { @@ -107,15 +108,20 @@ public class PeertubeAdapter extends RecyclerView.Adapter getCaptions(String videoId) { + public LiveData getCaptions(String instance, String videoId) { apiResponseMutableLiveData = new MutableLiveData<>(); - loadCaptions(videoId); + loadCaptions(instance, videoId); return apiResponseMutableLiveData; } - private void loadCaptions(String videoId) { + private void loadCaptions(String instance, String videoId) { Context _mContext = getApplication().getApplicationContext(); new Thread(() -> { try { - RetrofitPeertubeAPI peertubeAPI = new RetrofitPeertubeAPI(_mContext); - APIResponse apiResponse = peertubeAPI.getCaptions(videoId); + RetrofitPeertubeAPI retrofitPeertubeAPI; + if( instance == null) { + retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext); + }else{ + retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext, instance, null); + } + APIResponse apiResponse = retrofitPeertubeAPI.getCaptions(videoId); Handler mainHandler = new Handler(Looper.getMainLooper()); Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse); mainHandler.post(myRunnable); diff --git a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/CommentVM.java b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/CommentVM.java index 3c567ee..bd329e6 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/CommentVM.java +++ b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/CommentVM.java @@ -35,9 +35,9 @@ public class CommentVM extends AndroidViewModel { super(application); } - public LiveData getThread(String videoId, String max_Id) { + public LiveData getThread(String instance, String videoId, String max_Id) { apiResponseMutableLiveData = new MutableLiveData<>(); - getThreadComments(videoId, max_Id); + getThreadComments(instance, videoId, max_Id); return apiResponseMutableLiveData; } @@ -48,12 +48,17 @@ public class CommentVM extends AndroidViewModel { } - private void getThreadComments(String videoId, String max_id) { + private void getThreadComments(String instance, String videoId, String max_id) { Context _mContext = getApplication().getApplicationContext(); new Thread(() -> { try { - RetrofitPeertubeAPI api = new RetrofitPeertubeAPI(_mContext); - APIResponse apiResponse = api.getComments(CommentVM.action.GET_THREAD, videoId, null, max_id); + RetrofitPeertubeAPI retrofitPeertubeAPI; + if( instance == null) { + retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext); + }else{ + retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext, instance, null); + } + APIResponse apiResponse = retrofitPeertubeAPI.getComments(CommentVM.action.GET_THREAD, videoId, null, max_id); Handler mainHandler = new Handler(Looper.getMainLooper()); Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse); mainHandler.post(myRunnable); diff --git a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/SepiaSearchVM.java b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/SepiaSearchVM.java index 4a1d8e3..c27e294 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/SepiaSearchVM.java +++ b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/SepiaSearchVM.java @@ -42,10 +42,9 @@ public class SepiaSearchVM extends AndroidViewModel { } private void getVideos(SepiaSearch sepiaSearch) { - Context _mContext = getApplication().getApplicationContext(); new Thread(() -> { try { - VideoData videoData = new RetrofitSepiaSearchAPI(_mContext).getVideos(sepiaSearch); + VideoData videoData = new RetrofitSepiaSearchAPI().getVideos(sepiaSearch); Handler mainHandler = new Handler(Looper.getMainLooper()); Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(videoData); mainHandler.post(myRunnable); diff --git a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/TimelineVM.java b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/TimelineVM.java index 6111027..0c03a72 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/TimelineVM.java +++ b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/TimelineVM.java @@ -51,9 +51,9 @@ public class TimelineVM extends AndroidViewModel { } - public LiveData getVideo(String videoId, boolean isMyVideo) { + public LiveData getVideo(String instance, String videoId, boolean isMyVideo) { apiResponseMutableLiveData = new MutableLiveData<>(); - getSingle(videoId, isMyVideo); + getSingle(instance, videoId, isMyVideo); return apiResponseMutableLiveData; } @@ -63,9 +63,9 @@ public class TimelineVM extends AndroidViewModel { return apiResponseMutableLiveData; } - public LiveData getMyVideo(String videoId) { + public LiveData getMyVideo(String instance, String videoId) { apiResponseMutableLiveData = new MutableLiveData<>(); - getSingle(videoId, true); + getSingle(instance, videoId, true); return apiResponseMutableLiveData; } @@ -90,13 +90,18 @@ public class TimelineVM extends AndroidViewModel { }).start(); } - private void getSingle(String videoId, boolean myVideo) { + private void getSingle(String instance, String videoId, boolean myVideo) { Context _mContext = getApplication().getApplicationContext(); new Thread(() -> { try { - RetrofitPeertubeAPI retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext); + RetrofitPeertubeAPI retrofitPeertubeAPI; + if( instance == null) { + retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext); + }else{ + retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext, instance, null); + } APIResponse apiResponse = retrofitPeertubeAPI.getVideos(videoId, myVideo); - if (Helper.isLoggedIn(_mContext) && !myVideo) { + if (Helper.isLoggedIn(_mContext) && !myVideo && instance == null) { if (apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0 && apiResponse.getPeertubes().get(0) != null) { APIResponse response = new RetrofitPeertubeAPI(_mContext).getRating(videoId); if (response != null) @@ -172,6 +177,7 @@ public class TimelineVM extends AndroidViewModel { MOST_LIKED, HISTORY, RECENT, - VIDEOS_IN_PLAYLIST + VIDEOS_IN_PLAYLIST, + SEPIA_SEARCH } } diff --git a/app/src/main/res/layout/activity_sepia_search.xml b/app/src/main/res/layout/activity_sepia_search.xml index 634f0ba..59124a8 100644 --- a/app/src/main/res/layout/activity_sepia_search.xml +++ b/app/src/main/res/layout/activity_sepia_search.xml @@ -14,84 +14,98 @@ You should have received a copy of the GNU General Public License along with TubeLab; if not, see . --> - - + - + android:layout_height="wrap_content" + android:fitsSystemWindows="true" + app:theme="@style/ThemeOverlay.AppCompat.Light"> + - + - -