Search in sources :

Example 1 with AccountHelper

use of net.iGap.module.accountManager.AccountHelper in project iGap-Android by KianIranian-STDG.

the class FragmentSettingViewModel method logout.

public void logout() {
    showLoading.set(View.VISIBLE);
    new HelperLogout().logoutUserWithRequest(new HelperLogout.LogOutUserCallBack() {

        @Override
        public void onLogOut() {
            // ToDo: foxed it and remove G.handler
            G.handler.post(() -> {
                boolean haveAnotherAccount = new AccountHelper().logoutAccount();
                showLoading.set(View.GONE);
                if (haveAnotherAccount) {
                    updateForOtherAccount.postValue(true);
                } else {
                    goToRegisterPage.postValue(true);
                }
            });
        }

        @Override
        public void onError() {
            showLoading.set(View.GONE);
            showError.postValue(true);
        }
    });
}
Also used : AccountHelper(net.iGap.module.accountManager.AccountHelper) HelperLogout(net.iGap.helper.HelperLogout)

Example 2 with AccountHelper

use of net.iGap.module.accountManager.AccountHelper in project iGap-Android by KianIranian-STDG.

the class ActivityMain method checkIntent.

private void checkIntent(Intent intent) {
    if (G.isRestartActivity) {
        return;
    }
    if (intent.getAction() != null && intent.getAction().equals("net.iGap.payment")) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        Fragment fragment = fragmentManager.findFragmentByTag(PaymentFragment.class.getName());
        if (fragment instanceof PaymentFragment) {
            ((PaymentFragment) fragment).setPaymentResult(new Payment(intent.getStringExtra("status"), intent.getStringExtra("message"), intent.getStringExtra("order_id"), intent.getStringExtra("tax"), intent.getStringExtra("discount")));
        }
    }
    new HelperGetDataFromOtherApp(this, intent);
    // check has shared data if true setup main fragment (room list) ui
    Fragment fragmentBottomNav = getSupportFragmentManager().findFragmentByTag(BottomNavigationFragment.class.getName());
    if (fragmentBottomNav instanceof BottomNavigationFragment) {
        // set true just for checking state
        ((BottomNavigationFragment) fragmentBottomNav).checkHasSharedData(true);
        ((BottomNavigationFragment) fragmentBottomNav).isFirstTabItem();
    }
    if (intent.getAction() != null && intent.getAction().equals("net.iGap.activities.OPEN_ACCOUNT")) {
        new HelperFragment(getSupportFragmentManager(), new FragmentSetting()).load();
    }
    Bundle extras = intent.getExtras();
    if (extras != null) {
        long roomId = extras.getLong(ActivityMain.openChat);
        if (!FragmentLanguage.languageChanged && roomId > 0) {
            // if language changed not need check enter to chat
            // GoToChatActivity goToChatActivity = new GoToChatActivity(roomId);
            // TODO this change is duo to room null bug. if it works server must change routine.
            long peerId = extras.getLong("PeerID");
            long userId = extras.getLong(ActivityMain.userId);
            if (AccountManager.getInstance().getCurrentUser().getId() != userId) {
                new AccountHelper().changeAccount(userId);
                updateUiForChangeAccount();
            }
            HelperUrl.goToActivityFromFCM(this, roomId, peerId);
        }
        FragmentLanguage.languageChanged = false;
        boolean openMediaPlayer = extras.getBoolean(ActivityMain.openMediaPlayer);
        if (openMediaPlayer) {
            if (getSupportFragmentManager().findFragmentByTag(FragmentMediaPlayer.class.getName()) == null) {
                FragmentMediaPlayer fragment = new FragmentMediaPlayer();
                new HelperFragment(getSupportFragmentManager(), fragment).setReplace(false).load();
            }
        }
    }
}
Also used : HelperGetDataFromOtherApp(net.iGap.helper.HelperGetDataFromOtherApp) AccountHelper(net.iGap.module.accountManager.AccountHelper) PaymentFragment(net.iGap.fragments.PaymentFragment) FragmentSetting(net.iGap.fragments.FragmentSetting) Bundle(android.os.Bundle) PaymentFragment(net.iGap.fragments.PaymentFragment) Fragment(androidx.fragment.app.Fragment) HelperFragment(net.iGap.helper.HelperFragment) OpenFragment(net.iGap.observers.interfaces.OpenFragment) TabletEmptyChatFragment(net.iGap.fragments.TabletEmptyChatFragment) BaseFragment(net.iGap.fragments.BaseFragment) CameraStoryFragment(net.iGap.story.CameraStoryFragment) CallSelectFragment(net.iGap.fragments.CallSelectFragment) SearchFragment(net.iGap.fragments.SearchFragment) DiscoveryFragment(net.iGap.fragments.discovery.DiscoveryFragment) BottomNavigationFragment(net.iGap.fragments.BottomNavigationFragment) FragmentManager(androidx.fragment.app.FragmentManager) OnPayment(net.iGap.observers.interfaces.OnPayment) Payment(net.iGap.model.payment.Payment) BottomNavigationFragment(net.iGap.fragments.BottomNavigationFragment) FragmentMediaPlayer(net.iGap.fragments.FragmentMediaPlayer) HelperFragment(net.iGap.helper.HelperFragment)

Example 3 with AccountHelper

use of net.iGap.module.accountManager.AccountHelper in project iGap-Android by KianIranian-STDG.

the class AccountsDialog method checkForAssigning.

public void checkForAssigning(boolean assign, long id) {
    if (assign) {
        if (getActivity() instanceof ActivityMain && AccountManager.getInstance().getCurrentUser().getId() != id) {
            new AccountHelper().changeAccount(id);
            ((ActivityMain) getActivity()).updateUiForChangeAccount();
        }
        dismiss();
    } else {
        if (getActivity() != null) {
            HelperTracker.sendTracker(HelperTracker.TRACKER_ADD_NEW_ACCOUNT);
            new AccountHelper().addAccount();
            // WebSocketClient.GGFconnectNewAccount();
            Intent intent = new Intent(getActivity(), ActivityRegistration.class);
            intent.putExtra("add account", true);
            getActivity().startActivity(intent);
            getActivity().finish();
        }
    }
}
Also used : AccountHelper(net.iGap.module.accountManager.AccountHelper) ActivityMain(net.iGap.activities.ActivityMain) Intent(android.content.Intent)

Example 4 with AccountHelper

use of net.iGap.module.accountManager.AccountHelper in project iGap-Android by KianIranian-STDG.

the class ActivityMain method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    sharedPreferences = getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE);
    super.onCreate(savedInstanceState);
    if (Config.FILE_LOG_ENABLE) {
        FileLog.i("Main activity on create");
    }
    setContentView(R.layout.activity_main);
    detectDeviceType();
    G.logoutAccount.observe(this, isLogout -> {
        if (isLogout != null && isLogout) {
            boolean haveOtherAccount = new AccountHelper().logoutAccount();
            if (haveOtherAccount) {
                updateUiForChangeAccount();
            } else {
                try {
                    NotificationManager nMgr = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
                    nMgr.cancelAll();
                } catch (Exception e) {
                    e.getStackTrace();
                }
                if (MusicPlayer.mp != null && MusicPlayer.mp.isPlaying()) {
                    MusicPlayer.stopSound();
                    MusicPlayer.closeLayoutMediaPlayer();
                }
                startActivity(new Intent(this, ActivityRegistration.class));
                finish();
            }
        }
    });
    if (G.ISRealmOK) {
        finishActivity = new FinishActivity() {

            @Override
            public void finishActivity() {
                // ActivityChat.this.finish();
                finish();
            }
        };
        if (G.isFirstPassCode) {
            openActivityPassCode();
        }
        initTabStrip(getIntent());
        // add it for handle ssl handshake error
        checkGoogleUpdate();
        G.refreshWalletBalance = this;
        BroadcastReceiver receiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
            // code...
            }
        };
        IntentFilter ringgerFilter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
        audioManagerReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                // code...
                if (!G.appChangeRinggerMode) {
                    AudioManager mainAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
                    G.mainRingerMode = mainAudioManager.getRingerMode();
                }
            }
        };
        registerReceiver(audioManagerReceiver, new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION));
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            if (Build.BRAND.equalsIgnoreCase("xiaomi") || Build.BRAND.equalsIgnoreCase("Honor") || Build.BRAND.equalsIgnoreCase("oppo") || Build.BRAND.equalsIgnoreCase("asus"))
                isChinesPhone();
        }
        EventManager.getInstance(AccountManager.selectedAccount).addObserver(EventManager.ON_ACCESS_TOKEN_RECIVE, this);
        // getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        boolean deleteFolderBackground = sharedPreferences.getBoolean(SHP_SETTING.DELETE_FOLDER_BACKGROUND, true);
        if (deleteFolderBackground) {
            deleteContentFolderChatBackground();
            sharedPreferences.edit().putBoolean(SHP_SETTING.DELETE_FOLDER_BACKGROUND, false).apply();
        }
        if (G.twoPaneMode) {
            G.isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
            designLayout(chatLayoutMode.none);
            setDialogFragmentSize();
            G.iTowPanModDesinLayout = new ITowPanModDesinLayout() {

                @Override
                public void onLayout(chatLayoutMode mode) {
                    designLayout(mode);
                }

                @Override
                public boolean getBackChatVisibility() {
                    FrameLayout fullScreenFrame = findViewById(R.id.fullScreenFrame);
                    if (fullScreenFrame != null) {
                        return G.twoPaneMode && fullScreenFrame.getVisibility() == View.VISIBLE;
                    }
                    return false;
                }

                @Override
                public void setBackChatVisibility(boolean visibility) {
                    if (G.twoPaneMode) {
                        findViewById(R.id.fullScreenFrame).setVisibility(View.VISIBLE);
                    }
                }
            };
        }
        isOpenChatBeforeShare = false;
        initComponent();
        G.onPayment = this;
        sharedPreferences = getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE);
        boolean isGetContactList = sharedPreferences.getBoolean(SHP_SETTING.KEY_GET_CONTACT, false);
        /**
         * just do this action once
         */
        new PermissionHelper(this).grantReadPhoneStatePermission();
        if (!isGetContactList) {
            try {
                HelperPermission.getContactPermision(ActivityMain.this, new OnGetPermission() {

                    @Override
                    public void Allow() throws IOException {
                        if (!G.isSendContact) {
                            G.isSendContact = true;
                            LoginActions.importContact();
                        }
                        SharedPreferences.Editor editor = sharedPreferences.edit();
                        editor.putBoolean(SHP_SETTING.KEY_GET_CONTACT, true);
                        editor.apply();
                    }

                    @Override
                    public void deny() {
                        SharedPreferences.Editor editor = sharedPreferences.edit();
                        editor.putBoolean(SHP_SETTING.KEY_GET_CONTACT, true);
                        editor.apply();
                        /**
                         * user not allowed to import contact, so client set
                         * isSendContact = true for avoid from try again
                         */
                        isSendContact = true;
                    }
                });
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        HelperNotification.getInstance().cancelNotification();
        G.onGroupAvatarResponse = this;
        G.onConvertToGroup = new OpenFragment() {

            @Override
            public void openFragmentOnActivity(String type, final Long roomId) {
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        FragmentNewGroup fragmentNewGroup = new FragmentNewGroup();
                        Bundle bundle = new Bundle();
                        bundle.putString("TYPE", "ConvertToGroup");
                        bundle.putLong("ROOMID", roomId);
                        fragmentNewGroup.setArguments(bundle);
                        try {
                            new HelperFragment(getSupportFragmentManager(), fragmentNewGroup).setStateLoss(true).load();
                        } catch (Exception e) {
                            e.getStackTrace();
                        }
                    }
                });
            }
        };
        connectionState();
        new Thread(this::checkKeepMedia).start();
        G.onVerifyNewDevice = new OnVerifyNewDevice() {

            @Override
            public void verifyNewDevice(String appName, int appId, int appBuildVersion, String appVersion, ProtoGlobal.Platform platform, String platformVersion, ProtoGlobal.Device device, String deviceName, boolean twoStepVerification) {
                final String content = "" + "App name: " + appName + "\n" + "Build version: " + appBuildVersion + "\n" + "App version: " + appVersion + "\n" + "Platform: " + platform + "\n" + "Platform version: " + platformVersion + "\n" + "Device: " + device + "\n" + "Device name: " + deviceName;
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        if (HelperCalander.isPersianUnicode) {
                            new MaterialDialog.Builder(ActivityMain.this).title(R.string.Input_device_specification).contentGravity(GravityEnum.END).content(content).positiveText(R.string.B_ok).show();
                        } else {
                            new MaterialDialog.Builder(ActivityMain.this).title(R.string.Input_device_specification).contentGravity(GravityEnum.START).content(content).positiveText(R.string.B_ok).show();
                        }
                    }
                });
            }

            @Override
            public void errorVerifyNewDevice(final int majorCode, final int minCode) {
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                    }
                });
            }
        };
        boolean isDefaultBg = sharedPreferences.getBoolean(SHP_SETTING.KEY_CHAT_BACKGROUND_IS_DEFAULT, true);
        if (isDefaultBg) {
            sharedPreferences.edit().putString(SHP_SETTING.KEY_PATH_CHAT_BACKGROUND, "").apply();
        }
    } else {
        TextView textView = new TextView(this);
        setContentView(textView);
        showToast(textView);
    }
    int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        AndroidUtils.statusBarHeight = getResources().getDimensionPixelSize(resourceId);
    }
    getSupportFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {

        @Override
        public void onBackStackChanged() {
            try {
                Log.wtf(this.getClass().getName(), "------------------------------------------------");
                for (int i = 0; i < getSupportFragmentManager().getBackStackEntryCount(); i++) {
                    Log.wtf(this.getClass().getName(), "fragment: " + getSupportFragmentManager().getBackStackEntryAt(i).getName());
                }
                Log.wtf(this.getClass().getName(), "------------------------------------------------");
            } catch (OutOfMemoryError error) {
                Log.e(this.getClass().getName(), error.getMessage());
            }
        }
    });
    GPSTracker.getGpsTrackerInstance().checkLocation();
    Log.wtf(this.getClass().getName(), "onCreate");
    try {
        InstallReferrerClient referrerClient = InstallReferrerClient.newBuilder(this).build();
        backgroundExecutor.execute(() -> getInstallReferrerFromClient(referrerClient));
        if (getIntent() != null) {
            checkIntent(getIntent());
        }
    } catch (RuntimeException e) {
        Log.e(this.getClass().getName(), e.getMessage());
    }
}
Also used : ProtoGlobal(net.iGap.proto.ProtoGlobal) OnGetPermission(net.iGap.observers.interfaces.OnGetPermission) AudioManager(android.media.AudioManager) FinishActivity(net.iGap.observers.interfaces.FinishActivity) TextView(android.widget.TextView) Context(android.content.Context) InstallReferrerClient(com.android.installreferrer.api.InstallReferrerClient) AccountHelper(net.iGap.module.accountManager.AccountHelper) IntentFilter(android.content.IntentFilter) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) NotificationManager(android.app.NotificationManager) OpenFragment(net.iGap.observers.interfaces.OpenFragment) Bundle(android.os.Bundle) FragmentNewGroup(net.iGap.fragments.FragmentNewGroup) Intent(android.content.Intent) IOException(java.io.IOException) BroadcastReceiver(android.content.BroadcastReceiver) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ActivityNotFoundException(android.content.ActivityNotFoundException) SuppressLint(android.annotation.SuppressLint) FragmentManager(androidx.fragment.app.FragmentManager) PermissionHelper(net.iGap.helper.PermissionHelper) FrameLayout(android.widget.FrameLayout) HelperFragment(net.iGap.helper.HelperFragment) ITowPanModDesinLayout(net.iGap.observers.interfaces.ITowPanModDesinLayout) OnVerifyNewDevice(net.iGap.observers.interfaces.OnVerifyNewDevice)

Example 5 with AccountHelper

use of net.iGap.module.accountManager.AccountHelper in project iGap-Android by KianIranian-STDG.

the class ActivityRegistration method onBackPressed.

@Override
public void onBackPressed() {
    Log.wtf(this.getClass().getName(), "onBackPressed 0");
    Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.registrationFrame);
    if (!(fragment instanceof FragmentActivation) && !(fragment instanceof FragmentRegistrationNickname)) {
        if (getSupportFragmentManager().getBackStackEntryCount() > 1) {
            Log.wtf(this.getClass().getName(), "onBackPressed");
            super.onBackPressed();
        } else {
            if (getIntent().getBooleanExtra("add account", false)) {
                new AccountHelper().changeAccount();
                Log.wtf(this.getClass().getName(), "current user: " + AccountManager.getInstance().getCurrentUser());
                finish();
                startActivity(new Intent(this, ActivityMain.class));
            } else {
                Log.wtf(this.getClass().getName(), "finish");
                finish();
            }
        }
    }
}
Also used : AccountHelper(net.iGap.module.accountManager.AccountHelper) FragmentRegistrationNickname(net.iGap.fragments.FragmentRegistrationNickname) Intent(android.content.Intent) Fragment(androidx.fragment.app.Fragment) WelcomeFragment(net.iGap.fragments.WelcomeFragment) FragmentActivation(net.iGap.fragments.FragmentActivation)

Aggregations

AccountHelper (net.iGap.module.accountManager.AccountHelper)5 Intent (android.content.Intent)3 Bundle (android.os.Bundle)2 Fragment (androidx.fragment.app.Fragment)2 FragmentManager (androidx.fragment.app.FragmentManager)2 HelperFragment (net.iGap.helper.HelperFragment)2 OpenFragment (net.iGap.observers.interfaces.OpenFragment)2 SuppressLint (android.annotation.SuppressLint)1 NotificationManager (android.app.NotificationManager)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 IntentFilter (android.content.IntentFilter)1 AudioManager (android.media.AudioManager)1 RemoteException (android.os.RemoteException)1 FrameLayout (android.widget.FrameLayout)1 TextView (android.widget.TextView)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 InstallReferrerClient (com.android.installreferrer.api.InstallReferrerClient)1 IOException (java.io.IOException)1