From fd13c5ce6466aa4109a212b5d0d04845020c7e62 Mon Sep 17 00:00:00 2001 From: Yenel Rodriguez Date: Fri, 28 Dec 2018 16:40:39 +0100 Subject: [PATCH 001/117] Task #11075-Improvements on contacts grid view (Updated) --- .../adapters/MegaContactsLollipopAdapter.java | 150 ++++++++++++------ .../MegaContactsAttachedLollipopAdapter.java | 2 +- .../background_contact_grid_selected.xml | 13 ++ .../background_item_grid_selected.xml | 2 +- app/src/main/res/layout/item_contact_grid.xml | 86 ++++++---- 5 files changed, 166 insertions(+), 87 deletions(-) create mode 100644 app/src/main/res/drawable/background_contact_grid_selected.xml diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/adapters/MegaContactsLollipopAdapter.java b/app/src/main/java/mega/privacy/android/app/lollipop/adapters/MegaContactsLollipopAdapter.java index e0e3c2a0705..7b85200e6d9 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/adapters/MegaContactsLollipopAdapter.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/adapters/MegaContactsLollipopAdapter.java @@ -9,6 +9,7 @@ import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; +import android.graphics.drawable.ColorDrawable; import android.support.v4.content.ContextCompat; import android.support.v7.widget.RecyclerView; import android.util.DisplayMetrics; @@ -22,6 +23,7 @@ import android.view.animation.AnimationUtils; import android.widget.ImageButton; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; @@ -129,7 +131,9 @@ public ViewHolderContactsGrid(View v) { super(v); } public ImageView imageView; + LinearLayout contactNameLayout; ImageView contactStateIcon; + ImageView contactSelectedIcon; ImageButton imageButtonThreeDots; } @@ -187,19 +191,20 @@ else if (viewType == MegaContactsLollipopAdapter.ITEM_VIEW_TYPE_GRID){ holderGrid.itemLayout = (RelativeLayout) v.findViewById(R.id.contact_grid_item_layout); holderGrid.imageView = (ImageView) v.findViewById(R.id.contact_grid_thumbnail); holderGrid.contactInitialLetter = (TextView) v.findViewById(R.id.contact_grid_initial_letter); + holderGrid.contactNameLayout = (LinearLayout) v.findViewById(R.id.contact_grid_name_layout); holderGrid.textViewContactName = (TextView) v.findViewById(R.id.contact_grid_name); - holderGrid.textViewContent = (MarqueeTextView) v.findViewById(R.id.contact_grid_content); - holderGrid.textViewContent.setHorizontallyScrolling(true); +// holderGrid.textViewContent = (MarqueeTextView) v.findViewById(R.id.contact_grid_content); holderGrid.imageButtonThreeDots = (ImageButton) v.findViewById(R.id.contact_grid_three_dots); holderGrid.contactStateIcon = (ImageView) v.findViewById(R.id.contact_grid_drawable_state); + holderGrid.contactSelectedIcon = (ImageView) v.findViewById(R.id.contact_grid_selected_icon); if(context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){ - holderGrid.textViewContactName.setMaxWidth(Util.scaleWidthPx(70, outMetrics)); - holderGrid.textViewContent.setMaxWidth(Util.scaleWidthPx(70, outMetrics)); + holderGrid.textViewContactName.setMaxWidth(Util.scaleWidthPx(61, outMetrics)); +// holderGrid.textViewContent.setMaxWidth(Util.scaleWidthPx(70, outMetrics)); } else{ - holderGrid.textViewContactName.setMaxWidth(Util.scaleWidthPx(120, outMetrics)); - holderGrid.textViewContent.setMaxWidth(Util.scaleWidthPx(120, outMetrics)); + holderGrid.textViewContactName.setMaxWidth(Util.scaleWidthPx(116, outMetrics)); +// holderGrid.textViewContent.setMaxWidth(Util.scaleWidthPx(120, outMetrics)); } holderGrid.itemLayout.setTag(holderGrid); @@ -323,80 +328,75 @@ public void onBindViewHolderGrid (ViewHolderContactsGrid holder, int position){ log("This user is connected"); holder.contactStateIcon.setVisibility(View.VISIBLE); holder.contactStateIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.circle_status_contact_online_grid)); - holder.textViewContent.setText(context.getString(R.string.online_status)); - holder.textViewContent.setVisibility(View.VISIBLE); +// holder.textViewContent.setText(context.getString(R.string.online_status)); +// holder.textViewContent.setVisibility(View.VISIBLE); } else if(userStatus == MegaChatApi.STATUS_AWAY){ log("This user is away"); holder.contactStateIcon.setVisibility(View.VISIBLE); holder.contactStateIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.circle_status_contact_away_grid)); - holder.textViewContent.setText(context.getString(R.string.away_status)); - holder.textViewContent.setVisibility(View.VISIBLE); +// holder.textViewContent.setText(context.getString(R.string.away_status)); +// holder.textViewContent.setVisibility(View.VISIBLE); } else if(userStatus == MegaChatApi.STATUS_BUSY){ log("This user is busy"); holder.contactStateIcon.setVisibility(View.VISIBLE); holder.contactStateIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.circle_status_contact_busy_grid)); - holder.textViewContent.setText(context.getString(R.string.busy_status)); - holder.textViewContent.setVisibility(View.VISIBLE); +// holder.textViewContent.setText(context.getString(R.string.busy_status)); +// holder.textViewContent.setVisibility(View.VISIBLE); } else if(userStatus == MegaChatApi.STATUS_OFFLINE){ log("This user is offline"); holder.contactStateIcon.setVisibility(View.VISIBLE); holder.contactStateIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.circle_status_contact_offline_grid)); - holder.textViewContent.setText(context.getString(R.string.offline_status)); - holder.textViewContent.setVisibility(View.VISIBLE); +// holder.textViewContent.setText(context.getString(R.string.offline_status)); +// holder.textViewContent.setVisibility(View.VISIBLE); } else if(userStatus == MegaChatApi.STATUS_INVALID){ log("INVALID status: "+userStatus); holder.contactStateIcon.setVisibility(View.GONE); - holder.textViewContent.setVisibility(View.GONE); +// holder.textViewContent.setVisibility(View.GONE); } else{ log("This user status is: "+userStatus); holder.contactStateIcon.setVisibility(View.GONE); - holder.textViewContent.setVisibility(View.GONE); +// holder.textViewContent.setVisibility(View.GONE); } - if(userStatus != MegaChatApi.STATUS_ONLINE && userStatus != MegaChatApi.STATUS_BUSY && userStatus != MegaChatApi.STATUS_INVALID){ - if(!contact.getLastGreen().isEmpty()){ - holder.textViewContent.setText(contact.getLastGreen()); - holder.textViewContent.isMarqueeIsNecessary(context); - } - } +// if(userStatus != MegaChatApi.STATUS_ONLINE && userStatus != MegaChatApi.STATUS_BUSY && userStatus != MegaChatApi.STATUS_INVALID){ +// if(!contact.getLastGreen().isEmpty()){ +// holder.textViewContent.setText(contact.getLastGreen()); +// holder.textViewContent.isMarqueeIsNecessary(context); +// } +// } } } else{ holder.contactStateIcon.setVisibility(View.GONE); - ArrayList sharedNodes = megaApi.getInShares(contact.getMegaUser()); - - String sharedNodesDescription = Util.getSubtitleDescription(sharedNodes); - holder.textViewContent.setVisibility(View.VISIBLE); - holder.textViewContent.setText(sharedNodesDescription); +// ArrayList sharedNodes = megaApi.getInShares(contact.getMegaUser()); +// +// String sharedNodesDescription = Util.getSubtitleDescription(sharedNodes); +// holder.textViewContent.setVisibility(View.VISIBLE); +// holder.textViewContent.setText(sharedNodesDescription); } - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) holder.textViewContactName.getLayoutParams(); - if (holder.textViewContent.getVisibility() == View.VISIBLE) { - params.setMargins(Util.px2dp(13, outMetrics), Util.px2dp(16, outMetrics), 0, 0); - } - else if (holder.textViewContent.getVisibility() == View.GONE) { - params.setMargins(Util.px2dp(13, outMetrics), Util.px2dp(24, outMetrics), 0, Util.px2dp(24, outMetrics)); - } - holder.textViewContactName.setLayoutParams(params); +// RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) holder.contactNameLayout.getLayoutParams(); +// if (holder.textViewContent.getVisibility() == View.VISIBLE) { +// params.setMargins(0, Util.px2dp(16, outMetrics), Util.px2dp(4, outMetrics), 0); +// } +// else if (holder.textViewContent.getVisibility() == View.GONE) { +// params.setMargins(0, Util.px2dp(24, outMetrics), Util.px2dp(4, outMetrics), Util.px2dp(24, outMetrics)); +// } +// holder.contactNameLayout.setLayoutParams(params); - if (!multipleSelect) { - + if (multipleSelect && this.isItemChecked(position)) { + holder.itemLayout.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.background_contact_grid_selected)); + holder.contactSelectedIcon.setImageResource(R.drawable.ic_select_folder); + } + else{ holder.itemLayout.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.background_item_grid_new)); - } - else { - - if(this.isItemChecked(position)){ - holder.itemLayout.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.background_item_grid_long_click_lollipop)); - } - else{ - holder.itemLayout.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.background_item_grid_new)); - } + holder.contactSelectedIcon.setImageDrawable(new ColorDrawable(Color.TRANSPARENT)); } holder.textViewContactName.setText(contact.getFullName()); @@ -1118,18 +1118,21 @@ public void setMultipleSelect(boolean multipleSelect) { // } // } - public void toggleSelection(int pos) { + public void toggleSelection(final int pos) { log("toggleSelection"); + final boolean delete; + if (selectedItems.get(pos, false)) { log("delete pos: "+pos); selectedItems.delete(pos); + delete = true; } else { log("PUT pos: "+pos); selectedItems.put(pos, true); + delete = false; } - notifyItemChanged(pos); if (adapterType == MegaContactsLollipopAdapter.ITEM_VIEW_TYPE_LIST) { log("adapter type is LIST"); @@ -1140,7 +1143,9 @@ public void toggleSelection(int pos) { flipAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { - + if (!delete) { + notifyItemChanged(pos); + } } @Override @@ -1148,6 +1153,9 @@ public void onAnimationEnd(Animation animation) { if (selectedItems.size() <= 0){ ((ContactsFragmentLollipop) fragment).hideMultipleSelect(); } + if (delete) { + notifyItemChanged(pos); + } } @Override @@ -1157,11 +1165,51 @@ public void onAnimationRepeat(Animation animation) { }); view.imageView.startAnimation(flipAnimation); } + else{ + if (selectedItems.size() <= 0){ + ((ContactsFragmentLollipop) fragment).hideMultipleSelect(); + } + notifyItemChanged(pos); + } } else{ log("adapter type is GRID"); - if (selectedItems.size() <= 0){ - ((ContactsFragmentLollipop) fragment).hideMultipleSelect(); + MegaContactsLollipopAdapter.ViewHolderContactsGrid view = (MegaContactsLollipopAdapter.ViewHolderContactsGrid) listFragment.findViewHolderForLayoutPosition(pos); + if(view!=null){ + log("Start animation: "+pos); + Animation flipAnimation = AnimationUtils.loadAnimation(context, R.anim.multiselect_flip); + if (!delete) { + notifyItemChanged(pos); + flipAnimation.setDuration(200); + } + flipAnimation.setAnimationListener(new Animation.AnimationListener() { + @Override + public void onAnimationStart(Animation animation) { + if (!delete) { + notifyItemChanged(pos); + } + } + + @Override + public void onAnimationEnd(Animation animation) { + if (selectedItems.size() <= 0){ + ((ContactsFragmentLollipop) fragment).hideMultipleSelect(); + } + notifyItemChanged(pos); + } + + @Override + public void onAnimationRepeat(Animation animation) { + + } + }); + view.contactSelectedIcon.startAnimation(flipAnimation); + } + else{ + if (selectedItems.size() <= 0){ + ((ContactsFragmentLollipop) fragment).hideMultipleSelect(); + } + notifyItemChanged(pos); } } } diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/megachat/chatAdapters/MegaContactsAttachedLollipopAdapter.java b/app/src/main/java/mega/privacy/android/app/lollipop/megachat/chatAdapters/MegaContactsAttachedLollipopAdapter.java index 356773a5d3f..835e9f95eb8 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/megachat/chatAdapters/MegaContactsAttachedLollipopAdapter.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/megachat/chatAdapters/MegaContactsAttachedLollipopAdapter.java @@ -243,7 +243,7 @@ else if (viewType == MegaContactsAttachedLollipopAdapter.ITEM_VIEW_TYPE_GRID){ holderGrid.imageView = (ImageView) v.findViewById(R.id.contact_grid_thumbnail); holderGrid.contactInitialLetter = (TextView) v.findViewById(R.id.contact_grid_initial_letter); holderGrid.textViewContactName = (TextView) v.findViewById(R.id.contact_grid_name); - holderGrid.textViewContent = (TextView) v.findViewById(R.id.contact_grid_content); +// holderGrid.textViewContent = (TextView) v.findViewById(R.id.contact_grid_content); holderGrid.imageButtonThreeDots = (ImageButton) v.findViewById(R.id.contact_grid_three_dots); holderGrid.contactStateIcon = (ImageView) v.findViewById(R.id.contact_grid_drawable_state); diff --git a/app/src/main/res/drawable/background_contact_grid_selected.xml b/app/src/main/res/drawable/background_contact_grid_selected.xml new file mode 100644 index 00000000000..e4911322e61 --- /dev/null +++ b/app/src/main/res/drawable/background_contact_grid_selected.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/background_item_grid_selected.xml b/app/src/main/res/drawable/background_item_grid_selected.xml index 78e2c3e7fff..06dc2562e03 100644 --- a/app/src/main/res/drawable/background_item_grid_selected.xml +++ b/app/src/main/res/drawable/background_item_grid_selected.xml @@ -1,7 +1,7 @@ - + @@ -20,23 +20,21 @@ android:background="@null" android:scaleType="fitXY" /> + + - - - - - - + android:layout_toLeftOf="@+id/contact_grid_three_dots" + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + From 3ac15e190ecda036146b4cc2f27985f0e055572c Mon Sep 17 00:00:00 2001 From: Yenel Rodriguez Date: Wed, 2 Jan 2019 10:35:52 +0100 Subject: [PATCH 002/117] Bug #11223-When it wants to share a folder and not grants the contact permission the contact explorer does not show MEGA contacts and toolbar title --- .../lollipop/AddContactActivityLollipop.java | 115 +++++++++++------- 1 file changed, 71 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/AddContactActivityLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/AddContactActivityLollipop.java index 3ffb3acf60e..626211acf0f 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/AddContactActivityLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/AddContactActivityLollipop.java @@ -222,6 +222,8 @@ public class AddContactActivityLollipop extends PinActivityLollipop implements V private boolean createNewGroup = false; private String title = ""; + private boolean queryPermissions = true; + @Override public List getAdapterData() { if (inputString != null && !inputString.equals("")) { @@ -241,44 +243,48 @@ protected Void doInBackground(Void... voids) { getVisibleMEGAContacts(); } else if (contactType == Constants.CONTACT_TYPE_DEVICE) { - phoneContacts.clear(); - filteredContactsPhone.clear(); - phoneContacts = getPhoneContacts(); - addedContactsPhone.clear(); - for (int i = 0; i < phoneContacts.size(); i++) { - filteredContactsPhone.add(phoneContacts.get(i)); - } - getVisibleMEGAContacts(); - - boolean found; - PhoneContactInfo contactPhone; - MegaContactAdapter contactMEGA; - - if (filteredContactsPhone != null && !filteredContactsPhone.isEmpty()) { - for (int i=0; i contacts) { - if(filteredContactsPhone!=null){ + if(queryPermissions &&filteredContactsPhone!=null){ if (filteredContactsPhone.size() == 0){ headerContacts.setVisibility(View.GONE); String textToShow = String.format(getString(R.string.context_empty_contacts), getString(R.string.section_contacts)); @@ -931,6 +939,9 @@ void setPhoneAdapterContacts (ArrayList contacts) { } } else{ + if (!queryPermissions) { + emptyTextView.setText(R.string.no_contacts_permissions); + } log("PhoneContactsTask: Phone contacts null"); boolean hasReadContactsPermission = (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED); if (!hasReadContactsPermission) { @@ -1204,6 +1215,10 @@ public boolean onQueryTextChange(String newText) { } } + if (!queryPermissions && contactType == Constants.CONTACT_TYPE_DEVICE) { + searchMenuItem.setVisible(false); + } + return super.onCreateOptionsMenu(menu); } @@ -1308,6 +1323,7 @@ protected void onSaveInstanceState(Bundle outState) { outState.putBoolean("isConfirmAddShown", isConfirmAddShown); outState.putString("confirmAddMail", confirmAddMail); outState.putBoolean("createNewGroup", createNewGroup); + outState.putBoolean("queryPermissions", queryPermissions); saveContactsAdded(outState); } @@ -1598,6 +1614,7 @@ else if(contactType == Constants.CONTACT_TYPE_DEVICE) { isConfirmAddShown = savedInstanceState.getBoolean("isConfirmAddShown", false); confirmAddMail = savedInstanceState.getString("confirmAddMail"); createNewGroup = savedInstanceState.getBoolean("createNewGroup", false); + queryPermissions = savedInstanceState.getBoolean("queryPermissions", true); if (contactType == Constants.CONTACT_TYPE_MEGA || contactType == Constants.CONTACT_TYPE_BOTH) { savedaddedContacts = savedInstanceState.getStringArrayList("savedaddedContacts"); @@ -1608,15 +1625,15 @@ else if(contactType == Constants.CONTACT_TYPE_DEVICE) { newGroupChatButton.setVisibility(View.GONE); } - if (savedaddedContacts == null && contactType == Constants.CONTACT_TYPE_MEGA) { + if (savedaddedContacts == null && (contactType == Constants.CONTACT_TYPE_MEGA || contactType == Constants.CONTACT_TYPE_BOTH)) { setAddedAdapterContacts(); getContactsTask = new GetContactsTask(); getContactsTask.execute(); } - else if (savedaddedContacts == null && contactType == Constants.CONTACT_TYPE_BOTH) { - setAddedAdapterContacts(); - queryIfHasReadContactsPermissions(); - } +// else if (savedaddedContacts == null && contactType == Constants.CONTACT_TYPE_BOTH) { +// setAddedAdapterContacts(); +// queryIfHasReadContactsPermissions(); +// } else { recoverContactsTask = new RecoverContactsTask(); recoverContactsTask.execute(); @@ -1629,7 +1646,7 @@ else if (contactType == Constants.CONTACT_TYPE_DEVICE){ setAddedAdapterContacts(); - if (filteredContactsPhone == null && phoneContacts == null) { + if (queryPermissions && filteredContactsPhone == null && phoneContacts == null) { queryIfHasReadContactsPermissions(); } else { @@ -3071,8 +3088,11 @@ else if (hasReadContactsPermissions && contactType == Constants.CONTACT_TYPE_BOT } else if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_DENIED) { boolean hasReadContactsPermissions = (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_DENIED); + queryPermissions = false; + supportInvalidateOptionsMenu(); if (hasReadContactsPermissions && contactType == Constants.CONTACT_TYPE_DEVICE) { log("Permission denied"); + setTitleAB(); filteredContactsPhone.clear(); emptyImageView.setVisibility(View.VISIBLE); emptyTextView.setVisibility(View.VISIBLE); @@ -3080,6 +3100,13 @@ else if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION progressBar.setVisibility(View.GONE); } + else{ + progressBar.setVisibility(View.VISIBLE); + emptyTextView.setText(R.string.contacts_list_empty_text_loading_share); + + getContactsTask = new GetContactsTask(); + getContactsTask.execute(); + } } break; } From eecbc2cada9c5b754faf4c1435ee4820ffa6ccfc Mon Sep 17 00:00:00 2001 From: aw Date: Tue, 12 Feb 2019 11:38:55 +1300 Subject: [PATCH 003/117] bug#11454-press-back-when-login fix by disabling back button while login. --- .../android/app/lollipop/LoginActivityLollipop.java | 4 ++++ .../android/app/lollipop/LoginFragmentLollipop.java | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/LoginActivityLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/LoginActivityLollipop.java index 57ac5652665..ebfb1e94184 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/LoginActivityLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/LoginActivityLollipop.java @@ -584,6 +584,10 @@ public void onBackPressed() { case Constants.LOGIN_FRAGMENT: { if (loginFragment != null) { valueReturn = loginFragment.onBackPressed(); + //While login, disable back. + if(valueReturn == -1) { + return; + } } break; } diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java index 3bd1e6a1b5e..7a3db18d679 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java @@ -2892,10 +2892,13 @@ public void onDestroy(){ public int onBackPressed() { log("onBackPressed"); - backWhileLogin = true; +// backWhileLogin = true; - if (loginClicked){ - return 0; + //While login, disable the back. + if (loginClicked || + loginProgressBar.getVisibility() == View.VISIBLE || + loginFetchNodesProgressBar.getVisibility() == View.VISIBLE){ + return -1; } else{ From 3643c7a3eee8f1f289fe9787006e32f78d4bcc82 Mon Sep 17 00:00:00 2001 From: aw Date: Thu, 14 Feb 2019 13:35:58 +1300 Subject: [PATCH 004/117] bug#11454-press-back-when-login 1. fix the hanging on bug without disabling back button. 2. press back when login, will get back to the login page, in case the user would like to login with another account. --- .../privacy/android/app/DatabaseHandler.java | 5 +- .../app/lollipop/LoginActivityLollipop.java | 4 -- .../app/lollipop/LoginFragmentLollipop.java | 60 ++++++++++++++++--- 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/mega/privacy/android/app/DatabaseHandler.java b/app/src/main/java/mega/privacy/android/app/DatabaseHandler.java index 30da2622e2a..efa797b4ab7 100644 --- a/app/src/main/java/mega/privacy/android/app/DatabaseHandler.java +++ b/app/src/main/java/mega/privacy/android/app/DatabaseHandler.java @@ -746,8 +746,9 @@ public UserCredentials getCredentials(){ String selectQuery = "SELECT * FROM " + TABLE_CREDENTIALS; try{ - Cursor cursor = db.rawQuery(selectQuery, null); - if (cursor.moveToFirst()) { + Cursor cursor = db.rawQuery(selectQuery, null); + //get the credential of last login + if (cursor.moveToLast()) { int id = Integer.parseInt(cursor.getString(0)); String email = decrypt(cursor.getString(1)); String session = decrypt(cursor.getString(2)); diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/LoginActivityLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/LoginActivityLollipop.java index ebfb1e94184..57ac5652665 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/LoginActivityLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/LoginActivityLollipop.java @@ -584,10 +584,6 @@ public void onBackPressed() { case Constants.LOGIN_FRAGMENT: { if (loginFragment != null) { valueReturn = loginFragment.onBackPressed(); - //While login, disable back. - if(valueReturn == -1) { - return; - } } break; } diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java index 7a3db18d679..f1e2b13cb32 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java @@ -22,6 +22,7 @@ import android.support.v7.widget.Toolbar; import android.text.Editable; import android.text.InputType; +import android.text.TextUtils; import android.text.TextWatcher; import android.util.DisplayMetrics; import android.util.TypedValue; @@ -56,6 +57,7 @@ import mega.privacy.android.app.lollipop.megachat.ChatSettings; import mega.privacy.android.app.providers.FileProviderActivity; import mega.privacy.android.app.utils.Constants; +import mega.privacy.android.app.utils.TL; import mega.privacy.android.app.utils.Util; import nz.mega.sdk.MegaApiAndroid; import nz.mega.sdk.MegaApiJava; @@ -867,7 +869,8 @@ else if (action.equals(Constants.ACTION_CANCEL_DOWNLOAD)) { log("No INTENT"); } - if (credentials != null){ + log("et_user.getText(): " + et_user.getText()); + if (credentials != null && TextUtils.isEmpty(et_user.getText())){ log("Credentials NOT null"); if ((intentReceived != null) && (intentReceived.getAction() != null)){ if (intentReceived.getAction().equals(Constants.ACTION_REFRESH)){ @@ -1527,6 +1530,34 @@ private void onKeysGenerated(String email, String password) { } } + public void backToLoginForm() { + loginLogin.setVisibility(View.VISIBLE); + loginCreateAccount.setVisibility(View.VISIBLE); + loginLoggingIn.setVisibility(View.GONE); + generatingKeysText.setVisibility(View.GONE); + loginProgressBar.setVisibility(View.GONE); + loginFetchNodesProgressBar.setVisibility(View.GONE); + + loginLogin.setVisibility(View.VISIBLE ); + loginCreateAccount.setVisibility(View.VISIBLE); + queryingSignupLinkText.setVisibility(View.VISIBLE); + confirmingAccountText.setVisibility(View.GONE); + loginLoggingIn.setVisibility(View.GONE); + loginProgressBar.setVisibility(View.GONE); + loginFetchNodesProgressBar.setVisibility(View.GONE); + loggingInText.setVisibility(View.VISIBLE); + fetchingNodesText.setVisibility(View.GONE); + prepareNodesText.setVisibility(View.GONE); + serversBusyText.setVisibility(View.GONE); + resumeSesion = false; + + UserCredentials credentials = dbH.getCredentials(); + if (credentials != null) { + et_user.setText(credentials.getEmail()); + et_password.requestFocus(); + } + } + private void onKeysGeneratedLogin(final String email, final String password) { log("onKeysGeneratedLogin"); @@ -1666,6 +1697,7 @@ public void onClick(View v) { log("click on button_login_login"); hidePasswordIfVisible(); loginClicked = true; + backWhileLogin = false; onLoginClick(v); break; } @@ -2160,6 +2192,11 @@ public void onRequestFinish(MegaApiJava api, MegaRequest request, MegaError erro log("onRequestFinish: " + request.getRequestString()); if (request.getType() == MegaRequest.TYPE_LOGIN){ + //cancel login process by press back. + if(!MegaApplication.isLoggingIn()) { + log("terminate login process"); + return; + } if (error.getErrorCode() != MegaError.API_OK) { MegaApplication.setLoggingIn(false); @@ -2310,6 +2347,11 @@ else if (error.getErrorCode() == MegaError.API_ENOENT){ } } else if (request.getType() == MegaRequest.TYPE_FETCH_NODES){ + //cancel login process by press back. + if(!MegaApplication.isLoggingIn()) { + log("terminate login process"); + return; + } MegaApplication.setLoggingIn(false); if (error.getErrorCode() == MegaError.API_OK){ @@ -2892,13 +2934,12 @@ public void onDestroy(){ public int onBackPressed() { log("onBackPressed"); -// backWhileLogin = true; - - //While login, disable the back. - if (loginClicked || - loginProgressBar.getVisibility() == View.VISIBLE || - loginFetchNodesProgressBar.getVisibility() == View.VISIBLE){ - return -1; + backWhileLogin = true; + if (loginClicked || MegaApplication.isLoggingIn()){ + MegaApplication.setLoggingIn(false); + loginClicked = false; + backToLoginForm(); + return 1; } else{ @@ -3106,6 +3147,7 @@ private void performLogin(){ } private static void log(String log) { - Util.log("LoginFragmentLollipop", log); +// Util.log("LoginFragmentLollipop", log); + TL.log("Login","@#@" ,log ); } } From 4f48dd3d01dd25ec328804551ddfed8578e9fb48 Mon Sep 17 00:00:00 2001 From: aw Date: Thu, 14 Feb 2019 13:42:56 +1300 Subject: [PATCH 005/117] bug#11454-press-back-when-login 1. clear code --- .../privacy/android/app/lollipop/LoginFragmentLollipop.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java index f1e2b13cb32..2d19aa4cb5f 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java @@ -57,7 +57,6 @@ import mega.privacy.android.app.lollipop.megachat.ChatSettings; import mega.privacy.android.app.providers.FileProviderActivity; import mega.privacy.android.app.utils.Constants; -import mega.privacy.android.app.utils.TL; import mega.privacy.android.app.utils.Util; import nz.mega.sdk.MegaApiAndroid; import nz.mega.sdk.MegaApiJava; @@ -3147,7 +3146,6 @@ private void performLogin(){ } private static void log(String log) { -// Util.log("LoginFragmentLollipop", log); - TL.log("Login","@#@" ,log ); + Util.log("LoginFragmentLollipop", log); } } From ff16736a9d9b708a42882088d2cde01f0a6159ec Mon Sep 17 00:00:00 2001 From: aw Date: Fri, 15 Feb 2019 11:07:55 +1300 Subject: [PATCH 006/117] bug#11454-press-back-when-login fix the bug when the account enabled 2fa --- .../app/lollipop/LoginFragmentLollipop.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java index 2d19aa4cb5f..701f5e4e417 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java @@ -520,7 +520,7 @@ else if (pinLongClick) { if (isErrorShown){ verifyQuitError(); } - permitVerify(); +// permitVerify(); } } }); @@ -563,7 +563,7 @@ else if (pinLongClick) { if (isErrorShown){ verifyQuitError(); } - permitVerify(); +// permitVerify(); } } }); @@ -1195,7 +1195,9 @@ void permitVerify(){ pin = sb.toString(); log("PIN: "+pin); if (!isErrorShown && pin != null){ + log("login with factor login"); verify2faProgressBar.setVisibility(View.VISIBLE); + MegaApplication.setLoggingIn(true); megaApi.multiFactorAuthLogin(lastEmail, lastPassword, pin, this); } } @@ -1530,6 +1532,7 @@ private void onKeysGenerated(String email, String password) { } public void backToLoginForm() { + //return to login form page loginLogin.setVisibility(View.VISIBLE); loginCreateAccount.setVisibility(View.VISIBLE); loginLoggingIn.setVisibility(View.GONE); @@ -1550,6 +1553,17 @@ public void backToLoginForm() { serversBusyText.setVisibility(View.GONE); resumeSesion = false; + //reset 2fa page + loginVerificationLayout.setVisibility(View.GONE); + verify2faProgressBar.setVisibility(View.GONE); + firstPin.setText(""); + secondPin.setText(""); + thirdPin.setText(""); + fourthPin.setText(""); + fifthPin.setText(""); + sixthPin.setText(""); + + //keep the email in login page. UserCredentials credentials = dbH.getCredentials(); if (credentials != null) { et_user.setText(credentials.getEmail()); @@ -2189,7 +2203,7 @@ public void onRequestFinish(MegaApiJava api, MegaRequest request, MegaError erro log(e.getMessage()); } - log("onRequestFinish: " + request.getRequestString()); + log("onRequestFinish: " + request.getRequestString() + ",error code: " + error.getErrorCode()); if (request.getType() == MegaRequest.TYPE_LOGIN){ //cancel login process by press back. if(!MegaApplication.isLoggingIn()) { @@ -2206,6 +2220,7 @@ public void onRequestFinish(MegaApiJava api, MegaRequest request, MegaError erro ((LoginActivityLollipop)context).showAlertLoggedOut(); } else if (error.getErrorCode() == MegaError.API_EMFAREQUIRED){ + log("require 2fa"); is2FAEnabled = true; ((LoginActivityLollipop) context).showAB(tB); loginLogin.setVisibility(View.GONE); From 166c08e30362259ef0f2f5f3cea95df95df85847 Mon Sep 17 00:00:00 2001 From: aw Date: Tue, 19 Feb 2019 11:05:26 +1300 Subject: [PATCH 007/117] bug#11454-press-back-when-login When press back while login, if the previous login is still in progress, the login button is disabled and show info to tell user what is going on. Only the previous login finished, the login button will be enabled once again. To do this is preventing the user to press login button too frequently and get a error message "Access denied". --- .../app/lollipop/LoginFragmentLollipop.java | 27 +++++++++++++++++++ app/src/main/res/layout/fragment_login.xml | 27 +++++++++++++++++-- app/src/main/res/values/strings.xml | 1 + 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java index 701f5e4e417..c4a43915cbe 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java @@ -122,6 +122,9 @@ public class LoginFragmentLollipop extends Fragment implements View.OnClickListe private TextView parkAccountSecondP; private Button parkAccountButton; + private ProgressBar loginInProgressPb; + private TextView loginInProgressInfo; + private CountDownTimer timer; private boolean firstRequestUpdate = true; @@ -360,6 +363,9 @@ public void onFocusChange(View v, boolean hasFocus) { bLogin.setText(getString(R.string.login_text).toUpperCase(Locale.getDefault())); bLogin.setOnClickListener(this); + loginInProgressPb = v.findViewById(R.id.pb_login_in_progress); + loginInProgressInfo = v.findViewById(R.id.text_login_tip); + bForgotPass = (TextView) v.findViewById(R.id.button_forgot_pass); bForgotPass.setText(getString(R.string.forgot_pass).toUpperCase(Locale.getDefault())); bForgotPass.setOnClickListener(this); @@ -1711,6 +1717,13 @@ public void onClick(View v) { hidePasswordIfVisible(); loginClicked = true; backWhileLogin = false; + //disbale it + bLogin.setBackground(context.getDrawable(R.drawable.background_button_disable)); + bLogin.setEnabled(false); + //display login info + loginInProgressPb.setVisibility(View.VISIBLE); + loginInProgressInfo.setVisibility(View.VISIBLE); + loginInProgressInfo.setText(R.string.login_in_progress); onLoginClick(v); break; } @@ -2205,6 +2218,12 @@ public void onRequestFinish(MegaApiJava api, MegaRequest request, MegaError erro log("onRequestFinish: " + request.getRequestString() + ",error code: " + error.getErrorCode()); if (request.getType() == MegaRequest.TYPE_LOGIN){ + //when get response, enable + bLogin.setEnabled(true); + bLogin.setBackground(context.getDrawable(R.drawable.background_accent_button)); + //hide login info + loginInProgressPb.setVisibility(View.GONE); + loginInProgressInfo.setVisibility(View.GONE); //cancel login process by press back. if(!MegaApplication.isLoggingIn()) { log("terminate login process"); @@ -2260,6 +2279,8 @@ else if (error.getErrorCode() == MegaError.API_EINCOMPLETE){ } else if (error.getErrorCode() == MegaError.API_EBLOCKED){ errorMessage = getString(R.string.error_account_suspended); + } else if(error.getErrorCode() == MegaError.API_EACCESS) { + errorMessage = error.getErrorString(); } else{ errorMessage = error.getErrorString(); @@ -2537,22 +2558,28 @@ public void onFinish() { log("onRequestTemporaryError:onFinish:API_EAGAIN: :value: "+error.getValue()); if(error.getValue() == MegaApiJava.RETRY_CONNECTIVITY){ serversBusyText.setText(getString(R.string.login_connectivity_issues)); + loginInProgressInfo.setText(getString(R.string.login_connectivity_issues)); } else if(error.getValue() == MegaApiJava.RETRY_SERVERS_BUSY){ serversBusyText.setText(getString(R.string.login_servers_busy)); + loginInProgressInfo.setText(getString(R.string.login_servers_busy)); } else if(error.getValue() == MegaApiJava.RETRY_API_LOCK){ serversBusyText.setText(getString(R.string.login_API_lock)); + loginInProgressInfo.setText(getString(R.string.login_API_lock)); } else if(error.getValue() == MegaApiJava.RETRY_RATE_LIMIT){ serversBusyText.setText(getString(R.string.login_API_rate)); + loginInProgressInfo.setText(getString(R.string.login_API_rate)); } else{ serversBusyText.setText(getString(R.string.servers_busy)); + loginInProgressInfo.setText(getString(R.string.servers_busy)); } } else{ serversBusyText.setText(getString(R.string.servers_busy)); + loginInProgressInfo.setText(getString(R.string.servers_busy)); } } catch (Exception e){} diff --git a/app/src/main/res/layout/fragment_login.xml b/app/src/main/res/layout/fragment_login.xml index e363918ea5d..694f2a1b8f2 100644 --- a/app/src/main/res/layout/fragment_login.xml +++ b/app/src/main/res/layout/fragment_login.xml @@ -146,14 +146,37 @@ android:textStyle="bold" android:layout_marginLeft="3dp" android:layout_marginTop="40dp" - android:layout_marginBottom="34dp" + android:layout_marginBottom="8dp" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="10dp" android:paddingBottom="10dp" style="@style/ButtonStyle" android:elevation="8dp"/> - + + + + Servers are too busy. Please wait. This process is taking longer than expected. Please wait. Too many requests. Please wait. + Login in progress. Please wait. Error. The file is corrupted or does not exist. From f29c25a9f61bc537d05cab36473a72d78c547f09 Mon Sep 17 00:00:00 2001 From: aw Date: Fri, 22 Feb 2019 12:24:47 +1300 Subject: [PATCH 008/117] bug#11454-press-back-when-login disable login button and show login info just before api.login() or api.fastlogin(). --- .../app/lollipop/LoginFragmentLollipop.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java index c4a43915cbe..c0fff3ad0e8 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java @@ -1409,6 +1409,7 @@ else if (ret == MegaChatApi.INIT_ERROR) else{ log("startFastLogin: Chat is NOT ENABLED"); } + disableLoginButton(); megaApi.fastLogin(gSession, this); } else{ @@ -1617,6 +1618,7 @@ private void onKeysGeneratedLogin(final String email, final String password) { log("onKeysGeneratedLogin: result of init ---> "+ret); if (ret ==MegaChatApi.INIT_WAITING_NEW_SESSION){ log("startFastLogin: condition ret == MegaChatApi.INIT_WAITING_NEW_SESSION"); + disableLoginButton(); megaApi.login(lastEmail, lastPassword, this); megaChatApi.enableGroupChatCalls(false); } @@ -1634,12 +1636,13 @@ private void onKeysGeneratedLogin(final String email, final String password) { log("2 - ERROR----> Switch OFF chat"); dbH.setEnabledChat(false + ""); } - + disableLoginButton(); megaApi.login(lastEmail, lastPassword, this); } } else{ log("onKeysGeneratedLogin: Chat is NOT ENABLED"); + disableLoginButton(); megaApi.login(lastEmail, lastPassword, this); } } @@ -1665,6 +1668,16 @@ private boolean validateForm() { return true; } + private void disableLoginButton() { + //disbale login button + bLogin.setBackground(context.getDrawable(R.drawable.background_button_disable)); + bLogin.setEnabled(false); + //display login info + loginInProgressPb.setVisibility(View.VISIBLE); + loginInProgressInfo.setVisibility(View.VISIBLE); + loginInProgressInfo.setText(R.string.login_in_progress); + } + public void onLoginClick(View v){ performLogin(); } @@ -1717,13 +1730,6 @@ public void onClick(View v) { hidePasswordIfVisible(); loginClicked = true; backWhileLogin = false; - //disbale it - bLogin.setBackground(context.getDrawable(R.drawable.background_button_disable)); - bLogin.setEnabled(false); - //display login info - loginInProgressPb.setVisibility(View.VISIBLE); - loginInProgressInfo.setVisibility(View.VISIBLE); - loginInProgressInfo.setText(R.string.login_in_progress); onLoginClick(v); break; } From 6812f131d2ccec3dda9023afab47eb10133dd317 Mon Sep 17 00:00:00 2001 From: aw Date: Mon, 25 Feb 2019 09:58:32 +1300 Subject: [PATCH 009/117] bug#11454-press-back-when-login 1. disable login button when login request starts(onRequestStart). 2. enable login button when login request ends(onRequestFinish). 3. logout when press back while login, otherwise chat cannot connect correctly. --- .../app/lollipop/LoginFragmentLollipop.java | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java index c0fff3ad0e8..2823e2cf755 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java @@ -44,6 +44,7 @@ import android.widget.ScrollView; import android.widget.TextView; +import java.io.File; import java.util.Locale; import mega.privacy.android.app.DatabaseHandler; @@ -1669,6 +1670,7 @@ private boolean validateForm() { } private void disableLoginButton() { + log("disable login button"); //disbale login button bLogin.setBackground(context.getDrawable(R.drawable.background_button_disable)); bLogin.setEnabled(false); @@ -1678,6 +1680,14 @@ private void disableLoginButton() { loginInProgressInfo.setText(R.string.login_in_progress); } + private void enableLoginButton() { + log("enable login button"); + bLogin.setEnabled(true); + bLogin.setBackground(context.getDrawable(R.drawable.background_accent_button)); + loginInProgressPb.setVisibility(View.GONE); + loginInProgressInfo.setVisibility(View.GONE); + } + public void onLoginClick(View v){ performLogin(); } @@ -2201,16 +2211,22 @@ else if (action.equals(Constants.ACTION_OPEN_CONTACTS_SECTION)){ public void onRequestStart(MegaApiJava api, MegaRequest request) { log("onRequestStart: " + request.getRequestString()); + if(request.getType() == MegaRequest.TYPE_LOGIN) { + disableLoginButton(); + } if (request.getType() == MegaRequest.TYPE_FETCH_NODES){ // loginProgressBar.setVisibility(View.GONE); loginFetchNodesProgressBar.setVisibility(View.VISIBLE); loginFetchNodesProgressBar.getLayoutParams().width = Util.px2dp((250*scaleW), outMetrics); loginFetchNodesProgressBar.setProgress(0); + disableLoginButton(); } } @Override public void onRequestFinish(MegaApiJava api, MegaRequest request, MegaError error) { + //when get response, enable, hide login info + enableLoginButton(); try{ if(timer!=null){ timer.cancel(); @@ -2224,15 +2240,9 @@ public void onRequestFinish(MegaApiJava api, MegaRequest request, MegaError erro log("onRequestFinish: " + request.getRequestString() + ",error code: " + error.getErrorCode()); if (request.getType() == MegaRequest.TYPE_LOGIN){ - //when get response, enable - bLogin.setEnabled(true); - bLogin.setBackground(context.getDrawable(R.drawable.background_accent_button)); - //hide login info - loginInProgressPb.setVisibility(View.GONE); - loginInProgressInfo.setVisibility(View.GONE); //cancel login process by press back. if(!MegaApplication.isLoggingIn()) { - log("terminate login process"); + log("terminate login process when login"); return; } if (error.getErrorCode() != MegaError.API_OK) { @@ -2390,7 +2400,7 @@ else if (error.getErrorCode() == MegaError.API_ENOENT){ else if (request.getType() == MegaRequest.TYPE_FETCH_NODES){ //cancel login process by press back. if(!MegaApplication.isLoggingIn()) { - log("terminate login process"); + log("terminate login process when fetch nodes"); return; } MegaApplication.setLoggingIn(false); @@ -2986,6 +2996,9 @@ public int onBackPressed() { MegaApplication.setLoggingIn(false); loginClicked = false; backToLoginForm(); + //when press back, need to logout account and chat first + megaApi.logout(); + megaChatApi.logout(this); return 1; } else{ From d05ad2b4df68db3652bb9001d3e4f225825a7451 Mon Sep 17 00:00:00 2001 From: aw Date: Thu, 28 Feb 2019 15:18:22 +1300 Subject: [PATCH 010/117] bug#10839_upload_crash 1. use CameraUploadImageProcessor to create thumbnail and preview for images and videos instead of using sdk which will block UI and lead to ANR. 2. update notification every 1 second while download and upload to release UI refresh work load. --- .../privacy/android/app/DownloadService.java | 11 +- .../privacy/android/app/UploadService.java | 73 +++++-- .../app/utils/CameraUploadImageProcessor.java | 199 ++++++++++++++++++ 3 files changed, 264 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/mega/privacy/android/app/utils/CameraUploadImageProcessor.java diff --git a/app/src/main/java/mega/privacy/android/app/DownloadService.java b/app/src/main/java/mega/privacy/android/app/DownloadService.java index d1c524dd387..7980e61de3b 100644 --- a/app/src/main/java/mega/privacy/android/app/DownloadService.java +++ b/app/src/main/java/mega/privacy/android/app/DownloadService.java @@ -133,8 +133,9 @@ public class DownloadService extends Service implements MegaTransferListenerInte MegaNode offlineNode; boolean isLoggingIn = false; + private long lastUpdated; - @SuppressLint("NewApi") + @SuppressLint("NewApi") @Override public void onCreate(){ super.onCreate(); @@ -1189,7 +1190,13 @@ else if (MimeTypeList.typeForName(currentFile.getName()).isURL()) { */ @SuppressLint("NewApi") private void updateProgressNotification() { - + //refresh UI every 1 seconds to avoid too much workload on main thread + long now = System.currentTimeMillis(); + if (now - lastUpdated > 1000) { + lastUpdated = now; + } else { + return; + } int pendingTransfers = megaApi.getNumPendingDownloads() + megaApiFolder.getNumPendingDownloads(); int totalTransfers = megaApi.getTotalDownloads() + megaApiFolder.getTotalDownloads(); diff --git a/app/src/main/java/mega/privacy/android/app/UploadService.java b/app/src/main/java/mega/privacy/android/app/UploadService.java index 722554b951f..b910feaeada 100644 --- a/app/src/main/java/mega/privacy/android/app/UploadService.java +++ b/app/src/main/java/mega/privacy/android/app/UploadService.java @@ -32,8 +32,11 @@ import java.util.Collection; import java.util.HashMap; import java.util.Iterator; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import mega.privacy.android.app.lollipop.ManagerActivityLollipop; +import mega.privacy.android.app.utils.CameraUploadImageProcessor; import mega.privacy.android.app.utils.Constants; import mega.privacy.android.app.utils.PreviewUtils; import mega.privacy.android.app.utils.ThumbnailUtils; @@ -92,6 +95,8 @@ public class UploadService extends Service implements MegaTransferListenerInterf MegaRequestListenerInterface megaRequestListener; MegaTransferListenerInterface megaTransferListener; + private ExecutorService threadPool = Executors.newCachedThreadPool(); + private int notificationId = Constants.NOTIFICATION_UPLOAD; private int notificationIdFinal = Constants.NOTIFICATION_UPLOAD_FINAL; private String notificationChannelId = Constants.NOTIFICATION_CHANNEL_UPLOAD_ID; @@ -107,7 +112,9 @@ public class UploadService extends Service implements MegaTransferListenerInterf //2 - pre-overquota int isOverquota = 0; - @SuppressLint("NewApi") + private long lastUpdated; + + @SuppressLint("NewApi") @Override public void onCreate() { super.onCreate(); @@ -167,7 +174,7 @@ public void onDestroy(){ } @Override - public int onStartCommand(Intent intent, int flags, int startId) { + public int onStartCommand(final Intent intent,int flags,int startId) { log("onStartCommand"); canceled = false; @@ -218,7 +225,7 @@ protected void onHandleIntent(final Intent intent) { if (nameInMEGAEdited != null){ switch (checkFileToUploadRenamed(file, parentHandle, nameInMEGAEdited)) { case CHECK_FILE_TO_UPLOAD_UPLOAD: { - log("CHECK_FILE_TO_UPLOAD_UPLOAD"); + log("CHECK_FILE_TO_UPLOAD_UPLOAD " + nameInMEGAEdited); if (!wl.isHeld()) { wl.acquire(); @@ -504,6 +511,13 @@ else if(errorCount>0){ @SuppressLint("NewApi") private void updateProgressNotification() { + //refresh UI every 1 seconds to avoid too much workload on main thread + long now = System.currentTimeMillis(); + if (now - lastUpdated > 1000) { + lastUpdated = now; + } else { + return; + } long progressPercent = 0; @@ -663,7 +677,7 @@ public void onTransferStart(MegaApiJava api, MegaTransfer transfer) { } @Override - public void onTransferFinish(MegaApiJava api, MegaTransfer transfer, MegaError error) { + public void onTransferFinish(final MegaApiJava api,final MegaTransfer transfer,MegaError error) { log("****onTransferFinish: " + transfer.getFileName() + " size " + transfer.getTransferredBytes()); log("transfer.getPath:" + transfer.getPath()); if(transfer.getType()==MegaTransfer.TYPE_UPLOAD) { @@ -721,12 +735,22 @@ public void onTransferFinish(MegaApiJava api, MegaTransfer transfer, MegaError e log("Is video!!!"); File previewDir = PreviewUtils.getPreviewFolder(this); - File preview = new File(previewDir, MegaApiAndroid.handleToBase64(transfer.getNodeHandle()) + ".jpg"); + final File preview = new File(previewDir, MegaApiAndroid.handleToBase64(transfer.getNodeHandle()) + ".jpg"); File thumbDir = ThumbnailUtils.getThumbFolder(this); - File thumb = new File(thumbDir, MegaApiAndroid.handleToBase64(transfer.getNodeHandle()) + ".jpg"); - megaApi.createThumbnail(transfer.getPath(), thumb.getAbsolutePath()); - megaApi.createPreview(transfer.getPath(), preview.getAbsolutePath()); - + final File thumb = new File(thumbDir, MegaApiAndroid.handleToBase64(transfer.getNodeHandle()) + ".jpg"); +// megaApi.createThumbnail(transfer.getPath(), thumb.getAbsolutePath()); +// megaApi.createPreview(transfer.getPath(), preview.getAbsolutePath()); + threadPool.execute(new Runnable() { + + @Override + public void run() { + File img = new File(transfer.getPath()); + if(!preview.exists()) { + CameraUploadImageProcessor.createVideoPreview(UploadService.this,img, preview); + } + CameraUploadImageProcessor.createVideoThumbnail(UploadService.this,api,transfer.getPath(),thumb); + } + }); MegaNode node = megaApi.getNodeByHandle(transfer.getNodeHandle()); if (node != null) { @@ -774,16 +798,28 @@ public void onTransferFinish(MegaApiJava api, MegaTransfer transfer, MegaError e else{ log("No location info"); } - } - } else if (MimeTypeList.typeForName(transfer.getPath()).isImage()) { + retriever.release(); + } + } else if (MimeTypeList.typeForName(transfer.getPath()).isImage()) { log("Is image!!!"); File previewDir = PreviewUtils.getPreviewFolder(this); - File preview = new File(previewDir, MegaApiAndroid.handleToBase64(transfer.getNodeHandle()) + ".jpg"); + final File preview = new File(previewDir, MegaApiAndroid.handleToBase64(transfer.getNodeHandle()) + ".jpg"); File thumbDir = ThumbnailUtils.getThumbFolder(this); - File thumb = new File(thumbDir, MegaApiAndroid.handleToBase64(transfer.getNodeHandle()) + ".jpg"); - megaApi.createThumbnail(transfer.getPath(), thumb.getAbsolutePath()); - megaApi.createPreview(transfer.getPath(), preview.getAbsolutePath()); + final File thumb = new File(thumbDir, MegaApiAndroid.handleToBase64(transfer.getNodeHandle()) + ".jpg"); +// megaApi.createThumbnail(transfer.getPath(), thumb.getAbsolutePath()); +// megaApi.createPreview(transfer.getPath(), preview.getAbsolutePath()); + threadPool.execute(new Runnable() { + + @Override + public void run() { + File img = new File(transfer.getPath()); + if(!preview.exists()) { + CameraUploadImageProcessor.createImagePreview(img, preview); + } + CameraUploadImageProcessor.createImageThumbnail(UploadService.this,api,transfer.getPath(),thumb); + } + }); MegaNode node = megaApi.getNodeByHandle(transfer.getNodeHandle()); if (node != null) { @@ -914,12 +950,13 @@ public void onTransferUpdate(MegaApiJava api, MegaTransfer transfer) { log("****onTransferUpdate"); if(transfer.getType()==MegaTransfer.TYPE_UPLOAD){ String appData = transfer.getAppData(); - + log("appData: " + appData); if(appData!=null){ return; } if (!transfer.isFolderTransfer()){ + log("transfer is not folder"); if (canceled) { log("Transfer cancel: " + transfer.getFileName()); @@ -942,7 +979,9 @@ public void onTransferUpdate(MegaApiJava api, MegaTransfer transfer) { mapProgressTransfers.put(transfer.getTag(), transfer); updateProgressNotification(); - } + } else { + log("transfer is folder"); + } } } diff --git a/app/src/main/java/mega/privacy/android/app/utils/CameraUploadImageProcessor.java b/app/src/main/java/mega/privacy/android/app/utils/CameraUploadImageProcessor.java new file mode 100644 index 00000000000..103cd07275b --- /dev/null +++ b/app/src/main/java/mega/privacy/android/app/utils/CameraUploadImageProcessor.java @@ -0,0 +1,199 @@ +package mega.privacy.android.app.utils; + +import android.content.ContentResolver; +import android.content.Context; +import android.database.Cursor; +import android.graphics.Bitmap; +import android.graphics.Rect; +import android.media.MediaMetadataRetriever; +import android.media.ThumbnailUtils; +import android.net.Uri; +import android.provider.BaseColumns; +import android.provider.MediaStore; + +import java.io.File; + +import nz.mega.sdk.MegaApiJava; +import nz.mega.sdk.MegaUtilsAndroid; + +import static android.provider.BaseColumns._ID; + +public class CameraUploadImageProcessor { + + private static int PREVIEW_SIZE = 1000; + + public static void createImageThumbnail(Context context,MegaApiJava api,String localPath,File dst) { + log("createImageThumbnail for: " + localPath); + boolean result = MegaUtilsAndroid.createThumbnail(new File(localPath),dst); + if (!result) { + Bitmap thumbnail = getImageThumbnailFromDB(context,localPath); + if (thumbnail == null) { + log("create thumbnail use api"); + api.createThumbnail(localPath,dst.getAbsolutePath()); + } else { + log("get from db is not null"); + nz.mega.sdk.AndroidGfxProcessor.saveBitmap(thumbnail,dst); + } + } + } + + public static void createVideoThumbnail(Context context,MegaApiJava api,String localPath,File dst) { + log("createVideoThumbnail for: " + localPath); + boolean result = MegaUtilsAndroid.createThumbnail(new File(localPath),dst); + if (!result) { + Bitmap thumbnail = getVideoThumbnailFromDB(context,localPath); + if (thumbnail == null) { + log("create thumbnail use api"); + api.createThumbnail(localPath,dst.getAbsolutePath()); + } else { + log("get from db is not null"); + nz.mega.sdk.AndroidGfxProcessor.saveBitmap(thumbnail,dst); + } + } + } + + public static boolean createImagePreview(File img,File preview) { + return MegaUtilsAndroid.createPreview(img,preview); + } + + public static boolean createVideoPreview(Context context,File video,File preview) { + if (!video.exists()) + return false; + + if (preview.exists()) + preview.delete(); + + String path = video.getAbsolutePath(); + int orientation = nz.mega.sdk.AndroidGfxProcessor.getExifOrientation(path); + Rect rect = nz.mega.sdk.AndroidGfxProcessor.getImageDimensions(path,orientation); + + int w = rect.right; + int h = rect.bottom; + + if ((w == 0) || (h == 0)) + return false; + + if (w >= PREVIEW_SIZE || h >= PREVIEW_SIZE) { + if (h > w) { + w = w * PREVIEW_SIZE / h; + h = PREVIEW_SIZE; + } else { + h = h * PREVIEW_SIZE / w; + w = PREVIEW_SIZE; + } + } + + if ((w == 0) || (h == 0)) + return false; + + Bitmap bitmap = getVideoBitmap(context,path,w,h); + return nz.mega.sdk.AndroidGfxProcessor.saveBitmap(bitmap,preview); + } + + public static Bitmap getVideoBitmap(Context context,String path,int w,int h) { + Bitmap bmThumbnail = null; + try { + bmThumbnail = ThumbnailUtils.createVideoThumbnail(path,MediaStore.Video.Thumbnails.FULL_SCREEN_KIND); + if (context != null && bmThumbnail == null) { + + String SELECTION = MediaStore.MediaColumns.DATA + "=?"; + String[] PROJECTION = {BaseColumns._ID}; + + Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; + String[] selectionArgs = {path}; + ContentResolver cr = context.getContentResolver(); + Cursor cursor = cr.query(uri,PROJECTION,SELECTION,selectionArgs,null); + if (cursor.moveToFirst()) { + long videoId = cursor.getLong(0); + bmThumbnail = MediaStore.Video.Thumbnails.getThumbnail(cr,videoId,MediaStore.Video.Thumbnails.FULL_SCREEN_KIND,null); + } + cursor.close(); + } + } catch (Exception e) { + } + + if (bmThumbnail == null) { + + MediaMetadataRetriever retriever = new MediaMetadataRetriever(); + try { + retriever.setDataSource(path); + bmThumbnail = retriever.getFrameAtTime(); + } catch (Exception e1) { + } finally { + try { + retriever.release(); + } catch (Exception ex) { + } + } + } + + if (bmThumbnail == null) { + try { + bmThumbnail = ThumbnailUtils.createVideoThumbnail(path,MediaStore.Video.Thumbnails.MINI_KIND); + if (context != null && bmThumbnail == null) { + + String SELECTION = MediaStore.MediaColumns.DATA + "=?"; + String[] PROJECTION = {BaseColumns._ID}; + + Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; + String[] selectionArgs = {path}; + ContentResolver cr = context.getContentResolver(); + Cursor cursor = cr.query(uri,PROJECTION,SELECTION,selectionArgs,null); + if (cursor.moveToFirst()) { + long videoId = cursor.getLong(0); + bmThumbnail = MediaStore.Video.Thumbnails.getThumbnail(cr,videoId,MediaStore.Video.Thumbnails.MINI_KIND,null); + } + cursor.close(); + } + } catch (Exception e2) { + } + } + + try { + if (bmThumbnail != null) { + return Bitmap.createScaledBitmap(bmThumbnail,w,h,true); + } + } catch (Exception e) { + } + return null; + } + + private static Bitmap getVideoThumbnailFromDB(Context context,String localPath) { + ContentResolver resolver = context.getContentResolver(); + Cursor cursor = resolver.query( + MediaStore.Video.Media.EXTERNAL_CONTENT_URI, + new String[] {_ID}, + MediaStore.Video.Media.DATA + "=?", + new String[] {localPath}, + null); + long id = 0; + if (cursor != null && cursor.moveToFirst()) { + log(localPath + "'s id is " + id); + id = cursor.getLong(cursor.getColumnIndex(_ID)); + cursor.close(); + return MediaStore.Video.Thumbnails.getThumbnail(resolver,id,MediaStore.Video.Thumbnails.MICRO_KIND,null); + } + return null; + } + + private static Bitmap getImageThumbnailFromDB(Context context,String localPath) { + ContentResolver resolver = context.getContentResolver(); + Cursor cursor = resolver.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, + new String[] {_ID}, + MediaStore.Images.Media.DATA + "=?", + new String[] {localPath}, + null); + long id = 0; + if (cursor != null && cursor.moveToFirst()) { + log(localPath + "'s id is " + id); + id = cursor.getLong(cursor.getColumnIndex(_ID)); + cursor.close(); + return MediaStore.Images.Thumbnails.getThumbnail(resolver,id,MediaStore.Images.Thumbnails.MICRO_KIND,null); + } + return null; + } + + private static void log(String msg) { + Util.log("CameraUploadImageProcessor",msg); + } +} \ No newline at end of file From 6258b265026dd0daa98c0de44f0e76e9bb20e71e Mon Sep 17 00:00:00 2001 From: aw Date: Thu, 28 Feb 2019 16:16:47 +1300 Subject: [PATCH 011/117] bug#10839_upload_crash change the location of UI refresh interceptor to avoid missing the notification update of over quota. --- .../mega/privacy/android/app/DownloadService.java | 14 +++++++------- .../mega/privacy/android/app/UploadService.java | 3 +-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/mega/privacy/android/app/DownloadService.java b/app/src/main/java/mega/privacy/android/app/DownloadService.java index 7980e61de3b..361ecdbb24d 100644 --- a/app/src/main/java/mega/privacy/android/app/DownloadService.java +++ b/app/src/main/java/mega/privacy/android/app/DownloadService.java @@ -1190,13 +1190,6 @@ else if (MimeTypeList.typeForName(currentFile.getName()).isURL()) { */ @SuppressLint("NewApi") private void updateProgressNotification() { - //refresh UI every 1 seconds to avoid too much workload on main thread - long now = System.currentTimeMillis(); - if (now - lastUpdated > 1000) { - lastUpdated = now; - } else { - return; - } int pendingTransfers = megaApi.getNumPendingDownloads() + megaApiFolder.getNumPendingDownloads(); int totalTransfers = megaApi.getTotalDownloads() + megaApiFolder.getTotalDownloads(); @@ -1222,6 +1215,13 @@ private void updateProgressNotification() { } if(update){ + //refresh UI every 1 seconds to avoid too much workload on main thread + long now = System.currentTimeMillis(); + if (!isOverquota && now - lastUpdated > 1000) { + lastUpdated = now; + } else { + return; + } int progressPercent = (int) Math.round((double) totalSizeTransferred / totalSizePendingTransfer * 100); log("updateProgressNotification: "+progressPercent); diff --git a/app/src/main/java/mega/privacy/android/app/UploadService.java b/app/src/main/java/mega/privacy/android/app/UploadService.java index b910feaeada..61c851c9e58 100644 --- a/app/src/main/java/mega/privacy/android/app/UploadService.java +++ b/app/src/main/java/mega/privacy/android/app/UploadService.java @@ -513,12 +513,11 @@ else if(errorCount>0){ private void updateProgressNotification() { //refresh UI every 1 seconds to avoid too much workload on main thread long now = System.currentTimeMillis(); - if (now - lastUpdated > 1000) { + if (isOverquota == 0 && now - lastUpdated > 1000) { lastUpdated = now; } else { return; } - long progressPercent = 0; Collection transfers= mapProgressTransfers.values(); From 708885099d3d16a7d6ae8333a3e9252e537e652f Mon Sep 17 00:00:00 2001 From: aw Date: Thu, 28 Feb 2019 16:32:01 +1300 Subject: [PATCH 012/117] bug#10839_upload_crash bug fix --- .../mega/privacy/android/app/DownloadService.java | 12 +++++++----- .../mega/privacy/android/app/UploadService.java | 13 ++++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/mega/privacy/android/app/DownloadService.java b/app/src/main/java/mega/privacy/android/app/DownloadService.java index 361ecdbb24d..458b3a26b1c 100644 --- a/app/src/main/java/mega/privacy/android/app/DownloadService.java +++ b/app/src/main/java/mega/privacy/android/app/DownloadService.java @@ -1216,11 +1216,13 @@ private void updateProgressNotification() { if(update){ //refresh UI every 1 seconds to avoid too much workload on main thread - long now = System.currentTimeMillis(); - if (!isOverquota && now - lastUpdated > 1000) { - lastUpdated = now; - } else { - return; + if(!isOverquota) { + long now = System.currentTimeMillis(); + if (now - lastUpdated > 1000) { + lastUpdated = now; + } else { + return; + } } int progressPercent = (int) Math.round((double) totalSizeTransferred / totalSizePendingTransfer * 100); log("updateProgressNotification: "+progressPercent); diff --git a/app/src/main/java/mega/privacy/android/app/UploadService.java b/app/src/main/java/mega/privacy/android/app/UploadService.java index 61c851c9e58..61d0e6a6f25 100644 --- a/app/src/main/java/mega/privacy/android/app/UploadService.java +++ b/app/src/main/java/mega/privacy/android/app/UploadService.java @@ -512,12 +512,15 @@ else if(errorCount>0){ @SuppressLint("NewApi") private void updateProgressNotification() { //refresh UI every 1 seconds to avoid too much workload on main thread - long now = System.currentTimeMillis(); - if (isOverquota == 0 && now - lastUpdated > 1000) { - lastUpdated = now; - } else { - return; + if(isOverquota == 0) { + long now = System.currentTimeMillis(); + if (now - lastUpdated > 1000) { + lastUpdated = now; + } else { + return; + } } + long progressPercent = 0; Collection transfers= mapProgressTransfers.values(); From fef2a285fd68871743fdabc370011ba2a91f7020 Mon Sep 17 00:00:00 2001 From: aw Date: Tue, 5 Mar 2019 10:54:34 +1300 Subject: [PATCH 013/117] bug#10839_upload_crash 1. when upload from SAF's recent, handle FileNotFoundException when the uri is no longer valid, which will lead to crash. 2. Fix the issue: progress dialog dismisses when the process is on going. --- .../mega/privacy/android/app/ShareInfo.java | 10 +++--- .../app/lollipop/ManagerActivityLollipop.java | 19 ++++------ .../android/app/utils/ProgressDialogUtil.java | 35 +++++++++++++++++++ 3 files changed, 46 insertions(+), 18 deletions(-) create mode 100644 app/src/main/java/mega/privacy/android/app/utils/ProgressDialogUtil.java diff --git a/app/src/main/java/mega/privacy/android/app/ShareInfo.java b/app/src/main/java/mega/privacy/android/app/ShareInfo.java index 8da094c1b76..f2c231c2b0f 100644 --- a/app/src/main/java/mega/privacy/android/app/ShareInfo.java +++ b/app/src/main/java/mega/privacy/android/app/ShareInfo.java @@ -3,17 +3,13 @@ import android.annotation.SuppressLint; import android.content.ClipData; import android.content.ContentProviderClient; -import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.os.RemoteException; -import android.provider.ContactsContract; import android.provider.MediaStore; -import android.text.TextUtils; import java.io.BufferedOutputStream; import java.io.File; @@ -238,7 +234,9 @@ private void processUri(Uri uri, Context context) { inputStream = null; try { inputStream = context.getContentResolver().openInputStream(uri); - } catch (Exception e) { + } catch (FileNotFoundException fileNotFound) { + return; + } catch (Exception e) { log("inputStream EXCEPTION!"); log(""+e); String path = uri.getPath(); @@ -423,7 +421,7 @@ private void processContent(Uri uri, Context context) { Cursor cursor = null; try { cursor = client.query(uri, null, null, null, null); - } catch (RemoteException e1) { + } catch (Exception e1) { log("cursor EXCEPTION!!!"); } if(cursor!=null){ diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java index 9ce7461f87e..64a89c68383 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java @@ -195,6 +195,7 @@ import mega.privacy.android.app.snackbarListeners.SnackbarNavigateOption; import mega.privacy.android.app.utils.Constants; import mega.privacy.android.app.utils.MegaApiUtils; +import mega.privacy.android.app.utils.ProgressDialogUtil; import mega.privacy.android.app.utils.Util; import mega.privacy.android.app.utils.billing.IabHelper; import mega.privacy.android.app.utils.billing.IabResult; @@ -1713,7 +1714,10 @@ protected void onCreate(Bundle savedInstanceState) { log("onCreate after call super"); boolean selectDrawerItemPending = true; - + //upload from device, progress dialog should show when screen orientation changes. + if (ProgressDialogUtil.isShowDialog) { + ProgressDialogUtil.showProcessFileDialog(this); + } if(savedInstanceState!=null){ log("Bundle is NOT NULL"); parentHandleBrowser = savedInstanceState.getLong("parentHandleBrowser", -1); @@ -13375,16 +13379,7 @@ else if (requestCode == Constants.REQUEST_CODE_GET && resultCode == RESULT_OK) { intent.setAction(Intent.ACTION_GET_CONTENT); FilePrepareTask filePrepareTask = new FilePrepareTask(this); filePrepareTask.execute(intent); - ProgressDialog temp = null; - try{ - temp = new ProgressDialog(this); - temp.setMessage(getString(R.string.upload_prepare)); - temp.show(); - } - catch(Exception e){ - return; - } - statusDialog = temp; + ProgressDialogUtil.showProcessFileDialog(this); } else if (requestCode == Constants.CHOOSE_PICTURE_PROFILE_CODE && resultCode == RESULT_OK) { @@ -14959,7 +14954,7 @@ public void onIntentProcessed(List infos) { } catch(Exception ex){} } - + ProgressDialogUtil.dissmisDialog(); long parentHandle = -1; MegaNode parentNode = null; if (drawerItem == DrawerItem.CLOUD_DRIVE){ diff --git a/app/src/main/java/mega/privacy/android/app/utils/ProgressDialogUtil.java b/app/src/main/java/mega/privacy/android/app/utils/ProgressDialogUtil.java new file mode 100644 index 00000000000..d1549aaf315 --- /dev/null +++ b/app/src/main/java/mega/privacy/android/app/utils/ProgressDialogUtil.java @@ -0,0 +1,35 @@ +package mega.privacy.android.app.utils; + +import android.app.ProgressDialog; +import android.content.Context; + +import mega.privacy.android.app.R; + +public class ProgressDialogUtil { + + private static ProgressDialog dialog; + + public static boolean isShowDialog; + + public static void showProcessFileDialog(Context context) { + isShowDialog = true; + dialog = new ProgressDialog(context){ + + @Override + public void onDetachedFromWindow() { + dismiss(); + } + }; + dialog.setCancelable(false); + dialog.setCanceledOnTouchOutside(false); + dialog.setMessage(context.getString(R.string.upload_prepare)); + dialog.show(); + } + + public static void dissmisDialog() { + isShowDialog = false; + if(dialog.isShowing()) { + dialog.dismiss(); + } + } +} From efaca7336c6abce1078ab42c3d3fb52933e42f4c Mon Sep 17 00:00:00 2001 From: aw Date: Tue, 5 Mar 2019 14:53:36 +1300 Subject: [PATCH 014/117] bug#10839_upload_crash 1. minor change for display progress dialog. 2. fix the string displaying on the progress dialog based on how many files are being processed. --- .../app/lollipop/ManagerActivityLollipop.java | 6 ++-- .../android/app/utils/ProgressDialogUtil.java | 28 +++++++++++++++---- app/src/main/res/values/strings.xml | 4 +++ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java index 64a89c68383..1e3523429f9 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java @@ -1715,8 +1715,8 @@ protected void onCreate(Bundle savedInstanceState) { boolean selectDrawerItemPending = true; //upload from device, progress dialog should show when screen orientation changes. - if (ProgressDialogUtil.isShowDialog) { - ProgressDialogUtil.showProcessFileDialog(this); + if (ProgressDialogUtil.shouldShowDialog) { + ProgressDialogUtil.showProcessFileDialog(this,null); } if(savedInstanceState!=null){ log("Bundle is NOT NULL"); @@ -13379,7 +13379,7 @@ else if (requestCode == Constants.REQUEST_CODE_GET && resultCode == RESULT_OK) { intent.setAction(Intent.ACTION_GET_CONTENT); FilePrepareTask filePrepareTask = new FilePrepareTask(this); filePrepareTask.execute(intent); - ProgressDialogUtil.showProcessFileDialog(this); + ProgressDialogUtil.showProcessFileDialog(this,intent); } else if (requestCode == Constants.CHOOSE_PICTURE_PROFILE_CODE && resultCode == RESULT_OK) { diff --git a/app/src/main/java/mega/privacy/android/app/utils/ProgressDialogUtil.java b/app/src/main/java/mega/privacy/android/app/utils/ProgressDialogUtil.java index d1549aaf315..61b1831d63f 100644 --- a/app/src/main/java/mega/privacy/android/app/utils/ProgressDialogUtil.java +++ b/app/src/main/java/mega/privacy/android/app/utils/ProgressDialogUtil.java @@ -1,7 +1,12 @@ package mega.privacy.android.app.utils; import android.app.ProgressDialog; +import android.content.ClipData; import android.content.Context; +import android.content.Intent; +import android.net.Uri; + +import java.util.ArrayList; import mega.privacy.android.app.R; @@ -9,10 +14,10 @@ public class ProgressDialogUtil { private static ProgressDialog dialog; - public static boolean isShowDialog; + public static boolean shouldShowDialog; + private static boolean isPl; - public static void showProcessFileDialog(Context context) { - isShowDialog = true; + public static void showProcessFileDialog(Context context,Intent intent) { dialog = new ProgressDialog(context){ @Override @@ -22,13 +27,24 @@ public void onDetachedFromWindow() { }; dialog.setCancelable(false); dialog.setCanceledOnTouchOutside(false); - dialog.setMessage(context.getString(R.string.upload_prepare)); + if (intent != null) { + ArrayList imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); + isPl = (imageUris != null && imageUris.size() > 1); + if (!isPl) { + ClipData clipData = intent.getClipData(); + isPl = (clipData != null && clipData.getItemCount() > 1); + } + } + int i = (isPl ? 2 : 1); + String message = context.getResources().getQuantityString(R.plurals.upload_prepare,i); + dialog.setMessage(message); + shouldShowDialog = true; dialog.show(); } public static void dissmisDialog() { - isShowDialog = false; - if(dialog.isShowing()) { + shouldShowDialog = false; + if(dialog != null && dialog.isShowing()) { dialog.dismiss(); } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4e80ca63d2a..63af117ce94 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -542,6 +542,10 @@ Do you want to cancel the upload? --> Processing file + + Processing file + Processing files + Resource temporarily not available, please try again later Cannot open selected file Upload has started From b7d068d0abce343b7368e5ef6af4fee6244a521d Mon Sep 17 00:00:00 2001 From: aw Date: Thu, 7 Mar 2019 09:35:08 +1300 Subject: [PATCH 015/117] Bug #10823 1. when uploading files has been uploaded, one snack bar including all the info. --- .../privacy/android/app/UploadService.java | 54 ++++++++++++++----- .../app/lollipop/ManagerActivityLollipop.java | 31 ++++++++--- 2 files changed, 65 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/mega/privacy/android/app/UploadService.java b/app/src/main/java/mega/privacy/android/app/UploadService.java index 61d0e6a6f25..3975f35a9e1 100644 --- a/app/src/main/java/mega/privacy/android/app/UploadService.java +++ b/app/src/main/java/mega/privacy/android/app/UploadService.java @@ -63,6 +63,7 @@ public class UploadService extends Service implements MegaTransferListenerInterf public static String EXTRA_NAME = "MEGA_FILE_NAME"; public static String EXTRA_NAME_EDITED = "MEGA_FILE_NAME_EDITED"; public static String EXTRA_SIZE = "MEGA_SIZE"; + public static String EXTRA_UPLOAD_COUNT = "EXTRA_UPLOAD_COUNT"; public static String EXTRA_PARENT_HASH = "MEGA_PARENT_HASH"; public static final int CHECK_FILE_TO_UPLOAD_UPLOAD = 1000; @@ -106,6 +107,8 @@ public class UploadService extends Service implements MegaTransferListenerInterf HashMap mapProgressTransfers; int totalUploadsCompleted = 0; int totalUploads = 0; + int uploadCount; + int currentUpload; //0 - not overquota, not pre-overquota //1 - overquota @@ -114,6 +117,8 @@ public class UploadService extends Service implements MegaTransferListenerInterf private long lastUpdated; + private StringBuilder sb = new StringBuilder(256); + @SuppressLint("NewApi") @Override public void onCreate() { @@ -177,7 +182,7 @@ public void onDestroy(){ public int onStartCommand(final Intent intent,int flags,int startId) { log("onStartCommand"); canceled = false; - + uploadCount = intent.getIntExtra(EXTRA_UPLOAD_COUNT,0); if(intent == null){ return START_NOT_STICKY; } @@ -194,13 +199,24 @@ public int onStartCommand(final Intent intent,int flags,int startId) { isOverquota = 0; onHandleIntent(intent); - + log(currentUpload +" / " + uploadCount); + if(currentUpload == uploadCount) { + log("send message"); + Intent i = new Intent(this, ManagerActivityLollipop.class); + i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + i.setAction(Constants.SHOW_REPEATED_UPLOAD); + i.putExtra("MESSAGE", sb.toString()); + startActivity(i); + //reset + currentUpload = 0; + sb = new StringBuilder(256); + } return START_NOT_STICKY; } protected void onHandleIntent(final Intent intent) { log("onHandleIntent"); - + currentUpload ++; final File file = new File(intent.getStringExtra(EXTRA_FILEPATH)); if(file!=null){ @@ -248,12 +264,18 @@ protected void onHandleIntent(final Intent intent) { String sShow = nameInMEGAEdited + " " + getString(R.string.general_already_uploaded); // Toast.makeText(getApplicationContext(), sShow,Toast.LENGTH_SHORT).show(); - Intent i = new Intent(this, ManagerActivityLollipop.class); - i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - i.setAction(Constants.SHOW_REPEATED_UPLOAD); - i.putExtra("MESSAGE", sShow); - startActivity(i); +// Intent i = new Intent(this, ManagerActivityLollipop.class); +// i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); +// i.setAction(Constants.SHOW_REPEATED_UPLOAD); +// i.putExtra("MESSAGE", sShow); +// startActivity(i); log("Return - file already uploaded"); + if(sb.length() == 0) { + sb.append(sShow); + } else { + sb.append("\n"); + sb.append(sShow); + } return; } @@ -311,11 +333,17 @@ protected void onHandleIntent(final Intent intent) { String sShow = file.getName() + " " + getString(R.string.general_already_uploaded); // Toast.makeText(getApplicationContext(), sShow,Toast.LENGTH_SHORT).show(); - Intent i = new Intent(this, ManagerActivityLollipop.class); - i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - i.setAction(Constants.SHOW_REPEATED_UPLOAD); - i.putExtra("MESSAGE", sShow); - startActivity(i); +// Intent i = new Intent(this, ManagerActivityLollipop.class); +// i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); +// i.setAction(Constants.SHOW_REPEATED_UPLOAD); +// i.putExtra("MESSAGE", sShow); +// startActivity(i); + if(sb.length() == 0) { + sb.append(sShow); + } else { + sb.append("\n"); + sb.append(sShow); + } log("Return - file already uploaded"); return; } diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java index 1e3523429f9..58a867888b3 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java @@ -63,6 +63,7 @@ import android.text.Html; import android.text.InputType; import android.text.Spanned; +import android.text.TextUtils; import android.text.TextWatcher; import android.util.DisplayMetrics; import android.util.TypedValue; @@ -3420,7 +3421,13 @@ else if (intent.getAction().equals(Constants.ACTION_TAKE_SELFIE)){ else if (intent.getAction().equals(Constants.SHOW_REPEATED_UPLOAD)){ log("onPostResume: Intent SHOW_REPEATED_UPLOAD"); String message = intent.getStringExtra("MESSAGE"); - showSnackbar(message); + int lines; + if(!TextUtils.isEmpty(message)) { + int temp = message.split("\n").length; + lines = (temp > 1) ? temp : 1; + lines = (lines > 10) ? 10 : lines; + showSnackbar(message,lines); + } } else if(getIntent().getAction().equals(Constants.ACTION_IPC)){ log("IPC - go to received request in Contacts"); @@ -9628,6 +9635,14 @@ public void showSnackbar(String s){ snackbar.show(); } + public void showSnackbar(String s,int lines){ + log("showSnackbar"); + Snackbar snackbar = Snackbar.make(fragmentContainer, s, Snackbar.LENGTH_LONG); + TextView snackbarTextView = (TextView)snackbar.getView().findViewById(android.support.design.R.id.snackbar_text); + snackbarTextView.setMaxLines(lines); + snackbar.show(); + } + public void showSnackbarNotSpace(){ log("showSnackbarNotSpace"); Snackbar mySnackbar = Snackbar.make(fragmentContainer, R.string.error_not_enough_free_space, Snackbar.LENGTH_LONG); @@ -14291,6 +14306,8 @@ public void run(){ log("EXTRA_FOLDER_PATH:" + folderPath); uploadServiceIntent.putExtra(UploadService.EXTRA_FOLDERPATH, folderPath); uploadServiceIntent.putExtra(UploadService.EXTRA_PARENT_HASH, parentNode.getHandle()); + uploadServiceIntent.putExtra(UploadService.EXTRA_UPLOAD_COUNT, paths.size()); + startService(uploadServiceIntent); } } @@ -15049,17 +15066,17 @@ else if(drawerItem == DrawerItem.ACCOUNT){ Snackbar.make(fragmentContainer, getString(R.string.upload_can_not_open), Snackbar.LENGTH_LONG).show(); } else { - for (ShareInfo info : infos) { - if(info.isContact){ - requestContactsPermissions(info, parentNode); - } + Snackbar.make(fragmentContainer, getString(R.string.upload_began), Snackbar.LENGTH_LONG).show(); + for (ShareInfo info : infos) { + if(info.isContact){ + requestContactsPermissions(info, parentNode); + } else{ - Snackbar.make(fragmentContainer, getString(R.string.upload_began), Snackbar.LENGTH_LONG).show(); Intent intent = new Intent(this, UploadService.class); intent.putExtra(UploadService.EXTRA_FILEPATH, info.getFileAbsolutePath()); intent.putExtra(UploadService.EXTRA_NAME, info.getTitle()); intent.putExtra(UploadService.EXTRA_PARENT_HASH, parentNode.getHandle()); - intent.putExtra(UploadService.EXTRA_SIZE, info.getSize()); + intent.putExtra(UploadService.EXTRA_UPLOAD_COUNT, infos.size()); startService(intent); } } From 5b05e2f60e3ddea88af4809fad1986927c0afea4 Mon Sep 17 00:00:00 2001 From: aw Date: Tue, 12 Mar 2019 11:20:45 +1300 Subject: [PATCH 016/117] bug#10839_upload_crash 1. when uploading files has been uploaded, one snack bar will show how many files has been uploaded. 2. fix the crash in TransferFragment. --- .../privacy/android/app/UploadService.java | 28 ++++++------------- .../app/lollipop/ManagerActivityLollipop.java | 16 +---------- .../TransfersFragmentLollipop.java | 2 +- 3 files changed, 11 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/mega/privacy/android/app/UploadService.java b/app/src/main/java/mega/privacy/android/app/UploadService.java index 3975f35a9e1..373b140f146 100644 --- a/app/src/main/java/mega/privacy/android/app/UploadService.java +++ b/app/src/main/java/mega/privacy/android/app/UploadService.java @@ -116,8 +116,7 @@ public class UploadService extends Service implements MegaTransferListenerInterf int isOverquota = 0; private long lastUpdated; - - private StringBuilder sb = new StringBuilder(256); + private int uploadedFileCount; @SuppressLint("NewApi") @Override @@ -200,16 +199,18 @@ public int onStartCommand(final Intent intent,int flags,int startId) { onHandleIntent(intent); log(currentUpload +" / " + uploadCount); - if(currentUpload == uploadCount) { + if(currentUpload == uploadCount && uploadedFileCount != 0) { log("send message"); Intent i = new Intent(this, ManagerActivityLollipop.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.setAction(Constants.SHOW_REPEATED_UPLOAD); - i.putExtra("MESSAGE", sb.toString()); + String file = getResources().getQuantityString(R.plurals.new_general_num_files,uploadedFileCount,uploadedFileCount); + String sShow = file + " " + getString(R.string.general_already_uploaded); + i.putExtra("MESSAGE", sShow); startActivity(i); //reset currentUpload = 0; - sb = new StringBuilder(256); + uploadedFileCount = 0; } return START_NOT_STICKY; } @@ -261,7 +262,7 @@ protected void onHandleIntent(final Intent intent) { } case CHECK_FILE_TO_UPLOAD_SAME_FILE_IN_FOLDER: { log("CHECK_FILE_TO_UPLOAD_SAME_FILE_IN_FOLDER"); - String sShow = nameInMEGAEdited + " " + getString(R.string.general_already_uploaded); + // Toast.makeText(getApplicationContext(), sShow,Toast.LENGTH_SHORT).show(); // Intent i = new Intent(this, ManagerActivityLollipop.class); @@ -270,12 +271,7 @@ protected void onHandleIntent(final Intent intent) { // i.putExtra("MESSAGE", sShow); // startActivity(i); log("Return - file already uploaded"); - if(sb.length() == 0) { - sb.append(sShow); - } else { - sb.append("\n"); - sb.append(sShow); - } + uploadedFileCount++; return; } @@ -330,7 +326,6 @@ protected void onHandleIntent(final Intent intent) { } case CHECK_FILE_TO_UPLOAD_SAME_FILE_IN_FOLDER: { log("CHECK_FILE_TO_UPLOAD_SAME_FILE_IN_FOLDER"); - String sShow = file.getName() + " " + getString(R.string.general_already_uploaded); // Toast.makeText(getApplicationContext(), sShow,Toast.LENGTH_SHORT).show(); // Intent i = new Intent(this, ManagerActivityLollipop.class); @@ -338,12 +333,7 @@ protected void onHandleIntent(final Intent intent) { // i.setAction(Constants.SHOW_REPEATED_UPLOAD); // i.putExtra("MESSAGE", sShow); // startActivity(i); - if(sb.length() == 0) { - sb.append(sShow); - } else { - sb.append("\n"); - sb.append(sShow); - } + uploadedFileCount++; log("Return - file already uploaded"); return; } diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java index 58a867888b3..4096bdff14a 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java @@ -3421,13 +3421,7 @@ else if (intent.getAction().equals(Constants.ACTION_TAKE_SELFIE)){ else if (intent.getAction().equals(Constants.SHOW_REPEATED_UPLOAD)){ log("onPostResume: Intent SHOW_REPEATED_UPLOAD"); String message = intent.getStringExtra("MESSAGE"); - int lines; - if(!TextUtils.isEmpty(message)) { - int temp = message.split("\n").length; - lines = (temp > 1) ? temp : 1; - lines = (lines > 10) ? 10 : lines; - showSnackbar(message,lines); - } + showSnackbar(message); } else if(getIntent().getAction().equals(Constants.ACTION_IPC)){ log("IPC - go to received request in Contacts"); @@ -9635,14 +9629,6 @@ public void showSnackbar(String s){ snackbar.show(); } - public void showSnackbar(String s,int lines){ - log("showSnackbar"); - Snackbar snackbar = Snackbar.make(fragmentContainer, s, Snackbar.LENGTH_LONG); - TextView snackbarTextView = (TextView)snackbar.getView().findViewById(android.support.design.R.id.snackbar_text); - snackbarTextView.setMaxLines(lines); - snackbar.show(); - } - public void showSnackbarNotSpace(){ log("showSnackbarNotSpace"); Snackbar mySnackbar = Snackbar.make(fragmentContainer, R.string.error_not_enough_free_space, Snackbar.LENGTH_LONG); diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/managerSections/TransfersFragmentLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/managerSections/TransfersFragmentLollipop.java index 0ccfd60b1e9..5888732ca8a 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/managerSections/TransfersFragmentLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/managerSections/TransfersFragmentLollipop.java @@ -255,7 +255,7 @@ public void changeStatusButton(int tag){ public void transferFinish(int position){ log("transferFinish: "+position); - if(!tL.isEmpty()){ + if(!tL.isEmpty() && position < tL.size()){ tL.remove(position); } From 9b06dbe582c8d44d6eef9550060cf53f6fc0d894 Mon Sep 17 00:00:00 2001 From: aw Date: Wed, 13 Mar 2019 09:06:28 +1300 Subject: [PATCH 017/117] bug#10839_upload_crash 1. default animator will cause NullPointerException, so don't set animator for list view. 2. turn off log. --- .../app/lollipop/managerSections/TransfersFragmentLollipop.java | 2 +- app/src/main/java/mega/privacy/android/app/utils/Util.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/managerSections/TransfersFragmentLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/managerSections/TransfersFragmentLollipop.java index 5888732ca8a..f1b210c7356 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/managerSections/TransfersFragmentLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/managerSections/TransfersFragmentLollipop.java @@ -101,7 +101,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, mLayoutManager = new LinearLayoutManager(context); listView.setLayoutManager(mLayoutManager); listView.setHasFixedSize(true); - listView.setItemAnimator(new DefaultItemAnimator()); + listView.setItemAnimator(null); listView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { diff --git a/app/src/main/java/mega/privacy/android/app/utils/Util.java b/app/src/main/java/mega/privacy/android/app/utils/Util.java index 225f8040b25..ec1aa4c0eb8 100644 --- a/app/src/main/java/mega/privacy/android/app/utils/Util.java +++ b/app/src/main/java/mega/privacy/android/app/utils/Util.java @@ -114,7 +114,7 @@ public class Util { public static double percScreenLoginReturning = 0.8; // Debug flag to enable logging and some other things - public static boolean DEBUG = true; + public static boolean DEBUG = false; public static String mainDIR = "/MEGA"; public static String offlineDIR = "MEGA/MEGA Offline"; From b0cf0613aae8f0a86a1cabbc33280381c4592796 Mon Sep 17 00:00:00 2001 From: aw Date: Thu, 14 Mar 2019 11:01:54 +1300 Subject: [PATCH 018/117] bug#11454-press-back-when-login 1. Fix NullPoniterException in BaseActivity which will cause crash. 2. Remove extra logout operation when press back. Instead, execute re-login process to keep this login right. 3. When press back after fetchNodes has launched, need to re-login, otherwise chat cannot connect correctly. 4. Press login button on landing page will go to login form page instead of login automatically. --- .../privacy/android/app/BaseActivity.java | 10 +++++++--- .../app/lollipop/LoginActivityLollipop.java | 5 ++++- .../app/lollipop/LoginFragmentLollipop.java | 19 ++++++------------- .../app/lollipop/ManagerActivityLollipop.java | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/mega/privacy/android/app/BaseActivity.java b/app/src/main/java/mega/privacy/android/app/BaseActivity.java index 8c89bc8e585..2b733210a89 100644 --- a/app/src/main/java/mega/privacy/android/app/BaseActivity.java +++ b/app/src/main/java/mega/privacy/android/app/BaseActivity.java @@ -34,6 +34,7 @@ import nz.mega.sdk.MegaApiAndroid; import nz.mega.sdk.MegaChatApiAndroid; import nz.mega.sdk.MegaChatCall; +import nz.mega.sdk.MegaChatPresenceConfig; import nz.mega.sdk.MegaChatRoom; import nz.mega.sdk.MegaHandleList; @@ -153,9 +154,12 @@ public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) { if (intent != null) { log("BROADCAST TO SEND SIGNAL PRESENCE"); - if(delaySignalPresence && megaChatApi.getPresenceConfig().isPending()==false){ - delaySignalPresence = false; - retryConnectionsAndSignalPresence(); + MegaChatPresenceConfig config = megaChatApi.getPresenceConfig(); + if(config != null) { + if(delaySignalPresence && !config.isPending()){ + delaySignalPresence = false; + retryConnectionsAndSignalPresence(); + } } } } diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/LoginActivityLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/LoginActivityLollipop.java index 30b8fc29a41..be635bc301f 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/LoginActivityLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/LoginActivityLollipop.java @@ -100,6 +100,9 @@ public class LoginActivityLollipop extends BaseActivity implements MegaGlobalLis String firstNameTemp = null; String lastNameTemp = null; + static boolean isBackFromLoginPage; + static boolean isFetchedNodes; + private BroadcastReceiver updateMyAccountReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -198,7 +201,7 @@ protected void onCreate(Bundle savedInstanceState) { } LocalBroadcastManager.getInstance(this).registerReceiver(updateMyAccountReceiver, new IntentFilter(Constants.BROADCAST_ACTION_INTENT_UPDATE_ACCOUNT_DETAILS)); - + isBackFromLoginPage = false; showFragment(visibleFragment); } diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java index be3abe572f6..2b5372d6a88 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java @@ -22,7 +22,6 @@ import android.support.v7.widget.Toolbar; import android.text.Editable; import android.text.InputType; -import android.text.TextUtils; import android.text.TextWatcher; import android.util.DisplayMetrics; import android.util.TypedValue; @@ -44,7 +43,6 @@ import android.widget.ScrollView; import android.widget.TextView; -import java.io.File; import java.util.Locale; import mega.privacy.android.app.DatabaseHandler; @@ -876,7 +874,7 @@ else if (action.equals(Constants.ACTION_CANCEL_DOWNLOAD)) { } log("et_user.getText(): " + et_user.getText()); - if (credentials != null && TextUtils.isEmpty(et_user.getText())){ + if (credentials != null && !((LoginActivityLollipop) context).isBackFromLoginPage){ log("Credentials NOT null"); if ((intentReceived != null) && (intentReceived.getAction() != null)){ if (intentReceived.getAction().equals(Constants.ACTION_REFRESH)){ @@ -998,7 +996,7 @@ else if (action.equals(Constants.ACTION_OPEN_CONTACTS_SECTION)){ } else{ MegaNode rootNode = megaApi.getRootNode(); - if (rootNode != null){ + if (rootNode != null && !((LoginActivityLollipop)context).isFetchedNodes){ log("rootNode != null"); Intent intent = new Intent(context, ManagerActivityLollipop.class); @@ -1563,12 +1561,7 @@ public void backToLoginForm() { fifthPin.setText(""); sixthPin.setText(""); - //keep the email in login page. - UserCredentials credentials = dbH.getCredentials(); - if (credentials != null) { - et_user.setText(credentials.getEmail()); - et_password.requestFocus(); - } + et_user.requestFocus(); } private void onKeysGeneratedLogin(final String email, final String password) { @@ -2211,6 +2204,7 @@ public void onRequestStart(MegaApiJava api, MegaRequest request) loginFetchNodesProgressBar.setVisibility(View.VISIBLE); loginFetchNodesProgressBar.getLayoutParams().width = Util.px2dp((250*scaleW), outMetrics); loginFetchNodesProgressBar.setProgress(0); + ((LoginActivityLollipop)context).isFetchedNodes = true; disableLoginButton(); } } @@ -2395,6 +2389,7 @@ else if (request.getType() == MegaRequest.TYPE_FETCH_NODES){ log("terminate login process when fetch nodes"); return; } + ((LoginActivityLollipop)context).isFetchedNodes = false; MegaApplication.setLoggingIn(false); if (error.getErrorCode() == MegaError.API_OK){ @@ -2982,9 +2977,6 @@ public int onBackPressed() { MegaApplication.setLoggingIn(false); loginClicked = false; backToLoginForm(); - //when press back, need to logout account and chat first - megaApi.logout(); - megaChatApi.logout(this); return 1; } else{ @@ -3001,6 +2993,7 @@ public int onBackPressed() { return 1; } + ((LoginActivityLollipop) context).isBackFromLoginPage = true; ((LoginActivityLollipop) context).showFragment(Constants.TOUR_FRAGMENT); return 1; } diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java index 81855a1270e..d4b6068529d 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java @@ -2269,7 +2269,7 @@ public void onPageScrollStateChanged(int state) { } rootNode = megaApi.getRootNode(); - if (rootNode == null){ + if (rootNode == null || LoginActivityLollipop.isBackFromLoginPage){ if (getIntent() != null){ log("Action: "+getIntent().getAction()); if (getIntent().getAction() != null){ From 9eb76b50ccc89932ed999bb1d23bc4078941206f Mon Sep 17 00:00:00 2001 From: aw Date: Thu, 14 Mar 2019 13:19:55 +1300 Subject: [PATCH 019/117] bug#11454-press-back-when-login 1. logout chat when press back, to make sure chat can init correctly when login. --- .../mega/privacy/android/app/lollipop/LoginFragmentLollipop.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java index 2b5372d6a88..6626ef7cee5 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java @@ -2977,6 +2977,7 @@ public int onBackPressed() { MegaApplication.setLoggingIn(false); loginClicked = false; backToLoginForm(); + megaChatApi.logout(); return 1; } else{ From ac05bb7a9537222f3cc53901cf6b7f93359f5ca5 Mon Sep 17 00:00:00 2001 From: aw Date: Mon, 25 Mar 2019 10:49:10 +1300 Subject: [PATCH 020/117] bug#11454-press-back-when-login remove unused and duplicated code. --- .../android/app/lollipop/LoginFragmentLollipop.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java index 6626ef7cee5..4e23c798bb6 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/LoginFragmentLollipop.java @@ -525,7 +525,6 @@ else if (pinLongClick) { if (isErrorShown){ verifyQuitError(); } -// permitVerify(); } } }); @@ -568,7 +567,6 @@ else if (pinLongClick) { if (isErrorShown){ verifyQuitError(); } -// permitVerify(); } } }); @@ -1538,13 +1536,8 @@ public void backToLoginForm() { loginProgressBar.setVisibility(View.GONE); loginFetchNodesProgressBar.setVisibility(View.GONE); - loginLogin.setVisibility(View.VISIBLE ); - loginCreateAccount.setVisibility(View.VISIBLE); queryingSignupLinkText.setVisibility(View.VISIBLE); confirmingAccountText.setVisibility(View.GONE); - loginLoggingIn.setVisibility(View.GONE); - loginProgressBar.setVisibility(View.GONE); - loginFetchNodesProgressBar.setVisibility(View.GONE); loggingInText.setVisibility(View.VISIBLE); fetchingNodesText.setVisibility(View.GONE); prepareNodesText.setVisibility(View.GONE); From 4d2be5ca18665bf552cc424e12331e0f92e6f1ef Mon Sep 17 00:00:00 2001 From: Yenel Rodriguez Date: Mon, 25 Mar 2019 15:59:21 +0100 Subject: [PATCH 021/117] Task #11703-Show an error in ''Open link' dialog if the link typed isn't file or folder link. If the link typed is other type of MEGA link, show a suggestion to open it. --- .../privacy/android/app/BaseActivity.java | 7 + .../app/lollipop/ManagerActivityLollipop.java | 319 +++++++----------- .../lollipop/controllers/NodeController.java | 39 ++- .../megachat/AndroidMegaRichLinkMessage.java | 8 + .../SnackbarNavigateOption.java | 22 ++ .../privacy/android/app/utils/Constants.java | 1 + ...pen_chat_link.xml => dialog_open_link.xml} | 20 +- app/src/main/res/values/strings.xml | 5 + 8 files changed, 184 insertions(+), 237 deletions(-) rename app/src/main/res/layout/{dialog_open_chat_link.xml => dialog_open_link.xml} (84%) diff --git a/app/src/main/java/mega/privacy/android/app/BaseActivity.java b/app/src/main/java/mega/privacy/android/app/BaseActivity.java index a94846c3924..1a20f6da781 100644 --- a/app/src/main/java/mega/privacy/android/app/BaseActivity.java +++ b/app/src/main/java/mega/privacy/android/app/BaseActivity.java @@ -26,6 +26,7 @@ import java.util.ArrayList; +import mega.privacy.android.app.lollipop.ManagerActivityLollipop; import mega.privacy.android.app.lollipop.listeners.MultipleAttachChatListener; import mega.privacy.android.app.lollipop.megachat.calls.ChatCallActivity; import mega.privacy.android.app.snackbarListeners.SnackbarNavigateOption; @@ -351,6 +352,12 @@ else if (snackbarLayout.getLayoutParams() instanceof FrameLayout.LayoutParams) { snackbar.show(); break; } + case Constants.OPEN_LINK_SNACKBAR_TYPE: { + if (view.getContext() instanceof ManagerActivityLollipop) { + snackbar.setAction(R.string.context_open_link, new SnackbarNavigateOption(view.getContext(), ((ManagerActivityLollipop) view.getContext()).getLinkUrlDialog())); + } + snackbar.show(); + } } } diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java b/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java index 743e20995eb..51cf9fe5762 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/ManagerActivityLollipop.java @@ -191,7 +191,6 @@ import mega.privacy.android.app.modalbottomsheet.TransfersBottomSheetDialogFragment; import mega.privacy.android.app.modalbottomsheet.UploadBottomSheetDialogFragment; import mega.privacy.android.app.modalbottomsheet.chatmodalbottomsheet.ChatBottomSheetDialogFragment; -import mega.privacy.android.app.snackbarListeners.SnackbarNavigateOption; import mega.privacy.android.app.utils.ChatUtil; import mega.privacy.android.app.utils.Constants; import mega.privacy.android.app.utils.MegaApiUtils; @@ -647,9 +646,9 @@ public String getTitle(Context context) { private boolean onAskingPermissionsFragment = false; - private AlertDialog openchatLinkDialog; - private EditText openChatLinkText; - private RelativeLayout openChatLinkError; + private String openLinkUrl; + private EditText openLinkText; + private RelativeLayout openLinkError; private BroadcastReceiver updateMyAccountReceiver = new BroadcastReceiver() { @Override @@ -2789,12 +2788,7 @@ else if (getIntent().getAction().equals(Constants.ACTION_IMPORT_LINK_FETCH_NODES } else if (getIntent().getAction().equals(Constants.ACTION_OPEN_CONTACTS_SECTION)){ markNotificationsSeen(true); - - handleInviteContact = getIntent().getLongExtra("handle", 0); - - drawerItem = DrawerItem.CONTACTS; - indexContacts = 0; - selectDrawerItemLollipop(drawerItem); + openContactLink(getIntent().getLongExtra("handle", 0)); } else if (getIntent().getAction().equals(Constants.ACTION_REFRESH_STAGING)){ update2FASetting(); @@ -3011,6 +3005,15 @@ else if(getIntent().getAction().equals(Constants.ACTION_SHOW_SNACKBAR_SENT_AS_ME log("END onCreate"); } + public void openContactLink (long handle) { + dismissOpenLinkDialog(); + handleInviteContact = handle; + log("openContactLink Handle to invite a contact: "+handle); + drawerItem = DrawerItem.CONTACTS; + indexContacts = 0; + selectDrawerItemLollipop(drawerItem); + } + void askForAccess () { boolean writeStorageGranted = checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE); boolean readStorageGranted = checkPermission(Manifest.permission.READ_EXTERNAL_STORAGE); @@ -3589,12 +3592,7 @@ else if(getIntent().getAction().equals(Constants.ACTION_INCOMING_SHARED_FOLDER_N else if(getIntent().getAction().equals(Constants.ACTION_OPEN_CONTACTS_SECTION)){ log("onPostResume: ACTION_OPEN_CONTACTS_SECTION"); markNotificationsSeen(true); - - handleInviteContact = getIntent().getLongExtra("handle", 0); - - drawerItem = DrawerItem.CONTACTS; - indexContacts = 0; - selectDrawerItemLollipop(drawerItem); + openContactLink(getIntent().getLongExtra("handle", 0)); } else if (getIntent().getAction().equals(Constants.ACTION_RECOVERY_KEY_EXPORTED)){ log("onPostResume: ACTION_RECOVERY_KEY_EXPORTED"); @@ -5789,7 +5787,6 @@ public void selectDrawerItemLollipop(DrawerItem item){ case CONTACTS:{ showHideBottomNavigationView(true); selectDrawerItemContacts(); - supportInvalidateOptionsMenu(); showFabButton(); break; } @@ -7014,11 +7011,15 @@ else if (drawerItem == DrawerItem.CONTACTS){ sortByMenuItem.setVisible(false); } if (handleInviteContact != 0) { + log("onCreateOptionsMenu Handle to invite a contact: "+handleInviteContact); if (cFLol != null) { cFLol.invite(handleInviteContact); } handleInviteContact = 0; } + else { + log("onCreateOptionsMenu Handle to invite a contact: "+handleInviteContact); + } //Hide searchByDate.setVisible(false); @@ -7825,12 +7826,7 @@ else if (drawerItem == DrawerItem.ACCOUNT){ return true; } case R.id.action_import_link:{ - if (drawerItem == DrawerItem.CLOUD_DRIVE) { - showImportLinkDialog(); - } - else if (drawerItem == DrawerItem.CHAT) { - showOpenChatLinkDialog(); - } + showOpenLinkDialog(); return true; } case R.id.action_take_picture:{ @@ -10934,39 +10930,85 @@ void permitVerify(int type){ } } - void showOpenChatLinkError(boolean show) { - if (openchatLinkDialog != null) { + void showOpenLinkError(boolean show) { + if (openLinkDialog != null) { if (show) { - openChatLinkText.setTextColor(ContextCompat.getColor(this, R.color.dark_primary_color)); - openChatLinkText.getBackground().mutate().clearColorFilter(); - openChatLinkText.getBackground().mutate().setColorFilter(ContextCompat.getColor(this, R.color.dark_primary_color), PorterDuff.Mode.SRC_ATOP); - openChatLinkError.setVisibility(View.VISIBLE); + openLinkText.setTextColor(ContextCompat.getColor(this, R.color.dark_primary_color)); + openLinkText.getBackground().mutate().clearColorFilter(); + openLinkText.getBackground().mutate().setColorFilter(ContextCompat.getColor(this, R.color.dark_primary_color), PorterDuff.Mode.SRC_ATOP); + openLinkError.setVisibility(View.VISIBLE); } else { - if (openChatLinkError.getVisibility() == View.VISIBLE) { - openChatLinkText.setTextColor(ContextCompat.getColor(this, R.color.name_my_account)); - openChatLinkText.getBackground().mutate().clearColorFilter(); - openChatLinkText.getBackground().mutate().setColorFilter(ContextCompat.getColor(this, R.color.accentColor), PorterDuff.Mode.SRC_ATOP); - openChatLinkError.setVisibility(View.GONE); + if (openLinkError.getVisibility() == View.VISIBLE) { + openLinkText.setTextColor(ContextCompat.getColor(this, R.color.name_my_account)); + openLinkText.getBackground().mutate().clearColorFilter(); + openLinkText.getBackground().mutate().setColorFilter(ContextCompat.getColor(this, R.color.accentColor), PorterDuff.Mode.SRC_ATOP); + openLinkError.setVisibility(View.GONE); } } } } - void dismissOpenChatLinkDialog() { + void dismissOpenLinkDialog() { try { - openchatLinkDialog.dismiss(); + openLinkDialog.dismiss(); } catch (Exception e) {} } - public void showOpenChatLinkDialog() { + void openLink (String link) { + if (drawerItem == DrawerItem.CLOUD_DRIVE) { + int error = nC.importLink(link); + switch (error) { + case 1: { + log("Do nothing: correct file link"); + dismissOpenLinkDialog(); + break; + } + case 2: { + log("Do nothing: correct folder link"); + dismissOpenLinkDialog(); + break; + } + case 3: { + log("Show error: correct chat link"); + openLinkUrl = link; + showSnackbar(Constants.OPEN_LINK_SNACKBAR_TYPE, openLinkDialog.getCurrentFocus(), getString(R.string.valid_chat_link), -1); + showOpenLinkError(true); + break; + } + case 4: { + log("Show error: correct contact link"); + openLinkUrl = link; + showSnackbar(Constants.OPEN_LINK_SNACKBAR_TYPE, openLinkDialog.getCurrentFocus(), getString(R.string.valid_contact_link), -1); + showOpenLinkError(true); + break; + } + case -1: { + log("Show error: invalid link"); + showOpenLinkError(true); + break; + } + } + } + else if (drawerItem == DrawerItem.CHAT) { + megaChatApi.checkChatLink(link, managerActivity); + } + } + + public String getLinkUrlDialog () { + return openLinkUrl; + } + + public void showOpenLinkDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); LayoutInflater inflater = getLayoutInflater(); - View v = inflater.inflate(R.layout.dialog_open_chat_link, null); + View v = inflater.inflate(R.layout.dialog_open_link, null); builder.setView(v); - openChatLinkText = (EditText) v.findViewById(R.id.chat_link_text); - openChatLinkText.addTextChangedListener(new TextWatcher() { + TextView title = (TextView) v.findViewById(R.id.link_title); + + openLinkText = (EditText) v.findViewById(R.id.link_text); + openLinkText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -10979,202 +11021,67 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { @Override public void afterTextChanged(Editable s) { - showOpenChatLinkError(false); + showOpenLinkError(false); } }); - openChatLinkText.setOnEditorActionListener(new OnEditorActionListener() { + openLinkText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { - megaChatApi.checkChatLink(openChatLinkText.getText().toString(), managerActivity); + Util.hideKeyboardView(managerActivity, v, 0); + openLink(openLinkText.getText().toString()); return true; } return false; } }); - openChatLinkError = (RelativeLayout) v.findViewById(R.id.chat_link_error); - openChatLinkError.setVisibility(View.GONE); + openLinkError = (RelativeLayout) v.findViewById(R.id.link_error); + openLinkError.setVisibility(View.GONE); + TextView errorText = (TextView) v.findViewById(R.id.link_error_text); + + if (drawerItem == DrawerItem.CLOUD_DRIVE) { + title.setText(R.string.action_open_link); + openLinkText.setHint(R.string.hint_paste_link); + errorText.setText(R.string.invalid_file_folder_link); + } + else if (drawerItem == DrawerItem.CHAT) { + title.setText(R.string.action_open_chat_link); + openLinkText.setHint(R.string.hint_enter_chat_link); + errorText.setText(R.string.invalid_chat_link_args); + } OnClickListener clickListener = new OnClickListener() { @Override public void onClick(View v) { switch (v.getId()) { - case R.id.chat_link_cancel_button: { - dismissOpenChatLinkDialog(); + case R.id.link_cancel_button: { + dismissOpenLinkDialog(); break; } - case R.id.chat_link_open_button: { - megaChatApi.checkChatLink(openChatLinkText.getText().toString(), managerActivity); + case R.id.link_open_button: { + Util.hideKeyboardView(managerActivity, v, 0); + openLink(openLinkText.getText().toString()); break; } } } }; - Button cancelButton = (Button) v.findViewById(R.id.chat_link_cancel_button); + Button cancelButton = (Button) v.findViewById(R.id.link_cancel_button); cancelButton.setOnClickListener(clickListener); - Button openButton = (Button) v.findViewById(R.id.chat_link_open_button); + Button openButton = (Button) v.findViewById(R.id.link_open_button); openButton.setOnClickListener(clickListener); - openchatLinkDialog = builder.create(); - openchatLinkDialog.setCanceledOnTouchOutside(false); + openLinkDialog = builder.create(); + openLinkDialog.setCanceledOnTouchOutside(false); try { - openchatLinkDialog.show(); + openLinkDialog.show(); }catch (Exception e){} } - public void showImportLinkDialog(){ - log("showImportLinkDialog"); - LinearLayout layout = new LinearLayout(this); - layout.setOrientation(LinearLayout.VERTICAL); - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); - params.setMargins(Util.scaleWidthPx(20, outMetrics), Util.scaleWidthPx(20, outMetrics), Util.scaleWidthPx(17, outMetrics), 0); - - final EditText input = new EditText(this); -// input.setId(EDIT_TEXT_ID); - input.setSingleLine(false); - - input.setTextColor(ContextCompat.getColor(this, R.color.text_secondary)); - input.setImeOptions(EditorInfo.IME_ACTION_DONE); - input.getBackground().mutate().clearColorFilter(); - input.getBackground().mutate().setColorFilter(ContextCompat.getColor(this, R.color.accentColor), PorterDuff.Mode.SRC_ATOP); - layout.addView(input, params); - input.setImeActionLabel(getString(R.string.context_open_link_title),EditorInfo.IME_ACTION_DONE); - - - LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); - params1.setMargins(Util.scaleWidthPx(20, outMetrics), 0, Util.scaleWidthPx(17, outMetrics), 0); - - final RelativeLayout error_layout = new RelativeLayout(ManagerActivityLollipop.this); - layout.addView(error_layout, params1); - - final ImageView error_icon = new ImageView(ManagerActivityLollipop.this); - error_icon.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_input_warning)); - error_layout.addView(error_icon); - RelativeLayout.LayoutParams params_icon = (RelativeLayout.LayoutParams) error_icon.getLayoutParams(); - -// params_icon.width = Util.scaleWidthPx(24, outMetrics); -// params_icon.width = 80; -// params_icon.height = Util.scaleHeightPx(24, outMetrics); -// params_icon.height = 80; - params_icon.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); - error_icon.setLayoutParams(params_icon); - - error_icon.setColorFilter(ContextCompat.getColor(ManagerActivityLollipop.this, R.color.login_warning)); - - final TextView textError = new TextView(ManagerActivityLollipop.this); - error_layout.addView(textError); - RelativeLayout.LayoutParams params_text_error = (RelativeLayout.LayoutParams) textError.getLayoutParams(); - params_text_error.height = ViewGroup.LayoutParams.WRAP_CONTENT; - params_text_error.width = ViewGroup.LayoutParams.WRAP_CONTENT; - params_text_error.addRule(RelativeLayout.CENTER_VERTICAL); - params_text_error.addRule(RelativeLayout.ALIGN_PARENT_LEFT); - params_text_error.setMargins(Util.scaleWidthPx(3, outMetrics), 0,0,0); - textError.setLayoutParams(params_text_error); - - textError.setTextColor(ContextCompat.getColor(ManagerActivityLollipop.this, R.color.login_warning)); - - error_layout.setVisibility(View.GONE); - - input.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { - - } - - @Override - public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { - - } - - @Override - public void afterTextChanged(Editable editable) { - if(error_layout.getVisibility() == View.VISIBLE){ - error_layout.setVisibility(View.GONE); - input.getBackground().mutate().clearColorFilter(); - input.getBackground().mutate().setColorFilter(ContextCompat.getColor(managerActivity, R.color.accentColor), PorterDuff.Mode.SRC_ATOP); - } - } - }); - - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(getString(R.string.context_open_link_title)); - builder.setPositiveButton(getString(R.string.context_open_link), - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - String value = input.getText().toString().trim(); - if (value.length() == 0) { - return; - } - - try{ - openLinkDialog.dismiss(); - } - catch(Exception e){} - nC.importLink(value); - } - }); - builder.setNegativeButton(getString(android.R.string.cancel), null); - builder.setView(layout); - openLinkDialog = builder.create(); - openLinkDialog.show(); - - input.setOnEditorActionListener(new OnEditorActionListener() { - @Override - public boolean onEditorAction(TextView v, int actionId, - KeyEvent event) { - if (actionId == EditorInfo.IME_ACTION_DONE) { - - String value = v.getText().toString().trim(); - if (value.length() == 0) { - input.getBackground().mutate().setColorFilter(ContextCompat.getColor(managerActivity, R.color.login_warning), PorterDuff.Mode.SRC_ATOP); - textError.setText(getString(R.string.invalid_string)); - error_layout.setVisibility(View.VISIBLE); - input.requestFocus(); - return true; - } - nC.importLink(value); - try{ - openLinkDialog.dismiss(); - } - catch(Exception e){} - return true; - } - try{ - openLinkDialog.dismiss(); - } - catch(Exception e){} - return false; - } - }); - - openLinkDialog.getButton(android.support.v7.app.AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() - { - @Override - public void onClick(View v) - { - String value = input.getText().toString().trim(); - if (value.length() == 0) { - input.getBackground().mutate().setColorFilter(ContextCompat.getColor(managerActivity, R.color.login_warning), PorterDuff.Mode.SRC_ATOP); - textError.setText(getString(R.string.invalid_string)); - error_layout.setVisibility(View.VISIBLE); - input.requestFocus(); - return; - } - - try{ - openLinkDialog.dismiss(); - } - catch(Exception e){} - - nC.importLink(value); - } - }); - } - public void showChatLink(String link){ log("showChatLink: "+link); Intent openChatLinkIntent = new Intent(this, ChatActivityLollipop.class); @@ -15563,15 +15470,15 @@ else if(!chatTitle.isEmpty() && chatTitle.length()>60){ else if(request.getType() == MegaChatRequest.TYPE_LOAD_PREVIEW){ if(e.getErrorCode()==MegaChatError.ERROR_OK || e.getErrorCode() == MegaChatError.ERROR_EXIST){ showChatLink(request.getLink()); - dismissOpenChatLinkDialog(); + dismissOpenLinkDialog(); } else { if(e.getErrorCode()==MegaChatError.ERROR_NOENT){ - dismissOpenChatLinkDialog(); + dismissOpenLinkDialog(); Util.showAlert(this, getString(R.string.invalid_chat_link), getString(R.string.title_alert_chat_link_error)); } else { - showOpenChatLinkError(true); + showOpenLinkError(true); } } } diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/controllers/NodeController.java b/app/src/main/java/mega/privacy/android/app/lollipop/controllers/NodeController.java index b814e645143..3bd25ca35d1 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/controllers/NodeController.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/controllers/NodeController.java @@ -48,6 +48,7 @@ import mega.privacy.android.app.lollipop.listeners.CopyAndSendToChatListener; import mega.privacy.android.app.lollipop.listeners.MultipleRequestListener; import mega.privacy.android.app.lollipop.managerSections.MyAccountFragmentLollipop; +import mega.privacy.android.app.lollipop.megachat.AndroidMegaRichLinkMessage; import mega.privacy.android.app.lollipop.megachat.ChatExplorerActivity; import mega.privacy.android.app.utils.Constants; import mega.privacy.android.app.utils.MegaApiUtils; @@ -1122,12 +1123,15 @@ public void renameNode(MegaNode document, String newName){ megaApi.renameNode(document, newName, ((ManagerActivityLollipop) context)); } - public void importLink(String url) { - + public int importLink(String url) { try { url = URLDecoder.decode(url, "UTF-8"); } - catch (UnsupportedEncodingException e) {} + catch (Exception e) { + log("Error decoding URL: " + url); + log(e.toString()); + } + url.replace(' ', '+'); if(url.startsWith("mega://")){ url = url.replace("mega://", "https://mega.co.nz/"); @@ -1136,36 +1140,31 @@ public void importLink(String url) { log("url " + url); // Download link - if (url != null && (url.matches("^https://mega.co.nz/#!.*!.*$") || url.matches("^https://mega.nz/#!.*!.*$"))) { - log("open link url"); - -// Intent openIntent = new Intent(this, ManagerActivityLollipop.class); + if (AndroidMegaRichLinkMessage.isFileLink(url)) { Intent openFileIntent = new Intent(context, FileLinkActivityLollipop.class); openFileIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); openFileIntent.setAction(Constants.ACTION_OPEN_MEGA_LINK); openFileIntent.setData(Uri.parse(url)); ((ManagerActivityLollipop) context).startActivity(openFileIntent); -// finish(); - return; + return 1; } - - // Folder Download link - else if (url != null && (url.matches("^https://mega.co.nz/#F!.+$") || url.matches("^https://mega.nz/#F!.+$"))) { - log("folder link url"); + else if (AndroidMegaRichLinkMessage.isFolderLink(url)) { Intent openFolderIntent = new Intent(context, FolderLinkActivityLollipop.class); openFolderIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); openFolderIntent.setAction(Constants.ACTION_OPEN_MEGA_FOLDER_LINK); openFolderIntent.setData(Uri.parse(url)); ((ManagerActivityLollipop) context).startActivity(openFolderIntent); -// finish(); - return; + return 2; } - else{ - log("wrong url"); - Intent errorIntent = new Intent(context, ManagerActivityLollipop.class); - errorIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - ((ManagerActivityLollipop) context).startActivity(errorIntent); + else if (AndroidMegaRichLinkMessage.isChatLink(url)) { + return 3; + } + else if (AndroidMegaRichLinkMessage.isContactLink(url)) { + return 4; } + + log("wrong url"); + return -1; } //old getPublicLinkAndShareIt diff --git a/app/src/main/java/mega/privacy/android/app/lollipop/megachat/AndroidMegaRichLinkMessage.java b/app/src/main/java/mega/privacy/android/app/lollipop/megachat/AndroidMegaRichLinkMessage.java index 118dc6e07c1..6737f6cc52f 100644 --- a/app/src/main/java/mega/privacy/android/app/lollipop/megachat/AndroidMegaRichLinkMessage.java +++ b/app/src/main/java/mega/privacy/android/app/lollipop/megachat/AndroidMegaRichLinkMessage.java @@ -171,6 +171,14 @@ public static boolean isChatLink(String url) { return false; } + public static boolean isContactLink(String url) { + if (url != null && (url.matches("^https://mega\\.co\\.nz/C!.+$") || url.matches("^https://mega\\.nz/C!.+$"))) { + log("IS contact link found"); + return true; + } + return false; + } + public boolean isChat() { return isChat; } diff --git a/app/src/main/java/mega/privacy/android/app/snackbarListeners/SnackbarNavigateOption.java b/app/src/main/java/mega/privacy/android/app/snackbarListeners/SnackbarNavigateOption.java index 7867b579ced..384ff422bd5 100644 --- a/app/src/main/java/mega/privacy/android/app/snackbarListeners/SnackbarNavigateOption.java +++ b/app/src/main/java/mega/privacy/android/app/snackbarListeners/SnackbarNavigateOption.java @@ -12,15 +12,19 @@ import mega.privacy.android.app.lollipop.FullScreenImageViewerLollipop; import mega.privacy.android.app.lollipop.ManagerActivityLollipop; import mega.privacy.android.app.lollipop.PdfViewerActivityLollipop; +import mega.privacy.android.app.lollipop.megachat.AndroidMegaRichLinkMessage; import mega.privacy.android.app.lollipop.megachat.ChatActivityLollipop; import mega.privacy.android.app.lollipop.megachat.ChatFullScreenImageViewer; import mega.privacy.android.app.utils.Constants; +import nz.mega.sdk.MegaApiAndroid; public class SnackbarNavigateOption implements View.OnClickListener{ Context context; long idChat; boolean isSentAsMessageSnackbar = false; + String url; + boolean isOpenLinkSnackbar = false; public SnackbarNavigateOption(Context context) { @@ -33,6 +37,12 @@ public SnackbarNavigateOption(Context context, long idChat) { isSentAsMessageSnackbar = true; } + public SnackbarNavigateOption (Context context, String url) { + this.context = context; + this.url = url; + isOpenLinkSnackbar = true; + } + @Override public void onClick(View v) { //Intent to Settings @@ -41,6 +51,18 @@ public void onClick(View v) { if (isSentAsMessageSnackbar) { ((ManagerActivityLollipop) context).moveToChatSection(idChat); } + else if (isOpenLinkSnackbar) { + if (AndroidMegaRichLinkMessage.isChatLink(url)) { + ((ManagerActivityLollipop) context).showChatLink(url); + } + else if (AndroidMegaRichLinkMessage.isContactLink(url)) { + String[] s = url.split("C!"); + if (s!= null && s.length>1) { + long handle = MegaApiAndroid.base64ToHandle(s[1].trim()); + ((ManagerActivityLollipop) context).openContactLink(handle); + } + } + } else { ((ManagerActivityLollipop) context).moveToSettingsSectionStorage(); } diff --git a/app/src/main/java/mega/privacy/android/app/utils/Constants.java b/app/src/main/java/mega/privacy/android/app/utils/Constants.java index 31df1ee48e4..6693cfd62f9 100644 --- a/app/src/main/java/mega/privacy/android/app/utils/Constants.java +++ b/app/src/main/java/mega/privacy/android/app/utils/Constants.java @@ -330,4 +330,5 @@ public class Constants { public static final int SNACKBAR_TYPE = 0; public static final int MESSAGE_SNACKBAR_TYPE = 1; public static final int NOT_SPACE_SNACKBAR_TYPE = 3; + public static final int OPEN_LINK_SNACKBAR_TYPE = 4; } diff --git a/app/src/main/res/layout/dialog_open_chat_link.xml b/app/src/main/res/layout/dialog_open_link.xml similarity index 84% rename from app/src/main/res/layout/dialog_open_chat_link.xml rename to app/src/main/res/layout/dialog_open_link.xml index d159249e6bf..1af920c8716 100644 --- a/app/src/main/res/layout/dialog_open_chat_link.xml +++ b/app/src/main/res/layout/dialog_open_link.xml @@ -9,40 +9,38 @@ android:paddingBottom="8dp"> + android:layout_below="@+id/link_title"/> + android:layout_below="@+id/link_text">