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());
}
}
Aggregations