mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 13:45:35 +03:00
Merge branch 'remember_last_share_location' into remember_last_share_location_fixed
This commit is contained in:
commit
0bedcb9128
2 changed files with 95 additions and 11 deletions
|
@ -39,7 +39,9 @@
|
|||
<string name="prefs_recommend">Recommend to a friend</string>
|
||||
<string name="prefs_feedback">Feedback</string>
|
||||
<string name="prefs_imprint">Imprint</string>
|
||||
|
||||
<string name="prefs_remember_last_share_location">Remember share location</string>
|
||||
<string name="prefs_remember_last_upload_location_summary">Remember last share upload location</string>
|
||||
|
||||
<string name="recommend_subject">"Try %1$s on your smartphone!"</string>
|
||||
<string name="recommend_text">"I want to invite you to use %1$s on your smartphone!\nDownload here: %2$s"</string>
|
||||
|
||||
|
@ -279,6 +281,7 @@
|
|||
<string name="network_error_socket_timeout_exception">An error occurred while waiting for the server, the operation couldn\'t have been done</string>
|
||||
<string name="network_error_connect_timeout_exception">An error occurred while waiting for the server, the operation couldn\'t have been done</string>
|
||||
<string name="network_host_not_available">The operation couldn\'t be completed, server is unavailable</string>
|
||||
|
||||
<string name="empty"></string>
|
||||
|
||||
<string name="forbidden_permissions">You do not have permission %s</string>
|
||||
|
@ -313,5 +316,4 @@
|
|||
|
||||
<string name="prefs_category_instant_uploading">Instant Uploads</string>
|
||||
<string name="prefs_category_security">Security</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -39,22 +39,22 @@ import android.accounts.AccountManager;
|
|||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.app.Dialog;
|
||||
import android.app.ListActivity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnCancelListener;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.MediaStore.Audio;
|
||||
import android.provider.MediaStore.Images;
|
||||
import android.provider.MediaStore.Video;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.Button;
|
||||
|
@ -62,6 +62,10 @@ import android.widget.EditText;
|
|||
import android.widget.SimpleAdapter;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.app.SherlockListActivity;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
import com.owncloud.android.utils.DisplayUtils;
|
||||
|
||||
/**
|
||||
* This can be used to upload things to an ownCloud instance.
|
||||
|
@ -69,7 +73,7 @@ import android.widget.Toast;
|
|||
* @author Bartek Przybylski
|
||||
*
|
||||
*/
|
||||
public class Uploader extends ListActivity implements OnItemClickListener, android.view.View.OnClickListener {
|
||||
public class Uploader extends SherlockListActivity implements OnItemClickListener, android.view.View.OnClickListener {
|
||||
private static final String TAG = "ownCloudUploader";
|
||||
|
||||
private Account mAccount;
|
||||
|
@ -91,9 +95,11 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
|
|||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
||||
mParents = new Stack<String>();
|
||||
mParents.add("");
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
actionBar.setIcon(DisplayUtils.getSeasonalIconId());
|
||||
|
||||
if (prepareStreamsToUpload()) {
|
||||
mAccountManager = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE);
|
||||
Account[] accounts = mAccountManager.getAccountsByType(MainApp.getAccountType());
|
||||
|
@ -106,8 +112,11 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
|
|||
} else {
|
||||
mAccount = accounts[0];
|
||||
mStorageManager = new FileDataStorageManager(mAccount, getContentResolver());
|
||||
initTargetFolder();
|
||||
populateDirectoryList();
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
showDialog(DIALOG_NO_STREAM);
|
||||
}
|
||||
|
@ -169,6 +178,7 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
|
|||
public void onClick(DialogInterface dialog, int which) {
|
||||
mAccount = mAccountManager.getAccountsByType(MainApp.getAccountType())[which];
|
||||
mStorageManager = new FileDataStorageManager(mAccount, getContentResolver());
|
||||
initTargetFolder();
|
||||
populateDirectoryList();
|
||||
}
|
||||
});
|
||||
|
@ -288,12 +298,22 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
|
|||
private void populateDirectoryList() {
|
||||
setContentView(R.layout.uploader_layout);
|
||||
|
||||
String full_path = "";
|
||||
for (String a : mParents)
|
||||
full_path += a + "/";
|
||||
String current_dir = mParents.peek();
|
||||
if(current_dir.equals("")){
|
||||
getSupportActionBar().setTitle(getString(R.string.default_display_name_for_root_folder));
|
||||
}
|
||||
else{
|
||||
getSupportActionBar().setTitle(current_dir);
|
||||
}
|
||||
boolean notRoot = (mParents.size() > 1);
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
actionBar.setDisplayHomeAsUpEnabled(notRoot);
|
||||
actionBar.setHomeButtonEnabled(notRoot);
|
||||
|
||||
String full_path = generatePath(mParents);
|
||||
|
||||
Log_OC.d(TAG, "Populating view with content of : " + full_path);
|
||||
|
||||
|
||||
mFile = mStorageManager.getFileByPath(full_path);
|
||||
if (mFile != null) {
|
||||
Vector<OCFile> files = mStorageManager.getFolderContent(mFile);
|
||||
|
@ -317,6 +337,14 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
|
|||
}
|
||||
}
|
||||
|
||||
private String generatePath(Stack<String> dirs) {
|
||||
String full_path = "";
|
||||
|
||||
for (String a : dirs)
|
||||
full_path += a + "/";
|
||||
return full_path;
|
||||
}
|
||||
|
||||
private boolean prepareStreamsToUpload() {
|
||||
if (getIntent().getAction().equals(Intent.ACTION_SEND)) {
|
||||
mStreamsToUpload = new ArrayList<Parcelable>();
|
||||
|
@ -408,6 +436,13 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
|
|||
intent.putExtra(FileUploader.KEY_REMOTE_FILE, remote.toArray(new String[remote.size()]));
|
||||
intent.putExtra(FileUploader.KEY_ACCOUNT, mAccount);
|
||||
startService(intent);
|
||||
|
||||
//Save the path to shared preferences
|
||||
SharedPreferences.Editor appPrefs = PreferenceManager
|
||||
.getDefaultSharedPreferences(getApplicationContext()).edit();
|
||||
appPrefs.putString("last_upload_path", mUploadPath);
|
||||
appPrefs.apply();
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
|
@ -416,5 +451,52 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
|
|||
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the target folder initialize shown to the user.
|
||||
*
|
||||
* The target account has to be chosen before this method is called.
|
||||
*/
|
||||
private void initTargetFolder() {
|
||||
if (mStorageManager == null) {
|
||||
throw new IllegalStateException("Do not call this method before initializing mStorageManager");
|
||||
}
|
||||
|
||||
SharedPreferences appPreferences = PreferenceManager
|
||||
.getDefaultSharedPreferences(getApplicationContext());
|
||||
|
||||
String last_path = appPreferences.getString("last_upload_path", "");
|
||||
// "/" equals root-directory
|
||||
if(last_path.equals("/")) {
|
||||
mParents.add("");
|
||||
}
|
||||
else{
|
||||
String[] dir_names = last_path.split("/");
|
||||
for (String dir : dir_names)
|
||||
mParents.add(dir);
|
||||
}
|
||||
//Make sure that path still exists, if it doesn't pop the stack and try the previous path
|
||||
while(!mStorageManager.fileExists(generatePath(mParents))){
|
||||
mParents.pop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
boolean retval = true;
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home: {
|
||||
if((mParents.size() > 1)) {
|
||||
onBackPressed();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
retval = super.onOptionsItemSelected(item);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue