Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General theming & customizations #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
android:exported="false" />
<activity
android:name="com.nextcloud.client.widget.DashboardWidgetConfigurationActivity"
android:enabled="false"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
Expand All @@ -278,6 +279,7 @@
android:exported="false" />
<receiver
android:name="com.nextcloud.client.widget.DashboardWidgetProvider"
android:enabled="false"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
Expand Down Expand Up @@ -389,6 +391,7 @@
<service
android:name="com.nextcloud.client.widget.DashboardWidgetService"
android:exported="true"
android:enabled="false"
android:permission="android.permission.BIND_REMOTEVIEWS" />

<provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ abstract class NextcloudDatabase : RoomDatabase() {
abstract fun offlineOperationDao(): OfflineOperationDao

companion object {
const val FIRST_ROOM_DB_VERSION = 65
// NMC customization
// NMC play store version 7.21.9 had db version 64 before SqLite to Room migration
// Keeping it 65(as per NC) will lead to crash when user tried to upgrade the app
const val FIRST_ROOM_DB_VERSION = 64
private var instance: NextcloudDatabase? = null

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
package com.nextcloud.client.editimage

import android.graphics.Bitmap
import android.graphics.drawable.ColorDrawable
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.graphics.drawable.DrawableCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.content.ContextCompat
import com.canhub.cropper.CropImageView
import com.nextcloud.client.di.Injectable
import com.nextcloud.client.jobs.upload.FileUploadHelper
Expand Down Expand Up @@ -72,20 +71,25 @@ class EditImageActivity :
file = intent.extras?.getParcelableArgument(EXTRA_FILE, OCFile::class.java)
?: throw IllegalArgumentException("Missing file argument")

setSupportActionBar(binding.toolbar)
supportActionBar?.apply {
title = file.fileName
setDisplayHomeAsUpEnabled(true)
}

val windowInsetsController = WindowCompat.getInsetsController(window, window.decorView)
windowInsetsController.hide(WindowInsetsCompat.Type.statusBars())

window.navigationBarColor = getColor(R.color.black)
// NMC Customization
setupToolbar()
setupActionBar()

setupCropper()
}

//NMC Customization
private fun setupActionBar() {
supportActionBar?.let {
viewThemeUtils.platform.themeStatusBar(this)
it.setDisplayHomeAsUpEnabled(true)
it.setDisplayShowTitleEnabled(true)
//custom color for back arrow for NMC
viewThemeUtils.files.themeActionBar(this, it, file.fileName)
it.setBackgroundDrawable(ColorDrawable(resources.getColor(R.color.bg_default, null)))
}
}

override fun onCropImageComplete(view: CropImageView, result: CropImageView.CropResult) {
if (!result.isSuccessful) {
DisplayUtils.showSnackMessage(this, getString(R.string.image_editor_unable_to_edit_image))
Expand Down Expand Up @@ -122,14 +126,20 @@ class EditImageActivity :
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
// add save button to action bar
menuInflater.inflate(R.menu.custom_menu_placeholder, menu)
val saveIcon = AppCompatResources.getDrawable(this, R.drawable.ic_check)?.also {
DrawableCompat.setTint(it, resources.getColor(R.color.white, theme))
}
// NMC: No need to apply NC tint here as we will be doing it later in code
val saveIcon = AppCompatResources.getDrawable(this, R.drawable.ic_tick)
menu?.findItem(R.id.custom_menu_placeholder_item)?.apply {
icon = saveIcon
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
contentDescription = getString(R.string.common_save)
}
// NMC customization
icon = icon?.let {
viewThemeUtils.platform.colorDrawable(
it,
ContextCompat.getColor(this@EditImageActivity, R.color.fontAppbar)
)
}
}
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ class FileActionsBottomSheet : BottomSheetDialogFragment(), Injectable {
binding.thumbnailLayout.thumbnailShimmer,
syncedFolderProvider.preferences,
viewThemeUtils,
syncedFolderProvider
syncedFolderProvider,
false
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ class TrashbinFileActionsBottomSheet : BottomSheetDialogFragment(), Injectable {
binding.thumbnailLayout.thumbnailShimmer,
syncedFolderProvider.preferences,
viewThemeUtils,
syncedFolderProvider
syncedFolderProvider,
false
)
}
}
Expand Down
42 changes: 42 additions & 0 deletions app/src/main/java/com/nmc/android/ui/utils/Log_NMC.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.nmc.android.ui.utils

import com.owncloud.android.BuildConfig
import com.owncloud.android.lib.common.utils.Log_OC

/**
* NMC log interpreter class
* this class will be used whenever we have to reduce the logs writing
* this will avoid printing logs in release builds
* todo: can be extended later for more functions
*/
object Log_NMC {
@JvmStatic
fun v(tag: String?, msg: String?) {
if (BuildConfig.DEBUG) Log_OC.v(tag, msg)
}

@JvmStatic
fun d(tag: String?, msg: String?) {
if (BuildConfig.DEBUG) Log_OC.d(tag, msg)
}

@JvmStatic
fun d(tag: String, msg: String, e: Exception) {
if (BuildConfig.DEBUG) Log_OC.d(tag, msg, e)
}

@JvmStatic
fun i(tag: String?, msg: String?) {
if (BuildConfig.DEBUG) Log_OC.i(tag, msg)
}

@JvmStatic
fun e(tag: String?, msg: String?) {
if (BuildConfig.DEBUG) Log_OC.e(tag, msg)
}

@JvmStatic
fun w(tag: String?, msg: String?) {
if (BuildConfig.DEBUG) Log_OC.w(tag, msg)
}
}
7 changes: 2 additions & 5 deletions app/src/main/java/com/owncloud/android/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -994,11 +994,8 @@ public AndroidInjector<Object> androidInjector() {
}

public static void setAppTheme(DarkMode mode) {
switch (mode) {
case LIGHT -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
case DARK -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
case SYSTEM -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
}
// NMC Customization -> Always follow system theme
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import android.net.Uri;
import android.provider.MediaStore;

import com.nmc.android.ui.utils.Log_NMC;
import com.owncloud.android.MainApp;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.utils.PermissionUtil;
import com.owncloud.android.utils.theme.ViewThemeUtils;

Expand Down Expand Up @@ -107,7 +107,7 @@ public static List<MediaFolder> getImageFolders(ContentResolver contentResolver,
MediaStore.Images.Media.DATE_TAKEN,
ContentResolverHelper.SORT_DIRECTION_DESCENDING,
itemLimit);
Log_OC.d(TAG, "Reading images for " + mediaFolder.folderName);
Log_NMC.d(TAG, "Reading images for " + mediaFolder.folderName);

if (cursorImages != null) {
String filePath;
Expand Down Expand Up @@ -217,7 +217,7 @@ public static List<MediaFolder> getVideoFolders(ContentResolver contentResolver,
ContentResolverHelper.SORT_DIRECTION_DESCENDING,
itemLimit);

Log_OC.d(TAG, "Reading videos for " + mediaFolder.folderName);
Log_NMC.d(TAG, "Reading videos for " + mediaFolder.folderName);

if (cursorVideos != null) {
String filePath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import com.nextcloud.client.account.User;
import com.nextcloud.client.network.ConnectivityService;
import com.nmc.android.ui.utils.Log_NMC;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.lib.common.OwnCloudAccount;
Expand Down Expand Up @@ -123,7 +124,7 @@ protected Void doInBackground(File... params) {
}

String cachePath = cacheDir.getPath() + File.separator + CACHE_FOLDER;
Log_OC.d(TAG, "thumbnail cache dir: " + cachePath);
Log_NMC.d(TAG, "thumbnail cache dir: " + cachePath);
File diskCacheDir = new File(cachePath);

// migrate from external cache to internal cache
Expand All @@ -140,7 +141,7 @@ protected Void doInBackground(File... params) {
mThumbnailCache = new DiskLruImageCache(diskCacheDir, DISK_CACHE_SIZE, mCompressFormat,
mCompressQuality);
} catch (Exception e) {
Log_OC.d(TAG, "Disk cache init failed", e);
Log_NMC.d(TAG, "Disk cache init failed", e);
mThumbnailCache = null;
}
}
Expand Down Expand Up @@ -723,7 +724,7 @@ private Bitmap doThumbnailFromOCFileInBackground() {
file.getLocalId() + "&x=" + pxW + "&y=" + pxH;
}

Log_OC.d(TAG, "generate thumbnail: " + file.getFileName() + " URI: " + uri);
Log_NMC.d(TAG, "generate thumbnail: " + file.getFileName() + " URI: " + uri);
getMethod = new GetMethod(uri);
getMethod.setRequestHeader("Cookie",
"nc_sameSiteCookielax=true;nc_sameSiteCookiestrict=true");
Expand Down Expand Up @@ -756,7 +757,7 @@ private Bitmap doThumbnailFromOCFileInBackground() {

// Add thumbnail to cache
if (thumbnail != null) {
Log_OC.d(TAG, "add thumbnail to cache: " + file.getFileName());
Log_NMC.d(TAG, "add thumbnail to cache: " + file.getFileName());
addBitmapToCache(imageKey, thumbnail);
}
}
Expand Down Expand Up @@ -926,13 +927,13 @@ private Bitmap doFileInBackground(File file, Type type) {
thumbnail = retriever.getFrameAtTime(-1);
} catch (Exception ex) {
// can't create a bitmap
Log_OC.w(TAG, "Failed to create bitmap from video " + file.getAbsolutePath());
Log_NMC.w(TAG, "Failed to create bitmap from video " + file.getAbsolutePath());
} finally {
try {
retriever.release();
} catch (RuntimeException | IOException ex) {
// Ignore failure at this point.
Log_OC.w(TAG, "Failed release MediaMetadataRetriever for " + file.getAbsolutePath());
Log_NMC.w(TAG, "Failed release MediaMetadataRetriever for " + file.getAbsolutePath());
}
}

Expand Down Expand Up @@ -1051,7 +1052,7 @@ Drawable doAvatarInBackground() {

int px = mResources.getInteger(R.integer.file_avatar_px);
String uri = mClient.getBaseUri() + "/index.php/avatar/" + Uri.encode(mUserId) + "/" + px;
Log_OC.d("Avatar", "URI: " + uri);
Log_NMC.d("Avatar", "URI: " + uri);
get = new GetMethod(uri);

// only use eTag if available and corresponding avatar is still there
Expand Down Expand Up @@ -1325,7 +1326,7 @@ public static void generateThumbnailFromOCFile(OCFile file, User user, Context c
String uri = client.getBaseUri() + "/index.php/apps/files/api/v1/thumbnail/" +
pxW + "/" + pxH + Uri.encode(file.getRemotePath(), "/");

Log_OC.d(TAG, "generate thumbnail: " + file.getFileName() + " URI: " + uri);
Log_NMC.d(TAG, "generate thumbnail: " + file.getFileName() + " URI: " + uri);
getMethod = new GetMethod(uri);
getMethod.setRequestHeader("Cookie", "nc_sameSiteCookielax=true;nc_sameSiteCookiestrict=true");

Expand All @@ -1348,7 +1349,7 @@ public static void generateThumbnailFromOCFile(OCFile file, User user, Context c
thumbnail = handlePNG(thumbnail, pxW, pxH);
}

Log_OC.d(TAG, "add thumbnail to cache: " + file.getFileName());
Log_NMC.d(TAG, "add thumbnail to cache: " + file.getFileName());
addBitmapToCache(imageKey, thumbnail);
}
} catch (Exception e) {
Expand Down Expand Up @@ -1402,7 +1403,7 @@ private static Bitmap doResizedImageInBackground(OCFile file, FileDataStorageMan
String uri = mClient.getBaseUri() + "/index.php/core/preview?fileId="
+ file.getLocalId()
+ "&x=" + (pxW / 2) + "&y=" + (pxH / 2) + "&a=1&mode=cover&forceIcon=0";
Log_OC.d(TAG, "generate resized image: " + file.getFileName() + " URI: " + uri);
Log_NMC.d(TAG, "generate resized image: " + file.getFileName() + " URI: " + uri);
getMethod = new GetMethod(uri);

int status = mClient.executeMethod(getMethod);
Expand All @@ -1420,7 +1421,7 @@ private static Bitmap doResizedImageInBackground(OCFile file, FileDataStorageMan

// Add thumbnail to cache
if (thumbnail != null) {
Log_OC.d(TAG, "add resized image to cache: " + file.getFileName());
Log_NMC.d(TAG, "add resized image to cache: " + file.getFileName());
addBitmapToCache(imageKey, thumbnail);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,8 @@ protected void onPostCreate(Bundle savedInstanceState) {
onOpenFileIntent(getIntent());
} else if (RESTART.equals(getIntent().getAction())) {
// most likely switched to different account
DisplayUtils.showSnackMessage(this, String.format(getString(R.string.logged_in_as), accountManager.getUser().getAccountName()));
// NMC-2576 --> Disabling switch account snackbar for NMC
/*DisplayUtils.showSnackMessage(this, String.format(getString(R.string.logged_in_as), accountManager.getUser().getAccountName()));*/
}

upgradeNotificationForInstantUpload();
Expand Down Expand Up @@ -520,6 +521,9 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted
getOCFileListFragmentFromFile().directCameraUpload();
} else if (!shouldShowRequestPermissionRationale(permissions[0])) {
// user CHECKED "never ask again"
DisplayUtils.showSnackMessage(this, R.string.camera_permission_rationale);
}
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.google.android.material.snackbar.Snackbar
import com.nextcloud.android.common.ui.theme.utils.ColorRole
import com.nextcloud.client.di.Injectable
import com.nextcloud.client.preferences.AppPreferences
import com.owncloud.android.R
Expand Down Expand Up @@ -80,30 +79,18 @@ class PassCodeActivity : AppCompatActivity(), Injectable {
setContentView(binding.root)

PassCodeManager.setSecureFlag(this, true)
applyTint()
setupPasscodeEditTexts()
setSoftInputMode()
setupUI(savedInstanceState)
setTextListeners()
}

private fun applyTint() {
viewThemeUtils.platform.colorViewBackground(binding.cardViewContent, ColorRole.SURFACE_VARIANT)
viewThemeUtils.material.colorMaterialButtonPrimaryBorderless(binding.cancel)
}

private fun setupPasscodeEditTexts() {
passCodeEditTexts[0] = binding.txt0
passCodeEditTexts[1] = binding.txt1
passCodeEditTexts[2] = binding.txt2
passCodeEditTexts[3] = binding.txt3

passCodeEditTexts.forEach {
it?.let { editText ->
viewThemeUtils.platform.colorEditText(editText)
}
}

passCodeEditTexts[0]?.requestFocus()

binding.cardViewContent.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class GalleryAdapter(
transferServiceGetter,
showMetadata = false,
showShareAvatar = false,
viewThemeUtils
viewThemeUtils,
true
)
}

Expand Down
Loading