Improve activity stack
Thanks to an anonymous contributor
This commit is contained in:
parent
3f41da709d
commit
693bd02f30
|
@ -22,7 +22,9 @@
|
|||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
tools:ignore="GoogleAppIndexingWarning">
|
||||
<activity android:name=".MainActivity">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:launchMode="singleTop">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
|
@ -38,10 +40,15 @@
|
|||
</activity>
|
||||
<activity
|
||||
android:name=".DebugActivity"
|
||||
android:label="@string/debug_activity_label" />
|
||||
android:label="@string/debug_activity_label">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".MainActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ReviewsActivity"
|
||||
android:label="@string/title_activity_reviews"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
|
||||
<activity
|
||||
|
|
|
@ -13,6 +13,8 @@ import androidx.appcompat.app.AlertDialog;
|
|||
import dummydomain.yetanothercallblocker.data.NumberInfo;
|
||||
import dummydomain.yetanothercallblocker.sia.model.NumberCategory;
|
||||
|
||||
import static dummydomain.yetanothercallblocker.IntentHelper.clearTop;
|
||||
|
||||
public class InfoDialogHelper {
|
||||
|
||||
public static void showDialog(Context context, NumberInfo numberInfo,
|
||||
|
@ -71,7 +73,9 @@ public class InfoDialogHelper {
|
|||
// avoid dismissing the original dialog on button press
|
||||
|
||||
Runnable action = () -> {
|
||||
ReviewsActivity.startForNumber(context, numberInfo.number);
|
||||
context.startActivity(clearTop(
|
||||
ReviewsActivity.getNumberIntent(context, numberInfo.number)));
|
||||
|
||||
dialog.dismiss();
|
||||
};
|
||||
|
||||
|
|
|
@ -16,4 +16,8 @@ public class IntentHelper {
|
|||
return PendingIntent.getActivity(context, 0, intent, 0);
|
||||
}
|
||||
|
||||
public static Intent clearTop(Intent intent) {
|
||||
return intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import dummydomain.yetanothercallblocker.data.NumberInfo;
|
|||
import dummydomain.yetanothercallblocker.sia.model.NumberCategory;
|
||||
import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabaseItem;
|
||||
|
||||
import static dummydomain.yetanothercallblocker.IntentHelper.clearTop;
|
||||
import static dummydomain.yetanothercallblocker.IntentHelper.pendingActivity;
|
||||
|
||||
public class NotificationHelper {
|
||||
|
@ -213,7 +214,8 @@ public class NotificationHelper {
|
|||
}
|
||||
|
||||
private static PendingIntent createReviewsIntent(Context context, NumberInfo numberInfo) {
|
||||
return pendingActivity(context, ReviewsActivity.getNumberIntent(context, numberInfo.number));
|
||||
return pendingActivity(context, clearTop(
|
||||
ReviewsActivity.getNumberIntent(context, numberInfo.number)));
|
||||
}
|
||||
|
||||
static void createNotificationChannels(Context context) {
|
||||
|
|
|
@ -9,10 +9,13 @@ import android.text.TextUtils;
|
|||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import dummydomain.yetanothercallblocker.data.DatabaseSingleton;
|
||||
|
@ -22,9 +25,10 @@ public class ReviewsActivity extends AppCompatActivity {
|
|||
|
||||
private static final String PARAM_NUMBER = "param_number";
|
||||
|
||||
private CollapsingToolbarLayout collapsingToolbarLayout;
|
||||
private CustomListViewAdapter listViewAdapter;
|
||||
|
||||
private AsyncTask<Void, Void, List<CommunityReview>> loadReviewsTask;
|
||||
private AsyncTask<String, Void, List<CommunityReview>> loadReviewsTask;
|
||||
|
||||
public static Intent getNumberIntent(Context context, String number) {
|
||||
Intent intent = new Intent(context, ReviewsActivity.class);
|
||||
|
@ -43,11 +47,12 @@ public class ReviewsActivity extends AppCompatActivity {
|
|||
setContentView(R.layout.activity_reviews);
|
||||
setSupportActionBar(findViewById(R.id.toolbar));
|
||||
|
||||
final String paramNumber = getIntent().getStringExtra(PARAM_NUMBER);
|
||||
collapsingToolbarLayout = findViewById(R.id.toolbar_layout);
|
||||
|
||||
findViewById(R.id.reviews_summary).setVisibility(View.GONE);
|
||||
setTitle(paramNumber);
|
||||
setText(getString(R.string.reviews_loading));
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
listViewAdapter = new CustomListViewAdapter();
|
||||
RecyclerView reviewsList = findViewById(R.id.reviews_list);
|
||||
|
@ -55,12 +60,44 @@ public class ReviewsActivity extends AppCompatActivity {
|
|||
reviewsList.setAdapter(listViewAdapter);
|
||||
reviewsList.addItemDecoration(new CustomVerticalDivider(this));
|
||||
|
||||
handleIntent(getIntent());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
|
||||
handleIntent(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
cancelReviewsLoadingTask();
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSupportNavigateUp() {
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void handleIntent(Intent intent) {
|
||||
String paramNumber = intent.getStringExtra(PARAM_NUMBER);
|
||||
|
||||
findViewById(R.id.reviews_summary).setVisibility(View.GONE);
|
||||
collapsingToolbarLayout.setTitle(paramNumber);
|
||||
setText(getString(R.string.reviews_loading));
|
||||
|
||||
cancelReviewsLoadingTask();
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
AsyncTask<Void, Void, List<CommunityReview>> asyncTask = loadReviewsTask
|
||||
= new AsyncTask<Void, Void, List<CommunityReview>>() {
|
||||
AsyncTask<String, Void, List<CommunityReview>> asyncTask = loadReviewsTask
|
||||
= new AsyncTask<String, Void, List<CommunityReview>>() {
|
||||
@Override
|
||||
protected List<CommunityReview> doInBackground(Void... voids) {
|
||||
return DatabaseSingleton.getCommunityReviewsLoader().loadReviews(paramNumber);
|
||||
protected List<CommunityReview> doInBackground(String... params) {
|
||||
return DatabaseSingleton.getCommunityReviewsLoader().loadReviews(params[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,14 +106,7 @@ public class ReviewsActivity extends AppCompatActivity {
|
|||
handleReviews(reviews);
|
||||
}
|
||||
};
|
||||
asyncTask.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
cancelReviewsLoadingTask();
|
||||
|
||||
super.onDestroy();
|
||||
asyncTask.execute(paramNumber);
|
||||
}
|
||||
|
||||
private void cancelReviewsLoadingTask() {
|
||||
|
|
Loading…
Reference in New Issue