FolderSyncActivity.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /**
  2. * Nextcloud Android client application
  3. *
  4. * @author Andy Scherzinger
  5. * Copyright (C) 2016 Andy Scherzinger
  6. * Copyright (C) 2016 Nextcloud
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. package com.owncloud.android.ui.activity;
  22. import android.app.Activity;
  23. import android.content.Intent;
  24. import android.os.Bundle;
  25. import android.os.Handler;
  26. import android.support.v7.widget.GridLayoutManager;
  27. import android.support.v7.widget.RecyclerView;
  28. import android.util.Log;
  29. import android.view.MenuItem;
  30. import android.view.View;
  31. import android.widget.ProgressBar;
  32. import android.widget.TextView;
  33. import com.owncloud.android.MainApp;
  34. import com.owncloud.android.R;
  35. import com.owncloud.android.datamodel.MediaFolder;
  36. import com.owncloud.android.datamodel.MediaProvider;
  37. import com.owncloud.android.ui.adapter.FolderSyncAdapter;
  38. import java.util.List;
  39. import java.util.TimerTask;
  40. /**
  41. * Activity displaying all auto-synced folders and/or instant upload media folders.
  42. */
  43. public class FolderSyncActivity extends DrawerActivity {
  44. private static final String TAG = FolderSyncActivity.class.getSimpleName();
  45. private RecyclerView mRecyclerView;
  46. private FolderSyncAdapter mAdapter;
  47. private ProgressBar mProgress;
  48. private TextView mEmpty;
  49. @Override
  50. protected void onCreate(Bundle savedInstanceState) {
  51. super.onCreate(savedInstanceState);
  52. setContentView(R.layout.folder_sync_layout);
  53. // setup toolbar
  54. setupToolbar();
  55. // setup drawer
  56. setupDrawer(R.id.nav_folder_sync);
  57. getSupportActionBar().setTitle(getString(R.string.drawer_folder_sync));
  58. setupContent();
  59. }
  60. private void setupContent() {
  61. // TODO setup/initialize UI
  62. mRecyclerView = (RecyclerView) findViewById(android.R.id.list);
  63. final int gridWidth = 4;
  64. mAdapter = new FolderSyncAdapter(this, gridWidth, new FolderSyncAdapter.ClickListener() {
  65. @Override
  66. public void onClick(View view, int section, int relative, int absolute) {
  67. selectItem(FolderSyncActivity.this);
  68. }
  69. }, mRecyclerView);
  70. final GridLayoutManager lm = new GridLayoutManager(this, gridWidth);
  71. mAdapter.setLayoutManager(lm);
  72. mRecyclerView.setLayoutManager(lm);
  73. mRecyclerView.setAdapter(mAdapter);
  74. load();
  75. }
  76. public static void selectItem(final Activity context) {
  77. // TODO implement selectItem()
  78. return;
  79. }
  80. private void load() {
  81. if (mAdapter.getItemCount() > 0) return;
  82. setListShown(false);
  83. final Handler mHandler = new Handler();
  84. new Thread(new Runnable() {
  85. @Override
  86. public void run() {
  87. final List<MediaFolder> mediaFolders = MediaProvider.getAllShownImagesPath(FolderSyncActivity.this);
  88. for (MediaFolder mediaFolder : mediaFolders) {
  89. Log.d(TAG, mediaFolder.path);
  90. }
  91. mHandler.post(new TimerTask() {
  92. @Override
  93. public void run() {
  94. mAdapter.setMediaFolders(mediaFolders);
  95. setListShown(true);
  96. }
  97. });
  98. }
  99. }).start();
  100. }
  101. void setListShown(boolean shown) {
  102. if (mRecyclerView != null) {
  103. mRecyclerView.setVisibility(shown ?
  104. View.VISIBLE : View.GONE);
  105. // TODO show/hide loading visuals
  106. /**
  107. mProgress.setVisibility(shown ?
  108. View.GONE : View.VISIBLE);
  109. mEmpty.setVisibility(shown && mAdapter.getItemCount() == 0 ?
  110. View.VISIBLE : View.GONE);
  111. **/
  112. }
  113. }
  114. @Override
  115. public boolean onOptionsItemSelected(MenuItem item) {
  116. boolean retval;
  117. switch (item.getItemId()) {
  118. case android.R.id.home: {
  119. if (isDrawerOpen()) {
  120. closeDrawer();
  121. } else {
  122. openDrawer();
  123. }
  124. }
  125. default:
  126. retval = super.onOptionsItemSelected(item);
  127. }
  128. return retval;
  129. }
  130. @Override
  131. public void restart() {
  132. Intent i = new Intent(this, FileDisplayActivity.class);
  133. i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  134. startActivity(i);
  135. }
  136. @Override
  137. public void showFiles(boolean onDeviceOnly) {
  138. MainApp.showOnlyFilesOnDevice(onDeviceOnly);
  139. Intent fileDisplayActivity = new Intent(getApplicationContext(), FileDisplayActivity.class);
  140. fileDisplayActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  141. startActivity(fileDisplayActivity);
  142. }
  143. }