#1343 Mute dialog sites counter and sites reset

This commit is contained in:
sictiru 2020-09-19 12:02:46 -07:00
parent 5686a6608d
commit 6828a47121
4 changed files with 113 additions and 15 deletions

View file

@ -4,6 +4,39 @@
android:layout_height="match_parent"
android:animateLayoutChanges="true">
<FrameLayout
android:id="@+id/container_sites_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="4dp"
android:paddingTop="16dp"
android:paddingEnd="8dp"
android:paddingBottom="16dp"
android:visibility="gone">
<TextView
android:id="@+id/text_reset_sites"
style="?linkText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:padding="4dp"
android:text="@string/mute_config_reset_button"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="@+id/text_sites"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:text="@string/mute_config_sites"
android:textColor="@color/positive"
android:textSize="12sp"
android:textStyle="bold" />
</FrameLayout>
<ExpandableListView
android:id="@+id/list_view"
android:layout_width="match_parent"

View file

@ -299,6 +299,8 @@
<string name="mute_config_title">You can follow up to 64 sites with a free standard account</string>
<string name="mute_config_message">Please mute %d sites or reset to most popular sites.</string>
<string name="mute_config_reset_button">RESET TO POPULAR SITES</string>
<string name="mute_config_upgrade">UPGRADE</string>
<string name="mute_config_sites">%s/%s</string>
<string name="menu_network_select">Download Using</string>
<string name="menu_network_select_sum">Restrict background data to chosen networks</string>

View file

@ -1,11 +1,16 @@
package com.newsblur.activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.database.Cursor;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.core.content.ContextCompat;
import com.newsblur.R;
import com.newsblur.databinding.ActivityMuteConfigBinding;
@ -15,15 +20,17 @@ import com.newsblur.service.NBSyncService;
import com.newsblur.util.AppConstants;
import com.newsblur.util.FeedUtils;
import com.newsblur.util.PrefsUtils;
import com.newsblur.util.UIUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class MuteConfig extends FeedChooser {
public class MuteConfig extends FeedChooser implements MuteConfigAdapter.FeedStateChangedListener {
private ActivityMuteConfigBinding binding;
private boolean checkedInitFeedsLimit = false;
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
@ -56,7 +63,7 @@ public class MuteConfig extends FeedChooser {
@Override
void setupList() {
adapter = new MuteConfigAdapter(this);
adapter = new MuteConfigAdapter(this, this);
binding.listView.setAdapter(adapter);
}
@ -74,7 +81,6 @@ public class MuteConfig extends FeedChooser {
@Override
void processData() {
int activeSites = 0;
if (folders != null && feeds != null) {
for (Folder folder : folders) {
ArrayList<Feed> children = new ArrayList<>();
@ -83,21 +89,14 @@ public class MuteConfig extends FeedChooser {
if (!children.contains(feed)) {
children.add(feed);
}
if (feed != null && feed.active) {
activeSites++;
}
}
folderNames.add(folder.flatName());
folderChildren.add(children);
}
setAdapterData();
// free standard accounts can follow up to 64 sites
boolean isPremium = PrefsUtils.getIsPremium(this);
if (!isPremium && activeSites > AppConstants.FREE_ACCOUNT_SITE_LIMIT) {
showAccountFeedsLimitDialog(activeSites - AppConstants.FREE_ACCOUNT_SITE_LIMIT);
}
syncActiveFeedCount();
checkedInitFeedsLimit = true;
}
}
@ -126,6 +125,34 @@ public class MuteConfig extends FeedChooser {
}
}
@Override
public void onFeedStateChanged() {
syncActiveFeedCount();
}
private void syncActiveFeedCount() {
// free standard accounts can follow up to 64 sites
boolean isPremium = PrefsUtils.getIsPremium(this);
if (!isPremium && feeds != null) {
int activeSites = 0;
for (Feed feed : feeds) {
if (feed.active) {
activeSites++;
}
}
int textColorRes = activeSites > AppConstants.FREE_ACCOUNT_SITE_LIMIT ? R.color.negative : R.color.positive;
binding.textSites.setTextColor(ContextCompat.getColor(this, textColorRes));
binding.textSites.setText(String.format(getString(R.string.mute_config_sites), activeSites, AppConstants.FREE_ACCOUNT_SITE_LIMIT));
showSitesCount();
if (activeSites > AppConstants.FREE_ACCOUNT_SITE_LIMIT && !checkedInitFeedsLimit) {
showAccountFeedsLimitDialog(activeSites - AppConstants.FREE_ACCOUNT_SITE_LIMIT);
}
} else {
hideSitesCount();
}
}
private void setFeedsState(boolean isMute) {
for (Feed feed : feeds) {
feed.active = !isMute;
@ -140,11 +167,29 @@ public class MuteConfig extends FeedChooser {
new AlertDialog.Builder(this)
.setTitle(R.string.mute_config_title)
.setMessage(String.format(getString(R.string.mute_config_message), exceededLimitCount))
.setPositiveButton(android.R.string.ok, null)
.setNeutralButton(R.string.mute_config_reset_button, (dialogInterface, i) -> resetToPopularFeeds())
.setNeutralButton(android.R.string.ok, null)
.setPositiveButton(R.string.mute_config_upgrade, (dialogInterface, i) -> openUpgradeToPremium())
.show();
}
private void showSitesCount() {
ViewGroup.LayoutParams oldLayout = binding.listView.getLayoutParams();
FrameLayout.LayoutParams newLayout = new FrameLayout.LayoutParams(oldLayout);
newLayout.topMargin = UIUtils.dp2px(this, 56);
binding.listView.setLayoutParams(newLayout);
binding.containerSitesCount.setVisibility(View.VISIBLE);
binding.textResetSites.setOnClickListener(view -> resetToPopularFeeds());
}
private void hideSitesCount() {
ViewGroup.LayoutParams oldLayout = binding.listView.getLayoutParams();
FrameLayout.LayoutParams newLayout = new FrameLayout.LayoutParams(oldLayout);
newLayout.topMargin = UIUtils.dp2px(this, 0);
binding.listView.setLayoutParams(newLayout);
binding.containerSitesCount.setVisibility(View.GONE);
binding.textResetSites.setOnClickListener(null);
}
// reset to most popular sites based on subscribers
private void resetToPopularFeeds() {
// sort descending by subscribers
@ -167,4 +212,10 @@ public class MuteConfig extends FeedChooser {
FeedUtils.muteFeeds(this, inactiveFeedIds);
finish();
}
private void openUpgradeToPremium() {
Intent intent = new Intent(this, Premium.class);
startActivity(intent);
finish();
}
}

View file

@ -16,8 +16,11 @@ import java.util.Set;
public class MuteConfigAdapter extends FeedChooserAdapter {
MuteConfigAdapter(Context context) {
private FeedStateChangedListener listener;
MuteConfigAdapter(Context context, FeedStateChangedListener listener) {
super(context);
this.listener = listener;
}
@Override
@ -44,6 +47,8 @@ public class MuteConfigAdapter extends FeedChooserAdapter {
// if allAreMute initially, we need to unMute feeds
if (allAreMute) FeedUtils.unmuteFeeds(groupView.getContext(), feedIds);
else FeedUtils.muteFeeds(groupView.getContext(), feedIds);
listener.onFeedStateChanged();
notifyDataChanged();
});
return groupView;
@ -67,8 +72,15 @@ public class MuteConfigAdapter extends FeedChooserAdapter {
feedIds.add(feed.feedId);
if (feed.active) FeedUtils.unmuteFeeds(childView.getContext(), feedIds);
else FeedUtils.muteFeeds(childView.getContext(), feedIds);
listener.onFeedStateChanged();
notifyDataChanged();
});
return childView;
}
interface FeedStateChangedListener {
void onFeedStateChanged();
}
}