Skip to content

Commit

Permalink
Merge pull request #745 from meganz/develop
Browse files Browse the repository at this point in the history
v3.5.1 (222)
  • Loading branch information
jraragon authored Jan 14, 2019
2 parents a712e61 + 0e6289b commit 79da818
Show file tree
Hide file tree
Showing 21 changed files with 383 additions and 163 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "mega.privacy.android.app"
minSdkVersion 21
targetSdkVersion 27
versionCode 219
versionName "3.5.1 (219)"
versionCode 222
versionName "3.5.1 (222)"
multiDexEnabled true
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mega.privacy.android.app"
android:installLocation="internalOnly"
android:versionCode="219"
android:versionName="3.5.1 (219)" >
android:versionCode="222"
android:versionName="3.5.1 (222)" >

<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<uses-feature android:name="android.hardware.camera" android:required="false"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
public class MegaApplication extends MultiDexApplication implements MegaGlobalListenerInterface, MegaChatRequestListenerInterface, MegaChatNotificationListenerInterface, MegaChatCallListenerInterface, NetworkStateReceiver.NetworkStateReceiverListener, MegaChatListenerInterface {
final String TAG = "MegaApplication";

static final public String USER_AGENT = "MEGAAndroid/3.5.1_219";
static final public String USER_AGENT = "MEGAAndroid/3.5.1_222";

DatabaseHandler dbH;
MegaApiAndroid megaApi;
Expand Down Expand Up @@ -538,9 +538,11 @@ public void onCreate() {

final EmojiCompat.Config config;
if (USE_BUNDLED_EMOJI) {
log("use Bundle emoji");
// Use the bundled font for EmojiCompat
config = new BundledEmojiCompatConfig(getApplicationContext());
} else {
log("use downloadable font for EmojiCompat");
// Use a downloadable font for EmojiCompat
final FontRequest fontRequest = new FontRequest(
"com.google.android.gms.fonts",
Expand All @@ -552,11 +554,11 @@ public void onCreate() {
.registerInitCallback(new EmojiCompat.InitCallback() {
@Override
public void onInitialized() {
Log.i(TAG, "EmojiCompat initialized");
log("EmojiCompat initialized");
}
@Override
public void onFailed(@Nullable Throwable throwable) {
Log.e(TAG, "EmojiCompat initialization failed", throwable);
log("EmojiCompat initialization failed");
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,52 +40,106 @@ public final class EmojiManager {
@Override public void replaceWithImages(final Context context, Spannable text, final float emojiSize, final float defaultEmojiSize, final EmojiReplacer fallback) {

final EmojiManager emojiManager = EmojiManager.getInstance();
// final EmojiSpan[] existingSpans = text.getSpans(0, text.length(), EmojiSpan.class);
// final List<Integer> existingSpanPositions = new ArrayList<>(existingSpans.length);
// final int size = existingSpans.length;

// //noinspection ForLoopReplaceableByForEach
// for (int i = 0; i < size; i++) {
// existingSpanPositions.add(text.getSpanStart(existingSpans[i]));
// }

final List<EmojiRange> findAllEmojis = emojiManager.findAllEmojis(text);
if(findAllEmojis.size() == 0){
EmojiCompat.get().process(text);
}else{
if(emojiManager.isOnlyEmojis(text.toString())){
for (int i = 0; i < findAllEmojis.size(); i++) {
final EmojiRange location = findAllEmojis.get(i);
text.setSpan(new EmojiSpan(context, location.emoji, emojiSize), location.start, location.end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
log("the text has not MEGA emojis");
if(EmojiCompat.get()!=null){
if (EmojiCompat.get().getLoadState() == EmojiCompat.LOAD_STATE_SUCCEEDED) {
log("EmojiCompat - LOAD_STATE_SUCCEEDED");
EmojiCompat.get().process(text);

} else if (EmojiCompat.get().getLoadState() == EmojiCompat.LOAD_STATE_LOADING) {
log("EmojiCompat - LOAD_STATE_LOADING");
}else if (EmojiCompat.get().getLoadState() == EmojiCompat.LOAD_STATE_FAILED) {
log("EmojiCompat - LOAD_STATE_FAILED");
}else{
for (int i = 0; i < findAllEmojis.size(); i++) {
EmojiRange currentLocation = findAllEmojis.get(i);
log("EmojiCompat - LOAD_OTHER_CASE");
}
}
}else{
log(" the text has MEGA emojis");

if(i == 0){
//First emoji found
if(emojiManager.isOnlyEmojis(text.toString())){
for (int i = 0; i < findAllEmojis.size(); i++) {
final EmojiRange location = findAllEmojis.get(i);
text.setSpan(new EmojiSpan(context, location.emoji, emojiSize), location.start, location.end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}else{
for (int i = 0; i < findAllEmojis.size(); i++) {
EmojiRange currentLocation = findAllEmojis.get(i);

if(i == 0){
//First emoji found
if(EmojiCompat.get()!=null){
if (EmojiCompat.get().getLoadState() == EmojiCompat.LOAD_STATE_SUCCEEDED) {
log("EmojiCompat - LOAD_STATE_SUCCEEDED");
EmojiCompat.get().process(text,0, currentLocation.start);

if(i == (findAllEmojis.size()-1)){
//First emoji found and it's the last one too
EmojiCompat.get().process(text,currentLocation.end, text.length());
} else if (EmojiCompat.get().getLoadState() == EmojiCompat.LOAD_STATE_LOADING) {
log("EmojiCompat - LOAD_STATE_LOADING");
}else if (EmojiCompat.get().getLoadState() == EmojiCompat.LOAD_STATE_FAILED) {
log("EmojiCompat - LOAD_STATE_FAILED");
}else{
log("EmojiCompat - LOAD_OTHER_CASE");
}
}

if(i == (findAllEmojis.size()-1)){
//First emoji found and it's the last one too
if(EmojiCompat.get()!=null) {
if (EmojiCompat.get().getLoadState() == EmojiCompat.LOAD_STATE_SUCCEEDED) {
log("EmojiCompat - LOAD_STATE_SUCCEEDED");
EmojiCompat.get().process(text, currentLocation.end, text.length());

} else if (EmojiCompat.get().getLoadState() == EmojiCompat.LOAD_STATE_LOADING) {
log("EmojiCompat - LOAD_STATE_LOADING");
} else if (EmojiCompat.get().getLoadState() == EmojiCompat.LOAD_STATE_FAILED) {
log("EmojiCompat - LOAD_STATE_FAILED");
} else {
log("EmojiCompat - LOAD_OTHER_CASE");
}
}
}

}else if(i == (findAllEmojis.size()-1)){
//Last emoji found but there is another minimum
EmojiRange previewLocation = findAllEmojis.get(i-1);
EmojiCompat.get().process(text,previewLocation.end, currentLocation.start);
EmojiCompat.get().process(text,currentLocation.end, text.length());
}else if(i == (findAllEmojis.size()-1)){
//Last emoji found but there is another minimum
EmojiRange previewLocation = findAllEmojis.get(i-1);
if(EmojiCompat.get()!=null) {
if (EmojiCompat.get().getLoadState() == EmojiCompat.LOAD_STATE_SUCCEEDED) {
log("EmojiCompat - LOAD_STATE_SUCCEEDED");
EmojiCompat.get().process(text, previewLocation.end, currentLocation.start);
EmojiCompat.get().process(text, currentLocation.end, text.length());

}else{
//Emoji found in the middle
EmojiRange previewLocation = findAllEmojis.get(i-1);
EmojiCompat.get().process(text,previewLocation.end, currentLocation.start);
} else if (EmojiCompat.get().getLoadState() == EmojiCompat.LOAD_STATE_LOADING) {
log("EmojiCompat - LOAD_STATE_LOADING");
} else if (EmojiCompat.get().getLoadState() == EmojiCompat.LOAD_STATE_FAILED) {
log("EmojiCompat - LOAD_STATE_FAILED");
} else {
log("EmojiCompat - LOAD_OTHER_CASE");
}
}
}else{
//Emoji found in the middle
EmojiRange previewLocation = findAllEmojis.get(i-1);
if(EmojiCompat.get()!=null) {
if (EmojiCompat.get().getLoadState() == EmojiCompat.LOAD_STATE_SUCCEEDED) {
log("EmojiCompat - LOAD_STATE_SUCCEEDED");
EmojiCompat.get().process(text, previewLocation.end, currentLocation.start);

} else if (EmojiCompat.get().getLoadState() == EmojiCompat.LOAD_STATE_LOADING) {
log("EmojiCompat - LOAD_STATE_LOADING");
} else if (EmojiCompat.get().getLoadState() == EmojiCompat.LOAD_STATE_FAILED) {
log("EmojiCompat - LOAD_STATE_FAILED");
} else {
log("EmojiCompat - LOAD_OTHER_CASE");
}
text.setSpan(new EmojiSpan(context, currentLocation.emoji, emojiSize), currentLocation.start, currentLocation.end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}

}
text.setSpan(new EmojiSpan(context, currentLocation.emoji, emojiSize), currentLocation.start, currentLocation.end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
}
};
Expand Down Expand Up @@ -194,20 +248,22 @@ public int getNumEmojis(@Nullable final CharSequence text){
return num;
}
@NonNull List<EmojiRange> findAllEmojis(@Nullable final CharSequence text) {
log("findAllEmojis() - text: "+text);
verifyInstalled();
log("findAllEmojis");
final List<EmojiRange> result = new ArrayList<>();
if (!TextUtils.isEmpty(text)) {
final Matcher matcher = emojiPattern.matcher(text);
while (matcher.find()) {
final Emoji found = findEmoji(text.subSequence(matcher.start(), matcher.end()));
if (found != null) {
result.add(new EmojiRange(matcher.start(), matcher.end(), found));
try {
verifyInstalled();
if (!TextUtils.isEmpty(text)) {
final Matcher matcher = emojiPattern.matcher(text);
while (matcher.find()) {
final Emoji found = findEmoji(text.subSequence(matcher.start(), matcher.end()));
if (found != null) {
result.add(new EmojiRange(matcher.start(), matcher.end(), found));
}
}
}

}else{

}catch (Exception e){
log("EXCEPTION findAllEmojis: "+e.getMessage());
return result;
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.os.Environment;
import android.os.Handler;
import android.provider.OpenableColumns;
import android.support.annotation.NonNull;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
Expand Down Expand Up @@ -2663,7 +2664,7 @@ void releasePlaylist(){
fragmentContainer.setVisibility(View.GONE);
draggableView.setDraggable(true);

getSupportFragmentManager().beginTransaction().remove(getSupportFragmentManager().findFragmentById(R.id.fragment_container)).commit();
getSupportFragmentManager().beginTransaction().remove(getSupportFragmentManager().findFragmentById(R.id.fragment_container)).commitNowAllowingStateLoss();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = this.getWindow();
Expand Down Expand Up @@ -3144,24 +3145,23 @@ else if(adapterType == Constants.INBOX_ADAPTER){
public void downloadFile() {

if (adapterType == Constants.FILE_LINK_ADAPTER){
MegaNode node = megaApi.getNodeByHandle(currentDocument.getHandle());
if (nC == null) {
nC = new NodeController(this);
}
nC.downloadFileLink(currentDocument, uri.toString());
}
else if (fromChat){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
boolean hasStoragePermission = (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED);
if (!hasStoragePermission) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
Constants.REQUEST_WRITE_STORAGE);

handleListM.add(node.getHandle());
handleListM.add(nodeChat.getHandle());
return;
}
}

if (nC == null) {
nC = new NodeController(this);
}
nC.downloadFileLink(currentDocument, uri.toString());
}
else if (fromChat){
if (chatC == null){
chatC = new ChatController(this);
}
Expand All @@ -3179,6 +3179,7 @@ else if (fromChat){
Constants.REQUEST_WRITE_STORAGE);

handleListM.add(node.getHandle());
return;
}
}

Expand All @@ -3192,6 +3193,39 @@ else if (fromChat){
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch(requestCode){
case Constants.REQUEST_WRITE_STORAGE:{
boolean hasStoragePermission = (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED);
if (hasStoragePermission) {
if (adapterType == Constants.FILE_LINK_ADAPTER) {
if(nC==null){
nC = new NodeController(this, isFolderLink);
}
nC.downloadFileLink(currentDocument, uri.toString());
}
else if (fromChat) {
if (chatC == null){
chatC = new ChatController(this);
}
if (nodeChat != null){
chatC.prepareForChatDownload(nodeChat);
}
}
else{
if(nC==null){
nC = new NodeController(this, isFolderLink);
}
nC.prepareForDownload(handleListM, false);
}
}
break;
}
}
}

public void intentToSendFile(Uri uri){
log("intentToSendFile");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,13 @@ public void onFocusChange(View v, boolean hasFocus) {
}
}

@Override
public void onBackPressed() {
log("onBackPressed");
super.callToSuperBack = true;
super.onBackPressed();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,7 @@ private void afterLoginAndFetch(){

FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.cloudDriveFrameLayout, cDriveExplorer, "cDriveExplorer");
ft.commit();
getSupportFragmentManager().executePendingTransactions();
ft.commitNowAllowingStateLoss();

cloudDriveFrameLayout.setVisibility(View.VISIBLE);

Expand Down Expand Up @@ -593,8 +592,7 @@ else if (intent.getAction().equals(ACTION_SELECT_FILE)){

FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.cloudDriveFrameLayout, cDriveExplorer, "cDriveExplorer");
ft.commit();
getSupportFragmentManager().executePendingTransactions();
ft.commitNowAllowingStateLoss();

cloudDriveFrameLayout.setVisibility(View.VISIBLE);

Expand Down Expand Up @@ -624,8 +622,7 @@ else if (intent.getAction().equals(ACTION_MULTISELECT_FILE)){

FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.cloudDriveFrameLayout, cDriveExplorer, "cDriveExplorer");
ft.commit();
getSupportFragmentManager().executePendingTransactions();
ft.commitNowAllowingStateLoss();

cloudDriveFrameLayout.setVisibility(View.VISIBLE);

Expand Down Expand Up @@ -785,8 +782,7 @@ else if ((intent.getAction().equals(ACTION_UPLOAD_TO_CLOUD))){

FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.cloudDriveFrameLayout, cDriveExplorer, "cDriveExplorer");
ft.commit();
getSupportFragmentManager().executePendingTransactions();
ft.commitNowAllowingStateLoss();

cloudDriveFrameLayout.setVisibility(View.VISIBLE);

Expand Down
Loading

0 comments on commit 79da818

Please sign in to comment.