diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a5b8f75..fbb71b1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -22,7 +22,9 @@ android:supportsRtl="true" android:theme="@style/AppTheme" tools:ignore="GoogleAppIndexingWarning"> - + @@ -38,10 +40,15 @@ + android:label="@string/debug_activity_label"> + + { - ReviewsActivity.startForNumber(context, numberInfo.number); + context.startActivity(clearTop( + ReviewsActivity.getNumberIntent(context, numberInfo.number))); + dialog.dismiss(); }; diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/IntentHelper.java b/app/src/main/java/dummydomain/yetanothercallblocker/IntentHelper.java index 1ad5b0e..0a5a111 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/IntentHelper.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/IntentHelper.java @@ -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); + } + } diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/NotificationHelper.java b/app/src/main/java/dummydomain/yetanothercallblocker/NotificationHelper.java index 046d2f8..e5df175 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/NotificationHelper.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/NotificationHelper.java @@ -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) { diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/ReviewsActivity.java b/app/src/main/java/dummydomain/yetanothercallblocker/ReviewsActivity.java index 5048cc8..0604e39 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/ReviewsActivity.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/ReviewsActivity.java @@ -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> loadReviewsTask; + private AsyncTask> 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> asyncTask = loadReviewsTask - = new AsyncTask>() { + AsyncTask> asyncTask = loadReviewsTask + = new AsyncTask>() { @Override - protected List doInBackground(Void... voids) { - return DatabaseSingleton.getCommunityReviewsLoader().loadReviews(paramNumber); + protected List 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() {