Skip to content

Commit

Permalink
Merge pull request #212 from kaczmarkiewiczp/dev
Browse files Browse the repository at this point in the history
Add notification channel for beta releases
  • Loading branch information
patrykcoding authored Sep 3, 2018
2 parents 9136706 + 5de2cc8 commit 3eac177
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class NotificationsSettingsFragment extends Fragment {
private View notificationsElement;
private View appUpdatesElement;
private Switch appUpdatesSwitch;
private View betaAppUpdatesElement;
private Switch betaAppUpdatesSwitch;

/**
* Mandatory empty constructor for the fragment manager to instantiate the
Expand Down Expand Up @@ -68,13 +70,23 @@ private void getViews(View view) {
notificationsElement = view.findViewById(R.id.notifications);
appUpdatesElement = view.findViewById(R.id.app_updates);
appUpdatesSwitch = view.findViewById(R.id.app_updates_switch);
betaAppUpdatesElement = view.findViewById(R.id.beta_app_updates);
betaAppUpdatesSwitch = view.findViewById(R.id.beta_app_updates_switch);
}

private void setDefaultStates() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean appUpdates = sharedPreferences.getBoolean(getString(R.string.pref_key_app_updates), false);
boolean betaUpdates = sharedPreferences.getBoolean(getString(R.string.pref_key_app_updates_beta), false);

appUpdatesSwitch.setChecked(appUpdates);
betaAppUpdatesSwitch.setChecked(betaUpdates);

if (appUpdates) {
betaAppUpdatesElement.setVisibility(View.VISIBLE);
} else {
betaAppUpdatesElement.setVisibility(View.GONE);
}
}

private void setClickListeners() {
Expand All @@ -101,6 +113,22 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
onAppUpdatesClicked(isChecked);
}
});
betaAppUpdatesElement.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (betaAppUpdatesSwitch.isChecked()) {
betaAppUpdatesSwitch.setChecked(false);
} else {
betaAppUpdatesSwitch.setChecked(true);
}
}
});
betaAppUpdatesSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
onBetaAppUpdatesClicked(isChecked);
}
});
}

private void onNotificationsClicked() {
Expand All @@ -124,13 +152,29 @@ private void onNotificationsClicked() {
private void onAppUpdatesClicked(boolean isChecked) {
if (isChecked) {
FirebaseMessaging.getInstance().subscribeToTopic(getString(R.string.firebase_msg_app_updates_topic));
betaAppUpdatesElement.setVisibility(View.VISIBLE);
} else {
FirebaseMessaging.getInstance().unsubscribeFromTopic(getString(R.string.firebase_msg_app_updates_topic));
betaAppUpdatesSwitch.setChecked(false);
betaAppUpdatesElement.setVisibility(View.GONE);
}

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(getString(R.string.pref_key_app_updates), isChecked);
editor.apply();
}

private void onBetaAppUpdatesClicked(boolean isChecked) {
if (isChecked) {
FirebaseMessaging.getInstance().subscribeToTopic(getString(R.string.firebase_msg_beta_app_updates_topic));
} else {
FirebaseMessaging.getInstance().unsubscribeFromTopic(getString(R.string.firebase_msg_beta_app_updates_topic));
}

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(getString(R.string.pref_key_app_updates_beta), isChecked);
editor.apply();
}
}
36 changes: 35 additions & 1 deletion app/src/main/res/layout/notification_settings_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="16dp">
android:paddingBottom="16dp"
android:animateLayoutChanges="true">

<RelativeLayout
android:id="@+id/notifications"
Expand Down Expand Up @@ -69,6 +70,39 @@

</RelativeLayout>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dividerColor"/>

<RelativeLayout
android:id="@+id/beta_app_updates"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingTop="24dp"
android:paddingBottom="24dp"
android:clickable="true"
android:focusable="true"
android:background="?selectableItemBackground" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textColor="?attr/textColorPrimary"
android:textStyle="bold"
android:text="@string/beta_app_updates_notifications"/>

<Switch
android:id="@+id/beta_app_updates_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true" />

</RelativeLayout>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
<string name="pref_key_color_accent">pref_key_color_accent</string>
<string name="pref_key_dark_theme">pref_key_dark_theme</string>
<string name="pref_key_app_updates">pref_key_app_updates</string>
<string name="pref_key_app_updates_beta">pref_key_app_updates_beta</string>
<string name="pref_key_crash_reports">pref_key_crash_reports</string>
<string name="pref_key_show_thumbnails">pref_key_show_thumbnails</string>
<string name="pref_key_wifi_only_transfers">pref_key_wifi_only_transfers</string>
Expand Down Expand Up @@ -279,8 +280,10 @@
<string name="choose_dir">Choose directory</string>
<string name="error_exporting_config_file">Error exporting config file</string>
<string name="firebase_msg_app_updates_topic">app_updates</string>
<string name="firebase_msg_beta_app_updates_topic">beta_app_updates</string>
<string name="app_update_notification_title">New version of Rclone Explorer is available on GitHub</string>
<string name="app_updates_notifications">Get notified about app updates</string>
<string name="beta_app_updates_notifications">Get notified about beta releases</string>
<string name="delete_remote_title">Delete remote?</string>
<string name="empty_trash">Empty trash</string>
<string name="trash_emptied">Trash emptied</string>
Expand Down

0 comments on commit 3eac177

Please sign in to comment.