re-add button/action and improve upon code review

Signed-off-by: Andy Scherzinger <[email protected]>
This commit is contained in:
Andy Scherzinger committed 2019-11-27 21:43:53 +01:00
1 parent 74bfe473c4
commit d17c853493
6 files changed
+141 -79

No files matched your search

@@ -62,9 +62,17 @@ public class SyncedFolder implements Serializable, Cloneable {
* @param type the type of the folder
* @param hidden hide item flag
*/
public SyncedFolder(String localPath, String remotePath, boolean wifiOnly, boolean chargingOnly,
boolean subfolderByDate, String account, int uploadAction, boolean enabled,
long timestampMs, MediaFolderType type, boolean hidden) {
public SyncedFolder(String localPath,
String remotePath,
boolean wifiOnly,
boolean chargingOnly,
boolean subfolderByDate,
String account,
int uploadAction,
boolean enabled,
long timestampMs,
MediaFolderType type,
boolean hidden) {
this(UNPERSISTED_ID, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction,
enabled, timestampMs, type, hidden);
}
@@ -74,9 +82,18 @@ public class SyncedFolder implements Serializable, Cloneable {
*
* @param id id
*/
protected SyncedFolder(long id, String localPath, String remotePath, boolean wifiOnly, boolean chargingOnly,
boolean subfolderByDate, String account, int uploadAction, boolean enabled,
long timestampMs, MediaFolderType type, boolean hidden) {
protected SyncedFolder(long id,
String localPath,
String remotePath,
boolean wifiOnly,
boolean chargingOnly,
boolean subfolderByDate,
String account,
int uploadAction,
boolean enabled,
long timestampMs,
MediaFolderType type,
boolean hidden) {
this.id = id;
this.localPath = localPath;
this.remotePath = remotePath;
@@ -55,11 +55,21 @@ public class SyncedFolderDisplayItem extends SyncedFolder {
* @param type the type of the folder
* @param hidden hide item flag
*/
public SyncedFolderDisplayItem(long id, String localPath, String remotePath, boolean wifiOnly, boolean chargingOnly,
boolean subfolderByDate, String account, int uploadAction, boolean enabled,
long timestampMs, List<String> filePaths, String folderName, long numberOfFiles,
MediaFolderType type, boolean hidden)
{
public SyncedFolderDisplayItem(long id,
String localPath,
String remotePath,
boolean wifiOnly,
boolean chargingOnly,
boolean subfolderByDate,
String account,
int uploadAction,
boolean enabled,
long timestampMs,
List<String> filePaths,
String folderName,
long numberOfFiles,
MediaFolderType type,
boolean hidden) {
super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled,
timestampMs, type, hidden);
this.filePaths = filePaths;
@@ -67,9 +77,17 @@ public class SyncedFolderDisplayItem extends SyncedFolder {
this.numberOfFiles = numberOfFiles;
}
public SyncedFolderDisplayItem(long id, String localPath, String remotePath, boolean wifiOnly, boolean chargingOnly,
boolean subfolderByDate, String account, int uploadAction, boolean enabled,
long timestampMs, String folderName, MediaFolderType type, boolean hidden) {
public SyncedFolderDisplayItem(long id,
String localPath,
String remotePath,
boolean wifiOnly,
boolean chargingOnly,
boolean subfolderByDate,
String account,
int uploadAction,
boolean enabled,
long timestampMs,
String folderName, MediaFolderType type, boolean hidden) {
super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled,
timestampMs, type, hidden);
this.folderName = folderName;
@@ -2076,12 +2076,6 @@ public class FileContentProvider extends ContentProvider {
db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
REMOVE_COLUMN + ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION);
}
if(oldVersion == 50 && newVersion < 50) {
db.execSQL(ALTER_TABLE + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
REMOVE_COLUMN + ProviderTableMeta.SYNCED_FOLDER_HIDDEN);
}
}
}
}
@@ -21,7 +21,6 @@
package com.owncloud.android.ui.activity;
import android.accounts.Account;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.NotificationManager;
@@ -43,6 +42,7 @@ import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.google.android.material.button.MaterialButton;
import com.nextcloud.client.account.User;
import com.nextcloud.client.core.Clock;
import com.nextcloud.client.device.PowerManagementService;
@@ -124,12 +124,15 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
@BindView(R.id.empty_list_view_text)
public TextView emptyContentMessage;
@BindView(R.id.empty_list_view_action)
public MaterialButton emptyContentActionButton;
@BindView(android.R.id.list)
public RecyclerView mRecyclerView;
private SyncedFolderAdapter mAdapter;
private SyncedFolderProvider mSyncedFolderProvider;
private SyncedFolderPreferencesDialogFragment mSyncedFolderPreferencesDialogFragment;
private SyncedFolderAdapter adapter;
private SyncedFolderProvider syncedFolderProvider;
private SyncedFolderPreferencesDialogFragment syncedFolderPreferencesDialogFragment;
private boolean showSidebar = true;
private String path;
@@ -243,24 +246,26 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
private void setupContent() {
final int gridWidth = getResources().getInteger(R.integer.media_grid_width);
boolean lightVersion = getResources().getBoolean(R.bool.syncedFolder_light);
mAdapter = new SyncedFolderAdapter(this, clock, gridWidth, this, lightVersion);
mSyncedFolderProvider = new SyncedFolderProvider(getContentResolver(), preferences, clock);
adapter = new SyncedFolderAdapter(this, clock, gridWidth, this, lightVersion);
syncedFolderProvider = new SyncedFolderProvider(getContentResolver(), preferences, clock);
emptyContentIcon.setImageResource(R.drawable.nav_synced_folders);
emptyContentActionButton.setBackgroundColor(ThemeUtils.primaryColor(this));
emptyContentActionButton.setTextColor(ThemeUtils.fontColor(this));
final GridLayoutManager lm = new GridLayoutManager(this, gridWidth);
mAdapter.setLayoutManager(lm);
adapter.setLayoutManager(lm);
int spacing = getResources().getDimensionPixelSize(R.dimen.media_grid_spacing);
mRecyclerView.addItemDecoration(new MediaGridItemDecoration(spacing));
mRecyclerView.setLayoutManager(lm);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setAdapter(adapter);
load(gridWidth * 2, false);
}
@OnClick(R.id.empty_list_view_text)
@OnClick(R.id.empty_list_view_action)
public void showHiddenItems() {
if (mAdapter.getSectionCount() == 0 && mAdapter.getUnfilteredSectionCount() > mAdapter.getSectionCount()) {
mAdapter.toggleHiddenItemsVisibility();
if (adapter.getSectionCount() == 0 && adapter.getUnfilteredSectionCount() > adapter.getSectionCount()) {
adapter.toggleHiddenItemsVisibility();
emptyContentContainer.setVisibility(View.GONE);
mRecyclerView.setVisibility(View.VISIBLE);
}
@@ -272,7 +277,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
* @param perFolderMediaItemLimit the amount of media items to be loaded/shown per media folder
*/
private void load(final int perFolderMediaItemLimit, boolean force) {
if (mAdapter.getItemCount() > 0 && !force) {
if (adapter.getItemCount() > 0 && !force) {
return;
}
showLoadingContent();
@@ -281,14 +286,14 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
mediaFolders.addAll(MediaProvider.getVideoFolders(getContentResolver(), perFolderMediaItemLimit,
this, false));
List<SyncedFolder> syncedFolderArrayList = mSyncedFolderProvider.getSyncedFolders();
List<SyncedFolder> syncedFolderArrayList = syncedFolderProvider.getSyncedFolders();
List<SyncedFolder> currentAccountSyncedFoldersList = new ArrayList<>();
User user = getUserAccountManager().getUser();
for (SyncedFolder syncedFolder : syncedFolderArrayList) {
if (syncedFolder.getAccount().equals(user.getAccountName())) {
// delete non-existing & disabled synced folders
if (!new File(syncedFolder.getLocalPath()).exists() && !syncedFolder.isEnabled()) {
mSyncedFolderProvider.deleteSyncedFolder(syncedFolder.getId());
syncedFolderProvider.deleteSyncedFolder(syncedFolder.getId());
} else {
currentAccountSyncedFoldersList.add(syncedFolder);
}
@@ -298,14 +303,14 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
List<SyncedFolderDisplayItem> syncFolderItems = sortSyncedFolderItems(
mergeFolderData(currentAccountSyncedFoldersList, mediaFolders));
mAdapter.setSyncFolderItems(syncFolderItems);
mAdapter.notifyDataSetChanged();
adapter.setSyncFolderItems(syncFolderItems);
adapter.notifyDataSetChanged();
showList();
if (!TextUtils.isEmpty(path)) {
int section = mAdapter.getSectionByLocalPathAndType(path, type);
int section = adapter.getSectionByLocalPathAndType(path, type);
if (section >= 0) {
onSyncFolderSettingsClick(section, mAdapter.get(section));
onSyncFolderSettingsClick(section, adapter.get(section));
}
}
}
@@ -523,24 +528,31 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
*/
private void showList() {
if (mRecyclerView != null) {
mRecyclerView.setVisibility(View.VISIBLE );
mRecyclerView.setVisibility(View.VISIBLE);
emptyContentProgressBar.setVisibility(View.GONE);
if (mAdapter.getSectionCount() == 0 && mAdapter.getUnfilteredSectionCount() > mAdapter.getSectionCount()) {
emptyContentContainer.setVisibility(View.VISIBLE);
int hiddenFoldersCount = mAdapter.getHiddenFolderCount();
checkAndShowEmptyListContent();
}
}
showEmptyContent(getString(R.string.drawer_synced_folders),
getResources().getQuantityString(R.plurals.synced_folders_show_hidden_folders,
hiddenFoldersCount,
hiddenFoldersCount));
} else if (mAdapter.getSectionCount() == 0 && mAdapter.getUnfilteredSectionCount() == 0) {
emptyContentContainer.setVisibility(View.VISIBLE);
showEmptyContent(getString(R.string.drawer_synced_folders),
getString(R.string.synced_folders_no_results));
} else {
emptyContentContainer.setVisibility(View.GONE);
}
private void checkAndShowEmptyListContent() {
if (adapter.getSectionCount() == 0 && adapter.getUnfilteredSectionCount() > adapter.getSectionCount()) {
emptyContentContainer.setVisibility(View.VISIBLE);
int hiddenFoldersCount = adapter.getHiddenFolderCount();
showEmptyContent(getString(R.string.drawer_synced_folders),
getResources().getQuantityString(R.plurals.synced_folders_show_hidden_folders,
hiddenFoldersCount,
hiddenFoldersCount),
getResources().getQuantityString(R.plurals.synced_folders_show_hidden_folders,
hiddenFoldersCount,
hiddenFoldersCount));
} else if (adapter.getSectionCount() == 0 && adapter.getUnfilteredSectionCount() == 0) {
emptyContentContainer.setVisibility(View.VISIBLE);
showEmptyContent(getString(R.string.drawer_synced_folders),
getString(R.string.synced_folders_no_results));
} else {
emptyContentContainer.setVisibility(View.GONE);
}
}
@@ -597,10 +609,10 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
@Override
public void onSyncStatusToggleClick(int section, SyncedFolderDisplayItem syncedFolderDisplayItem) {
if (syncedFolderDisplayItem.getId() > UNPERSISTED_ID) {
mSyncedFolderProvider.updateSyncedFolderEnabled(syncedFolderDisplayItem.getId(),
syncedFolderDisplayItem.isEnabled());
syncedFolderProvider.updateSyncedFolderEnabled(syncedFolderDisplayItem.getId(),
syncedFolderDisplayItem.isEnabled());
} else {
long storedId = mSyncedFolderProvider.storeSyncedFolder(syncedFolderDisplayItem);
long storedId = syncedFolderProvider.storeSyncedFolder(syncedFolderDisplayItem);
if (storedId != -1) {
syncedFolderDisplayItem.setId(storedId);
}
@@ -619,9 +631,9 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
FragmentTransaction ft = fm.beginTransaction();
ft.addToBackStack(null);
mSyncedFolderPreferencesDialogFragment = SyncedFolderPreferencesDialogFragment.newInstance(
syncedFolderPreferencesDialogFragment = SyncedFolderPreferencesDialogFragment.newInstance(
syncedFolderDisplayItem, section);
mSyncedFolderPreferencesDialogFragment.show(ft, SYNCED_FOLDER_PREFERENCES_DIALOG_TAG);
syncedFolderPreferencesDialogFragment.show(ft, SYNCED_FOLDER_PREFERENCES_DIALOG_TAG);
}
@Override
@@ -629,11 +641,21 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
syncedFolder.setHidden(!syncedFolder.isHidden());
saveOrUpdateSyncedFolder(syncedFolder);
mAdapter.setSyncFolderItem(section, syncedFolder);
adapter.setSyncFolderItem(section, syncedFolder);
checkAndShowEmptyListContent();
}
private void showEmptyContent(String headline, String message) {
showEmptyContent(headline, message, false);
emptyContentActionButton.setVisibility(View.GONE);
}
private void showEmptyContent(String headline, String message, String action) {
showEmptyContent(headline, message, false);
emptyContentActionButton.setText(action);
emptyContentActionButton.setVisibility(View.VISIBLE);
emptyContentMessage.setVisibility(View.GONE);
}
private void showLoadingContent() {
@@ -642,6 +664,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
getString(R.string.synced_folders_loading_folders),
true
);
emptyContentActionButton.setVisibility(View.GONE);
}
private void showEmptyContent(String headline, String message, boolean loading) {
@@ -666,14 +689,14 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == SyncedFolderPreferencesDialogFragment.REQUEST_CODE__SELECT_REMOTE_FOLDER
&& resultCode == RESULT_OK && mSyncedFolderPreferencesDialogFragment != null) {
&& resultCode == RESULT_OK && syncedFolderPreferencesDialogFragment != null) {
OCFile chosenFolder = data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER);
mSyncedFolderPreferencesDialogFragment.setRemoteFolderSummary(chosenFolder.getRemotePath());
syncedFolderPreferencesDialogFragment.setRemoteFolderSummary(chosenFolder.getRemotePath());
}
if (requestCode == SyncedFolderPreferencesDialogFragment.REQUEST_CODE__SELECT_LOCAL_FOLDER
&& resultCode == RESULT_OK && mSyncedFolderPreferencesDialogFragment != null) {
&& resultCode == RESULT_OK && syncedFolderPreferencesDialogFragment != null) {
String localPath = data.getStringExtra(UploadFilesActivity.EXTRA_CHOSEN_FILES);
mSyncedFolderPreferencesDialogFragment.setLocalFolderSummary(localPath);
syncedFolderPreferencesDialogFragment.setLocalFolderSummary(localPath);
} else {
super.onActivityResult(requestCode, resultCode, data);
}
@@ -691,9 +714,9 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
clock.getCurrentTime(), new File(syncedFolder.getLocalPath()).getName(), syncedFolder.getType(), syncedFolder.isHidden());
saveOrUpdateSyncedFolder(newCustomFolder);
mAdapter.addSyncFolderItem(newCustomFolder);
adapter.addSyncFolderItem(newCustomFolder);
} else {
SyncedFolderDisplayItem item = mAdapter.get(syncedFolder.getSection());
SyncedFolderDisplayItem item = adapter.get(syncedFolder.getSection());
updateSyncedFolderItem(item, syncedFolder.getId(), syncedFolder.getLocalPath(),
syncedFolder.getRemotePath(), syncedFolder
.isWifiOnly(), syncedFolder.isChargingOnly(), syncedFolder.isSubfolderByDate(), syncedFolder
@@ -702,10 +725,10 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
saveOrUpdateSyncedFolder(item);
// TODO test if notifiyItemChanged is suffiecient (should improve performance)
mAdapter.notifyDataSetChanged();
adapter.notifyDataSetChanged();
}
mSyncedFolderPreferencesDialogFragment = null;
syncedFolderPreferencesDialogFragment = null;
if (syncedFolder.isEnabled()) {
showBatteryOptimizationInfo();
@@ -718,7 +741,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
storeSyncedFolder(item);
} else {
// existing synced folder setup to be updated
mSyncedFolderProvider.updateSyncFolder(item);
syncedFolderProvider.updateSyncFolder(item);
if (item.isEnabled()) {
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(item);
} else {
@@ -734,7 +757,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
private void storeSyncedFolder(SyncedFolderDisplayItem item) {
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext().
getContentResolver());
long storedId = mSyncedFolderProvider.storeSyncedFolder(item);
long storedId = syncedFolderProvider.storeSyncedFolder(item);
if (storedId != -1) {
item.setId(storedId);
if (item.isEnabled()) {
@@ -748,13 +771,13 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
@Override
public void onCancelSyncedFolderPreference() {
mSyncedFolderPreferencesDialogFragment = null;
syncedFolderPreferencesDialogFragment = null;
}
@Override
public void onDeleteSyncedFolderPreference(SyncedFolderParcelable syncedFolder) {
mSyncedFolderProvider.deleteSyncedFolder(syncedFolder.getId());
mAdapter.removeItem(syncedFolder.getSection());
syncedFolderProvider.deleteSyncedFolder(syncedFolder.getId());
adapter.removeItem(syncedFolder.getSection());
}
/**
@@ -83,7 +83,7 @@ public class SyncedFolderAdapter extends SectionedRecyclerViewAdapter<SectionedV
shouldShowFooters(true);
}
private void toggleHiddenItemsVisibility() {
public void toggleHiddenItemsVisibility() {
hideItems = !hideItems;
filteredSyncFolderItems.clear();
filteredSyncFolderItems.addAll(filterHiddenItems(syncFolderItems, hideItems));
@@ -99,7 +99,6 @@ public class SyncedFolderAdapter extends SectionedRecyclerViewAdapter<SectionedV
}
public void setSyncFolderItem(int location, SyncedFolderDisplayItem syncFolderItem) {
// show all items OR
if (hideItems && syncFolderItem.isHidden() && filteredSyncFolderItems.contains(syncFolderItem)) {
filteredSyncFolderItems.remove(location);
} else {
@@ -123,7 +122,7 @@ public class SyncedFolderAdapter extends SectionedRecyclerViewAdapter<SectionedV
syncFolderItems.add(syncFolderItem);
// add item for display when either all items should be shown (!hideItems)
// or if items should be hi
// or if item should be shown (!.isHidden())
if (!hideItems || !syncFolderItem.isHidden()) {
filteredSyncFolderItems.add(syncFolderItem);
notifyDataSetChanged();
@@ -148,15 +147,15 @@ public class SyncedFolderAdapter extends SectionedRecyclerViewAdapter<SectionedV
if (!hide) {
return items;
} else {
List<SyncedFolderDisplayItem> ret = new ArrayList<>();
List<SyncedFolderDisplayItem> result = new ArrayList<>();
for (SyncedFolderDisplayItem item : items) {
if (!item.isHidden() && !ret.contains(item)) {
ret.add(item);
if (!item.isHidden() && !result.contains(item)) {
result.add(item);
}
}
return ret;
return result;
}
}
+11
View File
@@ -19,6 +19,7 @@
License along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/empty_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -63,7 +64,17 @@
android:ellipsize="end"
android:gravity="center"
android:paddingTop="@dimen/standard_half_padding"
android:paddingBottom="@dimen/standard_half_padding"
android:text="@string/file_list_empty"
android:visibility="gone"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/empty_list_view_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/Button.Primary"
app:cornerRadius="@dimen/button_corner_radius"
android:layout_marginTop="@dimen/standard_half_margin"
android:visibility="gone"/>
</LinearLayout>