mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 08:39:22 +01:00
Move several Permissions dependencies to core.
This commit is contained in:
@@ -12,7 +12,7 @@ import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.animation.ArgbEvaluatorCompat
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import org.thoughtcrime.securesms.util.views.Stub
|
||||
import org.signal.core.ui.view.Stub
|
||||
import org.signal.core.ui.R as CoreUiR
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,7 +17,7 @@ import org.thoughtcrime.securesms.BuildConfig;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.database.NoExternalStorageException;
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies;
|
||||
import org.thoughtcrime.securesms.permissions.PermissionCompat;
|
||||
import org.signal.core.util.permissions.PermissionCompat;
|
||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
|
||||
import androidx.annotation.AttrRes;
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StyleRes;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
import androidx.appcompat.view.ContextThemeWrapper;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
|
||||
public class ThemeUtil {
|
||||
|
||||
public static boolean isDarkNotificationTheme(@NonNull Context context) {
|
||||
return (context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
|
||||
}
|
||||
|
||||
public static boolean isDarkTheme(@NonNull Context context) {
|
||||
return getAttribute(context, R.attr.theme_type, "light").equals("dark");
|
||||
}
|
||||
|
||||
public static int getThemedResourceId(@NonNull Context context, @AttrRes int attr) {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
Resources.Theme theme = context.getTheme();
|
||||
|
||||
if (theme.resolveAttribute(attr, typedValue, true)) {
|
||||
return typedValue.resourceId;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static boolean getThemedBoolean(@NonNull Context context, @AttrRes int attr) {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
Resources.Theme theme = context.getTheme();
|
||||
|
||||
if (theme.resolveAttribute(attr, typedValue, true)) {
|
||||
return typedValue.data != 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static @ColorInt int getThemedColor(@NonNull Context context, @AttrRes int attr) {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
Resources.Theme theme = context.getTheme();
|
||||
|
||||
if (theme.resolveAttribute(attr, typedValue, true)) {
|
||||
return typedValue.data;
|
||||
}
|
||||
return Color.RED;
|
||||
}
|
||||
|
||||
public static @Nullable Drawable getThemedDrawable(@NonNull Context context, @AttrRes int attr) {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
Resources.Theme theme = context.getTheme();
|
||||
|
||||
if (theme.resolveAttribute(attr, typedValue, true)) {
|
||||
return AppCompatResources.getDrawable(context, typedValue.resourceId);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static LayoutInflater getThemedInflater(@NonNull Context context, @NonNull LayoutInflater inflater, @StyleRes int theme) {
|
||||
Context contextThemeWrapper = new ContextThemeWrapper(context, theme);
|
||||
return inflater.cloneInContext(contextThemeWrapper);
|
||||
}
|
||||
|
||||
public static float getThemedDimen(@NonNull Context context, @AttrRes int attr) {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
Resources.Theme theme = context.getTheme();
|
||||
|
||||
if (theme.resolveAttribute(attr, typedValue, true)) {
|
||||
return typedValue.getDimension(context.getResources().getDisplayMetrics());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static String getAttribute(Context context, int attribute, String defaultValue) {
|
||||
TypedValue outValue = new TypedValue();
|
||||
|
||||
if (context.getTheme().resolveAttribute(attribute, outValue, true)) {
|
||||
CharSequence charSequence = outValue.coerceToString();
|
||||
if (charSequence != null) {
|
||||
return charSequence.toString();
|
||||
}
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ import androidx.lifecycle.Lifecycle;
|
||||
|
||||
import org.signal.core.util.concurrent.ListenableFuture;
|
||||
import org.signal.core.util.concurrent.SettableFuture;
|
||||
import org.thoughtcrime.securesms.util.views.Stub;
|
||||
import org.signal.core.ui.view.Stub;
|
||||
|
||||
public final class ViewUtil {
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ import android.view.WindowManager;
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.signal.core.ui.util.ThemeUtil;
|
||||
|
||||
public final class WindowUtil {
|
||||
|
||||
private WindowUtil() {
|
||||
|
||||
@@ -20,7 +20,7 @@ import androidx.core.content.ContextCompat;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.util.CommunicationActions;
|
||||
import org.thoughtcrime.securesms.util.ThemeUtil;
|
||||
import org.signal.core.ui.util.ThemeUtil;
|
||||
|
||||
/**
|
||||
* Appends an optional "Learn more" link to a given piece of text.
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
package org.thoughtcrime.securesms.util.views;
|
||||
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewStub;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class Stub<T extends View> {
|
||||
|
||||
private ViewStub viewStub;
|
||||
private T view;
|
||||
|
||||
public Stub(@NonNull ViewStub viewStub) {
|
||||
this.viewStub = viewStub;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return (viewStub != null) ? viewStub.getId() : view.getId();
|
||||
}
|
||||
|
||||
public T get() {
|
||||
if (view == null) {
|
||||
//noinspection unchecked
|
||||
view = (T) viewStub.inflate();
|
||||
viewStub = null;
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
public boolean resolved() {
|
||||
return view != null;
|
||||
}
|
||||
|
||||
public void setVisibility(int visibility) {
|
||||
if (resolved() || visibility == View.VISIBLE) {
|
||||
get().setVisibility(visibility);
|
||||
}
|
||||
}
|
||||
|
||||
public int getVisibility() {
|
||||
if (resolved()) {
|
||||
return get().getVisibility();
|
||||
} else {
|
||||
return View.GONE;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return getVisibility() == View.VISIBLE;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user