java 带有mvvm模式的Android活动类示例。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 带有mvvm模式的Android活动类示例。相关的知识,希望对你有一定的参考价值。

package com.dev.ui.auth;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.GraphRequest;
import com.facebook.appevents.AppEventsLogger;
import com.facebook.login.LoginManager;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.mevics.dev.R;
import com.mevics.dev.data.models.User;
import com.mevics.dev.data.source.AuthDataSource;
import com.mevics.dev.data.source.AuthRepository;
import com.mevics.dev.databinding.ActivityAuthBinding;
import com.mevics.dev.ui.dialog.AuthDialog;
import com.mevics.dev.util.MessageEvent;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONException;

import java.util.Arrays;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Activity class for auth screen that uses to authenticate users
 */

public class MyActivity extends AppCompatActivity{
    
    private ActivityAuthBinding binding;

    private AuthViewModel viewModel;

    private CallbackManager callbackManager;

    private LoginManager loginManager;

    @BindView(R.id.btnAuthFacebook)
    LoginButton loginButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FacebookSdk.sdkInitialize(getApplicationContext());
        AppEventsLogger.activateApp(this);
        callbackManager = CallbackManager.Factory.create();
        loginManager = LoginManager.getInstance();
        binding = DataBindingUtil.setContentView(this, R.layout.activity_my);
        ButterKnife.bind(this);
        viewModel = new AuthViewModel(this, callbackManager,
                getSupportFragmentManager(), loginButton);
        binding.setViewModel(viewModel);

    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        viewModel.onActivityResult(requestCode, resultCode, data);
    }

}

以上是关于java 带有mvvm模式的Android活动类示例。的主要内容,如果未能解决你的问题,请参考以下文章

Android 对比MVCMVP来聊聊MVVM模式的理解

java 具有MVVM模式的Android ViewModel类示例。

MVVM 模式和 startActivity

Android MVVM 对话框视图模型

防止键盘在活动开始时显示

在MVVM架构Android中启动服务的正确位置是什么