mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-26 02:48:23 +01:00
Mark as read functionality
This commits adds the mark post as read functionality. Previously, the app crashed if it tried to mark a post as read.
This commit is contained in:
parent
1974322013
commit
3e10186c7c
@ -82,7 +82,6 @@ import eu.toldi.infinityforlemmy.fragments.ViewImgurVideoFragment;
|
||||
import eu.toldi.infinityforlemmy.fragments.ViewPostDetailFragment;
|
||||
import eu.toldi.infinityforlemmy.fragments.ViewRedditGalleryImageOrGifFragment;
|
||||
import eu.toldi.infinityforlemmy.fragments.ViewRedditGalleryVideoFragment;
|
||||
import eu.toldi.infinityforlemmy.post.ObjectResolver;
|
||||
import eu.toldi.infinityforlemmy.services.DownloadMediaService;
|
||||
import eu.toldi.infinityforlemmy.services.DownloadRedditVideoService;
|
||||
import eu.toldi.infinityforlemmy.services.EditProfileService;
|
||||
@ -308,8 +307,6 @@ public interface AppComponent {
|
||||
|
||||
void inject(MorePostsInfoFragment morePostsInfoFragment);
|
||||
|
||||
void inject(ObjectResolver mObjectResolver);
|
||||
|
||||
|
||||
@Component.Factory
|
||||
interface Factory {
|
||||
|
@ -22,6 +22,7 @@ import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.customviews.LoopAvailableExoCreator;
|
||||
import eu.toldi.infinityforlemmy.post.MarkPostAsRead;
|
||||
import eu.toldi.infinityforlemmy.post.ObjectResolver;
|
||||
import eu.toldi.infinityforlemmy.utils.CustomThemeSharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
@ -206,7 +207,13 @@ abstract class AppModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
static ObjectResolver provideObjectResolver() {
|
||||
return new ObjectResolver();
|
||||
static ObjectResolver provideObjectResolver(@Named("no_oauth") RetrofitHolder retrofitHolder) {
|
||||
return new ObjectResolver(retrofitHolder);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
static MarkPostAsRead provideMarkPostAsRead(@Named("no_oauth") RetrofitHolder retrofitHolder) {
|
||||
return new MarkPostAsRead(retrofitHolder);
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@ -40,6 +41,7 @@ import eu.toldi.infinityforlemmy.events.ChangeNSFWEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.fragments.CommentsListingFragment;
|
||||
import eu.toldi.infinityforlemmy.fragments.PostFragment;
|
||||
import eu.toldi.infinityforlemmy.post.MarkPostAsRead;
|
||||
import eu.toldi.infinityforlemmy.post.Post;
|
||||
import eu.toldi.infinityforlemmy.post.PostPagingSource;
|
||||
import eu.toldi.infinityforlemmy.readpost.InsertReadPost;
|
||||
@ -64,10 +66,15 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
|
||||
CustomThemeWrapper mCustomThemeWrapper;
|
||||
@Inject
|
||||
Executor mExecutor;
|
||||
|
||||
@Inject
|
||||
MarkPostAsRead markPostAsRead;
|
||||
private FragmentManager fragmentManager;
|
||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||
private String mAccessToken;
|
||||
private String mAccountName;
|
||||
|
||||
private String mAccountQualifiedName;
|
||||
private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment;
|
||||
private ActivityAccountSavedThingBinding binding;
|
||||
|
||||
@ -116,6 +123,7 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
|
||||
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||
|
||||
initializeViewPager();
|
||||
}
|
||||
@ -249,7 +257,17 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
|
||||
|
||||
@Override
|
||||
public void markPostAsRead(Post post) {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, post.getId());
|
||||
markPostAsRead.markPostAsRead(post.getId(), mAccessToken, new MarkPostAsRead.MarkPostAsReadListener() {
|
||||
@Override
|
||||
public void onMarkPostAsReadSuccess() {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountQualifiedName, post.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMarkPostAsReadFailed() {
|
||||
Toast.makeText(AccountSavedThingActivity.this, R.string.mark_post_as_read_failed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private class SectionsPagerAdapter extends FragmentStateAdapter {
|
||||
|
@ -103,6 +103,8 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
||||
public SubredditViewModel mSubredditViewModel;
|
||||
private String mAccessToken;
|
||||
private String mAccountName;
|
||||
|
||||
private String mAccountQualifiedName;
|
||||
private String name;
|
||||
private String userWhere;
|
||||
private int postType;
|
||||
@ -158,6 +160,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
||||
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||
name = getIntent().getStringExtra(EXTRA_NAME);
|
||||
postType = getIntent().getIntExtra(EXTRA_POST_TYPE, PostPagingSource.TYPE_FRONT_PAGE);
|
||||
|
||||
@ -470,7 +473,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
||||
|
||||
@Override
|
||||
public void markPostAsRead(Post post) {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, post.getId());
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountQualifiedName, post.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -197,7 +197,6 @@ public class LinkResolverActivity extends AppCompatActivity {
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
((Infinity) getApplication()).getAppComponent().inject(mObjectResolver);
|
||||
mObjectResolver.resolvePost(uri.toString(), mAccessToken, new ObjectResolver.ObjectResolverListener() {
|
||||
@Override
|
||||
public void onResolveObjectSuccess(Object p) {
|
||||
@ -238,7 +237,6 @@ public class LinkResolverActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
((Infinity) getApplication()).getAppComponent().inject(mObjectResolver);
|
||||
mObjectResolver.resolveComment(uri.toString(), mAccessToken, new ObjectResolver.ObjectResolverListener() {
|
||||
@Override
|
||||
public void onResolveObjectSuccess(Object c) {
|
||||
|
@ -113,6 +113,7 @@ import eu.toldi.infinityforlemmy.fragments.PostFragment;
|
||||
import eu.toldi.infinityforlemmy.message.ReadMessage;
|
||||
import eu.toldi.infinityforlemmy.multireddit.MultiReddit;
|
||||
import eu.toldi.infinityforlemmy.multireddit.MultiRedditViewModel;
|
||||
import eu.toldi.infinityforlemmy.post.MarkPostAsRead;
|
||||
import eu.toldi.infinityforlemmy.post.Post;
|
||||
import eu.toldi.infinityforlemmy.post.PostPagingSource;
|
||||
import eu.toldi.infinityforlemmy.readpost.InsertReadPost;
|
||||
@ -213,6 +214,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
CustomThemeWrapper mCustomThemeWrapper;
|
||||
@Inject
|
||||
Executor mExecutor;
|
||||
|
||||
@Inject
|
||||
MarkPostAsRead markPostAsRead;
|
||||
|
||||
private FragmentManager fragmentManager;
|
||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||
private NavigationDrawerRecyclerViewMergedAdapter adapter;
|
||||
@ -1608,7 +1613,17 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
|
||||
@Override
|
||||
public void markPostAsRead(Post post) {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, post.getId());
|
||||
markPostAsRead.markPostAsRead(post.getId(), mAccessToken, new MarkPostAsRead.MarkPostAsReadListener() {
|
||||
@Override
|
||||
public void onMarkPostAsReadSuccess() {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountQualifiedName, post.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMarkPostAsReadFailed() {
|
||||
Toast.makeText(MainActivity.this, R.string.mark_post_as_read_failed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void doNotShowRedditAPIInfoAgain() {
|
||||
|
@ -67,6 +67,7 @@ import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.fragments.PostFragment;
|
||||
import eu.toldi.infinityforlemmy.multireddit.DeleteMultiReddit;
|
||||
import eu.toldi.infinityforlemmy.multireddit.MultiReddit;
|
||||
import eu.toldi.infinityforlemmy.post.MarkPostAsRead;
|
||||
import eu.toldi.infinityforlemmy.post.Post;
|
||||
import eu.toldi.infinityforlemmy.post.PostPagingSource;
|
||||
import eu.toldi.infinityforlemmy.readpost.InsertReadPost;
|
||||
@ -131,8 +132,11 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
|
||||
CustomThemeWrapper mCustomThemeWrapper;
|
||||
@Inject
|
||||
Executor mExecutor;
|
||||
@Inject
|
||||
MarkPostAsRead markPostAsRead;
|
||||
private String mAccessToken;
|
||||
private String mAccountName;
|
||||
private String mAccountQualifiedName;
|
||||
private String multiPath;
|
||||
private Fragment mFragment;
|
||||
private int fabOption;
|
||||
@ -221,6 +225,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
|
||||
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||
lockBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_BOTTOM_APP_BAR, false);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
@ -868,7 +873,17 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
|
||||
|
||||
@Override
|
||||
public void markPostAsRead(Post post) {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, post.getId());
|
||||
markPostAsRead.markPostAsRead(post.getId(), mAccessToken, new MarkPostAsRead.MarkPostAsReadListener() {
|
||||
@Override
|
||||
public void onMarkPostAsReadSuccess() {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountQualifiedName, post.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMarkPostAsReadFailed() {
|
||||
Toast.makeText(ViewMultiRedditDetailActivity.this, R.string.mark_post_as_read_failed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,6 +93,7 @@ import eu.toldi.infinityforlemmy.fragments.SidebarFragment;
|
||||
import eu.toldi.infinityforlemmy.markdown.MarkdownUtils;
|
||||
import eu.toldi.infinityforlemmy.message.ReadMessage;
|
||||
import eu.toldi.infinityforlemmy.multireddit.MultiReddit;
|
||||
import eu.toldi.infinityforlemmy.post.MarkPostAsRead;
|
||||
import eu.toldi.infinityforlemmy.post.Post;
|
||||
import eu.toldi.infinityforlemmy.post.PostPagingSource;
|
||||
import eu.toldi.infinityforlemmy.readpost.InsertReadPost;
|
||||
@ -196,6 +197,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
CustomThemeWrapper mCustomThemeWrapper;
|
||||
@Inject
|
||||
Executor mExecutor;
|
||||
@Inject
|
||||
MarkPostAsRead markPostAsRead;
|
||||
|
||||
private FragmentManager fragmentManager;
|
||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||
private NavigationWrapper navigationWrapper;
|
||||
@ -1562,7 +1566,18 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
|
||||
@Override
|
||||
public void markPostAsRead(Post post) {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, post.getId());
|
||||
markPostAsRead.markPostAsRead(post.getId(), mAccessToken, new MarkPostAsRead.MarkPostAsReadListener() {
|
||||
@Override
|
||||
public void onMarkPostAsReadSuccess() {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountQualifiedName, post.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMarkPostAsReadFailed() {
|
||||
Toast.makeText(ViewSubredditDetailActivity.this, R.string.mark_post_as_read_failed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -95,6 +95,7 @@ import eu.toldi.infinityforlemmy.fragments.PostFragment;
|
||||
import eu.toldi.infinityforlemmy.markdown.MarkdownUtils;
|
||||
import eu.toldi.infinityforlemmy.message.ReadMessage;
|
||||
import eu.toldi.infinityforlemmy.multireddit.MultiReddit;
|
||||
import eu.toldi.infinityforlemmy.post.MarkPostAsRead;
|
||||
import eu.toldi.infinityforlemmy.post.Post;
|
||||
import eu.toldi.infinityforlemmy.post.PostPagingSource;
|
||||
import eu.toldi.infinityforlemmy.readpost.InsertReadPost;
|
||||
@ -202,6 +203,9 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
||||
CustomThemeWrapper mCustomThemeWrapper;
|
||||
@Inject
|
||||
Executor mExecutor;
|
||||
|
||||
@Inject
|
||||
MarkPostAsRead markPostAsRead;
|
||||
public UserViewModel userViewModel;
|
||||
private FragmentManager fragmentManager;
|
||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||
@ -210,6 +214,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
||||
private Call<String> subredditAutocompleteCall;
|
||||
private String mAccessToken;
|
||||
private String mAccountName;
|
||||
private String mAccountQualifiedName;
|
||||
private String username;
|
||||
private String qualifiedName;
|
||||
private String description;
|
||||
@ -272,6 +277,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
||||
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||
lockBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_BOTTOM_APP_BAR, false);
|
||||
|
||||
|
||||
@ -1550,7 +1556,17 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
||||
|
||||
@Override
|
||||
public void markPostAsRead(Post post) {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, post.getId());
|
||||
markPostAsRead.markPostAsRead(post.getId(), mAccessToken, new MarkPostAsRead.MarkPostAsReadListener() {
|
||||
@Override
|
||||
public void onMarkPostAsReadSuccess() {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountQualifiedName, post.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMarkPostAsReadFailed() {
|
||||
Toast.makeText(ViewUserDetailActivity.this, R.string.mark_post_as_read_failed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8,6 +8,7 @@ import eu.toldi.infinityforlemmy.dto.CommentVoteDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.EditCommentDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.FollowCommunityDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.PostVoteDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.ReadPostDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.SaveCommentDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.SavePostDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.SubmitPostDTO;
|
||||
@ -98,6 +99,10 @@ public interface LemmyAPI {
|
||||
@PUT("api/v3/post/save")
|
||||
Call<String> postSave(@Body SavePostDTO params);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST("api/v3/post/mark_as_read")
|
||||
Call<String> postRead(@Body ReadPostDTO params);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@PUT("api/v3/comment/save")
|
||||
Call<String> commentSave(@Body SaveCommentDTO params);
|
||||
|
@ -0,0 +1,26 @@
|
||||
package eu.toldi.infinityforlemmy.dto;
|
||||
|
||||
public class ReadPostDTO {
|
||||
|
||||
private int post_id;
|
||||
private boolean read;
|
||||
private String auth;
|
||||
|
||||
public ReadPostDTO(int post_id, boolean read, String auth) {
|
||||
this.post_id = post_id;
|
||||
this.read = read;
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public int getPost_id() {
|
||||
return post_id;
|
||||
}
|
||||
|
||||
public boolean isRead() {
|
||||
return read;
|
||||
}
|
||||
|
||||
public String getAuth() {
|
||||
return auth;
|
||||
}
|
||||
}
|
@ -107,6 +107,7 @@ import eu.toldi.infinityforlemmy.message.ReadMessage;
|
||||
import eu.toldi.infinityforlemmy.post.FetchPost;
|
||||
import eu.toldi.infinityforlemmy.post.FetchRemovedPost;
|
||||
import eu.toldi.infinityforlemmy.post.HidePost;
|
||||
import eu.toldi.infinityforlemmy.post.MarkPostAsRead;
|
||||
import eu.toldi.infinityforlemmy.post.Post;
|
||||
import eu.toldi.infinityforlemmy.readpost.InsertReadPost;
|
||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||
@ -190,6 +191,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
ExoCreator mExoCreator;
|
||||
@Inject
|
||||
Executor mExecutor;
|
||||
@Inject
|
||||
MarkPostAsRead markPostAsRead;
|
||||
@State
|
||||
Post mPost;
|
||||
@State
|
||||
@ -225,6 +228,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
private Menu mMenu;
|
||||
private String mAccessToken;
|
||||
private String mAccountName;
|
||||
private String mAccountQualifiedName;
|
||||
private int postListPosition = -1;
|
||||
private Integer mSingleCommentId;
|
||||
private String mContextNumber;
|
||||
@ -277,6 +281,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||
|
||||
mSavedIcon = getMenuItemIcon(R.drawable.ic_bookmark_toolbar_24dp);
|
||||
mUnsavedIcon = getMenuItemIcon(R.drawable.ic_bookmark_border_toolbar_24dp);
|
||||
@ -307,7 +312,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
mLockFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false);
|
||||
mSwipeUpToHideFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_UP_TO_HIDE_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false);
|
||||
mExpandChildren = !mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false);
|
||||
mMarkPostsAsRead = mPostHistorySharedPreferences.getBoolean(mAccountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false);
|
||||
mMarkPostsAsRead = mPostHistorySharedPreferences.getBoolean(mAccountQualifiedName + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false);
|
||||
if (savedInstanceState == null) {
|
||||
mRespectSubredditRecommendedSortType = mSharedPreferences.getBoolean(SharedPreferencesUtils.RESPECT_SUBREDDIT_RECOMMENDED_COMMENT_SORT_TYPE, false);
|
||||
viewPostDetailFragmentId = System.currentTimeMillis();
|
||||
@ -1166,9 +1171,19 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
private void tryMarkingPostAsRead() {
|
||||
if (mMarkPostsAsRead && mPost != null && !mPost.isRead()) {
|
||||
mPost.markAsRead();
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, mPost.getId());
|
||||
markPostAsRead.markPostAsRead(mPost.getId(), mAccessToken, new MarkPostAsRead.MarkPostAsReadListener() {
|
||||
@Override
|
||||
public void onMarkPostAsReadSuccess() {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountQualifiedName, mPost.getId());
|
||||
EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMarkPostAsReadFailed() {
|
||||
Toast.makeText(activity, R.string.mark_post_as_read_failed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,51 @@
|
||||
package eu.toldi.infinityforlemmy.post;
|
||||
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||
import eu.toldi.infinityforlemmy.dto.ReadPostDTO;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class MarkPostAsRead {
|
||||
RetrofitHolder retrofitHolder;
|
||||
|
||||
public MarkPostAsRead(RetrofitHolder retrofitHolder) {
|
||||
this.retrofitHolder = retrofitHolder;
|
||||
}
|
||||
|
||||
private void setPostAsRead(int post_id, boolean markAsRead, String auth, MarkPostAsReadListener markPostAsReadListener) {
|
||||
LemmyAPI lemmyAPI = retrofitHolder.getRetrofit().create(LemmyAPI.class);
|
||||
|
||||
lemmyAPI.postRead(new ReadPostDTO(post_id, markAsRead, auth)).enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(Call<String> call, Response<String> response) {
|
||||
if (response.isSuccessful()
|
||||
&& response.body() != null) {
|
||||
markPostAsReadListener.onMarkPostAsReadSuccess();
|
||||
} else {
|
||||
markPostAsReadListener.onMarkPostAsReadFailed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<String> call, Throwable t) {
|
||||
markPostAsReadListener.onMarkPostAsReadFailed();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void markPostAsRead(int post_id, String auth, MarkPostAsReadListener markPostAsReadListener) {
|
||||
setPostAsRead(post_id, true, auth, markPostAsReadListener);
|
||||
}
|
||||
|
||||
public void markPostAsUnread(int post_id, String auth, MarkPostAsReadListener markPostAsReadListener) {
|
||||
setPostAsRead(post_id, false, auth, markPostAsReadListener);
|
||||
}
|
||||
|
||||
public interface MarkPostAsReadListener {
|
||||
void onMarkPostAsReadSuccess();
|
||||
|
||||
void onMarkPostAsReadFailed();
|
||||
}
|
||||
}
|
@ -5,9 +5,6 @@ import org.json.JSONObject;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||
import eu.toldi.infinityforlemmy.comment.Comment;
|
||||
@ -18,10 +15,12 @@ import retrofit2.Response;
|
||||
|
||||
public class ObjectResolver {
|
||||
|
||||
@Inject
|
||||
@Named("no_oauth")
|
||||
RetrofitHolder retrofitHolder;
|
||||
|
||||
public ObjectResolver(RetrofitHolder retrofitHolder) {
|
||||
this.retrofitHolder = retrofitHolder;
|
||||
}
|
||||
|
||||
public void resolvePost(String query, String auth, ObjectResolverListener objectResolverListener) {
|
||||
LemmyAPI lemmyAPI = retrofitHolder.getRetrofit().create(LemmyAPI.class);
|
||||
|
||||
|
@ -1342,4 +1342,5 @@
|
||||
<string name="anonymous_account_instance">Anonymous Account Instance</string>
|
||||
<string name="url_cannot_be_null_or_empty">URL cannot be null or empty</string>
|
||||
<string name="could_not_resolve_link">Could not resolve URL :(</string>
|
||||
<string name="mark_post_as_read_failed">Failed to mark post as read</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user