some fixes

This commit is contained in:
Thomas 2020-10-13 17:50:52 +02:00
parent 75d3f74e48
commit 7c4ce7701c
15 changed files with 139 additions and 43 deletions

View File

@ -8,7 +8,8 @@
<string name="set_video_cache_choice" translatable="false">set_video_cache_choice</string>
<string name="set_theme_choice" translatable="false">set_theme_choice</string>
<string name="delete_account_comment">Supprimer tous les commentaires</string>
<string name="delete_account_comment_confirm">Etes-vous sûr de vouloir supprimer tous les commentaires de ce compte pour vos vidéos ?</string>
<string-array name="settings_theme">
<item>Clair</item>
<item>Sombre</item>

View File

@ -1 +1,3 @@
- Corrige un bug lors de la connexion
- Theme: Clair, Sombre et automatique
- Supprimer tous les commentaires d'un compte sur vos vidéos
- Mettre en sourdine un compte depuis les commentaires.

View File

@ -1 +1,6 @@
- Fix an issue with the authentication of some accounts
- Theme: Light, Dark and auto
- Remove all comments of an account on your videos
- Sepia search: Allow interactions when the video is federated
- Mute accounts from comments
- Fix all comments not displayed
- Fix some minor other bugs

View File

@ -193,6 +193,8 @@
<string name="none">None</string>
<string name="set_video_mode_description">Allows to change mode for playing videos (default, streaming or via a browser).</string>
<string name="delete_account_comment">Delete account comments</string>
<string name="delete_account_comment_confirm">Are you sure you want to remove all the comments of this account?</string>
<string name="delete_video">Delete video</string>
<string name="delete_video_confirmation">Are you sure to delete this video?</string>

View File

@ -32,7 +32,6 @@ import android.os.Handler;
import android.support.v4.media.session.MediaSessionCompat;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
@ -46,7 +45,6 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
@ -59,6 +57,7 @@ import androidx.appcompat.widget.PopupMenu;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.core.widget.NestedScrollView;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@ -137,7 +136,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
private FullScreenMediaController.fullscreen fullscreen;
private RelativeLayout loader;
private TextView peertube_view_count, peertube_playlist, peertube_bookmark, peertube_like_count, peertube_dislike_count, peertube_description, peertube_title, more_actions;
private ScrollView peertube_information_container;
private NestedScrollView peertube_information_container;
private VideoData.Video peertube;
private PlayerView playerView;
private SimpleExoPlayer player;
@ -288,7 +287,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
flag_loading = true;
comments = new ArrayList<>();
lv_comments = findViewById(R.id.peertube_comments);
commentListAdapter = new CommentListAdapter(comments);
commentListAdapter = new CommentListAdapter(comments, Helper.isVideoOwner(PeertubeActivity.this, peertube));
commentListAdapter.allCommentRemoved = PeertubeActivity.this;
LinearLayoutManager mLayoutManager = new LinearLayoutManager(PeertubeActivity.this);
lv_comments.setLayoutManager(mLayoutManager);
@ -419,11 +418,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
return super.dispatchTouchEvent(ev);
}
@Override
public boolean onCreateOptionsMenu(@NotNull Menu menu) {
getMenuInflater().inflate(R.menu.main_peertube, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
@ -434,19 +428,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
finish();
}
return true;
} else if (item.getItemId() == R.id.action_report) {
androidx.appcompat.app.AlertDialog.Builder dialogBuilder = new androidx.appcompat.app.AlertDialog.Builder(PeertubeActivity.this);
LayoutInflater inflater1 = getLayoutInflater();
View dialogView = inflater1.inflate(R.layout.popup_report_choice, new LinearLayout(PeertubeActivity.this), false);
dialogBuilder.setView(dialogView);
Button report_video = dialogView.findViewById(R.id.report_video);
Button report_account = dialogView.findViewById(R.id.report_account);
dialogBuilder.setNeutralButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
androidx.appcompat.app.AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
report_video.setOnClickListener(v -> reportAlert(REPORT_VIDEO, alertDialog));
report_account.setOnClickListener(v -> reportAlert(REPORT_ACCOUNT, alertDialog));
return true;
}
return super.onOptionsItemSelected(item);
}
@ -815,6 +796,20 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
alertDialog.show();
break;
case R.id.action_report:
dialogBuilder = new androidx.appcompat.app.AlertDialog.Builder(PeertubeActivity.this);
LayoutInflater inflater1 = getLayoutInflater();
View dialogView = inflater1.inflate(R.layout.popup_report_choice, new LinearLayout(PeertubeActivity.this), false);
dialogBuilder.setView(dialogView);
Button report_video = dialogView.findViewById(R.id.report_video);
Button report_account = dialogView.findViewById(R.id.report_account);
dialogBuilder.setNeutralButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
alertDialog = dialogBuilder.create();
alertDialog.show();
report_video.setOnClickListener(v -> reportAlert(REPORT_VIDEO, alertDialog));
report_account.setOnClickListener(v -> reportAlert(REPORT_ACCOUNT, alertDialog));
break;
}
return true;
});

View File

@ -341,9 +341,12 @@ public interface PeertubeService {
@DELETE("videos/{id}/comments/{commentId}")
Call<String> deleteComment(@Header("Authorization") String credentials, @Path("id") String id, @Path("commentId") String commentId);
@POST("bulk/remove-comments-of")
Call<String> deleteAllCommentForAccount(@Header("Authorization") String credentials, @Field("accountName") String accountName, @Field("scope") String scope);
@Headers({"Content-Type: application/json", "Cache-Control: max-age=640000"})
@POST("abuses")
Call<String> report(
Call<Report.ReportReturn> report(
@Header("Authorization") String credentials,
@Body Report report);

View File

@ -692,12 +692,12 @@ public class RetrofitPeertubeAPI {
public APIResponse report(Report report) {
PeertubeService peertubeService = init();
Call<String> report1 = peertubeService.report(getToken(), report);
Call<Report.ReportReturn> report1 = peertubeService.report(getToken(), report);
APIResponse apiResponse = new APIResponse();
try {
Response<String> response = report1.execute();
if (response.isSuccessful()) {
apiResponse.setActionReturn(response.body());
Response<Report.ReportReturn> response = report1.execute();
if (response.isSuccessful() && response.body() != null) {
apiResponse.setActionReturn(response.body().getItemStr().getLabel());
} else {
setError(apiResponse, response.code(), response.errorBody());
}
@ -816,6 +816,9 @@ public class RetrofitPeertubeAPI {
case PEERTUBEDELETECOMMENT:
postCall = peertubeService.deleteComment(getToken(), id, element);
break;
case PEERTUBE_DELETE_ALL_COMMENT_FOR_ACCOUNT:
postCall = peertubeService.deleteAllCommentForAccount(getToken(), id, element);
break;
case DELETE_CHANNEL:
postCall = peertubeService.deleteChannel(getToken(), id);
break;
@ -1384,6 +1387,7 @@ public class RetrofitPeertubeAPI {
UNMUTE,
RATEVIDEO,
PEERTUBEDELETECOMMENT,
PEERTUBE_DELETE_ALL_COMMENT_FOR_ACCOUNT,
PEERTUBEDELETEVIDEO,
REPORT_VIDEO,
REPORT_ACCOUNT,

View File

@ -131,4 +131,17 @@ public class Report {
this.id = id;
}
}
public static class ReportReturn {
@SerializedName("abuse")
private ItemStr reply;
public ItemStr getItemStr() {
return reply;
}
public void setItemStr(ItemStr itemStr) {
this.reply = itemStr;
}
}
}

View File

@ -49,6 +49,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.ShowAccountActivity;
import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
import app.fedilab.fedilabtube.client.data.CommentData.Comment;
@ -57,6 +58,8 @@ import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.viewmodel.PostActionsVM;
import es.dmoral.toasty.Toasty;
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.MUTE;
public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@ -65,10 +68,12 @@ public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
private Context context;
private List<Comment> comments;
private CommentListAdapter commentListAdapter;
boolean isVideoOwner;
public CommentListAdapter(List<Comment> comments) {
public CommentListAdapter(List<Comment> comments, boolean isVideoOwner) {
this.comments = comments;
commentListAdapter = this;
this.isVideoOwner = isVideoOwner;
}
@Override
@ -112,6 +117,18 @@ public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
.inflate(R.menu.comment_menu, popup.getMenu());
if (!Helper.isOwner(context, comment.getAccount())) {
popup.getMenu().findItem(R.id.action_delete).setVisible(false);
}else {
popup.getMenu().findItem(R.id.action_mute).setVisible(false);
popup.getMenu().findItem(R.id.action_remove_comments).setVisible(false);
popup.getMenu().findItem(R.id.action_report).setVisible(false);
}
if( !isVideoOwner) {
popup.getMenu().findItem(R.id.action_remove_comments).setVisible(false);
}
if( !Helper.isLoggedIn(context)) {
popup.getMenu().findItem(R.id.action_mute).setVisible(false);
popup.getMenu().findItem(R.id.action_remove_comments).setVisible(false);
popup.getMenu().findItem(R.id.action_delete).setVisible(false);
}
popup.setOnMenuItemClickListener(item -> {
switch (item.getItemId()) {
@ -142,6 +159,39 @@ public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
case R.id.action_report:
reportComment(comment);
break;
case R.id.action_mute:
PostActionsVM viewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PostActionsVM.class);
viewModel.post(MUTE, comment.getAccount().getAcct(), null).observe((LifecycleOwner) context, apiResponse -> manageVIewPostActions(MUTE, apiResponse));
comments.remove(comment);
notifyDataSetChanged();
if (comments.size() == 0) {
allCommentRemoved.onAllCommentRemoved();
}
break;
case R.id.action_remove_comments:
builder = new android.app.AlertDialog.Builder(context);
builder.setTitle(R.string.delete_account_comment);
builder.setMessage(R.string.delete_account_comment_confirm);
builder.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(R.string.delete, (dialog, which) -> {
new Thread(() -> {
new RetrofitPeertubeAPI(context).post(RetrofitPeertubeAPI.ActionType.PEERTUBE_DELETE_ALL_COMMENT_FOR_ACCOUNT, comment.getAccount().getAcct(), "my-videos");
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
comments.remove(comment);
notifyDataSetChanged();
if (comments.size() == 0) {
allCommentRemoved.onAllCommentRemoved();
}
};
mainHandler.post(myRunnable);
}).start();
dialog.dismiss();
})
.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss())
.show();
break;
}
return true;
});
@ -208,6 +258,8 @@ public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
}
} else if (statusAction == RetrofitPeertubeAPI.ActionType.REPORT_COMMENT) {
Toasty.success(context, context.getString(R.string.successful_report_comment), Toasty.LENGTH_LONG).show();
}else if (statusAction == MUTE) {
Toasty.info(context, context.getString(R.string.muted_done), Toast.LENGTH_LONG).show();
}
}

View File

@ -111,7 +111,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
if (timelineType == TimelineVM.TimelineType.MY_VIDEOS) {
ownVideos = true;
} else {
ownVideos = video.getAccount() != null && video.getAccount().getId() != null && video.getAccount().getHost().compareTo(Helper.getLiveInstance(context)) == 0 && video.getAccount().getId().compareTo(userId) == 0;
ownVideos = Helper.isVideoOwner(context, video);
}
String instance = null;

View File

@ -58,6 +58,7 @@ import app.fedilab.fedilabtube.MainActivity;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.WebviewActivity;
import app.fedilab.fedilabtube.client.data.AccountData.Account;
import app.fedilab.fedilabtube.client.data.VideoData;
import app.fedilab.fedilabtube.client.entities.File;
import app.fedilab.fedilabtube.sqlite.AccountDAO;
import app.fedilab.fedilabtube.sqlite.Sqlite;
@ -592,6 +593,18 @@ public class Helper {
}
}
public static boolean isVideoOwner(Context context, VideoData.Video video) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userName = sharedpreferences.getString(Helper.PREF_KEY_NAME, "");
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, "");
Account account = video.getAccount();
if (instance != null && userName != null) {
return account.getUsername().compareTo(userName) == 0 && account.getHost().compareTo(instance) == 0;
} else {
return false;
}
}
/***
* Return a File depending of the requested quality
* @param context Context

View File

@ -76,7 +76,7 @@
</RelativeLayout>
</RelativeLayout>
<ScrollView
<androidx.core.widget.NestedScrollView
android:id="@+id/peertube_information_container"
android:layout_width="match_parent"
android:layout_height="0dp"
@ -295,7 +295,7 @@
android:textSize="25sp" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</androidx.core.widget.NestedScrollView>
<!-- View where the video will be shown when video goes fullscreen -->
<RelativeLayout
android:id="@+id/videoLayout"

View File

@ -6,6 +6,16 @@
android:icon="@drawable/ic_baseline_delete_24"
android:title="@string/delete"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_mute"
android:icon="@drawable/ic_baseline_volume_mute_24"
android:title="@string/action_mute"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_remove_comments"
android:icon="@drawable/ic_baseline_delete_24"
android:title="@string/delete_account_comment"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_report"
android:icon="@drawable/ic_baseline_report_24"

View File

@ -1,9 +0,0 @@
<?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_report"
android:icon="@drawable/ic_baseline_report_24"
android:title="@string/report"
app:showAsAction="ifRoom" />
</menu>

View File

@ -16,4 +16,9 @@
android:icon="@drawable/ic_baseline_subtitles_24"
android:title="@string/captions"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_report"
android:icon="@drawable/ic_baseline_report_24"
android:title="@string/report"
app:showAsAction="ifRoom" />
</menu>