mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-24 00:44:43 +01:00
Synchronizing voting state between PostRecyclerViewAdapter and ViewPostDetailActivity using EventBus by greenrobot. Minor bugs fixed.
This commit is contained in:
parent
a7e9695717
commit
cd4730c649
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
BIN
.idea/caches/gradle_models.ser
generated
BIN
.idea/caches/gradle_models.ser
generated
Binary file not shown.
29
.idea/codeStyles/Project.xml
generated
29
.idea/codeStyles/Project.xml
generated
@ -1,29 +0,0 @@
|
|||||||
<component name="ProjectCodeStyleConfiguration">
|
|
||||||
<code_scheme name="Project" version="173">
|
|
||||||
<Objective-C-extensions>
|
|
||||||
<file>
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
|
|
||||||
</file>
|
|
||||||
<class>
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
|
|
||||||
</class>
|
|
||||||
<extensions>
|
|
||||||
<pair source="cpp" header="h" fileNamingConvention="NONE" />
|
|
||||||
<pair source="c" header="h" fileNamingConvention="NONE" />
|
|
||||||
</extensions>
|
|
||||||
</Objective-C-extensions>
|
|
||||||
</code_scheme>
|
|
||||||
</component>
|
|
4
.idea/encodings.xml
generated
Normal file
4
.idea/encodings.xml
generated
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
|
||||||
|
</project>
|
@ -41,8 +41,8 @@ dependencies {
|
|||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
androidTestImplementation 'androidx.test:runner:1.2.0-alpha03'
|
androidTestImplementation 'androidx.test:runner:1.2.0-alpha03'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha03'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha03'
|
||||||
implementation 'com.google.android.exoplayer:exoplayer:2.7.0'
|
implementation 'com.google.android.exoplayer:exoplayer:2.9.6'
|
||||||
implementation 'com.google.android.exoplayer:exoplayer-dash:2.7.0'
|
implementation 'com.google.android.exoplayer:exoplayer-dash:2.9.6'
|
||||||
implementation 'androidx.browser:browser:1.0.0'
|
implementation 'androidx.browser:browser:1.0.0'
|
||||||
implementation 'com.alexvasilkov:gesture-views:2.5.2'
|
implementation 'com.alexvasilkov:gesture-views:2.5.2'
|
||||||
implementation 'androidx.cardview:cardview:1.0.0'
|
implementation 'androidx.cardview:cardview:1.0.0'
|
||||||
@ -74,4 +74,5 @@ dependencies {
|
|||||||
implementation "ru.noties:markwon-view:2.0.1"
|
implementation "ru.noties:markwon-view:2.0.1"
|
||||||
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.16'
|
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.16'
|
||||||
implementation 'com.github.Ferfalk:SimpleSearchView:0.1.3'
|
implementation 'com.github.Ferfalk:SimpleSearchView:0.1.3'
|
||||||
|
implementation 'org.greenrobot:eventbus:3.1.1'
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,11 @@ import android.widget.ProgressBar;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.browser.customtabs.CustomTabsIntent;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.multilevelview.MultiLevelAdapter;
|
import com.multilevelview.MultiLevelAdapter;
|
||||||
import com.multilevelview.MultiLevelRecyclerView;
|
import com.multilevelview.MultiLevelRecyclerView;
|
||||||
import com.multilevelview.models.RecyclerViewItem;
|
import com.multilevelview.models.RecyclerViewItem;
|
||||||
@ -21,10 +26,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.browser.customtabs.CustomTabsIntent;
|
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
@ -184,6 +185,7 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public void onVoteThingFail(int position1) {
|
public void onVoteThingFail(int position1) {
|
||||||
Toast.makeText(mContext, R.string.vote_failed, Toast.LENGTH_SHORT).show();
|
Toast.makeText(mContext, R.string.vote_failed, Toast.LENGTH_SHORT).show();
|
||||||
|
commentItem.setVoteType(previousVoteType);
|
||||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() + previousVoteType));
|
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() + previousVoteType));
|
||||||
((CommentViewHolder) holder).upvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
|
((CommentViewHolder) holder).upvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
|
||||||
((CommentViewHolder) holder).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
|
((CommentViewHolder) holder).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
|
||||||
@ -233,6 +235,7 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public void onVoteThingFail(int position1) {
|
public void onVoteThingFail(int position1) {
|
||||||
Toast.makeText(mContext, R.string.vote_failed, Toast.LENGTH_SHORT).show();
|
Toast.makeText(mContext, R.string.vote_failed, Toast.LENGTH_SHORT).show();
|
||||||
|
commentItem.setVoteType(previousVoteType);
|
||||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() + previousVoteType));
|
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() + previousVoteType));
|
||||||
((CommentViewHolder) holder).upvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
|
((CommentViewHolder) holder).upvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
|
||||||
((CommentViewHolder) holder).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
|
((CommentViewHolder) holder).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
|
||||||
|
@ -81,7 +81,9 @@ class ParsePost {
|
|||||||
voteType = 0;
|
voteType = 0;
|
||||||
} else {
|
} else {
|
||||||
voteType = data.getBoolean(JSONUtils.LIKES_KEY) ? 1 : -1;
|
voteType = data.getBoolean(JSONUtils.LIKES_KEY) ? 1 : -1;
|
||||||
|
score -= voteType;
|
||||||
}
|
}
|
||||||
|
|
||||||
Calendar postTimeCalendar = Calendar.getInstance();
|
Calendar postTimeCalendar = Calendar.getInstance();
|
||||||
postTimeCalendar.setTimeInMillis(postTime);
|
postTimeCalendar.setTimeInMillis(postTime);
|
||||||
String formattedPostTime = new SimpleDateFormat("MMM d, YYYY, HH:mm",
|
String formattedPostTime = new SimpleDateFormat("MMM d, YYYY, HH:mm",
|
||||||
|
@ -1,15 +1,9 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModelProviders;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -17,9 +11,19 @@ import android.widget.ImageView;
|
|||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.lifecycle.ViewModelProviders;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
|
import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
|
||||||
|
|
||||||
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
@ -83,6 +87,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
|
|
||||||
ButterKnife.bind(this, rootView);
|
ButterKnife.bind(this, rootView);
|
||||||
|
|
||||||
|
EventBus.getDefault().register(this);
|
||||||
|
|
||||||
mLinearLayoutManager = new LinearLayoutManager(getActivity());
|
mLinearLayoutManager = new LinearLayoutManager(getActivity());
|
||||||
mPostRecyclerView.setLayoutManager(mLinearLayoutManager);
|
mPostRecyclerView.setLayoutManager(mLinearLayoutManager);
|
||||||
/*FloatingActionButton fab = rootView.findViewById(R.id.fab_post_fragment);
|
/*FloatingActionButton fab = rootView.findViewById(R.id.fab_post_fragment);
|
||||||
@ -180,4 +186,19 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
Glide.with(this).load(R.drawable.load_post_error_indicator).into(mFetchPostInfoImageView);
|
Glide.with(this).load(R.drawable.load_post_error_indicator).into(mFetchPostInfoImageView);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onVoteEvent(VoteEventToPostList event) {
|
||||||
|
Post post = mAdapter.getCurrentList().get(event.positionInList);
|
||||||
|
if(post != null) {
|
||||||
|
post.setVoteType(event.voteType);
|
||||||
|
mAdapter.notifyItemChanged(event.positionInList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
EventBus.getDefault().unregister(this);
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
}
|
}
|
@ -18,6 +18,15 @@ import android.widget.RelativeLayout;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.browser.customtabs.CustomTabsIntent;
|
||||||
|
import androidx.cardview.widget.CardView;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.paging.PagedListAdapter;
|
||||||
|
import androidx.recyclerview.widget.DiffUtil;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.RequestBuilder;
|
import com.bumptech.glide.RequestBuilder;
|
||||||
import com.bumptech.glide.RequestManager;
|
import com.bumptech.glide.RequestManager;
|
||||||
@ -29,19 +38,13 @@ import com.bumptech.glide.request.target.Target;
|
|||||||
import com.google.android.material.card.MaterialCardView;
|
import com.google.android.material.card.MaterialCardView;
|
||||||
import com.google.android.material.chip.Chip;
|
import com.google.android.material.chip.Chip;
|
||||||
|
|
||||||
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
|
||||||
import CustomView.AspectRatioGifImageView;
|
import CustomView.AspectRatioGifImageView;
|
||||||
import SubredditDatabase.SubredditDao;
|
import SubredditDatabase.SubredditDao;
|
||||||
import SubredditDatabase.SubredditRoomDatabase;
|
import SubredditDatabase.SubredditRoomDatabase;
|
||||||
import User.UserDao;
|
import User.UserDao;
|
||||||
import User.UserRoomDatabase;
|
import User.UserRoomDatabase;
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.browser.customtabs.CustomTabsIntent;
|
|
||||||
import androidx.cardview.widget.CardView;
|
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
import androidx.paging.PagedListAdapter;
|
|
||||||
import androidx.recyclerview.widget.DiffUtil;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import jp.wasabeef.glide.transformations.BlurTransformation;
|
import jp.wasabeef.glide.transformations.BlurTransformation;
|
||||||
@ -144,6 +147,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
Intent intent = new Intent(mContext, ViewPostDetailActivity.class);
|
Intent intent = new Intent(mContext, ViewPostDetailActivity.class);
|
||||||
intent.putExtra(ViewPostDetailActivity.EXTRA_TITLE, title);
|
intent.putExtra(ViewPostDetailActivity.EXTRA_TITLE, title);
|
||||||
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_DATA, post);
|
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_DATA, post);
|
||||||
|
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_LIST_POSITION, position);
|
||||||
mContext.startActivity(intent);
|
mContext.startActivity(intent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -249,7 +253,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
|
|
||||||
((DataViewHolder) holder).postTimeTextView.setText(postTime);
|
((DataViewHolder) holder).postTimeTextView.setText(postTime);
|
||||||
((DataViewHolder) holder).titleTextView.setText(title);
|
((DataViewHolder) holder).titleTextView.setText(title);
|
||||||
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore()));
|
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType()));
|
||||||
|
|
||||||
if(gilded > 0) {
|
if(gilded > 0) {
|
||||||
((DataViewHolder) holder).gildedImageView.setVisibility(View.VISIBLE);
|
((DataViewHolder) holder).gildedImageView.setVisibility(View.VISIBLE);
|
||||||
@ -414,14 +418,19 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
|
|
||||||
((DataViewHolder) holder).downvoteButton.clearColorFilter();
|
((DataViewHolder) holder).downvoteButton.clearColorFilter();
|
||||||
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType()));
|
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType()));
|
||||||
|
|
||||||
|
EventBus.getDefault().post(new VoteEventToDetailActivity(post.getId(), post.getVoteType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingFail(int position1) {
|
public void onVoteThingFail(int position1) {
|
||||||
Toast.makeText(mContext, R.string.vote_failed, Toast.LENGTH_SHORT).show();
|
Toast.makeText(mContext, R.string.vote_failed, Toast.LENGTH_SHORT).show();
|
||||||
|
post.setVoteType(previousVoteType);
|
||||||
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + previousVoteType));
|
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + previousVoteType));
|
||||||
((DataViewHolder) holder).upvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
|
((DataViewHolder) holder).upvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
|
||||||
((DataViewHolder) holder).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
|
((DataViewHolder) holder).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
|
||||||
|
|
||||||
|
EventBus.getDefault().post(new VoteEventToDetailActivity(post.getId(), post.getVoteType()));
|
||||||
}
|
}
|
||||||
}, id, newVoteType, holder.getAdapterPosition());
|
}, id, newVoteType, holder.getAdapterPosition());
|
||||||
});
|
});
|
||||||
@ -464,14 +473,19 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
|
|
||||||
((DataViewHolder) holder).upvoteButton.clearColorFilter();
|
((DataViewHolder) holder).upvoteButton.clearColorFilter();
|
||||||
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType()));
|
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType()));
|
||||||
|
|
||||||
|
EventBus.getDefault().post(new VoteEventToDetailActivity(post.getId(), post.getVoteType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingFail(int position1) {
|
public void onVoteThingFail(int position1) {
|
||||||
Toast.makeText(mContext, R.string.vote_failed, Toast.LENGTH_SHORT).show();
|
Toast.makeText(mContext, R.string.vote_failed, Toast.LENGTH_SHORT).show();
|
||||||
|
post.setVoteType(previousVoteType);
|
||||||
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + previousVoteType));
|
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + previousVoteType));
|
||||||
((DataViewHolder) holder).upvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
|
((DataViewHolder) holder).upvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
|
||||||
((DataViewHolder) holder).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
|
((DataViewHolder) holder).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
|
||||||
|
|
||||||
|
EventBus.getDefault().post(new VoteEventToDetailActivity(post.getId(), post.getVoteType()));
|
||||||
}
|
}
|
||||||
}, id, newVoteType, holder.getAdapterPosition());
|
}, id, newVoteType, holder.getAdapterPosition());
|
||||||
});
|
});
|
||||||
|
@ -17,6 +17,16 @@ import android.widget.RelativeLayout;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.browser.customtabs.CustomTabsIntent;
|
||||||
|
import androidx.cardview.widget.CardView;
|
||||||
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.core.widget.NestedScrollView;
|
||||||
|
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.RequestBuilder;
|
import com.bumptech.glide.RequestBuilder;
|
||||||
import com.bumptech.glide.RequestManager;
|
import com.bumptech.glide.RequestManager;
|
||||||
@ -31,6 +41,9 @@ import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
|
|||||||
import com.multilevelview.MultiLevelRecyclerView;
|
import com.multilevelview.MultiLevelRecyclerView;
|
||||||
import com.santalu.aspectratioimageview.AspectRatioImageView;
|
import com.santalu.aspectratioimageview.AspectRatioImageView;
|
||||||
|
|
||||||
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -39,15 +52,6 @@ import javax.inject.Named;
|
|||||||
|
|
||||||
import CustomView.AspectRatioGifImageView;
|
import CustomView.AspectRatioGifImageView;
|
||||||
import SubredditDatabase.SubredditRoomDatabase;
|
import SubredditDatabase.SubredditRoomDatabase;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
import androidx.browser.customtabs.CustomTabsIntent;
|
|
||||||
import androidx.cardview.widget.CardView;
|
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
import androidx.core.widget.NestedScrollView;
|
|
||||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import jp.wasabeef.glide.transformations.BlurTransformation;
|
import jp.wasabeef.glide.transformations.BlurTransformation;
|
||||||
@ -60,6 +64,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
static final String EXTRA_TITLE = "ET";
|
static final String EXTRA_TITLE = "ET";
|
||||||
static final String EXTRA_POST_DATA = "EPD";
|
static final String EXTRA_POST_DATA = "EPD";
|
||||||
|
static final String EXTRA_POST_LIST_POSITION = "EPLI";
|
||||||
|
|
||||||
private RequestManager glide;
|
private RequestManager glide;
|
||||||
|
|
||||||
@ -67,6 +72,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
private String orientationState = "OS";
|
private String orientationState = "OS";
|
||||||
|
|
||||||
private Post mPost;
|
private Post mPost;
|
||||||
|
private int postListPosition = -1;
|
||||||
|
|
||||||
private boolean isLoadingMoreChildren = false;
|
private boolean isLoadingMoreChildren = false;
|
||||||
private ArrayList<String> children;
|
private ArrayList<String> children;
|
||||||
@ -121,8 +127,11 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_view_post_detail);
|
setContentView(R.layout.activity_view_post_detail);
|
||||||
|
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
|
EventBus.getDefault().register(this);
|
||||||
|
|
||||||
((Infinity) getApplication()).getmNetworkComponent().inject(this);
|
((Infinity) getApplication()).getmNetworkComponent().inject(this);
|
||||||
|
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
@ -131,6 +140,10 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
mPost = getIntent().getExtras().getParcelable(EXTRA_POST_DATA);
|
mPost = getIntent().getExtras().getParcelable(EXTRA_POST_DATA);
|
||||||
|
|
||||||
|
if(getIntent().hasExtra(EXTRA_POST_LIST_POSITION)) {
|
||||||
|
postListPosition = getIntent().getExtras().getInt(EXTRA_POST_LIST_POSITION);
|
||||||
|
}
|
||||||
|
|
||||||
TextView titleTextView = findViewById(R.id.title_text_view_view_post_detail);
|
TextView titleTextView = findViewById(R.id.title_text_view_view_post_detail);
|
||||||
titleTextView.setText(mPost.getTitle());
|
titleTextView.setText(mPost.getTitle());
|
||||||
|
|
||||||
@ -214,7 +227,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
if(mPost.isNSFW()) {
|
if(mPost.isNSFW()) {
|
||||||
mNSFWChip.setVisibility(View.VISIBLE);
|
mNSFWChip.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
mScoreTextView.setText(Integer.toString(mPost.getScore()));
|
mScoreTextView.setText(Integer.toString(mPost.getScore() + mPost.getVoteType()));
|
||||||
|
|
||||||
mShareButton.setOnClickListener(view -> {
|
mShareButton.setOnClickListener(view -> {
|
||||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||||
@ -333,6 +346,10 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
mScoreTextView.setText(Integer.toString(mPost.getScore() + mPost.getVoteType()));
|
mScoreTextView.setText(Integer.toString(mPost.getScore() + mPost.getVoteType()));
|
||||||
|
|
||||||
|
if(postListPosition != -1) {
|
||||||
|
EventBus.getDefault().post(new VoteEventToPostList(postListPosition, mPost.getVoteType()));
|
||||||
|
}
|
||||||
|
|
||||||
VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingWithoutPositionListener() {
|
VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingWithoutPositionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess() {
|
public void onVoteThingSuccess() {
|
||||||
@ -346,14 +363,23 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
mDownvoteButton.clearColorFilter();
|
mDownvoteButton.clearColorFilter();
|
||||||
mScoreTextView.setText(Integer.toString(mPost.getScore() + mPost.getVoteType()));
|
mScoreTextView.setText(Integer.toString(mPost.getScore() + mPost.getVoteType()));
|
||||||
|
|
||||||
|
if(postListPosition != -1) {
|
||||||
|
EventBus.getDefault().post(new VoteEventToPostList(postListPosition, mPost.getVoteType()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingFail() {
|
public void onVoteThingFail() {
|
||||||
Toast.makeText(ViewPostDetailActivity.this, R.string.vote_failed, Toast.LENGTH_SHORT).show();
|
Toast.makeText(ViewPostDetailActivity.this, R.string.vote_failed, Toast.LENGTH_SHORT).show();
|
||||||
|
mPost.setVoteType(previousVoteType);
|
||||||
mScoreTextView.setText(Integer.toString(mPost.getScore() + previousVoteType));
|
mScoreTextView.setText(Integer.toString(mPost.getScore() + previousVoteType));
|
||||||
mUpvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
|
mUpvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
|
||||||
mDownvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
|
mDownvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
|
||||||
|
|
||||||
|
if(postListPosition != -1) {
|
||||||
|
EventBus.getDefault().post(new VoteEventToPostList(postListPosition, mPost.getVoteType()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, mPost.getFullName(), newVoteType);
|
}, mPost.getFullName(), newVoteType);
|
||||||
});
|
});
|
||||||
@ -380,6 +406,10 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
mScoreTextView.setText(Integer.toString(mPost.getScore() + mPost.getVoteType()));
|
mScoreTextView.setText(Integer.toString(mPost.getScore() + mPost.getVoteType()));
|
||||||
|
|
||||||
|
if(postListPosition != -1) {
|
||||||
|
EventBus.getDefault().post(new VoteEventToPostList(postListPosition, mPost.getVoteType()));
|
||||||
|
}
|
||||||
|
|
||||||
VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingWithoutPositionListener() {
|
VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingWithoutPositionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess() {
|
public void onVoteThingSuccess() {
|
||||||
@ -393,14 +423,23 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
mUpvoteButton.clearColorFilter();
|
mUpvoteButton.clearColorFilter();
|
||||||
mScoreTextView.setText(Integer.toString(mPost.getScore() + mPost.getVoteType()));
|
mScoreTextView.setText(Integer.toString(mPost.getScore() + mPost.getVoteType()));
|
||||||
|
|
||||||
|
if(postListPosition != -1) {
|
||||||
|
EventBus.getDefault().post(new VoteEventToPostList(postListPosition, mPost.getVoteType()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingFail() {
|
public void onVoteThingFail() {
|
||||||
Toast.makeText(ViewPostDetailActivity.this, R.string.vote_failed, Toast.LENGTH_SHORT).show();
|
Toast.makeText(ViewPostDetailActivity.this, R.string.vote_failed, Toast.LENGTH_SHORT).show();
|
||||||
|
mPost.setVoteType(previousVoteType);
|
||||||
mScoreTextView.setText(Integer.toString(mPost.getScore() + previousVoteType));
|
mScoreTextView.setText(Integer.toString(mPost.getScore() + previousVoteType));
|
||||||
mUpvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
|
mUpvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
|
||||||
mDownvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
|
mDownvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
|
||||||
|
|
||||||
|
if(postListPosition != -1) {
|
||||||
|
EventBus.getDefault().post(new VoteEventToPostList(postListPosition, mPost.getVoteType()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, mPost.getFullName(), newVoteType);
|
}, mPost.getFullName(), newVoteType);
|
||||||
});
|
});
|
||||||
@ -535,6 +574,14 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
snackbar.show();
|
snackbar.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onVoteEvent(VoteEventToDetailActivity event) {
|
||||||
|
if(mPost.getId() == event.postId) {
|
||||||
|
mPost.setVoteType(event.voteType);
|
||||||
|
mScoreTextView.setText(Integer.toString(mPost.getScore() + event.voteType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
@ -568,6 +615,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
|
EventBus.getDefault().unregister(this);
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
if(mLoadSubredditIconAsyncTask != null) {
|
if(mLoadSubredditIconAsyncTask != null) {
|
||||||
mLoadSubredditIconAsyncTask.cancel(true);
|
mLoadSubredditIconAsyncTask.cancel(true);
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
|
public class VoteEventToDetailActivity {
|
||||||
|
public final String postId;
|
||||||
|
public final int voteType;
|
||||||
|
|
||||||
|
public VoteEventToDetailActivity(String postId, int voteType) {
|
||||||
|
this.postId = postId;
|
||||||
|
this.voteType = voteType;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
|
public class VoteEventToPostList {
|
||||||
|
public final int positionInList;
|
||||||
|
public final int voteType;
|
||||||
|
|
||||||
|
public VoteEventToPostList(int positionInList, int voteType) {
|
||||||
|
this.positionInList = positionInList;
|
||||||
|
this.voteType = voteType;
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,7 @@ buildscript {
|
|||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.3.2'
|
classpath 'com.android.tools.build:gradle:3.4.0'
|
||||||
|
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
|
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,6 @@
|
|||||||
#Tue Jan 22 01:13:16 HKT 2019
|
#Thu Apr 18 18:17:08 HKT 2019
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
|
||||||
|
Loading…
x
Reference in New Issue
Block a user