// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
// 
//     private MainPresenter mainPresenter;
// 
//     @DebugLog
//     @Override
//     protected void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         FirebaseCrashUtils.log("MainActivity created");
//         setContentView(R.layout.activity_main);
// 
//         mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
//         mainPresenter.start();
//     }
// }
// 
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
// 
//     private static AccountManager accountManager = new AccountManager();
//     private AccessToken accessToken;
//     private User me;
// 
//     private AccountManager() {
//     }
// 
//     public static AccountManager getInstance() {
//         return accountManager;
//     }
// 
//     public AccessToken getAccessToken() {
//         return accessToken;
//     }
// 
//     public void setAccessToken(AccessToken accessToken) {
//         this.accessToken = accessToken;
//     }
// 
//     public void setAccessToken(String token) {
//         accessToken = new GsonBuilder()
//                 .registerTypeAdapterFactory(ProteinAdapterFactory.create())
//                 .create()
//                 .fromJson(token, AccessToken.class);
//     }
// 
//     public boolean isLogin() {
//         return accessToken != null;
//     }
// 
//     public User getMe() {
//         return me;
//     }
// 
//     public void setMe(User me) {
//         this.me = me;
//     }
// 
//     public void clear() {
//         accessToken = null;
//         me = null;
//     }
// }
// 
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
// 
//     private Constants() {
//         throw new AssertionError("No construction for constant class");
//     }
// 
//     public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
// 
//     public static final String ACCESS_TOKEN_KEY = "access_token";
// 
//     public static final String USER = "user";
// 
// }


import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import com.ge.protein.R;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;
/*
 * Copyright 2017 Jiaheng Ge
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ge.protein.ui.dialog;



public class LogoutDialog extends DialogFragment {

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        return new AlertDialog.Builder(getContext())
                .setTitle(R.string.logout_title)
                .setMessage(R.string.logout_message)
                .setNegativeButton(R.string.dialog_cancel, (dialog, which) -> dismiss())
                .setPositiveButton(R.string.dialog_ok, (dialog, which) -> {
                    AccountManager.getInstance().clear();
                    SharedPreferences sp = getActivity().getSharedPreferences(Constants.DEFAULT_SHARED_PREFERENCES,
                            Context.MODE_PRIVATE);
                    sp.edit().remove(Constants.ACCESS_TOKEN_KEY).remove(Constants.USER).apply();

// Path: app/src/main/java/com/ge/protein/main/MainActivity.java
// public class MainActivity extends BaseProteinActivity {
// 
//     private MainPresenter mainPresenter;
// 
//     @DebugLog
//     @Override
//     protected void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         FirebaseCrashUtils.log("MainActivity created");
//         setContentView(R.layout.activity_main);
// 
//         mainPresenter = new MainPresenter((MainView) findViewById(R.id.main_view));
//         mainPresenter.start();
//     }
// }
// 
// Path: app/src/main/java/com/ge/protein/util/AccountManager.java
// public class AccountManager {
// 
//     private static AccountManager accountManager = new AccountManager();
//     private AccessToken accessToken;
//     private User me;
// 
//     private AccountManager() {
//     }
// 
//     public static AccountManager getInstance() {
//         return accountManager;
//     }
// 
//     public AccessToken getAccessToken() {
//         return accessToken;
//     }
// 
//     public void setAccessToken(AccessToken accessToken) {
//         this.accessToken = accessToken;
//     }
// 
//     public void setAccessToken(String token) {
//         accessToken = new GsonBuilder()
//                 .registerTypeAdapterFactory(ProteinAdapterFactory.create())
//                 .create()
//                 .fromJson(token, AccessToken.class);
//     }
// 
//     public boolean isLogin() {
//         return accessToken != null;
//     }
// 
//     public User getMe() {
//         return me;
//     }
// 
//     public void setMe(User me) {
//         this.me = me;
//     }
// 
//     public void clear() {
//         accessToken = null;
//         me = null;
//     }
// }
// 
// Path: app/src/main/java/com/ge/protein/util/Constants.java
// public final class Constants {
// 
//     private Constants() {
//         throw new AssertionError("No construction for constant class");
//     }
// 
//     public static final String DEFAULT_SHARED_PREFERENCES = "default_shared_preferences";
// 
//     public static final String ACCESS_TOKEN_KEY = "access_token";
// 
//     public static final String USER = "user";
// 
// }


// Path: app/src/main/java/com/ge/protein/ui/dialog/LogoutDialog.java
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import com.ge.protein.R;
import com.ge.protein.main.MainActivity;
import com.ge.protein.util.AccountManager;
import com.ge.protein.util.Constants;

/*
 * Copyright 2017 Jiaheng Ge
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ge.protein.ui.dialog;



public class LogoutDialog extends DialogFragment {

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        return new AlertDialog.Builder(getContext())
                .setTitle(R.string.logout_title)
                .setMessage(R.string.logout_message)
                .setNegativeButton(R.string.dialog_cancel, (dialog, which) -> dismiss())
                .setPositiveButton(R.string.dialog_ok, (dialog, which) -> {
                    AccountManager.getInstance().clear();
                    SharedPreferences sp = getActivity().getSharedPreferences(Constants.DEFAULT_SHARED_PREFERENCES,
                            Context.MODE_PRIVATE);
                    sp.edit().remove(Constants.ACCESS_TOKEN_KEY).remove(Constants.USER).apply();

                    Intent intent = new Intent(getContext(), MainActivity.class);