aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/ml')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FollowedUsersListingFragment.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FollowedUsersRecyclerViewAdapter.java (renamed from app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRecyclerViewAdapter.java)4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java29
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java28
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditsListingFragment.java14
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditsRecyclerViewAdapter.java21
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java11
7 files changed, 90 insertions, 19 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FollowedUsersListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FollowedUsersListingFragment.java
index 9e64ae04..3db27463 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/FollowedUsersListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FollowedUsersListingFragment.java
@@ -54,7 +54,7 @@ public class FollowedUsersListingFragment extends Fragment {
mGlide = Glide.with(this);
mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
- SubscribedUserRecyclerViewAdapter adapter = new SubscribedUserRecyclerViewAdapter(mActivity);
+ FollowedUsersRecyclerViewAdapter adapter = new FollowedUsersRecyclerViewAdapter(mActivity);
mRecyclerView.setAdapter(adapter);
mSubscribedUserViewModel = ViewModelProviders.of(this).get(SubscribedUserViewModel.class);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FollowedUsersRecyclerViewAdapter.java
index 68c040b0..6f83527b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FollowedUsersRecyclerViewAdapter.java
@@ -20,12 +20,12 @@ import SubscribedUserDatabase.SubscribedUserData;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import pl.droidsonroids.gif.GifImageView;
-public class SubscribedUserRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
+public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private List<SubscribedUserData> mSubscribedUserData;
private Context mContext;
private RequestManager glide;
- SubscribedUserRecyclerViewAdapter(Context context) {
+ FollowedUsersRecyclerViewAdapter(Context context) {
mContext = context;
glide = Glide.with(context.getApplicationContext());
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java
index d499dae4..26ece355 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java
@@ -9,6 +9,7 @@ import android.widget.EditText;
import android.widget.TextView;
import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
@@ -25,6 +26,8 @@ public class PostTextActivity extends AppCompatActivity {
static final String EXTRA_SUBREDDIT_NAME = "ESN";
+ private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
+
@BindView(R.id.subreddit_icon_gif_image_view_post_text_activity) GifImageView iconGifImageView;
@BindView(R.id.subreddit_name_text_view_post_text_activity) TextView subreditNameTextView;
@BindView(R.id.rules_button_post_text_activity) Button rulesButton;
@@ -56,7 +59,7 @@ public class PostTextActivity extends AppCompatActivity {
subreditNameTextView.setOnClickListener(view -> {
Intent intent = new Intent(this, SubredditSelectionActivity.class);
- startActivity(intent);
+ startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
});
}
@@ -70,4 +73,28 @@ public class PostTextActivity extends AppCompatActivity {
return false;
}
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if(requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
+ if(resultCode == RESULT_OK) {
+ subreditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor));
+ subreditNameTextView.setText(data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME_KEY));
+
+ String iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL_KEY);
+ if(!iconUrl.equals("")) {
+ mGlide.load(iconUrl)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .error(mGlide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
+ .into(iconGifImageView);
+ } else {
+ mGlide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .into(iconGifImageView);
+ }
+ }
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java
index 25569eb5..3d565f3c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java
@@ -1,5 +1,7 @@
package ml.docilealligator.infinityforreddit;
+import android.app.Activity;
+import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.MenuItem;
@@ -7,17 +9,14 @@ import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
-import androidx.lifecycle.ViewModelProviders;
-import androidx.recyclerview.widget.LinearLayoutManager;
-import androidx.recyclerview.widget.RecyclerView;
import SubscribedSubredditDatabase.SubscribedSubredditViewModel;
-import butterknife.BindView;
import butterknife.ButterKnife;
public class SubredditSelectionActivity extends AppCompatActivity {
- @BindView(R.id.recycler_view_subreddit_selection_activity) RecyclerView recyclerView;
+ static final String EXTRA_RETURN_SUBREDDIT_NAME_KEY = "ERSNK";
+ static final String EXTRA_RETURN_SUBREDDIT_ICON_URL_KEY = "ERSIUK";
private SubscribedSubredditViewModel mSubscribedSubredditViewModel;
@@ -32,12 +31,11 @@ public class SubredditSelectionActivity extends AppCompatActivity {
Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
actionBar.setHomeAsUpIndicator(upArrow);
- recyclerView.setLayoutManager(new LinearLayoutManager(this));
- SubscribedSubredditsRecyclerViewAdapter adapter = new SubscribedSubredditsRecyclerViewAdapter(this);
- recyclerView.setAdapter(adapter);
-
- mSubscribedSubredditViewModel = ViewModelProviders.of(this).get(SubscribedSubredditViewModel.class);
- mSubscribedSubredditViewModel.getAllSubscribedSubreddits().observe(this, adapter::setSubscribedSubreddits);
+ SubscribedSubredditsListingFragment fragment = new SubscribedSubredditsListingFragment();
+ Bundle bundle = new Bundle();
+ bundle.putInt(PostFragment.POST_TYPE_KEY, PostDataSource.TYPE_FRONT_PAGE);
+ fragment.setArguments(bundle);
+ getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_subreddit_selection_activity, fragment).commit();
}
@Override
@@ -50,4 +48,12 @@ public class SubredditSelectionActivity extends AppCompatActivity {
return false;
}
+
+ void getSelectedSubreddit(String name, String iconUrl) {
+ Intent returnIntent = new Intent();
+ returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME_KEY, name);
+ returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_ICON_URL_KEY, iconUrl);
+ setResult(Activity.RESULT_OK, returnIntent);
+ finish();
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditsListingFragment.java
index 6dd8d4fa..476782cb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditsListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditsListingFragment.java
@@ -27,6 +27,8 @@ import butterknife.ButterKnife;
*/
public class SubscribedSubredditsListingFragment extends Fragment {
+ static final String EXTRA_IS_SUBREDDIT_SELECTION = "EISSK";
+
@BindView(R.id.recycler_view_subscribed_subreddits_listing_fragment) RecyclerView mRecyclerView;
@BindView(R.id.no_subscriptions_linear_layout_subreddits_listing_fragment) LinearLayout mLinearLayout;
@BindView(R.id.no_subscriptions_image_view_subreddits_listing_fragment) ImageView mImageView;
@@ -55,7 +57,17 @@ public class SubscribedSubredditsListingFragment extends Fragment {
mGlide = Glide.with(this);
mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
- SubscribedSubredditsRecyclerViewAdapter adapter = new SubscribedSubredditsRecyclerViewAdapter(mActivity);
+
+ SubscribedSubredditsRecyclerViewAdapter adapter;
+ if(getArguments().getBoolean(EXTRA_IS_SUBREDDIT_SELECTION)) {
+ adapter = new SubscribedSubredditsRecyclerViewAdapter(mActivity);
+ } else {
+ adapter = new SubscribedSubredditsRecyclerViewAdapter(mActivity, (name, iconUrl) -> {
+ ((SubredditSelectionActivity) mActivity).getSelectedSubreddit(name, iconUrl);
+ });
+ }
+
+
mRecyclerView.setAdapter(adapter);
mSubscribedSubredditViewModel = ViewModelProviders.of(this).get(SubscribedSubredditViewModel.class);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditsRecyclerViewAdapter.java
index f3bdb63b..d9f37e73 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditsRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditsRecyclerViewAdapter.java
@@ -24,12 +24,23 @@ class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
private Context mContext;
private List<SubscribedSubredditData> mSubscribedSubredditData;
private RequestManager glide;
+ private ItemClickListener itemClickListener;
+
+ interface ItemClickListener {
+ void onClick(String name, String iconUrl);
+ }
SubscribedSubredditsRecyclerViewAdapter(Context context) {
mContext = context;
glide = Glide.with(context.getApplicationContext());
}
+ SubscribedSubredditsRecyclerViewAdapter(Context context, ItemClickListener itemClickListener) {
+ mContext = context;
+ glide = Glide.with(context.getApplicationContext());
+ this.itemClickListener = itemClickListener;
+ }
+
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
@@ -40,9 +51,13 @@ class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, final int i) {
viewHolder.itemView.setOnClickListener(view -> {
if(viewHolder.getAdapterPosition() >= 0) {
- Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class);
- intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, mSubscribedSubredditData.get(viewHolder.getAdapterPosition()).getName());
- mContext.startActivity(intent);
+ if(itemClickListener != null) {
+ itemClickListener.onClick(mSubscribedSubredditData.get(i).getName(), mSubscribedSubredditData.get(i).getIconUrl());
+ } else {
+ Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class);
+ intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, mSubscribedSubredditData.get(viewHolder.getAdapterPosition()).getName());
+ mContext.startActivity(intent);
+ }
}
});
if(!mSubscribedSubredditData.get(i).getIconUrl().equals("")) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java
index 1ae1327e..ce3a8b72 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java
@@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit;
import android.content.SharedPreferences;
import android.os.Bundle;
+import android.view.MenuItem;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
@@ -74,6 +75,16 @@ public class SubscribedThingListingActivity extends AppCompatActivity {
}
@Override
+ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
+ if(item.getItemId() == android.R.id.home) {
+ finish();
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE, mInsertSuccess);