Skip to content

Commit

Permalink
Merge pull request #27 from Steve-Mr/wheel
Browse files Browse the repository at this point in the history
清理部分代码,MainActivity增加当前锁屏/主屏指示按钮,处理 bug
  • Loading branch information
Steve-Mr authored Apr 22, 2024
2 parents b454974 + 158d2e0 commit 88eb438
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 16 deletions.
24 changes: 14 additions & 10 deletions app/src/main/java/com/maary/shareas/WallpaperViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,6 @@ class WallpaperViewModel : ViewModel() {
}
}

fun getInputBitmap(): Bitmap? {
return when (currentBitmap) {
HOME -> bakBitmap.bitmapHome
LOCK -> bakBitmap.bitmapLock
else -> bitmap
}
}

fun currentBitmapToggle() {
currentBitmap = if (currentBitmap == HOME) LOCK else HOME
}
Expand Down Expand Up @@ -276,14 +268,14 @@ class WallpaperViewModel : ViewModel() {
}

fun restoreChanges() {
bakBitmap.bitmapLock = bitmap
bakBitmap.bitmapHome = bitmap
_viewerState.update { currentState ->
currentState.copy(
bitmapHome = bitmap,
bitmapLock = bitmap
)
}
bakBitmap.bitmapLock = bitmap
bakBitmap.bitmapHome = bitmap
}

/**
Expand Down Expand Up @@ -328,6 +320,11 @@ class WallpaperViewModel : ViewModel() {
else tertiary!!
}

fun getTertiaryColorAlt(context: Context): Int {
return if (!isDarkMode(context)) tertiaryDark!!
else tertiary!!
}

fun getFabResource(): Int {
if (currentBitmap == HOME) {
return R.drawable.ic_vertical
Expand Down Expand Up @@ -368,6 +365,13 @@ class WallpaperViewModel : ViewModel() {
)
}

private fun getInputBitmap(): Bitmap? {
return when (currentBitmap) {
HOME -> bakBitmap.bitmapHome
LOCK -> bakBitmap.bitmapLock
else -> bitmap
}
}

private fun fitBitmapToScreen(value: Bitmap, context: Context): Bitmap {
val deviceBounds = Util.getDeviceBounds(context)
Expand Down
24 changes: 22 additions & 2 deletions app/src/main/java/com/maary/shareas/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@
import android.os.Looper;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.view.menu.ActionMenuItemView;
import androidx.core.content.ContextCompat;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
Expand Down Expand Up @@ -71,6 +76,15 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(binding.getRoot());
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);

ViewCompat.setOnApplyWindowInsetsListener(binding.indicatorContainer, (v, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
mlp.topMargin = insets.top; // * 2; //+ mlp.topMargin;
v.setLayoutParams(mlp);
return windowInsets;
});


Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
Expand All @@ -87,12 +101,14 @@ protected void onCreate(Bundle savedInstanceState) {
viewModel.getViewerStateLiveData().observe(this, state -> binding.mainView.setImageBitmap(Objects.requireNonNull(viewModel.getDisplayBitmap())));
viewModel.getCurrentBitmapStateLiveData().observe(this, state -> {
binding.mainView.setImageBitmap(Objects.requireNonNull(viewModel.getDisplayBitmap()));
binding.fab.setImageResource(viewModel.getFabResource());
binding.indicatorCurrentState.setIcon(ContextCompat.getDrawable(getApplicationContext(), viewModel.getFabResource()));
});
viewModel.getInEditorLiveData().observe(this, inEditor -> {
if (inEditor) {
binding.indicatorCurrentState.setVisibility(View.INVISIBLE);
binding.bottomAppBarContainer.setVisibility(View.INVISIBLE);
} else {
binding.indicatorCurrentState.setVisibility(View.VISIBLE);
binding.bottomAppBarContainer.setVisibility(View.VISIBLE);
}
});
Expand All @@ -101,6 +117,10 @@ protected void onCreate(Bundle savedInstanceState) {

binding.mainView.setOnImageClickListener(v -> viewModel.currentBitmapToggle());

binding.indicatorCurrentState.setOnClickListener( v -> viewModel.currentBitmapToggle());
binding.indicatorCurrentState.setBackgroundColor(viewModel.getTertiaryColorAlt(getApplicationContext()));
binding.indicatorCurrentState.setIconTint(ColorStateList.valueOf(viewModel.getTertiaryColor(getApplicationContext())));

Palette.from(bitmap).generate(palette -> {
// Access the colors from the palette
assert palette != null;
Expand Down Expand Up @@ -133,7 +153,7 @@ protected void onCreate(Bundle savedInstanceState) {

//TODO:ADD zoom (if possible

Snackbar snackbarReturnHome = Snackbar.make(binding.container, getString(R.string.wallpaper_setted), Snackbar.LENGTH_INDEFINITE)
Snackbar snackbarReturnHome = Snackbar.make(binding.container, getString(R.string.wallpaper_setted), Snackbar.LENGTH_LONG)
.setAction(getString(R.string.gohome), v -> returnToHomeScreen());

WallpaperManager.OnColorsChangedListener wallpaperChangedListener = new WallpaperManager.OnColorsChangedListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ class UpscaleFragment : Fragment() {

}

val preferencesHelper = PreferencesHelper(requireContext())


return binding.root
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_setter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M10,13c0.55,0 1,0.45 1,1s-0.45,1 -1,1s-1,-0.45 -1,-1S9.45,13 10,13M10,11c-1.66,0 -3,1.34 -3,3s1.34,3 3,3s3,-1.34 3,-3S11.66,11 10,11L10,11zM18.5,9l1.09,-2.41L22,5.5l-2.41,-1.09L18.5,2l-1.09,2.41L15,5.5l2.41,1.09L18.5,9zM21.28,12.72L20.5,11l-0.78,1.72L18,13.5l1.72,0.78L20.5,16l0.78,-1.72L23,13.5L21.28,12.72zM16.25,14c0,-0.12 0,-0.25 -0.01,-0.37l1.94,-1.47l-2.5,-4.33l-2.24,0.94c-0.2,-0.13 -0.42,-0.26 -0.64,-0.37L12.5,6h-5L7.2,8.41C6.98,8.52 6.77,8.65 6.56,8.78L4.32,7.83l-2.5,4.33l1.94,1.47C3.75,13.75 3.75,13.88 3.75,14s0,0.25 0.01,0.37l-1.94,1.47l2.5,4.33l2.24,-0.94c0.2,0.13 0.42,0.26 0.64,0.37L7.5,22h5l0.3,-2.41c0.22,-0.11 0.43,-0.23 0.64,-0.37l2.24,0.94l2.5,-4.33l-1.94,-1.47C16.25,14.25 16.25,14.12 16.25,14zM14.83,17.64l-1.73,-0.73c-0.56,0.6 -1.3,1.04 -2.13,1.23L10.73,20H9.27l-0.23,-1.86c-0.83,-0.19 -1.57,-0.63 -2.13,-1.23l-1.73,0.73l-0.73,-1.27l1.49,-1.13c-0.12,-0.39 -0.18,-0.8 -0.18,-1.23c0,-0.43 0.06,-0.84 0.18,-1.23l-1.49,-1.13l0.73,-1.27l1.73,0.73c0.56,-0.6 1.3,-1.04 2.13,-1.23L9.27,8h1.47l0.23,1.86c0.83,0.19 1.57,0.63 2.13,1.23l1.73,-0.73l0.73,1.27l-1.49,1.13c0.12,0.39 0.18,0.8 0.18,1.23c0,0.43 -0.06,0.84 -0.18,1.23l1.49,1.13L14.83,17.64z"/>

</vector>
20 changes: 19 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>

<LinearLayout
android:id="@+id/indicator_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<com.google.android.material.button.MaterialButton
style="?attr/materialIconButtonStyle"
android:id="@+id/indicator_current_state"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:icon="@drawable/ic_vertical"
app:shapeAppearance="@style/Circular"
android:layout_margin="16dp"/>

</LinearLayout>

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/bottomAppBarContainer"
android:layout_width="match_parent"
Expand All @@ -53,7 +71,7 @@
android:layout_height="wrap_content"
android:contentDescription="@string/setAsWallpaper"
app:layout_anchor="@id/bottomAppBar"
app:srcCompat="@drawable/ic_vertical" />
app:srcCompat="@drawable/ic_setter" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

Expand Down

0 comments on commit 88eb438

Please sign in to comment.