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