Added notification for failures in manual synchronizations; some improvements in...
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / FileDetailActivity.java
1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18 package com.owncloud.android.ui.activity;
19
20 import android.accounts.Account;
21 import android.app.Dialog;
22 import android.app.ProgressDialog;
23 import android.content.Intent;
24 import android.content.res.Configuration;
25 import android.os.Bundle;
26 import android.support.v4.app.FragmentTransaction;
27
28 import com.actionbarsherlock.app.ActionBar;
29 import com.actionbarsherlock.app.SherlockFragmentActivity;
30 import com.actionbarsherlock.view.MenuItem;
31 import com.owncloud.android.datamodel.OCFile;
32 import com.owncloud.android.files.services.FileDownloader;
33 import com.owncloud.android.ui.fragment.FileDetailFragment;
34
35 import com.owncloud.android.R;
36
37 /**
38 * This activity displays the details of a file like its name, its size and so
39 * on.
40 *
41 * @author Bartek Przybylski
42 *
43 */
44 public class FileDetailActivity extends SherlockFragmentActivity implements FileDetailFragment.ContainerActivity {
45
46 public static final int DIALOG_SHORT_WAIT = 0;
47
48 private boolean mConfigurationChangedToLandscape = false;
49
50 @Override
51 protected void onCreate(Bundle savedInstanceState) {
52 super.onCreate(savedInstanceState);
53
54 // check if configuration changed to large-land ; for a tablet being changed from portrait to landscape when in FileDetailActivity
55 Configuration conf = getResources().getConfiguration();
56 mConfigurationChangedToLandscape = (conf.orientation == Configuration.ORIENTATION_LANDSCAPE &&
57 (conf.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE
58 );
59
60 if (!mConfigurationChangedToLandscape) {
61 setContentView(R.layout.file_activity_details);
62
63 ActionBar actionBar = getSupportActionBar();
64 actionBar.setDisplayHomeAsUpEnabled(true);
65
66 OCFile file = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE);
67 Account account = getIntent().getParcelableExtra(FileDownloader.EXTRA_ACCOUNT);
68 FileDetailFragment mFileDetail = new FileDetailFragment(file, account);
69
70 FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
71 ft.replace(R.id.fragment, mFileDetail, FileDetailFragment.FTAG);
72 ft.commit();
73
74 } else {
75 backToDisplayActivity(); // the 'back' won't be effective until this.onStart() and this.onResume() are completed;
76 }
77
78
79 }
80
81 @Override
82 public boolean onOptionsItemSelected(MenuItem item) {
83 boolean returnValue = false;
84
85 switch(item.getItemId()){
86 case android.R.id.home:
87 backToDisplayActivity();
88 returnValue = true;
89 }
90
91 return returnValue;
92 }
93
94
95
96 @Override
97 protected void onResume() {
98
99 super.onResume();
100 if (!mConfigurationChangedToLandscape) {
101 FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
102 fragment.updateFileDetails();
103 }
104 }
105
106
107 private void backToDisplayActivity() {
108 Intent intent = new Intent(this, FileDisplayActivity.class);
109 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
110 intent.putExtra(FileDetailFragment.EXTRA_FILE, getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE));
111 startActivity(intent);
112 finish();
113 }
114
115
116 @Override
117 protected Dialog onCreateDialog(int id) {
118 Dialog dialog = null;
119 switch (id) {
120 case DIALOG_SHORT_WAIT: {
121 ProgressDialog working_dialog = new ProgressDialog(this);
122 working_dialog.setMessage(getResources().getString(
123 R.string.wait_a_moment));
124 working_dialog.setIndeterminate(true);
125 working_dialog.setCancelable(false);
126 dialog = working_dialog;
127 break;
128 }
129 default:
130 dialog = null;
131 }
132 return dialog;
133 }
134
135
136 /**
137 * {@inheritDoc}
138 */
139 @Override
140 public void onFileStateChanged() {
141 // nothing to do here!
142 }
143
144 }