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.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager; import androidx.viewpager.widget.ViewPager;
import com.bumptech.glide.Glide;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayout;
import com.squareup.picasso.Picasso;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; 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.NewParseTask;
import gr.thmmy.mthmmy.utils.parsing.ParseException; import gr.thmmy.mthmmy.utils.parsing.ParseException;
import gr.thmmy.mthmmy.utils.ui.CenterVerticalSpan; import gr.thmmy.mthmmy.utils.ui.CenterVerticalSpan;
import gr.thmmy.mthmmy.utils.ui.CircleTransform;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import okhttp3.Response; import okhttp3.Response;
import timber.log.Timber; import timber.log.Timber;
@ -130,9 +129,9 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
avatarView = findViewById(R.id.user_thumbnail); avatarView = findViewById(R.id.user_thumbnail);
if (!Objects.equals(avatarUrl, "")) if (!Objects.equals(avatarUrl, ""))
//noinspection ConstantConditions //noinspection ConstantConditions
loadAvatar(); loadAvatar(false);
else else
loadDefaultAvatar(); loadAvatar(true);
usernameView = findViewById(R.id.profile_activity_username); usernameView = findViewById(R.id.profile_activity_username);
usernameView.setTypeface(Typeface.createFromAsset(this.getAssets() usernameView.setTypeface(Typeface.createFromAsset(this.getAssets()
, "fonts/fontawesome-webfont.ttf")); , "fonts/fontawesome-webfont.ttf"));
@ -213,29 +212,18 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
if (pmFAB.getVisibility() != View.GONE) pmFAB.setEnabled(false); if (pmFAB.getVisibility() != View.GONE) pmFAB.setEnabled(false);
} }
private void loadAvatar(){ private void loadAvatar(Boolean loadDefault){
Picasso.with(this) String avatarUri;
.load(avatarUrl) if(loadDefault)
.fit() avatarUri = "R.drawable.ic_default_user_avatar";
.centerCrop() else
.error(Objects.requireNonNull(ResourcesCompat.getDrawable(this.getResources() avatarUri = avatarUrl;
, 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 loadDefaultAvatar(){ Glide.with(this)
Picasso.with(this) .load(avatarUri)
.load(R.drawable.ic_default_user_avatar) .circleCrop()
.fit() .error(R.drawable.ic_default_user_avatar)
.centerCrop() .placeholder(R.drawable.ic_default_user_avatar)
.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); .into(avatarView);
} }
@ -319,9 +307,9 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
} else if (usernameView.getText() != username) usernameView.setText(username); } else if (usernameView.getText() != username) usernameView.setText(username);
if (avatarUrl != null && !Objects.equals(avatarUrl, "")) if (avatarUrl != null && !Objects.equals(avatarUrl, ""))
//noinspection ConstantConditions //noinspection ConstantConditions
loadAvatar(); loadAvatar(false);
else else
loadDefaultAvatar(); loadAvatar(true);
if (personalText != null) { if (personalText != null) {
personalTextView.setText(personalText); personalTextView.setText(personalText);
personalTextView.setVisibility(View.VISIBLE); 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.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.RecyclerView; 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.charts.HorizontalBarChart;
import com.github.mikephil.charting.components.XAxis; import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis; import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData; import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet; import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry; import com.github.mikephil.charting.data.BarEntry;
import com.squareup.picasso.Picasso;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.ArrayList; 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.board.BoardActivity;
import gr.thmmy.mthmmy.activities.profile.ProfileActivity; import gr.thmmy.mthmmy.activities.profile.ProfileActivity;
import gr.thmmy.mthmmy.base.BaseActivity; import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.base.BaseApplication;
import gr.thmmy.mthmmy.model.Poll; import gr.thmmy.mthmmy.model.Poll;
import gr.thmmy.mthmmy.model.Post; import gr.thmmy.mthmmy.model.Post;
import gr.thmmy.mthmmy.model.ThmmyFile; 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.model.TopicItem;
import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import gr.thmmy.mthmmy.utils.parsing.ParseHelpers;
import gr.thmmy.mthmmy.utils.parsing.ThmmyParser; import gr.thmmy.mthmmy.utils.parsing.ThmmyParser;
import gr.thmmy.mthmmy.utils.ui.CircleTransform;
import gr.thmmy.mthmmy.viewmodel.TopicViewModel; import gr.thmmy.mthmmy.viewmodel.TopicViewModel;
import gr.thmmy.mthmmy.views.ReactiveWebView; import gr.thmmy.mthmmy.views.ReactiveWebView;
import gr.thmmy.mthmmy.views.editorview.EditorView; import gr.thmmy.mthmmy.views.editorview.EditorView;
@ -365,7 +367,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
holder.post.setWebViewClient(new LinkLauncher()); holder.post.setWebViewClient(new LinkLauncher());
//noinspection ConstantConditions //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 //Sets username,submit date, index number, subject, post's and attached files texts
holder.username.setText(currentPost.getAuthor()); holder.username.setText(currentPost.getAuthor());
@ -646,7 +648,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
Post reply = (Post) topicItems.get(position); Post reply = (Post) topicItems.get(position);
//noinspection ConstantConditions //noinspection ConstantConditions
loadAvatar(getSessionManager().getAvatarLink(), holder.thumbnail); loadAvatar(getSessionManager().getAvatarLink(), holder.thumbnail, holder.itemView.getContext());
holder.username.setText(getSessionManager().getUsername()); holder.username.setText(getSessionManager().getUsername());
holder.itemView.setAlpha(1f); holder.itemView.setAlpha(1f);
@ -738,7 +740,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
final EditMessageViewHolder holder = (EditMessageViewHolder) currentHolder; final EditMessageViewHolder holder = (EditMessageViewHolder) currentHolder;
//noinspection ConstantConditions //noinspection ConstantConditions
loadAvatar(getSessionManager().getAvatarLink(), holder.thumbnail); loadAvatar(getSessionManager().getAvatarLink(), holder.thumbnail, holder.itemView.getContext());
holder.username.setText(getSessionManager().getUsername()); holder.username.setText(getSessionManager().getUsername());
holder.editSubject.setText(currentPost.getSubject()); holder.editSubject.setText(currentPost.getSubject());
@ -808,16 +810,15 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
} }
} }
private void loadAvatar(String imageUrl, ImageView imageView) { private void loadAvatar(String imageUrl, ImageView imageView, Context context) {
Picasso.with(context) if(imageUrl!=null)
imageUrl = imageUrl.trim();
Glide.with(context)
.load(imageUrl) .load(imageUrl)
.fit() .circleCrop()
.centerCrop() .error(R.drawable.ic_default_user_avatar_darker)
.error(Objects.requireNonNull(ResourcesCompat.getDrawable(context.getResources() .placeholder(R.drawable.ic_default_user_avatar_darker)
, 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())
.into(imageView); .into(imageView);
} }

Loading…
Cancel
Save