/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  android.app.Activity
 *  android.app.AlertDialog
 *  android.app.AlertDialog$Builder
 *  android.app.Dialog
 *  android.content.Context
 *  android.content.DialogInterface
 *  android.content.DialogInterface$OnClickListener
 *  android.content.Intent
 *  android.content.SharedPreferences
 *  android.content.SharedPreferences$Editor
 *  android.content.res.Resources
 *  android.os.Bundle
 *  android.text.Editable
 *  android.text.TextPaint
 *  android.view.LayoutInflater
 *  android.view.MotionEvent
 *  android.view.View
 *  android.view.View$OnClickListener
 *  android.view.View$OnTouchListener
 *  android.view.ViewGroup
 *  android.view.ViewGroup$LayoutParams
 *  android.view.ViewParent
 *  android.widget.EditText
 *  android.widget.ImageButton
 *  android.widget.ImageView
 *  android.widget.TableLayout
 *  android.widget.TableRow
 *  android.widget.TableRow$LayoutParams
 *  android.widget.TextView
 *  android.widget.Toast
 *  java.lang.CharSequence
 *  java.lang.Class
 *  java.lang.Exception
 *  java.lang.Integer
 *  java.lang.Object
 *  java.lang.String
 *  java.lang.StringBuilder
 *  java.lang.reflect.Field
 *  java.util.Iterator
 *  java.util.Map
 *  java.util.Set
 */
package com.xinli.portalclient;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextPaint;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
import com.xinli.portalclient.MainActivity;
import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class SetAccountActivity
extends Activity {
    public static final String DEFAULT_ACCOUNT = "default_account";
    public static final int REFRESH;
    private Dialog accountDialog;
    private ImageView btnAdd;
    private SharedPreferences defaultAccFile;
    private int defaultAccountTextId;
    private EditText password;
    private SharedPreferences sp;
    private TableLayout tableLayout;
    private EditText username;

    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    private String accountShowOnPage(String string2) {
        StringBuilder stringBuilder = new StringBuilder();
        int n = string2.length();
        if (n > 10) {
            stringBuilder = new StringBuilder(string2.substring(0, 10));
            stringBuilder.append("...").append(string2.substring(n - 6));
            do {
                return stringBuilder.toString();
                break;
            } while (true);
        }
        stringBuilder.append(string2);
        return stringBuilder.toString();
    }

    private void addAccount(String string2, String string3) {
        if (string2.isEmpty() || string3.isEmpty()) {
            Toast.makeText((Context)this.getApplicationContext(), (CharSequence)"\u5e10\u53f7\u6216\u5bc6\u7801\u5747\u4e0d\u80fd\u4e3a\u7a7a\uff01", (int)0).show();
            super.setDialogMiss(this.accountDialog, false);
            return;
        }
        Set set = this.sp.getAll().keySet();
        if (set.contains((Object)string2)) {
            Toast.makeText((Context)this.getApplicationContext(), (int)2131099671, (int)0).show();
            super.setDialogMiss(this.accountDialog, false);
            return;
        }
        SharedPreferences.Editor editor = this.sp.edit();
        editor.putString(string2, string3);
        editor.commit();
        if (set.size() == 0) {
            SharedPreferences.Editor editor2 = this.defaultAccFile.edit();
            editor2.putString("default_account", string2);
            editor2.commit();
            ((TextView)this.findViewById(2131296274)).setText((CharSequence)string2);
            this.defaultAccountTextId = 13;
        }
        Toast.makeText((Context)this.getApplicationContext(), (CharSequence)"\u5e10\u53f7\u4fdd\u5b58\u6210\u529f\uff01", (int)0).show();
        super.setDialogMiss(this.accountDialog, true);
        super.showAccount(string2, 1 + set.size());
    }

    private void defaultAccount(final View view) {
        final TextView textView = (TextView)this.findViewById(Integer.valueOf((int)(1 + view.getId())).intValue());
        this.accountDialog = new AlertDialog.Builder((Context)this).setTitle((CharSequence)"\u9ed8\u8ba4\u5e10\u53f7").setMessage((CharSequence)("\u786e\u5b9a\u8bbe\u7f6e\u5e10\u53f7" + (Object)textView.getText() + "\u4e3a\u9ed8\u8ba4\u5e10\u53f7\u5417\uff1f")).setPositiveButton((CharSequence)"\u786e\u5b9a", new DialogInterface.OnClickListener(){

            public void onClick(DialogInterface dialogInterface, int n) {
                SetAccountActivity.this.setDefaultAccount(view.getId(), textView.getText().toString());
            }
        }).setNeutralButton((CharSequence)"\u53d6\u6d88", new DialogInterface.OnClickListener(){

            public void onClick(DialogInterface dialogInterface, int n) {
                SetAccountActivity.this.setDialogMiss(SetAccountActivity.this.accountDialog, true);
            }
        }).create();
        this.accountDialog.show();
    }

    private void delAccount(final View view) {
        final TextView textView = (TextView)this.findViewById(Integer.valueOf((int)(-2 + view.getId())).intValue());
        final TextView textView2 = (TextView)this.findViewById(Integer.valueOf((int)(2 + view.getId())).intValue());
        this.accountDialog = new AlertDialog.Builder((Context)this).setTitle((CharSequence)"\u5220\u9664\u5e10\u53f7").setMessage((CharSequence)("\u786e\u5b9a\u5220\u9664\u5e10\u53f7" + (Object)textView2.getText() + "\u5417\uff1f")).setPositiveButton((CharSequence)"\u786e\u5b9a", new DialogInterface.OnClickListener(){

            public void onClick(DialogInterface dialogInterface, int n) {
                TableRow tableRow = (TableRow)view.getParent();
                SetAccountActivity.this.tableLayout.removeView((View)tableRow);
                SharedPreferences.Editor editor = SetAccountActivity.this.sp.edit();
                editor.remove(textView2.getText().toString());
                editor.commit();
                int n2 = textView.getId() / 10;
                int n3 = 10 + textView.getId();
                int n4 = 0;
                do {
                    if (n4 >= SetAccountActivity.this.sp.getAll().size() - n2) {
                        if (textView2.getText().equals((Object)SetAccountActivity.this.defaultAccFile.getString("default_account", ""))) {
                            ((TextView)SetAccountActivity.this.findViewById(2131296274)).setText((CharSequence)"");
                            SharedPreferences.Editor editor2 = SetAccountActivity.this.defaultAccFile.edit();
                            editor2.remove("default_account");
                            editor2.commit();
                        }
                        return;
                    }
                    TextView textView4 = (TextView)SetAccountActivity.this.findViewById(n3);
                    ImageView imageView = (ImageView)SetAccountActivity.this.findViewById(n3 + 1);
                    ImageView imageView2 = (ImageView)SetAccountActivity.this.findViewById(n3 + 2);
                    TextView textView22 = (TextView)SetAccountActivity.this.findViewById(n3 + 3);
                    TextView textView3 = (TextView)SetAccountActivity.this.findViewById(n3 + 4);
                    int n5 = -10 + textView4.getId();
                    textView4.setId(n5);
                    imageView.setId(n5 + 1);
                    imageView2.setId(n5 + 2);
                    textView22.setId(n5 + 3);
                    textView3.setId(n5 + 4);
                    n3 += 10;
                    ++n4;
                } while (true);
            }
        }).setNeutralButton((CharSequence)"\u53d6\u6d88", new DialogInterface.OnClickListener(){

            public void onClick(DialogInterface dialogInterface, int n) {
                SetAccountActivity.this.setDialogMiss(SetAccountActivity.this.accountDialog, true);
            }
        }).create();
        this.accountDialog.show();
    }

    private void editAccount(View view) {
        final TextView textView = (TextView)this.findViewById(Integer.valueOf((int)(-1 + view.getId())).intValue());
        final TextView textView2 = (TextView)this.findViewById(Integer.valueOf((int)(3 + view.getId())).intValue());
        final String string2 = textView2.getText().toString();
        final String string3 = this.sp.getString(string2, "");
        View view2 = LayoutInflater.from((Context)this).inflate(2130903041, null);
        this.username = (EditText)view2.findViewById(2131296266);
        this.password = (EditText)view2.findViewById(2131296267);
        this.username.setText((CharSequence)string2);
        this.password.setText((CharSequence)string3);
        this.accountDialog = new AlertDialog.Builder((Context)this).setTitle((CharSequence)"\u7f16\u8f91\u5e10\u53f7").setView(view2).setPositiveButton((CharSequence)"\u786e\u5b9a", new DialogInterface.OnClickListener(){

            public void onClick(DialogInterface dialogInterface, int n) {
                if (SetAccountActivity.this.username.getText().toString().isEmpty() || SetAccountActivity.this.password.getText().toString().isEmpty()) {
                    Toast.makeText((Context)SetAccountActivity.this.getApplicationContext(), (CharSequence)"\u5e10\u53f7\u548c\u5bc6\u7801\u5747\u4e0d\u80fd\u4e3a\u7a7a\uff01", (int)0).show();
                    SetAccountActivity.this.username.setText((CharSequence)string2);
                    SetAccountActivity.this.password.setText((CharSequence)string3);
                    SetAccountActivity.this.setDialogMiss(SetAccountActivity.this.accountDialog, false);
                    return;
                }
                if (!SetAccountActivity.this.username.getText().toString().equals((Object)string2) && SetAccountActivity.this.sp.getAll().keySet().contains((Object)SetAccountActivity.this.username.getText().toString())) {
                    Toast.makeText((Context)SetAccountActivity.this.getApplicationContext(), (int)2131099671, (int)0).show();
                    SetAccountActivity.this.setDialogMiss(SetAccountActivity.this.accountDialog, false);
                    return;
                }
                SharedPreferences.Editor editor = SetAccountActivity.this.sp.edit();
                editor.remove(string2);
                editor.putString(SetAccountActivity.this.username.getText().toString(), SetAccountActivity.this.password.getText().toString());
                editor.commit();
                String string22 = SetAccountActivity.this.accountShowOnPage(SetAccountActivity.this.username.getText().toString());
                textView.setText((CharSequence)string22);
                textView2.setText((CharSequence)SetAccountActivity.this.username.getText().toString());
                if (SetAccountActivity.this.defaultAccFile.getString("default_account", "").equals((Object)string2)) {
                    ((TextView)SetAccountActivity.this.findViewById(2131296274)).setText((CharSequence)SetAccountActivity.this.username.getText().toString());
                    SharedPreferences.Editor editor2 = SetAccountActivity.this.defaultAccFile.edit();
                    editor2.putString("default_account", SetAccountActivity.this.username.getText().toString());
                    editor2.commit();
                }
                SetAccountActivity.this.setDialogMiss(SetAccountActivity.this.accountDialog, true);
            }
        }).setNeutralButton((CharSequence)"\u53d6\u6d88", new DialogInterface.OnClickListener(){

            public void onClick(DialogInterface dialogInterface, int n) {
                SetAccountActivity.this.setDialogMiss(SetAccountActivity.this.accountDialog, true);
            }
        }).create();
        this.accountDialog.show();
    }

    private void setDefaultAccount(int n, String string2) {
        TextView textView;
        ((TextView)this.findViewById(2131296274)).setText((CharSequence)string2);
        SharedPreferences.Editor editor = this.defaultAccFile.edit();
        editor.putString("default_account", string2);
        editor.commit();
        if (this.defaultAccountTextId != 0 && (textView = (TextView)this.findViewById(this.defaultAccountTextId)) != null) {
            textView.setText((CharSequence)"\u8bbe\u4e3a\u9ed8\u8ba4");
        }
        this.defaultAccountTextId = n;
        ((TextView)this.findViewById(this.defaultAccountTextId)).setText((CharSequence)"");
    }

    /*
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    private void setDialogMiss(Dialog dialog, boolean bl) {
        try {
            Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
            field.setAccessible(true);
            field.set((Object)dialog, (Object)bl);
        }
        catch (Exception var3_4) {
            var3_4.printStackTrace();
        }
        if (bl) {
            dialog.dismiss();
        }
    }

    /*
     * Enabled aggressive block sorting
     */
    private void showAccount(String string2, int n) {
        TextView textView = new TextView((Context)this);
        textView.setId(Integer.valueOf((String)(String.valueOf((int)n) + "0")).intValue());
        textView.setText((CharSequence)super.accountShowOnPage(string2));
        textView.setGravity(3);
        textView.setPadding(25, 25, 0, 25);
        textView.getPaint().setFlags(8);
        textView.setLayoutParams((ViewGroup.LayoutParams)new TableRow.LayoutParams(-1, -2));
        TextView textView2 = new TextView((Context)this);
        textView2.setId(Integer.valueOf((String)(String.valueOf((int)n) + "3")).intValue());
        if (!this.defaultAccFile.getString("default_account", "").equals((Object)string2)) {
            textView2.setText((CharSequence)"\u8bbe\u4e3a\u9ed8\u8ba4");
        } else {
            this.defaultAccountTextId = textView2.getId();
        }
        TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(-1, -2);
        layoutParams.rightMargin = 25;
        textView2.setPadding(0, 25, 0, 25);
        textView2.setLayoutParams((ViewGroup.LayoutParams)layoutParams);
        textView2.setOnClickListener(new View.OnClickListener(){

            public void onClick(View view) {
                if (!((TextView)SetAccountActivity.this.findViewById(Integer.valueOf((int)view.getId()).intValue())).getText().toString().isEmpty()) {
                    SetAccountActivity.this.defaultAccount(view);
                }
            }
        });
        ImageView imageView = new ImageView((Context)this);
        imageView.setId(Integer.valueOf((String)(String.valueOf((int)n) + "1")).intValue());
        imageView.setBackgroundResource(2130837508);
        TableRow.LayoutParams layoutParams2 = new TableRow.LayoutParams(-1, -2);
        layoutParams2.rightMargin = 25;
        imageView.setLayoutParams((ViewGroup.LayoutParams)layoutParams2);
        imageView.setOnClickListener(new View.OnClickListener(){

            public void onClick(View view) {
                SetAccountActivity.this.editAccount(view);
            }
        });
        ImageView imageView2 = new ImageView((Context)this);
        imageView2.setId(Integer.valueOf((String)(String.valueOf((int)n) + "2")).intValue());
        imageView2.setBackgroundResource(2130837507);
        TableRow.LayoutParams layoutParams3 = new TableRow.LayoutParams(-1, -2);
        layoutParams3.rightMargin = 25;
        imageView2.setLayoutParams((ViewGroup.LayoutParams)layoutParams3);
        imageView2.setOnClickListener(new View.OnClickListener(){

            public void onClick(View view) {
                SetAccountActivity.this.delAccount(view);
            }
        });
        TextView textView3 = new TextView((Context)this);
        textView3.setId(Integer.valueOf((String)(String.valueOf((int)n) + "4")).intValue());
        textView3.setText((CharSequence)string2);
        textView3.setVisibility(8);
        TableRow tableRow = new TableRow((Context)this);
        tableRow.setGravity(17);
        tableRow.setBackgroundColor(this.getResources().getColor(2130968590));
        tableRow.setLayoutParams((ViewGroup.LayoutParams)new TableRow.LayoutParams(-1, -2));
        tableRow.addView((View)textView);
        tableRow.addView((View)textView2);
        tableRow.addView((View)imageView);
        tableRow.addView((View)imageView2);
        tableRow.addView((View)textView3);
        this.tableLayout.addView((View)tableRow);
    }

    public void addAccountDialog() {
        View view = LayoutInflater.from((Context)this).inflate(2130903041, null);
        this.username = (EditText)view.findViewById(2131296266);
        this.password = (EditText)view.findViewById(2131296267);
        this.accountDialog = new AlertDialog.Builder((Context)this).setTitle((CharSequence)"\u6dfb\u52a0\u5e10\u53f7").setView(view).setPositiveButton((CharSequence)"\u786e\u5b9a", new DialogInterface.OnClickListener(){

            public void onClick(DialogInterface dialogInterface, int n) {
                SetAccountActivity.this.addAccount(SetAccountActivity.this.username.getText().toString(), SetAccountActivity.this.password.getText().toString());
            }
        }).setNeutralButton((CharSequence)"\u53d6\u6d88", new DialogInterface.OnClickListener(){

            public void onClick(DialogInterface dialogInterface, int n) {
                SetAccountActivity.this.setDialogMiss(SetAccountActivity.this.accountDialog, true);
            }
        }).create();
        this.accountDialog.show();
    }

    protected void onCreate(Bundle bundle) {
        this.requestWindowFeature(1);
        super.onCreate(bundle);
        this.setContentView(2130903044);
        ImageButton imageButton = (ImageButton)this.findViewById(2131296271);
        TextView textView = (TextView)this.findViewById(2131296274);
        this.sp = this.getSharedPreferences("passwordFile", 0);
        this.defaultAccFile = this.getSharedPreferences("default_account", 0);
        textView.setText((CharSequence)this.defaultAccFile.getString("default_account", ""));
        this.tableLayout = (TableLayout)this.findViewById(2131296277);
        this.btnAdd = (ImageView)this.findViewById(2131296278);
        int n = 1;
        Iterator iterator = this.sp.getAll().keySet().iterator();
        do {
            if (!iterator.hasNext()) {
                this.btnAdd.setBackgroundResource(2130837505);
                this.btnAdd.setOnTouchListener(new View.OnTouchListener(){

                    /*
                     * Enabled aggressive block sorting
                     */
                    public boolean onTouch(View view, MotionEvent motionEvent) {
                        if (motionEvent.getAction() == 0) {
                            view.setBackgroundResource(2130837506);
                            return false;
                        }
                        if (motionEvent.getAction() != 1) return false;
                        view.setBackgroundResource(2130837505);
                        return false;
                    }
                });
                this.btnAdd.setOnClickListener(new View.OnClickListener(){

                    public void onClick(View view) {
                        SetAccountActivity.this.addAccountDialog();
                    }
                });
                imageButton.setBackgroundResource(2130837536);
                imageButton.setOnTouchListener(new View.OnTouchListener(){

                    /*
                     * Enabled aggressive block sorting
                     */
                    public boolean onTouch(View view, MotionEvent motionEvent) {
                        if (motionEvent.getAction() == 0) {
                            view.setBackgroundResource(2130837537);
                            return false;
                        }
                        if (motionEvent.getAction() != 1) return false;
                        view.setBackgroundResource(2130837536);
                        return false;
                    }
                });
                imageButton.setOnClickListener(new View.OnClickListener(){

                    public void onClick(View view) {
                        Intent intent = new Intent();
                        intent.setClass((Context)SetAccountActivity.this, (Class)MainActivity.class);
                        SetAccountActivity.this.startActivity(intent);
                        SetAccountActivity.this.finish();
                    }
                });
                return;
            }
            super.showAccount((String)iterator.next(), n);
            ++n;
        } while (true);
    }

}

