2013-10-25 17:19:00 +02:00
|
|
|
/*
|
2013-12-20 20:25:49 +01:00
|
|
|
* This is the source code of Telegram for Android v. 1.3.2.
|
2013-10-25 17:19:00 +02:00
|
|
|
* 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;
|
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
import android.animation.Animator;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.app.AlertDialog;
|
2014-06-13 12:42:21 +02:00
|
|
|
import android.app.ProgressDialog;
|
2014-06-04 01:31:48 +02:00
|
|
|
import android.content.Context;
|
2014-04-05 01:00:38 +02:00
|
|
|
import android.content.SharedPreferences;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.os.Bundle;
|
2014-06-04 01:31:48 +02:00
|
|
|
import android.view.LayoutInflater;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.view.View;
|
2014-06-04 01:31:48 +02:00
|
|
|
import android.view.ViewGroup;
|
2014-11-07 11:23:17 +01:00
|
|
|
import android.view.WindowManager;
|
2013-12-20 20:25:49 +01:00
|
|
|
import android.view.animation.AccelerateDecelerateInterpolator;
|
2014-06-14 10:36:01 +02:00
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.ScrollView;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.android.AndroidUtilities;
|
2014-04-05 01:00:38 +02:00
|
|
|
import org.telegram.messenger.FileLog;
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.android.LocaleController;
|
2013-10-25 17:19:00 +02:00
|
|
|
import org.telegram.messenger.R;
|
2014-11-11 23:16:17 +01:00
|
|
|
import org.telegram.ui.Views.ActionBar.ActionBar;
|
2014-06-04 01:31:48 +02:00
|
|
|
import org.telegram.ui.Views.ActionBar.ActionBarMenu;
|
|
|
|
import org.telegram.ui.Views.ActionBar.BaseFragment;
|
2013-12-20 20:25:49 +01:00
|
|
|
import org.telegram.ui.Views.SlideView;
|
|
|
|
|
2014-04-05 01:00:38 +02:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
public class LoginActivity extends BaseFragment implements SlideView.SlideViewDelegate {
|
2013-12-20 20:25:49 +01:00
|
|
|
private int currentViewNum = 0;
|
|
|
|
private SlideView[] views = new SlideView[3];
|
2014-06-13 12:42:21 +02:00
|
|
|
private ProgressDialog progressDialog;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
private final static int done_button = 1;
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
2014-06-04 01:31:48 +02:00
|
|
|
public boolean onFragmentCreate() {
|
|
|
|
return super.onFragmentCreate();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-04 01:31:48 +02:00
|
|
|
public void onFragmentDestroy() {
|
|
|
|
super.onFragmentDestroy();
|
|
|
|
for (SlideView v : views) {
|
|
|
|
if (v != null) {
|
|
|
|
v.onDestroyActivity();
|
|
|
|
}
|
|
|
|
}
|
2014-10-14 10:13:16 +02:00
|
|
|
if (progressDialog != null) {
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2014-10-14 22:36:15 +02:00
|
|
|
progressDialog = null;
|
2014-10-14 10:13:16 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-04 01:31:48 +02:00
|
|
|
public View createView(LayoutInflater inflater, ViewGroup container) {
|
|
|
|
if (fragmentView == null) {
|
2014-11-11 23:16:17 +01:00
|
|
|
actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2014-11-11 23:16:17 +01:00
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
2014-06-04 01:31:48 +02:00
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == done_button) {
|
|
|
|
onNextAction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-11-11 23:16:17 +01:00
|
|
|
ActionBarMenu menu = actionBar.createMenu();
|
2014-06-04 01:31:48 +02:00
|
|
|
View doneItem = menu.addItemResource(done_button, R.layout.group_create_done_layout);
|
|
|
|
TextView doneTextView = (TextView)doneItem.findViewById(R.id.done_button);
|
2014-06-12 17:53:20 +02:00
|
|
|
doneTextView.setText(LocaleController.getString("Done", R.string.Done).toUpperCase());
|
2014-06-04 01:31:48 +02:00
|
|
|
|
|
|
|
fragmentView = inflater.inflate(R.layout.login_layout, container, false);
|
|
|
|
|
|
|
|
views[0] = (SlideView)fragmentView.findViewById(R.id.login_page1);
|
|
|
|
views[1] = (SlideView)fragmentView.findViewById(R.id.login_page2);
|
|
|
|
views[2] = (SlideView)fragmentView.findViewById(R.id.login_page3);
|
|
|
|
|
2014-06-14 10:36:01 +02:00
|
|
|
try {
|
|
|
|
if (views[0] == null || views[1] == null || views[2] == null) {
|
|
|
|
FrameLayout parent = (FrameLayout)((ScrollView) fragmentView).getChildAt(0);
|
|
|
|
for (int a = 0; a < views.length; a++) {
|
|
|
|
if (views[a] == null) {
|
|
|
|
views[a] = (SlideView)parent.getChildAt(a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
|
2014-11-11 23:16:17 +01:00
|
|
|
actionBar.setTitle(views[0].getHeaderName());
|
2014-06-04 01:31:48 +02:00
|
|
|
|
|
|
|
Bundle savedInstanceState = loadCurrentState();
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
currentViewNum = savedInstanceState.getInt("currentViewNum", 0);
|
|
|
|
}
|
|
|
|
for (int a = 0; a < views.length; a++) {
|
|
|
|
SlideView v = views[a];
|
|
|
|
if (v != null) {
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
v.restoreStateParams(savedInstanceState);
|
|
|
|
}
|
|
|
|
v.delegate = this;
|
|
|
|
v.setVisibility(currentViewNum == a ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ViewGroup parent = (ViewGroup)fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(fragmentView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fragmentView;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2014-11-07 11:23:17 +01:00
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
getParentActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
getParentActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
|
}
|
|
|
|
|
2014-04-05 01:00:38 +02:00
|
|
|
private void saveCurrentState() {
|
|
|
|
try {
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
bundle.putInt("currentViewNum", currentViewNum);
|
|
|
|
for (int a = 0; a <= currentViewNum; a++) {
|
|
|
|
SlideView v = views[a];
|
|
|
|
if (v != null) {
|
|
|
|
v.saveStateParams(bundle);
|
|
|
|
}
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("logininfo", Context.MODE_PRIVATE);
|
2014-04-05 01:00:38 +02:00
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.clear();
|
|
|
|
putBundleToEditor(bundle, editor, null);
|
|
|
|
editor.commit();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Bundle loadCurrentState() {
|
|
|
|
try {
|
|
|
|
Bundle bundle = new Bundle();
|
2014-06-04 01:31:48 +02:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("logininfo", Context.MODE_PRIVATE);
|
2014-04-05 01:00:38 +02:00
|
|
|
Map<String, ?> params = preferences.getAll();
|
|
|
|
for (Map.Entry<String, ?> entry : params.entrySet()) {
|
|
|
|
String key = entry.getKey();
|
|
|
|
Object value = entry.getValue();
|
|
|
|
String[] args = key.split("_\\|_");
|
|
|
|
if (args.length == 1) {
|
|
|
|
if (value instanceof String) {
|
|
|
|
bundle.putString(key, (String) value);
|
|
|
|
} else if (value instanceof Integer) {
|
|
|
|
bundle.putInt(key, (Integer) value);
|
|
|
|
}
|
|
|
|
} else if (args.length == 2) {
|
|
|
|
Bundle inner = bundle.getBundle(args[0]);
|
|
|
|
if (inner == null) {
|
|
|
|
inner = new Bundle();
|
|
|
|
bundle.putBundle(args[0], inner);
|
|
|
|
}
|
|
|
|
if (value instanceof String) {
|
|
|
|
inner.putString(args[1], (String) value);
|
|
|
|
} else if (value instanceof Integer) {
|
|
|
|
inner.putInt(args[1], (Integer) value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bundle;
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void clearCurrentState() {
|
2014-06-04 01:31:48 +02:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("logininfo", Context.MODE_PRIVATE);
|
2014-04-05 01:00:38 +02:00
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.clear();
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void putBundleToEditor(Bundle bundle, SharedPreferences.Editor editor, String prefix) {
|
|
|
|
Set<String> keys = bundle.keySet();
|
|
|
|
for (String key : keys) {
|
|
|
|
Object obj = bundle.get(key);
|
|
|
|
if (obj instanceof String) {
|
|
|
|
if (prefix != null) {
|
|
|
|
editor.putString(prefix + "_|_" + key, (String) obj);
|
|
|
|
} else {
|
|
|
|
editor.putString(key, (String) obj);
|
|
|
|
}
|
|
|
|
} else if (obj instanceof Integer) {
|
|
|
|
if (prefix != null) {
|
|
|
|
editor.putInt(prefix + "_|_" + key, (Integer) obj);
|
|
|
|
} else {
|
|
|
|
editor.putInt(key, (Integer) obj);
|
|
|
|
}
|
|
|
|
} else if (obj instanceof Bundle) {
|
|
|
|
putBundleToEditor((Bundle)obj, editor, key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
@Override
|
2014-06-04 01:31:48 +02:00
|
|
|
public boolean onBackPressed() {
|
2013-12-20 20:25:49 +01:00
|
|
|
if (currentViewNum == 0) {
|
|
|
|
for (SlideView v : views) {
|
|
|
|
if (v != null) {
|
|
|
|
v.onDestroyActivity();
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
return true;
|
2013-12-20 20:25:49 +01:00
|
|
|
} else if (currentViewNum != 1 && currentViewNum != 2) {
|
|
|
|
setPage(0, true, null, true);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
return false;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-04 01:31:48 +02:00
|
|
|
public void needShowAlert(final String text) {
|
2014-06-13 12:42:21 +02:00
|
|
|
if (text == null || getParentActivity() == null) {
|
2014-03-10 10:27:49 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-06-13 12:42:21 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setMessage(text);
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
|
|
|
showAlertDialog(builder);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
@Override
|
|
|
|
public void needShowProgress() {
|
2014-06-13 12:42:21 +02:00
|
|
|
if (getParentActivity() == null || getParentActivity().isFinishing() || progressDialog != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
progressDialog = new ProgressDialog(getParentActivity());
|
|
|
|
progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
|
|
|
|
progressDialog.setCanceledOnTouchOutside(false);
|
|
|
|
progressDialog.setCancelable(false);
|
|
|
|
progressDialog.show();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-12-20 20:25:49 +01:00
|
|
|
public void needHideProgress() {
|
2014-06-13 12:42:21 +02:00
|
|
|
if (progressDialog == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2014-10-14 22:36:15 +02:00
|
|
|
progressDialog = null;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2013-12-20 20:25:49 +01:00
|
|
|
public void setPage(int page, boolean animated, Bundle params, boolean back) {
|
2013-12-23 00:47:35 +01:00
|
|
|
if(android.os.Build.VERSION.SDK_INT > 13) {
|
2013-12-20 20:25:49 +01:00
|
|
|
final SlideView outView = views[currentViewNum];
|
|
|
|
final SlideView newView = views[page];
|
|
|
|
currentViewNum = page;
|
|
|
|
|
|
|
|
newView.setParams(params);
|
2014-11-11 23:16:17 +01:00
|
|
|
actionBar.setTitle(newView.getHeaderName());
|
2013-12-20 20:25:49 +01:00
|
|
|
newView.onShow();
|
2014-07-03 00:39:05 +02:00
|
|
|
newView.setX(back ? -AndroidUtilities.displaySize.x : AndroidUtilities.displaySize.x);
|
2013-12-20 20:25:49 +01:00
|
|
|
outView.animate().setInterpolator(new AccelerateDecelerateInterpolator()).setListener(new Animator.AnimatorListener() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationStart(Animator animator) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animator) {
|
|
|
|
outView.setVisibility(View.GONE);
|
|
|
|
outView.setX(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationCancel(Animator animator) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationRepeat(Animator animator) {
|
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
}).setDuration(300).translationX(back ? AndroidUtilities.displaySize.x : -AndroidUtilities.displaySize.x).start();
|
2013-12-20 20:25:49 +01:00
|
|
|
newView.animate().setInterpolator(new AccelerateDecelerateInterpolator()).setListener(new Animator.AnimatorListener() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationStart(Animator animator) {
|
|
|
|
newView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animator) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationCancel(Animator animator) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationRepeat(Animator animator) {
|
|
|
|
}
|
|
|
|
}).setDuration(300).translationX(0).start();
|
|
|
|
} else {
|
|
|
|
views[currentViewNum].setVisibility(View.GONE);
|
|
|
|
currentViewNum = page;
|
|
|
|
views[page].setParams(params);
|
|
|
|
views[page].setVisibility(View.VISIBLE);
|
2014-11-11 23:16:17 +01:00
|
|
|
actionBar.setTitle(views[page].getHeaderName());
|
2013-12-20 20:25:49 +01:00
|
|
|
views[page].onShow();
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-12-20 20:25:49 +01:00
|
|
|
public void onNextAction() {
|
|
|
|
views[currentViewNum].onNextPressed();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-04 01:31:48 +02:00
|
|
|
public void saveSelfArgs(Bundle outState) {
|
2014-04-05 01:00:38 +02:00
|
|
|
saveCurrentState();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void needFinishActivity() {
|
2014-04-05 01:00:38 +02:00
|
|
|
clearCurrentState();
|
2014-06-04 01:31:48 +02:00
|
|
|
presentFragment(new MessagesActivity(null), true);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|