Skip to content

Commit

Permalink
fix: blank screen on back press in LoginActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Aug 19, 2019
1 parent eb0279c commit aa2db37
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 30 deletions.
2 changes: 0 additions & 2 deletions app/src/main/java/co/tinode/tindroid/FindFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import androidx.appcompat.widget.ShareActionProvider;
import android.widget.Toast;

import java.io.IOException;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
Expand Down
18 changes: 10 additions & 8 deletions app/src/main/java/co/tinode/tindroid/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ public void onClick(View v) {

if (TextUtils.isEmpty(cred)) {
// Display the login form.
showFragment(FRAGMENT_LOGIN);
showFragment(FRAGMENT_LOGIN, null, false);
} else {
// Ask for validation code
Bundle args = new Bundle();
args.putString("method", cred);
showFragment(FRAGMENT_CREDENTIALS, args);
showFragment(FRAGMENT_CREDENTIALS, args, false);
}

// Check and possibly request runtime permissions.
Expand Down Expand Up @@ -250,10 +250,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

void showFragment(String tag) {
showFragment(tag, null);
showFragment(tag, null, true);
}

private void showFragment(String tag, Bundle args) {
private void showFragment(String tag, Bundle args, Boolean addToBackstack) {
FragmentManager fm = getSupportFragmentManager();
Fragment fragment = fm.findFragmentByTag(tag);
if (fragment == null) {
Expand Down Expand Up @@ -282,11 +282,13 @@ private void showFragment(String tag, Bundle args) {
fragment.setArguments(args);
}

fm.beginTransaction()
FragmentTransaction tx = fm.beginTransaction()
.replace(R.id.contentFragment, fragment)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.addToBackStack(null)
.commit();
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
if (addToBackstack) {
tx = tx.addToBackStack(null);
}
tx.commit();
}

/**
Expand Down
10 changes: 4 additions & 6 deletions app/src/main/java/co/tinode/tindroid/SplashActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,14 @@ protected void onCreate(Bundle savedInstanceState) {

// Account found, try to use it for login
UiUtils.loginWithSavedAccount(this, accountManager, account);
finish();
return;
}
}

startActivity(new Intent(this, LoginActivity.class));
}

@Override
protected void onPause() {
super.onPause();
Intent intent = new Intent(this, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
startActivity(intent);
finish();
}
}
15 changes: 2 additions & 13 deletions app/src/main/java/co/tinode/tindroid/StartChatActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,9 @@ public void onTabReselected(TabLayout.Tab tab) {}
});
}


@Override
public void onResume() {
super.onResume();
}

@Override
public void onPause() {
super.onPause();
}

@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String permissions[], @NonNull int[] grantResults) {
@NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == UiUtils.READ_EXTERNAL_STORAGE_PERMISSION) {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
Expand All @@ -111,7 +100,7 @@ private class PagerAdapter extends FragmentStatePagerAdapter {
Fragment mById;

PagerAdapter(FragmentManager fm) {
super(fm);
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
}

@Override
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/co/tinode/tindroid/UiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ public void run(AccountManagerFuture<Bundle> future) {
}
}
}
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
activity.startActivity(launch);
}
}, null);
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<FrameLayout
android:id="@+id/contentFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent"
tools:layout="@layout/fragment_login" />

</LinearLayout>

0 comments on commit aa2db37

Please sign in to comment.