Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
<activity android:name=".ui.activity.UploadFilesActivity" />
<activity android:name=".ui.activity.ReceiveExternalFilesActivity"
android:taskAffinity=""
android:excludeFromRecents="true">
android:excludeFromRecents="true"
android:theme="@style/Theme.ownCloud">
<intent-filter>
<action android:name="android.intent.action.SEND" />

Expand Down
2 changes: 1 addition & 1 deletion owncloud-android-library
Submodule owncloud-android-library updated 0 files
32 changes: 14 additions & 18 deletions res/layout/uploader_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,20 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:orientation="vertical"
android:layout_width="wrap_content" android:background="#fefefe"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_width="wrap_content"
android:background="@color/white"
android:gravity="center">

<TextView android:layout_width="fill_parent"
android:text="@string/uploader_top_message"
android:layout_height="wrap_content"
android:id="@+id/drawer_username"
android:textColor="@android:color/black"
android:gravity="center_horizontal">
</TextView>
<FrameLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/upload_list"
android:layout_above="@+id/upload_actions">

<FrameLayout android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/frameLayout1"
android:layout_below="@+id/drawer_username"
android:layout_above="@+id/linearLayout1">

<ListView android:id="@android:id/list"
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="@color/list_divider_background"
Expand All @@ -46,11 +41,12 @@
</FrameLayout>

<LinearLayout
android:id="@+id/linearLayout1"
android:id="@+id/upload_actions"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
android:orientation="horizontal"
android:padding="@dimen/standard_padding">

<android.support.v7.widget.AppCompatButton
android:theme="@style/Button"
Expand Down
91 changes: 69 additions & 22 deletions res/layout/uploader_list_item_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,75 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:background="#fefefe"
android:orientation="horizontal"
android:layout_height="72dp"
android:padding="@dimen/standard_padding">

<ImageView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="72dp"
android:background="@drawable/list_selector"
android:orientation="horizontal">

<ImageView
android:id="@+id/thumbnail"
android:layout_width="@dimen/file_icon_size"
android:layout_height="@dimen/file_icon_size"
android:layout_gravity="center_vertical|center"
android:src="@drawable/ic_menu_archive"
android:id="@+id/thumbnail"
android:layout_marginRight="@dimen/standard_padding"/>

<TextView
android:text="TextView"
android:layout_width="fill_parent"
android:id="@+id/filename"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:textSize="16sp" />

android:layout_gravity="center_vertical"
android:layout_margin="12dp"
android:src="@drawable/ic_menu_archive" />

<LinearLayout
android:layout_width="0dp"
android:layout_height="72dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical">

<TextView
android:id="@+id/filename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="0dp"
android:layout_marginRight="4dp"
android:ellipsize="middle"
android:singleLine="true"
android:text="TextView"
android:textColor="@color/textColor"
android:textSize="16dip" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginRight="4dp"
android:orientation="horizontal">

<TextView
android:id="@+id/file_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Size MB"
android:textColor="@color/list_item_lastmod_and_filesize_text"
android:textSize="@dimen/two_line_secondary_text_size"/>

<TextView
android:id="@+id/file_separator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text=", "
android:textColor="@color/list_item_lastmod_and_filesize_text"
android:textSize="@dimen/two_line_secondary_text_size"/>

<TextView
android:id="@+id/last_mod"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Mod Date"
android:textColor="@color/list_item_lastmod_and_filesize_text"
android:textSize="@dimen/two_line_secondary_text_size"/>

</LinearLayout>

</LinearLayout>

</LinearLayout>
2 changes: 1 addition & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<string name="sync_string_files">Files</string>
<string name="setup_btn_connect">Connect</string>
<string name="uploader_btn_upload_text">Upload</string>
<string name="uploader_top_message">Choose upload folder:</string>
<string name="uploader_top_message">Choose upload folder</string>
<string name="uploader_wrn_no_account_title">No account found</string>
<string name="uploader_wrn_no_account_text">There are no %1$s accounts on your device. Please set up an account first.</string>
<string name="uploader_wrn_no_account_setup_btn_text">Setup</string>
Expand Down
110 changes: 80 additions & 30 deletions src/com/owncloud/android/db/PreferenceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,70 +22,120 @@
import android.content.Context;
import android.content.SharedPreferences;

import com.owncloud.android.utils.FileStorageUtils;

/**
* Helper to simplify reading of Preferences all around the app
*/

public class PreferenceManager {

public abstract class PreferenceManager {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why abstract ?

@AndyScherzinger AndyScherzinger Jun 10, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because all it is is a helper class with all methods being static so nobody should create instances but simply call the helper methods thus I made it abstract :)

/**
* Constant to access value of last path selected by the user to upload a file shared from other app.
* Value handled by the app without direct access in the UI.
*/
private static final String AUTO_PREF__LAST_UPLOAD_PATH = "last_upload_path";
private static final String AUTO_PREF__SORT_ORDER = "sortOrder";
private static final String AUTO_PREF__SORT_ASCENDING = "sortAscending";
private static final String PREF__INSTANT_UPLOADING = "instant_uploading";
private static final String PREF__INSTANT_VIDEO_UPLOADING = "instant_video_uploading";
private static final String PREF__INSTANT_UPLOAD_ON_WIFI = "instant_upload_on_wifi";
private static final String PREF__INSTANT_VIDEO_UPLOAD_ON_WIFI = "instant_video_upload_on_wifi";

public static boolean instantPictureUploadEnabled(Context context) {
return android.preference.PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
"instant_uploading",
false
);
return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_UPLOADING, false);
}

public static boolean instantVideoUploadEnabled(Context context) {
return android.preference.PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
"instant_video_uploading",
false
);
return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_VIDEO_UPLOADING, false);
}

public static boolean instantPictureUploadViaWiFiOnly(Context context) {
return android.preference.PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
"instant_upload_on_wifi",
false
);
return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_UPLOAD_ON_WIFI, false);
}

public static boolean instantVideoUploadViaWiFiOnly(Context context) {
return android.preference.PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
"instant_video_upload_on_wifi",
false
);
return getDefaultSharedPreferences(context).getBoolean(PREF__INSTANT_VIDEO_UPLOAD_ON_WIFI, false);
}

/**
* Gets the path where the user selected to do the last upload of a file shared from other app.
*
* @param context Caller {@link Context}, used to access to shared preferences manager.
* @param context Caller {@link Context}, used to access to shared preferences manager.
* @return path Absolute path to a folder, as previously stored by {@link #setLastUploadPath(String, Context)},
* or empty String if never saved before.
* or empty String if never saved before.
*/
public static String getLastUploadPath(Context context) {
SharedPreferences appPreferences = android.preference.PreferenceManager
.getDefaultSharedPreferences(context.getApplicationContext());
return appPreferences.getString(AUTO_PREF__LAST_UPLOAD_PATH, "");
return getDefaultSharedPreferences(context).getString(AUTO_PREF__LAST_UPLOAD_PATH, "");
}

/**
* Saves the path where the user selected to do the last upload of a file shared from other app.
*
* @param path Absolute path to a folder.
* @param context Caller {@link Context}, used to access to shared preferences manager.
* @param path Absolute path to a folder.
* @param context Caller {@link Context}, used to access to shared preferences manager.
*/
public static void setLastUploadPath(String path, Context context) {
SharedPreferences.Editor appPrefs = android.preference.PreferenceManager
.getDefaultSharedPreferences(context.getApplicationContext()).edit();
appPrefs.putString(AUTO_PREF__LAST_UPLOAD_PATH, path);
appPrefs.apply();
saveStringPreference(AUTO_PREF__LAST_UPLOAD_PATH, path, context);
}

/**
* Gets the sort order which the user has set last.
*
* @param context Caller {@link Context}, used to access to shared preferences manager.
* @return sort order the sort order, default is {@link FileStorageUtils#SORT_NAME} (sort by name)
*/
public static int getSortOrder(Context context) {
return getDefaultSharedPreferences(context).getInt(AUTO_PREF__SORT_ORDER, FileStorageUtils.SORT_NAME);
}

/**
* Save the sort order which the user has set last.
*
* @param order the sort order
* @param context Caller {@link Context}, used to access to shared preferences manager.
*/
public static void setSortOrder(int order, Context context) {
saveIntPreference(AUTO_PREF__SORT_ORDER, order, context);
}

/**
* Gets the ascending order flag which the user has set last.
*
* @param context Caller {@link Context}, used to access to shared preferences manager.
* @return ascending order the ascending order, default is true
*/
public static boolean getSortAscending(Context context) {
return getDefaultSharedPreferences(context).getBoolean(AUTO_PREF__SORT_ASCENDING, true);
}

/**
* Saves the ascending order flag which the user has set last.
*
* @param ascending flag if sorting is ascending or descending
* @param context Caller {@link Context}, used to access to shared preferences manager.
*/
public static void setSortAscending(boolean ascending, Context context) {
saveBooleanPreference(AUTO_PREF__SORT_ASCENDING, ascending, context);
}

private static void saveBooleanPreference(String key, boolean value, Context context) {
SharedPreferences.Editor appPreferences = getDefaultSharedPreferences(context.getApplicationContext()).edit();
appPreferences.putBoolean(key, value);
appPreferences.apply();
}

private static void saveStringPreference(String key, String value, Context context) {
SharedPreferences.Editor appPreferences = getDefaultSharedPreferences(context.getApplicationContext()).edit();
appPreferences.putString(key, value);
appPreferences.apply();
}

private static void saveIntPreference(String key, int value, Context context) {
SharedPreferences.Editor appPreferences = getDefaultSharedPreferences(context.getApplicationContext()).edit();
appPreferences.putInt(key, value);
appPreferences.apply();
}

private static SharedPreferences getDefaultSharedPreferences(Context context) {
return android.preference.PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
}
}
13 changes: 4 additions & 9 deletions src/com/owncloud/android/ui/activity/FileDisplayActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.SyncRequest;
import android.content.pm.PackageManager;
import android.content.res.Resources.NotFoundException;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Parcelable;
import android.preference.PreferenceManager;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
Expand All @@ -60,6 +58,7 @@
import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.db.PreferenceManager;
import com.owncloud.android.files.services.FileDownloader;
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.files.services.FileUploader;
Expand Down Expand Up @@ -90,12 +89,13 @@
import com.owncloud.android.ui.preview.PreviewVideoActivity;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.ErrorMessageAdapter;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.PermissionUtil;

import java.io.File;
import java.util.ArrayList;

import static com.owncloud.android.db.PreferenceManager.*;

/**
* Displays, what files the user has available in his ownCloud. This is the main view.
*/
Expand Down Expand Up @@ -564,12 +564,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
break;
}
case R.id.action_sort: {
SharedPreferences appPreferences = PreferenceManager
.getDefaultSharedPreferences(this);

// Read sorting order, default to sort by name ascending
Integer sortOrder = appPreferences
.getInt("sortOrder", FileStorageUtils.SORT_NAME);
Integer sortOrder = getSortOrder(this);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really nice catch. Thanks a lot.


AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.actionbar_sort_title)
Expand Down
Loading