mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 17:46:37 +03:00
Add automated configuration opener
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
1f8d5dddfe
commit
7d2d6465f6
2 changed files with 93 additions and 68 deletions
|
@ -52,6 +52,9 @@ import java.util.List;
|
|||
public class MediaFoldersDetectionJob extends Job {
|
||||
public static final String TAG = "MediaFoldersDetectionJob";
|
||||
|
||||
public static final String KEY_MEDIA_FOLDER_PATH = "KEY_MEDIA_FOLDER_PATH";
|
||||
public static final String KEY_MEDIA_FOLDER_TYPE = "KEY_MEDIA_FOLDER_TYPE";
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected Result onRunJob(@NonNull Params params) {
|
||||
|
@ -107,9 +110,9 @@ public class MediaFoldersDetectionJob extends Job {
|
|||
String imageMediaFolder = imageMediaFolderPaths.get(i);
|
||||
sendNotification(String.format(context.getString(R.string.new_media_folder_detected),
|
||||
context.getString(R.string.new_media_folder_photos)),
|
||||
imageMediaFolder.substring(imageMediaFolder.lastIndexOf("/"),
|
||||
imageMediaFolder.substring(imageMediaFolder.lastIndexOf("/") + 1,
|
||||
imageMediaFolder.length()),
|
||||
account);
|
||||
account, imageMediaFolder, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,7 +124,7 @@ public class MediaFoldersDetectionJob extends Job {
|
|||
context.getString(R.string.new_media_folder_photos)),
|
||||
videoMediaFolder.substring(videoMediaFolder.lastIndexOf("/") + 1,
|
||||
videoMediaFolder.length()),
|
||||
account);
|
||||
account, videoMediaFolder, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -136,11 +139,14 @@ public class MediaFoldersDetectionJob extends Job {
|
|||
return Result.SUCCESS;
|
||||
}
|
||||
|
||||
private void sendNotification(String contentTitle, String subtitle, Account account) {
|
||||
private void sendNotification(String contentTitle, String subtitle, Account account,
|
||||
String path, int type) {
|
||||
Context context = getContext();
|
||||
Intent intent = new Intent(getContext(), SyncedFoldersActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
intent.putExtra(NotificationJob.KEY_NOTIFICATION_ACCOUNT, account.name);
|
||||
intent.putExtra(KEY_MEDIA_FOLDER_PATH, path);
|
||||
intent.putExtra(KEY_MEDIA_FOLDER_TYPE, type);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);
|
||||
|
||||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
|
||||
|
|
|
@ -37,6 +37,7 @@ import android.support.v4.widget.DrawerLayout;
|
|||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
@ -56,6 +57,7 @@ import com.owncloud.android.datamodel.SyncedFolder;
|
|||
import com.owncloud.android.datamodel.SyncedFolderDisplayItem;
|
||||
import com.owncloud.android.datamodel.SyncedFolderProvider;
|
||||
import com.owncloud.android.files.services.FileUploader;
|
||||
import com.owncloud.android.jobs.MediaFoldersDetectionJob;
|
||||
import com.owncloud.android.jobs.NotificationJob;
|
||||
import com.owncloud.android.ui.adapter.SyncedFolderAdapter;
|
||||
import com.owncloud.android.ui.decoration.MediaGridItemDecoration;
|
||||
|
@ -86,10 +88,9 @@ import static com.owncloud.android.datamodel.SyncedFolderDisplayItem.UNPERSISTED
|
|||
public class SyncedFoldersActivity extends FileActivity implements SyncedFolderAdapter.ClickListener,
|
||||
SyncedFolderPreferencesDialogFragment.OnSyncedFolderPreferenceListener {
|
||||
|
||||
private static final String SYNCED_FOLDER_PREFERENCES_DIALOG_TAG = "SYNCED_FOLDER_PREFERENCES_DIALOG";
|
||||
public static final String[] PRIORITIZED_FOLDERS = new String[] { "Camera", "Screenshots" };
|
||||
public static final String[] PRIORITIZED_FOLDERS = new String[]{"Camera", "Screenshots"};
|
||||
public static final String EXTRA_SHOW_SIDEBAR = "SHOW_SIDEBAR";
|
||||
|
||||
private static final String SYNCED_FOLDER_PREFERENCES_DIALOG_TAG = "SYNCED_FOLDER_PREFERENCES_DIALOG";
|
||||
private static final String TAG = SyncedFoldersActivity.class.getSimpleName();
|
||||
|
||||
private RecyclerView mRecyclerView;
|
||||
|
@ -101,6 +102,56 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
|||
private boolean showSidebar = true;
|
||||
private RelativeLayout mCustomFolderRelativeLayout;
|
||||
|
||||
private String path;
|
||||
private int type;
|
||||
/**
|
||||
* Sorts list of {@link SyncedFolderDisplayItem}s.
|
||||
*
|
||||
* @param syncFolderItemList list of items to be sorted
|
||||
* @return sorted list of items
|
||||
*/
|
||||
public static List<SyncedFolderDisplayItem> sortSyncedFolderItems(List<SyncedFolderDisplayItem>
|
||||
syncFolderItemList) {
|
||||
Collections.sort(syncFolderItemList, new Comparator<SyncedFolderDisplayItem>() {
|
||||
public int compare(SyncedFolderDisplayItem f1, SyncedFolderDisplayItem f2) {
|
||||
if (f1 == null && f2 == null) {
|
||||
return 0;
|
||||
} else if (f1 == null) {
|
||||
return -1;
|
||||
} else if (f2 == null) {
|
||||
return 1;
|
||||
} else if (f1.isEnabled() && f2.isEnabled()) {
|
||||
return f1.getFolderName().toLowerCase(Locale.getDefault()).compareTo(
|
||||
f2.getFolderName().toLowerCase(Locale.getDefault()));
|
||||
} else if (f1.isEnabled()) {
|
||||
return -1;
|
||||
} else if (f2.isEnabled()) {
|
||||
return 1;
|
||||
} else if (f1.getFolderName() == null && f2.getFolderName() == null) {
|
||||
return 0;
|
||||
} else if (f1.getFolderName() == null) {
|
||||
return -1;
|
||||
} else if (f2.getFolderName() == null) {
|
||||
return 1;
|
||||
}
|
||||
for (String folder : PRIORITIZED_FOLDERS) {
|
||||
if (folder.equals(f1.getFolderName()) &&
|
||||
folder.equals(f2.getFolderName())) {
|
||||
return 0;
|
||||
} else if (folder.equals(f1.getFolderName())) {
|
||||
return -1;
|
||||
} else if (folder.equals(f2.getFolderName())) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return f1.getFolderName().toLowerCase(Locale.getDefault()).compareTo(
|
||||
f2.getFolderName().toLowerCase(Locale.getDefault()));
|
||||
}
|
||||
});
|
||||
|
||||
return syncFolderItemList;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -113,13 +164,18 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
|||
|
||||
String account;
|
||||
Account currentAccount;
|
||||
if (getIntent() != null && getIntent().getExtras() != null &&
|
||||
(account = getIntent().getExtras().getString(NotificationJob.KEY_NOTIFICATION_ACCOUNT)) != null &&
|
||||
(currentAccount = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext())) != null &&
|
||||
!account.equalsIgnoreCase(currentAccount.name)) {
|
||||
AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), account);
|
||||
setAccount(AccountUtils.getCurrentOwnCloudAccount(this));
|
||||
if (getIntent() != null && getIntent().getExtras() != null) {
|
||||
if ((account = getIntent().getExtras().getString(NotificationJob.KEY_NOTIFICATION_ACCOUNT)) != null &&
|
||||
(currentAccount = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext())) != null &&
|
||||
!account.equalsIgnoreCase(currentAccount.name)) {
|
||||
AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), account);
|
||||
setAccount(AccountUtils.getCurrentOwnCloudAccount(this));
|
||||
}
|
||||
|
||||
path = getIntent().getStringExtra(MediaFoldersDetectionJob.KEY_MEDIA_FOLDER_PATH);
|
||||
type = getIntent().getIntExtra(MediaFoldersDetectionJob.KEY_MEDIA_FOLDER_TYPE, -1);
|
||||
}
|
||||
|
||||
// setup toolbar
|
||||
setupToolbar();
|
||||
CollapsingToolbarLayout mCollapsingToolbarLayout = findViewById(R.id.collapsing_toolbar);
|
||||
|
@ -228,6 +284,17 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
|||
mAdapter.setSyncFolderItems(syncFolderItems);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
setListShown(true);
|
||||
|
||||
if (!TextUtils.isEmpty(path)) {
|
||||
for (int i = 0; i < syncFolderItems.size(); i++) {
|
||||
SyncedFolderDisplayItem syncedFolderDisplayItem = syncFolderItems.get(i);
|
||||
if (syncedFolderDisplayItem.getLocalPath().equalsIgnoreCase(path) &&
|
||||
syncedFolderDisplayItem.getType().getId().equals(type)) {
|
||||
mRecyclerView.getLayoutManager().scrollToPosition(i);
|
||||
onSyncFolderSettingsClick(1, syncedFolderDisplayItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -244,9 +311,9 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
|||
List<SyncedFolderDisplayItem> result = new ArrayList<>();
|
||||
|
||||
for (MediaFolder mediaFolder : mediaFolders) {
|
||||
if (syncedFoldersMap.containsKey(mediaFolder.absolutePath+"-"+mediaFolder.type)) {
|
||||
SyncedFolder syncedFolder = syncedFoldersMap.get(mediaFolder.absolutePath+"-"+mediaFolder.type);
|
||||
syncedFoldersMap.remove(mediaFolder.absolutePath+"-"+mediaFolder.type);
|
||||
if (syncedFoldersMap.containsKey(mediaFolder.absolutePath + "-" + mediaFolder.type)) {
|
||||
SyncedFolder syncedFolder = syncedFoldersMap.get(mediaFolder.absolutePath + "-" + mediaFolder.type);
|
||||
syncedFoldersMap.remove(mediaFolder.absolutePath + "-" + mediaFolder.type);
|
||||
|
||||
if (MediaFolderType.CUSTOM == syncedFolder.getType()) {
|
||||
result.add(createSyncedFolderWithoutMediaFolder(syncedFolder));
|
||||
|
@ -265,54 +332,6 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts list of {@link SyncedFolderDisplayItem}s.
|
||||
*
|
||||
* @param syncFolderItemList list of items to be sorted
|
||||
* @return sorted list of items
|
||||
*/
|
||||
public static List<SyncedFolderDisplayItem> sortSyncedFolderItems(List<SyncedFolderDisplayItem>
|
||||
syncFolderItemList) {
|
||||
Collections.sort(syncFolderItemList, new Comparator<SyncedFolderDisplayItem>() {
|
||||
public int compare(SyncedFolderDisplayItem f1, SyncedFolderDisplayItem f2) {
|
||||
if (f1 == null && f2 == null) {
|
||||
return 0;
|
||||
} else if (f1 == null) {
|
||||
return -1;
|
||||
} else if (f2 == null) {
|
||||
return 1;
|
||||
} else if (f1.isEnabled() && f2.isEnabled()) {
|
||||
return f1.getFolderName().toLowerCase(Locale.getDefault()).compareTo(
|
||||
f2.getFolderName().toLowerCase(Locale.getDefault()));
|
||||
} else if (f1.isEnabled()) {
|
||||
return -1;
|
||||
} else if (f2.isEnabled()) {
|
||||
return 1;
|
||||
} else if (f1.getFolderName() == null && f2.getFolderName() == null) {
|
||||
return 0;
|
||||
} else if (f1.getFolderName() == null) {
|
||||
return -1;
|
||||
} else if (f2.getFolderName() == null) {
|
||||
return 1;
|
||||
}
|
||||
for (String folder : PRIORITIZED_FOLDERS) {
|
||||
if (folder.equals(f1.getFolderName()) &&
|
||||
folder.equals(f2.getFolderName())) {
|
||||
return 0;
|
||||
} else if (folder.equals(f1.getFolderName())) {
|
||||
return -1;
|
||||
} else if (folder.equals(f2.getFolderName())) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return f1.getFolderName().toLowerCase(Locale.getDefault()).compareTo(
|
||||
f2.getFolderName().toLowerCase(Locale.getDefault()));
|
||||
}
|
||||
});
|
||||
|
||||
return syncFolderItemList;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private SyncedFolderDisplayItem createSyncedFolderWithoutMediaFolder(@NonNull SyncedFolder syncedFolder) {
|
||||
|
||||
|
@ -430,7 +449,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
|||
Map<String, SyncedFolder> result = new HashMap<>();
|
||||
if (syncFolders != null) {
|
||||
for (SyncedFolder syncFolder : syncFolders) {
|
||||
result.put(syncFolder.getLocalPath()+"-"+syncFolder.getType(), syncFolder);
|
||||
result.put(syncFolder.getLocalPath() + "-" + syncFolder.getType(), syncFolder);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -532,12 +551,12 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
|||
&& resultCode == RESULT_OK && mSyncedFolderPreferencesDialogFragment != null) {
|
||||
OCFile chosenFolder = data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER);
|
||||
mSyncedFolderPreferencesDialogFragment.setRemoteFolderSummary(chosenFolder.getRemotePath());
|
||||
} if (requestCode == SyncedFolderPreferencesDialogFragment.REQUEST_CODE__SELECT_LOCAL_FOLDER
|
||||
}
|
||||
if (requestCode == SyncedFolderPreferencesDialogFragment.REQUEST_CODE__SELECT_LOCAL_FOLDER
|
||||
&& resultCode == RESULT_OK && mSyncedFolderPreferencesDialogFragment != null) {
|
||||
String localPath = data.getStringExtra(UploadFilesActivity.EXTRA_CHOSEN_FILES);
|
||||
mSyncedFolderPreferencesDialogFragment.setLocalFolderSummary(localPath);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue