From e46ec1cfee2f670028a5d7676ac5de93156ba3bf Mon Sep 17 00:00:00 2001 From: Bnyro <82752168+Bnyro@users.noreply.github.com> Date: Wed, 10 May 2023 22:21:03 +0200 Subject: [PATCH] Migration to Material Design 3 (fixes #1833, fixes #1418) (#1895) --- app/build.gradle | 2 +- .../syncthingandroid/SyncthingApp.java | 3 + .../activities/DeviceActivity.java | 9 +- .../activities/FirstStartActivity.java | 11 ++- .../activities/FolderActivity.java | 9 +- .../activities/MainActivity.java | 5 + .../activities/QRScannerActivity.java | 3 +- .../activities/SettingsActivity.java | 13 ++- .../nutomic/syncthingandroid/util/Util.java | 3 +- .../views/DevicesAdapter.java | 5 +- .../views/FoldersAdapter.java | 5 +- app/src/main/res/drawable/dialog_bg_monet.xml | 22 +++++ app/src/main/res/drawable/ic_monochrome.xml | 20 ++++ .../main/res/layout/activity_first_start.xml | 91 +++++++++---------- ...activity_firststart_slide_api_level_30.xml | 6 +- .../activity_firststart_slide_intro.xml | 9 +- .../activity_firststart_slide_location.xml | 8 +- .../activity_firststart_slide_storage.xml | 13 ++- app/src/main/res/layout/activity_main.xml | 6 +- .../main/res/layout/activity_preferences.xml | 15 +++ app/src/main/res/layout/activity_share.xml | 2 - app/src/main/res/layout/dialog_loading.xml | 3 +- .../res/layout/dialog_usage_reporting.xml | 1 - app/src/main/res/layout/fragment_device.xml | 4 +- app/src/main/res/layout/fragment_folder.xml | 42 ++++----- .../res/layout/fragment_foldertype_dialog.xml | 5 +- .../res/layout/fragment_pullorder_dialog.xml | 5 +- .../res/layout/fragment_versioning_dialog.xml | 5 +- app/src/main/res/layout/item_device_form.xml | 3 +- app/src/main/res/layout/item_folder_list.xml | 3 +- .../res/mipmap-anydpi-v26/ic_launcher.xml | 1 + app/src/main/res/values-night/themes.xml | 8 ++ app/src/main/res/values/colors.xml | 36 -------- app/src/main/res/values/dimens.xml | 1 + app/src/main/res/values/styles.xml | 4 +- app/src/main/res/values/themes.xml | 54 +++++++---- 36 files changed, 241 insertions(+), 194 deletions(-) create mode 100644 app/src/main/res/drawable/dialog_bg_monet.xml create mode 100644 app/src/main/res/drawable/ic_monochrome.xml create mode 100644 app/src/main/res/layout/activity_preferences.xml create mode 100644 app/src/main/res/values-night/themes.xml diff --git a/app/build.gradle b/app/build.gradle index 83dab43f..a41271e2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,7 +6,7 @@ plugins { dependencies { implementation 'eu.chainfire:libsuperuser:1.1.0.202004101746' - implementation 'com.google.android.material:material:1.4.0' + implementation 'com.google.android.material:material:1.8.0' implementation 'com.google.code.gson:gson:2.10.1' implementation 'org.mindrot:jbcrypt:0.4' implementation 'com.google.guava:guava:31.1-android' diff --git a/app/src/main/java/com/nutomic/syncthingandroid/SyncthingApp.java b/app/src/main/java/com/nutomic/syncthingandroid/SyncthingApp.java index d003e02f..05816157 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/SyncthingApp.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/SyncthingApp.java @@ -3,6 +3,7 @@ package com.nutomic.syncthingandroid; import android.app.Application; import android.os.StrictMode; +import com.google.android.material.color.DynamicColors; import com.nutomic.syncthingandroid.util.Languages; import javax.inject.Inject; @@ -13,6 +14,8 @@ public class SyncthingApp extends Application { @Override public void onCreate() { + DynamicColors.applyToActivitiesIfAvailable(this); + super.onCreate(); DaggerDaggerComponent.builder() diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/DeviceActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/DeviceActivity.java index cd4de415..a308d8b4 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/DeviceActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/DeviceActivity.java @@ -8,8 +8,6 @@ import android.content.Intent; import android.graphics.drawable.Drawable; import android.os.Bundle; import androidx.core.content.ContextCompat; -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.widget.SwitchCompat; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; @@ -22,9 +20,8 @@ import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; +import com.google.android.material.materialswitch.MaterialSwitch; import com.google.gson.Gson; -import com.google.zxing.integration.android.IntentIntegrator; -import com.google.zxing.integration.android.IntentResult; import com.nutomic.syncthingandroid.R; import com.nutomic.syncthingandroid.model.Connections; import com.nutomic.syncthingandroid.model.Device; @@ -82,9 +79,9 @@ public class DeviceActivity extends SyncthingActivity implements View.OnClickLis private TextView mCompressionValueView; - private SwitchCompat mIntroducerView; + private MaterialSwitch mIntroducerView; - private SwitchCompat mDevicePaused; + private MaterialSwitch mDevicePaused; private TextView mSyncthingVersionView; diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/FirstStartActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/FirstStartActivity.java index 2c0bfbda..94d66dbb 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/FirstStartActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/FirstStartActivity.java @@ -36,6 +36,7 @@ import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; +import com.google.android.material.color.MaterialColors; import com.nutomic.syncthingandroid.R; import com.nutomic.syncthingandroid.SyncthingApp; import com.nutomic.syncthingandroid.service.Constants; @@ -257,12 +258,12 @@ public class FirstStartActivity extends Activity { } private void setActiveBottomDot(int currentPage) { - int[] colorsActive = getResources().getIntArray(R.array.array_dot_active); - int[] colorsInactive = getResources().getIntArray(R.array.array_dot_inactive); - for (int i = 0; i < mDots.length; i++) { - mDots[i].setTextColor(colorsInactive[currentPage]); + int colorInactive = MaterialColors.getColor(this, R.attr.colorPrimary, Color.BLUE); + int colorActive = MaterialColors.getColor(this, R.attr.colorSecondary, Color.BLUE); + for (TextView mDot : mDots) { + mDot.setTextColor(colorInactive); } - mDots[currentPage].setTextColor(colorsActive[currentPage]); + mDots[currentPage].setTextColor(colorActive); } // ViewPager change listener diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderActivity.java index e2e16eab..95dcebf2 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderActivity.java @@ -9,8 +9,6 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import androidx.documentfile.provider.DocumentFile; -import androidx.appcompat.widget.SwitchCompat; -import androidx.appcompat.app.AlertDialog; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; @@ -26,6 +24,7 @@ import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; +import com.google.android.material.materialswitch.MaterialSwitch; import com.google.gson.Gson; import com.nutomic.syncthingandroid.R; import com.nutomic.syncthingandroid.model.Device; @@ -93,8 +92,8 @@ public class FolderActivity extends SyncthingActivity private TextView mAccessExplanationView; private TextView mFolderTypeView; private TextView mFolderTypeDescriptionView; - private SwitchCompat mFolderFileWatcher; - private SwitchCompat mFolderPaused; + private MaterialSwitch mFolderFileWatcher; + private MaterialSwitch mFolderPaused; private ViewGroup mDevicesContainer; private TextView mPullOrderTypeView; private TextView mPullOrderDescriptionView; @@ -644,7 +643,7 @@ public class FolderActivity extends SyncthingActivity private void addDeviceViewAndSetListener(Device device, LayoutInflater inflater) { inflater.inflate(R.layout.item_device_form, mDevicesContainer); - SwitchCompat deviceView = (SwitchCompat) mDevicesContainer.getChildAt(mDevicesContainer.getChildCount()-1); + MaterialSwitch deviceView = (MaterialSwitch) mDevicesContainer.getChildAt(mDevicesContainer.getChildCount()-1); deviceView.setOnCheckedChangeListener(null); deviceView.setChecked(mFolder.getDevice(device.deviceID) != null); deviceView.setText(device.getDisplayName()); diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java index e88d74c7..4c7154bd 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/MainActivity.java @@ -2,6 +2,8 @@ package com.nutomic.syncthingandroid.activities; import android.annotation.SuppressLint; import android.app.Activity; + +import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import android.app.Dialog; import android.content.ActivityNotFoundException; @@ -18,8 +20,11 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.IBinder; +import android.os.PersistableBundle; import android.os.PowerManager; import android.provider.Settings; + +import com.google.android.material.color.DynamicColors; import com.google.android.material.tabs.TabLayout; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/QRScannerActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/QRScannerActivity.java index 1bf9a0b3..4bc6216b 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/QRScannerActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/QRScannerActivity.java @@ -60,8 +60,9 @@ public class QRScannerActivity extends ThemedAppCompatActivity implements Barcod // region === Permissions Callback === @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == RC_HANDLE_CAMERA_PERM) { - if (grantResults.length !=0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + if (grantResults.length != 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { startScanner(); } else { finish(); diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java index fe356a62..5baa6f1d 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java @@ -1,6 +1,5 @@ package com.nutomic.syncthingandroid.activities; -import android.Manifest; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; @@ -56,17 +55,21 @@ public class SettingsActivity extends SyncthingActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setContentView(R.layout.activity_preferences); + setTitle(R.string.settings_title); + SettingsFragment settingsFragment = new SettingsFragment(); Bundle bundle = new Bundle(); bundle.putString(EXTRA_OPEN_SUB_PREF_SCREEN, getIntent().getStringExtra(EXTRA_OPEN_SUB_PREF_SCREEN)); settingsFragment.setArguments(bundle); getFragmentManager().beginTransaction() - .replace(android.R.id.content, settingsFragment) + .replace(R.id.settings_container, settingsFragment) .commit(); } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == Constants.PermissionRequestType.LOCATION.ordinal()) { boolean granted = grantResults.length > 0; for (int i = 0; i < grantResults.length; i++) { @@ -80,9 +83,9 @@ public class SettingsActivity extends SyncthingActivity { .setAction(SyncthingService.ACTION_REFRESH_NETWORK_INFO)); } else { Util.getAlertDialogBuilder(this) - .setTitle(R.string.sync_only_wifi_ssids_location_permission_rejected_dialog_title) - .setMessage(R.string.sync_only_wifi_ssids_location_permission_rejected_dialog_content) - .setPositiveButton(android.R.string.ok, null).show(); + .setTitle(R.string.sync_only_wifi_ssids_location_permission_rejected_dialog_title) + .setMessage(R.string.sync_only_wifi_ssids_location_permission_rejected_dialog_content) + .setPositiveButton(android.R.string.ok, null).show(); } } } diff --git a/app/src/main/java/com/nutomic/syncthingandroid/util/Util.java b/app/src/main/java/com/nutomic/syncthingandroid/util/Util.java index 17bb1ded..fb30197d 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/util/Util.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/util/Util.java @@ -13,6 +13,7 @@ import androidx.appcompat.app.AlertDialog; import android.util.Log; import android.widget.Toast; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.nutomic.syncthingandroid.R; import com.nutomic.syncthingandroid.service.Constants; @@ -238,6 +239,6 @@ public class Util { */ public static AlertDialog.Builder getAlertDialogBuilder(Context context) { - return new AlertDialog.Builder(context, R.style.Theme_Syncthing_Dialog); + return new MaterialAlertDialogBuilder(context); } } diff --git a/app/src/main/java/com/nutomic/syncthingandroid/views/DevicesAdapter.java b/app/src/main/java/com/nutomic/syncthingandroid/views/DevicesAdapter.java index 8a42687d..c8e8e340 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/views/DevicesAdapter.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/views/DevicesAdapter.java @@ -4,12 +4,15 @@ import android.content.Context; import android.content.res.Resources; import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; + +import android.graphics.Color; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView; +import com.google.android.material.color.MaterialColors; import com.nutomic.syncthingandroid.R; import com.nutomic.syncthingandroid.model.Connections; import com.nutomic.syncthingandroid.model.Device; @@ -63,7 +66,7 @@ public class DevicesAdapter extends ArrayAdapter { download.setText(Util.readableTransferRate(getContext(), 0)); upload.setText(Util.readableTransferRate(getContext(), 0)); status.setText(r.getString(R.string.device_paused)); - status.setTextColor(ContextCompat.getColor(getContext(), R.color.text_black)); + status.setTextColor(MaterialColors.getColor(getContext(), android.R.attr.textColorPrimary, Color.BLACK)); return convertView; } diff --git a/app/src/main/java/com/nutomic/syncthingandroid/views/FoldersAdapter.java b/app/src/main/java/com/nutomic/syncthingandroid/views/FoldersAdapter.java index a8952e4e..4605f7d9 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/views/FoldersAdapter.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/views/FoldersAdapter.java @@ -3,6 +3,8 @@ package com.nutomic.syncthingandroid.views; import android.content.Context; import android.content.Intent; import androidx.databinding.DataBindingUtil; + +import android.graphics.Color; import android.net.Uri; import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; @@ -15,6 +17,7 @@ import android.widget.ArrayAdapter; import android.widget.TextView; import android.widget.Toast; +import com.google.android.material.color.MaterialColors; import com.nutomic.syncthingandroid.R; import com.nutomic.syncthingandroid.databinding.ItemFolderListBinding; import com.nutomic.syncthingandroid.model.Folder; @@ -107,7 +110,7 @@ public class FoldersAdapter extends ArrayAdapter { } else { if (folder.paused) { binding.state.setText(mContext.getString(R.string.state_paused)); - binding.state.setTextColor(ContextCompat.getColor(mContext, R.color.text_black)); + binding.state.setTextColor(MaterialColors.getColor(mContext, android.R.attr.textColorPrimary, Color.BLACK)); } else { binding.state.setText(getLocalizedState(mContext, folderStatus)); switch(folderStatus.state) { diff --git a/app/src/main/res/drawable/dialog_bg_monet.xml b/app/src/main/res/drawable/dialog_bg_monet.xml new file mode 100644 index 00000000..df668bfb --- /dev/null +++ b/app/src/main/res/drawable/dialog_bg_monet.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_monochrome.xml b/app/src/main/res/drawable/ic_monochrome.xml new file mode 100644 index 00000000..31e49bcd --- /dev/null +++ b/app/src/main/res/drawable/ic_monochrome.xml @@ -0,0 +1,20 @@ + + + + diff --git a/app/src/main/res/layout/activity_first_start.xml b/app/src/main/res/layout/activity_first_start.xml index 5918e9c5..75a2b762 100644 --- a/app/src/main/res/layout/activity_first_start.xml +++ b/app/src/main/res/layout/activity_first_start.xml @@ -1,56 +1,51 @@ - + + + android:layout_height="match_parent" /> - + - - + - + -