Skip to content

Commit

Permalink
Show more info about auto upload on GPlay
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <[email protected]>
  • Loading branch information
tobiasKaminsky committed Jan 10, 2025
1 parent 510b5e0 commit 7879bc4
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import com.nextcloud.client.account.UserAccountManager
import com.nextcloud.client.core.Clock
import com.nextcloud.client.preferences.AppPreferences
import com.nextcloud.client.preferences.AppPreferencesImpl
import com.nextcloud.utils.BuildHelper
import com.owncloud.android.BuildConfig
import com.owncloud.android.MainApp
import com.owncloud.android.R
import com.owncloud.android.datamodel.ArbitraryDataProvider
Expand All @@ -41,6 +43,7 @@ import com.owncloud.android.datamodel.MediaFoldersModel
import com.owncloud.android.datamodel.MediaProvider
import com.owncloud.android.datamodel.SyncedFolderProvider
import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.ui.activity.FileDisplayActivity
import com.owncloud.android.ui.activity.ManageAccountsActivity.PENDING_FOR_REMOVAL
import com.owncloud.android.ui.activity.SyncedFoldersActivity
import com.owncloud.android.ui.notifications.NotificationUtils
Expand Down Expand Up @@ -75,6 +78,7 @@ class MediaFoldersDetectionWork constructor(

@Suppress("LongMethod", "ComplexMethod", "NestedBlockDepth") // legacy code
override fun doWork(): Result {

val arbitraryDataProvider: ArbitraryDataProvider = ArbitraryDataProviderImpl(context)
val gson = Gson()
val mediaFoldersModel: MediaFoldersModel
Expand Down Expand Up @@ -190,8 +194,47 @@ class MediaFoldersDetectionWork constructor(
gson.toJson(mediaFoldersModel)
)
}

// only send notification when synced folder is setup, gplay flavor and not branded client
if (syncedFolderProvider.syncedFolders.isNotEmpty() &&
BuildHelper.GPLAY == BuildConfig.FLAVOR &&
!preferences.isAutoUploadGPlayNotificationShown &&
!MainApp.isClientBranded()) {
sendAutoUploadNotification()
}

return Result.success()
}

private fun sendAutoUploadNotification() {
val notificationId = randomIdGenerator.nextInt()
val intent = Intent(context, FileDisplayActivity::class.java).apply {
setAction(FileDisplayActivity.AUTO_UPLOAD_NOTIFICATION)
}
val pendingIntent = PendingIntent.getActivity(
context,
0,
intent,
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
)

val notificationBuilder = NotificationCompat.Builder(
context,
NotificationUtils.NOTIFICATION_CHANNEL_GENERAL
)
.setSmallIcon(R.drawable.notification_icon)
.setLargeIcon(BitmapFactory.decodeResource(context.resources, R.drawable.notification_icon))
.setContentTitle("Re-enable Disrupted Auto Uploads")
.setContentText("Click to learn how to re-enable auto uploads")
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setAutoCancel(true)
.setContentIntent(pendingIntent)

viewThemeUtils.androidx.themeNotificationCompatBuilder(context, notificationBuilder)

val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(notificationId, notificationBuilder.build())
}

@Suppress("LongMethod")
private fun sendNotification(contentTitle: String, subtitle: String, user: User, path: String, type: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,7 @@ default void onDarkThemeModeChanged(DarkMode mode) {

boolean isAutoUploadGPlayWarning2Shown();
void setAutoUploadGPlayWarning2Shown(boolean value);

boolean isAutoUploadGPlayNotificationShown();
void setAutoUploadGPlayNotificationShown(boolean value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public final class AppPreferencesImpl implements AppPreferences {

private static final String PREF__AUTO_UPLOAD_GPLAY_WARNING_SHOWN = "auto_upload_gplay_warning_shown";
private static final String PREF__AUTO_UPLOAD_GPLAY_WARNING2_SHOWN = "auto_upload_gplay_warning2_shown";
private static final String PREF__AUTO_UPLOAD_GPLAY_NOTIFICATION_SHOWN = "auto_upload_gplay_notification_shown";

private static final String LOG_ENTRY = "log_entry";

Expand Down Expand Up @@ -848,4 +849,14 @@ public boolean isAutoUploadGPlayWarning2Shown() {
public void setAutoUploadGPlayWarning2Shown(boolean value) {
preferences.edit().putBoolean(PREF__AUTO_UPLOAD_GPLAY_WARNING2_SHOWN, value).apply();
}

@Override
public boolean isAutoUploadGPlayNotificationShown() {
return preferences.getBoolean(PREF__AUTO_UPLOAD_GPLAY_NOTIFICATION_SHOWN, false);
}

@Override
public void setAutoUploadGPlayNotificationShown(boolean value) {
preferences.edit().putBoolean(PREF__AUTO_UPLOAD_GPLAY_NOTIFICATION_SHOWN, value).apply();
}
}
6 changes: 5 additions & 1 deletion app/src/main/java/com/owncloud/android/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,13 @@ private void setProxyForNonBrandedPlusClients() {
Log_OC.d(TAG, "Error caught at setProxyForNonBrandedPlusClients: " + e);
}
}

public static boolean isClientBranded() {
return getAppContext().getResources().getBoolean(R.bool.is_branded_client);
}

public static boolean isClientBrandedPlus() {
return (getAppContext().getResources().getBoolean(R.bool.is_branded_plus_client));
return getAppContext().getResources().getBoolean(R.bool.is_branded_plus_client);
}

private final IntentFilter restrictionsFilter = new IntentFilter(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public class FileDisplayActivity extends FileActivity
public static final String RESTART = "RESTART";
public static final String ALL_FILES = "ALL_FILES";
public static final String LIST_GROUPFOLDERS = "LIST_GROUPFOLDERS";
public static final String AUTO_UPLOAD_NOTIFICATION = "AUTO_UPLOAD_NOTIFICATION";
public static final int SINGLE_USER_SIZE = 1;
public static final String OPEN_FILE = "NC_OPEN_FILE";
public static final String FOLDER_SYNC_CONFLICT = "FOLDER_SYNC_CONFLICT";
Expand Down Expand Up @@ -295,7 +296,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

private void checkAutoUploadOnGPlay() {
if (!BuildHelper.GPLAY.equals(BuildConfig.FLAVOR)) {
if (!BuildHelper.GPLAY.equals(BuildConfig.FLAVOR) || MainApp.isClientBranded()) {
return;
}

Expand Down Expand Up @@ -338,7 +339,7 @@ private void checkAutoUploadOnGPlay() {
}

private void checkAutoUploadOnGPlay2() {
if (!BuildHelper.GPLAY.equals(BuildConfig.FLAVOR)) {
if (!BuildHelper.GPLAY.equals(BuildConfig.FLAVOR) || MainApp.isClientBranded()) {
return;
}

Expand All @@ -363,6 +364,7 @@ private void checkAutoUploadOnGPlay2() {
.setMessage(R.string.auto_upload_gplay_desc2)
.setNegativeButton(R.string.dialog_close, (dialog, which) -> {
dialog.dismiss();
preferences.setAutoUploadGPlayWarning2Shown(true);
})
.setIcon(R.drawable.nav_synced_folders)
.create()
Expand All @@ -375,6 +377,7 @@ private void checkAutoUploadOnGPlay2() {
.setMessage(R.string.upload_gplay_desc)
.setNegativeButton(R.string.dialog_close, (dialog, which) -> {
dialog.dismiss();
preferences.setAutoUploadGPlayWarning2Shown(true);
})
.setIcon(R.drawable.nav_synced_folders)
.create()
Expand All @@ -385,7 +388,7 @@ private void checkAutoUploadOnGPlay2() {
PermissionUtil.requestMediaLocationPermission(this);
PermissionUtil.requestExternalStoragePermission(this, viewThemeUtils, true);

preferences.setAutoUploadGPlayWarning2Shown(false);

}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -688,6 +691,17 @@ protected void onNewIntent(Intent intent) {
DrawerActivity.menuItemId = R.id.nav_groupfolders;
setLeftFragment(new GroupfolderListFragment());
getSupportFragmentManager().executePendingTransactions();
} else if (AUTO_UPLOAD_NOTIFICATION.equals(intent.getAction())) {
new MaterialAlertDialogBuilder(this, R.style.Theme_ownCloud_Dialog)
.setTitle(R.string.re_enable_auto_upload)
.setMessage(R.string.re_enable_auto_upload_desc)
.setNegativeButton(R.string.dialog_close, (dialog, which) -> {
dialog.dismiss();
preferences.setAutoUploadGPlayNotificationShown(true);
})
.setIcon(R.drawable.nav_synced_folders)
.create()
.show();
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1299,4 +1299,6 @@
<string name="auto_upload_gplay_desc2">Google restricted our app and removed an important permission.\nThus auto upload can only access images and videos, but no other file formats.\nFurthermore \"access location\" is required for persisting GPS information in images.\nPlease also double check that "all access" is granted for photo and video access.</string>
<string name="upload_gplay">Upload needs more permissions</string>
<string name="upload_gplay_desc">A new permission \"access location\" is required for persisting GPS information in images.\nPlease also double check that \"all access\" is granted for photo and video access.</string>
<string name="re_enable_auto_upload">Re-enable disrupted Auto Uploads</string>
<string name="re_enable_auto_upload_desc">Please check manually for missing file uploads since mid-December.\nTo re-enable Auto Uploads for new photos and videos:\n- Grant \"Photos and Videos\" permission in the next dialog,\n- Grant \"Location\" permission to keep location data in uploaded photos.\n\nTo re-enable Auto Uploads for all other files:\n- Auto Uploads of other files are not possible anymore with the Play Store version of the Nextcloud app.\n\nAuto Uploads stopped working because Google rejected the necessary file permission in a previous app update. Nextcloud is working with Google to rectify the situation and restore full functionality.</string>
</resources>

0 comments on commit 7879bc4

Please sign in to comment.