aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-04-18 15:31:41 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-04-18 15:31:41 +0000
commitcd4730c6492eae869e74182383c35be16c70ae25 (patch)
tree0f80b0578b5807b1c979221759be131cd5d50054
parenta7e96957174f78af054316cd9efb6fd176b1d59d (diff)
downloadinfinity-for-reddit-cd4730c6492eae869e74182383c35be16c70ae25.tar
infinity-for-reddit-cd4730c6492eae869e74182383c35be16c70ae25.tar.gz
infinity-for-reddit-cd4730c6492eae869e74182383c35be16c70ae25.tar.bz2
infinity-for-reddit-cd4730c6492eae869e74182383c35be16c70ae25.tar.lz
infinity-for-reddit-cd4730c6492eae869e74182383c35be16c70ae25.tar.xz
infinity-for-reddit-cd4730c6492eae869e74182383c35be16c70ae25.tar.zst
infinity-for-reddit-cd4730c6492eae869e74182383c35be16c70ae25.zip
Synchronizing voting state between PostRecyclerViewAdapter and ViewPostDetailActivity using EventBus by greenrobot. Minor bugs fixed.
-rw-r--r--.idea/caches/build_file_checksums.serbin533 -> 533 bytes
-rw-r--r--.idea/caches/gradle_models.serbin300258 -> 252290 bytes
-rw-r--r--.idea/codeStyles/Project.xml29
-rw-r--r--.idea/encodings.xml4
-rw-r--r--app/build.gradle5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java11
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java33
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java32
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java68
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/VoteEventToDetailActivity.java11
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/VoteEventToPostList.java11
-rw-r--r--build.gradle2
-rw-r--r--gradle/wrapper/gradle-wrapper.properties4
14 files changed, 149 insertions, 63 deletions
diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser
index e2cbe3a1..94a9af7a 100644
--- a/.idea/caches/build_file_checksums.ser
+++ b/.idea/caches/build_file_checksums.ser
Binary files differ
diff --git a/.idea/caches/gradle_models.ser b/.idea/caches/gradle_models.ser
index 9a74a867..3646acb5 100644
--- a/.idea/caches/gradle_models.ser
+++ b/.idea/caches/gradle_models.ser
Binary files differ
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
deleted file mode 100644
index 30aa626c..00000000
--- a/.idea/codeStyles/Project.xml
+++ /dev/null
@@ -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> \ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 00000000..15a15b21
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="Encoding" addBOMForNewFiles="with NO BOM" />
+</project> \ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index a8524124..82064ea1 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -41,8 +41,8 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.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-dash:2.7.0'
+ implementation 'com.google.android.exoplayer:exoplayer:2.9.6'
+ implementation 'com.google.android.exoplayer:exoplayer-dash:2.9.6'
implementation 'androidx.browser:browser:1.0.0'
implementation 'com.alexvasilkov:gesture-views:2.5.2'
implementation 'androidx.cardview:cardview:1.0.0'
@@ -74,4 +74,5 @@ dependencies {
implementation "ru.noties:markwon-view:2.0.1"
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.16'
implementation 'com.github.Ferfalk:SimpleSearchView:0.1.3'
+ implementation 'org.greenrobot:eventbus:3.1.1'
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java
index a649ed15..a8928495 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java
@@ -13,6 +13,11 @@ import android.widget.ProgressBar;
import android.widget.TextView;
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.MultiLevelRecyclerView;
import com.multilevelview.models.RecyclerViewItem;
@@ -21,10 +26,6 @@ import java.util.ArrayList;
import java.util.List;
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.ButterKnife;
import retrofit2.Retrofit;
@@ -184,6 +185,7 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
@Override
public void onVoteThingFail(int position1) {
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).upvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
((CommentViewHolder) holder).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
@@ -233,6 +235,7 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
@Override
public void onVoteThingFail(int position1) {
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).upvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
((CommentViewHolder) holder).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
index 4e0b574b..f3d92f70 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
@@ -81,7 +81,9 @@ class ParsePost {
voteType = 0;
} else {
voteType = data.getBoolean(JSONUtils.LIKES_KEY) ? 1 : -1;
+ score -= voteType;
}
+
Calendar postTimeCalendar = Calendar.getInstance();
postTimeCalendar.setTimeInMillis(postTime);
String formattedPostTime = new SimpleDateFormat("MMM d, YYYY, HH:mm",
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
index 493eb616..de03f164 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
@@ -1,15 +1,9 @@
package ml.docilealligator.infinityforreddit;
-import androidx.lifecycle.ViewModelProviders;
import android.content.Context;
import android.content.SharedPreferences;
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.View;
import android.view.ViewGroup;
@@ -17,9 +11,19 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
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.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
+import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+
import javax.inject.Inject;
import javax.inject.Named;
@@ -83,6 +87,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
ButterKnife.bind(this, rootView);
+ EventBus.getDefault().register(this);
+
mLinearLayoutManager = new LinearLayoutManager(getActivity());
mPostRecyclerView.setLayoutManager(mLinearLayoutManager);
/*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);
}
}
+
+ @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();
+ }
} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
index 9aec077f..5b2fecb7 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
@@ -18,6 +18,15 @@ import android.widget.RelativeLayout;
import android.widget.TextView;
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.RequestBuilder;
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.chip.Chip;
+import org.greenrobot.eventbus.EventBus;
+
import CustomView.AspectRatioGifImageView;
import SubredditDatabase.SubredditDao;
import SubredditDatabase.SubredditRoomDatabase;
import User.UserDao;
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.ButterKnife;
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.putExtra(ViewPostDetailActivity.EXTRA_TITLE, title);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_DATA, post);
+ intent.putExtra(ViewPostDetailActivity.EXTRA_POST_LIST_POSITION, position);
mContext.startActivity(intent);
}
});
@@ -249,7 +253,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
((DataViewHolder) holder).postTimeTextView.setText(postTime);
((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) {
((DataViewHolder) holder).gildedImageView.setVisibility(View.VISIBLE);
@@ -414,14 +418,19 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
((DataViewHolder) holder).downvoteButton.clearColorFilter();
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType()));
+
+ EventBus.getDefault().post(new VoteEventToDetailActivity(post.getId(), post.getVoteType()));
}
@Override
public void onVoteThingFail(int position1) {
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).upvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
((DataViewHolder) holder).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
+
+ EventBus.getDefault().post(new VoteEventToDetailActivity(post.getId(), post.getVoteType()));
}
}, id, newVoteType, holder.getAdapterPosition());
});
@@ -464,14 +473,19 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
((DataViewHolder) holder).upvoteButton.clearColorFilter();
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType()));
+
+ EventBus.getDefault().post(new VoteEventToDetailActivity(post.getId(), post.getVoteType()));
}
@Override
public void onVoteThingFail(int position1) {
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).upvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
((DataViewHolder) holder).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
+
+ EventBus.getDefault().post(new VoteEventToDetailActivity(post.getId(), post.getVoteType()));
}
}, id, newVoteType, holder.getAdapterPosition());
});
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
index 505d2fb1..56302115 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
@@ -17,6 +17,16 @@ import android.widget.RelativeLayout;
import android.widget.TextView;
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.RequestBuilder;
import com.bumptech.glide.RequestManager;
@@ -31,6 +41,9 @@ import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
import com.multilevelview.MultiLevelRecyclerView;
import com.santalu.aspectratioimageview.AspectRatioImageView;
+import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+
import java.util.ArrayList;
import java.util.List;
@@ -39,15 +52,6 @@ import javax.inject.Named;
import CustomView.AspectRatioGifImageView;
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.ButterKnife;
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_POST_DATA = "EPD";
+ static final String EXTRA_POST_LIST_POSITION = "EPLI";
private RequestManager glide;
@@ -67,6 +72,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
private String orientationState = "OS";
private Post mPost;
+ private int postListPosition = -1;
private boolean isLoadingMoreChildren = false;
private ArrayList<String> children;
@@ -121,8 +127,11 @@ public class ViewPostDetailActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_post_detail);
+
ButterKnife.bind(this);
+ EventBus.getDefault().register(this);
+
((Infinity) getApplication()).getmNetworkComponent().inject(this);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@@ -131,6 +140,10 @@ public class ViewPostDetailActivity extends AppCompatActivity {
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);
titleTextView.setText(mPost.getTitle());
@@ -214,7 +227,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
if(mPost.isNSFW()) {
mNSFWChip.setVisibility(View.VISIBLE);
}
- mScoreTextView.setText(Integer.toString(mPost.getScore()));
+ mScoreTextView.setText(Integer.toString(mPost.getScore() + mPost.getVoteType()));
mShareButton.setOnClickListener(view -> {
Intent intent = new Intent(Intent.ACTION_SEND);
@@ -333,6 +346,10 @@ public class ViewPostDetailActivity extends AppCompatActivity {
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() {
@Override
public void onVoteThingSuccess() {
@@ -346,14 +363,23 @@ public class ViewPostDetailActivity extends AppCompatActivity {
mDownvoteButton.clearColorFilter();
mScoreTextView.setText(Integer.toString(mPost.getScore() + mPost.getVoteType()));
+
+ if(postListPosition != -1) {
+ EventBus.getDefault().post(new VoteEventToPostList(postListPosition, mPost.getVoteType()));
+ }
}
@Override
public void onVoteThingFail() {
Toast.makeText(ViewPostDetailActivity.this, R.string.vote_failed, Toast.LENGTH_SHORT).show();
+ mPost.setVoteType(previousVoteType);
mScoreTextView.setText(Integer.toString(mPost.getScore() + previousVoteType));
mUpvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
mDownvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
+
+ if(postListPosition != -1) {
+ EventBus.getDefault().post(new VoteEventToPostList(postListPosition, mPost.getVoteType()));
+ }
}
}, mPost.getFullName(), newVoteType);
});
@@ -380,6 +406,10 @@ public class ViewPostDetailActivity extends AppCompatActivity {
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() {
@Override
public void onVoteThingSuccess() {
@@ -393,14 +423,23 @@ public class ViewPostDetailActivity extends AppCompatActivity {
mUpvoteButton.clearColorFilter();
mScoreTextView.setText(Integer.toString(mPost.getScore() + mPost.getVoteType()));
+
+ if(postListPosition != -1) {
+ EventBus.getDefault().post(new VoteEventToPostList(postListPosition, mPost.getVoteType()));
+ }
}
@Override
public void onVoteThingFail() {
Toast.makeText(ViewPostDetailActivity.this, R.string.vote_failed, Toast.LENGTH_SHORT).show();
+ mPost.setVoteType(previousVoteType);
mScoreTextView.setText(Integer.toString(mPost.getScore() + previousVoteType));
mUpvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
mDownvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
+
+ if(postListPosition != -1) {
+ EventBus.getDefault().post(new VoteEventToPostList(postListPosition, mPost.getVoteType()));
+ }
}
}, mPost.getFullName(), newVoteType);
});
@@ -535,6 +574,14 @@ public class ViewPostDetailActivity extends AppCompatActivity {
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
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@@ -568,6 +615,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
@Override
protected void onDestroy() {
+ EventBus.getDefault().unregister(this);
super.onDestroy();
if(mLoadSubredditIconAsyncTask != null) {
mLoadSubredditIconAsyncTask.cancel(true);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/VoteEventToDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/VoteEventToDetailActivity.java
new file mode 100644
index 00000000..d3e80ba4
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/VoteEventToDetailActivity.java
@@ -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;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/VoteEventToPostList.java b/app/src/main/java/ml/docilealligator/infinityforreddit/VoteEventToPostList.java
new file mode 100644
index 00000000..5de4d799
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/VoteEventToPostList.java
@@ -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;
+ }
+}
diff --git a/build.gradle b/build.gradle
index dd60d87a..caac2d79 100644
--- a/build.gradle
+++ b/build.gradle
@@ -7,7 +7,7 @@ buildscript {
jcenter()
}
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
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 50e8894c..6fbf7e5b 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Tue Jan 22 01:13:16 HKT 2019
+#Thu Apr 18 18:17:08 HKT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
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