diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-04-05 08:21:47 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-04-05 08:21:47 +0000 |
commit | 7a429f902dc0e9519382032cca2da97816877b0d (patch) | |
tree | 18c41d46c31e3a12517457bd014632a4d38a6cfd /app/src/main/java/ml/docilealligator | |
parent | 28b9eb37daf90b4a4282788ab19093e5d4a63250 (diff) | |
download | infinity-for-reddit-7a429f902dc0e9519382032cca2da97816877b0d.tar infinity-for-reddit-7a429f902dc0e9519382032cca2da97816877b0d.tar.gz infinity-for-reddit-7a429f902dc0e9519382032cca2da97816877b0d.tar.bz2 infinity-for-reddit-7a429f902dc0e9519382032cca2da97816877b0d.tar.lz infinity-for-reddit-7a429f902dc0e9519382032cca2da97816877b0d.tar.xz infinity-for-reddit-7a429f902dc0e9519382032cca2da97816877b0d.tar.zst infinity-for-reddit-7a429f902dc0e9519382032cca2da97816877b0d.zip |
Long press a multireddit in the list to show some options. Fix some UI issues.
Diffstat (limited to 'app/src/main/java/ml/docilealligator')
15 files changed, 269 insertions, 111 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java index 678dee79..0a8acf90 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java @@ -103,6 +103,16 @@ public class CustomThemeListingActivity extends BaseActivity implements CustomThemeWrapper.getPredefinedThemes(this)); recyclerView.setAdapter(adapter); recyclerView.setLayoutManager(new LinearLayoutManager(this)); + recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { + if (dy > 0) { + fab.hide(); + } else if (dy < 0) { + fab.show(); + } + } + }); customThemeViewModel = new ViewModelProvider(this, new CustomThemeViewModel.Factory(redditDataRoomDatabase)) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java index 18799121..92ef6064 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -71,72 +71,76 @@ public class LinkResolverActivity extends AppCompatActivity { String messageFullname = getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME); String newAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME); - if (path.matches(POST_PATTERN)) { - List<String> segments = uri.getPathSegments(); - int commentsIndex = segments.lastIndexOf("comments"); - if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { - Intent intent = new Intent(this, ViewPostDetailActivity.class); - intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1)); - intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + String authority = uri.getAuthority(); + if (authority != null && (authority.contains("reddit.com") || authority.contains("redd.it") || authority.contains("reddit.app"))) { + if (path.matches(POST_PATTERN)) { + List<String> segments = uri.getPathSegments(); + int commentsIndex = segments.lastIndexOf("comments"); + if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { + Intent intent = new Intent(this, ViewPostDetailActivity.class); + intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1)); + intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } else { + deepLinkError(uri); + } + } else if (path.matches(COMMENT_PATTERN)) { + List<String> segments = uri.getPathSegments(); + int commentsIndex = segments.lastIndexOf("comments"); + if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { + Intent intent = new Intent(this, ViewPostDetailActivity.class); + intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1)); + intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, segments.get(segments.size() - 1)); + intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } else { + deepLinkError(uri); + } + } else if (path.matches(SUBREDDIT_PATTERN)) { + String subredditName = path.substring(3); + if (subredditName.equals("popular") || subredditName.equals("all")) { + Intent intent = new Intent(this, MainActivity.class); + intent.putExtra(MainActivity.EXTRA_POST_TYPE, subredditName); + intent.putExtra(MainActivity.EXTRA_MESSSAGE_FULLNAME, messageFullname); + intent.putExtra(MainActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } else { + Intent intent = new Intent(this, ViewSubredditDetailActivity.class); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, path.substring(3)); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } + } else if (path.matches(USER_PATTERN_1)) { + Intent intent = new Intent(this, ViewUserDetailActivity.class); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, path.substring(6)); + intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); startActivity(intent); - } else { - deepLinkError(uri); - } - } else if (path.matches(COMMENT_PATTERN)) { - List<String> segments = uri.getPathSegments(); - int commentsIndex = segments.lastIndexOf("comments"); - if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { + } else if (path.matches(USER_PATTERN_2)) { + Intent intent = new Intent(this, ViewUserDetailActivity.class); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, path.substring(3)); + intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } else if (path.matches(SIDEBAR_PATTERN)) { + Intent intent = new Intent(this, ViewSidebarActivity.class); + intent.putExtra(ViewSidebarActivity.EXTRA_SUBREDDIT_NAME, path.substring(3, path.length() - 14)); + startActivity(intent); + } else if (path.matches(MULTIREDDIT_PATTERN)) { + Intent intent = new Intent(this, ViewMultiRedditDetailActivity.class); + intent.putExtra(ViewMultiRedditDetailActivity.EXTRA_MULTIREDDIT_PATH, path); + startActivity(intent); + } else if (path.matches(REDD_IT_POST_PATTERN)) { Intent intent = new Intent(this, ViewPostDetailActivity.class); - intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1)); - intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, segments.get(segments.size() - 1)); - intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, path.substring(1)); startActivity(intent); } else { deepLinkError(uri); } - } else if (path.matches(SUBREDDIT_PATTERN)) { - String subredditName = path.substring(3); - if (subredditName.equals("popular") || subredditName.equals("all")) { - Intent intent = new Intent(this, MainActivity.class); - intent.putExtra(MainActivity.EXTRA_POST_TYPE, subredditName); - intent.putExtra(MainActivity.EXTRA_MESSSAGE_FULLNAME, messageFullname); - intent.putExtra(MainActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); - startActivity(intent); - } else { - Intent intent = new Intent(this, ViewSubredditDetailActivity.class); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, path.substring(3)); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); - startActivity(intent); - } - } else if (path.matches(USER_PATTERN_1)) { - Intent intent = new Intent(this, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, path.substring(6)); - intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); - startActivity(intent); - } else if (path.matches(USER_PATTERN_2)) { - Intent intent = new Intent(this, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, path.substring(3)); - intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); - startActivity(intent); - } else if (path.matches(SIDEBAR_PATTERN)) { - Intent intent = new Intent(this, ViewSidebarActivity.class); - intent.putExtra(ViewSidebarActivity.EXTRA_SUBREDDIT_NAME, path.substring(3, path.length() - 14)); - startActivity(intent); - } else if (path.matches(MULTIREDDIT_PATTERN)) { - Intent intent = new Intent(this, ViewMultiRedditDetailActivity.class); - intent.putExtra(ViewMultiRedditDetailActivity.EXTRA_MULTIREDDIT_PATH, path); - startActivity(intent); - } else if (path.matches(REDD_IT_POST_PATTERN)) { - Intent intent = new Intent(this, ViewPostDetailActivity.class); - intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, path.substring(1)); - startActivity(intent); - } - else { + } else { deepLinkError(uri); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java index 9e0164b6..b1d2890d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java @@ -24,8 +24,11 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.floatingactionbutton.FloatingActionButton; +import org.greenrobot.eventbus.Subscribe; + import java.util.ArrayList; import javax.inject.Inject; @@ -37,7 +40,9 @@ import ml.docilealligator.infinityforreddit.Adapter.MultiRedditListingRecyclerVi import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.InsertMultiRedditAsyncTask; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.Event.RefreshMultiRedditsEvent; import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.MultiReddit.DeleteMultiReddit; import ml.docilealligator.infinityforreddit.MultiReddit.FetchMyMultiReddits; import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit; import ml.docilealligator.infinityforreddit.MultiReddit.MultiRedditViewModel; @@ -260,4 +265,33 @@ public class MultiRedditListingActivity extends BaseActivity { mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); applyFABTheme(fab); } + + public void deleteMultiReddit(MultiReddit multiReddit) { + new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) + .setTitle(R.string.delete) + .setMessage(R.string.delete_multi_reddit_dialog_message) + .setPositiveButton(R.string.delete, (dialogInterface, i) + -> DeleteMultiReddit.deleteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, + mAccessToken, mAccountName, multiReddit.getPath(), new DeleteMultiReddit.DeleteMultiRedditListener() { + @Override + public void success() { + Toast.makeText(MultiRedditListingActivity.this, + R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show(); + loadMultiReddits(); + } + + @Override + public void failed() { + Toast.makeText(MultiRedditListingActivity.this, + R.string.delete_multi_reddit_failed, Toast.LENGTH_SHORT).show(); + } + })) + .setNegativeButton(R.string.cancel, null) + .show(); + } + + @Subscribe + public void onRefreshMultiRedditsEvent(RefreshMultiRedditsEvent event) { + loadMultiReddits(); + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java index 1f1c0f8f..4e612476 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java @@ -75,6 +75,17 @@ public class SelectedSubredditsActivity extends BaseActivity { adapter = new SelectedSubredditsRecyclerViewAdapter(mCustomThemeWrapper, subreddits); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setAdapter(adapter); + recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { + super.onScrolled(recyclerView, dx, dy); + if (dy > 0) { + fab.hide(); + } else { + fab.show(); + } + } + }); fab.setOnClickListener(view -> { Intent intent = new Intent(this, SubredditMultiselectionActivity.class); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java index 168d7276..f1ee3a02 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java @@ -19,6 +19,8 @@ import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import org.greenrobot.eventbus.EventBus; + import javax.inject.Inject; import javax.inject.Named; @@ -26,6 +28,7 @@ import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.Event.RefreshMultiRedditsEvent; import ml.docilealligator.infinityforreddit.Fragment.PostFragment; import ml.docilealligator.infinityforreddit.Fragment.PostLayoutBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment; @@ -33,7 +36,6 @@ import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.MultiReddit.DeleteMultiReddit; -import ml.docilealligator.infinityforreddit.MultiReddit.EditMultiReddit; import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit; import ml.docilealligator.infinityforreddit.Post.PostDataSource; import ml.docilealligator.infinityforreddit.R; @@ -259,23 +261,22 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT .setTitle(R.string.delete) .setMessage(R.string.delete_multi_reddit_dialog_message) .setPositiveButton(R.string.delete, (dialogInterface, i) - -> { - DeleteMultiReddit.deleteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, - mAccessToken, mAccountName, multiPath, new DeleteMultiReddit.DeleteMultiRedditListener() { - @Override - public void success() { - Toast.makeText(ViewMultiRedditDetailActivity.this, - R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show(); - finish(); - } - - @Override - public void failed() { - Toast.makeText(ViewMultiRedditDetailActivity.this, - R.string.delete_multi_reddit_failed, Toast.LENGTH_SHORT).show(); - } - }); - }) + -> DeleteMultiReddit.deleteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, + mAccessToken, mAccountName, multiPath, new DeleteMultiReddit.DeleteMultiRedditListener() { + @Override + public void success() { + Toast.makeText(ViewMultiRedditDetailActivity.this, + R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show(); + EventBus.getDefault().post(new RefreshMultiRedditsEvent()); + finish(); + } + + @Override + public void failed() { + Toast.makeText(ViewMultiRedditDetailActivity.this, + R.string.delete_multi_reddit_failed, Toast.LENGTH_SHORT).show(); + } + })) .setNegativeButton(R.string.cancel, null) .show(); return true; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomThemeListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomThemeListingRecyclerViewAdapter.java index ca3fb72d..b3cbb38c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomThemeListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomThemeListingRecyclerViewAdapter.java @@ -101,6 +101,10 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< customThemeOptionsBottomSheetFragment.setArguments(bundle); customThemeOptionsBottomSheetFragment.show(activity.getSupportFragmentManager(), customThemeOptionsBottomSheetFragment.getTag()); }); + ((UserCustomThemeViewHolder) holder).itemView.setOnLongClickListener(view -> { + ((UserCustomThemeViewHolder) holder).itemView.performClick(); + return true; + }); } else if (holder instanceof PreDefinedThemeDividerViewHolder) { ((TextView) ((PreDefinedThemeDividerViewHolder) holder).itemView).setText(R.string.predefined_themes); } else if (holder instanceof UserThemeDividerViewHolder) { @@ -127,7 +131,7 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< @BindView(R.id.add_image_view_item_predefined_custom_theme) ImageView createThemeImageView; - public PredefinedCustomThemeViewHolder(@NonNull View itemView) { + PredefinedCustomThemeViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); } @@ -144,7 +148,7 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< @BindView(R.id.share_image_view_item_user_custom_theme) ImageView shareImageView; - public UserCustomThemeViewHolder(@NonNull View itemView) { + UserCustomThemeViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); } @@ -152,14 +156,14 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< class PreDefinedThemeDividerViewHolder extends RecyclerView.ViewHolder { - public PreDefinedThemeDividerViewHolder(@NonNull View itemView) { + PreDefinedThemeDividerViewHolder(@NonNull View itemView) { super(itemView); } } class UserThemeDividerViewHolder extends RecyclerView.ViewHolder { - public UserThemeDividerViewHolder(@NonNull View itemView) { + UserThemeDividerViewHolder(@NonNull View itemView) { super(itemView); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/FollowedUsersRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/FollowedUsersRecyclerViewAdapter.java index 23f73a7c..dd5c8be1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/FollowedUsersRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/FollowedUsersRecyclerViewAdapter.java @@ -54,7 +54,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc mOauthRetrofit = oauthRetrofit; mRedditDataRoomDatabase = redditDataRoomDatabase; mAccessToken = accessToken; - glide = Glide.with(context.getApplicationContext()); + glide = Glide.with(context); mPrimaryTextColor = customThemeWrapper.getPrimaryTextColor(); mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MultiRedditListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MultiRedditListingRecyclerViewAdapter.java index 4463f071..8d99220e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MultiRedditListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MultiRedditListingRecyclerViewAdapter.java @@ -1,7 +1,7 @@ package ml.docilealligator.infinityforreddit.Adapter; -import android.content.Context; import android.content.Intent; +import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -10,6 +10,7 @@ import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; @@ -23,6 +24,7 @@ import butterknife.ButterKnife; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.Activity.ViewMultiRedditDetailActivity; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.Fragment.MultiRedditOptionsBottomSheetFragment; import ml.docilealligator.infinityforreddit.MultiReddit.FavoriteMultiReddit; import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit; import ml.docilealligator.infinityforreddit.R; @@ -37,7 +39,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< private static final int VIEW_TYPE_MULTI_REDDIT_DIVIDER = 2; private static final int VIEW_TYPE_MULTI_REDDIT = 3; - private Context mContext; + private AppCompatActivity mActivity; private Retrofit mOauthRetrofit; private RedditDataRoomDatabase mRedditDataRoomDatabase; private RequestManager mGlide; @@ -49,12 +51,12 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< private int mPrimaryTextColor; private int mSecondaryTextColor; - public MultiRedditListingRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, + public MultiRedditListingRecyclerViewAdapter(AppCompatActivity activity, Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, CustomThemeWrapper customThemeWrapper, String accessToken, String accountName) { - mContext = context; - mGlide = Glide.with(context.getApplicationContext()); + mActivity = activity; + mGlide = Glide.with(activity); mOauthRetrofit = oauthRetrofit; mRedditDataRoomDatabase = redditDataRoomDatabase; mAccessToken = accessToken; @@ -135,7 +137,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< @Override public void failed() { - Toast.makeText(mContext, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show(); + Toast.makeText(mActivity, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show(); int position = holder.getAdapterPosition() - offset; if(position >= 0 && mMultiReddits.size() > position) { mMultiReddits.get(position).setFavorite(true); @@ -161,7 +163,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< @Override public void failed() { - Toast.makeText(mContext, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show(); + Toast.makeText(mActivity, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show(); int position = holder.getAdapterPosition() - offset; if(position >= 0 && mMultiReddits.size() > position) { mMultiReddits.get(position).setFavorite(false); @@ -173,9 +175,14 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< } }); holder.itemView.setOnClickListener(view -> { - Intent intent = new Intent(mContext, ViewMultiRedditDetailActivity.class); + Intent intent = new Intent(mActivity, ViewMultiRedditDetailActivity.class); intent.putExtra(ViewMultiRedditDetailActivity.EXTRA_MULTIREDDIT_DATA, multiReddit); - mContext.startActivity(intent); + mActivity.startActivity(intent); + }); + + holder.itemView.setOnLongClickListener(view -> { + showOptionsBottomSheetFragment(multiReddit); + return true; }); if (iconUrl != null && !iconUrl.equals("")) { @@ -218,7 +225,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< @Override public void failed() { - Toast.makeText(mContext, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show(); + Toast.makeText(mActivity, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show(); int position = holder.getAdapterPosition() - 1; if(position >= 0 && mFavoriteMultiReddits.size() > position) { mFavoriteMultiReddits.get(position).setFavorite(true); @@ -244,7 +251,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< @Override public void failed() { - Toast.makeText(mContext, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show(); + Toast.makeText(mActivity, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show(); int position = holder.getAdapterPosition() - 1; if(position >= 0 && mFavoriteMultiReddits.size() > position) { mFavoriteMultiReddits.get(position).setFavorite(false); @@ -256,9 +263,14 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< } }); holder.itemView.setOnClickListener(view -> { - Intent intent = new Intent(mContext, ViewMultiRedditDetailActivity.class); + Intent intent = new Intent(mActivity, ViewMultiRedditDetailActivity.class); intent.putExtra(ViewMultiRedditDetailActivity.EXTRA_MULTIREDDIT_DATA, multiReddit); - mContext.startActivity(intent); + mActivity.startActivity(intent); + }); + + holder.itemView.setOnLongClickListener(view -> { + showOptionsBottomSheetFragment(multiReddit); + return true; }); if (iconUrl != null && !iconUrl.equals("")) { @@ -298,6 +310,14 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< } } + private void showOptionsBottomSheetFragment(MultiReddit multiReddit) { + MultiRedditOptionsBottomSheetFragment fragment = new MultiRedditOptionsBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putParcelable(MultiRedditOptionsBottomSheetFragment.EXTRA_MULTI_REDDIT, multiReddit); + fragment.setArguments(bundle); + fragment.show(mActivity.getSupportFragmentManager(), fragment.getTag()); + } + public void setMultiReddits(List<MultiReddit> multiReddits) { mMultiReddits = multiReddits; notifyDataSetChanged(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index e3b935b5..e6203992 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -198,7 +198,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView DrawableCompat.setTint(mCommentIcon, mPostIconAndInfoColor); } mScale = activity.getResources().getDisplayMetrics().density; - mGlide = Glide.with(mActivity.getApplicationContext()); + mGlide = Glide.with(mActivity); mRedditDataRoomDatabase = redditDataRoomDatabase; mUserDao = redditDataRoomDatabase.userDao(); mCallback = callback; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SubredditListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SubredditListingRecyclerViewAdapter.java index 0ad06f02..52caf4e1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SubredditListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SubredditListingRecyclerViewAdapter.java @@ -80,7 +80,7 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred this.accountName = accountName; this.redditDataRoomDatabase = redditDataRoomDatabase; this.callback = callback; - glide = Glide.with(context.getApplicationContext()); + glide = Glide.with(context); colorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme(); primaryTextColor = customThemeWrapper.getPrimaryTextColor(); secondaryTextColor = customThemeWrapper.getSecondaryTextColor(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SubscribedSubredditsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SubscribedSubredditsRecyclerViewAdapter.java index 18662781..bd01c64d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SubscribedSubredditsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SubscribedSubredditsRecyclerViewAdapter.java @@ -57,7 +57,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte CustomThemeWrapper customThemeWrapper, String accessToken) { mContext = context; - glide = Glide.with(context.getApplicationContext()); + glide = Glide.with(context); mOauthRetrofit = oauthRetrofit; mRedditDataRoomDatabase = redditDataRoomDatabase; this.accessToken = accessToken; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/UserListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/UserListingRecyclerViewAdapter.java index f9c2cf35..33867a0d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/UserListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/UserListingRecyclerViewAdapter.java @@ -81,7 +81,7 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R this.accountName = accountName; this.subscribedUserDao = subscribedUserDao; this.retryLoadingMoreCallback = retryLoadingMoreCallback; - glide = Glide.with(context.getApplicationContext()); + glide = Glide.with(context); primaryTextColor = customThemeWrapper.getPrimaryTextColor(); buttonTextColor = customThemeWrapper.getButtonTextColor(); colorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeWrapper.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeWrapper.java index 95e6d97f..9c37ccaf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeWrapper.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeWrapper.java @@ -641,7 +641,7 @@ public class CustomThemeWrapper { return customTheme; } - public static CustomTheme getWhite(Context context) { + private static CustomTheme getWhite(Context context) { CustomTheme customTheme = new CustomTheme(context.getString(R.string.theme_name_white)); customTheme.isLightTheme = true; customTheme.isDarkTheme = false; @@ -715,7 +715,7 @@ public class CustomThemeWrapper { return customTheme; } - public static CustomTheme getWhiteDark(Context context) { + private static CustomTheme getWhiteDark(Context context) { CustomTheme customTheme = new CustomTheme(context.getString(R.string.theme_name_white_dark)); customTheme.isLightTheme = false; customTheme.isDarkTheme = true; @@ -789,7 +789,7 @@ public class CustomThemeWrapper { return customTheme; } - public static CustomTheme getWhiteAmoled(Context context) { + private static CustomTheme getWhiteAmoled(Context context) { CustomTheme customTheme = new CustomTheme(context.getString(R.string.theme_name_white_amoled)); customTheme.isLightTheme = false; customTheme.isDarkTheme = false; @@ -863,7 +863,7 @@ public class CustomThemeWrapper { return customTheme; } - public static CustomTheme getRed(Context context) { + private static CustomTheme getRed(Context context) { CustomTheme customTheme = new CustomTheme(context.getString(R.string.theme_name_red)); customTheme.isLightTheme = true; customTheme.isDarkTheme = false; @@ -937,7 +937,7 @@ public class CustomThemeWrapper { return customTheme; } - public static CustomTheme getRedDark(Context context) { + private static CustomTheme getRedDark(Context context) { CustomTheme customTheme = new CustomTheme(context.getString(R.string.theme_name_red_dark)); customTheme.isLightTheme = false; customTheme.isDarkTheme = true; @@ -1011,7 +1011,7 @@ public class CustomThemeWrapper { return customTheme; } - public static CustomTheme getRedAmoled(Context context) { + private static CustomTheme getRedAmoled(Context context) { CustomTheme customTheme = new CustomTheme(context.getString(R.string.theme_name_red_amoled)); customTheme.isLightTheme = false; customTheme.isDarkTheme = false; @@ -1085,7 +1085,7 @@ public class CustomThemeWrapper { return customTheme; } - public static CustomTheme getDracula(Context context) { + private static CustomTheme getDracula(Context context) { CustomTheme customTheme = new CustomTheme(context.getString(R.string.theme_name_dracula)); customTheme.isLightTheme = true; customTheme.isDarkTheme = true; @@ -1159,7 +1159,7 @@ public class CustomThemeWrapper { return customTheme; } - public static CustomTheme getCalmPastel(Context context) { + private static CustomTheme getCalmPastel(Context context) { CustomTheme customTheme = new CustomTheme(context.getString(R.string.theme_name_calm_pastel)); customTheme.isLightTheme = true; customTheme.isDarkTheme = false; @@ -1177,7 +1177,7 @@ public class CustomThemeWrapper { customTheme.backgroundColor = Color.parseColor("#DAD0DE"); customTheme.cardViewBackgroundColor = Color.parseColor("#C0F0F4"); customTheme.commentBackgroundColor = Color.parseColor("#C0F0F4"); - customTheme.bottomAppBarBackgroundColor = Color.parseColor("#C0F0F4"); + customTheme.bottomAppBarBackgroundColor = Color.parseColor("#D48AE0"); customTheme.primaryIconColor = Color.parseColor("#000000"); customTheme.postIconAndInfoColor = Color.parseColor("#000000"); customTheme.commentIconAndInfoColor = Color.parseColor("#000000"); @@ -1226,9 +1226,9 @@ public class CustomThemeWrapper { customTheme.fabIconColor = Color.parseColor("#000000"); customTheme.chipTextColor = Color.parseColor("#FFFFFF"); customTheme.navBarColor = Color.parseColor("#D48AE0"); - customTheme.isLightStatusBar = false; + customTheme.isLightStatusBar = true; customTheme.isLightNavBar = true; - customTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface = true; + customTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface = false; return customTheme; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Event/RefreshMultiRedditsEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/RefreshMultiRedditsEvent.java new file mode 100644 index 00000000..0b0ccf3f --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/RefreshMultiRedditsEvent.java @@ -0,0 +1,4 @@ +package ml.docilealligator.infinityforreddit.Event; + +public class RefreshMultiRedditsEvent { +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/MultiRedditOptionsBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/MultiRedditOptionsBottomSheetFragment.java new file mode 100644 index 00000000..3ac1c407 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/MultiRedditOptionsBottomSheetFragment.java @@ -0,0 +1,70 @@ +package ml.docilealligator.infinityforreddit.Fragment; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; + +import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment; + +import butterknife.BindView; +import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.Activity.EditMultiRedditActivity; +import ml.docilealligator.infinityforreddit.Activity.MultiRedditListingActivity; +import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit; +import ml.docilealligator.infinityforreddit.R; + +/** + * A simple {@link Fragment} subclass. + */ +public class MultiRedditOptionsBottomSheetFragment extends RoundedBottomSheetDialogFragment { + + public static final String EXTRA_MULTI_REDDIT = "EMR"; + + @BindView(R.id.edit_multi_reddit_text_view_multi_reddit_options_bottom_sheet_fragment) + TextView editMultiRedditTextView; + @BindView(R.id.delete_multi_reddit_text_view_multi_reddit_options_bottom_sheet_fragment) + TextView deleteMultiRedditTextView; + private MultiRedditListingActivity multiRedditListingActivity; + + public MultiRedditOptionsBottomSheetFragment() { + // Required empty public constructor + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_multi_reddit_options_bottom_sheet, container, false); + + ButterKnife.bind(this, rootView); + + MultiReddit multiReddit = getArguments().getParcelable(EXTRA_MULTI_REDDIT); + + editMultiRedditTextView.setOnClickListener(view -> { + Intent editIntent = new Intent(multiRedditListingActivity, EditMultiRedditActivity.class); + editIntent.putExtra(EditMultiRedditActivity.EXTRA_MULTI_REDDIT, multiReddit); + startActivity(editIntent); + dismiss(); + }); + + deleteMultiRedditTextView.setOnClickListener(view -> { + multiRedditListingActivity.deleteMultiReddit(multiReddit); + dismiss(); + }); + + return rootView; + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + multiRedditListingActivity = (MultiRedditListingActivity) context; + } +} |