Some fixes
This commit is contained in:
parent
a984607ee8
commit
150a81adc6
|
@ -16,24 +16,37 @@ package app.fedilab.fedilabtube;
|
|||
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
|
||||
import app.fedilab.fedilabtube.databinding.ActivitySearchResultBinding;
|
||||
import app.fedilab.fedilabtube.fragment.DisplayVideosFragment;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.viewmodel.TimelineVM;
|
||||
|
||||
import static app.fedilab.fedilabtube.viewmodel.TimelineVM.TimelineType.HISTORY;
|
||||
|
||||
|
||||
public class VideosTimelineActivity extends AppCompatActivity {
|
||||
|
||||
private TimelineVM.TimelineType type;
|
||||
private DisplayVideosFragment displayVideosFragment;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_search_result);
|
||||
ActivitySearchResultBinding binding = ActivitySearchResultBinding.inflate(getLayoutInflater());
|
||||
View mainView = binding.getRoot();
|
||||
setContentView(mainView);
|
||||
|
||||
if (getSupportActionBar() != null)
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
@ -41,22 +54,63 @@ public class VideosTimelineActivity extends AppCompatActivity {
|
|||
Bundle b = getIntent().getExtras();
|
||||
if (b != null)
|
||||
type = (TimelineVM.TimelineType) b.get("type");
|
||||
displayVideosFragment = null;
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
if (savedInstanceState == null) {
|
||||
displayVideosFragment = new DisplayVideosFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putSerializable(Helper.TIMELINE_TYPE, type);
|
||||
displayVideosFragment.setArguments(bundle);
|
||||
ft.add(R.id.container, displayVideosFragment).addToBackStack(null).commit();
|
||||
}
|
||||
|
||||
if (type == TimelineVM.TimelineType.MY_VIDEOS) {
|
||||
setTitle(R.string.my_videos);
|
||||
} else if (type == TimelineVM.TimelineType.HISTORY) {
|
||||
} else if (type == HISTORY) {
|
||||
setTitle(R.string.my_history);
|
||||
//TODO: uncomment when available
|
||||
// binding.historyFilter.setVisibility(View.VISIBLE);
|
||||
binding.historyFilterAll.setOnClickListener(v -> historyFilter(null));
|
||||
binding.historyFilterToday.setOnClickListener(v -> {
|
||||
Calendar cal = GregorianCalendar.getInstance();
|
||||
cal.set(Calendar.HOUR_OF_DAY, 0);
|
||||
cal.set(Calendar.MINUTE, 0);
|
||||
cal.set(Calendar.SECOND, 0);
|
||||
cal.set(Calendar.MILLISECOND, 0);
|
||||
cal.getTime();
|
||||
historyFilter(cal.getTime());
|
||||
});
|
||||
binding.historyFilterLast7Days.setOnClickListener(v -> {
|
||||
Calendar cal = GregorianCalendar.getInstance();
|
||||
cal.setTime(new Date());
|
||||
cal.add(Calendar.DAY_OF_YEAR, -7);
|
||||
cal.getTime();
|
||||
historyFilter(cal.getTime());
|
||||
});
|
||||
|
||||
} else if (type == TimelineVM.TimelineType.MOST_LIKED) {
|
||||
setTitle(R.string.title_most_liked);
|
||||
}
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
DisplayVideosFragment displayVideosFragment = new DisplayVideosFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putSerializable(Helper.TIMELINE_TYPE, type);
|
||||
displayVideosFragment.setArguments(bundle);
|
||||
|
||||
}
|
||||
|
||||
private void historyFilter(Date date) {
|
||||
String startDate = null;
|
||||
if (date != null) {
|
||||
SimpleDateFormat fmtOut = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH);
|
||||
startDate = fmtOut.format(date);
|
||||
}
|
||||
if (displayVideosFragment != null) {
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
ft.add(R.id.container, displayVideosFragment).commit();
|
||||
displayVideosFragment = new DisplayVideosFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putSerializable(Helper.TIMELINE_TYPE, HISTORY);
|
||||
bundle.putSerializable("startDate", startDate);
|
||||
displayVideosFragment.setArguments(bundle);
|
||||
ft.replace(R.id.container, displayVideosFragment);
|
||||
ft.addToBackStack(null);
|
||||
ft.commit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -175,7 +175,13 @@ public interface PeertubeService {
|
|||
|
||||
//History
|
||||
@GET("users/me/history/videos")
|
||||
Call<VideoData> getHistory(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count);
|
||||
Call<VideoData> getHistory(
|
||||
@Header("Authorization") String credentials,
|
||||
@Query("start") String maxId,
|
||||
@Query("count") String count,
|
||||
@Query("startDate") String startDate,
|
||||
@Query("endDate") String endDate
|
||||
);
|
||||
|
||||
//Search
|
||||
@GET("search/videos")
|
||||
|
|
|
@ -347,6 +347,28 @@ public class RetrofitPeertubeAPI {
|
|||
return apiResponse;
|
||||
}
|
||||
|
||||
public APIResponse getHistory(String max_id, String startDate, String endDate) {
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
PeertubeService peertubeService = init();
|
||||
Call<VideoData> videoCall = peertubeService.getHistory(getToken(), max_id, count, startDate, endDate);
|
||||
if (videoCall != null) {
|
||||
try {
|
||||
Response<VideoData> response = videoCall.execute();
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setPeertubes(response.body().data);
|
||||
} else {
|
||||
setError(apiResponse, response.code(), response.errorBody());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Error error = new Error();
|
||||
error.setError(_context.getString(R.string.toast_error));
|
||||
apiResponse.setError(error);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
public APIResponse getTL(TimelineVM.TimelineType timelineType, String max_id, String forAccount) {
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
PeertubeService peertubeService = init();
|
||||
|
@ -376,7 +398,7 @@ public class RetrofitPeertubeAPI {
|
|||
videoCall = peertubeService.getTrendingVideos(getToken(), max_id, count, filter);
|
||||
break;
|
||||
case HISTORY:
|
||||
videoCall = peertubeService.getHistory(getToken(), max_id, count);
|
||||
videoCall = peertubeService.getHistory(getToken(), max_id, count, null, null);
|
||||
break;
|
||||
case RECENT:
|
||||
videoCall = peertubeService.getRecentlyAddedVideos(getToken(), max_id, count, filter);
|
||||
|
|
|
@ -99,6 +99,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
private String playlistId;
|
||||
private String remoteInstance;
|
||||
private boolean sepiaSearch;
|
||||
private String startDate, endDate;
|
||||
|
||||
public DisplayVideosFragment() {
|
||||
}
|
||||
|
@ -112,6 +113,8 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
peertubes = new ArrayList<>();
|
||||
channels = new ArrayList<>();
|
||||
context = getContext();
|
||||
startDate = null;
|
||||
endDate = null;
|
||||
Bundle bundle = this.getArguments();
|
||||
if (bundle != null) {
|
||||
search_peertube = bundle.getString("search_peertube", null);
|
||||
|
@ -120,6 +123,8 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
sepiaSearch = bundle.getBoolean("sepia_search", false);
|
||||
type = (TimelineVM.TimelineType) bundle.get(Helper.TIMELINE_TYPE);
|
||||
playlistId = bundle.getString("playlistId", null);
|
||||
startDate = bundle.getString("startDate", null);
|
||||
endDate = bundle.getString("endDate", null);
|
||||
}
|
||||
max_id = "0";
|
||||
forAccount = type == TimelineVM.TimelineType.ACCOUNT_VIDEOS ? channelId : null;
|
||||
|
@ -502,6 +507,8 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
viewModelFeeds.getVideosInChannel(sepiaSearch ? remoteInstance : null, channelId, max_id).observe(this.requireActivity(), this::manageVIewVideos);
|
||||
} else if (type == TimelineVM.TimelineType.VIDEOS_IN_PLAYLIST) {
|
||||
viewModelFeeds.loadVideosInPlaylist(playlistId, max_id).observe(this.requireActivity(), this::manageVIewVideos);
|
||||
} else if (type == TimelineVM.TimelineType.HISTORY) {
|
||||
viewModelFeeds.getVideoHistory(max_id, startDate, endDate).observe(this.requireActivity(), this::manageVIewVideos);
|
||||
} else {
|
||||
viewModelFeeds.getVideos(type, max_id, forAccount).observe(this.requireActivity(), this::manageVIewVideos);
|
||||
}
|
||||
|
|
|
@ -51,6 +51,12 @@ public class TimelineVM extends AndroidViewModel {
|
|||
}
|
||||
|
||||
|
||||
public LiveData<APIResponse> getVideoHistory(String max_id, String startDate, String endDate) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
loadHistory(max_id, startDate, endDate);
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> getVideo(String instance, String videoId, boolean isMyVideo) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
getSingle(instance, videoId, isMyVideo);
|
||||
|
@ -156,6 +162,22 @@ public class TimelineVM extends AndroidViewModel {
|
|||
}).start();
|
||||
}
|
||||
|
||||
private void loadHistory(String max_id, String startDate, String endDate) {
|
||||
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
RetrofitPeertubeAPI retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext);
|
||||
APIResponse apiResponse = retrofitPeertubeAPI.getHistory(max_id, startDate, endDate);
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
||||
mainHandler.post(myRunnable);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
private void loadOverviewVideos(String page) {
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:color="?attr/colorAccent" />
|
||||
<corners android:radius="20dp" />
|
||||
</shape>
|
|
@ -14,7 +14,72 @@
|
|||
You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
see <http://www.gnu.org/licenses>.
|
||||
-->
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<HorizontalScrollView
|
||||
android:id="@+id/history_filter"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:paddingTop="5dp"
|
||||
android:paddingBottom="5dp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/history_filter_all"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/background_rounded_item"
|
||||
android:paddingStart="5dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:text="@string/all"
|
||||
android:textColor="?attr/colorAccent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/history_filter_today"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
android:background="@drawable/background_rounded_item"
|
||||
android:paddingStart="5dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:text="@string/today"
|
||||
android:textColor="?attr/colorAccent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/history_filter_last_7_days"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
android:background="@drawable/background_rounded_item"
|
||||
android:paddingStart="5dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:text="@string/last_7_days"
|
||||
android:textColor="?attr/colorAccent" />
|
||||
</LinearLayout>
|
||||
|
||||
</HorizontalScrollView>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/history_filter">
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue