mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-02-03 05:14:45 +01:00
Select subreddit in PostTextActivity.
This commit is contained in:
parent
bc91260e8a
commit
36d24523b6
@ -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);
|
||||
|
@ -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());
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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,10 +51,14 @@ 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) {
|
||||
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("")) {
|
||||
glide.load(mSubscribedSubredditData.get(i).getIconUrl())
|
||||
|
@ -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;
|
||||
@ -73,6 +74,16 @@ public class SubscribedThingListingActivity extends AppCompatActivity {
|
||||
loadSubscriptions();
|
||||
}
|
||||
|
||||
@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);
|
||||
|
@ -1,14 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".SubredditSelectionActivity">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view_subreddit_selection_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
android:id="@+id/frame_layout_subreddit_selection_activity"
|
||||
tools:context=".SubredditSelectionActivity" />
|
Loading…
x
Reference in New Issue
Block a user