X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/c837207a40e7f647b93909c7f213e4b4b4a41d52..bcc972d63d3ed1d76b51a8a03a27e809983dc756:/src/com/owncloud/android/ui/activity/InstantUploadActivity.java diff --git a/src/com/owncloud/android/ui/activity/InstantUploadActivity.java b/src/com/owncloud/android/ui/activity/InstantUploadActivity.java index 4325b8ab..0d455bd2 100644 --- a/src/com/owncloud/android/ui/activity/InstantUploadActivity.java +++ b/src/com/owncloud/android/ui/activity/InstantUploadActivity.java @@ -2,9 +2,8 @@ * Copyright (C) 2012-2013 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -20,6 +19,14 @@ package com.owncloud.android.ui.activity; import java.util.ArrayList; import java.util.List; +import com.owncloud.android.R; +import com.owncloud.android.authentication.AccountUtils; +import com.owncloud.android.db.DbHandler; +import com.owncloud.android.files.InstantUploadBroadcastReceiver; +import com.owncloud.android.files.services.FileUploader; +import com.owncloud.android.utils.FileStorageUtils; +import com.owncloud.android.utils.Log_OC; + import android.accounts.Account; import android.app.Activity; import android.content.Intent; @@ -27,11 +34,11 @@ import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; -import android.util.Log; import android.util.SparseArray; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; +import android.view.View.OnLongClickListener; import android.view.ViewGroup; import android.widget.Button; import android.widget.CheckBox; @@ -39,58 +46,45 @@ import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.ImageButton; import android.widget.LinearLayout; +import android.widget.TextView; import android.widget.Toast; -import com.owncloud.android.AccountUtils; -import com.owncloud.android.R; -import com.owncloud.android.db.DbHandler; -import com.owncloud.android.files.InstantUploadBroadcastReceiver; -import com.owncloud.android.files.services.FileUploader; -import com.owncloud.android.files.services.InstantUploadService; /** * This Activity is used to display a list with images they could not be * uploaded instantly. The images can be selected for delete or for a try again * upload * - * The entrypoint for this activity is the 'Failed upload Notification" and a - * submenue underneath the 'Upload' menuentry + * The entry-point for this activity is the 'Failed upload Notification" and a + * sub-menu underneath the 'Upload' menu-item * * @author andomaex / Matthias Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more de/ */ public class InstantUploadActivity extends Activity { private static final String LOG_TAG = InstantUploadActivity.class.getSimpleName(); private LinearLayout listView; private static final String retry_chexbox_tag = "retry_chexbox_tag"; + public static final boolean IS_ENABLED = false; private static int MAX_LOAD_IMAGES = 5; private int lastLoadImageIdx = 0; private SparseArray fileList = null; + CheckBox failed_upload_all_cb; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.failed_upload_files); - Button delete_all_btn = (Button) findViewById(R.id.failed_upload_delete_all_btn); - delete_all_btn.setOnClickListener(getDeleteListner()); - Button retry_all_btn = (Button) findViewById(R.id.failed_upload_retry_all_btn); - retry_all_btn.setOnClickListener(getRetryListner()); - CheckBox failed_upload_all_cb = (CheckBox) findViewById(R.id.failed_upload_headline_cb); + Button deleteAllBtn = (Button) findViewById(R.id.failed_upload_delete_all_btn); + deleteAllBtn.setOnClickListener(getDeleteListner()); + Button retryAllBtn = (Button) findViewById(R.id.failed_upload_retry_all_btn); + retryAllBtn.setOnClickListener(getRetryListner()); + this.failed_upload_all_cb = (CheckBox) findViewById(R.id.failed_upload_headline_cb); failed_upload_all_cb.setOnCheckedChangeListener(getCheckAllListener()); listView = (LinearLayout) findViewById(R.id.failed_upload_scrollviewlayout); - + loadListView(true); } @@ -121,13 +115,14 @@ public class InstantUploadActivity extends Activity { lastLoadImageIdx++; String imp_path = c.getString(1); + String message = c.getString(4); fileList.put(lastLoadImageIdx, imp_path); - LinearLayout rowLayout = getLinearLayout(lastLoadImageIdx); + LinearLayout rowLayout = getHorizontalLinearLayout(lastLoadImageIdx); rowLayout.addView(getFileCheckbox(lastLoadImageIdx)); rowLayout.addView(getImageButton(imp_path, lastLoadImageIdx)); - rowLayout.addView(getFileButton(imp_path, lastLoadImageIdx)); + rowLayout.addView(getFileButton(imp_path, message, lastLoadImageIdx)); listView.addView(rowLayout); - Log.d(LOG_TAG, imp_path + " on idx: " + lastLoadImageIdx); + Log_OC.d(LOG_TAG, imp_path + " on idx: " + lastLoadImageIdx); if (lastLoadImageIdx % MAX_LOAD_IMAGES == 0) { break; } @@ -155,7 +150,7 @@ public class InstantUploadActivity extends Activity { loadmoreBtn = new Button(this); loadmoreBtn.setId(42); loadmoreBtn.setText(getString(R.string.failed_upload_load_more_images)); - loadmoreBtn.setBackgroundResource(R.color.owncloud_white); + loadmoreBtn.setBackgroundResource(R.color.background_color); loadmoreBtn.setTextSize(12); loadmoreBtn.setOnClickListener(new OnClickListener() { @Override @@ -178,12 +173,12 @@ public class InstantUploadActivity extends Activity { private List getCheckboxList() { List list = new ArrayList(); for (int i = 0; i < listView.getChildCount(); i++) { - Log.d(LOG_TAG, "ListView has Childs: " + listView.getChildCount()); + Log_OC.d(LOG_TAG, "ListView has Childs: " + listView.getChildCount()); View childView = listView.getChildAt(i); if (childView != null && childView instanceof ViewGroup) { View checkboxView = getChildViews((ViewGroup) childView); if (checkboxView != null && checkboxView instanceof CheckBox) { - Log.d(LOG_TAG, "found Child: " + checkboxView.getId() + " " + checkboxView.getClass()); + Log_OC.d(LOG_TAG, "found Child: " + checkboxView.getId() + " " + checkboxView.getClass()); list.add((CheckBox) checkboxView); } } @@ -241,16 +236,17 @@ public class InstantUploadActivity extends Activity { public void onClick(View v) { try { + List list = getCheckboxList(); for (CheckBox checkbox : list) { boolean to_retry = checkbox.isChecked(); - Log.d(LOG_TAG, "Checkbox for " + checkbox.getId() + " was checked: " + to_retry); + Log_OC.d(LOG_TAG, "Checkbox for " + checkbox.getId() + " was checked: " + to_retry); String img_path = fileList.get(checkbox.getId()); if (to_retry) { final String msg = "Image-Path " + checkbox.getId() + " was checked: " + img_path; - Log.d(LOG_TAG, msg); + Log_OC.d(LOG_TAG, msg); startUpload(img_path); } @@ -259,6 +255,9 @@ public class InstantUploadActivity extends Activity { // refresh the List listView.removeAllViews(); loadListView(true); + if (failed_upload_all_cb != null) { + failed_upload_all_cb.setChecked(false); + } } } @@ -276,18 +275,19 @@ public class InstantUploadActivity extends Activity { @Override public void onClick(View v) { + final DbHandler dbh = new DbHandler(getApplicationContext()); try { List list = getCheckboxList(); for (CheckBox checkbox : list) { boolean to_be_delete = checkbox.isChecked(); - Log.d(LOG_TAG, "Checkbox for " + checkbox.getId() + " was checked: " + to_be_delete); + Log_OC.d(LOG_TAG, "Checkbox for " + checkbox.getId() + " was checked: " + to_be_delete); String img_path = fileList.get(checkbox.getId()); - Log.d(LOG_TAG, "Image-Path " + checkbox.getId() + " was checked: " + img_path); + Log_OC.d(LOG_TAG, "Image-Path " + checkbox.getId() + " was checked: " + img_path); if (to_be_delete) { boolean deleted = dbh.removeIUPendingFile(img_path); - Log.d(LOG_TAG, "removing " + checkbox.getId() + " was : " + deleted); + Log_OC.d(LOG_TAG, "removing " + checkbox.getId() + " was : " + deleted); } @@ -297,13 +297,16 @@ public class InstantUploadActivity extends Activity { // refresh the List listView.removeAllViews(); loadListView(true); + if (failed_upload_all_cb != null) { + failed_upload_all_cb.setChecked(false); + } } } }; } - private LinearLayout getLinearLayout(int id) { + private LinearLayout getHorizontalLinearLayout(int id) { LinearLayout linearLayout = new LinearLayout(getApplicationContext()); linearLayout.setId(id); linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, @@ -313,20 +316,57 @@ public class InstantUploadActivity extends Activity { return linearLayout; } - private Button getFileButton(final String img_path, int id) { - Button retryButton = new Button(this); + private LinearLayout getVerticalLinearLayout() { + LinearLayout linearLayout = new LinearLayout(getApplicationContext()); + linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, + LinearLayout.LayoutParams.MATCH_PARENT)); + linearLayout.setGravity(Gravity.TOP); + linearLayout.setOrientation(LinearLayout.VERTICAL); + return linearLayout; + } + + private View getFileButton(final String img_path, String message, int id) { + + TextView failureTextView = new TextView(this); + failureTextView.setText(getString(R.string.failed_upload_failure_text) + message); + failureTextView.setBackgroundResource(R.color.background_color); + failureTextView.setTextSize(8); + failureTextView.setOnLongClickListener(getOnLongClickListener(message)); + failureTextView.setPadding(5, 5, 5, 10); + TextView retryButton = new TextView(this); retryButton.setId(id); retryButton.setText(img_path); - retryButton.setBackgroundResource(R.color.owncloud_white); + retryButton.setBackgroundResource(R.color.background_color); retryButton.setTextSize(8); retryButton.setOnClickListener(getImageButtonOnClickListener(img_path)); - return retryButton; + retryButton.setOnLongClickListener(getOnLongClickListener(message)); + retryButton.setPadding(5, 5, 5, 10); + LinearLayout verticalLayout = getVerticalLinearLayout(); + verticalLayout.addView(retryButton); + verticalLayout.addView(failureTextView); + + return verticalLayout; + } + + private OnLongClickListener getOnLongClickListener(final String message) { + return new OnLongClickListener() { + + @Override + public boolean onLongClick(View v) { + Log_OC.d(LOG_TAG, message); + Toast toast = Toast.makeText(InstantUploadActivity.this, getString(R.string.failed_upload_retry_text) + + message, Toast.LENGTH_LONG); + toast.show(); + return true; + } + + }; } private CheckBox getFileCheckbox(int id) { CheckBox retryCB = new CheckBox(this); retryCB.setId(id); - retryCB.setBackgroundResource(R.color.owncloud_white); + retryCB.setBackgroundResource(R.color.background_color); retryCB.setTextSize(8); retryCB.setTag(retry_chexbox_tag); return retryCB; @@ -341,7 +381,7 @@ public class InstantUploadActivity extends Activity { // scale and add a thumbnail to the imagebutton int base_scale_size = 32; if (img_path != null) { - Log.d(LOG_TAG, "add " + img_path + " to Image Button"); + Log_OC.d(LOG_TAG, "add " + img_path + " to Image Button"); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; Bitmap bitmap = BitmapFactory.decodeFile(img_path, options); @@ -356,16 +396,16 @@ public class InstantUploadActivity extends Activity { scale++; } - Log.d(LOG_TAG, "scale Imgae with: " + scale); + Log_OC.d(LOG_TAG, "scale Imgae with: " + scale); BitmapFactory.Options options2 = new BitmapFactory.Options(); options2.inSampleSize = scale; bitmap = BitmapFactory.decodeFile(img_path, options2); if (bitmap != null) { - Log.d(LOG_TAG, "loaded Bitmap Bytes: " + bitmap.getRowBytes()); + Log_OC.d(LOG_TAG, "loaded Bitmap Bytes: " + bitmap.getRowBytes()); imageButton.setImageBitmap(bitmap); } else { - Log.d(LOG_TAG, "could not load imgage: " + img_path); + Log_OC.d(LOG_TAG, "could not load imgage: " + img_path); } } return imageButton; @@ -390,13 +430,13 @@ public class InstantUploadActivity extends Activity { */ private void startUpload(String img_path) { // extract filename - String filename = img_path.substring(img_path.lastIndexOf('/'), img_path.length()); + String filename = FileStorageUtils.getInstantUploadFilePath(this, img_path); if (canInstantUpload()) { Account account = AccountUtils.getCurrentOwnCloudAccount(InstantUploadActivity.this); // add file again to upload queue DbHandler db = new DbHandler(InstantUploadActivity.this); try { - db.updateFileState(img_path, DbHandler.UPLOAD_STATUS_UPLOAD_LATER); + db.updateFileState(img_path, DbHandler.UPLOAD_STATUS_UPLOAD_LATER, null); } finally { db.close(); } @@ -404,12 +444,12 @@ public class InstantUploadActivity extends Activity { Intent i = new Intent(InstantUploadActivity.this, FileUploader.class); i.putExtra(FileUploader.KEY_ACCOUNT, account); i.putExtra(FileUploader.KEY_LOCAL_FILE, img_path); - i.putExtra(FileUploader.KEY_REMOTE_FILE, InstantUploadService.INSTANT_UPLOAD_DIR + "/" + filename); + i.putExtra(FileUploader.KEY_REMOTE_FILE, filename); i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE); i.putExtra(com.owncloud.android.files.services.FileUploader.KEY_INSTANT_UPLOAD, true); final String msg = "try to upload file with name :" + filename; - Log.d(LOG_TAG, msg); + Log_OC.d(LOG_TAG, msg); Toast toast = Toast.makeText(InstantUploadActivity.this, getString(R.string.failed_upload_retry_text) + filename, Toast.LENGTH_LONG); toast.show();