diff --git a/app/src/acad/res/values/strings.xml b/app/src/acad/res/values/strings.xml index b7f498c..81636cf 100644 --- a/app/src/acad/res/values/strings.xml +++ b/app/src/acad/res/values/strings.xml @@ -178,6 +178,7 @@ Signaler le compte Quelques explications concernant votre signalement… Le compte a été signalé ! + Le commentaire a été signalé ! La vidéo a été signalée ! Veuillez préciser les raisons. Tout @@ -203,6 +204,7 @@ Sourdine Bloqués Aucun compte en sourdine ! + Aucune notification ! Mettre en sourdine Réactiver le compte Le compte a été mis en sourdine ! diff --git a/app/src/full/res/values/strings.xml b/app/src/full/res/values/strings.xml index 625df8d..a1280ce 100644 --- a/app/src/full/res/values/strings.xml +++ b/app/src/full/res/values/strings.xml @@ -16,6 +16,7 @@ Pick an instance This instance does not seem to be valid! No videos! + No notifications! Favicon Open with Edit a playlist @@ -229,6 +230,8 @@ You must be authenticated to proceed to this action! The account has been reported! + The comment has been reported! + The video has been reported! diff --git a/app/src/main/java/app/fedilab/fedilabtube/AccountActivity.java b/app/src/main/java/app/fedilab/fedilabtube/AccountActivity.java index 95f37cf..8f5364e 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/AccountActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/AccountActivity.java @@ -78,14 +78,10 @@ public class AccountActivity extends AppCompatActivity { SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - String instance = Helper.getLiveInstance(AccountActivity.this); + String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); TextView instanceView = findViewById(R.id.instance); - Account account = new AccountDAO(AccountActivity.this, db).getUniqAccount(userId, instance); - if (account == null) { - account = new AccountDAO(AccountActivity.this, db).getUniqAccount(userId, Helper.getPeertubeUrl(instance)); - } + Account account = new AccountDAO(AccountActivity.this, db).getAccountByToken(token); if (account == null) { @@ -241,6 +237,7 @@ public class AccountActivity extends AppCompatActivity { editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, account.getToken()); editor.putString(Helper.PREF_INSTANCE, account.getHost()); editor.putString(Helper.PREF_KEY_ID, account.getId()); + editor.putString(Helper.PREF_KEY_NAME, account.getUsername()); editor.apply(); dialog.dismiss(); Intent intent = new Intent(AccountActivity.this, MainActivity.class); diff --git a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java index 9bbb609..7483cdb 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java @@ -48,6 +48,8 @@ import app.fedilab.fedilabtube.client.data.AccountData.Account; import app.fedilab.fedilabtube.client.entities.Error; import app.fedilab.fedilabtube.client.entities.OauthParams; import app.fedilab.fedilabtube.client.entities.PeertubeInformation; +import app.fedilab.fedilabtube.client.entities.Token; +import app.fedilab.fedilabtube.client.entities.UserMe; import app.fedilab.fedilabtube.client.entities.WellKnownNodeinfo; import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.services.RetrieveInfoService; @@ -71,14 +73,14 @@ public class MainActivity extends AppCompatActivity { BottomNavigationView navView = findViewById(R.id.nav_view); - if (Helper.isLoggedIn(MainActivity.this)) { navView.inflateMenu(R.menu.bottom_nav_menu_connected); final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); + String tokenStr = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); String instance = Helper.getLiveInstance(MainActivity.this); SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - Account account = new AccountDAO(MainActivity.this, db).getUniqAccount(userId, instance); + + Account account = new AccountDAO(MainActivity.this, db).getAccountByToken(tokenStr); if (account != null) { OauthParams oauthParams = new OauthParams(); oauthParams.setGrant_type("refresh_token"); @@ -88,7 +90,19 @@ public class MainActivity extends AppCompatActivity { oauthParams.setAccess_token(account.getToken()); new Thread(() -> { try { - new RetrofitPeertubeAPI(MainActivity.this).manageToken(oauthParams); + Token token = new RetrofitPeertubeAPI(MainActivity.this).manageToken(oauthParams); + if (token == null) { + Helper.logoutCurrentUser(MainActivity.this, account); + return; + } + UserMe userMe = new RetrofitPeertubeAPI(MainActivity.this, instance, token.getAccess_token()).verifyCredentials(); + if (userMe != null && userMe.getAccount() != null) { + new AccountDAO(MainActivity.this.getApplicationContext(), db).updateAccount(userMe.getAccount()); + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putString(Helper.PREF_KEY_ID, account.getId()); + editor.putString(Helper.PREF_KEY_NAME, account.getUsername()); + editor.apply(); + } } catch (Error error) { error.printStackTrace(); } diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java index 97cd3b2..5042cf1 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java @@ -94,7 +94,7 @@ import app.fedilab.fedilabtube.client.data.CommentData.Comment; import app.fedilab.fedilabtube.client.data.PlaylistData.Playlist; import app.fedilab.fedilabtube.client.data.VideoData; import app.fedilab.fedilabtube.client.entities.File; -import app.fedilab.fedilabtube.client.entities.Item; +import app.fedilab.fedilabtube.client.entities.ItemStr; import app.fedilab.fedilabtube.client.entities.Report; import app.fedilab.fedilabtube.drawer.CommentListAdapter; import app.fedilab.fedilabtube.helper.CacheDataSourceFactory; @@ -123,7 +123,7 @@ import static app.fedilab.fedilabtube.viewmodel.PlaylistsVM.action.GET_PLAYLISTS import static app.fedilab.fedilabtube.viewmodel.PlaylistsVM.action.GET_PLAYLIST_FOR_VIDEO; -public class PeertubeActivity extends AppCompatActivity { +public class PeertubeActivity extends AppCompatActivity implements CommentListAdapter.AllCommentRemoved { public static String video_id; private String peertubeInstance, videoId; @@ -149,6 +149,7 @@ public class PeertubeActivity extends AppCompatActivity { private boolean playInMinimized; private boolean onStopCalled; private List captions; + private TextView no_action_text; public static void hideKeyboard(Activity activity) { if (activity != null && activity.getWindow() != null) { @@ -185,10 +186,9 @@ public class PeertubeActivity extends AppCompatActivity { ImageView my_pp = findViewById(R.id.my_pp); SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); - String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - String instance = Helper.getLiveInstance(PeertubeActivity.this); - Account account = new AccountDAO(PeertubeActivity.this, db).getUniqAccount(userId, instance); - Helper.loadGiF(PeertubeActivity.this, account != null && account.getAvatar() != null ? account.getAvatar().getPath() : null, my_pp); + String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); + Account account = new AccountDAO(PeertubeActivity.this, db).getAccountByToken(token); + Helper.loadGiF(PeertubeActivity.this, account.getAvatar() != null ? account.getAvatar().getPath() : null, my_pp); if (Helper.isTablet(PeertubeActivity.this)) { @@ -303,10 +303,8 @@ public class PeertubeActivity extends AppCompatActivity { peertube_playlist.setVisibility(View.VISIBLE); peertube_bookmark.setVisibility(View.GONE); - TimelineVM feedsViewModel = new ViewModelProvider(PeertubeActivity.this).get(TimelineVM.class); feedsViewModel.getVideo(videoId).observe(PeertubeActivity.this, this::manageVIewVideo); - CaptionsVM captionsViewModel = new ViewModelProvider(PeertubeActivity.this).get(CaptionsVM.class); captionsViewModel.getCaptions(videoId).observe(PeertubeActivity.this, this::manageCaptions); } @@ -537,7 +535,7 @@ public class PeertubeActivity extends AppCompatActivity { } } }); - + no_action_text = findViewById(R.id.no_action_text); if (peertube.isCommentsEnabled()) { CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class); @@ -546,7 +544,7 @@ public class PeertubeActivity extends AppCompatActivity { } else { RelativeLayout no_action = findViewById(R.id.no_action); - TextView no_action_text = findViewById(R.id.no_action_text); + no_action_text.setText(getString(R.string.comment_no_allowed_peertube)); no_action.setVisibility(View.VISIBLE); write_comment_container.setVisibility(View.GONE); @@ -689,9 +687,9 @@ public class PeertubeActivity extends AppCompatActivity { int i = 1; if (captions.size() > 0) { for (Caption caption : captions) { - Item lang = caption.getLanguage(); - itemsLabelLanguage[i] = String.valueOf(lang.getId()); - itemsKeyLanguage[i] = lang.getLabel(); + ItemStr lang = caption.getLanguage(); + itemsLabelLanguage[i] = lang.getLabel(); + itemsKeyLanguage[i] = lang.getId(); i++; } } @@ -797,8 +795,9 @@ public class PeertubeActivity extends AppCompatActivity { return; } List comments = new ArrayList<>(); + for (Comment comment : apiResponse.getComments()) { - if (comment.getDescription() != null && comment.getDescription().trim().length() > 0) { + if (comment.getText() != null && comment.getText().trim().length() > 0) { comments.add(comment); } } @@ -806,6 +805,7 @@ public class PeertubeActivity extends AppCompatActivity { if (comments.size() > 0) { lv_comments.setVisibility(View.VISIBLE); CommentListAdapter commentListAdapter = new CommentListAdapter(comments); + commentListAdapter.allCommentRemoved = PeertubeActivity.this; LinearLayoutManager mLayoutManager = new LinearLayoutManager(PeertubeActivity.this); lv_comments.setLayoutManager(mLayoutManager); lv_comments.setNestedScrollingEnabled(false); @@ -1040,4 +1040,8 @@ public class PeertubeActivity extends AppCompatActivity { } } + @Override + public void onAllCommentRemoved() { + no_action_text.setVisibility(View.VISIBLE); + } } diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java b/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java index 9b6bbe5..d1cef90 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java @@ -35,6 +35,7 @@ import app.fedilab.fedilabtube.client.entities.PlaylistExist; import app.fedilab.fedilabtube.client.entities.Rating; import app.fedilab.fedilabtube.client.entities.Report; import app.fedilab.fedilabtube.client.entities.Token; +import app.fedilab.fedilabtube.client.entities.UserMe; import app.fedilab.fedilabtube.client.entities.WellKnownNodeinfo; import okhttp3.MultipartBody; import okhttp3.RequestBody; @@ -45,6 +46,7 @@ import retrofit2.http.Field; import retrofit2.http.FormUrlEncoded; import retrofit2.http.GET; import retrofit2.http.Header; +import retrofit2.http.Headers; import retrofit2.http.Multipart; import retrofit2.http.POST; import retrofit2.http.PUT; @@ -109,7 +111,7 @@ public interface PeertubeService { @Field("grant_type") String grant_type); @GET("users/me") - Call verifyCredentials(@Header("Authorization") String credentials); + Call verifyCredentials(@Header("Authorization") String credentials); //Timelines Authenticated //Subscriber timeline @@ -138,7 +140,7 @@ public interface PeertubeService { //History @GET("users/me/history/videos") - Call getHistory(@Query("start") String maxId); + Call getHistory(@Header("Authorization") String credentials, @Query("start") String maxId); //Search @GET("search/videos") @@ -340,9 +342,18 @@ public interface PeertubeService { @DELETE("videos/{id}/comments/{commentId}") Call deleteComment(@Header("Authorization") String credentials, @Path("id") String id, @Path("commentId") String commentId); - @POST("abuse") - Call report(@Header("Authorization") String credentials, @Body Report report); + @Headers({"Content-Type: application/json", "Cache-Control: max-age=640000"}) + @POST("abuses") + Call report( + @Header("Authorization") String credentials, + @Body Report report); - @POST("abuse") - Call register(@Query("email") String email, @Query("password") String password, @Query("username") String username, @Query("displayName") String displayName); + @FormUrlEncoded + @POST("users/register") + Call register( + @Field("email") String email, + @Field("password") String password, + @Field("username") String username, + @Field("displayName") String displayName + ); } 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 0b2c897..4c89949 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java @@ -58,6 +58,7 @@ import app.fedilab.fedilabtube.client.entities.PlaylistParams; import app.fedilab.fedilabtube.client.entities.Rating; import app.fedilab.fedilabtube.client.entities.Report; import app.fedilab.fedilabtube.client.entities.Token; +import app.fedilab.fedilabtube.client.entities.UserMe; import app.fedilab.fedilabtube.client.entities.VideoParams; import app.fedilab.fedilabtube.client.entities.WellKnownNodeinfo; import app.fedilab.fedilabtube.helper.Helper; @@ -107,7 +108,8 @@ public class RetrofitPeertubeAPI { instance = Helper.getPeertubeUrl(host); } try { - account = new RetrofitPeertubeAPI(activity, instance, token).verifyCredentials(); + UserMe userMe = new RetrofitPeertubeAPI(activity, instance, token).verifyCredentials(); + account = userMe.getAccount(); } catch (Error error) { Error.displayError(activity, error); error.printStackTrace(); @@ -128,6 +130,7 @@ public class RetrofitPeertubeAPI { boolean userExists = new AccountDAO(activity, db).userExist(account); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(Helper.PREF_KEY_ID, account.getId()); + editor.putString(Helper.PREF_KEY_NAME, account.getUsername()); if (!host.startsWith("tube")) { editor.putString(Helper.PREF_INSTANCE, host); } @@ -321,7 +324,7 @@ public class RetrofitPeertubeAPI { videoCall = peertubeService.getTrendingVideos(max_id, filter); break; case HISTORY: - videoCall = peertubeService.getHistory(max_id); + videoCall = peertubeService.getHistory(getToken(), max_id); break; case RECENT: videoCall = peertubeService.getRecentlyAddedVideos(max_id, filter); @@ -436,6 +439,7 @@ public class RetrofitPeertubeAPI { Response response = captions.execute(); if (response.isSuccessful() && response.body() != null) { apiResponse.setCaptions(response.body().data); + } else { setError(apiResponse, response.code(), response.errorBody()); } @@ -627,12 +631,12 @@ public class RetrofitPeertubeAPI { * Verifiy credential of the authenticated user *synchronously* * @return Account */ - public AccountData.Account verifyCredentials() throws Error { + public UserMe verifyCredentials() throws Error { PeertubeService peertubeService = init(); - Call accountCall = peertubeService.verifyCredentials("Bearer " + token); + Call accountCall = peertubeService.verifyCredentials("Bearer " + token); APIResponse apiResponse = new APIResponse(); try { - Response response = accountCall.execute(); + Response response = accountCall.execute(); if (response.isSuccessful() && response.body() != null) { return response.body(); } else { @@ -701,7 +705,7 @@ public class RetrofitPeertubeAPI { RequestBody name = RequestBody.create(MediaType.parse("text/plain"), videoParams.getName()); List tags = null; - if( videoParams.getTags() != null && videoParams.getTags().size() >0 ) { + if (videoParams.getTags() != null && videoParams.getTags().size() > 0) { tags = new ArrayList<>(); for (String tag : videoParams.getTags()) { tags.add(RequestBody.create(MediaType.parse("text/plain"), tag)); @@ -777,6 +781,9 @@ public class RetrofitPeertubeAPI { case PEERTUBEDELETEVIDEO: postCall = peertubeService.deleteVideo(getToken(), id); break; + case PEERTUBEDELETECOMMENT: + postCall = peertubeService.deleteComment(getToken(), id, element); + break; case DELETE_CHANNEL: postCall = peertubeService.deleteChannel(getToken(), id); break; @@ -1342,6 +1349,7 @@ public class RetrofitPeertubeAPI { PEERTUBEDELETEVIDEO, REPORT_VIDEO, REPORT_ACCOUNT, + REPORT_COMMENT, DELETE_CHANNEL, ADD_COMMENT, REPLY, diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/data/CaptionData.java b/app/src/main/java/app/fedilab/fedilabtube/client/data/CaptionData.java index 4dc8f2f..e10b5a6 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/data/CaptionData.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/data/CaptionData.java @@ -18,7 +18,7 @@ import com.google.gson.annotations.SerializedName; import java.util.List; -import app.fedilab.fedilabtube.client.entities.Item; +import app.fedilab.fedilabtube.client.entities.ItemStr; @SuppressWarnings("unused") public class CaptionData { @@ -32,7 +32,7 @@ public class CaptionData { @SerializedName("captionPath") private String captionPath; @SerializedName("language") - private Item language; + private ItemStr language; public String getCaptionPath() { return captionPath; @@ -42,11 +42,11 @@ public class CaptionData { this.captionPath = captionPath; } - public Item getLanguage() { + public ItemStr getLanguage() { return language; } - public void setLanguage(Item language) { + public void setLanguage(ItemStr language) { this.language = language; } } diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/data/CommentData.java b/app/src/main/java/app/fedilab/fedilabtube/client/data/CommentData.java index 835332a..8867c0c 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/data/CommentData.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/data/CommentData.java @@ -34,26 +34,28 @@ public class CommentData { private AccountData.Account account; @SerializedName("createdAt") private Date createdAt; - @SerializedName("description") - private String description; - @SerializedName("displayName") - private String displayName; - @SerializedName("followersCount") - private int followersCount; - @SerializedName("followingCount") - private int followingCount; - @SerializedName("host") - private String host; - @SerializedName("hostRedundancyAllowed") - private boolean hostRedundancyAllowed; + @SerializedName("deletedAt") + private Date deletedAt; @SerializedName("id") private String id; - @SerializedName("name") - private String name; + @SerializedName("inReplyToCommentId") + private String inReplyToCommentId; + @SerializedName("isDeleted") + private boolean isDeleted; + @SerializedName("text") + private String text; + @SerializedName("threadId") + private String threadId; + @SerializedName("totalReplies") + private int totalReplies; + @SerializedName("totalRepliesFromVideoAuthor") + private int totalRepliesFromVideoAuthor; @SerializedName("updatedAt") private String updatedAt; @SerializedName("url") private String url; + @SerializedName("videoId") + private String videoId; public AccountData.Account getAccount() { @@ -72,52 +74,12 @@ public class CommentData { this.createdAt = createdAt; } - public String getDescription() { - return description; + public Date getDeletedAt() { + return deletedAt; } - public void setDescription(String description) { - this.description = description; - } - - public String getDisplayName() { - return displayName; - } - - public void setDisplayName(String displayName) { - this.displayName = displayName; - } - - public int getFollowersCount() { - return followersCount; - } - - public void setFollowersCount(int followersCount) { - this.followersCount = followersCount; - } - - public int getFollowingCount() { - return followingCount; - } - - public void setFollowingCount(int followingCount) { - this.followingCount = followingCount; - } - - public String getHost() { - return host; - } - - public void setHost(String host) { - this.host = host; - } - - public boolean isHostRedundancyAllowed() { - return hostRedundancyAllowed; - } - - public void setHostRedundancyAllowed(boolean hostRedundancyAllowed) { - this.hostRedundancyAllowed = hostRedundancyAllowed; + public void setDeletedAt(Date deletedAt) { + this.deletedAt = deletedAt; } public String getId() { @@ -128,12 +90,52 @@ public class CommentData { this.id = id; } - public String getName() { - return name; + public String getInReplyToCommentId() { + return inReplyToCommentId; } - public void setName(String name) { - this.name = name; + public void setInReplyToCommentId(String inReplyToCommentId) { + this.inReplyToCommentId = inReplyToCommentId; + } + + public boolean isDeleted() { + return isDeleted; + } + + public void setDeleted(boolean deleted) { + isDeleted = deleted; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public String getThreadId() { + return threadId; + } + + public void setThreadId(String threadId) { + this.threadId = threadId; + } + + public int getTotalReplies() { + return totalReplies; + } + + public void setTotalReplies(int totalReplies) { + this.totalReplies = totalReplies; + } + + public int getTotalRepliesFromVideoAuthor() { + return totalRepliesFromVideoAuthor; + } + + public void setTotalRepliesFromVideoAuthor(int totalRepliesFromVideoAuthor) { + this.totalRepliesFromVideoAuthor = totalRepliesFromVideoAuthor; } public String getUpdatedAt() { @@ -151,6 +153,14 @@ public class CommentData { public void setUrl(String url) { this.url = url; } + + public String getVideoId() { + return videoId; + } + + public void setVideoId(String videoId) { + this.videoId = videoId; + } } public static class NotificationComment { diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/entities/Avatar.java b/app/src/main/java/app/fedilab/fedilabtube/client/entities/Avatar.java index 4756013..f837e24 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/entities/Avatar.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/entities/Avatar.java @@ -5,6 +5,8 @@ import android.os.Parcelable; import com.google.gson.annotations.SerializedName; +import java.util.Date; + /* Copyright 2020 Thomas Schneider * * This file is a part of TubeLab @@ -22,7 +24,8 @@ import com.google.gson.annotations.SerializedName; @SuppressWarnings("unused") public class Avatar implements Parcelable { - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + + public static final Creator CREATOR = new Creator() { @Override public Avatar createFromParcel(Parcel source) { return new Avatar(source); @@ -34,26 +37,28 @@ public class Avatar implements Parcelable { } }; @SerializedName("createdAt") - private String createdAt; + private Date createdAt; @SerializedName("path") private String path; @SerializedName("updatedAt") - private String updatedAt; + private Date updatedAt; public Avatar() { } protected Avatar(Parcel in) { - this.createdAt = in.readString(); + long tmpCreatedAt = in.readLong(); + this.createdAt = tmpCreatedAt == -1 ? null : new Date(tmpCreatedAt); this.path = in.readString(); - this.updatedAt = in.readString(); + long tmpUpdatedAt = in.readLong(); + this.updatedAt = tmpUpdatedAt == -1 ? null : new Date(tmpUpdatedAt); } - public String getCreatedAt() { + public Date getCreatedAt() { return createdAt; } - public void setCreatedAt(String createdAt) { + public void setCreatedAt(Date createdAt) { this.createdAt = createdAt; } @@ -65,11 +70,11 @@ public class Avatar implements Parcelable { this.path = path; } - public String getUpdatedAt() { + public Date getUpdatedAt() { return updatedAt; } - public void setUpdatedAt(String updatedAt) { + public void setUpdatedAt(Date updatedAt) { this.updatedAt = updatedAt; } @@ -80,8 +85,8 @@ public class Avatar implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { - dest.writeString(this.createdAt); + dest.writeLong(this.createdAt != null ? this.createdAt.getTime() : -1); dest.writeString(this.path); - dest.writeString(this.updatedAt); + dest.writeLong(this.updatedAt != null ? this.updatedAt.getTime() : -1); } } diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/entities/NotificationSettings.java b/app/src/main/java/app/fedilab/fedilabtube/client/entities/NotificationSettings.java new file mode 100644 index 0000000..0102561 --- /dev/null +++ b/app/src/main/java/app/fedilab/fedilabtube/client/entities/NotificationSettings.java @@ -0,0 +1,162 @@ +package app.fedilab.fedilabtube.client.entities; +/* Copyright 2020 Thomas Schneider + * + * This file is a part of TubeLab + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with TubeLab; if not, + * see . */ + +import com.google.gson.annotations.SerializedName; + +public class NotificationSettings { + + @SerializedName("abuseAsModerator") + private int abuseAsModerator; + @SerializedName("abuseNewMessage") + private int abuseNewMessage; + @SerializedName("abuseStateChange") + private int abuseStateChange; + @SerializedName("autoInstanceFollowing") + private int autoInstanceFollowing; + @SerializedName("blacklistOnMyVideo") + private int blacklistOnMyVideo; + @SerializedName("commentMention") + private int commentMention; + @SerializedName("myVideoImportFinished") + private int myVideoImportFinished; + @SerializedName("myVideoPublished") + private int myVideoPublished; + @SerializedName("newCommentOnMyVideo") + private int newCommentOnMyVideo; + @SerializedName("newFollow") + private int newFollow; + @SerializedName("newInstanceFollower") + private int newInstanceFollower; + @SerializedName("newUserRegistration") + private int newUserRegistration; + @SerializedName("newVideoFromSubscription") + private int newVideoFromSubscription; + @SerializedName("videoAutoBlacklistAsModerator") + private int videoAutoBlacklistAsModerator; + + + public int getAbuseAsModerator() { + return abuseAsModerator; + } + + public void setAbuseAsModerator(int abuseAsModerator) { + this.abuseAsModerator = abuseAsModerator; + } + + public int getAbuseNewMessage() { + return abuseNewMessage; + } + + public void setAbuseNewMessage(int abuseNewMessage) { + this.abuseNewMessage = abuseNewMessage; + } + + public int getAbuseStateChange() { + return abuseStateChange; + } + + public void setAbuseStateChange(int abuseStateChange) { + this.abuseStateChange = abuseStateChange; + } + + public int getAutoInstanceFollowing() { + return autoInstanceFollowing; + } + + public void setAutoInstanceFollowing(int autoInstanceFollowing) { + this.autoInstanceFollowing = autoInstanceFollowing; + } + + public int getBlacklistOnMyVideo() { + return blacklistOnMyVideo; + } + + public void setBlacklistOnMyVideo(int blacklistOnMyVideo) { + this.blacklistOnMyVideo = blacklistOnMyVideo; + } + + public int getCommentMention() { + return commentMention; + } + + public void setCommentMention(int commentMention) { + this.commentMention = commentMention; + } + + public int getMyVideoImportFinished() { + return myVideoImportFinished; + } + + public void setMyVideoImportFinished(int myVideoImportFinished) { + this.myVideoImportFinished = myVideoImportFinished; + } + + public int getMyVideoPublished() { + return myVideoPublished; + } + + public void setMyVideoPublished(int myVideoPublished) { + this.myVideoPublished = myVideoPublished; + } + + public int getNewCommentOnMyVideo() { + return newCommentOnMyVideo; + } + + public void setNewCommentOnMyVideo(int newCommentOnMyVideo) { + this.newCommentOnMyVideo = newCommentOnMyVideo; + } + + public int getNewFollow() { + return newFollow; + } + + public void setNewFollow(int newFollow) { + this.newFollow = newFollow; + } + + public int getNewInstanceFollower() { + return newInstanceFollower; + } + + public void setNewInstanceFollower(int newInstanceFollower) { + this.newInstanceFollower = newInstanceFollower; + } + + public int getNewUserRegistration() { + return newUserRegistration; + } + + public void setNewUserRegistration(int newUserRegistration) { + this.newUserRegistration = newUserRegistration; + } + + public int getNewVideoFromSubscription() { + return newVideoFromSubscription; + } + + public void setNewVideoFromSubscription(int newVideoFromSubscription) { + this.newVideoFromSubscription = newVideoFromSubscription; + } + + public int getVideoAutoBlacklistAsModerator() { + return videoAutoBlacklistAsModerator; + } + + public void setVideoAutoBlacklistAsModerator(int videoAutoBlacklistAsModerator) { + this.videoAutoBlacklistAsModerator = videoAutoBlacklistAsModerator; + } +} diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/entities/UserMe.java b/app/src/main/java/app/fedilab/fedilabtube/client/entities/UserMe.java new file mode 100644 index 0000000..7432618 --- /dev/null +++ b/app/src/main/java/app/fedilab/fedilabtube/client/entities/UserMe.java @@ -0,0 +1,257 @@ +package app.fedilab.fedilabtube.client.entities; +/* Copyright 2020 Thomas Schneider + * + * This file is a part of TubeLab + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with TubeLab; if not, + * see . */ + +import com.google.gson.annotations.SerializedName; + +import java.util.Date; +import java.util.List; + +import app.fedilab.fedilabtube.client.data.AccountData.Account; +import app.fedilab.fedilabtube.client.data.ChannelData; + +public class UserMe { + + @SerializedName("account") + private Account account; + @SerializedName("autoPlayNextVideo") + private boolean autoPlayNextVideo; + @SerializedName("autoPlayNextVideoPlaylist") + private boolean autoPlayNextVideoPlaylist; + @SerializedName("blocked") + private boolean blocked; + @SerializedName("blockedReason") + private String blockedReason; + @SerializedName("createdAt") + private Date createdAt; + @SerializedName("email") + private String email; + @SerializedName("emailVerified") + private String emailVerified; + @SerializedName("id") + private String id; + @SerializedName("lastLoginDate") + private Date lastLoginDate; + @SerializedName("noInstanceConfigWarningModal") + private boolean noInstanceConfigWarningModal; + @SerializedName("noWelcomeModal") + private boolean noWelcomeModal; + @SerializedName("notificationSettings") + private NotificationSettings notificationSettings; + @SerializedName("nsfwPolicy") + private String nsfwPolicy; + @SerializedName("role") + private int role; + @SerializedName("roleLabel") + private String roleLabel; + @SerializedName("username") + private String username; + @SerializedName("videoChannels") + private List videoChannels; + @SerializedName("videoLanguages") + private List videoLanguages; + @SerializedName("videoQuota") + private String videoQuota; + @SerializedName("videoQuotaDaily") + private String videoQuotaDaily; + @SerializedName("videosHistoryEnabled") + private boolean videosHistoryEnabled; + @SerializedName("webTorrentEnabled") + private boolean webTorrentEnabled; + + public Account getAccount() { + return account; + } + + public void setAccount(Account account) { + this.account = account; + } + + public boolean isAutoPlayNextVideo() { + return autoPlayNextVideo; + } + + public void setAutoPlayNextVideo(boolean autoPlayNextVideo) { + this.autoPlayNextVideo = autoPlayNextVideo; + } + + public boolean isAutoPlayNextVideoPlaylist() { + return autoPlayNextVideoPlaylist; + } + + public void setAutoPlayNextVideoPlaylist(boolean autoPlayNextVideoPlaylist) { + this.autoPlayNextVideoPlaylist = autoPlayNextVideoPlaylist; + } + + public boolean isBlocked() { + return blocked; + } + + public void setBlocked(boolean blocked) { + this.blocked = blocked; + } + + public String getBlockedReason() { + return blockedReason; + } + + public void setBlockedReason(String blockedReason) { + this.blockedReason = blockedReason; + } + + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getEmailVerified() { + return emailVerified; + } + + public void setEmailVerified(String emailVerified) { + this.emailVerified = emailVerified; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Date getLastLoginDate() { + return lastLoginDate; + } + + public void setLastLoginDate(Date lastLoginDate) { + this.lastLoginDate = lastLoginDate; + } + + public boolean isNoInstanceConfigWarningModal() { + return noInstanceConfigWarningModal; + } + + public void setNoInstanceConfigWarningModal(boolean noInstanceConfigWarningModal) { + this.noInstanceConfigWarningModal = noInstanceConfigWarningModal; + } + + public boolean isNoWelcomeModal() { + return noWelcomeModal; + } + + public void setNoWelcomeModal(boolean noWelcomeModal) { + this.noWelcomeModal = noWelcomeModal; + } + + public NotificationSettings getNotificationSettings() { + return notificationSettings; + } + + public void setNotificationSettings(NotificationSettings notificationSettings) { + this.notificationSettings = notificationSettings; + } + + public String getNsfwPolicy() { + return nsfwPolicy; + } + + public void setNsfwPolicy(String nsfwPolicy) { + this.nsfwPolicy = nsfwPolicy; + } + + public int getRole() { + return role; + } + + public void setRole(int role) { + this.role = role; + } + + public String getRoleLabel() { + return roleLabel; + } + + public void setRoleLabel(String roleLabel) { + this.roleLabel = roleLabel; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public List getVideoChannels() { + return videoChannels; + } + + public void setVideoChannels(List videoChannels) { + this.videoChannels = videoChannels; + } + + public List getVideoLanguages() { + return videoLanguages; + } + + public void setVideoLanguages(List videoLanguages) { + this.videoLanguages = videoLanguages; + } + + public String getVideoQuota() { + return videoQuota; + } + + public void setVideoQuota(String videoQuota) { + this.videoQuota = videoQuota; + } + + public String getVideoQuotaDaily() { + return videoQuotaDaily; + } + + public void setVideoQuotaDaily(String videoQuotaDaily) { + this.videoQuotaDaily = videoQuotaDaily; + } + + public boolean isVideosHistoryEnabled() { + return videosHistoryEnabled; + } + + public void setVideosHistoryEnabled(boolean videosHistoryEnabled) { + this.videosHistoryEnabled = videosHistoryEnabled; + } + + public boolean isWebTorrentEnabled() { + return webTorrentEnabled; + } + + public void setWebTorrentEnabled(boolean webTorrentEnabled) { + this.webTorrentEnabled = webTorrentEnabled; + } +} diff --git a/app/src/main/java/app/fedilab/fedilabtube/drawer/ChannelListAdapter.java b/app/src/main/java/app/fedilab/fedilabtube/drawer/ChannelListAdapter.java index b916ed9..ac658fd 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/drawer/ChannelListAdapter.java +++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/ChannelListAdapter.java @@ -91,8 +91,6 @@ public class ChannelListAdapter extends RecyclerView.Adapter { - channels.remove(channel); - notifyDataSetChanged(); new Thread(() -> { new RetrofitPeertubeAPI(context).post(RetrofitPeertubeAPI.ActionType.DELETE_CHANNEL, channel.getName(), null); Handler mainHandler = new Handler(Looper.getMainLooper()); diff --git a/app/src/main/java/app/fedilab/fedilabtube/drawer/CommentListAdapter.java b/app/src/main/java/app/fedilab/fedilabtube/drawer/CommentListAdapter.java index d93c29a..2f7f1c1 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/drawer/CommentListAdapter.java +++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/CommentListAdapter.java @@ -15,9 +15,11 @@ package app.fedilab.fedilabtube.drawer; * see . */ import android.annotation.SuppressLint; +import android.app.Activity; import android.content.Context; -import android.content.SharedPreferences; import android.os.Build; +import android.os.Handler; +import android.os.Looper; import android.text.Html; import android.text.Spannable; import android.text.SpannableString; @@ -28,13 +30,14 @@ import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.widget.PopupMenu; import androidx.core.content.ContextCompat; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.ViewModelProvider; @@ -45,28 +48,24 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import app.fedilab.fedilabtube.PeertubeActivity; import app.fedilab.fedilabtube.R; import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI; import app.fedilab.fedilabtube.client.data.CommentData.Comment; +import app.fedilab.fedilabtube.client.entities.Report; import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.viewmodel.PostActionsVM; import es.dmoral.toasty.Toasty; -import static android.content.Context.MODE_PRIVATE; -import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.PEERTUBEDELETECOMMENT; - public class CommentListAdapter extends RecyclerView.Adapter { + public AllCommentRemoved allCommentRemoved; private Context context; private List comments; - private CommentListAdapter commentListAdapter; - public CommentListAdapter(List comments) { this.comments = comments; commentListAdapter = this; @@ -89,7 +88,7 @@ public class CommentListAdapter extends RecyclerView.Adapter { - AlertDialog.Builder builderInner; - builderInner = new AlertDialog.Builder(context); - builderInner.setTitle(R.string.delete_comment); - builderInner.setMessage(R.string.delete_comment_confirm); - builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); - builderInner.setPositiveButton(R.string.yes, (dialog, which) -> { - PostActionsVM viewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PostActionsVM.class); - viewModel.post(PEERTUBEDELETECOMMENT, PeertubeActivity.video_id, comment.getId()).observe((LifecycleOwner) context, apiResponse -> manageVIewPostActions(PEERTUBEDELETECOMMENT, apiResponse)); - dialog.dismiss(); + + + holder.more_actions.setOnClickListener(view -> { + PopupMenu popup = new PopupMenu(context, holder.more_actions); + popup.getMenuInflater() + .inflate(R.menu.comment_menu, popup.getMenu()); + if (!Helper.isOwner(context, comment.getAccount())) { + popup.getMenu().findItem(R.id.action_delete).setVisible(false); + } + popup.setOnMenuItemClickListener(item -> { + switch (item.getItemId()) { + case R.id.action_delete: + android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context); + builder.setTitle(R.string.delete_comment); + builder.setMessage(R.string.delete_comment_confirm); + builder.setIcon(android.R.drawable.ic_dialog_alert) + .setPositiveButton(R.string.delete, (dialog, which) -> { + new Thread(() -> { + new RetrofitPeertubeAPI(context).post(RetrofitPeertubeAPI.ActionType.PEERTUBEDELETECOMMENT, comment.getVideoId(), comment.getId()); + 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; + case R.id.action_report: + reportComment(comment); + break; + } + return true; }); - builderInner.show(); + popup.show(); }); - - - holder.status_content.setOnTouchListener((view, motionEvent) -> { + holder.comment_content.setOnTouchListener((view, motionEvent) -> { if (motionEvent.getAction() == MotionEvent.ACTION_UP && !view.hasFocus()) { try { view.requestFocus(); @@ -139,17 +159,16 @@ public class CommentListAdapter extends RecyclerView.Adapter= Build.VERSION_CODES.N) - commentSpan = Html.fromHtml(comment.getDescription(), Html.FROM_HTML_MODE_LEGACY); + commentSpan = Html.fromHtml(comment.getText(), Html.FROM_HTML_MODE_LEGACY); else - commentSpan = Html.fromHtml(comment.getDescription()); - holder.status_content.setText(commentSpan, TextView.BufferType.SPANNABLE); + commentSpan = Html.fromHtml(comment.getText()); + holder.comment_content.setText(commentSpan, TextView.BufferType.SPANNABLE); - holder.status_content.setMovementMethod(LinkMovementMethod.getInstance()); + holder.comment_content.setMovementMethod(LinkMovementMethod.getInstance()); + holder.comment_account_displayname.setText(comment.getAccount().getDisplayName()); - holder.status_account_displayname.setVisibility(View.GONE); if (comment.getAccount() != null) { - holder.status_account_displayname_owner.setText(comment.getAccount().getUsername().replace("@", ""), TextView.BufferType.SPANNABLE); Spannable wordtoSpan; Pattern hashAcct; wordtoSpan = new SpannableString("@" + comment.getAccount().getAcct()); @@ -161,16 +180,14 @@ public class CommentListAdapter extends RecyclerView.Adapter= matchEnd && matchStart < matchEnd) { wordtoSpan.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, android.R.color.darker_gray)), matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } - } - holder.status_account_username.setText(wordtoSpan); + holder.comment_account_username.setText(wordtoSpan); } - - holder.status_toot_date.setText(Helper.dateDiff(context, comment.getCreatedAt())); + holder.comment_date.setText(Helper.dateDiff(context, comment.getCreatedAt())); - Helper.loadGiF(context, comment.getAccount().getAvatar().getPath(), holder.status_account_profile); + Helper.loadGiF(context, comment.getAccount().getAvatar() != null ? comment.getAccount().getAvatar().getPath() : null, holder.comment_account_profile); } public void manageVIewPostActions(RetrofitPeertubeAPI.ActionType statusAction, APIResponse apiResponse) { @@ -179,7 +196,6 @@ public class CommentListAdapter extends RecyclerView.Adapter dialog.dismiss()); + dialogBuilder.setPositiveButton(R.string.report, (dialog, id) -> { + if (report_content.getText().toString().trim().length() == 0) { + Toasty.info(context, context.getString(R.string.report_comment_size), Toasty.LENGTH_LONG).show(); + } else { + PostActionsVM viewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(PostActionsVM.class); + Report report = new Report(); + Report.CommentReport commentReport = new Report.CommentReport(); + commentReport.setId(comment.getId()); + report.setComment(commentReport); + report.setReason(report_content.getText().toString()); + viewModel.report(report).observe((LifecycleOwner) context, apiResponse -> manageVIewPostActions(RetrofitPeertubeAPI.ActionType.REPORT_COMMENT, apiResponse)); + dialog.dismiss(); + } + }); + androidx.appcompat.app.AlertDialog alertDialog2 = dialogBuilder.create(); + alertDialog2.show(); + } + + public interface AllCommentRemoved { + void onAllCommentRemoved(); + } + static class ViewHolder extends RecyclerView.ViewHolder { - TextView status_content; - TextView status_account_username; - TextView status_account_displayname, status_account_displayname_owner; - ImageView status_account_profile; - TextView status_toot_date; + TextView comment_content; + TextView comment_account_username; + TextView comment_account_displayname; + ImageView comment_account_profile; + TextView comment_date; LinearLayout main_container; - LinearLayout status_content_container; - TextView status_peertube_delete; + TextView more_actions; @SuppressLint("SetJavaScriptEnabled") ViewHolder(View itemView) { super(itemView); - status_content = itemView.findViewById(R.id.status_content); - status_account_username = itemView.findViewById(R.id.status_account_username); - status_account_displayname = itemView.findViewById(R.id.status_account_displayname); - status_account_displayname_owner = itemView.findViewById(R.id.status_account_displayname_owner); - status_account_profile = itemView.findViewById(R.id.status_account_profile); - status_toot_date = itemView.findViewById(R.id.status_toot_date); + comment_content = itemView.findViewById(R.id.comment_content); + comment_account_username = itemView.findViewById(R.id.comment_account_username); + comment_account_profile = itemView.findViewById(R.id.comment_account_profile); + comment_account_displayname = itemView.findViewById(R.id.comment_account_displayname); + comment_date = itemView.findViewById(R.id.comment_date); main_container = itemView.findViewById(R.id.main_container); - status_content_container = itemView.findViewById(R.id.status_content_container); - status_peertube_delete = itemView.findViewById(R.id.status_peertube_delete); + more_actions = itemView.findViewById(R.id.more_actions); } diff --git a/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayNotificationsFragment.java b/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayNotificationsFragment.java index d51c1a7..a313051 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayNotificationsFragment.java +++ b/app/src/main/java/app/fedilab/fedilabtube/fragment/DisplayNotificationsFragment.java @@ -20,6 +20,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.RelativeLayout; +import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; @@ -75,6 +76,8 @@ public class DisplayNotificationsFragment extends Fragment { mainLoader = rootView.findViewById(R.id.loader); nextElementLoader = rootView.findViewById(R.id.loading_next); textviewNoAction = rootView.findViewById(R.id.no_action); + TextView no_action_text = rootView.findViewById(R.id.no_action_text); + no_action_text.setText(context.getString(R.string.no_notifications)); mainLoader.setVisibility(View.VISIBLE); nextElementLoader.setVisibility(View.GONE); peertubeNotificationsListAdapter = new PeertubeNotificationsListAdapter(this.notifications); diff --git a/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java b/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java index 235b7c6..9ffb314 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java +++ b/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java @@ -106,6 +106,7 @@ public class Helper { public static final String SET_PROXY_PASSWORD = "set_proxy_password"; public static final String INTENT_ACTION = "intent_action"; public static final String PREF_KEY_ID = "userID"; + public static final String PREF_KEY_NAME = "my_user_name"; public static final String PREF_IS_MODERATOR = "is_moderator"; public static final String PREF_IS_ADMINISTRATOR = "is_administrator"; public static final String PREF_INSTANCE = "instance"; @@ -670,4 +671,15 @@ public class Helper { public static int getColorPrimary() { return BuildConfig.full_instances ? R.color.colorPrimary_full : R.color.colorPrimary; } + + public static boolean isOwner(Context context, Account account) { + 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, ""); + if (instance != null && userName != null) { + return account.getUsername().compareTo(userName) == 0 && account.getHost().compareTo(instance) == 0; + } else { + return false; + } + } } diff --git a/app/src/main/java/app/fedilab/fedilabtube/sqlite/AccountDAO.java b/app/src/main/java/app/fedilab/fedilabtube/sqlite/AccountDAO.java index 0e81fe8..176a3c8 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/sqlite/AccountDAO.java +++ b/app/src/main/java/app/fedilab/fedilabtube/sqlite/AccountDAO.java @@ -106,6 +106,7 @@ public class AccountDAO { account.setCreatedAt(new Date()); if (account.getDescription() == null) account.setDescription(""); + values.put(Sqlite.COL_USER_ID, account.getId()); values.put(Sqlite.COL_USERNAME, account.getUsername()); values.put(Sqlite.COL_ACCT, account.getUsername() + "@" + account.getHost()); values.put(Sqlite.COL_DISPLAYED_NAME, account.getDisplayName()); @@ -113,20 +114,18 @@ public class AccountDAO { values.put(Sqlite.COL_FOLLOWING_COUNT, account.getFollowingCount()); values.put(Sqlite.COL_NOTE, account.getDescription()); values.put(Sqlite.COL_URL, account.getUrl()); - values.put(Sqlite.COL_AVATAR, account.getAvatar().getPath()); + values.put(Sqlite.COL_AVATAR, account.getAvatar() != null ? account.getAvatar().getPath() : "null"); values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(account.getCreatedAt())); - if (account.getClient_id() != null && account.getClient_secret() != null) { - values.put(Sqlite.COL_CLIENT_ID, account.getClient_id()); - values.put(Sqlite.COL_CLIENT_SECRET, account.getClient_secret()); + + try { + return db.update(Sqlite.TABLE_USER_ACCOUNT, + values, Sqlite.COL_USERNAME + " = ? AND " + Sqlite.COL_INSTANCE + " =?", + new String[]{account.getUsername(), account.getHost()}); + } catch (Exception e) { + e.printStackTrace(); + return -1; } - if (account.getRefresh_token() != null) { - values.put(Sqlite.COL_REFRESH_TOKEN, account.getRefresh_token()); - } - if (account.getToken() != null) - values.put(Sqlite.COL_OAUTHTOKEN, account.getToken()); - return db.update(Sqlite.TABLE_USER_ACCOUNT, - values, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =?", - new String[]{account.getId(), account.getHost()}); + } @@ -248,23 +247,6 @@ public class AccountDAO { } } - /** - * Returns an Account by token - * - * @param userId String - * @param instance String - * @return Account - */ - public Account getUniqAccount(String userId, String instance) { - - try { - Cursor c = db.query(Sqlite.TABLE_USER_ACCOUNT, null, Sqlite.COL_USER_ID + " = \"" + userId + "\" AND " + Sqlite.COL_INSTANCE + " = \"" + instance + "\"", null, null, null, null, "1"); - return cursorToUser(c); - } catch (Exception e) { - return null; - } - } - /** * Test if the current user is already stored in data base diff --git a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/PlaylistsVM.java b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/PlaylistsVM.java index b3efc27..551caee 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/PlaylistsVM.java +++ b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/PlaylistsVM.java @@ -73,13 +73,10 @@ public class PlaylistsVM extends AndroidViewModel { new Thread(() -> { try { SharedPreferences sharedpreferences = _mContext.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); + String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); String instance = Helper.getLiveInstance(_mContext); SQLiteDatabase db = Sqlite.getInstance(_mContext.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - Account account = new AccountDAO(_mContext, db).getUniqAccount(userId, instance); - if (account == null) { - account = new AccountDAO(_mContext, db).getUniqAccount(userId, Helper.getPeertubeUrl(instance)); - } + Account account = new AccountDAO(_mContext, db).getAccountByToken(token); int statusCode = -1; APIResponse apiResponse; if (account == null) { diff --git a/app/src/main/res/layout/activity_instance_picker.xml b/app/src/main/res/layout/activity_instance_picker.xml index 14cb1f0..692e607 100644 --- a/app/src/main/res/layout/activity_instance_picker.xml +++ b/app/src/main/res/layout/activity_instance_picker.xml @@ -15,17 +15,17 @@ see . --> + tools:context=".InstancePickerActivity"> + + android:layout_marginTop="10dp" + android:orientation="vertical" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/filters_container"> + android:layout_height="wrap_content" + android:layout_marginTop="20dp" + android:orientation="horizontal"> + @@ -63,7 +63,6 @@ android:layout_height="40dp" android:layout_gravity="center" android:contentDescription="@string/display_more" - android:src="@drawable/ic_baseline_more_vert_24" - /> + android:src="@drawable/ic_baseline_more_vert_24" /> \ No newline at end of file diff --git a/app/src/main/res/layout/drawer_comment.xml b/app/src/main/res/layout/drawer_comment.xml new file mode 100644 index 0000000..4171c05 --- /dev/null +++ b/app/src/main/res/layout/drawer_comment.xml @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/menu/comment_menu.xml b/app/src/main/res/menu/comment_menu.xml new file mode 100644 index 0000000..2c9df39 --- /dev/null +++ b/app/src/main/res/menu/comment_menu.xml @@ -0,0 +1,14 @@ + + + + +