diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
index c33f8fa3..72e8c2c2 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
@@ -56,11 +56,6 @@ public class MainActivity extends AppCompatActivity {
@BindView(R.id.settings_linear_layout_main_activity) LinearLayout settingsLinearLayout;
@BindView(R.id.fab_main_activity) FloatingActionButton fab;
- private LinearLayout textTypeLinearLayout;
- private LinearLayout linkTypeLinearLayout;
- private LinearLayout imageTypeLinearLayout;
- private LinearLayout videoTypeLinearLayout;
-
private BottomSheetDialog dialog;
private TextView mNameTextView;
@@ -102,10 +97,10 @@ public class MainActivity extends AppCompatActivity {
ButterKnife.bind(this);
View dialogView = View.inflate(this, R.layout.post_type_bottom_sheet, null);
- textTypeLinearLayout = dialogView.findViewById(R.id.text_type_linear_layout_post_type_bottom_sheet);
- linkTypeLinearLayout = dialogView.findViewById(R.id.link_type_linear_layout_post_type_bottom_sheet);
- imageTypeLinearLayout = dialogView.findViewById(R.id.image_type_linear_layout_post_type_bottom_sheet);
- videoTypeLinearLayout = dialogView.findViewById(R.id.video_type_linear_layout_post_type_bottom_sheet);
+ LinearLayout textTypeLinearLayout = dialogView.findViewById(R.id.text_type_linear_layout_post_type_bottom_sheet);
+ LinearLayout linkTypeLinearLayout = dialogView.findViewById(R.id.link_type_linear_layout_post_type_bottom_sheet);
+ LinearLayout imageTypeLinearLayout = dialogView.findViewById(R.id.image_type_linear_layout_post_type_bottom_sheet);
+ LinearLayout videoTypeLinearLayout = dialogView.findViewById(R.id.video_type_linear_layout_post_type_bottom_sheet);
dialog = new BottomSheetDialog(this);
dialog.setContentView(dialogView);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java
index 97dfc576..57ffcf0d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java
@@ -35,6 +35,7 @@ import java.util.Locale;
import javax.inject.Inject;
import javax.inject.Named;
+import SubredditDatabase.SubredditRoomDatabase;
import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
@@ -46,13 +47,13 @@ import retrofit2.Retrofit;
public class PostImageActivity extends AppCompatActivity {
static final String EXTRA_SUBREDDIT_NAME = "ESN";
- static final String EXTRA_SUBREDDIT_ICON = "ESI";
private static final String SUBREDDIT_NAME_STATE = "SNS";
private static final String SUBREDDIT_ICON_STATE = "SIS";
private static final String SUBREDDIT_SELECTED_STATE = "SSS";
private static final String SUBREDDIT_IS_USER_STATE = "SIUS";
private static final String IMAGE_URI_STATE = "IUS";
+ private static final String LOAD_SUBREDDIT_ICON_STATE = "LSIS";
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
private static final int PICK_IMAGE_REQUEST_CODE = 1;
@@ -72,6 +73,7 @@ public class PostImageActivity extends AppCompatActivity {
private String subredditName;
private boolean subredditSelected = false;
private boolean subredditIsUser;
+ private boolean loadSubredditIconSuccessful = true;
private Uri imageUri;
private RequestManager mGlide;
@@ -114,6 +116,8 @@ public class PostImageActivity extends AppCompatActivity {
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
subredditIsUser = savedInstanceState.getBoolean(SUBREDDIT_IS_USER_STATE);
+ loadSubredditIconSuccessful = savedInstanceState.getBoolean(LOAD_SUBREDDIT_ICON_STATE);
+
if(savedInstanceState.getString(IMAGE_URI_STATE) != null) {
imageUri = Uri.parse(savedInstanceState.getString(IMAGE_URI_STATE));
loadImage();
@@ -121,24 +125,16 @@ public class PostImageActivity extends AppCompatActivity {
if(subredditName != null) {
subreditNameTextView.setText(subredditName);
+ if(!loadSubredditIconSuccessful) {
+ loadSubredditIcon();
+ }
}
- if(iconUrl != null && !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);
- }
-
+ displaySubredditIcon();
} else {
if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME);
- iconUrl = getIntent().getExtras().getString(EXTRA_SUBREDDIT_ICON);
subreditNameTextView.setText(subredditName);
+ loadSubredditIcon();
} else {
mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
@@ -182,6 +178,29 @@ public class PostImageActivity extends AppCompatActivity {
mGlide.load(imageUri).into(imageView);
}
+ private void displaySubredditIcon() {
+ if(iconUrl != null && !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);
+ }
+ }
+
+ private void loadSubredditIcon() {
+ new LoadSubredditIconAsyncTask(SubredditRoomDatabase.getDatabase(this).subredditDao(),
+ subredditName, iconImageUrl -> {
+ iconUrl = iconImageUrl;
+ displaySubredditIcon();
+ loadSubredditIconSuccessful = true;
+ }).execute();
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.post_image_activity, menu);
@@ -306,6 +325,7 @@ public class PostImageActivity extends AppCompatActivity {
if(imageUri != null) {
outState.putString(IMAGE_URI_STATE, imageUri.toString());
}
+ outState.putBoolean(LOAD_SUBREDDIT_ICON_STATE, loadSubredditIconSuccessful);
}
@Override
@@ -320,17 +340,7 @@ public class PostImageActivity extends AppCompatActivity {
subreditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor));
subreditNameTextView.setText(subredditName);
- 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);
- }
+ displaySubredditIcon();
}
} else if(requestCode == PICK_IMAGE_REQUEST_CODE) {
if(resultCode == RESULT_OK) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java
index 193fabbc..ec979f4e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java
@@ -26,6 +26,7 @@ import java.util.Locale;
import javax.inject.Inject;
import javax.inject.Named;
+import SubredditDatabase.SubredditRoomDatabase;
import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
@@ -35,12 +36,12 @@ import retrofit2.Retrofit;
public class PostLinkActivity extends AppCompatActivity {
static final String EXTRA_SUBREDDIT_NAME = "ESN";
- static final String EXTRA_SUBREDDIT_ICON = "ESI";
private static final String SUBREDDIT_NAME_STATE = "SNS";
private static final String SUBREDDIT_ICON_STATE = "SIS";
private static final String SUBREDDIT_SELECTED_STATE = "SSS";
private static final String SUBREDDIT_IS_USER_STATE = "SIUS";
+ private static final String LOAD_SUBREDDIT_ICON_STATE = "LSIS";
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
@@ -55,6 +56,7 @@ public class PostLinkActivity extends AppCompatActivity {
private String subredditName;
private boolean subredditSelected = false;
private boolean subredditIsUser;
+ private boolean loadSubredditIconSuccessful = true;
private RequestManager mGlide;
private Locale mLocale;
@@ -88,26 +90,20 @@ public class PostLinkActivity extends AppCompatActivity {
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
subredditIsUser = savedInstanceState.getBoolean(SUBREDDIT_IS_USER_STATE);
+ loadSubredditIconSuccessful = savedInstanceState.getBoolean(LOAD_SUBREDDIT_ICON_STATE);
if(subredditName != null) {
subreditNameTextView.setText(subredditName);
+ if(!loadSubredditIconSuccessful) {
+ loadSubredditIcon();
+ }
}
- if(iconUrl != null && !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);
- }
+ displaySubredditIcon();
} else {
if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME);
- iconUrl = getIntent().getExtras().getString(EXTRA_SUBREDDIT_ICON);
subreditNameTextView.setText(subredditName);
+ loadSubredditIcon();
} else {
mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
@@ -126,6 +122,29 @@ public class PostLinkActivity extends AppCompatActivity {
});
}
+ private void displaySubredditIcon() {
+ if(iconUrl != null && !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);
+ }
+ }
+
+ private void loadSubredditIcon() {
+ new LoadSubredditIconAsyncTask(SubredditRoomDatabase.getDatabase(this).subredditDao(),
+ subredditName, iconImageUrl -> {
+ iconUrl = iconImageUrl;
+ displaySubredditIcon();
+ loadSubredditIconSuccessful = true;
+ }).execute();
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.post_link_activity, menu);
@@ -192,6 +211,7 @@ public class PostLinkActivity extends AppCompatActivity {
outState.putString(SUBREDDIT_ICON_STATE, iconUrl);
outState.putBoolean(SUBREDDIT_SELECTED_STATE, subredditSelected);
outState.putBoolean(SUBREDDIT_IS_USER_STATE, subredditIsUser);
+ outState.putBoolean(LOAD_SUBREDDIT_ICON_STATE, loadSubredditIconSuccessful);
}
@Override
@@ -206,17 +226,7 @@ public class PostLinkActivity extends AppCompatActivity {
subreditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor));
subreditNameTextView.setText(subredditName);
- 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);
- }
+ displaySubredditIcon();
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java
index ea6e655d..8e9df088 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java
@@ -26,6 +26,7 @@ import java.util.Locale;
import javax.inject.Inject;
import javax.inject.Named;
+import SubredditDatabase.SubredditRoomDatabase;
import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
@@ -35,12 +36,12 @@ import retrofit2.Retrofit;
public class PostTextActivity extends AppCompatActivity {
static final String EXTRA_SUBREDDIT_NAME = "ESN";
- static final String EXTRA_SUBREDDIT_ICON = "ESI";
private static final String SUBREDDIT_NAME_STATE = "SNS";
private static final String SUBREDDIT_ICON_STATE = "SIS";
private static final String SUBREDDIT_SELECTED_STATE = "SSS";
private static final String SUBREDDIT_IS_USER_STATE = "SIUS";
+ private static final String LOAD_SUBREDDIT_ICON_STATE = "LSIS";
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
@@ -55,6 +56,7 @@ public class PostTextActivity extends AppCompatActivity {
private String subredditName;
private boolean subredditSelected = false;
private boolean subredditIsUser;
+ private boolean loadSubredditIconSuccessful = true;
private RequestManager mGlide;
private Locale mLocale;
@@ -88,26 +90,21 @@ public class PostTextActivity extends AppCompatActivity {
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
subredditIsUser = savedInstanceState.getBoolean(SUBREDDIT_IS_USER_STATE);
+ loadSubredditIconSuccessful = savedInstanceState.getBoolean(LOAD_SUBREDDIT_ICON_STATE);
if(subredditName != null) {
subreditNameTextView.setText(subredditName);
+ if(!loadSubredditIconSuccessful) {
+ loadSubredditIcon();
+ }
}
- if(iconUrl != null && !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);
- }
+ displaySubredditIcon();
} else {
if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
+ loadSubredditIconSuccessful = false;
subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME);
- iconUrl = getIntent().getExtras().getString(EXTRA_SUBREDDIT_ICON);
subreditNameTextView.setText(subredditName);
+ loadSubredditIcon();
} else {
mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
@@ -126,6 +123,29 @@ public class PostTextActivity extends AppCompatActivity {
});
}
+ private void displaySubredditIcon() {
+ if(iconUrl != null && !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);
+ }
+ }
+
+ private void loadSubredditIcon() {
+ new LoadSubredditIconAsyncTask(SubredditRoomDatabase.getDatabase(this).subredditDao(),
+ subredditName, iconImageUrl -> {
+ iconUrl = iconImageUrl;
+ displaySubredditIcon();
+ loadSubredditIconSuccessful = true;
+ }).execute();
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.post_text_activity, menu);
@@ -192,6 +212,7 @@ public class PostTextActivity extends AppCompatActivity {
outState.putString(SUBREDDIT_ICON_STATE, iconUrl);
outState.putBoolean(SUBREDDIT_SELECTED_STATE, subredditSelected);
outState.putBoolean(SUBREDDIT_IS_USER_STATE, subredditIsUser);
+ outState.putBoolean(LOAD_SUBREDDIT_ICON_STATE, loadSubredditIconSuccessful);
}
@Override
@@ -206,17 +227,7 @@ public class PostTextActivity extends AppCompatActivity {
subreditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor));
subreditNameTextView.setText(subredditName);
- 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);
- }
+ displaySubredditIcon();
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java
index a0d562c2..6a13ff16 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java
@@ -38,6 +38,7 @@ import java.util.Locale;
import javax.inject.Inject;
import javax.inject.Named;
+import SubredditDatabase.SubredditRoomDatabase;
import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
@@ -47,13 +48,13 @@ import retrofit2.Retrofit;
public class PostVideoActivity extends AppCompatActivity {
static final String EXTRA_SUBREDDIT_NAME = "ESN";
- static final String EXTRA_SUBREDDIT_ICON = "ESI";
private static final String SUBREDDIT_NAME_STATE = "SNS";
private static final String SUBREDDIT_ICON_STATE = "SIS";
private static final String SUBREDDIT_SELECTED_STATE = "SSS";
private static final String SUBREDDIT_IS_USER_STATE = "SIUS";
private static final String VIDEO_URI_STATE = "IUS";
+ private static final String LOAD_SUBREDDIT_ICON_STATE = "LSIS";
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
private static final int PICK_VIDEO_REQUEST_CODE = 1;
@@ -74,6 +75,7 @@ public class PostVideoActivity extends AppCompatActivity {
private boolean subredditSelected = false;
private boolean subredditIsUser;
private Uri videoUri;
+ private boolean loadSubredditIconSuccessful = true;
private RequestManager mGlide;
private Locale mLocale;
@@ -119,6 +121,8 @@ public class PostVideoActivity extends AppCompatActivity {
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
subredditIsUser = savedInstanceState.getBoolean(SUBREDDIT_IS_USER_STATE);
+ loadSubredditIconSuccessful = savedInstanceState.getBoolean(LOAD_SUBREDDIT_ICON_STATE);
+
if(savedInstanceState.getString(VIDEO_URI_STATE) != null) {
videoUri = Uri.parse(savedInstanceState.getString(VIDEO_URI_STATE));
loadImage();
@@ -126,24 +130,16 @@ public class PostVideoActivity extends AppCompatActivity {
if(subredditName != null) {
subreditNameTextView.setText(subredditName);
+ if(!loadSubredditIconSuccessful) {
+ loadSubredditIcon();
+ }
}
- if(iconUrl != null && !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);
- }
-
+ displaySubredditIcon();
} else {
if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME);
- iconUrl = getIntent().getExtras().getString(EXTRA_SUBREDDIT_ICON);
subreditNameTextView.setText(subredditName);
+ loadSubredditIcon();
} else {
mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
@@ -187,6 +183,29 @@ public class PostVideoActivity extends AppCompatActivity {
mGlide.asBitmap().load(videoUri).into(imageView);
}
+ private void displaySubredditIcon() {
+ if(iconUrl != null && !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);
+ }
+ }
+
+ private void loadSubredditIcon() {
+ new LoadSubredditIconAsyncTask(SubredditRoomDatabase.getDatabase(this).subredditDao(),
+ subredditName, iconImageUrl -> {
+ iconUrl = iconImageUrl;
+ displaySubredditIcon();
+ loadSubredditIconSuccessful = true;
+ }).execute();
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.post_image_activity, menu);
@@ -287,6 +306,7 @@ public class PostVideoActivity extends AppCompatActivity {
if(videoUri != null) {
outState.putString(VIDEO_URI_STATE, videoUri.toString());
}
+ outState.putBoolean(LOAD_SUBREDDIT_ICON_STATE, loadSubredditIconSuccessful);
}
@Override
@@ -301,17 +321,7 @@ public class PostVideoActivity extends AppCompatActivity {
subreditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor));
subreditNameTextView.setText(subredditName);
- 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);
- }
+ displaySubredditIcon();
}
} else if(requestCode == PICK_VIDEO_REQUEST_CODE) {
if(resultCode == RESULT_OK) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java
index 58f01eaf..3433cfb8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java
@@ -8,6 +8,7 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
@@ -22,7 +23,9 @@ import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
+import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.android.material.chip.Chip;
+import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import javax.inject.Inject;
@@ -57,6 +60,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
@BindView(R.id.subscriber_count_text_view_view_subreddit_detail_activity) TextView nSubscribersTextView;
@BindView(R.id.online_subscriber_count_text_view_view_subreddit_detail_activity) TextView nOnlineSubscribersTextView;
@BindView(R.id.description_text_view_view_subreddit_detail_activity) TextView descriptionTextView;
+ @BindView(R.id.fab_view_subreddit_detail_activity) FloatingActionButton fab;
private boolean subscriptionReady = false;
private boolean isInLazyMode = false;
@@ -65,6 +69,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
private Fragment mFragment;
private Menu mMenu;
private AppBarLayout.LayoutParams params;
+ private BottomSheetDialog dialog;
private SubscribedSubredditDao subscribedSubredditDao;
private SubredditViewModel mSubredditViewModel;
@@ -85,8 +90,18 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_subreddit_detail);
+
ButterKnife.bind(this);
+ View dialogView = View.inflate(this, R.layout.post_type_bottom_sheet, null);
+ LinearLayout textTypeLinearLayout = dialogView.findViewById(R.id.text_type_linear_layout_post_type_bottom_sheet);
+ LinearLayout linkTypeLinearLayout = dialogView.findViewById(R.id.link_type_linear_layout_post_type_bottom_sheet);
+ LinearLayout imageTypeLinearLayout = dialogView.findViewById(R.id.image_type_linear_layout_post_type_bottom_sheet);
+ LinearLayout videoTypeLinearLayout = dialogView.findViewById(R.id.video_type_linear_layout_post_type_bottom_sheet);
+
+ dialog = new BottomSheetDialog(this);
+ dialog.setContentView(dialogView);
+
((Infinity) getApplication()).getmAppComponent().inject(this);
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
@@ -261,6 +276,38 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_subreddit_detail_activity, mFragment).commit();
}
+
+ textTypeLinearLayout.setOnClickListener(view -> {
+ Intent intent = new Intent(this, PostTextActivity.class);
+ intent.putExtra(PostTextActivity.EXTRA_SUBREDDIT_NAME, subredditName);
+ startActivity(intent);
+ dialog.dismiss();
+ });
+
+ linkTypeLinearLayout.setOnClickListener(view -> {
+ Intent intent = new Intent(this, PostLinkActivity.class);
+ intent.putExtra(PostLinkActivity.EXTRA_SUBREDDIT_NAME, subredditName);
+ startActivity(intent);
+ dialog.dismiss();
+ });
+
+ imageTypeLinearLayout.setOnClickListener(view -> {
+ Intent intent = new Intent(this, PostImageActivity.class);
+ intent.putExtra(PostImageActivity.EXTRA_SUBREDDIT_NAME, subredditName);
+ startActivity(intent);
+ dialog.dismiss();
+ });
+
+ videoTypeLinearLayout.setOnClickListener(view -> {
+ Intent intent = new Intent(this, PostVideoActivity.class);
+ intent.putExtra(PostVideoActivity.EXTRA_SUBREDDIT_NAME, subredditName);
+ startActivity(intent);
+ dialog.dismiss();
+ });
+
+ fab.setOnClickListener(view -> {
+ dialog.show();
+ });
}
@Override
diff --git a/app/src/main/res/layout/activity_view_subreddit_detail.xml b/app/src/main/res/layout/activity_view_subreddit_detail.xml
index d7ef40a3..00563d1b 100644
--- a/app/src/main/res/layout/activity_view_subreddit_detail.xml
+++ b/app/src/main/res/layout/activity_view_subreddit_detail.xml
@@ -119,4 +119,12 @@
+
+
\ No newline at end of file