Fixes after rebase

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>

Fixes after rebase

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>

Fixes after rebase

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>

Fix after rebase

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2022-03-14 14:20:39 +01:00 committed by Álvaro Brey (Rebase PR Action)
parent 75cb8a767c
commit 74e17ee7c6
8 changed files with 65 additions and 34 deletions

View file

@ -183,7 +183,7 @@ public final class MediaProvider {
ThemeButtonUtils themeButtonUtils) {
if (activity != null &&
!PermissionUtil.checkExternalStoragePermission(activity.getApplicationContext())) {
PermissionUtil.requestExternalStoragePermission(activity, true);
PermissionUtil.requestExternalStoragePermission(activity, themeSnackbarUtils, true);
}
}

View file

@ -29,12 +29,9 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.Switch;
import com.nextcloud.client.di.Injectable;
import com.owncloud.android.R;
import com.owncloud.android.utils.theme.ThemeColorUtils;
import javax.inject.Inject;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.graphics.drawable.DrawableCompat;
@ -42,9 +39,8 @@ import androidx.core.graphics.drawable.DrawableCompat;
/**
* Themeable switch preference TODO Migrate to androidx
*/
public class ThemeableSwitchPreference extends SwitchPreference implements Injectable {
@Inject ThemeColorUtils themeColorUtils;
public class ThemeableSwitchPreference extends SwitchPreference {
private ThemeColorUtils themeColorUtils;
public ThemeableSwitchPreference(Context context) {
super(context);
@ -58,6 +54,10 @@ public class ThemeableSwitchPreference extends SwitchPreference implements Injec
super(context, attrs);
}
public void setThemeColorUtils(ThemeColorUtils themeColorUtils) {
this.themeColorUtils = themeColorUtils;
}
@Override
protected void onBindView(View view) {
super.onBindView(view);

View file

@ -121,8 +121,6 @@ import com.owncloud.android.utils.MimeTypeUtil;
import com.owncloud.android.utils.PermissionUtil;
import com.owncloud.android.utils.PushUtils;
import com.owncloud.android.utils.StringUtils;
import com.owncloud.android.utils.theme.ThemeButtonUtils;
import com.owncloud.android.utils.theme.ThemeToolbarUtils;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@ -318,7 +316,7 @@ public class FileDisplayActivity extends FileActivity
super.onPostCreate(savedInstanceState);
PermissionUtil.requestExternalStoragePermission(this);
PermissionUtil.requestExternalStoragePermission(this, themeSnackbarUtils);
if (getIntent().getParcelableExtra(OCFileListFragment.SEARCH_EVENT) != null) {
switchToSearchFragment(savedInstanceState);

View file

@ -69,6 +69,7 @@ import com.owncloud.android.lib.common.ExternalLink;
import com.owncloud.android.lib.common.ExternalLinkType;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.providers.DocumentsStorageProvider;
import com.owncloud.android.ui.ThemeableSwitchPreference;
import com.owncloud.android.ui.asynctasks.LoadingVersionNumberTask;
import com.owncloud.android.utils.DeviceCredentialUtils;
import com.owncloud.android.utils.DisplayUtils;
@ -127,7 +128,7 @@ public class SettingsActivity extends ThemedPreferenceActivity
private Uri serverBaseUri;
private ListPreference lock;
private SwitchPreference showHiddenFiles;
private ThemeableSwitchPreference showHiddenFiles;
private AppCompatDelegate delegate;
private ListPreference prefStoragePath;
@ -148,13 +149,14 @@ public class SettingsActivity extends ThemedPreferenceActivity
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (themeUtils.themingEnabled(this)) {
setTheme(R.style.FallbackThemingTheme);
}
getDelegate().installViewFactory();
getDelegate().onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
setupActionBar();
@ -536,7 +538,9 @@ public class SettingsActivity extends ThemedPreferenceActivity
private void setupShowMediaScanNotifications(PreferenceCategory preferenceCategoryDetails,
boolean fShowMediaScanNotifications) {
SwitchPreference mShowMediaScanNotifications = (SwitchPreference) findPreference(PREFERENCE_SHOW_MEDIA_SCAN_NOTIFICATIONS);
ThemeableSwitchPreference mShowMediaScanNotifications =
(ThemeableSwitchPreference) findPreference(PREFERENCE_SHOW_MEDIA_SCAN_NOTIFICATIONS);
mShowMediaScanNotifications.setThemeColorUtils(themeColorUtils);
if (fShowMediaScanNotifications) {
preferenceCategoryDetails.removePreference(mShowMediaScanNotifications);
@ -545,7 +549,8 @@ public class SettingsActivity extends ThemedPreferenceActivity
private void setupHiddenFilesPreference(PreferenceCategory preferenceCategoryDetails,
boolean fShowHiddenFilesEnabled) {
showHiddenFiles = (SwitchPreference) findPreference("show_hidden_files");
showHiddenFiles = (ThemeableSwitchPreference) findPreference("show_hidden_files");
showHiddenFiles.setThemeColorUtils(themeColorUtils);
if (fShowHiddenFilesEnabled) {
showHiddenFiles.setOnPreferenceClickListener(preference -> {
preferences.setShowHiddenFilesEnabled(showHiddenFiles.isChecked());
@ -608,10 +613,14 @@ public class SettingsActivity extends ThemedPreferenceActivity
private void setupAutoUploadCategory(int accentColor, PreferenceScreen preferenceScreen) {
PreferenceCategory preferenceCategorySyncedFolders =
(PreferenceCategory) findPreference("synced_folders_category");
(PreferenceCategory) findPreference("synced_folders_category");
preferenceCategorySyncedFolders.setTitle(themeTextUtils.getColoredTitle(getString(R.string.drawer_synced_folders),
accentColor));
ThemeableSwitchPreference syncedFolderOnWifiSwitch =
(ThemeableSwitchPreference) findPreference("synced_folder_on_wifi");
syncedFolderOnWifiSwitch.setThemeColorUtils(themeColorUtils);
if (!getResources().getBoolean(R.bool.syncedFolder_light)) {
preferenceScreen.removePreference(preferenceCategorySyncedFolders);
} else {

View file

@ -67,6 +67,7 @@ import com.owncloud.android.ui.dialog.parcel.SyncedFolderParcelable
import com.owncloud.android.utils.PermissionUtil
import com.owncloud.android.utils.SyncedFolderUtils
import com.owncloud.android.utils.theme.ThemeButtonUtils
import com.owncloud.android.utils.theme.ThemeSnackbarUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
@ -159,6 +160,9 @@ class SyncedFoldersActivity :
@Inject
lateinit var themeButtonUtils: ThemeButtonUtils
@Inject
lateinit var themeSnackBarUtils: ThemeSnackbarUtils
private lateinit var binding: SyncedFoldersLayoutBinding
private lateinit var adapter: SyncedFolderAdapter
private lateinit var syncedFolderProvider: SyncedFolderProvider
@ -546,7 +550,7 @@ class SyncedFoldersActivity :
)
onSyncFolderSettingsClick(0, emptyCustomFolder)
} else {
PermissionUtil.requestExternalStoragePermission(this, true)
PermissionUtil.requestExternalStoragePermission(this, themeSnackBarUtils, true)
}
result = super.onOptionsItemSelected(item)
}
@ -773,7 +777,7 @@ class SyncedFoldersActivity :
load(getItemsDisplayedPerFolder(), true)
} else {
// permission denied --> request again
PermissionUtil.requestExternalStoragePermission(this, true)
PermissionUtil.requestExternalStoragePermission(this, themeSnackbarUtils, true)
}
}
else -> super.onRequestPermissionsResult(requestCode, permissions, grantResults)

View file

@ -56,10 +56,6 @@ import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.FileSortOrder;
import com.owncloud.android.utils.PermissionUtil;
import com.owncloud.android.utils.theme.ThemeSnackbarUtils;
import com.owncloud.android.utils.theme.ThemeColorUtils;
import com.owncloud.android.utils.theme.ThemeDrawableUtils;
import com.owncloud.android.utils.theme.ThemeToolbarUtils;
import com.owncloud.android.utils.theme.ThemeUtils;
import java.io.File;
import java.util.ArrayList;
@ -265,7 +261,7 @@ public class UploadFilesActivity extends DrawerActivity implements LocalFileList
}
private void requestPermissions() {
PermissionUtil.requestExternalStoragePermission(this, true);
PermissionUtil.requestExternalStoragePermission(this, themeSnackbarUtils, true);
}
public void showToolbarSpinner() {

View file

@ -41,8 +41,6 @@ import com.google.android.material.snackbar.Snackbar
import com.nextcloud.client.preferences.AppPreferences
import com.nextcloud.client.preferences.AppPreferencesImpl
import com.owncloud.android.R
import com.owncloud.android.utils.theme.ThemeButtonUtils
import com.owncloud.android.utils.theme.ThemeColorUtils
import com.owncloud.android.ui.dialog.StoragePermissionDialogFragment
import com.owncloud.android.utils.theme.ThemeSnackbarUtils
@ -116,26 +114,43 @@ object PermissionUtil {
*/
@JvmStatic
@JvmOverloads
fun requestExternalStoragePermission(activity: AppCompatActivity, permissionRequired: Boolean = false) {
fun requestExternalStoragePermission(
activity: AppCompatActivity,
themeSnackbarUtils: ThemeSnackbarUtils,
permissionRequired: Boolean = false
) {
if (!checkExternalStoragePermission(activity)) {
when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> {
if (canRequestAllFilesPermission(activity)) {
// can request All Files, show choice
showPermissionChoiceDialog(activity, permissionRequired)
showPermissionChoiceDialog(activity, permissionRequired, themeSnackbarUtils)
} else {
// can not request all files, request READ_EXTERNAL_STORAGE
requestStoragePermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE)
requestStoragePermission(
activity,
Manifest.permission.READ_EXTERNAL_STORAGE,
themeSnackbarUtils
)
}
}
else -> requestStoragePermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)
else -> requestStoragePermission(
activity,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
themeSnackbarUtils
)
}
}
}
/**
* Request a storage permission
*/
private fun requestStoragePermission(activity: Activity, permission: String) {
private fun requestStoragePermission(
activity: Activity,
permission: String,
themeSnackbarUtils: ThemeSnackbarUtils
) {
fun doRequest() {
ActivityCompat.requestPermissions(
activity, arrayOf(permission),
@ -185,7 +200,11 @@ object PermissionUtil {
* sdk >= 30: Choice between All Files access or read_external_storage
*/
@RequiresApi(Build.VERSION_CODES.R)
private fun showPermissionChoiceDialog(activity: AppCompatActivity, permissionRequired: Boolean) {
private fun showPermissionChoiceDialog(
activity: AppCompatActivity,
permissionRequired: Boolean,
themeSnackbarUtils: ThemeSnackbarUtils
) {
val preferences: AppPreferences = AppPreferencesImpl.fromContext(activity)
if (!preferences.isStoragePermissionRequested || permissionRequired) {
@ -204,7 +223,11 @@ object PermissionUtil {
override fun onClickMediaReadOnly() {
preferences.isStoragePermissionRequested = true
requestStoragePermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE)
requestStoragePermission(
activity,
Manifest.permission.READ_EXTERNAL_STORAGE,
themeSnackbarUtils
)
}
}
val dialogFragment = StoragePermissionDialogFragment(listener, permissionRequired)

View file

@ -50,7 +50,7 @@ public class ThemeColorUtils {
}
public int primaryAccentColor(Context context) {
OCCapability capability = getCapability(context);
OCCapability capability = CapabilityUtils.getCapability(context);
try {
float adjust;
@ -70,7 +70,7 @@ public class ThemeColorUtils {
}
public int primaryDarkColor(Account account, Context context) {
OCCapability capability = getCapability(account, context);
OCCapability capability = CapabilityUtils.getCapability(account, context);
try {
return calculateDarkColor(Color.parseColor(capability.getServerColor()), context);
@ -163,7 +163,8 @@ public class ThemeColorUtils {
}
public boolean themingEnabled(Context context) {
return getCapability(context).getServerColor() != null && !getCapability(context).getServerColor().isEmpty();
return CapabilityUtils.getCapability(context).getServerColor() != null &&
!CapabilityUtils.getCapability(context).getServerColor().isEmpty();
}
/**