package org.telegram;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import org.telegram.messenger.R;
import org.telegram.tgnet.ConnectionsManager;

import rx.Subscriber;
import rx.functions.Action1;
import rx.subjects.PublishSubject;


public class MainActivity extends AppCompatActivity {

    EditText editText;
    ConnectionsManager connectionsManager;
    private int value = 0;

    private PublishSubject<Integer> subject ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ConnectionsManager.setProxySettings("NewProxy.dynu.net",9969,"00000000000000000000000000000000");
                getSubject().subscribe(new Subscriber<Integer>() {
                    @Override
                    public void onCompleted() {
                        Log.e("Tag","onCompleted");
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e("Tag","onError");
                    }

                    @Override
                    public void onNext(Integer integer) {
                        Log.e("Tag","rxvalue :"+integer);
                    }
                });
                setValue(15);
            }


        });





    }

    private PublishSubject<Integer> getSubject()
    {
        subject=PublishSubject.create();
        return subject;
    }


    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
        if (subject !=null)
        {
            subject.onNext(value);
            subject.onCompleted();
        }


    }


}
