Browse Source

Animated avatars

pull/70/head
Ezerous 5 years ago
parent
commit
ae71f9492c
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 44
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java
  2. 29
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

44
app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java

@ -25,9 +25,9 @@ import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.bumptech.glide.Glide;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.tabs.TabLayout;
import com.squareup.picasso.Picasso;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
@ -51,7 +51,6 @@ import gr.thmmy.mthmmy.utils.Parcel;
import gr.thmmy.mthmmy.utils.parsing.NewParseTask;
import gr.thmmy.mthmmy.utils.parsing.ParseException;
import gr.thmmy.mthmmy.utils.ui.CenterVerticalSpan;
import gr.thmmy.mthmmy.utils.ui.CircleTransform;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import okhttp3.Response;
import timber.log.Timber;
@ -130,9 +129,9 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
avatarView = findViewById(R.id.user_thumbnail);
if (!Objects.equals(avatarUrl, ""))
//noinspection ConstantConditions
loadAvatar();
loadAvatar(false);
else
loadDefaultAvatar();
loadAvatar(true);
usernameView = findViewById(R.id.profile_activity_username);
usernameView.setTypeface(Typeface.createFromAsset(this.getAssets()
, "fonts/fontawesome-webfont.ttf"));
@ -213,29 +212,18 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
if (pmFAB.getVisibility() != View.GONE) pmFAB.setEnabled(false);
}
private void loadAvatar(){
Picasso.with(this)
.load(avatarUrl)
.fit()
.centerCrop()
.error(Objects.requireNonNull(ResourcesCompat.getDrawable(this.getResources()
, R.drawable.ic_default_user_avatar, null)))
.placeholder(Objects.requireNonNull(ResourcesCompat.getDrawable(this.getResources()
, R.drawable.ic_default_user_avatar, null)))
.transform(new CircleTransform())
.into(avatarView);
}
private void loadAvatar(Boolean loadDefault){
String avatarUri;
if(loadDefault)
avatarUri = "R.drawable.ic_default_user_avatar";
else
avatarUri = avatarUrl;
private void loadDefaultAvatar(){
Picasso.with(this)
.load(R.drawable.ic_default_user_avatar)
.fit()
.centerCrop()
.error(Objects.requireNonNull(ResourcesCompat.getDrawable(this.getResources()
, R.drawable.ic_default_user_avatar, null)))
.placeholder(Objects.requireNonNull(ResourcesCompat.getDrawable(this.getResources()
, R.drawable.ic_default_user_avatar, null)))
.transform(new CircleTransform())
Glide.with(this)
.load(avatarUri)
.circleCrop()
.error(R.drawable.ic_default_user_avatar)
.placeholder(R.drawable.ic_default_user_avatar)
.into(avatarView);
}
@ -319,9 +307,9 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
} else if (usernameView.getText() != username) usernameView.setText(username);
if (avatarUrl != null && !Objects.equals(avatarUrl, ""))
//noinspection ConstantConditions
loadAvatar();
loadAvatar(false);
else
loadDefaultAvatar();
loadAvatar(true);
if (personalText != null) {
personalTextView.setText(personalText);
personalTextView.setVisibility(View.VISIBLE);

29
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

@ -47,13 +47,15 @@ import androidx.core.content.res.ResourcesCompat;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.github.mikephil.charting.charts.HorizontalBarChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.squareup.picasso.Picasso;
import java.text.DecimalFormat;
import java.util.ArrayList;
@ -65,6 +67,7 @@ import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.board.BoardActivity;
import gr.thmmy.mthmmy.activities.profile.ProfileActivity;
import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.base.BaseApplication;
import gr.thmmy.mthmmy.model.Poll;
import gr.thmmy.mthmmy.model.Post;
import gr.thmmy.mthmmy.model.ThmmyFile;
@ -72,7 +75,6 @@ import gr.thmmy.mthmmy.model.ThmmyPage;
import gr.thmmy.mthmmy.model.TopicItem;
import gr.thmmy.mthmmy.utils.parsing.ParseHelpers;
import gr.thmmy.mthmmy.utils.parsing.ThmmyParser;
import gr.thmmy.mthmmy.utils.ui.CircleTransform;
import gr.thmmy.mthmmy.viewmodel.TopicViewModel;
import gr.thmmy.mthmmy.views.ReactiveWebView;
import gr.thmmy.mthmmy.views.editorview.EditorView;
@ -365,7 +367,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
holder.post.setWebViewClient(new LinkLauncher());
//noinspection ConstantConditions
loadAvatar(currentPost.getThumbnailURL(), holder.thumbnail);
loadAvatar(currentPost.getThumbnailURL(), holder.thumbnail, holder.itemView.getContext());
//Sets username,submit date, index number, subject, post's and attached files texts
holder.username.setText(currentPost.getAuthor());
@ -646,7 +648,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
Post reply = (Post) topicItems.get(position);
//noinspection ConstantConditions
loadAvatar(getSessionManager().getAvatarLink(), holder.thumbnail);
loadAvatar(getSessionManager().getAvatarLink(), holder.thumbnail, holder.itemView.getContext());
holder.username.setText(getSessionManager().getUsername());
holder.itemView.setAlpha(1f);
@ -738,7 +740,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
final EditMessageViewHolder holder = (EditMessageViewHolder) currentHolder;
//noinspection ConstantConditions
loadAvatar(getSessionManager().getAvatarLink(), holder.thumbnail);
loadAvatar(getSessionManager().getAvatarLink(), holder.thumbnail, holder.itemView.getContext());
holder.username.setText(getSessionManager().getUsername());
holder.editSubject.setText(currentPost.getSubject());
@ -808,16 +810,15 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
}
}
private void loadAvatar(String imageUrl, ImageView imageView) {
Picasso.with(context)
private void loadAvatar(String imageUrl, ImageView imageView, Context context) {
if(imageUrl!=null)
imageUrl = imageUrl.trim();
Glide.with(context)
.load(imageUrl)
.fit()
.centerCrop()
.error(Objects.requireNonNull(ResourcesCompat.getDrawable(context.getResources()
, R.drawable.ic_default_user_avatar_darker, null)))
.placeholder(Objects.requireNonNull(ResourcesCompat.getDrawable(context.getResources()
, R.drawable.ic_default_user_avatar_darker, null)))
.transform(new CircleTransform())
.circleCrop()
.error(R.drawable.ic_default_user_avatar_darker)
.placeholder(R.drawable.ic_default_user_avatar_darker)
.into(imageView);
}

Loading…
Cancel
Save