Allow hiding pro banner one day

This commit is contained in:
M66B 2019-11-23 11:39:34 +01:00
parent 7077be3f5a
commit f5aebd93b9
6 changed files with 66 additions and 6 deletions

View File

@ -2627,10 +2627,11 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if ("pro".equals(key)) {
if ("pro".equals(key) || "banner".equals(key)) {
boolean pro = ActivityBilling.isPro(getContext());
boolean banner = prefs.getBoolean("banner", true);
grpSupport.setVisibility(
!pro && viewType == AdapterMessage.ViewType.UNIFIED
!pro && banner && viewType == AdapterMessage.ViewType.UNIFIED
? View.VISIBLE : View.GONE);
}
}

View File

@ -19,6 +19,9 @@ package eu.faircode.email;
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Paint;
@ -29,6 +32,8 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
@ -39,10 +44,13 @@ import androidx.preference.PreferenceManager;
import com.google.android.material.snackbar.Snackbar;
import java.util.Date;
public class FragmentPro extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
private TextView tvPending;
private TextView tvActivated;
private TextView tvInfo;
private CheckBox cbHide;
private TextView tvList;
private Button btnPurchase;
private TextView tvPrice;
@ -55,7 +63,7 @@ public class FragmentPro extends FragmentBase implements SharedPreferences.OnSha
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.menu_pro);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean debug = prefs.getBoolean("debug", false);
View view = inflater.inflate(R.layout.fragment_pro, container, false);
@ -63,6 +71,7 @@ public class FragmentPro extends FragmentBase implements SharedPreferences.OnSha
tvPending = view.findViewById(R.id.tvPending);
tvActivated = view.findViewById(R.id.tvActivated);
tvInfo = view.findViewById(R.id.tvInfo);
cbHide = view.findViewById(R.id.cbHide);
tvList = view.findViewById(R.id.tvList);
btnPurchase = view.findViewById(R.id.btnPurchase);
tvPrice = view.findViewById(R.id.tvPrice);
@ -74,6 +83,33 @@ public class FragmentPro extends FragmentBase implements SharedPreferences.OnSha
tvInfo.setText(getString(R.string.title_pro_info)
.replaceAll("^\\s+", "").replaceAll("\\s+", " "));
boolean banner = prefs.getBoolean("banner", true);
cbHide.setChecked(!banner);
cbHide.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
prefs.edit().putBoolean("banner", !isChecked).apply();
Intent daily = new Intent(getContext(), ServiceUI.class);
daily.setAction("daily");
PendingIntent pi = PendingIntent.getService(getContext(), ServiceUI.PI_DAILY, daily, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
if (isChecked) {
long now = new Date().getTime();
long interval = AlarmManager.INTERVAL_DAY;
long due = interval - (now % interval);
long trigger = now + due;
Log.i("Set banner alarm at " + new Date(trigger) + " due=" + due);
am.set(AlarmManager.RTC, trigger, pi);
} else {
Log.i("Cancel banner alarm");
am.cancel(pi);
}
}
});
tvList.setPaintFlags(tvList.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
tvList.setOnClickListener(new View.OnClickListener() {
@Override
@ -104,6 +140,7 @@ public class FragmentPro extends FragmentBase implements SharedPreferences.OnSha
tvPending.setVisibility(View.GONE);
tvActivated.setVisibility(View.GONE);
cbHide.setVisibility(View.GONE);
btnPurchase.setEnabled(false);
tvPrice.setText(null);
btnCheck.setEnabled(false);
@ -187,9 +224,11 @@ public class FragmentPro extends FragmentBase implements SharedPreferences.OnSha
if ("pro".equals(key)) {
boolean pro = ActivityBilling.isPro(getContext());
tvActivated.setVisibility(pro ? View.VISIBLE : View.GONE);
cbHide.setVisibility(pro ? View.GONE : View.VISIBLE);
if (!Helper.isPlayStoreInstall())
btnPurchase.setEnabled(!pro || BuildConfig.DEBUG);
}
} else if ("banner".equals(key))
cbHide.setChecked(!prefs.getBoolean(key, true));
}
}

View File

@ -34,7 +34,7 @@ public class ReceiverAutoStart extends BroadcastReceiver {
Log.i("Received " + intent);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().remove("last_vacuum").apply();
prefs.edit().remove("banner").apply();
ServiceSynchronize.boot(context);
ServiceSend.boot(context);

View File

@ -52,6 +52,7 @@ public class ServiceUI extends IntentService {
static final int PI_IGNORED = 10;
static final int PI_THREAD = 11;
static final int PI_WAKEUP = 12;
static final int PI_DAILY = 13;
public ServiceUI() {
this(ServiceUI.class.getName());
@ -151,6 +152,10 @@ public class ServiceUI extends IntentService {
// https://developer.android.com/reference/android/app/AlarmManager
onWakeup(id);
break;
case "daily":
onDaily();
break;
default:
throw new IllegalArgumentException("Unknown UI action: " + parts[0]);
}
@ -403,4 +408,9 @@ public class ServiceUI extends IntentService {
db.endTransaction();
}
}
private void onDaily() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.edit().remove("banner").apply();
}
}

View File

@ -42,6 +42,15 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvActivated" />
<CheckBox
android:id="@+id/cbHide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_pro_hide"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvInfo" />
<TextView
android:id="@+id/tvList"
android:layout_width="wrap_content"
@ -51,7 +60,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?attr/colorAccent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvInfo" />
app:layout_constraintTop_toBottomOf="@id/cbHide" />
<Button
android:id="@+id/btnPurchase"

View File

@ -949,6 +949,7 @@
To make FairEmail sustainable in the long term, some convenience and advanced features are not free to use.
FairEmail displays a small message to remind you of this, which will be removed if you purchase the pro features.
</string>
<string name="title_pro_hide">Hide small message until tomorrow</string>
<string name="title_pro_hint">Buying pro features will allow you to use all current and future pro features, will keep this app maintained, and supported.</string>
<string name="title_pro_price">Please see <a href="https://github.com/M66B/FairEmail/blob/master/FAQ.md#user-content-faq19">this FAQ</a> about the price of the pro features</string>
<string name="title_pro_pending">Purchase pending</string>