mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 04:37:25 +01:00
Change the logic of parsing the subreddit icon. Click the icon and the banner of the subreddit to view the image in ViewImageActivity.
This commit is contained in:
parent
97079663ff
commit
f90bd4d1cc
@ -53,6 +53,7 @@ class JSONUtils {
|
||||
static final String SCORE_HIDDEN_KEY = "score_hidden";
|
||||
static final String SUBREDDIT_KEY = "subreddit";
|
||||
static final String BANNER_IMG_KEY = "banner_img";
|
||||
static final String BANNER_BACKGROUND_IMAGE_KEY = "banner_background_image";
|
||||
static final String ICON_IMG_KEY = "icon_img";
|
||||
static final String COMMUNITY_ICON_KEY = "community_icon";
|
||||
static final String LINK_KARMA_KEY = "link_karma";
|
||||
|
@ -44,17 +44,23 @@ class ParseSubredditData {
|
||||
String id = data.getString(JSONUtils.NAME_KEY);
|
||||
String subredditFullName = data.getString(JSONUtils.DISPLAY_NAME_PREFIXED);
|
||||
String description = data.getString(JSONUtils.PUBLIC_DESCRIPTION).trim();
|
||||
String bannerImageUrl = data.getString(JSONUtils.BANNER_IMG_KEY);
|
||||
String iconImageUrl = data.getString(JSONUtils.ICON_IMG_KEY);
|
||||
if(iconImageUrl.equals("") || iconImageUrl.equals("null")) {
|
||||
iconImageUrl = data.getString(JSONUtils.COMMUNITY_ICON_KEY);
|
||||
if(iconImageUrl.equals("null")) {
|
||||
iconImageUrl = "";
|
||||
String bannerImageUrl = data.getString(JSONUtils.BANNER_BACKGROUND_IMAGE_KEY);
|
||||
if(bannerImageUrl.equals("") || bannerImageUrl.equals("null")) {
|
||||
bannerImageUrl= data.getString(JSONUtils.BANNER_IMG_KEY);
|
||||
if(bannerImageUrl.equals("null")) {
|
||||
bannerImageUrl = "";
|
||||
}
|
||||
}
|
||||
String iconUrl = data.getString(JSONUtils.COMMUNITY_ICON_KEY);
|
||||
if(iconUrl.equals("") || iconUrl.equals("null")) {
|
||||
iconUrl = data.getString(JSONUtils.ICON_IMG_KEY);
|
||||
if(iconUrl.equals("null")) {
|
||||
iconUrl = "";
|
||||
}
|
||||
}
|
||||
int nSubscribers = data.getInt(JSONUtils.SUBSCRIBERS_KEY);
|
||||
int nCurrentOnlineSubscribers = data.getInt(JSONUtils.ACTIVE_USER_COUNT);
|
||||
subredditData = new SubredditData(id, subredditFullName, iconImageUrl, bannerImageUrl, description, nSubscribers);
|
||||
subredditData = new SubredditData(id, subredditFullName, iconUrl, bannerImageUrl, description, nSubscribers);
|
||||
mNCurrentOnlineSubscribers = nCurrentOnlineSubscribers;
|
||||
} catch (JSONException e) {
|
||||
parseFailed = true;
|
||||
|
@ -65,8 +65,20 @@ class ParseSubscribedThing {
|
||||
for(int i = 0; i < children.length(); i++) {
|
||||
JSONObject data = children.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
|
||||
String name = data.getString(JSONUtils.DISPLAY_NAME);
|
||||
String bannerUrl = data.getString(JSONUtils.BANNER_IMG_KEY);
|
||||
String iconUrl = data.getString(JSONUtils.ICON_IMG_KEY);
|
||||
String bannerImageUrl = data.getString(JSONUtils.BANNER_IMG_KEY);
|
||||
if(bannerImageUrl.equals("") || bannerImageUrl.equals("null")) {
|
||||
bannerImageUrl= data.getString(JSONUtils.BANNER_IMG_KEY);
|
||||
if(bannerImageUrl.equals("null")) {
|
||||
bannerImageUrl = "";
|
||||
}
|
||||
}
|
||||
String iconUrl = data.getString(JSONUtils.COMMUNITY_ICON_KEY);
|
||||
if(iconUrl.equals("") || iconUrl.equals("null")) {
|
||||
iconUrl = data.getString(JSONUtils.ICON_IMG_KEY);
|
||||
if(iconUrl.equals("null")) {
|
||||
iconUrl = "";
|
||||
}
|
||||
}
|
||||
String id = data.getString(JSONUtils.NAME_KEY);
|
||||
if(iconUrl.equals("") || iconUrl.equals("null")) {
|
||||
iconUrl = data.getString(JSONUtils.COMMUNITY_ICON_KEY);
|
||||
@ -84,7 +96,7 @@ class ParseSubscribedThing {
|
||||
String description = data.getString(JSONUtils.PUBLIC_DESCRIPTION).trim();
|
||||
int nSubscribers = data.getInt(JSONUtils.SUBSCRIBERS_KEY);
|
||||
newSubscribedSubredditData.add(new SubscribedSubredditData(id, name, iconUrl));
|
||||
newSubredditData.add(new SubredditData(id, subredditFullName, iconUrl, bannerUrl, description, nSubscribers));
|
||||
newSubredditData.add(new SubredditData(id, subredditFullName, iconUrl, bannerImageUrl, description, nSubscribers));
|
||||
}
|
||||
}
|
||||
lastItem = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY);
|
||||
|
@ -170,8 +170,8 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||
Intent intent = new Intent(mContext, ViewImageActivity.class);
|
||||
intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, imageUrl);
|
||||
intent.putExtra(ViewImageActivity.TITLE_KEY, title);
|
||||
intent.putExtra(ViewImageActivity.SUBREDDIT_KEY, subredditName);
|
||||
intent.putExtra(ViewImageActivity.ID_KEY, id);
|
||||
intent.putExtra(ViewImageActivity.FILE_NAME_KEY, subredditName.substring(2)
|
||||
+ "-" + id.substring(3));
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
@ -57,8 +57,7 @@ public class ViewImageActivity extends AppCompatActivity {
|
||||
|
||||
static final String TITLE_KEY = "TK";
|
||||
static final String IMAGE_URL_KEY = "IUK";
|
||||
static final String SUBREDDIT_KEY = "SK";
|
||||
static final String ID_KEY = "IK";
|
||||
static final String FILE_NAME_KEY = "FNK";
|
||||
|
||||
private boolean isActionBarHidden = false;
|
||||
private boolean isDownloading = false;
|
||||
@ -83,12 +82,11 @@ public class ViewImageActivity extends AppCompatActivity {
|
||||
|
||||
Intent intent = getIntent();
|
||||
mImageUrl = intent.getExtras().getString(IMAGE_URL_KEY);
|
||||
mImageFileName = intent.getExtras().getString(FILE_NAME_KEY);
|
||||
String title = intent.getExtras().getString(TITLE_KEY);
|
||||
final Spannable text = new SpannableString(title);
|
||||
setTitle(text);
|
||||
|
||||
mImageFileName = intent.getExtras().getString(SUBREDDIT_KEY).substring(2) + "-" + intent.getExtras().getString(ID_KEY).substring(3);
|
||||
|
||||
final RelativeLayout relativeLayout = findViewById(R.id.parent_relative_layout_view_image_activity);
|
||||
final GestureImageView imageView = findViewById(R.id.image_view_view_image_activity);
|
||||
final ProgressBar progressBar = findViewById(R.id.progress_bar_view_image_activity);
|
||||
|
@ -168,8 +168,8 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
||||
Intent intent = new Intent(ViewPostDetailActivity.this, ViewImageActivity.class);
|
||||
intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, mPostData.getUrl());
|
||||
intent.putExtra(ViewImageActivity.TITLE_KEY, mPostData.getTitle());
|
||||
intent.putExtra(ViewImageActivity.SUBREDDIT_KEY, mPostData.getSubredditName());
|
||||
intent.putExtra(ViewImageActivity.ID_KEY, mPostData.getId());
|
||||
intent.putExtra(ViewImageActivity.FILE_NAME_KEY, mPostData.getSubredditName().substring(2)
|
||||
+ "-" + mPostData.getId().substring(3));
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit;
|
||||
|
||||
import android.arch.lifecycle.Observer;
|
||||
import android.arch.lifecycle.ViewModelProviders;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
@ -12,6 +13,7 @@ import android.support.v4.app.Fragment;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
@ -39,7 +41,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
String id = getIntent().getExtras().getString(EXTRA_SUBREDDIT_ID);
|
||||
String subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME);
|
||||
final String subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME);
|
||||
|
||||
final String title = "r/" + subredditName;
|
||||
setTitle(title);
|
||||
@ -77,22 +79,60 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
|
||||
mSubredditViewModel = ViewModelProviders.of(this, factory).get(SubredditViewModel.class);
|
||||
mSubredditViewModel.getSubredditLiveData().observe(this, new Observer<SubredditData>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable SubredditData subredditData) {
|
||||
public void onChanged(@Nullable final SubredditData subredditData) {
|
||||
if(subredditData != null) {
|
||||
if(!subredditData.getBannerUrl().equals("") && !subredditData.getBannerUrl().equals("null")) {
|
||||
if(subredditData.getBannerUrl().equals("")) {
|
||||
iconCircleImageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
//Do nothing as it has no image
|
||||
}
|
||||
});
|
||||
} else {
|
||||
glide.load(subredditData.getBannerUrl()).into(bannerImageView);
|
||||
bannerImageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(ViewSubredditDetailActivity.this, ViewImageActivity.class);
|
||||
intent.putExtra(ViewImageActivity.TITLE_KEY, title);
|
||||
intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, subredditData.getBannerUrl());
|
||||
intent.putExtra(ViewImageActivity.FILE_NAME_KEY, subredditName + "-banner");
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(subredditData.getIconUrl().equals("") || subredditData.getIconUrl().equals("null")) {
|
||||
if(subredditData.getIconUrl().equals("")) {
|
||||
glide.load(getDrawable(R.drawable.subreddit_default_icon)).into(iconCircleImageView);
|
||||
iconCircleImageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
//Do nothing as it is a default icon
|
||||
}
|
||||
});
|
||||
} else {
|
||||
glide.load(subredditData.getIconUrl()).into(iconCircleImageView);
|
||||
iconCircleImageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(ViewSubredditDetailActivity.this, ViewImageActivity.class);
|
||||
intent.putExtra(ViewImageActivity.TITLE_KEY, title);
|
||||
intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, subredditData.getIconUrl());
|
||||
intent.putExtra(ViewImageActivity.FILE_NAME_KEY, subredditName + "-icon");
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
subredditNameTextView.setText(subredditData.getName());
|
||||
String nSubscribers = getString(R.string.subscribers_number_detail, subredditData.getNSubscribers());
|
||||
nSubscribersTextView.setText(nSubscribers);
|
||||
descriptionTextView.setText(subredditData.getDescription());
|
||||
if(subredditData.getDescription().equals("")) {
|
||||
descriptionTextView.setVisibility(View.GONE);
|
||||
} else {
|
||||
descriptionTextView.setVisibility(View.VISIBLE);
|
||||
descriptionTextView.setText(subredditData.getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -43,7 +43,8 @@
|
||||
app:civ_border_width="1dp"
|
||||
android:layout_below="@id/banner_image_view_view_subreddit_detail_activity"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:elevation="1000dp"/>
|
||||
android:elevation="4dp"
|
||||
app:civ_circle_background_color="@android:color/white"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@ -64,7 +65,8 @@
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/subscriber_count_text_view_view_subreddit_detail_activity"
|
||||
@ -92,8 +94,11 @@
|
||||
android:id="@+id/description_text_view_view_subreddit_detail_activity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:textColor="@android:color/black" />
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:textColor="@android:color/black"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user