comment #5 - Add searches

This commit is contained in:
Thomas 2020-10-09 18:22:05 +02:00
parent fd7632f001
commit 056092ac71
14 changed files with 249 additions and 153 deletions

View File

@ -160,6 +160,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
private boolean isMyVideo;
private List<Comment> 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<String> 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) {

View File

@ -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);

View File

@ -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 <http://www.gnu.org/licenses>. */
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<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories());
LinkedHashMap<Integer, String> 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<String, String> languagesCheck = new LinkedHashMap<>(peertubeInformation.getLanguages());
Iterator<Map.Entry<String, String>> it = languagesCheck.entrySet().iterator();

View File

@ -86,7 +86,7 @@ public class RetrofitPeertubeAPI {
private String instance;
private String token;
private Set<String> 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<VideoData.Video> response = video.execute();
if (response.isSuccessful()) {
List<VideoData.Video> videos = new ArrayList<>();
videos.add(response.body());

View File

@ -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 <http://www.gnu.org/licenses>. */
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<VideoData> 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<VideoData> response = videoDataCall.execute();
if (response.isSuccessful() && response.body() != null) {

View File

@ -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<String> languageOneOf,
@Query("categoryOneOf") List<Integer> categoryOneOf,
@Query("licenceOneOf") List<Integer> licenceOneOf,

View File

@ -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<RecyclerView.ViewHolder> {
@ -107,15 +108,20 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
ownVideos = video.getAccount() != null && video.getAccount().getId() != null && video.getAccount().getHost().compareTo(Helper.getLiveInstance(context)) == 0 && video.getAccount().getId().compareTo(userId) == 0;
}
String instance = null;
if( timelineType == SEPIA_SEARCH) {
instance = video.getAccount().getHost();
}
holder.peertube_account_name.setText(video.getChannel().getAcct());
Helper.loadGiF(context, video.getChannel().getAvatar() != null ? video.getChannel().getAvatar().getPath() : null, holder.peertube_profile);
Helper.loadGiF(context, instance, video.getChannel().getAvatar() != null ? video.getChannel().getAvatar().getPath() : null, holder.peertube_profile);
holder.peertube_title.setText(video.getName());
holder.peertube_duration.setText(Helper.secondsToString(video.getDuration()));
holder.peertube_date.setText(String.format(" - %s", Helper.dateDiff(context, video.getCreatedAt())));
holder.peertube_views.setText(context.getString(R.string.number_view_video, Helper.withSuffix(video.getViews())));
Helper.loadGiF(context, video.getThumbnailPath(), holder.peertube_video_image);
Helper.loadGiF(context, instance, video.getThumbnailPath(), holder.peertube_video_image);
//For Overview Videos: boolean values for displaying title is managed in the fragment
if (video.isHasTitle()) {
@ -138,6 +144,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
Intent intent = new Intent(context, ShowChannelActivity.class);
Bundle b = new Bundle();
b.putParcelable("channel", video.getChannel());
b.putBoolean("sepia_search", timelineType == SEPIA_SEARCH);
intent.putExtras(b);
context.startActivity(intent);
});
@ -245,6 +252,10 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
b.putString("video_id", video.getId());
b.putString("video_uuid", video.getUuid());
b.putBoolean("isMyVideo", ownVideos);
b.putBoolean("sepia_search", timelineType == SEPIA_SEARCH);
if( timelineType == SEPIA_SEARCH) {
b.putString("peertube_instance", video.getAccount().getHost());
}
intent.putExtras(b);
context.startActivity(intent);
});
@ -254,6 +265,10 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
b.putString("video_id", video.getId());
b.putString("video_uuid", video.getUuid());
b.putBoolean("isMyVideo", ownVideos);
b.putBoolean("sepia_search", timelineType == SEPIA_SEARCH);
if( timelineType == SEPIA_SEARCH) {
b.putString("peertube_instance", video.getAccount().getHost());
}
intent.putExtras(b);
context.startActivity(intent);
});

View File

@ -48,6 +48,8 @@ import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.viewmodel.SepiaSearchVM;
import es.dmoral.toasty.Toasty;
import static app.fedilab.fedilabtube.viewmodel.TimelineVM.TimelineType.SEPIA_SEARCH;
public class DisplaySepiaSearchFragment extends Fragment implements AccountsHorizontalListAdapter.EventListener {
@ -100,7 +102,7 @@ public class DisplaySepiaSearchFragment extends Fragment implements AccountsHori
mainLoader.setVisibility(View.VISIBLE);
nextElementLoader.setVisibility(View.GONE);
peertubeAdapater = new PeertubeAdapter(this.peertubes);
peertubeAdapater = new PeertubeAdapter(this.peertubes, SEPIA_SEARCH);
lv_status.setAdapter(peertubeAdapater);
@ -220,10 +222,11 @@ public class DisplaySepiaSearchFragment extends Fragment implements AccountsHori
this.peertubes.addAll(videoData.data);
//If no item were inserted previously the adapter is created
if (previousPosition == 0) {
peertubeAdapater = new PeertubeAdapter(this.peertubes);
peertubeAdapater = new PeertubeAdapter(this.peertubes, SEPIA_SEARCH);
lv_status.setAdapter(peertubeAdapater);
} else
peertubeAdapater.notifyItemRangeInserted(previousPosition, videoData.data.size());
//remove handlers
swipeRefreshLayout.setRefreshing(false);
textviewNoAction.setVisibility(View.GONE);

View File

@ -72,7 +72,7 @@ public class Helper {
public static final int RELOAD_MYVIDEOS = 10;
public static final String SET_VIDEO_MODE = "set_video_mode";
public static final String SET_QUALITY_MODE = "set_quality_mode";
public static final String TIMELINE_TYPE = Helper.TIMELINE_TYPE;
public static final String TIMELINE_TYPE = "timeline_type";
public static final int VIDEO_MODE_NORMAL = 0;
public static final int VIDEO_MODE_STREAMING = 2;
public static final int VIDEO_MODE_WEBVIEW = 1;
@ -370,7 +370,16 @@ public class Helper {
loadGiF(context, url, imageView, 10);
}
public static void loadGiF(final Context context, String instance, String url, final ImageView imageView) {
loadGif(context, instance, url, imageView, 10);
}
public static void loadGiF(final Context context, String url, final ImageView imageView, int round) {
loadGif(context, null, url, imageView, 10);
}
@SuppressWarnings("SameParameterValue")
private static void loadGif(final Context context, String instance, String url, final ImageView imageView, int round) {
if (url == null || url.trim().toLowerCase().compareTo("null") == 0) {
Glide.with(imageView.getContext())
.asDrawable()
@ -380,7 +389,7 @@ public class Helper {
return;
}
if (url.startsWith("/")) {
url = Helper.getLiveInstance(context) + url;
url = instance!=null?instance+ url:Helper.getLiveInstance(context) + url;
}
if (!url.startsWith("http")) {
url = "https://" + url;

View File

@ -35,18 +35,23 @@ public class CaptionsVM extends AndroidViewModel {
super(application);
}
public LiveData<APIResponse> getCaptions(String videoId) {
public LiveData<APIResponse> 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);

View File

@ -35,9 +35,9 @@ public class CommentVM extends AndroidViewModel {
super(application);
}
public LiveData<APIResponse> getThread(String videoId, String max_Id) {
public LiveData<APIResponse> 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);

View File

@ -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);

View File

@ -51,9 +51,9 @@ public class TimelineVM extends AndroidViewModel {
}
public LiveData<APIResponse> getVideo(String videoId, boolean isMyVideo) {
public LiveData<APIResponse> 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<APIResponse> getMyVideo(String videoId) {
public LiveData<APIResponse> 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
}
}

View File

@ -14,84 +14,98 @@
You should have received a copy of the GNU General Public License along with TubeLab; if not,
see <http://www.gnu.org/licenses>.
-->
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:TagsEditText="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/fab_margin"
android:layout_marginEnd="@dimen/fab_margin"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:TagsEditText="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true">
<ScrollView
android:fitsSystemWindows="true"
tools:context=".SepiaSearchActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:theme="@style/ThemeOverlay.AppCompat.Light">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
android:background="@color/white"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_marginStart="@dimen/fab_margin"
android:layout_marginEnd="@dimen/fab_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:id="@+id/header"
android:animateLayoutChanges="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<com.mancj.materialsearchbar.MaterialSearchBar
style="@style/MaterialSearchBarLight"
app:mt_speechMode="false"
app:mt_hint="@string/sepia_search_hint"
app:mt_maxSuggestionsCount="10"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:id="@+id/header"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:id="@+id/searchBar" />
<TextView
android:layout_marginTop="5dp"
app:layout_constraintTop_toBottomOf="@+id/searchBar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?attr/colorAccent"
android:id="@+id/explanations"
android:text="@string/sepia_indication"
/>
<Button
android:id="@+id/filter"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/filter"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/explanations"
android:drawableEnd="@drawable/ic_baseline_arrow_drop_down_24"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/explanations"
app:layout_constraintEnd_toStartOf="@+id/sort_by"
android:text="@string/sort_by"
android:labelFor="@+id/sort_by"/>
<Spinner
android:id="@+id/sort_by"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/explanations"
/>
app:layout_constraintEnd_toEndOf="parent">
<com.mancj.materialsearchbar.MaterialSearchBar
style="@style/MaterialSearchBarLight"
app:mt_speechMode="false"
app:mt_hint="@string/sepia_search_hint"
app:mt_maxSuggestionsCount="10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:animateLayoutChanges="false"
android:id="@+id/searchBar" />
<TextView
android:layout_marginTop="5dp"
app:layout_constraintTop_toBottomOf="@+id/searchBar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?attr/colorAccent"
android:id="@+id/explanations"
android:text="@string/sepia_indication"
/>
<Button
android:id="@+id/filter"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/filter"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/explanations"
android:drawableEnd="@drawable/ic_baseline_arrow_drop_down_24"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/explanations"
app:layout_constraintEnd_toStartOf="@+id/sort_by"
android:text="@string/sort_by"
android:labelFor="@+id/sort_by"/>
<Spinner
android:id="@+id/sort_by"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/explanations"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/filter_elements"
android:visibility="gone"
android:animateLayoutChanges="true"
app:layout_constraintTop_toBottomOf="@+id/filter"
app:layout_constraintTop_toBottomOf="@+id/header"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
@ -341,21 +355,17 @@
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<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="wrap_content"
app:defaultNavHost="true"
app:layout_constraintTop_toBottomOf="@+id/header"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</androidx.drawerlayout.widget.DrawerLayout>
<FrameLayout
android:layout_marginStart="@dimen/fab_margin"
android:layout_marginEnd="@dimen/fab_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="?attr/actionBarSize"
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>