From 8d4aebe8e76b091c09bcfbef77bf73bf393807f0 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Mon, 9 Jan 2017 21:16:05 +0100 Subject: [PATCH] Cleanup. --- .../com/b44t/messenger/AndroidUtilities.java | 82 -------------- .../b44t/messenger/NotificationCenter.java | 1 - .../java/com/b44t/ui/DialogsActivity.java | 107 ++++++------------ .../main/java/com/b44t/ui/LaunchActivity.java | 28 +---- 4 files changed, 34 insertions(+), 184 deletions(-) diff --git a/MessengerProj/src/main/java/com/b44t/messenger/AndroidUtilities.java b/MessengerProj/src/main/java/com/b44t/messenger/AndroidUtilities.java index c516d06cd..908c1b797 100644 --- a/MessengerProj/src/main/java/com/b44t/messenger/AndroidUtilities.java +++ b/MessengerProj/src/main/java/com/b44t/messenger/AndroidUtilities.java @@ -108,9 +108,6 @@ public class AndroidUtilities { private static Boolean isTablet = null; private static int adjustOwnerClassGuid = 0; - private static Paint roundPaint; - private static RectF bitmapRect; - public static Pattern WEB_URL = null; static { try { @@ -257,36 +254,6 @@ public class AndroidUtilities { } } - /* - public static boolean isGoogleMapsInstalled(final BaseFragment fragment) { - try { - ApplicationLoader.applicationContext.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0); - return true; - } catch (PackageManager.NameNotFoundException e) { - if (fragment.getParentActivity() == null) { - return false; - } - AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getParentActivity()); - builder.setMessage("Install Google Maps?"); - builder.setCancelable(true); - builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - try { - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.apps.maps")); - fragment.getParentActivity().startActivityForResult(intent, 500); - } catch (Exception e) { - FileLog.e("messenger", e); - } - } - }); - builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); - fragment.showDialog(builder.create()); - return false; - } - } - */ - public static boolean isInternalUri(Uri uri) { String pathString = uri.getPath(); if (pathString == null) { @@ -817,55 +784,6 @@ public class AndroidUtilities { animatorSet.start(); } - /*public static String ellipsize(String text, int maxLines, int maxWidth, TextPaint paint) { - if (text == null || paint == null) { - return null; - } - int count; - int offset = 0; - StringBuilder result = null; - TextView - for (int a = 0; a < maxLines; a++) { - count = paint.breakText(text, true, maxWidth, null); - if (a != maxLines - 1) { - if (result == null) { - result = new StringBuilder(count * maxLines + 1); - } - boolean foundSpace = false; - for (int c = count - 1; c >= offset; c--) { - if (text.charAt(c) == ' ') { - foundSpace = true; - result.append(text.substring(offset, c - 1)); - offset = c - 1; - } - } - if (!foundSpace) { - offset = count; - } - text = text.substring(0, offset); - } else if (maxLines == 1) { - return text.substring(0, count); - } else { - result.append(text.substring(0, count)); - } - } - return result.toString(); - }*/ - - /*public static void turnOffHardwareAcceleration(Window window) { - if (window == null || Build.MODEL == null) { - return; - } - if (Build.MODEL.contains("GT-S5301") || - Build.MODEL.contains("GT-S5303") || - Build.MODEL.contains("GT-B5330") || - Build.MODEL.contains("GT-S5302") || - Build.MODEL.contains("GT-S6012B") || - Build.MODEL.contains("MegaFon_SP-AI")) { - window.clearFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); - } - }*/ - public static void addToClipboard(CharSequence str) { try { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE); diff --git a/MessengerProj/src/main/java/com/b44t/messenger/NotificationCenter.java b/MessengerProj/src/main/java/com/b44t/messenger/NotificationCenter.java index cccc0da87..9bbea5707 100644 --- a/MessengerProj/src/main/java/com/b44t/messenger/NotificationCenter.java +++ b/MessengerProj/src/main/java/com/b44t/messenger/NotificationCenter.java @@ -72,7 +72,6 @@ public class NotificationCenter { public static final int closeOtherAppActivities = totalEvents++; public static final int didUpdatedConnectionState = totalEvents++; public static final int emojiDidLoaded = totalEvents++; - public static final int appDidLogout = totalEvents++; public static final int FileDidUpload = totalEvents++; public static final int FileDidFailUpload = totalEvents++; diff --git a/MessengerProj/src/main/java/com/b44t/ui/DialogsActivity.java b/MessengerProj/src/main/java/com/b44t/ui/DialogsActivity.java index a8a6947e1..5a04b606e 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/DialogsActivity.java +++ b/MessengerProj/src/main/java/com/b44t/ui/DialogsActivity.java @@ -50,7 +50,6 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; -import android.widget.Toast; import com.b44t.messenger.AndroidUtilities; import com.b44t.messenger.ImageLoader; @@ -116,7 +115,6 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. private boolean searching; private boolean searchWas; private boolean onlySelect; - private String searchString; private long openedDialogId; private DialogsActivityDelegate delegate; @@ -139,19 +137,15 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. addToGroupAlertString = arguments.getString("addToGroupAlertString"); } - if (searchString == null) { - NotificationCenter.getInstance().addObserver(this, NotificationCenter.dialogsNeedReload); - NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded); - NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces); - NotificationCenter.getInstance().addObserver(this, NotificationCenter.contactsDidLoaded); - NotificationCenter.getInstance().addObserver(this, NotificationCenter.appDidLogout); - NotificationCenter.getInstance().addObserver(this, NotificationCenter.openedChatChanged); - NotificationCenter.getInstance().addObserver(this, NotificationCenter.notificationsSettingsUpdated); - NotificationCenter.getInstance().addObserver(this, NotificationCenter.messageSendError); - NotificationCenter.getInstance().addObserver(this, NotificationCenter.didSetPasscode); - NotificationCenter.getInstance().addObserver(this, NotificationCenter.reloadHints); - } - + NotificationCenter.getInstance().addObserver(this, NotificationCenter.dialogsNeedReload); + NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded); + NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces); + NotificationCenter.getInstance().addObserver(this, NotificationCenter.contactsDidLoaded); + NotificationCenter.getInstance().addObserver(this, NotificationCenter.openedChatChanged); + NotificationCenter.getInstance().addObserver(this, NotificationCenter.notificationsSettingsUpdated); + NotificationCenter.getInstance().addObserver(this, NotificationCenter.messageSendError); + NotificationCenter.getInstance().addObserver(this, NotificationCenter.didSetPasscode); + NotificationCenter.getInstance().addObserver(this, NotificationCenter.reloadHints); if (!dialogsLoaded) { NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload); // this is the rest of the first call to the removed MessagesController.loadDialogs(); not sure, if this is really needed @@ -163,18 +157,17 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. @Override public void onFragmentDestroy() { super.onFragmentDestroy(); - if (searchString == null) { - NotificationCenter.getInstance().removeObserver(this, NotificationCenter.dialogsNeedReload); - NotificationCenter.getInstance().removeObserver(this, NotificationCenter.emojiDidLoaded); - NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces); - NotificationCenter.getInstance().removeObserver(this, NotificationCenter.contactsDidLoaded); - NotificationCenter.getInstance().removeObserver(this, NotificationCenter.appDidLogout); - NotificationCenter.getInstance().removeObserver(this, NotificationCenter.openedChatChanged); - NotificationCenter.getInstance().removeObserver(this, NotificationCenter.notificationsSettingsUpdated); - NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messageSendError); - NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didSetPasscode); - NotificationCenter.getInstance().removeObserver(this, NotificationCenter.reloadHints); - } + + NotificationCenter.getInstance().removeObserver(this, NotificationCenter.dialogsNeedReload); + NotificationCenter.getInstance().removeObserver(this, NotificationCenter.emojiDidLoaded); + NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces); + NotificationCenter.getInstance().removeObserver(this, NotificationCenter.contactsDidLoaded); + NotificationCenter.getInstance().removeObserver(this, NotificationCenter.openedChatChanged); + NotificationCenter.getInstance().removeObserver(this, NotificationCenter.notificationsSettingsUpdated); + NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messageSendError); + NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didSetPasscode); + NotificationCenter.getInstance().removeObserver(this, NotificationCenter.reloadHints); + delegate = null; } @@ -191,7 +184,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. }); ActionBarMenu menu = actionBar.createMenu(); - if (!onlySelect && searchString == null) { + if (!onlySelect ) { passcodeItem = menu.addItem(1, R.drawable.lock_close); updatePasscodeButton(); } @@ -200,10 +193,6 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. public void onSearchExpand() { searching = true; if (listView != null) { - if (searchString != null) { - listView.setEmptyView(searchEmptyView); - emptyView.setVisibility(View.GONE); - } if (!onlySelect) { floatingButton.setVisibility(View.GONE); } @@ -213,10 +202,6 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. @Override public boolean canCollapseSearch() { - if (searchString != null) { - finishFragment(); - return false; - } return true; } @@ -272,11 +257,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setTitle(LocaleController.getString("SelectChat", R.string.SelectChat)); } else { - if (searchString != null) { - actionBar.setBackButtonImage(R.drawable.ic_ab_back); - } else { - actionBar.setBackButtonDrawable(new MenuDrawable()); - } + actionBar.setBackButtonDrawable(new MenuDrawable()); actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName)); } actionBar.setAllowOverlayTitle(true); @@ -369,12 +350,8 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG); } } - if (searchString != null) { - NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); - presentFragment(new ChatActivity(args)); - } else { - presentFragment(new ChatActivity(args)); - } + + presentFragment(new ChatActivity(args)); } } }); @@ -453,16 +430,16 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { - int firstVisibleItem = layoutManager.findFirstVisibleItemPosition(); + //int firstVisibleItem = layoutManager.findFirstVisibleItemPosition(); //int visibleItemCount = Math.abs(layoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1; //int totalItemCount = recyclerView.getAdapter().getItemCount(); - if (searching && searchWas) { + //if (searching && searchWas) { //if (visibleItemCount > 0 && layoutManager.findLastVisibleItemPosition() == totalItemCount - 1 && !dialogsSearchAdapter.isMessagesSearchEndReached()) { // dialogsSearchAdapter.loadMoreSearchMessages(); //} - return; - } + //return; + //} // Floating hiding action /* if (floatingButton.getVisibility() != View.GONE) { @@ -491,28 +468,16 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. } }); - if (searchString == null) { - dialogsAdapter = new DialogsAdapter(context); - if (AndroidUtilities.isTablet() && openedDialogId != 0) { - dialogsAdapter.setOpenedDialogId(openedDialogId); - } - listView.setAdapter(dialogsAdapter); - } - int type = 0; - if (searchString != null) { - type = 2; - } else if (!onlySelect) { - type = 1; + dialogsAdapter = new DialogsAdapter(context); + if (AndroidUtilities.isTablet() && openedDialogId != 0) { + dialogsAdapter.setOpenedDialogId(openedDialogId); } + listView.setAdapter(dialogsAdapter); dialogsSearchAdapter = new DialogsSearchAdapter(context); searchEmptyView.setVisibility(View.GONE); listView.setEmptyView(emptyView); - if (searchString != null) { - actionBar.openSearchField(searchString); - } - if (!onlySelect ) { frameLayout.addView(new PlayerView(context, this), LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 39, Gravity.TOP | Gravity.LEFT, 0, -36, 0, 0)); } @@ -644,8 +609,6 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. updateVisibleRows(0); } else if (id == NotificationCenter.updateInterfaces) { updateVisibleRows((Integer) args[0]); - } else if (id == NotificationCenter.appDidLogout) { - dialogsLoaded = false; } else if (id == NotificationCenter.contactsDidLoaded) { updateVisibleRows(0); } else if (id == NotificationCenter.openedChatChanged) { @@ -748,12 +711,8 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. delegate = dialogsActivityDelegate; } - public void setSearchString(String string) { - searchString = string; - } - public boolean isMainDialogList() { - return delegate == null && searchString == null; + return delegate == null; } private void didSelectResult(final long dialog_id, boolean useAlert, final boolean param) { diff --git a/MessengerProj/src/main/java/com/b44t/ui/LaunchActivity.java b/MessengerProj/src/main/java/com/b44t/ui/LaunchActivity.java index a152f4b99..bf9b053ad 100644 --- a/MessengerProj/src/main/java/com/b44t/ui/LaunchActivity.java +++ b/MessengerProj/src/main/java/com/b44t/ui/LaunchActivity.java @@ -371,7 +371,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeOtherAppActivities, this); currentConnectionState = ConnectionsManager.getInstance().getConnectionState(); - NotificationCenter.getInstance().addObserver(this, NotificationCenter.appDidLogout); NotificationCenter.getInstance().addObserver(this, NotificationCenter.mainUserInfoChanged); NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeOtherAppActivities); NotificationCenter.getInstance().addObserver(this, NotificationCenter.didUpdatedConnectionState); @@ -1163,7 +1162,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa AndroidUtilities.cancelRunOnUIThread(lockRunnable); lockRunnable = null; } - NotificationCenter.getInstance().removeObserver(this, NotificationCenter.appDidLogout); NotificationCenter.getInstance().removeObserver(this, NotificationCenter.mainUserInfoChanged); NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeOtherAppActivities); NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didUpdatedConnectionState); @@ -1472,31 +1470,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa @Override @SuppressWarnings("unchecked") public void didReceivedNotification(int id, Object... args) { - if (id == NotificationCenter.appDidLogout) { - /* EDIT BY MR - if (drawerLayoutAdapter != null) { - drawerLayoutAdapter.notifyDataSetChanged(); - } - for (BaseFragment fragment : actionBarLayout.fragmentsStack) { - fragment.onFragmentDestroy(); - } - actionBarLayout.fragmentsStack.clear(); - if (AndroidUtilities.isTablet()) { - for (BaseFragment fragment : layersActionBarLayout.fragmentsStack) { - fragment.onFragmentDestroy(); - } - layersActionBarLayout.fragmentsStack.clear(); - for (BaseFragment fragment : rightActionBarLayout.fragmentsStack) { - fragment.onFragmentDestroy(); - } - rightActionBarLayout.fragmentsStack.clear(); - } - Intent intent2 = new Intent(this, IntroActivity.class); - startActivity(intent2); - onFinish(); - finish(); - */ - } else if (id == NotificationCenter.closeOtherAppActivities) { + if (id == NotificationCenter.closeOtherAppActivities) { if (args[0] != this) { onFinish(); finish();