Search in sources :

Example 1 with OpenFragment

use of net.iGap.observers.interfaces.OpenFragment 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)

Aggregations

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 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 AudioManager (android.media.AudioManager)1 Bundle (android.os.Bundle)1 RemoteException (android.os.RemoteException)1 FrameLayout (android.widget.FrameLayout)1 TextView (android.widget.TextView)1 FragmentManager (androidx.fragment.app.FragmentManager)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 InstallReferrerClient (com.android.installreferrer.api.InstallReferrerClient)1 IOException (java.io.IOException)1 FragmentNewGroup (net.iGap.fragments.FragmentNewGroup)1 HelperFragment (net.iGap.helper.HelperFragment)1 PermissionHelper (net.iGap.helper.PermissionHelper)1 AccountHelper (net.iGap.module.accountManager.AccountHelper)1