bug fix, item layout update

This commit is contained in:
nuclearfog 2023-09-23 15:39:07 +02:00
parent 3fdd67f0fb
commit a98a614bc4
No known key found for this signature in database
GPG Key ID: 03488A185C476379
8 changed files with 66 additions and 67 deletions

View File

@ -1,6 +1,5 @@
package org.nuclearfog.twidda.backend.utils;
import android.app.Activity;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
@ -248,11 +247,10 @@ public class AppStyles {
/**
* setup a transparent blurry toolbar
*
* @param activity activity reference to get the measures
* @param background background overlapped by the toolbar at the top
* @param toolbarBackground background image of the toolbar
*/
public static void setToolbarBackground(Activity activity, ImageView background, ImageView toolbarBackground) {
public static void setToolbarBackground(ImageView background, ImageView toolbarBackground) {
Drawable backgroundDrawable = background.getDrawable();
if (backgroundDrawable instanceof BitmapDrawable) {
try {
@ -278,9 +276,9 @@ public class AppStyles {
}
int widthPixels = Resources.getSystem().getDisplayMetrics().widthPixels;
int blurRadius = Math.max(Math.round((image.getWidth() * 20.0f) / widthPixels), 10);
float toolbarRatio = activity.getResources().getDimension(R.dimen.profile_toolbar_height) / widthPixels;
float toolbarRatio = background.getResources().getDimension(R.dimen.profile_toolbar_height) / widthPixels;
// do final transformations (crop first image to toolbar background size, then blur)
BlurTransformation blur = new BlurTransformation(activity.getApplicationContext(), blurRadius);
BlurTransformation blur = new BlurTransformation(background.getContext(), blurRadius);
CropTransformation crop = new CropTransformation(image.getWidth(), (int) (image.getWidth() * toolbarRatio), GravityHorizontal.CENTER, GravityVertical.TOP);
image = blur.transform(crop.transform(image));
toolbarBackground.setImageBitmap(image);

View File

@ -0,0 +1,34 @@
package org.nuclearfog.twidda.backend.utils;
import android.widget.ImageView;
import java.lang.ref.WeakReference;
/**
* Runnable class used to update blur background of a toolbar
*
* @author nuclearfog
*/
public class ToolbarUpdater implements Runnable {
private WeakReference<ImageView> bannerRef, toolbarRef;
/**
* @param profile_banner profile banner view
* @param toolbar_background toolbar background view
*/
public ToolbarUpdater(ImageView profile_banner, ImageView toolbar_background) {
bannerRef = new WeakReference<>(profile_banner);
toolbarRef = new WeakReference<>(toolbar_background);
}
@Override
public void run() {
ImageView profile_banner = bannerRef.get();
ImageView toolbar_background = toolbarRef.get();
if (profile_banner != null && toolbar_background != null) {
AppStyles.setToolbarBackground(profile_banner, toolbar_background);
}
}
}

View File

@ -55,6 +55,7 @@ import org.nuclearfog.twidda.backend.utils.EmojiUtils;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.backend.utils.LinkUtils;
import org.nuclearfog.twidda.backend.utils.StringUtils;
import org.nuclearfog.twidda.backend.utils.ToolbarUpdater;
import org.nuclearfog.twidda.config.GlobalSettings;
import org.nuclearfog.twidda.model.Relation;
import org.nuclearfog.twidda.model.User;
@ -539,13 +540,7 @@ public class ProfileActivity extends AppCompatActivity implements OnClickListene
public void onSuccess() {
// setup toolbar background
if (settings.toolbarOverlapEnabled()) {
// fixme may cause memory leak
bannerImage.post(new Runnable() {
@Override
public void run() {
AppStyles.setToolbarBackground(ProfileActivity.this, bannerImage, toolbarBackground);
}
});
bannerImage.post(new ToolbarUpdater(bannerImage, toolbarBackground));
}
}

View File

@ -35,6 +35,7 @@ import org.nuclearfog.twidda.backend.helper.update.UserUpdate;
import org.nuclearfog.twidda.backend.image.PicassoBuilder;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.ErrorUtils;
import org.nuclearfog.twidda.backend.utils.ToolbarUpdater;
import org.nuclearfog.twidda.config.Configuration;
import org.nuclearfog.twidda.config.GlobalSettings;
import org.nuclearfog.twidda.model.User;
@ -260,13 +261,7 @@ public class ProfileEditor extends MediaActivity implements OnClickListener, Asy
public void onSuccess() {
// set toolbar background
if (settings.toolbarOverlapEnabled()) {
// fixme may cause memory leak
profile_banner.post(new Runnable() {
@Override
public void run() {
AppStyles.setToolbarBackground(ProfileEditor.this, profile_banner, toolbar_background);
}
});
profile_banner.post(new ToolbarUpdater(profile_banner, toolbar_background));
}
}

View File

@ -14,14 +14,10 @@ import androidx.constraintlayout.widget.ConstraintLayout;
*/
public class LockableConstraintLayout extends ConstraintLayout {
private static final float LOCK_RATIO = 1.1f;
@Nullable
private LockCallback callback;
private boolean xLock = false;
private boolean yLock = false;
private float yPos = 0.0f;
private float xPos = 0.0f;
/**
* @inheritDoc
@ -42,27 +38,20 @@ public class LockableConstraintLayout extends ConstraintLayout {
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_MOVE:
float deltaX = ev.getX() - xPos;
float deltaY = ev.getY() - yPos;
// lock x-axis when swiping up/down
if (!xLock && Math.abs(deltaY) > Math.abs(deltaX) * LOCK_RATIO) {
xLock = true;
}
float deltaY = ev.getAxisValue(MotionEvent.AXIS_Y) - yPos;
// detect scroll down, then aquire scroll lock
if (xLock && deltaY < 0.0f && callback != null) {
if (!yLock && deltaY < 0.0f && callback != null) {
yLock = callback.aquireVerticalScrollLock();
}
// fall through
case MotionEvent.ACTION_DOWN:
// note the current coordinates touch event
xPos = ev.getX();
yPos = ev.getY();
yPos = ev.getAxisValue(MotionEvent.AXIS_Y);
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
xLock = false;
yLock = false;
break;
}

View File

@ -9,25 +9,17 @@
android:id="@+id/item_account_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/login_layout_padding">
android:padding="@dimen/login_card_padding">
<ImageView
android:id="@+id/item_account_profile"
android:layout_width="@dimen/login_image_size"
android:layout_height="@dimen/login_image_size"
android:layout_marginEnd="@dimen/login_layout_padding"
android:layout_marginEnd="@dimen/login_layout_margin"
android:contentDescription="@string/profile_image"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/item_account_profile_barrier" />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/item_account_profile_barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="start"
app:constraint_referenced_ids="item_account_username,item_account_screenname,item_account_date" />
app:layout_constraintBottom_toBottomOf="parent" />
<TextView
android:id="@+id/item_account_username"
@ -35,9 +27,11 @@
android:layout_height="wrap_content"
android:lines="1"
android:textSize="@dimen/login_name_textsize_big"
app:layout_constraintStart_toEndOf="@id/item_account_profile_barrier"
android:layout_marginStart="@dimen/login_layout_margin"
android:layout_marginEnd="@dimen/login_layout_margin"
app:layout_constraintStart_toEndOf="@id/item_account_profile"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@id/item_login_button_barrier" />
app:layout_constraintEnd_toStartOf="@id/item_account_remove" />
<TextView
android:id="@+id/item_account_screenname"
@ -45,40 +39,34 @@
android:layout_height="wrap_content"
android:lines="1"
android:textSize="@dimen/login_name_textsize"
app:layout_constraintStart_toEndOf="@id/item_account_profile_barrier"
android:layout_marginStart="@dimen/login_layout_margin"
android:layout_marginEnd="@dimen/login_layout_margin"
app:layout_constraintStart_toEndOf="@id/item_account_profile"
app:layout_constraintTop_toBottomOf="@id/item_account_username"
app:layout_constraintBottom_toTopOf="@id/item_account_date"
app:layout_constraintEnd_toStartOf="@id/item_login_button_barrier" />
app:layout_constraintEnd_toStartOf="@id/item_account_remove" />
<TextView
android:id="@+id/item_account_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="@dimen/login_date_textsize"
app:layout_constraintStart_toEndOf="@id/item_account_profile_barrier"
android:layout_marginStart="@dimen/login_layout_margin"
android:layout_marginEnd="@dimen/login_layout_margin"
app:layout_constraintStart_toEndOf="@id/item_account_profile"
app:layout_constraintTop_toBottomOf="@id/item_account_screenname"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/item_login_button_barrier" />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/item_login_button_barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="end"
app:constraint_referenced_ids="item_account_username,item_account_screenname,item_account_date" />
app:layout_constraintEnd_toStartOf="@id/item_account_remove" />
<ImageButton
android:id="@+id/item_account_remove"
android:layout_width="@dimen/login_button_size"
android:layout_height="@dimen/login_button_size"
android:padding="@dimen/login_button_padding"
android:layout_marginStart="@dimen/login_layout_padding"
android:contentDescription="@string/descr_remove_user"
android:scaleType="fitCenter"
android:src="@drawable/cross"
app:layout_constraintStart_toEndOf="@id/item_login_button_barrier"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
style="@style/RoundButton" />

View File

@ -168,8 +168,7 @@
android:contentDescription="@string/descr_remove_user"
android:scaleType="fitCenter"
android:src="@drawable/cross"
app:layout_constraintTop_toTopOf="@id/item_user_profile"
app:layout_constraintBottom_toBottomOf="@id/item_user_profile"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
style="@style/RoundButton" />

View File

@ -105,10 +105,10 @@
<dimen name="item_user_layout_padding">5dp</dimen>
<dimen name="item_user_textview_padding">5dp</dimen>
<dimen name="item_user_drawable_margin">5dp</dimen>
<dimen name="item_user_button_size">36dp</dimen>
<dimen name="item_user_button_size">20sp</dimen>
<dimen name="item_user_notification_button_size">20sp</dimen>
<dimen name="item_user_notification_button_drawable_padding">1dp</dimen>
<dimen name="item_user_button_padding">7dp</dimen>
<dimen name="item_user_button_padding">1dp</dimen>
<dimen name="item_user_textsize_small">12sp</dimen>
<dimen name="item_user_icon_size">14sp</dimen>
<dimen name="item_user_image_margin">8dp</dimen>
@ -131,9 +131,10 @@
<dimen name="login_name_textsize_big">14sp</dimen>
<dimen name="login_name_textsize">12sp</dimen>
<dimen name="login_date_textsize">11sp</dimen>
<dimen name="login_layout_padding">8dp</dimen>
<dimen name="login_button_size">36dp</dimen>
<dimen name="login_button_padding">7dp</dimen>
<dimen name="login_card_padding">8dp</dimen>
<dimen name="login_layout_margin">8dp</dimen>
<dimen name="login_button_size">20sp</dimen>
<dimen name="login_button_padding">1dp</dimen>
<dimen name="login_image_size">64dp</dimen>
<!--dimens of item_dropdown-->