2014-06-04 01:31:48 +02:00
|
|
|
/*
|
|
|
|
* This is the source code of Telegram for Android v. 1.3.2.
|
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
|
|
|
* Copyright Nikolai Kudashov, 2013.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui.Views.ActionBar;
|
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
import android.app.Activity;
|
2014-06-07 01:35:21 +02:00
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.DialogInterface;
|
2014-06-04 01:31:48 +02:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
|
|
|
import org.telegram.messenger.ConnectionsManager;
|
2014-06-07 01:35:21 +02:00
|
|
|
import org.telegram.messenger.FileLog;
|
|
|
|
import org.telegram.messenger.R;
|
2014-06-04 01:31:48 +02:00
|
|
|
|
|
|
|
public class BaseFragment {
|
|
|
|
private boolean isFinished = false;
|
2014-11-11 23:16:17 +01:00
|
|
|
private AlertDialog visibleDialog = null;
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
protected View fragmentView;
|
2014-09-24 04:17:27 +02:00
|
|
|
protected ActionBarLayout parentLayout;
|
2014-11-11 23:16:17 +01:00
|
|
|
protected ActionBar actionBar;
|
2014-06-04 01:31:48 +02:00
|
|
|
protected int classGuid = 0;
|
|
|
|
protected Bundle arguments;
|
2014-06-17 17:10:02 +02:00
|
|
|
protected boolean swipeBackEnabled = true;
|
2014-06-04 01:31:48 +02:00
|
|
|
|
|
|
|
public BaseFragment() {
|
|
|
|
classGuid = ConnectionsManager.getInstance().generateClassGuid();
|
|
|
|
}
|
|
|
|
|
|
|
|
public BaseFragment(Bundle args) {
|
|
|
|
arguments = args;
|
|
|
|
classGuid = ConnectionsManager.getInstance().generateClassGuid();
|
|
|
|
}
|
|
|
|
|
|
|
|
public View createView(LayoutInflater inflater, ViewGroup container) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Bundle getArguments() {
|
|
|
|
return arguments;
|
|
|
|
}
|
|
|
|
|
2014-11-11 23:16:17 +01:00
|
|
|
protected void setParentLayout(ActionBarLayout layout) {
|
2014-09-24 04:17:27 +02:00
|
|
|
if (parentLayout != layout) {
|
|
|
|
parentLayout = layout;
|
2014-06-04 01:31:48 +02:00
|
|
|
if (fragmentView != null) {
|
|
|
|
ViewGroup parent = (ViewGroup) fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
2014-10-11 13:30:32 +02:00
|
|
|
try {
|
|
|
|
parent.removeView(fragmentView);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
fragmentView = null;
|
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
if (actionBar != null) {
|
|
|
|
ViewGroup parent = (ViewGroup) actionBar.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
try {
|
|
|
|
parent.removeView(actionBar);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2014-06-04 20:57:11 +02:00
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
}
|
|
|
|
if (parentLayout != null) {
|
|
|
|
actionBar = new ActionBar(parentLayout.getContext());
|
|
|
|
actionBar.parentFragment = this;
|
|
|
|
actionBar.setBackgroundResource(R.color.header);
|
|
|
|
actionBar.setItemsBackground(R.drawable.bar_selector);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void finishFragment() {
|
2014-06-13 17:03:06 +02:00
|
|
|
finishFragment(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void finishFragment(boolean animated) {
|
2014-09-24 04:17:27 +02:00
|
|
|
if (isFinished || parentLayout == null) {
|
2014-06-04 01:31:48 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
parentLayout.closeLastFragment(animated);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void removeSelfFromStack() {
|
2014-09-24 04:17:27 +02:00
|
|
|
if (isFinished || parentLayout == null) {
|
2014-06-04 01:31:48 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
parentLayout.removeFragmentFromStack(this);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onFragmentCreate() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onFragmentDestroy() {
|
|
|
|
ConnectionsManager.getInstance().cancelRpcsForClassGuid(classGuid);
|
|
|
|
isFinished = true;
|
2014-11-11 23:16:17 +01:00
|
|
|
if (actionBar != null) {
|
|
|
|
actionBar.setEnabled(false);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onResume() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onPause() {
|
2014-11-11 23:16:17 +01:00
|
|
|
if (actionBar != null) {
|
|
|
|
actionBar.onPause();
|
|
|
|
actionBar.closeSearchField();
|
2014-06-04 18:00:42 +02:00
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
try {
|
|
|
|
if (visibleDialog != null && visibleDialog.isShowing()) {
|
|
|
|
visibleDialog.dismiss();
|
|
|
|
visibleDialog = null;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onBackPressed() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void saveSelfArgs(Bundle args) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void restoreSelfArgs(Bundle args) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-10-01 00:36:18 +02:00
|
|
|
public boolean presentFragment(BaseFragment fragment) {
|
|
|
|
return parentLayout != null && parentLayout.presentFragment(fragment);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
2014-10-01 00:36:18 +02:00
|
|
|
public boolean presentFragment(BaseFragment fragment, boolean removeLast) {
|
|
|
|
return parentLayout != null && parentLayout.presentFragment(fragment, removeLast);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
2014-10-01 00:36:18 +02:00
|
|
|
public boolean presentFragment(BaseFragment fragment, boolean removeLast, boolean forceWithoutAnimation) {
|
|
|
|
return parentLayout != null && parentLayout.presentFragment(fragment, removeLast, forceWithoutAnimation, true);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
public Activity getParentActivity() {
|
2014-09-28 15:37:26 +02:00
|
|
|
if (parentLayout != null) {
|
|
|
|
return parentLayout.parentActivity;
|
|
|
|
}
|
|
|
|
return null;
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
2014-10-01 00:36:18 +02:00
|
|
|
public void startActivityForResult(final Intent intent, final int requestCode) {
|
|
|
|
if (parentLayout != null) {
|
|
|
|
parentLayout.startActivityForResult(intent, requestCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
public void onBeginSlide() {
|
2014-06-07 01:35:21 +02:00
|
|
|
try {
|
|
|
|
if (visibleDialog != null && visibleDialog.isShowing()) {
|
|
|
|
visibleDialog.dismiss();
|
|
|
|
visibleDialog = null;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
if (actionBar != null) {
|
|
|
|
actionBar.onPause();
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onOpenAnimationEnd() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onLowMemory() {
|
|
|
|
|
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2014-11-11 23:16:17 +01:00
|
|
|
public boolean needAddActionBar() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-14 10:36:01 +02:00
|
|
|
protected void showAlertDialog(AlertDialog.Builder builder) {
|
2014-09-24 04:17:27 +02:00
|
|
|
if (parentLayout == null || parentLayout.checkTransitionAnimation() || parentLayout.animationInProgress || parentLayout.startedTracking) {
|
2014-06-14 10:36:01 +02:00
|
|
|
return;
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2014-06-13 17:03:06 +02:00
|
|
|
try {
|
|
|
|
if (visibleDialog != null) {
|
|
|
|
visibleDialog.dismiss();
|
|
|
|
visibleDialog = null;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
|
|
|
visibleDialog = builder.show();
|
|
|
|
visibleDialog.setCanceledOnTouchOutside(true);
|
|
|
|
visibleDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
|
|
|
@Override
|
|
|
|
public void onDismiss(DialogInterface dialog) {
|
|
|
|
visibleDialog = null;
|
2014-08-22 16:24:33 +02:00
|
|
|
onDialogDismiss();
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
|
|
|
|
protected void onDialogDismiss() {
|
|
|
|
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|