added user ImageView stand alone

This commit is contained in:
h4h13 2019-05-20 00:09:56 +05:30
parent 9c363a6b28
commit 762fb4dbbe
24 changed files with 215 additions and 261 deletions

View file

@ -40,8 +40,8 @@ class ContributorAdapter(private var contributors: List<Contributor>) : Recycler
text.text = contributor.summary
GlideApp.with(image.context)
.load(contributor.profileImage)
.error(R.drawable.ic_person_flat)
.placeholder(R.drawable.ic_person_flat)
.error(R.drawable.ic_account_white_24dp)
.placeholder(R.drawable.ic_account_white_24dp)
.into(image)
}
}

View file

@ -145,7 +145,7 @@ class OptionsSheetDialogFragment : RoundedBottomSheetDialogFragment(), View.OnCl
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ userImage!!.setImageBitmap(it) }, {
userImage!!.setImageDrawable(ContextCompat
.getDrawable(context!!, R.drawable.ic_person_flat))
.getDrawable(context!!, R.drawable.ic_account_white_24dp))
}, {
}))

View file

@ -22,7 +22,7 @@ enum class NowPlayingScreen constructor(@param:StringRes @field:StringRes
PLAIN(R.string.plain, R.drawable.np_plain, 3),
TINY(R.string.tiny, R.drawable.np_tiny, 7),
SIMPLE(R.string.simple, R.drawable.np_simple, 8),
CLASSIC(R.string.classic, R.drawable.np_normal, 13);
CLASSIC(R.string.classic, R.drawable.np_classic, 13);
//SLIDE(R.string.slide, R.drawable.np_slide, 13)
}

View file

@ -1,8 +1,6 @@
package code.name.monkey.retromusic.fragments.mainactivity;
import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
@ -23,16 +21,10 @@ import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import com.afollestad.materialcab.MaterialCab;
import com.bumptech.glide.request.Request;
import com.bumptech.glide.request.target.SizeReadyCallback;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import com.google.android.material.appbar.AppBarLayout;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import code.name.monkey.appthemehelper.ThemeStore;
import code.name.monkey.appthemehelper.common.ATHToolbarActivity;
import code.name.monkey.appthemehelper.util.ATHUtil;
@ -42,18 +34,14 @@ import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.dialogs.CreatePlaylistDialog;
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment;
import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment;
import code.name.monkey.retromusic.glide.GlideApp;
import code.name.monkey.retromusic.helper.SortOrder;
import code.name.monkey.retromusic.interfaces.CabHolder;
import code.name.monkey.retromusic.interfaces.MainActivityFragmentCallbacks;
import code.name.monkey.retromusic.util.NavigationUtil;
import code.name.monkey.retromusic.util.PreferenceUtil;
import code.name.monkey.retromusic.util.RetroColorUtil;
import code.name.monkey.retromusic.util.RetroUtil;
import io.reactivex.disposables.CompositeDisposable;
import static code.name.monkey.retromusic.Constants.USER_PROFILE;
public class LibraryFragment extends AbsMainActivityFragment implements CabHolder, MainActivityFragmentCallbacks {
public static final String TAG = "LibraryFragment";
@ -101,78 +89,9 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
toolbar = view.findViewById(R.id.toolbar);
userImage = view.findViewById(R.id.userImage);
userImage.setOnClickListener(v -> showMainMenu());
loadImageFromStorage();
return view;
}
private void loadImageFromStorage() {
GlideApp.with(getMainActivity())
.asDrawable()
.placeholder(R.drawable.ic_person_flat)
.fallback(R.drawable.ic_person_flat)
.load(new File(PreferenceUtil.getInstance().getProfileImage(), USER_PROFILE))
.into(new Target<Drawable>() {
@Override
public void onLoadStarted(@Nullable Drawable placeholder) {
userImage.setImageDrawable(placeholder);
}
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
userImage.setImageDrawable(errorDrawable);
}
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
userImage.setImageDrawable(resource);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
@Override
public void getSize(@NonNull SizeReadyCallback cb) {
cb.onSizeReady(32, 32);
}
@Override
public void removeCallback(@NonNull SizeReadyCallback cb) {
}
@Override
public void setRequest(@Nullable Request request) {
}
@Nullable
@Override
public Request getRequest() {
return null;
}
@Override
public void onStart() {
}
@Override
public void onStop() {
}
@Override
public void onDestroy() {
}
});
}
public void setTitle(@StringRes int name) {
bannerTitle.setText(getString(name));
}

View file

@ -160,72 +160,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements
}
}
private void loadImageFromStorage() {
GlideApp.with(getMainActivity())
.asDrawable()
.placeholder(R.drawable.ic_person_flat)
.fallback(R.drawable.ic_person_flat)
.load(new File(PreferenceUtil.getInstance().getProfileImage(), USER_PROFILE))
.into(new Target<Drawable>() {
@Override
public void onLoadStarted(@Nullable Drawable placeholder) {
userImage.setImageDrawable(placeholder);
}
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
userImage.setImageDrawable(errorDrawable);
}
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
userImage.setImageDrawable(resource);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
@Override
public void getSize(@NonNull SizeReadyCallback cb) {
cb.onSizeReady(32, 32);
}
@Override
public void removeCallback(@NonNull SizeReadyCallback cb) {
}
@Nullable
@Override
public Request getRequest() {
return null;
}
@Override
public void setRequest(@Nullable Request request) {
}
@Override
public void onStart() {
}
@Override
public void onStop() {
}
@Override
public void onDestroy() {
}
});
}
private void initViews(View view) {
coordinatorLayout = view.findViewById(R.id.coordinatorLayout);
userImage = view.findViewById(R.id.userImage);
@ -305,7 +239,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements
setUpBreadCrumbs();
setUpRecyclerView();
setUpAdapter();
loadImageFromStorage();
}
private void setUpAppbarColor() {

View file

@ -109,61 +109,6 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
}
}
private fun loadImageFromStorage(imageView: ImageView) {
GlideApp.with(mainActivity)
.asDrawable()
.placeholder(R.drawable.ic_person_flat)
.fallback(R.drawable.ic_person_flat)
.load(File(PreferenceUtil.getInstance().profileImage, USER_PROFILE))
.into(object : Target<Drawable> {
override fun onLoadStarted(placeholder: Drawable?) {
imageView.setImageDrawable(placeholder)
}
override fun onLoadFailed(errorDrawable: Drawable?) {
imageView.setImageDrawable(errorDrawable)
}
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
imageView.setImageDrawable(resource)
}
override fun onLoadCleared(placeholder: Drawable?) {
}
override fun getSize(cb: SizeReadyCallback) {
cb.onSizeReady(32, 32)
}
override fun removeCallback(cb: SizeReadyCallback) {
}
override fun setRequest(request: Request?) {
}
override fun getRequest(): Request? {
return null
}
override fun onStart() {
}
override fun onStop() {
}
override fun onDestroy() {
}
})
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
homePresenter = HomePresenter(this)
@ -240,7 +185,6 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
override fun onResume() {
super.onResume()
disposable = CompositeDisposable()
loadImageFromStorage(userImage)
getTimeOfTheDay()
}

View file

@ -74,32 +74,8 @@ class MainSettingsFragment : Fragment(), View.OnClickListener {
text.text = PreferenceUtil.getInstance().userBio
titleWelcome.setTextColor(ThemeStore.textColorPrimary(context!!))
titleWelcome.text = String.format("%s %s!", getTimeOfTheDay(), PreferenceUtil.getInstance().userName)
loadImageFromStorage()
userInfoContainer.setOnClickListener { NavigationUtil.goToUserInfo(activity!!) }
}
override fun onDestroyView() {
super.onDestroyView()
disposable.clear()
}
private val disposable = CompositeDisposable()
private fun loadImageFromStorage() {
disposable.add(Compressor(context!!)
.setMaxHeight(300)
.setMaxWidth(300)
.setQuality(75)
.setCompressFormat(Bitmap.CompressFormat.WEBP)
.compressToBitmapAsFlowable(
File(PreferenceUtil.getInstance().profileImage, USER_PROFILE))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ userImage.setImageBitmap(it) }, {
userImage.setImageDrawable(ContextCompat.getDrawable(context!!, R.drawable.ic_person_flat))
}))
}
private fun inflateFragment(fragment: Fragment, @StringRes title: Int) {
if (activity != null) {
(activity as SettingsActivity).setupFragment(fragment, title)

View file

@ -51,8 +51,8 @@ public class NetworkImageView extends CircularImageView {
public void setImageUrl(@NonNull Context context, @NonNull String imageUrl) {
GlideApp.with(context)
.load(imageUrl)
.error(R.drawable.ic_person_flat)
.placeholder(R.drawable.ic_person_flat)
.error(R.drawable.ic_account_white_24dp)
.placeholder(R.drawable.ic_account_white_24dp)
.into(this);
}

View file

@ -0,0 +1,147 @@
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package code.name.monkey.retromusic.views;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.preference.PreferenceManager;
import android.util.AttributeSet;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.bumptech.glide.request.Request;
import com.bumptech.glide.request.target.SizeReadyCallback;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import java.io.File;
import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.glide.GlideApp;
import code.name.monkey.retromusic.util.PreferenceUtil;
import static code.name.monkey.retromusic.Constants.USER_PROFILE;
public class UserImageView extends CircularImageView implements SharedPreferences.OnSharedPreferenceChangeListener {
public UserImageView(@NonNull Context context) {
super(context);
init(context);
}
public UserImageView(@NonNull Context context, @NonNull AttributeSet attrs) {
super(context, attrs);
init(context);
}
public UserImageView(@NonNull Context context, @NonNull AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
void init(@NonNull Context context) {
resetImage(context);
}
private void resetImage(@NonNull Context context) {
GlideApp.with(context)
.asDrawable()
.placeholder(R.drawable.ic_account_white_24dp)
.fallback(R.drawable.ic_account_white_24dp)
.load(new File(PreferenceUtil.getInstance().getProfileImage(), USER_PROFILE))
.into(new Target<Drawable>() {
@Override
public void onLoadStarted(@Nullable Drawable placeholder) {
setImageDrawable(placeholder);
setBackgroundColor(Color.TRANSPARENT);
}
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
setImageDrawable(errorDrawable);
setBackgroundColor(Color.TRANSPARENT);
}
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
setImageDrawable(resource);
setBackgroundColor(Color.TRANSPARENT);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
@Override
public void getSize(@NonNull SizeReadyCallback cb) {
cb.onSizeReady(32, 32);
}
@Override
public void removeCallback(@NonNull SizeReadyCallback cb) {
}
@Nullable
@Override
public Request getRequest() {
return null;
}
@Override
public void setRequest(@Nullable Request request) {
}
@Override
public void onStart() {
}
@Override
public void onStop() {
}
@Override
public void onDestroy() {
}
});
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
PreferenceManager.getDefaultSharedPreferences(getContext()).unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(@NonNull SharedPreferences sharedPreferences, @NonNull String key) {
if (key.equals(PreferenceUtil.PROFILE_IMAGE_PATH)) {
resetImage(getContext());
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

View file

@ -62,14 +62,17 @@
app:layout_collapseMode="pin"
tools:ignore="UnusedAttribute">
<code.name.monkey.retromusic.views.CircularImageView
<code.name.monkey.retromusic.views.UserImageView
android:id="@+id/userImage"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="14dp"
android:layout_weight="0"
app:civ_border="false" />
android:background="@android:color/transparent"
app:civ_border="false"
app:civ_border_width="0dp"
app:civ_shadow="false" />
<TextView
android:id="@+id/bannerTitle"

View file

@ -31,15 +31,18 @@
style="@style/Toolbar"
app:layout_collapseMode="pin"
tools:ignore="UnusedAttribute">
<code.name.monkey.retromusic.views.CircularImageView
<code.name.monkey.retromusic.views.UserImageView
android:id="@+id/userImage"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="14dp"
android:layout_weight="0"
app:civ_border="false" />
android:background="@android:color/transparent"
app:civ_border="false"
app:civ_border_width="0dp"
app:civ_shadow="false" />
<TextView
android:id="@+id/bannerTitle"

View file

@ -64,14 +64,18 @@
app:layout_collapseMode="pin"
tools:ignore="UnusedAttribute">
<code.name.monkey.retromusic.views.CircularImageView
<code.name.monkey.retromusic.views.UserImageView
android:id="@+id/userImage"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="14dp"
android:layout_weight="0"
app:civ_border="false" />
android:background="@android:color/transparent"
app:civ_border="false"
app:civ_border_width="0dp"
app:civ_shadow="false" />
<TextView
android:id="@+id/bannerTitle"

View file

@ -33,14 +33,17 @@
app:layout_collapseMode="pin"
tools:ignore="UnusedAttribute">
<code.name.monkey.retromusic.views.CircularImageView
<code.name.monkey.retromusic.views.UserImageView
android:id="@+id/userImage"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="14dp"
android:layout_weight="0"
app:civ_border="false" />
android:background="@android:color/transparent"
app:civ_border="false"
app:civ_border_width="0dp"
app:civ_shadow="false" />
<TextView
android:id="@+id/bannerTitle"

View file

@ -62,15 +62,17 @@
style="@style/Toolbar"
app:layout_collapseMode="pin"
tools:ignore="UnusedAttribute">
<code.name.monkey.retromusic.views.CircularImageView
<code.name.monkey.retromusic.views.UserImageView
android:id="@+id/userImage"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="14dp"
android:layout_weight="0"
app:civ_border="false" />
android:background="@android:color/transparent"
app:civ_border="false"
app:civ_border_width="0dp"
app:civ_shadow="false" />
<TextView
android:id="@+id/bannerTitle"

View file

@ -34,14 +34,17 @@
app:layout_collapseMode="pin"
tools:ignore="UnusedAttribute">
<code.name.monkey.retromusic.views.CircularImageView
<code.name.monkey.retromusic.views.UserImageView
android:id="@+id/userImage"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="14dp"
android:layout_weight="0"
app:civ_border="false" />
android:background="@android:color/transparent"
app:civ_border="false"
app:civ_border_width="0dp"
app:civ_shadow="false" />
<TextView
android:id="@+id/bannerTitle"

View file

@ -9,7 +9,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="@drawable/img_offer"
android:contentDescription="TODO" />
<LinearLayout

View file

@ -58,14 +58,18 @@
app:layout_collapseMode="pin"
tools:ignore="UnusedAttribute">
<code.name.monkey.retromusic.views.CircularImageView
<code.name.monkey.retromusic.views.UserImageView
android:id="@+id/userImage"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="14dp"
android:layout_weight="0"
app:civ_border="false" />
android:background="@android:color/transparent"
app:civ_border="false"
app:civ_border_width="0dp"
app:civ_shadow="false" />
<TextView
android:id="@+id/bannerTitle"

View file

@ -42,14 +42,17 @@
app:layout_collapseMode="pin"
tools:ignore="UnusedAttribute">
<code.name.monkey.retromusic.views.CircularImageView
<code.name.monkey.retromusic.views.UserImageView
android:id="@+id/userImage"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="14dp"
android:layout_weight="0"
app:civ_border="false" />
android:background="@android:color/transparent"
app:civ_border="false"
app:civ_border_width="0dp"
app:civ_shadow="false" />
<TextView
android:id="@+id/bannerTitle"

View file

@ -30,14 +30,17 @@
app:layout_collapseMode="pin"
tools:ignore="UnusedAttribute">
<code.name.monkey.retromusic.views.CircularImageView
<code.name.monkey.retromusic.views.UserImageView
android:id="@+id/userImage"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="14dp"
android:layout_weight="0"
app:civ_border="false" />
android:background="@android:color/transparent"
app:civ_border="false"
app:civ_border_width="0dp"
app:civ_shadow="false" />
<TextView
android:id="@+id/bannerTitle"

View file

@ -40,14 +40,17 @@
app:layout_collapseMode="pin"
tools:ignore="UnusedAttribute">
<code.name.monkey.retromusic.views.CircularImageView
<code.name.monkey.retromusic.views.UserImageView
android:id="@+id/userImage"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="14dp"
android:layout_weight="0"
app:civ_border="false" />
android:background="@android:color/transparent"
app:civ_border="false"
app:civ_border_width="0dp"
app:civ_shadow="false" />
<TextView
android:id="@+id/bannerTitle"

View file

@ -21,13 +21,18 @@
android:minHeight="72dp"
android:orientation="horizontal">
<code.name.monkey.retromusic.views.CircularImageView
<code.name.monkey.retromusic.views.UserImageView
android:id="@+id/userImage"
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="16dp"
android:layout_weight="0"
app:civ_border="false" />
android:background="@android:color/transparent"
app:civ_border="false"
app:civ_border_width="0dp"
app:civ_shadow="false" />
<LinearLayout
android:layout_width="match_parent"

View file

@ -1,4 +1,4 @@
<!-- drawable/toggle_switch.xml -->
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"