Comment issue #46 - Allow to delete history
This commit is contained in:
parent
02cd267cae
commit
2cd076bfb8
|
@ -21,6 +21,8 @@
|
||||||
<string name="export_list">Exporter</string>
|
<string name="export_list">Exporter</string>
|
||||||
<string name="import_list">Importer</string>
|
<string name="import_list">Importer</string>
|
||||||
|
|
||||||
|
<string name="delete_history">Supprimer l\'historique de vidéos</string>
|
||||||
|
<string name="delete_history_confirm">Êtes vous sur de vouloir supprimer toutes les vidéos de votre historique ?</string>
|
||||||
<string name="export_notification_title">Exportation réussie !</string>
|
<string name="export_notification_title">Exportation réussie !</string>
|
||||||
<string name="export_notification_content">Cliquer ici pour envoyer l\'exportation par mèl.</string>
|
<string name="export_notification_content">Cliquer ici pour envoyer l\'exportation par mèl.</string>
|
||||||
<string name="export_notification_subjet">Nouvelle liste de lecture</string>
|
<string name="export_notification_subjet">Nouvelle liste de lecture</string>
|
||||||
|
|
|
@ -284,6 +284,9 @@
|
||||||
<!-- end languages -->
|
<!-- end languages -->
|
||||||
|
|
||||||
|
|
||||||
|
<string name="delete_history">Delete videos history</string>
|
||||||
|
<string name="delete_history_confirm">Are you sure you want to delete all your videos history?</string>
|
||||||
|
|
||||||
<string name="export_list">Export</string>
|
<string name="export_list">Export</string>
|
||||||
<string name="import_list">Import</string>
|
<string name="import_list">Import</string>
|
||||||
<string name="export_notification_title">Successful export!</string>
|
<string name="export_notification_title">Successful export!</string>
|
||||||
|
|
|
@ -14,12 +14,17 @@ package app.fedilab.fedilabtube;
|
||||||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.fragment.app.FragmentTransaction;
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
@ -27,6 +32,7 @@ import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import app.fedilab.fedilabtube.client.APIResponse;
|
||||||
import app.fedilab.fedilabtube.databinding.ActivitySearchResultBinding;
|
import app.fedilab.fedilabtube.databinding.ActivitySearchResultBinding;
|
||||||
import app.fedilab.fedilabtube.fragment.DisplayVideosFragment;
|
import app.fedilab.fedilabtube.fragment.DisplayVideosFragment;
|
||||||
import app.fedilab.fedilabtube.helper.Helper;
|
import app.fedilab.fedilabtube.helper.Helper;
|
||||||
|
@ -114,14 +120,51 @@ public class VideosTimelineActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(@NotNull Menu menu) {
|
||||||
|
if (type == HISTORY) {
|
||||||
|
getMenuInflater().inflate(R.menu.main_history, menu);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return super.onCreateOptionsMenu(menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
if (item.getItemId() == android.R.id.home) {
|
if (item.getItemId() == android.R.id.home) {
|
||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
|
} else if (item.getItemId() == R.id.action_delete) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(VideosTimelineActivity.this);
|
||||||
|
builder.setTitle(R.string.delete_history);
|
||||||
|
builder.setMessage(R.string.delete_history_confirm);
|
||||||
|
builder.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
|
.setPositiveButton(R.string.delete, (dialog, which) -> {
|
||||||
|
TimelineVM viewModelFeeds = new ViewModelProvider(VideosTimelineActivity.this).get(TimelineVM.class);
|
||||||
|
viewModelFeeds.deleterHistory().observe(VideosTimelineActivity.this, this::manageVIewVideos);
|
||||||
|
|
||||||
|
dialog.dismiss();
|
||||||
|
})
|
||||||
|
.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss())
|
||||||
|
.show();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void manageVIewVideos(APIResponse apiResponse) {
|
||||||
|
if (type == HISTORY) {
|
||||||
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||||
|
displayVideosFragment = new DisplayVideosFragment();
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putSerializable(Helper.TIMELINE_TYPE, HISTORY);
|
||||||
|
displayVideosFragment.setArguments(bundle);
|
||||||
|
ft.replace(R.id.container, displayVideosFragment);
|
||||||
|
ft.addToBackStack(null);
|
||||||
|
ft.commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,6 +183,10 @@ public interface PeertubeService {
|
||||||
@Query("endDate") String endDate
|
@Query("endDate") String endDate
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@POST("users/me/history/videos/remove")
|
||||||
|
Call<String> deleteHistory(
|
||||||
|
@Header("Authorization") String credentials);
|
||||||
|
|
||||||
//Search
|
//Search
|
||||||
@GET("search/videos")
|
@GET("search/videos")
|
||||||
Call<VideoData> searchVideos(
|
Call<VideoData> searchVideos(
|
||||||
|
|
|
@ -347,6 +347,29 @@ public class RetrofitPeertubeAPI {
|
||||||
return apiResponse;
|
return apiResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public APIResponse deleteHistory() {
|
||||||
|
APIResponse apiResponse = new APIResponse();
|
||||||
|
PeertubeService peertubeService = init();
|
||||||
|
Call<String> stringCall = peertubeService.deleteHistory(getToken());
|
||||||
|
if (stringCall != null) {
|
||||||
|
try {
|
||||||
|
Response<String> response = stringCall.execute();
|
||||||
|
if (response.isSuccessful() && response.body() != null) {
|
||||||
|
apiResponse.setActionReturn(response.body());
|
||||||
|
} 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 getHistory(String max_id, String startDate, String endDate) {
|
public APIResponse getHistory(String max_id, String startDate, String endDate) {
|
||||||
APIResponse apiResponse = new APIResponse();
|
APIResponse apiResponse = new APIResponse();
|
||||||
PeertubeService peertubeService = init();
|
PeertubeService peertubeService = init();
|
||||||
|
|
|
@ -64,6 +64,12 @@ public class TimelineVM extends AndroidViewModel {
|
||||||
return apiResponseMutableLiveData;
|
return apiResponseMutableLiveData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LiveData<APIResponse> deleterHistory() {
|
||||||
|
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||||
|
deleteHistory();
|
||||||
|
return apiResponseMutableLiveData;
|
||||||
|
}
|
||||||
|
|
||||||
public LiveData<APIResponse> getVideo(String instance, String videoId, boolean isMyVideo) {
|
public LiveData<APIResponse> getVideo(String instance, String videoId, boolean isMyVideo) {
|
||||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||||
getSingle(instance, videoId, isMyVideo);
|
getSingle(instance, videoId, isMyVideo);
|
||||||
|
@ -212,6 +218,22 @@ public class TimelineVM extends AndroidViewModel {
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void deleteHistory() {
|
||||||
|
|
||||||
|
Context _mContext = getApplication().getApplicationContext();
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
RetrofitPeertubeAPI retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext);
|
||||||
|
APIResponse apiResponse = retrofitPeertubeAPI.deleteHistory();
|
||||||
|
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) {
|
private void loadOverviewVideos(String page) {
|
||||||
Context _mContext = getApplication().getApplicationContext();
|
Context _mContext = getApplication().getApplicationContext();
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_delete"
|
||||||
|
android:icon="@drawable/ic_baseline_delete_24"
|
||||||
|
android:title="@string/delete"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
</menu>
|
Loading…
Reference in New Issue